Merge branch 'for-linus' of git://oss.sgi.com/xfs/xfs
[sfrench/cifs-2.6.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <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 /* for GPIO Poll */
242 #define GPIO_MASK       0x03
243
244 struct alc_spec {
245         /* codec parameterization */
246         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
247         unsigned int num_mixers;
248         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
249
250         const struct hda_verb *init_verbs[5];   /* initialization verbs
251                                                  * don't forget NULL
252                                                  * termination!
253                                                  */
254         unsigned int num_init_verbs;
255
256         char *stream_name_analog;       /* analog PCM stream */
257         struct hda_pcm_stream *stream_analog_playback;
258         struct hda_pcm_stream *stream_analog_capture;
259         struct hda_pcm_stream *stream_analog_alt_playback;
260         struct hda_pcm_stream *stream_analog_alt_capture;
261
262         char *stream_name_digital;      /* digital PCM stream */
263         struct hda_pcm_stream *stream_digital_playback;
264         struct hda_pcm_stream *stream_digital_capture;
265
266         /* playback */
267         struct hda_multi_out multiout;  /* playback set-up
268                                          * max_channels, dacs must be set
269                                          * dig_out_nid and hp_nid are optional
270                                          */
271         hda_nid_t alt_dac_nid;
272
273         /* capture */
274         unsigned int num_adc_nids;
275         hda_nid_t *adc_nids;
276         hda_nid_t *capsrc_nids;
277         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
278         unsigned char is_mix_capture;   /* matrix-style capture (non-mux) */
279
280         /* capture source */
281         unsigned int num_mux_defs;
282         const struct hda_input_mux *input_mux;
283         unsigned int cur_mux[3];
284
285         /* channel model */
286         const struct hda_channel_mode *channel_mode;
287         int num_channel_mode;
288         int need_dac_fix;
289
290         /* PCM information */
291         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
292
293         /* dynamic controls, init_verbs and input_mux */
294         struct auto_pin_cfg autocfg;
295         struct snd_array kctls;
296         struct hda_input_mux private_imux;
297         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
298
299         /* hooks */
300         void (*init_hook)(struct hda_codec *codec);
301         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
302
303         /* for pin sensing */
304         unsigned int sense_updated: 1;
305         unsigned int jack_present: 1;
306         unsigned int master_sw: 1;
307
308         /* for virtual master */
309         hda_nid_t vmaster_nid;
310 #ifdef CONFIG_SND_HDA_POWER_SAVE
311         struct hda_loopback_check loopback;
312 #endif
313
314         /* for PLL fix */
315         hda_nid_t pll_nid;
316         unsigned int pll_coef_idx, pll_coef_bit;
317
318 #ifdef SND_HDA_NEEDS_RESUME
319 #define ALC_MAX_PINS    16
320         unsigned int num_pins;
321         hda_nid_t pin_nids[ALC_MAX_PINS];
322         unsigned int pin_cfgs[ALC_MAX_PINS];
323 #endif
324 };
325
326 /*
327  * configuration template - to be copied to the spec instance
328  */
329 struct alc_config_preset {
330         struct snd_kcontrol_new *mixers[5]; /* should be identical size
331                                              * with spec
332                                              */
333         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
334         const struct hda_verb *init_verbs[5];
335         unsigned int num_dacs;
336         hda_nid_t *dac_nids;
337         hda_nid_t dig_out_nid;          /* optional */
338         hda_nid_t hp_nid;               /* optional */
339         unsigned int num_adc_nids;
340         hda_nid_t *adc_nids;
341         hda_nid_t *capsrc_nids;
342         hda_nid_t dig_in_nid;
343         unsigned int num_channel_mode;
344         const struct hda_channel_mode *channel_mode;
345         int need_dac_fix;
346         unsigned int num_mux_defs;
347         const struct hda_input_mux *input_mux;
348         void (*unsol_event)(struct hda_codec *, unsigned int);
349         void (*init_hook)(struct hda_codec *);
350 #ifdef CONFIG_SND_HDA_POWER_SAVE
351         struct hda_amp_list *loopbacks;
352 #endif
353 };
354
355
356 /*
357  * input MUX handling
358  */
359 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
360                              struct snd_ctl_elem_info *uinfo)
361 {
362         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
363         struct alc_spec *spec = codec->spec;
364         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
365         if (mux_idx >= spec->num_mux_defs)
366                 mux_idx = 0;
367         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
368 }
369
370 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
371                             struct snd_ctl_elem_value *ucontrol)
372 {
373         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
374         struct alc_spec *spec = codec->spec;
375         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
376
377         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
378         return 0;
379 }
380
381 static int alc_mux_enum_put(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         const struct hda_input_mux *imux;
387         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
388         unsigned int mux_idx;
389         hda_nid_t nid = spec->capsrc_nids ?
390                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
391
392         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
393         imux = &spec->input_mux[mux_idx];
394
395         if (spec->is_mix_capture) {
396                 /* Matrix-mixer style (e.g. ALC882) */
397                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
398                 unsigned int i, idx;
399
400                 idx = ucontrol->value.enumerated.item[0];
401                 if (idx >= imux->num_items)
402                         idx = imux->num_items - 1;
403                 if (*cur_val == idx)
404                         return 0;
405                 for (i = 0; i < imux->num_items; i++) {
406                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
407                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
408                                                  imux->items[i].index,
409                                                  HDA_AMP_MUTE, v);
410                 }
411                 *cur_val = idx;
412                 return 1;
413         } else {
414                 /* MUX style (e.g. ALC880) */
415                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
416                                              &spec->cur_mux[adc_idx]);
417         }
418 }
419
420 /*
421  * channel mode setting
422  */
423 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
424                             struct snd_ctl_elem_info *uinfo)
425 {
426         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
427         struct alc_spec *spec = codec->spec;
428         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
429                                     spec->num_channel_mode);
430 }
431
432 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
433                            struct snd_ctl_elem_value *ucontrol)
434 {
435         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
436         struct alc_spec *spec = codec->spec;
437         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
438                                    spec->num_channel_mode,
439                                    spec->multiout.max_channels);
440 }
441
442 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
443                            struct snd_ctl_elem_value *ucontrol)
444 {
445         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
446         struct alc_spec *spec = codec->spec;
447         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
448                                       spec->num_channel_mode,
449                                       &spec->multiout.max_channels);
450         if (err >= 0 && spec->need_dac_fix)
451                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
452         return err;
453 }
454
455 /*
456  * Control the mode of pin widget settings via the mixer.  "pc" is used
457  * instead of "%" to avoid consequences of accidently treating the % as
458  * being part of a format specifier.  Maximum allowed length of a value is
459  * 63 characters plus NULL terminator.
460  *
461  * Note: some retasking pin complexes seem to ignore requests for input
462  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
463  * are requested.  Therefore order this list so that this behaviour will not
464  * cause problems when mixer clients move through the enum sequentially.
465  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
466  * March 2006.
467  */
468 static char *alc_pin_mode_names[] = {
469         "Mic 50pc bias", "Mic 80pc bias",
470         "Line in", "Line out", "Headphone out",
471 };
472 static unsigned char alc_pin_mode_values[] = {
473         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
474 };
475 /* The control can present all 5 options, or it can limit the options based
476  * in the pin being assumed to be exclusively an input or an output pin.  In
477  * addition, "input" pins may or may not process the mic bias option
478  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
479  * accept requests for bias as of chip versions up to March 2006) and/or
480  * wiring in the computer.
481  */
482 #define ALC_PIN_DIR_IN              0x00
483 #define ALC_PIN_DIR_OUT             0x01
484 #define ALC_PIN_DIR_INOUT           0x02
485 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
486 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
487
488 /* Info about the pin modes supported by the different pin direction modes.
489  * For each direction the minimum and maximum values are given.
490  */
491 static signed char alc_pin_mode_dir_info[5][2] = {
492         { 0, 2 },    /* ALC_PIN_DIR_IN */
493         { 3, 4 },    /* ALC_PIN_DIR_OUT */
494         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
495         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
496         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
497 };
498 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
499 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
500 #define alc_pin_mode_n_items(_dir) \
501         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
502
503 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
504                              struct snd_ctl_elem_info *uinfo)
505 {
506         unsigned int item_num = uinfo->value.enumerated.item;
507         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
508
509         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
510         uinfo->count = 1;
511         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
512
513         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
514                 item_num = alc_pin_mode_min(dir);
515         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
516         return 0;
517 }
518
519 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
520                             struct snd_ctl_elem_value *ucontrol)
521 {
522         unsigned int i;
523         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
524         hda_nid_t nid = kcontrol->private_value & 0xffff;
525         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
526         long *valp = ucontrol->value.integer.value;
527         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
528                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
529                                                  0x00);
530
531         /* Find enumerated value for current pinctl setting */
532         i = alc_pin_mode_min(dir);
533         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
534                 i++;
535         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
536         return 0;
537 }
538
539 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
540                             struct snd_ctl_elem_value *ucontrol)
541 {
542         signed int change;
543         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
544         hda_nid_t nid = kcontrol->private_value & 0xffff;
545         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
546         long val = *ucontrol->value.integer.value;
547         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
548                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
549                                                  0x00);
550
551         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
552                 val = alc_pin_mode_min(dir);
553
554         change = pinctl != alc_pin_mode_values[val];
555         if (change) {
556                 /* Set pin mode to that requested */
557                 snd_hda_codec_write_cache(codec, nid, 0,
558                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
559                                           alc_pin_mode_values[val]);
560
561                 /* Also enable the retasking pin's input/output as required
562                  * for the requested pin mode.  Enum values of 2 or less are
563                  * input modes.
564                  *
565                  * Dynamically switching the input/output buffers probably
566                  * reduces noise slightly (particularly on input) so we'll
567                  * do it.  However, having both input and output buffers
568                  * enabled simultaneously doesn't seem to be problematic if
569                  * this turns out to be necessary in the future.
570                  */
571                 if (val <= 2) {
572                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
573                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
574                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
575                                                  HDA_AMP_MUTE, 0);
576                 } else {
577                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
578                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
579                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
580                                                  HDA_AMP_MUTE, 0);
581                 }
582         }
583         return change;
584 }
585
586 #define ALC_PIN_MODE(xname, nid, dir) \
587         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
588           .info = alc_pin_mode_info, \
589           .get = alc_pin_mode_get, \
590           .put = alc_pin_mode_put, \
591           .private_value = nid | (dir<<16) }
592
593 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
594  * together using a mask with more than one bit set.  This control is
595  * currently used only by the ALC260 test model.  At this stage they are not
596  * needed for any "production" models.
597  */
598 #ifdef CONFIG_SND_DEBUG
599 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
600
601 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
602                              struct snd_ctl_elem_value *ucontrol)
603 {
604         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
605         hda_nid_t nid = kcontrol->private_value & 0xffff;
606         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
607         long *valp = ucontrol->value.integer.value;
608         unsigned int val = snd_hda_codec_read(codec, nid, 0,
609                                               AC_VERB_GET_GPIO_DATA, 0x00);
610
611         *valp = (val & mask) != 0;
612         return 0;
613 }
614 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
615                              struct snd_ctl_elem_value *ucontrol)
616 {
617         signed int change;
618         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
619         hda_nid_t nid = kcontrol->private_value & 0xffff;
620         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
621         long val = *ucontrol->value.integer.value;
622         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
623                                                     AC_VERB_GET_GPIO_DATA,
624                                                     0x00);
625
626         /* Set/unset the masked GPIO bit(s) as needed */
627         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
628         if (val == 0)
629                 gpio_data &= ~mask;
630         else
631                 gpio_data |= mask;
632         snd_hda_codec_write_cache(codec, nid, 0,
633                                   AC_VERB_SET_GPIO_DATA, gpio_data);
634
635         return change;
636 }
637 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
638         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
639           .info = alc_gpio_data_info, \
640           .get = alc_gpio_data_get, \
641           .put = alc_gpio_data_put, \
642           .private_value = nid | (mask<<16) }
643 #endif   /* CONFIG_SND_DEBUG */
644
645 /* A switch control to allow the enabling of the digital IO pins on the
646  * ALC260.  This is incredibly simplistic; the intention of this control is
647  * to provide something in the test model allowing digital outputs to be
648  * identified if present.  If models are found which can utilise these
649  * outputs a more complete mixer control can be devised for those models if
650  * necessary.
651  */
652 #ifdef CONFIG_SND_DEBUG
653 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
654
655 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
656                               struct snd_ctl_elem_value *ucontrol)
657 {
658         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
659         hda_nid_t nid = kcontrol->private_value & 0xffff;
660         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
661         long *valp = ucontrol->value.integer.value;
662         unsigned int val = snd_hda_codec_read(codec, nid, 0,
663                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
664
665         *valp = (val & mask) != 0;
666         return 0;
667 }
668 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
669                               struct snd_ctl_elem_value *ucontrol)
670 {
671         signed int change;
672         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
673         hda_nid_t nid = kcontrol->private_value & 0xffff;
674         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
675         long val = *ucontrol->value.integer.value;
676         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
677                                                     AC_VERB_GET_DIGI_CONVERT_1,
678                                                     0x00);
679
680         /* Set/unset the masked control bit(s) as needed */
681         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
682         if (val==0)
683                 ctrl_data &= ~mask;
684         else
685                 ctrl_data |= mask;
686         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
687                                   ctrl_data);
688
689         return change;
690 }
691 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
692         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
693           .info = alc_spdif_ctrl_info, \
694           .get = alc_spdif_ctrl_get, \
695           .put = alc_spdif_ctrl_put, \
696           .private_value = nid | (mask<<16) }
697 #endif   /* CONFIG_SND_DEBUG */
698
699 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
700  * Again, this is only used in the ALC26x test models to help identify when
701  * the EAPD line must be asserted for features to work.
702  */
703 #ifdef CONFIG_SND_DEBUG
704 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
705
706 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
707                               struct snd_ctl_elem_value *ucontrol)
708 {
709         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
710         hda_nid_t nid = kcontrol->private_value & 0xffff;
711         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
712         long *valp = ucontrol->value.integer.value;
713         unsigned int val = snd_hda_codec_read(codec, nid, 0,
714                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
715
716         *valp = (val & mask) != 0;
717         return 0;
718 }
719
720 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
721                               struct snd_ctl_elem_value *ucontrol)
722 {
723         int change;
724         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
725         hda_nid_t nid = kcontrol->private_value & 0xffff;
726         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
727         long val = *ucontrol->value.integer.value;
728         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
729                                                     AC_VERB_GET_EAPD_BTLENABLE,
730                                                     0x00);
731
732         /* Set/unset the masked control bit(s) as needed */
733         change = (!val ? 0 : mask) != (ctrl_data & mask);
734         if (!val)
735                 ctrl_data &= ~mask;
736         else
737                 ctrl_data |= mask;
738         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
739                                   ctrl_data);
740
741         return change;
742 }
743
744 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
745         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
746           .info = alc_eapd_ctrl_info, \
747           .get = alc_eapd_ctrl_get, \
748           .put = alc_eapd_ctrl_put, \
749           .private_value = nid | (mask<<16) }
750 #endif   /* CONFIG_SND_DEBUG */
751
752 /*
753  */
754 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
755 {
756         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
757                 return;
758         spec->mixers[spec->num_mixers++] = mix;
759 }
760
761 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
762 {
763         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
764                 return;
765         spec->init_verbs[spec->num_init_verbs++] = verb;
766 }
767
768 #ifdef CONFIG_PROC_FS
769 /*
770  * hook for proc
771  */
772 static void print_realtek_coef(struct snd_info_buffer *buffer,
773                                struct hda_codec *codec, hda_nid_t nid)
774 {
775         int coeff;
776
777         if (nid != 0x20)
778                 return;
779         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
780         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
781         coeff = snd_hda_codec_read(codec, nid, 0,
782                                    AC_VERB_GET_COEF_INDEX, 0);
783         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
784 }
785 #else
786 #define print_realtek_coef      NULL
787 #endif
788
789 /*
790  * set up from the preset table
791  */
792 static void setup_preset(struct alc_spec *spec,
793                          const struct alc_config_preset *preset)
794 {
795         int i;
796
797         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
798                 add_mixer(spec, preset->mixers[i]);
799         spec->cap_mixer = preset->cap_mixer;
800         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
801              i++)
802                 add_verb(spec, preset->init_verbs[i]);
803
804         spec->channel_mode = preset->channel_mode;
805         spec->num_channel_mode = preset->num_channel_mode;
806         spec->need_dac_fix = preset->need_dac_fix;
807
808         spec->multiout.max_channels = spec->channel_mode[0].channels;
809
810         spec->multiout.num_dacs = preset->num_dacs;
811         spec->multiout.dac_nids = preset->dac_nids;
812         spec->multiout.dig_out_nid = preset->dig_out_nid;
813         spec->multiout.hp_nid = preset->hp_nid;
814
815         spec->num_mux_defs = preset->num_mux_defs;
816         if (!spec->num_mux_defs)
817                 spec->num_mux_defs = 1;
818         spec->input_mux = preset->input_mux;
819
820         spec->num_adc_nids = preset->num_adc_nids;
821         spec->adc_nids = preset->adc_nids;
822         spec->capsrc_nids = preset->capsrc_nids;
823         spec->dig_in_nid = preset->dig_in_nid;
824
825         spec->unsol_event = preset->unsol_event;
826         spec->init_hook = preset->init_hook;
827 #ifdef CONFIG_SND_HDA_POWER_SAVE
828         spec->loopback.amplist = preset->loopbacks;
829 #endif
830 }
831
832 /* Enable GPIO mask and set output */
833 static struct hda_verb alc_gpio1_init_verbs[] = {
834         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
835         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
836         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
837         { }
838 };
839
840 static struct hda_verb alc_gpio2_init_verbs[] = {
841         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
842         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
843         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
844         { }
845 };
846
847 static struct hda_verb alc_gpio3_init_verbs[] = {
848         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
849         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
850         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
851         { }
852 };
853
854 /*
855  * Fix hardware PLL issue
856  * On some codecs, the analog PLL gating control must be off while
857  * the default value is 1.
858  */
859 static void alc_fix_pll(struct hda_codec *codec)
860 {
861         struct alc_spec *spec = codec->spec;
862         unsigned int val;
863
864         if (!spec->pll_nid)
865                 return;
866         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
867                             spec->pll_coef_idx);
868         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
869                                  AC_VERB_GET_PROC_COEF, 0);
870         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
871                             spec->pll_coef_idx);
872         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
873                             val & ~(1 << spec->pll_coef_bit));
874 }
875
876 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
877                              unsigned int coef_idx, unsigned int coef_bit)
878 {
879         struct alc_spec *spec = codec->spec;
880         spec->pll_nid = nid;
881         spec->pll_coef_idx = coef_idx;
882         spec->pll_coef_bit = coef_bit;
883         alc_fix_pll(codec);
884 }
885
886 static void alc_sku_automute(struct hda_codec *codec)
887 {
888         struct alc_spec *spec = codec->spec;
889         unsigned int present;
890         unsigned int hp_nid = spec->autocfg.hp_pins[0];
891         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
892
893         /* need to execute and sync at first */
894         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
895         present = snd_hda_codec_read(codec, hp_nid, 0,
896                                      AC_VERB_GET_PIN_SENSE, 0);
897         spec->jack_present = (present & 0x80000000) != 0;
898         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
899                             spec->jack_present ? 0 : PIN_OUT);
900 }
901
902 #if 0 /* it's broken in some acses -- temporarily disabled */
903 static void alc_mic_automute(struct hda_codec *codec)
904 {
905         struct alc_spec *spec = codec->spec;
906         unsigned int present;
907         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
908         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
909         unsigned int mix_nid = spec->capsrc_nids[0];
910         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
911
912         capsrc_idx_mic = mic_nid - 0x18;
913         capsrc_idx_fmic = fmic_nid - 0x18;
914         present = snd_hda_codec_read(codec, mic_nid, 0,
915                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
916         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
917                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
918         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
919                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
920         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
921                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
922 }
923 #else
924 #define alc_mic_automute(codec) /* NOP */
925 #endif /* disabled */
926
927 /* unsolicited event for HP jack sensing */
928 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
929 {
930         if (codec->vendor_id == 0x10ec0880)
931                 res >>= 28;
932         else
933                 res >>= 26;
934         if (res == ALC880_HP_EVENT)
935                 alc_sku_automute(codec);
936
937         if (res == ALC880_MIC_EVENT)
938                 alc_mic_automute(codec);
939 }
940
941 static void alc_inithook(struct hda_codec *codec)
942 {
943         alc_sku_automute(codec);
944         alc_mic_automute(codec);
945 }
946
947 /* additional initialization for ALC888 variants */
948 static void alc888_coef_init(struct hda_codec *codec)
949 {
950         unsigned int tmp;
951
952         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
953         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
954         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
955         if ((tmp & 0xf0) == 2)
956                 /* alc888S-VC */
957                 snd_hda_codec_read(codec, 0x20, 0,
958                                    AC_VERB_SET_PROC_COEF, 0x830);
959          else
960                  /* alc888-VB */
961                  snd_hda_codec_read(codec, 0x20, 0,
962                                     AC_VERB_SET_PROC_COEF, 0x3030);
963 }
964
965 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
966  *      31 ~ 16 :       Manufacture ID
967  *      15 ~ 8  :       SKU ID
968  *      7  ~ 0  :       Assembly ID
969  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
970  */
971 static void alc_subsystem_id(struct hda_codec *codec,
972                              unsigned int porta, unsigned int porte,
973                              unsigned int portd)
974 {
975         unsigned int ass, tmp, i;
976         unsigned nid;
977         struct alc_spec *spec = codec->spec;
978
979         ass = codec->subsystem_id & 0xffff;
980         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
981                 goto do_sku;
982
983         /*
984          * 31~30        : port conetcivity
985          * 29~21        : reserve
986          * 20           : PCBEEP input
987          * 19~16        : Check sum (15:1)
988          * 15~1         : Custom
989          * 0            : override
990         */
991         nid = 0x1d;
992         if (codec->vendor_id == 0x10ec0260)
993                 nid = 0x17;
994         ass = snd_hda_codec_read(codec, nid, 0,
995                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
996         if (!(ass & 1) && !(ass & 0x100000))
997                 return;
998         if ((ass >> 30) != 1)   /* no physical connection */
999                 return;
1000
1001         /* check sum */
1002         tmp = 0;
1003         for (i = 1; i < 16; i++) {
1004                 if ((ass >> i) & 1)
1005                         tmp++;
1006         }
1007         if (((ass >> 16) & 0xf) != tmp)
1008                 return;
1009 do_sku:
1010         /*
1011          * 0 : override
1012          * 1 :  Swap Jack
1013          * 2 : 0 --> Desktop, 1 --> Laptop
1014          * 3~5 : External Amplifier control
1015          * 7~6 : Reserved
1016         */
1017         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1018         switch (tmp) {
1019         case 1:
1020                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1021                 break;
1022         case 3:
1023                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1024                 break;
1025         case 7:
1026                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1027                 break;
1028         case 5: /* set EAPD output high */
1029                 switch (codec->vendor_id) {
1030                 case 0x10ec0260:
1031                         snd_hda_codec_write(codec, 0x0f, 0,
1032                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1033                         snd_hda_codec_write(codec, 0x10, 0,
1034                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1035                         break;
1036                 case 0x10ec0262:
1037                 case 0x10ec0267:
1038                 case 0x10ec0268:
1039                 case 0x10ec0269:
1040                 case 0x10ec0272:
1041                 case 0x10ec0660:
1042                 case 0x10ec0662:
1043                 case 0x10ec0663:
1044                 case 0x10ec0862:
1045                 case 0x10ec0889:
1046                         snd_hda_codec_write(codec, 0x14, 0,
1047                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1048                         snd_hda_codec_write(codec, 0x15, 0,
1049                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1050                         break;
1051                 }
1052                 switch (codec->vendor_id) {
1053                 case 0x10ec0260:
1054                         snd_hda_codec_write(codec, 0x1a, 0,
1055                                             AC_VERB_SET_COEF_INDEX, 7);
1056                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1057                                                  AC_VERB_GET_PROC_COEF, 0);
1058                         snd_hda_codec_write(codec, 0x1a, 0,
1059                                             AC_VERB_SET_COEF_INDEX, 7);
1060                         snd_hda_codec_write(codec, 0x1a, 0,
1061                                             AC_VERB_SET_PROC_COEF,
1062                                             tmp | 0x2010);
1063                         break;
1064                 case 0x10ec0262:
1065                 case 0x10ec0880:
1066                 case 0x10ec0882:
1067                 case 0x10ec0883:
1068                 case 0x10ec0885:
1069                 case 0x10ec0887:
1070                 case 0x10ec0889:
1071                         snd_hda_codec_write(codec, 0x20, 0,
1072                                             AC_VERB_SET_COEF_INDEX, 7);
1073                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1074                                                  AC_VERB_GET_PROC_COEF, 0);
1075                         snd_hda_codec_write(codec, 0x20, 0,
1076                                             AC_VERB_SET_COEF_INDEX, 7);
1077                         snd_hda_codec_write(codec, 0x20, 0,
1078                                             AC_VERB_SET_PROC_COEF,
1079                                             tmp | 0x2010);
1080                         break;
1081                 case 0x10ec0888:
1082                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1083                         break;
1084                 case 0x10ec0267:
1085                 case 0x10ec0268:
1086                         snd_hda_codec_write(codec, 0x20, 0,
1087                                             AC_VERB_SET_COEF_INDEX, 7);
1088                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1089                                                  AC_VERB_GET_PROC_COEF, 0);
1090                         snd_hda_codec_write(codec, 0x20, 0,
1091                                             AC_VERB_SET_COEF_INDEX, 7);
1092                         snd_hda_codec_write(codec, 0x20, 0,
1093                                             AC_VERB_SET_PROC_COEF,
1094                                             tmp | 0x3000);
1095                         break;
1096                 }
1097         default:
1098                 break;
1099         }
1100
1101         /* is laptop or Desktop and enable the function "Mute internal speaker
1102          * when the external headphone out jack is plugged"
1103          */
1104         if (!(ass & 0x8000))
1105                 return;
1106         /*
1107          * 10~8 : Jack location
1108          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1109          * 14~13: Resvered
1110          * 15   : 1 --> enable the function "Mute internal speaker
1111          *              when the external headphone out jack is plugged"
1112          */
1113         if (!spec->autocfg.speaker_pins[0]) {
1114                 if (spec->autocfg.line_out_pins[0])
1115                         spec->autocfg.speaker_pins[0] =
1116                                 spec->autocfg.line_out_pins[0];
1117                 else
1118                         return;
1119         }
1120
1121         if (!spec->autocfg.hp_pins[0]) {
1122                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1123                 if (tmp == 0)
1124                         spec->autocfg.hp_pins[0] = porta;
1125                 else if (tmp == 1)
1126                         spec->autocfg.hp_pins[0] = porte;
1127                 else if (tmp == 2)
1128                         spec->autocfg.hp_pins[0] = portd;
1129                 else
1130                         return;
1131         }
1132         if (spec->autocfg.hp_pins[0])
1133                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1134                         AC_VERB_SET_UNSOLICITED_ENABLE,
1135                         AC_USRSP_EN | ALC880_HP_EVENT);
1136
1137 #if 0 /* it's broken in some acses -- temporarily disabled */
1138         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1139                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1140                 snd_hda_codec_write(codec,
1141                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1142                         AC_VERB_SET_UNSOLICITED_ENABLE,
1143                         AC_USRSP_EN | ALC880_MIC_EVENT);
1144 #endif /* disabled */
1145
1146         spec->unsol_event = alc_sku_unsol_event;
1147 }
1148
1149 /*
1150  * Fix-up pin default configurations
1151  */
1152
1153 struct alc_pincfg {
1154         hda_nid_t nid;
1155         u32 val;
1156 };
1157
1158 static void alc_fix_pincfg(struct hda_codec *codec,
1159                            const struct snd_pci_quirk *quirk,
1160                            const struct alc_pincfg **pinfix)
1161 {
1162         const struct alc_pincfg *cfg;
1163
1164         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1165         if (!quirk)
1166                 return;
1167
1168         cfg = pinfix[quirk->value];
1169         for (; cfg->nid; cfg++) {
1170                 int i;
1171                 u32 val = cfg->val;
1172                 for (i = 0; i < 4; i++) {
1173                         snd_hda_codec_write(codec, cfg->nid, 0,
1174                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1175                                     val & 0xff);
1176                         val >>= 8;
1177                 }
1178         }
1179 }
1180
1181 /*
1182  * ALC888
1183  */
1184
1185 /*
1186  * 2ch mode
1187  */
1188 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1189 /* Mic-in jack as mic in */
1190         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1191         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1192 /* Line-in jack as Line in */
1193         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1194         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1195 /* Line-Out as Front */
1196         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1197         { } /* end */
1198 };
1199
1200 /*
1201  * 4ch mode
1202  */
1203 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1204 /* Mic-in jack as mic in */
1205         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1206         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1207 /* Line-in jack as Surround */
1208         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1209         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1210 /* Line-Out as Front */
1211         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1212         { } /* end */
1213 };
1214
1215 /*
1216  * 6ch mode
1217  */
1218 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1219 /* Mic-in jack as CLFE */
1220         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1221         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1222 /* Line-in jack as Surround */
1223         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1224         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1225 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1226         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1227         { } /* end */
1228 };
1229
1230 /*
1231  * 8ch mode
1232  */
1233 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1234 /* Mic-in jack as CLFE */
1235         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1236         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1237 /* Line-in jack as Surround */
1238         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1239         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1240 /* Line-Out as Side */
1241         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1242         { } /* end */
1243 };
1244
1245 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1246         { 2, alc888_4ST_ch2_intel_init },
1247         { 4, alc888_4ST_ch4_intel_init },
1248         { 6, alc888_4ST_ch6_intel_init },
1249         { 8, alc888_4ST_ch8_intel_init },
1250 };
1251
1252 /*
1253  * ALC888 Fujitsu Siemens Amillo xa3530
1254  */
1255
1256 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1257 /* Front Mic: set to PIN_IN (empty by default) */
1258         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1259 /* Connect Internal HP to Front */
1260         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1261         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1262         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1263 /* Connect Bass HP to Front */
1264         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1265         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1266         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1267 /* Connect Line-Out side jack (SPDIF) to Side */
1268         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1269         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1270         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1271 /* Connect Mic jack to CLFE */
1272         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1273         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1274         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1275 /* Connect Line-in jack to Surround */
1276         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1277         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1278         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1279 /* Connect HP out jack to Front */
1280         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1281         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1282         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1283 /* Enable unsolicited event for HP jack and Line-out jack */
1284         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1285         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1286         {}
1287 };
1288
1289 static void alc888_fujitsu_xa3530_automute(struct hda_codec *codec)
1290 {
1291         unsigned int present;
1292         unsigned int bits;
1293         /* Line out presence */
1294         present = snd_hda_codec_read(codec, 0x17, 0,
1295                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1296         /* HP out presence */
1297         present = present || snd_hda_codec_read(codec, 0x1b, 0,
1298                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1299         bits = present ? HDA_AMP_MUTE : 0;
1300         /* Toggle internal speakers muting */
1301         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1302                                  HDA_AMP_MUTE, bits);
1303         /* Toggle internal bass muting */
1304         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1305                                  HDA_AMP_MUTE, bits);
1306 }
1307
1308 static void alc888_fujitsu_xa3530_unsol_event(struct hda_codec *codec,
1309                 unsigned int res)
1310 {
1311         if (res >> 26 == ALC880_HP_EVENT)
1312                 alc888_fujitsu_xa3530_automute(codec);
1313 }
1314
1315
1316 /*
1317  * ALC888 Acer Aspire 4930G model
1318  */
1319
1320 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1321 /* Front Mic: set to PIN_IN (empty by default) */
1322         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1323 /* Unselect Front Mic by default in input mixer 3 */
1324         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1325 /* Enable unsolicited event for HP jack */
1326         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1327 /* Connect Internal HP to front */
1328         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1329         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1330         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1331 /* Connect HP out to front */
1332         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1333         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1334         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1335         { }
1336 };
1337
1338 static struct hda_input_mux alc888_2_capture_sources[2] = {
1339         /* Front mic only available on one ADC */
1340         {
1341                 .num_items = 4,
1342                 .items = {
1343                         { "Mic", 0x0 },
1344                         { "Line", 0x2 },
1345                         { "CD", 0x4 },
1346                         { "Front Mic", 0xb },
1347                 },
1348         },
1349         {
1350                 .num_items = 3,
1351                 .items = {
1352                         { "Mic", 0x0 },
1353                         { "Line", 0x2 },
1354                         { "CD", 0x4 },
1355                 },
1356         }
1357 };
1358
1359 static struct snd_kcontrol_new alc888_base_mixer[] = {
1360         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1361         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1362         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1363         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1364         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1365                 HDA_OUTPUT),
1366         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1367         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1368         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1369         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1370         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1371         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1372         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1373         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1374         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1375         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1376         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1377         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1378         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1379         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1380         { } /* end */
1381 };
1382
1383 static void alc888_acer_aspire_4930g_automute(struct hda_codec *codec)
1384 {
1385         unsigned int present;
1386         unsigned int bits;
1387         present = snd_hda_codec_read(codec, 0x15, 0,
1388                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1389         bits = present ? HDA_AMP_MUTE : 0;
1390         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1391                                  HDA_AMP_MUTE, bits);
1392 }
1393
1394 static void alc888_acer_aspire_4930g_unsol_event(struct hda_codec *codec,
1395                 unsigned int res)
1396 {
1397         if (res >> 26 == ALC880_HP_EVENT)
1398                 alc888_acer_aspire_4930g_automute(codec);
1399 }
1400
1401 /*
1402  * ALC880 3-stack model
1403  *
1404  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1405  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1406  *                 F-Mic = 0x1b, HP = 0x19
1407  */
1408
1409 static hda_nid_t alc880_dac_nids[4] = {
1410         /* front, rear, clfe, rear_surr */
1411         0x02, 0x05, 0x04, 0x03
1412 };
1413
1414 static hda_nid_t alc880_adc_nids[3] = {
1415         /* ADC0-2 */
1416         0x07, 0x08, 0x09,
1417 };
1418
1419 /* The datasheet says the node 0x07 is connected from inputs,
1420  * but it shows zero connection in the real implementation on some devices.
1421  * Note: this is a 915GAV bug, fixed on 915GLV
1422  */
1423 static hda_nid_t alc880_adc_nids_alt[2] = {
1424         /* ADC1-2 */
1425         0x08, 0x09,
1426 };
1427
1428 #define ALC880_DIGOUT_NID       0x06
1429 #define ALC880_DIGIN_NID        0x0a
1430
1431 static struct hda_input_mux alc880_capture_source = {
1432         .num_items = 4,
1433         .items = {
1434                 { "Mic", 0x0 },
1435                 { "Front Mic", 0x3 },
1436                 { "Line", 0x2 },
1437                 { "CD", 0x4 },
1438         },
1439 };
1440
1441 /* channel source setting (2/6 channel selection for 3-stack) */
1442 /* 2ch mode */
1443 static struct hda_verb alc880_threestack_ch2_init[] = {
1444         /* set line-in to input, mute it */
1445         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1446         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1447         /* set mic-in to input vref 80%, mute it */
1448         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1449         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1450         { } /* end */
1451 };
1452
1453 /* 6ch mode */
1454 static struct hda_verb alc880_threestack_ch6_init[] = {
1455         /* set line-in to output, unmute it */
1456         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1457         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1458         /* set mic-in to output, unmute it */
1459         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1460         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1461         { } /* end */
1462 };
1463
1464 static struct hda_channel_mode alc880_threestack_modes[2] = {
1465         { 2, alc880_threestack_ch2_init },
1466         { 6, alc880_threestack_ch6_init },
1467 };
1468
1469 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1470         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1471         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1472         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1473         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1474         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1475         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1476         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1477         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1478         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1479         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1480         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1481         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1482         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1483         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1484         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1485         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1486         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1487         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1488         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1489         {
1490                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1491                 .name = "Channel Mode",
1492                 .info = alc_ch_mode_info,
1493                 .get = alc_ch_mode_get,
1494                 .put = alc_ch_mode_put,
1495         },
1496         { } /* end */
1497 };
1498
1499 /* capture mixer elements */
1500 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1501                             struct snd_ctl_elem_info *uinfo)
1502 {
1503         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1504         struct alc_spec *spec = codec->spec;
1505         int err;
1506
1507         mutex_lock(&codec->control_mutex);
1508         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1509                                                       HDA_INPUT);
1510         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1511         mutex_unlock(&codec->control_mutex);
1512         return err;
1513 }
1514
1515 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1516                            unsigned int size, unsigned int __user *tlv)
1517 {
1518         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1519         struct alc_spec *spec = codec->spec;
1520         int err;
1521
1522         mutex_lock(&codec->control_mutex);
1523         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1524                                                       HDA_INPUT);
1525         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1526         mutex_unlock(&codec->control_mutex);
1527         return err;
1528 }
1529
1530 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1531                              struct snd_ctl_elem_value *ucontrol);
1532
1533 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1534                                  struct snd_ctl_elem_value *ucontrol,
1535                                  getput_call_t func)
1536 {
1537         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1538         struct alc_spec *spec = codec->spec;
1539         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1540         int err;
1541
1542         mutex_lock(&codec->control_mutex);
1543         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1544                                                       3, 0, HDA_INPUT);
1545         err = func(kcontrol, ucontrol);
1546         mutex_unlock(&codec->control_mutex);
1547         return err;
1548 }
1549
1550 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1551                            struct snd_ctl_elem_value *ucontrol)
1552 {
1553         return alc_cap_getput_caller(kcontrol, ucontrol,
1554                                      snd_hda_mixer_amp_volume_get);
1555 }
1556
1557 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1558                            struct snd_ctl_elem_value *ucontrol)
1559 {
1560         return alc_cap_getput_caller(kcontrol, ucontrol,
1561                                      snd_hda_mixer_amp_volume_put);
1562 }
1563
1564 /* capture mixer elements */
1565 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1566
1567 static int alc_cap_sw_get(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_switch_get);
1572 }
1573
1574 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1575                           struct snd_ctl_elem_value *ucontrol)
1576 {
1577         return alc_cap_getput_caller(kcontrol, ucontrol,
1578                                      snd_hda_mixer_amp_switch_put);
1579 }
1580
1581 #define DEFINE_CAPMIX(num) \
1582 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1583         { \
1584                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1585                 .name = "Capture Switch", \
1586                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1587                 .count = num, \
1588                 .info = alc_cap_sw_info, \
1589                 .get = alc_cap_sw_get, \
1590                 .put = alc_cap_sw_put, \
1591         }, \
1592         { \
1593                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1594                 .name = "Capture Volume", \
1595                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1596                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1597                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1598                 .count = num, \
1599                 .info = alc_cap_vol_info, \
1600                 .get = alc_cap_vol_get, \
1601                 .put = alc_cap_vol_put, \
1602                 .tlv = { .c = alc_cap_vol_tlv }, \
1603         }, \
1604         { \
1605                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1606                 /* .name = "Capture Source", */ \
1607                 .name = "Input Source", \
1608                 .count = num, \
1609                 .info = alc_mux_enum_info, \
1610                 .get = alc_mux_enum_get, \
1611                 .put = alc_mux_enum_put, \
1612         }, \
1613         { } /* end */ \
1614 }
1615
1616 /* up to three ADCs */
1617 DEFINE_CAPMIX(1);
1618 DEFINE_CAPMIX(2);
1619 DEFINE_CAPMIX(3);
1620
1621
1622 /*
1623  * ALC880 5-stack model
1624  *
1625  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1626  *      Side = 0x02 (0xd)
1627  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1628  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1629  */
1630
1631 /* additional mixers to alc880_three_stack_mixer */
1632 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1633         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1634         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1635         { } /* end */
1636 };
1637
1638 /* channel source setting (6/8 channel selection for 5-stack) */
1639 /* 6ch mode */
1640 static struct hda_verb alc880_fivestack_ch6_init[] = {
1641         /* set line-in to input, mute it */
1642         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1643         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1644         { } /* end */
1645 };
1646
1647 /* 8ch mode */
1648 static struct hda_verb alc880_fivestack_ch8_init[] = {
1649         /* set line-in to output, unmute it */
1650         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1651         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1652         { } /* end */
1653 };
1654
1655 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1656         { 6, alc880_fivestack_ch6_init },
1657         { 8, alc880_fivestack_ch8_init },
1658 };
1659
1660
1661 /*
1662  * ALC880 6-stack model
1663  *
1664  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1665  *      Side = 0x05 (0x0f)
1666  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1667  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1668  */
1669
1670 static hda_nid_t alc880_6st_dac_nids[4] = {
1671         /* front, rear, clfe, rear_surr */
1672         0x02, 0x03, 0x04, 0x05
1673 };
1674
1675 static struct hda_input_mux alc880_6stack_capture_source = {
1676         .num_items = 4,
1677         .items = {
1678                 { "Mic", 0x0 },
1679                 { "Front Mic", 0x1 },
1680                 { "Line", 0x2 },
1681                 { "CD", 0x4 },
1682         },
1683 };
1684
1685 /* fixed 8-channels */
1686 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1687         { 8, NULL },
1688 };
1689
1690 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1691         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1692         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1693         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1694         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1695         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1696         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1697         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1698         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1699         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1700         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1701         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1702         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1703         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1704         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1705         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1706         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1707         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1708         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1709         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1710         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1711         {
1712                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1713                 .name = "Channel Mode",
1714                 .info = alc_ch_mode_info,
1715                 .get = alc_ch_mode_get,
1716                 .put = alc_ch_mode_put,
1717         },
1718         { } /* end */
1719 };
1720
1721
1722 /*
1723  * ALC880 W810 model
1724  *
1725  * W810 has rear IO for:
1726  * Front (DAC 02)
1727  * Surround (DAC 03)
1728  * Center/LFE (DAC 04)
1729  * Digital out (06)
1730  *
1731  * The system also has a pair of internal speakers, and a headphone jack.
1732  * These are both connected to Line2 on the codec, hence to DAC 02.
1733  *
1734  * There is a variable resistor to control the speaker or headphone
1735  * volume. This is a hardware-only device without a software API.
1736  *
1737  * Plugging headphones in will disable the internal speakers. This is
1738  * implemented in hardware, not via the driver using jack sense. In
1739  * a similar fashion, plugging into the rear socket marked "front" will
1740  * disable both the speakers and headphones.
1741  *
1742  * For input, there's a microphone jack, and an "audio in" jack.
1743  * These may not do anything useful with this driver yet, because I
1744  * haven't setup any initialization verbs for these yet...
1745  */
1746
1747 static hda_nid_t alc880_w810_dac_nids[3] = {
1748         /* front, rear/surround, clfe */
1749         0x02, 0x03, 0x04
1750 };
1751
1752 /* fixed 6 channels */
1753 static struct hda_channel_mode alc880_w810_modes[1] = {
1754         { 6, NULL }
1755 };
1756
1757 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1758 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1759         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1760         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1761         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1762         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1763         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1764         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1765         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1766         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1767         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1768         { } /* end */
1769 };
1770
1771
1772 /*
1773  * Z710V model
1774  *
1775  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1776  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1777  *                 Line = 0x1a
1778  */
1779
1780 static hda_nid_t alc880_z71v_dac_nids[1] = {
1781         0x02
1782 };
1783 #define ALC880_Z71V_HP_DAC      0x03
1784
1785 /* fixed 2 channels */
1786 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1787         { 2, NULL }
1788 };
1789
1790 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1791         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1792         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1793         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1794         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1795         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1796         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1797         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1798         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1799         { } /* end */
1800 };
1801
1802
1803 /*
1804  * ALC880 F1734 model
1805  *
1806  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1807  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1808  */
1809
1810 static hda_nid_t alc880_f1734_dac_nids[1] = {
1811         0x03
1812 };
1813 #define ALC880_F1734_HP_DAC     0x02
1814
1815 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1816         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1817         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1818         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1819         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1820         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1821         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1822         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1823         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1824         { } /* end */
1825 };
1826
1827 static struct hda_input_mux alc880_f1734_capture_source = {
1828         .num_items = 2,
1829         .items = {
1830                 { "Mic", 0x1 },
1831                 { "CD", 0x4 },
1832         },
1833 };
1834
1835
1836 /*
1837  * ALC880 ASUS model
1838  *
1839  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1840  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1841  *  Mic = 0x18, Line = 0x1a
1842  */
1843
1844 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1845 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1846
1847 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1848         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1849         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1850         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1851         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1852         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1853         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1854         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1855         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1856         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1857         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1858         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1859         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1860         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1861         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1862         {
1863                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1864                 .name = "Channel Mode",
1865                 .info = alc_ch_mode_info,
1866                 .get = alc_ch_mode_get,
1867                 .put = alc_ch_mode_put,
1868         },
1869         { } /* end */
1870 };
1871
1872 /*
1873  * ALC880 ASUS W1V model
1874  *
1875  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1876  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1877  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1878  */
1879
1880 /* additional mixers to alc880_asus_mixer */
1881 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1882         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1883         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1884         { } /* end */
1885 };
1886
1887 /* additional mixers to alc880_asus_mixer */
1888 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1889         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1890         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1891         { } /* end */
1892 };
1893
1894 /* TCL S700 */
1895 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1896         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1897         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1898         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1899         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1900         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1901         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1902         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1903         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1904         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1905         { } /* end */
1906 };
1907
1908 /* Uniwill */
1909 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1910         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1911         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1912         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1913         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1914         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1915         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1916         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1917         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1918         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1919         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1920         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1921         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1922         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1923         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1924         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1925         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1926         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1927         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1928         {
1929                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1930                 .name = "Channel Mode",
1931                 .info = alc_ch_mode_info,
1932                 .get = alc_ch_mode_get,
1933                 .put = alc_ch_mode_put,
1934         },
1935         { } /* end */
1936 };
1937
1938 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1939         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1940         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1941         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1942         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1943         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1944         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1945         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1946         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1947         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1948         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1949         { } /* end */
1950 };
1951
1952 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1953         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1954         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1955         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1956         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1957         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1958         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1959         { } /* end */
1960 };
1961
1962 /*
1963  * virtual master controls
1964  */
1965
1966 /*
1967  * slave controls for virtual master
1968  */
1969 static const char *alc_slave_vols[] = {
1970         "Front Playback Volume",
1971         "Surround Playback Volume",
1972         "Center Playback Volume",
1973         "LFE Playback Volume",
1974         "Side Playback Volume",
1975         "Headphone Playback Volume",
1976         "Speaker Playback Volume",
1977         "Mono Playback Volume",
1978         "Line-Out Playback Volume",
1979         "PCM Playback Volume",
1980         NULL,
1981 };
1982
1983 static const char *alc_slave_sws[] = {
1984         "Front Playback Switch",
1985         "Surround Playback Switch",
1986         "Center Playback Switch",
1987         "LFE Playback Switch",
1988         "Side Playback Switch",
1989         "Headphone Playback Switch",
1990         "Speaker Playback Switch",
1991         "Mono Playback Switch",
1992         "IEC958 Playback Switch",
1993         NULL,
1994 };
1995
1996 /*
1997  * build control elements
1998  */
1999
2000 static void alc_free_kctls(struct hda_codec *codec);
2001
2002 static int alc_build_controls(struct hda_codec *codec)
2003 {
2004         struct alc_spec *spec = codec->spec;
2005         int err;
2006         int i;
2007
2008         for (i = 0; i < spec->num_mixers; i++) {
2009                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2010                 if (err < 0)
2011                         return err;
2012         }
2013         if (spec->cap_mixer) {
2014                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2015                 if (err < 0)
2016                         return err;
2017         }
2018         if (spec->multiout.dig_out_nid) {
2019                 err = snd_hda_create_spdif_out_ctls(codec,
2020                                                     spec->multiout.dig_out_nid);
2021                 if (err < 0)
2022                         return err;
2023                 err = snd_hda_create_spdif_share_sw(codec,
2024                                                     &spec->multiout);
2025                 if (err < 0)
2026                         return err;
2027                 spec->multiout.share_spdif = 1;
2028         }
2029         if (spec->dig_in_nid) {
2030                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2031                 if (err < 0)
2032                         return err;
2033         }
2034
2035         /* if we have no master control, let's create it */
2036         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2037                 unsigned int vmaster_tlv[4];
2038                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2039                                         HDA_OUTPUT, vmaster_tlv);
2040                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2041                                           vmaster_tlv, alc_slave_vols);
2042                 if (err < 0)
2043                         return err;
2044         }
2045         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2046                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2047                                           NULL, alc_slave_sws);
2048                 if (err < 0)
2049                         return err;
2050         }
2051
2052         alc_free_kctls(codec); /* no longer needed */
2053         return 0;
2054 }
2055
2056
2057 /*
2058  * initialize the codec volumes, etc
2059  */
2060
2061 /*
2062  * generic initialization of ADC, input mixers and output mixers
2063  */
2064 static struct hda_verb alc880_volume_init_verbs[] = {
2065         /*
2066          * Unmute ADC0-2 and set the default input to mic-in
2067          */
2068         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2069         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2070         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2071         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2072         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2073         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2074
2075         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2076          * mixer widget
2077          * Note: PASD motherboards uses the Line In 2 as the input for front
2078          * panel mic (mic 2)
2079          */
2080         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2081         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2082         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2083         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2084         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2085         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2086         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2087         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2088
2089         /*
2090          * Set up output mixers (0x0c - 0x0f)
2091          */
2092         /* set vol=0 to output mixers */
2093         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2094         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2095         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2096         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2097         /* set up input amps for analog loopback */
2098         /* Amp Indices: DAC = 0, mixer = 1 */
2099         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2100         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2101         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2102         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2103         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2104         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2105         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2106         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2107
2108         { }
2109 };
2110
2111 /*
2112  * 3-stack pin configuration:
2113  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2114  */
2115 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2116         /*
2117          * preset connection lists of input pins
2118          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2119          */
2120         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2121         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2122         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2123
2124         /*
2125          * Set pin mode and muting
2126          */
2127         /* set front pin widgets 0x14 for output */
2128         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2129         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2130         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2131         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2132         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2133         /* Mic2 (as headphone out) for HP output */
2134         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2135         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2136         /* Line In pin widget for input */
2137         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2138         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2139         /* Line2 (as front mic) pin widget for input and vref at 80% */
2140         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2141         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2142         /* CD pin widget for input */
2143         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2144
2145         { }
2146 };
2147
2148 /*
2149  * 5-stack pin configuration:
2150  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2151  * line-in/side = 0x1a, f-mic = 0x1b
2152  */
2153 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2154         /*
2155          * preset connection lists of input pins
2156          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2157          */
2158         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2159         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2160
2161         /*
2162          * Set pin mode and muting
2163          */
2164         /* set pin widgets 0x14-0x17 for output */
2165         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2166         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2167         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2168         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2169         /* unmute pins for output (no gain on this amp) */
2170         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2171         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2172         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2173         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2174
2175         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2176         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2177         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2178         /* Mic2 (as headphone out) for HP output */
2179         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2180         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2181         /* Line In pin widget for input */
2182         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2183         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2184         /* Line2 (as front mic) pin widget for input and vref at 80% */
2185         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2186         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2187         /* CD pin widget for input */
2188         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2189
2190         { }
2191 };
2192
2193 /*
2194  * W810 pin configuration:
2195  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2196  */
2197 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2198         /* hphone/speaker input selector: front DAC */
2199         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2200
2201         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2202         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2203         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2204         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2205         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2206         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2207
2208         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2209         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2210
2211         { }
2212 };
2213
2214 /*
2215  * Z71V pin configuration:
2216  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2217  */
2218 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2219         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2220         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2221         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2222         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2223
2224         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2225         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2226         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2227         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2228
2229         { }
2230 };
2231
2232 /*
2233  * 6-stack pin configuration:
2234  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2235  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2236  */
2237 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2238         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2239
2240         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2241         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2242         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2243         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2244         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2245         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2246         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2247         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2248
2249         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2250         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2251         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2252         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2253         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2254         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2255         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2256         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2257         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2258
2259         { }
2260 };
2261
2262 /*
2263  * Uniwill pin configuration:
2264  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2265  * line = 0x1a
2266  */
2267 static struct hda_verb alc880_uniwill_init_verbs[] = {
2268         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2269
2270         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2271         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2272         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2273         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2274         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2275         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2276         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2277         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2278         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2279         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2280         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2281         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2282         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2283         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2284
2285         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2286         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2287         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2288         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2289         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2290         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2291         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2292         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2293         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2294
2295         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2296         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2297
2298         { }
2299 };
2300
2301 /*
2302 * Uniwill P53
2303 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2304  */
2305 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2306         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2307
2308         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2309         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2310         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2311         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2312         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2313         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2314         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2315         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2316         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2317         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2318         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2319         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2320
2321         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2322         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2323         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2324         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2325         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2326         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2327
2328         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2329         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2330
2331         { }
2332 };
2333
2334 static struct hda_verb alc880_beep_init_verbs[] = {
2335         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2336         { }
2337 };
2338
2339 /* toggle speaker-output according to the hp-jack state */
2340 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
2341 {
2342         unsigned int present;
2343         unsigned char bits;
2344
2345         present = snd_hda_codec_read(codec, 0x14, 0,
2346                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2347         bits = present ? HDA_AMP_MUTE : 0;
2348         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
2349                                  HDA_AMP_MUTE, bits);
2350         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
2351                                  HDA_AMP_MUTE, bits);
2352 }
2353
2354 /* auto-toggle front mic */
2355 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2356 {
2357         unsigned int present;
2358         unsigned char bits;
2359
2360         present = snd_hda_codec_read(codec, 0x18, 0,
2361                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2362         bits = present ? HDA_AMP_MUTE : 0;
2363         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2364 }
2365
2366 static void alc880_uniwill_automute(struct hda_codec *codec)
2367 {
2368         alc880_uniwill_hp_automute(codec);
2369         alc880_uniwill_mic_automute(codec);
2370 }
2371
2372 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2373                                        unsigned int res)
2374 {
2375         /* Looks like the unsol event is incompatible with the standard
2376          * definition.  4bit tag is placed at 28 bit!
2377          */
2378         switch (res >> 28) {
2379         case ALC880_HP_EVENT:
2380                 alc880_uniwill_hp_automute(codec);
2381                 break;
2382         case ALC880_MIC_EVENT:
2383                 alc880_uniwill_mic_automute(codec);
2384                 break;
2385         }
2386 }
2387
2388 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2389 {
2390         unsigned int present;
2391         unsigned char bits;
2392
2393         present = snd_hda_codec_read(codec, 0x14, 0,
2394                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2395         bits = present ? HDA_AMP_MUTE : 0;
2396         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2397 }
2398
2399 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2400 {
2401         unsigned int present;
2402
2403         present = snd_hda_codec_read(codec, 0x21, 0,
2404                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2405         present &= HDA_AMP_VOLMASK;
2406         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2407                                  HDA_AMP_VOLMASK, present);
2408         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2409                                  HDA_AMP_VOLMASK, present);
2410 }
2411
2412 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2413                                            unsigned int res)
2414 {
2415         /* Looks like the unsol event is incompatible with the standard
2416          * definition.  4bit tag is placed at 28 bit!
2417          */
2418         if ((res >> 28) == ALC880_HP_EVENT)
2419                 alc880_uniwill_p53_hp_automute(codec);
2420         if ((res >> 28) == ALC880_DCVOL_EVENT)
2421                 alc880_uniwill_p53_dcvol_automute(codec);
2422 }
2423
2424 /*
2425  * F1734 pin configuration:
2426  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2427  */
2428 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2429         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2430         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2431         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2432         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2433         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2434
2435         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2436         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2437         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2438         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2439
2440         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2441         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2442         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2443         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2444         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2445         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2446         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2447         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2448         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2449
2450         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2451         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2452
2453         { }
2454 };
2455
2456 /*
2457  * ASUS pin configuration:
2458  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2459  */
2460 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2461         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2462         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2463         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2464         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2465
2466         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2467         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2468         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2469         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2470         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2471         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2472         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2473         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2474
2475         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2476         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2477         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2478         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2479         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2480         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2481         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2482         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2483         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2484
2485         { }
2486 };
2487
2488 /* Enable GPIO mask and set output */
2489 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2490 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2491
2492 /* Clevo m520g init */
2493 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2494         /* headphone output */
2495         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2496         /* line-out */
2497         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2498         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2499         /* Line-in */
2500         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2501         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2502         /* CD */
2503         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2504         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2505         /* Mic1 (rear panel) */
2506         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2507         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2508         /* Mic2 (front panel) */
2509         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2510         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2511         /* headphone */
2512         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2513         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2514         /* change to EAPD mode */
2515         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2516         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2517
2518         { }
2519 };
2520
2521 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2522         /* change to EAPD mode */
2523         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2524         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2525
2526         /* Headphone output */
2527         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2528         /* Front output*/
2529         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2530         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2531
2532         /* Line In pin widget for input */
2533         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2534         /* CD pin widget for input */
2535         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2536         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2537         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2538
2539         /* change to EAPD mode */
2540         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2541         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2542
2543         { }
2544 };
2545
2546 /*
2547  * LG m1 express dual
2548  *
2549  * Pin assignment:
2550  *   Rear Line-In/Out (blue): 0x14
2551  *   Build-in Mic-In: 0x15
2552  *   Speaker-out: 0x17
2553  *   HP-Out (green): 0x1b
2554  *   Mic-In/Out (red): 0x19
2555  *   SPDIF-Out: 0x1e
2556  */
2557
2558 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2559 static hda_nid_t alc880_lg_dac_nids[3] = {
2560         0x05, 0x02, 0x03
2561 };
2562
2563 /* seems analog CD is not working */
2564 static struct hda_input_mux alc880_lg_capture_source = {
2565         .num_items = 3,
2566         .items = {
2567                 { "Mic", 0x1 },
2568                 { "Line", 0x5 },
2569                 { "Internal Mic", 0x6 },
2570         },
2571 };
2572
2573 /* 2,4,6 channel modes */
2574 static struct hda_verb alc880_lg_ch2_init[] = {
2575         /* set line-in and mic-in to input */
2576         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2577         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2578         { }
2579 };
2580
2581 static struct hda_verb alc880_lg_ch4_init[] = {
2582         /* set line-in to out and mic-in to input */
2583         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2584         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2585         { }
2586 };
2587
2588 static struct hda_verb alc880_lg_ch6_init[] = {
2589         /* set line-in and mic-in to output */
2590         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2591         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2592         { }
2593 };
2594
2595 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2596         { 2, alc880_lg_ch2_init },
2597         { 4, alc880_lg_ch4_init },
2598         { 6, alc880_lg_ch6_init },
2599 };
2600
2601 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2602         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2603         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2604         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2605         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2606         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2607         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2608         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2609         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2610         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2611         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2612         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2613         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2614         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2615         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2616         {
2617                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2618                 .name = "Channel Mode",
2619                 .info = alc_ch_mode_info,
2620                 .get = alc_ch_mode_get,
2621                 .put = alc_ch_mode_put,
2622         },
2623         { } /* end */
2624 };
2625
2626 static struct hda_verb alc880_lg_init_verbs[] = {
2627         /* set capture source to mic-in */
2628         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2629         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2630         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2631         /* mute all amp mixer inputs */
2632         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2633         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2634         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2635         /* line-in to input */
2636         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2637         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2638         /* built-in mic */
2639         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2640         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2641         /* speaker-out */
2642         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2643         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2644         /* mic-in to input */
2645         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2646         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2647         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2648         /* HP-out */
2649         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2650         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2651         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2652         /* jack sense */
2653         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2654         { }
2655 };
2656
2657 /* toggle speaker-output according to the hp-jack state */
2658 static void alc880_lg_automute(struct hda_codec *codec)
2659 {
2660         unsigned int present;
2661         unsigned char bits;
2662
2663         present = snd_hda_codec_read(codec, 0x1b, 0,
2664                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2665         bits = present ? HDA_AMP_MUTE : 0;
2666         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2667                                  HDA_AMP_MUTE, bits);
2668 }
2669
2670 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2671 {
2672         /* Looks like the unsol event is incompatible with the standard
2673          * definition.  4bit tag is placed at 28 bit!
2674          */
2675         if ((res >> 28) == 0x01)
2676                 alc880_lg_automute(codec);
2677 }
2678
2679 /*
2680  * LG LW20
2681  *
2682  * Pin assignment:
2683  *   Speaker-out: 0x14
2684  *   Mic-In: 0x18
2685  *   Built-in Mic-In: 0x19
2686  *   Line-In: 0x1b
2687  *   HP-Out: 0x1a
2688  *   SPDIF-Out: 0x1e
2689  */
2690
2691 static struct hda_input_mux alc880_lg_lw_capture_source = {
2692         .num_items = 3,
2693         .items = {
2694                 { "Mic", 0x0 },
2695                 { "Internal Mic", 0x1 },
2696                 { "Line In", 0x2 },
2697         },
2698 };
2699
2700 #define alc880_lg_lw_modes alc880_threestack_modes
2701
2702 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2703         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2704         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2705         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2706         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2707         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2708         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2709         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2710         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2711         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2712         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2713         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2714         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2715         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2716         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2717         {
2718                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2719                 .name = "Channel Mode",
2720                 .info = alc_ch_mode_info,
2721                 .get = alc_ch_mode_get,
2722                 .put = alc_ch_mode_put,
2723         },
2724         { } /* end */
2725 };
2726
2727 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2728         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2729         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2730         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2731
2732         /* set capture source to mic-in */
2733         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2734         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2735         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2736         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2737         /* speaker-out */
2738         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2739         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2740         /* HP-out */
2741         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2742         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2743         /* mic-in to input */
2744         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2745         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2746         /* built-in mic */
2747         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2748         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2749         /* jack sense */
2750         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2751         { }
2752 };
2753
2754 /* toggle speaker-output according to the hp-jack state */
2755 static void alc880_lg_lw_automute(struct hda_codec *codec)
2756 {
2757         unsigned int present;
2758         unsigned char bits;
2759
2760         present = snd_hda_codec_read(codec, 0x1b, 0,
2761                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2762         bits = present ? HDA_AMP_MUTE : 0;
2763         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2764                                  HDA_AMP_MUTE, bits);
2765 }
2766
2767 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2768 {
2769         /* Looks like the unsol event is incompatible with the standard
2770          * definition.  4bit tag is placed at 28 bit!
2771          */
2772         if ((res >> 28) == 0x01)
2773                 alc880_lg_lw_automute(codec);
2774 }
2775
2776 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2777         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2778         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2779         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2780         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2781         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2782         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2783         { } /* end */
2784 };
2785
2786 static struct hda_input_mux alc880_medion_rim_capture_source = {
2787         .num_items = 2,
2788         .items = {
2789                 { "Mic", 0x0 },
2790                 { "Internal Mic", 0x1 },
2791         },
2792 };
2793
2794 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2795         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2796
2797         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2798         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2799
2800         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2801         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2802         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2803         /* Mic2 (as headphone out) for HP output */
2804         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2805         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2806         /* Internal Speaker */
2807         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2808         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2809
2810         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2811         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2812
2813         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2814         { }
2815 };
2816
2817 /* toggle speaker-output according to the hp-jack state */
2818 static void alc880_medion_rim_automute(struct hda_codec *codec)
2819 {
2820         unsigned int present;
2821         unsigned char bits;
2822
2823         present = snd_hda_codec_read(codec, 0x14, 0,
2824                                      AC_VERB_GET_PIN_SENSE, 0)
2825                 & AC_PINSENSE_PRESENCE;
2826         bits = present ? HDA_AMP_MUTE : 0;
2827         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2828                                  HDA_AMP_MUTE, bits);
2829         if (present)
2830                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2831         else
2832                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2833 }
2834
2835 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2836                                           unsigned int res)
2837 {
2838         /* Looks like the unsol event is incompatible with the standard
2839          * definition.  4bit tag is placed at 28 bit!
2840          */
2841         if ((res >> 28) == ALC880_HP_EVENT)
2842                 alc880_medion_rim_automute(codec);
2843 }
2844
2845 #ifdef CONFIG_SND_HDA_POWER_SAVE
2846 static struct hda_amp_list alc880_loopbacks[] = {
2847         { 0x0b, HDA_INPUT, 0 },
2848         { 0x0b, HDA_INPUT, 1 },
2849         { 0x0b, HDA_INPUT, 2 },
2850         { 0x0b, HDA_INPUT, 3 },
2851         { 0x0b, HDA_INPUT, 4 },
2852         { } /* end */
2853 };
2854
2855 static struct hda_amp_list alc880_lg_loopbacks[] = {
2856         { 0x0b, HDA_INPUT, 1 },
2857         { 0x0b, HDA_INPUT, 6 },
2858         { 0x0b, HDA_INPUT, 7 },
2859         { } /* end */
2860 };
2861 #endif
2862
2863 /*
2864  * Common callbacks
2865  */
2866
2867 static int alc_init(struct hda_codec *codec)
2868 {
2869         struct alc_spec *spec = codec->spec;
2870         unsigned int i;
2871
2872         alc_fix_pll(codec);
2873         if (codec->vendor_id == 0x10ec0888)
2874                 alc888_coef_init(codec);
2875
2876         for (i = 0; i < spec->num_init_verbs; i++)
2877                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2878
2879         if (spec->init_hook)
2880                 spec->init_hook(codec);
2881
2882         return 0;
2883 }
2884
2885 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2886 {
2887         struct alc_spec *spec = codec->spec;
2888
2889         if (spec->unsol_event)
2890                 spec->unsol_event(codec, res);
2891 }
2892
2893 #ifdef CONFIG_SND_HDA_POWER_SAVE
2894 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2895 {
2896         struct alc_spec *spec = codec->spec;
2897         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2898 }
2899 #endif
2900
2901 /*
2902  * Analog playback callbacks
2903  */
2904 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2905                                     struct hda_codec *codec,
2906                                     struct snd_pcm_substream *substream)
2907 {
2908         struct alc_spec *spec = codec->spec;
2909         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2910                                              hinfo);
2911 }
2912
2913 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2914                                        struct hda_codec *codec,
2915                                        unsigned int stream_tag,
2916                                        unsigned int format,
2917                                        struct snd_pcm_substream *substream)
2918 {
2919         struct alc_spec *spec = codec->spec;
2920         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2921                                                 stream_tag, format, substream);
2922 }
2923
2924 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2925                                        struct hda_codec *codec,
2926                                        struct snd_pcm_substream *substream)
2927 {
2928         struct alc_spec *spec = codec->spec;
2929         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2930 }
2931
2932 /*
2933  * Digital out
2934  */
2935 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2936                                         struct hda_codec *codec,
2937                                         struct snd_pcm_substream *substream)
2938 {
2939         struct alc_spec *spec = codec->spec;
2940         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2941 }
2942
2943 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2944                                            struct hda_codec *codec,
2945                                            unsigned int stream_tag,
2946                                            unsigned int format,
2947                                            struct snd_pcm_substream *substream)
2948 {
2949         struct alc_spec *spec = codec->spec;
2950         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2951                                              stream_tag, format, substream);
2952 }
2953
2954 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2955                                          struct hda_codec *codec,
2956                                          struct snd_pcm_substream *substream)
2957 {
2958         struct alc_spec *spec = codec->spec;
2959         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2960 }
2961
2962 /*
2963  * Analog capture
2964  */
2965 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2966                                       struct hda_codec *codec,
2967                                       unsigned int stream_tag,
2968                                       unsigned int format,
2969                                       struct snd_pcm_substream *substream)
2970 {
2971         struct alc_spec *spec = codec->spec;
2972
2973         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2974                                    stream_tag, 0, format);
2975         return 0;
2976 }
2977
2978 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2979                                       struct hda_codec *codec,
2980                                       struct snd_pcm_substream *substream)
2981 {
2982         struct alc_spec *spec = codec->spec;
2983
2984         snd_hda_codec_cleanup_stream(codec,
2985                                      spec->adc_nids[substream->number + 1]);
2986         return 0;
2987 }
2988
2989
2990 /*
2991  */
2992 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2993         .substreams = 1,
2994         .channels_min = 2,
2995         .channels_max = 8,
2996         /* NID is set in alc_build_pcms */
2997         .ops = {
2998                 .open = alc880_playback_pcm_open,
2999                 .prepare = alc880_playback_pcm_prepare,
3000                 .cleanup = alc880_playback_pcm_cleanup
3001         },
3002 };
3003
3004 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3005         .substreams = 1,
3006         .channels_min = 2,
3007         .channels_max = 2,
3008         /* NID is set in alc_build_pcms */
3009 };
3010
3011 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3012         .substreams = 1,
3013         .channels_min = 2,
3014         .channels_max = 2,
3015         /* NID is set in alc_build_pcms */
3016 };
3017
3018 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3019         .substreams = 2, /* can be overridden */
3020         .channels_min = 2,
3021         .channels_max = 2,
3022         /* NID is set in alc_build_pcms */
3023         .ops = {
3024                 .prepare = alc880_alt_capture_pcm_prepare,
3025                 .cleanup = alc880_alt_capture_pcm_cleanup
3026         },
3027 };
3028
3029 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3030         .substreams = 1,
3031         .channels_min = 2,
3032         .channels_max = 2,
3033         /* NID is set in alc_build_pcms */
3034         .ops = {
3035                 .open = alc880_dig_playback_pcm_open,
3036                 .close = alc880_dig_playback_pcm_close,
3037                 .prepare = alc880_dig_playback_pcm_prepare
3038         },
3039 };
3040
3041 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3042         .substreams = 1,
3043         .channels_min = 2,
3044         .channels_max = 2,
3045         /* NID is set in alc_build_pcms */
3046 };
3047
3048 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3049 static struct hda_pcm_stream alc_pcm_null_stream = {
3050         .substreams = 0,
3051         .channels_min = 0,
3052         .channels_max = 0,
3053 };
3054
3055 static int alc_build_pcms(struct hda_codec *codec)
3056 {
3057         struct alc_spec *spec = codec->spec;
3058         struct hda_pcm *info = spec->pcm_rec;
3059         int i;
3060
3061         codec->num_pcms = 1;
3062         codec->pcm_info = info;
3063
3064         info->name = spec->stream_name_analog;
3065         if (spec->stream_analog_playback) {
3066                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3067                         return -EINVAL;
3068                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3069                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3070         }
3071         if (spec->stream_analog_capture) {
3072                 if (snd_BUG_ON(!spec->adc_nids))
3073                         return -EINVAL;
3074                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3075                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3076         }
3077
3078         if (spec->channel_mode) {
3079                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3080                 for (i = 0; i < spec->num_channel_mode; i++) {
3081                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3082                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3083                         }
3084                 }
3085         }
3086
3087         /* SPDIF for stream index #1 */
3088         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3089                 codec->num_pcms = 2;
3090                 info = spec->pcm_rec + 1;
3091                 info->name = spec->stream_name_digital;
3092                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
3093                 if (spec->multiout.dig_out_nid &&
3094                     spec->stream_digital_playback) {
3095                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3096                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3097                 }
3098                 if (spec->dig_in_nid &&
3099                     spec->stream_digital_capture) {
3100                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3101                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3102                 }
3103                 /* FIXME: do we need this for all Realtek codec models? */
3104                 codec->spdif_status_reset = 1;
3105         }
3106
3107         /* If the use of more than one ADC is requested for the current
3108          * model, configure a second analog capture-only PCM.
3109          */
3110         /* Additional Analaog capture for index #2 */
3111         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3112             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3113                 codec->num_pcms = 3;
3114                 info = spec->pcm_rec + 2;
3115                 info->name = spec->stream_name_analog;
3116                 if (spec->alt_dac_nid) {
3117                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3118                                 *spec->stream_analog_alt_playback;
3119                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3120                                 spec->alt_dac_nid;
3121                 } else {
3122                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3123                                 alc_pcm_null_stream;
3124                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3125                 }
3126                 if (spec->num_adc_nids > 1) {
3127                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3128                                 *spec->stream_analog_alt_capture;
3129                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3130                                 spec->adc_nids[1];
3131                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3132                                 spec->num_adc_nids - 1;
3133                 } else {
3134                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3135                                 alc_pcm_null_stream;
3136                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3137                 }
3138         }
3139
3140         return 0;
3141 }
3142
3143 static void alc_free_kctls(struct hda_codec *codec)
3144 {
3145         struct alc_spec *spec = codec->spec;
3146
3147         if (spec->kctls.list) {
3148                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3149                 int i;
3150                 for (i = 0; i < spec->kctls.used; i++)
3151                         kfree(kctl[i].name);
3152         }
3153         snd_array_free(&spec->kctls);
3154 }
3155
3156 static void alc_free(struct hda_codec *codec)
3157 {
3158         struct alc_spec *spec = codec->spec;
3159
3160         if (!spec)
3161                 return;
3162
3163         alc_free_kctls(codec);
3164         kfree(spec);
3165         codec->spec = NULL; /* to be sure */
3166 }
3167
3168 #ifdef SND_HDA_NEEDS_RESUME
3169 static void store_pin_configs(struct hda_codec *codec)
3170 {
3171         struct alc_spec *spec = codec->spec;
3172         hda_nid_t nid, end_nid;
3173
3174         end_nid = codec->start_nid + codec->num_nodes;
3175         for (nid = codec->start_nid; nid < end_nid; nid++) {
3176                 unsigned int wid_caps = get_wcaps(codec, nid);
3177                 unsigned int wid_type =
3178                         (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3179                 if (wid_type != AC_WID_PIN)
3180                         continue;
3181                 if (spec->num_pins >= ARRAY_SIZE(spec->pin_nids))
3182                         break;
3183                 spec->pin_nids[spec->num_pins] = nid;
3184                 spec->pin_cfgs[spec->num_pins] =
3185                         snd_hda_codec_read(codec, nid, 0,
3186                                            AC_VERB_GET_CONFIG_DEFAULT, 0);
3187                 spec->num_pins++;
3188         }
3189 }
3190
3191 static void resume_pin_configs(struct hda_codec *codec)
3192 {
3193         struct alc_spec *spec = codec->spec;
3194         int i;
3195
3196         for (i = 0; i < spec->num_pins; i++) {
3197                 hda_nid_t pin_nid = spec->pin_nids[i];
3198                 unsigned int pin_config = spec->pin_cfgs[i];
3199                 snd_hda_codec_write(codec, pin_nid, 0,
3200                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
3201                                     pin_config & 0x000000ff);
3202                 snd_hda_codec_write(codec, pin_nid, 0,
3203                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
3204                                     (pin_config & 0x0000ff00) >> 8);
3205                 snd_hda_codec_write(codec, pin_nid, 0,
3206                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
3207                                     (pin_config & 0x00ff0000) >> 16);
3208                 snd_hda_codec_write(codec, pin_nid, 0,
3209                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
3210                                     pin_config >> 24);
3211         }
3212 }
3213
3214 static int alc_resume(struct hda_codec *codec)
3215 {
3216         resume_pin_configs(codec);
3217         codec->patch_ops.init(codec);
3218         snd_hda_codec_resume_amp(codec);
3219         snd_hda_codec_resume_cache(codec);
3220         return 0;
3221 }
3222 #else
3223 #define store_pin_configs(codec)
3224 #endif
3225
3226 /*
3227  */
3228 static struct hda_codec_ops alc_patch_ops = {
3229         .build_controls = alc_build_controls,
3230         .build_pcms = alc_build_pcms,
3231         .init = alc_init,
3232         .free = alc_free,
3233         .unsol_event = alc_unsol_event,
3234 #ifdef SND_HDA_NEEDS_RESUME
3235         .resume = alc_resume,
3236 #endif
3237 #ifdef CONFIG_SND_HDA_POWER_SAVE
3238         .check_power_status = alc_check_power_status,
3239 #endif
3240 };
3241
3242
3243 /*
3244  * Test configuration for debugging
3245  *
3246  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3247  * enum controls.
3248  */
3249 #ifdef CONFIG_SND_DEBUG
3250 static hda_nid_t alc880_test_dac_nids[4] = {
3251         0x02, 0x03, 0x04, 0x05
3252 };
3253
3254 static struct hda_input_mux alc880_test_capture_source = {
3255         .num_items = 7,
3256         .items = {
3257                 { "In-1", 0x0 },
3258                 { "In-2", 0x1 },
3259                 { "In-3", 0x2 },
3260                 { "In-4", 0x3 },
3261                 { "CD", 0x4 },
3262                 { "Front", 0x5 },
3263                 { "Surround", 0x6 },
3264         },
3265 };
3266
3267 static struct hda_channel_mode alc880_test_modes[4] = {
3268         { 2, NULL },
3269         { 4, NULL },
3270         { 6, NULL },
3271         { 8, NULL },
3272 };
3273
3274 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3275                                  struct snd_ctl_elem_info *uinfo)
3276 {
3277         static char *texts[] = {
3278                 "N/A", "Line Out", "HP Out",
3279                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3280         };
3281         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3282         uinfo->count = 1;
3283         uinfo->value.enumerated.items = 8;
3284         if (uinfo->value.enumerated.item >= 8)
3285                 uinfo->value.enumerated.item = 7;
3286         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3287         return 0;
3288 }
3289
3290 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3291                                 struct snd_ctl_elem_value *ucontrol)
3292 {
3293         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3294         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3295         unsigned int pin_ctl, item = 0;
3296
3297         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3298                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3299         if (pin_ctl & AC_PINCTL_OUT_EN) {
3300                 if (pin_ctl & AC_PINCTL_HP_EN)
3301                         item = 2;
3302                 else
3303                         item = 1;
3304         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3305                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3306                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3307                 case AC_PINCTL_VREF_50:  item = 4; break;
3308                 case AC_PINCTL_VREF_GRD: item = 5; break;
3309                 case AC_PINCTL_VREF_80:  item = 6; break;
3310                 case AC_PINCTL_VREF_100: item = 7; break;
3311                 }
3312         }
3313         ucontrol->value.enumerated.item[0] = item;
3314         return 0;
3315 }
3316
3317 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3318                                 struct snd_ctl_elem_value *ucontrol)
3319 {
3320         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3321         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3322         static unsigned int ctls[] = {
3323                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3324                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3325                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3326                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3327                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3328                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3329         };
3330         unsigned int old_ctl, new_ctl;
3331
3332         old_ctl = snd_hda_codec_read(codec, nid, 0,
3333                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3334         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3335         if (old_ctl != new_ctl) {
3336                 int val;
3337                 snd_hda_codec_write_cache(codec, nid, 0,
3338                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3339                                           new_ctl);
3340                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3341                         HDA_AMP_MUTE : 0;
3342                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3343                                          HDA_AMP_MUTE, val);
3344                 return 1;
3345         }
3346         return 0;
3347 }
3348
3349 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3350                                  struct snd_ctl_elem_info *uinfo)
3351 {
3352         static char *texts[] = {
3353                 "Front", "Surround", "CLFE", "Side"
3354         };
3355         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3356         uinfo->count = 1;
3357         uinfo->value.enumerated.items = 4;
3358         if (uinfo->value.enumerated.item >= 4)
3359                 uinfo->value.enumerated.item = 3;
3360         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3361         return 0;
3362 }
3363
3364 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3365                                 struct snd_ctl_elem_value *ucontrol)
3366 {
3367         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3368         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3369         unsigned int sel;
3370
3371         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3372         ucontrol->value.enumerated.item[0] = sel & 3;
3373         return 0;
3374 }
3375
3376 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3377                                 struct snd_ctl_elem_value *ucontrol)
3378 {
3379         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3380         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3381         unsigned int sel;
3382
3383         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3384         if (ucontrol->value.enumerated.item[0] != sel) {
3385                 sel = ucontrol->value.enumerated.item[0] & 3;
3386                 snd_hda_codec_write_cache(codec, nid, 0,
3387                                           AC_VERB_SET_CONNECT_SEL, sel);
3388                 return 1;
3389         }
3390         return 0;
3391 }
3392
3393 #define PIN_CTL_TEST(xname,nid) {                       \
3394                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3395                         .name = xname,                 \
3396                         .info = alc_test_pin_ctl_info, \
3397                         .get = alc_test_pin_ctl_get,   \
3398                         .put = alc_test_pin_ctl_put,   \
3399                         .private_value = nid           \
3400                         }
3401
3402 #define PIN_SRC_TEST(xname,nid) {                       \
3403                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3404                         .name = xname,                 \
3405                         .info = alc_test_pin_src_info, \
3406                         .get = alc_test_pin_src_get,   \
3407                         .put = alc_test_pin_src_put,   \
3408                         .private_value = nid           \
3409                         }
3410
3411 static struct snd_kcontrol_new alc880_test_mixer[] = {
3412         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3413         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3414         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3415         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3416         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3417         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3418         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3419         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3420         PIN_CTL_TEST("Front Pin Mode", 0x14),
3421         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3422         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3423         PIN_CTL_TEST("Side Pin Mode", 0x17),
3424         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3425         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3426         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3427         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3428         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3429         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3430         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3431         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3432         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3433         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3434         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3435         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3436         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3437         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3438         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3439         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3440         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3441         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3442         {
3443                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3444                 .name = "Channel Mode",
3445                 .info = alc_ch_mode_info,
3446                 .get = alc_ch_mode_get,
3447                 .put = alc_ch_mode_put,
3448         },
3449         { } /* end */
3450 };
3451
3452 static struct hda_verb alc880_test_init_verbs[] = {
3453         /* Unmute inputs of 0x0c - 0x0f */
3454         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3455         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3456         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3457         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3458         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3459         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3460         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3461         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3462         /* Vol output for 0x0c-0x0f */
3463         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3464         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3465         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3466         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3467         /* Set output pins 0x14-0x17 */
3468         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3469         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3470         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3471         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3472         /* Unmute output pins 0x14-0x17 */
3473         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3474         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3475         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3476         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3477         /* Set input pins 0x18-0x1c */
3478         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3479         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3480         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3481         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3482         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3483         /* Mute input pins 0x18-0x1b */
3484         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3485         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3486         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3487         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3488         /* ADC set up */
3489         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3490         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3491         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3492         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3493         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3494         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3495         /* Analog input/passthru */
3496         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3497         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3498         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3499         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3500         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3501         { }
3502 };
3503 #endif
3504
3505 /*
3506  */
3507
3508 static const char *alc880_models[ALC880_MODEL_LAST] = {
3509         [ALC880_3ST]            = "3stack",
3510         [ALC880_TCL_S700]       = "tcl",
3511         [ALC880_3ST_DIG]        = "3stack-digout",
3512         [ALC880_CLEVO]          = "clevo",
3513         [ALC880_5ST]            = "5stack",
3514         [ALC880_5ST_DIG]        = "5stack-digout",
3515         [ALC880_W810]           = "w810",
3516         [ALC880_Z71V]           = "z71v",
3517         [ALC880_6ST]            = "6stack",
3518         [ALC880_6ST_DIG]        = "6stack-digout",
3519         [ALC880_ASUS]           = "asus",
3520         [ALC880_ASUS_W1V]       = "asus-w1v",
3521         [ALC880_ASUS_DIG]       = "asus-dig",
3522         [ALC880_ASUS_DIG2]      = "asus-dig2",
3523         [ALC880_UNIWILL_DIG]    = "uniwill",
3524         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3525         [ALC880_FUJITSU]        = "fujitsu",
3526         [ALC880_F1734]          = "F1734",
3527         [ALC880_LG]             = "lg",
3528         [ALC880_LG_LW]          = "lg-lw",
3529         [ALC880_MEDION_RIM]     = "medion",
3530 #ifdef CONFIG_SND_DEBUG
3531         [ALC880_TEST]           = "test",
3532 #endif
3533         [ALC880_AUTO]           = "auto",
3534 };
3535
3536 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3537         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3538         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3539         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3540         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3541         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3542         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3543         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3544         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3545         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3546         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3547         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3548         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3549         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3550         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3551         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3552         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3553         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3554         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3555         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3556         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3557         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3558         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3559         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3560         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3561         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3562         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3563         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3564         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3565         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3566         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3567         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3568         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3569         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3570         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3571         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3572         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3573         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3574         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3575         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3576         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3577         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3578         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3579         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3580         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3581         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3582         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3583         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3584         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3585         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3586         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3587         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3588         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3589         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3590         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3591         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3592         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3593         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3594         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3595         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3596         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3597         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3598         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3599         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3600         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3601         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3602         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3603         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3604         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3605         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3606         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3607         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3608         {}
3609 };
3610
3611 /*
3612  * ALC880 codec presets
3613  */
3614 static struct alc_config_preset alc880_presets[] = {
3615         [ALC880_3ST] = {
3616                 .mixers = { alc880_three_stack_mixer },
3617                 .init_verbs = { alc880_volume_init_verbs,
3618                                 alc880_pin_3stack_init_verbs },
3619                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3620                 .dac_nids = alc880_dac_nids,
3621                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3622                 .channel_mode = alc880_threestack_modes,
3623                 .need_dac_fix = 1,
3624                 .input_mux = &alc880_capture_source,
3625         },
3626         [ALC880_3ST_DIG] = {
3627                 .mixers = { alc880_three_stack_mixer },
3628                 .init_verbs = { alc880_volume_init_verbs,
3629                                 alc880_pin_3stack_init_verbs },
3630                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3631                 .dac_nids = alc880_dac_nids,
3632                 .dig_out_nid = ALC880_DIGOUT_NID,
3633                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3634                 .channel_mode = alc880_threestack_modes,
3635                 .need_dac_fix = 1,
3636                 .input_mux = &alc880_capture_source,
3637         },
3638         [ALC880_TCL_S700] = {
3639                 .mixers = { alc880_tcl_s700_mixer },
3640                 .init_verbs = { alc880_volume_init_verbs,
3641                                 alc880_pin_tcl_S700_init_verbs,
3642                                 alc880_gpio2_init_verbs },
3643                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3644                 .dac_nids = alc880_dac_nids,
3645                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3646                 .num_adc_nids = 1, /* single ADC */
3647                 .hp_nid = 0x03,
3648                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3649                 .channel_mode = alc880_2_jack_modes,
3650                 .input_mux = &alc880_capture_source,
3651         },
3652         [ALC880_5ST] = {
3653                 .mixers = { alc880_three_stack_mixer,
3654                             alc880_five_stack_mixer},
3655                 .init_verbs = { alc880_volume_init_verbs,
3656                                 alc880_pin_5stack_init_verbs },
3657                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3658                 .dac_nids = alc880_dac_nids,
3659                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3660                 .channel_mode = alc880_fivestack_modes,
3661                 .input_mux = &alc880_capture_source,
3662         },
3663         [ALC880_5ST_DIG] = {
3664                 .mixers = { alc880_three_stack_mixer,
3665                             alc880_five_stack_mixer },
3666                 .init_verbs = { alc880_volume_init_verbs,
3667                                 alc880_pin_5stack_init_verbs },
3668                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3669                 .dac_nids = alc880_dac_nids,
3670                 .dig_out_nid = ALC880_DIGOUT_NID,
3671                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3672                 .channel_mode = alc880_fivestack_modes,
3673                 .input_mux = &alc880_capture_source,
3674         },
3675         [ALC880_6ST] = {
3676                 .mixers = { alc880_six_stack_mixer },
3677                 .init_verbs = { alc880_volume_init_verbs,
3678                                 alc880_pin_6stack_init_verbs },
3679                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3680                 .dac_nids = alc880_6st_dac_nids,
3681                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3682                 .channel_mode = alc880_sixstack_modes,
3683                 .input_mux = &alc880_6stack_capture_source,
3684         },
3685         [ALC880_6ST_DIG] = {
3686                 .mixers = { alc880_six_stack_mixer },
3687                 .init_verbs = { alc880_volume_init_verbs,
3688                                 alc880_pin_6stack_init_verbs },
3689                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3690                 .dac_nids = alc880_6st_dac_nids,
3691                 .dig_out_nid = ALC880_DIGOUT_NID,
3692                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3693                 .channel_mode = alc880_sixstack_modes,
3694                 .input_mux = &alc880_6stack_capture_source,
3695         },
3696         [ALC880_W810] = {
3697                 .mixers = { alc880_w810_base_mixer },
3698                 .init_verbs = { alc880_volume_init_verbs,
3699                                 alc880_pin_w810_init_verbs,
3700                                 alc880_gpio2_init_verbs },
3701                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3702                 .dac_nids = alc880_w810_dac_nids,
3703                 .dig_out_nid = ALC880_DIGOUT_NID,
3704                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3705                 .channel_mode = alc880_w810_modes,
3706                 .input_mux = &alc880_capture_source,
3707         },
3708         [ALC880_Z71V] = {
3709                 .mixers = { alc880_z71v_mixer },
3710                 .init_verbs = { alc880_volume_init_verbs,
3711                                 alc880_pin_z71v_init_verbs },
3712                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3713                 .dac_nids = alc880_z71v_dac_nids,
3714                 .dig_out_nid = ALC880_DIGOUT_NID,
3715                 .hp_nid = 0x03,
3716                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3717                 .channel_mode = alc880_2_jack_modes,
3718                 .input_mux = &alc880_capture_source,
3719         },
3720         [ALC880_F1734] = {
3721                 .mixers = { alc880_f1734_mixer },
3722                 .init_verbs = { alc880_volume_init_verbs,
3723                                 alc880_pin_f1734_init_verbs },
3724                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3725                 .dac_nids = alc880_f1734_dac_nids,
3726                 .hp_nid = 0x02,
3727                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3728                 .channel_mode = alc880_2_jack_modes,
3729                 .input_mux = &alc880_f1734_capture_source,
3730                 .unsol_event = alc880_uniwill_p53_unsol_event,
3731                 .init_hook = alc880_uniwill_p53_hp_automute,
3732         },
3733         [ALC880_ASUS] = {
3734                 .mixers = { alc880_asus_mixer },
3735                 .init_verbs = { alc880_volume_init_verbs,
3736                                 alc880_pin_asus_init_verbs,
3737                                 alc880_gpio1_init_verbs },
3738                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3739                 .dac_nids = alc880_asus_dac_nids,
3740                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3741                 .channel_mode = alc880_asus_modes,
3742                 .need_dac_fix = 1,
3743                 .input_mux = &alc880_capture_source,
3744         },
3745         [ALC880_ASUS_DIG] = {
3746                 .mixers = { alc880_asus_mixer },
3747                 .init_verbs = { alc880_volume_init_verbs,
3748                                 alc880_pin_asus_init_verbs,
3749                                 alc880_gpio1_init_verbs },
3750                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3751                 .dac_nids = alc880_asus_dac_nids,
3752                 .dig_out_nid = ALC880_DIGOUT_NID,
3753                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3754                 .channel_mode = alc880_asus_modes,
3755                 .need_dac_fix = 1,
3756                 .input_mux = &alc880_capture_source,
3757         },
3758         [ALC880_ASUS_DIG2] = {
3759                 .mixers = { alc880_asus_mixer },
3760                 .init_verbs = { alc880_volume_init_verbs,
3761                                 alc880_pin_asus_init_verbs,
3762                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3763                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3764                 .dac_nids = alc880_asus_dac_nids,
3765                 .dig_out_nid = ALC880_DIGOUT_NID,
3766                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3767                 .channel_mode = alc880_asus_modes,
3768                 .need_dac_fix = 1,
3769                 .input_mux = &alc880_capture_source,
3770         },
3771         [ALC880_ASUS_W1V] = {
3772                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3773                 .init_verbs = { alc880_volume_init_verbs,
3774                                 alc880_pin_asus_init_verbs,
3775                                 alc880_gpio1_init_verbs },
3776                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3777                 .dac_nids = alc880_asus_dac_nids,
3778                 .dig_out_nid = ALC880_DIGOUT_NID,
3779                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3780                 .channel_mode = alc880_asus_modes,
3781                 .need_dac_fix = 1,
3782                 .input_mux = &alc880_capture_source,
3783         },
3784         [ALC880_UNIWILL_DIG] = {
3785                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3786                 .init_verbs = { alc880_volume_init_verbs,
3787                                 alc880_pin_asus_init_verbs },
3788                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3789                 .dac_nids = alc880_asus_dac_nids,
3790                 .dig_out_nid = ALC880_DIGOUT_NID,
3791                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3792                 .channel_mode = alc880_asus_modes,
3793                 .need_dac_fix = 1,
3794                 .input_mux = &alc880_capture_source,
3795         },
3796         [ALC880_UNIWILL] = {
3797                 .mixers = { alc880_uniwill_mixer },
3798                 .init_verbs = { alc880_volume_init_verbs,
3799                                 alc880_uniwill_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_threestack_modes),
3804                 .channel_mode = alc880_threestack_modes,
3805                 .need_dac_fix = 1,
3806                 .input_mux = &alc880_capture_source,
3807                 .unsol_event = alc880_uniwill_unsol_event,
3808                 .init_hook = alc880_uniwill_automute,
3809         },
3810         [ALC880_UNIWILL_P53] = {
3811                 .mixers = { alc880_uniwill_p53_mixer },
3812                 .init_verbs = { alc880_volume_init_verbs,
3813                                 alc880_uniwill_p53_init_verbs },
3814                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3815                 .dac_nids = alc880_asus_dac_nids,
3816                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3817                 .channel_mode = alc880_threestack_modes,
3818                 .input_mux = &alc880_capture_source,
3819                 .unsol_event = alc880_uniwill_p53_unsol_event,
3820                 .init_hook = alc880_uniwill_p53_hp_automute,
3821         },
3822         [ALC880_FUJITSU] = {
3823                 .mixers = { alc880_fujitsu_mixer,
3824                             alc880_pcbeep_mixer, },
3825                 .init_verbs = { alc880_volume_init_verbs,
3826                                 alc880_uniwill_p53_init_verbs,
3827                                 alc880_beep_init_verbs },
3828                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3829                 .dac_nids = alc880_dac_nids,
3830                 .dig_out_nid = ALC880_DIGOUT_NID,
3831                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3832                 .channel_mode = alc880_2_jack_modes,
3833                 .input_mux = &alc880_capture_source,
3834                 .unsol_event = alc880_uniwill_p53_unsol_event,
3835                 .init_hook = alc880_uniwill_p53_hp_automute,
3836         },
3837         [ALC880_CLEVO] = {
3838                 .mixers = { alc880_three_stack_mixer },
3839                 .init_verbs = { alc880_volume_init_verbs,
3840                                 alc880_pin_clevo_init_verbs },
3841                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3842                 .dac_nids = alc880_dac_nids,
3843                 .hp_nid = 0x03,
3844                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3845                 .channel_mode = alc880_threestack_modes,
3846                 .need_dac_fix = 1,
3847                 .input_mux = &alc880_capture_source,
3848         },
3849         [ALC880_LG] = {
3850                 .mixers = { alc880_lg_mixer },
3851                 .init_verbs = { alc880_volume_init_verbs,
3852                                 alc880_lg_init_verbs },
3853                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3854                 .dac_nids = alc880_lg_dac_nids,
3855                 .dig_out_nid = ALC880_DIGOUT_NID,
3856                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3857                 .channel_mode = alc880_lg_ch_modes,
3858                 .need_dac_fix = 1,
3859                 .input_mux = &alc880_lg_capture_source,
3860                 .unsol_event = alc880_lg_unsol_event,
3861                 .init_hook = alc880_lg_automute,
3862 #ifdef CONFIG_SND_HDA_POWER_SAVE
3863                 .loopbacks = alc880_lg_loopbacks,
3864 #endif
3865         },
3866         [ALC880_LG_LW] = {
3867                 .mixers = { alc880_lg_lw_mixer },
3868                 .init_verbs = { alc880_volume_init_verbs,
3869                                 alc880_lg_lw_init_verbs },
3870                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3871                 .dac_nids = alc880_dac_nids,
3872                 .dig_out_nid = ALC880_DIGOUT_NID,
3873                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3874                 .channel_mode = alc880_lg_lw_modes,
3875                 .input_mux = &alc880_lg_lw_capture_source,
3876                 .unsol_event = alc880_lg_lw_unsol_event,
3877                 .init_hook = alc880_lg_lw_automute,
3878         },
3879         [ALC880_MEDION_RIM] = {
3880                 .mixers = { alc880_medion_rim_mixer },
3881                 .init_verbs = { alc880_volume_init_verbs,
3882                                 alc880_medion_rim_init_verbs,
3883                                 alc_gpio2_init_verbs },
3884                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3885                 .dac_nids = alc880_dac_nids,
3886                 .dig_out_nid = ALC880_DIGOUT_NID,
3887                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3888                 .channel_mode = alc880_2_jack_modes,
3889                 .input_mux = &alc880_medion_rim_capture_source,
3890                 .unsol_event = alc880_medion_rim_unsol_event,
3891                 .init_hook = alc880_medion_rim_automute,
3892         },
3893 #ifdef CONFIG_SND_DEBUG
3894         [ALC880_TEST] = {
3895                 .mixers = { alc880_test_mixer },
3896                 .init_verbs = { alc880_test_init_verbs },
3897                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3898                 .dac_nids = alc880_test_dac_nids,
3899                 .dig_out_nid = ALC880_DIGOUT_NID,
3900                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3901                 .channel_mode = alc880_test_modes,
3902                 .input_mux = &alc880_test_capture_source,
3903         },
3904 #endif
3905 };
3906
3907 /*
3908  * Automatic parse of I/O pins from the BIOS configuration
3909  */
3910
3911 enum {
3912         ALC_CTL_WIDGET_VOL,
3913         ALC_CTL_WIDGET_MUTE,
3914         ALC_CTL_BIND_MUTE,
3915 };
3916 static struct snd_kcontrol_new alc880_control_templates[] = {
3917         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3918         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3919         HDA_BIND_MUTE(NULL, 0, 0, 0),
3920 };
3921
3922 /* add dynamic controls */
3923 static int add_control(struct alc_spec *spec, int type, const char *name,
3924                        unsigned long val)
3925 {
3926         struct snd_kcontrol_new *knew;
3927
3928         snd_array_init(&spec->kctls, sizeof(*knew), 32);
3929         knew = snd_array_new(&spec->kctls);
3930         if (!knew)
3931                 return -ENOMEM;
3932         *knew = alc880_control_templates[type];
3933         knew->name = kstrdup(name, GFP_KERNEL);
3934         if (!knew->name)
3935                 return -ENOMEM;
3936         knew->private_value = val;
3937         return 0;
3938 }
3939
3940 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3941 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3942 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3943 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3944 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3945 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3946 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3947 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3948 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3949 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3950 #define ALC880_PIN_CD_NID               0x1c
3951
3952 /* fill in the dac_nids table from the parsed pin configuration */
3953 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3954                                      const struct auto_pin_cfg *cfg)
3955 {
3956         hda_nid_t nid;
3957         int assigned[4];
3958         int i, j;
3959
3960         memset(assigned, 0, sizeof(assigned));
3961         spec->multiout.dac_nids = spec->private_dac_nids;
3962
3963         /* check the pins hardwired to audio widget */
3964         for (i = 0; i < cfg->line_outs; i++) {
3965                 nid = cfg->line_out_pins[i];
3966                 if (alc880_is_fixed_pin(nid)) {
3967                         int idx = alc880_fixed_pin_idx(nid);
3968                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3969                         assigned[idx] = 1;
3970                 }
3971         }
3972         /* left pins can be connect to any audio widget */
3973         for (i = 0; i < cfg->line_outs; i++) {
3974                 nid = cfg->line_out_pins[i];
3975                 if (alc880_is_fixed_pin(nid))
3976                         continue;
3977                 /* search for an empty channel */
3978                 for (j = 0; j < cfg->line_outs; j++) {
3979                         if (!assigned[j]) {
3980                                 spec->multiout.dac_nids[i] =
3981                                         alc880_idx_to_dac(j);
3982                                 assigned[j] = 1;
3983                                 break;
3984                         }
3985                 }
3986         }
3987         spec->multiout.num_dacs = cfg->line_outs;
3988         return 0;
3989 }
3990
3991 /* add playback controls from the parsed DAC table */
3992 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3993                                              const struct auto_pin_cfg *cfg)
3994 {
3995         char name[32];
3996         static const char *chname[4] = {
3997                 "Front", "Surround", NULL /*CLFE*/, "Side"
3998         };
3999         hda_nid_t nid;
4000         int i, err;
4001
4002         for (i = 0; i < cfg->line_outs; i++) {
4003                 if (!spec->multiout.dac_nids[i])
4004                         continue;
4005                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4006                 if (i == 2) {
4007                         /* Center/LFE */
4008                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4009                                           "Center Playback Volume",
4010                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4011                                                               HDA_OUTPUT));
4012                         if (err < 0)
4013                                 return err;
4014                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4015                                           "LFE Playback Volume",
4016                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4017                                                               HDA_OUTPUT));
4018                         if (err < 0)
4019                                 return err;
4020                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4021                                           "Center Playback Switch",
4022                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4023                                                               HDA_INPUT));
4024                         if (err < 0)
4025                                 return err;
4026                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4027                                           "LFE Playback Switch",
4028                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4029                                                               HDA_INPUT));
4030                         if (err < 0)
4031                                 return err;
4032                 } else {
4033                         sprintf(name, "%s Playback Volume", chname[i]);
4034                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4035                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4036                                                               HDA_OUTPUT));
4037                         if (err < 0)
4038                                 return err;
4039                         sprintf(name, "%s Playback Switch", chname[i]);
4040                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4041                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4042                                                               HDA_INPUT));
4043                         if (err < 0)
4044                                 return err;
4045                 }
4046         }
4047         return 0;
4048 }
4049
4050 /* add playback controls for speaker and HP outputs */
4051 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4052                                         const char *pfx)
4053 {
4054         hda_nid_t nid;
4055         int err;
4056         char name[32];
4057
4058         if (!pin)
4059                 return 0;
4060
4061         if (alc880_is_fixed_pin(pin)) {
4062                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4063                 /* specify the DAC as the extra output */
4064                 if (!spec->multiout.hp_nid)
4065                         spec->multiout.hp_nid = nid;
4066                 else
4067                         spec->multiout.extra_out_nid[0] = nid;
4068                 /* control HP volume/switch on the output mixer amp */
4069                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4070                 sprintf(name, "%s Playback Volume", pfx);
4071                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4072                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4073                 if (err < 0)
4074                         return err;
4075                 sprintf(name, "%s Playback Switch", pfx);
4076                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4077                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4078                 if (err < 0)
4079                         return err;
4080         } else if (alc880_is_multi_pin(pin)) {
4081                 /* set manual connection */
4082                 /* we have only a switch on HP-out PIN */
4083                 sprintf(name, "%s Playback Switch", pfx);
4084                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4085                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4086                 if (err < 0)
4087                         return err;
4088         }
4089         return 0;
4090 }
4091
4092 /* create input playback/capture controls for the given pin */
4093 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4094                             const char *ctlname,
4095                             int idx, hda_nid_t mix_nid)
4096 {
4097         char name[32];
4098         int err;
4099
4100         sprintf(name, "%s Playback Volume", ctlname);
4101         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4102                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4103         if (err < 0)
4104                 return err;
4105         sprintf(name, "%s Playback Switch", ctlname);
4106         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4107                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4108         if (err < 0)
4109                 return err;
4110         return 0;
4111 }
4112
4113 /* create playback/capture controls for input pins */
4114 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
4115                                                 const struct auto_pin_cfg *cfg)
4116 {
4117         struct hda_input_mux *imux = &spec->private_imux;
4118         int i, err, idx;
4119
4120         for (i = 0; i < AUTO_PIN_LAST; i++) {
4121                 if (alc880_is_input_pin(cfg->input_pins[i])) {
4122                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
4123                         err = new_analog_input(spec, cfg->input_pins[i],
4124                                                auto_pin_cfg_labels[i],
4125                                                idx, 0x0b);
4126                         if (err < 0)
4127                                 return err;
4128                         imux->items[imux->num_items].label =
4129                                 auto_pin_cfg_labels[i];
4130                         imux->items[imux->num_items].index =
4131                                 alc880_input_pin_idx(cfg->input_pins[i]);
4132                         imux->num_items++;
4133                 }
4134         }
4135         return 0;
4136 }
4137
4138 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4139                                unsigned int pin_type)
4140 {
4141         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4142                             pin_type);
4143         /* unmute pin */
4144         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4145                             AMP_OUT_UNMUTE);
4146 }
4147
4148 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4149                                               hda_nid_t nid, int pin_type,
4150                                               int dac_idx)
4151 {
4152         alc_set_pin_output(codec, nid, pin_type);
4153         /* need the manual connection? */
4154         if (alc880_is_multi_pin(nid)) {
4155                 struct alc_spec *spec = codec->spec;
4156                 int idx = alc880_multi_pin_idx(nid);
4157                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4158                                     AC_VERB_SET_CONNECT_SEL,
4159                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4160         }
4161 }
4162
4163 static int get_pin_type(int line_out_type)
4164 {
4165         if (line_out_type == AUTO_PIN_HP_OUT)
4166                 return PIN_HP;
4167         else
4168                 return PIN_OUT;
4169 }
4170
4171 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4172 {
4173         struct alc_spec *spec = codec->spec;
4174         int i;
4175
4176         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
4177         for (i = 0; i < spec->autocfg.line_outs; i++) {
4178                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4179                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4180                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4181         }
4182 }
4183
4184 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4185 {
4186         struct alc_spec *spec = codec->spec;
4187         hda_nid_t pin;
4188
4189         pin = spec->autocfg.speaker_pins[0];
4190         if (pin) /* connect to front */
4191                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4192         pin = spec->autocfg.hp_pins[0];
4193         if (pin) /* connect to front */
4194                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4195 }
4196
4197 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4198 {
4199         struct alc_spec *spec = codec->spec;
4200         int i;
4201
4202         for (i = 0; i < AUTO_PIN_LAST; i++) {
4203                 hda_nid_t nid = spec->autocfg.input_pins[i];
4204                 if (alc880_is_input_pin(nid)) {
4205                         snd_hda_codec_write(codec, nid, 0,
4206                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4207                                             i <= AUTO_PIN_FRONT_MIC ?
4208                                             PIN_VREF80 : PIN_IN);
4209                         if (nid != ALC880_PIN_CD_NID)
4210                                 snd_hda_codec_write(codec, nid, 0,
4211                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4212                                                     AMP_OUT_MUTE);
4213                 }
4214         }
4215 }
4216
4217 /* parse the BIOS configuration and set up the alc_spec */
4218 /* return 1 if successful, 0 if the proper config is not found,
4219  * or a negative error code
4220  */
4221 static int alc880_parse_auto_config(struct hda_codec *codec)
4222 {
4223         struct alc_spec *spec = codec->spec;
4224         int err;
4225         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4226
4227         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4228                                            alc880_ignore);
4229         if (err < 0)
4230                 return err;
4231         if (!spec->autocfg.line_outs)
4232                 return 0; /* can't find valid BIOS pin config */
4233
4234         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4235         if (err < 0)
4236                 return err;
4237         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4238         if (err < 0)
4239                 return err;
4240         err = alc880_auto_create_extra_out(spec,
4241                                            spec->autocfg.speaker_pins[0],
4242                                            "Speaker");
4243         if (err < 0)
4244                 return err;
4245         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4246                                            "Headphone");
4247         if (err < 0)
4248                 return err;
4249         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
4250         if (err < 0)
4251                 return err;
4252
4253         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4254
4255         if (spec->autocfg.dig_out_pin)
4256                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
4257         if (spec->autocfg.dig_in_pin)
4258                 spec->dig_in_nid = ALC880_DIGIN_NID;
4259
4260         if (spec->kctls.list)
4261                 add_mixer(spec, spec->kctls.list);
4262
4263         add_verb(spec, alc880_volume_init_verbs);
4264
4265         spec->num_mux_defs = 1;
4266         spec->input_mux = &spec->private_imux;
4267
4268         store_pin_configs(codec);
4269         return 1;
4270 }
4271
4272 /* additional initialization for auto-configuration model */
4273 static void alc880_auto_init(struct hda_codec *codec)
4274 {
4275         struct alc_spec *spec = codec->spec;
4276         alc880_auto_init_multi_out(codec);
4277         alc880_auto_init_extra_out(codec);
4278         alc880_auto_init_analog_input(codec);
4279         if (spec->unsol_event)
4280                 alc_inithook(codec);
4281 }
4282
4283 /*
4284  * OK, here we have finally the patch for ALC880
4285  */
4286
4287 static void set_capture_mixer(struct alc_spec *spec)
4288 {
4289         static struct snd_kcontrol_new *caps[3] = {
4290                 alc_capture_mixer1,
4291                 alc_capture_mixer2,
4292                 alc_capture_mixer3,
4293         };
4294         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3)
4295                 spec->cap_mixer = caps[spec->num_adc_nids - 1];
4296 }
4297
4298 static int patch_alc880(struct hda_codec *codec)
4299 {
4300         struct alc_spec *spec;
4301         int board_config;
4302         int err;
4303
4304         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4305         if (spec == NULL)
4306                 return -ENOMEM;
4307
4308         codec->spec = spec;
4309
4310         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4311                                                   alc880_models,
4312                                                   alc880_cfg_tbl);
4313         if (board_config < 0) {
4314                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
4315                        "trying auto-probe from BIOS...\n");
4316                 board_config = ALC880_AUTO;
4317         }
4318
4319         if (board_config == ALC880_AUTO) {
4320                 /* automatic parse from the BIOS config */
4321                 err = alc880_parse_auto_config(codec);
4322                 if (err < 0) {
4323                         alc_free(codec);
4324                         return err;
4325                 } else if (!err) {
4326                         printk(KERN_INFO
4327                                "hda_codec: Cannot set up configuration "
4328                                "from BIOS.  Using 3-stack mode...\n");
4329                         board_config = ALC880_3ST;
4330                 }
4331         }
4332
4333         if (board_config != ALC880_AUTO)
4334                 setup_preset(spec, &alc880_presets[board_config]);
4335
4336         spec->stream_name_analog = "ALC880 Analog";
4337         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4338         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4339         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4340
4341         spec->stream_name_digital = "ALC880 Digital";
4342         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4343         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4344
4345         if (!spec->adc_nids && spec->input_mux) {
4346                 /* check whether NID 0x07 is valid */
4347                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4348                 /* get type */
4349                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4350                 if (wcap != AC_WID_AUD_IN) {
4351                         spec->adc_nids = alc880_adc_nids_alt;
4352                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4353                 } else {
4354                         spec->adc_nids = alc880_adc_nids;
4355                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4356                 }
4357         }
4358         set_capture_mixer(spec);
4359
4360         spec->vmaster_nid = 0x0c;
4361
4362         codec->patch_ops = alc_patch_ops;
4363         if (board_config == ALC880_AUTO)
4364                 spec->init_hook = alc880_auto_init;
4365 #ifdef CONFIG_SND_HDA_POWER_SAVE
4366         if (!spec->loopback.amplist)
4367                 spec->loopback.amplist = alc880_loopbacks;
4368 #endif
4369         codec->proc_widget_hook = print_realtek_coef;
4370
4371         return 0;
4372 }
4373
4374
4375 /*
4376  * ALC260 support
4377  */
4378
4379 static hda_nid_t alc260_dac_nids[1] = {
4380         /* front */
4381         0x02,
4382 };
4383
4384 static hda_nid_t alc260_adc_nids[1] = {
4385         /* ADC0 */
4386         0x04,
4387 };
4388
4389 static hda_nid_t alc260_adc_nids_alt[1] = {
4390         /* ADC1 */
4391         0x05,
4392 };
4393
4394 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4395  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4396  */
4397 static hda_nid_t alc260_dual_adc_nids[2] = {
4398         /* ADC0, ADC1 */
4399         0x04, 0x05
4400 };
4401
4402 #define ALC260_DIGOUT_NID       0x03
4403 #define ALC260_DIGIN_NID        0x06
4404
4405 static struct hda_input_mux alc260_capture_source = {
4406         .num_items = 4,
4407         .items = {
4408                 { "Mic", 0x0 },
4409                 { "Front Mic", 0x1 },
4410                 { "Line", 0x2 },
4411                 { "CD", 0x4 },
4412         },
4413 };
4414
4415 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4416  * headphone jack and the internal CD lines since these are the only pins at
4417  * which audio can appear.  For flexibility, also allow the option of
4418  * recording the mixer output on the second ADC (ADC0 doesn't have a
4419  * connection to the mixer output).
4420  */
4421 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4422         {
4423                 .num_items = 3,
4424                 .items = {
4425                         { "Mic/Line", 0x0 },
4426                         { "CD", 0x4 },
4427                         { "Headphone", 0x2 },
4428                 },
4429         },
4430         {
4431                 .num_items = 4,
4432                 .items = {
4433                         { "Mic/Line", 0x0 },
4434                         { "CD", 0x4 },
4435                         { "Headphone", 0x2 },
4436                         { "Mixer", 0x5 },
4437                 },
4438         },
4439
4440 };
4441
4442 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4443  * the Fujitsu S702x, but jacks are marked differently.
4444  */
4445 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4446         {
4447                 .num_items = 4,
4448                 .items = {
4449                         { "Mic", 0x0 },
4450                         { "Line", 0x2 },
4451                         { "CD", 0x4 },
4452                         { "Headphone", 0x5 },
4453                 },
4454         },
4455         {
4456                 .num_items = 5,
4457                 .items = {
4458                         { "Mic", 0x0 },
4459                         { "Line", 0x2 },
4460                         { "CD", 0x4 },
4461                         { "Headphone", 0x6 },
4462                         { "Mixer", 0x5 },
4463                 },
4464         },
4465 };
4466 /*
4467  * This is just place-holder, so there's something for alc_build_pcms to look
4468  * at when it calculates the maximum number of channels. ALC260 has no mixer
4469  * element which allows changing the channel mode, so the verb list is
4470  * never used.
4471  */
4472 static struct hda_channel_mode alc260_modes[1] = {
4473         { 2, NULL },
4474 };
4475
4476
4477 /* Mixer combinations
4478  *
4479  * basic: base_output + input + pc_beep + capture
4480  * HP: base_output + input + capture_alt
4481  * HP_3013: hp_3013 + input + capture
4482  * fujitsu: fujitsu + capture
4483  * acer: acer + capture
4484  */
4485
4486 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4487         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4488         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4489         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4490         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4491         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4492         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4493         { } /* end */
4494 };
4495
4496 static struct snd_kcontrol_new alc260_input_mixer[] = {
4497         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4498         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4499         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4500         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4501         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4502         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4503         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4504         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4505         { } /* end */
4506 };
4507
4508 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4509         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4510         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4511         { } /* end */
4512 };
4513
4514 /* update HP, line and mono out pins according to the master switch */
4515 static void alc260_hp_master_update(struct hda_codec *codec,
4516                                     hda_nid_t hp, hda_nid_t line,
4517                                     hda_nid_t mono)
4518 {
4519         struct alc_spec *spec = codec->spec;
4520         unsigned int val = spec->master_sw ? PIN_HP : 0;
4521         /* change HP and line-out pins */
4522         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4523                             val);
4524         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4525                             val);
4526         /* mono (speaker) depending on the HP jack sense */
4527         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4528         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4529                             val);
4530 }
4531
4532 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4533                                    struct snd_ctl_elem_value *ucontrol)
4534 {
4535         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4536         struct alc_spec *spec = codec->spec;
4537         *ucontrol->value.integer.value = spec->master_sw;
4538         return 0;
4539 }
4540
4541 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4542                                    struct snd_ctl_elem_value *ucontrol)
4543 {
4544         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4545         struct alc_spec *spec = codec->spec;
4546         int val = !!*ucontrol->value.integer.value;
4547         hda_nid_t hp, line, mono;
4548
4549         if (val == spec->master_sw)
4550                 return 0;
4551         spec->master_sw = val;
4552         hp = (kcontrol->private_value >> 16) & 0xff;
4553         line = (kcontrol->private_value >> 8) & 0xff;
4554         mono = kcontrol->private_value & 0xff;
4555         alc260_hp_master_update(codec, hp, line, mono);
4556         return 1;
4557 }
4558
4559 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4560         {
4561                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4562                 .name = "Master Playback Switch",
4563                 .info = snd_ctl_boolean_mono_info,
4564                 .get = alc260_hp_master_sw_get,
4565                 .put = alc260_hp_master_sw_put,
4566                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4567         },
4568         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4569         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4570         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4571         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4572         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4573                               HDA_OUTPUT),
4574         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4575         { } /* end */
4576 };
4577
4578 static struct hda_verb alc260_hp_unsol_verbs[] = {
4579         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4580         {},
4581 };
4582
4583 static void alc260_hp_automute(struct hda_codec *codec)
4584 {
4585         struct alc_spec *spec = codec->spec;
4586         unsigned int present;
4587
4588         present = snd_hda_codec_read(codec, 0x10, 0,
4589                                      AC_VERB_GET_PIN_SENSE, 0);
4590         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4591         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4592 }
4593
4594 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4595 {
4596         if ((res >> 26) == ALC880_HP_EVENT)
4597                 alc260_hp_automute(codec);
4598 }
4599
4600 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4601         {
4602                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4603                 .name = "Master Playback Switch",
4604                 .info = snd_ctl_boolean_mono_info,
4605                 .get = alc260_hp_master_sw_get,
4606                 .put = alc260_hp_master_sw_put,
4607                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4608         },
4609         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4610         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4611         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4612         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4613         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4614         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4615         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4616         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4617         { } /* end */
4618 };
4619
4620 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4621         .ops = &snd_hda_bind_vol,
4622         .values = {
4623                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4624                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4625                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4626                 0
4627         },
4628 };
4629
4630 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4631         .ops = &snd_hda_bind_sw,
4632         .values = {
4633                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4634                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4635                 0
4636         },
4637 };
4638
4639 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4640         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4641         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4642         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4643         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4644         { } /* end */
4645 };
4646
4647 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4648         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4649         {},
4650 };
4651
4652 static void alc260_hp_3013_automute(struct hda_codec *codec)
4653 {
4654         struct alc_spec *spec = codec->spec;
4655         unsigned int present;
4656
4657         present = snd_hda_codec_read(codec, 0x15, 0,
4658                                      AC_VERB_GET_PIN_SENSE, 0);
4659         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4660         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4661 }
4662
4663 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4664                                        unsigned int res)
4665 {
4666         if ((res >> 26) == ALC880_HP_EVENT)
4667                 alc260_hp_3013_automute(codec);
4668 }
4669
4670 static void alc260_hp_3012_automute(struct hda_codec *codec)
4671 {
4672         unsigned int present, bits;
4673
4674         present = snd_hda_codec_read(codec, 0x10, 0,
4675                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4676
4677         bits = present ? 0 : PIN_OUT;
4678         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4679                             bits);
4680         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4681                             bits);
4682         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4683                             bits);
4684 }
4685
4686 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4687                                        unsigned int res)
4688 {
4689         if ((res >> 26) == ALC880_HP_EVENT)
4690                 alc260_hp_3012_automute(codec);
4691 }
4692
4693 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4694  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4695  */
4696 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4697         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4698         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4699         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4700         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4701         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4702         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4703         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4704         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4705         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4706         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4707         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4708         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4709         { } /* end */
4710 };
4711
4712 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4713  * versions of the ALC260 don't act on requests to enable mic bias from NID
4714  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4715  * datasheet doesn't mention this restriction.  At this stage it's not clear
4716  * whether this behaviour is intentional or is a hardware bug in chip
4717  * revisions available in early 2006.  Therefore for now allow the
4718  * "Headphone Jack Mode" control to span all choices, but if it turns out
4719  * that the lack of mic bias for this NID is intentional we could change the
4720  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4721  *
4722  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4723  * don't appear to make the mic bias available from the "line" jack, even
4724  * though the NID used for this jack (0x14) can supply it.  The theory is
4725  * that perhaps Acer have included blocking capacitors between the ALC260
4726  * and the output jack.  If this turns out to be the case for all such
4727  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4728  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4729  *
4730  * The C20x Tablet series have a mono internal speaker which is controlled
4731  * via the chip's Mono sum widget and pin complex, so include the necessary
4732  * controls for such models.  On models without a "mono speaker" the control
4733  * won't do anything.
4734  */
4735 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4736         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4737         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4738         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4739         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4740                               HDA_OUTPUT),
4741         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4742                            HDA_INPUT),
4743         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4744         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4745         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4746         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4747         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4748         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4749         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4750         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4751         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4752         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4753         { } /* end */
4754 };
4755
4756 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4757  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4758  */
4759 static struct snd_kcontrol_new alc260_will_mixer[] = {
4760         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4761         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4762         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4763         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4764         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4765         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4766         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4767         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4768         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4769         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4770         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4771         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4772         { } /* end */
4773 };
4774
4775 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4776  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4777  */
4778 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4779         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4780         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4781         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4782         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4783         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4784         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4785         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4786         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4787         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4788         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4789         { } /* end */
4790 };
4791
4792 /*
4793  * initialization verbs
4794  */
4795 static struct hda_verb alc260_init_verbs[] = {
4796         /* Line In pin widget for input */
4797         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4798         /* CD pin widget for input */
4799         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4800         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4801         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4802         /* Mic2 (front panel) pin widget for input and vref at 80% */
4803         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4804         /* LINE-2 is used for line-out in rear */
4805         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4806         /* select line-out */
4807         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4808         /* LINE-OUT pin */
4809         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4810         /* enable HP */
4811         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4812         /* enable Mono */
4813         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4814         /* mute capture amp left and right */
4815         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4816         /* set connection select to line in (default select for this ADC) */
4817         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4818         /* mute capture amp left and right */
4819         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4820         /* set connection select to line in (default select for this ADC) */
4821         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4822         /* set vol=0 Line-Out mixer amp left and right */
4823         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4824         /* unmute pin widget amp left and right (no gain on this amp) */
4825         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4826         /* set vol=0 HP mixer amp left and right */
4827         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4828         /* unmute pin widget amp left and right (no gain on this amp) */
4829         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4830         /* set vol=0 Mono mixer amp left and right */
4831         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4832         /* unmute pin widget amp left and right (no gain on this amp) */
4833         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4834         /* unmute LINE-2 out pin */
4835         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4836         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4837          * Line In 2 = 0x03
4838          */
4839         /* mute analog inputs */
4840         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4841         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4842         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4843         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4844         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4845         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4846         /* mute Front out path */
4847         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4848         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4849         /* mute Headphone out path */
4850         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4851         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4852         /* mute Mono out path */
4853         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4854         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4855         { }
4856 };
4857
4858 #if 0 /* should be identical with alc260_init_verbs? */
4859 static struct hda_verb alc260_hp_init_verbs[] = {
4860         /* Headphone and output */
4861         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4862         /* mono output */
4863         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4864         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4865         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4866         /* Mic2 (front panel) pin widget for input and vref at 80% */
4867         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4868         /* Line In pin widget for input */
4869         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4870         /* Line-2 pin widget for output */
4871         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4872         /* CD pin widget for input */
4873         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4874         /* unmute amp left and right */
4875         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4876         /* set connection select to line in (default select for this ADC) */
4877         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4878         /* unmute Line-Out mixer amp left and right (volume = 0) */
4879         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4880         /* mute pin widget amp left and right (no gain on this amp) */
4881         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4882         /* unmute HP mixer amp left and right (volume = 0) */
4883         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4884         /* mute pin widget amp left and right (no gain on this amp) */
4885         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4886         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4887          * Line In 2 = 0x03
4888          */
4889         /* mute analog inputs */
4890         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4891         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4892         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4893         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4894         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4895         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4896         /* Unmute Front out path */
4897         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4898         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4899         /* Unmute Headphone out path */
4900         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4901         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4902         /* Unmute Mono out path */
4903         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4904         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4905         { }
4906 };
4907 #endif
4908
4909 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4910         /* Line out and output */
4911         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4912         /* mono output */
4913         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4914         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4915         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4916         /* Mic2 (front panel) pin widget for input and vref at 80% */
4917         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4918         /* Line In pin widget for input */
4919         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4920         /* Headphone pin widget for output */
4921         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4922         /* CD pin widget for input */
4923         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4924         /* unmute amp left and right */
4925         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4926         /* set connection select to line in (default select for this ADC) */
4927         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4928         /* unmute Line-Out mixer amp left and right (volume = 0) */
4929         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4930         /* mute pin widget amp left and right (no gain on this amp) */
4931         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4932         /* unmute HP mixer amp left and right (volume = 0) */
4933         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4934         /* mute pin widget amp left and right (no gain on this amp) */
4935         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4936         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4937          * Line In 2 = 0x03
4938          */
4939         /* mute analog inputs */
4940         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4941         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4942         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4943         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4944         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4945         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4946         /* Unmute Front out path */
4947         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4948         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4949         /* Unmute Headphone out path */
4950         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4951         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4952         /* Unmute Mono out path */
4953         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4954         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4955         { }
4956 };
4957
4958 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4959  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4960  * audio = 0x16, internal speaker = 0x10.
4961  */
4962 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4963         /* Disable all GPIOs */
4964         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4965         /* Internal speaker is connected to headphone pin */
4966         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4967         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4968         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4969         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4970         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4971         /* Ensure all other unused pins are disabled and muted. */
4972         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4973         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4974         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4975         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4976         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4977         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4978         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4979         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4980
4981         /* Disable digital (SPDIF) pins */
4982         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4983         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4984
4985         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
4986          * when acting as an output.
4987          */
4988         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4989
4990         /* Start with output sum widgets muted and their output gains at min */
4991         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4992         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4993         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4994         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4995         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4996         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4997         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4998         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4999         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5000
5001         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5002         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5003         /* Unmute Line1 pin widget output buffer since it starts as an output.
5004          * If the pin mode is changed by the user the pin mode control will
5005          * take care of enabling the pin's input/output buffers as needed.
5006          * Therefore there's no need to enable the input buffer at this
5007          * stage.
5008          */
5009         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5010         /* Unmute input buffer of pin widget used for Line-in (no equiv
5011          * mixer ctrl)
5012          */
5013         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5014
5015         /* Mute capture amp left and right */
5016         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5017         /* Set ADC connection select to match default mixer setting - line
5018          * in (on mic1 pin)
5019          */
5020         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5021
5022         /* Do the same for the second ADC: mute capture input amp and
5023          * set ADC connection to line in (on mic1 pin)
5024          */
5025         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5026         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5027
5028         /* Mute all inputs to mixer widget (even unconnected ones) */
5029         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5030         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5031         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5032         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5033         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5034         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5035         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5036         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5037
5038         { }
5039 };
5040
5041 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5042  * similar laptops (adapted from Fujitsu init verbs).
5043  */
5044 static struct hda_verb alc260_acer_init_verbs[] = {
5045         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5046          * the headphone jack.  Turn this on and rely on the standard mute
5047          * methods whenever the user wants to turn these outputs off.
5048          */
5049         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5050         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5051         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5052         /* Internal speaker/Headphone jack is connected to Line-out pin */
5053         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5054         /* Internal microphone/Mic jack is connected to Mic1 pin */
5055         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5056         /* Line In jack is connected to Line1 pin */
5057         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5058         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5059         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5060         /* Ensure all other unused pins are disabled and muted. */
5061         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5062         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5063         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5064         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5065         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5066         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5067         /* Disable digital (SPDIF) pins */
5068         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5069         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5070
5071         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5072          * bus when acting as outputs.
5073          */
5074         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5075         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5076
5077         /* Start with output sum widgets muted and their output gains at min */
5078         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5079         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5080         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5081         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5082         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5083         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5084         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5085         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5086         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5087
5088         /* Unmute Line-out pin widget amp left and right
5089          * (no equiv mixer ctrl)
5090          */
5091         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5092         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5093         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5094         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5095          * inputs. If the pin mode is changed by the user the pin mode control
5096          * will take care of enabling the pin's input/output buffers as needed.
5097          * Therefore there's no need to enable the input buffer at this
5098          * stage.
5099          */
5100         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5101         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5102
5103         /* Mute capture amp left and right */
5104         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5105         /* Set ADC connection select to match default mixer setting - mic
5106          * (on mic1 pin)
5107          */
5108         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5109
5110         /* Do similar with the second ADC: mute capture input amp and
5111          * set ADC connection to mic to match ALSA's default state.
5112          */
5113         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5114         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5115
5116         /* Mute all inputs to mixer widget (even unconnected ones) */
5117         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5118         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5119         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5120         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5121         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5122         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5123         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5124         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5125
5126         { }
5127 };
5128
5129 static struct hda_verb alc260_will_verbs[] = {
5130         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5131         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5132         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5133         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5134         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5135         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5136         {}
5137 };
5138
5139 static struct hda_verb alc260_replacer_672v_verbs[] = {
5140         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5141         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5142         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5143
5144         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5145         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5146         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5147
5148         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5149         {}
5150 };
5151
5152 /* toggle speaker-output according to the hp-jack state */
5153 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5154 {
5155         unsigned int present;
5156
5157         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5158         present = snd_hda_codec_read(codec, 0x0f, 0,
5159                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5160         if (present) {
5161                 snd_hda_codec_write_cache(codec, 0x01, 0,
5162                                           AC_VERB_SET_GPIO_DATA, 1);
5163                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5164                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5165                                           PIN_HP);
5166         } else {
5167                 snd_hda_codec_write_cache(codec, 0x01, 0,
5168                                           AC_VERB_SET_GPIO_DATA, 0);
5169                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5170                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5171                                           PIN_OUT);
5172         }
5173 }
5174
5175 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5176                                        unsigned int res)
5177 {
5178         if ((res >> 26) == ALC880_HP_EVENT)
5179                 alc260_replacer_672v_automute(codec);
5180 }
5181
5182 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5183         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5184         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5185         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5186         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5187         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5188         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5189         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5190         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5191         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5192         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5193         {}
5194 };
5195
5196 /* Test configuration for debugging, modelled after the ALC880 test
5197  * configuration.
5198  */
5199 #ifdef CONFIG_SND_DEBUG
5200 static hda_nid_t alc260_test_dac_nids[1] = {
5201         0x02,
5202 };
5203 static hda_nid_t alc260_test_adc_nids[2] = {
5204         0x04, 0x05,
5205 };
5206 /* For testing the ALC260, each input MUX needs its own definition since
5207  * the signal assignments are different.  This assumes that the first ADC
5208  * is NID 0x04.
5209  */
5210 static struct hda_input_mux alc260_test_capture_sources[2] = {
5211         {
5212                 .num_items = 7,
5213                 .items = {
5214                         { "MIC1 pin", 0x0 },
5215                         { "MIC2 pin", 0x1 },
5216                         { "LINE1 pin", 0x2 },
5217                         { "LINE2 pin", 0x3 },
5218                         { "CD pin", 0x4 },
5219                         { "LINE-OUT pin", 0x5 },
5220                         { "HP-OUT pin", 0x6 },
5221                 },
5222         },
5223         {
5224                 .num_items = 8,
5225                 .items = {
5226                         { "MIC1 pin", 0x0 },
5227                         { "MIC2 pin", 0x1 },
5228                         { "LINE1 pin", 0x2 },
5229                         { "LINE2 pin", 0x3 },
5230                         { "CD pin", 0x4 },
5231                         { "Mixer", 0x5 },
5232                         { "LINE-OUT pin", 0x6 },
5233                         { "HP-OUT pin", 0x7 },
5234                 },
5235         },
5236 };
5237 static struct snd_kcontrol_new alc260_test_mixer[] = {
5238         /* Output driver widgets */
5239         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5240         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5241         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5242         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5243         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5244         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5245
5246         /* Modes for retasking pin widgets
5247          * Note: the ALC260 doesn't seem to act on requests to enable mic
5248          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5249          * mention this restriction.  At this stage it's not clear whether
5250          * this behaviour is intentional or is a hardware bug in chip
5251          * revisions available at least up until early 2006.  Therefore for
5252          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5253          * choices, but if it turns out that the lack of mic bias for these
5254          * NIDs is intentional we could change their modes from
5255          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5256          */
5257         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5258         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5259         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5260         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5261         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5262         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5263
5264         /* Loopback mixer controls */
5265         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5266         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5267         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5268         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5269         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5270         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5271         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5272         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5273         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5274         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5275         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
5276         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
5277         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5278         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5279         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5280         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5281
5282         /* Controls for GPIO pins, assuming they are configured as outputs */
5283         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5284         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5285         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5286         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5287
5288         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5289          * is ambigious as to which NID is which; testing on laptops which
5290          * make this output available should provide clarification.
5291          */
5292         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5293         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5294
5295         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5296          * this output to turn on an external amplifier.
5297          */
5298         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5299         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5300
5301         { } /* end */
5302 };
5303 static struct hda_verb alc260_test_init_verbs[] = {
5304         /* Enable all GPIOs as outputs with an initial value of 0 */
5305         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5306         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5307         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5308
5309         /* Enable retasking pins as output, initially without power amp */
5310         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5311         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5312         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5313         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5314         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5315         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5316
5317         /* Disable digital (SPDIF) pins initially, but users can enable
5318          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5319          * payload also sets the generation to 0, output to be in "consumer"
5320          * PCM format, copyright asserted, no pre-emphasis and no validity
5321          * control.
5322          */
5323         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5324         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5325
5326         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5327          * OUT1 sum bus when acting as an output.
5328          */
5329         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5330         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5331         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5332         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5333
5334         /* Start with output sum widgets muted and their output gains at min */
5335         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5336         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5337         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5338         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5339         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5340         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5341         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5342         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5343         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5344
5345         /* Unmute retasking pin widget output buffers since the default
5346          * state appears to be output.  As the pin mode is changed by the
5347          * user the pin mode control will take care of enabling the pin's
5348          * input/output buffers as needed.
5349          */
5350         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5351         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5352         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5353         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5354         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5355         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5356         /* Also unmute the mono-out pin widget */
5357         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5358
5359         /* Mute capture amp left and right */
5360         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5361         /* Set ADC connection select to match default mixer setting (mic1
5362          * pin)
5363          */
5364         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5365
5366         /* Do the same for the second ADC: mute capture input amp and
5367          * set ADC connection to mic1 pin
5368          */
5369         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5370         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5371
5372         /* Mute all inputs to mixer widget (even unconnected ones) */
5373         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5374         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5375         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5376         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5377         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5378         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5379         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5380         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5381
5382         { }
5383 };
5384 #endif
5385
5386 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5387 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5388
5389 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5390 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5391
5392 /*
5393  * for BIOS auto-configuration
5394  */
5395
5396 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5397                                         const char *pfx, int *vol_bits)
5398 {
5399         hda_nid_t nid_vol;
5400         unsigned long vol_val, sw_val;
5401         char name[32];
5402         int err;
5403
5404         if (nid >= 0x0f && nid < 0x11) {
5405                 nid_vol = nid - 0x7;
5406                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5407                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5408         } else if (nid == 0x11) {
5409                 nid_vol = nid - 0x7;
5410                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5411                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5412         } else if (nid >= 0x12 && nid <= 0x15) {
5413                 nid_vol = 0x08;
5414                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5415                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5416         } else
5417                 return 0; /* N/A */
5418
5419         if (!(*vol_bits & (1 << nid_vol))) {
5420                 /* first control for the volume widget */
5421                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5422                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5423                 if (err < 0)
5424                         return err;
5425                 *vol_bits |= (1 << nid_vol);
5426         }
5427         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5428         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5429         if (err < 0)
5430                 return err;
5431         return 1;
5432 }
5433
5434 /* add playback controls from the parsed DAC table */
5435 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5436                                              const struct auto_pin_cfg *cfg)
5437 {
5438         hda_nid_t nid;
5439         int err;
5440         int vols = 0;
5441
5442         spec->multiout.num_dacs = 1;
5443         spec->multiout.dac_nids = spec->private_dac_nids;
5444         spec->multiout.dac_nids[0] = 0x02;
5445
5446         nid = cfg->line_out_pins[0];
5447         if (nid) {
5448                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5449                 if (err < 0)
5450                         return err;
5451         }
5452
5453         nid = cfg->speaker_pins[0];
5454         if (nid) {
5455                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5456                 if (err < 0)
5457                         return err;
5458         }
5459
5460         nid = cfg->hp_pins[0];
5461         if (nid) {
5462                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5463                                                    &vols);
5464                 if (err < 0)
5465                         return err;
5466         }
5467         return 0;
5468 }
5469
5470 /* create playback/capture controls for input pins */
5471 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5472                                                 const struct auto_pin_cfg *cfg)
5473 {
5474         struct hda_input_mux *imux = &spec->private_imux;
5475         int i, err, idx;
5476
5477         for (i = 0; i < AUTO_PIN_LAST; i++) {
5478                 if (cfg->input_pins[i] >= 0x12) {
5479                         idx = cfg->input_pins[i] - 0x12;
5480                         err = new_analog_input(spec, cfg->input_pins[i],
5481                                                auto_pin_cfg_labels[i], idx,
5482                                                0x07);
5483                         if (err < 0)
5484                                 return err;
5485                         imux->items[imux->num_items].label =
5486                                 auto_pin_cfg_labels[i];
5487                         imux->items[imux->num_items].index = idx;
5488                         imux->num_items++;
5489                 }
5490                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5491                         idx = cfg->input_pins[i] - 0x09;
5492                         err = new_analog_input(spec, cfg->input_pins[i],
5493                                                auto_pin_cfg_labels[i], idx,
5494                                                0x07);
5495                         if (err < 0)
5496                                 return err;
5497                         imux->items[imux->num_items].label =
5498                                 auto_pin_cfg_labels[i];
5499                         imux->items[imux->num_items].index = idx;
5500                         imux->num_items++;
5501                 }
5502         }
5503         return 0;
5504 }
5505
5506 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5507                                               hda_nid_t nid, int pin_type,
5508                                               int sel_idx)
5509 {
5510         alc_set_pin_output(codec, nid, pin_type);
5511         /* need the manual connection? */
5512         if (nid >= 0x12) {
5513                 int idx = nid - 0x12;
5514                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5515                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5516         }
5517 }
5518
5519 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5520 {
5521         struct alc_spec *spec = codec->spec;
5522         hda_nid_t nid;
5523
5524         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5525         nid = spec->autocfg.line_out_pins[0];
5526         if (nid) {
5527                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5528                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5529         }
5530
5531         nid = spec->autocfg.speaker_pins[0];
5532         if (nid)
5533                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5534
5535         nid = spec->autocfg.hp_pins[0];
5536         if (nid)
5537                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5538 }
5539
5540 #define ALC260_PIN_CD_NID               0x16
5541 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5542 {
5543         struct alc_spec *spec = codec->spec;
5544         int i;
5545
5546         for (i = 0; i < AUTO_PIN_LAST; i++) {
5547                 hda_nid_t nid = spec->autocfg.input_pins[i];
5548                 if (nid >= 0x12) {
5549                         snd_hda_codec_write(codec, nid, 0,
5550                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5551                                             i <= AUTO_PIN_FRONT_MIC ?
5552                                             PIN_VREF80 : PIN_IN);
5553                         if (nid != ALC260_PIN_CD_NID)
5554                                 snd_hda_codec_write(codec, nid, 0,
5555                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5556                                                     AMP_OUT_MUTE);
5557                 }
5558         }
5559 }
5560
5561 /*
5562  * generic initialization of ADC, input mixers and output mixers
5563  */
5564 static struct hda_verb alc260_volume_init_verbs[] = {
5565         /*
5566          * Unmute ADC0-1 and set the default input to mic-in
5567          */
5568         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5569         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5570         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5571         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5572
5573         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5574          * mixer widget
5575          * Note: PASD motherboards uses the Line In 2 as the input for
5576          * front panel mic (mic 2)
5577          */
5578         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5579         /* mute analog inputs */
5580         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5581         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5582         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5583         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5584         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5585
5586         /*
5587          * Set up output mixers (0x08 - 0x0a)
5588          */
5589         /* set vol=0 to output mixers */
5590         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5591         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5592         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5593         /* set up input amps for analog loopback */
5594         /* Amp Indices: DAC = 0, mixer = 1 */
5595         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5596         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5597         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5598         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5599         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5600         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5601
5602         { }
5603 };
5604
5605 static int alc260_parse_auto_config(struct hda_codec *codec)
5606 {
5607         struct alc_spec *spec = codec->spec;
5608         int err;
5609         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5610
5611         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5612                                            alc260_ignore);
5613         if (err < 0)
5614                 return err;
5615         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5616         if (err < 0)
5617                 return err;
5618         if (!spec->kctls.list)
5619                 return 0; /* can't find valid BIOS pin config */
5620         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5621         if (err < 0)
5622                 return err;
5623
5624         spec->multiout.max_channels = 2;
5625
5626         if (spec->autocfg.dig_out_pin)
5627                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5628         if (spec->kctls.list)
5629                 add_mixer(spec, spec->kctls.list);
5630
5631         add_verb(spec, alc260_volume_init_verbs);
5632
5633         spec->num_mux_defs = 1;
5634         spec->input_mux = &spec->private_imux;
5635
5636         store_pin_configs(codec);
5637         return 1;
5638 }
5639
5640 /* additional initialization for auto-configuration model */
5641 static void alc260_auto_init(struct hda_codec *codec)
5642 {
5643         struct alc_spec *spec = codec->spec;
5644         alc260_auto_init_multi_out(codec);
5645         alc260_auto_init_analog_input(codec);
5646         if (spec->unsol_event)
5647                 alc_inithook(codec);
5648 }
5649
5650 #ifdef CONFIG_SND_HDA_POWER_SAVE
5651 static struct hda_amp_list alc260_loopbacks[] = {
5652         { 0x07, HDA_INPUT, 0 },
5653         { 0x07, HDA_INPUT, 1 },
5654         { 0x07, HDA_INPUT, 2 },
5655         { 0x07, HDA_INPUT, 3 },
5656         { 0x07, HDA_INPUT, 4 },
5657         { } /* end */
5658 };
5659 #endif
5660
5661 /*
5662  * ALC260 configurations
5663  */
5664 static const char *alc260_models[ALC260_MODEL_LAST] = {
5665         [ALC260_BASIC]          = "basic",
5666         [ALC260_HP]             = "hp",
5667         [ALC260_HP_3013]        = "hp-3013",
5668         [ALC260_HP_DC7600]      = "hp-dc7600",
5669         [ALC260_FUJITSU_S702X]  = "fujitsu",
5670         [ALC260_ACER]           = "acer",
5671         [ALC260_WILL]           = "will",
5672         [ALC260_REPLACER_672V]  = "replacer",
5673 #ifdef CONFIG_SND_DEBUG
5674         [ALC260_TEST]           = "test",
5675 #endif
5676         [ALC260_AUTO]           = "auto",
5677 };
5678
5679 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5680         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5681         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5682         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5683         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5684         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5685         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5686         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5687         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5688         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5689         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5690         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5691         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5692         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5693         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5694         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5695         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5696         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5697         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5698         {}
5699 };
5700
5701 static struct alc_config_preset alc260_presets[] = {
5702         [ALC260_BASIC] = {
5703                 .mixers = { alc260_base_output_mixer,
5704                             alc260_input_mixer,
5705                             alc260_pc_beep_mixer },
5706                 .init_verbs = { alc260_init_verbs },
5707                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5708                 .dac_nids = alc260_dac_nids,
5709                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5710                 .adc_nids = alc260_adc_nids,
5711                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5712                 .channel_mode = alc260_modes,
5713                 .input_mux = &alc260_capture_source,
5714         },
5715         [ALC260_HP] = {
5716                 .mixers = { alc260_hp_output_mixer,
5717                             alc260_input_mixer },
5718                 .init_verbs = { alc260_init_verbs,
5719                                 alc260_hp_unsol_verbs },
5720                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5721                 .dac_nids = alc260_dac_nids,
5722                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5723                 .adc_nids = alc260_adc_nids_alt,
5724                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5725                 .channel_mode = alc260_modes,
5726                 .input_mux = &alc260_capture_source,
5727                 .unsol_event = alc260_hp_unsol_event,
5728                 .init_hook = alc260_hp_automute,
5729         },
5730         [ALC260_HP_DC7600] = {
5731                 .mixers = { alc260_hp_dc7600_mixer,
5732                             alc260_input_mixer },
5733                 .init_verbs = { alc260_init_verbs,
5734                                 alc260_hp_dc7600_verbs },
5735                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5736                 .dac_nids = alc260_dac_nids,
5737                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5738                 .adc_nids = alc260_adc_nids_alt,
5739                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5740                 .channel_mode = alc260_modes,
5741                 .input_mux = &alc260_capture_source,
5742                 .unsol_event = alc260_hp_3012_unsol_event,
5743                 .init_hook = alc260_hp_3012_automute,
5744         },
5745         [ALC260_HP_3013] = {
5746                 .mixers = { alc260_hp_3013_mixer,
5747                             alc260_input_mixer },
5748                 .init_verbs = { alc260_hp_3013_init_verbs,
5749                                 alc260_hp_3013_unsol_verbs },
5750                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5751                 .dac_nids = alc260_dac_nids,
5752                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5753                 .adc_nids = alc260_adc_nids_alt,
5754                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5755                 .channel_mode = alc260_modes,
5756                 .input_mux = &alc260_capture_source,
5757                 .unsol_event = alc260_hp_3013_unsol_event,
5758                 .init_hook = alc260_hp_3013_automute,
5759         },
5760         [ALC260_FUJITSU_S702X] = {
5761                 .mixers = { alc260_fujitsu_mixer },
5762                 .init_verbs = { alc260_fujitsu_init_verbs },
5763                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5764                 .dac_nids = alc260_dac_nids,
5765                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5766                 .adc_nids = alc260_dual_adc_nids,
5767                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5768                 .channel_mode = alc260_modes,
5769                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5770                 .input_mux = alc260_fujitsu_capture_sources,
5771         },
5772         [ALC260_ACER] = {
5773                 .mixers = { alc260_acer_mixer },
5774                 .init_verbs = { alc260_acer_init_verbs },
5775                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5776                 .dac_nids = alc260_dac_nids,
5777                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5778                 .adc_nids = alc260_dual_adc_nids,
5779                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5780                 .channel_mode = alc260_modes,
5781                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5782                 .input_mux = alc260_acer_capture_sources,
5783         },
5784         [ALC260_WILL] = {
5785                 .mixers = { alc260_will_mixer },
5786                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5787                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5788                 .dac_nids = alc260_dac_nids,
5789                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5790                 .adc_nids = alc260_adc_nids,
5791                 .dig_out_nid = ALC260_DIGOUT_NID,
5792                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5793                 .channel_mode = alc260_modes,
5794                 .input_mux = &alc260_capture_source,
5795         },
5796         [ALC260_REPLACER_672V] = {
5797                 .mixers = { alc260_replacer_672v_mixer },
5798                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5799                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5800                 .dac_nids = alc260_dac_nids,
5801                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5802                 .adc_nids = alc260_adc_nids,
5803                 .dig_out_nid = ALC260_DIGOUT_NID,
5804                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5805                 .channel_mode = alc260_modes,
5806                 .input_mux = &alc260_capture_source,
5807                 .unsol_event = alc260_replacer_672v_unsol_event,
5808                 .init_hook = alc260_replacer_672v_automute,
5809         },
5810 #ifdef CONFIG_SND_DEBUG
5811         [ALC260_TEST] = {
5812                 .mixers = { alc260_test_mixer },
5813                 .init_verbs = { alc260_test_init_verbs },
5814                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5815                 .dac_nids = alc260_test_dac_nids,
5816                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5817                 .adc_nids = alc260_test_adc_nids,
5818                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5819                 .channel_mode = alc260_modes,
5820                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5821                 .input_mux = alc260_test_capture_sources,
5822         },
5823 #endif
5824 };
5825
5826 static int patch_alc260(struct hda_codec *codec)
5827 {
5828         struct alc_spec *spec;
5829         int err, board_config;
5830
5831         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5832         if (spec == NULL)
5833                 return -ENOMEM;
5834
5835         codec->spec = spec;
5836
5837         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5838                                                   alc260_models,
5839                                                   alc260_cfg_tbl);
5840         if (board_config < 0) {
5841                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5842                            "trying auto-probe from BIOS...\n");
5843                 board_config = ALC260_AUTO;
5844         }
5845
5846         if (board_config == ALC260_AUTO) {
5847                 /* automatic parse from the BIOS config */
5848                 err = alc260_parse_auto_config(codec);
5849                 if (err < 0) {
5850                         alc_free(codec);
5851                         return err;
5852                 } else if (!err) {
5853                         printk(KERN_INFO
5854                                "hda_codec: Cannot set up configuration "
5855                                "from BIOS.  Using base mode...\n");
5856                         board_config = ALC260_BASIC;
5857                 }
5858         }
5859
5860         if (board_config != ALC260_AUTO)
5861                 setup_preset(spec, &alc260_presets[board_config]);
5862
5863         spec->stream_name_analog = "ALC260 Analog";
5864         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5865         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5866
5867         spec->stream_name_digital = "ALC260 Digital";
5868         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5869         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5870
5871         if (!spec->adc_nids && spec->input_mux) {
5872                 /* check whether NID 0x04 is valid */
5873                 unsigned int wcap = get_wcaps(codec, 0x04);
5874                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5875                 /* get type */
5876                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5877                         spec->adc_nids = alc260_adc_nids_alt;
5878                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5879                 } else {
5880                         spec->adc_nids = alc260_adc_nids;
5881                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5882                 }
5883         }
5884         set_capture_mixer(spec);
5885
5886         spec->vmaster_nid = 0x08;
5887
5888         codec->patch_ops = alc_patch_ops;
5889         if (board_config == ALC260_AUTO)
5890                 spec->init_hook = alc260_auto_init;
5891 #ifdef CONFIG_SND_HDA_POWER_SAVE
5892         if (!spec->loopback.amplist)
5893                 spec->loopback.amplist = alc260_loopbacks;
5894 #endif
5895         codec->proc_widget_hook = print_realtek_coef;
5896
5897         return 0;
5898 }
5899
5900
5901 /*
5902  * ALC882 support
5903  *
5904  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5905  * configuration.  Each pin widget can choose any input DACs and a mixer.
5906  * Each ADC is connected from a mixer of all inputs.  This makes possible
5907  * 6-channel independent captures.
5908  *
5909  * In addition, an independent DAC for the multi-playback (not used in this
5910  * driver yet).
5911  */
5912 #define ALC882_DIGOUT_NID       0x06
5913 #define ALC882_DIGIN_NID        0x0a
5914
5915 static struct hda_channel_mode alc882_ch_modes[1] = {
5916         { 8, NULL }
5917 };
5918
5919 static hda_nid_t alc882_dac_nids[4] = {
5920         /* front, rear, clfe, rear_surr */
5921         0x02, 0x03, 0x04, 0x05
5922 };
5923
5924 /* identical with ALC880 */
5925 #define alc882_adc_nids         alc880_adc_nids
5926 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5927
5928 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5929 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5930
5931 /* input MUX */
5932 /* FIXME: should be a matrix-type input source selection */
5933
5934 static struct hda_input_mux alc882_capture_source = {
5935         .num_items = 4,
5936         .items = {
5937                 { "Mic", 0x0 },
5938                 { "Front Mic", 0x1 },
5939                 { "Line", 0x2 },
5940                 { "CD", 0x4 },
5941         },
5942 };
5943 /*
5944  * 2ch mode
5945  */
5946 static struct hda_verb alc882_3ST_ch2_init[] = {
5947         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5948         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5949         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5950         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5951         { } /* end */
5952 };
5953
5954 /*
5955  * 6ch mode
5956  */
5957 static struct hda_verb alc882_3ST_ch6_init[] = {
5958         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5959         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5960         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5961         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5962         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5963         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5964         { } /* end */
5965 };
5966
5967 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5968         { 2, alc882_3ST_ch2_init },
5969         { 6, alc882_3ST_ch6_init },
5970 };
5971
5972 /*
5973  * 6ch mode
5974  */
5975 static struct hda_verb alc882_sixstack_ch6_init[] = {
5976         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5977         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5978         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5979         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5980         { } /* end */
5981 };
5982
5983 /*
5984  * 8ch mode
5985  */
5986 static struct hda_verb alc882_sixstack_ch8_init[] = {
5987         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5988         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5989         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5990         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5991         { } /* end */
5992 };
5993
5994 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5995         { 6, alc882_sixstack_ch6_init },
5996         { 8, alc882_sixstack_ch8_init },
5997 };
5998
5999 /*
6000  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
6001  */
6002
6003 /*
6004  * 2ch mode
6005  */
6006 static struct hda_verb alc885_mbp_ch2_init[] = {
6007         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6008         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6009         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6010         { } /* end */
6011 };
6012
6013 /*
6014  * 6ch mode
6015  */
6016 static struct hda_verb alc885_mbp_ch6_init[] = {
6017         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6018         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6019         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6020         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6021         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6022         { } /* end */
6023 };
6024
6025 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
6026         { 2, alc885_mbp_ch2_init },
6027         { 6, alc885_mbp_ch6_init },
6028 };
6029
6030
6031 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6032  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6033  */
6034 static struct snd_kcontrol_new alc882_base_mixer[] = {
6035         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6036         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6037         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6038         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6039         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6040         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6041         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6042         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6043         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6044         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6045         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6046         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6047         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6048         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6049         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6050         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6051         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6052         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6053         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6054         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6055         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6056         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6057         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6058         { } /* end */
6059 };
6060
6061 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6062         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6063         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6064         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
6065         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6066         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6067         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6068         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
6069         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
6070         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
6071         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
6072         { } /* end */
6073 };
6074 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6075         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6076         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6077         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6078         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6079         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6080         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6081         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6082         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6083         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6084         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6085         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6086         { } /* end */
6087 };
6088
6089 static struct snd_kcontrol_new alc882_targa_mixer[] = {
6090         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6091         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6092         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6093         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6094         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6095         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6096         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6097         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6098         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6099         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6100         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6101         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6102         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6103         { } /* end */
6104 };
6105
6106 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
6107  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
6108  */
6109 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
6110         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6111         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6112         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6113         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
6114         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6115         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6116         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6117         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6118         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
6119         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
6120         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6121         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6122         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6123         { } /* end */
6124 };
6125
6126 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6127         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6128         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6129         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6130         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6131         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6132         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6133         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6134         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6135         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6136         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6137         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6138         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6139         { } /* end */
6140 };
6141
6142 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6143         {
6144                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6145                 .name = "Channel Mode",
6146                 .info = alc_ch_mode_info,
6147                 .get = alc_ch_mode_get,
6148                 .put = alc_ch_mode_put,
6149         },
6150         { } /* end */
6151 };
6152
6153 static struct hda_verb alc882_init_verbs[] = {
6154         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6155         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6156         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6157         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6158         /* Rear mixer */
6159         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6160         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6161         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6162         /* CLFE mixer */
6163         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6164         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6165         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6166         /* Side mixer */
6167         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6168         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6169         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6170
6171         /* Front Pin: output 0 (0x0c) */
6172         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6173         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6174         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6175         /* Rear Pin: output 1 (0x0d) */
6176         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6177         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6178         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6179         /* CLFE Pin: output 2 (0x0e) */
6180         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6181         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6182         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6183         /* Side Pin: output 3 (0x0f) */
6184         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6185         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6186         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6187         /* Mic (rear) pin: input vref at 80% */
6188         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6189         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6190         /* Front Mic pin: input vref at 80% */
6191         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6192         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6193         /* Line In pin: input */
6194         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6195         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6196         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6197         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6198         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6199         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6200         /* CD pin widget for input */
6201         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6202
6203         /* FIXME: use matrix-type input source selection */
6204         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6205         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6206         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6207         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6208         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6209         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6210         /* Input mixer2 */
6211         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6212         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6213         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6214         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6215         /* Input mixer3 */
6216         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6217         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6218         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6219         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6220         /* ADC1: mute amp left and right */
6221         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6222         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6223         /* ADC2: mute amp left and right */
6224         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6225         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6226         /* ADC3: mute amp left and right */
6227         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6228         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6229
6230         { }
6231 };
6232
6233 static struct hda_verb alc882_eapd_verbs[] = {
6234         /* change to EAPD mode */
6235         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6236         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
6237         { }
6238 };
6239
6240 /* Mac Pro test */
6241 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6242         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6243         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6244         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6245         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6246         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6247         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6248         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6249         { } /* end */
6250 };
6251
6252 static struct hda_verb alc882_macpro_init_verbs[] = {
6253         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6254         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6255         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6256         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6257         /* Front Pin: output 0 (0x0c) */
6258         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6259         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6260         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6261         /* Front Mic pin: input vref at 80% */
6262         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6263         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6264         /* Speaker:  output */
6265         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6266         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6267         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6268         /* Headphone output (output 0 - 0x0c) */
6269         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6270         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6271         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6272
6273         /* FIXME: use matrix-type input source selection */
6274         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6275         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6276         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6277         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6278         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6279         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6280         /* Input mixer2 */
6281         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6282         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6283         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6284         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6285         /* Input mixer3 */
6286         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6287         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6288         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6289         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6290         /* ADC1: mute amp left and right */
6291         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6292         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6293         /* ADC2: mute amp left and right */
6294         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6295         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6296         /* ADC3: mute amp left and right */
6297         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6298         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6299
6300         { }
6301 };
6302
6303 /* Macbook Pro rev3 */
6304 static struct hda_verb alc885_mbp3_init_verbs[] = {
6305         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6306         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6307         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6308         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6309         /* Rear mixer */
6310         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6311         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6312         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6313         /* Front Pin: output 0 (0x0c) */
6314         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6315         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6316         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6317         /* HP Pin: output 0 (0x0d) */
6318         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6319         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6320         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6321         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6322         /* Mic (rear) pin: input vref at 80% */
6323         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6324         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6325         /* Front Mic pin: input vref at 80% */
6326         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6327         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6328         /* Line In pin: use output 1 when in LineOut mode */
6329         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6330         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6331         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6332
6333         /* FIXME: use matrix-type input source selection */
6334         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6335         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6336         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6337         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6338         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6339         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6340         /* Input mixer2 */
6341         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6342         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6343         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6344         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6345         /* Input mixer3 */
6346         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6347         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6348         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6349         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6350         /* ADC1: mute amp left and right */
6351         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6352         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6353         /* ADC2: mute amp left and right */
6354         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6355         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6356         /* ADC3: mute amp left and right */
6357         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6358         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6359
6360         { }
6361 };
6362
6363 /* iMac 24 mixer. */
6364 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6365         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6366         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6367         { } /* end */
6368 };
6369
6370 /* iMac 24 init verbs. */
6371 static struct hda_verb alc885_imac24_init_verbs[] = {
6372         /* Internal speakers: output 0 (0x0c) */
6373         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6374         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6375         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6376         /* Internal speakers: output 0 (0x0c) */
6377         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6378         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6379         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6380         /* Headphone: output 0 (0x0c) */
6381         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6382         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6383         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6384         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6385         /* Front Mic: input vref at 80% */
6386         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6387         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6388         { }
6389 };
6390
6391 /* Toggle speaker-output according to the hp-jack state */
6392 static void alc885_imac24_automute(struct hda_codec *codec)
6393 {
6394         unsigned int present;
6395
6396         present = snd_hda_codec_read(codec, 0x14, 0,
6397                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6398         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6399                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6400         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6401                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6402 }
6403
6404 /* Processes unsolicited events. */
6405 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6406                                       unsigned int res)
6407 {
6408         /* Headphone insertion or removal. */
6409         if ((res >> 26) == ALC880_HP_EVENT)
6410                 alc885_imac24_automute(codec);
6411 }
6412
6413 static void alc885_mbp3_automute(struct hda_codec *codec)
6414 {
6415         unsigned int present;
6416
6417         present = snd_hda_codec_read(codec, 0x15, 0,
6418                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6419         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6420                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6421         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6422                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6423
6424 }
6425 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6426                                     unsigned int res)
6427 {
6428         /* Headphone insertion or removal. */
6429         if ((res >> 26) == ALC880_HP_EVENT)
6430                 alc885_mbp3_automute(codec);
6431 }
6432
6433
6434 static struct hda_verb alc882_targa_verbs[] = {
6435         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6436         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6437
6438         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6439         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6440
6441         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6442         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6443         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6444
6445         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6446         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6447         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6448         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6449         { } /* end */
6450 };
6451
6452 /* toggle speaker-output according to the hp-jack state */
6453 static void alc882_targa_automute(struct hda_codec *codec)
6454 {
6455         unsigned int present;
6456
6457         present = snd_hda_codec_read(codec, 0x14, 0,
6458                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6459         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6460                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6461         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6462                                   present ? 1 : 3);
6463 }
6464
6465 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6466 {
6467         /* Looks like the unsol event is incompatible with the standard
6468          * definition.  4bit tag is placed at 26 bit!
6469          */
6470         if (((res >> 26) == ALC880_HP_EVENT)) {
6471                 alc882_targa_automute(codec);
6472         }
6473 }
6474
6475 static struct hda_verb alc882_asus_a7j_verbs[] = {
6476         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6477         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6478
6479         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6480         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6481         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6482
6483         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6484         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6485         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6486
6487         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6488         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6489         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6490         { } /* end */
6491 };
6492
6493 static struct hda_verb alc882_asus_a7m_verbs[] = {
6494         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6495         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6496
6497         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6498         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6499         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6500
6501         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6502         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6503         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6504
6505         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6506         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6507         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6508         { } /* end */
6509 };
6510
6511 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6512 {
6513         unsigned int gpiostate, gpiomask, gpiodir;
6514
6515         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6516                                        AC_VERB_GET_GPIO_DATA, 0);
6517
6518         if (!muted)
6519                 gpiostate |= (1 << pin);
6520         else
6521                 gpiostate &= ~(1 << pin);
6522
6523         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6524                                       AC_VERB_GET_GPIO_MASK, 0);
6525         gpiomask |= (1 << pin);
6526
6527         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6528                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6529         gpiodir |= (1 << pin);
6530
6531
6532         snd_hda_codec_write(codec, codec->afg, 0,
6533                             AC_VERB_SET_GPIO_MASK, gpiomask);
6534         snd_hda_codec_write(codec, codec->afg, 0,
6535                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6536
6537         msleep(1);
6538
6539         snd_hda_codec_write(codec, codec->afg, 0,
6540                             AC_VERB_SET_GPIO_DATA, gpiostate);
6541 }
6542
6543 /* set up GPIO at initialization */
6544 static void alc885_macpro_init_hook(struct hda_codec *codec)
6545 {
6546         alc882_gpio_mute(codec, 0, 0);
6547         alc882_gpio_mute(codec, 1, 0);
6548 }
6549
6550 /* set up GPIO and update auto-muting at initialization */
6551 static void alc885_imac24_init_hook(struct hda_codec *codec)
6552 {
6553         alc885_macpro_init_hook(codec);
6554         alc885_imac24_automute(codec);
6555 }
6556
6557 /*
6558  * generic initialization of ADC, input mixers and output mixers
6559  */
6560 static struct hda_verb alc882_auto_init_verbs[] = {
6561         /*
6562          * Unmute ADC0-2 and set the default input to mic-in
6563          */
6564         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6565         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6566         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6567         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6568         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6569         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6570
6571         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6572          * mixer widget
6573          * Note: PASD motherboards uses the Line In 2 as the input for
6574          * front panel mic (mic 2)
6575          */
6576         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6577         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6578         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6579         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6580         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6581         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6582
6583         /*
6584          * Set up output mixers (0x0c - 0x0f)
6585          */
6586         /* set vol=0 to output mixers */
6587         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6588         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6589         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6590         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6591         /* set up input amps for analog loopback */
6592         /* Amp Indices: DAC = 0, mixer = 1 */
6593         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6594         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6595         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6596         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6597         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6598         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6599         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6600         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6601         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6602         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6603
6604         /* FIXME: use matrix-type input source selection */
6605         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6606         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6607         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6608         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6609         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6610         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6611         /* Input mixer2 */
6612         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6613         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6614         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6615         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6616         /* Input mixer3 */
6617         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6618         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6619         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6620         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6621
6622         { }
6623 };
6624
6625 #ifdef CONFIG_SND_HDA_POWER_SAVE
6626 #define alc882_loopbacks        alc880_loopbacks
6627 #endif
6628
6629 /* pcm configuration: identiacal with ALC880 */
6630 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6631 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6632 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6633 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6634
6635 /*
6636  * configuration and preset
6637  */
6638 static const char *alc882_models[ALC882_MODEL_LAST] = {
6639         [ALC882_3ST_DIG]        = "3stack-dig",
6640         [ALC882_6ST_DIG]        = "6stack-dig",
6641         [ALC882_ARIMA]          = "arima",
6642         [ALC882_W2JC]           = "w2jc",
6643         [ALC882_TARGA]          = "targa",
6644         [ALC882_ASUS_A7J]       = "asus-a7j",
6645         [ALC882_ASUS_A7M]       = "asus-a7m",
6646         [ALC885_MACPRO]         = "macpro",
6647         [ALC885_MBP3]           = "mbp3",
6648         [ALC885_IMAC24]         = "imac24",
6649         [ALC882_AUTO]           = "auto",
6650 };
6651
6652 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6653         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6654         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6655         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6656         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6657         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6658         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6659         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6660         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6661         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6662         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6663         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6664         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6665         {}
6666 };
6667
6668 static struct alc_config_preset alc882_presets[] = {
6669         [ALC882_3ST_DIG] = {
6670                 .mixers = { alc882_base_mixer },
6671                 .init_verbs = { alc882_init_verbs },
6672                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6673                 .dac_nids = alc882_dac_nids,
6674                 .dig_out_nid = ALC882_DIGOUT_NID,
6675                 .dig_in_nid = ALC882_DIGIN_NID,
6676                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6677                 .channel_mode = alc882_ch_modes,
6678                 .need_dac_fix = 1,
6679                 .input_mux = &alc882_capture_source,
6680         },
6681         [ALC882_6ST_DIG] = {
6682                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6683                 .init_verbs = { alc882_init_verbs },
6684                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6685                 .dac_nids = alc882_dac_nids,
6686                 .dig_out_nid = ALC882_DIGOUT_NID,
6687                 .dig_in_nid = ALC882_DIGIN_NID,
6688                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6689                 .channel_mode = alc882_sixstack_modes,
6690                 .input_mux = &alc882_capture_source,
6691         },
6692         [ALC882_ARIMA] = {
6693                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6694                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6695                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6696                 .dac_nids = alc882_dac_nids,
6697                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6698                 .channel_mode = alc882_sixstack_modes,
6699                 .input_mux = &alc882_capture_source,
6700         },
6701         [ALC882_W2JC] = {
6702                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6703                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6704                                 alc880_gpio1_init_verbs },
6705                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6706                 .dac_nids = alc882_dac_nids,
6707                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6708                 .channel_mode = alc880_threestack_modes,
6709                 .need_dac_fix = 1,
6710                 .input_mux = &alc882_capture_source,
6711                 .dig_out_nid = ALC882_DIGOUT_NID,
6712         },
6713         [ALC885_MBP3] = {
6714                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6715                 .init_verbs = { alc885_mbp3_init_verbs,
6716                                 alc880_gpio1_init_verbs },
6717                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6718                 .dac_nids = alc882_dac_nids,
6719                 .channel_mode = alc885_mbp_6ch_modes,
6720                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6721                 .input_mux = &alc882_capture_source,
6722                 .dig_out_nid = ALC882_DIGOUT_NID,
6723                 .dig_in_nid = ALC882_DIGIN_NID,
6724                 .unsol_event = alc885_mbp3_unsol_event,
6725                 .init_hook = alc885_mbp3_automute,
6726         },
6727         [ALC885_MACPRO] = {
6728                 .mixers = { alc882_macpro_mixer },
6729                 .init_verbs = { alc882_macpro_init_verbs },
6730                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6731                 .dac_nids = alc882_dac_nids,
6732                 .dig_out_nid = ALC882_DIGOUT_NID,
6733                 .dig_in_nid = ALC882_DIGIN_NID,
6734                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6735                 .channel_mode = alc882_ch_modes,
6736                 .input_mux = &alc882_capture_source,
6737                 .init_hook = alc885_macpro_init_hook,
6738         },
6739         [ALC885_IMAC24] = {
6740                 .mixers = { alc885_imac24_mixer },
6741                 .init_verbs = { alc885_imac24_init_verbs },
6742                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6743                 .dac_nids = alc882_dac_nids,
6744                 .dig_out_nid = ALC882_DIGOUT_NID,
6745                 .dig_in_nid = ALC882_DIGIN_NID,
6746                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6747                 .channel_mode = alc882_ch_modes,
6748                 .input_mux = &alc882_capture_source,
6749                 .unsol_event = alc885_imac24_unsol_event,
6750                 .init_hook = alc885_imac24_init_hook,
6751         },
6752         [ALC882_TARGA] = {
6753                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
6754                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6755                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6756                 .dac_nids = alc882_dac_nids,
6757                 .dig_out_nid = ALC882_DIGOUT_NID,
6758                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6759                 .adc_nids = alc882_adc_nids,
6760                 .capsrc_nids = alc882_capsrc_nids,
6761                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6762                 .channel_mode = alc882_3ST_6ch_modes,
6763                 .need_dac_fix = 1,
6764                 .input_mux = &alc882_capture_source,
6765                 .unsol_event = alc882_targa_unsol_event,
6766                 .init_hook = alc882_targa_automute,
6767         },
6768         [ALC882_ASUS_A7J] = {
6769                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
6770                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6771                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6772                 .dac_nids = alc882_dac_nids,
6773                 .dig_out_nid = ALC882_DIGOUT_NID,
6774                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6775                 .adc_nids = alc882_adc_nids,
6776                 .capsrc_nids = alc882_capsrc_nids,
6777                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6778                 .channel_mode = alc882_3ST_6ch_modes,
6779                 .need_dac_fix = 1,
6780                 .input_mux = &alc882_capture_source,
6781         },
6782         [ALC882_ASUS_A7M] = {
6783                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6784                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6785                                 alc880_gpio1_init_verbs,
6786                                 alc882_asus_a7m_verbs },
6787                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6788                 .dac_nids = alc882_dac_nids,
6789                 .dig_out_nid = ALC882_DIGOUT_NID,
6790                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6791                 .channel_mode = alc880_threestack_modes,
6792                 .need_dac_fix = 1,
6793                 .input_mux = &alc882_capture_source,
6794         },
6795 };
6796
6797
6798 /*
6799  * Pin config fixes
6800  */
6801 enum {
6802         PINFIX_ABIT_AW9D_MAX
6803 };
6804
6805 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6806         { 0x15, 0x01080104 }, /* side */
6807         { 0x16, 0x01011012 }, /* rear */
6808         { 0x17, 0x01016011 }, /* clfe */
6809         { }
6810 };
6811
6812 static const struct alc_pincfg *alc882_pin_fixes[] = {
6813         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6814 };
6815
6816 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6817         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6818         {}
6819 };
6820
6821 /*
6822  * BIOS auto configuration
6823  */
6824 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6825                                               hda_nid_t nid, int pin_type,
6826                                               int dac_idx)
6827 {
6828         /* set as output */
6829         struct alc_spec *spec = codec->spec;
6830         int idx;
6831
6832         alc_set_pin_output(codec, nid, pin_type);
6833         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6834                 idx = 4;
6835         else
6836                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6837         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6838
6839 }
6840
6841 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6842 {
6843         struct alc_spec *spec = codec->spec;
6844         int i;
6845
6846         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6847         for (i = 0; i <= HDA_SIDE; i++) {
6848                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6849                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6850                 if (nid)
6851                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6852                                                           i);
6853         }
6854 }
6855
6856 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6857 {
6858         struct alc_spec *spec = codec->spec;
6859         hda_nid_t pin;
6860
6861         pin = spec->autocfg.hp_pins[0];
6862         if (pin) /* connect to front */
6863                 /* use dac 0 */
6864                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6865         pin = spec->autocfg.speaker_pins[0];
6866         if (pin)
6867                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6868 }
6869
6870 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6871 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6872
6873 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6874 {
6875         struct alc_spec *spec = codec->spec;
6876         int i;
6877
6878         for (i = 0; i < AUTO_PIN_LAST; i++) {
6879                 hda_nid_t nid = spec->autocfg.input_pins[i];
6880                 unsigned int vref;
6881                 if (!nid)
6882                         continue;
6883                 vref = PIN_IN;
6884                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6885                         unsigned int pincap;
6886                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6887                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6888                             AC_PINCAP_VREF_80)
6889                                 vref = PIN_VREF80;
6890                 }
6891                 snd_hda_codec_write(codec, nid, 0,
6892                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6893                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6894                         snd_hda_codec_write(codec, nid, 0,
6895                                             AC_VERB_SET_AMP_GAIN_MUTE,
6896                                             AMP_OUT_MUTE);
6897         }
6898 }
6899
6900 static void alc882_auto_init_input_src(struct hda_codec *codec)
6901 {
6902         struct alc_spec *spec = codec->spec;
6903         const struct hda_input_mux *imux = spec->input_mux;
6904         int c;
6905
6906         for (c = 0; c < spec->num_adc_nids; c++) {
6907                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6908                 hda_nid_t nid = spec->capsrc_nids[c];
6909                 int conns, mute, idx, item;
6910
6911                 conns = snd_hda_get_connections(codec, nid, conn_list,
6912                                                 ARRAY_SIZE(conn_list));
6913                 if (conns < 0)
6914                         continue;
6915                 for (idx = 0; idx < conns; idx++) {
6916                         /* if the current connection is the selected one,
6917                          * unmute it as default - otherwise mute it
6918                          */
6919                         mute = AMP_IN_MUTE(idx);
6920                         for (item = 0; item < imux->num_items; item++) {
6921                                 if (imux->items[item].index == idx) {
6922                                         if (spec->cur_mux[c] == item)
6923                                                 mute = AMP_IN_UNMUTE(idx);
6924                                         break;
6925                                 }
6926                         }
6927                         snd_hda_codec_write(codec, nid, 0,
6928                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6929                 }
6930         }
6931 }
6932
6933 /* add mic boosts if needed */
6934 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6935 {
6936         struct alc_spec *spec = codec->spec;
6937         int err;
6938         hda_nid_t nid;
6939
6940         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6941         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6942                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6943                                   "Mic Boost",
6944                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6945                 if (err < 0)
6946                         return err;
6947         }
6948         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6949         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6950                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6951                                   "Front Mic Boost",
6952                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6953                 if (err < 0)
6954                         return err;
6955         }
6956         return 0;
6957 }
6958
6959 /* almost identical with ALC880 parser... */
6960 static int alc882_parse_auto_config(struct hda_codec *codec)
6961 {
6962         struct alc_spec *spec = codec->spec;
6963         int err = alc880_parse_auto_config(codec);
6964
6965         if (err < 0)
6966                 return err;
6967         else if (!err)
6968                 return 0; /* no config found */
6969
6970         err = alc_auto_add_mic_boost(codec);
6971         if (err < 0)
6972                 return err;
6973
6974         /* hack - override the init verbs */
6975         spec->init_verbs[0] = alc882_auto_init_verbs;
6976
6977         return 1; /* config found */
6978 }
6979
6980 /* additional initialization for auto-configuration model */
6981 static void alc882_auto_init(struct hda_codec *codec)
6982 {
6983         struct alc_spec *spec = codec->spec;
6984         alc882_auto_init_multi_out(codec);
6985         alc882_auto_init_hp_out(codec);
6986         alc882_auto_init_analog_input(codec);
6987         alc882_auto_init_input_src(codec);
6988         if (spec->unsol_event)
6989                 alc_inithook(codec);
6990 }
6991
6992 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6993
6994 static int patch_alc882(struct hda_codec *codec)
6995 {
6996         struct alc_spec *spec;
6997         int err, board_config;
6998
6999         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7000         if (spec == NULL)
7001                 return -ENOMEM;
7002
7003         codec->spec = spec;
7004
7005         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
7006                                                   alc882_models,
7007                                                   alc882_cfg_tbl);
7008
7009         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
7010                 /* Pick up systems that don't supply PCI SSID */
7011                 switch (codec->subsystem_id) {
7012                 case 0x106b0c00: /* Mac Pro */
7013                         board_config = ALC885_MACPRO;
7014                         break;
7015                 case 0x106b1000: /* iMac 24 */
7016                 case 0x106b2800: /* AppleTV */
7017                 case 0x106b3e00: /* iMac 24 Aluminium */
7018                         board_config = ALC885_IMAC24;
7019                         break;
7020                 case 0x106b00a0: /* MacBookPro3,1 - Another revision */
7021                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
7022                 case 0x106b00a4: /* MacbookPro4,1 */
7023                 case 0x106b2c00: /* Macbook Pro rev3 */
7024                 case 0x106b3600: /* Macbook 3.1 */
7025                 case 0x106b3800: /* MacbookPro4,1 - latter revision */
7026                         board_config = ALC885_MBP3;
7027                         break;
7028                 default:
7029                         /* ALC889A is handled better as ALC888-compatible */
7030                         if (codec->revision_id == 0x100101 ||
7031                             codec->revision_id == 0x100103) {
7032                                 alc_free(codec);
7033                                 return patch_alc883(codec);
7034                         }
7035                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
7036                                          "trying auto-probe from BIOS...\n");
7037                         board_config = ALC882_AUTO;
7038                 }
7039         }
7040
7041         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7042
7043         if (board_config == ALC882_AUTO) {
7044                 /* automatic parse from the BIOS config */
7045                 err = alc882_parse_auto_config(codec);
7046                 if (err < 0) {
7047                         alc_free(codec);
7048                         return err;
7049                 } else if (!err) {
7050                         printk(KERN_INFO
7051                                "hda_codec: Cannot set up configuration "
7052                                "from BIOS.  Using base mode...\n");
7053                         board_config = ALC882_3ST_DIG;
7054                 }
7055         }
7056
7057         if (board_config != ALC882_AUTO)
7058                 setup_preset(spec, &alc882_presets[board_config]);
7059
7060         if (codec->vendor_id == 0x10ec0885) {
7061                 spec->stream_name_analog = "ALC885 Analog";
7062                 spec->stream_name_digital = "ALC885 Digital";
7063         } else {
7064                 spec->stream_name_analog = "ALC882 Analog";
7065                 spec->stream_name_digital = "ALC882 Digital";
7066         }
7067
7068         spec->stream_analog_playback = &alc882_pcm_analog_playback;
7069         spec->stream_analog_capture = &alc882_pcm_analog_capture;
7070         /* FIXME: setup DAC5 */
7071         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7072         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7073
7074         spec->stream_digital_playback = &alc882_pcm_digital_playback;
7075         spec->stream_digital_capture = &alc882_pcm_digital_capture;
7076
7077         spec->is_mix_capture = 1; /* matrix-style capture */
7078         if (!spec->adc_nids && spec->input_mux) {
7079                 /* check whether NID 0x07 is valid */
7080                 unsigned int wcap = get_wcaps(codec, 0x07);
7081                 /* get type */
7082                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7083                 if (wcap != AC_WID_AUD_IN) {
7084                         spec->adc_nids = alc882_adc_nids_alt;
7085                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7086                         spec->capsrc_nids = alc882_capsrc_nids_alt;
7087                 } else {
7088                         spec->adc_nids = alc882_adc_nids;
7089                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7090                         spec->capsrc_nids = alc882_capsrc_nids;
7091                 }
7092         }
7093         set_capture_mixer(spec);
7094
7095         spec->vmaster_nid = 0x0c;
7096
7097         codec->patch_ops = alc_patch_ops;
7098         if (board_config == ALC882_AUTO)
7099                 spec->init_hook = alc882_auto_init;
7100 #ifdef CONFIG_SND_HDA_POWER_SAVE
7101         if (!spec->loopback.amplist)
7102                 spec->loopback.amplist = alc882_loopbacks;
7103 #endif
7104         codec->proc_widget_hook = print_realtek_coef;
7105
7106         return 0;
7107 }
7108
7109 /*
7110  * ALC883 support
7111  *
7112  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7113  * configuration.  Each pin widget can choose any input DACs and a mixer.
7114  * Each ADC is connected from a mixer of all inputs.  This makes possible
7115  * 6-channel independent captures.
7116  *
7117  * In addition, an independent DAC for the multi-playback (not used in this
7118  * driver yet).
7119  */
7120 #define ALC883_DIGOUT_NID       0x06
7121 #define ALC883_DIGIN_NID        0x0a
7122
7123 #define ALC1200_DIGOUT_NID      0x10
7124
7125 static hda_nid_t alc883_dac_nids[4] = {
7126         /* front, rear, clfe, rear_surr */
7127         0x02, 0x03, 0x04, 0x05
7128 };
7129
7130 static hda_nid_t alc883_adc_nids[2] = {
7131         /* ADC1-2 */
7132         0x08, 0x09,
7133 };
7134
7135 static hda_nid_t alc883_adc_nids_alt[1] = {
7136         /* ADC1 */
7137         0x08,
7138 };
7139
7140 static hda_nid_t alc883_adc_nids_rev[2] = {
7141         /* ADC2-1 */
7142         0x09, 0x08
7143 };
7144
7145 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7146
7147 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7148
7149 /* input MUX */
7150 /* FIXME: should be a matrix-type input source selection */
7151
7152 static struct hda_input_mux alc883_capture_source = {
7153         .num_items = 4,
7154         .items = {
7155                 { "Mic", 0x0 },
7156                 { "Front Mic", 0x1 },
7157                 { "Line", 0x2 },
7158                 { "CD", 0x4 },
7159         },
7160 };
7161
7162 static struct hda_input_mux alc883_3stack_6ch_intel = {
7163         .num_items = 4,
7164         .items = {
7165                 { "Mic", 0x1 },
7166                 { "Front Mic", 0x0 },
7167                 { "Line", 0x2 },
7168                 { "CD", 0x4 },
7169         },
7170 };
7171
7172 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7173         .num_items = 2,
7174         .items = {
7175                 { "Mic", 0x1 },
7176                 { "Line", 0x2 },
7177         },
7178 };
7179
7180 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7181         .num_items = 4,
7182         .items = {
7183                 { "Mic", 0x0 },
7184                 { "iMic", 0x1 },
7185                 { "Line", 0x2 },
7186                 { "CD", 0x4 },
7187         },
7188 };
7189
7190 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7191         .num_items = 2,
7192         .items = {
7193                 { "Mic", 0x0 },
7194                 { "Int Mic", 0x1 },
7195         },
7196 };
7197
7198 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7199         .num_items = 3,
7200         .items = {
7201                 { "Mic", 0x0 },
7202                 { "Front Mic", 0x1 },
7203                 { "Line", 0x4 },
7204         },
7205 };
7206
7207 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7208         .num_items = 2,
7209         .items = {
7210                 { "Mic", 0x0 },
7211                 { "Line", 0x2 },
7212         },
7213 };
7214
7215 /*
7216  * 2ch mode
7217  */
7218 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7219         { 2, NULL }
7220 };
7221
7222 /*
7223  * 2ch mode
7224  */
7225 static struct hda_verb alc883_3ST_ch2_init[] = {
7226         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7227         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7228         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7229         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7230         { } /* end */
7231 };
7232
7233 /*
7234  * 4ch mode
7235  */
7236 static struct hda_verb alc883_3ST_ch4_init[] = {
7237         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7238         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7239         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7240         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7241         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7242         { } /* end */
7243 };
7244
7245 /*
7246  * 6ch mode
7247  */
7248 static struct hda_verb alc883_3ST_ch6_init[] = {
7249         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7250         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7251         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7252         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7253         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7254         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7255         { } /* end */
7256 };
7257
7258 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7259         { 2, alc883_3ST_ch2_init },
7260         { 4, alc883_3ST_ch4_init },
7261         { 6, alc883_3ST_ch6_init },
7262 };
7263
7264 /*
7265  * 2ch mode
7266  */
7267 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7268         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7269         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7270         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7271         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7272         { } /* end */
7273 };
7274
7275 /*
7276  * 4ch mode
7277  */
7278 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7279         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7280         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7281         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7282         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7283         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7284         { } /* end */
7285 };
7286
7287 /*
7288  * 6ch mode
7289  */
7290 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7291         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7292         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7293         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7294         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7295         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7296         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7297         { } /* end */
7298 };
7299
7300 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7301         { 2, alc883_3ST_ch2_intel_init },
7302         { 4, alc883_3ST_ch4_intel_init },
7303         { 6, alc883_3ST_ch6_intel_init },
7304 };
7305
7306 /*
7307  * 6ch mode
7308  */
7309 static struct hda_verb alc883_sixstack_ch6_init[] = {
7310         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7311         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7312         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7313         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7314         { } /* end */
7315 };
7316
7317 /*
7318  * 8ch mode
7319  */
7320 static struct hda_verb alc883_sixstack_ch8_init[] = {
7321         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7322         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7323         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7324         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7325         { } /* end */
7326 };
7327
7328 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7329         { 6, alc883_sixstack_ch6_init },
7330         { 8, alc883_sixstack_ch8_init },
7331 };
7332
7333 static struct hda_verb alc883_medion_eapd_verbs[] = {
7334         /* eanable EAPD on medion laptop */
7335         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7336         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7337         { }
7338 };
7339
7340 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7341  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7342  */
7343
7344 static struct snd_kcontrol_new alc883_base_mixer[] = {
7345         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7346         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7347         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7348         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7349         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7350         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7351         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7352         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7353         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7354         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7355         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7356         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7357         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7358         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7359         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7360         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7361         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7362         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7363         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7364         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7365         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7366         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7367         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7368         { } /* end */
7369 };
7370
7371 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7372         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7373         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 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_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7379         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7380         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7381         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7382         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7383         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7384         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7385         { } /* end */
7386 };
7387
7388 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7389         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7390         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7391         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7392         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7393         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7394         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7395         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7396         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7397         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7398         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7399         { } /* end */
7400 };
7401
7402 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7403         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7404         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7405         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7406         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7407         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7408         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7409         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7410         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7411         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7412         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7413         { } /* end */
7414 };
7415
7416 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7417         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7418         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7419         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7420         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7421         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7422         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7423         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7424         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7425         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7426         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7427         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7428         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7429         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7430         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7431         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7432         { } /* end */
7433 };
7434
7435 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7436         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7437         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7438         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7439         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7440         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7441         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7442         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7443         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 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_intel_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,
7466                               HDA_OUTPUT),
7467         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7468         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7469         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7470         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7471         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7472         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7473         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7474         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7475         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7476         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7477         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7478         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7479         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7480         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7481         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7482         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7483         { } /* end */
7484 };
7485
7486 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7487         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7488         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7489         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7490         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7491         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, 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", 0x1b, 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, 0x0, HDA_INPUT),
7501         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7502         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7503         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7504         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7505         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, 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_tagra_mixer[] = {
7512         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7513         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7514         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7515         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7516         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7517         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7518         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7519         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7520         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
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         { } /* end */
7529 };
7530
7531 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7532         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7533         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7534         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7535         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7536         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7537         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7538         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7539         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7540         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7541         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7542         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7543         { } /* end */
7544 };
7545
7546 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7547         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7548         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7549         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7550         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7551         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7552         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7553         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7554         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7555         { } /* end */
7556 };
7557
7558 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7559         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7560         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7561         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7562         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7563         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7564         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7565         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7566         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7567         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7568         { } /* end */
7569 };
7570
7571 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7572         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7573         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7574         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7575         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7576         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7577         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7578         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7579         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7580         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7581         { } /* end */
7582 };
7583
7584 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7585         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7586         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7587         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7588         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7589         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7590         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7591         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7592         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7593         { } /* end */
7594 };
7595
7596 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7597         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7598         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7599         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7600         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7601         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7602                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7603         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7604         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7605         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7606         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7607         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7608         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7609         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7610         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7611         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7612         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7613         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7614         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7615         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7616         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7617         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7618         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7619         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7620         { } /* end */
7621 };
7622
7623 static struct hda_bind_ctls alc883_bind_cap_vol = {
7624         .ops = &snd_hda_bind_vol,
7625         .values = {
7626                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7627                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7628                 0
7629         },
7630 };
7631
7632 static struct hda_bind_ctls alc883_bind_cap_switch = {
7633         .ops = &snd_hda_bind_sw,
7634         .values = {
7635                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7636                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7637                 0
7638         },
7639 };
7640
7641 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7642         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7643         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7644         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7645         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7646         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7647         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7648         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7649         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7650         { } /* end */
7651 };
7652
7653 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
7654         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7655         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7656         {
7657                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7658                 /* .name = "Capture Source", */
7659                 .name = "Input Source",
7660                 .count = 1,
7661                 .info = alc_mux_enum_info,
7662                 .get = alc_mux_enum_get,
7663                 .put = alc_mux_enum_put,
7664         },
7665         { } /* end */
7666 };
7667
7668 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7669         {
7670                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7671                 .name = "Channel Mode",
7672                 .info = alc_ch_mode_info,
7673                 .get = alc_ch_mode_get,
7674                 .put = alc_ch_mode_put,
7675         },
7676         { } /* end */
7677 };
7678
7679 static struct hda_verb alc883_init_verbs[] = {
7680         /* ADC1: mute amp left and right */
7681         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7682         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7683         /* ADC2: mute amp left and right */
7684         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7685         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7686         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7687         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7688         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7689         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7690         /* Rear mixer */
7691         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7692         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7693         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7694         /* CLFE mixer */
7695         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7696         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7697         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7698         /* Side mixer */
7699         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7700         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7701         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7702
7703         /* mute analog input loopbacks */
7704         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7705         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7706         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7707         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7708         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7709
7710         /* Front Pin: output 0 (0x0c) */
7711         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7712         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7713         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7714         /* Rear Pin: output 1 (0x0d) */
7715         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7716         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7717         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7718         /* CLFE Pin: output 2 (0x0e) */
7719         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7720         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7721         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7722         /* Side Pin: output 3 (0x0f) */
7723         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7724         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7725         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7726         /* Mic (rear) pin: input vref at 80% */
7727         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7728         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7729         /* Front Mic pin: input vref at 80% */
7730         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7731         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7732         /* Line In pin: input */
7733         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7734         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7735         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7736         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7737         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7738         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7739         /* CD pin widget for input */
7740         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7741
7742         /* FIXME: use matrix-type input source selection */
7743         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7744         /* Input mixer2 */
7745         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7746         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7747         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7748         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7749         /* Input mixer3 */
7750         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7751         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7752         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7753         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7754         { }
7755 };
7756
7757 /* toggle speaker-output according to the hp-jack state */
7758 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7759 {
7760         unsigned int present;
7761
7762         present = snd_hda_codec_read(codec, 0x15, 0,
7763                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7764         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7765                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7766         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7767                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7768 }
7769
7770 /* auto-toggle front mic */
7771 /*
7772 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7773 {
7774         unsigned int present;
7775         unsigned char bits;
7776
7777         present = snd_hda_codec_read(codec, 0x18, 0,
7778                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7779         bits = present ? HDA_AMP_MUTE : 0;
7780         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7781 }
7782 */
7783
7784 static void alc883_mitac_automute(struct hda_codec *codec)
7785 {
7786         alc883_mitac_hp_automute(codec);
7787         /* alc883_mitac_mic_automute(codec); */
7788 }
7789
7790 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7791                                            unsigned int res)
7792 {
7793         switch (res >> 26) {
7794         case ALC880_HP_EVENT:
7795                 alc883_mitac_hp_automute(codec);
7796                 break;
7797         case ALC880_MIC_EVENT:
7798                 /* alc883_mitac_mic_automute(codec); */
7799                 break;
7800         }
7801 }
7802
7803 static struct hda_verb alc883_mitac_verbs[] = {
7804         /* HP */
7805         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7806         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7807         /* Subwoofer */
7808         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7809         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7810
7811         /* enable unsolicited event */
7812         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7813         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7814
7815         { } /* end */
7816 };
7817
7818 static struct hda_verb alc883_clevo_m720_verbs[] = {
7819         /* HP */
7820         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7821         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7822         /* Int speaker */
7823         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7824         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7825
7826         /* enable unsolicited event */
7827         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7828         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7829
7830         { } /* end */
7831 };
7832
7833 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7834         /* HP */
7835         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7836         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7837         /* Subwoofer */
7838         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7839         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7840
7841         /* enable unsolicited event */
7842         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7843
7844         { } /* end */
7845 };
7846
7847 static struct hda_verb alc883_tagra_verbs[] = {
7848         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7849         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7850
7851         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7852         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7853
7854         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7855         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7856         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7857
7858         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7859         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7860         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7861         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7862
7863         { } /* end */
7864 };
7865
7866 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7867         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7868         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7869         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7870         { } /* end */
7871 };
7872
7873 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7874         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7875         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7876         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7877         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7878         { } /* end */
7879 };
7880
7881 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7882         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7883         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7884         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7885         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7886         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7887         { } /* end */
7888 };
7889
7890 static struct hda_verb alc883_haier_w66_verbs[] = {
7891         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7892         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7893
7894         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7895
7896         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7897         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7898         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7899         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7900         { } /* end */
7901 };
7902
7903 static struct hda_verb alc888_lenovo_sky_verbs[] = {
7904         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7905         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7906         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7907         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7908         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7909         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7910         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7911         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7912         { } /* end */
7913 };
7914
7915 static struct hda_verb alc888_3st_hp_verbs[] = {
7916         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7917         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7918         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7919         { }
7920 };
7921
7922 static struct hda_verb alc888_6st_dell_verbs[] = {
7923         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7924         { }
7925 };
7926
7927 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7928         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7929         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7930         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7931         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7932         { }
7933 };
7934
7935 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7936         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7937         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7938         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7939         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7940         { }
7941 };
7942
7943 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7944         { 2, alc888_3st_hp_2ch_init },
7945         { 6, alc888_3st_hp_6ch_init },
7946 };
7947
7948 /* toggle front-jack and RCA according to the hp-jack state */
7949 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7950 {
7951         unsigned int present;
7952
7953         present = snd_hda_codec_read(codec, 0x1b, 0,
7954                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7955         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7956                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7957         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7958                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7959 }
7960
7961 /* toggle RCA according to the front-jack state */
7962 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7963 {
7964         unsigned int present;
7965
7966         present = snd_hda_codec_read(codec, 0x14, 0,
7967                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7968         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7969                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7970 }
7971
7972 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7973                                              unsigned int res)
7974 {
7975         if ((res >> 26) == ALC880_HP_EVENT)
7976                 alc888_lenovo_ms7195_front_automute(codec);
7977         if ((res >> 26) == ALC880_FRONT_EVENT)
7978                 alc888_lenovo_ms7195_rca_automute(codec);
7979 }
7980
7981 static struct hda_verb alc883_medion_md2_verbs[] = {
7982         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7983         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7984
7985         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7986
7987         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7988         { } /* end */
7989 };
7990
7991 /* toggle speaker-output according to the hp-jack state */
7992 static void alc883_medion_md2_automute(struct hda_codec *codec)
7993 {
7994         unsigned int present;
7995
7996         present = snd_hda_codec_read(codec, 0x14, 0,
7997                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7998         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7999                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8000 }
8001
8002 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
8003                                           unsigned int res)
8004 {
8005         if ((res >> 26) == ALC880_HP_EVENT)
8006                 alc883_medion_md2_automute(codec);
8007 }
8008
8009 /* toggle speaker-output according to the hp-jack state */
8010 static void alc883_tagra_automute(struct hda_codec *codec)
8011 {
8012         unsigned int present;
8013         unsigned char bits;
8014
8015         present = snd_hda_codec_read(codec, 0x14, 0,
8016                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8017         bits = present ? HDA_AMP_MUTE : 0;
8018         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8019                                  HDA_AMP_MUTE, bits);
8020         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
8021                                   present ? 1 : 3);
8022 }
8023
8024 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
8025 {
8026         if ((res >> 26) == ALC880_HP_EVENT)
8027                 alc883_tagra_automute(codec);
8028 }
8029
8030 /* toggle speaker-output according to the hp-jack state */
8031 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
8032 {
8033         unsigned int present;
8034         unsigned char bits;
8035
8036         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
8037                 & AC_PINSENSE_PRESENCE;
8038         bits = present ? HDA_AMP_MUTE : 0;
8039         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8040                                  HDA_AMP_MUTE, bits);
8041 }
8042
8043 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8044 {
8045         unsigned int present;
8046
8047         present = snd_hda_codec_read(codec, 0x18, 0,
8048                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8049         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8050                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8051 }
8052
8053 static void alc883_clevo_m720_automute(struct hda_codec *codec)
8054 {
8055         alc883_clevo_m720_hp_automute(codec);
8056         alc883_clevo_m720_mic_automute(codec);
8057 }
8058
8059 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8060                                            unsigned int res)
8061 {
8062         switch (res >> 26) {
8063         case ALC880_HP_EVENT:
8064                 alc883_clevo_m720_hp_automute(codec);
8065                 break;
8066         case ALC880_MIC_EVENT:
8067                 alc883_clevo_m720_mic_automute(codec);
8068                 break;
8069         }
8070 }
8071
8072 /* toggle speaker-output according to the hp-jack state */
8073 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
8074 {
8075         unsigned int present;
8076         unsigned char bits;
8077
8078         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8079                 & AC_PINSENSE_PRESENCE;
8080         bits = present ? HDA_AMP_MUTE : 0;
8081         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8082                                  HDA_AMP_MUTE, bits);
8083 }
8084
8085 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
8086                                                   unsigned int res)
8087 {
8088         if ((res >> 26) == ALC880_HP_EVENT)
8089                 alc883_2ch_fujitsu_pi2515_automute(codec);
8090 }
8091
8092 static void alc883_haier_w66_automute(struct hda_codec *codec)
8093 {
8094         unsigned int present;
8095         unsigned char bits;
8096
8097         present = snd_hda_codec_read(codec, 0x1b, 0,
8098                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8099         bits = present ? 0x80 : 0;
8100         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8101                                  0x80, bits);
8102 }
8103
8104 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
8105                                          unsigned int res)
8106 {
8107         if ((res >> 26) == ALC880_HP_EVENT)
8108                 alc883_haier_w66_automute(codec);
8109 }
8110
8111 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8112 {
8113         unsigned int present;
8114         unsigned char bits;
8115
8116         present = snd_hda_codec_read(codec, 0x14, 0,
8117                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8118         bits = present ? HDA_AMP_MUTE : 0;
8119         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8120                                  HDA_AMP_MUTE, bits);
8121 }
8122
8123 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8124 {
8125         unsigned int present;
8126         unsigned char bits;
8127
8128         present = snd_hda_codec_read(codec, 0x1b, 0,
8129                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8130         bits = present ? HDA_AMP_MUTE : 0;
8131         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8132                                  HDA_AMP_MUTE, bits);
8133         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8134                                  HDA_AMP_MUTE, bits);
8135 }
8136
8137 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8138                                            unsigned int res)
8139 {
8140         if ((res >> 26) == ALC880_HP_EVENT)
8141                 alc883_lenovo_101e_all_automute(codec);
8142         if ((res >> 26) == ALC880_FRONT_EVENT)
8143                 alc883_lenovo_101e_ispeaker_automute(codec);
8144 }
8145
8146 /* toggle speaker-output according to the hp-jack state */
8147 static void alc883_acer_aspire_automute(struct hda_codec *codec)
8148 {
8149         unsigned int present;
8150
8151         present = snd_hda_codec_read(codec, 0x14, 0,
8152                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8153         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8154                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8155         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8156                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8157 }
8158
8159 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
8160                                            unsigned int res)
8161 {
8162         if ((res >> 26) == ALC880_HP_EVENT)
8163                 alc883_acer_aspire_automute(codec);
8164 }
8165
8166 static struct hda_verb alc883_acer_eapd_verbs[] = {
8167         /* HP Pin: output 0 (0x0c) */
8168         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8169         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8170         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8171         /* Front Pin: output 0 (0x0c) */
8172         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8173         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8174         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8175         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8176         /* eanable EAPD on medion laptop */
8177         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8178         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8179         /* enable unsolicited event */
8180         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8181         { }
8182 };
8183
8184 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
8185 {
8186         unsigned int present;
8187
8188         present = snd_hda_codec_read(codec, 0x1b, 0,
8189                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8190         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8191                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8192         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8193                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8194         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8195                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8196         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8197                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8198 }
8199
8200 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8201                                              unsigned int res)
8202 {
8203         switch (res >> 26) {
8204         case ALC880_HP_EVENT:
8205                 printk("hp_event\n");
8206                 alc888_6st_dell_front_automute(codec);
8207                 break;
8208         }
8209 }
8210
8211 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8212 {
8213         unsigned int mute;
8214         unsigned int present;
8215
8216         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8217         present = snd_hda_codec_read(codec, 0x1b, 0,
8218                                      AC_VERB_GET_PIN_SENSE, 0);
8219         present = (present & 0x80000000) != 0;
8220         if (present) {
8221                 /* mute internal speaker */
8222                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8223                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8224                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8225                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8226                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8227                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8228                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8229                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8230                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8231                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8232         } else {
8233                 /* unmute internal speaker if necessary */
8234                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8235                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8236                                          HDA_AMP_MUTE, mute);
8237                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8238                                          HDA_AMP_MUTE, mute);
8239                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8240                                          HDA_AMP_MUTE, mute);
8241                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8242                                          HDA_AMP_MUTE, mute);
8243                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8244                                          HDA_AMP_MUTE, mute);
8245         }
8246 }
8247
8248 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8249                                              unsigned int res)
8250 {
8251         if ((res >> 26) == ALC880_HP_EVENT)
8252                 alc888_lenovo_sky_front_automute(codec);
8253 }
8254
8255 /*
8256  * generic initialization of ADC, input mixers and output mixers
8257  */
8258 static struct hda_verb alc883_auto_init_verbs[] = {
8259         /*
8260          * Unmute ADC0-2 and set the default input to mic-in
8261          */
8262         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8263         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8264         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8265         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8266
8267         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8268          * mixer widget
8269          * Note: PASD motherboards uses the Line In 2 as the input for
8270          * front panel mic (mic 2)
8271          */
8272         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8273         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8274         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8275         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8276         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8277         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8278
8279         /*
8280          * Set up output mixers (0x0c - 0x0f)
8281          */
8282         /* set vol=0 to output mixers */
8283         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8284         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8285         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8286         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8287         /* set up input amps for analog loopback */
8288         /* Amp Indices: DAC = 0, mixer = 1 */
8289         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8290         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8291         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8292         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8293         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8294         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8295         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8296         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8297         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8298         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8299
8300         /* FIXME: use matrix-type input source selection */
8301         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8302         /* Input mixer1 */
8303         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8304         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8305         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8306         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8307         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8308         /* Input mixer2 */
8309         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8310         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8311         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8312         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8313         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8314
8315         { }
8316 };
8317
8318 static struct hda_verb alc888_asus_m90v_verbs[] = {
8319         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8320         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8321         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8322         /* enable unsolicited event */
8323         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8324         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8325         { } /* end */
8326 };
8327
8328 static void alc883_nb_mic_automute(struct hda_codec *codec)
8329 {
8330         unsigned int present;
8331
8332         present = snd_hda_codec_read(codec, 0x18, 0,
8333                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8334         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8335                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8336         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8337                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8338 }
8339
8340 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8341 {
8342         unsigned int present;
8343         unsigned char bits;
8344
8345         present = snd_hda_codec_read(codec, 0x1b, 0,
8346                                      AC_VERB_GET_PIN_SENSE, 0)
8347                 & AC_PINSENSE_PRESENCE;
8348         bits = present ? 0 : PIN_OUT;
8349         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8350                             bits);
8351         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8352                             bits);
8353         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8354                             bits);
8355 }
8356
8357 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8358                                            unsigned int res)
8359 {
8360         switch (res >> 26) {
8361         case ALC880_HP_EVENT:
8362                 alc883_M90V_speaker_automute(codec);
8363                 break;
8364         case ALC880_MIC_EVENT:
8365                 alc883_nb_mic_automute(codec);
8366                 break;
8367         }
8368 }
8369
8370 static void alc883_mode2_inithook(struct hda_codec *codec)
8371 {
8372         alc883_M90V_speaker_automute(codec);
8373         alc883_nb_mic_automute(codec);
8374 }
8375
8376 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8377         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8378         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8379         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8380         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8381         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8382         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8383         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8384         /* enable unsolicited event */
8385         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8386         { } /* end */
8387 };
8388
8389 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8390 {
8391         unsigned int present;
8392         unsigned char bits;
8393
8394         present = snd_hda_codec_read(codec, 0x14, 0,
8395                                      AC_VERB_GET_PIN_SENSE, 0)
8396                 & AC_PINSENSE_PRESENCE;
8397         bits = present ? 0 : PIN_OUT;
8398         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8399                             bits);
8400 }
8401
8402 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8403                                            unsigned int res)
8404 {
8405         switch (res >> 26) {
8406         case ALC880_HP_EVENT:
8407                 alc883_eee1601_speaker_automute(codec);
8408                 break;
8409         }
8410 }
8411
8412 static void alc883_eee1601_inithook(struct hda_codec *codec)
8413 {
8414         alc883_eee1601_speaker_automute(codec);
8415 }
8416
8417 #ifdef CONFIG_SND_HDA_POWER_SAVE
8418 #define alc883_loopbacks        alc880_loopbacks
8419 #endif
8420
8421 /* pcm configuration: identiacal with ALC880 */
8422 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8423 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8424 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8425 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8426 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8427
8428 /*
8429  * configuration and preset
8430  */
8431 static const char *alc883_models[ALC883_MODEL_LAST] = {
8432         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8433         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8434         [ALC883_3ST_6ch]        = "3stack-6ch",
8435         [ALC883_6ST_DIG]        = "6stack-dig",
8436         [ALC883_TARGA_DIG]      = "targa-dig",
8437         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8438         [ALC883_ACER]           = "acer",
8439         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8440         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8441         [ALC883_MEDION]         = "medion",
8442         [ALC883_MEDION_MD2]     = "medion-md2",
8443         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8444         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8445         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8446         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8447         [ALC888_LENOVO_SKY] = "lenovo-sky",
8448         [ALC883_HAIER_W66]      = "haier-w66",
8449         [ALC888_3ST_HP]         = "3stack-hp",
8450         [ALC888_6ST_DELL]       = "6stack-dell",
8451         [ALC883_MITAC]          = "mitac",
8452         [ALC883_CLEVO_M720]     = "clevo-m720",
8453         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8454         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8455         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8456         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8457         [ALC883_AUTO]           = "auto",
8458 };
8459
8460 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8461         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8462         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8463         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8464         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8465         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8466         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8467         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8468                 ALC888_ACER_ASPIRE_4930G),
8469         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
8470                 ALC888_ACER_ASPIRE_4930G),
8471         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
8472                 ALC888_ACER_ASPIRE_4930G),
8473         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
8474                 ALC888_ACER_ASPIRE_4930G),
8475         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8476         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8477         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8478         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8479         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8480         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8481         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
8482         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8483         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8484         SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
8485         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8486         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8487         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8488         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8489         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
8490         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8491         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8492         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8493         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8494         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8495         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8496         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8497         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8498         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8499         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8500         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8501         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8502         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8503         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8504         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8505         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8506         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8507         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8508         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8509         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8510         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8511         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8512         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8513         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8514         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8515         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8516         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8517         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8518         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8519         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8520         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8521         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8522         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8523         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8524         SND_PCI_QUIRK(0x1734, 0x1107, "FSC AMILO Xi2550",
8525                       ALC883_FUJITSU_PI2515),
8526         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8527         SND_PCI_QUIRK(0x1734, 0x113d, "Fujitsu AMILO Xa3530",
8528                 ALC888_FUJITSU_XA3530),
8529         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8530         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8531         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8532         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8533         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8534         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8535         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8536         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8537         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8538         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8539         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8540         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
8541         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC883_3ST_6ch_INTEL),
8542         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8543         {}
8544 };
8545
8546 static struct alc_config_preset alc883_presets[] = {
8547         [ALC883_3ST_2ch_DIG] = {
8548                 .mixers = { alc883_3ST_2ch_mixer },
8549                 .init_verbs = { alc883_init_verbs },
8550                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8551                 .dac_nids = alc883_dac_nids,
8552                 .dig_out_nid = ALC883_DIGOUT_NID,
8553                 .dig_in_nid = ALC883_DIGIN_NID,
8554                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8555                 .channel_mode = alc883_3ST_2ch_modes,
8556                 .input_mux = &alc883_capture_source,
8557         },
8558         [ALC883_3ST_6ch_DIG] = {
8559                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8560                 .init_verbs = { alc883_init_verbs },
8561                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8562                 .dac_nids = alc883_dac_nids,
8563                 .dig_out_nid = ALC883_DIGOUT_NID,
8564                 .dig_in_nid = ALC883_DIGIN_NID,
8565                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8566                 .channel_mode = alc883_3ST_6ch_modes,
8567                 .need_dac_fix = 1,
8568                 .input_mux = &alc883_capture_source,
8569         },
8570         [ALC883_3ST_6ch] = {
8571                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8572                 .init_verbs = { alc883_init_verbs },
8573                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8574                 .dac_nids = alc883_dac_nids,
8575                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8576                 .channel_mode = alc883_3ST_6ch_modes,
8577                 .need_dac_fix = 1,
8578                 .input_mux = &alc883_capture_source,
8579         },
8580         [ALC883_3ST_6ch_INTEL] = {
8581                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8582                 .init_verbs = { alc883_init_verbs },
8583                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8584                 .dac_nids = alc883_dac_nids,
8585                 .dig_out_nid = ALC883_DIGOUT_NID,
8586                 .dig_in_nid = ALC883_DIGIN_NID,
8587                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8588                 .channel_mode = alc883_3ST_6ch_intel_modes,
8589                 .need_dac_fix = 1,
8590                 .input_mux = &alc883_3stack_6ch_intel,
8591         },
8592         [ALC883_6ST_DIG] = {
8593                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8594                 .init_verbs = { alc883_init_verbs },
8595                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8596                 .dac_nids = alc883_dac_nids,
8597                 .dig_out_nid = ALC883_DIGOUT_NID,
8598                 .dig_in_nid = ALC883_DIGIN_NID,
8599                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8600                 .channel_mode = alc883_sixstack_modes,
8601                 .input_mux = &alc883_capture_source,
8602         },
8603         [ALC883_TARGA_DIG] = {
8604                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8605                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8606                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8607                 .dac_nids = alc883_dac_nids,
8608                 .dig_out_nid = ALC883_DIGOUT_NID,
8609                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8610                 .channel_mode = alc883_3ST_6ch_modes,
8611                 .need_dac_fix = 1,
8612                 .input_mux = &alc883_capture_source,
8613                 .unsol_event = alc883_tagra_unsol_event,
8614                 .init_hook = alc883_tagra_automute,
8615         },
8616         [ALC883_TARGA_2ch_DIG] = {
8617                 .mixers = { alc883_tagra_2ch_mixer},
8618                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8619                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8620                 .dac_nids = alc883_dac_nids,
8621                 .adc_nids = alc883_adc_nids_alt,
8622                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8623                 .dig_out_nid = ALC883_DIGOUT_NID,
8624                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8625                 .channel_mode = alc883_3ST_2ch_modes,
8626                 .input_mux = &alc883_capture_source,
8627                 .unsol_event = alc883_tagra_unsol_event,
8628                 .init_hook = alc883_tagra_automute,
8629         },
8630         [ALC883_ACER] = {
8631                 .mixers = { alc883_base_mixer },
8632                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8633                  * and the headphone jack.  Turn this on and rely on the
8634                  * standard mute methods whenever the user wants to turn
8635                  * these outputs off.
8636                  */
8637                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8638                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8639                 .dac_nids = alc883_dac_nids,
8640                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8641                 .channel_mode = alc883_3ST_2ch_modes,
8642                 .input_mux = &alc883_capture_source,
8643         },
8644         [ALC883_ACER_ASPIRE] = {
8645                 .mixers = { alc883_acer_aspire_mixer },
8646                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8647                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8648                 .dac_nids = alc883_dac_nids,
8649                 .dig_out_nid = ALC883_DIGOUT_NID,
8650                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8651                 .channel_mode = alc883_3ST_2ch_modes,
8652                 .input_mux = &alc883_capture_source,
8653                 .unsol_event = alc883_acer_aspire_unsol_event,
8654                 .init_hook = alc883_acer_aspire_automute,
8655         },
8656         [ALC888_ACER_ASPIRE_4930G] = {
8657                 .mixers = { alc888_base_mixer,
8658                                 alc883_chmode_mixer },
8659                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
8660                                 alc888_acer_aspire_4930g_verbs },
8661                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8662                 .dac_nids = alc883_dac_nids,
8663                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8664                 .adc_nids = alc883_adc_nids_rev,
8665                 .capsrc_nids = alc883_capsrc_nids_rev,
8666                 .dig_out_nid = ALC883_DIGOUT_NID,
8667                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8668                 .channel_mode = alc883_3ST_6ch_modes,
8669                 .need_dac_fix = 1,
8670                 .num_mux_defs =
8671                         ARRAY_SIZE(alc888_2_capture_sources),
8672                 .input_mux = alc888_2_capture_sources,
8673                 .unsol_event = alc888_acer_aspire_4930g_unsol_event,
8674                 .init_hook = alc888_acer_aspire_4930g_automute,
8675         },
8676         [ALC883_MEDION] = {
8677                 .mixers = { alc883_fivestack_mixer,
8678                             alc883_chmode_mixer },
8679                 .init_verbs = { alc883_init_verbs,
8680                                 alc883_medion_eapd_verbs },
8681                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8682                 .dac_nids = alc883_dac_nids,
8683                 .adc_nids = alc883_adc_nids_alt,
8684                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8685                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8686                 .channel_mode = alc883_sixstack_modes,
8687                 .input_mux = &alc883_capture_source,
8688         },
8689         [ALC883_MEDION_MD2] = {
8690                 .mixers = { alc883_medion_md2_mixer},
8691                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8692                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8693                 .dac_nids = alc883_dac_nids,
8694                 .dig_out_nid = ALC883_DIGOUT_NID,
8695                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8696                 .channel_mode = alc883_3ST_2ch_modes,
8697                 .input_mux = &alc883_capture_source,
8698                 .unsol_event = alc883_medion_md2_unsol_event,
8699                 .init_hook = alc883_medion_md2_automute,
8700         },
8701         [ALC883_LAPTOP_EAPD] = {
8702                 .mixers = { alc883_base_mixer },
8703                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8704                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8705                 .dac_nids = alc883_dac_nids,
8706                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8707                 .channel_mode = alc883_3ST_2ch_modes,
8708                 .input_mux = &alc883_capture_source,
8709         },
8710         [ALC883_CLEVO_M720] = {
8711                 .mixers = { alc883_clevo_m720_mixer },
8712                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8713                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8714                 .dac_nids = alc883_dac_nids,
8715                 .dig_out_nid = ALC883_DIGOUT_NID,
8716                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8717                 .channel_mode = alc883_3ST_2ch_modes,
8718                 .input_mux = &alc883_capture_source,
8719                 .unsol_event = alc883_clevo_m720_unsol_event,
8720                 .init_hook = alc883_clevo_m720_automute,
8721         },
8722         [ALC883_LENOVO_101E_2ch] = {
8723                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8724                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8725                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8726                 .dac_nids = alc883_dac_nids,
8727                 .adc_nids = alc883_adc_nids_alt,
8728                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8729                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8730                 .channel_mode = alc883_3ST_2ch_modes,
8731                 .input_mux = &alc883_lenovo_101e_capture_source,
8732                 .unsol_event = alc883_lenovo_101e_unsol_event,
8733                 .init_hook = alc883_lenovo_101e_all_automute,
8734         },
8735         [ALC883_LENOVO_NB0763] = {
8736                 .mixers = { alc883_lenovo_nb0763_mixer },
8737                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8738                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8739                 .dac_nids = alc883_dac_nids,
8740                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8741                 .channel_mode = alc883_3ST_2ch_modes,
8742                 .need_dac_fix = 1,
8743                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8744                 .unsol_event = alc883_medion_md2_unsol_event,
8745                 .init_hook = alc883_medion_md2_automute,
8746         },
8747         [ALC888_LENOVO_MS7195_DIG] = {
8748                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8749                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8750                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8751                 .dac_nids = alc883_dac_nids,
8752                 .dig_out_nid = ALC883_DIGOUT_NID,
8753                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8754                 .channel_mode = alc883_3ST_6ch_modes,
8755                 .need_dac_fix = 1,
8756                 .input_mux = &alc883_capture_source,
8757                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8758                 .init_hook = alc888_lenovo_ms7195_front_automute,
8759         },
8760         [ALC883_HAIER_W66] = {
8761                 .mixers = { alc883_tagra_2ch_mixer},
8762                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8763                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8764                 .dac_nids = alc883_dac_nids,
8765                 .dig_out_nid = ALC883_DIGOUT_NID,
8766                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8767                 .channel_mode = alc883_3ST_2ch_modes,
8768                 .input_mux = &alc883_capture_source,
8769                 .unsol_event = alc883_haier_w66_unsol_event,
8770                 .init_hook = alc883_haier_w66_automute,
8771         },
8772         [ALC888_3ST_HP] = {
8773                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8774                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8775                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8776                 .dac_nids = alc883_dac_nids,
8777                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8778                 .channel_mode = alc888_3st_hp_modes,
8779                 .need_dac_fix = 1,
8780                 .input_mux = &alc883_capture_source,
8781         },
8782         [ALC888_6ST_DELL] = {
8783                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8784                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8785                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8786                 .dac_nids = alc883_dac_nids,
8787                 .dig_out_nid = ALC883_DIGOUT_NID,
8788                 .dig_in_nid = ALC883_DIGIN_NID,
8789                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8790                 .channel_mode = alc883_sixstack_modes,
8791                 .input_mux = &alc883_capture_source,
8792                 .unsol_event = alc888_6st_dell_unsol_event,
8793                 .init_hook = alc888_6st_dell_front_automute,
8794         },
8795         [ALC883_MITAC] = {
8796                 .mixers = { alc883_mitac_mixer },
8797                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8798                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8799                 .dac_nids = alc883_dac_nids,
8800                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8801                 .channel_mode = alc883_3ST_2ch_modes,
8802                 .input_mux = &alc883_capture_source,
8803                 .unsol_event = alc883_mitac_unsol_event,
8804                 .init_hook = alc883_mitac_automute,
8805         },
8806         [ALC883_FUJITSU_PI2515] = {
8807                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8808                 .init_verbs = { alc883_init_verbs,
8809                                 alc883_2ch_fujitsu_pi2515_verbs},
8810                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8811                 .dac_nids = alc883_dac_nids,
8812                 .dig_out_nid = ALC883_DIGOUT_NID,
8813                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8814                 .channel_mode = alc883_3ST_2ch_modes,
8815                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8816                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8817                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8818         },
8819         [ALC888_FUJITSU_XA3530] = {
8820                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
8821                 .init_verbs = { alc883_init_verbs,
8822                         alc888_fujitsu_xa3530_verbs },
8823                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8824                 .dac_nids = alc883_dac_nids,
8825                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8826                 .adc_nids = alc883_adc_nids_rev,
8827                 .capsrc_nids = alc883_capsrc_nids_rev,
8828                 .dig_out_nid = ALC883_DIGOUT_NID,
8829                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
8830                 .channel_mode = alc888_4ST_8ch_intel_modes,
8831                 .num_mux_defs =
8832                         ARRAY_SIZE(alc888_2_capture_sources),
8833                 .input_mux = alc888_2_capture_sources,
8834                 .unsol_event = alc888_fujitsu_xa3530_unsol_event,
8835                 .init_hook = alc888_fujitsu_xa3530_automute,
8836         },
8837         [ALC888_LENOVO_SKY] = {
8838                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8839                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8840                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8841                 .dac_nids = alc883_dac_nids,
8842                 .dig_out_nid = ALC883_DIGOUT_NID,
8843                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8844                 .channel_mode = alc883_sixstack_modes,
8845                 .need_dac_fix = 1,
8846                 .input_mux = &alc883_lenovo_sky_capture_source,
8847                 .unsol_event = alc883_lenovo_sky_unsol_event,
8848                 .init_hook = alc888_lenovo_sky_front_automute,
8849         },
8850         [ALC888_ASUS_M90V] = {
8851                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8852                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8853                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8854                 .dac_nids = alc883_dac_nids,
8855                 .dig_out_nid = ALC883_DIGOUT_NID,
8856                 .dig_in_nid = ALC883_DIGIN_NID,
8857                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8858                 .channel_mode = alc883_3ST_6ch_modes,
8859                 .need_dac_fix = 1,
8860                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8861                 .unsol_event = alc883_mode2_unsol_event,
8862                 .init_hook = alc883_mode2_inithook,
8863         },
8864         [ALC888_ASUS_EEE1601] = {
8865                 .mixers = { alc883_asus_eee1601_mixer },
8866                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
8867                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8868                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8869                 .dac_nids = alc883_dac_nids,
8870                 .dig_out_nid = ALC883_DIGOUT_NID,
8871                 .dig_in_nid = ALC883_DIGIN_NID,
8872                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8873                 .channel_mode = alc883_3ST_2ch_modes,
8874                 .need_dac_fix = 1,
8875                 .input_mux = &alc883_asus_eee1601_capture_source,
8876                 .unsol_event = alc883_eee1601_unsol_event,
8877                 .init_hook = alc883_eee1601_inithook,
8878         },
8879         [ALC1200_ASUS_P5Q] = {
8880                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8881                 .init_verbs = { alc883_init_verbs },
8882                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8883                 .dac_nids = alc883_dac_nids,
8884                 .dig_out_nid = ALC1200_DIGOUT_NID,
8885                 .dig_in_nid = ALC883_DIGIN_NID,
8886                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8887                 .channel_mode = alc883_sixstack_modes,
8888                 .input_mux = &alc883_capture_source,
8889         },
8890 };
8891
8892
8893 /*
8894  * BIOS auto configuration
8895  */
8896 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8897                                               hda_nid_t nid, int pin_type,
8898                                               int dac_idx)
8899 {
8900         /* set as output */
8901         struct alc_spec *spec = codec->spec;
8902         int idx;
8903
8904         alc_set_pin_output(codec, nid, pin_type);
8905         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8906                 idx = 4;
8907         else
8908                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8909         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8910
8911 }
8912
8913 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8914 {
8915         struct alc_spec *spec = codec->spec;
8916         int i;
8917
8918         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8919         for (i = 0; i <= HDA_SIDE; i++) {
8920                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8921                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8922                 if (nid)
8923                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8924                                                           i);
8925         }
8926 }
8927
8928 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8929 {
8930         struct alc_spec *spec = codec->spec;
8931         hda_nid_t pin;
8932
8933         pin = spec->autocfg.hp_pins[0];
8934         if (pin) /* connect to front */
8935                 /* use dac 0 */
8936                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8937         pin = spec->autocfg.speaker_pins[0];
8938         if (pin)
8939                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8940 }
8941
8942 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8943 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8944
8945 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8946 {
8947         struct alc_spec *spec = codec->spec;
8948         int i;
8949
8950         for (i = 0; i < AUTO_PIN_LAST; i++) {
8951                 hda_nid_t nid = spec->autocfg.input_pins[i];
8952                 if (alc883_is_input_pin(nid)) {
8953                         snd_hda_codec_write(codec, nid, 0,
8954                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8955                                             (i <= AUTO_PIN_FRONT_MIC ?
8956                                              PIN_VREF80 : PIN_IN));
8957                         if (nid != ALC883_PIN_CD_NID)
8958                                 snd_hda_codec_write(codec, nid, 0,
8959                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8960                                                     AMP_OUT_MUTE);
8961                 }
8962         }
8963 }
8964
8965 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8966
8967 /* almost identical with ALC880 parser... */
8968 static int alc883_parse_auto_config(struct hda_codec *codec)
8969 {
8970         struct alc_spec *spec = codec->spec;
8971         int err = alc880_parse_auto_config(codec);
8972
8973         if (err < 0)
8974                 return err;
8975         else if (!err)
8976                 return 0; /* no config found */
8977
8978         err = alc_auto_add_mic_boost(codec);
8979         if (err < 0)
8980                 return err;
8981
8982         /* hack - override the init verbs */
8983         spec->init_verbs[0] = alc883_auto_init_verbs;
8984
8985         return 1; /* config found */
8986 }
8987
8988 /* additional initialization for auto-configuration model */
8989 static void alc883_auto_init(struct hda_codec *codec)
8990 {
8991         struct alc_spec *spec = codec->spec;
8992         alc883_auto_init_multi_out(codec);
8993         alc883_auto_init_hp_out(codec);
8994         alc883_auto_init_analog_input(codec);
8995         alc883_auto_init_input_src(codec);
8996         if (spec->unsol_event)
8997                 alc_inithook(codec);
8998 }
8999
9000 static int patch_alc883(struct hda_codec *codec)
9001 {
9002         struct alc_spec *spec;
9003         int err, board_config;
9004
9005         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9006         if (spec == NULL)
9007                 return -ENOMEM;
9008
9009         codec->spec = spec;
9010
9011         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9012
9013         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
9014                                                   alc883_models,
9015                                                   alc883_cfg_tbl);
9016         if (board_config < 0) {
9017                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
9018                        "trying auto-probe from BIOS...\n");
9019                 board_config = ALC883_AUTO;
9020         }
9021
9022         if (board_config == ALC883_AUTO) {
9023                 /* automatic parse from the BIOS config */
9024                 err = alc883_parse_auto_config(codec);
9025                 if (err < 0) {
9026                         alc_free(codec);
9027                         return err;
9028                 } else if (!err) {
9029                         printk(KERN_INFO
9030                                "hda_codec: Cannot set up configuration "
9031                                "from BIOS.  Using base mode...\n");
9032                         board_config = ALC883_3ST_2ch_DIG;
9033                 }
9034         }
9035
9036         if (board_config != ALC883_AUTO)
9037                 setup_preset(spec, &alc883_presets[board_config]);
9038
9039         switch (codec->vendor_id) {
9040         case 0x10ec0888:
9041                 if (codec->revision_id == 0x100101) {
9042                         spec->stream_name_analog = "ALC1200 Analog";
9043                         spec->stream_name_digital = "ALC1200 Digital";
9044                 } else {
9045                         spec->stream_name_analog = "ALC888 Analog";
9046                         spec->stream_name_digital = "ALC888 Digital";
9047                 }
9048                 break;
9049         case 0x10ec0889:
9050                 spec->stream_name_analog = "ALC889 Analog";
9051                 spec->stream_name_digital = "ALC889 Digital";
9052                 break;
9053         default:
9054                 spec->stream_name_analog = "ALC883 Analog";
9055                 spec->stream_name_digital = "ALC883 Digital";
9056                 break;
9057         }
9058
9059         spec->stream_analog_playback = &alc883_pcm_analog_playback;
9060         spec->stream_analog_capture = &alc883_pcm_analog_capture;
9061         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9062
9063         spec->stream_digital_playback = &alc883_pcm_digital_playback;
9064         spec->stream_digital_capture = &alc883_pcm_digital_capture;
9065
9066         if (!spec->num_adc_nids) {
9067                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9068                 spec->adc_nids = alc883_adc_nids;
9069         }
9070         if (!spec->capsrc_nids)
9071                 spec->capsrc_nids = alc883_capsrc_nids;
9072         spec->is_mix_capture = 1; /* matrix-style capture */
9073         if (!spec->cap_mixer)
9074                 set_capture_mixer(spec);
9075
9076         spec->vmaster_nid = 0x0c;
9077
9078         codec->patch_ops = alc_patch_ops;
9079         if (board_config == ALC883_AUTO)
9080                 spec->init_hook = alc883_auto_init;
9081
9082 #ifdef CONFIG_SND_HDA_POWER_SAVE
9083         if (!spec->loopback.amplist)
9084                 spec->loopback.amplist = alc883_loopbacks;
9085 #endif
9086         codec->proc_widget_hook = print_realtek_coef;
9087
9088         return 0;
9089 }
9090
9091 /*
9092  * ALC262 support
9093  */
9094
9095 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9096 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9097
9098 #define alc262_dac_nids         alc260_dac_nids
9099 #define alc262_adc_nids         alc882_adc_nids
9100 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9101 #define alc262_capsrc_nids      alc882_capsrc_nids
9102 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9103
9104 #define alc262_modes            alc260_modes
9105 #define alc262_capture_source   alc882_capture_source
9106
9107 static hda_nid_t alc262_dmic_adc_nids[1] = {
9108         /* ADC0 */
9109         0x09
9110 };
9111
9112 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9113
9114 static struct snd_kcontrol_new alc262_base_mixer[] = {
9115         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9116         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9117         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9118         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9119         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9120         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9121         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9122         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9123         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9124         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9125         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9126         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9127         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9128            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9129         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9130         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9131         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9132         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9133         { } /* end */
9134 };
9135
9136 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
9137         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9138         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9139         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9140         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9141         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9142         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9143         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9144         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9145         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9146         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9147         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9148         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9149         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9150            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9151         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
9152         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9153         { } /* end */
9154 };
9155
9156 /* update HP, line and mono-out pins according to the master switch */
9157 static void alc262_hp_master_update(struct hda_codec *codec)
9158 {
9159         struct alc_spec *spec = codec->spec;
9160         int val = spec->master_sw;
9161
9162         /* HP & line-out */
9163         snd_hda_codec_write_cache(codec, 0x1b, 0,
9164                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9165                                   val ? PIN_HP : 0);
9166         snd_hda_codec_write_cache(codec, 0x15, 0,
9167                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9168                                   val ? PIN_HP : 0);
9169         /* mono (speaker) depending on the HP jack sense */
9170         val = val && !spec->jack_present;
9171         snd_hda_codec_write_cache(codec, 0x16, 0,
9172                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9173                                   val ? PIN_OUT : 0);
9174 }
9175
9176 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9177 {
9178         struct alc_spec *spec = codec->spec;
9179         unsigned int presence;
9180         presence = snd_hda_codec_read(codec, 0x1b, 0,
9181                                       AC_VERB_GET_PIN_SENSE, 0);
9182         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9183         alc262_hp_master_update(codec);
9184 }
9185
9186 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9187 {
9188         if ((res >> 26) != ALC880_HP_EVENT)
9189                 return;
9190         alc262_hp_bpc_automute(codec);
9191 }
9192
9193 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9194 {
9195         struct alc_spec *spec = codec->spec;
9196         unsigned int presence;
9197         presence = snd_hda_codec_read(codec, 0x15, 0,
9198                                       AC_VERB_GET_PIN_SENSE, 0);
9199         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9200         alc262_hp_master_update(codec);
9201 }
9202
9203 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9204                                            unsigned int res)
9205 {
9206         if ((res >> 26) != ALC880_HP_EVENT)
9207                 return;
9208         alc262_hp_wildwest_automute(codec);
9209 }
9210
9211 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
9212                                    struct snd_ctl_elem_value *ucontrol)
9213 {
9214         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9215         struct alc_spec *spec = codec->spec;
9216         *ucontrol->value.integer.value = spec->master_sw;
9217         return 0;
9218 }
9219
9220 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9221                                    struct snd_ctl_elem_value *ucontrol)
9222 {
9223         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9224         struct alc_spec *spec = codec->spec;
9225         int val = !!*ucontrol->value.integer.value;
9226
9227         if (val == spec->master_sw)
9228                 return 0;
9229         spec->master_sw = val;
9230         alc262_hp_master_update(codec);
9231         return 1;
9232 }
9233
9234 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9235         {
9236                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9237                 .name = "Master Playback Switch",
9238                 .info = snd_ctl_boolean_mono_info,
9239                 .get = alc262_hp_master_sw_get,
9240                 .put = alc262_hp_master_sw_put,
9241         },
9242         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9243         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9244         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9245         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9246                               HDA_OUTPUT),
9247         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9248                             HDA_OUTPUT),
9249         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9250         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9251         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9252         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9253         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9254         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9255         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9256         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9257         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9258         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9259         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9260         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9261         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9262         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9263         { } /* end */
9264 };
9265
9266 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9267         {
9268                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9269                 .name = "Master Playback Switch",
9270                 .info = snd_ctl_boolean_mono_info,
9271                 .get = alc262_hp_master_sw_get,
9272                 .put = alc262_hp_master_sw_put,
9273         },
9274         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9275         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9276         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9277         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9278         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9279                               HDA_OUTPUT),
9280         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9281                             HDA_OUTPUT),
9282         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9283         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9284         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9285         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9286         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9287         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9288         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9289         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9290         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9291         { } /* end */
9292 };
9293
9294 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9295         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9296         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9297         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9298         { } /* end */
9299 };
9300
9301 /* mute/unmute internal speaker according to the hp jack and mute state */
9302 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
9303 {
9304         struct alc_spec *spec = codec->spec;
9305
9306         if (force || !spec->sense_updated) {
9307                 unsigned int present;
9308                 present = snd_hda_codec_read(codec, 0x15, 0,
9309                                              AC_VERB_GET_PIN_SENSE, 0);
9310                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9311                 spec->sense_updated = 1;
9312         }
9313         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
9314                                  spec->jack_present ? HDA_AMP_MUTE : 0);
9315 }
9316
9317 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
9318                                         unsigned int res)
9319 {
9320         if ((res >> 26) != ALC880_HP_EVENT)
9321                 return;
9322         alc262_hp_t5735_automute(codec, 1);
9323 }
9324
9325 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9326 {
9327         alc262_hp_t5735_automute(codec, 1);
9328 }
9329
9330 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9331         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9332         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 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("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9336         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9337         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9338         { } /* end */
9339 };
9340
9341 static struct hda_verb alc262_hp_t5735_verbs[] = {
9342         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9343         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9344
9345         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9346         { }
9347 };
9348
9349 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9350         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9351         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9352         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9353         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9354         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9355         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9356         { } /* end */
9357 };
9358
9359 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9360         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9361         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9362         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9363         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9364         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9365         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9366         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9367         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9368         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9369         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9370         {}
9371 };
9372
9373 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9374         .num_items = 1,
9375         .items = {
9376                 { "Line", 0x1 },
9377         },
9378 };
9379
9380 /* bind hp and internal speaker mute (with plug check) */
9381 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9382                                      struct snd_ctl_elem_value *ucontrol)
9383 {
9384         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9385         long *valp = ucontrol->value.integer.value;
9386         int change;
9387
9388         /* change hp mute */
9389         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9390                                           HDA_AMP_MUTE,
9391                                           valp[0] ? 0 : HDA_AMP_MUTE);
9392         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9393                                            HDA_AMP_MUTE,
9394                                            valp[1] ? 0 : HDA_AMP_MUTE);
9395         if (change) {
9396                 /* change speaker according to HP jack state */
9397                 struct alc_spec *spec = codec->spec;
9398                 unsigned int mute;
9399                 if (spec->jack_present)
9400                         mute = HDA_AMP_MUTE;
9401                 else
9402                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9403                                                       HDA_OUTPUT, 0);
9404                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9405                                          HDA_AMP_MUTE, mute);
9406         }
9407         return change;
9408 }
9409
9410 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9411         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9412         {
9413                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9414                 .name = "Master Playback Switch",
9415                 .info = snd_hda_mixer_amp_switch_info,
9416                 .get = snd_hda_mixer_amp_switch_get,
9417                 .put = alc262_sony_master_sw_put,
9418                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9419         },
9420         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9421         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9422         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9423         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9424         { } /* end */
9425 };
9426
9427 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9428         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9429         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9430         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9431         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9432         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9433         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9434         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9435         { } /* end */
9436 };
9437
9438 #define alc262_capture_mixer            alc882_capture_mixer
9439 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9440
9441 /*
9442  * generic initialization of ADC, input mixers and output mixers
9443  */
9444 static struct hda_verb alc262_init_verbs[] = {
9445         /*
9446          * Unmute ADC0-2 and set the default input to mic-in
9447          */
9448         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9449         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9450         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9451         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9452         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9453         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9454
9455         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9456          * mixer widget
9457          * Note: PASD motherboards uses the Line In 2 as the input for
9458          * front panel mic (mic 2)
9459          */
9460         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9461         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9462         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9463         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9464         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9465         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9466
9467         /*
9468          * Set up output mixers (0x0c - 0x0e)
9469          */
9470         /* set vol=0 to output mixers */
9471         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9472         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9473         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9474         /* set up input amps for analog loopback */
9475         /* Amp Indices: DAC = 0, mixer = 1 */
9476         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9477         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9478         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9479         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9480         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9481         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9482
9483         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9484         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9485         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9486         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9487         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9488         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9489
9490         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9491         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9492         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9493         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9494         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9495
9496         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9497         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9498
9499         /* FIXME: use matrix-type input source selection */
9500         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9501         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9502         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9503         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9504         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9505         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9506         /* Input mixer2 */
9507         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9508         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9509         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9510         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9511         /* Input mixer3 */
9512         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9513         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9514         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9515         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9516
9517         { }
9518 };
9519
9520 static struct hda_verb alc262_eapd_verbs[] = {
9521         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9522         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9523         { }
9524 };
9525
9526 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9527         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9528         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9529         {}
9530 };
9531
9532 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9533         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9534         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9535         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9536
9537         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9538         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9539         {}
9540 };
9541
9542 static struct hda_verb alc262_sony_unsol_verbs[] = {
9543         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9544         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9545         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9546
9547         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9548         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9549         {}
9550 };
9551
9552 static struct hda_input_mux alc262_dmic_capture_source = {
9553         .num_items = 2,
9554         .items = {
9555                 { "Int DMic", 0x9 },
9556                 { "Mic", 0x0 },
9557         },
9558 };
9559
9560 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9561         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9562         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9563         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9564         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9565         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9566         { } /* end */
9567 };
9568
9569 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9570         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9571         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9572         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9573         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9574         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9575         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9576         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9577         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9578         {}
9579 };
9580
9581 static void alc262_dmic_automute(struct hda_codec *codec)
9582 {
9583         unsigned int present;
9584
9585         present = snd_hda_codec_read(codec, 0x18, 0,
9586                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9587         snd_hda_codec_write(codec, 0x22, 0,
9588                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9589 }
9590
9591 /* toggle speaker-output according to the hp-jack state */
9592 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9593 {
9594         unsigned int present;
9595         unsigned char bits;
9596
9597         present = snd_hda_codec_read(codec, 0x15, 0,
9598                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9599         bits = present ? 0 : PIN_OUT;
9600         snd_hda_codec_write(codec, 0x14, 0,
9601                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9602 }
9603
9604
9605
9606 /* unsolicited event for HP jack sensing */
9607 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9608                                        unsigned int res)
9609 {
9610         if ((res >> 26) == ALC880_HP_EVENT)
9611                 alc262_toshiba_s06_speaker_automute(codec);
9612         if ((res >> 26) == ALC880_MIC_EVENT)
9613                 alc262_dmic_automute(codec);
9614
9615 }
9616
9617 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9618 {
9619         alc262_toshiba_s06_speaker_automute(codec);
9620         alc262_dmic_automute(codec);
9621 }
9622
9623 /* mute/unmute internal speaker according to the hp jack and mute state */
9624 static void alc262_hippo_automute(struct hda_codec *codec)
9625 {
9626         struct alc_spec *spec = codec->spec;
9627         unsigned int mute;
9628         unsigned int present;
9629
9630         /* need to execute and sync at first */
9631         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9632         present = snd_hda_codec_read(codec, 0x15, 0,
9633                                      AC_VERB_GET_PIN_SENSE, 0);
9634         spec->jack_present = (present & 0x80000000) != 0;
9635         if (spec->jack_present) {
9636                 /* mute internal speaker */
9637                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9638                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9639         } else {
9640                 /* unmute internal speaker if necessary */
9641                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9642                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9643                                          HDA_AMP_MUTE, mute);
9644         }
9645 }
9646
9647 /* unsolicited event for HP jack sensing */
9648 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9649                                        unsigned int res)
9650 {
9651         if ((res >> 26) != ALC880_HP_EVENT)
9652                 return;
9653         alc262_hippo_automute(codec);
9654 }
9655
9656 static void alc262_hippo1_automute(struct hda_codec *codec)
9657 {
9658         unsigned int mute;
9659         unsigned int present;
9660
9661         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9662         present = snd_hda_codec_read(codec, 0x1b, 0,
9663                                      AC_VERB_GET_PIN_SENSE, 0);
9664         present = (present & 0x80000000) != 0;
9665         if (present) {
9666                 /* mute internal speaker */
9667                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9668                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9669         } else {
9670                 /* unmute internal speaker if necessary */
9671                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9672                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9673                                          HDA_AMP_MUTE, mute);
9674         }
9675 }
9676
9677 /* unsolicited event for HP jack sensing */
9678 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9679                                        unsigned int res)
9680 {
9681         if ((res >> 26) != ALC880_HP_EVENT)
9682                 return;
9683         alc262_hippo1_automute(codec);
9684 }
9685
9686 /*
9687  * nec model
9688  *  0x15 = headphone
9689  *  0x16 = internal speaker
9690  *  0x18 = external mic
9691  */
9692
9693 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9694         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9695         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9696
9697         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9698         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9699         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9700
9701         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9702         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9703         { } /* end */
9704 };
9705
9706 static struct hda_verb alc262_nec_verbs[] = {
9707         /* Unmute Speaker */
9708         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9709
9710         /* Headphone */
9711         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9712         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9713
9714         /* External mic to headphone */
9715         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9716         /* External mic to speaker */
9717         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9718         {}
9719 };
9720
9721 /*
9722  * fujitsu model
9723  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9724  *  0x1b = port replicator headphone out
9725  */
9726
9727 #define ALC_HP_EVENT    0x37
9728
9729 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9730         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9731         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9732         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9733         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9734         {}
9735 };
9736
9737 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9738         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9739         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9740         {}
9741 };
9742
9743 static struct hda_input_mux alc262_fujitsu_capture_source = {
9744         .num_items = 3,
9745         .items = {
9746                 { "Mic", 0x0 },
9747                 { "Int Mic", 0x1 },
9748                 { "CD", 0x4 },
9749         },
9750 };
9751
9752 static struct hda_input_mux alc262_HP_capture_source = {
9753         .num_items = 5,
9754         .items = {
9755                 { "Mic", 0x0 },
9756                 { "Front Mic", 0x1 },
9757                 { "Line", 0x2 },
9758                 { "CD", 0x4 },
9759                 { "AUX IN", 0x6 },
9760         },
9761 };
9762
9763 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9764         .num_items = 4,
9765         .items = {
9766                 { "Mic", 0x0 },
9767                 { "Front Mic", 0x2 },
9768                 { "Line", 0x1 },
9769                 { "CD", 0x4 },
9770         },
9771 };
9772
9773 /* mute/unmute internal speaker according to the hp jacks and mute state */
9774 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9775 {
9776         struct alc_spec *spec = codec->spec;
9777         unsigned int mute;
9778
9779         if (force || !spec->sense_updated) {
9780                 unsigned int present;
9781                 /* need to execute and sync at first */
9782                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9783                 /* check laptop HP jack */
9784                 present = snd_hda_codec_read(codec, 0x14, 0,
9785                                              AC_VERB_GET_PIN_SENSE, 0);
9786                 /* need to execute and sync at first */
9787                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9788                 /* check docking HP jack */
9789                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9790                                               AC_VERB_GET_PIN_SENSE, 0);
9791                 if (present & AC_PINSENSE_PRESENCE)
9792                         spec->jack_present = 1;
9793                 else
9794                         spec->jack_present = 0;
9795                 spec->sense_updated = 1;
9796         }
9797         /* unmute internal speaker only if both HPs are unplugged and
9798          * master switch is on
9799          */
9800         if (spec->jack_present)
9801                 mute = HDA_AMP_MUTE;
9802         else
9803                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9804         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9805                                  HDA_AMP_MUTE, mute);
9806 }
9807
9808 /* unsolicited event for HP jack sensing */
9809 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9810                                        unsigned int res)
9811 {
9812         if ((res >> 26) != ALC_HP_EVENT)
9813                 return;
9814         alc262_fujitsu_automute(codec, 1);
9815 }
9816
9817 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9818 {
9819         alc262_fujitsu_automute(codec, 1);
9820 }
9821
9822 /* bind volumes of both NID 0x0c and 0x0d */
9823 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9824         .ops = &snd_hda_bind_vol,
9825         .values = {
9826                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9827                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9828                 0
9829         },
9830 };
9831
9832 /* mute/unmute internal speaker according to the hp jack and mute state */
9833 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9834 {
9835         struct alc_spec *spec = codec->spec;
9836         unsigned int mute;
9837
9838         if (force || !spec->sense_updated) {
9839                 unsigned int present_int_hp;
9840                 /* need to execute and sync at first */
9841                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9842                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9843                                         AC_VERB_GET_PIN_SENSE, 0);
9844                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9845                 spec->sense_updated = 1;
9846         }
9847         if (spec->jack_present) {
9848                 /* mute internal speaker */
9849                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9850                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9851                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9852                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9853         } else {
9854                 /* unmute internal speaker if necessary */
9855                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9856                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9857                                          HDA_AMP_MUTE, mute);
9858                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9859                                          HDA_AMP_MUTE, mute);
9860         }
9861 }
9862
9863 /* unsolicited event for HP jack sensing */
9864 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9865                                        unsigned int res)
9866 {
9867         if ((res >> 26) != ALC_HP_EVENT)
9868                 return;
9869         alc262_lenovo_3000_automute(codec, 1);
9870 }
9871
9872 /* bind hp and internal speaker mute (with plug check) */
9873 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9874                                          struct snd_ctl_elem_value *ucontrol)
9875 {
9876         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9877         long *valp = ucontrol->value.integer.value;
9878         int change;
9879
9880         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9881                                                  HDA_AMP_MUTE,
9882                                                  valp ? 0 : HDA_AMP_MUTE);
9883         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9884                                                  HDA_AMP_MUTE,
9885                                                  valp ? 0 : HDA_AMP_MUTE);
9886
9887         if (change)
9888                 alc262_fujitsu_automute(codec, 0);
9889         return change;
9890 }
9891
9892 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9893         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9894         {
9895                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9896                 .name = "Master Playback Switch",
9897                 .info = snd_hda_mixer_amp_switch_info,
9898                 .get = snd_hda_mixer_amp_switch_get,
9899                 .put = alc262_fujitsu_master_sw_put,
9900                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9901         },
9902         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9903         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9904         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9905         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9906         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9907         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9908         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9909         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9910         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9911         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9912         { } /* end */
9913 };
9914
9915 /* bind hp and internal speaker mute (with plug check) */
9916 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9917                                          struct snd_ctl_elem_value *ucontrol)
9918 {
9919         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9920         long *valp = ucontrol->value.integer.value;
9921         int change;
9922
9923         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9924                                                  HDA_AMP_MUTE,
9925                                                  valp ? 0 : HDA_AMP_MUTE);
9926
9927         if (change)
9928                 alc262_lenovo_3000_automute(codec, 0);
9929         return change;
9930 }
9931
9932 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9933         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9934         {
9935                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9936                 .name = "Master Playback Switch",
9937                 .info = snd_hda_mixer_amp_switch_info,
9938                 .get = snd_hda_mixer_amp_switch_get,
9939                 .put = alc262_lenovo_3000_master_sw_put,
9940                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9941         },
9942         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9943         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9944         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9945         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9946         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9947         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9948         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9949         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9950         { } /* end */
9951 };
9952
9953 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
9954         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9955         {
9956                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9957                 .name = "Master Playback Switch",
9958                 .info = snd_hda_mixer_amp_switch_info,
9959                 .get = snd_hda_mixer_amp_switch_get,
9960                 .put = alc262_sony_master_sw_put,
9961                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9962         },
9963         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9964         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9965         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9966         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9967         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9968         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9969         { } /* end */
9970 };
9971
9972 /* additional init verbs for Benq laptops */
9973 static struct hda_verb alc262_EAPD_verbs[] = {
9974         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9975         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9976         {}
9977 };
9978
9979 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9980         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9981         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9982
9983         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9984         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9985         {}
9986 };
9987
9988 /* Samsung Q1 Ultra Vista model setup */
9989 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9990         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9991         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9992         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9993         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9994         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9995         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9996         { } /* end */
9997 };
9998
9999 static struct hda_verb alc262_ultra_verbs[] = {
10000         /* output mixer */
10001         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10002         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10003         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10004         /* speaker */
10005         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10006         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10007         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10008         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10009         /* HP */
10010         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10011         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10012         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10013         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10014         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10015         /* internal mic */
10016         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10017         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10018         /* ADC, choose mic */
10019         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10020         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10021         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10022         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10023         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10024         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10025         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10026         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10027         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10028         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10029         {}
10030 };
10031
10032 /* mute/unmute internal speaker according to the hp jack and mute state */
10033 static void alc262_ultra_automute(struct hda_codec *codec)
10034 {
10035         struct alc_spec *spec = codec->spec;
10036         unsigned int mute;
10037
10038         mute = 0;
10039         /* auto-mute only when HP is used as HP */
10040         if (!spec->cur_mux[0]) {
10041                 unsigned int present;
10042                 /* need to execute and sync at first */
10043                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10044                 present = snd_hda_codec_read(codec, 0x15, 0,
10045                                              AC_VERB_GET_PIN_SENSE, 0);
10046                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10047                 if (spec->jack_present)
10048                         mute = HDA_AMP_MUTE;
10049         }
10050         /* mute/unmute internal speaker */
10051         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10052                                  HDA_AMP_MUTE, mute);
10053         /* mute/unmute HP */
10054         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10055                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10056 }
10057
10058 /* unsolicited event for HP jack sensing */
10059 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10060                                        unsigned int res)
10061 {
10062         if ((res >> 26) != ALC880_HP_EVENT)
10063                 return;
10064         alc262_ultra_automute(codec);
10065 }
10066
10067 static struct hda_input_mux alc262_ultra_capture_source = {
10068         .num_items = 2,
10069         .items = {
10070                 { "Mic", 0x1 },
10071                 { "Headphone", 0x7 },
10072         },
10073 };
10074
10075 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10076                                      struct snd_ctl_elem_value *ucontrol)
10077 {
10078         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10079         struct alc_spec *spec = codec->spec;
10080         int ret;
10081
10082         ret = alc_mux_enum_put(kcontrol, ucontrol);
10083         if (!ret)
10084                 return 0;
10085         /* reprogram the HP pin as mic or HP according to the input source */
10086         snd_hda_codec_write_cache(codec, 0x15, 0,
10087                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10088                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10089         alc262_ultra_automute(codec); /* mute/unmute HP */
10090         return ret;
10091 }
10092
10093 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10094         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10095         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10096         {
10097                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10098                 .name = "Capture Source",
10099                 .info = alc_mux_enum_info,
10100                 .get = alc_mux_enum_get,
10101                 .put = alc262_ultra_mux_enum_put,
10102         },
10103         { } /* end */
10104 };
10105
10106 /* add playback controls from the parsed DAC table */
10107 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10108                                              const struct auto_pin_cfg *cfg)
10109 {
10110         hda_nid_t nid;
10111         int err;
10112
10113         spec->multiout.num_dacs = 1;    /* only use one dac */
10114         spec->multiout.dac_nids = spec->private_dac_nids;
10115         spec->multiout.dac_nids[0] = 2;
10116
10117         nid = cfg->line_out_pins[0];
10118         if (nid) {
10119                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10120                                   "Front Playback Volume",
10121                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10122                 if (err < 0)
10123                         return err;
10124                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10125                                   "Front Playback Switch",
10126                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10127                 if (err < 0)
10128                         return err;
10129         }
10130
10131         nid = cfg->speaker_pins[0];
10132         if (nid) {
10133                 if (nid == 0x16) {
10134                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10135                                           "Speaker Playback Volume",
10136                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10137                                                               HDA_OUTPUT));
10138                         if (err < 0)
10139                                 return err;
10140                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10141                                           "Speaker Playback Switch",
10142                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10143                                                               HDA_OUTPUT));
10144                         if (err < 0)
10145                                 return err;
10146                 } else {
10147                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10148                                           "Speaker Playback Switch",
10149                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10150                                                               HDA_OUTPUT));
10151                         if (err < 0)
10152                                 return err;
10153                 }
10154         }
10155         nid = cfg->hp_pins[0];
10156         if (nid) {
10157                 /* spec->multiout.hp_nid = 2; */
10158                 if (nid == 0x16) {
10159                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10160                                           "Headphone Playback Volume",
10161                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10162                                                               HDA_OUTPUT));
10163                         if (err < 0)
10164                                 return err;
10165                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10166                                           "Headphone Playback Switch",
10167                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10168                                                               HDA_OUTPUT));
10169                         if (err < 0)
10170                                 return err;
10171                 } else {
10172                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10173                                           "Headphone Playback Switch",
10174                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10175                                                               HDA_OUTPUT));
10176                         if (err < 0)
10177                                 return err;
10178                 }
10179         }
10180         return 0;
10181 }
10182
10183 /* identical with ALC880 */
10184 #define alc262_auto_create_analog_input_ctls \
10185         alc880_auto_create_analog_input_ctls
10186
10187 /*
10188  * generic initialization of ADC, input mixers and output mixers
10189  */
10190 static struct hda_verb alc262_volume_init_verbs[] = {
10191         /*
10192          * Unmute ADC0-2 and set the default input to mic-in
10193          */
10194         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10195         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10196         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10197         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10198         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10199         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10200
10201         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10202          * mixer widget
10203          * Note: PASD motherboards uses the Line In 2 as the input for
10204          * front panel mic (mic 2)
10205          */
10206         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10207         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10208         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10209         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10210         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10211         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10212
10213         /*
10214          * Set up output mixers (0x0c - 0x0f)
10215          */
10216         /* set vol=0 to output mixers */
10217         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10218         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10219         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10220
10221         /* set up input amps for analog loopback */
10222         /* Amp Indices: DAC = 0, mixer = 1 */
10223         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10224         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10225         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10226         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10227         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10228         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10229
10230         /* FIXME: use matrix-type input source selection */
10231         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10232         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10233         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10234         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10235         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10236         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10237         /* Input mixer2 */
10238         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10239         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10240         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10241         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10242         /* Input mixer3 */
10243         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10244         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10245         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10246         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10247
10248         { }
10249 };
10250
10251 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10252         /*
10253          * Unmute ADC0-2 and set the default input to mic-in
10254          */
10255         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10256         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10257         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10258         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10259         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10260         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10261
10262         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10263          * mixer widget
10264          * Note: PASD motherboards uses the Line In 2 as the input for
10265          * front panel mic (mic 2)
10266          */
10267         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10268         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10269         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10270         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10271         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10272         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10273         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10274         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10275
10276         /*
10277          * Set up output mixers (0x0c - 0x0e)
10278          */
10279         /* set vol=0 to output mixers */
10280         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10281         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10282         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10283
10284         /* set up input amps for analog loopback */
10285         /* Amp Indices: DAC = 0, mixer = 1 */
10286         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10287         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10288         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10289         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10290         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10291         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10292
10293         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10294         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10295         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10296
10297         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10298         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10299
10300         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10301         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10302
10303         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10304         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10305         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10306         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10307         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10308
10309         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10310         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10311         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10312         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10313         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10314         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10315
10316
10317         /* FIXME: use matrix-type input source selection */
10318         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10319         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10320         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10321         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10322         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10323         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10324         /* Input mixer2 */
10325         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10326         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10327         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10328         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10329         /* Input mixer3 */
10330         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10331         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10332         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10333         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10334
10335         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10336
10337         { }
10338 };
10339
10340 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10341         /*
10342          * Unmute ADC0-2 and set the default input to mic-in
10343          */
10344         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10345         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10346         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10347         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10348         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10349         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10350
10351         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10352          * mixer widget
10353          * Note: PASD motherboards uses the Line In 2 as the input for front
10354          * panel mic (mic 2)
10355          */
10356         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10357         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10358         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10359         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10360         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10361         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10362         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10363         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10364         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10365         /*
10366          * Set up output mixers (0x0c - 0x0e)
10367          */
10368         /* set vol=0 to output mixers */
10369         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10370         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10371         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10372
10373         /* set up input amps for analog loopback */
10374         /* Amp Indices: DAC = 0, mixer = 1 */
10375         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10376         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10377         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10378         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10379         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10380         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10381
10382
10383         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10384         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10385         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10386         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10387         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10388         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10389         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10390
10391         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10392         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10393
10394         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10395         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10396
10397         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10398         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10399         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10400         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10401         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10402         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10403
10404         /* FIXME: use matrix-type input source selection */
10405         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10406         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10407         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10408         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10409         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10410         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10411         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10412         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10413         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10414         /* Input mixer2 */
10415         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10416         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10417         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10418         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10419         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10420         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10421         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10422         /* Input mixer3 */
10423         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10424         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10425         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10426         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10427         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10428         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10429         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10430
10431         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10432
10433         { }
10434 };
10435
10436 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10437
10438         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10439         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10440         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10441
10442         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10443         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10444         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10445         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10446
10447         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10448         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10449         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10450         {}
10451 };
10452
10453
10454 #ifdef CONFIG_SND_HDA_POWER_SAVE
10455 #define alc262_loopbacks        alc880_loopbacks
10456 #endif
10457
10458 /* pcm configuration: identiacal with ALC880 */
10459 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10460 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10461 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10462 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10463
10464 /*
10465  * BIOS auto configuration
10466  */
10467 static int alc262_parse_auto_config(struct hda_codec *codec)
10468 {
10469         struct alc_spec *spec = codec->spec;
10470         int err;
10471         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10472
10473         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10474                                            alc262_ignore);
10475         if (err < 0)
10476                 return err;
10477         if (!spec->autocfg.line_outs)
10478                 return 0; /* can't find valid BIOS pin config */
10479         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10480         if (err < 0)
10481                 return err;
10482         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10483         if (err < 0)
10484                 return err;
10485
10486         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10487
10488         if (spec->autocfg.dig_out_pin)
10489                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10490         if (spec->autocfg.dig_in_pin)
10491                 spec->dig_in_nid = ALC262_DIGIN_NID;
10492
10493         if (spec->kctls.list)
10494                 add_mixer(spec, spec->kctls.list);
10495
10496         add_verb(spec, alc262_volume_init_verbs);
10497         spec->num_mux_defs = 1;
10498         spec->input_mux = &spec->private_imux;
10499
10500         err = alc_auto_add_mic_boost(codec);
10501         if (err < 0)
10502                 return err;
10503
10504         store_pin_configs(codec);
10505         return 1;
10506 }
10507
10508 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10509 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10510 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10511 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10512
10513
10514 /* init callback for auto-configuration model -- overriding the default init */
10515 static void alc262_auto_init(struct hda_codec *codec)
10516 {
10517         struct alc_spec *spec = codec->spec;
10518         alc262_auto_init_multi_out(codec);
10519         alc262_auto_init_hp_out(codec);
10520         alc262_auto_init_analog_input(codec);
10521         alc262_auto_init_input_src(codec);
10522         if (spec->unsol_event)
10523                 alc_inithook(codec);
10524 }
10525
10526 /*
10527  * configuration and preset
10528  */
10529 static const char *alc262_models[ALC262_MODEL_LAST] = {
10530         [ALC262_BASIC]          = "basic",
10531         [ALC262_HIPPO]          = "hippo",
10532         [ALC262_HIPPO_1]        = "hippo_1",
10533         [ALC262_FUJITSU]        = "fujitsu",
10534         [ALC262_HP_BPC]         = "hp-bpc",
10535         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10536         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10537         [ALC262_HP_RP5700]      = "hp-rp5700",
10538         [ALC262_BENQ_ED8]       = "benq",
10539         [ALC262_BENQ_T31]       = "benq-t31",
10540         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10541         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10542         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10543         [ALC262_ULTRA]          = "ultra",
10544         [ALC262_LENOVO_3000]    = "lenovo-3000",
10545         [ALC262_NEC]            = "nec",
10546         [ALC262_AUTO]           = "auto",
10547 };
10548
10549 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10550         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10551         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10552         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
10553         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
10554         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
10555         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
10556         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
10557         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
10558         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10559         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10560         SND_PCI_QUIRK(0x103c, 0x170b, "HP xw*", ALC262_HP_BPC),
10561         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10562         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10563         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10564         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10565         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10566         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10567         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10568         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10569         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10570         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10571         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10572         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10573                       ALC262_HP_TC_T5735),
10574         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10575         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10576         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10577         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10578         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10579         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10580         SND_PCI_QUIRK(0x104d, 0x9033, "Sony VAIO VGN-SR19XN",
10581                       ALC262_SONY_ASSAMD),
10582         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10583                       ALC262_TOSHIBA_RX1),
10584         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10585         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10586         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10587         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
10588         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
10589         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
10590         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10591         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10592         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10593         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10594         {}
10595 };
10596
10597 static struct alc_config_preset alc262_presets[] = {
10598         [ALC262_BASIC] = {
10599                 .mixers = { alc262_base_mixer },
10600                 .init_verbs = { alc262_init_verbs },
10601                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10602                 .dac_nids = alc262_dac_nids,
10603                 .hp_nid = 0x03,
10604                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10605                 .channel_mode = alc262_modes,
10606                 .input_mux = &alc262_capture_source,
10607         },
10608         [ALC262_HIPPO] = {
10609                 .mixers = { alc262_base_mixer },
10610                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10611                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10612                 .dac_nids = alc262_dac_nids,
10613                 .hp_nid = 0x03,
10614                 .dig_out_nid = ALC262_DIGOUT_NID,
10615                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10616                 .channel_mode = alc262_modes,
10617                 .input_mux = &alc262_capture_source,
10618                 .unsol_event = alc262_hippo_unsol_event,
10619                 .init_hook = alc262_hippo_automute,
10620         },
10621         [ALC262_HIPPO_1] = {
10622                 .mixers = { alc262_hippo1_mixer },
10623                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10624                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10625                 .dac_nids = alc262_dac_nids,
10626                 .hp_nid = 0x02,
10627                 .dig_out_nid = ALC262_DIGOUT_NID,
10628                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10629                 .channel_mode = alc262_modes,
10630                 .input_mux = &alc262_capture_source,
10631                 .unsol_event = alc262_hippo1_unsol_event,
10632                 .init_hook = alc262_hippo1_automute,
10633         },
10634         [ALC262_FUJITSU] = {
10635                 .mixers = { alc262_fujitsu_mixer },
10636                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10637                                 alc262_fujitsu_unsol_verbs },
10638                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10639                 .dac_nids = alc262_dac_nids,
10640                 .hp_nid = 0x03,
10641                 .dig_out_nid = ALC262_DIGOUT_NID,
10642                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10643                 .channel_mode = alc262_modes,
10644                 .input_mux = &alc262_fujitsu_capture_source,
10645                 .unsol_event = alc262_fujitsu_unsol_event,
10646                 .init_hook = alc262_fujitsu_init_hook,
10647         },
10648         [ALC262_HP_BPC] = {
10649                 .mixers = { alc262_HP_BPC_mixer },
10650                 .init_verbs = { alc262_HP_BPC_init_verbs },
10651                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10652                 .dac_nids = alc262_dac_nids,
10653                 .hp_nid = 0x03,
10654                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10655                 .channel_mode = alc262_modes,
10656                 .input_mux = &alc262_HP_capture_source,
10657                 .unsol_event = alc262_hp_bpc_unsol_event,
10658                 .init_hook = alc262_hp_bpc_automute,
10659         },
10660         [ALC262_HP_BPC_D7000_WF] = {
10661                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10662                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10663                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10664                 .dac_nids = alc262_dac_nids,
10665                 .hp_nid = 0x03,
10666                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10667                 .channel_mode = alc262_modes,
10668                 .input_mux = &alc262_HP_D7000_capture_source,
10669                 .unsol_event = alc262_hp_wildwest_unsol_event,
10670                 .init_hook = alc262_hp_wildwest_automute,
10671         },
10672         [ALC262_HP_BPC_D7000_WL] = {
10673                 .mixers = { alc262_HP_BPC_WildWest_mixer,
10674                             alc262_HP_BPC_WildWest_option_mixer },
10675                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10676                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10677                 .dac_nids = alc262_dac_nids,
10678                 .hp_nid = 0x03,
10679                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10680                 .channel_mode = alc262_modes,
10681                 .input_mux = &alc262_HP_D7000_capture_source,
10682                 .unsol_event = alc262_hp_wildwest_unsol_event,
10683                 .init_hook = alc262_hp_wildwest_automute,
10684         },
10685         [ALC262_HP_TC_T5735] = {
10686                 .mixers = { alc262_hp_t5735_mixer },
10687                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10688                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10689                 .dac_nids = alc262_dac_nids,
10690                 .hp_nid = 0x03,
10691                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10692                 .channel_mode = alc262_modes,
10693                 .input_mux = &alc262_capture_source,
10694                 .unsol_event = alc262_hp_t5735_unsol_event,
10695                 .init_hook = alc262_hp_t5735_init_hook,
10696         },
10697         [ALC262_HP_RP5700] = {
10698                 .mixers = { alc262_hp_rp5700_mixer },
10699                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10700                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10701                 .dac_nids = alc262_dac_nids,
10702                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10703                 .channel_mode = alc262_modes,
10704                 .input_mux = &alc262_hp_rp5700_capture_source,
10705         },
10706         [ALC262_BENQ_ED8] = {
10707                 .mixers = { alc262_base_mixer },
10708                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
10709                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10710                 .dac_nids = alc262_dac_nids,
10711                 .hp_nid = 0x03,
10712                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10713                 .channel_mode = alc262_modes,
10714                 .input_mux = &alc262_capture_source,
10715         },
10716         [ALC262_SONY_ASSAMD] = {
10717                 .mixers = { alc262_sony_mixer },
10718                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10719                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10720                 .dac_nids = alc262_dac_nids,
10721                 .hp_nid = 0x02,
10722                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10723                 .channel_mode = alc262_modes,
10724                 .input_mux = &alc262_capture_source,
10725                 .unsol_event = alc262_hippo_unsol_event,
10726                 .init_hook = alc262_hippo_automute,
10727         },
10728         [ALC262_BENQ_T31] = {
10729                 .mixers = { alc262_benq_t31_mixer },
10730                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10731                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10732                 .dac_nids = alc262_dac_nids,
10733                 .hp_nid = 0x03,
10734                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10735                 .channel_mode = alc262_modes,
10736                 .input_mux = &alc262_capture_source,
10737                 .unsol_event = alc262_hippo_unsol_event,
10738                 .init_hook = alc262_hippo_automute,
10739         },
10740         [ALC262_ULTRA] = {
10741                 .mixers = { alc262_ultra_mixer },
10742                 .cap_mixer = alc262_ultra_capture_mixer,
10743                 .init_verbs = { alc262_ultra_verbs },
10744                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10745                 .dac_nids = alc262_dac_nids,
10746                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10747                 .channel_mode = alc262_modes,
10748                 .input_mux = &alc262_ultra_capture_source,
10749                 .adc_nids = alc262_adc_nids, /* ADC0 */
10750                 .capsrc_nids = alc262_capsrc_nids,
10751                 .num_adc_nids = 1, /* single ADC */
10752                 .unsol_event = alc262_ultra_unsol_event,
10753                 .init_hook = alc262_ultra_automute,
10754         },
10755         [ALC262_LENOVO_3000] = {
10756                 .mixers = { alc262_lenovo_3000_mixer },
10757                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10758                                 alc262_lenovo_3000_unsol_verbs },
10759                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10760                 .dac_nids = alc262_dac_nids,
10761                 .hp_nid = 0x03,
10762                 .dig_out_nid = ALC262_DIGOUT_NID,
10763                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10764                 .channel_mode = alc262_modes,
10765                 .input_mux = &alc262_fujitsu_capture_source,
10766                 .unsol_event = alc262_lenovo_3000_unsol_event,
10767         },
10768         [ALC262_NEC] = {
10769                 .mixers = { alc262_nec_mixer },
10770                 .init_verbs = { alc262_nec_verbs },
10771                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10772                 .dac_nids = alc262_dac_nids,
10773                 .hp_nid = 0x03,
10774                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10775                 .channel_mode = alc262_modes,
10776                 .input_mux = &alc262_capture_source,
10777         },
10778         [ALC262_TOSHIBA_S06] = {
10779                 .mixers = { alc262_toshiba_s06_mixer },
10780                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10781                                                         alc262_eapd_verbs },
10782                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10783                 .capsrc_nids = alc262_dmic_capsrc_nids,
10784                 .dac_nids = alc262_dac_nids,
10785                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10786                 .dig_out_nid = ALC262_DIGOUT_NID,
10787                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10788                 .channel_mode = alc262_modes,
10789                 .input_mux = &alc262_dmic_capture_source,
10790                 .unsol_event = alc262_toshiba_s06_unsol_event,
10791                 .init_hook = alc262_toshiba_s06_init_hook,
10792         },
10793         [ALC262_TOSHIBA_RX1] = {
10794                 .mixers = { alc262_toshiba_rx1_mixer },
10795                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_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 };
10806
10807 static int patch_alc262(struct hda_codec *codec)
10808 {
10809         struct alc_spec *spec;
10810         int board_config;
10811         int err;
10812
10813         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10814         if (spec == NULL)
10815                 return -ENOMEM;
10816
10817         codec->spec = spec;
10818 #if 0
10819         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10820          * under-run
10821          */
10822         {
10823         int tmp;
10824         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10825         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10826         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10827         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10828         }
10829 #endif
10830
10831         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10832
10833         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10834                                                   alc262_models,
10835                                                   alc262_cfg_tbl);
10836
10837         if (board_config < 0) {
10838                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10839                        "trying auto-probe from BIOS...\n");
10840                 board_config = ALC262_AUTO;
10841         }
10842
10843         if (board_config == ALC262_AUTO) {
10844                 /* automatic parse from the BIOS config */
10845                 err = alc262_parse_auto_config(codec);
10846                 if (err < 0) {
10847                         alc_free(codec);
10848                         return err;
10849                 } else if (!err) {
10850                         printk(KERN_INFO
10851                                "hda_codec: Cannot set up configuration "
10852                                "from BIOS.  Using base mode...\n");
10853                         board_config = ALC262_BASIC;
10854                 }
10855         }
10856
10857         if (board_config != ALC262_AUTO)
10858                 setup_preset(spec, &alc262_presets[board_config]);
10859
10860         spec->stream_name_analog = "ALC262 Analog";
10861         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10862         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10863
10864         spec->stream_name_digital = "ALC262 Digital";
10865         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10866         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10867
10868         spec->is_mix_capture = 1;
10869         if (!spec->adc_nids && spec->input_mux) {
10870                 /* check whether NID 0x07 is valid */
10871                 unsigned int wcap = get_wcaps(codec, 0x07);
10872
10873                 /* get type */
10874                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10875                 if (wcap != AC_WID_AUD_IN) {
10876                         spec->adc_nids = alc262_adc_nids_alt;
10877                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10878                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10879                 } else {
10880                         spec->adc_nids = alc262_adc_nids;
10881                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10882                         spec->capsrc_nids = alc262_capsrc_nids;
10883                 }
10884         }
10885         if (!spec->cap_mixer)
10886                 set_capture_mixer(spec);
10887
10888         spec->vmaster_nid = 0x0c;
10889
10890         codec->patch_ops = alc_patch_ops;
10891         if (board_config == ALC262_AUTO)
10892                 spec->init_hook = alc262_auto_init;
10893 #ifdef CONFIG_SND_HDA_POWER_SAVE
10894         if (!spec->loopback.amplist)
10895                 spec->loopback.amplist = alc262_loopbacks;
10896 #endif
10897         codec->proc_widget_hook = print_realtek_coef;
10898
10899         return 0;
10900 }
10901
10902 /*
10903  *  ALC268 channel source setting (2 channel)
10904  */
10905 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10906 #define alc268_modes            alc260_modes
10907
10908 static hda_nid_t alc268_dac_nids[2] = {
10909         /* front, hp */
10910         0x02, 0x03
10911 };
10912
10913 static hda_nid_t alc268_adc_nids[2] = {
10914         /* ADC0-1 */
10915         0x08, 0x07
10916 };
10917
10918 static hda_nid_t alc268_adc_nids_alt[1] = {
10919         /* ADC0 */
10920         0x08
10921 };
10922
10923 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10924
10925 static struct snd_kcontrol_new alc268_base_mixer[] = {
10926         /* output mixer control */
10927         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10928         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10929         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10930         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10931         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10932         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10933         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10934         { }
10935 };
10936
10937 /* bind Beep switches of both NID 0x0f and 0x10 */
10938 static struct hda_bind_ctls alc268_bind_beep_sw = {
10939         .ops = &snd_hda_bind_sw,
10940         .values = {
10941                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10942                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10943                 0
10944         },
10945 };
10946
10947 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10948         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10949         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10950         { }
10951 };
10952
10953 static struct hda_verb alc268_eapd_verbs[] = {
10954         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10955         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10956         { }
10957 };
10958
10959 /* Toshiba specific */
10960 #define alc268_toshiba_automute alc262_hippo_automute
10961
10962 static struct hda_verb alc268_toshiba_verbs[] = {
10963         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10964         { } /* end */
10965 };
10966
10967 static struct hda_input_mux alc268_acer_lc_capture_source = {
10968         .num_items = 2,
10969         .items = {
10970                 { "i-Mic", 0x6 },
10971                 { "E-Mic", 0x0 },
10972         },
10973 };
10974
10975 /* Acer specific */
10976 /* bind volumes of both NID 0x02 and 0x03 */
10977 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10978         .ops = &snd_hda_bind_vol,
10979         .values = {
10980                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10981                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10982                 0
10983         },
10984 };
10985
10986 /* mute/unmute internal speaker according to the hp jack and mute state */
10987 static void alc268_acer_automute(struct hda_codec *codec, int force)
10988 {
10989         struct alc_spec *spec = codec->spec;
10990         unsigned int mute;
10991
10992         if (force || !spec->sense_updated) {
10993                 unsigned int present;
10994                 present = snd_hda_codec_read(codec, 0x14, 0,
10995                                          AC_VERB_GET_PIN_SENSE, 0);
10996                 spec->jack_present = (present & 0x80000000) != 0;
10997                 spec->sense_updated = 1;
10998         }
10999         if (spec->jack_present)
11000                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11001         else /* unmute internal speaker if necessary */
11002                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11003         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11004                                  HDA_AMP_MUTE, mute);
11005 }
11006
11007
11008 /* bind hp and internal speaker mute (with plug check) */
11009 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11010                                      struct snd_ctl_elem_value *ucontrol)
11011 {
11012         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11013         long *valp = ucontrol->value.integer.value;
11014         int change;
11015
11016         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
11017                                           HDA_AMP_MUTE,
11018                                           valp[0] ? 0 : HDA_AMP_MUTE);
11019         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
11020                                            HDA_AMP_MUTE,
11021                                            valp[1] ? 0 : HDA_AMP_MUTE);
11022         if (change)
11023                 alc268_acer_automute(codec, 0);
11024         return change;
11025 }
11026
11027 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11028         /* output mixer control */
11029         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11030         {
11031                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11032                 .name = "Master Playback Switch",
11033                 .info = snd_hda_mixer_amp_switch_info,
11034                 .get = snd_hda_mixer_amp_switch_get,
11035                 .put = alc268_acer_master_sw_put,
11036                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11037         },
11038         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11039         { }
11040 };
11041
11042 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11043         /* output mixer control */
11044         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11045         {
11046                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11047                 .name = "Master Playback Switch",
11048                 .info = snd_hda_mixer_amp_switch_info,
11049                 .get = snd_hda_mixer_amp_switch_get,
11050                 .put = alc268_acer_master_sw_put,
11051                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11052         },
11053         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11054         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11055         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11056         { }
11057 };
11058
11059 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11060         /* output mixer control */
11061         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11062         {
11063                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11064                 .name = "Master Playback Switch",
11065                 .info = snd_hda_mixer_amp_switch_info,
11066                 .get = snd_hda_mixer_amp_switch_get,
11067                 .put = alc268_acer_master_sw_put,
11068                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11069         },
11070         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11071         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11072         { }
11073 };
11074
11075 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11076         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11077         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11078         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11079         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11080         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11081         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11082         { }
11083 };
11084
11085 static struct hda_verb alc268_acer_verbs[] = {
11086         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11087         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11088         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11089         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11090         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11091         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11092         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11093         { }
11094 };
11095
11096 /* unsolicited event for HP jack sensing */
11097 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
11098                                        unsigned int res)
11099 {
11100         if ((res >> 26) != ALC880_HP_EVENT)
11101                 return;
11102         alc268_toshiba_automute(codec);
11103 }
11104
11105 static void alc268_acer_unsol_event(struct hda_codec *codec,
11106                                        unsigned int res)
11107 {
11108         if ((res >> 26) != ALC880_HP_EVENT)
11109                 return;
11110         alc268_acer_automute(codec, 1);
11111 }
11112
11113 static void alc268_acer_init_hook(struct hda_codec *codec)
11114 {
11115         alc268_acer_automute(codec, 1);
11116 }
11117
11118 /* toggle speaker-output according to the hp-jack state */
11119 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11120 {
11121         unsigned int present;
11122         unsigned char bits;
11123
11124         present = snd_hda_codec_read(codec, 0x15, 0,
11125                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11126         bits = present ? AMP_IN_MUTE(0) : 0;
11127         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
11128                                 AMP_IN_MUTE(0), bits);
11129         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
11130                                 AMP_IN_MUTE(0), bits);
11131 }
11132
11133
11134 static void alc268_acer_mic_automute(struct hda_codec *codec)
11135 {
11136         unsigned int present;
11137
11138         present = snd_hda_codec_read(codec, 0x18, 0,
11139                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11140         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11141                             present ? 0x0 : 0x6);
11142 }
11143
11144 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11145                                     unsigned int res)
11146 {
11147         if ((res >> 26) == ALC880_HP_EVENT)
11148                 alc268_aspire_one_speaker_automute(codec);
11149         if ((res >> 26) == ALC880_MIC_EVENT)
11150                 alc268_acer_mic_automute(codec);
11151 }
11152
11153 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11154 {
11155         alc268_aspire_one_speaker_automute(codec);
11156         alc268_acer_mic_automute(codec);
11157 }
11158
11159 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11160         /* output mixer control */
11161         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11162         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11163         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11164         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11165         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11166         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11167         { }
11168 };
11169
11170 static struct hda_verb alc268_dell_verbs[] = {
11171         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11172         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11173         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11174         { }
11175 };
11176
11177 /* mute/unmute internal speaker according to the hp jack and mute state */
11178 static void alc268_dell_automute(struct hda_codec *codec)
11179 {
11180         unsigned int present;
11181         unsigned int mute;
11182
11183         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
11184         if (present & 0x80000000)
11185                 mute = HDA_AMP_MUTE;
11186         else
11187                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
11188         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11189                                  HDA_AMP_MUTE, mute);
11190 }
11191
11192 static void alc268_dell_unsol_event(struct hda_codec *codec,
11193                                     unsigned int res)
11194 {
11195         if ((res >> 26) != ALC880_HP_EVENT)
11196                 return;
11197         alc268_dell_automute(codec);
11198 }
11199
11200 #define alc268_dell_init_hook   alc268_dell_automute
11201
11202 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
11203         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11204         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11205         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11206         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11207         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11208         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
11209         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
11210         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
11211         { }
11212 };
11213
11214 static struct hda_verb alc267_quanta_il1_verbs[] = {
11215         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11216         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
11217         { }
11218 };
11219
11220 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
11221 {
11222         unsigned int present;
11223
11224         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
11225                 & AC_PINSENSE_PRESENCE;
11226         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11227                             present ? 0 : PIN_OUT);
11228 }
11229
11230 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
11231 {
11232         unsigned int present;
11233
11234         present = snd_hda_codec_read(codec, 0x18, 0,
11235                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11236         snd_hda_codec_write(codec, 0x23, 0,
11237                             AC_VERB_SET_CONNECT_SEL,
11238                             present ? 0x00 : 0x01);
11239 }
11240
11241 static void alc267_quanta_il1_automute(struct hda_codec *codec)
11242 {
11243         alc267_quanta_il1_hp_automute(codec);
11244         alc267_quanta_il1_mic_automute(codec);
11245 }
11246
11247 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11248                                            unsigned int res)
11249 {
11250         switch (res >> 26) {
11251         case ALC880_HP_EVENT:
11252                 alc267_quanta_il1_hp_automute(codec);
11253                 break;
11254         case ALC880_MIC_EVENT:
11255                 alc267_quanta_il1_mic_automute(codec);
11256                 break;
11257         }
11258 }
11259
11260 /*
11261  * generic initialization of ADC, input mixers and output mixers
11262  */
11263 static struct hda_verb alc268_base_init_verbs[] = {
11264         /* Unmute DAC0-1 and set vol = 0 */
11265         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11266         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11267         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11268         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11269         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11270         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11271
11272         /*
11273          * Set up output mixers (0x0c - 0x0e)
11274          */
11275         /* set vol=0 to output mixers */
11276         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11277         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11278         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11279         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11280
11281         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11282         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11283
11284         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11285         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11286         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11287         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11288         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11289         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11290         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11291         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11292
11293         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11294         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11295         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11296         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11297         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11298         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11299         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11300
11301         /* set PCBEEP vol = 0, mute connections */
11302         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11303         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11304         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11305
11306         /* Unmute Selector 23h,24h and set the default input to mic-in */
11307
11308         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11309         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11310         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11311         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11312
11313         { }
11314 };
11315
11316 /*
11317  * generic initialization of ADC, input mixers and output mixers
11318  */
11319 static struct hda_verb alc268_volume_init_verbs[] = {
11320         /* set output DAC */
11321         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11322         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11323         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11324         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11325
11326         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11327         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11328         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11329         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11330         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11331
11332         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11333         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11334         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11335         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11336         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11337
11338         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11339         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11340         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11341         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11342
11343         /* set PCBEEP vol = 0, mute connections */
11344         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11345         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11346         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11347
11348         { }
11349 };
11350
11351 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11352         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11353         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11354         {
11355                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11356                 /* The multiple "Capture Source" controls confuse alsamixer
11357                  * So call somewhat different..
11358                  */
11359                 /* .name = "Capture Source", */
11360                 .name = "Input Source",
11361                 .count = 1,
11362                 .info = alc_mux_enum_info,
11363                 .get = alc_mux_enum_get,
11364                 .put = alc_mux_enum_put,
11365         },
11366         { } /* end */
11367 };
11368
11369 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11370         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11371         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11372         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11373         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11374         {
11375                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11376                 /* The multiple "Capture Source" controls confuse alsamixer
11377                  * So call somewhat different..
11378                  */
11379                 /* .name = "Capture Source", */
11380                 .name = "Input Source",
11381                 .count = 2,
11382                 .info = alc_mux_enum_info,
11383                 .get = alc_mux_enum_get,
11384                 .put = alc_mux_enum_put,
11385         },
11386         { } /* end */
11387 };
11388
11389 static struct hda_input_mux alc268_capture_source = {
11390         .num_items = 4,
11391         .items = {
11392                 { "Mic", 0x0 },
11393                 { "Front Mic", 0x1 },
11394                 { "Line", 0x2 },
11395                 { "CD", 0x3 },
11396         },
11397 };
11398
11399 static struct hda_input_mux alc268_acer_capture_source = {
11400         .num_items = 3,
11401         .items = {
11402                 { "Mic", 0x0 },
11403                 { "Internal Mic", 0x1 },
11404                 { "Line", 0x2 },
11405         },
11406 };
11407
11408 static struct hda_input_mux alc268_acer_dmic_capture_source = {
11409         .num_items = 3,
11410         .items = {
11411                 { "Mic", 0x0 },
11412                 { "Internal Mic", 0x6 },
11413                 { "Line", 0x2 },
11414         },
11415 };
11416
11417 #ifdef CONFIG_SND_DEBUG
11418 static struct snd_kcontrol_new alc268_test_mixer[] = {
11419         /* Volume widgets */
11420         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11421         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11422         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11423         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11424         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11425         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11426         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11427         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11428         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11429         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11430         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11431         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11432         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11433         /* The below appears problematic on some hardwares */
11434         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11435         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11436         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11437         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11438         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11439
11440         /* Modes for retasking pin widgets */
11441         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11442         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11443         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11444         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11445
11446         /* Controls for GPIO pins, assuming they are configured as outputs */
11447         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11448         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11449         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11450         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11451
11452         /* Switches to allow the digital SPDIF output pin to be enabled.
11453          * The ALC268 does not have an SPDIF input.
11454          */
11455         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11456
11457         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11458          * this output to turn on an external amplifier.
11459          */
11460         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11461         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11462
11463         { } /* end */
11464 };
11465 #endif
11466
11467 /* create input playback/capture controls for the given pin */
11468 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11469                                     const char *ctlname, int idx)
11470 {
11471         char name[32];
11472         int err;
11473
11474         sprintf(name, "%s Playback Volume", ctlname);
11475         if (nid == 0x14) {
11476                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11477                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11478                                                       HDA_OUTPUT));
11479                 if (err < 0)
11480                         return err;
11481         } else if (nid == 0x15) {
11482                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11483                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11484                                                       HDA_OUTPUT));
11485                 if (err < 0)
11486                         return err;
11487         } else
11488                 return -1;
11489         sprintf(name, "%s Playback Switch", ctlname);
11490         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11491                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11492         if (err < 0)
11493                 return err;
11494         return 0;
11495 }
11496
11497 /* add playback controls from the parsed DAC table */
11498 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11499                                              const struct auto_pin_cfg *cfg)
11500 {
11501         hda_nid_t nid;
11502         int err;
11503
11504         spec->multiout.num_dacs = 2;    /* only use one dac */
11505         spec->multiout.dac_nids = spec->private_dac_nids;
11506         spec->multiout.dac_nids[0] = 2;
11507         spec->multiout.dac_nids[1] = 3;
11508
11509         nid = cfg->line_out_pins[0];
11510         if (nid)
11511                 alc268_new_analog_output(spec, nid, "Front", 0);
11512
11513         nid = cfg->speaker_pins[0];
11514         if (nid == 0x1d) {
11515                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11516                                   "Speaker Playback Volume",
11517                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11518                 if (err < 0)
11519                         return err;
11520         }
11521         nid = cfg->hp_pins[0];
11522         if (nid)
11523                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11524
11525         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11526         if (nid == 0x16) {
11527                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11528                                   "Mono Playback Switch",
11529                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11530                 if (err < 0)
11531                         return err;
11532         }
11533         return 0;
11534 }
11535
11536 /* create playback/capture controls for input pins */
11537 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11538                                                 const struct auto_pin_cfg *cfg)
11539 {
11540         struct hda_input_mux *imux = &spec->private_imux;
11541         int i, idx1;
11542
11543         for (i = 0; i < AUTO_PIN_LAST; i++) {
11544                 switch(cfg->input_pins[i]) {
11545                 case 0x18:
11546                         idx1 = 0;       /* Mic 1 */
11547                         break;
11548                 case 0x19:
11549                         idx1 = 1;       /* Mic 2 */
11550                         break;
11551                 case 0x1a:
11552                         idx1 = 2;       /* Line In */
11553                         break;
11554                 case 0x1c:
11555                         idx1 = 3;       /* CD */
11556                         break;
11557                 case 0x12:
11558                 case 0x13:
11559                         idx1 = 6;       /* digital mics */
11560                         break;
11561                 default:
11562                         continue;
11563                 }
11564                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11565                 imux->items[imux->num_items].index = idx1;
11566                 imux->num_items++;
11567         }
11568         return 0;
11569 }
11570
11571 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11572 {
11573         struct alc_spec *spec = codec->spec;
11574         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11575         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11576         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11577         unsigned int    dac_vol1, dac_vol2;
11578
11579         if (speaker_nid) {
11580                 snd_hda_codec_write(codec, speaker_nid, 0,
11581                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11582                 snd_hda_codec_write(codec, 0x0f, 0,
11583                                     AC_VERB_SET_AMP_GAIN_MUTE,
11584                                     AMP_IN_UNMUTE(1));
11585                 snd_hda_codec_write(codec, 0x10, 0,
11586                                     AC_VERB_SET_AMP_GAIN_MUTE,
11587                                     AMP_IN_UNMUTE(1));
11588         } else {
11589                 snd_hda_codec_write(codec, 0x0f, 0,
11590                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11591                 snd_hda_codec_write(codec, 0x10, 0,
11592                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11593         }
11594
11595         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11596         if (line_nid == 0x14)
11597                 dac_vol2 = AMP_OUT_ZERO;
11598         else if (line_nid == 0x15)
11599                 dac_vol1 = AMP_OUT_ZERO;
11600         if (hp_nid == 0x14)
11601                 dac_vol2 = AMP_OUT_ZERO;
11602         else if (hp_nid == 0x15)
11603                 dac_vol1 = AMP_OUT_ZERO;
11604         if (line_nid != 0x16 || hp_nid != 0x16 ||
11605             spec->autocfg.line_out_pins[1] != 0x16 ||
11606             spec->autocfg.line_out_pins[2] != 0x16)
11607                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11608
11609         snd_hda_codec_write(codec, 0x02, 0,
11610                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11611         snd_hda_codec_write(codec, 0x03, 0,
11612                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11613 }
11614
11615 /* pcm configuration: identiacal with ALC880 */
11616 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11617 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11618 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11619 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11620
11621 /*
11622  * BIOS auto configuration
11623  */
11624 static int alc268_parse_auto_config(struct hda_codec *codec)
11625 {
11626         struct alc_spec *spec = codec->spec;
11627         int err;
11628         static hda_nid_t alc268_ignore[] = { 0 };
11629
11630         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11631                                            alc268_ignore);
11632         if (err < 0)
11633                 return err;
11634         if (!spec->autocfg.line_outs)
11635                 return 0; /* can't find valid BIOS pin config */
11636
11637         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11638         if (err < 0)
11639                 return err;
11640         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11641         if (err < 0)
11642                 return err;
11643
11644         spec->multiout.max_channels = 2;
11645
11646         /* digital only support output */
11647         if (spec->autocfg.dig_out_pin)
11648                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11649
11650         if (spec->kctls.list)
11651                 add_mixer(spec, spec->kctls.list);
11652
11653         if (spec->autocfg.speaker_pins[0] != 0x1d)
11654                 add_mixer(spec, alc268_beep_mixer);
11655
11656         add_verb(spec, alc268_volume_init_verbs);
11657         spec->num_mux_defs = 1;
11658         spec->input_mux = &spec->private_imux;
11659
11660         err = alc_auto_add_mic_boost(codec);
11661         if (err < 0)
11662                 return err;
11663
11664         store_pin_configs(codec);
11665         return 1;
11666 }
11667
11668 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
11669 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
11670 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
11671
11672 /* init callback for auto-configuration model -- overriding the default init */
11673 static void alc268_auto_init(struct hda_codec *codec)
11674 {
11675         struct alc_spec *spec = codec->spec;
11676         alc268_auto_init_multi_out(codec);
11677         alc268_auto_init_hp_out(codec);
11678         alc268_auto_init_mono_speaker_out(codec);
11679         alc268_auto_init_analog_input(codec);
11680         if (spec->unsol_event)
11681                 alc_inithook(codec);
11682 }
11683
11684 /*
11685  * configuration and preset
11686  */
11687 static const char *alc268_models[ALC268_MODEL_LAST] = {
11688         [ALC267_QUANTA_IL1]     = "quanta-il1",
11689         [ALC268_3ST]            = "3stack",
11690         [ALC268_TOSHIBA]        = "toshiba",
11691         [ALC268_ACER]           = "acer",
11692         [ALC268_ACER_DMIC]      = "acer-dmic",
11693         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
11694         [ALC268_DELL]           = "dell",
11695         [ALC268_ZEPTO]          = "zepto",
11696 #ifdef CONFIG_SND_DEBUG
11697         [ALC268_TEST]           = "test",
11698 #endif
11699         [ALC268_AUTO]           = "auto",
11700 };
11701
11702 static struct snd_pci_quirk alc268_cfg_tbl[] = {
11703         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
11704         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
11705         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
11706         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
11707         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11708         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11709                                                 ALC268_ACER_ASPIRE_ONE),
11710         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
11711         SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL),
11712         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
11713         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
11714         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
11715         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11716         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
11717         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
11718         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
11719         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
11720         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
11721         {}
11722 };
11723
11724 static struct alc_config_preset alc268_presets[] = {
11725         [ALC267_QUANTA_IL1] = {
11726                 .mixers = { alc267_quanta_il1_mixer },
11727                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11728                                 alc267_quanta_il1_verbs },
11729                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11730                 .dac_nids = alc268_dac_nids,
11731                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11732                 .adc_nids = alc268_adc_nids_alt,
11733                 .hp_nid = 0x03,
11734                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11735                 .channel_mode = alc268_modes,
11736                 .input_mux = &alc268_capture_source,
11737                 .unsol_event = alc267_quanta_il1_unsol_event,
11738                 .init_hook = alc267_quanta_il1_automute,
11739         },
11740         [ALC268_3ST] = {
11741                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11742                             alc268_beep_mixer },
11743                 .init_verbs = { alc268_base_init_verbs },
11744                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11745                 .dac_nids = alc268_dac_nids,
11746                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11747                 .adc_nids = alc268_adc_nids_alt,
11748                 .capsrc_nids = alc268_capsrc_nids,
11749                 .hp_nid = 0x03,
11750                 .dig_out_nid = ALC268_DIGOUT_NID,
11751                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11752                 .channel_mode = alc268_modes,
11753                 .input_mux = &alc268_capture_source,
11754         },
11755         [ALC268_TOSHIBA] = {
11756                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11757                             alc268_beep_mixer },
11758                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11759                                 alc268_toshiba_verbs },
11760                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11761                 .dac_nids = alc268_dac_nids,
11762                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11763                 .adc_nids = alc268_adc_nids_alt,
11764                 .capsrc_nids = alc268_capsrc_nids,
11765                 .hp_nid = 0x03,
11766                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11767                 .channel_mode = alc268_modes,
11768                 .input_mux = &alc268_capture_source,
11769                 .unsol_event = alc268_toshiba_unsol_event,
11770                 .init_hook = alc268_toshiba_automute,
11771         },
11772         [ALC268_ACER] = {
11773                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
11774                             alc268_beep_mixer },
11775                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11776                                 alc268_acer_verbs },
11777                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11778                 .dac_nids = alc268_dac_nids,
11779                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11780                 .adc_nids = alc268_adc_nids_alt,
11781                 .capsrc_nids = alc268_capsrc_nids,
11782                 .hp_nid = 0x02,
11783                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11784                 .channel_mode = alc268_modes,
11785                 .input_mux = &alc268_acer_capture_source,
11786                 .unsol_event = alc268_acer_unsol_event,
11787                 .init_hook = alc268_acer_init_hook,
11788         },
11789         [ALC268_ACER_DMIC] = {
11790                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
11791                             alc268_beep_mixer },
11792                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11793                                 alc268_acer_verbs },
11794                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11795                 .dac_nids = alc268_dac_nids,
11796                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11797                 .adc_nids = alc268_adc_nids_alt,
11798                 .capsrc_nids = alc268_capsrc_nids,
11799                 .hp_nid = 0x02,
11800                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11801                 .channel_mode = alc268_modes,
11802                 .input_mux = &alc268_acer_dmic_capture_source,
11803                 .unsol_event = alc268_acer_unsol_event,
11804                 .init_hook = alc268_acer_init_hook,
11805         },
11806         [ALC268_ACER_ASPIRE_ONE] = {
11807                 .mixers = { alc268_acer_aspire_one_mixer,
11808                                 alc268_capture_alt_mixer },
11809                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11810                                 alc268_acer_aspire_one_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_acer_lc_capture_source,
11820                 .unsol_event = alc268_acer_lc_unsol_event,
11821                 .init_hook = alc268_acer_lc_init_hook,
11822         },
11823         [ALC268_DELL] = {
11824                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
11825                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11826                                 alc268_dell_verbs },
11827                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11828                 .dac_nids = alc268_dac_nids,
11829                 .hp_nid = 0x02,
11830                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11831                 .channel_mode = alc268_modes,
11832                 .unsol_event = alc268_dell_unsol_event,
11833                 .init_hook = alc268_dell_init_hook,
11834                 .input_mux = &alc268_capture_source,
11835         },
11836         [ALC268_ZEPTO] = {
11837                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11838                             alc268_beep_mixer },
11839                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11840                                 alc268_toshiba_verbs },
11841                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11842                 .dac_nids = alc268_dac_nids,
11843                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11844                 .adc_nids = alc268_adc_nids_alt,
11845                 .capsrc_nids = alc268_capsrc_nids,
11846                 .hp_nid = 0x03,
11847                 .dig_out_nid = ALC268_DIGOUT_NID,
11848                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11849                 .channel_mode = alc268_modes,
11850                 .input_mux = &alc268_capture_source,
11851                 .unsol_event = alc268_toshiba_unsol_event,
11852                 .init_hook = alc268_toshiba_automute
11853         },
11854 #ifdef CONFIG_SND_DEBUG
11855         [ALC268_TEST] = {
11856                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11857                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11858                                 alc268_volume_init_verbs },
11859                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11860                 .dac_nids = alc268_dac_nids,
11861                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11862                 .adc_nids = alc268_adc_nids_alt,
11863                 .capsrc_nids = alc268_capsrc_nids,
11864                 .hp_nid = 0x03,
11865                 .dig_out_nid = ALC268_DIGOUT_NID,
11866                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11867                 .channel_mode = alc268_modes,
11868                 .input_mux = &alc268_capture_source,
11869         },
11870 #endif
11871 };
11872
11873 static int patch_alc268(struct hda_codec *codec)
11874 {
11875         struct alc_spec *spec;
11876         int board_config;
11877         int err;
11878
11879         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11880         if (spec == NULL)
11881                 return -ENOMEM;
11882
11883         codec->spec = spec;
11884
11885         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11886                                                   alc268_models,
11887                                                   alc268_cfg_tbl);
11888
11889         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11890                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11891                        "trying auto-probe from BIOS...\n");
11892                 board_config = ALC268_AUTO;
11893         }
11894
11895         if (board_config == ALC268_AUTO) {
11896                 /* automatic parse from the BIOS config */
11897                 err = alc268_parse_auto_config(codec);
11898                 if (err < 0) {
11899                         alc_free(codec);
11900                         return err;
11901                 } else if (!err) {
11902                         printk(KERN_INFO
11903                                "hda_codec: Cannot set up configuration "
11904                                "from BIOS.  Using base mode...\n");
11905                         board_config = ALC268_3ST;
11906                 }
11907         }
11908
11909         if (board_config != ALC268_AUTO)
11910                 setup_preset(spec, &alc268_presets[board_config]);
11911
11912         if (codec->vendor_id == 0x10ec0267) {
11913                 spec->stream_name_analog = "ALC267 Analog";
11914                 spec->stream_name_digital = "ALC267 Digital";
11915         } else {
11916                 spec->stream_name_analog = "ALC268 Analog";
11917                 spec->stream_name_digital = "ALC268 Digital";
11918         }
11919
11920         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11921         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11922         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11923
11924         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11925
11926         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11927                 /* override the amp caps for beep generator */
11928                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11929                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11930                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11931                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11932                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11933
11934         if (!spec->adc_nids && spec->input_mux) {
11935                 /* check whether NID 0x07 is valid */
11936                 unsigned int wcap = get_wcaps(codec, 0x07);
11937                 int i;
11938
11939                 /* get type */
11940                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11941                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11942                         spec->adc_nids = alc268_adc_nids_alt;
11943                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11944                         add_mixer(spec, alc268_capture_alt_mixer);
11945                 } else {
11946                         spec->adc_nids = alc268_adc_nids;
11947                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11948                         add_mixer(spec, alc268_capture_mixer);
11949                 }
11950                 spec->capsrc_nids = alc268_capsrc_nids;
11951                 /* set default input source */
11952                 for (i = 0; i < spec->num_adc_nids; i++)
11953                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11954                                 0, AC_VERB_SET_CONNECT_SEL,
11955                                 spec->input_mux->items[0].index);
11956         }
11957
11958         spec->vmaster_nid = 0x02;
11959
11960         codec->patch_ops = alc_patch_ops;
11961         if (board_config == ALC268_AUTO)
11962                 spec->init_hook = alc268_auto_init;
11963
11964         codec->proc_widget_hook = print_realtek_coef;
11965
11966         return 0;
11967 }
11968
11969 /*
11970  *  ALC269 channel source setting (2 channel)
11971  */
11972 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11973
11974 #define alc269_dac_nids         alc260_dac_nids
11975
11976 static hda_nid_t alc269_adc_nids[1] = {
11977         /* ADC1 */
11978         0x08,
11979 };
11980
11981 static hda_nid_t alc269_capsrc_nids[1] = {
11982         0x23,
11983 };
11984
11985 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11986  *       not a mux!
11987  */
11988
11989 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11990         .num_items = 2,
11991         .items = {
11992                 { "i-Mic", 0x5 },
11993                 { "e-Mic", 0x0 },
11994         },
11995 };
11996
11997 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11998         .num_items = 2,
11999         .items = {
12000                 { "i-Mic", 0x1 },
12001                 { "e-Mic", 0x0 },
12002         },
12003 };
12004
12005 #define alc269_modes            alc260_modes
12006 #define alc269_capture_source   alc880_lg_lw_capture_source
12007
12008 static struct snd_kcontrol_new alc269_base_mixer[] = {
12009         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12010         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12011         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12012         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12013         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12014         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12015         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12016         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12017         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12018         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12019         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12020         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12021         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12022         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12023         { } /* end */
12024 };
12025
12026 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12027         /* output mixer control */
12028         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12029         {
12030                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12031                 .name = "Master Playback Switch",
12032                 .info = snd_hda_mixer_amp_switch_info,
12033                 .get = snd_hda_mixer_amp_switch_get,
12034                 .put = alc268_acer_master_sw_put,
12035                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12036         },
12037         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12038         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12039         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12040         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12041         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12042         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12043         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12044         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12045         { }
12046 };
12047
12048 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12049         /* output mixer control */
12050         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12051         {
12052                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12053                 .name = "Master Playback Switch",
12054                 .info = snd_hda_mixer_amp_switch_info,
12055                 .get = snd_hda_mixer_amp_switch_get,
12056                 .put = alc268_acer_master_sw_put,
12057                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12058         },
12059         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12060         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12061         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12062         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12063         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12064         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12065         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12066         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12067         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12068         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12069         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12070         { }
12071 };
12072
12073 /* bind volumes of both NID 0x0c and 0x0d */
12074 static struct hda_bind_ctls alc269_epc_bind_vol = {
12075         .ops = &snd_hda_bind_vol,
12076         .values = {
12077                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12078                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12079                 0
12080         },
12081 };
12082
12083 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12084         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12085         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
12086         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12087         { } /* end */
12088 };
12089
12090 /* capture mixer elements */
12091 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12092         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12093         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12094         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12095         { } /* end */
12096 };
12097
12098 /* FSC amilo */
12099 static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
12100         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12101         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12102         HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12103         { } /* end */
12104 };
12105
12106 /* beep control */
12107 static struct snd_kcontrol_new alc269_beep_mixer[] = {
12108         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12109         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12110         { } /* end */
12111 };
12112
12113 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12114         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12115         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12116         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12117         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12118         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12119         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12120         { }
12121 };
12122
12123 static struct hda_verb alc269_lifebook_verbs[] = {
12124         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12125         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12126         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12127         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12128         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12129         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12130         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12131         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12132         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12133         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12134         { }
12135 };
12136
12137 /* toggle speaker-output according to the hp-jack state */
12138 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
12139 {
12140         unsigned int present;
12141         unsigned char bits;
12142
12143         present = snd_hda_codec_read(codec, 0x15, 0,
12144                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12145         bits = present ? AMP_IN_MUTE(0) : 0;
12146         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12147                         AMP_IN_MUTE(0), bits);
12148         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12149                         AMP_IN_MUTE(0), bits);
12150
12151         snd_hda_codec_write(codec, 0x20, 0,
12152                         AC_VERB_SET_COEF_INDEX, 0x0c);
12153         snd_hda_codec_write(codec, 0x20, 0,
12154                         AC_VERB_SET_PROC_COEF, 0x680);
12155
12156         snd_hda_codec_write(codec, 0x20, 0,
12157                         AC_VERB_SET_COEF_INDEX, 0x0c);
12158         snd_hda_codec_write(codec, 0x20, 0,
12159                         AC_VERB_SET_PROC_COEF, 0x480);
12160 }
12161
12162 /* toggle speaker-output according to the hp-jacks state */
12163 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12164 {
12165         unsigned int present;
12166         unsigned char bits;
12167
12168         /* Check laptop headphone socket */
12169         present = snd_hda_codec_read(codec, 0x15, 0,
12170                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12171
12172         /* Check port replicator headphone socket */
12173         present |= snd_hda_codec_read(codec, 0x1a, 0,
12174                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12175
12176         bits = present ? AMP_IN_MUTE(0) : 0;
12177         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12178                         AMP_IN_MUTE(0), bits);
12179         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12180                         AMP_IN_MUTE(0), bits);
12181
12182         snd_hda_codec_write(codec, 0x20, 0,
12183                         AC_VERB_SET_COEF_INDEX, 0x0c);
12184         snd_hda_codec_write(codec, 0x20, 0,
12185                         AC_VERB_SET_PROC_COEF, 0x680);
12186
12187         snd_hda_codec_write(codec, 0x20, 0,
12188                         AC_VERB_SET_COEF_INDEX, 0x0c);
12189         snd_hda_codec_write(codec, 0x20, 0,
12190                         AC_VERB_SET_PROC_COEF, 0x480);
12191 }
12192
12193 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12194 {
12195         unsigned int present;
12196
12197         present = snd_hda_codec_read(codec, 0x18, 0,
12198                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12199         snd_hda_codec_write(codec, 0x23, 0,
12200                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
12201 }
12202
12203 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12204 {
12205         unsigned int present_laptop;
12206         unsigned int present_dock;
12207
12208         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
12209                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12210
12211         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
12212                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12213
12214         /* Laptop mic port overrides dock mic port, design decision */
12215         if (present_dock)
12216                 snd_hda_codec_write(codec, 0x23, 0,
12217                                 AC_VERB_SET_CONNECT_SEL, 0x3);
12218         if (present_laptop)
12219                 snd_hda_codec_write(codec, 0x23, 0,
12220                                 AC_VERB_SET_CONNECT_SEL, 0x0);
12221         if (!present_dock && !present_laptop)
12222                 snd_hda_codec_write(codec, 0x23, 0,
12223                                 AC_VERB_SET_CONNECT_SEL, 0x1);
12224 }
12225
12226 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
12227                                     unsigned int res)
12228 {
12229         if ((res >> 26) == ALC880_HP_EVENT)
12230                 alc269_quanta_fl1_speaker_automute(codec);
12231         if ((res >> 26) == ALC880_MIC_EVENT)
12232                 alc269_quanta_fl1_mic_automute(codec);
12233 }
12234
12235 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
12236                                         unsigned int res)
12237 {
12238         if ((res >> 26) == ALC880_HP_EVENT)
12239                 alc269_lifebook_speaker_automute(codec);
12240         if ((res >> 26) == ALC880_MIC_EVENT)
12241                 alc269_lifebook_mic_autoswitch(codec);
12242 }
12243
12244 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
12245 {
12246         alc269_quanta_fl1_speaker_automute(codec);
12247         alc269_quanta_fl1_mic_automute(codec);
12248 }
12249
12250 static void alc269_lifebook_init_hook(struct hda_codec *codec)
12251 {
12252         alc269_lifebook_speaker_automute(codec);
12253         alc269_lifebook_mic_autoswitch(codec);
12254 }
12255
12256 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
12257         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12258         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
12259         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12260         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
12261         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12262         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12263         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12264         {}
12265 };
12266
12267 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
12268         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12269         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
12270         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12271         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
12272         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12273         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12274         {}
12275 };
12276
12277 /* toggle speaker-output according to the hp-jack state */
12278 static void alc269_speaker_automute(struct hda_codec *codec)
12279 {
12280         unsigned int present;
12281         unsigned char bits;
12282
12283         present = snd_hda_codec_read(codec, 0x15, 0,
12284                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12285         bits = present ? AMP_IN_MUTE(0) : 0;
12286         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12287                                 AMP_IN_MUTE(0), bits);
12288         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12289                                 AMP_IN_MUTE(0), bits);
12290 }
12291
12292 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
12293 {
12294         unsigned int present;
12295
12296         present = snd_hda_codec_read(codec, 0x18, 0,
12297                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12298         snd_hda_codec_write(codec, 0x23, 0,
12299                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
12300 }
12301
12302 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
12303 {
12304         unsigned int present;
12305
12306         present = snd_hda_codec_read(codec, 0x18, 0,
12307                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12308         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12309                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12310         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12311                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12312 }
12313
12314 /* unsolicited event for HP jack sensing */
12315 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
12316                                      unsigned int res)
12317 {
12318         if ((res >> 26) == ALC880_HP_EVENT)
12319                 alc269_speaker_automute(codec);
12320
12321         if ((res >> 26) == ALC880_MIC_EVENT)
12322                 alc269_eeepc_dmic_automute(codec);
12323 }
12324
12325 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
12326 {
12327         alc269_speaker_automute(codec);
12328         alc269_eeepc_dmic_automute(codec);
12329 }
12330
12331 /* unsolicited event for HP jack sensing */
12332 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
12333                                      unsigned int res)
12334 {
12335         if ((res >> 26) == ALC880_HP_EVENT)
12336                 alc269_speaker_automute(codec);
12337
12338         if ((res >> 26) == ALC880_MIC_EVENT)
12339                 alc269_eeepc_amic_automute(codec);
12340 }
12341
12342 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
12343 {
12344         alc269_speaker_automute(codec);
12345         alc269_eeepc_amic_automute(codec);
12346 }
12347
12348 /*
12349  * generic initialization of ADC, input mixers and output mixers
12350  */
12351 static struct hda_verb alc269_init_verbs[] = {
12352         /*
12353          * Unmute ADC0 and set the default input to mic-in
12354          */
12355         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12356
12357         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
12358          * analog-loopback mixer widget
12359          * Note: PASD motherboards uses the Line In 2 as the input for
12360          * front panel mic (mic 2)
12361          */
12362         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12363         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12364         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12365         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12366         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12367         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12368
12369         /*
12370          * Set up output mixers (0x0c - 0x0e)
12371          */
12372         /* set vol=0 to output mixers */
12373         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12374         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12375
12376         /* set up input amps for analog loopback */
12377         /* Amp Indices: DAC = 0, mixer = 1 */
12378         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12379         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12380         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12381         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12382         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12383         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12384
12385         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12386         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12387         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12388         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12389         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12390         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12391         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12392
12393         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12394         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12395         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12396         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12397         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12398         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12399         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12400
12401         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12402         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12403
12404         /* FIXME: use matrix-type input source selection */
12405         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12406         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12407         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12408         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12409         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12410         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12411
12412         /* set EAPD */
12413         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12414         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12415         { }
12416 };
12417
12418 /* add playback controls from the parsed DAC table */
12419 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12420                                              const struct auto_pin_cfg *cfg)
12421 {
12422         hda_nid_t nid;
12423         int err;
12424
12425         spec->multiout.num_dacs = 1;    /* only use one dac */
12426         spec->multiout.dac_nids = spec->private_dac_nids;
12427         spec->multiout.dac_nids[0] = 2;
12428
12429         nid = cfg->line_out_pins[0];
12430         if (nid) {
12431                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12432                                   "Front Playback Volume",
12433                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12434                 if (err < 0)
12435                         return err;
12436                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12437                                   "Front Playback Switch",
12438                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12439                 if (err < 0)
12440                         return err;
12441         }
12442
12443         nid = cfg->speaker_pins[0];
12444         if (nid) {
12445                 if (!cfg->line_out_pins[0]) {
12446                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12447                                           "Speaker Playback Volume",
12448                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12449                                                               HDA_OUTPUT));
12450                         if (err < 0)
12451                                 return err;
12452                 }
12453                 if (nid == 0x16) {
12454                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12455                                           "Speaker Playback Switch",
12456                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12457                                                               HDA_OUTPUT));
12458                         if (err < 0)
12459                                 return err;
12460                 } else {
12461                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12462                                           "Speaker Playback Switch",
12463                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12464                                                               HDA_OUTPUT));
12465                         if (err < 0)
12466                                 return err;
12467                 }
12468         }
12469         nid = cfg->hp_pins[0];
12470         if (nid) {
12471                 /* spec->multiout.hp_nid = 2; */
12472                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12473                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12474                                           "Headphone Playback Volume",
12475                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12476                                                               HDA_OUTPUT));
12477                         if (err < 0)
12478                                 return err;
12479                 }
12480                 if (nid == 0x16) {
12481                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12482                                           "Headphone Playback Switch",
12483                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12484                                                               HDA_OUTPUT));
12485                         if (err < 0)
12486                                 return err;
12487                 } else {
12488                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12489                                           "Headphone Playback Switch",
12490                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12491                                                               HDA_OUTPUT));
12492                         if (err < 0)
12493                                 return err;
12494                 }
12495         }
12496         return 0;
12497 }
12498
12499 static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
12500                                                 const struct auto_pin_cfg *cfg)
12501 {
12502         int err;
12503
12504         err = alc880_auto_create_analog_input_ctls(spec, cfg);
12505         if (err < 0)
12506                 return err;
12507         /* digital-mic input pin is excluded in alc880_auto_create..()
12508          * because it's under 0x18
12509          */
12510         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
12511             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
12512                 struct hda_input_mux *imux = &spec->private_imux;
12513                 imux->items[imux->num_items].label = "Int Mic";
12514                 imux->items[imux->num_items].index = 0x05;
12515                 imux->num_items++;
12516         }
12517         return 0;
12518 }
12519
12520 #ifdef CONFIG_SND_HDA_POWER_SAVE
12521 #define alc269_loopbacks        alc880_loopbacks
12522 #endif
12523
12524 /* pcm configuration: identiacal with ALC880 */
12525 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12526 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12527 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12528 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12529
12530 /*
12531  * BIOS auto configuration
12532  */
12533 static int alc269_parse_auto_config(struct hda_codec *codec)
12534 {
12535         struct alc_spec *spec = codec->spec;
12536         int i, err;
12537         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12538
12539         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12540                                            alc269_ignore);
12541         if (err < 0)
12542                 return err;
12543
12544         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12545         if (err < 0)
12546                 return err;
12547         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12548         if (err < 0)
12549                 return err;
12550
12551         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12552
12553         if (spec->autocfg.dig_out_pin)
12554                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12555
12556         if (spec->kctls.list)
12557                 add_mixer(spec, spec->kctls.list);
12558
12559         /* create a beep mixer control if the pin 0x1d isn't assigned */
12560         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12561                 if (spec->autocfg.input_pins[i] == 0x1d)
12562                         break;
12563         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12564                 add_mixer(spec, alc269_beep_mixer);
12565
12566         add_verb(spec, alc269_init_verbs);
12567         spec->num_mux_defs = 1;
12568         spec->input_mux = &spec->private_imux;
12569         /* set default input source */
12570         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12571                                   0, AC_VERB_SET_CONNECT_SEL,
12572                                   spec->input_mux->items[0].index);
12573
12574         err = alc_auto_add_mic_boost(codec);
12575         if (err < 0)
12576                 return err;
12577
12578         if (!spec->cap_mixer)
12579                 set_capture_mixer(spec);
12580
12581         store_pin_configs(codec);
12582         return 1;
12583 }
12584
12585 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12586 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12587 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12588
12589
12590 /* init callback for auto-configuration model -- overriding the default init */
12591 static void alc269_auto_init(struct hda_codec *codec)
12592 {
12593         struct alc_spec *spec = codec->spec;
12594         alc269_auto_init_multi_out(codec);
12595         alc269_auto_init_hp_out(codec);
12596         alc269_auto_init_analog_input(codec);
12597         if (spec->unsol_event)
12598                 alc_inithook(codec);
12599 }
12600
12601 /*
12602  * configuration and preset
12603  */
12604 static const char *alc269_models[ALC269_MODEL_LAST] = {
12605         [ALC269_BASIC]                  = "basic",
12606         [ALC269_QUANTA_FL1]             = "quanta",
12607         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12608         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
12609         [ALC269_FUJITSU]                = "fujitsu",
12610         [ALC269_LIFEBOOK]               = "lifebook"
12611 };
12612
12613 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12614         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12615         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12616                       ALC269_ASUS_EEEPC_P703),
12617         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12618                       ALC269_ASUS_EEEPC_P901),
12619         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12620                       ALC269_ASUS_EEEPC_P901),
12621         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
12622         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
12623         {}
12624 };
12625
12626 static struct alc_config_preset alc269_presets[] = {
12627         [ALC269_BASIC] = {
12628                 .mixers = { alc269_base_mixer },
12629                 .init_verbs = { alc269_init_verbs },
12630                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12631                 .dac_nids = alc269_dac_nids,
12632                 .hp_nid = 0x03,
12633                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12634                 .channel_mode = alc269_modes,
12635                 .input_mux = &alc269_capture_source,
12636         },
12637         [ALC269_QUANTA_FL1] = {
12638                 .mixers = { alc269_quanta_fl1_mixer },
12639                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
12640                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12641                 .dac_nids = alc269_dac_nids,
12642                 .hp_nid = 0x03,
12643                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12644                 .channel_mode = alc269_modes,
12645                 .input_mux = &alc269_capture_source,
12646                 .unsol_event = alc269_quanta_fl1_unsol_event,
12647                 .init_hook = alc269_quanta_fl1_init_hook,
12648         },
12649         [ALC269_ASUS_EEEPC_P703] = {
12650                 .mixers = { alc269_eeepc_mixer },
12651                 .cap_mixer = alc269_epc_capture_mixer,
12652                 .init_verbs = { alc269_init_verbs,
12653                                 alc269_eeepc_amic_init_verbs },
12654                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12655                 .dac_nids = alc269_dac_nids,
12656                 .hp_nid = 0x03,
12657                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12658                 .channel_mode = alc269_modes,
12659                 .input_mux = &alc269_eeepc_amic_capture_source,
12660                 .unsol_event = alc269_eeepc_amic_unsol_event,
12661                 .init_hook = alc269_eeepc_amic_inithook,
12662         },
12663         [ALC269_ASUS_EEEPC_P901] = {
12664                 .mixers = { alc269_eeepc_mixer },
12665                 .cap_mixer = alc269_epc_capture_mixer,
12666                 .init_verbs = { alc269_init_verbs,
12667                                 alc269_eeepc_dmic_init_verbs },
12668                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12669                 .dac_nids = alc269_dac_nids,
12670                 .hp_nid = 0x03,
12671                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12672                 .channel_mode = alc269_modes,
12673                 .input_mux = &alc269_eeepc_dmic_capture_source,
12674                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12675                 .init_hook = alc269_eeepc_dmic_inithook,
12676         },
12677         [ALC269_FUJITSU] = {
12678                 .mixers = { alc269_fujitsu_mixer, alc269_beep_mixer },
12679                 .cap_mixer = alc269_epc_capture_mixer,
12680                 .init_verbs = { alc269_init_verbs,
12681                                 alc269_eeepc_dmic_init_verbs },
12682                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12683                 .dac_nids = alc269_dac_nids,
12684                 .hp_nid = 0x03,
12685                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12686                 .channel_mode = alc269_modes,
12687                 .input_mux = &alc269_eeepc_dmic_capture_source,
12688                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12689                 .init_hook = alc269_eeepc_dmic_inithook,
12690         },
12691         [ALC269_LIFEBOOK] = {
12692                 .mixers = { alc269_lifebook_mixer },
12693                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
12694                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12695                 .dac_nids = alc269_dac_nids,
12696                 .hp_nid = 0x03,
12697                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12698                 .channel_mode = alc269_modes,
12699                 .input_mux = &alc269_capture_source,
12700                 .unsol_event = alc269_lifebook_unsol_event,
12701                 .init_hook = alc269_lifebook_init_hook,
12702         },
12703 };
12704
12705 static int patch_alc269(struct hda_codec *codec)
12706 {
12707         struct alc_spec *spec;
12708         int board_config;
12709         int err;
12710
12711         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12712         if (spec == NULL)
12713                 return -ENOMEM;
12714
12715         codec->spec = spec;
12716
12717         alc_fix_pll_init(codec, 0x20, 0x04, 15);
12718
12719         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
12720                                                   alc269_models,
12721                                                   alc269_cfg_tbl);
12722
12723         if (board_config < 0) {
12724                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
12725                        "trying auto-probe from BIOS...\n");
12726                 board_config = ALC269_AUTO;
12727         }
12728
12729         if (board_config == ALC269_AUTO) {
12730                 /* automatic parse from the BIOS config */
12731                 err = alc269_parse_auto_config(codec);
12732                 if (err < 0) {
12733                         alc_free(codec);
12734                         return err;
12735                 } else if (!err) {
12736                         printk(KERN_INFO
12737                                "hda_codec: Cannot set up configuration "
12738                                "from BIOS.  Using base mode...\n");
12739                         board_config = ALC269_BASIC;
12740                 }
12741         }
12742
12743         if (board_config != ALC269_AUTO)
12744                 setup_preset(spec, &alc269_presets[board_config]);
12745
12746         spec->stream_name_analog = "ALC269 Analog";
12747         spec->stream_analog_playback = &alc269_pcm_analog_playback;
12748         spec->stream_analog_capture = &alc269_pcm_analog_capture;
12749
12750         spec->stream_name_digital = "ALC269 Digital";
12751         spec->stream_digital_playback = &alc269_pcm_digital_playback;
12752         spec->stream_digital_capture = &alc269_pcm_digital_capture;
12753
12754         spec->adc_nids = alc269_adc_nids;
12755         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12756         spec->capsrc_nids = alc269_capsrc_nids;
12757         if (!spec->cap_mixer)
12758                 set_capture_mixer(spec);
12759
12760         codec->patch_ops = alc_patch_ops;
12761         if (board_config == ALC269_AUTO)
12762                 spec->init_hook = alc269_auto_init;
12763 #ifdef CONFIG_SND_HDA_POWER_SAVE
12764         if (!spec->loopback.amplist)
12765                 spec->loopback.amplist = alc269_loopbacks;
12766 #endif
12767         codec->proc_widget_hook = print_realtek_coef;
12768
12769         return 0;
12770 }
12771
12772 /*
12773  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
12774  */
12775
12776 /*
12777  * set the path ways for 2 channel output
12778  * need to set the codec line out and mic 1 pin widgets to inputs
12779  */
12780 static struct hda_verb alc861_threestack_ch2_init[] = {
12781         /* set pin widget 1Ah (line in) for input */
12782         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12783         /* set pin widget 18h (mic1/2) for input, for mic also enable
12784          * the vref
12785          */
12786         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12787
12788         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12789 #if 0
12790         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12791         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12792 #endif
12793         { } /* end */
12794 };
12795 /*
12796  * 6ch mode
12797  * need to set the codec line out and mic 1 pin widgets to outputs
12798  */
12799 static struct hda_verb alc861_threestack_ch6_init[] = {
12800         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12801         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12802         /* set pin widget 18h (mic1) for output (CLFE)*/
12803         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12804
12805         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12806         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12807
12808         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12809 #if 0
12810         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12811         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12812 #endif
12813         { } /* end */
12814 };
12815
12816 static struct hda_channel_mode alc861_threestack_modes[2] = {
12817         { 2, alc861_threestack_ch2_init },
12818         { 6, alc861_threestack_ch6_init },
12819 };
12820 /* Set mic1 as input and unmute the mixer */
12821 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
12822         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12823         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12824         { } /* end */
12825 };
12826 /* Set mic1 as output and mute mixer */
12827 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
12828         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12829         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12830         { } /* end */
12831 };
12832
12833 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
12834         { 2, alc861_uniwill_m31_ch2_init },
12835         { 4, alc861_uniwill_m31_ch4_init },
12836 };
12837
12838 /* Set mic1 and line-in as input and unmute the mixer */
12839 static struct hda_verb alc861_asus_ch2_init[] = {
12840         /* set pin widget 1Ah (line in) for input */
12841         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12842         /* set pin widget 18h (mic1/2) for input, for mic also enable
12843          * the vref
12844          */
12845         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12846
12847         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12848 #if 0
12849         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12850         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12851 #endif
12852         { } /* end */
12853 };
12854 /* Set mic1 nad line-in as output and mute mixer */
12855 static struct hda_verb alc861_asus_ch6_init[] = {
12856         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12857         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12858         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12859         /* set pin widget 18h (mic1) for output (CLFE)*/
12860         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12861         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12862         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12863         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12864
12865         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12866 #if 0
12867         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12868         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12869 #endif
12870         { } /* end */
12871 };
12872
12873 static struct hda_channel_mode alc861_asus_modes[2] = {
12874         { 2, alc861_asus_ch2_init },
12875         { 6, alc861_asus_ch6_init },
12876 };
12877
12878 /* patch-ALC861 */
12879
12880 static struct snd_kcontrol_new alc861_base_mixer[] = {
12881         /* output mixer control */
12882         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12883         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12884         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12885         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12886         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12887
12888         /*Input mixer control */
12889         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12890            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12891         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12892         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12893         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12894         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12895         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12896         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12897         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12898         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12899
12900         { } /* end */
12901 };
12902
12903 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12904         /* output mixer control */
12905         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12906         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12907         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12908         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12909         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12910
12911         /* Input mixer control */
12912         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12913            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12914         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12915         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12916         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12917         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12918         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12919         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12920         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12921         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12922
12923         {
12924                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12925                 .name = "Channel Mode",
12926                 .info = alc_ch_mode_info,
12927                 .get = alc_ch_mode_get,
12928                 .put = alc_ch_mode_put,
12929                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
12930         },
12931         { } /* end */
12932 };
12933
12934 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
12935         /* output mixer control */
12936         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12937         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12938         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12939
12940         { } /* end */
12941 };
12942
12943 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
12944         /* output mixer control */
12945         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12946         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12947         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12948         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12949         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12950
12951         /* Input mixer control */
12952         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12953            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12954         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12955         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12956         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12957         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12958         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12959         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12960         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12961         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12962
12963         {
12964                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12965                 .name = "Channel Mode",
12966                 .info = alc_ch_mode_info,
12967                 .get = alc_ch_mode_get,
12968                 .put = alc_ch_mode_put,
12969                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
12970         },
12971         { } /* end */
12972 };
12973
12974 static struct snd_kcontrol_new alc861_asus_mixer[] = {
12975         /* output mixer control */
12976         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12977         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12978         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12979         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12980         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12981
12982         /* Input mixer control */
12983         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12984         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12985         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12986         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12987         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12988         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12989         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12990         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12991         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12992         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
12993
12994         {
12995                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12996                 .name = "Channel Mode",
12997                 .info = alc_ch_mode_info,
12998                 .get = alc_ch_mode_get,
12999                 .put = alc_ch_mode_put,
13000                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13001         },
13002         { }
13003 };
13004
13005 /* additional mixer */
13006 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13007         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13008         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13009         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
13010         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
13011         { }
13012 };
13013
13014 /*
13015  * generic initialization of ADC, input mixers and output mixers
13016  */
13017 static struct hda_verb alc861_base_init_verbs[] = {
13018         /*
13019          * Unmute ADC0 and set the default input to mic-in
13020          */
13021         /* port-A for surround (rear panel) */
13022         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13023         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13024         /* port-B for mic-in (rear panel) with vref */
13025         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13026         /* port-C for line-in (rear panel) */
13027         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13028         /* port-D for Front */
13029         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13030         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13031         /* port-E for HP out (front panel) */
13032         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13033         /* route front PCM to HP */
13034         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13035         /* port-F for mic-in (front panel) with vref */
13036         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13037         /* port-G for CLFE (rear panel) */
13038         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13039         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13040         /* port-H for side (rear panel) */
13041         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13042         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13043         /* CD-in */
13044         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13045         /* route front mic to ADC1*/
13046         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13047         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13048
13049         /* Unmute DAC0~3 & spdif out*/
13050         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13051         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13052         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13053         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13054         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13055
13056         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13057         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13058         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13059         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13060         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13061
13062         /* Unmute Stereo Mixer 15 */
13063         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13064         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13065         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13066         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13067
13068         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13069         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13070         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13071         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13072         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13073         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13074         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13075         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13076         /* hp used DAC 3 (Front) */
13077         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13078         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13079
13080         { }
13081 };
13082
13083 static struct hda_verb alc861_threestack_init_verbs[] = {
13084         /*
13085          * Unmute ADC0 and set the default input to mic-in
13086          */
13087         /* port-A for surround (rear panel) */
13088         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13089         /* port-B for mic-in (rear panel) with vref */
13090         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13091         /* port-C for line-in (rear panel) */
13092         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13093         /* port-D for Front */
13094         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13095         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13096         /* port-E for HP out (front panel) */
13097         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13098         /* route front PCM to HP */
13099         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13100         /* port-F for mic-in (front panel) with vref */
13101         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13102         /* port-G for CLFE (rear panel) */
13103         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13104         /* port-H for side (rear panel) */
13105         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13106         /* CD-in */
13107         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13108         /* route front mic to ADC1*/
13109         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13110         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13111         /* Unmute DAC0~3 & spdif out*/
13112         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13113         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13114         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13115         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13116         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13117
13118         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13119         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13120         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13121         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13122         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13123
13124         /* Unmute Stereo Mixer 15 */
13125         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13126         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13127         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13128         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13129
13130         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13131         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13132         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13133         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13134         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13135         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13136         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13137         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13138         /* hp used DAC 3 (Front) */
13139         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13140         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13141         { }
13142 };
13143
13144 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13145         /*
13146          * Unmute ADC0 and set the default input to mic-in
13147          */
13148         /* port-A for surround (rear panel) */
13149         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13150         /* port-B for mic-in (rear panel) with vref */
13151         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13152         /* port-C for line-in (rear panel) */
13153         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13154         /* port-D for Front */
13155         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13156         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13157         /* port-E for HP out (front panel) */
13158         /* this has to be set to VREF80 */
13159         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13160         /* route front PCM to HP */
13161         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13162         /* port-F for mic-in (front panel) with vref */
13163         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13164         /* port-G for CLFE (rear panel) */
13165         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13166         /* port-H for side (rear panel) */
13167         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13168         /* CD-in */
13169         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13170         /* route front mic to ADC1*/
13171         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13172         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13173         /* Unmute DAC0~3 & spdif out*/
13174         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13175         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13176         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13177         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13178         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13179
13180         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13181         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13182         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13183         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13184         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13185
13186         /* Unmute Stereo Mixer 15 */
13187         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13188         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13189         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13190         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13191
13192         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13193         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13194         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13195         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13196         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13197         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13198         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13199         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13200         /* hp used DAC 3 (Front) */
13201         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13202         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13203         { }
13204 };
13205
13206 static struct hda_verb alc861_asus_init_verbs[] = {
13207         /*
13208          * Unmute ADC0 and set the default input to mic-in
13209          */
13210         /* port-A for surround (rear panel)
13211          * according to codec#0 this is the HP jack
13212          */
13213         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
13214         /* route front PCM to HP */
13215         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
13216         /* port-B for mic-in (rear panel) with vref */
13217         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13218         /* port-C for line-in (rear panel) */
13219         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13220         /* port-D for Front */
13221         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13222         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13223         /* port-E for HP out (front panel) */
13224         /* this has to be set to VREF80 */
13225         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13226         /* route front PCM to HP */
13227         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13228         /* port-F for mic-in (front panel) with vref */
13229         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13230         /* port-G for CLFE (rear panel) */
13231         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13232         /* port-H for side (rear panel) */
13233         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13234         /* CD-in */
13235         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13236         /* route front mic to ADC1*/
13237         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13238         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13239         /* Unmute DAC0~3 & spdif out*/
13240         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13241         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13242         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13243         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13244         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13245         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13246         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13247         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13248         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13249         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13250
13251         /* Unmute Stereo Mixer 15 */
13252         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13253         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13254         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13255         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13256
13257         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13258         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13259         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13260         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13261         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13262         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13263         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13264         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13265         /* hp used DAC 3 (Front) */
13266         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13267         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13268         { }
13269 };
13270
13271 /* additional init verbs for ASUS laptops */
13272 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
13273         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
13274         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
13275         { }
13276 };
13277
13278 /*
13279  * generic initialization of ADC, input mixers and output mixers
13280  */
13281 static struct hda_verb alc861_auto_init_verbs[] = {
13282         /*
13283          * Unmute ADC0 and set the default input to mic-in
13284          */
13285         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
13286         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13287
13288         /* Unmute DAC0~3 & spdif out*/
13289         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13290         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13291         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13292         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13293         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13294
13295         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13296         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13297         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13298         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13299         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13300
13301         /* Unmute Stereo Mixer 15 */
13302         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13303         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13304         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13305         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
13306
13307         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13308         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13309         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13310         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13311         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13312         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13313         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13314         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13315
13316         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13317         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13318         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13319         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13320         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13321         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13322         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13323         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13324
13325         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
13326
13327         { }
13328 };
13329
13330 static struct hda_verb alc861_toshiba_init_verbs[] = {
13331         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13332
13333         { }
13334 };
13335
13336 /* toggle speaker-output according to the hp-jack state */
13337 static void alc861_toshiba_automute(struct hda_codec *codec)
13338 {
13339         unsigned int present;
13340
13341         present = snd_hda_codec_read(codec, 0x0f, 0,
13342                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13343         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
13344                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13345         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
13346                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
13347 }
13348
13349 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
13350                                        unsigned int res)
13351 {
13352         if ((res >> 26) == ALC880_HP_EVENT)
13353                 alc861_toshiba_automute(codec);
13354 }
13355
13356 /* pcm configuration: identiacal with ALC880 */
13357 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
13358 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
13359 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
13360 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
13361
13362
13363 #define ALC861_DIGOUT_NID       0x07
13364
13365 static struct hda_channel_mode alc861_8ch_modes[1] = {
13366         { 8, NULL }
13367 };
13368
13369 static hda_nid_t alc861_dac_nids[4] = {
13370         /* front, surround, clfe, side */
13371         0x03, 0x06, 0x05, 0x04
13372 };
13373
13374 static hda_nid_t alc660_dac_nids[3] = {
13375         /* front, clfe, surround */
13376         0x03, 0x05, 0x06
13377 };
13378
13379 static hda_nid_t alc861_adc_nids[1] = {
13380         /* ADC0-2 */
13381         0x08,
13382 };
13383
13384 static struct hda_input_mux alc861_capture_source = {
13385         .num_items = 5,
13386         .items = {
13387                 { "Mic", 0x0 },
13388                 { "Front Mic", 0x3 },
13389                 { "Line", 0x1 },
13390                 { "CD", 0x4 },
13391                 { "Mixer", 0x5 },
13392         },
13393 };
13394
13395 /* fill in the dac_nids table from the parsed pin configuration */
13396 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13397                                      const struct auto_pin_cfg *cfg)
13398 {
13399         int i;
13400         hda_nid_t nid;
13401
13402         spec->multiout.dac_nids = spec->private_dac_nids;
13403         for (i = 0; i < cfg->line_outs; i++) {
13404                 nid = cfg->line_out_pins[i];
13405                 if (nid) {
13406                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13407                                 continue;
13408                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13409                 }
13410         }
13411         spec->multiout.num_dacs = cfg->line_outs;
13412         return 0;
13413 }
13414
13415 /* add playback controls from the parsed DAC table */
13416 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13417                                              const struct auto_pin_cfg *cfg)
13418 {
13419         char name[32];
13420         static const char *chname[4] = {
13421                 "Front", "Surround", NULL /*CLFE*/, "Side"
13422         };
13423         hda_nid_t nid;
13424         int i, idx, err;
13425
13426         for (i = 0; i < cfg->line_outs; i++) {
13427                 nid = spec->multiout.dac_nids[i];
13428                 if (!nid)
13429                         continue;
13430                 if (nid == 0x05) {
13431                         /* Center/LFE */
13432                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13433                                           "Center Playback Switch",
13434                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13435                                                               HDA_OUTPUT));
13436                         if (err < 0)
13437                                 return err;
13438                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13439                                           "LFE Playback Switch",
13440                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13441                                                               HDA_OUTPUT));
13442                         if (err < 0)
13443                                 return err;
13444                 } else {
13445                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13446                              idx++)
13447                                 if (nid == alc861_dac_nids[idx])
13448                                         break;
13449                         sprintf(name, "%s Playback Switch", chname[idx]);
13450                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13451                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13452                                                               HDA_OUTPUT));
13453                         if (err < 0)
13454                                 return err;
13455                 }
13456         }
13457         return 0;
13458 }
13459
13460 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13461 {
13462         int err;
13463         hda_nid_t nid;
13464
13465         if (!pin)
13466                 return 0;
13467
13468         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13469                 nid = 0x03;
13470                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13471                                   "Headphone Playback Switch",
13472                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13473                 if (err < 0)
13474                         return err;
13475                 spec->multiout.hp_nid = nid;
13476         }
13477         return 0;
13478 }
13479
13480 /* create playback/capture controls for input pins */
13481 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13482                                                 const struct auto_pin_cfg *cfg)
13483 {
13484         struct hda_input_mux *imux = &spec->private_imux;
13485         int i, err, idx, idx1;
13486
13487         for (i = 0; i < AUTO_PIN_LAST; i++) {
13488                 switch (cfg->input_pins[i]) {
13489                 case 0x0c:
13490                         idx1 = 1;
13491                         idx = 2;        /* Line In */
13492                         break;
13493                 case 0x0f:
13494                         idx1 = 2;
13495                         idx = 2;        /* Line In */
13496                         break;
13497                 case 0x0d:
13498                         idx1 = 0;
13499                         idx = 1;        /* Mic In */
13500                         break;
13501                 case 0x10:
13502                         idx1 = 3;
13503                         idx = 1;        /* Mic In */
13504                         break;
13505                 case 0x11:
13506                         idx1 = 4;
13507                         idx = 0;        /* CD */
13508                         break;
13509                 default:
13510                         continue;
13511                 }
13512
13513                 err = new_analog_input(spec, cfg->input_pins[i],
13514                                        auto_pin_cfg_labels[i], idx, 0x15);
13515                 if (err < 0)
13516                         return err;
13517
13518                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13519                 imux->items[imux->num_items].index = idx1;
13520                 imux->num_items++;
13521         }
13522         return 0;
13523 }
13524
13525 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13526                                               hda_nid_t nid,
13527                                               int pin_type, int dac_idx)
13528 {
13529         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13530                             pin_type);
13531         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13532                             AMP_OUT_UNMUTE);
13533 }
13534
13535 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13536 {
13537         struct alc_spec *spec = codec->spec;
13538         int i;
13539
13540         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13541         for (i = 0; i < spec->autocfg.line_outs; i++) {
13542                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13543                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13544                 if (nid)
13545                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13546                                                           spec->multiout.dac_nids[i]);
13547         }
13548 }
13549
13550 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13551 {
13552         struct alc_spec *spec = codec->spec;
13553         hda_nid_t pin;
13554
13555         pin = spec->autocfg.hp_pins[0];
13556         if (pin) /* connect to front */
13557                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13558                                                   spec->multiout.dac_nids[0]);
13559         pin = spec->autocfg.speaker_pins[0];
13560         if (pin)
13561                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13562 }
13563
13564 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13565 {
13566         struct alc_spec *spec = codec->spec;
13567         int i;
13568
13569         for (i = 0; i < AUTO_PIN_LAST; i++) {
13570                 hda_nid_t nid = spec->autocfg.input_pins[i];
13571                 if (nid >= 0x0c && nid <= 0x11) {
13572                         snd_hda_codec_write(codec, nid, 0,
13573                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13574                                             i <= AUTO_PIN_FRONT_MIC ?
13575                                             PIN_VREF80 : PIN_IN);
13576                 }
13577         }
13578 }
13579
13580 /* parse the BIOS configuration and set up the alc_spec */
13581 /* return 1 if successful, 0 if the proper config is not found,
13582  * or a negative error code
13583  */
13584 static int alc861_parse_auto_config(struct hda_codec *codec)
13585 {
13586         struct alc_spec *spec = codec->spec;
13587         int err;
13588         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13589
13590         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13591                                            alc861_ignore);
13592         if (err < 0)
13593                 return err;
13594         if (!spec->autocfg.line_outs)
13595                 return 0; /* can't find valid BIOS pin config */
13596
13597         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13598         if (err < 0)
13599                 return err;
13600         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13601         if (err < 0)
13602                 return err;
13603         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13604         if (err < 0)
13605                 return err;
13606         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13607         if (err < 0)
13608                 return err;
13609
13610         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13611
13612         if (spec->autocfg.dig_out_pin)
13613                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13614
13615         if (spec->kctls.list)
13616                 add_mixer(spec, spec->kctls.list);
13617
13618         add_verb(spec, alc861_auto_init_verbs);
13619
13620         spec->num_mux_defs = 1;
13621         spec->input_mux = &spec->private_imux;
13622
13623         spec->adc_nids = alc861_adc_nids;
13624         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13625         set_capture_mixer(spec);
13626
13627         store_pin_configs(codec);
13628         return 1;
13629 }
13630
13631 /* additional initialization for auto-configuration model */
13632 static void alc861_auto_init(struct hda_codec *codec)
13633 {
13634         struct alc_spec *spec = codec->spec;
13635         alc861_auto_init_multi_out(codec);
13636         alc861_auto_init_hp_out(codec);
13637         alc861_auto_init_analog_input(codec);
13638         if (spec->unsol_event)
13639                 alc_inithook(codec);
13640 }
13641
13642 #ifdef CONFIG_SND_HDA_POWER_SAVE
13643 static struct hda_amp_list alc861_loopbacks[] = {
13644         { 0x15, HDA_INPUT, 0 },
13645         { 0x15, HDA_INPUT, 1 },
13646         { 0x15, HDA_INPUT, 2 },
13647         { 0x15, HDA_INPUT, 3 },
13648         { } /* end */
13649 };
13650 #endif
13651
13652
13653 /*
13654  * configuration and preset
13655  */
13656 static const char *alc861_models[ALC861_MODEL_LAST] = {
13657         [ALC861_3ST]            = "3stack",
13658         [ALC660_3ST]            = "3stack-660",
13659         [ALC861_3ST_DIG]        = "3stack-dig",
13660         [ALC861_6ST_DIG]        = "6stack-dig",
13661         [ALC861_UNIWILL_M31]    = "uniwill-m31",
13662         [ALC861_TOSHIBA]        = "toshiba",
13663         [ALC861_ASUS]           = "asus",
13664         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
13665         [ALC861_AUTO]           = "auto",
13666 };
13667
13668 static struct snd_pci_quirk alc861_cfg_tbl[] = {
13669         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
13670         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13671         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13672         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
13673         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
13674         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
13675         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
13676         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
13677          *        Any other models that need this preset?
13678          */
13679         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
13680         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
13681         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
13682         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
13683         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
13684         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
13685         /* FIXME: the below seems conflict */
13686         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
13687         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
13688         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
13689         {}
13690 };
13691
13692 static struct alc_config_preset alc861_presets[] = {
13693         [ALC861_3ST] = {
13694                 .mixers = { alc861_3ST_mixer },
13695                 .init_verbs = { alc861_threestack_init_verbs },
13696                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13697                 .dac_nids = alc861_dac_nids,
13698                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13699                 .channel_mode = alc861_threestack_modes,
13700                 .need_dac_fix = 1,
13701                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13702                 .adc_nids = alc861_adc_nids,
13703                 .input_mux = &alc861_capture_source,
13704         },
13705         [ALC861_3ST_DIG] = {
13706                 .mixers = { alc861_base_mixer },
13707                 .init_verbs = { alc861_threestack_init_verbs },
13708                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13709                 .dac_nids = alc861_dac_nids,
13710                 .dig_out_nid = ALC861_DIGOUT_NID,
13711                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13712                 .channel_mode = alc861_threestack_modes,
13713                 .need_dac_fix = 1,
13714                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13715                 .adc_nids = alc861_adc_nids,
13716                 .input_mux = &alc861_capture_source,
13717         },
13718         [ALC861_6ST_DIG] = {
13719                 .mixers = { alc861_base_mixer },
13720                 .init_verbs = { alc861_base_init_verbs },
13721                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13722                 .dac_nids = alc861_dac_nids,
13723                 .dig_out_nid = ALC861_DIGOUT_NID,
13724                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
13725                 .channel_mode = alc861_8ch_modes,
13726                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13727                 .adc_nids = alc861_adc_nids,
13728                 .input_mux = &alc861_capture_source,
13729         },
13730         [ALC660_3ST] = {
13731                 .mixers = { alc861_3ST_mixer },
13732                 .init_verbs = { alc861_threestack_init_verbs },
13733                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
13734                 .dac_nids = alc660_dac_nids,
13735                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13736                 .channel_mode = alc861_threestack_modes,
13737                 .need_dac_fix = 1,
13738                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13739                 .adc_nids = alc861_adc_nids,
13740                 .input_mux = &alc861_capture_source,
13741         },
13742         [ALC861_UNIWILL_M31] = {
13743                 .mixers = { alc861_uniwill_m31_mixer },
13744                 .init_verbs = { alc861_uniwill_m31_init_verbs },
13745                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13746                 .dac_nids = alc861_dac_nids,
13747                 .dig_out_nid = ALC861_DIGOUT_NID,
13748                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
13749                 .channel_mode = alc861_uniwill_m31_modes,
13750                 .need_dac_fix = 1,
13751                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13752                 .adc_nids = alc861_adc_nids,
13753                 .input_mux = &alc861_capture_source,
13754         },
13755         [ALC861_TOSHIBA] = {
13756                 .mixers = { alc861_toshiba_mixer },
13757                 .init_verbs = { alc861_base_init_verbs,
13758                                 alc861_toshiba_init_verbs },
13759                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13760                 .dac_nids = alc861_dac_nids,
13761                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13762                 .channel_mode = alc883_3ST_2ch_modes,
13763                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13764                 .adc_nids = alc861_adc_nids,
13765                 .input_mux = &alc861_capture_source,
13766                 .unsol_event = alc861_toshiba_unsol_event,
13767                 .init_hook = alc861_toshiba_automute,
13768         },
13769         [ALC861_ASUS] = {
13770                 .mixers = { alc861_asus_mixer },
13771                 .init_verbs = { alc861_asus_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_asus_modes),
13776                 .channel_mode = alc861_asus_modes,
13777                 .need_dac_fix = 1,
13778                 .hp_nid = 0x06,
13779                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13780                 .adc_nids = alc861_adc_nids,
13781                 .input_mux = &alc861_capture_source,
13782         },
13783         [ALC861_ASUS_LAPTOP] = {
13784                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
13785                 .init_verbs = { alc861_asus_init_verbs,
13786                                 alc861_asus_laptop_init_verbs },
13787                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13788                 .dac_nids = alc861_dac_nids,
13789                 .dig_out_nid = ALC861_DIGOUT_NID,
13790                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13791                 .channel_mode = alc883_3ST_2ch_modes,
13792                 .need_dac_fix = 1,
13793                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13794                 .adc_nids = alc861_adc_nids,
13795                 .input_mux = &alc861_capture_source,
13796         },
13797 };
13798
13799
13800 static int patch_alc861(struct hda_codec *codec)
13801 {
13802         struct alc_spec *spec;
13803         int board_config;
13804         int err;
13805
13806         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13807         if (spec == NULL)
13808                 return -ENOMEM;
13809
13810         codec->spec = spec;
13811
13812         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
13813                                                   alc861_models,
13814                                                   alc861_cfg_tbl);
13815
13816         if (board_config < 0) {
13817                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
13818                        "trying auto-probe from BIOS...\n");
13819                 board_config = ALC861_AUTO;
13820         }
13821
13822         if (board_config == ALC861_AUTO) {
13823                 /* automatic parse from the BIOS config */
13824                 err = alc861_parse_auto_config(codec);
13825                 if (err < 0) {
13826                         alc_free(codec);
13827                         return err;
13828                 } else if (!err) {
13829                         printk(KERN_INFO
13830                                "hda_codec: Cannot set up configuration "
13831                                "from BIOS.  Using base mode...\n");
13832                    board_config = ALC861_3ST_DIG;
13833                 }
13834         }
13835
13836         if (board_config != ALC861_AUTO)
13837                 setup_preset(spec, &alc861_presets[board_config]);
13838
13839         spec->stream_name_analog = "ALC861 Analog";
13840         spec->stream_analog_playback = &alc861_pcm_analog_playback;
13841         spec->stream_analog_capture = &alc861_pcm_analog_capture;
13842
13843         spec->stream_name_digital = "ALC861 Digital";
13844         spec->stream_digital_playback = &alc861_pcm_digital_playback;
13845         spec->stream_digital_capture = &alc861_pcm_digital_capture;
13846
13847         spec->vmaster_nid = 0x03;
13848
13849         codec->patch_ops = alc_patch_ops;
13850         if (board_config == ALC861_AUTO)
13851                 spec->init_hook = alc861_auto_init;
13852 #ifdef CONFIG_SND_HDA_POWER_SAVE
13853         if (!spec->loopback.amplist)
13854                 spec->loopback.amplist = alc861_loopbacks;
13855 #endif
13856         codec->proc_widget_hook = print_realtek_coef;
13857
13858         return 0;
13859 }
13860
13861 /*
13862  * ALC861-VD support
13863  *
13864  * Based on ALC882
13865  *
13866  * In addition, an independent DAC
13867  */
13868 #define ALC861VD_DIGOUT_NID     0x06
13869
13870 static hda_nid_t alc861vd_dac_nids[4] = {
13871         /* front, surr, clfe, side surr */
13872         0x02, 0x03, 0x04, 0x05
13873 };
13874
13875 /* dac_nids for ALC660vd are in a different order - according to
13876  * Realtek's driver.
13877  * This should probably tesult in a different mixer for 6stack models
13878  * of ALC660vd codecs, but for now there is only 3stack mixer
13879  * - and it is the same as in 861vd.
13880  * adc_nids in ALC660vd are (is) the same as in 861vd
13881  */
13882 static hda_nid_t alc660vd_dac_nids[3] = {
13883         /* front, rear, clfe, rear_surr */
13884         0x02, 0x04, 0x03
13885 };
13886
13887 static hda_nid_t alc861vd_adc_nids[1] = {
13888         /* ADC0 */
13889         0x09,
13890 };
13891
13892 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
13893
13894 /* input MUX */
13895 /* FIXME: should be a matrix-type input source selection */
13896 static struct hda_input_mux alc861vd_capture_source = {
13897         .num_items = 4,
13898         .items = {
13899                 { "Mic", 0x0 },
13900                 { "Front Mic", 0x1 },
13901                 { "Line", 0x2 },
13902                 { "CD", 0x4 },
13903         },
13904 };
13905
13906 static struct hda_input_mux alc861vd_dallas_capture_source = {
13907         .num_items = 2,
13908         .items = {
13909                 { "Ext Mic", 0x0 },
13910                 { "Int Mic", 0x1 },
13911         },
13912 };
13913
13914 static struct hda_input_mux alc861vd_hp_capture_source = {
13915         .num_items = 2,
13916         .items = {
13917                 { "Front Mic", 0x0 },
13918                 { "ATAPI Mic", 0x1 },
13919         },
13920 };
13921
13922 /*
13923  * 2ch mode
13924  */
13925 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
13926         { 2, NULL }
13927 };
13928
13929 /*
13930  * 6ch mode
13931  */
13932 static struct hda_verb alc861vd_6stack_ch6_init[] = {
13933         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13934         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13935         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13936         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13937         { } /* end */
13938 };
13939
13940 /*
13941  * 8ch mode
13942  */
13943 static struct hda_verb alc861vd_6stack_ch8_init[] = {
13944         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13945         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13946         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13947         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13948         { } /* end */
13949 };
13950
13951 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
13952         { 6, alc861vd_6stack_ch6_init },
13953         { 8, alc861vd_6stack_ch8_init },
13954 };
13955
13956 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
13957         {
13958                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13959                 .name = "Channel Mode",
13960                 .info = alc_ch_mode_info,
13961                 .get = alc_ch_mode_get,
13962                 .put = alc_ch_mode_put,
13963         },
13964         { } /* end */
13965 };
13966
13967 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13968  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13969  */
13970 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
13971         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13972         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13973
13974         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13975         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
13976
13977         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
13978                                 HDA_OUTPUT),
13979         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
13980                                 HDA_OUTPUT),
13981         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
13982         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
13983
13984         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
13985         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
13986
13987         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13988
13989         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13990         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13991         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13992
13993         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13994         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13995         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13996
13997         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13998         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13999
14000         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14001         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14002
14003         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14004         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14005
14006         { } /* end */
14007 };
14008
14009 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14010         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14011         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14012
14013         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14014
14015         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14016         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14017         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14018
14019         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14020         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14021         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14022
14023         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14024         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14025
14026         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14027         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14028
14029         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14030         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14031
14032         { } /* end */
14033 };
14034
14035 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14036         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14037         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14038         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14039
14040         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14041
14042         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14043         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14044         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14045
14046         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14047         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14048         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14049
14050         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14051         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14052
14053         { } /* end */
14054 };
14055
14056 /* Pin assignment: Speaker=0x14, HP = 0x15,
14057  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14058  */
14059 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14060         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14061         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14062         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14063         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14064         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14065         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14066         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14067         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14068         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14069         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14070         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
14071         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
14072         { } /* end */
14073 };
14074
14075 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14076  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14077  */
14078 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14079         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14080         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14081         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14082         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14083         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14084         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14085         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14086         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14087
14088         { } /* end */
14089 };
14090
14091 /*
14092  * generic initialization of ADC, input mixers and output mixers
14093  */
14094 static struct hda_verb alc861vd_volume_init_verbs[] = {
14095         /*
14096          * Unmute ADC0 and set the default input to mic-in
14097          */
14098         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14099         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14100
14101         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14102          * the analog-loopback mixer widget
14103          */
14104         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14105         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14106         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14107         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14108         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14109         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14110
14111         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14112         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14113         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14114         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14115         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14116
14117         /*
14118          * Set up output mixers (0x02 - 0x05)
14119          */
14120         /* set vol=0 to output mixers */
14121         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14122         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14123         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14124         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14125
14126         /* set up input amps for analog loopback */
14127         /* Amp Indices: DAC = 0, mixer = 1 */
14128         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14129         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14130         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14131         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14132         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14133         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14134         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14135         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14136
14137         { }
14138 };
14139
14140 /*
14141  * 3-stack pin configuration:
14142  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14143  */
14144 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14145         /*
14146          * Set pin mode and muting
14147          */
14148         /* set front pin widgets 0x14 for output */
14149         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14150         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14151         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14152
14153         /* Mic (rear) pin: input vref at 80% */
14154         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14155         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14156         /* Front Mic pin: input vref at 80% */
14157         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14158         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14159         /* Line In pin: input */
14160         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14161         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14162         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14163         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14164         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14165         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14166         /* CD pin widget for input */
14167         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14168
14169         { }
14170 };
14171
14172 /*
14173  * 6-stack pin configuration:
14174  */
14175 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14176         /*
14177          * Set pin mode and muting
14178          */
14179         /* set front pin widgets 0x14 for output */
14180         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14181         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14182         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14183
14184         /* Rear Pin: output 1 (0x0d) */
14185         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14186         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14187         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14188         /* CLFE Pin: output 2 (0x0e) */
14189         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14190         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14191         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14192         /* Side Pin: output 3 (0x0f) */
14193         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14194         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14195         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
14196
14197         /* Mic (rear) pin: input vref at 80% */
14198         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14199         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14200         /* Front Mic pin: input vref at 80% */
14201         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14202         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14203         /* Line In pin: input */
14204         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14205         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14206         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14207         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14208         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14209         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14210         /* CD pin widget for input */
14211         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14212
14213         { }
14214 };
14215
14216 static struct hda_verb alc861vd_eapd_verbs[] = {
14217         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14218         { }
14219 };
14220
14221 static struct hda_verb alc660vd_eapd_verbs[] = {
14222         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14223         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14224         { }
14225 };
14226
14227 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
14228         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14229         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14230         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
14231         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14232         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14233         {}
14234 };
14235
14236 /* toggle speaker-output according to the hp-jack state */
14237 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
14238 {
14239         unsigned int present;
14240         unsigned char bits;
14241
14242         present = snd_hda_codec_read(codec, 0x1b, 0,
14243                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14244         bits = present ? HDA_AMP_MUTE : 0;
14245         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14246                                  HDA_AMP_MUTE, bits);
14247 }
14248
14249 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
14250 {
14251         unsigned int present;
14252         unsigned char bits;
14253
14254         present = snd_hda_codec_read(codec, 0x18, 0,
14255                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14256         bits = present ? HDA_AMP_MUTE : 0;
14257         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
14258                                  HDA_AMP_MUTE, bits);
14259 }
14260
14261 static void alc861vd_lenovo_automute(struct hda_codec *codec)
14262 {
14263         alc861vd_lenovo_hp_automute(codec);
14264         alc861vd_lenovo_mic_automute(codec);
14265 }
14266
14267 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
14268                                         unsigned int res)
14269 {
14270         switch (res >> 26) {
14271         case ALC880_HP_EVENT:
14272                 alc861vd_lenovo_hp_automute(codec);
14273                 break;
14274         case ALC880_MIC_EVENT:
14275                 alc861vd_lenovo_mic_automute(codec);
14276                 break;
14277         }
14278 }
14279
14280 static struct hda_verb alc861vd_dallas_verbs[] = {
14281         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14282         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14283         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14284         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14285
14286         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14287         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14288         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14289         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14290         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14291         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14292         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14293         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14294
14295         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14296         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14297         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14298         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14299         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14300         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14301         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14302         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14303
14304         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14305         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14306         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14307         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14308         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14309         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14310         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14311         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14312
14313         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14314         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14315         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14316         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14317
14318         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14319         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14320         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14321
14322         { } /* end */
14323 };
14324
14325 /* toggle speaker-output according to the hp-jack state */
14326 static void alc861vd_dallas_automute(struct hda_codec *codec)
14327 {
14328         unsigned int present;
14329
14330         present = snd_hda_codec_read(codec, 0x15, 0,
14331                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14332         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14333                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14334 }
14335
14336 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
14337 {
14338         if ((res >> 26) == ALC880_HP_EVENT)
14339                 alc861vd_dallas_automute(codec);
14340 }
14341
14342 #ifdef CONFIG_SND_HDA_POWER_SAVE
14343 #define alc861vd_loopbacks      alc880_loopbacks
14344 #endif
14345
14346 /* pcm configuration: identiacal with ALC880 */
14347 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14348 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14349 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14350 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14351
14352 /*
14353  * configuration and preset
14354  */
14355 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14356         [ALC660VD_3ST]          = "3stack-660",
14357         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14358         [ALC660VD_ASUS_V1S]     = "asus-v1s",
14359         [ALC861VD_3ST]          = "3stack",
14360         [ALC861VD_3ST_DIG]      = "3stack-digout",
14361         [ALC861VD_6ST_DIG]      = "6stack-digout",
14362         [ALC861VD_LENOVO]       = "lenovo",
14363         [ALC861VD_DALLAS]       = "dallas",
14364         [ALC861VD_HP]           = "hp",
14365         [ALC861VD_AUTO]         = "auto",
14366 };
14367
14368 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14369         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14370         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14371         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14372         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14373         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
14374         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14375         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14376         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14377         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14378         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14379         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14380         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14381         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14382         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
14383         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
14384         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
14385         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14386         {}
14387 };
14388
14389 static struct alc_config_preset alc861vd_presets[] = {
14390         [ALC660VD_3ST] = {
14391                 .mixers = { alc861vd_3st_mixer },
14392                 .init_verbs = { alc861vd_volume_init_verbs,
14393                                  alc861vd_3stack_init_verbs },
14394                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14395                 .dac_nids = alc660vd_dac_nids,
14396                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14397                 .channel_mode = alc861vd_3stack_2ch_modes,
14398                 .input_mux = &alc861vd_capture_source,
14399         },
14400         [ALC660VD_3ST_DIG] = {
14401                 .mixers = { alc861vd_3st_mixer },
14402                 .init_verbs = { alc861vd_volume_init_verbs,
14403                                  alc861vd_3stack_init_verbs },
14404                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14405                 .dac_nids = alc660vd_dac_nids,
14406                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14407                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14408                 .channel_mode = alc861vd_3stack_2ch_modes,
14409                 .input_mux = &alc861vd_capture_source,
14410         },
14411         [ALC861VD_3ST] = {
14412                 .mixers = { alc861vd_3st_mixer },
14413                 .init_verbs = { alc861vd_volume_init_verbs,
14414                                  alc861vd_3stack_init_verbs },
14415                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14416                 .dac_nids = alc861vd_dac_nids,
14417                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14418                 .channel_mode = alc861vd_3stack_2ch_modes,
14419                 .input_mux = &alc861vd_capture_source,
14420         },
14421         [ALC861VD_3ST_DIG] = {
14422                 .mixers = { alc861vd_3st_mixer },
14423                 .init_verbs = { alc861vd_volume_init_verbs,
14424                                  alc861vd_3stack_init_verbs },
14425                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14426                 .dac_nids = alc861vd_dac_nids,
14427                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14428                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14429                 .channel_mode = alc861vd_3stack_2ch_modes,
14430                 .input_mux = &alc861vd_capture_source,
14431         },
14432         [ALC861VD_6ST_DIG] = {
14433                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14434                 .init_verbs = { alc861vd_volume_init_verbs,
14435                                 alc861vd_6stack_init_verbs },
14436                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14437                 .dac_nids = alc861vd_dac_nids,
14438                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14439                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14440                 .channel_mode = alc861vd_6stack_modes,
14441                 .input_mux = &alc861vd_capture_source,
14442         },
14443         [ALC861VD_LENOVO] = {
14444                 .mixers = { alc861vd_lenovo_mixer },
14445                 .init_verbs = { alc861vd_volume_init_verbs,
14446                                 alc861vd_3stack_init_verbs,
14447                                 alc861vd_eapd_verbs,
14448                                 alc861vd_lenovo_unsol_verbs },
14449                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14450                 .dac_nids = alc660vd_dac_nids,
14451                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14452                 .channel_mode = alc861vd_3stack_2ch_modes,
14453                 .input_mux = &alc861vd_capture_source,
14454                 .unsol_event = alc861vd_lenovo_unsol_event,
14455                 .init_hook = alc861vd_lenovo_automute,
14456         },
14457         [ALC861VD_DALLAS] = {
14458                 .mixers = { alc861vd_dallas_mixer },
14459                 .init_verbs = { alc861vd_dallas_verbs },
14460                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14461                 .dac_nids = alc861vd_dac_nids,
14462                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14463                 .channel_mode = alc861vd_3stack_2ch_modes,
14464                 .input_mux = &alc861vd_dallas_capture_source,
14465                 .unsol_event = alc861vd_dallas_unsol_event,
14466                 .init_hook = alc861vd_dallas_automute,
14467         },
14468         [ALC861VD_HP] = {
14469                 .mixers = { alc861vd_hp_mixer },
14470                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14471                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14472                 .dac_nids = alc861vd_dac_nids,
14473                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14474                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14475                 .channel_mode = alc861vd_3stack_2ch_modes,
14476                 .input_mux = &alc861vd_hp_capture_source,
14477                 .unsol_event = alc861vd_dallas_unsol_event,
14478                 .init_hook = alc861vd_dallas_automute,
14479         },
14480         [ALC660VD_ASUS_V1S] = {
14481                 .mixers = { alc861vd_lenovo_mixer },
14482                 .init_verbs = { alc861vd_volume_init_verbs,
14483                                 alc861vd_3stack_init_verbs,
14484                                 alc861vd_eapd_verbs,
14485                                 alc861vd_lenovo_unsol_verbs },
14486                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14487                 .dac_nids = alc660vd_dac_nids,
14488                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14489                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14490                 .channel_mode = alc861vd_3stack_2ch_modes,
14491                 .input_mux = &alc861vd_capture_source,
14492                 .unsol_event = alc861vd_lenovo_unsol_event,
14493                 .init_hook = alc861vd_lenovo_automute,
14494         },
14495 };
14496
14497 /*
14498  * BIOS auto configuration
14499  */
14500 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14501                                 hda_nid_t nid, int pin_type, int dac_idx)
14502 {
14503         alc_set_pin_output(codec, nid, pin_type);
14504 }
14505
14506 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14507 {
14508         struct alc_spec *spec = codec->spec;
14509         int i;
14510
14511         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14512         for (i = 0; i <= HDA_SIDE; i++) {
14513                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14514                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14515                 if (nid)
14516                         alc861vd_auto_set_output_and_unmute(codec, nid,
14517                                                             pin_type, i);
14518         }
14519 }
14520
14521
14522 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14523 {
14524         struct alc_spec *spec = codec->spec;
14525         hda_nid_t pin;
14526
14527         pin = spec->autocfg.hp_pins[0];
14528         if (pin) /* connect to front and  use dac 0 */
14529                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14530         pin = spec->autocfg.speaker_pins[0];
14531         if (pin)
14532                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14533 }
14534
14535 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14536 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14537
14538 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14539 {
14540         struct alc_spec *spec = codec->spec;
14541         int i;
14542
14543         for (i = 0; i < AUTO_PIN_LAST; i++) {
14544                 hda_nid_t nid = spec->autocfg.input_pins[i];
14545                 if (alc861vd_is_input_pin(nid)) {
14546                         snd_hda_codec_write(codec, nid, 0,
14547                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
14548                                         i <= AUTO_PIN_FRONT_MIC ?
14549                                                         PIN_VREF80 : PIN_IN);
14550                         if (nid != ALC861VD_PIN_CD_NID)
14551                                 snd_hda_codec_write(codec, nid, 0,
14552                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14553                                                 AMP_OUT_MUTE);
14554                 }
14555         }
14556 }
14557
14558 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14559
14560 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14561 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14562
14563 /* add playback controls from the parsed DAC table */
14564 /* Based on ALC880 version. But ALC861VD has separate,
14565  * different NIDs for mute/unmute switch and volume control */
14566 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14567                                              const struct auto_pin_cfg *cfg)
14568 {
14569         char name[32];
14570         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14571         hda_nid_t nid_v, nid_s;
14572         int i, err;
14573
14574         for (i = 0; i < cfg->line_outs; i++) {
14575                 if (!spec->multiout.dac_nids[i])
14576                         continue;
14577                 nid_v = alc861vd_idx_to_mixer_vol(
14578                                 alc880_dac_to_idx(
14579                                         spec->multiout.dac_nids[i]));
14580                 nid_s = alc861vd_idx_to_mixer_switch(
14581                                 alc880_dac_to_idx(
14582                                         spec->multiout.dac_nids[i]));
14583
14584                 if (i == 2) {
14585                         /* Center/LFE */
14586                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14587                                           "Center Playback Volume",
14588                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14589                                                               HDA_OUTPUT));
14590                         if (err < 0)
14591                                 return err;
14592                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14593                                           "LFE Playback Volume",
14594                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14595                                                               HDA_OUTPUT));
14596                         if (err < 0)
14597                                 return err;
14598                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14599                                           "Center Playback Switch",
14600                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14601                                                               HDA_INPUT));
14602                         if (err < 0)
14603                                 return err;
14604                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14605                                           "LFE Playback Switch",
14606                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14607                                                               HDA_INPUT));
14608                         if (err < 0)
14609                                 return err;
14610                 } else {
14611                         sprintf(name, "%s Playback Volume", chname[i]);
14612                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14613                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14614                                                               HDA_OUTPUT));
14615                         if (err < 0)
14616                                 return err;
14617                         sprintf(name, "%s Playback Switch", chname[i]);
14618                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14619                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14620                                                               HDA_INPUT));
14621                         if (err < 0)
14622                                 return err;
14623                 }
14624         }
14625         return 0;
14626 }
14627
14628 /* add playback controls for speaker and HP outputs */
14629 /* Based on ALC880 version. But ALC861VD has separate,
14630  * different NIDs for mute/unmute switch and volume control */
14631 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14632                                         hda_nid_t pin, const char *pfx)
14633 {
14634         hda_nid_t nid_v, nid_s;
14635         int err;
14636         char name[32];
14637
14638         if (!pin)
14639                 return 0;
14640
14641         if (alc880_is_fixed_pin(pin)) {
14642                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14643                 /* specify the DAC as the extra output */
14644                 if (!spec->multiout.hp_nid)
14645                         spec->multiout.hp_nid = nid_v;
14646                 else
14647                         spec->multiout.extra_out_nid[0] = nid_v;
14648                 /* control HP volume/switch on the output mixer amp */
14649                 nid_v = alc861vd_idx_to_mixer_vol(
14650                                 alc880_fixed_pin_idx(pin));
14651                 nid_s = alc861vd_idx_to_mixer_switch(
14652                                 alc880_fixed_pin_idx(pin));
14653
14654                 sprintf(name, "%s Playback Volume", pfx);
14655                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14656                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
14657                 if (err < 0)
14658                         return err;
14659                 sprintf(name, "%s Playback Switch", pfx);
14660                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14661                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
14662                 if (err < 0)
14663                         return err;
14664         } else if (alc880_is_multi_pin(pin)) {
14665                 /* set manual connection */
14666                 /* we have only a switch on HP-out PIN */
14667                 sprintf(name, "%s Playback Switch", pfx);
14668                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14669                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14670                 if (err < 0)
14671                         return err;
14672         }
14673         return 0;
14674 }
14675
14676 /* parse the BIOS configuration and set up the alc_spec
14677  * return 1 if successful, 0 if the proper config is not found,
14678  * or a negative error code
14679  * Based on ALC880 version - had to change it to override
14680  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
14681 static int alc861vd_parse_auto_config(struct hda_codec *codec)
14682 {
14683         struct alc_spec *spec = codec->spec;
14684         int err;
14685         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
14686
14687         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14688                                            alc861vd_ignore);
14689         if (err < 0)
14690                 return err;
14691         if (!spec->autocfg.line_outs)
14692                 return 0; /* can't find valid BIOS pin config */
14693
14694         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14695         if (err < 0)
14696                 return err;
14697         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
14698         if (err < 0)
14699                 return err;
14700         err = alc861vd_auto_create_extra_out(spec,
14701                                              spec->autocfg.speaker_pins[0],
14702                                              "Speaker");
14703         if (err < 0)
14704                 return err;
14705         err = alc861vd_auto_create_extra_out(spec,
14706                                              spec->autocfg.hp_pins[0],
14707                                              "Headphone");
14708         if (err < 0)
14709                 return err;
14710         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
14711         if (err < 0)
14712                 return err;
14713
14714         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14715
14716         if (spec->autocfg.dig_out_pin)
14717                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14718
14719         if (spec->kctls.list)
14720                 add_mixer(spec, spec->kctls.list);
14721
14722         add_verb(spec, alc861vd_volume_init_verbs);
14723
14724         spec->num_mux_defs = 1;
14725         spec->input_mux = &spec->private_imux;
14726
14727         err = alc_auto_add_mic_boost(codec);
14728         if (err < 0)
14729                 return err;
14730
14731         store_pin_configs(codec);
14732         return 1;
14733 }
14734
14735 /* additional initialization for auto-configuration model */
14736 static void alc861vd_auto_init(struct hda_codec *codec)
14737 {
14738         struct alc_spec *spec = codec->spec;
14739         alc861vd_auto_init_multi_out(codec);
14740         alc861vd_auto_init_hp_out(codec);
14741         alc861vd_auto_init_analog_input(codec);
14742         alc861vd_auto_init_input_src(codec);
14743         if (spec->unsol_event)
14744                 alc_inithook(codec);
14745 }
14746
14747 static int patch_alc861vd(struct hda_codec *codec)
14748 {
14749         struct alc_spec *spec;
14750         int err, board_config;
14751
14752         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14753         if (spec == NULL)
14754                 return -ENOMEM;
14755
14756         codec->spec = spec;
14757
14758         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
14759                                                   alc861vd_models,
14760                                                   alc861vd_cfg_tbl);
14761
14762         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
14763                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
14764                         "ALC861VD, trying auto-probe from BIOS...\n");
14765                 board_config = ALC861VD_AUTO;
14766         }
14767
14768         if (board_config == ALC861VD_AUTO) {
14769                 /* automatic parse from the BIOS config */
14770                 err = alc861vd_parse_auto_config(codec);
14771                 if (err < 0) {
14772                         alc_free(codec);
14773                         return err;
14774                 } else if (!err) {
14775                         printk(KERN_INFO
14776                                "hda_codec: Cannot set up configuration "
14777                                "from BIOS.  Using base mode...\n");
14778                         board_config = ALC861VD_3ST;
14779                 }
14780         }
14781
14782         if (board_config != ALC861VD_AUTO)
14783                 setup_preset(spec, &alc861vd_presets[board_config]);
14784
14785         if (codec->vendor_id == 0x10ec0660) {
14786                 spec->stream_name_analog = "ALC660-VD Analog";
14787                 spec->stream_name_digital = "ALC660-VD Digital";
14788                 /* always turn on EAPD */
14789                 add_verb(spec, alc660vd_eapd_verbs);
14790         } else {
14791                 spec->stream_name_analog = "ALC861VD Analog";
14792                 spec->stream_name_digital = "ALC861VD Digital";
14793         }
14794
14795         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
14796         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
14797
14798         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
14799         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
14800
14801         spec->adc_nids = alc861vd_adc_nids;
14802         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14803         spec->capsrc_nids = alc861vd_capsrc_nids;
14804         spec->is_mix_capture = 1;
14805
14806         set_capture_mixer(spec);
14807
14808         spec->vmaster_nid = 0x02;
14809
14810         codec->patch_ops = alc_patch_ops;
14811
14812         if (board_config == ALC861VD_AUTO)
14813                 spec->init_hook = alc861vd_auto_init;
14814 #ifdef CONFIG_SND_HDA_POWER_SAVE
14815         if (!spec->loopback.amplist)
14816                 spec->loopback.amplist = alc861vd_loopbacks;
14817 #endif
14818         codec->proc_widget_hook = print_realtek_coef;
14819
14820         return 0;
14821 }
14822
14823 /*
14824  * ALC662 support
14825  *
14826  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
14827  * configuration.  Each pin widget can choose any input DACs and a mixer.
14828  * Each ADC is connected from a mixer of all inputs.  This makes possible
14829  * 6-channel independent captures.
14830  *
14831  * In addition, an independent DAC for the multi-playback (not used in this
14832  * driver yet).
14833  */
14834 #define ALC662_DIGOUT_NID       0x06
14835 #define ALC662_DIGIN_NID        0x0a
14836
14837 static hda_nid_t alc662_dac_nids[4] = {
14838         /* front, rear, clfe, rear_surr */
14839         0x02, 0x03, 0x04
14840 };
14841
14842 static hda_nid_t alc662_adc_nids[1] = {
14843         /* ADC1-2 */
14844         0x09,
14845 };
14846
14847 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
14848
14849 /* input MUX */
14850 /* FIXME: should be a matrix-type input source selection */
14851 static struct hda_input_mux alc662_capture_source = {
14852         .num_items = 4,
14853         .items = {
14854                 { "Mic", 0x0 },
14855                 { "Front Mic", 0x1 },
14856                 { "Line", 0x2 },
14857                 { "CD", 0x4 },
14858         },
14859 };
14860
14861 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
14862         .num_items = 2,
14863         .items = {
14864                 { "Mic", 0x1 },
14865                 { "Line", 0x2 },
14866         },
14867 };
14868
14869 static struct hda_input_mux alc662_eeepc_capture_source = {
14870         .num_items = 2,
14871         .items = {
14872                 { "i-Mic", 0x1 },
14873                 { "e-Mic", 0x0 },
14874         },
14875 };
14876
14877 static struct hda_input_mux alc663_capture_source = {
14878         .num_items = 3,
14879         .items = {
14880                 { "Mic", 0x0 },
14881                 { "Front Mic", 0x1 },
14882                 { "Line", 0x2 },
14883         },
14884 };
14885
14886 static struct hda_input_mux alc663_m51va_capture_source = {
14887         .num_items = 2,
14888         .items = {
14889                 { "Ext-Mic", 0x0 },
14890                 { "D-Mic", 0x9 },
14891         },
14892 };
14893
14894 /*
14895  * 2ch mode
14896  */
14897 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
14898         { 2, NULL }
14899 };
14900
14901 /*
14902  * 2ch mode
14903  */
14904 static struct hda_verb alc662_3ST_ch2_init[] = {
14905         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
14906         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14907         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
14908         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14909         { } /* end */
14910 };
14911
14912 /*
14913  * 6ch mode
14914  */
14915 static struct hda_verb alc662_3ST_ch6_init[] = {
14916         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14917         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14918         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
14919         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14920         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14921         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
14922         { } /* end */
14923 };
14924
14925 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
14926         { 2, alc662_3ST_ch2_init },
14927         { 6, alc662_3ST_ch6_init },
14928 };
14929
14930 /*
14931  * 2ch mode
14932  */
14933 static struct hda_verb alc662_sixstack_ch6_init[] = {
14934         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14935         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14936         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14937         { } /* end */
14938 };
14939
14940 /*
14941  * 6ch mode
14942  */
14943 static struct hda_verb alc662_sixstack_ch8_init[] = {
14944         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14945         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14946         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14947         { } /* end */
14948 };
14949
14950 static struct hda_channel_mode alc662_5stack_modes[2] = {
14951         { 2, alc662_sixstack_ch6_init },
14952         { 6, alc662_sixstack_ch8_init },
14953 };
14954
14955 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14956  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14957  */
14958
14959 static struct snd_kcontrol_new alc662_base_mixer[] = {
14960         /* output mixer control */
14961         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
14962         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14963         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
14964         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14965         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14966         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14967         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14968         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14969         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14970
14971         /*Input mixer control */
14972         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
14973         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
14974         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
14975         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
14976         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
14977         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
14978         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
14979         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
14980         { } /* end */
14981 };
14982
14983 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
14984         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14985         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14986         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14987         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14988         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14989         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14990         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14991         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14992         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14993         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14994         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14995         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14996         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14997         { } /* end */
14998 };
14999
15000 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15001         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15002         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15003         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15004         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15005         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15006         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15007         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15008         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15009         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15010         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15011         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15012         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15013         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15014         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15015         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15016         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15017         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15018         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
15019         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
15020         { } /* end */
15021 };
15022
15023 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15024         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15025         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15026         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15027         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15028         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15029         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15030         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15031         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15032         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15033         { } /* end */
15034 };
15035
15036 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15037         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15038
15039         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15040         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15041
15042         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15043         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15044         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15045
15046         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15047         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15048         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15049         { } /* end */
15050 };
15051
15052 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15053         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15054         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15055         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15056         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
15057         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15058         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15059         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
15060         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
15061         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15062         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, 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         { } /* end */
15068 };
15069
15070 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15071         .ops = &snd_hda_bind_vol,
15072         .values = {
15073                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15074                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15075                 0
15076         },
15077 };
15078
15079 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15080         .ops = &snd_hda_bind_sw,
15081         .values = {
15082                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15083                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15084                 0
15085         },
15086 };
15087
15088 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15089         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15090         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15091         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15092         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15093         { } /* end */
15094 };
15095
15096 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15097         .ops = &snd_hda_bind_sw,
15098         .values = {
15099                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15100                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15101                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15102                 0
15103         },
15104 };
15105
15106 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15107         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15108         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15109         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15110         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15111         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15112         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15113
15114         { } /* end */
15115 };
15116
15117 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15118         .ops = &snd_hda_bind_sw,
15119         .values = {
15120                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15121                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15122                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15123                 0
15124         },
15125 };
15126
15127 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15128         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15129         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15130         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15131         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15132         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15133         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15134         { } /* end */
15135 };
15136
15137 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15138         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15139         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15140         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15141         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15142         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15143         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15144         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15145         { } /* end */
15146 };
15147
15148 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15149         .ops = &snd_hda_bind_vol,
15150         .values = {
15151                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15152                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15153                 0
15154         },
15155 };
15156
15157 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15158         .ops = &snd_hda_bind_sw,
15159         .values = {
15160                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15161                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15162                 0
15163         },
15164 };
15165
15166 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15167         HDA_BIND_VOL("Master Playback Volume",
15168                                 &alc663_asus_two_bind_master_vol),
15169         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15170         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15171         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15172         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15173         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15174         { } /* end */
15175 };
15176
15177 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15178         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15179         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15180         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15181         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15182         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15183         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15184         { } /* end */
15185 };
15186
15187 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
15188         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15189         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15190         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15191         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15192         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15193
15194         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15195         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15196         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15197         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15198         { } /* end */
15199 };
15200
15201 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
15202         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15203         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15204         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15205
15206         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15207         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15208         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15209         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15210         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15211         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15212         { } /* end */
15213 };
15214
15215 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
15216         {
15217                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15218                 .name = "Channel Mode",
15219                 .info = alc_ch_mode_info,
15220                 .get = alc_ch_mode_get,
15221                 .put = alc_ch_mode_put,
15222         },
15223         { } /* end */
15224 };
15225
15226 static struct hda_verb alc662_init_verbs[] = {
15227         /* ADC: mute amp left and right */
15228         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15229         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15230         /* Front mixer: unmute input/output amp left and right (volume = 0) */
15231
15232         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15233         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15234         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15235         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15236         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15237
15238         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15239         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15240         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15241         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15242         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15243         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15244
15245         /* Front Pin: output 0 (0x0c) */
15246         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15247         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15248
15249         /* Rear Pin: output 1 (0x0d) */
15250         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15251         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15252
15253         /* CLFE Pin: output 2 (0x0e) */
15254         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15255         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15256
15257         /* Mic (rear) pin: input vref at 80% */
15258         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15259         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15260         /* Front Mic pin: input vref at 80% */
15261         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15262         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15263         /* Line In pin: input */
15264         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15265         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15266         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15267         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15268         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15269         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15270         /* CD pin widget for input */
15271         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15272
15273         /* FIXME: use matrix-type input source selection */
15274         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15275         /* Input mixer */
15276         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15277         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15278         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15279         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15280
15281         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15282         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15283         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15284         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15285
15286         /* always trun on EAPD */
15287         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15288         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15289
15290         { }
15291 };
15292
15293 static struct hda_verb alc662_sue_init_verbs[] = {
15294         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15295         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15296         {}
15297 };
15298
15299 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
15300         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15301         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15302         {}
15303 };
15304
15305 /* Set Unsolicited Event*/
15306 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
15307         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15308         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15309         {}
15310 };
15311
15312 /*
15313  * generic initialization of ADC, input mixers and output mixers
15314  */
15315 static struct hda_verb alc662_auto_init_verbs[] = {
15316         /*
15317          * Unmute ADC and set the default input to mic-in
15318          */
15319         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15320         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15321
15322         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
15323          * mixer widget
15324          * Note: PASD motherboards uses the Line In 2 as the input for front
15325          * panel mic (mic 2)
15326          */
15327         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
15328         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15329         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15330         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15331         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15332         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15333
15334         /*
15335          * Set up output mixers (0x0c - 0x0f)
15336          */
15337         /* set vol=0 to output mixers */
15338         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15339         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15340         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15341
15342         /* set up input amps for analog loopback */
15343         /* Amp Indices: DAC = 0, mixer = 1 */
15344         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15345         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15346         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15347         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15348         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15349         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15350
15351
15352         /* FIXME: use matrix-type input source selection */
15353         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15354         /* Input mixer */
15355         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15356         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15357         { }
15358 };
15359
15360 /* additional verbs for ALC663 */
15361 static struct hda_verb alc663_auto_init_verbs[] = {
15362         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15363         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15364         { }
15365 };
15366
15367 static struct hda_verb alc663_m51va_init_verbs[] = {
15368         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15369         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15370         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15371         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15372         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15373         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15374         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15375         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15376         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15377         {}
15378 };
15379
15380 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15381         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15382         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15383         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15384         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15385         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15386         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15387         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15388         {}
15389 };
15390
15391 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15392         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15393         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15394         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15395         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15396         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15397         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15398         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15399         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15400         {}
15401 };
15402
15403 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15404         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15405         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15406         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15407         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15408         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15409         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15410         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15411         {}
15412 };
15413
15414 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15415         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15416         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15417         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15418         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15419         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15420         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15421         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15422         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15423         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15424         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15425         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15426         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15427         {}
15428 };
15429
15430 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15431         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15432         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15433         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15434         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15435         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15436         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15437         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15438         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15439         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15440         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15441         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15442         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15443         {}
15444 };
15445
15446 static struct hda_verb alc663_g71v_init_verbs[] = {
15447         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15448         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15449         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15450
15451         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15452         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15453         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15454
15455         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15456         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15457         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15458         {}
15459 };
15460
15461 static struct hda_verb alc663_g50v_init_verbs[] = {
15462         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15463         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15464         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15465
15466         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15467         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15468         {}
15469 };
15470
15471 static struct hda_verb alc662_ecs_init_verbs[] = {
15472         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15473         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15474         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15475         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15476         {}
15477 };
15478
15479 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15480         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15481         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15482         { } /* end */
15483 };
15484
15485 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15486 {
15487         unsigned int present;
15488         unsigned char bits;
15489
15490         present = snd_hda_codec_read(codec, 0x14, 0,
15491                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15492         bits = present ? HDA_AMP_MUTE : 0;
15493         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15494                                  HDA_AMP_MUTE, bits);
15495 }
15496
15497 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15498 {
15499         unsigned int present;
15500         unsigned char bits;
15501
15502         present = snd_hda_codec_read(codec, 0x1b, 0,
15503                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15504         bits = present ? HDA_AMP_MUTE : 0;
15505         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15506                                  HDA_AMP_MUTE, bits);
15507         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15508                                  HDA_AMP_MUTE, bits);
15509 }
15510
15511 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15512                                            unsigned int res)
15513 {
15514         if ((res >> 26) == ALC880_HP_EVENT)
15515                 alc662_lenovo_101e_all_automute(codec);
15516         if ((res >> 26) == ALC880_FRONT_EVENT)
15517                 alc662_lenovo_101e_ispeaker_automute(codec);
15518 }
15519
15520 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15521 {
15522         unsigned int present;
15523
15524         present = snd_hda_codec_read(codec, 0x18, 0,
15525                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15526         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15527                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15528         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15529                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15530         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15531                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15532         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15533                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15534 }
15535
15536 /* unsolicited event for HP jack sensing */
15537 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15538                                      unsigned int res)
15539 {
15540         if ((res >> 26) == ALC880_HP_EVENT)
15541                 alc262_hippo1_automute( codec );
15542
15543         if ((res >> 26) == ALC880_MIC_EVENT)
15544                 alc662_eeepc_mic_automute(codec);
15545 }
15546
15547 static void alc662_eeepc_inithook(struct hda_codec *codec)
15548 {
15549         alc262_hippo1_automute( codec );
15550         alc662_eeepc_mic_automute(codec);
15551 }
15552
15553 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15554 {
15555         unsigned int mute;
15556         unsigned int present;
15557
15558         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15559         present = snd_hda_codec_read(codec, 0x14, 0,
15560                                      AC_VERB_GET_PIN_SENSE, 0);
15561         present = (present & 0x80000000) != 0;
15562         if (present) {
15563                 /* mute internal speaker */
15564                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15565                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15566         } else {
15567                 /* unmute internal speaker if necessary */
15568                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15569                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15570                                         HDA_AMP_MUTE, mute);
15571         }
15572 }
15573
15574 /* unsolicited event for HP jack sensing */
15575 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15576                                           unsigned int res)
15577 {
15578         if ((res >> 26) == ALC880_HP_EVENT)
15579                 alc662_eeepc_ep20_automute(codec);
15580 }
15581
15582 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15583 {
15584         alc662_eeepc_ep20_automute(codec);
15585 }
15586
15587 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15588 {
15589         unsigned int present;
15590         unsigned char bits;
15591
15592         present = snd_hda_codec_read(codec, 0x21, 0,
15593                         AC_VERB_GET_PIN_SENSE, 0)
15594                         & AC_PINSENSE_PRESENCE;
15595         bits = present ? HDA_AMP_MUTE : 0;
15596         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15597                                 AMP_IN_MUTE(0), bits);
15598         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15599                                 AMP_IN_MUTE(0), bits);
15600 }
15601
15602 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15603 {
15604         unsigned int present;
15605         unsigned char bits;
15606
15607         present = snd_hda_codec_read(codec, 0x21, 0,
15608                         AC_VERB_GET_PIN_SENSE, 0)
15609                         & AC_PINSENSE_PRESENCE;
15610         bits = present ? HDA_AMP_MUTE : 0;
15611         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15612                                 AMP_IN_MUTE(0), bits);
15613         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15614                                 AMP_IN_MUTE(0), bits);
15615         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15616                                 AMP_IN_MUTE(0), bits);
15617         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15618                                 AMP_IN_MUTE(0), bits);
15619 }
15620
15621 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15622 {
15623         unsigned int present;
15624         unsigned char bits;
15625
15626         present = snd_hda_codec_read(codec, 0x15, 0,
15627                         AC_VERB_GET_PIN_SENSE, 0)
15628                         & AC_PINSENSE_PRESENCE;
15629         bits = present ? HDA_AMP_MUTE : 0;
15630         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15631                                 AMP_IN_MUTE(0), bits);
15632         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15633                                 AMP_IN_MUTE(0), bits);
15634         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15635                                 AMP_IN_MUTE(0), bits);
15636         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15637                                 AMP_IN_MUTE(0), bits);
15638 }
15639
15640 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15641 {
15642         unsigned int present;
15643         unsigned char bits;
15644
15645         present = snd_hda_codec_read(codec, 0x1b, 0,
15646                         AC_VERB_GET_PIN_SENSE, 0)
15647                         & AC_PINSENSE_PRESENCE;
15648         bits = present ? 0 : PIN_OUT;
15649         snd_hda_codec_write(codec, 0x14, 0,
15650                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15651 }
15652
15653 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15654 {
15655         unsigned int present1, present2;
15656
15657         present1 = snd_hda_codec_read(codec, 0x21, 0,
15658                         AC_VERB_GET_PIN_SENSE, 0)
15659                         & AC_PINSENSE_PRESENCE;
15660         present2 = snd_hda_codec_read(codec, 0x15, 0,
15661                         AC_VERB_GET_PIN_SENSE, 0)
15662                         & AC_PINSENSE_PRESENCE;
15663
15664         if (present1 || present2) {
15665                 snd_hda_codec_write_cache(codec, 0x14, 0,
15666                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15667         } else {
15668                 snd_hda_codec_write_cache(codec, 0x14, 0,
15669                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15670         }
15671 }
15672
15673 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15674 {
15675         unsigned int present1, present2;
15676
15677         present1 = snd_hda_codec_read(codec, 0x1b, 0,
15678                                 AC_VERB_GET_PIN_SENSE, 0)
15679                                 & AC_PINSENSE_PRESENCE;
15680         present2 = snd_hda_codec_read(codec, 0x15, 0,
15681                                 AC_VERB_GET_PIN_SENSE, 0)
15682                                 & AC_PINSENSE_PRESENCE;
15683
15684         if (present1 || present2) {
15685                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15686                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15687                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15688                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15689         } else {
15690                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15691                                 AMP_IN_MUTE(0), 0);
15692                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15693                                 AMP_IN_MUTE(0), 0);
15694         }
15695 }
15696
15697 static void alc663_m51va_mic_automute(struct hda_codec *codec)
15698 {
15699         unsigned int present;
15700
15701         present = snd_hda_codec_read(codec, 0x18, 0,
15702                         AC_VERB_GET_PIN_SENSE, 0)
15703                         & AC_PINSENSE_PRESENCE;
15704         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15705                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15706         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15707                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15708         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15709                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15710         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15711                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15712 }
15713
15714 static void alc663_m51va_unsol_event(struct hda_codec *codec,
15715                                            unsigned int res)
15716 {
15717         switch (res >> 26) {
15718         case ALC880_HP_EVENT:
15719                 alc663_m51va_speaker_automute(codec);
15720                 break;
15721         case ALC880_MIC_EVENT:
15722                 alc663_m51va_mic_automute(codec);
15723                 break;
15724         }
15725 }
15726
15727 static void alc663_m51va_inithook(struct hda_codec *codec)
15728 {
15729         alc663_m51va_speaker_automute(codec);
15730         alc663_m51va_mic_automute(codec);
15731 }
15732
15733 /* ***************** Mode1 ******************************/
15734 static void alc663_mode1_unsol_event(struct hda_codec *codec,
15735                                            unsigned int res)
15736 {
15737         switch (res >> 26) {
15738         case ALC880_HP_EVENT:
15739                 alc663_m51va_speaker_automute(codec);
15740                 break;
15741         case ALC880_MIC_EVENT:
15742                 alc662_eeepc_mic_automute(codec);
15743                 break;
15744         }
15745 }
15746
15747 static void alc663_mode1_inithook(struct hda_codec *codec)
15748 {
15749         alc663_m51va_speaker_automute(codec);
15750         alc662_eeepc_mic_automute(codec);
15751 }
15752 /* ***************** Mode2 ******************************/
15753 static void alc662_mode2_unsol_event(struct hda_codec *codec,
15754                                            unsigned int res)
15755 {
15756         switch (res >> 26) {
15757         case ALC880_HP_EVENT:
15758                 alc662_f5z_speaker_automute(codec);
15759                 break;
15760         case ALC880_MIC_EVENT:
15761                 alc662_eeepc_mic_automute(codec);
15762                 break;
15763         }
15764 }
15765
15766 static void alc662_mode2_inithook(struct hda_codec *codec)
15767 {
15768         alc662_f5z_speaker_automute(codec);
15769         alc662_eeepc_mic_automute(codec);
15770 }
15771 /* ***************** Mode3 ******************************/
15772 static void alc663_mode3_unsol_event(struct hda_codec *codec,
15773                                            unsigned int res)
15774 {
15775         switch (res >> 26) {
15776         case ALC880_HP_EVENT:
15777                 alc663_two_hp_m1_speaker_automute(codec);
15778                 break;
15779         case ALC880_MIC_EVENT:
15780                 alc662_eeepc_mic_automute(codec);
15781                 break;
15782         }
15783 }
15784
15785 static void alc663_mode3_inithook(struct hda_codec *codec)
15786 {
15787         alc663_two_hp_m1_speaker_automute(codec);
15788         alc662_eeepc_mic_automute(codec);
15789 }
15790 /* ***************** Mode4 ******************************/
15791 static void alc663_mode4_unsol_event(struct hda_codec *codec,
15792                                            unsigned int res)
15793 {
15794         switch (res >> 26) {
15795         case ALC880_HP_EVENT:
15796                 alc663_21jd_two_speaker_automute(codec);
15797                 break;
15798         case ALC880_MIC_EVENT:
15799                 alc662_eeepc_mic_automute(codec);
15800                 break;
15801         }
15802 }
15803
15804 static void alc663_mode4_inithook(struct hda_codec *codec)
15805 {
15806         alc663_21jd_two_speaker_automute(codec);
15807         alc662_eeepc_mic_automute(codec);
15808 }
15809 /* ***************** Mode5 ******************************/
15810 static void alc663_mode5_unsol_event(struct hda_codec *codec,
15811                                            unsigned int res)
15812 {
15813         switch (res >> 26) {
15814         case ALC880_HP_EVENT:
15815                 alc663_15jd_two_speaker_automute(codec);
15816                 break;
15817         case ALC880_MIC_EVENT:
15818                 alc662_eeepc_mic_automute(codec);
15819                 break;
15820         }
15821 }
15822
15823 static void alc663_mode5_inithook(struct hda_codec *codec)
15824 {
15825         alc663_15jd_two_speaker_automute(codec);
15826         alc662_eeepc_mic_automute(codec);
15827 }
15828 /* ***************** Mode6 ******************************/
15829 static void alc663_mode6_unsol_event(struct hda_codec *codec,
15830                                            unsigned int res)
15831 {
15832         switch (res >> 26) {
15833         case ALC880_HP_EVENT:
15834                 alc663_two_hp_m2_speaker_automute(codec);
15835                 break;
15836         case ALC880_MIC_EVENT:
15837                 alc662_eeepc_mic_automute(codec);
15838                 break;
15839         }
15840 }
15841
15842 static void alc663_mode6_inithook(struct hda_codec *codec)
15843 {
15844         alc663_two_hp_m2_speaker_automute(codec);
15845         alc662_eeepc_mic_automute(codec);
15846 }
15847
15848 static void alc663_g71v_hp_automute(struct hda_codec *codec)
15849 {
15850         unsigned int present;
15851         unsigned char bits;
15852
15853         present = snd_hda_codec_read(codec, 0x21, 0,
15854                                      AC_VERB_GET_PIN_SENSE, 0)
15855                 & AC_PINSENSE_PRESENCE;
15856         bits = present ? HDA_AMP_MUTE : 0;
15857         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15858                                  HDA_AMP_MUTE, bits);
15859         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15860                                  HDA_AMP_MUTE, bits);
15861 }
15862
15863 static void alc663_g71v_front_automute(struct hda_codec *codec)
15864 {
15865         unsigned int present;
15866         unsigned char bits;
15867
15868         present = snd_hda_codec_read(codec, 0x15, 0,
15869                                      AC_VERB_GET_PIN_SENSE, 0)
15870                 & AC_PINSENSE_PRESENCE;
15871         bits = present ? HDA_AMP_MUTE : 0;
15872         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15873                                  HDA_AMP_MUTE, bits);
15874 }
15875
15876 static void alc663_g71v_unsol_event(struct hda_codec *codec,
15877                                            unsigned int res)
15878 {
15879         switch (res >> 26) {
15880         case ALC880_HP_EVENT:
15881                 alc663_g71v_hp_automute(codec);
15882                 break;
15883         case ALC880_FRONT_EVENT:
15884                 alc663_g71v_front_automute(codec);
15885                 break;
15886         case ALC880_MIC_EVENT:
15887                 alc662_eeepc_mic_automute(codec);
15888                 break;
15889         }
15890 }
15891
15892 static void alc663_g71v_inithook(struct hda_codec *codec)
15893 {
15894         alc663_g71v_front_automute(codec);
15895         alc663_g71v_hp_automute(codec);
15896         alc662_eeepc_mic_automute(codec);
15897 }
15898
15899 static void alc663_g50v_unsol_event(struct hda_codec *codec,
15900                                            unsigned int res)
15901 {
15902         switch (res >> 26) {
15903         case ALC880_HP_EVENT:
15904                 alc663_m51va_speaker_automute(codec);
15905                 break;
15906         case ALC880_MIC_EVENT:
15907                 alc662_eeepc_mic_automute(codec);
15908                 break;
15909         }
15910 }
15911
15912 static void alc663_g50v_inithook(struct hda_codec *codec)
15913 {
15914         alc663_m51va_speaker_automute(codec);
15915         alc662_eeepc_mic_automute(codec);
15916 }
15917
15918 /* bind hp and internal speaker mute (with plug check) */
15919 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15920                                      struct snd_ctl_elem_value *ucontrol)
15921 {
15922         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15923         long *valp = ucontrol->value.integer.value;
15924         int change;
15925
15926         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15927                                           HDA_AMP_MUTE,
15928                                           valp[0] ? 0 : HDA_AMP_MUTE);
15929         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15930                                            HDA_AMP_MUTE,
15931                                            valp[1] ? 0 : HDA_AMP_MUTE);
15932         if (change)
15933                 alc262_hippo1_automute(codec);
15934         return change;
15935 }
15936
15937 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
15938         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15939         {
15940                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15941                 .name = "Master Playback Switch",
15942                 .info = snd_hda_mixer_amp_switch_info,
15943                 .get = snd_hda_mixer_amp_switch_get,
15944                 .put = alc662_ecs_master_sw_put,
15945                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15946         },
15947
15948         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
15949         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
15950         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
15951
15952         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15953         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15954         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15955         { } /* end */
15956 };
15957
15958 #ifdef CONFIG_SND_HDA_POWER_SAVE
15959 #define alc662_loopbacks        alc880_loopbacks
15960 #endif
15961
15962
15963 /* pcm configuration: identiacal with ALC880 */
15964 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
15965 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
15966 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
15967 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
15968
15969 /*
15970  * configuration and preset
15971  */
15972 static const char *alc662_models[ALC662_MODEL_LAST] = {
15973         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
15974         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
15975         [ALC662_3ST_6ch]        = "3stack-6ch",
15976         [ALC662_5ST_DIG]        = "6stack-dig",
15977         [ALC662_LENOVO_101E]    = "lenovo-101e",
15978         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
15979         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
15980         [ALC662_ECS] = "ecs",
15981         [ALC663_ASUS_M51VA] = "m51va",
15982         [ALC663_ASUS_G71V] = "g71v",
15983         [ALC663_ASUS_H13] = "h13",
15984         [ALC663_ASUS_G50V] = "g50v",
15985         [ALC663_ASUS_MODE1] = "asus-mode1",
15986         [ALC662_ASUS_MODE2] = "asus-mode2",
15987         [ALC663_ASUS_MODE3] = "asus-mode3",
15988         [ALC663_ASUS_MODE4] = "asus-mode4",
15989         [ALC663_ASUS_MODE5] = "asus-mode5",
15990         [ALC663_ASUS_MODE6] = "asus-mode6",
15991         [ALC662_AUTO]           = "auto",
15992 };
15993
15994 static struct snd_pci_quirk alc662_cfg_tbl[] = {
15995         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
15996         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
15997         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
15998         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
15999         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16000         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16001         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
16002         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16003         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16004         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16005         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
16006         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16007         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16008         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16009         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16010         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16011         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16012         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16013         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16014         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16015         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16016         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16017         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16018         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16019         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16020         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16021         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16022         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16023         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16024         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16025         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16026         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16027         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16028         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16029         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16030         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16031         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16032         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16033                       ALC662_3ST_6ch_DIG),
16034         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16035         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16036         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16037         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16038                       ALC662_3ST_6ch_DIG),
16039         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16040         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16041                                         ALC662_3ST_6ch_DIG),
16042         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
16043         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
16044         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
16045         {}
16046 };
16047
16048 static struct alc_config_preset alc662_presets[] = {
16049         [ALC662_3ST_2ch_DIG] = {
16050                 .mixers = { alc662_3ST_2ch_mixer },
16051                 .init_verbs = { alc662_init_verbs },
16052                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16053                 .dac_nids = alc662_dac_nids,
16054                 .dig_out_nid = ALC662_DIGOUT_NID,
16055                 .dig_in_nid = ALC662_DIGIN_NID,
16056                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16057                 .channel_mode = alc662_3ST_2ch_modes,
16058                 .input_mux = &alc662_capture_source,
16059         },
16060         [ALC662_3ST_6ch_DIG] = {
16061                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16062                 .init_verbs = { alc662_init_verbs },
16063                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16064                 .dac_nids = alc662_dac_nids,
16065                 .dig_out_nid = ALC662_DIGOUT_NID,
16066                 .dig_in_nid = ALC662_DIGIN_NID,
16067                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16068                 .channel_mode = alc662_3ST_6ch_modes,
16069                 .need_dac_fix = 1,
16070                 .input_mux = &alc662_capture_source,
16071         },
16072         [ALC662_3ST_6ch] = {
16073                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16074                 .init_verbs = { alc662_init_verbs },
16075                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16076                 .dac_nids = alc662_dac_nids,
16077                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16078                 .channel_mode = alc662_3ST_6ch_modes,
16079                 .need_dac_fix = 1,
16080                 .input_mux = &alc662_capture_source,
16081         },
16082         [ALC662_5ST_DIG] = {
16083                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16084                 .init_verbs = { alc662_init_verbs },
16085                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16086                 .dac_nids = alc662_dac_nids,
16087                 .dig_out_nid = ALC662_DIGOUT_NID,
16088                 .dig_in_nid = ALC662_DIGIN_NID,
16089                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16090                 .channel_mode = alc662_5stack_modes,
16091                 .input_mux = &alc662_capture_source,
16092         },
16093         [ALC662_LENOVO_101E] = {
16094                 .mixers = { alc662_lenovo_101e_mixer },
16095                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16096                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16097                 .dac_nids = alc662_dac_nids,
16098                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16099                 .channel_mode = alc662_3ST_2ch_modes,
16100                 .input_mux = &alc662_lenovo_101e_capture_source,
16101                 .unsol_event = alc662_lenovo_101e_unsol_event,
16102                 .init_hook = alc662_lenovo_101e_all_automute,
16103         },
16104         [ALC662_ASUS_EEEPC_P701] = {
16105                 .mixers = { alc662_eeepc_p701_mixer },
16106                 .init_verbs = { alc662_init_verbs,
16107                                 alc662_eeepc_sue_init_verbs },
16108                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16109                 .dac_nids = alc662_dac_nids,
16110                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16111                 .channel_mode = alc662_3ST_2ch_modes,
16112                 .input_mux = &alc662_eeepc_capture_source,
16113                 .unsol_event = alc662_eeepc_unsol_event,
16114                 .init_hook = alc662_eeepc_inithook,
16115         },
16116         [ALC662_ASUS_EEEPC_EP20] = {
16117                 .mixers = { alc662_eeepc_ep20_mixer,
16118                             alc662_chmode_mixer },
16119                 .init_verbs = { alc662_init_verbs,
16120                                 alc662_eeepc_ep20_sue_init_verbs },
16121                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16122                 .dac_nids = alc662_dac_nids,
16123                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16124                 .channel_mode = alc662_3ST_6ch_modes,
16125                 .input_mux = &alc662_lenovo_101e_capture_source,
16126                 .unsol_event = alc662_eeepc_ep20_unsol_event,
16127                 .init_hook = alc662_eeepc_ep20_inithook,
16128         },
16129         [ALC662_ECS] = {
16130                 .mixers = { alc662_ecs_mixer },
16131                 .init_verbs = { alc662_init_verbs,
16132                                 alc662_ecs_init_verbs },
16133                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16134                 .dac_nids = alc662_dac_nids,
16135                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16136                 .channel_mode = alc662_3ST_2ch_modes,
16137                 .input_mux = &alc662_eeepc_capture_source,
16138                 .unsol_event = alc662_eeepc_unsol_event,
16139                 .init_hook = alc662_eeepc_inithook,
16140         },
16141         [ALC663_ASUS_M51VA] = {
16142                 .mixers = { alc663_m51va_mixer },
16143                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16144                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16145                 .dac_nids = alc662_dac_nids,
16146                 .dig_out_nid = ALC662_DIGOUT_NID,
16147                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16148                 .channel_mode = alc662_3ST_2ch_modes,
16149                 .input_mux = &alc663_m51va_capture_source,
16150                 .unsol_event = alc663_m51va_unsol_event,
16151                 .init_hook = alc663_m51va_inithook,
16152         },
16153         [ALC663_ASUS_G71V] = {
16154                 .mixers = { alc663_g71v_mixer },
16155                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16156                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16157                 .dac_nids = alc662_dac_nids,
16158                 .dig_out_nid = ALC662_DIGOUT_NID,
16159                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16160                 .channel_mode = alc662_3ST_2ch_modes,
16161                 .input_mux = &alc662_eeepc_capture_source,
16162                 .unsol_event = alc663_g71v_unsol_event,
16163                 .init_hook = alc663_g71v_inithook,
16164         },
16165         [ALC663_ASUS_H13] = {
16166                 .mixers = { alc663_m51va_mixer },
16167                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16168                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16169                 .dac_nids = alc662_dac_nids,
16170                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16171                 .channel_mode = alc662_3ST_2ch_modes,
16172                 .input_mux = &alc663_m51va_capture_source,
16173                 .unsol_event = alc663_m51va_unsol_event,
16174                 .init_hook = alc663_m51va_inithook,
16175         },
16176         [ALC663_ASUS_G50V] = {
16177                 .mixers = { alc663_g50v_mixer },
16178                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
16179                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16180                 .dac_nids = alc662_dac_nids,
16181                 .dig_out_nid = ALC662_DIGOUT_NID,
16182                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16183                 .channel_mode = alc662_3ST_6ch_modes,
16184                 .input_mux = &alc663_capture_source,
16185                 .unsol_event = alc663_g50v_unsol_event,
16186                 .init_hook = alc663_g50v_inithook,
16187         },
16188         [ALC663_ASUS_MODE1] = {
16189                 .mixers = { alc663_m51va_mixer },
16190                 .cap_mixer = alc662_auto_capture_mixer,
16191                 .init_verbs = { alc662_init_verbs,
16192                                 alc663_21jd_amic_init_verbs },
16193                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16194                 .hp_nid = 0x03,
16195                 .dac_nids = alc662_dac_nids,
16196                 .dig_out_nid = ALC662_DIGOUT_NID,
16197                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16198                 .channel_mode = alc662_3ST_2ch_modes,
16199                 .input_mux = &alc662_eeepc_capture_source,
16200                 .unsol_event = alc663_mode1_unsol_event,
16201                 .init_hook = alc663_mode1_inithook,
16202         },
16203         [ALC662_ASUS_MODE2] = {
16204                 .mixers = { alc662_1bjd_mixer },
16205                 .cap_mixer = alc662_auto_capture_mixer,
16206                 .init_verbs = { alc662_init_verbs,
16207                                 alc662_1bjd_amic_init_verbs },
16208                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16209                 .dac_nids = alc662_dac_nids,
16210                 .dig_out_nid = ALC662_DIGOUT_NID,
16211                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16212                 .channel_mode = alc662_3ST_2ch_modes,
16213                 .input_mux = &alc662_eeepc_capture_source,
16214                 .unsol_event = alc662_mode2_unsol_event,
16215                 .init_hook = alc662_mode2_inithook,
16216         },
16217         [ALC663_ASUS_MODE3] = {
16218                 .mixers = { alc663_two_hp_m1_mixer },
16219                 .cap_mixer = alc662_auto_capture_mixer,
16220                 .init_verbs = { alc662_init_verbs,
16221                                 alc663_two_hp_amic_m1_init_verbs },
16222                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16223                 .hp_nid = 0x03,
16224                 .dac_nids = alc662_dac_nids,
16225                 .dig_out_nid = ALC662_DIGOUT_NID,
16226                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16227                 .channel_mode = alc662_3ST_2ch_modes,
16228                 .input_mux = &alc662_eeepc_capture_source,
16229                 .unsol_event = alc663_mode3_unsol_event,
16230                 .init_hook = alc663_mode3_inithook,
16231         },
16232         [ALC663_ASUS_MODE4] = {
16233                 .mixers = { alc663_asus_21jd_clfe_mixer },
16234                 .cap_mixer = alc662_auto_capture_mixer,
16235                 .init_verbs = { alc662_init_verbs,
16236                                 alc663_21jd_amic_init_verbs},
16237                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16238                 .hp_nid = 0x03,
16239                 .dac_nids = alc662_dac_nids,
16240                 .dig_out_nid = ALC662_DIGOUT_NID,
16241                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16242                 .channel_mode = alc662_3ST_2ch_modes,
16243                 .input_mux = &alc662_eeepc_capture_source,
16244                 .unsol_event = alc663_mode4_unsol_event,
16245                 .init_hook = alc663_mode4_inithook,
16246         },
16247         [ALC663_ASUS_MODE5] = {
16248                 .mixers = { alc663_asus_15jd_clfe_mixer },
16249                 .cap_mixer = alc662_auto_capture_mixer,
16250                 .init_verbs = { alc662_init_verbs,
16251                                 alc663_15jd_amic_init_verbs },
16252                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16253                 .hp_nid = 0x03,
16254                 .dac_nids = alc662_dac_nids,
16255                 .dig_out_nid = ALC662_DIGOUT_NID,
16256                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16257                 .channel_mode = alc662_3ST_2ch_modes,
16258                 .input_mux = &alc662_eeepc_capture_source,
16259                 .unsol_event = alc663_mode5_unsol_event,
16260                 .init_hook = alc663_mode5_inithook,
16261         },
16262         [ALC663_ASUS_MODE6] = {
16263                 .mixers = { alc663_two_hp_m2_mixer },
16264                 .cap_mixer = alc662_auto_capture_mixer,
16265                 .init_verbs = { alc662_init_verbs,
16266                                 alc663_two_hp_amic_m2_init_verbs },
16267                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16268                 .hp_nid = 0x03,
16269                 .dac_nids = alc662_dac_nids,
16270                 .dig_out_nid = ALC662_DIGOUT_NID,
16271                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16272                 .channel_mode = alc662_3ST_2ch_modes,
16273                 .input_mux = &alc662_eeepc_capture_source,
16274                 .unsol_event = alc663_mode6_unsol_event,
16275                 .init_hook = alc663_mode6_inithook,
16276         },
16277 };
16278
16279
16280 /*
16281  * BIOS auto configuration
16282  */
16283
16284 /* add playback controls from the parsed DAC table */
16285 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
16286                                              const struct auto_pin_cfg *cfg)
16287 {
16288         char name[32];
16289         static const char *chname[4] = {
16290                 "Front", "Surround", NULL /*CLFE*/, "Side"
16291         };
16292         hda_nid_t nid;
16293         int i, err;
16294
16295         for (i = 0; i < cfg->line_outs; i++) {
16296                 if (!spec->multiout.dac_nids[i])
16297                         continue;
16298                 nid = alc880_idx_to_dac(i);
16299                 if (i == 2) {
16300                         /* Center/LFE */
16301                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16302                                           "Center Playback Volume",
16303                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
16304                                                               HDA_OUTPUT));
16305                         if (err < 0)
16306                                 return err;
16307                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16308                                           "LFE Playback Volume",
16309                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
16310                                                               HDA_OUTPUT));
16311                         if (err < 0)
16312                                 return err;
16313                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16314                                           "Center Playback Switch",
16315                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
16316                                                               HDA_INPUT));
16317                         if (err < 0)
16318                                 return err;
16319                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16320                                           "LFE Playback Switch",
16321                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
16322                                                               HDA_INPUT));
16323                         if (err < 0)
16324                                 return err;
16325                 } else {
16326                         sprintf(name, "%s Playback Volume", chname[i]);
16327                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16328                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
16329                                                               HDA_OUTPUT));
16330                         if (err < 0)
16331                                 return err;
16332                         sprintf(name, "%s Playback Switch", chname[i]);
16333                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16334                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
16335                                                     3, 0, HDA_INPUT));
16336                         if (err < 0)
16337                                 return err;
16338                 }
16339         }
16340         return 0;
16341 }
16342
16343 /* add playback controls for speaker and HP outputs */
16344 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16345                                         const char *pfx)
16346 {
16347         hda_nid_t nid;
16348         int err;
16349         char name[32];
16350
16351         if (!pin)
16352                 return 0;
16353
16354         if (pin == 0x17) {
16355                 /* ALC663 has a mono output pin on 0x17 */
16356                 sprintf(name, "%s Playback Switch", pfx);
16357                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16358                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16359                 return err;
16360         }
16361
16362         if (alc880_is_fixed_pin(pin)) {
16363                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16364                 /* printk("DAC nid=%x\n",nid); */
16365                 /* specify the DAC as the extra output */
16366                 if (!spec->multiout.hp_nid)
16367                         spec->multiout.hp_nid = nid;
16368                 else
16369                         spec->multiout.extra_out_nid[0] = nid;
16370                 /* control HP volume/switch on the output mixer amp */
16371                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16372                 sprintf(name, "%s Playback Volume", pfx);
16373                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16374                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16375                 if (err < 0)
16376                         return err;
16377                 sprintf(name, "%s Playback Switch", pfx);
16378                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16379                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16380                 if (err < 0)
16381                         return err;
16382         } else if (alc880_is_multi_pin(pin)) {
16383                 /* set manual connection */
16384                 /* we have only a switch on HP-out PIN */
16385                 sprintf(name, "%s Playback Switch", pfx);
16386                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16387                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16388                 if (err < 0)
16389                         return err;
16390         }
16391         return 0;
16392 }
16393
16394 /* create playback/capture controls for input pins */
16395 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
16396                                                 const struct auto_pin_cfg *cfg)
16397 {
16398         struct hda_input_mux *imux = &spec->private_imux;
16399         int i, err, idx;
16400
16401         for (i = 0; i < AUTO_PIN_LAST; i++) {
16402                 if (alc880_is_input_pin(cfg->input_pins[i])) {
16403                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
16404                         err = new_analog_input(spec, cfg->input_pins[i],
16405                                                auto_pin_cfg_labels[i],
16406                                                idx, 0x0b);
16407                         if (err < 0)
16408                                 return err;
16409                         imux->items[imux->num_items].label =
16410                                 auto_pin_cfg_labels[i];
16411                         imux->items[imux->num_items].index =
16412                                 alc880_input_pin_idx(cfg->input_pins[i]);
16413                         imux->num_items++;
16414                 }
16415         }
16416         return 0;
16417 }
16418
16419 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16420                                               hda_nid_t nid, int pin_type,
16421                                               int dac_idx)
16422 {
16423         alc_set_pin_output(codec, nid, pin_type);
16424         /* need the manual connection? */
16425         if (alc880_is_multi_pin(nid)) {
16426                 struct alc_spec *spec = codec->spec;
16427                 int idx = alc880_multi_pin_idx(nid);
16428                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16429                                     AC_VERB_SET_CONNECT_SEL,
16430                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16431         }
16432 }
16433
16434 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16435 {
16436         struct alc_spec *spec = codec->spec;
16437         int i;
16438
16439         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16440         for (i = 0; i <= HDA_SIDE; i++) {
16441                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16442                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16443                 if (nid)
16444                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16445                                                           i);
16446         }
16447 }
16448
16449 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16450 {
16451         struct alc_spec *spec = codec->spec;
16452         hda_nid_t pin;
16453
16454         pin = spec->autocfg.hp_pins[0];
16455         if (pin) /* connect to front */
16456                 /* use dac 0 */
16457                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16458         pin = spec->autocfg.speaker_pins[0];
16459         if (pin)
16460                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16461 }
16462
16463 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
16464 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16465
16466 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16467 {
16468         struct alc_spec *spec = codec->spec;
16469         int i;
16470
16471         for (i = 0; i < AUTO_PIN_LAST; i++) {
16472                 hda_nid_t nid = spec->autocfg.input_pins[i];
16473                 if (alc662_is_input_pin(nid)) {
16474                         snd_hda_codec_write(codec, nid, 0,
16475                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
16476                                             (i <= AUTO_PIN_FRONT_MIC ?
16477                                              PIN_VREF80 : PIN_IN));
16478                         if (nid != ALC662_PIN_CD_NID)
16479                                 snd_hda_codec_write(codec, nid, 0,
16480                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16481                                                     AMP_OUT_MUTE);
16482                 }
16483         }
16484 }
16485
16486 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16487
16488 static int alc662_parse_auto_config(struct hda_codec *codec)
16489 {
16490         struct alc_spec *spec = codec->spec;
16491         int err;
16492         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16493
16494         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16495                                            alc662_ignore);
16496         if (err < 0)
16497                 return err;
16498         if (!spec->autocfg.line_outs)
16499                 return 0; /* can't find valid BIOS pin config */
16500
16501         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16502         if (err < 0)
16503                 return err;
16504         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16505         if (err < 0)
16506                 return err;
16507         err = alc662_auto_create_extra_out(spec,
16508                                            spec->autocfg.speaker_pins[0],
16509                                            "Speaker");
16510         if (err < 0)
16511                 return err;
16512         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
16513                                            "Headphone");
16514         if (err < 0)
16515                 return err;
16516         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
16517         if (err < 0)
16518                 return err;
16519
16520         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16521
16522         if (spec->autocfg.dig_out_pin)
16523                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16524
16525         if (spec->kctls.list)
16526                 add_mixer(spec, spec->kctls.list);
16527
16528         spec->num_mux_defs = 1;
16529         spec->input_mux = &spec->private_imux;
16530
16531         add_verb(spec, alc662_auto_init_verbs);
16532         if (codec->vendor_id == 0x10ec0663)
16533                 add_verb(spec, alc663_auto_init_verbs);
16534
16535         err = alc_auto_add_mic_boost(codec);
16536         if (err < 0)
16537                 return err;
16538
16539         store_pin_configs(codec);
16540         return 1;
16541 }
16542
16543 /* additional initialization for auto-configuration model */
16544 static void alc662_auto_init(struct hda_codec *codec)
16545 {
16546         struct alc_spec *spec = codec->spec;
16547         alc662_auto_init_multi_out(codec);
16548         alc662_auto_init_hp_out(codec);
16549         alc662_auto_init_analog_input(codec);
16550         alc662_auto_init_input_src(codec);
16551         if (spec->unsol_event)
16552                 alc_inithook(codec);
16553 }
16554
16555 static int patch_alc662(struct hda_codec *codec)
16556 {
16557         struct alc_spec *spec;
16558         int err, board_config;
16559
16560         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16561         if (!spec)
16562                 return -ENOMEM;
16563
16564         codec->spec = spec;
16565
16566         alc_fix_pll_init(codec, 0x20, 0x04, 15);
16567
16568         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
16569                                                   alc662_models,
16570                                                   alc662_cfg_tbl);
16571         if (board_config < 0) {
16572                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
16573                        "trying auto-probe from BIOS...\n");
16574                 board_config = ALC662_AUTO;
16575         }
16576
16577         if (board_config == ALC662_AUTO) {
16578                 /* automatic parse from the BIOS config */
16579                 err = alc662_parse_auto_config(codec);
16580                 if (err < 0) {
16581                         alc_free(codec);
16582                         return err;
16583                 } else if (!err) {
16584                         printk(KERN_INFO
16585                                "hda_codec: Cannot set up configuration "
16586                                "from BIOS.  Using base mode...\n");
16587                         board_config = ALC662_3ST_2ch_DIG;
16588                 }
16589         }
16590
16591         if (board_config != ALC662_AUTO)
16592                 setup_preset(spec, &alc662_presets[board_config]);
16593
16594         if (codec->vendor_id == 0x10ec0663) {
16595                 spec->stream_name_analog = "ALC663 Analog";
16596                 spec->stream_name_digital = "ALC663 Digital";
16597         } else if (codec->vendor_id == 0x10ec0272) {
16598                 spec->stream_name_analog = "ALC272 Analog";
16599                 spec->stream_name_digital = "ALC272 Digital";
16600         } else {
16601                 spec->stream_name_analog = "ALC662 Analog";
16602                 spec->stream_name_digital = "ALC662 Digital";
16603         }
16604
16605         spec->stream_analog_playback = &alc662_pcm_analog_playback;
16606         spec->stream_analog_capture = &alc662_pcm_analog_capture;
16607
16608         spec->stream_digital_playback = &alc662_pcm_digital_playback;
16609         spec->stream_digital_capture = &alc662_pcm_digital_capture;
16610
16611         spec->adc_nids = alc662_adc_nids;
16612         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16613         spec->capsrc_nids = alc662_capsrc_nids;
16614         spec->is_mix_capture = 1;
16615
16616         if (!spec->cap_mixer)
16617                 set_capture_mixer(spec);
16618
16619         spec->vmaster_nid = 0x02;
16620
16621         codec->patch_ops = alc_patch_ops;
16622         if (board_config == ALC662_AUTO)
16623                 spec->init_hook = alc662_auto_init;
16624 #ifdef CONFIG_SND_HDA_POWER_SAVE
16625         if (!spec->loopback.amplist)
16626                 spec->loopback.amplist = alc662_loopbacks;
16627 #endif
16628         codec->proc_widget_hook = print_realtek_coef;
16629
16630         return 0;
16631 }
16632
16633 /*
16634  * patch entries
16635  */
16636 static struct hda_codec_preset snd_hda_preset_realtek[] = {
16637         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16638         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16639         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
16640         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
16641         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
16642         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
16643         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
16644           .patch = patch_alc861 },
16645         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
16646         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
16647         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
16648         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
16649           .patch = patch_alc883 },
16650         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
16651           .patch = patch_alc662 },
16652         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
16653         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
16654         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
16655         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16656         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
16657           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16658         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
16659           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16660         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
16661         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
16662         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
16663           .patch = patch_alc883 },
16664         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
16665         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16666         {} /* terminator */
16667 };
16668
16669 MODULE_ALIAS("snd-hda-codec-id:10ec*");
16670
16671 MODULE_LICENSE("GPL");
16672 MODULE_DESCRIPTION("Realtek HD-audio codec");
16673
16674 static struct hda_codec_preset_list realtek_list = {
16675         .preset = snd_hda_preset_realtek,
16676         .owner = THIS_MODULE,
16677 };
16678
16679 static int __init patch_realtek_init(void)
16680 {
16681         return snd_hda_add_codec_preset(&realtek_list);
16682 }
16683
16684 static void __exit patch_realtek_exit(void)
16685 {
16686         snd_hda_delete_codec_preset(&realtek_list);
16687 }
16688
16689 module_init(patch_realtek_init)
16690 module_exit(patch_realtek_exit)