ALSA: hda - Add quirk for MSI 7260 mobo
[safe/jmp/linux-2.6] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_patch.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_DC7600,
76         ALC260_HP_3013,
77         ALC260_FUJITSU_S702X,
78         ALC260_ACER,
79         ALC260_WILL,
80         ALC260_REPLACER_672V,
81 #ifdef CONFIG_SND_DEBUG
82         ALC260_TEST,
83 #endif
84         ALC260_AUTO,
85         ALC260_MODEL_LAST /* last tag */
86 };
87
88 /* ALC262 models */
89 enum {
90         ALC262_BASIC,
91         ALC262_HIPPO,
92         ALC262_HIPPO_1,
93         ALC262_FUJITSU,
94         ALC262_HP_BPC,
95         ALC262_HP_BPC_D7000_WL,
96         ALC262_HP_BPC_D7000_WF,
97         ALC262_HP_TC_T5735,
98         ALC262_HP_RP5700,
99         ALC262_BENQ_ED8,
100         ALC262_SONY_ASSAMD,
101         ALC262_BENQ_T31,
102         ALC262_ULTRA,
103         ALC262_LENOVO_3000,
104         ALC262_NEC,
105         ALC262_TOSHIBA_S06,
106         ALC262_TOSHIBA_RX1,
107         ALC262_AUTO,
108         ALC262_MODEL_LAST /* last tag */
109 };
110
111 /* ALC268 models */
112 enum {
113         ALC267_QUANTA_IL1,
114         ALC268_3ST,
115         ALC268_TOSHIBA,
116         ALC268_ACER,
117         ALC268_ACER_DMIC,
118         ALC268_ACER_ASPIRE_ONE,
119         ALC268_DELL,
120         ALC268_ZEPTO,
121 #ifdef CONFIG_SND_DEBUG
122         ALC268_TEST,
123 #endif
124         ALC268_AUTO,
125         ALC268_MODEL_LAST /* last tag */
126 };
127
128 /* ALC269 models */
129 enum {
130         ALC269_BASIC,
131         ALC269_QUANTA_FL1,
132         ALC269_ASUS_EEEPC_P703,
133         ALC269_ASUS_EEEPC_P901,
134         ALC269_FUJITSU,
135         ALC269_LIFEBOOK,
136         ALC269_AUTO,
137         ALC269_MODEL_LAST /* last tag */
138 };
139
140 /* ALC861 models */
141 enum {
142         ALC861_3ST,
143         ALC660_3ST,
144         ALC861_3ST_DIG,
145         ALC861_6ST_DIG,
146         ALC861_UNIWILL_M31,
147         ALC861_TOSHIBA,
148         ALC861_ASUS,
149         ALC861_ASUS_LAPTOP,
150         ALC861_AUTO,
151         ALC861_MODEL_LAST,
152 };
153
154 /* ALC861-VD models */
155 enum {
156         ALC660VD_3ST,
157         ALC660VD_3ST_DIG,
158         ALC660VD_ASUS_V1S,
159         ALC861VD_3ST,
160         ALC861VD_3ST_DIG,
161         ALC861VD_6ST_DIG,
162         ALC861VD_LENOVO,
163         ALC861VD_DALLAS,
164         ALC861VD_HP,
165         ALC861VD_AUTO,
166         ALC861VD_MODEL_LAST,
167 };
168
169 /* ALC662 models */
170 enum {
171         ALC662_3ST_2ch_DIG,
172         ALC662_3ST_6ch_DIG,
173         ALC662_3ST_6ch,
174         ALC662_5ST_DIG,
175         ALC662_LENOVO_101E,
176         ALC662_ASUS_EEEPC_P701,
177         ALC662_ASUS_EEEPC_EP20,
178         ALC663_ASUS_M51VA,
179         ALC663_ASUS_G71V,
180         ALC663_ASUS_H13,
181         ALC663_ASUS_G50V,
182         ALC662_ECS,
183         ALC663_ASUS_MODE1,
184         ALC662_ASUS_MODE2,
185         ALC663_ASUS_MODE3,
186         ALC663_ASUS_MODE4,
187         ALC663_ASUS_MODE5,
188         ALC663_ASUS_MODE6,
189         ALC662_AUTO,
190         ALC662_MODEL_LAST,
191 };
192
193 /* ALC882 models */
194 enum {
195         ALC882_3ST_DIG,
196         ALC882_6ST_DIG,
197         ALC882_ARIMA,
198         ALC882_W2JC,
199         ALC882_TARGA,
200         ALC882_ASUS_A7J,
201         ALC882_ASUS_A7M,
202         ALC885_MACPRO,
203         ALC885_MBP3,
204         ALC885_IMAC24,
205         ALC882_AUTO,
206         ALC882_MODEL_LAST,
207 };
208
209 /* ALC883 models */
210 enum {
211         ALC883_3ST_2ch_DIG,
212         ALC883_3ST_6ch_DIG,
213         ALC883_3ST_6ch,
214         ALC883_6ST_DIG,
215         ALC883_TARGA_DIG,
216         ALC883_TARGA_2ch_DIG,
217         ALC883_ACER,
218         ALC883_ACER_ASPIRE,
219         ALC888_ACER_ASPIRE_4930G,
220         ALC883_MEDION,
221         ALC883_MEDION_MD2,
222         ALC883_LAPTOP_EAPD,
223         ALC883_LENOVO_101E_2ch,
224         ALC883_LENOVO_NB0763,
225         ALC888_LENOVO_MS7195_DIG,
226         ALC888_LENOVO_SKY,
227         ALC883_HAIER_W66,
228         ALC888_3ST_HP,
229         ALC888_6ST_DELL,
230         ALC883_MITAC,
231         ALC883_CLEVO_M720,
232         ALC883_FUJITSU_PI2515,
233         ALC888_FUJITSU_XA3530,
234         ALC883_3ST_6ch_INTEL,
235         ALC888_ASUS_M90V,
236         ALC888_ASUS_EEE1601,
237         ALC1200_ASUS_P5Q,
238         ALC883_AUTO,
239         ALC883_MODEL_LAST,
240 };
241
242 /* for GPIO Poll */
243 #define GPIO_MASK       0x03
244
245 struct alc_spec {
246         /* codec parameterization */
247         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
248         unsigned int num_mixers;
249         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
250
251         const struct hda_verb *init_verbs[5];   /* initialization verbs
252                                                  * don't forget NULL
253                                                  * termination!
254                                                  */
255         unsigned int num_init_verbs;
256
257         char *stream_name_analog;       /* analog PCM stream */
258         struct hda_pcm_stream *stream_analog_playback;
259         struct hda_pcm_stream *stream_analog_capture;
260         struct hda_pcm_stream *stream_analog_alt_playback;
261         struct hda_pcm_stream *stream_analog_alt_capture;
262
263         char *stream_name_digital;      /* digital PCM stream */
264         struct hda_pcm_stream *stream_digital_playback;
265         struct hda_pcm_stream *stream_digital_capture;
266
267         /* playback */
268         struct hda_multi_out multiout;  /* playback set-up
269                                          * max_channels, dacs must be set
270                                          * dig_out_nid and hp_nid are optional
271                                          */
272         hda_nid_t alt_dac_nid;
273
274         /* capture */
275         unsigned int num_adc_nids;
276         hda_nid_t *adc_nids;
277         hda_nid_t *capsrc_nids;
278         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
279         unsigned char is_mix_capture;   /* matrix-style capture (non-mux) */
280
281         /* capture source */
282         unsigned int num_mux_defs;
283         const struct hda_input_mux *input_mux;
284         unsigned int cur_mux[3];
285
286         /* channel model */
287         const struct hda_channel_mode *channel_mode;
288         int num_channel_mode;
289         int need_dac_fix;
290
291         /* PCM information */
292         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
293
294         /* dynamic controls, init_verbs and input_mux */
295         struct auto_pin_cfg autocfg;
296         struct snd_array kctls;
297         struct hda_input_mux private_imux;
298         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
299
300         /* hooks */
301         void (*init_hook)(struct hda_codec *codec);
302         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
303
304         /* for pin sensing */
305         unsigned int sense_updated: 1;
306         unsigned int jack_present: 1;
307         unsigned int master_sw: 1;
308
309         /* for virtual master */
310         hda_nid_t vmaster_nid;
311 #ifdef CONFIG_SND_HDA_POWER_SAVE
312         struct hda_loopback_check loopback;
313 #endif
314
315         /* for PLL fix */
316         hda_nid_t pll_nid;
317         unsigned int pll_coef_idx, pll_coef_bit;
318
319 #ifdef SND_HDA_NEEDS_RESUME
320 #define ALC_MAX_PINS    16
321         unsigned int num_pins;
322         hda_nid_t pin_nids[ALC_MAX_PINS];
323         unsigned int pin_cfgs[ALC_MAX_PINS];
324 #endif
325 };
326
327 /*
328  * configuration template - to be copied to the spec instance
329  */
330 struct alc_config_preset {
331         struct snd_kcontrol_new *mixers[5]; /* should be identical size
332                                              * with spec
333                                              */
334         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
335         const struct hda_verb *init_verbs[5];
336         unsigned int num_dacs;
337         hda_nid_t *dac_nids;
338         hda_nid_t dig_out_nid;          /* optional */
339         hda_nid_t hp_nid;               /* optional */
340         unsigned int num_adc_nids;
341         hda_nid_t *adc_nids;
342         hda_nid_t *capsrc_nids;
343         hda_nid_t dig_in_nid;
344         unsigned int num_channel_mode;
345         const struct hda_channel_mode *channel_mode;
346         int need_dac_fix;
347         unsigned int num_mux_defs;
348         const struct hda_input_mux *input_mux;
349         void (*unsol_event)(struct hda_codec *, unsigned int);
350         void (*init_hook)(struct hda_codec *);
351 #ifdef CONFIG_SND_HDA_POWER_SAVE
352         struct hda_amp_list *loopbacks;
353 #endif
354 };
355
356
357 /*
358  * input MUX handling
359  */
360 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
361                              struct snd_ctl_elem_info *uinfo)
362 {
363         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
364         struct alc_spec *spec = codec->spec;
365         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
366         if (mux_idx >= spec->num_mux_defs)
367                 mux_idx = 0;
368         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
369 }
370
371 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
372                             struct snd_ctl_elem_value *ucontrol)
373 {
374         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
375         struct alc_spec *spec = codec->spec;
376         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
377
378         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
379         return 0;
380 }
381
382 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
383                             struct snd_ctl_elem_value *ucontrol)
384 {
385         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
386         struct alc_spec *spec = codec->spec;
387         const struct hda_input_mux *imux;
388         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
389         unsigned int mux_idx;
390         hda_nid_t nid = spec->capsrc_nids ?
391                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
392
393         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
394         imux = &spec->input_mux[mux_idx];
395
396         if (spec->is_mix_capture) {
397                 /* Matrix-mixer style (e.g. ALC882) */
398                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
399                 unsigned int i, idx;
400
401                 idx = ucontrol->value.enumerated.item[0];
402                 if (idx >= imux->num_items)
403                         idx = imux->num_items - 1;
404                 if (*cur_val == idx)
405                         return 0;
406                 for (i = 0; i < imux->num_items; i++) {
407                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
408                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
409                                                  imux->items[i].index,
410                                                  HDA_AMP_MUTE, v);
411                 }
412                 *cur_val = idx;
413                 return 1;
414         } else {
415                 /* MUX style (e.g. ALC880) */
416                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
417                                              &spec->cur_mux[adc_idx]);
418         }
419 }
420
421 /*
422  * channel mode setting
423  */
424 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
425                             struct snd_ctl_elem_info *uinfo)
426 {
427         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
428         struct alc_spec *spec = codec->spec;
429         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
430                                     spec->num_channel_mode);
431 }
432
433 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
434                            struct snd_ctl_elem_value *ucontrol)
435 {
436         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
437         struct alc_spec *spec = codec->spec;
438         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
439                                    spec->num_channel_mode,
440                                    spec->multiout.max_channels);
441 }
442
443 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
444                            struct snd_ctl_elem_value *ucontrol)
445 {
446         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
447         struct alc_spec *spec = codec->spec;
448         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
449                                       spec->num_channel_mode,
450                                       &spec->multiout.max_channels);
451         if (err >= 0 && spec->need_dac_fix)
452                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
453         return err;
454 }
455
456 /*
457  * Control the mode of pin widget settings via the mixer.  "pc" is used
458  * instead of "%" to avoid consequences of accidently treating the % as
459  * being part of a format specifier.  Maximum allowed length of a value is
460  * 63 characters plus NULL terminator.
461  *
462  * Note: some retasking pin complexes seem to ignore requests for input
463  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
464  * are requested.  Therefore order this list so that this behaviour will not
465  * cause problems when mixer clients move through the enum sequentially.
466  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
467  * March 2006.
468  */
469 static char *alc_pin_mode_names[] = {
470         "Mic 50pc bias", "Mic 80pc bias",
471         "Line in", "Line out", "Headphone out",
472 };
473 static unsigned char alc_pin_mode_values[] = {
474         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
475 };
476 /* The control can present all 5 options, or it can limit the options based
477  * in the pin being assumed to be exclusively an input or an output pin.  In
478  * addition, "input" pins may or may not process the mic bias option
479  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
480  * accept requests for bias as of chip versions up to March 2006) and/or
481  * wiring in the computer.
482  */
483 #define ALC_PIN_DIR_IN              0x00
484 #define ALC_PIN_DIR_OUT             0x01
485 #define ALC_PIN_DIR_INOUT           0x02
486 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
487 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
488
489 /* Info about the pin modes supported by the different pin direction modes.
490  * For each direction the minimum and maximum values are given.
491  */
492 static signed char alc_pin_mode_dir_info[5][2] = {
493         { 0, 2 },    /* ALC_PIN_DIR_IN */
494         { 3, 4 },    /* ALC_PIN_DIR_OUT */
495         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
496         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
497         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
498 };
499 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
500 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
501 #define alc_pin_mode_n_items(_dir) \
502         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
503
504 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
505                              struct snd_ctl_elem_info *uinfo)
506 {
507         unsigned int item_num = uinfo->value.enumerated.item;
508         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
509
510         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
511         uinfo->count = 1;
512         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
513
514         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
515                 item_num = alc_pin_mode_min(dir);
516         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
517         return 0;
518 }
519
520 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
521                             struct snd_ctl_elem_value *ucontrol)
522 {
523         unsigned int i;
524         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
525         hda_nid_t nid = kcontrol->private_value & 0xffff;
526         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
527         long *valp = ucontrol->value.integer.value;
528         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
529                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
530                                                  0x00);
531
532         /* Find enumerated value for current pinctl setting */
533         i = alc_pin_mode_min(dir);
534         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
535                 i++;
536         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
537         return 0;
538 }
539
540 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
541                             struct snd_ctl_elem_value *ucontrol)
542 {
543         signed int change;
544         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
545         hda_nid_t nid = kcontrol->private_value & 0xffff;
546         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
547         long val = *ucontrol->value.integer.value;
548         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
549                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
550                                                  0x00);
551
552         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
553                 val = alc_pin_mode_min(dir);
554
555         change = pinctl != alc_pin_mode_values[val];
556         if (change) {
557                 /* Set pin mode to that requested */
558                 snd_hda_codec_write_cache(codec, nid, 0,
559                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
560                                           alc_pin_mode_values[val]);
561
562                 /* Also enable the retasking pin's input/output as required
563                  * for the requested pin mode.  Enum values of 2 or less are
564                  * input modes.
565                  *
566                  * Dynamically switching the input/output buffers probably
567                  * reduces noise slightly (particularly on input) so we'll
568                  * do it.  However, having both input and output buffers
569                  * enabled simultaneously doesn't seem to be problematic if
570                  * this turns out to be necessary in the future.
571                  */
572                 if (val <= 2) {
573                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
574                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
575                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
576                                                  HDA_AMP_MUTE, 0);
577                 } else {
578                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
579                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
580                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
581                                                  HDA_AMP_MUTE, 0);
582                 }
583         }
584         return change;
585 }
586
587 #define ALC_PIN_MODE(xname, nid, dir) \
588         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
589           .info = alc_pin_mode_info, \
590           .get = alc_pin_mode_get, \
591           .put = alc_pin_mode_put, \
592           .private_value = nid | (dir<<16) }
593
594 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
595  * together using a mask with more than one bit set.  This control is
596  * currently used only by the ALC260 test model.  At this stage they are not
597  * needed for any "production" models.
598  */
599 #ifdef CONFIG_SND_DEBUG
600 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
601
602 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
603                              struct snd_ctl_elem_value *ucontrol)
604 {
605         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
606         hda_nid_t nid = kcontrol->private_value & 0xffff;
607         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
608         long *valp = ucontrol->value.integer.value;
609         unsigned int val = snd_hda_codec_read(codec, nid, 0,
610                                               AC_VERB_GET_GPIO_DATA, 0x00);
611
612         *valp = (val & mask) != 0;
613         return 0;
614 }
615 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
616                              struct snd_ctl_elem_value *ucontrol)
617 {
618         signed int change;
619         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
620         hda_nid_t nid = kcontrol->private_value & 0xffff;
621         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
622         long val = *ucontrol->value.integer.value;
623         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
624                                                     AC_VERB_GET_GPIO_DATA,
625                                                     0x00);
626
627         /* Set/unset the masked GPIO bit(s) as needed */
628         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
629         if (val == 0)
630                 gpio_data &= ~mask;
631         else
632                 gpio_data |= mask;
633         snd_hda_codec_write_cache(codec, nid, 0,
634                                   AC_VERB_SET_GPIO_DATA, gpio_data);
635
636         return change;
637 }
638 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
639         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
640           .info = alc_gpio_data_info, \
641           .get = alc_gpio_data_get, \
642           .put = alc_gpio_data_put, \
643           .private_value = nid | (mask<<16) }
644 #endif   /* CONFIG_SND_DEBUG */
645
646 /* A switch control to allow the enabling of the digital IO pins on the
647  * ALC260.  This is incredibly simplistic; the intention of this control is
648  * to provide something in the test model allowing digital outputs to be
649  * identified if present.  If models are found which can utilise these
650  * outputs a more complete mixer control can be devised for those models if
651  * necessary.
652  */
653 #ifdef CONFIG_SND_DEBUG
654 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
655
656 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
657                               struct snd_ctl_elem_value *ucontrol)
658 {
659         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
660         hda_nid_t nid = kcontrol->private_value & 0xffff;
661         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
662         long *valp = ucontrol->value.integer.value;
663         unsigned int val = snd_hda_codec_read(codec, nid, 0,
664                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
665
666         *valp = (val & mask) != 0;
667         return 0;
668 }
669 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
670                               struct snd_ctl_elem_value *ucontrol)
671 {
672         signed int change;
673         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
674         hda_nid_t nid = kcontrol->private_value & 0xffff;
675         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
676         long val = *ucontrol->value.integer.value;
677         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
678                                                     AC_VERB_GET_DIGI_CONVERT_1,
679                                                     0x00);
680
681         /* Set/unset the masked control bit(s) as needed */
682         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
683         if (val==0)
684                 ctrl_data &= ~mask;
685         else
686                 ctrl_data |= mask;
687         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
688                                   ctrl_data);
689
690         return change;
691 }
692 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
693         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
694           .info = alc_spdif_ctrl_info, \
695           .get = alc_spdif_ctrl_get, \
696           .put = alc_spdif_ctrl_put, \
697           .private_value = nid | (mask<<16) }
698 #endif   /* CONFIG_SND_DEBUG */
699
700 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
701  * Again, this is only used in the ALC26x test models to help identify when
702  * the EAPD line must be asserted for features to work.
703  */
704 #ifdef CONFIG_SND_DEBUG
705 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
706
707 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
708                               struct snd_ctl_elem_value *ucontrol)
709 {
710         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
711         hda_nid_t nid = kcontrol->private_value & 0xffff;
712         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
713         long *valp = ucontrol->value.integer.value;
714         unsigned int val = snd_hda_codec_read(codec, nid, 0,
715                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
716
717         *valp = (val & mask) != 0;
718         return 0;
719 }
720
721 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
722                               struct snd_ctl_elem_value *ucontrol)
723 {
724         int change;
725         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
726         hda_nid_t nid = kcontrol->private_value & 0xffff;
727         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
728         long val = *ucontrol->value.integer.value;
729         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
730                                                     AC_VERB_GET_EAPD_BTLENABLE,
731                                                     0x00);
732
733         /* Set/unset the masked control bit(s) as needed */
734         change = (!val ? 0 : mask) != (ctrl_data & mask);
735         if (!val)
736                 ctrl_data &= ~mask;
737         else
738                 ctrl_data |= mask;
739         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
740                                   ctrl_data);
741
742         return change;
743 }
744
745 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
746         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
747           .info = alc_eapd_ctrl_info, \
748           .get = alc_eapd_ctrl_get, \
749           .put = alc_eapd_ctrl_put, \
750           .private_value = nid | (mask<<16) }
751 #endif   /* CONFIG_SND_DEBUG */
752
753 /*
754  */
755 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
756 {
757         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
758                 return;
759         spec->mixers[spec->num_mixers++] = mix;
760 }
761
762 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
763 {
764         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
765                 return;
766         spec->init_verbs[spec->num_init_verbs++] = verb;
767 }
768
769 /*
770  * set up from the preset table
771  */
772 static void setup_preset(struct alc_spec *spec,
773                          const struct alc_config_preset *preset)
774 {
775         int i;
776
777         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
778                 add_mixer(spec, preset->mixers[i]);
779         spec->cap_mixer = preset->cap_mixer;
780         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
781              i++)
782                 add_verb(spec, preset->init_verbs[i]);
783
784         spec->channel_mode = preset->channel_mode;
785         spec->num_channel_mode = preset->num_channel_mode;
786         spec->need_dac_fix = preset->need_dac_fix;
787
788         spec->multiout.max_channels = spec->channel_mode[0].channels;
789
790         spec->multiout.num_dacs = preset->num_dacs;
791         spec->multiout.dac_nids = preset->dac_nids;
792         spec->multiout.dig_out_nid = preset->dig_out_nid;
793         spec->multiout.hp_nid = preset->hp_nid;
794
795         spec->num_mux_defs = preset->num_mux_defs;
796         if (!spec->num_mux_defs)
797                 spec->num_mux_defs = 1;
798         spec->input_mux = preset->input_mux;
799
800         spec->num_adc_nids = preset->num_adc_nids;
801         spec->adc_nids = preset->adc_nids;
802         spec->capsrc_nids = preset->capsrc_nids;
803         spec->dig_in_nid = preset->dig_in_nid;
804
805         spec->unsol_event = preset->unsol_event;
806         spec->init_hook = preset->init_hook;
807 #ifdef CONFIG_SND_HDA_POWER_SAVE
808         spec->loopback.amplist = preset->loopbacks;
809 #endif
810 }
811
812 /* Enable GPIO mask and set output */
813 static struct hda_verb alc_gpio1_init_verbs[] = {
814         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
815         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
816         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
817         { }
818 };
819
820 static struct hda_verb alc_gpio2_init_verbs[] = {
821         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
822         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
823         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
824         { }
825 };
826
827 static struct hda_verb alc_gpio3_init_verbs[] = {
828         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
829         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
830         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
831         { }
832 };
833
834 /*
835  * Fix hardware PLL issue
836  * On some codecs, the analog PLL gating control must be off while
837  * the default value is 1.
838  */
839 static void alc_fix_pll(struct hda_codec *codec)
840 {
841         struct alc_spec *spec = codec->spec;
842         unsigned int val;
843
844         if (!spec->pll_nid)
845                 return;
846         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
847                             spec->pll_coef_idx);
848         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
849                                  AC_VERB_GET_PROC_COEF, 0);
850         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
851                             spec->pll_coef_idx);
852         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
853                             val & ~(1 << spec->pll_coef_bit));
854 }
855
856 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
857                              unsigned int coef_idx, unsigned int coef_bit)
858 {
859         struct alc_spec *spec = codec->spec;
860         spec->pll_nid = nid;
861         spec->pll_coef_idx = coef_idx;
862         spec->pll_coef_bit = coef_bit;
863         alc_fix_pll(codec);
864 }
865
866 static void alc_sku_automute(struct hda_codec *codec)
867 {
868         struct alc_spec *spec = codec->spec;
869         unsigned int present;
870         unsigned int hp_nid = spec->autocfg.hp_pins[0];
871         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
872
873         /* need to execute and sync at first */
874         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
875         present = snd_hda_codec_read(codec, hp_nid, 0,
876                                      AC_VERB_GET_PIN_SENSE, 0);
877         spec->jack_present = (present & 0x80000000) != 0;
878         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
879                             spec->jack_present ? 0 : PIN_OUT);
880 }
881
882 #if 0 /* it's broken in some acses -- temporarily disabled */
883 static void alc_mic_automute(struct hda_codec *codec)
884 {
885         struct alc_spec *spec = codec->spec;
886         unsigned int present;
887         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
888         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
889         unsigned int mix_nid = spec->capsrc_nids[0];
890         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
891
892         capsrc_idx_mic = mic_nid - 0x18;
893         capsrc_idx_fmic = fmic_nid - 0x18;
894         present = snd_hda_codec_read(codec, mic_nid, 0,
895                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
896         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
897                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
898         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
899                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
900         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
901                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
902 }
903 #else
904 #define alc_mic_automute(codec) /* NOP */
905 #endif /* disabled */
906
907 /* unsolicited event for HP jack sensing */
908 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
909 {
910         if (codec->vendor_id == 0x10ec0880)
911                 res >>= 28;
912         else
913                 res >>= 26;
914         if (res == ALC880_HP_EVENT)
915                 alc_sku_automute(codec);
916
917         if (res == ALC880_MIC_EVENT)
918                 alc_mic_automute(codec);
919 }
920
921 static void alc_inithook(struct hda_codec *codec)
922 {
923         alc_sku_automute(codec);
924         alc_mic_automute(codec);
925 }
926
927 /* additional initialization for ALC888 variants */
928 static void alc888_coef_init(struct hda_codec *codec)
929 {
930         unsigned int tmp;
931
932         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
933         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
934         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
935         if ((tmp & 0xf0) == 2)
936                 /* alc888S-VC */
937                 snd_hda_codec_read(codec, 0x20, 0,
938                                    AC_VERB_SET_PROC_COEF, 0x830);
939          else
940                  /* alc888-VB */
941                  snd_hda_codec_read(codec, 0x20, 0,
942                                     AC_VERB_SET_PROC_COEF, 0x3030);
943 }
944
945 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
946  *      31 ~ 16 :       Manufacture ID
947  *      15 ~ 8  :       SKU ID
948  *      7  ~ 0  :       Assembly ID
949  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
950  */
951 static void alc_subsystem_id(struct hda_codec *codec,
952                              unsigned int porta, unsigned int porte,
953                              unsigned int portd)
954 {
955         unsigned int ass, tmp, i;
956         unsigned nid;
957         struct alc_spec *spec = codec->spec;
958
959         ass = codec->subsystem_id & 0xffff;
960         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
961                 goto do_sku;
962
963         /*
964          * 31~30        : port conetcivity
965          * 29~21        : reserve
966          * 20           : PCBEEP input
967          * 19~16        : Check sum (15:1)
968          * 15~1         : Custom
969          * 0            : override
970         */
971         nid = 0x1d;
972         if (codec->vendor_id == 0x10ec0260)
973                 nid = 0x17;
974         ass = snd_hda_codec_read(codec, nid, 0,
975                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
976         if (!(ass & 1) && !(ass & 0x100000))
977                 return;
978         if ((ass >> 30) != 1)   /* no physical connection */
979                 return;
980
981         /* check sum */
982         tmp = 0;
983         for (i = 1; i < 16; i++) {
984                 if ((ass >> i) & 1)
985                         tmp++;
986         }
987         if (((ass >> 16) & 0xf) != tmp)
988                 return;
989 do_sku:
990         /*
991          * 0 : override
992          * 1 :  Swap Jack
993          * 2 : 0 --> Desktop, 1 --> Laptop
994          * 3~5 : External Amplifier control
995          * 7~6 : Reserved
996         */
997         tmp = (ass & 0x38) >> 3;        /* external Amp control */
998         switch (tmp) {
999         case 1:
1000                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1001                 break;
1002         case 3:
1003                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1004                 break;
1005         case 7:
1006                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1007                 break;
1008         case 5: /* set EAPD output high */
1009                 switch (codec->vendor_id) {
1010                 case 0x10ec0260:
1011                         snd_hda_codec_write(codec, 0x0f, 0,
1012                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1013                         snd_hda_codec_write(codec, 0x10, 0,
1014                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1015                         break;
1016                 case 0x10ec0262:
1017                 case 0x10ec0267:
1018                 case 0x10ec0268:
1019                 case 0x10ec0269:
1020                 case 0x10ec0660:
1021                 case 0x10ec0662:
1022                 case 0x10ec0663:
1023                 case 0x10ec0862:
1024                 case 0x10ec0889:
1025                         snd_hda_codec_write(codec, 0x14, 0,
1026                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1027                         snd_hda_codec_write(codec, 0x15, 0,
1028                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1029                         break;
1030                 }
1031                 switch (codec->vendor_id) {
1032                 case 0x10ec0260:
1033                         snd_hda_codec_write(codec, 0x1a, 0,
1034                                             AC_VERB_SET_COEF_INDEX, 7);
1035                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1036                                                  AC_VERB_GET_PROC_COEF, 0);
1037                         snd_hda_codec_write(codec, 0x1a, 0,
1038                                             AC_VERB_SET_COEF_INDEX, 7);
1039                         snd_hda_codec_write(codec, 0x1a, 0,
1040                                             AC_VERB_SET_PROC_COEF,
1041                                             tmp | 0x2010);
1042                         break;
1043                 case 0x10ec0262:
1044                 case 0x10ec0880:
1045                 case 0x10ec0882:
1046                 case 0x10ec0883:
1047                 case 0x10ec0885:
1048                 case 0x10ec0889:
1049                         snd_hda_codec_write(codec, 0x20, 0,
1050                                             AC_VERB_SET_COEF_INDEX, 7);
1051                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1052                                                  AC_VERB_GET_PROC_COEF, 0);
1053                         snd_hda_codec_write(codec, 0x20, 0,
1054                                             AC_VERB_SET_COEF_INDEX, 7);
1055                         snd_hda_codec_write(codec, 0x20, 0,
1056                                             AC_VERB_SET_PROC_COEF,
1057                                             tmp | 0x2010);
1058                         break;
1059                 case 0x10ec0888:
1060                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1061                         break;
1062                 case 0x10ec0267:
1063                 case 0x10ec0268:
1064                         snd_hda_codec_write(codec, 0x20, 0,
1065                                             AC_VERB_SET_COEF_INDEX, 7);
1066                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1067                                                  AC_VERB_GET_PROC_COEF, 0);
1068                         snd_hda_codec_write(codec, 0x20, 0,
1069                                             AC_VERB_SET_COEF_INDEX, 7);
1070                         snd_hda_codec_write(codec, 0x20, 0,
1071                                             AC_VERB_SET_PROC_COEF,
1072                                             tmp | 0x3000);
1073                         break;
1074                 }
1075         default:
1076                 break;
1077         }
1078
1079         /* is laptop or Desktop and enable the function "Mute internal speaker
1080          * when the external headphone out jack is plugged"
1081          */
1082         if (!(ass & 0x8000))
1083                 return;
1084         /*
1085          * 10~8 : Jack location
1086          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1087          * 14~13: Resvered
1088          * 15   : 1 --> enable the function "Mute internal speaker
1089          *              when the external headphone out jack is plugged"
1090          */
1091         if (!spec->autocfg.speaker_pins[0]) {
1092                 if (spec->autocfg.line_out_pins[0])
1093                         spec->autocfg.speaker_pins[0] =
1094                                 spec->autocfg.line_out_pins[0];
1095                 else
1096                         return;
1097         }
1098
1099         if (!spec->autocfg.hp_pins[0]) {
1100                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1101                 if (tmp == 0)
1102                         spec->autocfg.hp_pins[0] = porta;
1103                 else if (tmp == 1)
1104                         spec->autocfg.hp_pins[0] = porte;
1105                 else if (tmp == 2)
1106                         spec->autocfg.hp_pins[0] = portd;
1107                 else
1108                         return;
1109         }
1110         if (spec->autocfg.hp_pins[0])
1111                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1112                         AC_VERB_SET_UNSOLICITED_ENABLE,
1113                         AC_USRSP_EN | ALC880_HP_EVENT);
1114
1115 #if 0 /* it's broken in some acses -- temporarily disabled */
1116         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1117                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1118                 snd_hda_codec_write(codec,
1119                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1120                         AC_VERB_SET_UNSOLICITED_ENABLE,
1121                         AC_USRSP_EN | ALC880_MIC_EVENT);
1122 #endif /* disabled */
1123
1124         spec->unsol_event = alc_sku_unsol_event;
1125 }
1126
1127 /*
1128  * Fix-up pin default configurations
1129  */
1130
1131 struct alc_pincfg {
1132         hda_nid_t nid;
1133         u32 val;
1134 };
1135
1136 static void alc_fix_pincfg(struct hda_codec *codec,
1137                            const struct snd_pci_quirk *quirk,
1138                            const struct alc_pincfg **pinfix)
1139 {
1140         const struct alc_pincfg *cfg;
1141
1142         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1143         if (!quirk)
1144                 return;
1145
1146         cfg = pinfix[quirk->value];
1147         for (; cfg->nid; cfg++) {
1148                 int i;
1149                 u32 val = cfg->val;
1150                 for (i = 0; i < 4; i++) {
1151                         snd_hda_codec_write(codec, cfg->nid, 0,
1152                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1153                                     val & 0xff);
1154                         val >>= 8;
1155                 }
1156         }
1157 }
1158
1159 /*
1160  * ALC888
1161  */
1162
1163 /*
1164  * 2ch mode
1165  */
1166 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1167 /* Mic-in jack as mic in */
1168         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1169         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1170 /* Line-in jack as Line in */
1171         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1172         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1173 /* Line-Out as Front */
1174         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1175         { } /* end */
1176 };
1177
1178 /*
1179  * 4ch mode
1180  */
1181 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1182 /* Mic-in jack as mic in */
1183         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1184         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1185 /* Line-in jack as Surround */
1186         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1187         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1188 /* Line-Out as Front */
1189         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1190         { } /* end */
1191 };
1192
1193 /*
1194  * 6ch mode
1195  */
1196 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1197 /* Mic-in jack as CLFE */
1198         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1199         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1200 /* Line-in jack as Surround */
1201         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1202         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1203 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1204         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1205         { } /* end */
1206 };
1207
1208 /*
1209  * 8ch mode
1210  */
1211 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1212 /* Mic-in jack as CLFE */
1213         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1214         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1215 /* Line-in jack as Surround */
1216         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1217         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1218 /* Line-Out as Side */
1219         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1220         { } /* end */
1221 };
1222
1223 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1224         { 2, alc888_4ST_ch2_intel_init },
1225         { 4, alc888_4ST_ch4_intel_init },
1226         { 6, alc888_4ST_ch6_intel_init },
1227         { 8, alc888_4ST_ch8_intel_init },
1228 };
1229
1230 /*
1231  * ALC888 Fujitsu Siemens Amillo xa3530
1232  */
1233
1234 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1235 /* Front Mic: set to PIN_IN (empty by default) */
1236         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1237 /* Connect Internal HP to Front */
1238         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1239         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1240         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1241 /* Connect Bass HP to Front */
1242         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1243         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1244         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1245 /* Connect Line-Out side jack (SPDIF) to Side */
1246         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1247         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1248         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1249 /* Connect Mic jack to CLFE */
1250         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1251         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1252         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1253 /* Connect Line-in jack to Surround */
1254         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1255         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1256         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1257 /* Connect HP out jack to Front */
1258         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1259         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1260         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1261 /* Enable unsolicited event for HP jack and Line-out jack */
1262         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1263         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1264         {}
1265 };
1266
1267 static void alc888_fujitsu_xa3530_automute(struct hda_codec *codec)
1268 {
1269         unsigned int present;
1270         unsigned int bits;
1271         /* Line out presence */
1272         present = snd_hda_codec_read(codec, 0x17, 0,
1273                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1274         /* HP out presence */
1275         present = present || snd_hda_codec_read(codec, 0x1b, 0,
1276                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1277         bits = present ? HDA_AMP_MUTE : 0;
1278         /* Toggle internal speakers muting */
1279         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1280                                  HDA_AMP_MUTE, bits);
1281         /* Toggle internal bass muting */
1282         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1283                                  HDA_AMP_MUTE, bits);
1284 }
1285
1286 static void alc888_fujitsu_xa3530_unsol_event(struct hda_codec *codec,
1287                 unsigned int res)
1288 {
1289         if (res >> 26 == ALC880_HP_EVENT)
1290                 alc888_fujitsu_xa3530_automute(codec);
1291 }
1292
1293
1294 /*
1295  * ALC888 Acer Aspire 4930G model
1296  */
1297
1298 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1299 /* Front Mic: set to PIN_IN (empty by default) */
1300         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1301 /* Unselect Front Mic by default in input mixer 3 */
1302         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1303 /* Enable unsolicited event for HP jack */
1304         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1305 /* Connect Internal HP to front */
1306         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1307         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1308         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1309 /* Connect HP out to front */
1310         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1311         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1312         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1313         { }
1314 };
1315
1316 static struct hda_input_mux alc888_2_capture_sources[2] = {
1317         /* Front mic only available on one ADC */
1318         {
1319                 .num_items = 4,
1320                 .items = {
1321                         { "Mic", 0x0 },
1322                         { "Line", 0x2 },
1323                         { "CD", 0x4 },
1324                         { "Front Mic", 0xb },
1325                 },
1326         },
1327         {
1328                 .num_items = 3,
1329                 .items = {
1330                         { "Mic", 0x0 },
1331                         { "Line", 0x2 },
1332                         { "CD", 0x4 },
1333                 },
1334         }
1335 };
1336
1337 static struct snd_kcontrol_new alc888_base_mixer[] = {
1338         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1339         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1340         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1341         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1342         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1343                 HDA_OUTPUT),
1344         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1345         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1346         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1347         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1348         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1349         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1350         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1351         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1352         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1353         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1354         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1355         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1356         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1357         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1358         { } /* end */
1359 };
1360
1361 static void alc888_acer_aspire_4930g_automute(struct hda_codec *codec)
1362 {
1363         unsigned int present;
1364         unsigned int bits;
1365         present = snd_hda_codec_read(codec, 0x15, 0,
1366                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1367         bits = present ? HDA_AMP_MUTE : 0;
1368         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1369                                  HDA_AMP_MUTE, bits);
1370 }
1371
1372 static void alc888_acer_aspire_4930g_unsol_event(struct hda_codec *codec,
1373                 unsigned int res)
1374 {
1375         if (res >> 26 == ALC880_HP_EVENT)
1376                 alc888_acer_aspire_4930g_automute(codec);
1377 }
1378
1379 /*
1380  * ALC880 3-stack model
1381  *
1382  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1383  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1384  *                 F-Mic = 0x1b, HP = 0x19
1385  */
1386
1387 static hda_nid_t alc880_dac_nids[4] = {
1388         /* front, rear, clfe, rear_surr */
1389         0x02, 0x05, 0x04, 0x03
1390 };
1391
1392 static hda_nid_t alc880_adc_nids[3] = {
1393         /* ADC0-2 */
1394         0x07, 0x08, 0x09,
1395 };
1396
1397 /* The datasheet says the node 0x07 is connected from inputs,
1398  * but it shows zero connection in the real implementation on some devices.
1399  * Note: this is a 915GAV bug, fixed on 915GLV
1400  */
1401 static hda_nid_t alc880_adc_nids_alt[2] = {
1402         /* ADC1-2 */
1403         0x08, 0x09,
1404 };
1405
1406 #define ALC880_DIGOUT_NID       0x06
1407 #define ALC880_DIGIN_NID        0x0a
1408
1409 static struct hda_input_mux alc880_capture_source = {
1410         .num_items = 4,
1411         .items = {
1412                 { "Mic", 0x0 },
1413                 { "Front Mic", 0x3 },
1414                 { "Line", 0x2 },
1415                 { "CD", 0x4 },
1416         },
1417 };
1418
1419 /* channel source setting (2/6 channel selection for 3-stack) */
1420 /* 2ch mode */
1421 static struct hda_verb alc880_threestack_ch2_init[] = {
1422         /* set line-in to input, mute it */
1423         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1424         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1425         /* set mic-in to input vref 80%, mute it */
1426         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1427         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1428         { } /* end */
1429 };
1430
1431 /* 6ch mode */
1432 static struct hda_verb alc880_threestack_ch6_init[] = {
1433         /* set line-in to output, unmute it */
1434         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1435         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1436         /* set mic-in to output, unmute it */
1437         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1438         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1439         { } /* end */
1440 };
1441
1442 static struct hda_channel_mode alc880_threestack_modes[2] = {
1443         { 2, alc880_threestack_ch2_init },
1444         { 6, alc880_threestack_ch6_init },
1445 };
1446
1447 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1448         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1449         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1450         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1451         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1452         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1453         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1454         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1455         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1456         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1457         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1458         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1459         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1460         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1461         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1462         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1463         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1464         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1465         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1466         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1467         {
1468                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1469                 .name = "Channel Mode",
1470                 .info = alc_ch_mode_info,
1471                 .get = alc_ch_mode_get,
1472                 .put = alc_ch_mode_put,
1473         },
1474         { } /* end */
1475 };
1476
1477 /* capture mixer elements */
1478 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1479                             struct snd_ctl_elem_info *uinfo)
1480 {
1481         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1482         struct alc_spec *spec = codec->spec;
1483         int err;
1484
1485         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1486         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1487                                                       HDA_INPUT);
1488         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1489         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1490         return err;
1491 }
1492
1493 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1494                            unsigned int size, unsigned int __user *tlv)
1495 {
1496         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1497         struct alc_spec *spec = codec->spec;
1498         int err;
1499
1500         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1501         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1502                                                       HDA_INPUT);
1503         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1504         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1505         return err;
1506 }
1507
1508 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1509                              struct snd_ctl_elem_value *ucontrol);
1510
1511 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1512                                  struct snd_ctl_elem_value *ucontrol,
1513                                  getput_call_t func)
1514 {
1515         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1516         struct alc_spec *spec = codec->spec;
1517         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1518         int err;
1519
1520         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1521         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1522                                                       3, 0, HDA_INPUT);
1523         err = func(kcontrol, ucontrol);
1524         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1525         return err;
1526 }
1527
1528 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1529                            struct snd_ctl_elem_value *ucontrol)
1530 {
1531         return alc_cap_getput_caller(kcontrol, ucontrol,
1532                                      snd_hda_mixer_amp_volume_get);
1533 }
1534
1535 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1536                            struct snd_ctl_elem_value *ucontrol)
1537 {
1538         return alc_cap_getput_caller(kcontrol, ucontrol,
1539                                      snd_hda_mixer_amp_volume_put);
1540 }
1541
1542 /* capture mixer elements */
1543 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1544
1545 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1546                           struct snd_ctl_elem_value *ucontrol)
1547 {
1548         return alc_cap_getput_caller(kcontrol, ucontrol,
1549                                      snd_hda_mixer_amp_switch_get);
1550 }
1551
1552 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1553                           struct snd_ctl_elem_value *ucontrol)
1554 {
1555         return alc_cap_getput_caller(kcontrol, ucontrol,
1556                                      snd_hda_mixer_amp_switch_put);
1557 }
1558
1559 #define DEFINE_CAPMIX(num) \
1560 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1561         { \
1562                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1563                 .name = "Capture Switch", \
1564                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1565                 .count = num, \
1566                 .info = alc_cap_sw_info, \
1567                 .get = alc_cap_sw_get, \
1568                 .put = alc_cap_sw_put, \
1569         }, \
1570         { \
1571                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1572                 .name = "Capture Volume", \
1573                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1574                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1575                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1576                 .count = num, \
1577                 .info = alc_cap_vol_info, \
1578                 .get = alc_cap_vol_get, \
1579                 .put = alc_cap_vol_put, \
1580                 .tlv = { .c = alc_cap_vol_tlv }, \
1581         }, \
1582         { \
1583                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1584                 /* .name = "Capture Source", */ \
1585                 .name = "Input Source", \
1586                 .count = num, \
1587                 .info = alc_mux_enum_info, \
1588                 .get = alc_mux_enum_get, \
1589                 .put = alc_mux_enum_put, \
1590         }, \
1591         { } /* end */ \
1592 }
1593
1594 /* up to three ADCs */
1595 DEFINE_CAPMIX(1);
1596 DEFINE_CAPMIX(2);
1597 DEFINE_CAPMIX(3);
1598
1599
1600 /*
1601  * ALC880 5-stack model
1602  *
1603  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1604  *      Side = 0x02 (0xd)
1605  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1606  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1607  */
1608
1609 /* additional mixers to alc880_three_stack_mixer */
1610 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1611         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1612         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1613         { } /* end */
1614 };
1615
1616 /* channel source setting (6/8 channel selection for 5-stack) */
1617 /* 6ch mode */
1618 static struct hda_verb alc880_fivestack_ch6_init[] = {
1619         /* set line-in to input, mute it */
1620         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1621         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1622         { } /* end */
1623 };
1624
1625 /* 8ch mode */
1626 static struct hda_verb alc880_fivestack_ch8_init[] = {
1627         /* set line-in to output, unmute it */
1628         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1629         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1630         { } /* end */
1631 };
1632
1633 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1634         { 6, alc880_fivestack_ch6_init },
1635         { 8, alc880_fivestack_ch8_init },
1636 };
1637
1638
1639 /*
1640  * ALC880 6-stack model
1641  *
1642  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1643  *      Side = 0x05 (0x0f)
1644  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1645  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1646  */
1647
1648 static hda_nid_t alc880_6st_dac_nids[4] = {
1649         /* front, rear, clfe, rear_surr */
1650         0x02, 0x03, 0x04, 0x05
1651 };
1652
1653 static struct hda_input_mux alc880_6stack_capture_source = {
1654         .num_items = 4,
1655         .items = {
1656                 { "Mic", 0x0 },
1657                 { "Front Mic", 0x1 },
1658                 { "Line", 0x2 },
1659                 { "CD", 0x4 },
1660         },
1661 };
1662
1663 /* fixed 8-channels */
1664 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1665         { 8, NULL },
1666 };
1667
1668 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1669         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1670         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1671         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1672         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1673         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1674         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1675         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1676         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1677         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1678         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1679         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1680         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1681         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1682         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1683         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1684         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1685         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1686         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1687         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1688         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1689         {
1690                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1691                 .name = "Channel Mode",
1692                 .info = alc_ch_mode_info,
1693                 .get = alc_ch_mode_get,
1694                 .put = alc_ch_mode_put,
1695         },
1696         { } /* end */
1697 };
1698
1699
1700 /*
1701  * ALC880 W810 model
1702  *
1703  * W810 has rear IO for:
1704  * Front (DAC 02)
1705  * Surround (DAC 03)
1706  * Center/LFE (DAC 04)
1707  * Digital out (06)
1708  *
1709  * The system also has a pair of internal speakers, and a headphone jack.
1710  * These are both connected to Line2 on the codec, hence to DAC 02.
1711  *
1712  * There is a variable resistor to control the speaker or headphone
1713  * volume. This is a hardware-only device without a software API.
1714  *
1715  * Plugging headphones in will disable the internal speakers. This is
1716  * implemented in hardware, not via the driver using jack sense. In
1717  * a similar fashion, plugging into the rear socket marked "front" will
1718  * disable both the speakers and headphones.
1719  *
1720  * For input, there's a microphone jack, and an "audio in" jack.
1721  * These may not do anything useful with this driver yet, because I
1722  * haven't setup any initialization verbs for these yet...
1723  */
1724
1725 static hda_nid_t alc880_w810_dac_nids[3] = {
1726         /* front, rear/surround, clfe */
1727         0x02, 0x03, 0x04
1728 };
1729
1730 /* fixed 6 channels */
1731 static struct hda_channel_mode alc880_w810_modes[1] = {
1732         { 6, NULL }
1733 };
1734
1735 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1736 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1737         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1738         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1739         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1740         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1741         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1742         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1743         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1744         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1745         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1746         { } /* end */
1747 };
1748
1749
1750 /*
1751  * Z710V model
1752  *
1753  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1754  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1755  *                 Line = 0x1a
1756  */
1757
1758 static hda_nid_t alc880_z71v_dac_nids[1] = {
1759         0x02
1760 };
1761 #define ALC880_Z71V_HP_DAC      0x03
1762
1763 /* fixed 2 channels */
1764 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1765         { 2, NULL }
1766 };
1767
1768 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1769         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1770         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1771         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1772         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1773         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1774         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1775         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1776         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1777         { } /* end */
1778 };
1779
1780
1781 /*
1782  * ALC880 F1734 model
1783  *
1784  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1785  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1786  */
1787
1788 static hda_nid_t alc880_f1734_dac_nids[1] = {
1789         0x03
1790 };
1791 #define ALC880_F1734_HP_DAC     0x02
1792
1793 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1794         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1795         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1796         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1797         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1798         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1799         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1800         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1801         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1802         { } /* end */
1803 };
1804
1805 static struct hda_input_mux alc880_f1734_capture_source = {
1806         .num_items = 2,
1807         .items = {
1808                 { "Mic", 0x1 },
1809                 { "CD", 0x4 },
1810         },
1811 };
1812
1813
1814 /*
1815  * ALC880 ASUS model
1816  *
1817  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1818  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1819  *  Mic = 0x18, Line = 0x1a
1820  */
1821
1822 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1823 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1824
1825 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1826         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1827         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1828         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1829         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1830         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1831         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1832         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1833         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1834         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1835         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1836         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1837         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1838         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1839         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1840         {
1841                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1842                 .name = "Channel Mode",
1843                 .info = alc_ch_mode_info,
1844                 .get = alc_ch_mode_get,
1845                 .put = alc_ch_mode_put,
1846         },
1847         { } /* end */
1848 };
1849
1850 /*
1851  * ALC880 ASUS W1V model
1852  *
1853  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1854  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1855  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1856  */
1857
1858 /* additional mixers to alc880_asus_mixer */
1859 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1860         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1861         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1862         { } /* end */
1863 };
1864
1865 /* additional mixers to alc880_asus_mixer */
1866 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1867         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1868         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1869         { } /* end */
1870 };
1871
1872 /* TCL S700 */
1873 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1874         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1875         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1876         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1877         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1878         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1879         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1880         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1881         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1882         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1883         { } /* end */
1884 };
1885
1886 /* Uniwill */
1887 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1888         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1889         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1890         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1891         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1892         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1893         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1894         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1895         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1896         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1897         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1898         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1899         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1900         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1901         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1902         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1903         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1904         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1905         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1906         {
1907                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1908                 .name = "Channel Mode",
1909                 .info = alc_ch_mode_info,
1910                 .get = alc_ch_mode_get,
1911                 .put = alc_ch_mode_put,
1912         },
1913         { } /* end */
1914 };
1915
1916 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1917         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1918         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1919         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1920         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1921         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1922         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1923         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1924         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1925         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1926         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1927         { } /* end */
1928 };
1929
1930 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1931         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1932         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1933         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1934         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1935         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1936         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1937         { } /* end */
1938 };
1939
1940 /*
1941  * virtual master controls
1942  */
1943
1944 /*
1945  * slave controls for virtual master
1946  */
1947 static const char *alc_slave_vols[] = {
1948         "Front Playback Volume",
1949         "Surround Playback Volume",
1950         "Center Playback Volume",
1951         "LFE Playback Volume",
1952         "Side Playback Volume",
1953         "Headphone Playback Volume",
1954         "Speaker Playback Volume",
1955         "Mono Playback Volume",
1956         "Line-Out Playback Volume",
1957         "PCM Playback Volume",
1958         NULL,
1959 };
1960
1961 static const char *alc_slave_sws[] = {
1962         "Front Playback Switch",
1963         "Surround Playback Switch",
1964         "Center Playback Switch",
1965         "LFE Playback Switch",
1966         "Side Playback Switch",
1967         "Headphone Playback Switch",
1968         "Speaker Playback Switch",
1969         "Mono Playback Switch",
1970         "IEC958 Playback Switch",
1971         NULL,
1972 };
1973
1974 /*
1975  * build control elements
1976  */
1977
1978 static void alc_free_kctls(struct hda_codec *codec);
1979
1980 static int alc_build_controls(struct hda_codec *codec)
1981 {
1982         struct alc_spec *spec = codec->spec;
1983         int err;
1984         int i;
1985
1986         for (i = 0; i < spec->num_mixers; i++) {
1987                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1988                 if (err < 0)
1989                         return err;
1990         }
1991         if (spec->cap_mixer) {
1992                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1993                 if (err < 0)
1994                         return err;
1995         }
1996         if (spec->multiout.dig_out_nid) {
1997                 err = snd_hda_create_spdif_out_ctls(codec,
1998                                                     spec->multiout.dig_out_nid);
1999                 if (err < 0)
2000                         return err;
2001                 err = snd_hda_create_spdif_share_sw(codec,
2002                                                     &spec->multiout);
2003                 if (err < 0)
2004                         return err;
2005                 spec->multiout.share_spdif = 1;
2006         }
2007         if (spec->dig_in_nid) {
2008                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2009                 if (err < 0)
2010                         return err;
2011         }
2012
2013         /* if we have no master control, let's create it */
2014         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2015                 unsigned int vmaster_tlv[4];
2016                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2017                                         HDA_OUTPUT, vmaster_tlv);
2018                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2019                                           vmaster_tlv, alc_slave_vols);
2020                 if (err < 0)
2021                         return err;
2022         }
2023         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2024                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2025                                           NULL, alc_slave_sws);
2026                 if (err < 0)
2027                         return err;
2028         }
2029
2030         alc_free_kctls(codec); /* no longer needed */
2031         return 0;
2032 }
2033
2034
2035 /*
2036  * initialize the codec volumes, etc
2037  */
2038
2039 /*
2040  * generic initialization of ADC, input mixers and output mixers
2041  */
2042 static struct hda_verb alc880_volume_init_verbs[] = {
2043         /*
2044          * Unmute ADC0-2 and set the default input to mic-in
2045          */
2046         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2047         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2048         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2049         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2050         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2051         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2052
2053         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2054          * mixer widget
2055          * Note: PASD motherboards uses the Line In 2 as the input for front
2056          * panel mic (mic 2)
2057          */
2058         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2059         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2060         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2061         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2062         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2063         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2064         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2065         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2066
2067         /*
2068          * Set up output mixers (0x0c - 0x0f)
2069          */
2070         /* set vol=0 to output mixers */
2071         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2072         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2073         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2074         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2075         /* set up input amps for analog loopback */
2076         /* Amp Indices: DAC = 0, mixer = 1 */
2077         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2078         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2079         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2080         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2081         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2082         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2083         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2084         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2085
2086         { }
2087 };
2088
2089 /*
2090  * 3-stack pin configuration:
2091  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2092  */
2093 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2094         /*
2095          * preset connection lists of input pins
2096          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2097          */
2098         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2099         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2100         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2101
2102         /*
2103          * Set pin mode and muting
2104          */
2105         /* set front pin widgets 0x14 for output */
2106         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2107         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2108         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2109         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2110         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2111         /* Mic2 (as headphone out) for HP output */
2112         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2113         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2114         /* Line In pin widget for input */
2115         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2116         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2117         /* Line2 (as front mic) pin widget for input and vref at 80% */
2118         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2119         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2120         /* CD pin widget for input */
2121         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2122
2123         { }
2124 };
2125
2126 /*
2127  * 5-stack pin configuration:
2128  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2129  * line-in/side = 0x1a, f-mic = 0x1b
2130  */
2131 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2132         /*
2133          * preset connection lists of input pins
2134          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2135          */
2136         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2137         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2138
2139         /*
2140          * Set pin mode and muting
2141          */
2142         /* set pin widgets 0x14-0x17 for output */
2143         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2144         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2145         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2146         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2147         /* unmute pins for output (no gain on this amp) */
2148         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2149         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2150         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2151         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2152
2153         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2154         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2155         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2156         /* Mic2 (as headphone out) for HP output */
2157         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2158         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2159         /* Line In pin widget for input */
2160         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2161         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2162         /* Line2 (as front mic) pin widget for input and vref at 80% */
2163         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2164         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2165         /* CD pin widget for input */
2166         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2167
2168         { }
2169 };
2170
2171 /*
2172  * W810 pin configuration:
2173  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2174  */
2175 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2176         /* hphone/speaker input selector: front DAC */
2177         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2178
2179         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2180         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2181         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2182         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2183         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2184         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2185
2186         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2187         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2188
2189         { }
2190 };
2191
2192 /*
2193  * Z71V pin configuration:
2194  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2195  */
2196 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2197         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2198         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2199         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2200         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2201
2202         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2203         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2204         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2205         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2206
2207         { }
2208 };
2209
2210 /*
2211  * 6-stack pin configuration:
2212  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2213  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2214  */
2215 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2216         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2217
2218         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2219         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2220         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2221         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2222         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2223         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2224         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2225         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2226
2227         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2228         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2229         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2230         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2231         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2232         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2233         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2234         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2235         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2236
2237         { }
2238 };
2239
2240 /*
2241  * Uniwill pin configuration:
2242  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2243  * line = 0x1a
2244  */
2245 static struct hda_verb alc880_uniwill_init_verbs[] = {
2246         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2247
2248         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2249         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2250         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2251         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2252         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2253         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2254         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2255         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2256         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2257         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2258         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2259         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2260         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2261         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2262
2263         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2264         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2265         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2266         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2267         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2268         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2269         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2270         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2271         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2272
2273         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2274         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2275
2276         { }
2277 };
2278
2279 /*
2280 * Uniwill P53
2281 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2282  */
2283 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2284         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2285
2286         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2287         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2288         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2289         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2290         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2291         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2292         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2293         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2294         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2295         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2296         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2297         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2298
2299         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2300         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2301         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2302         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2303         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2304         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2305
2306         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2307         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2308
2309         { }
2310 };
2311
2312 static struct hda_verb alc880_beep_init_verbs[] = {
2313         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2314         { }
2315 };
2316
2317 /* toggle speaker-output according to the hp-jack state */
2318 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
2319 {
2320         unsigned int present;
2321         unsigned char bits;
2322
2323         present = snd_hda_codec_read(codec, 0x14, 0,
2324                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2325         bits = present ? HDA_AMP_MUTE : 0;
2326         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
2327                                  HDA_AMP_MUTE, bits);
2328         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
2329                                  HDA_AMP_MUTE, bits);
2330 }
2331
2332 /* auto-toggle front mic */
2333 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2334 {
2335         unsigned int present;
2336         unsigned char bits;
2337
2338         present = snd_hda_codec_read(codec, 0x18, 0,
2339                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2340         bits = present ? HDA_AMP_MUTE : 0;
2341         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2342 }
2343
2344 static void alc880_uniwill_automute(struct hda_codec *codec)
2345 {
2346         alc880_uniwill_hp_automute(codec);
2347         alc880_uniwill_mic_automute(codec);
2348 }
2349
2350 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2351                                        unsigned int res)
2352 {
2353         /* Looks like the unsol event is incompatible with the standard
2354          * definition.  4bit tag is placed at 28 bit!
2355          */
2356         switch (res >> 28) {
2357         case ALC880_HP_EVENT:
2358                 alc880_uniwill_hp_automute(codec);
2359                 break;
2360         case ALC880_MIC_EVENT:
2361                 alc880_uniwill_mic_automute(codec);
2362                 break;
2363         }
2364 }
2365
2366 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2367 {
2368         unsigned int present;
2369         unsigned char bits;
2370
2371         present = snd_hda_codec_read(codec, 0x14, 0,
2372                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2373         bits = present ? HDA_AMP_MUTE : 0;
2374         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2375 }
2376
2377 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2378 {
2379         unsigned int present;
2380
2381         present = snd_hda_codec_read(codec, 0x21, 0,
2382                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2383         present &= HDA_AMP_VOLMASK;
2384         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2385                                  HDA_AMP_VOLMASK, present);
2386         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2387                                  HDA_AMP_VOLMASK, present);
2388 }
2389
2390 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2391                                            unsigned int res)
2392 {
2393         /* Looks like the unsol event is incompatible with the standard
2394          * definition.  4bit tag is placed at 28 bit!
2395          */
2396         if ((res >> 28) == ALC880_HP_EVENT)
2397                 alc880_uniwill_p53_hp_automute(codec);
2398         if ((res >> 28) == ALC880_DCVOL_EVENT)
2399                 alc880_uniwill_p53_dcvol_automute(codec);
2400 }
2401
2402 /*
2403  * F1734 pin configuration:
2404  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2405  */
2406 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2407         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2408         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2409         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2410         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2411         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2412
2413         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2414         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2415         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2416         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2417
2418         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2419         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2420         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2421         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2422         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2423         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2424         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2425         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2426         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2427
2428         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2429         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2430
2431         { }
2432 };
2433
2434 /*
2435  * ASUS pin configuration:
2436  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2437  */
2438 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2439         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2440         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2441         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2442         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2443
2444         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2445         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2446         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2447         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2448         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2449         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2450         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2451         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2452
2453         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2454         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2455         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2456         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2457         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2458         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2459         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2460         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2461         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2462
2463         { }
2464 };
2465
2466 /* Enable GPIO mask and set output */
2467 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2468 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2469
2470 /* Clevo m520g init */
2471 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2472         /* headphone output */
2473         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2474         /* line-out */
2475         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2476         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2477         /* Line-in */
2478         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2479         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2480         /* CD */
2481         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2482         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2483         /* Mic1 (rear panel) */
2484         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2485         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2486         /* Mic2 (front panel) */
2487         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2488         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2489         /* headphone */
2490         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2491         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2492         /* change to EAPD mode */
2493         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2494         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2495
2496         { }
2497 };
2498
2499 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2500         /* change to EAPD mode */
2501         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2502         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2503
2504         /* Headphone output */
2505         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2506         /* Front output*/
2507         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2508         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2509
2510         /* Line In pin widget for input */
2511         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2512         /* CD pin widget for input */
2513         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2514         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2515         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2516
2517         /* change to EAPD mode */
2518         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2519         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2520
2521         { }
2522 };
2523
2524 /*
2525  * LG m1 express dual
2526  *
2527  * Pin assignment:
2528  *   Rear Line-In/Out (blue): 0x14
2529  *   Build-in Mic-In: 0x15
2530  *   Speaker-out: 0x17
2531  *   HP-Out (green): 0x1b
2532  *   Mic-In/Out (red): 0x19
2533  *   SPDIF-Out: 0x1e
2534  */
2535
2536 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2537 static hda_nid_t alc880_lg_dac_nids[3] = {
2538         0x05, 0x02, 0x03
2539 };
2540
2541 /* seems analog CD is not working */
2542 static struct hda_input_mux alc880_lg_capture_source = {
2543         .num_items = 3,
2544         .items = {
2545                 { "Mic", 0x1 },
2546                 { "Line", 0x5 },
2547                 { "Internal Mic", 0x6 },
2548         },
2549 };
2550
2551 /* 2,4,6 channel modes */
2552 static struct hda_verb alc880_lg_ch2_init[] = {
2553         /* set line-in and mic-in to input */
2554         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2555         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2556         { }
2557 };
2558
2559 static struct hda_verb alc880_lg_ch4_init[] = {
2560         /* set line-in to out and mic-in to input */
2561         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2562         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2563         { }
2564 };
2565
2566 static struct hda_verb alc880_lg_ch6_init[] = {
2567         /* set line-in and mic-in to output */
2568         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2569         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2570         { }
2571 };
2572
2573 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2574         { 2, alc880_lg_ch2_init },
2575         { 4, alc880_lg_ch4_init },
2576         { 6, alc880_lg_ch6_init },
2577 };
2578
2579 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2580         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2581         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2582         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2583         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2584         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2585         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2586         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2587         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2588         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2589         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2590         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2591         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2592         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2593         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2594         {
2595                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2596                 .name = "Channel Mode",
2597                 .info = alc_ch_mode_info,
2598                 .get = alc_ch_mode_get,
2599                 .put = alc_ch_mode_put,
2600         },
2601         { } /* end */
2602 };
2603
2604 static struct hda_verb alc880_lg_init_verbs[] = {
2605         /* set capture source to mic-in */
2606         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2607         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2608         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2609         /* mute all amp mixer inputs */
2610         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2611         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2612         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2613         /* line-in to input */
2614         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2615         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2616         /* built-in mic */
2617         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2618         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2619         /* speaker-out */
2620         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2621         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2622         /* mic-in to input */
2623         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2624         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2625         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2626         /* HP-out */
2627         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2628         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2629         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2630         /* jack sense */
2631         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2632         { }
2633 };
2634
2635 /* toggle speaker-output according to the hp-jack state */
2636 static void alc880_lg_automute(struct hda_codec *codec)
2637 {
2638         unsigned int present;
2639         unsigned char bits;
2640
2641         present = snd_hda_codec_read(codec, 0x1b, 0,
2642                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2643         bits = present ? HDA_AMP_MUTE : 0;
2644         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2645                                  HDA_AMP_MUTE, bits);
2646 }
2647
2648 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2649 {
2650         /* Looks like the unsol event is incompatible with the standard
2651          * definition.  4bit tag is placed at 28 bit!
2652          */
2653         if ((res >> 28) == 0x01)
2654                 alc880_lg_automute(codec);
2655 }
2656
2657 /*
2658  * LG LW20
2659  *
2660  * Pin assignment:
2661  *   Speaker-out: 0x14
2662  *   Mic-In: 0x18
2663  *   Built-in Mic-In: 0x19
2664  *   Line-In: 0x1b
2665  *   HP-Out: 0x1a
2666  *   SPDIF-Out: 0x1e
2667  */
2668
2669 static struct hda_input_mux alc880_lg_lw_capture_source = {
2670         .num_items = 3,
2671         .items = {
2672                 { "Mic", 0x0 },
2673                 { "Internal Mic", 0x1 },
2674                 { "Line In", 0x2 },
2675         },
2676 };
2677
2678 #define alc880_lg_lw_modes alc880_threestack_modes
2679
2680 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2681         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2682         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2683         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2684         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2685         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2686         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2687         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2688         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2689         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2690         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2691         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2692         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2693         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2694         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2695         {
2696                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2697                 .name = "Channel Mode",
2698                 .info = alc_ch_mode_info,
2699                 .get = alc_ch_mode_get,
2700                 .put = alc_ch_mode_put,
2701         },
2702         { } /* end */
2703 };
2704
2705 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2706         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2707         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2708         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2709
2710         /* set capture source to mic-in */
2711         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2712         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2713         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2714         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2715         /* speaker-out */
2716         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2717         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2718         /* HP-out */
2719         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2720         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2721         /* mic-in to input */
2722         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2723         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2724         /* built-in mic */
2725         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2726         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2727         /* jack sense */
2728         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2729         { }
2730 };
2731
2732 /* toggle speaker-output according to the hp-jack state */
2733 static void alc880_lg_lw_automute(struct hda_codec *codec)
2734 {
2735         unsigned int present;
2736         unsigned char bits;
2737
2738         present = snd_hda_codec_read(codec, 0x1b, 0,
2739                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2740         bits = present ? HDA_AMP_MUTE : 0;
2741         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2742                                  HDA_AMP_MUTE, bits);
2743 }
2744
2745 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2746 {
2747         /* Looks like the unsol event is incompatible with the standard
2748          * definition.  4bit tag is placed at 28 bit!
2749          */
2750         if ((res >> 28) == 0x01)
2751                 alc880_lg_lw_automute(codec);
2752 }
2753
2754 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2755         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2756         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2757         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2758         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2759         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2760         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2761         { } /* end */
2762 };
2763
2764 static struct hda_input_mux alc880_medion_rim_capture_source = {
2765         .num_items = 2,
2766         .items = {
2767                 { "Mic", 0x0 },
2768                 { "Internal Mic", 0x1 },
2769         },
2770 };
2771
2772 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2773         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2774
2775         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2776         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2777
2778         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2779         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2780         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2781         /* Mic2 (as headphone out) for HP output */
2782         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2783         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2784         /* Internal Speaker */
2785         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2786         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2787
2788         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2789         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2790
2791         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2792         { }
2793 };
2794
2795 /* toggle speaker-output according to the hp-jack state */
2796 static void alc880_medion_rim_automute(struct hda_codec *codec)
2797 {
2798         unsigned int present;
2799         unsigned char bits;
2800
2801         present = snd_hda_codec_read(codec, 0x14, 0,
2802                                      AC_VERB_GET_PIN_SENSE, 0)
2803                 & AC_PINSENSE_PRESENCE;
2804         bits = present ? HDA_AMP_MUTE : 0;
2805         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2806                                  HDA_AMP_MUTE, bits);
2807         if (present)
2808                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2809         else
2810                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2811 }
2812
2813 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2814                                           unsigned int res)
2815 {
2816         /* Looks like the unsol event is incompatible with the standard
2817          * definition.  4bit tag is placed at 28 bit!
2818          */
2819         if ((res >> 28) == ALC880_HP_EVENT)
2820                 alc880_medion_rim_automute(codec);
2821 }
2822
2823 #ifdef CONFIG_SND_HDA_POWER_SAVE
2824 static struct hda_amp_list alc880_loopbacks[] = {
2825         { 0x0b, HDA_INPUT, 0 },
2826         { 0x0b, HDA_INPUT, 1 },
2827         { 0x0b, HDA_INPUT, 2 },
2828         { 0x0b, HDA_INPUT, 3 },
2829         { 0x0b, HDA_INPUT, 4 },
2830         { } /* end */
2831 };
2832
2833 static struct hda_amp_list alc880_lg_loopbacks[] = {
2834         { 0x0b, HDA_INPUT, 1 },
2835         { 0x0b, HDA_INPUT, 6 },
2836         { 0x0b, HDA_INPUT, 7 },
2837         { } /* end */
2838 };
2839 #endif
2840
2841 /*
2842  * Common callbacks
2843  */
2844
2845 static int alc_init(struct hda_codec *codec)
2846 {
2847         struct alc_spec *spec = codec->spec;
2848         unsigned int i;
2849
2850         alc_fix_pll(codec);
2851         if (codec->vendor_id == 0x10ec0888)
2852                 alc888_coef_init(codec);
2853
2854         for (i = 0; i < spec->num_init_verbs; i++)
2855                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2856
2857         if (spec->init_hook)
2858                 spec->init_hook(codec);
2859
2860         return 0;
2861 }
2862
2863 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2864 {
2865         struct alc_spec *spec = codec->spec;
2866
2867         if (spec->unsol_event)
2868                 spec->unsol_event(codec, res);
2869 }
2870
2871 #ifdef CONFIG_SND_HDA_POWER_SAVE
2872 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2873 {
2874         struct alc_spec *spec = codec->spec;
2875         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2876 }
2877 #endif
2878
2879 /*
2880  * Analog playback callbacks
2881  */
2882 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2883                                     struct hda_codec *codec,
2884                                     struct snd_pcm_substream *substream)
2885 {
2886         struct alc_spec *spec = codec->spec;
2887         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2888                                              hinfo);
2889 }
2890
2891 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2892                                        struct hda_codec *codec,
2893                                        unsigned int stream_tag,
2894                                        unsigned int format,
2895                                        struct snd_pcm_substream *substream)
2896 {
2897         struct alc_spec *spec = codec->spec;
2898         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2899                                                 stream_tag, format, substream);
2900 }
2901
2902 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2903                                        struct hda_codec *codec,
2904                                        struct snd_pcm_substream *substream)
2905 {
2906         struct alc_spec *spec = codec->spec;
2907         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2908 }
2909
2910 /*
2911  * Digital out
2912  */
2913 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2914                                         struct hda_codec *codec,
2915                                         struct snd_pcm_substream *substream)
2916 {
2917         struct alc_spec *spec = codec->spec;
2918         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2919 }
2920
2921 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2922                                            struct hda_codec *codec,
2923                                            unsigned int stream_tag,
2924                                            unsigned int format,
2925                                            struct snd_pcm_substream *substream)
2926 {
2927         struct alc_spec *spec = codec->spec;
2928         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2929                                              stream_tag, format, substream);
2930 }
2931
2932 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2933                                          struct hda_codec *codec,
2934                                          struct snd_pcm_substream *substream)
2935 {
2936         struct alc_spec *spec = codec->spec;
2937         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2938 }
2939
2940 /*
2941  * Analog capture
2942  */
2943 static int alc880_alt_capture_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
2951         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2952                                    stream_tag, 0, format);
2953         return 0;
2954 }
2955
2956 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2957                                       struct hda_codec *codec,
2958                                       struct snd_pcm_substream *substream)
2959 {
2960         struct alc_spec *spec = codec->spec;
2961
2962         snd_hda_codec_cleanup_stream(codec,
2963                                      spec->adc_nids[substream->number + 1]);
2964         return 0;
2965 }
2966
2967
2968 /*
2969  */
2970 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2971         .substreams = 1,
2972         .channels_min = 2,
2973         .channels_max = 8,
2974         /* NID is set in alc_build_pcms */
2975         .ops = {
2976                 .open = alc880_playback_pcm_open,
2977                 .prepare = alc880_playback_pcm_prepare,
2978                 .cleanup = alc880_playback_pcm_cleanup
2979         },
2980 };
2981
2982 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2983         .substreams = 1,
2984         .channels_min = 2,
2985         .channels_max = 2,
2986         /* NID is set in alc_build_pcms */
2987 };
2988
2989 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
2990         .substreams = 1,
2991         .channels_min = 2,
2992         .channels_max = 2,
2993         /* NID is set in alc_build_pcms */
2994 };
2995
2996 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2997         .substreams = 2, /* can be overridden */
2998         .channels_min = 2,
2999         .channels_max = 2,
3000         /* NID is set in alc_build_pcms */
3001         .ops = {
3002                 .prepare = alc880_alt_capture_pcm_prepare,
3003                 .cleanup = alc880_alt_capture_pcm_cleanup
3004         },
3005 };
3006
3007 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3008         .substreams = 1,
3009         .channels_min = 2,
3010         .channels_max = 2,
3011         /* NID is set in alc_build_pcms */
3012         .ops = {
3013                 .open = alc880_dig_playback_pcm_open,
3014                 .close = alc880_dig_playback_pcm_close,
3015                 .prepare = alc880_dig_playback_pcm_prepare
3016         },
3017 };
3018
3019 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3020         .substreams = 1,
3021         .channels_min = 2,
3022         .channels_max = 2,
3023         /* NID is set in alc_build_pcms */
3024 };
3025
3026 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3027 static struct hda_pcm_stream alc_pcm_null_stream = {
3028         .substreams = 0,
3029         .channels_min = 0,
3030         .channels_max = 0,
3031 };
3032
3033 static int alc_build_pcms(struct hda_codec *codec)
3034 {
3035         struct alc_spec *spec = codec->spec;
3036         struct hda_pcm *info = spec->pcm_rec;
3037         int i;
3038
3039         codec->num_pcms = 1;
3040         codec->pcm_info = info;
3041
3042         info->name = spec->stream_name_analog;
3043         if (spec->stream_analog_playback) {
3044                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3045                         return -EINVAL;
3046                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3047                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3048         }
3049         if (spec->stream_analog_capture) {
3050                 if (snd_BUG_ON(!spec->adc_nids))
3051                         return -EINVAL;
3052                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3053                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3054         }
3055
3056         if (spec->channel_mode) {
3057                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3058                 for (i = 0; i < spec->num_channel_mode; i++) {
3059                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3060                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3061                         }
3062                 }
3063         }
3064
3065         /* SPDIF for stream index #1 */
3066         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3067                 codec->num_pcms = 2;
3068                 info = spec->pcm_rec + 1;
3069                 info->name = spec->stream_name_digital;
3070                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
3071                 if (spec->multiout.dig_out_nid &&
3072                     spec->stream_digital_playback) {
3073                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3074                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3075                 }
3076                 if (spec->dig_in_nid &&
3077                     spec->stream_digital_capture) {
3078                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3079                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3080                 }
3081                 /* FIXME: do we need this for all Realtek codec models? */
3082                 codec->spdif_status_reset = 1;
3083         }
3084
3085         /* If the use of more than one ADC is requested for the current
3086          * model, configure a second analog capture-only PCM.
3087          */
3088         /* Additional Analaog capture for index #2 */
3089         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3090             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3091                 codec->num_pcms = 3;
3092                 info = spec->pcm_rec + 2;
3093                 info->name = spec->stream_name_analog;
3094                 if (spec->alt_dac_nid) {
3095                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3096                                 *spec->stream_analog_alt_playback;
3097                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3098                                 spec->alt_dac_nid;
3099                 } else {
3100                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3101                                 alc_pcm_null_stream;
3102                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3103                 }
3104                 if (spec->num_adc_nids > 1) {
3105                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3106                                 *spec->stream_analog_alt_capture;
3107                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3108                                 spec->adc_nids[1];
3109                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3110                                 spec->num_adc_nids - 1;
3111                 } else {
3112                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3113                                 alc_pcm_null_stream;
3114                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3115                 }
3116         }
3117
3118         return 0;
3119 }
3120
3121 static void alc_free_kctls(struct hda_codec *codec)
3122 {
3123         struct alc_spec *spec = codec->spec;
3124
3125         if (spec->kctls.list) {
3126                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3127                 int i;
3128                 for (i = 0; i < spec->kctls.used; i++)
3129                         kfree(kctl[i].name);
3130         }
3131         snd_array_free(&spec->kctls);
3132 }
3133
3134 static void alc_free(struct hda_codec *codec)
3135 {
3136         struct alc_spec *spec = codec->spec;
3137
3138         if (!spec)
3139                 return;
3140
3141         alc_free_kctls(codec);
3142         kfree(spec);
3143         codec->spec = NULL; /* to be sure */
3144 }
3145
3146 #ifdef SND_HDA_NEEDS_RESUME
3147 static void store_pin_configs(struct hda_codec *codec)
3148 {
3149         struct alc_spec *spec = codec->spec;
3150         hda_nid_t nid, end_nid;
3151
3152         end_nid = codec->start_nid + codec->num_nodes;
3153         for (nid = codec->start_nid; nid < end_nid; nid++) {
3154                 unsigned int wid_caps = get_wcaps(codec, nid);
3155                 unsigned int wid_type =
3156                         (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3157                 if (wid_type != AC_WID_PIN)
3158                         continue;
3159                 if (spec->num_pins >= ARRAY_SIZE(spec->pin_nids))
3160                         break;
3161                 spec->pin_nids[spec->num_pins] = nid;
3162                 spec->pin_cfgs[spec->num_pins] =
3163                         snd_hda_codec_read(codec, nid, 0,
3164                                            AC_VERB_GET_CONFIG_DEFAULT, 0);
3165                 spec->num_pins++;
3166         }
3167 }
3168
3169 static void resume_pin_configs(struct hda_codec *codec)
3170 {
3171         struct alc_spec *spec = codec->spec;
3172         int i;
3173
3174         for (i = 0; i < spec->num_pins; i++) {
3175                 hda_nid_t pin_nid = spec->pin_nids[i];
3176                 unsigned int pin_config = spec->pin_cfgs[i];
3177                 snd_hda_codec_write(codec, pin_nid, 0,
3178                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
3179                                     pin_config & 0x000000ff);
3180                 snd_hda_codec_write(codec, pin_nid, 0,
3181                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
3182                                     (pin_config & 0x0000ff00) >> 8);
3183                 snd_hda_codec_write(codec, pin_nid, 0,
3184                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
3185                                     (pin_config & 0x00ff0000) >> 16);
3186                 snd_hda_codec_write(codec, pin_nid, 0,
3187                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
3188                                     pin_config >> 24);
3189         }
3190 }
3191
3192 static int alc_resume(struct hda_codec *codec)
3193 {
3194         resume_pin_configs(codec);
3195         codec->patch_ops.init(codec);
3196         snd_hda_codec_resume_amp(codec);
3197         snd_hda_codec_resume_cache(codec);
3198         return 0;
3199 }
3200 #else
3201 #define store_pin_configs(codec)
3202 #endif
3203
3204 /*
3205  */
3206 static struct hda_codec_ops alc_patch_ops = {
3207         .build_controls = alc_build_controls,
3208         .build_pcms = alc_build_pcms,
3209         .init = alc_init,
3210         .free = alc_free,
3211         .unsol_event = alc_unsol_event,
3212 #ifdef SND_HDA_NEEDS_RESUME
3213         .resume = alc_resume,
3214 #endif
3215 #ifdef CONFIG_SND_HDA_POWER_SAVE
3216         .check_power_status = alc_check_power_status,
3217 #endif
3218 };
3219
3220
3221 /*
3222  * Test configuration for debugging
3223  *
3224  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3225  * enum controls.
3226  */
3227 #ifdef CONFIG_SND_DEBUG
3228 static hda_nid_t alc880_test_dac_nids[4] = {
3229         0x02, 0x03, 0x04, 0x05
3230 };
3231
3232 static struct hda_input_mux alc880_test_capture_source = {
3233         .num_items = 7,
3234         .items = {
3235                 { "In-1", 0x0 },
3236                 { "In-2", 0x1 },
3237                 { "In-3", 0x2 },
3238                 { "In-4", 0x3 },
3239                 { "CD", 0x4 },
3240                 { "Front", 0x5 },
3241                 { "Surround", 0x6 },
3242         },
3243 };
3244
3245 static struct hda_channel_mode alc880_test_modes[4] = {
3246         { 2, NULL },
3247         { 4, NULL },
3248         { 6, NULL },
3249         { 8, NULL },
3250 };
3251
3252 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3253                                  struct snd_ctl_elem_info *uinfo)
3254 {
3255         static char *texts[] = {
3256                 "N/A", "Line Out", "HP Out",
3257                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3258         };
3259         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3260         uinfo->count = 1;
3261         uinfo->value.enumerated.items = 8;
3262         if (uinfo->value.enumerated.item >= 8)
3263                 uinfo->value.enumerated.item = 7;
3264         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3265         return 0;
3266 }
3267
3268 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3269                                 struct snd_ctl_elem_value *ucontrol)
3270 {
3271         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3272         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3273         unsigned int pin_ctl, item = 0;
3274
3275         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3276                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3277         if (pin_ctl & AC_PINCTL_OUT_EN) {
3278                 if (pin_ctl & AC_PINCTL_HP_EN)
3279                         item = 2;
3280                 else
3281                         item = 1;
3282         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3283                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3284                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3285                 case AC_PINCTL_VREF_50:  item = 4; break;
3286                 case AC_PINCTL_VREF_GRD: item = 5; break;
3287                 case AC_PINCTL_VREF_80:  item = 6; break;
3288                 case AC_PINCTL_VREF_100: item = 7; break;
3289                 }
3290         }
3291         ucontrol->value.enumerated.item[0] = item;
3292         return 0;
3293 }
3294
3295 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3296                                 struct snd_ctl_elem_value *ucontrol)
3297 {
3298         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3299         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3300         static unsigned int ctls[] = {
3301                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3302                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3303                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3304                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3305                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3306                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3307         };
3308         unsigned int old_ctl, new_ctl;
3309
3310         old_ctl = snd_hda_codec_read(codec, nid, 0,
3311                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3312         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3313         if (old_ctl != new_ctl) {
3314                 int val;
3315                 snd_hda_codec_write_cache(codec, nid, 0,
3316                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3317                                           new_ctl);
3318                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3319                         HDA_AMP_MUTE : 0;
3320                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3321                                          HDA_AMP_MUTE, val);
3322                 return 1;
3323         }
3324         return 0;
3325 }
3326
3327 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3328                                  struct snd_ctl_elem_info *uinfo)
3329 {
3330         static char *texts[] = {
3331                 "Front", "Surround", "CLFE", "Side"
3332         };
3333         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3334         uinfo->count = 1;
3335         uinfo->value.enumerated.items = 4;
3336         if (uinfo->value.enumerated.item >= 4)
3337                 uinfo->value.enumerated.item = 3;
3338         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3339         return 0;
3340 }
3341
3342 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3343                                 struct snd_ctl_elem_value *ucontrol)
3344 {
3345         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3346         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3347         unsigned int sel;
3348
3349         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3350         ucontrol->value.enumerated.item[0] = sel & 3;
3351         return 0;
3352 }
3353
3354 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3355                                 struct snd_ctl_elem_value *ucontrol)
3356 {
3357         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3358         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3359         unsigned int sel;
3360
3361         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3362         if (ucontrol->value.enumerated.item[0] != sel) {
3363                 sel = ucontrol->value.enumerated.item[0] & 3;
3364                 snd_hda_codec_write_cache(codec, nid, 0,
3365                                           AC_VERB_SET_CONNECT_SEL, sel);
3366                 return 1;
3367         }
3368         return 0;
3369 }
3370
3371 #define PIN_CTL_TEST(xname,nid) {                       \
3372                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3373                         .name = xname,                 \
3374                         .info = alc_test_pin_ctl_info, \
3375                         .get = alc_test_pin_ctl_get,   \
3376                         .put = alc_test_pin_ctl_put,   \
3377                         .private_value = nid           \
3378                         }
3379
3380 #define PIN_SRC_TEST(xname,nid) {                       \
3381                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3382                         .name = xname,                 \
3383                         .info = alc_test_pin_src_info, \
3384                         .get = alc_test_pin_src_get,   \
3385                         .put = alc_test_pin_src_put,   \
3386                         .private_value = nid           \
3387                         }
3388
3389 static struct snd_kcontrol_new alc880_test_mixer[] = {
3390         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3391         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3392         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3393         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3394         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3395         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3396         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3397         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3398         PIN_CTL_TEST("Front Pin Mode", 0x14),
3399         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3400         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3401         PIN_CTL_TEST("Side Pin Mode", 0x17),
3402         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3403         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3404         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3405         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3406         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3407         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3408         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3409         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3410         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3411         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3412         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3413         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3414         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3415         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3416         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3417         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3418         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3419         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3420         {
3421                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3422                 .name = "Channel Mode",
3423                 .info = alc_ch_mode_info,
3424                 .get = alc_ch_mode_get,
3425                 .put = alc_ch_mode_put,
3426         },
3427         { } /* end */
3428 };
3429
3430 static struct hda_verb alc880_test_init_verbs[] = {
3431         /* Unmute inputs of 0x0c - 0x0f */
3432         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3433         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3434         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3435         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3436         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3437         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3438         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3439         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3440         /* Vol output for 0x0c-0x0f */
3441         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3442         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3443         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3444         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3445         /* Set output pins 0x14-0x17 */
3446         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3447         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3448         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3449         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3450         /* Unmute output pins 0x14-0x17 */
3451         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3452         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3453         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3454         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3455         /* Set input pins 0x18-0x1c */
3456         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3457         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3458         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3459         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3460         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3461         /* Mute input pins 0x18-0x1b */
3462         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3463         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3464         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3465         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3466         /* ADC set up */
3467         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3468         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3469         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3470         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3471         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3472         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3473         /* Analog input/passthru */
3474         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3475         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3476         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3477         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3478         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3479         { }
3480 };
3481 #endif
3482
3483 /*
3484  */
3485
3486 static const char *alc880_models[ALC880_MODEL_LAST] = {
3487         [ALC880_3ST]            = "3stack",
3488         [ALC880_TCL_S700]       = "tcl",
3489         [ALC880_3ST_DIG]        = "3stack-digout",
3490         [ALC880_CLEVO]          = "clevo",
3491         [ALC880_5ST]            = "5stack",
3492         [ALC880_5ST_DIG]        = "5stack-digout",
3493         [ALC880_W810]           = "w810",
3494         [ALC880_Z71V]           = "z71v",
3495         [ALC880_6ST]            = "6stack",
3496         [ALC880_6ST_DIG]        = "6stack-digout",
3497         [ALC880_ASUS]           = "asus",
3498         [ALC880_ASUS_W1V]       = "asus-w1v",
3499         [ALC880_ASUS_DIG]       = "asus-dig",
3500         [ALC880_ASUS_DIG2]      = "asus-dig2",
3501         [ALC880_UNIWILL_DIG]    = "uniwill",
3502         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3503         [ALC880_FUJITSU]        = "fujitsu",
3504         [ALC880_F1734]          = "F1734",
3505         [ALC880_LG]             = "lg",
3506         [ALC880_LG_LW]          = "lg-lw",
3507         [ALC880_MEDION_RIM]     = "medion",
3508 #ifdef CONFIG_SND_DEBUG
3509         [ALC880_TEST]           = "test",
3510 #endif
3511         [ALC880_AUTO]           = "auto",
3512 };
3513
3514 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3515         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3516         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3517         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3518         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3519         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3520         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3521         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3522         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3523         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3524         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3525         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3526         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3527         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3528         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3529         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3530         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3531         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3532         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3533         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3534         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3535         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3536         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3537         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3538         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3539         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3540         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3541         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3542         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3543         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3544         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3545         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3546         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3547         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3548         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3549         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3550         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3551         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3552         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3553         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3554         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3555         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3556         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3557         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3558         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3559         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3560         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3561         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3562         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3563         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3564         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3565         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3566         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3567         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3568         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3569         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3570         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3571         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3572         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3573         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3574         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3575         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3576         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3577         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3578         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3579         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3580         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3581         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3582         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3583         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3584         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3585         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3586         {}
3587 };
3588
3589 /*
3590  * ALC880 codec presets
3591  */
3592 static struct alc_config_preset alc880_presets[] = {
3593         [ALC880_3ST] = {
3594                 .mixers = { alc880_three_stack_mixer },
3595                 .init_verbs = { alc880_volume_init_verbs,
3596                                 alc880_pin_3stack_init_verbs },
3597                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3598                 .dac_nids = alc880_dac_nids,
3599                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3600                 .channel_mode = alc880_threestack_modes,
3601                 .need_dac_fix = 1,
3602                 .input_mux = &alc880_capture_source,
3603         },
3604         [ALC880_3ST_DIG] = {
3605                 .mixers = { alc880_three_stack_mixer },
3606                 .init_verbs = { alc880_volume_init_verbs,
3607                                 alc880_pin_3stack_init_verbs },
3608                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3609                 .dac_nids = alc880_dac_nids,
3610                 .dig_out_nid = ALC880_DIGOUT_NID,
3611                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3612                 .channel_mode = alc880_threestack_modes,
3613                 .need_dac_fix = 1,
3614                 .input_mux = &alc880_capture_source,
3615         },
3616         [ALC880_TCL_S700] = {
3617                 .mixers = { alc880_tcl_s700_mixer },
3618                 .init_verbs = { alc880_volume_init_verbs,
3619                                 alc880_pin_tcl_S700_init_verbs,
3620                                 alc880_gpio2_init_verbs },
3621                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3622                 .dac_nids = alc880_dac_nids,
3623                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3624                 .num_adc_nids = 1, /* single ADC */
3625                 .hp_nid = 0x03,
3626                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3627                 .channel_mode = alc880_2_jack_modes,
3628                 .input_mux = &alc880_capture_source,
3629         },
3630         [ALC880_5ST] = {
3631                 .mixers = { alc880_three_stack_mixer,
3632                             alc880_five_stack_mixer},
3633                 .init_verbs = { alc880_volume_init_verbs,
3634                                 alc880_pin_5stack_init_verbs },
3635                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3636                 .dac_nids = alc880_dac_nids,
3637                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3638                 .channel_mode = alc880_fivestack_modes,
3639                 .input_mux = &alc880_capture_source,
3640         },
3641         [ALC880_5ST_DIG] = {
3642                 .mixers = { alc880_three_stack_mixer,
3643                             alc880_five_stack_mixer },
3644                 .init_verbs = { alc880_volume_init_verbs,
3645                                 alc880_pin_5stack_init_verbs },
3646                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3647                 .dac_nids = alc880_dac_nids,
3648                 .dig_out_nid = ALC880_DIGOUT_NID,
3649                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3650                 .channel_mode = alc880_fivestack_modes,
3651                 .input_mux = &alc880_capture_source,
3652         },
3653         [ALC880_6ST] = {
3654                 .mixers = { alc880_six_stack_mixer },
3655                 .init_verbs = { alc880_volume_init_verbs,
3656                                 alc880_pin_6stack_init_verbs },
3657                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3658                 .dac_nids = alc880_6st_dac_nids,
3659                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3660                 .channel_mode = alc880_sixstack_modes,
3661                 .input_mux = &alc880_6stack_capture_source,
3662         },
3663         [ALC880_6ST_DIG] = {
3664                 .mixers = { alc880_six_stack_mixer },
3665                 .init_verbs = { alc880_volume_init_verbs,
3666                                 alc880_pin_6stack_init_verbs },
3667                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3668                 .dac_nids = alc880_6st_dac_nids,
3669                 .dig_out_nid = ALC880_DIGOUT_NID,
3670                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3671                 .channel_mode = alc880_sixstack_modes,
3672                 .input_mux = &alc880_6stack_capture_source,
3673         },
3674         [ALC880_W810] = {
3675                 .mixers = { alc880_w810_base_mixer },
3676                 .init_verbs = { alc880_volume_init_verbs,
3677                                 alc880_pin_w810_init_verbs,
3678                                 alc880_gpio2_init_verbs },
3679                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3680                 .dac_nids = alc880_w810_dac_nids,
3681                 .dig_out_nid = ALC880_DIGOUT_NID,
3682                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3683                 .channel_mode = alc880_w810_modes,
3684                 .input_mux = &alc880_capture_source,
3685         },
3686         [ALC880_Z71V] = {
3687                 .mixers = { alc880_z71v_mixer },
3688                 .init_verbs = { alc880_volume_init_verbs,
3689                                 alc880_pin_z71v_init_verbs },
3690                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3691                 .dac_nids = alc880_z71v_dac_nids,
3692                 .dig_out_nid = ALC880_DIGOUT_NID,
3693                 .hp_nid = 0x03,
3694                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3695                 .channel_mode = alc880_2_jack_modes,
3696                 .input_mux = &alc880_capture_source,
3697         },
3698         [ALC880_F1734] = {
3699                 .mixers = { alc880_f1734_mixer },
3700                 .init_verbs = { alc880_volume_init_verbs,
3701                                 alc880_pin_f1734_init_verbs },
3702                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3703                 .dac_nids = alc880_f1734_dac_nids,
3704                 .hp_nid = 0x02,
3705                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3706                 .channel_mode = alc880_2_jack_modes,
3707                 .input_mux = &alc880_f1734_capture_source,
3708                 .unsol_event = alc880_uniwill_p53_unsol_event,
3709                 .init_hook = alc880_uniwill_p53_hp_automute,
3710         },
3711         [ALC880_ASUS] = {
3712                 .mixers = { alc880_asus_mixer },
3713                 .init_verbs = { alc880_volume_init_verbs,
3714                                 alc880_pin_asus_init_verbs,
3715                                 alc880_gpio1_init_verbs },
3716                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3717                 .dac_nids = alc880_asus_dac_nids,
3718                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3719                 .channel_mode = alc880_asus_modes,
3720                 .need_dac_fix = 1,
3721                 .input_mux = &alc880_capture_source,
3722         },
3723         [ALC880_ASUS_DIG] = {
3724                 .mixers = { alc880_asus_mixer },
3725                 .init_verbs = { alc880_volume_init_verbs,
3726                                 alc880_pin_asus_init_verbs,
3727                                 alc880_gpio1_init_verbs },
3728                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3729                 .dac_nids = alc880_asus_dac_nids,
3730                 .dig_out_nid = ALC880_DIGOUT_NID,
3731                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3732                 .channel_mode = alc880_asus_modes,
3733                 .need_dac_fix = 1,
3734                 .input_mux = &alc880_capture_source,
3735         },
3736         [ALC880_ASUS_DIG2] = {
3737                 .mixers = { alc880_asus_mixer },
3738                 .init_verbs = { alc880_volume_init_verbs,
3739                                 alc880_pin_asus_init_verbs,
3740                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3741                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3742                 .dac_nids = alc880_asus_dac_nids,
3743                 .dig_out_nid = ALC880_DIGOUT_NID,
3744                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3745                 .channel_mode = alc880_asus_modes,
3746                 .need_dac_fix = 1,
3747                 .input_mux = &alc880_capture_source,
3748         },
3749         [ALC880_ASUS_W1V] = {
3750                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3751                 .init_verbs = { alc880_volume_init_verbs,
3752                                 alc880_pin_asus_init_verbs,
3753                                 alc880_gpio1_init_verbs },
3754                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3755                 .dac_nids = alc880_asus_dac_nids,
3756                 .dig_out_nid = ALC880_DIGOUT_NID,
3757                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3758                 .channel_mode = alc880_asus_modes,
3759                 .need_dac_fix = 1,
3760                 .input_mux = &alc880_capture_source,
3761         },
3762         [ALC880_UNIWILL_DIG] = {
3763                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3764                 .init_verbs = { alc880_volume_init_verbs,
3765                                 alc880_pin_asus_init_verbs },
3766                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3767                 .dac_nids = alc880_asus_dac_nids,
3768                 .dig_out_nid = ALC880_DIGOUT_NID,
3769                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3770                 .channel_mode = alc880_asus_modes,
3771                 .need_dac_fix = 1,
3772                 .input_mux = &alc880_capture_source,
3773         },
3774         [ALC880_UNIWILL] = {
3775                 .mixers = { alc880_uniwill_mixer },
3776                 .init_verbs = { alc880_volume_init_verbs,
3777                                 alc880_uniwill_init_verbs },
3778                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3779                 .dac_nids = alc880_asus_dac_nids,
3780                 .dig_out_nid = ALC880_DIGOUT_NID,
3781                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3782                 .channel_mode = alc880_threestack_modes,
3783                 .need_dac_fix = 1,
3784                 .input_mux = &alc880_capture_source,
3785                 .unsol_event = alc880_uniwill_unsol_event,
3786                 .init_hook = alc880_uniwill_automute,
3787         },
3788         [ALC880_UNIWILL_P53] = {
3789                 .mixers = { alc880_uniwill_p53_mixer },
3790                 .init_verbs = { alc880_volume_init_verbs,
3791                                 alc880_uniwill_p53_init_verbs },
3792                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3793                 .dac_nids = alc880_asus_dac_nids,
3794                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3795                 .channel_mode = alc880_threestack_modes,
3796                 .input_mux = &alc880_capture_source,
3797                 .unsol_event = alc880_uniwill_p53_unsol_event,
3798                 .init_hook = alc880_uniwill_p53_hp_automute,
3799         },
3800         [ALC880_FUJITSU] = {
3801                 .mixers = { alc880_fujitsu_mixer,
3802                             alc880_pcbeep_mixer, },
3803                 .init_verbs = { alc880_volume_init_verbs,
3804                                 alc880_uniwill_p53_init_verbs,
3805                                 alc880_beep_init_verbs },
3806                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3807                 .dac_nids = alc880_dac_nids,
3808                 .dig_out_nid = ALC880_DIGOUT_NID,
3809                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3810                 .channel_mode = alc880_2_jack_modes,
3811                 .input_mux = &alc880_capture_source,
3812                 .unsol_event = alc880_uniwill_p53_unsol_event,
3813                 .init_hook = alc880_uniwill_p53_hp_automute,
3814         },
3815         [ALC880_CLEVO] = {
3816                 .mixers = { alc880_three_stack_mixer },
3817                 .init_verbs = { alc880_volume_init_verbs,
3818                                 alc880_pin_clevo_init_verbs },
3819                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3820                 .dac_nids = alc880_dac_nids,
3821                 .hp_nid = 0x03,
3822                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3823                 .channel_mode = alc880_threestack_modes,
3824                 .need_dac_fix = 1,
3825                 .input_mux = &alc880_capture_source,
3826         },
3827         [ALC880_LG] = {
3828                 .mixers = { alc880_lg_mixer },
3829                 .init_verbs = { alc880_volume_init_verbs,
3830                                 alc880_lg_init_verbs },
3831                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3832                 .dac_nids = alc880_lg_dac_nids,
3833                 .dig_out_nid = ALC880_DIGOUT_NID,
3834                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3835                 .channel_mode = alc880_lg_ch_modes,
3836                 .need_dac_fix = 1,
3837                 .input_mux = &alc880_lg_capture_source,
3838                 .unsol_event = alc880_lg_unsol_event,
3839                 .init_hook = alc880_lg_automute,
3840 #ifdef CONFIG_SND_HDA_POWER_SAVE
3841                 .loopbacks = alc880_lg_loopbacks,
3842 #endif
3843         },
3844         [ALC880_LG_LW] = {
3845                 .mixers = { alc880_lg_lw_mixer },
3846                 .init_verbs = { alc880_volume_init_verbs,
3847                                 alc880_lg_lw_init_verbs },
3848                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3849                 .dac_nids = alc880_dac_nids,
3850                 .dig_out_nid = ALC880_DIGOUT_NID,
3851                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3852                 .channel_mode = alc880_lg_lw_modes,
3853                 .input_mux = &alc880_lg_lw_capture_source,
3854                 .unsol_event = alc880_lg_lw_unsol_event,
3855                 .init_hook = alc880_lg_lw_automute,
3856         },
3857         [ALC880_MEDION_RIM] = {
3858                 .mixers = { alc880_medion_rim_mixer },
3859                 .init_verbs = { alc880_volume_init_verbs,
3860                                 alc880_medion_rim_init_verbs,
3861                                 alc_gpio2_init_verbs },
3862                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3863                 .dac_nids = alc880_dac_nids,
3864                 .dig_out_nid = ALC880_DIGOUT_NID,
3865                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3866                 .channel_mode = alc880_2_jack_modes,
3867                 .input_mux = &alc880_medion_rim_capture_source,
3868                 .unsol_event = alc880_medion_rim_unsol_event,
3869                 .init_hook = alc880_medion_rim_automute,
3870         },
3871 #ifdef CONFIG_SND_DEBUG
3872         [ALC880_TEST] = {
3873                 .mixers = { alc880_test_mixer },
3874                 .init_verbs = { alc880_test_init_verbs },
3875                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3876                 .dac_nids = alc880_test_dac_nids,
3877                 .dig_out_nid = ALC880_DIGOUT_NID,
3878                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3879                 .channel_mode = alc880_test_modes,
3880                 .input_mux = &alc880_test_capture_source,
3881         },
3882 #endif
3883 };
3884
3885 /*
3886  * Automatic parse of I/O pins from the BIOS configuration
3887  */
3888
3889 enum {
3890         ALC_CTL_WIDGET_VOL,
3891         ALC_CTL_WIDGET_MUTE,
3892         ALC_CTL_BIND_MUTE,
3893 };
3894 static struct snd_kcontrol_new alc880_control_templates[] = {
3895         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3896         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3897         HDA_BIND_MUTE(NULL, 0, 0, 0),
3898 };
3899
3900 /* add dynamic controls */
3901 static int add_control(struct alc_spec *spec, int type, const char *name,
3902                        unsigned long val)
3903 {
3904         struct snd_kcontrol_new *knew;
3905
3906         snd_array_init(&spec->kctls, sizeof(*knew), 32);
3907         knew = snd_array_new(&spec->kctls);
3908         if (!knew)
3909                 return -ENOMEM;
3910         *knew = alc880_control_templates[type];
3911         knew->name = kstrdup(name, GFP_KERNEL);
3912         if (!knew->name)
3913                 return -ENOMEM;
3914         knew->private_value = val;
3915         return 0;
3916 }
3917
3918 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3919 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3920 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3921 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3922 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3923 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3924 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3925 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3926 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3927 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3928 #define ALC880_PIN_CD_NID               0x1c
3929
3930 /* fill in the dac_nids table from the parsed pin configuration */
3931 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3932                                      const struct auto_pin_cfg *cfg)
3933 {
3934         hda_nid_t nid;
3935         int assigned[4];
3936         int i, j;
3937
3938         memset(assigned, 0, sizeof(assigned));
3939         spec->multiout.dac_nids = spec->private_dac_nids;
3940
3941         /* check the pins hardwired to audio widget */
3942         for (i = 0; i < cfg->line_outs; i++) {
3943                 nid = cfg->line_out_pins[i];
3944                 if (alc880_is_fixed_pin(nid)) {
3945                         int idx = alc880_fixed_pin_idx(nid);
3946                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3947                         assigned[idx] = 1;
3948                 }
3949         }
3950         /* left pins can be connect to any audio widget */
3951         for (i = 0; i < cfg->line_outs; i++) {
3952                 nid = cfg->line_out_pins[i];
3953                 if (alc880_is_fixed_pin(nid))
3954                         continue;
3955                 /* search for an empty channel */
3956                 for (j = 0; j < cfg->line_outs; j++) {
3957                         if (!assigned[j]) {
3958                                 spec->multiout.dac_nids[i] =
3959                                         alc880_idx_to_dac(j);
3960                                 assigned[j] = 1;
3961                                 break;
3962                         }
3963                 }
3964         }
3965         spec->multiout.num_dacs = cfg->line_outs;
3966         return 0;
3967 }
3968
3969 /* add playback controls from the parsed DAC table */
3970 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3971                                              const struct auto_pin_cfg *cfg)
3972 {
3973         char name[32];
3974         static const char *chname[4] = {
3975                 "Front", "Surround", NULL /*CLFE*/, "Side"
3976         };
3977         hda_nid_t nid;
3978         int i, err;
3979
3980         for (i = 0; i < cfg->line_outs; i++) {
3981                 if (!spec->multiout.dac_nids[i])
3982                         continue;
3983                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3984                 if (i == 2) {
3985                         /* Center/LFE */
3986                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3987                                           "Center Playback Volume",
3988                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3989                                                               HDA_OUTPUT));
3990                         if (err < 0)
3991                                 return err;
3992                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3993                                           "LFE Playback Volume",
3994                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3995                                                               HDA_OUTPUT));
3996                         if (err < 0)
3997                                 return err;
3998                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3999                                           "Center Playback Switch",
4000                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4001                                                               HDA_INPUT));
4002                         if (err < 0)
4003                                 return err;
4004                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4005                                           "LFE Playback Switch",
4006                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4007                                                               HDA_INPUT));
4008                         if (err < 0)
4009                                 return err;
4010                 } else {
4011                         sprintf(name, "%s Playback Volume", chname[i]);
4012                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4013                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4014                                                               HDA_OUTPUT));
4015                         if (err < 0)
4016                                 return err;
4017                         sprintf(name, "%s Playback Switch", chname[i]);
4018                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4019                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4020                                                               HDA_INPUT));
4021                         if (err < 0)
4022                                 return err;
4023                 }
4024         }
4025         return 0;
4026 }
4027
4028 /* add playback controls for speaker and HP outputs */
4029 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4030                                         const char *pfx)
4031 {
4032         hda_nid_t nid;
4033         int err;
4034         char name[32];
4035
4036         if (!pin)
4037                 return 0;
4038
4039         if (alc880_is_fixed_pin(pin)) {
4040                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4041                 /* specify the DAC as the extra output */
4042                 if (!spec->multiout.hp_nid)
4043                         spec->multiout.hp_nid = nid;
4044                 else
4045                         spec->multiout.extra_out_nid[0] = nid;
4046                 /* control HP volume/switch on the output mixer amp */
4047                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4048                 sprintf(name, "%s Playback Volume", pfx);
4049                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4050                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4051                 if (err < 0)
4052                         return err;
4053                 sprintf(name, "%s Playback Switch", pfx);
4054                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4055                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4056                 if (err < 0)
4057                         return err;
4058         } else if (alc880_is_multi_pin(pin)) {
4059                 /* set manual connection */
4060                 /* we have only a switch on HP-out PIN */
4061                 sprintf(name, "%s Playback Switch", pfx);
4062                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4063                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4064                 if (err < 0)
4065                         return err;
4066         }
4067         return 0;
4068 }
4069
4070 /* create input playback/capture controls for the given pin */
4071 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4072                             const char *ctlname,
4073                             int idx, hda_nid_t mix_nid)
4074 {
4075         char name[32];
4076         int err;
4077
4078         sprintf(name, "%s Playback Volume", ctlname);
4079         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4080                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4081         if (err < 0)
4082                 return err;
4083         sprintf(name, "%s Playback Switch", ctlname);
4084         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4085                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4086         if (err < 0)
4087                 return err;
4088         return 0;
4089 }
4090
4091 /* create playback/capture controls for input pins */
4092 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
4093                                                 const struct auto_pin_cfg *cfg)
4094 {
4095         struct hda_input_mux *imux = &spec->private_imux;
4096         int i, err, idx;
4097
4098         for (i = 0; i < AUTO_PIN_LAST; i++) {
4099                 if (alc880_is_input_pin(cfg->input_pins[i])) {
4100                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
4101                         err = new_analog_input(spec, cfg->input_pins[i],
4102                                                auto_pin_cfg_labels[i],
4103                                                idx, 0x0b);
4104                         if (err < 0)
4105                                 return err;
4106                         imux->items[imux->num_items].label =
4107                                 auto_pin_cfg_labels[i];
4108                         imux->items[imux->num_items].index =
4109                                 alc880_input_pin_idx(cfg->input_pins[i]);
4110                         imux->num_items++;
4111                 }
4112         }
4113         return 0;
4114 }
4115
4116 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4117                                unsigned int pin_type)
4118 {
4119         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4120                             pin_type);
4121         /* unmute pin */
4122         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4123                             AMP_OUT_UNMUTE);
4124 }
4125
4126 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4127                                               hda_nid_t nid, int pin_type,
4128                                               int dac_idx)
4129 {
4130         alc_set_pin_output(codec, nid, pin_type);
4131         /* need the manual connection? */
4132         if (alc880_is_multi_pin(nid)) {
4133                 struct alc_spec *spec = codec->spec;
4134                 int idx = alc880_multi_pin_idx(nid);
4135                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4136                                     AC_VERB_SET_CONNECT_SEL,
4137                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4138         }
4139 }
4140
4141 static int get_pin_type(int line_out_type)
4142 {
4143         if (line_out_type == AUTO_PIN_HP_OUT)
4144                 return PIN_HP;
4145         else
4146                 return PIN_OUT;
4147 }
4148
4149 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4150 {
4151         struct alc_spec *spec = codec->spec;
4152         int i;
4153
4154         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
4155         for (i = 0; i < spec->autocfg.line_outs; i++) {
4156                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4157                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4158                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4159         }
4160 }
4161
4162 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4163 {
4164         struct alc_spec *spec = codec->spec;
4165         hda_nid_t pin;
4166
4167         pin = spec->autocfg.speaker_pins[0];
4168         if (pin) /* connect to front */
4169                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4170         pin = spec->autocfg.hp_pins[0];
4171         if (pin) /* connect to front */
4172                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4173 }
4174
4175 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4176 {
4177         struct alc_spec *spec = codec->spec;
4178         int i;
4179
4180         for (i = 0; i < AUTO_PIN_LAST; i++) {
4181                 hda_nid_t nid = spec->autocfg.input_pins[i];
4182                 if (alc880_is_input_pin(nid)) {
4183                         snd_hda_codec_write(codec, nid, 0,
4184                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4185                                             i <= AUTO_PIN_FRONT_MIC ?
4186                                             PIN_VREF80 : PIN_IN);
4187                         if (nid != ALC880_PIN_CD_NID)
4188                                 snd_hda_codec_write(codec, nid, 0,
4189                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4190                                                     AMP_OUT_MUTE);
4191                 }
4192         }
4193 }
4194
4195 /* parse the BIOS configuration and set up the alc_spec */
4196 /* return 1 if successful, 0 if the proper config is not found,
4197  * or a negative error code
4198  */
4199 static int alc880_parse_auto_config(struct hda_codec *codec)
4200 {
4201         struct alc_spec *spec = codec->spec;
4202         int err;
4203         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4204
4205         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4206                                            alc880_ignore);
4207         if (err < 0)
4208                 return err;
4209         if (!spec->autocfg.line_outs)
4210                 return 0; /* can't find valid BIOS pin config */
4211
4212         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4213         if (err < 0)
4214                 return err;
4215         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4216         if (err < 0)
4217                 return err;
4218         err = alc880_auto_create_extra_out(spec,
4219                                            spec->autocfg.speaker_pins[0],
4220                                            "Speaker");
4221         if (err < 0)
4222                 return err;
4223         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4224                                            "Headphone");
4225         if (err < 0)
4226                 return err;
4227         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
4228         if (err < 0)
4229                 return err;
4230
4231         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4232
4233         if (spec->autocfg.dig_out_pin)
4234                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
4235         if (spec->autocfg.dig_in_pin)
4236                 spec->dig_in_nid = ALC880_DIGIN_NID;
4237
4238         if (spec->kctls.list)
4239                 add_mixer(spec, spec->kctls.list);
4240
4241         add_verb(spec, alc880_volume_init_verbs);
4242
4243         spec->num_mux_defs = 1;
4244         spec->input_mux = &spec->private_imux;
4245
4246         store_pin_configs(codec);
4247         return 1;
4248 }
4249
4250 /* additional initialization for auto-configuration model */
4251 static void alc880_auto_init(struct hda_codec *codec)
4252 {
4253         struct alc_spec *spec = codec->spec;
4254         alc880_auto_init_multi_out(codec);
4255         alc880_auto_init_extra_out(codec);
4256         alc880_auto_init_analog_input(codec);
4257         if (spec->unsol_event)
4258                 alc_inithook(codec);
4259 }
4260
4261 /*
4262  * OK, here we have finally the patch for ALC880
4263  */
4264
4265 static void set_capture_mixer(struct alc_spec *spec)
4266 {
4267         static struct snd_kcontrol_new *caps[3] = {
4268                 alc_capture_mixer1,
4269                 alc_capture_mixer2,
4270                 alc_capture_mixer3,
4271         };
4272         if (spec->num_adc_nids > 0 && spec->num_adc_nids < 3)
4273                 spec->cap_mixer = caps[spec->num_adc_nids - 1];
4274 }
4275
4276 static int patch_alc880(struct hda_codec *codec)
4277 {
4278         struct alc_spec *spec;
4279         int board_config;
4280         int err;
4281
4282         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4283         if (spec == NULL)
4284                 return -ENOMEM;
4285
4286         codec->spec = spec;
4287
4288         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4289                                                   alc880_models,
4290                                                   alc880_cfg_tbl);
4291         if (board_config < 0) {
4292                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
4293                        "trying auto-probe from BIOS...\n");
4294                 board_config = ALC880_AUTO;
4295         }
4296
4297         if (board_config == ALC880_AUTO) {
4298                 /* automatic parse from the BIOS config */
4299                 err = alc880_parse_auto_config(codec);
4300                 if (err < 0) {
4301                         alc_free(codec);
4302                         return err;
4303                 } else if (!err) {
4304                         printk(KERN_INFO
4305                                "hda_codec: Cannot set up configuration "
4306                                "from BIOS.  Using 3-stack mode...\n");
4307                         board_config = ALC880_3ST;
4308                 }
4309         }
4310
4311         if (board_config != ALC880_AUTO)
4312                 setup_preset(spec, &alc880_presets[board_config]);
4313
4314         spec->stream_name_analog = "ALC880 Analog";
4315         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4316         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4317         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4318
4319         spec->stream_name_digital = "ALC880 Digital";
4320         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4321         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4322
4323         if (!spec->adc_nids && spec->input_mux) {
4324                 /* check whether NID 0x07 is valid */
4325                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4326                 /* get type */
4327                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4328                 if (wcap != AC_WID_AUD_IN) {
4329                         spec->adc_nids = alc880_adc_nids_alt;
4330                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4331                 } else {
4332                         spec->adc_nids = alc880_adc_nids;
4333                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4334                 }
4335         }
4336         set_capture_mixer(spec);
4337
4338         spec->vmaster_nid = 0x0c;
4339
4340         codec->patch_ops = alc_patch_ops;
4341         if (board_config == ALC880_AUTO)
4342                 spec->init_hook = alc880_auto_init;
4343 #ifdef CONFIG_SND_HDA_POWER_SAVE
4344         if (!spec->loopback.amplist)
4345                 spec->loopback.amplist = alc880_loopbacks;
4346 #endif
4347
4348         return 0;
4349 }
4350
4351
4352 /*
4353  * ALC260 support
4354  */
4355
4356 static hda_nid_t alc260_dac_nids[1] = {
4357         /* front */
4358         0x02,
4359 };
4360
4361 static hda_nid_t alc260_adc_nids[1] = {
4362         /* ADC0 */
4363         0x04,
4364 };
4365
4366 static hda_nid_t alc260_adc_nids_alt[1] = {
4367         /* ADC1 */
4368         0x05,
4369 };
4370
4371 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4372  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4373  */
4374 static hda_nid_t alc260_dual_adc_nids[2] = {
4375         /* ADC0, ADC1 */
4376         0x04, 0x05
4377 };
4378
4379 #define ALC260_DIGOUT_NID       0x03
4380 #define ALC260_DIGIN_NID        0x06
4381
4382 static struct hda_input_mux alc260_capture_source = {
4383         .num_items = 4,
4384         .items = {
4385                 { "Mic", 0x0 },
4386                 { "Front Mic", 0x1 },
4387                 { "Line", 0x2 },
4388                 { "CD", 0x4 },
4389         },
4390 };
4391
4392 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4393  * headphone jack and the internal CD lines since these are the only pins at
4394  * which audio can appear.  For flexibility, also allow the option of
4395  * recording the mixer output on the second ADC (ADC0 doesn't have a
4396  * connection to the mixer output).
4397  */
4398 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4399         {
4400                 .num_items = 3,
4401                 .items = {
4402                         { "Mic/Line", 0x0 },
4403                         { "CD", 0x4 },
4404                         { "Headphone", 0x2 },
4405                 },
4406         },
4407         {
4408                 .num_items = 4,
4409                 .items = {
4410                         { "Mic/Line", 0x0 },
4411                         { "CD", 0x4 },
4412                         { "Headphone", 0x2 },
4413                         { "Mixer", 0x5 },
4414                 },
4415         },
4416
4417 };
4418
4419 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4420  * the Fujitsu S702x, but jacks are marked differently.
4421  */
4422 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4423         {
4424                 .num_items = 4,
4425                 .items = {
4426                         { "Mic", 0x0 },
4427                         { "Line", 0x2 },
4428                         { "CD", 0x4 },
4429                         { "Headphone", 0x5 },
4430                 },
4431         },
4432         {
4433                 .num_items = 5,
4434                 .items = {
4435                         { "Mic", 0x0 },
4436                         { "Line", 0x2 },
4437                         { "CD", 0x4 },
4438                         { "Headphone", 0x6 },
4439                         { "Mixer", 0x5 },
4440                 },
4441         },
4442 };
4443 /*
4444  * This is just place-holder, so there's something for alc_build_pcms to look
4445  * at when it calculates the maximum number of channels. ALC260 has no mixer
4446  * element which allows changing the channel mode, so the verb list is
4447  * never used.
4448  */
4449 static struct hda_channel_mode alc260_modes[1] = {
4450         { 2, NULL },
4451 };
4452
4453
4454 /* Mixer combinations
4455  *
4456  * basic: base_output + input + pc_beep + capture
4457  * HP: base_output + input + capture_alt
4458  * HP_3013: hp_3013 + input + capture
4459  * fujitsu: fujitsu + capture
4460  * acer: acer + capture
4461  */
4462
4463 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4464         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4465         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4466         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4467         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4468         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4469         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4470         { } /* end */
4471 };
4472
4473 static struct snd_kcontrol_new alc260_input_mixer[] = {
4474         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4475         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4476         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4477         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4478         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4479         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4480         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4481         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4482         { } /* end */
4483 };
4484
4485 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4486         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4487         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4488         { } /* end */
4489 };
4490
4491 /* update HP, line and mono out pins according to the master switch */
4492 static void alc260_hp_master_update(struct hda_codec *codec,
4493                                     hda_nid_t hp, hda_nid_t line,
4494                                     hda_nid_t mono)
4495 {
4496         struct alc_spec *spec = codec->spec;
4497         unsigned int val = spec->master_sw ? PIN_HP : 0;
4498         /* change HP and line-out pins */
4499         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4500                             val);
4501         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4502                             val);
4503         /* mono (speaker) depending on the HP jack sense */
4504         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4505         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4506                             val);
4507 }
4508
4509 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4510                                    struct snd_ctl_elem_value *ucontrol)
4511 {
4512         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4513         struct alc_spec *spec = codec->spec;
4514         *ucontrol->value.integer.value = spec->master_sw;
4515         return 0;
4516 }
4517
4518 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4519                                    struct snd_ctl_elem_value *ucontrol)
4520 {
4521         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4522         struct alc_spec *spec = codec->spec;
4523         int val = !!*ucontrol->value.integer.value;
4524         hda_nid_t hp, line, mono;
4525
4526         if (val == spec->master_sw)
4527                 return 0;
4528         spec->master_sw = val;
4529         hp = (kcontrol->private_value >> 16) & 0xff;
4530         line = (kcontrol->private_value >> 8) & 0xff;
4531         mono = kcontrol->private_value & 0xff;
4532         alc260_hp_master_update(codec, hp, line, mono);
4533         return 1;
4534 }
4535
4536 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4537         {
4538                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4539                 .name = "Master Playback Switch",
4540                 .info = snd_ctl_boolean_mono_info,
4541                 .get = alc260_hp_master_sw_get,
4542                 .put = alc260_hp_master_sw_put,
4543                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4544         },
4545         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4546         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4547         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4548         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4549         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4550                               HDA_OUTPUT),
4551         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4552         { } /* end */
4553 };
4554
4555 static struct hda_verb alc260_hp_unsol_verbs[] = {
4556         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4557         {},
4558 };
4559
4560 static void alc260_hp_automute(struct hda_codec *codec)
4561 {
4562         struct alc_spec *spec = codec->spec;
4563         unsigned int present;
4564
4565         present = snd_hda_codec_read(codec, 0x10, 0,
4566                                      AC_VERB_GET_PIN_SENSE, 0);
4567         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4568         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4569 }
4570
4571 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4572 {
4573         if ((res >> 26) == ALC880_HP_EVENT)
4574                 alc260_hp_automute(codec);
4575 }
4576
4577 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4578         {
4579                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4580                 .name = "Master Playback Switch",
4581                 .info = snd_ctl_boolean_mono_info,
4582                 .get = alc260_hp_master_sw_get,
4583                 .put = alc260_hp_master_sw_put,
4584                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4585         },
4586         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4587         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4588         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4589         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4590         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4591         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4592         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4593         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4594         { } /* end */
4595 };
4596
4597 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4598         .ops = &snd_hda_bind_vol,
4599         .values = {
4600                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4601                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4602                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4603                 0
4604         },
4605 };
4606
4607 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4608         .ops = &snd_hda_bind_sw,
4609         .values = {
4610                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4611                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4612                 0
4613         },
4614 };
4615
4616 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4617         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4618         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4619         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4620         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4621         { } /* end */
4622 };
4623
4624 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4625         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4626         {},
4627 };
4628
4629 static void alc260_hp_3013_automute(struct hda_codec *codec)
4630 {
4631         struct alc_spec *spec = codec->spec;
4632         unsigned int present;
4633
4634         present = snd_hda_codec_read(codec, 0x15, 0,
4635                                      AC_VERB_GET_PIN_SENSE, 0);
4636         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4637         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4638 }
4639
4640 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4641                                        unsigned int res)
4642 {
4643         if ((res >> 26) == ALC880_HP_EVENT)
4644                 alc260_hp_3013_automute(codec);
4645 }
4646
4647 static void alc260_hp_3012_automute(struct hda_codec *codec)
4648 {
4649         unsigned int present, bits;
4650
4651         present = snd_hda_codec_read(codec, 0x10, 0,
4652                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4653
4654         bits = present ? 0 : PIN_OUT;
4655         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4656                             bits);
4657         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4658                             bits);
4659         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4660                             bits);
4661 }
4662
4663 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4664                                        unsigned int res)
4665 {
4666         if ((res >> 26) == ALC880_HP_EVENT)
4667                 alc260_hp_3012_automute(codec);
4668 }
4669
4670 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4671  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4672  */
4673 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4674         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4675         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4676         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4677         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4678         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4679         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4680         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4681         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4682         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4683         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4684         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4685         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4686         { } /* end */
4687 };
4688
4689 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4690  * versions of the ALC260 don't act on requests to enable mic bias from NID
4691  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4692  * datasheet doesn't mention this restriction.  At this stage it's not clear
4693  * whether this behaviour is intentional or is a hardware bug in chip
4694  * revisions available in early 2006.  Therefore for now allow the
4695  * "Headphone Jack Mode" control to span all choices, but if it turns out
4696  * that the lack of mic bias for this NID is intentional we could change the
4697  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4698  *
4699  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4700  * don't appear to make the mic bias available from the "line" jack, even
4701  * though the NID used for this jack (0x14) can supply it.  The theory is
4702  * that perhaps Acer have included blocking capacitors between the ALC260
4703  * and the output jack.  If this turns out to be the case for all such
4704  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4705  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4706  *
4707  * The C20x Tablet series have a mono internal speaker which is controlled
4708  * via the chip's Mono sum widget and pin complex, so include the necessary
4709  * controls for such models.  On models without a "mono speaker" the control
4710  * won't do anything.
4711  */
4712 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4713         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4714         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4715         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4716         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4717                               HDA_OUTPUT),
4718         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4719                            HDA_INPUT),
4720         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4721         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4722         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4723         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4724         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4725         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4726         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4727         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4728         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4729         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4730         { } /* end */
4731 };
4732
4733 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4734  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4735  */
4736 static struct snd_kcontrol_new alc260_will_mixer[] = {
4737         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4738         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4739         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4740         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4741         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4742         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4743         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4744         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4745         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4746         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4747         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4748         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4749         { } /* end */
4750 };
4751
4752 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4753  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4754  */
4755 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4756         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4757         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4758         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4759         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4760         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4761         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4762         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4763         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4764         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4765         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4766         { } /* end */
4767 };
4768
4769 /*
4770  * initialization verbs
4771  */
4772 static struct hda_verb alc260_init_verbs[] = {
4773         /* Line In pin widget for input */
4774         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4775         /* CD pin widget for input */
4776         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4777         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4778         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4779         /* Mic2 (front panel) pin widget for input and vref at 80% */
4780         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4781         /* LINE-2 is used for line-out in rear */
4782         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4783         /* select line-out */
4784         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4785         /* LINE-OUT pin */
4786         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4787         /* enable HP */
4788         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4789         /* enable Mono */
4790         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4791         /* mute capture amp left and right */
4792         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4793         /* set connection select to line in (default select for this ADC) */
4794         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4795         /* mute capture amp left and right */
4796         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4797         /* set connection select to line in (default select for this ADC) */
4798         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4799         /* set vol=0 Line-Out mixer amp left and right */
4800         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4801         /* unmute pin widget amp left and right (no gain on this amp) */
4802         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4803         /* set vol=0 HP mixer amp left and right */
4804         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4805         /* unmute pin widget amp left and right (no gain on this amp) */
4806         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4807         /* set vol=0 Mono mixer amp left and right */
4808         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4809         /* unmute pin widget amp left and right (no gain on this amp) */
4810         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4811         /* unmute LINE-2 out pin */
4812         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4813         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4814          * Line In 2 = 0x03
4815          */
4816         /* mute analog inputs */
4817         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4818         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4819         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4820         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4821         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4822         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4823         /* mute Front out path */
4824         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4825         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4826         /* mute Headphone out path */
4827         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4828         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4829         /* mute Mono out path */
4830         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4831         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4832         { }
4833 };
4834
4835 #if 0 /* should be identical with alc260_init_verbs? */
4836 static struct hda_verb alc260_hp_init_verbs[] = {
4837         /* Headphone and output */
4838         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4839         /* mono output */
4840         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4841         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4842         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4843         /* Mic2 (front panel) pin widget for input and vref at 80% */
4844         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4845         /* Line In pin widget for input */
4846         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4847         /* Line-2 pin widget for output */
4848         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4849         /* CD pin widget for input */
4850         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4851         /* unmute amp left and right */
4852         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4853         /* set connection select to line in (default select for this ADC) */
4854         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4855         /* unmute Line-Out mixer amp left and right (volume = 0) */
4856         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4857         /* mute pin widget amp left and right (no gain on this amp) */
4858         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4859         /* unmute HP mixer amp left and right (volume = 0) */
4860         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4861         /* mute pin widget amp left and right (no gain on this amp) */
4862         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4863         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4864          * Line In 2 = 0x03
4865          */
4866         /* mute analog inputs */
4867         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4868         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4869         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4870         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4871         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4872         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4873         /* Unmute Front out path */
4874         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4875         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4876         /* Unmute Headphone out path */
4877         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4878         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4879         /* Unmute Mono out path */
4880         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4881         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4882         { }
4883 };
4884 #endif
4885
4886 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4887         /* Line out and output */
4888         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4889         /* mono output */
4890         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4891         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4892         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4893         /* Mic2 (front panel) pin widget for input and vref at 80% */
4894         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4895         /* Line In pin widget for input */
4896         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4897         /* Headphone pin widget for output */
4898         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4899         /* CD pin widget for input */
4900         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4901         /* unmute amp left and right */
4902         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4903         /* set connection select to line in (default select for this ADC) */
4904         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4905         /* unmute Line-Out mixer amp left and right (volume = 0) */
4906         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4907         /* mute pin widget amp left and right (no gain on this amp) */
4908         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4909         /* unmute HP mixer amp left and right (volume = 0) */
4910         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4911         /* mute pin widget amp left and right (no gain on this amp) */
4912         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4913         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4914          * Line In 2 = 0x03
4915          */
4916         /* mute analog inputs */
4917         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4918         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4919         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4920         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4921         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4922         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4923         /* Unmute Front out path */
4924         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4925         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4926         /* Unmute Headphone out path */
4927         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4928         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4929         /* Unmute Mono out path */
4930         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4931         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4932         { }
4933 };
4934
4935 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4936  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4937  * audio = 0x16, internal speaker = 0x10.
4938  */
4939 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4940         /* Disable all GPIOs */
4941         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4942         /* Internal speaker is connected to headphone pin */
4943         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4944         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4945         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4946         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4947         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4948         /* Ensure all other unused pins are disabled and muted. */
4949         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4950         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4951         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4952         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4953         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4954         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4955         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4956         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4957
4958         /* Disable digital (SPDIF) pins */
4959         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4960         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4961
4962         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
4963          * when acting as an output.
4964          */
4965         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4966
4967         /* Start with output sum widgets muted and their output gains at min */
4968         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4969         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4970         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4971         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4972         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4973         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4974         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4975         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4976         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4977
4978         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4979         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4980         /* Unmute Line1 pin widget output buffer since it starts as an output.
4981          * If the pin mode is changed by the user the pin mode control will
4982          * take care of enabling the pin's input/output buffers as needed.
4983          * Therefore there's no need to enable the input buffer at this
4984          * stage.
4985          */
4986         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4987         /* Unmute input buffer of pin widget used for Line-in (no equiv
4988          * mixer ctrl)
4989          */
4990         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4991
4992         /* Mute capture amp left and right */
4993         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4994         /* Set ADC connection select to match default mixer setting - line
4995          * in (on mic1 pin)
4996          */
4997         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4998
4999         /* Do the same for the second ADC: mute capture input amp and
5000          * set ADC connection to line in (on mic1 pin)
5001          */
5002         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5003         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5004
5005         /* Mute all inputs to mixer widget (even unconnected ones) */
5006         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5007         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5008         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5009         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5010         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5011         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5012         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5013         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5014
5015         { }
5016 };
5017
5018 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5019  * similar laptops (adapted from Fujitsu init verbs).
5020  */
5021 static struct hda_verb alc260_acer_init_verbs[] = {
5022         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5023          * the headphone jack.  Turn this on and rely on the standard mute
5024          * methods whenever the user wants to turn these outputs off.
5025          */
5026         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5027         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5028         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5029         /* Internal speaker/Headphone jack is connected to Line-out pin */
5030         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5031         /* Internal microphone/Mic jack is connected to Mic1 pin */
5032         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5033         /* Line In jack is connected to Line1 pin */
5034         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5035         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5036         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5037         /* Ensure all other unused pins are disabled and muted. */
5038         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5039         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5040         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5041         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5042         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5043         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5044         /* Disable digital (SPDIF) pins */
5045         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5046         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5047
5048         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5049          * bus when acting as outputs.
5050          */
5051         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5052         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5053
5054         /* Start with output sum widgets muted and their output gains at min */
5055         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5056         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5057         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5058         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5059         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5060         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5061         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5062         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5063         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5064
5065         /* Unmute Line-out pin widget amp left and right
5066          * (no equiv mixer ctrl)
5067          */
5068         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5069         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5070         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5071         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5072          * inputs. If the pin mode is changed by the user the pin mode control
5073          * will take care of enabling the pin's input/output buffers as needed.
5074          * Therefore there's no need to enable the input buffer at this
5075          * stage.
5076          */
5077         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5078         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5079
5080         /* Mute capture amp left and right */
5081         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5082         /* Set ADC connection select to match default mixer setting - mic
5083          * (on mic1 pin)
5084          */
5085         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5086
5087         /* Do similar with the second ADC: mute capture input amp and
5088          * set ADC connection to mic to match ALSA's default state.
5089          */
5090         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5091         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5092
5093         /* Mute all inputs to mixer widget (even unconnected ones) */
5094         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5095         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5096         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5097         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5098         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5099         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5100         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5101         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5102
5103         { }
5104 };
5105
5106 static struct hda_verb alc260_will_verbs[] = {
5107         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5108         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5109         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5110         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5111         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5112         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5113         {}
5114 };
5115
5116 static struct hda_verb alc260_replacer_672v_verbs[] = {
5117         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5118         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5119         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5120
5121         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5122         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5123         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5124
5125         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5126         {}
5127 };
5128
5129 /* toggle speaker-output according to the hp-jack state */
5130 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5131 {
5132         unsigned int present;
5133
5134         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5135         present = snd_hda_codec_read(codec, 0x0f, 0,
5136                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5137         if (present) {
5138                 snd_hda_codec_write_cache(codec, 0x01, 0,
5139                                           AC_VERB_SET_GPIO_DATA, 1);
5140                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5141                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5142                                           PIN_HP);
5143         } else {
5144                 snd_hda_codec_write_cache(codec, 0x01, 0,
5145                                           AC_VERB_SET_GPIO_DATA, 0);
5146                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5147                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5148                                           PIN_OUT);
5149         }
5150 }
5151
5152 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5153                                        unsigned int res)
5154 {
5155         if ((res >> 26) == ALC880_HP_EVENT)
5156                 alc260_replacer_672v_automute(codec);
5157 }
5158
5159 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5160         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5161         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5162         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5163         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5164         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5165         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5166         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5167         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5168         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5169         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5170         {}
5171 };
5172
5173 /* Test configuration for debugging, modelled after the ALC880 test
5174  * configuration.
5175  */
5176 #ifdef CONFIG_SND_DEBUG
5177 static hda_nid_t alc260_test_dac_nids[1] = {
5178         0x02,
5179 };
5180 static hda_nid_t alc260_test_adc_nids[2] = {
5181         0x04, 0x05,
5182 };
5183 /* For testing the ALC260, each input MUX needs its own definition since
5184  * the signal assignments are different.  This assumes that the first ADC
5185  * is NID 0x04.
5186  */
5187 static struct hda_input_mux alc260_test_capture_sources[2] = {
5188         {
5189                 .num_items = 7,
5190                 .items = {
5191                         { "MIC1 pin", 0x0 },
5192                         { "MIC2 pin", 0x1 },
5193                         { "LINE1 pin", 0x2 },
5194                         { "LINE2 pin", 0x3 },
5195                         { "CD pin", 0x4 },
5196                         { "LINE-OUT pin", 0x5 },
5197                         { "HP-OUT pin", 0x6 },
5198                 },
5199         },
5200         {
5201                 .num_items = 8,
5202                 .items = {
5203                         { "MIC1 pin", 0x0 },
5204                         { "MIC2 pin", 0x1 },
5205                         { "LINE1 pin", 0x2 },
5206                         { "LINE2 pin", 0x3 },
5207                         { "CD pin", 0x4 },
5208                         { "Mixer", 0x5 },
5209                         { "LINE-OUT pin", 0x6 },
5210                         { "HP-OUT pin", 0x7 },
5211                 },
5212         },
5213 };
5214 static struct snd_kcontrol_new alc260_test_mixer[] = {
5215         /* Output driver widgets */
5216         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5217         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5218         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5219         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5220         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5221         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5222
5223         /* Modes for retasking pin widgets
5224          * Note: the ALC260 doesn't seem to act on requests to enable mic
5225          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5226          * mention this restriction.  At this stage it's not clear whether
5227          * this behaviour is intentional or is a hardware bug in chip
5228          * revisions available at least up until early 2006.  Therefore for
5229          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5230          * choices, but if it turns out that the lack of mic bias for these
5231          * NIDs is intentional we could change their modes from
5232          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5233          */
5234         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5235         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5236         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5237         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5238         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5239         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5240
5241         /* Loopback mixer controls */
5242         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5243         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5244         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5245         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5246         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5247         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5248         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5249         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5250         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5251         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5252         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
5253         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
5254         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5255         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5256         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5257         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5258
5259         /* Controls for GPIO pins, assuming they are configured as outputs */
5260         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5261         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5262         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5263         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5264
5265         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5266          * is ambigious as to which NID is which; testing on laptops which
5267          * make this output available should provide clarification.
5268          */
5269         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5270         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5271
5272         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5273          * this output to turn on an external amplifier.
5274          */
5275         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5276         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5277
5278         { } /* end */
5279 };
5280 static struct hda_verb alc260_test_init_verbs[] = {
5281         /* Enable all GPIOs as outputs with an initial value of 0 */
5282         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5283         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5284         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5285
5286         /* Enable retasking pins as output, initially without power amp */
5287         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5288         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5289         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5290         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5291         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5292         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5293
5294         /* Disable digital (SPDIF) pins initially, but users can enable
5295          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5296          * payload also sets the generation to 0, output to be in "consumer"
5297          * PCM format, copyright asserted, no pre-emphasis and no validity
5298          * control.
5299          */
5300         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5301         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5302
5303         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5304          * OUT1 sum bus when acting as an output.
5305          */
5306         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5307         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5308         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5309         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5310
5311         /* Start with output sum widgets muted and their output gains at min */
5312         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5313         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5314         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5315         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5316         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5317         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5318         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5319         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5320         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5321
5322         /* Unmute retasking pin widget output buffers since the default
5323          * state appears to be output.  As the pin mode is changed by the
5324          * user the pin mode control will take care of enabling the pin's
5325          * input/output buffers as needed.
5326          */
5327         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5328         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5329         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5330         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5331         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5332         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5333         /* Also unmute the mono-out pin widget */
5334         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5335
5336         /* Mute capture amp left and right */
5337         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5338         /* Set ADC connection select to match default mixer setting (mic1
5339          * pin)
5340          */
5341         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5342
5343         /* Do the same for the second ADC: mute capture input amp and
5344          * set ADC connection to mic1 pin
5345          */
5346         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5347         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5348
5349         /* Mute all inputs to mixer widget (even unconnected ones) */
5350         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5351         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5352         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5353         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5354         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5355         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5356         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5357         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5358
5359         { }
5360 };
5361 #endif
5362
5363 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5364 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5365
5366 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5367 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5368
5369 /*
5370  * for BIOS auto-configuration
5371  */
5372
5373 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5374                                         const char *pfx, int *vol_bits)
5375 {
5376         hda_nid_t nid_vol;
5377         unsigned long vol_val, sw_val;
5378         char name[32];
5379         int err;
5380
5381         if (nid >= 0x0f && nid < 0x11) {
5382                 nid_vol = nid - 0x7;
5383                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5384                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5385         } else if (nid == 0x11) {
5386                 nid_vol = nid - 0x7;
5387                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5388                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5389         } else if (nid >= 0x12 && nid <= 0x15) {
5390                 nid_vol = 0x08;
5391                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5392                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5393         } else
5394                 return 0; /* N/A */
5395
5396         if (!(*vol_bits & (1 << nid_vol))) {
5397                 /* first control for the volume widget */
5398                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5399                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5400                 if (err < 0)
5401                         return err;
5402                 *vol_bits |= (1 << nid_vol);
5403         }
5404         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5405         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5406         if (err < 0)
5407                 return err;
5408         return 1;
5409 }
5410
5411 /* add playback controls from the parsed DAC table */
5412 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5413                                              const struct auto_pin_cfg *cfg)
5414 {
5415         hda_nid_t nid;
5416         int err;
5417         int vols = 0;
5418
5419         spec->multiout.num_dacs = 1;
5420         spec->multiout.dac_nids = spec->private_dac_nids;
5421         spec->multiout.dac_nids[0] = 0x02;
5422
5423         nid = cfg->line_out_pins[0];
5424         if (nid) {
5425                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5426                 if (err < 0)
5427                         return err;
5428         }
5429
5430         nid = cfg->speaker_pins[0];
5431         if (nid) {
5432                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5433                 if (err < 0)
5434                         return err;
5435         }
5436
5437         nid = cfg->hp_pins[0];
5438         if (nid) {
5439                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5440                                                    &vols);
5441                 if (err < 0)
5442                         return err;
5443         }
5444         return 0;
5445 }
5446
5447 /* create playback/capture controls for input pins */
5448 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5449                                                 const struct auto_pin_cfg *cfg)
5450 {
5451         struct hda_input_mux *imux = &spec->private_imux;
5452         int i, err, idx;
5453
5454         for (i = 0; i < AUTO_PIN_LAST; i++) {
5455                 if (cfg->input_pins[i] >= 0x12) {
5456                         idx = cfg->input_pins[i] - 0x12;
5457                         err = new_analog_input(spec, cfg->input_pins[i],
5458                                                auto_pin_cfg_labels[i], idx,
5459                                                0x07);
5460                         if (err < 0)
5461                                 return err;
5462                         imux->items[imux->num_items].label =
5463                                 auto_pin_cfg_labels[i];
5464                         imux->items[imux->num_items].index = idx;
5465                         imux->num_items++;
5466                 }
5467                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5468                         idx = cfg->input_pins[i] - 0x09;
5469                         err = new_analog_input(spec, cfg->input_pins[i],
5470                                                auto_pin_cfg_labels[i], idx,
5471                                                0x07);
5472                         if (err < 0)
5473                                 return err;
5474                         imux->items[imux->num_items].label =
5475                                 auto_pin_cfg_labels[i];
5476                         imux->items[imux->num_items].index = idx;
5477                         imux->num_items++;
5478                 }
5479         }
5480         return 0;
5481 }
5482
5483 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5484                                               hda_nid_t nid, int pin_type,
5485                                               int sel_idx)
5486 {
5487         alc_set_pin_output(codec, nid, pin_type);
5488         /* need the manual connection? */
5489         if (nid >= 0x12) {
5490                 int idx = nid - 0x12;
5491                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5492                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5493         }
5494 }
5495
5496 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5497 {
5498         struct alc_spec *spec = codec->spec;
5499         hda_nid_t nid;
5500
5501         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5502         nid = spec->autocfg.line_out_pins[0];
5503         if (nid) {
5504                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5505                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5506         }
5507
5508         nid = spec->autocfg.speaker_pins[0];
5509         if (nid)
5510                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5511
5512         nid = spec->autocfg.hp_pins[0];
5513         if (nid)
5514                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5515 }
5516
5517 #define ALC260_PIN_CD_NID               0x16
5518 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5519 {
5520         struct alc_spec *spec = codec->spec;
5521         int i;
5522
5523         for (i = 0; i < AUTO_PIN_LAST; i++) {
5524                 hda_nid_t nid = spec->autocfg.input_pins[i];
5525                 if (nid >= 0x12) {
5526                         snd_hda_codec_write(codec, nid, 0,
5527                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5528                                             i <= AUTO_PIN_FRONT_MIC ?
5529                                             PIN_VREF80 : PIN_IN);
5530                         if (nid != ALC260_PIN_CD_NID)
5531                                 snd_hda_codec_write(codec, nid, 0,
5532                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5533                                                     AMP_OUT_MUTE);
5534                 }
5535         }
5536 }
5537
5538 /*
5539  * generic initialization of ADC, input mixers and output mixers
5540  */
5541 static struct hda_verb alc260_volume_init_verbs[] = {
5542         /*
5543          * Unmute ADC0-1 and set the default input to mic-in
5544          */
5545         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5546         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5547         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5548         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5549
5550         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5551          * mixer widget
5552          * Note: PASD motherboards uses the Line In 2 as the input for
5553          * front panel mic (mic 2)
5554          */
5555         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5556         /* mute analog inputs */
5557         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5558         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5559         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5560         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5561         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5562
5563         /*
5564          * Set up output mixers (0x08 - 0x0a)
5565          */
5566         /* set vol=0 to output mixers */
5567         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5568         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5569         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5570         /* set up input amps for analog loopback */
5571         /* Amp Indices: DAC = 0, mixer = 1 */
5572         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5573         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5574         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5575         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5576         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5577         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5578
5579         { }
5580 };
5581
5582 static int alc260_parse_auto_config(struct hda_codec *codec)
5583 {
5584         struct alc_spec *spec = codec->spec;
5585         int err;
5586         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5587
5588         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5589                                            alc260_ignore);
5590         if (err < 0)
5591                 return err;
5592         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5593         if (err < 0)
5594                 return err;
5595         if (!spec->kctls.list)
5596                 return 0; /* can't find valid BIOS pin config */
5597         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5598         if (err < 0)
5599                 return err;
5600
5601         spec->multiout.max_channels = 2;
5602
5603         if (spec->autocfg.dig_out_pin)
5604                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5605         if (spec->kctls.list)
5606                 add_mixer(spec, spec->kctls.list);
5607
5608         add_verb(spec, alc260_volume_init_verbs);
5609
5610         spec->num_mux_defs = 1;
5611         spec->input_mux = &spec->private_imux;
5612
5613         store_pin_configs(codec);
5614         return 1;
5615 }
5616
5617 /* additional initialization for auto-configuration model */
5618 static void alc260_auto_init(struct hda_codec *codec)
5619 {
5620         struct alc_spec *spec = codec->spec;
5621         alc260_auto_init_multi_out(codec);
5622         alc260_auto_init_analog_input(codec);
5623         if (spec->unsol_event)
5624                 alc_inithook(codec);
5625 }
5626
5627 #ifdef CONFIG_SND_HDA_POWER_SAVE
5628 static struct hda_amp_list alc260_loopbacks[] = {
5629         { 0x07, HDA_INPUT, 0 },
5630         { 0x07, HDA_INPUT, 1 },
5631         { 0x07, HDA_INPUT, 2 },
5632         { 0x07, HDA_INPUT, 3 },
5633         { 0x07, HDA_INPUT, 4 },
5634         { } /* end */
5635 };
5636 #endif
5637
5638 /*
5639  * ALC260 configurations
5640  */
5641 static const char *alc260_models[ALC260_MODEL_LAST] = {
5642         [ALC260_BASIC]          = "basic",
5643         [ALC260_HP]             = "hp",
5644         [ALC260_HP_3013]        = "hp-3013",
5645         [ALC260_HP_DC7600]      = "hp-dc7600",
5646         [ALC260_FUJITSU_S702X]  = "fujitsu",
5647         [ALC260_ACER]           = "acer",
5648         [ALC260_WILL]           = "will",
5649         [ALC260_REPLACER_672V]  = "replacer",
5650 #ifdef CONFIG_SND_DEBUG
5651         [ALC260_TEST]           = "test",
5652 #endif
5653         [ALC260_AUTO]           = "auto",
5654 };
5655
5656 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5657         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5658         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5659         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5660         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5661         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5662         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5663         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5664         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5665         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5666         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5667         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5668         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5669         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5670         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5671         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5672         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5673         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5674         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5675         {}
5676 };
5677
5678 static struct alc_config_preset alc260_presets[] = {
5679         [ALC260_BASIC] = {
5680                 .mixers = { alc260_base_output_mixer,
5681                             alc260_input_mixer,
5682                             alc260_pc_beep_mixer },
5683                 .init_verbs = { alc260_init_verbs },
5684                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5685                 .dac_nids = alc260_dac_nids,
5686                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5687                 .adc_nids = alc260_adc_nids,
5688                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5689                 .channel_mode = alc260_modes,
5690                 .input_mux = &alc260_capture_source,
5691         },
5692         [ALC260_HP] = {
5693                 .mixers = { alc260_hp_output_mixer,
5694                             alc260_input_mixer },
5695                 .init_verbs = { alc260_init_verbs,
5696                                 alc260_hp_unsol_verbs },
5697                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5698                 .dac_nids = alc260_dac_nids,
5699                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5700                 .adc_nids = alc260_adc_nids_alt,
5701                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5702                 .channel_mode = alc260_modes,
5703                 .input_mux = &alc260_capture_source,
5704                 .unsol_event = alc260_hp_unsol_event,
5705                 .init_hook = alc260_hp_automute,
5706         },
5707         [ALC260_HP_DC7600] = {
5708                 .mixers = { alc260_hp_dc7600_mixer,
5709                             alc260_input_mixer },
5710                 .init_verbs = { alc260_init_verbs,
5711                                 alc260_hp_dc7600_verbs },
5712                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5713                 .dac_nids = alc260_dac_nids,
5714                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5715                 .adc_nids = alc260_adc_nids_alt,
5716                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5717                 .channel_mode = alc260_modes,
5718                 .input_mux = &alc260_capture_source,
5719                 .unsol_event = alc260_hp_3012_unsol_event,
5720                 .init_hook = alc260_hp_3012_automute,
5721         },
5722         [ALC260_HP_3013] = {
5723                 .mixers = { alc260_hp_3013_mixer,
5724                             alc260_input_mixer },
5725                 .init_verbs = { alc260_hp_3013_init_verbs,
5726                                 alc260_hp_3013_unsol_verbs },
5727                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5728                 .dac_nids = alc260_dac_nids,
5729                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5730                 .adc_nids = alc260_adc_nids_alt,
5731                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5732                 .channel_mode = alc260_modes,
5733                 .input_mux = &alc260_capture_source,
5734                 .unsol_event = alc260_hp_3013_unsol_event,
5735                 .init_hook = alc260_hp_3013_automute,
5736         },
5737         [ALC260_FUJITSU_S702X] = {
5738                 .mixers = { alc260_fujitsu_mixer },
5739                 .init_verbs = { alc260_fujitsu_init_verbs },
5740                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5741                 .dac_nids = alc260_dac_nids,
5742                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5743                 .adc_nids = alc260_dual_adc_nids,
5744                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5745                 .channel_mode = alc260_modes,
5746                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5747                 .input_mux = alc260_fujitsu_capture_sources,
5748         },
5749         [ALC260_ACER] = {
5750                 .mixers = { alc260_acer_mixer },
5751                 .init_verbs = { alc260_acer_init_verbs },
5752                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5753                 .dac_nids = alc260_dac_nids,
5754                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5755                 .adc_nids = alc260_dual_adc_nids,
5756                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5757                 .channel_mode = alc260_modes,
5758                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5759                 .input_mux = alc260_acer_capture_sources,
5760         },
5761         [ALC260_WILL] = {
5762                 .mixers = { alc260_will_mixer },
5763                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5764                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5765                 .dac_nids = alc260_dac_nids,
5766                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5767                 .adc_nids = alc260_adc_nids,
5768                 .dig_out_nid = ALC260_DIGOUT_NID,
5769                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5770                 .channel_mode = alc260_modes,
5771                 .input_mux = &alc260_capture_source,
5772         },
5773         [ALC260_REPLACER_672V] = {
5774                 .mixers = { alc260_replacer_672v_mixer },
5775                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5776                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5777                 .dac_nids = alc260_dac_nids,
5778                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5779                 .adc_nids = alc260_adc_nids,
5780                 .dig_out_nid = ALC260_DIGOUT_NID,
5781                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5782                 .channel_mode = alc260_modes,
5783                 .input_mux = &alc260_capture_source,
5784                 .unsol_event = alc260_replacer_672v_unsol_event,
5785                 .init_hook = alc260_replacer_672v_automute,
5786         },
5787 #ifdef CONFIG_SND_DEBUG
5788         [ALC260_TEST] = {
5789                 .mixers = { alc260_test_mixer },
5790                 .init_verbs = { alc260_test_init_verbs },
5791                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5792                 .dac_nids = alc260_test_dac_nids,
5793                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5794                 .adc_nids = alc260_test_adc_nids,
5795                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5796                 .channel_mode = alc260_modes,
5797                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5798                 .input_mux = alc260_test_capture_sources,
5799         },
5800 #endif
5801 };
5802
5803 static int patch_alc260(struct hda_codec *codec)
5804 {
5805         struct alc_spec *spec;
5806         int err, board_config;
5807
5808         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5809         if (spec == NULL)
5810                 return -ENOMEM;
5811
5812         codec->spec = spec;
5813
5814         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5815                                                   alc260_models,
5816                                                   alc260_cfg_tbl);
5817         if (board_config < 0) {
5818                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5819                            "trying auto-probe from BIOS...\n");
5820                 board_config = ALC260_AUTO;
5821         }
5822
5823         if (board_config == ALC260_AUTO) {
5824                 /* automatic parse from the BIOS config */
5825                 err = alc260_parse_auto_config(codec);
5826                 if (err < 0) {
5827                         alc_free(codec);
5828                         return err;
5829                 } else if (!err) {
5830                         printk(KERN_INFO
5831                                "hda_codec: Cannot set up configuration "
5832                                "from BIOS.  Using base mode...\n");
5833                         board_config = ALC260_BASIC;
5834                 }
5835         }
5836
5837         if (board_config != ALC260_AUTO)
5838                 setup_preset(spec, &alc260_presets[board_config]);
5839
5840         spec->stream_name_analog = "ALC260 Analog";
5841         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5842         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5843
5844         spec->stream_name_digital = "ALC260 Digital";
5845         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5846         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5847
5848         if (!spec->adc_nids && spec->input_mux) {
5849                 /* check whether NID 0x04 is valid */
5850                 unsigned int wcap = get_wcaps(codec, 0x04);
5851                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5852                 /* get type */
5853                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5854                         spec->adc_nids = alc260_adc_nids_alt;
5855                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5856                 } else {
5857                         spec->adc_nids = alc260_adc_nids;
5858                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5859                 }
5860         }
5861         set_capture_mixer(spec);
5862
5863         spec->vmaster_nid = 0x08;
5864
5865         codec->patch_ops = alc_patch_ops;
5866         if (board_config == ALC260_AUTO)
5867                 spec->init_hook = alc260_auto_init;
5868 #ifdef CONFIG_SND_HDA_POWER_SAVE
5869         if (!spec->loopback.amplist)
5870                 spec->loopback.amplist = alc260_loopbacks;
5871 #endif
5872
5873         return 0;
5874 }
5875
5876
5877 /*
5878  * ALC882 support
5879  *
5880  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5881  * configuration.  Each pin widget can choose any input DACs and a mixer.
5882  * Each ADC is connected from a mixer of all inputs.  This makes possible
5883  * 6-channel independent captures.
5884  *
5885  * In addition, an independent DAC for the multi-playback (not used in this
5886  * driver yet).
5887  */
5888 #define ALC882_DIGOUT_NID       0x06
5889 #define ALC882_DIGIN_NID        0x0a
5890
5891 static struct hda_channel_mode alc882_ch_modes[1] = {
5892         { 8, NULL }
5893 };
5894
5895 static hda_nid_t alc882_dac_nids[4] = {
5896         /* front, rear, clfe, rear_surr */
5897         0x02, 0x03, 0x04, 0x05
5898 };
5899
5900 /* identical with ALC880 */
5901 #define alc882_adc_nids         alc880_adc_nids
5902 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5903
5904 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5905 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5906
5907 /* input MUX */
5908 /* FIXME: should be a matrix-type input source selection */
5909
5910 static struct hda_input_mux alc882_capture_source = {
5911         .num_items = 4,
5912         .items = {
5913                 { "Mic", 0x0 },
5914                 { "Front Mic", 0x1 },
5915                 { "Line", 0x2 },
5916                 { "CD", 0x4 },
5917         },
5918 };
5919 /*
5920  * 2ch mode
5921  */
5922 static struct hda_verb alc882_3ST_ch2_init[] = {
5923         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5924         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5925         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5926         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5927         { } /* end */
5928 };
5929
5930 /*
5931  * 6ch mode
5932  */
5933 static struct hda_verb alc882_3ST_ch6_init[] = {
5934         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5935         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5936         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5937         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5938         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5939         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5940         { } /* end */
5941 };
5942
5943 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5944         { 2, alc882_3ST_ch2_init },
5945         { 6, alc882_3ST_ch6_init },
5946 };
5947
5948 /*
5949  * 6ch mode
5950  */
5951 static struct hda_verb alc882_sixstack_ch6_init[] = {
5952         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5953         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5954         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5955         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5956         { } /* end */
5957 };
5958
5959 /*
5960  * 8ch mode
5961  */
5962 static struct hda_verb alc882_sixstack_ch8_init[] = {
5963         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5964         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5965         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5966         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5967         { } /* end */
5968 };
5969
5970 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5971         { 6, alc882_sixstack_ch6_init },
5972         { 8, alc882_sixstack_ch8_init },
5973 };
5974
5975 /*
5976  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5977  */
5978
5979 /*
5980  * 2ch mode
5981  */
5982 static struct hda_verb alc885_mbp_ch2_init[] = {
5983         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5984         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5985         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5986         { } /* end */
5987 };
5988
5989 /*
5990  * 6ch mode
5991  */
5992 static struct hda_verb alc885_mbp_ch6_init[] = {
5993         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5994         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5995         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5996         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5997         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5998         { } /* end */
5999 };
6000
6001 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
6002         { 2, alc885_mbp_ch2_init },
6003         { 6, alc885_mbp_ch6_init },
6004 };
6005
6006
6007 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6008  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6009  */
6010 static struct snd_kcontrol_new alc882_base_mixer[] = {
6011         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6012         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6013         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6014         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6015         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6016         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6017         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6018         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6019         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6020         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6021         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6022         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6023         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6024         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6025         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6026         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6027         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6028         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6029         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6030         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6031         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6032         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6033         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6034         { } /* end */
6035 };
6036
6037 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6038         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6039         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6040         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
6041         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6042         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6043         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6044         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
6045         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
6046         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
6047         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
6048         { } /* end */
6049 };
6050 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6051         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6052         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6053         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6054         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6055         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6056         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6057         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6058         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6059         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6060         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6061         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6062         { } /* end */
6063 };
6064
6065 static struct snd_kcontrol_new alc882_targa_mixer[] = {
6066         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6067         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6068         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6069         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6070         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6071         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6072         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6073         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6074         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6075         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6076         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6077         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6078         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6079         { } /* end */
6080 };
6081
6082 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
6083  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
6084  */
6085 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
6086         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6087         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6088         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6089         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
6090         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6091         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6092         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6093         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6094         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
6095         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
6096         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6097         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6098         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6099         { } /* end */
6100 };
6101
6102 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6103         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6104         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6105         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6106         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6107         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6108         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6109         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6110         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6111         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6112         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6113         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6114         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6115         { } /* end */
6116 };
6117
6118 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6119         {
6120                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6121                 .name = "Channel Mode",
6122                 .info = alc_ch_mode_info,
6123                 .get = alc_ch_mode_get,
6124                 .put = alc_ch_mode_put,
6125         },
6126         { } /* end */
6127 };
6128
6129 static struct hda_verb alc882_init_verbs[] = {
6130         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6131         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6132         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6133         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6134         /* Rear mixer */
6135         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6136         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6137         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6138         /* CLFE mixer */
6139         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6140         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6141         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6142         /* Side mixer */
6143         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6144         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6145         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6146
6147         /* Front Pin: output 0 (0x0c) */
6148         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6149         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6150         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6151         /* Rear Pin: output 1 (0x0d) */
6152         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6153         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6154         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6155         /* CLFE Pin: output 2 (0x0e) */
6156         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6157         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6158         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6159         /* Side Pin: output 3 (0x0f) */
6160         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6161         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6162         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6163         /* Mic (rear) pin: input vref at 80% */
6164         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6165         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6166         /* Front Mic pin: input vref at 80% */
6167         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6168         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6169         /* Line In pin: input */
6170         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6171         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6172         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6173         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6174         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6175         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6176         /* CD pin widget for input */
6177         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6178
6179         /* FIXME: use matrix-type input source selection */
6180         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6181         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6182         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6183         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6184         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6185         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6186         /* Input mixer2 */
6187         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6188         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6189         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6190         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6191         /* Input mixer3 */
6192         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6193         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6194         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6195         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6196         /* ADC1: mute amp left and right */
6197         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6198         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6199         /* ADC2: mute amp left and right */
6200         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6201         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6202         /* ADC3: mute amp left and right */
6203         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6204         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6205
6206         { }
6207 };
6208
6209 static struct hda_verb alc882_eapd_verbs[] = {
6210         /* change to EAPD mode */
6211         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6212         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
6213         { }
6214 };
6215
6216 /* Mac Pro test */
6217 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6218         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6219         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6220         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6221         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6222         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6223         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6224         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6225         { } /* end */
6226 };
6227
6228 static struct hda_verb alc882_macpro_init_verbs[] = {
6229         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6230         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6231         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6232         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6233         /* Front Pin: output 0 (0x0c) */
6234         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6235         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6236         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6237         /* Front Mic pin: input vref at 80% */
6238         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6239         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6240         /* Speaker:  output */
6241         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6242         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6243         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6244         /* Headphone output (output 0 - 0x0c) */
6245         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6246         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6247         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6248
6249         /* FIXME: use matrix-type input source selection */
6250         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6251         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6252         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6253         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6254         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6255         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6256         /* Input mixer2 */
6257         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6258         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6259         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6260         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6261         /* Input mixer3 */
6262         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6263         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6264         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6265         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6266         /* ADC1: mute amp left and right */
6267         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6268         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6269         /* ADC2: mute amp left and right */
6270         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6271         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6272         /* ADC3: mute amp left and right */
6273         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6274         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6275
6276         { }
6277 };
6278
6279 /* Macbook Pro rev3 */
6280 static struct hda_verb alc885_mbp3_init_verbs[] = {
6281         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6282         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6283         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6284         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6285         /* Rear mixer */
6286         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6287         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6288         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6289         /* Front Pin: output 0 (0x0c) */
6290         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6291         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6292         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6293         /* HP Pin: output 0 (0x0d) */
6294         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6295         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6296         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6297         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6298         /* Mic (rear) pin: input vref at 80% */
6299         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6300         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6301         /* Front Mic pin: input vref at 80% */
6302         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6303         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6304         /* Line In pin: use output 1 when in LineOut mode */
6305         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6306         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6307         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6308
6309         /* FIXME: use matrix-type input source selection */
6310         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6311         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6312         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6313         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6314         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6315         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6316         /* Input mixer2 */
6317         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6318         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6319         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6320         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6321         /* Input mixer3 */
6322         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6323         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6324         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6325         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6326         /* ADC1: mute amp left and right */
6327         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6328         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6329         /* ADC2: mute amp left and right */
6330         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6331         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6332         /* ADC3: mute amp left and right */
6333         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6334         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6335
6336         { }
6337 };
6338
6339 /* iMac 24 mixer. */
6340 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6341         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6342         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6343         { } /* end */
6344 };
6345
6346 /* iMac 24 init verbs. */
6347 static struct hda_verb alc885_imac24_init_verbs[] = {
6348         /* Internal speakers: output 0 (0x0c) */
6349         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6350         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6351         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6352         /* Internal speakers: output 0 (0x0c) */
6353         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6354         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6355         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6356         /* Headphone: output 0 (0x0c) */
6357         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6358         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6359         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6360         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6361         /* Front Mic: input vref at 80% */
6362         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6363         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6364         { }
6365 };
6366
6367 /* Toggle speaker-output according to the hp-jack state */
6368 static void alc885_imac24_automute(struct hda_codec *codec)
6369 {
6370         unsigned int present;
6371
6372         present = snd_hda_codec_read(codec, 0x14, 0,
6373                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6374         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6375                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6376         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6377                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6378 }
6379
6380 /* Processes unsolicited events. */
6381 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6382                                       unsigned int res)
6383 {
6384         /* Headphone insertion or removal. */
6385         if ((res >> 26) == ALC880_HP_EVENT)
6386                 alc885_imac24_automute(codec);
6387 }
6388
6389 static void alc885_mbp3_automute(struct hda_codec *codec)
6390 {
6391         unsigned int present;
6392
6393         present = snd_hda_codec_read(codec, 0x15, 0,
6394                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6395         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6396                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6397         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6398                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6399
6400 }
6401 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6402                                     unsigned int res)
6403 {
6404         /* Headphone insertion or removal. */
6405         if ((res >> 26) == ALC880_HP_EVENT)
6406                 alc885_mbp3_automute(codec);
6407 }
6408
6409
6410 static struct hda_verb alc882_targa_verbs[] = {
6411         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6412         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6413
6414         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6415         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6416
6417         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6418         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6419         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6420
6421         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6422         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6423         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6424         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6425         { } /* end */
6426 };
6427
6428 /* toggle speaker-output according to the hp-jack state */
6429 static void alc882_targa_automute(struct hda_codec *codec)
6430 {
6431         unsigned int present;
6432
6433         present = snd_hda_codec_read(codec, 0x14, 0,
6434                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6435         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6436                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6437         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6438                                   present ? 1 : 3);
6439 }
6440
6441 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6442 {
6443         /* Looks like the unsol event is incompatible with the standard
6444          * definition.  4bit tag is placed at 26 bit!
6445          */
6446         if (((res >> 26) == ALC880_HP_EVENT)) {
6447                 alc882_targa_automute(codec);
6448         }
6449 }
6450
6451 static struct hda_verb alc882_asus_a7j_verbs[] = {
6452         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6453         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6454
6455         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6456         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6457         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6458
6459         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6460         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6461         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6462
6463         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6464         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6465         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6466         { } /* end */
6467 };
6468
6469 static struct hda_verb alc882_asus_a7m_verbs[] = {
6470         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6471         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6472
6473         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6474         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6475         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6476
6477         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6478         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6479         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6480
6481         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6482         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6483         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6484         { } /* end */
6485 };
6486
6487 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6488 {
6489         unsigned int gpiostate, gpiomask, gpiodir;
6490
6491         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6492                                        AC_VERB_GET_GPIO_DATA, 0);
6493
6494         if (!muted)
6495                 gpiostate |= (1 << pin);
6496         else
6497                 gpiostate &= ~(1 << pin);
6498
6499         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6500                                       AC_VERB_GET_GPIO_MASK, 0);
6501         gpiomask |= (1 << pin);
6502
6503         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6504                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6505         gpiodir |= (1 << pin);
6506
6507
6508         snd_hda_codec_write(codec, codec->afg, 0,
6509                             AC_VERB_SET_GPIO_MASK, gpiomask);
6510         snd_hda_codec_write(codec, codec->afg, 0,
6511                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6512
6513         msleep(1);
6514
6515         snd_hda_codec_write(codec, codec->afg, 0,
6516                             AC_VERB_SET_GPIO_DATA, gpiostate);
6517 }
6518
6519 /* set up GPIO at initialization */
6520 static void alc885_macpro_init_hook(struct hda_codec *codec)
6521 {
6522         alc882_gpio_mute(codec, 0, 0);
6523         alc882_gpio_mute(codec, 1, 0);
6524 }
6525
6526 /* set up GPIO and update auto-muting at initialization */
6527 static void alc885_imac24_init_hook(struct hda_codec *codec)
6528 {
6529         alc885_macpro_init_hook(codec);
6530         alc885_imac24_automute(codec);
6531 }
6532
6533 /*
6534  * generic initialization of ADC, input mixers and output mixers
6535  */
6536 static struct hda_verb alc882_auto_init_verbs[] = {
6537         /*
6538          * Unmute ADC0-2 and set the default input to mic-in
6539          */
6540         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6541         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6542         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6543         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6544         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6545         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6546
6547         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6548          * mixer widget
6549          * Note: PASD motherboards uses the Line In 2 as the input for
6550          * front panel mic (mic 2)
6551          */
6552         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6553         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6554         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6555         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6556         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6557         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6558
6559         /*
6560          * Set up output mixers (0x0c - 0x0f)
6561          */
6562         /* set vol=0 to output mixers */
6563         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6564         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6565         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6566         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6567         /* set up input amps for analog loopback */
6568         /* Amp Indices: DAC = 0, mixer = 1 */
6569         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6570         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6571         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6572         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6573         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6574         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6575         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6576         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6577         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6578         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6579
6580         /* FIXME: use matrix-type input source selection */
6581         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6582         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6583         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6584         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6585         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6586         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6587         /* Input mixer2 */
6588         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6589         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6590         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6591         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6592         /* Input mixer3 */
6593         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6594         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6595         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6596         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6597
6598         { }
6599 };
6600
6601 #ifdef CONFIG_SND_HDA_POWER_SAVE
6602 #define alc882_loopbacks        alc880_loopbacks
6603 #endif
6604
6605 /* pcm configuration: identiacal with ALC880 */
6606 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6607 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6608 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6609 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6610
6611 /*
6612  * configuration and preset
6613  */
6614 static const char *alc882_models[ALC882_MODEL_LAST] = {
6615         [ALC882_3ST_DIG]        = "3stack-dig",
6616         [ALC882_6ST_DIG]        = "6stack-dig",
6617         [ALC882_ARIMA]          = "arima",
6618         [ALC882_W2JC]           = "w2jc",
6619         [ALC882_TARGA]          = "targa",
6620         [ALC882_ASUS_A7J]       = "asus-a7j",
6621         [ALC882_ASUS_A7M]       = "asus-a7m",
6622         [ALC885_MACPRO]         = "macpro",
6623         [ALC885_MBP3]           = "mbp3",
6624         [ALC885_IMAC24]         = "imac24",
6625         [ALC882_AUTO]           = "auto",
6626 };
6627
6628 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6629         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6630         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6631         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6632         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6633         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6634         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6635         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6636         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6637         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6638         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6639         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6640         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6641         {}
6642 };
6643
6644 static struct alc_config_preset alc882_presets[] = {
6645         [ALC882_3ST_DIG] = {
6646                 .mixers = { alc882_base_mixer },
6647                 .init_verbs = { alc882_init_verbs },
6648                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6649                 .dac_nids = alc882_dac_nids,
6650                 .dig_out_nid = ALC882_DIGOUT_NID,
6651                 .dig_in_nid = ALC882_DIGIN_NID,
6652                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6653                 .channel_mode = alc882_ch_modes,
6654                 .need_dac_fix = 1,
6655                 .input_mux = &alc882_capture_source,
6656         },
6657         [ALC882_6ST_DIG] = {
6658                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6659                 .init_verbs = { alc882_init_verbs },
6660                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6661                 .dac_nids = alc882_dac_nids,
6662                 .dig_out_nid = ALC882_DIGOUT_NID,
6663                 .dig_in_nid = ALC882_DIGIN_NID,
6664                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6665                 .channel_mode = alc882_sixstack_modes,
6666                 .input_mux = &alc882_capture_source,
6667         },
6668         [ALC882_ARIMA] = {
6669                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6670                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6671                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6672                 .dac_nids = alc882_dac_nids,
6673                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6674                 .channel_mode = alc882_sixstack_modes,
6675                 .input_mux = &alc882_capture_source,
6676         },
6677         [ALC882_W2JC] = {
6678                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6679                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6680                                 alc880_gpio1_init_verbs },
6681                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6682                 .dac_nids = alc882_dac_nids,
6683                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6684                 .channel_mode = alc880_threestack_modes,
6685                 .need_dac_fix = 1,
6686                 .input_mux = &alc882_capture_source,
6687                 .dig_out_nid = ALC882_DIGOUT_NID,
6688         },
6689         [ALC885_MBP3] = {
6690                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6691                 .init_verbs = { alc885_mbp3_init_verbs,
6692                                 alc880_gpio1_init_verbs },
6693                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6694                 .dac_nids = alc882_dac_nids,
6695                 .channel_mode = alc885_mbp_6ch_modes,
6696                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6697                 .input_mux = &alc882_capture_source,
6698                 .dig_out_nid = ALC882_DIGOUT_NID,
6699                 .dig_in_nid = ALC882_DIGIN_NID,
6700                 .unsol_event = alc885_mbp3_unsol_event,
6701                 .init_hook = alc885_mbp3_automute,
6702         },
6703         [ALC885_MACPRO] = {
6704                 .mixers = { alc882_macpro_mixer },
6705                 .init_verbs = { alc882_macpro_init_verbs },
6706                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6707                 .dac_nids = alc882_dac_nids,
6708                 .dig_out_nid = ALC882_DIGOUT_NID,
6709                 .dig_in_nid = ALC882_DIGIN_NID,
6710                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6711                 .channel_mode = alc882_ch_modes,
6712                 .input_mux = &alc882_capture_source,
6713                 .init_hook = alc885_macpro_init_hook,
6714         },
6715         [ALC885_IMAC24] = {
6716                 .mixers = { alc885_imac24_mixer },
6717                 .init_verbs = { alc885_imac24_init_verbs },
6718                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6719                 .dac_nids = alc882_dac_nids,
6720                 .dig_out_nid = ALC882_DIGOUT_NID,
6721                 .dig_in_nid = ALC882_DIGIN_NID,
6722                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6723                 .channel_mode = alc882_ch_modes,
6724                 .input_mux = &alc882_capture_source,
6725                 .unsol_event = alc885_imac24_unsol_event,
6726                 .init_hook = alc885_imac24_init_hook,
6727         },
6728         [ALC882_TARGA] = {
6729                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
6730                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6731                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6732                 .dac_nids = alc882_dac_nids,
6733                 .dig_out_nid = ALC882_DIGOUT_NID,
6734                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6735                 .adc_nids = alc882_adc_nids,
6736                 .capsrc_nids = alc882_capsrc_nids,
6737                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6738                 .channel_mode = alc882_3ST_6ch_modes,
6739                 .need_dac_fix = 1,
6740                 .input_mux = &alc882_capture_source,
6741                 .unsol_event = alc882_targa_unsol_event,
6742                 .init_hook = alc882_targa_automute,
6743         },
6744         [ALC882_ASUS_A7J] = {
6745                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
6746                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6747                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6748                 .dac_nids = alc882_dac_nids,
6749                 .dig_out_nid = ALC882_DIGOUT_NID,
6750                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6751                 .adc_nids = alc882_adc_nids,
6752                 .capsrc_nids = alc882_capsrc_nids,
6753                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6754                 .channel_mode = alc882_3ST_6ch_modes,
6755                 .need_dac_fix = 1,
6756                 .input_mux = &alc882_capture_source,
6757         },
6758         [ALC882_ASUS_A7M] = {
6759                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6760                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6761                                 alc880_gpio1_init_verbs,
6762                                 alc882_asus_a7m_verbs },
6763                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6764                 .dac_nids = alc882_dac_nids,
6765                 .dig_out_nid = ALC882_DIGOUT_NID,
6766                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6767                 .channel_mode = alc880_threestack_modes,
6768                 .need_dac_fix = 1,
6769                 .input_mux = &alc882_capture_source,
6770         },
6771 };
6772
6773
6774 /*
6775  * Pin config fixes
6776  */
6777 enum {
6778         PINFIX_ABIT_AW9D_MAX
6779 };
6780
6781 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6782         { 0x15, 0x01080104 }, /* side */
6783         { 0x16, 0x01011012 }, /* rear */
6784         { 0x17, 0x01016011 }, /* clfe */
6785         { }
6786 };
6787
6788 static const struct alc_pincfg *alc882_pin_fixes[] = {
6789         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6790 };
6791
6792 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6793         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6794         {}
6795 };
6796
6797 /*
6798  * BIOS auto configuration
6799  */
6800 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6801                                               hda_nid_t nid, int pin_type,
6802                                               int dac_idx)
6803 {
6804         /* set as output */
6805         struct alc_spec *spec = codec->spec;
6806         int idx;
6807
6808         alc_set_pin_output(codec, nid, pin_type);
6809         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6810                 idx = 4;
6811         else
6812                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6813         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6814
6815 }
6816
6817 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6818 {
6819         struct alc_spec *spec = codec->spec;
6820         int i;
6821
6822         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6823         for (i = 0; i <= HDA_SIDE; i++) {
6824                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6825                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6826                 if (nid)
6827                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6828                                                           i);
6829         }
6830 }
6831
6832 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6833 {
6834         struct alc_spec *spec = codec->spec;
6835         hda_nid_t pin;
6836
6837         pin = spec->autocfg.hp_pins[0];
6838         if (pin) /* connect to front */
6839                 /* use dac 0 */
6840                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6841         pin = spec->autocfg.speaker_pins[0];
6842         if (pin)
6843                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6844 }
6845
6846 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6847 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6848
6849 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6850 {
6851         struct alc_spec *spec = codec->spec;
6852         int i;
6853
6854         for (i = 0; i < AUTO_PIN_LAST; i++) {
6855                 hda_nid_t nid = spec->autocfg.input_pins[i];
6856                 unsigned int vref;
6857                 if (!nid)
6858                         continue;
6859                 vref = PIN_IN;
6860                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6861                         unsigned int pincap;
6862                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6863                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6864                             AC_PINCAP_VREF_80)
6865                                 vref = PIN_VREF80;
6866                 }
6867                 snd_hda_codec_write(codec, nid, 0,
6868                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6869                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6870                         snd_hda_codec_write(codec, nid, 0,
6871                                             AC_VERB_SET_AMP_GAIN_MUTE,
6872                                             AMP_OUT_MUTE);
6873         }
6874 }
6875
6876 static void alc882_auto_init_input_src(struct hda_codec *codec)
6877 {
6878         struct alc_spec *spec = codec->spec;
6879         const struct hda_input_mux *imux = spec->input_mux;
6880         int c;
6881
6882         for (c = 0; c < spec->num_adc_nids; c++) {
6883                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6884                 hda_nid_t nid = spec->capsrc_nids[c];
6885                 int conns, mute, idx, item;
6886
6887                 conns = snd_hda_get_connections(codec, nid, conn_list,
6888                                                 ARRAY_SIZE(conn_list));
6889                 if (conns < 0)
6890                         continue;
6891                 for (idx = 0; idx < conns; idx++) {
6892                         /* if the current connection is the selected one,
6893                          * unmute it as default - otherwise mute it
6894                          */
6895                         mute = AMP_IN_MUTE(idx);
6896                         for (item = 0; item < imux->num_items; item++) {
6897                                 if (imux->items[item].index == idx) {
6898                                         if (spec->cur_mux[c] == item)
6899                                                 mute = AMP_IN_UNMUTE(idx);
6900                                         break;
6901                                 }
6902                         }
6903                         snd_hda_codec_write(codec, nid, 0,
6904                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6905                 }
6906         }
6907 }
6908
6909 /* add mic boosts if needed */
6910 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6911 {
6912         struct alc_spec *spec = codec->spec;
6913         int err;
6914         hda_nid_t nid;
6915
6916         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6917         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6918                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6919                                   "Mic Boost",
6920                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6921                 if (err < 0)
6922                         return err;
6923         }
6924         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6925         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6926                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6927                                   "Front Mic Boost",
6928                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6929                 if (err < 0)
6930                         return err;
6931         }
6932         return 0;
6933 }
6934
6935 /* almost identical with ALC880 parser... */
6936 static int alc882_parse_auto_config(struct hda_codec *codec)
6937 {
6938         struct alc_spec *spec = codec->spec;
6939         int err = alc880_parse_auto_config(codec);
6940
6941         if (err < 0)
6942                 return err;
6943         else if (!err)
6944                 return 0; /* no config found */
6945
6946         err = alc_auto_add_mic_boost(codec);
6947         if (err < 0)
6948                 return err;
6949
6950         /* hack - override the init verbs */
6951         spec->init_verbs[0] = alc882_auto_init_verbs;
6952
6953         return 1; /* config found */
6954 }
6955
6956 /* additional initialization for auto-configuration model */
6957 static void alc882_auto_init(struct hda_codec *codec)
6958 {
6959         struct alc_spec *spec = codec->spec;
6960         alc882_auto_init_multi_out(codec);
6961         alc882_auto_init_hp_out(codec);
6962         alc882_auto_init_analog_input(codec);
6963         alc882_auto_init_input_src(codec);
6964         if (spec->unsol_event)
6965                 alc_inithook(codec);
6966 }
6967
6968 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6969
6970 static int patch_alc882(struct hda_codec *codec)
6971 {
6972         struct alc_spec *spec;
6973         int err, board_config;
6974
6975         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6976         if (spec == NULL)
6977                 return -ENOMEM;
6978
6979         codec->spec = spec;
6980
6981         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6982                                                   alc882_models,
6983                                                   alc882_cfg_tbl);
6984
6985         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6986                 /* Pick up systems that don't supply PCI SSID */
6987                 switch (codec->subsystem_id) {
6988                 case 0x106b0c00: /* Mac Pro */
6989                         board_config = ALC885_MACPRO;
6990                         break;
6991                 case 0x106b1000: /* iMac 24 */
6992                 case 0x106b2800: /* AppleTV */
6993                         board_config = ALC885_IMAC24;
6994                         break;
6995                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
6996                 case 0x106b00a4: /* MacbookPro4,1 */
6997                 case 0x106b2c00: /* Macbook Pro rev3 */
6998                 case 0x106b3600: /* Macbook 3.1 */
6999                         board_config = ALC885_MBP3;
7000                         break;
7001                 default:
7002                         /* ALC889A is handled better as ALC888-compatible */
7003                         if (codec->revision_id == 0x100101 ||
7004                             codec->revision_id == 0x100103) {
7005                                 alc_free(codec);
7006                                 return patch_alc883(codec);
7007                         }
7008                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
7009                                          "trying auto-probe from BIOS...\n");
7010                         board_config = ALC882_AUTO;
7011                 }
7012         }
7013
7014         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7015
7016         if (board_config == ALC882_AUTO) {
7017                 /* automatic parse from the BIOS config */
7018                 err = alc882_parse_auto_config(codec);
7019                 if (err < 0) {
7020                         alc_free(codec);
7021                         return err;
7022                 } else if (!err) {
7023                         printk(KERN_INFO
7024                                "hda_codec: Cannot set up configuration "
7025                                "from BIOS.  Using base mode...\n");
7026                         board_config = ALC882_3ST_DIG;
7027                 }
7028         }
7029
7030         if (board_config != ALC882_AUTO)
7031                 setup_preset(spec, &alc882_presets[board_config]);
7032
7033         if (codec->vendor_id == 0x10ec0885) {
7034                 spec->stream_name_analog = "ALC885 Analog";
7035                 spec->stream_name_digital = "ALC885 Digital";
7036         } else {
7037                 spec->stream_name_analog = "ALC882 Analog";
7038                 spec->stream_name_digital = "ALC882 Digital";
7039         }
7040
7041         spec->stream_analog_playback = &alc882_pcm_analog_playback;
7042         spec->stream_analog_capture = &alc882_pcm_analog_capture;
7043         /* FIXME: setup DAC5 */
7044         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7045         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7046
7047         spec->stream_digital_playback = &alc882_pcm_digital_playback;
7048         spec->stream_digital_capture = &alc882_pcm_digital_capture;
7049
7050         spec->is_mix_capture = 1; /* matrix-style capture */
7051         if (!spec->adc_nids && spec->input_mux) {
7052                 /* check whether NID 0x07 is valid */
7053                 unsigned int wcap = get_wcaps(codec, 0x07);
7054                 /* get type */
7055                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7056                 if (wcap != AC_WID_AUD_IN) {
7057                         spec->adc_nids = alc882_adc_nids_alt;
7058                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7059                         spec->capsrc_nids = alc882_capsrc_nids_alt;
7060                 } else {
7061                         spec->adc_nids = alc882_adc_nids;
7062                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7063                         spec->capsrc_nids = alc882_capsrc_nids;
7064                 }
7065         }
7066         set_capture_mixer(spec);
7067
7068         spec->vmaster_nid = 0x0c;
7069
7070         codec->patch_ops = alc_patch_ops;
7071         if (board_config == ALC882_AUTO)
7072                 spec->init_hook = alc882_auto_init;
7073 #ifdef CONFIG_SND_HDA_POWER_SAVE
7074         if (!spec->loopback.amplist)
7075                 spec->loopback.amplist = alc882_loopbacks;
7076 #endif
7077
7078         return 0;
7079 }
7080
7081 /*
7082  * ALC883 support
7083  *
7084  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7085  * configuration.  Each pin widget can choose any input DACs and a mixer.
7086  * Each ADC is connected from a mixer of all inputs.  This makes possible
7087  * 6-channel independent captures.
7088  *
7089  * In addition, an independent DAC for the multi-playback (not used in this
7090  * driver yet).
7091  */
7092 #define ALC883_DIGOUT_NID       0x06
7093 #define ALC883_DIGIN_NID        0x0a
7094
7095 #define ALC1200_DIGOUT_NID      0x10
7096
7097 static hda_nid_t alc883_dac_nids[4] = {
7098         /* front, rear, clfe, rear_surr */
7099         0x02, 0x03, 0x04, 0x05
7100 };
7101
7102 static hda_nid_t alc883_adc_nids[2] = {
7103         /* ADC1-2 */
7104         0x08, 0x09,
7105 };
7106
7107 static hda_nid_t alc883_adc_nids_alt[1] = {
7108         /* ADC1 */
7109         0x08,
7110 };
7111
7112 static hda_nid_t alc883_adc_nids_rev[2] = {
7113         /* ADC2-1 */
7114         0x09, 0x08
7115 };
7116
7117 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7118
7119 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7120
7121 /* input MUX */
7122 /* FIXME: should be a matrix-type input source selection */
7123
7124 static struct hda_input_mux alc883_capture_source = {
7125         .num_items = 4,
7126         .items = {
7127                 { "Mic", 0x0 },
7128                 { "Front Mic", 0x1 },
7129                 { "Line", 0x2 },
7130                 { "CD", 0x4 },
7131         },
7132 };
7133
7134 static struct hda_input_mux alc883_3stack_6ch_intel = {
7135         .num_items = 4,
7136         .items = {
7137                 { "Mic", 0x1 },
7138                 { "Front Mic", 0x0 },
7139                 { "Line", 0x2 },
7140                 { "CD", 0x4 },
7141         },
7142 };
7143
7144 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7145         .num_items = 2,
7146         .items = {
7147                 { "Mic", 0x1 },
7148                 { "Line", 0x2 },
7149         },
7150 };
7151
7152 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7153         .num_items = 4,
7154         .items = {
7155                 { "Mic", 0x0 },
7156                 { "iMic", 0x1 },
7157                 { "Line", 0x2 },
7158                 { "CD", 0x4 },
7159         },
7160 };
7161
7162 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7163         .num_items = 2,
7164         .items = {
7165                 { "Mic", 0x0 },
7166                 { "Int Mic", 0x1 },
7167         },
7168 };
7169
7170 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7171         .num_items = 3,
7172         .items = {
7173                 { "Mic", 0x0 },
7174                 { "Front Mic", 0x1 },
7175                 { "Line", 0x4 },
7176         },
7177 };
7178
7179 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7180         .num_items = 2,
7181         .items = {
7182                 { "Mic", 0x0 },
7183                 { "Line", 0x2 },
7184         },
7185 };
7186
7187 /*
7188  * 2ch mode
7189  */
7190 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7191         { 2, NULL }
7192 };
7193
7194 /*
7195  * 2ch mode
7196  */
7197 static struct hda_verb alc883_3ST_ch2_init[] = {
7198         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7199         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7200         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7201         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7202         { } /* end */
7203 };
7204
7205 /*
7206  * 4ch mode
7207  */
7208 static struct hda_verb alc883_3ST_ch4_init[] = {
7209         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7210         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7211         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7212         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7213         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7214         { } /* end */
7215 };
7216
7217 /*
7218  * 6ch mode
7219  */
7220 static struct hda_verb alc883_3ST_ch6_init[] = {
7221         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7222         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7223         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7224         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7225         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7226         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7227         { } /* end */
7228 };
7229
7230 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7231         { 2, alc883_3ST_ch2_init },
7232         { 4, alc883_3ST_ch4_init },
7233         { 6, alc883_3ST_ch6_init },
7234 };
7235
7236 /*
7237  * 2ch mode
7238  */
7239 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7240         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7241         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7242         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7243         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7244         { } /* end */
7245 };
7246
7247 /*
7248  * 4ch mode
7249  */
7250 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7251         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7252         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7253         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7254         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7255         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7256         { } /* end */
7257 };
7258
7259 /*
7260  * 6ch mode
7261  */
7262 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7263         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7264         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7265         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7266         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7267         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7268         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7269         { } /* end */
7270 };
7271
7272 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7273         { 2, alc883_3ST_ch2_intel_init },
7274         { 4, alc883_3ST_ch4_intel_init },
7275         { 6, alc883_3ST_ch6_intel_init },
7276 };
7277
7278 /*
7279  * 6ch mode
7280  */
7281 static struct hda_verb alc883_sixstack_ch6_init[] = {
7282         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7283         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7284         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7285         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7286         { } /* end */
7287 };
7288
7289 /*
7290  * 8ch mode
7291  */
7292 static struct hda_verb alc883_sixstack_ch8_init[] = {
7293         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7294         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7295         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7296         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7297         { } /* end */
7298 };
7299
7300 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7301         { 6, alc883_sixstack_ch6_init },
7302         { 8, alc883_sixstack_ch8_init },
7303 };
7304
7305 static struct hda_verb alc883_medion_eapd_verbs[] = {
7306         /* eanable EAPD on medion laptop */
7307         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7308         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7309         { }
7310 };
7311
7312 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7313  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7314  */
7315
7316 static struct snd_kcontrol_new alc883_base_mixer[] = {
7317         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7318         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7319         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7320         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7321         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7322         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7323         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7324         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7325         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7326         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7327         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7328         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7329         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7330         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7331         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7332         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7333         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7334         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7335         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7336         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7337         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7338         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7339         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7340         { } /* end */
7341 };
7342
7343 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7344         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7345         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7346         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7347         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7348         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7349         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7350         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7351         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7352         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7353         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7354         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7355         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7356         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7357         { } /* end */
7358 };
7359
7360 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7361         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7362         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7363         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7364         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7365         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7366         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7367         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7368         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7369         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7370         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7371         { } /* end */
7372 };
7373
7374 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7375         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7376         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7377         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7378         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
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("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7383         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7384         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7385         { } /* end */
7386 };
7387
7388 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7389         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7390         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7391         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7392         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7393         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7394         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7395         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7396         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7397         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7398         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7399         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7400         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7401         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7402         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7403         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7404         { } /* end */
7405 };
7406
7407 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7408         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7409         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7410         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7411         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7412         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7413         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7414         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7415         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7416         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7417         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7418         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7419         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7420         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7421         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7422         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7423         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7424         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7425         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7426         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7427         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7428         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7429         { } /* end */
7430 };
7431
7432 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7433         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7434         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7435         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7436         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7437         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7438                               HDA_OUTPUT),
7439         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7440         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7441         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7442         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7443         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7444         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7445         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7446         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7447         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7448         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7449         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7450         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7451         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7452         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7453         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7454         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7455         { } /* end */
7456 };
7457
7458 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7459         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7460         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7461         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7462         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7463         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7464         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7465         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7466         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7467         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7468         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7469         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7470         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7471         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7472         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7473         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7474         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7475         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7476         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7477         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7478         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7479         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7480         { } /* end */
7481 };
7482
7483 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7484         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7485         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7486         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7487         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7488         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7489         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7490         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7491         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7492         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7493         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7494         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7495         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7496         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7497         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7498         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7499         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7500         { } /* end */
7501 };
7502
7503 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7504         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7505         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7506         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7507         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7508         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7509         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7510         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7511         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7512         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7513         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7514         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7515         { } /* end */
7516 };
7517
7518 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7519         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7520         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7521         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7522         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7523         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7524         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7525         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7526         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7527         { } /* end */
7528 };
7529
7530 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7531         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7532         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7533         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7534         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7535         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7536         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7537         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7538         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7539         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7540         { } /* end */
7541 };
7542
7543 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7544         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7545         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7546         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7547         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7548         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7549         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7550         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7551         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7552         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7553         { } /* end */
7554 };
7555
7556 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7557         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7558         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7559         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7560         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7561         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7562         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7563         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7564         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7565         { } /* end */
7566 };
7567
7568 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7569         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7570         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7571         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7572         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7573         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7574                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7575         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7576         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7577         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7578         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7579         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7580         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7581         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7582         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7583         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7584         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7585         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7586         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7587         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7588         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7589         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7590         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7591         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7592         { } /* end */
7593 };
7594
7595 static struct hda_bind_ctls alc883_bind_cap_vol = {
7596         .ops = &snd_hda_bind_vol,
7597         .values = {
7598                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7599                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7600                 0
7601         },
7602 };
7603
7604 static struct hda_bind_ctls alc883_bind_cap_switch = {
7605         .ops = &snd_hda_bind_sw,
7606         .values = {
7607                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7608                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7609                 0
7610         },
7611 };
7612
7613 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7614         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7615         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7616         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7617         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7618         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7619         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7620         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7621         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7622         { } /* end */
7623 };
7624
7625 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
7626         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7627         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7628         {
7629                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7630                 /* .name = "Capture Source", */
7631                 .name = "Input Source",
7632                 .count = 1,
7633                 .info = alc_mux_enum_info,
7634                 .get = alc_mux_enum_get,
7635                 .put = alc_mux_enum_put,
7636         },
7637         { } /* end */
7638 };
7639
7640 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7641         {
7642                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7643                 .name = "Channel Mode",
7644                 .info = alc_ch_mode_info,
7645                 .get = alc_ch_mode_get,
7646                 .put = alc_ch_mode_put,
7647         },
7648         { } /* end */
7649 };
7650
7651 static struct hda_verb alc883_init_verbs[] = {
7652         /* ADC1: mute amp left and right */
7653         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7654         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7655         /* ADC2: mute amp left and right */
7656         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7657         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7658         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7659         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7660         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7661         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7662         /* Rear mixer */
7663         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7664         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7665         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7666         /* CLFE mixer */
7667         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7668         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7669         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7670         /* Side mixer */
7671         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7672         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7673         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7674
7675         /* mute analog input loopbacks */
7676         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7677         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7678         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7679         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7680         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7681
7682         /* Front Pin: output 0 (0x0c) */
7683         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7684         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7685         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7686         /* Rear Pin: output 1 (0x0d) */
7687         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7688         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7689         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7690         /* CLFE Pin: output 2 (0x0e) */
7691         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7692         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7693         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7694         /* Side Pin: output 3 (0x0f) */
7695         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7696         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7697         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7698         /* Mic (rear) pin: input vref at 80% */
7699         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7700         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7701         /* Front Mic pin: input vref at 80% */
7702         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7703         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7704         /* Line In pin: input */
7705         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7706         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7707         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7708         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7709         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7710         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7711         /* CD pin widget for input */
7712         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7713
7714         /* FIXME: use matrix-type input source selection */
7715         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7716         /* Input mixer2 */
7717         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7718         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7719         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7720         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7721         /* Input mixer3 */
7722         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7723         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7724         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7725         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7726         { }
7727 };
7728
7729 /* toggle speaker-output according to the hp-jack state */
7730 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7731 {
7732         unsigned int present;
7733
7734         present = snd_hda_codec_read(codec, 0x15, 0,
7735                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7736         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7737                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7738         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7739                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7740 }
7741
7742 /* auto-toggle front mic */
7743 /*
7744 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7745 {
7746         unsigned int present;
7747         unsigned char bits;
7748
7749         present = snd_hda_codec_read(codec, 0x18, 0,
7750                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7751         bits = present ? HDA_AMP_MUTE : 0;
7752         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7753 }
7754 */
7755
7756 static void alc883_mitac_automute(struct hda_codec *codec)
7757 {
7758         alc883_mitac_hp_automute(codec);
7759         /* alc883_mitac_mic_automute(codec); */
7760 }
7761
7762 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7763                                            unsigned int res)
7764 {
7765         switch (res >> 26) {
7766         case ALC880_HP_EVENT:
7767                 alc883_mitac_hp_automute(codec);
7768                 break;
7769         case ALC880_MIC_EVENT:
7770                 /* alc883_mitac_mic_automute(codec); */
7771                 break;
7772         }
7773 }
7774
7775 static struct hda_verb alc883_mitac_verbs[] = {
7776         /* HP */
7777         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7778         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7779         /* Subwoofer */
7780         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7781         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7782
7783         /* enable unsolicited event */
7784         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7785         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7786
7787         { } /* end */
7788 };
7789
7790 static struct hda_verb alc883_clevo_m720_verbs[] = {
7791         /* HP */
7792         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7793         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7794         /* Int speaker */
7795         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7796         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7797
7798         /* enable unsolicited event */
7799         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7800         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7801
7802         { } /* end */
7803 };
7804
7805 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7806         /* HP */
7807         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7808         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7809         /* Subwoofer */
7810         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7811         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7812
7813         /* enable unsolicited event */
7814         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7815
7816         { } /* end */
7817 };
7818
7819 static struct hda_verb alc883_tagra_verbs[] = {
7820         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7821         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7822
7823         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7824         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7825
7826         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7827         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7828         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7829
7830         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7831         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7832         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7833         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7834
7835         { } /* end */
7836 };
7837
7838 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7839         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7840         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7841         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7842         { } /* end */
7843 };
7844
7845 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7846         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7847         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7848         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7849         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7850         { } /* end */
7851 };
7852
7853 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7854         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7855         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7856         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7857         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7858         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7859         { } /* end */
7860 };
7861
7862 static struct hda_verb alc883_haier_w66_verbs[] = {
7863         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7864         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7865
7866         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7867
7868         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7869         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7870         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7871         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7872         { } /* end */
7873 };
7874
7875 static struct hda_verb alc888_lenovo_sky_verbs[] = {
7876         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7877         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7878         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7879         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7880         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7881         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7882         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7883         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7884         { } /* end */
7885 };
7886
7887 static struct hda_verb alc888_3st_hp_verbs[] = {
7888         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7889         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7890         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7891         { }
7892 };
7893
7894 static struct hda_verb alc888_6st_dell_verbs[] = {
7895         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7896         { }
7897 };
7898
7899 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7900         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7901         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7902         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7903         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7904         { }
7905 };
7906
7907 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7908         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7909         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7910         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7911         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7912         { }
7913 };
7914
7915 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7916         { 2, alc888_3st_hp_2ch_init },
7917         { 6, alc888_3st_hp_6ch_init },
7918 };
7919
7920 /* toggle front-jack and RCA according to the hp-jack state */
7921 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7922 {
7923         unsigned int present;
7924
7925         present = snd_hda_codec_read(codec, 0x1b, 0,
7926                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7927         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7928                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7929         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7930                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7931 }
7932
7933 /* toggle RCA according to the front-jack state */
7934 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7935 {
7936         unsigned int present;
7937
7938         present = snd_hda_codec_read(codec, 0x14, 0,
7939                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7940         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7941                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7942 }
7943
7944 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7945                                              unsigned int res)
7946 {
7947         if ((res >> 26) == ALC880_HP_EVENT)
7948                 alc888_lenovo_ms7195_front_automute(codec);
7949         if ((res >> 26) == ALC880_FRONT_EVENT)
7950                 alc888_lenovo_ms7195_rca_automute(codec);
7951 }
7952
7953 static struct hda_verb alc883_medion_md2_verbs[] = {
7954         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7955         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7956
7957         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7958
7959         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7960         { } /* end */
7961 };
7962
7963 /* toggle speaker-output according to the hp-jack state */
7964 static void alc883_medion_md2_automute(struct hda_codec *codec)
7965 {
7966         unsigned int present;
7967
7968         present = snd_hda_codec_read(codec, 0x14, 0,
7969                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7970         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7971                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7972 }
7973
7974 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7975                                           unsigned int res)
7976 {
7977         if ((res >> 26) == ALC880_HP_EVENT)
7978                 alc883_medion_md2_automute(codec);
7979 }
7980
7981 /* toggle speaker-output according to the hp-jack state */
7982 static void alc883_tagra_automute(struct hda_codec *codec)
7983 {
7984         unsigned int present;
7985         unsigned char bits;
7986
7987         present = snd_hda_codec_read(codec, 0x14, 0,
7988                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7989         bits = present ? HDA_AMP_MUTE : 0;
7990         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7991                                  HDA_AMP_MUTE, bits);
7992         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7993                                   present ? 1 : 3);
7994 }
7995
7996 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7997 {
7998         if ((res >> 26) == ALC880_HP_EVENT)
7999                 alc883_tagra_automute(codec);
8000 }
8001
8002 /* toggle speaker-output according to the hp-jack state */
8003 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
8004 {
8005         unsigned int present;
8006         unsigned char bits;
8007
8008         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
8009                 & AC_PINSENSE_PRESENCE;
8010         bits = present ? HDA_AMP_MUTE : 0;
8011         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8012                                  HDA_AMP_MUTE, bits);
8013 }
8014
8015 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8016 {
8017         unsigned int present;
8018
8019         present = snd_hda_codec_read(codec, 0x18, 0,
8020                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8021         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8022                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8023 }
8024
8025 static void alc883_clevo_m720_automute(struct hda_codec *codec)
8026 {
8027         alc883_clevo_m720_hp_automute(codec);
8028         alc883_clevo_m720_mic_automute(codec);
8029 }
8030
8031 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8032                                            unsigned int res)
8033 {
8034         switch (res >> 26) {
8035         case ALC880_HP_EVENT:
8036                 alc883_clevo_m720_hp_automute(codec);
8037                 break;
8038         case ALC880_MIC_EVENT:
8039                 alc883_clevo_m720_mic_automute(codec);
8040                 break;
8041         }
8042 }
8043
8044 /* toggle speaker-output according to the hp-jack state */
8045 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
8046 {
8047         unsigned int present;
8048         unsigned char bits;
8049
8050         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8051                 & AC_PINSENSE_PRESENCE;
8052         bits = present ? HDA_AMP_MUTE : 0;
8053         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8054                                  HDA_AMP_MUTE, bits);
8055 }
8056
8057 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
8058                                                   unsigned int res)
8059 {
8060         if ((res >> 26) == ALC880_HP_EVENT)
8061                 alc883_2ch_fujitsu_pi2515_automute(codec);
8062 }
8063
8064 static void alc883_haier_w66_automute(struct hda_codec *codec)
8065 {
8066         unsigned int present;
8067         unsigned char bits;
8068
8069         present = snd_hda_codec_read(codec, 0x1b, 0,
8070                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8071         bits = present ? 0x80 : 0;
8072         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8073                                  0x80, bits);
8074 }
8075
8076 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
8077                                          unsigned int res)
8078 {
8079         if ((res >> 26) == ALC880_HP_EVENT)
8080                 alc883_haier_w66_automute(codec);
8081 }
8082
8083 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8084 {
8085         unsigned int present;
8086         unsigned char bits;
8087
8088         present = snd_hda_codec_read(codec, 0x14, 0,
8089                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8090         bits = present ? HDA_AMP_MUTE : 0;
8091         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8092                                  HDA_AMP_MUTE, bits);
8093 }
8094
8095 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8096 {
8097         unsigned int present;
8098         unsigned char bits;
8099
8100         present = snd_hda_codec_read(codec, 0x1b, 0,
8101                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8102         bits = present ? HDA_AMP_MUTE : 0;
8103         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8104                                  HDA_AMP_MUTE, bits);
8105         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8106                                  HDA_AMP_MUTE, bits);
8107 }
8108
8109 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8110                                            unsigned int res)
8111 {
8112         if ((res >> 26) == ALC880_HP_EVENT)
8113                 alc883_lenovo_101e_all_automute(codec);
8114         if ((res >> 26) == ALC880_FRONT_EVENT)
8115                 alc883_lenovo_101e_ispeaker_automute(codec);
8116 }
8117
8118 /* toggle speaker-output according to the hp-jack state */
8119 static void alc883_acer_aspire_automute(struct hda_codec *codec)
8120 {
8121         unsigned int present;
8122
8123         present = snd_hda_codec_read(codec, 0x14, 0,
8124                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8125         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8126                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8127         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8128                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8129 }
8130
8131 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
8132                                            unsigned int res)
8133 {
8134         if ((res >> 26) == ALC880_HP_EVENT)
8135                 alc883_acer_aspire_automute(codec);
8136 }
8137
8138 static struct hda_verb alc883_acer_eapd_verbs[] = {
8139         /* HP Pin: output 0 (0x0c) */
8140         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8141         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8142         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8143         /* Front Pin: output 0 (0x0c) */
8144         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8145         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8146         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8147         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8148         /* eanable EAPD on medion laptop */
8149         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8150         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8151         /* enable unsolicited event */
8152         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8153         { }
8154 };
8155
8156 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
8157 {
8158         unsigned int present;
8159
8160         present = snd_hda_codec_read(codec, 0x1b, 0,
8161                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8162         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8163                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8164         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8165                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8166         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8167                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8168         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8169                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8170 }
8171
8172 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8173                                              unsigned int res)
8174 {
8175         switch (res >> 26) {
8176         case ALC880_HP_EVENT:
8177                 printk("hp_event\n");
8178                 alc888_6st_dell_front_automute(codec);
8179                 break;
8180         }
8181 }
8182
8183 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8184 {
8185         unsigned int mute;
8186         unsigned int present;
8187
8188         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8189         present = snd_hda_codec_read(codec, 0x1b, 0,
8190                                      AC_VERB_GET_PIN_SENSE, 0);
8191         present = (present & 0x80000000) != 0;
8192         if (present) {
8193                 /* mute internal speaker */
8194                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8195                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8196                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8197                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8198                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8199                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8200                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8201                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8202                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8203                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8204         } else {
8205                 /* unmute internal speaker if necessary */
8206                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8207                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8208                                          HDA_AMP_MUTE, mute);
8209                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8210                                          HDA_AMP_MUTE, mute);
8211                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8212                                          HDA_AMP_MUTE, mute);
8213                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8214                                          HDA_AMP_MUTE, mute);
8215                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8216                                          HDA_AMP_MUTE, mute);
8217         }
8218 }
8219
8220 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8221                                              unsigned int res)
8222 {
8223         if ((res >> 26) == ALC880_HP_EVENT)
8224                 alc888_lenovo_sky_front_automute(codec);
8225 }
8226
8227 /*
8228  * generic initialization of ADC, input mixers and output mixers
8229  */
8230 static struct hda_verb alc883_auto_init_verbs[] = {
8231         /*
8232          * Unmute ADC0-2 and set the default input to mic-in
8233          */
8234         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8235         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8236         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8237         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8238
8239         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8240          * mixer widget
8241          * Note: PASD motherboards uses the Line In 2 as the input for
8242          * front panel mic (mic 2)
8243          */
8244         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8245         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8246         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8247         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8248         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8249         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8250
8251         /*
8252          * Set up output mixers (0x0c - 0x0f)
8253          */
8254         /* set vol=0 to output mixers */
8255         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8256         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8257         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8258         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8259         /* set up input amps for analog loopback */
8260         /* Amp Indices: DAC = 0, mixer = 1 */
8261         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8262         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8263         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8264         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8265         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8266         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8267         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8268         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8269         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8270         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8271
8272         /* FIXME: use matrix-type input source selection */
8273         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8274         /* Input mixer1 */
8275         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8276         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8277         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8278         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8279         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8280         /* Input mixer2 */
8281         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8282         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8283         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8284         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8285         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8286
8287         { }
8288 };
8289
8290 static struct hda_verb alc888_asus_m90v_verbs[] = {
8291         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8292         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8293         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8294         /* enable unsolicited event */
8295         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8296         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8297         { } /* end */
8298 };
8299
8300 static void alc883_nb_mic_automute(struct hda_codec *codec)
8301 {
8302         unsigned int present;
8303
8304         present = snd_hda_codec_read(codec, 0x18, 0,
8305                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8306         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8307                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8308         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8309                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8310 }
8311
8312 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8313 {
8314         unsigned int present;
8315         unsigned char bits;
8316
8317         present = snd_hda_codec_read(codec, 0x1b, 0,
8318                                      AC_VERB_GET_PIN_SENSE, 0)
8319                 & AC_PINSENSE_PRESENCE;
8320         bits = present ? 0 : PIN_OUT;
8321         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8322                             bits);
8323         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8324                             bits);
8325         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8326                             bits);
8327 }
8328
8329 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8330                                            unsigned int res)
8331 {
8332         switch (res >> 26) {
8333         case ALC880_HP_EVENT:
8334                 alc883_M90V_speaker_automute(codec);
8335                 break;
8336         case ALC880_MIC_EVENT:
8337                 alc883_nb_mic_automute(codec);
8338                 break;
8339         }
8340 }
8341
8342 static void alc883_mode2_inithook(struct hda_codec *codec)
8343 {
8344         alc883_M90V_speaker_automute(codec);
8345         alc883_nb_mic_automute(codec);
8346 }
8347
8348 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8349         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8350         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8351         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8352         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8353         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8354         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8355         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8356         /* enable unsolicited event */
8357         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8358         { } /* end */
8359 };
8360
8361 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8362 {
8363         unsigned int present;
8364         unsigned char bits;
8365
8366         present = snd_hda_codec_read(codec, 0x14, 0,
8367                                      AC_VERB_GET_PIN_SENSE, 0)
8368                 & AC_PINSENSE_PRESENCE;
8369         bits = present ? 0 : PIN_OUT;
8370         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8371                             bits);
8372 }
8373
8374 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8375                                            unsigned int res)
8376 {
8377         switch (res >> 26) {
8378         case ALC880_HP_EVENT:
8379                 alc883_eee1601_speaker_automute(codec);
8380                 break;
8381         }
8382 }
8383
8384 static void alc883_eee1601_inithook(struct hda_codec *codec)
8385 {
8386         alc883_eee1601_speaker_automute(codec);
8387 }
8388
8389 #ifdef CONFIG_SND_HDA_POWER_SAVE
8390 #define alc883_loopbacks        alc880_loopbacks
8391 #endif
8392
8393 /* pcm configuration: identiacal with ALC880 */
8394 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8395 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8396 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8397 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8398 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8399
8400 /*
8401  * configuration and preset
8402  */
8403 static const char *alc883_models[ALC883_MODEL_LAST] = {
8404         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8405         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8406         [ALC883_3ST_6ch]        = "3stack-6ch",
8407         [ALC883_6ST_DIG]        = "6stack-dig",
8408         [ALC883_TARGA_DIG]      = "targa-dig",
8409         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8410         [ALC883_ACER]           = "acer",
8411         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8412         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8413         [ALC883_MEDION]         = "medion",
8414         [ALC883_MEDION_MD2]     = "medion-md2",
8415         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8416         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8417         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8418         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8419         [ALC888_LENOVO_SKY] = "lenovo-sky",
8420         [ALC883_HAIER_W66]      = "haier-w66",
8421         [ALC888_3ST_HP]         = "3stack-hp",
8422         [ALC888_6ST_DELL]       = "6stack-dell",
8423         [ALC883_MITAC]          = "mitac",
8424         [ALC883_CLEVO_M720]     = "clevo-m720",
8425         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8426         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8427         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8428         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8429         [ALC883_AUTO]           = "auto",
8430 };
8431
8432 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8433         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8434         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8435         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8436         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8437         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8438         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8439         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8440                 ALC888_ACER_ASPIRE_4930G),
8441         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8442         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8443         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8444         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8445         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8446         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8447         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8448         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8449         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8450         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8451         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8452         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8453         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8454         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8455         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8456         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8457         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8458         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8459         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8460         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8461         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8462         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8463         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8464         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8465         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8466         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8467         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8468         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8469         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8470         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8471         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8472         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8473         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8474         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8475         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8476         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8477         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8478         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8479         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8480         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8481         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8482         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8483         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8484         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8485         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8486         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8487         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8488         SND_PCI_QUIRK(0x1734, 0x113d, "Fujitsu AMILO Xa3530",
8489                 ALC888_FUJITSU_XA3530),
8490         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8491         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8492         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8493         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8494         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8495         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8496         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8497         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8498         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8499         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8500         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8501         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8502         {}
8503 };
8504
8505 static struct alc_config_preset alc883_presets[] = {
8506         [ALC883_3ST_2ch_DIG] = {
8507                 .mixers = { alc883_3ST_2ch_mixer },
8508                 .init_verbs = { alc883_init_verbs },
8509                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8510                 .dac_nids = alc883_dac_nids,
8511                 .dig_out_nid = ALC883_DIGOUT_NID,
8512                 .dig_in_nid = ALC883_DIGIN_NID,
8513                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8514                 .channel_mode = alc883_3ST_2ch_modes,
8515                 .input_mux = &alc883_capture_source,
8516         },
8517         [ALC883_3ST_6ch_DIG] = {
8518                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8519                 .init_verbs = { alc883_init_verbs },
8520                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8521                 .dac_nids = alc883_dac_nids,
8522                 .dig_out_nid = ALC883_DIGOUT_NID,
8523                 .dig_in_nid = ALC883_DIGIN_NID,
8524                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8525                 .channel_mode = alc883_3ST_6ch_modes,
8526                 .need_dac_fix = 1,
8527                 .input_mux = &alc883_capture_source,
8528         },
8529         [ALC883_3ST_6ch] = {
8530                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8531                 .init_verbs = { alc883_init_verbs },
8532                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8533                 .dac_nids = alc883_dac_nids,
8534                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8535                 .channel_mode = alc883_3ST_6ch_modes,
8536                 .need_dac_fix = 1,
8537                 .input_mux = &alc883_capture_source,
8538         },
8539         [ALC883_3ST_6ch_INTEL] = {
8540                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8541                 .init_verbs = { alc883_init_verbs },
8542                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8543                 .dac_nids = alc883_dac_nids,
8544                 .dig_out_nid = ALC883_DIGOUT_NID,
8545                 .dig_in_nid = ALC883_DIGIN_NID,
8546                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8547                 .channel_mode = alc883_3ST_6ch_intel_modes,
8548                 .need_dac_fix = 1,
8549                 .input_mux = &alc883_3stack_6ch_intel,
8550         },
8551         [ALC883_6ST_DIG] = {
8552                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8553                 .init_verbs = { alc883_init_verbs },
8554                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8555                 .dac_nids = alc883_dac_nids,
8556                 .dig_out_nid = ALC883_DIGOUT_NID,
8557                 .dig_in_nid = ALC883_DIGIN_NID,
8558                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8559                 .channel_mode = alc883_sixstack_modes,
8560                 .input_mux = &alc883_capture_source,
8561         },
8562         [ALC883_TARGA_DIG] = {
8563                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8564                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8565                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8566                 .dac_nids = alc883_dac_nids,
8567                 .dig_out_nid = ALC883_DIGOUT_NID,
8568                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8569                 .channel_mode = alc883_3ST_6ch_modes,
8570                 .need_dac_fix = 1,
8571                 .input_mux = &alc883_capture_source,
8572                 .unsol_event = alc883_tagra_unsol_event,
8573                 .init_hook = alc883_tagra_automute,
8574         },
8575         [ALC883_TARGA_2ch_DIG] = {
8576                 .mixers = { alc883_tagra_2ch_mixer},
8577                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8578                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8579                 .dac_nids = alc883_dac_nids,
8580                 .adc_nids = alc883_adc_nids_alt,
8581                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8582                 .dig_out_nid = ALC883_DIGOUT_NID,
8583                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8584                 .channel_mode = alc883_3ST_2ch_modes,
8585                 .input_mux = &alc883_capture_source,
8586                 .unsol_event = alc883_tagra_unsol_event,
8587                 .init_hook = alc883_tagra_automute,
8588         },
8589         [ALC883_ACER] = {
8590                 .mixers = { alc883_base_mixer },
8591                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8592                  * and the headphone jack.  Turn this on and rely on the
8593                  * standard mute methods whenever the user wants to turn
8594                  * these outputs off.
8595                  */
8596                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8597                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8598                 .dac_nids = alc883_dac_nids,
8599                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8600                 .channel_mode = alc883_3ST_2ch_modes,
8601                 .input_mux = &alc883_capture_source,
8602         },
8603         [ALC883_ACER_ASPIRE] = {
8604                 .mixers = { alc883_acer_aspire_mixer },
8605                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_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_2ch_modes),
8610                 .channel_mode = alc883_3ST_2ch_modes,
8611                 .input_mux = &alc883_capture_source,
8612                 .unsol_event = alc883_acer_aspire_unsol_event,
8613                 .init_hook = alc883_acer_aspire_automute,
8614         },
8615         [ALC888_ACER_ASPIRE_4930G] = {
8616                 .mixers = { alc888_base_mixer,
8617                                 alc883_chmode_mixer },
8618                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
8619                                 alc888_acer_aspire_4930g_verbs },
8620                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8621                 .dac_nids = alc883_dac_nids,
8622                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8623                 .adc_nids = alc883_adc_nids_rev,
8624                 .capsrc_nids = alc883_capsrc_nids_rev,
8625                 .dig_out_nid = ALC883_DIGOUT_NID,
8626                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8627                 .channel_mode = alc883_3ST_6ch_modes,
8628                 .need_dac_fix = 1,
8629                 .num_mux_defs =
8630                         ARRAY_SIZE(alc888_2_capture_sources),
8631                 .input_mux = alc888_2_capture_sources,
8632                 .unsol_event = alc888_acer_aspire_4930g_unsol_event,
8633                 .init_hook = alc888_acer_aspire_4930g_automute,
8634         },
8635         [ALC883_MEDION] = {
8636                 .mixers = { alc883_fivestack_mixer,
8637                             alc883_chmode_mixer },
8638                 .init_verbs = { alc883_init_verbs,
8639                                 alc883_medion_eapd_verbs },
8640                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8641                 .dac_nids = alc883_dac_nids,
8642                 .adc_nids = alc883_adc_nids_alt,
8643                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8644                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8645                 .channel_mode = alc883_sixstack_modes,
8646                 .input_mux = &alc883_capture_source,
8647         },
8648         [ALC883_MEDION_MD2] = {
8649                 .mixers = { alc883_medion_md2_mixer},
8650                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8651                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8652                 .dac_nids = alc883_dac_nids,
8653                 .dig_out_nid = ALC883_DIGOUT_NID,
8654                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8655                 .channel_mode = alc883_3ST_2ch_modes,
8656                 .input_mux = &alc883_capture_source,
8657                 .unsol_event = alc883_medion_md2_unsol_event,
8658                 .init_hook = alc883_medion_md2_automute,
8659         },
8660         [ALC883_LAPTOP_EAPD] = {
8661                 .mixers = { alc883_base_mixer },
8662                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8663                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8664                 .dac_nids = alc883_dac_nids,
8665                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8666                 .channel_mode = alc883_3ST_2ch_modes,
8667                 .input_mux = &alc883_capture_source,
8668         },
8669         [ALC883_CLEVO_M720] = {
8670                 .mixers = { alc883_clevo_m720_mixer },
8671                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8672                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8673                 .dac_nids = alc883_dac_nids,
8674                 .dig_out_nid = ALC883_DIGOUT_NID,
8675                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8676                 .channel_mode = alc883_3ST_2ch_modes,
8677                 .input_mux = &alc883_capture_source,
8678                 .unsol_event = alc883_clevo_m720_unsol_event,
8679                 .init_hook = alc883_clevo_m720_automute,
8680         },
8681         [ALC883_LENOVO_101E_2ch] = {
8682                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8683                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8684                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8685                 .dac_nids = alc883_dac_nids,
8686                 .adc_nids = alc883_adc_nids_alt,
8687                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8688                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8689                 .channel_mode = alc883_3ST_2ch_modes,
8690                 .input_mux = &alc883_lenovo_101e_capture_source,
8691                 .unsol_event = alc883_lenovo_101e_unsol_event,
8692                 .init_hook = alc883_lenovo_101e_all_automute,
8693         },
8694         [ALC883_LENOVO_NB0763] = {
8695                 .mixers = { alc883_lenovo_nb0763_mixer },
8696                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8697                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8698                 .dac_nids = alc883_dac_nids,
8699                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8700                 .channel_mode = alc883_3ST_2ch_modes,
8701                 .need_dac_fix = 1,
8702                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8703                 .unsol_event = alc883_medion_md2_unsol_event,
8704                 .init_hook = alc883_medion_md2_automute,
8705         },
8706         [ALC888_LENOVO_MS7195_DIG] = {
8707                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8708                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8709                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8710                 .dac_nids = alc883_dac_nids,
8711                 .dig_out_nid = ALC883_DIGOUT_NID,
8712                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8713                 .channel_mode = alc883_3ST_6ch_modes,
8714                 .need_dac_fix = 1,
8715                 .input_mux = &alc883_capture_source,
8716                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8717                 .init_hook = alc888_lenovo_ms7195_front_automute,
8718         },
8719         [ALC883_HAIER_W66] = {
8720                 .mixers = { alc883_tagra_2ch_mixer},
8721                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8722                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8723                 .dac_nids = alc883_dac_nids,
8724                 .dig_out_nid = ALC883_DIGOUT_NID,
8725                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8726                 .channel_mode = alc883_3ST_2ch_modes,
8727                 .input_mux = &alc883_capture_source,
8728                 .unsol_event = alc883_haier_w66_unsol_event,
8729                 .init_hook = alc883_haier_w66_automute,
8730         },
8731         [ALC888_3ST_HP] = {
8732                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8733                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8734                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8735                 .dac_nids = alc883_dac_nids,
8736                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8737                 .channel_mode = alc888_3st_hp_modes,
8738                 .need_dac_fix = 1,
8739                 .input_mux = &alc883_capture_source,
8740         },
8741         [ALC888_6ST_DELL] = {
8742                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8743                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8744                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8745                 .dac_nids = alc883_dac_nids,
8746                 .dig_out_nid = ALC883_DIGOUT_NID,
8747                 .dig_in_nid = ALC883_DIGIN_NID,
8748                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8749                 .channel_mode = alc883_sixstack_modes,
8750                 .input_mux = &alc883_capture_source,
8751                 .unsol_event = alc888_6st_dell_unsol_event,
8752                 .init_hook = alc888_6st_dell_front_automute,
8753         },
8754         [ALC883_MITAC] = {
8755                 .mixers = { alc883_mitac_mixer },
8756                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8757                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8758                 .dac_nids = alc883_dac_nids,
8759                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8760                 .channel_mode = alc883_3ST_2ch_modes,
8761                 .input_mux = &alc883_capture_source,
8762                 .unsol_event = alc883_mitac_unsol_event,
8763                 .init_hook = alc883_mitac_automute,
8764         },
8765         [ALC883_FUJITSU_PI2515] = {
8766                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8767                 .init_verbs = { alc883_init_verbs,
8768                                 alc883_2ch_fujitsu_pi2515_verbs},
8769                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8770                 .dac_nids = alc883_dac_nids,
8771                 .dig_out_nid = ALC883_DIGOUT_NID,
8772                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8773                 .channel_mode = alc883_3ST_2ch_modes,
8774                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8775                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8776                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8777         },
8778         [ALC888_FUJITSU_XA3530] = {
8779                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
8780                 .init_verbs = { alc883_init_verbs,
8781                         alc888_fujitsu_xa3530_verbs },
8782                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8783                 .dac_nids = alc883_dac_nids,
8784                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8785                 .adc_nids = alc883_adc_nids_rev,
8786                 .capsrc_nids = alc883_capsrc_nids_rev,
8787                 .dig_out_nid = ALC883_DIGOUT_NID,
8788                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
8789                 .channel_mode = alc888_4ST_8ch_intel_modes,
8790                 .num_mux_defs =
8791                         ARRAY_SIZE(alc888_2_capture_sources),
8792                 .input_mux = alc888_2_capture_sources,
8793                 .unsol_event = alc888_fujitsu_xa3530_unsol_event,
8794                 .init_hook = alc888_fujitsu_xa3530_automute,
8795         },
8796         [ALC888_LENOVO_SKY] = {
8797                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8798                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8799                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8800                 .dac_nids = alc883_dac_nids,
8801                 .dig_out_nid = ALC883_DIGOUT_NID,
8802                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8803                 .channel_mode = alc883_sixstack_modes,
8804                 .need_dac_fix = 1,
8805                 .input_mux = &alc883_lenovo_sky_capture_source,
8806                 .unsol_event = alc883_lenovo_sky_unsol_event,
8807                 .init_hook = alc888_lenovo_sky_front_automute,
8808         },
8809         [ALC888_ASUS_M90V] = {
8810                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8811                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8812                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8813                 .dac_nids = alc883_dac_nids,
8814                 .dig_out_nid = ALC883_DIGOUT_NID,
8815                 .dig_in_nid = ALC883_DIGIN_NID,
8816                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8817                 .channel_mode = alc883_3ST_6ch_modes,
8818                 .need_dac_fix = 1,
8819                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8820                 .unsol_event = alc883_mode2_unsol_event,
8821                 .init_hook = alc883_mode2_inithook,
8822         },
8823         [ALC888_ASUS_EEE1601] = {
8824                 .mixers = { alc883_asus_eee1601_mixer },
8825                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
8826                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8827                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8828                 .dac_nids = alc883_dac_nids,
8829                 .dig_out_nid = ALC883_DIGOUT_NID,
8830                 .dig_in_nid = ALC883_DIGIN_NID,
8831                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8832                 .channel_mode = alc883_3ST_2ch_modes,
8833                 .need_dac_fix = 1,
8834                 .input_mux = &alc883_asus_eee1601_capture_source,
8835                 .unsol_event = alc883_eee1601_unsol_event,
8836                 .init_hook = alc883_eee1601_inithook,
8837         },
8838         [ALC1200_ASUS_P5Q] = {
8839                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8840                 .init_verbs = { alc883_init_verbs },
8841                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8842                 .dac_nids = alc883_dac_nids,
8843                 .dig_out_nid = ALC1200_DIGOUT_NID,
8844                 .dig_in_nid = ALC883_DIGIN_NID,
8845                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8846                 .channel_mode = alc883_sixstack_modes,
8847                 .input_mux = &alc883_capture_source,
8848         },
8849 };
8850
8851
8852 /*
8853  * BIOS auto configuration
8854  */
8855 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8856                                               hda_nid_t nid, int pin_type,
8857                                               int dac_idx)
8858 {
8859         /* set as output */
8860         struct alc_spec *spec = codec->spec;
8861         int idx;
8862
8863         alc_set_pin_output(codec, nid, pin_type);
8864         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8865                 idx = 4;
8866         else
8867                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8868         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8869
8870 }
8871
8872 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8873 {
8874         struct alc_spec *spec = codec->spec;
8875         int i;
8876
8877         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8878         for (i = 0; i <= HDA_SIDE; i++) {
8879                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8880                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8881                 if (nid)
8882                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8883                                                           i);
8884         }
8885 }
8886
8887 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8888 {
8889         struct alc_spec *spec = codec->spec;
8890         hda_nid_t pin;
8891
8892         pin = spec->autocfg.hp_pins[0];
8893         if (pin) /* connect to front */
8894                 /* use dac 0 */
8895                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8896         pin = spec->autocfg.speaker_pins[0];
8897         if (pin)
8898                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8899 }
8900
8901 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8902 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8903
8904 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8905 {
8906         struct alc_spec *spec = codec->spec;
8907         int i;
8908
8909         for (i = 0; i < AUTO_PIN_LAST; i++) {
8910                 hda_nid_t nid = spec->autocfg.input_pins[i];
8911                 if (alc883_is_input_pin(nid)) {
8912                         snd_hda_codec_write(codec, nid, 0,
8913                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8914                                             (i <= AUTO_PIN_FRONT_MIC ?
8915                                              PIN_VREF80 : PIN_IN));
8916                         if (nid != ALC883_PIN_CD_NID)
8917                                 snd_hda_codec_write(codec, nid, 0,
8918                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8919                                                     AMP_OUT_MUTE);
8920                 }
8921         }
8922 }
8923
8924 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8925
8926 /* almost identical with ALC880 parser... */
8927 static int alc883_parse_auto_config(struct hda_codec *codec)
8928 {
8929         struct alc_spec *spec = codec->spec;
8930         int err = alc880_parse_auto_config(codec);
8931
8932         if (err < 0)
8933                 return err;
8934         else if (!err)
8935                 return 0; /* no config found */
8936
8937         err = alc_auto_add_mic_boost(codec);
8938         if (err < 0)
8939                 return err;
8940
8941         /* hack - override the init verbs */
8942         spec->init_verbs[0] = alc883_auto_init_verbs;
8943
8944         return 1; /* config found */
8945 }
8946
8947 /* additional initialization for auto-configuration model */
8948 static void alc883_auto_init(struct hda_codec *codec)
8949 {
8950         struct alc_spec *spec = codec->spec;
8951         alc883_auto_init_multi_out(codec);
8952         alc883_auto_init_hp_out(codec);
8953         alc883_auto_init_analog_input(codec);
8954         alc883_auto_init_input_src(codec);
8955         if (spec->unsol_event)
8956                 alc_inithook(codec);
8957 }
8958
8959 static int patch_alc883(struct hda_codec *codec)
8960 {
8961         struct alc_spec *spec;
8962         int err, board_config;
8963
8964         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8965         if (spec == NULL)
8966                 return -ENOMEM;
8967
8968         codec->spec = spec;
8969
8970         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
8971
8972         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8973                                                   alc883_models,
8974                                                   alc883_cfg_tbl);
8975         if (board_config < 0) {
8976                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8977                        "trying auto-probe from BIOS...\n");
8978                 board_config = ALC883_AUTO;
8979         }
8980
8981         if (board_config == ALC883_AUTO) {
8982                 /* automatic parse from the BIOS config */
8983                 err = alc883_parse_auto_config(codec);
8984                 if (err < 0) {
8985                         alc_free(codec);
8986                         return err;
8987                 } else if (!err) {
8988                         printk(KERN_INFO
8989                                "hda_codec: Cannot set up configuration "
8990                                "from BIOS.  Using base mode...\n");
8991                         board_config = ALC883_3ST_2ch_DIG;
8992                 }
8993         }
8994
8995         if (board_config != ALC883_AUTO)
8996                 setup_preset(spec, &alc883_presets[board_config]);
8997
8998         switch (codec->vendor_id) {
8999         case 0x10ec0888:
9000                 if (codec->revision_id == 0x100101) {
9001                         spec->stream_name_analog = "ALC1200 Analog";
9002                         spec->stream_name_digital = "ALC1200 Digital";
9003                 } else {
9004                         spec->stream_name_analog = "ALC888 Analog";
9005                         spec->stream_name_digital = "ALC888 Digital";
9006                 }
9007                 break;
9008         case 0x10ec0889:
9009                 spec->stream_name_analog = "ALC889 Analog";
9010                 spec->stream_name_digital = "ALC889 Digital";
9011                 break;
9012         default:
9013                 spec->stream_name_analog = "ALC883 Analog";
9014                 spec->stream_name_digital = "ALC883 Digital";
9015                 break;
9016         }
9017
9018         spec->stream_analog_playback = &alc883_pcm_analog_playback;
9019         spec->stream_analog_capture = &alc883_pcm_analog_capture;
9020         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9021
9022         spec->stream_digital_playback = &alc883_pcm_digital_playback;
9023         spec->stream_digital_capture = &alc883_pcm_digital_capture;
9024
9025         if (!spec->num_adc_nids) {
9026                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9027                 spec->adc_nids = alc883_adc_nids;
9028         }
9029         if (!spec->capsrc_nids)
9030                 spec->capsrc_nids = alc883_capsrc_nids;
9031         spec->is_mix_capture = 1; /* matrix-style capture */
9032         if (!spec->cap_mixer)
9033                 set_capture_mixer(spec);
9034
9035         spec->vmaster_nid = 0x0c;
9036
9037         codec->patch_ops = alc_patch_ops;
9038         if (board_config == ALC883_AUTO)
9039                 spec->init_hook = alc883_auto_init;
9040
9041 #ifdef CONFIG_SND_HDA_POWER_SAVE
9042         if (!spec->loopback.amplist)
9043                 spec->loopback.amplist = alc883_loopbacks;
9044 #endif
9045
9046         return 0;
9047 }
9048
9049 /*
9050  * ALC262 support
9051  */
9052
9053 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9054 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9055
9056 #define alc262_dac_nids         alc260_dac_nids
9057 #define alc262_adc_nids         alc882_adc_nids
9058 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9059 #define alc262_capsrc_nids      alc882_capsrc_nids
9060 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9061
9062 #define alc262_modes            alc260_modes
9063 #define alc262_capture_source   alc882_capture_source
9064
9065 static hda_nid_t alc262_dmic_adc_nids[1] = {
9066         /* ADC0 */
9067         0x09
9068 };
9069
9070 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9071
9072 static struct snd_kcontrol_new alc262_base_mixer[] = {
9073         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9074         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9075         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9076         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9077         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9078         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9079         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9080         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9081         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9082         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9083         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9084         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9085         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9086            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9087         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9088         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9089         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9090         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9091         { } /* end */
9092 };
9093
9094 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
9095         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9096         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9097         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9098         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9099         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9100         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9101         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9102         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9103         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9104         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9105         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9106         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9107         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9108            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9109         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
9110         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9111         { } /* end */
9112 };
9113
9114 /* update HP, line and mono-out pins according to the master switch */
9115 static void alc262_hp_master_update(struct hda_codec *codec)
9116 {
9117         struct alc_spec *spec = codec->spec;
9118         int val = spec->master_sw;
9119
9120         /* HP & line-out */
9121         snd_hda_codec_write_cache(codec, 0x1b, 0,
9122                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9123                                   val ? PIN_HP : 0);
9124         snd_hda_codec_write_cache(codec, 0x15, 0,
9125                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9126                                   val ? PIN_HP : 0);
9127         /* mono (speaker) depending on the HP jack sense */
9128         val = val && !spec->jack_present;
9129         snd_hda_codec_write_cache(codec, 0x16, 0,
9130                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9131                                   val ? PIN_OUT : 0);
9132 }
9133
9134 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9135 {
9136         struct alc_spec *spec = codec->spec;
9137         unsigned int presence;
9138         presence = snd_hda_codec_read(codec, 0x1b, 0,
9139                                       AC_VERB_GET_PIN_SENSE, 0);
9140         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9141         alc262_hp_master_update(codec);
9142 }
9143
9144 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9145 {
9146         if ((res >> 26) != ALC880_HP_EVENT)
9147                 return;
9148         alc262_hp_bpc_automute(codec);
9149 }
9150
9151 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9152 {
9153         struct alc_spec *spec = codec->spec;
9154         unsigned int presence;
9155         presence = snd_hda_codec_read(codec, 0x15, 0,
9156                                       AC_VERB_GET_PIN_SENSE, 0);
9157         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9158         alc262_hp_master_update(codec);
9159 }
9160
9161 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9162                                            unsigned int res)
9163 {
9164         if ((res >> 26) != ALC880_HP_EVENT)
9165                 return;
9166         alc262_hp_wildwest_automute(codec);
9167 }
9168
9169 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
9170                                    struct snd_ctl_elem_value *ucontrol)
9171 {
9172         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9173         struct alc_spec *spec = codec->spec;
9174         *ucontrol->value.integer.value = spec->master_sw;
9175         return 0;
9176 }
9177
9178 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9179                                    struct snd_ctl_elem_value *ucontrol)
9180 {
9181         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9182         struct alc_spec *spec = codec->spec;
9183         int val = !!*ucontrol->value.integer.value;
9184
9185         if (val == spec->master_sw)
9186                 return 0;
9187         spec->master_sw = val;
9188         alc262_hp_master_update(codec);
9189         return 1;
9190 }
9191
9192 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9193         {
9194                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9195                 .name = "Master Playback Switch",
9196                 .info = snd_ctl_boolean_mono_info,
9197                 .get = alc262_hp_master_sw_get,
9198                 .put = alc262_hp_master_sw_put,
9199         },
9200         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9201         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9202         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9203         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9204                               HDA_OUTPUT),
9205         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9206                             HDA_OUTPUT),
9207         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9208         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9209         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9210         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9211         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9212         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9213         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9214         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9215         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9216         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9217         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9218         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9219         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9220         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9221         { } /* end */
9222 };
9223
9224 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9225         {
9226                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9227                 .name = "Master Playback Switch",
9228                 .info = snd_ctl_boolean_mono_info,
9229                 .get = alc262_hp_master_sw_get,
9230                 .put = alc262_hp_master_sw_put,
9231         },
9232         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9233         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9234         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9235         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9236         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9237                               HDA_OUTPUT),
9238         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9239                             HDA_OUTPUT),
9240         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9241         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9242         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9243         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9244         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9245         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9246         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9247         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9248         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9249         { } /* end */
9250 };
9251
9252 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9253         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9254         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9255         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9256         { } /* end */
9257 };
9258
9259 /* mute/unmute internal speaker according to the hp jack and mute state */
9260 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
9261 {
9262         struct alc_spec *spec = codec->spec;
9263
9264         if (force || !spec->sense_updated) {
9265                 unsigned int present;
9266                 present = snd_hda_codec_read(codec, 0x15, 0,
9267                                              AC_VERB_GET_PIN_SENSE, 0);
9268                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9269                 spec->sense_updated = 1;
9270         }
9271         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
9272                                  spec->jack_present ? HDA_AMP_MUTE : 0);
9273 }
9274
9275 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
9276                                         unsigned int res)
9277 {
9278         if ((res >> 26) != ALC880_HP_EVENT)
9279                 return;
9280         alc262_hp_t5735_automute(codec, 1);
9281 }
9282
9283 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9284 {
9285         alc262_hp_t5735_automute(codec, 1);
9286 }
9287
9288 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9289         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9290         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9291         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9292         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9293         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9294         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9295         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9296         { } /* end */
9297 };
9298
9299 static struct hda_verb alc262_hp_t5735_verbs[] = {
9300         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9301         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9302
9303         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9304         { }
9305 };
9306
9307 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9308         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9309         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9310         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9311         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9312         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9313         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9314         { } /* end */
9315 };
9316
9317 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9318         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9319         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9320         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9321         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9322         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9323         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9324         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9325         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9326         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9327         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9328         {}
9329 };
9330
9331 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9332         .num_items = 1,
9333         .items = {
9334                 { "Line", 0x1 },
9335         },
9336 };
9337
9338 /* bind hp and internal speaker mute (with plug check) */
9339 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9340                                      struct snd_ctl_elem_value *ucontrol)
9341 {
9342         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9343         long *valp = ucontrol->value.integer.value;
9344         int change;
9345
9346         /* change hp mute */
9347         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9348                                           HDA_AMP_MUTE,
9349                                           valp[0] ? 0 : HDA_AMP_MUTE);
9350         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9351                                            HDA_AMP_MUTE,
9352                                            valp[1] ? 0 : HDA_AMP_MUTE);
9353         if (change) {
9354                 /* change speaker according to HP jack state */
9355                 struct alc_spec *spec = codec->spec;
9356                 unsigned int mute;
9357                 if (spec->jack_present)
9358                         mute = HDA_AMP_MUTE;
9359                 else
9360                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9361                                                       HDA_OUTPUT, 0);
9362                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9363                                          HDA_AMP_MUTE, mute);
9364         }
9365         return change;
9366 }
9367
9368 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9369         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9370         {
9371                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9372                 .name = "Master Playback Switch",
9373                 .info = snd_hda_mixer_amp_switch_info,
9374                 .get = snd_hda_mixer_amp_switch_get,
9375                 .put = alc262_sony_master_sw_put,
9376                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9377         },
9378         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9379         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9380         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9381         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9382         { } /* end */
9383 };
9384
9385 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9386         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9387         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9388         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9389         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9390         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9391         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9392         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9393         { } /* end */
9394 };
9395
9396 #define alc262_capture_mixer            alc882_capture_mixer
9397 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9398
9399 /*
9400  * generic initialization of ADC, input mixers and output mixers
9401  */
9402 static struct hda_verb alc262_init_verbs[] = {
9403         /*
9404          * Unmute ADC0-2 and set the default input to mic-in
9405          */
9406         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9407         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9408         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9409         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9410         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9411         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9412
9413         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9414          * mixer widget
9415          * Note: PASD motherboards uses the Line In 2 as the input for
9416          * front panel mic (mic 2)
9417          */
9418         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9419         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9420         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9421         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9422         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9423         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9424
9425         /*
9426          * Set up output mixers (0x0c - 0x0e)
9427          */
9428         /* set vol=0 to output mixers */
9429         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9430         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9431         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9432         /* set up input amps for analog loopback */
9433         /* Amp Indices: DAC = 0, mixer = 1 */
9434         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9435         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9436         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9437         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9438         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9439         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9440
9441         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9442         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9443         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9444         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9445         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9446         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9447
9448         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9449         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9450         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9451         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9452         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9453
9454         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9455         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9456
9457         /* FIXME: use matrix-type input source selection */
9458         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9459         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9460         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9461         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9462         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9463         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9464         /* Input mixer2 */
9465         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9466         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9467         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9468         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9469         /* Input mixer3 */
9470         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9471         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9472         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9473         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9474
9475         { }
9476 };
9477
9478 static struct hda_verb alc262_eapd_verbs[] = {
9479         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9480         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9481         { }
9482 };
9483
9484 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9485         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9486         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9487         {}
9488 };
9489
9490 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9491         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9492         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9493         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9494
9495         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9496         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9497         {}
9498 };
9499
9500 static struct hda_verb alc262_sony_unsol_verbs[] = {
9501         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9502         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9503         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9504
9505         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9506         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9507         {}
9508 };
9509
9510 static struct hda_input_mux alc262_dmic_capture_source = {
9511         .num_items = 2,
9512         .items = {
9513                 { "Int DMic", 0x9 },
9514                 { "Mic", 0x0 },
9515         },
9516 };
9517
9518 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9519         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9520         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9521         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9522         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9523         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9524         { } /* end */
9525 };
9526
9527 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9528         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9529         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9530         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9531         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9532         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9533         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9534         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9535         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9536         {}
9537 };
9538
9539 static void alc262_dmic_automute(struct hda_codec *codec)
9540 {
9541         unsigned int present;
9542
9543         present = snd_hda_codec_read(codec, 0x18, 0,
9544                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9545         snd_hda_codec_write(codec, 0x22, 0,
9546                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9547 }
9548
9549 /* toggle speaker-output according to the hp-jack state */
9550 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9551 {
9552         unsigned int present;
9553         unsigned char bits;
9554
9555         present = snd_hda_codec_read(codec, 0x15, 0,
9556                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9557         bits = present ? 0 : PIN_OUT;
9558         snd_hda_codec_write(codec, 0x14, 0,
9559                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9560 }
9561
9562
9563
9564 /* unsolicited event for HP jack sensing */
9565 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9566                                        unsigned int res)
9567 {
9568         if ((res >> 26) == ALC880_HP_EVENT)
9569                 alc262_toshiba_s06_speaker_automute(codec);
9570         if ((res >> 26) == ALC880_MIC_EVENT)
9571                 alc262_dmic_automute(codec);
9572
9573 }
9574
9575 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9576 {
9577         alc262_toshiba_s06_speaker_automute(codec);
9578         alc262_dmic_automute(codec);
9579 }
9580
9581 /* mute/unmute internal speaker according to the hp jack and mute state */
9582 static void alc262_hippo_automute(struct hda_codec *codec)
9583 {
9584         struct alc_spec *spec = codec->spec;
9585         unsigned int mute;
9586         unsigned int present;
9587
9588         /* need to execute and sync at first */
9589         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9590         present = snd_hda_codec_read(codec, 0x15, 0,
9591                                      AC_VERB_GET_PIN_SENSE, 0);
9592         spec->jack_present = (present & 0x80000000) != 0;
9593         if (spec->jack_present) {
9594                 /* mute internal speaker */
9595                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9596                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9597         } else {
9598                 /* unmute internal speaker if necessary */
9599                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9600                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9601                                          HDA_AMP_MUTE, mute);
9602         }
9603 }
9604
9605 /* unsolicited event for HP jack sensing */
9606 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9607                                        unsigned int res)
9608 {
9609         if ((res >> 26) != ALC880_HP_EVENT)
9610                 return;
9611         alc262_hippo_automute(codec);
9612 }
9613
9614 static void alc262_hippo1_automute(struct hda_codec *codec)
9615 {
9616         unsigned int mute;
9617         unsigned int present;
9618
9619         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9620         present = snd_hda_codec_read(codec, 0x1b, 0,
9621                                      AC_VERB_GET_PIN_SENSE, 0);
9622         present = (present & 0x80000000) != 0;
9623         if (present) {
9624                 /* mute internal speaker */
9625                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9626                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9627         } else {
9628                 /* unmute internal speaker if necessary */
9629                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9630                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9631                                          HDA_AMP_MUTE, mute);
9632         }
9633 }
9634
9635 /* unsolicited event for HP jack sensing */
9636 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9637                                        unsigned int res)
9638 {
9639         if ((res >> 26) != ALC880_HP_EVENT)
9640                 return;
9641         alc262_hippo1_automute(codec);
9642 }
9643
9644 /*
9645  * nec model
9646  *  0x15 = headphone
9647  *  0x16 = internal speaker
9648  *  0x18 = external mic
9649  */
9650
9651 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9652         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9653         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9654
9655         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9656         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9657         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9658
9659         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9660         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9661         { } /* end */
9662 };
9663
9664 static struct hda_verb alc262_nec_verbs[] = {
9665         /* Unmute Speaker */
9666         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9667
9668         /* Headphone */
9669         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9670         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9671
9672         /* External mic to headphone */
9673         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9674         /* External mic to speaker */
9675         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9676         {}
9677 };
9678
9679 /*
9680  * fujitsu model
9681  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9682  *  0x1b = port replicator headphone out
9683  */
9684
9685 #define ALC_HP_EVENT    0x37
9686
9687 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9688         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9689         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9690         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9691         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9692         {}
9693 };
9694
9695 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9696         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9697         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9698         {}
9699 };
9700
9701 static struct hda_input_mux alc262_fujitsu_capture_source = {
9702         .num_items = 3,
9703         .items = {
9704                 { "Mic", 0x0 },
9705                 { "Int Mic", 0x1 },
9706                 { "CD", 0x4 },
9707         },
9708 };
9709
9710 static struct hda_input_mux alc262_HP_capture_source = {
9711         .num_items = 5,
9712         .items = {
9713                 { "Mic", 0x0 },
9714                 { "Front Mic", 0x1 },
9715                 { "Line", 0x2 },
9716                 { "CD", 0x4 },
9717                 { "AUX IN", 0x6 },
9718         },
9719 };
9720
9721 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9722         .num_items = 4,
9723         .items = {
9724                 { "Mic", 0x0 },
9725                 { "Front Mic", 0x2 },
9726                 { "Line", 0x1 },
9727                 { "CD", 0x4 },
9728         },
9729 };
9730
9731 /* mute/unmute internal speaker according to the hp jacks and mute state */
9732 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9733 {
9734         struct alc_spec *spec = codec->spec;
9735         unsigned int mute;
9736
9737         if (force || !spec->sense_updated) {
9738                 unsigned int present;
9739                 /* need to execute and sync at first */
9740                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9741                 /* check laptop HP jack */
9742                 present = snd_hda_codec_read(codec, 0x14, 0,
9743                                              AC_VERB_GET_PIN_SENSE, 0);
9744                 /* need to execute and sync at first */
9745                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9746                 /* check docking HP jack */
9747                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9748                                               AC_VERB_GET_PIN_SENSE, 0);
9749                 if (present & AC_PINSENSE_PRESENCE)
9750                         spec->jack_present = 1;
9751                 else
9752                         spec->jack_present = 0;
9753                 spec->sense_updated = 1;
9754         }
9755         /* unmute internal speaker only if both HPs are unplugged and
9756          * master switch is on
9757          */
9758         if (spec->jack_present)
9759                 mute = HDA_AMP_MUTE;
9760         else
9761                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9762         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9763                                  HDA_AMP_MUTE, mute);
9764 }
9765
9766 /* unsolicited event for HP jack sensing */
9767 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9768                                        unsigned int res)
9769 {
9770         if ((res >> 26) != ALC_HP_EVENT)
9771                 return;
9772         alc262_fujitsu_automute(codec, 1);
9773 }
9774
9775 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9776 {
9777         alc262_fujitsu_automute(codec, 1);
9778 }
9779
9780 /* bind volumes of both NID 0x0c and 0x0d */
9781 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9782         .ops = &snd_hda_bind_vol,
9783         .values = {
9784                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9785                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9786                 0
9787         },
9788 };
9789
9790 /* mute/unmute internal speaker according to the hp jack and mute state */
9791 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9792 {
9793         struct alc_spec *spec = codec->spec;
9794         unsigned int mute;
9795
9796         if (force || !spec->sense_updated) {
9797                 unsigned int present_int_hp;
9798                 /* need to execute and sync at first */
9799                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9800                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9801                                         AC_VERB_GET_PIN_SENSE, 0);
9802                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9803                 spec->sense_updated = 1;
9804         }
9805         if (spec->jack_present) {
9806                 /* mute internal speaker */
9807                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9808                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9809                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9810                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9811         } else {
9812                 /* unmute internal speaker if necessary */
9813                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9814                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9815                                          HDA_AMP_MUTE, mute);
9816                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9817                                          HDA_AMP_MUTE, mute);
9818         }
9819 }
9820
9821 /* unsolicited event for HP jack sensing */
9822 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9823                                        unsigned int res)
9824 {
9825         if ((res >> 26) != ALC_HP_EVENT)
9826                 return;
9827         alc262_lenovo_3000_automute(codec, 1);
9828 }
9829
9830 /* bind hp and internal speaker mute (with plug check) */
9831 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9832                                          struct snd_ctl_elem_value *ucontrol)
9833 {
9834         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9835         long *valp = ucontrol->value.integer.value;
9836         int change;
9837
9838         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9839                                                  HDA_AMP_MUTE,
9840                                                  valp ? 0 : HDA_AMP_MUTE);
9841         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9842                                                  HDA_AMP_MUTE,
9843                                                  valp ? 0 : HDA_AMP_MUTE);
9844
9845         if (change)
9846                 alc262_fujitsu_automute(codec, 0);
9847         return change;
9848 }
9849
9850 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9851         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9852         {
9853                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9854                 .name = "Master Playback Switch",
9855                 .info = snd_hda_mixer_amp_switch_info,
9856                 .get = snd_hda_mixer_amp_switch_get,
9857                 .put = alc262_fujitsu_master_sw_put,
9858                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9859         },
9860         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9861         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9862         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9863         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9864         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9865         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9866         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9867         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9868         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9869         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9870         { } /* end */
9871 };
9872
9873 /* bind hp and internal speaker mute (with plug check) */
9874 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9875                                          struct snd_ctl_elem_value *ucontrol)
9876 {
9877         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9878         long *valp = ucontrol->value.integer.value;
9879         int change;
9880
9881         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9882                                                  HDA_AMP_MUTE,
9883                                                  valp ? 0 : HDA_AMP_MUTE);
9884
9885         if (change)
9886                 alc262_lenovo_3000_automute(codec, 0);
9887         return change;
9888 }
9889
9890 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9891         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9892         {
9893                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9894                 .name = "Master Playback Switch",
9895                 .info = snd_hda_mixer_amp_switch_info,
9896                 .get = snd_hda_mixer_amp_switch_get,
9897                 .put = alc262_lenovo_3000_master_sw_put,
9898                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9899         },
9900         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9901         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9902         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9903         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9904         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9905         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9906         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9907         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9908         { } /* end */
9909 };
9910
9911 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
9912         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9913         {
9914                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9915                 .name = "Master Playback Switch",
9916                 .info = snd_hda_mixer_amp_switch_info,
9917                 .get = snd_hda_mixer_amp_switch_get,
9918                 .put = alc262_sony_master_sw_put,
9919                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9920         },
9921         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9922         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9923         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9924         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9925         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9926         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9927         { } /* end */
9928 };
9929
9930 /* additional init verbs for Benq laptops */
9931 static struct hda_verb alc262_EAPD_verbs[] = {
9932         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9933         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9934         {}
9935 };
9936
9937 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9938         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9939         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9940
9941         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9942         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9943         {}
9944 };
9945
9946 /* Samsung Q1 Ultra Vista model setup */
9947 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9948         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9949         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9950         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9951         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9952         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9953         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9954         { } /* end */
9955 };
9956
9957 static struct hda_verb alc262_ultra_verbs[] = {
9958         /* output mixer */
9959         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9960         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9961         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9962         /* speaker */
9963         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9964         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9965         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9966         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9967         /* HP */
9968         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9969         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9970         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9971         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9972         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9973         /* internal mic */
9974         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9975         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9976         /* ADC, choose mic */
9977         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9978         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9979         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9980         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9981         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9982         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9983         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9984         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9985         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9986         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
9987         {}
9988 };
9989
9990 /* mute/unmute internal speaker according to the hp jack and mute state */
9991 static void alc262_ultra_automute(struct hda_codec *codec)
9992 {
9993         struct alc_spec *spec = codec->spec;
9994         unsigned int mute;
9995
9996         mute = 0;
9997         /* auto-mute only when HP is used as HP */
9998         if (!spec->cur_mux[0]) {
9999                 unsigned int present;
10000                 /* need to execute and sync at first */
10001                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10002                 present = snd_hda_codec_read(codec, 0x15, 0,
10003                                              AC_VERB_GET_PIN_SENSE, 0);
10004                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10005                 if (spec->jack_present)
10006                         mute = HDA_AMP_MUTE;
10007         }
10008         /* mute/unmute internal speaker */
10009         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10010                                  HDA_AMP_MUTE, mute);
10011         /* mute/unmute HP */
10012         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10013                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10014 }
10015
10016 /* unsolicited event for HP jack sensing */
10017 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10018                                        unsigned int res)
10019 {
10020         if ((res >> 26) != ALC880_HP_EVENT)
10021                 return;
10022         alc262_ultra_automute(codec);
10023 }
10024
10025 static struct hda_input_mux alc262_ultra_capture_source = {
10026         .num_items = 2,
10027         .items = {
10028                 { "Mic", 0x1 },
10029                 { "Headphone", 0x7 },
10030         },
10031 };
10032
10033 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10034                                      struct snd_ctl_elem_value *ucontrol)
10035 {
10036         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10037         struct alc_spec *spec = codec->spec;
10038         int ret;
10039
10040         ret = alc_mux_enum_put(kcontrol, ucontrol);
10041         if (!ret)
10042                 return 0;
10043         /* reprogram the HP pin as mic or HP according to the input source */
10044         snd_hda_codec_write_cache(codec, 0x15, 0,
10045                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10046                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10047         alc262_ultra_automute(codec); /* mute/unmute HP */
10048         return ret;
10049 }
10050
10051 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10052         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10053         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10054         {
10055                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10056                 .name = "Capture Source",
10057                 .info = alc_mux_enum_info,
10058                 .get = alc_mux_enum_get,
10059                 .put = alc262_ultra_mux_enum_put,
10060         },
10061         { } /* end */
10062 };
10063
10064 /* add playback controls from the parsed DAC table */
10065 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10066                                              const struct auto_pin_cfg *cfg)
10067 {
10068         hda_nid_t nid;
10069         int err;
10070
10071         spec->multiout.num_dacs = 1;    /* only use one dac */
10072         spec->multiout.dac_nids = spec->private_dac_nids;
10073         spec->multiout.dac_nids[0] = 2;
10074
10075         nid = cfg->line_out_pins[0];
10076         if (nid) {
10077                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10078                                   "Front Playback Volume",
10079                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10080                 if (err < 0)
10081                         return err;
10082                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10083                                   "Front Playback Switch",
10084                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10085                 if (err < 0)
10086                         return err;
10087         }
10088
10089         nid = cfg->speaker_pins[0];
10090         if (nid) {
10091                 if (nid == 0x16) {
10092                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10093                                           "Speaker Playback Volume",
10094                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10095                                                               HDA_OUTPUT));
10096                         if (err < 0)
10097                                 return err;
10098                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10099                                           "Speaker Playback Switch",
10100                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10101                                                               HDA_OUTPUT));
10102                         if (err < 0)
10103                                 return err;
10104                 } else {
10105                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10106                                           "Speaker Playback Switch",
10107                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10108                                                               HDA_OUTPUT));
10109                         if (err < 0)
10110                                 return err;
10111                 }
10112         }
10113         nid = cfg->hp_pins[0];
10114         if (nid) {
10115                 /* spec->multiout.hp_nid = 2; */
10116                 if (nid == 0x16) {
10117                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10118                                           "Headphone Playback Volume",
10119                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10120                                                               HDA_OUTPUT));
10121                         if (err < 0)
10122                                 return err;
10123                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10124                                           "Headphone Playback Switch",
10125                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10126                                                               HDA_OUTPUT));
10127                         if (err < 0)
10128                                 return err;
10129                 } else {
10130                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10131                                           "Headphone Playback Switch",
10132                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10133                                                               HDA_OUTPUT));
10134                         if (err < 0)
10135                                 return err;
10136                 }
10137         }
10138         return 0;
10139 }
10140
10141 /* identical with ALC880 */
10142 #define alc262_auto_create_analog_input_ctls \
10143         alc880_auto_create_analog_input_ctls
10144
10145 /*
10146  * generic initialization of ADC, input mixers and output mixers
10147  */
10148 static struct hda_verb alc262_volume_init_verbs[] = {
10149         /*
10150          * Unmute ADC0-2 and set the default input to mic-in
10151          */
10152         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10153         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10154         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10155         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10156         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10157         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10158
10159         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10160          * mixer widget
10161          * Note: PASD motherboards uses the Line In 2 as the input for
10162          * front panel mic (mic 2)
10163          */
10164         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10165         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10166         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10167         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10168         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10169         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10170
10171         /*
10172          * Set up output mixers (0x0c - 0x0f)
10173          */
10174         /* set vol=0 to output mixers */
10175         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10176         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10177         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10178
10179         /* set up input amps for analog loopback */
10180         /* Amp Indices: DAC = 0, mixer = 1 */
10181         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10182         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10183         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10184         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10185         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10186         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10187
10188         /* FIXME: use matrix-type input source selection */
10189         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10190         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10191         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10192         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10193         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10194         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10195         /* Input mixer2 */
10196         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10197         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10198         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10199         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10200         /* Input mixer3 */
10201         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10202         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10203         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10204         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10205
10206         { }
10207 };
10208
10209 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10210         /*
10211          * Unmute ADC0-2 and set the default input to mic-in
10212          */
10213         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10214         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10215         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10216         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10217         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10218         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10219
10220         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10221          * mixer widget
10222          * Note: PASD motherboards uses the Line In 2 as the input for
10223          * front panel mic (mic 2)
10224          */
10225         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10226         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10227         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10228         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10229         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10230         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10231         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10232         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10233
10234         /*
10235          * Set up output mixers (0x0c - 0x0e)
10236          */
10237         /* set vol=0 to output mixers */
10238         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10239         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10240         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10241
10242         /* set up input amps for analog loopback */
10243         /* Amp Indices: DAC = 0, mixer = 1 */
10244         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10245         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10246         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10247         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10248         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10249         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10250
10251         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10252         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10253         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10254
10255         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10256         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10257
10258         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10259         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10260
10261         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10262         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10263         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10264         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10265         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10266
10267         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10268         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10269         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10270         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10271         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10272         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10273
10274
10275         /* FIXME: use matrix-type input source selection */
10276         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10277         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10278         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10279         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10280         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10281         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10282         /* Input mixer2 */
10283         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10284         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10285         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10286         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10287         /* Input mixer3 */
10288         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10289         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10290         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10291         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10292
10293         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10294
10295         { }
10296 };
10297
10298 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10299         /*
10300          * Unmute ADC0-2 and set the default input to mic-in
10301          */
10302         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10303         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10304         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10305         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10306         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10307         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10308
10309         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10310          * mixer widget
10311          * Note: PASD motherboards uses the Line In 2 as the input for front
10312          * panel mic (mic 2)
10313          */
10314         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10315         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10316         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10317         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10318         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10319         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10320         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10321         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10322         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10323         /*
10324          * Set up output mixers (0x0c - 0x0e)
10325          */
10326         /* set vol=0 to output mixers */
10327         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10328         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10329         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10330
10331         /* set up input amps for analog loopback */
10332         /* Amp Indices: DAC = 0, mixer = 1 */
10333         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10334         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10335         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10336         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10337         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10338         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10339
10340
10341         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10342         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10343         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10344         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10345         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10346         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10347         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10348
10349         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10350         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10351
10352         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10353         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10354
10355         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10356         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10357         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10358         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10359         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10360         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10361
10362         /* FIXME: use matrix-type input source selection */
10363         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10364         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10365         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10366         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10367         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10368         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10369         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10370         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10371         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10372         /* Input mixer2 */
10373         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10374         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10375         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10376         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10377         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10378         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10379         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10380         /* Input mixer3 */
10381         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10382         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10383         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10384         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10385         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10386         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10387         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10388
10389         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10390
10391         { }
10392 };
10393
10394 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10395
10396         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10397         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10398         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10399
10400         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10401         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10402         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10403         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10404
10405         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10406         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10407         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10408         {}
10409 };
10410
10411
10412 #ifdef CONFIG_SND_HDA_POWER_SAVE
10413 #define alc262_loopbacks        alc880_loopbacks
10414 #endif
10415
10416 /* pcm configuration: identiacal with ALC880 */
10417 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10418 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10419 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10420 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10421
10422 /*
10423  * BIOS auto configuration
10424  */
10425 static int alc262_parse_auto_config(struct hda_codec *codec)
10426 {
10427         struct alc_spec *spec = codec->spec;
10428         int err;
10429         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10430
10431         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10432                                            alc262_ignore);
10433         if (err < 0)
10434                 return err;
10435         if (!spec->autocfg.line_outs)
10436                 return 0; /* can't find valid BIOS pin config */
10437         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10438         if (err < 0)
10439                 return err;
10440         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10441         if (err < 0)
10442                 return err;
10443
10444         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10445
10446         if (spec->autocfg.dig_out_pin)
10447                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10448         if (spec->autocfg.dig_in_pin)
10449                 spec->dig_in_nid = ALC262_DIGIN_NID;
10450
10451         if (spec->kctls.list)
10452                 add_mixer(spec, spec->kctls.list);
10453
10454         add_verb(spec, alc262_volume_init_verbs);
10455         spec->num_mux_defs = 1;
10456         spec->input_mux = &spec->private_imux;
10457
10458         err = alc_auto_add_mic_boost(codec);
10459         if (err < 0)
10460                 return err;
10461
10462         store_pin_configs(codec);
10463         return 1;
10464 }
10465
10466 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10467 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10468 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10469 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10470
10471
10472 /* init callback for auto-configuration model -- overriding the default init */
10473 static void alc262_auto_init(struct hda_codec *codec)
10474 {
10475         struct alc_spec *spec = codec->spec;
10476         alc262_auto_init_multi_out(codec);
10477         alc262_auto_init_hp_out(codec);
10478         alc262_auto_init_analog_input(codec);
10479         alc262_auto_init_input_src(codec);
10480         if (spec->unsol_event)
10481                 alc_inithook(codec);
10482 }
10483
10484 /*
10485  * configuration and preset
10486  */
10487 static const char *alc262_models[ALC262_MODEL_LAST] = {
10488         [ALC262_BASIC]          = "basic",
10489         [ALC262_HIPPO]          = "hippo",
10490         [ALC262_HIPPO_1]        = "hippo_1",
10491         [ALC262_FUJITSU]        = "fujitsu",
10492         [ALC262_HP_BPC]         = "hp-bpc",
10493         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10494         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10495         [ALC262_HP_RP5700]      = "hp-rp5700",
10496         [ALC262_BENQ_ED8]       = "benq",
10497         [ALC262_BENQ_T31]       = "benq-t31",
10498         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10499         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10500         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10501         [ALC262_ULTRA]          = "ultra",
10502         [ALC262_LENOVO_3000]    = "lenovo-3000",
10503         [ALC262_NEC]            = "nec",
10504         [ALC262_AUTO]           = "auto",
10505 };
10506
10507 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10508         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10509         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10510         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
10511         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
10512         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
10513         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
10514         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
10515         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
10516         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10517         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10518         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10519         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10520         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10521         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10522         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10523         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10524         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10525         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10526         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10527         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10528         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10529         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10530                       ALC262_HP_TC_T5735),
10531         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10532         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10533         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10534         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10535         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10536         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10537         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10538                       ALC262_TOSHIBA_RX1),
10539         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10540         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10541         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10542         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
10543         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
10544         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10545         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10546         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10547         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10548         {}
10549 };
10550
10551 static struct alc_config_preset alc262_presets[] = {
10552         [ALC262_BASIC] = {
10553                 .mixers = { alc262_base_mixer },
10554                 .init_verbs = { alc262_init_verbs },
10555                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10556                 .dac_nids = alc262_dac_nids,
10557                 .hp_nid = 0x03,
10558                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10559                 .channel_mode = alc262_modes,
10560                 .input_mux = &alc262_capture_source,
10561         },
10562         [ALC262_HIPPO] = {
10563                 .mixers = { alc262_base_mixer },
10564                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10565                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10566                 .dac_nids = alc262_dac_nids,
10567                 .hp_nid = 0x03,
10568                 .dig_out_nid = ALC262_DIGOUT_NID,
10569                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10570                 .channel_mode = alc262_modes,
10571                 .input_mux = &alc262_capture_source,
10572                 .unsol_event = alc262_hippo_unsol_event,
10573                 .init_hook = alc262_hippo_automute,
10574         },
10575         [ALC262_HIPPO_1] = {
10576                 .mixers = { alc262_hippo1_mixer },
10577                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10578                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10579                 .dac_nids = alc262_dac_nids,
10580                 .hp_nid = 0x02,
10581                 .dig_out_nid = ALC262_DIGOUT_NID,
10582                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10583                 .channel_mode = alc262_modes,
10584                 .input_mux = &alc262_capture_source,
10585                 .unsol_event = alc262_hippo1_unsol_event,
10586                 .init_hook = alc262_hippo1_automute,
10587         },
10588         [ALC262_FUJITSU] = {
10589                 .mixers = { alc262_fujitsu_mixer },
10590                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10591                                 alc262_fujitsu_unsol_verbs },
10592                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10593                 .dac_nids = alc262_dac_nids,
10594                 .hp_nid = 0x03,
10595                 .dig_out_nid = ALC262_DIGOUT_NID,
10596                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10597                 .channel_mode = alc262_modes,
10598                 .input_mux = &alc262_fujitsu_capture_source,
10599                 .unsol_event = alc262_fujitsu_unsol_event,
10600                 .init_hook = alc262_fujitsu_init_hook,
10601         },
10602         [ALC262_HP_BPC] = {
10603                 .mixers = { alc262_HP_BPC_mixer },
10604                 .init_verbs = { alc262_HP_BPC_init_verbs },
10605                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10606                 .dac_nids = alc262_dac_nids,
10607                 .hp_nid = 0x03,
10608                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10609                 .channel_mode = alc262_modes,
10610                 .input_mux = &alc262_HP_capture_source,
10611                 .unsol_event = alc262_hp_bpc_unsol_event,
10612                 .init_hook = alc262_hp_bpc_automute,
10613         },
10614         [ALC262_HP_BPC_D7000_WF] = {
10615                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10616                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10617                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10618                 .dac_nids = alc262_dac_nids,
10619                 .hp_nid = 0x03,
10620                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10621                 .channel_mode = alc262_modes,
10622                 .input_mux = &alc262_HP_D7000_capture_source,
10623                 .unsol_event = alc262_hp_wildwest_unsol_event,
10624                 .init_hook = alc262_hp_wildwest_automute,
10625         },
10626         [ALC262_HP_BPC_D7000_WL] = {
10627                 .mixers = { alc262_HP_BPC_WildWest_mixer,
10628                             alc262_HP_BPC_WildWest_option_mixer },
10629                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10630                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10631                 .dac_nids = alc262_dac_nids,
10632                 .hp_nid = 0x03,
10633                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10634                 .channel_mode = alc262_modes,
10635                 .input_mux = &alc262_HP_D7000_capture_source,
10636                 .unsol_event = alc262_hp_wildwest_unsol_event,
10637                 .init_hook = alc262_hp_wildwest_automute,
10638         },
10639         [ALC262_HP_TC_T5735] = {
10640                 .mixers = { alc262_hp_t5735_mixer },
10641                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10642                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10643                 .dac_nids = alc262_dac_nids,
10644                 .hp_nid = 0x03,
10645                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10646                 .channel_mode = alc262_modes,
10647                 .input_mux = &alc262_capture_source,
10648                 .unsol_event = alc262_hp_t5735_unsol_event,
10649                 .init_hook = alc262_hp_t5735_init_hook,
10650         },
10651         [ALC262_HP_RP5700] = {
10652                 .mixers = { alc262_hp_rp5700_mixer },
10653                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10654                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10655                 .dac_nids = alc262_dac_nids,
10656                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10657                 .channel_mode = alc262_modes,
10658                 .input_mux = &alc262_hp_rp5700_capture_source,
10659         },
10660         [ALC262_BENQ_ED8] = {
10661                 .mixers = { alc262_base_mixer },
10662                 .init_verbs = { alc262_init_verbs, alc262_EAPD_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_capture_source,
10669         },
10670         [ALC262_SONY_ASSAMD] = {
10671                 .mixers = { alc262_sony_mixer },
10672                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10673                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10674                 .dac_nids = alc262_dac_nids,
10675                 .hp_nid = 0x02,
10676                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10677                 .channel_mode = alc262_modes,
10678                 .input_mux = &alc262_capture_source,
10679                 .unsol_event = alc262_hippo_unsol_event,
10680                 .init_hook = alc262_hippo_automute,
10681         },
10682         [ALC262_BENQ_T31] = {
10683                 .mixers = { alc262_benq_t31_mixer },
10684                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10685                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10686                 .dac_nids = alc262_dac_nids,
10687                 .hp_nid = 0x03,
10688                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10689                 .channel_mode = alc262_modes,
10690                 .input_mux = &alc262_capture_source,
10691                 .unsol_event = alc262_hippo_unsol_event,
10692                 .init_hook = alc262_hippo_automute,
10693         },
10694         [ALC262_ULTRA] = {
10695                 .mixers = { alc262_ultra_mixer },
10696                 .cap_mixer = alc262_ultra_capture_mixer,
10697                 .init_verbs = { alc262_ultra_verbs },
10698                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10699                 .dac_nids = alc262_dac_nids,
10700                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10701                 .channel_mode = alc262_modes,
10702                 .input_mux = &alc262_ultra_capture_source,
10703                 .adc_nids = alc262_adc_nids, /* ADC0 */
10704                 .capsrc_nids = alc262_capsrc_nids,
10705                 .num_adc_nids = 1, /* single ADC */
10706                 .unsol_event = alc262_ultra_unsol_event,
10707                 .init_hook = alc262_ultra_automute,
10708         },
10709         [ALC262_LENOVO_3000] = {
10710                 .mixers = { alc262_lenovo_3000_mixer },
10711                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10712                                 alc262_lenovo_3000_unsol_verbs },
10713                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10714                 .dac_nids = alc262_dac_nids,
10715                 .hp_nid = 0x03,
10716                 .dig_out_nid = ALC262_DIGOUT_NID,
10717                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10718                 .channel_mode = alc262_modes,
10719                 .input_mux = &alc262_fujitsu_capture_source,
10720                 .unsol_event = alc262_lenovo_3000_unsol_event,
10721         },
10722         [ALC262_NEC] = {
10723                 .mixers = { alc262_nec_mixer },
10724                 .init_verbs = { alc262_nec_verbs },
10725                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10726                 .dac_nids = alc262_dac_nids,
10727                 .hp_nid = 0x03,
10728                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10729                 .channel_mode = alc262_modes,
10730                 .input_mux = &alc262_capture_source,
10731         },
10732         [ALC262_TOSHIBA_S06] = {
10733                 .mixers = { alc262_toshiba_s06_mixer },
10734                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10735                                                         alc262_eapd_verbs },
10736                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10737                 .capsrc_nids = alc262_dmic_capsrc_nids,
10738                 .dac_nids = alc262_dac_nids,
10739                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10740                 .dig_out_nid = ALC262_DIGOUT_NID,
10741                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10742                 .channel_mode = alc262_modes,
10743                 .input_mux = &alc262_dmic_capture_source,
10744                 .unsol_event = alc262_toshiba_s06_unsol_event,
10745                 .init_hook = alc262_toshiba_s06_init_hook,
10746         },
10747         [ALC262_TOSHIBA_RX1] = {
10748                 .mixers = { alc262_toshiba_rx1_mixer },
10749                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
10750                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10751                 .dac_nids = alc262_dac_nids,
10752                 .hp_nid = 0x03,
10753                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10754                 .channel_mode = alc262_modes,
10755                 .input_mux = &alc262_capture_source,
10756                 .unsol_event = alc262_hippo_unsol_event,
10757                 .init_hook = alc262_hippo_automute,
10758         },
10759 };
10760
10761 static int patch_alc262(struct hda_codec *codec)
10762 {
10763         struct alc_spec *spec;
10764         int board_config;
10765         int err;
10766
10767         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10768         if (spec == NULL)
10769                 return -ENOMEM;
10770
10771         codec->spec = spec;
10772 #if 0
10773         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10774          * under-run
10775          */
10776         {
10777         int tmp;
10778         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10779         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10780         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10781         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10782         }
10783 #endif
10784
10785         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10786
10787         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10788                                                   alc262_models,
10789                                                   alc262_cfg_tbl);
10790
10791         if (board_config < 0) {
10792                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10793                        "trying auto-probe from BIOS...\n");
10794                 board_config = ALC262_AUTO;
10795         }
10796
10797         if (board_config == ALC262_AUTO) {
10798                 /* automatic parse from the BIOS config */
10799                 err = alc262_parse_auto_config(codec);
10800                 if (err < 0) {
10801                         alc_free(codec);
10802                         return err;
10803                 } else if (!err) {
10804                         printk(KERN_INFO
10805                                "hda_codec: Cannot set up configuration "
10806                                "from BIOS.  Using base mode...\n");
10807                         board_config = ALC262_BASIC;
10808                 }
10809         }
10810
10811         if (board_config != ALC262_AUTO)
10812                 setup_preset(spec, &alc262_presets[board_config]);
10813
10814         spec->stream_name_analog = "ALC262 Analog";
10815         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10816         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10817
10818         spec->stream_name_digital = "ALC262 Digital";
10819         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10820         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10821
10822         spec->is_mix_capture = 1;
10823         if (!spec->adc_nids && spec->input_mux) {
10824                 /* check whether NID 0x07 is valid */
10825                 unsigned int wcap = get_wcaps(codec, 0x07);
10826
10827                 /* get type */
10828                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10829                 if (wcap != AC_WID_AUD_IN) {
10830                         spec->adc_nids = alc262_adc_nids_alt;
10831                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10832                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10833                 } else {
10834                         spec->adc_nids = alc262_adc_nids;
10835                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10836                         spec->capsrc_nids = alc262_capsrc_nids;
10837                 }
10838         }
10839         if (!spec->cap_mixer)
10840                 set_capture_mixer(spec);
10841
10842         spec->vmaster_nid = 0x0c;
10843
10844         codec->patch_ops = alc_patch_ops;
10845         if (board_config == ALC262_AUTO)
10846                 spec->init_hook = alc262_auto_init;
10847 #ifdef CONFIG_SND_HDA_POWER_SAVE
10848         if (!spec->loopback.amplist)
10849                 spec->loopback.amplist = alc262_loopbacks;
10850 #endif
10851
10852         return 0;
10853 }
10854
10855 /*
10856  *  ALC268 channel source setting (2 channel)
10857  */
10858 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10859 #define alc268_modes            alc260_modes
10860
10861 static hda_nid_t alc268_dac_nids[2] = {
10862         /* front, hp */
10863         0x02, 0x03
10864 };
10865
10866 static hda_nid_t alc268_adc_nids[2] = {
10867         /* ADC0-1 */
10868         0x08, 0x07
10869 };
10870
10871 static hda_nid_t alc268_adc_nids_alt[1] = {
10872         /* ADC0 */
10873         0x08
10874 };
10875
10876 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10877
10878 static struct snd_kcontrol_new alc268_base_mixer[] = {
10879         /* output mixer control */
10880         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10881         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10882         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10883         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10884         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10885         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10886         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10887         { }
10888 };
10889
10890 /* bind Beep switches of both NID 0x0f and 0x10 */
10891 static struct hda_bind_ctls alc268_bind_beep_sw = {
10892         .ops = &snd_hda_bind_sw,
10893         .values = {
10894                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10895                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10896                 0
10897         },
10898 };
10899
10900 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10901         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10902         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10903         { }
10904 };
10905
10906 static struct hda_verb alc268_eapd_verbs[] = {
10907         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10908         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10909         { }
10910 };
10911
10912 /* Toshiba specific */
10913 #define alc268_toshiba_automute alc262_hippo_automute
10914
10915 static struct hda_verb alc268_toshiba_verbs[] = {
10916         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10917         { } /* end */
10918 };
10919
10920 static struct hda_input_mux alc268_acer_lc_capture_source = {
10921         .num_items = 2,
10922         .items = {
10923                 { "i-Mic", 0x6 },
10924                 { "E-Mic", 0x0 },
10925         },
10926 };
10927
10928 /* Acer specific */
10929 /* bind volumes of both NID 0x02 and 0x03 */
10930 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10931         .ops = &snd_hda_bind_vol,
10932         .values = {
10933                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10934                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10935                 0
10936         },
10937 };
10938
10939 /* mute/unmute internal speaker according to the hp jack and mute state */
10940 static void alc268_acer_automute(struct hda_codec *codec, int force)
10941 {
10942         struct alc_spec *spec = codec->spec;
10943         unsigned int mute;
10944
10945         if (force || !spec->sense_updated) {
10946                 unsigned int present;
10947                 present = snd_hda_codec_read(codec, 0x14, 0,
10948                                          AC_VERB_GET_PIN_SENSE, 0);
10949                 spec->jack_present = (present & 0x80000000) != 0;
10950                 spec->sense_updated = 1;
10951         }
10952         if (spec->jack_present)
10953                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10954         else /* unmute internal speaker if necessary */
10955                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10956         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10957                                  HDA_AMP_MUTE, mute);
10958 }
10959
10960
10961 /* bind hp and internal speaker mute (with plug check) */
10962 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10963                                      struct snd_ctl_elem_value *ucontrol)
10964 {
10965         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10966         long *valp = ucontrol->value.integer.value;
10967         int change;
10968
10969         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10970                                           HDA_AMP_MUTE,
10971                                           valp[0] ? 0 : HDA_AMP_MUTE);
10972         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10973                                            HDA_AMP_MUTE,
10974                                            valp[1] ? 0 : HDA_AMP_MUTE);
10975         if (change)
10976                 alc268_acer_automute(codec, 0);
10977         return change;
10978 }
10979
10980 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
10981         /* output mixer control */
10982         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10983         {
10984                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10985                 .name = "Master Playback Switch",
10986                 .info = snd_hda_mixer_amp_switch_info,
10987                 .get = snd_hda_mixer_amp_switch_get,
10988                 .put = alc268_acer_master_sw_put,
10989                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10990         },
10991         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
10992         { }
10993 };
10994
10995 static struct snd_kcontrol_new alc268_acer_mixer[] = {
10996         /* output mixer control */
10997         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10998         {
10999                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11000                 .name = "Master Playback Switch",
11001                 .info = snd_hda_mixer_amp_switch_info,
11002                 .get = snd_hda_mixer_amp_switch_get,
11003                 .put = alc268_acer_master_sw_put,
11004                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11005         },
11006         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11007         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11008         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11009         { }
11010 };
11011
11012 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11013         /* output mixer control */
11014         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11015         {
11016                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11017                 .name = "Master Playback Switch",
11018                 .info = snd_hda_mixer_amp_switch_info,
11019                 .get = snd_hda_mixer_amp_switch_get,
11020                 .put = alc268_acer_master_sw_put,
11021                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11022         },
11023         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11024         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11025         { }
11026 };
11027
11028 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11029         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11030         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11031         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11032         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11033         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11034         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11035         { }
11036 };
11037
11038 static struct hda_verb alc268_acer_verbs[] = {
11039         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11040         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11041         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11042         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11043         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11044         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11045         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11046         { }
11047 };
11048
11049 /* unsolicited event for HP jack sensing */
11050 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
11051                                        unsigned int res)
11052 {
11053         if ((res >> 26) != ALC880_HP_EVENT)
11054                 return;
11055         alc268_toshiba_automute(codec);
11056 }
11057
11058 static void alc268_acer_unsol_event(struct hda_codec *codec,
11059                                        unsigned int res)
11060 {
11061         if ((res >> 26) != ALC880_HP_EVENT)
11062                 return;
11063         alc268_acer_automute(codec, 1);
11064 }
11065
11066 static void alc268_acer_init_hook(struct hda_codec *codec)
11067 {
11068         alc268_acer_automute(codec, 1);
11069 }
11070
11071 /* toggle speaker-output according to the hp-jack state */
11072 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11073 {
11074         unsigned int present;
11075         unsigned char bits;
11076
11077         present = snd_hda_codec_read(codec, 0x15, 0,
11078                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11079         bits = present ? AMP_IN_MUTE(0) : 0;
11080         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
11081                                 AMP_IN_MUTE(0), bits);
11082         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
11083                                 AMP_IN_MUTE(0), bits);
11084 }
11085
11086
11087 static void alc268_acer_mic_automute(struct hda_codec *codec)
11088 {
11089         unsigned int present;
11090
11091         present = snd_hda_codec_read(codec, 0x18, 0,
11092                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11093         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11094                             present ? 0x0 : 0x6);
11095 }
11096
11097 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11098                                     unsigned int res)
11099 {
11100         if ((res >> 26) == ALC880_HP_EVENT)
11101                 alc268_aspire_one_speaker_automute(codec);
11102         if ((res >> 26) == ALC880_MIC_EVENT)
11103                 alc268_acer_mic_automute(codec);
11104 }
11105
11106 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11107 {
11108         alc268_aspire_one_speaker_automute(codec);
11109         alc268_acer_mic_automute(codec);
11110 }
11111
11112 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11113         /* output mixer control */
11114         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11115         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11116         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11117         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11118         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11119         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11120         { }
11121 };
11122
11123 static struct hda_verb alc268_dell_verbs[] = {
11124         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11125         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11126         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11127         { }
11128 };
11129
11130 /* mute/unmute internal speaker according to the hp jack and mute state */
11131 static void alc268_dell_automute(struct hda_codec *codec)
11132 {
11133         unsigned int present;
11134         unsigned int mute;
11135
11136         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
11137         if (present & 0x80000000)
11138                 mute = HDA_AMP_MUTE;
11139         else
11140                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
11141         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11142                                  HDA_AMP_MUTE, mute);
11143 }
11144
11145 static void alc268_dell_unsol_event(struct hda_codec *codec,
11146                                     unsigned int res)
11147 {
11148         if ((res >> 26) != ALC880_HP_EVENT)
11149                 return;
11150         alc268_dell_automute(codec);
11151 }
11152
11153 #define alc268_dell_init_hook   alc268_dell_automute
11154
11155 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
11156         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11157         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11158         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11159         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11160         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11161         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
11162         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
11163         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
11164         { }
11165 };
11166
11167 static struct hda_verb alc267_quanta_il1_verbs[] = {
11168         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11169         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
11170         { }
11171 };
11172
11173 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
11174 {
11175         unsigned int present;
11176
11177         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
11178                 & AC_PINSENSE_PRESENCE;
11179         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11180                             present ? 0 : PIN_OUT);
11181 }
11182
11183 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
11184 {
11185         unsigned int present;
11186
11187         present = snd_hda_codec_read(codec, 0x18, 0,
11188                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11189         snd_hda_codec_write(codec, 0x23, 0,
11190                             AC_VERB_SET_CONNECT_SEL,
11191                             present ? 0x00 : 0x01);
11192 }
11193
11194 static void alc267_quanta_il1_automute(struct hda_codec *codec)
11195 {
11196         alc267_quanta_il1_hp_automute(codec);
11197         alc267_quanta_il1_mic_automute(codec);
11198 }
11199
11200 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11201                                            unsigned int res)
11202 {
11203         switch (res >> 26) {
11204         case ALC880_HP_EVENT:
11205                 alc267_quanta_il1_hp_automute(codec);
11206                 break;
11207         case ALC880_MIC_EVENT:
11208                 alc267_quanta_il1_mic_automute(codec);
11209                 break;
11210         }
11211 }
11212
11213 /*
11214  * generic initialization of ADC, input mixers and output mixers
11215  */
11216 static struct hda_verb alc268_base_init_verbs[] = {
11217         /* Unmute DAC0-1 and set vol = 0 */
11218         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11219         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11220         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11221         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11222         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11223         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11224
11225         /*
11226          * Set up output mixers (0x0c - 0x0e)
11227          */
11228         /* set vol=0 to output mixers */
11229         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11230         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11231         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11232         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11233
11234         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11235         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11236
11237         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11238         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11239         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11240         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11241         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11242         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11243         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11244         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11245
11246         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11247         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11248         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11249         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11250         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11251         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11252         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11253
11254         /* set PCBEEP vol = 0, mute connections */
11255         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11256         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11257         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11258
11259         /* Unmute Selector 23h,24h and set the default input to mic-in */
11260
11261         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11262         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11263         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11264         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11265
11266         { }
11267 };
11268
11269 /*
11270  * generic initialization of ADC, input mixers and output mixers
11271  */
11272 static struct hda_verb alc268_volume_init_verbs[] = {
11273         /* set output DAC */
11274         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11275         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11276         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11277         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11278
11279         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11280         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11281         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11282         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11283         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11284
11285         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11286         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11287         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11288         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11289         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11290
11291         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11292         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11293         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11294         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11295
11296         /* set PCBEEP vol = 0, mute connections */
11297         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11298         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11299         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11300
11301         { }
11302 };
11303
11304 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11305         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11306         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11307         {
11308                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11309                 /* The multiple "Capture Source" controls confuse alsamixer
11310                  * So call somewhat different..
11311                  */
11312                 /* .name = "Capture Source", */
11313                 .name = "Input Source",
11314                 .count = 1,
11315                 .info = alc_mux_enum_info,
11316                 .get = alc_mux_enum_get,
11317                 .put = alc_mux_enum_put,
11318         },
11319         { } /* end */
11320 };
11321
11322 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11323         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11324         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11325         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11326         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11327         {
11328                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11329                 /* The multiple "Capture Source" controls confuse alsamixer
11330                  * So call somewhat different..
11331                  */
11332                 /* .name = "Capture Source", */
11333                 .name = "Input Source",
11334                 .count = 2,
11335                 .info = alc_mux_enum_info,
11336                 .get = alc_mux_enum_get,
11337                 .put = alc_mux_enum_put,
11338         },
11339         { } /* end */
11340 };
11341
11342 static struct hda_input_mux alc268_capture_source = {
11343         .num_items = 4,
11344         .items = {
11345                 { "Mic", 0x0 },
11346                 { "Front Mic", 0x1 },
11347                 { "Line", 0x2 },
11348                 { "CD", 0x3 },
11349         },
11350 };
11351
11352 static struct hda_input_mux alc268_acer_capture_source = {
11353         .num_items = 3,
11354         .items = {
11355                 { "Mic", 0x0 },
11356                 { "Internal Mic", 0x1 },
11357                 { "Line", 0x2 },
11358         },
11359 };
11360
11361 static struct hda_input_mux alc268_acer_dmic_capture_source = {
11362         .num_items = 3,
11363         .items = {
11364                 { "Mic", 0x0 },
11365                 { "Internal Mic", 0x6 },
11366                 { "Line", 0x2 },
11367         },
11368 };
11369
11370 #ifdef CONFIG_SND_DEBUG
11371 static struct snd_kcontrol_new alc268_test_mixer[] = {
11372         /* Volume widgets */
11373         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11374         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11375         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11376         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11377         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11378         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11379         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11380         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11381         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11382         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11383         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11384         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11385         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11386         /* The below appears problematic on some hardwares */
11387         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11388         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11389         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11390         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11391         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11392
11393         /* Modes for retasking pin widgets */
11394         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11395         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11396         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11397         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11398
11399         /* Controls for GPIO pins, assuming they are configured as outputs */
11400         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11401         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11402         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11403         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11404
11405         /* Switches to allow the digital SPDIF output pin to be enabled.
11406          * The ALC268 does not have an SPDIF input.
11407          */
11408         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11409
11410         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11411          * this output to turn on an external amplifier.
11412          */
11413         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11414         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11415
11416         { } /* end */
11417 };
11418 #endif
11419
11420 /* create input playback/capture controls for the given pin */
11421 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11422                                     const char *ctlname, int idx)
11423 {
11424         char name[32];
11425         int err;
11426
11427         sprintf(name, "%s Playback Volume", ctlname);
11428         if (nid == 0x14) {
11429                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11430                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11431                                                       HDA_OUTPUT));
11432                 if (err < 0)
11433                         return err;
11434         } else if (nid == 0x15) {
11435                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11436                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11437                                                       HDA_OUTPUT));
11438                 if (err < 0)
11439                         return err;
11440         } else
11441                 return -1;
11442         sprintf(name, "%s Playback Switch", ctlname);
11443         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11444                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11445         if (err < 0)
11446                 return err;
11447         return 0;
11448 }
11449
11450 /* add playback controls from the parsed DAC table */
11451 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11452                                              const struct auto_pin_cfg *cfg)
11453 {
11454         hda_nid_t nid;
11455         int err;
11456
11457         spec->multiout.num_dacs = 2;    /* only use one dac */
11458         spec->multiout.dac_nids = spec->private_dac_nids;
11459         spec->multiout.dac_nids[0] = 2;
11460         spec->multiout.dac_nids[1] = 3;
11461
11462         nid = cfg->line_out_pins[0];
11463         if (nid)
11464                 alc268_new_analog_output(spec, nid, "Front", 0);
11465
11466         nid = cfg->speaker_pins[0];
11467         if (nid == 0x1d) {
11468                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11469                                   "Speaker Playback Volume",
11470                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11471                 if (err < 0)
11472                         return err;
11473         }
11474         nid = cfg->hp_pins[0];
11475         if (nid)
11476                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11477
11478         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11479         if (nid == 0x16) {
11480                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11481                                   "Mono Playback Switch",
11482                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11483                 if (err < 0)
11484                         return err;
11485         }
11486         return 0;
11487 }
11488
11489 /* create playback/capture controls for input pins */
11490 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11491                                                 const struct auto_pin_cfg *cfg)
11492 {
11493         struct hda_input_mux *imux = &spec->private_imux;
11494         int i, idx1;
11495
11496         for (i = 0; i < AUTO_PIN_LAST; i++) {
11497                 switch(cfg->input_pins[i]) {
11498                 case 0x18:
11499                         idx1 = 0;       /* Mic 1 */
11500                         break;
11501                 case 0x19:
11502                         idx1 = 1;       /* Mic 2 */
11503                         break;
11504                 case 0x1a:
11505                         idx1 = 2;       /* Line In */
11506                         break;
11507                 case 0x1c:
11508                         idx1 = 3;       /* CD */
11509                         break;
11510                 case 0x12:
11511                 case 0x13:
11512                         idx1 = 6;       /* digital mics */
11513                         break;
11514                 default:
11515                         continue;
11516                 }
11517                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11518                 imux->items[imux->num_items].index = idx1;
11519                 imux->num_items++;
11520         }
11521         return 0;
11522 }
11523
11524 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11525 {
11526         struct alc_spec *spec = codec->spec;
11527         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11528         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11529         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11530         unsigned int    dac_vol1, dac_vol2;
11531
11532         if (speaker_nid) {
11533                 snd_hda_codec_write(codec, speaker_nid, 0,
11534                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11535                 snd_hda_codec_write(codec, 0x0f, 0,
11536                                     AC_VERB_SET_AMP_GAIN_MUTE,
11537                                     AMP_IN_UNMUTE(1));
11538                 snd_hda_codec_write(codec, 0x10, 0,
11539                                     AC_VERB_SET_AMP_GAIN_MUTE,
11540                                     AMP_IN_UNMUTE(1));
11541         } else {
11542                 snd_hda_codec_write(codec, 0x0f, 0,
11543                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11544                 snd_hda_codec_write(codec, 0x10, 0,
11545                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11546         }
11547
11548         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11549         if (line_nid == 0x14)
11550                 dac_vol2 = AMP_OUT_ZERO;
11551         else if (line_nid == 0x15)
11552                 dac_vol1 = AMP_OUT_ZERO;
11553         if (hp_nid == 0x14)
11554                 dac_vol2 = AMP_OUT_ZERO;
11555         else if (hp_nid == 0x15)
11556                 dac_vol1 = AMP_OUT_ZERO;
11557         if (line_nid != 0x16 || hp_nid != 0x16 ||
11558             spec->autocfg.line_out_pins[1] != 0x16 ||
11559             spec->autocfg.line_out_pins[2] != 0x16)
11560                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11561
11562         snd_hda_codec_write(codec, 0x02, 0,
11563                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11564         snd_hda_codec_write(codec, 0x03, 0,
11565                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11566 }
11567
11568 /* pcm configuration: identiacal with ALC880 */
11569 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11570 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11571 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11572 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11573
11574 /*
11575  * BIOS auto configuration
11576  */
11577 static int alc268_parse_auto_config(struct hda_codec *codec)
11578 {
11579         struct alc_spec *spec = codec->spec;
11580         int err;
11581         static hda_nid_t alc268_ignore[] = { 0 };
11582
11583         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11584                                            alc268_ignore);
11585         if (err < 0)
11586                 return err;
11587         if (!spec->autocfg.line_outs)
11588                 return 0; /* can't find valid BIOS pin config */
11589
11590         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11591         if (err < 0)
11592                 return err;
11593         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11594         if (err < 0)
11595                 return err;
11596
11597         spec->multiout.max_channels = 2;
11598
11599         /* digital only support output */
11600         if (spec->autocfg.dig_out_pin)
11601                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11602
11603         if (spec->kctls.list)
11604                 add_mixer(spec, spec->kctls.list);
11605
11606         if (spec->autocfg.speaker_pins[0] != 0x1d)
11607                 add_mixer(spec, alc268_beep_mixer);
11608
11609         add_verb(spec, alc268_volume_init_verbs);
11610         spec->num_mux_defs = 1;
11611         spec->input_mux = &spec->private_imux;
11612
11613         err = alc_auto_add_mic_boost(codec);
11614         if (err < 0)
11615                 return err;
11616
11617         store_pin_configs(codec);
11618         return 1;
11619 }
11620
11621 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
11622 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
11623 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
11624
11625 /* init callback for auto-configuration model -- overriding the default init */
11626 static void alc268_auto_init(struct hda_codec *codec)
11627 {
11628         struct alc_spec *spec = codec->spec;
11629         alc268_auto_init_multi_out(codec);
11630         alc268_auto_init_hp_out(codec);
11631         alc268_auto_init_mono_speaker_out(codec);
11632         alc268_auto_init_analog_input(codec);
11633         if (spec->unsol_event)
11634                 alc_inithook(codec);
11635 }
11636
11637 /*
11638  * configuration and preset
11639  */
11640 static const char *alc268_models[ALC268_MODEL_LAST] = {
11641         [ALC267_QUANTA_IL1]     = "quanta-il1",
11642         [ALC268_3ST]            = "3stack",
11643         [ALC268_TOSHIBA]        = "toshiba",
11644         [ALC268_ACER]           = "acer",
11645         [ALC268_ACER_DMIC]      = "acer-dmic",
11646         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
11647         [ALC268_DELL]           = "dell",
11648         [ALC268_ZEPTO]          = "zepto",
11649 #ifdef CONFIG_SND_DEBUG
11650         [ALC268_TEST]           = "test",
11651 #endif
11652         [ALC268_AUTO]           = "auto",
11653 };
11654
11655 static struct snd_pci_quirk alc268_cfg_tbl[] = {
11656         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
11657         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
11658         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
11659         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
11660         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11661         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11662                                                 ALC268_ACER_ASPIRE_ONE),
11663         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
11664         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
11665         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
11666         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
11667         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11668         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
11669         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
11670         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
11671         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
11672         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
11673         {}
11674 };
11675
11676 static struct alc_config_preset alc268_presets[] = {
11677         [ALC267_QUANTA_IL1] = {
11678                 .mixers = { alc267_quanta_il1_mixer },
11679                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11680                                 alc267_quanta_il1_verbs },
11681                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11682                 .dac_nids = alc268_dac_nids,
11683                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11684                 .adc_nids = alc268_adc_nids_alt,
11685                 .hp_nid = 0x03,
11686                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11687                 .channel_mode = alc268_modes,
11688                 .input_mux = &alc268_capture_source,
11689                 .unsol_event = alc267_quanta_il1_unsol_event,
11690                 .init_hook = alc267_quanta_il1_automute,
11691         },
11692         [ALC268_3ST] = {
11693                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11694                             alc268_beep_mixer },
11695                 .init_verbs = { alc268_base_init_verbs },
11696                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11697                 .dac_nids = alc268_dac_nids,
11698                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11699                 .adc_nids = alc268_adc_nids_alt,
11700                 .capsrc_nids = alc268_capsrc_nids,
11701                 .hp_nid = 0x03,
11702                 .dig_out_nid = ALC268_DIGOUT_NID,
11703                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11704                 .channel_mode = alc268_modes,
11705                 .input_mux = &alc268_capture_source,
11706         },
11707         [ALC268_TOSHIBA] = {
11708                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11709                             alc268_beep_mixer },
11710                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11711                                 alc268_toshiba_verbs },
11712                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11713                 .dac_nids = alc268_dac_nids,
11714                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11715                 .adc_nids = alc268_adc_nids_alt,
11716                 .capsrc_nids = alc268_capsrc_nids,
11717                 .hp_nid = 0x03,
11718                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11719                 .channel_mode = alc268_modes,
11720                 .input_mux = &alc268_capture_source,
11721                 .unsol_event = alc268_toshiba_unsol_event,
11722                 .init_hook = alc268_toshiba_automute,
11723         },
11724         [ALC268_ACER] = {
11725                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
11726                             alc268_beep_mixer },
11727                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11728                                 alc268_acer_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                 .capsrc_nids = alc268_capsrc_nids,
11734                 .hp_nid = 0x02,
11735                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11736                 .channel_mode = alc268_modes,
11737                 .input_mux = &alc268_acer_capture_source,
11738                 .unsol_event = alc268_acer_unsol_event,
11739                 .init_hook = alc268_acer_init_hook,
11740         },
11741         [ALC268_ACER_DMIC] = {
11742                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
11743                             alc268_beep_mixer },
11744                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11745                                 alc268_acer_verbs },
11746                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11747                 .dac_nids = alc268_dac_nids,
11748                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11749                 .adc_nids = alc268_adc_nids_alt,
11750                 .capsrc_nids = alc268_capsrc_nids,
11751                 .hp_nid = 0x02,
11752                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11753                 .channel_mode = alc268_modes,
11754                 .input_mux = &alc268_acer_dmic_capture_source,
11755                 .unsol_event = alc268_acer_unsol_event,
11756                 .init_hook = alc268_acer_init_hook,
11757         },
11758         [ALC268_ACER_ASPIRE_ONE] = {
11759                 .mixers = { alc268_acer_aspire_one_mixer,
11760                                 alc268_capture_alt_mixer },
11761                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11762                                 alc268_acer_aspire_one_verbs },
11763                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11764                 .dac_nids = alc268_dac_nids,
11765                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11766                 .adc_nids = alc268_adc_nids_alt,
11767                 .capsrc_nids = alc268_capsrc_nids,
11768                 .hp_nid = 0x03,
11769                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11770                 .channel_mode = alc268_modes,
11771                 .input_mux = &alc268_acer_lc_capture_source,
11772                 .unsol_event = alc268_acer_lc_unsol_event,
11773                 .init_hook = alc268_acer_lc_init_hook,
11774         },
11775         [ALC268_DELL] = {
11776                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
11777                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11778                                 alc268_dell_verbs },
11779                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11780                 .dac_nids = alc268_dac_nids,
11781                 .hp_nid = 0x02,
11782                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11783                 .channel_mode = alc268_modes,
11784                 .unsol_event = alc268_dell_unsol_event,
11785                 .init_hook = alc268_dell_init_hook,
11786                 .input_mux = &alc268_capture_source,
11787         },
11788         [ALC268_ZEPTO] = {
11789                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11790                             alc268_beep_mixer },
11791                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11792                                 alc268_toshiba_verbs },
11793                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11794                 .dac_nids = alc268_dac_nids,
11795                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11796                 .adc_nids = alc268_adc_nids_alt,
11797                 .capsrc_nids = alc268_capsrc_nids,
11798                 .hp_nid = 0x03,
11799                 .dig_out_nid = ALC268_DIGOUT_NID,
11800                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11801                 .channel_mode = alc268_modes,
11802                 .input_mux = &alc268_capture_source,
11803                 .unsol_event = alc268_toshiba_unsol_event,
11804                 .init_hook = alc268_toshiba_automute
11805         },
11806 #ifdef CONFIG_SND_DEBUG
11807         [ALC268_TEST] = {
11808                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11809                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11810                                 alc268_volume_init_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                 .dig_out_nid = ALC268_DIGOUT_NID,
11818                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11819                 .channel_mode = alc268_modes,
11820                 .input_mux = &alc268_capture_source,
11821         },
11822 #endif
11823 };
11824
11825 static int patch_alc268(struct hda_codec *codec)
11826 {
11827         struct alc_spec *spec;
11828         int board_config;
11829         int err;
11830
11831         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11832         if (spec == NULL)
11833                 return -ENOMEM;
11834
11835         codec->spec = spec;
11836
11837         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11838                                                   alc268_models,
11839                                                   alc268_cfg_tbl);
11840
11841         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11842                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11843                        "trying auto-probe from BIOS...\n");
11844                 board_config = ALC268_AUTO;
11845         }
11846
11847         if (board_config == ALC268_AUTO) {
11848                 /* automatic parse from the BIOS config */
11849                 err = alc268_parse_auto_config(codec);
11850                 if (err < 0) {
11851                         alc_free(codec);
11852                         return err;
11853                 } else if (!err) {
11854                         printk(KERN_INFO
11855                                "hda_codec: Cannot set up configuration "
11856                                "from BIOS.  Using base mode...\n");
11857                         board_config = ALC268_3ST;
11858                 }
11859         }
11860
11861         if (board_config != ALC268_AUTO)
11862                 setup_preset(spec, &alc268_presets[board_config]);
11863
11864         if (codec->vendor_id == 0x10ec0267) {
11865                 spec->stream_name_analog = "ALC267 Analog";
11866                 spec->stream_name_digital = "ALC267 Digital";
11867         } else {
11868                 spec->stream_name_analog = "ALC268 Analog";
11869                 spec->stream_name_digital = "ALC268 Digital";
11870         }
11871
11872         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11873         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11874         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11875
11876         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11877
11878         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11879                 /* override the amp caps for beep generator */
11880                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11881                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11882                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11883                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11884                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11885
11886         if (!spec->adc_nids && spec->input_mux) {
11887                 /* check whether NID 0x07 is valid */
11888                 unsigned int wcap = get_wcaps(codec, 0x07);
11889                 int i;
11890
11891                 /* get type */
11892                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11893                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11894                         spec->adc_nids = alc268_adc_nids_alt;
11895                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11896                         add_mixer(spec, alc268_capture_alt_mixer);
11897                 } else {
11898                         spec->adc_nids = alc268_adc_nids;
11899                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11900                         add_mixer(spec, alc268_capture_mixer);
11901                 }
11902                 spec->capsrc_nids = alc268_capsrc_nids;
11903                 /* set default input source */
11904                 for (i = 0; i < spec->num_adc_nids; i++)
11905                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11906                                 0, AC_VERB_SET_CONNECT_SEL,
11907                                 spec->input_mux->items[0].index);
11908         }
11909
11910         spec->vmaster_nid = 0x02;
11911
11912         codec->patch_ops = alc_patch_ops;
11913         if (board_config == ALC268_AUTO)
11914                 spec->init_hook = alc268_auto_init;
11915
11916         return 0;
11917 }
11918
11919 /*
11920  *  ALC269 channel source setting (2 channel)
11921  */
11922 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11923
11924 #define alc269_dac_nids         alc260_dac_nids
11925
11926 static hda_nid_t alc269_adc_nids[1] = {
11927         /* ADC1 */
11928         0x08,
11929 };
11930
11931 static hda_nid_t alc269_capsrc_nids[1] = {
11932         0x23,
11933 };
11934
11935 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11936  *       not a mux!
11937  */
11938
11939 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11940         .num_items = 2,
11941         .items = {
11942                 { "i-Mic", 0x5 },
11943                 { "e-Mic", 0x0 },
11944         },
11945 };
11946
11947 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11948         .num_items = 2,
11949         .items = {
11950                 { "i-Mic", 0x1 },
11951                 { "e-Mic", 0x0 },
11952         },
11953 };
11954
11955 #define alc269_modes            alc260_modes
11956 #define alc269_capture_source   alc880_lg_lw_capture_source
11957
11958 static struct snd_kcontrol_new alc269_base_mixer[] = {
11959         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11960         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11961         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11962         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11963         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11964         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11965         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11966         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11967         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11968         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11969         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11970         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11971         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11972         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
11973         { } /* end */
11974 };
11975
11976 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
11977         /* output mixer control */
11978         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11979         {
11980                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11981                 .name = "Master Playback Switch",
11982                 .info = snd_hda_mixer_amp_switch_info,
11983                 .get = snd_hda_mixer_amp_switch_get,
11984                 .put = alc268_acer_master_sw_put,
11985                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11986         },
11987         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11988         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11989         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11990         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11991         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11992         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11993         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
11994         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
11995         { }
11996 };
11997
11998 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
11999         /* output mixer control */
12000         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12001         {
12002                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12003                 .name = "Master Playback Switch",
12004                 .info = snd_hda_mixer_amp_switch_info,
12005                 .get = snd_hda_mixer_amp_switch_get,
12006                 .put = alc268_acer_master_sw_put,
12007                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12008         },
12009         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12010         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12011         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12012         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12013         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12014         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12015         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12016         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12017         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12018         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12019         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12020         { }
12021 };
12022
12023 /* bind volumes of both NID 0x0c and 0x0d */
12024 static struct hda_bind_ctls alc269_epc_bind_vol = {
12025         .ops = &snd_hda_bind_vol,
12026         .values = {
12027                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12028                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12029                 0
12030         },
12031 };
12032
12033 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12034         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12035         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
12036         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12037         { } /* end */
12038 };
12039
12040 /* capture mixer elements */
12041 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12042         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12043         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12044         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12045         { } /* end */
12046 };
12047
12048 /* FSC amilo */
12049 static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
12050         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12051         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12052         HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12053         { } /* end */
12054 };
12055
12056 /* beep control */
12057 static struct snd_kcontrol_new alc269_beep_mixer[] = {
12058         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12059         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12060         { } /* end */
12061 };
12062
12063 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12064         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12065         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12066         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12067         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12068         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12069         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12070         { }
12071 };
12072
12073 static struct hda_verb alc269_lifebook_verbs[] = {
12074         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12075         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12076         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12077         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12078         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12079         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12080         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12081         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12082         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12083         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12084         { }
12085 };
12086
12087 /* toggle speaker-output according to the hp-jack state */
12088 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
12089 {
12090         unsigned int present;
12091         unsigned char bits;
12092
12093         present = snd_hda_codec_read(codec, 0x15, 0,
12094                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12095         bits = present ? AMP_IN_MUTE(0) : 0;
12096         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12097                         AMP_IN_MUTE(0), bits);
12098         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12099                         AMP_IN_MUTE(0), bits);
12100
12101         snd_hda_codec_write(codec, 0x20, 0,
12102                         AC_VERB_SET_COEF_INDEX, 0x0c);
12103         snd_hda_codec_write(codec, 0x20, 0,
12104                         AC_VERB_SET_PROC_COEF, 0x680);
12105
12106         snd_hda_codec_write(codec, 0x20, 0,
12107                         AC_VERB_SET_COEF_INDEX, 0x0c);
12108         snd_hda_codec_write(codec, 0x20, 0,
12109                         AC_VERB_SET_PROC_COEF, 0x480);
12110 }
12111
12112 /* toggle speaker-output according to the hp-jacks state */
12113 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12114 {
12115         unsigned int present;
12116         unsigned char bits;
12117
12118         /* Check laptop headphone socket */
12119         present = snd_hda_codec_read(codec, 0x15, 0,
12120                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12121
12122         /* Check port replicator headphone socket */
12123         present |= snd_hda_codec_read(codec, 0x1a, 0,
12124                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12125
12126         bits = present ? AMP_IN_MUTE(0) : 0;
12127         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12128                         AMP_IN_MUTE(0), bits);
12129         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12130                         AMP_IN_MUTE(0), bits);
12131
12132         snd_hda_codec_write(codec, 0x20, 0,
12133                         AC_VERB_SET_COEF_INDEX, 0x0c);
12134         snd_hda_codec_write(codec, 0x20, 0,
12135                         AC_VERB_SET_PROC_COEF, 0x680);
12136
12137         snd_hda_codec_write(codec, 0x20, 0,
12138                         AC_VERB_SET_COEF_INDEX, 0x0c);
12139         snd_hda_codec_write(codec, 0x20, 0,
12140                         AC_VERB_SET_PROC_COEF, 0x480);
12141 }
12142
12143 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12144 {
12145         unsigned int present;
12146
12147         present = snd_hda_codec_read(codec, 0x18, 0,
12148                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12149         snd_hda_codec_write(codec, 0x23, 0,
12150                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
12151 }
12152
12153 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12154 {
12155         unsigned int present_laptop;
12156         unsigned int present_dock;
12157
12158         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
12159                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12160
12161         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
12162                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12163
12164         /* Laptop mic port overrides dock mic port, design decision */
12165         if (present_dock)
12166                 snd_hda_codec_write(codec, 0x23, 0,
12167                                 AC_VERB_SET_CONNECT_SEL, 0x3);
12168         if (present_laptop)
12169                 snd_hda_codec_write(codec, 0x23, 0,
12170                                 AC_VERB_SET_CONNECT_SEL, 0x0);
12171         if (!present_dock && !present_laptop)
12172                 snd_hda_codec_write(codec, 0x23, 0,
12173                                 AC_VERB_SET_CONNECT_SEL, 0x1);
12174 }
12175
12176 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
12177                                     unsigned int res)
12178 {
12179         if ((res >> 26) == ALC880_HP_EVENT)
12180                 alc269_quanta_fl1_speaker_automute(codec);
12181         if ((res >> 26) == ALC880_MIC_EVENT)
12182                 alc269_quanta_fl1_mic_automute(codec);
12183 }
12184
12185 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
12186                                         unsigned int res)
12187 {
12188         if ((res >> 26) == ALC880_HP_EVENT)
12189                 alc269_lifebook_speaker_automute(codec);
12190         if ((res >> 26) == ALC880_MIC_EVENT)
12191                 alc269_lifebook_mic_autoswitch(codec);
12192 }
12193
12194 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
12195 {
12196         alc269_quanta_fl1_speaker_automute(codec);
12197         alc269_quanta_fl1_mic_automute(codec);
12198 }
12199
12200 static void alc269_lifebook_init_hook(struct hda_codec *codec)
12201 {
12202         alc269_lifebook_speaker_automute(codec);
12203         alc269_lifebook_mic_autoswitch(codec);
12204 }
12205
12206 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
12207         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12208         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
12209         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12210         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
12211         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12212         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12213         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12214         {}
12215 };
12216
12217 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
12218         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12219         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
12220         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12221         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
12222         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12223         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12224         {}
12225 };
12226
12227 /* toggle speaker-output according to the hp-jack state */
12228 static void alc269_speaker_automute(struct hda_codec *codec)
12229 {
12230         unsigned int present;
12231         unsigned char bits;
12232
12233         present = snd_hda_codec_read(codec, 0x15, 0,
12234                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12235         bits = present ? AMP_IN_MUTE(0) : 0;
12236         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12237                                 AMP_IN_MUTE(0), bits);
12238         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12239                                 AMP_IN_MUTE(0), bits);
12240 }
12241
12242 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
12243 {
12244         unsigned int present;
12245
12246         present = snd_hda_codec_read(codec, 0x18, 0,
12247                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12248         snd_hda_codec_write(codec, 0x23, 0,
12249                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
12250 }
12251
12252 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
12253 {
12254         unsigned int present;
12255
12256         present = snd_hda_codec_read(codec, 0x18, 0,
12257                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12258         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12259                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12260         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12261                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12262 }
12263
12264 /* unsolicited event for HP jack sensing */
12265 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
12266                                      unsigned int res)
12267 {
12268         if ((res >> 26) == ALC880_HP_EVENT)
12269                 alc269_speaker_automute(codec);
12270
12271         if ((res >> 26) == ALC880_MIC_EVENT)
12272                 alc269_eeepc_dmic_automute(codec);
12273 }
12274
12275 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
12276 {
12277         alc269_speaker_automute(codec);
12278         alc269_eeepc_dmic_automute(codec);
12279 }
12280
12281 /* unsolicited event for HP jack sensing */
12282 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
12283                                      unsigned int res)
12284 {
12285         if ((res >> 26) == ALC880_HP_EVENT)
12286                 alc269_speaker_automute(codec);
12287
12288         if ((res >> 26) == ALC880_MIC_EVENT)
12289                 alc269_eeepc_amic_automute(codec);
12290 }
12291
12292 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
12293 {
12294         alc269_speaker_automute(codec);
12295         alc269_eeepc_amic_automute(codec);
12296 }
12297
12298 /*
12299  * generic initialization of ADC, input mixers and output mixers
12300  */
12301 static struct hda_verb alc269_init_verbs[] = {
12302         /*
12303          * Unmute ADC0 and set the default input to mic-in
12304          */
12305         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12306
12307         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
12308          * analog-loopback mixer widget
12309          * Note: PASD motherboards uses the Line In 2 as the input for
12310          * front panel mic (mic 2)
12311          */
12312         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12313         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12314         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12315         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12316         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12317         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12318
12319         /*
12320          * Set up output mixers (0x0c - 0x0e)
12321          */
12322         /* set vol=0 to output mixers */
12323         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12324         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12325
12326         /* set up input amps for analog loopback */
12327         /* Amp Indices: DAC = 0, mixer = 1 */
12328         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12329         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12330         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12331         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12332         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12333         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12334
12335         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12336         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12337         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12338         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12339         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12340         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12341         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12342
12343         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12344         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12345         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12346         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12347         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12348         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12349         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12350
12351         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12352         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12353
12354         /* FIXME: use matrix-type input source selection */
12355         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12356         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12357         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12358         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12359         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12360         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12361
12362         /* set EAPD */
12363         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12364         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12365         { }
12366 };
12367
12368 /* add playback controls from the parsed DAC table */
12369 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12370                                              const struct auto_pin_cfg *cfg)
12371 {
12372         hda_nid_t nid;
12373         int err;
12374
12375         spec->multiout.num_dacs = 1;    /* only use one dac */
12376         spec->multiout.dac_nids = spec->private_dac_nids;
12377         spec->multiout.dac_nids[0] = 2;
12378
12379         nid = cfg->line_out_pins[0];
12380         if (nid) {
12381                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12382                                   "Front Playback Volume",
12383                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12384                 if (err < 0)
12385                         return err;
12386                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12387                                   "Front Playback Switch",
12388                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12389                 if (err < 0)
12390                         return err;
12391         }
12392
12393         nid = cfg->speaker_pins[0];
12394         if (nid) {
12395                 if (!cfg->line_out_pins[0]) {
12396                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12397                                           "Speaker Playback Volume",
12398                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12399                                                               HDA_OUTPUT));
12400                         if (err < 0)
12401                                 return err;
12402                 }
12403                 if (nid == 0x16) {
12404                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12405                                           "Speaker Playback Switch",
12406                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12407                                                               HDA_OUTPUT));
12408                         if (err < 0)
12409                                 return err;
12410                 } else {
12411                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12412                                           "Speaker Playback Switch",
12413                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12414                                                               HDA_OUTPUT));
12415                         if (err < 0)
12416                                 return err;
12417                 }
12418         }
12419         nid = cfg->hp_pins[0];
12420         if (nid) {
12421                 /* spec->multiout.hp_nid = 2; */
12422                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12423                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12424                                           "Headphone Playback Volume",
12425                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12426                                                               HDA_OUTPUT));
12427                         if (err < 0)
12428                                 return err;
12429                 }
12430                 if (nid == 0x16) {
12431                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12432                                           "Headphone Playback Switch",
12433                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12434                                                               HDA_OUTPUT));
12435                         if (err < 0)
12436                                 return err;
12437                 } else {
12438                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12439                                           "Headphone Playback Switch",
12440                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12441                                                               HDA_OUTPUT));
12442                         if (err < 0)
12443                                 return err;
12444                 }
12445         }
12446         return 0;
12447 }
12448
12449 static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
12450                                                 const struct auto_pin_cfg *cfg)
12451 {
12452         int err;
12453
12454         err = alc880_auto_create_analog_input_ctls(spec, cfg);
12455         if (err < 0)
12456                 return err;
12457         /* digital-mic input pin is excluded in alc880_auto_create..()
12458          * because it's under 0x18
12459          */
12460         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
12461             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
12462                 struct hda_input_mux *imux = &spec->private_imux;
12463                 imux->items[imux->num_items].label = "Int Mic";
12464                 imux->items[imux->num_items].index = 0x05;
12465                 imux->num_items++;
12466         }
12467         return 0;
12468 }
12469
12470 #ifdef CONFIG_SND_HDA_POWER_SAVE
12471 #define alc269_loopbacks        alc880_loopbacks
12472 #endif
12473
12474 /* pcm configuration: identiacal with ALC880 */
12475 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12476 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12477 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12478 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12479
12480 /*
12481  * BIOS auto configuration
12482  */
12483 static int alc269_parse_auto_config(struct hda_codec *codec)
12484 {
12485         struct alc_spec *spec = codec->spec;
12486         int i, err;
12487         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12488
12489         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12490                                            alc269_ignore);
12491         if (err < 0)
12492                 return err;
12493
12494         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12495         if (err < 0)
12496                 return err;
12497         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12498         if (err < 0)
12499                 return err;
12500
12501         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12502
12503         if (spec->autocfg.dig_out_pin)
12504                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12505
12506         if (spec->kctls.list)
12507                 add_mixer(spec, spec->kctls.list);
12508
12509         /* create a beep mixer control if the pin 0x1d isn't assigned */
12510         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12511                 if (spec->autocfg.input_pins[i] == 0x1d)
12512                         break;
12513         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12514                 add_mixer(spec, alc269_beep_mixer);
12515
12516         add_verb(spec, alc269_init_verbs);
12517         spec->num_mux_defs = 1;
12518         spec->input_mux = &spec->private_imux;
12519         /* set default input source */
12520         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12521                                   0, AC_VERB_SET_CONNECT_SEL,
12522                                   spec->input_mux->items[0].index);
12523
12524         err = alc_auto_add_mic_boost(codec);
12525         if (err < 0)
12526                 return err;
12527
12528         if (!spec->cap_mixer)
12529                 set_capture_mixer(spec);
12530
12531         store_pin_configs(codec);
12532         return 1;
12533 }
12534
12535 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12536 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12537 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12538
12539
12540 /* init callback for auto-configuration model -- overriding the default init */
12541 static void alc269_auto_init(struct hda_codec *codec)
12542 {
12543         struct alc_spec *spec = codec->spec;
12544         alc269_auto_init_multi_out(codec);
12545         alc269_auto_init_hp_out(codec);
12546         alc269_auto_init_analog_input(codec);
12547         if (spec->unsol_event)
12548                 alc_inithook(codec);
12549 }
12550
12551 /*
12552  * configuration and preset
12553  */
12554 static const char *alc269_models[ALC269_MODEL_LAST] = {
12555         [ALC269_BASIC]                  = "basic",
12556         [ALC269_QUANTA_FL1]             = "quanta",
12557         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12558         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
12559         [ALC269_FUJITSU]                = "fujitsu",
12560         [ALC269_LIFEBOOK]               = "lifebook"
12561 };
12562
12563 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12564         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12565         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12566                       ALC269_ASUS_EEEPC_P703),
12567         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12568                       ALC269_ASUS_EEEPC_P901),
12569         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12570                       ALC269_ASUS_EEEPC_P901),
12571         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
12572         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
12573         {}
12574 };
12575
12576 static struct alc_config_preset alc269_presets[] = {
12577         [ALC269_BASIC] = {
12578                 .mixers = { alc269_base_mixer },
12579                 .init_verbs = { alc269_init_verbs },
12580                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12581                 .dac_nids = alc269_dac_nids,
12582                 .hp_nid = 0x03,
12583                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12584                 .channel_mode = alc269_modes,
12585                 .input_mux = &alc269_capture_source,
12586         },
12587         [ALC269_QUANTA_FL1] = {
12588                 .mixers = { alc269_quanta_fl1_mixer },
12589                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
12590                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12591                 .dac_nids = alc269_dac_nids,
12592                 .hp_nid = 0x03,
12593                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12594                 .channel_mode = alc269_modes,
12595                 .input_mux = &alc269_capture_source,
12596                 .unsol_event = alc269_quanta_fl1_unsol_event,
12597                 .init_hook = alc269_quanta_fl1_init_hook,
12598         },
12599         [ALC269_ASUS_EEEPC_P703] = {
12600                 .mixers = { alc269_eeepc_mixer },
12601                 .cap_mixer = alc269_epc_capture_mixer,
12602                 .init_verbs = { alc269_init_verbs,
12603                                 alc269_eeepc_amic_init_verbs },
12604                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12605                 .dac_nids = alc269_dac_nids,
12606                 .hp_nid = 0x03,
12607                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12608                 .channel_mode = alc269_modes,
12609                 .input_mux = &alc269_eeepc_amic_capture_source,
12610                 .unsol_event = alc269_eeepc_amic_unsol_event,
12611                 .init_hook = alc269_eeepc_amic_inithook,
12612         },
12613         [ALC269_ASUS_EEEPC_P901] = {
12614                 .mixers = { alc269_eeepc_mixer },
12615                 .cap_mixer = alc269_epc_capture_mixer,
12616                 .init_verbs = { alc269_init_verbs,
12617                                 alc269_eeepc_dmic_init_verbs },
12618                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12619                 .dac_nids = alc269_dac_nids,
12620                 .hp_nid = 0x03,
12621                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12622                 .channel_mode = alc269_modes,
12623                 .input_mux = &alc269_eeepc_dmic_capture_source,
12624                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12625                 .init_hook = alc269_eeepc_dmic_inithook,
12626         },
12627         [ALC269_FUJITSU] = {
12628                 .mixers = { alc269_fujitsu_mixer, alc269_beep_mixer },
12629                 .cap_mixer = alc269_epc_capture_mixer,
12630                 .init_verbs = { alc269_init_verbs,
12631                                 alc269_eeepc_dmic_init_verbs },
12632                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12633                 .dac_nids = alc269_dac_nids,
12634                 .hp_nid = 0x03,
12635                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12636                 .channel_mode = alc269_modes,
12637                 .input_mux = &alc269_eeepc_dmic_capture_source,
12638                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12639                 .init_hook = alc269_eeepc_dmic_inithook,
12640         },
12641         [ALC269_LIFEBOOK] = {
12642                 .mixers = { alc269_lifebook_mixer },
12643                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
12644                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12645                 .dac_nids = alc269_dac_nids,
12646                 .hp_nid = 0x03,
12647                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12648                 .channel_mode = alc269_modes,
12649                 .input_mux = &alc269_capture_source,
12650                 .unsol_event = alc269_lifebook_unsol_event,
12651                 .init_hook = alc269_lifebook_init_hook,
12652         },
12653 };
12654
12655 static int patch_alc269(struct hda_codec *codec)
12656 {
12657         struct alc_spec *spec;
12658         int board_config;
12659         int err;
12660
12661         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12662         if (spec == NULL)
12663                 return -ENOMEM;
12664
12665         codec->spec = spec;
12666
12667         alc_fix_pll_init(codec, 0x20, 0x04, 15);
12668
12669         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
12670                                                   alc269_models,
12671                                                   alc269_cfg_tbl);
12672
12673         if (board_config < 0) {
12674                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
12675                        "trying auto-probe from BIOS...\n");
12676                 board_config = ALC269_AUTO;
12677         }
12678
12679         if (board_config == ALC269_AUTO) {
12680                 /* automatic parse from the BIOS config */
12681                 err = alc269_parse_auto_config(codec);
12682                 if (err < 0) {
12683                         alc_free(codec);
12684                         return err;
12685                 } else if (!err) {
12686                         printk(KERN_INFO
12687                                "hda_codec: Cannot set up configuration "
12688                                "from BIOS.  Using base mode...\n");
12689                         board_config = ALC269_BASIC;
12690                 }
12691         }
12692
12693         if (board_config != ALC269_AUTO)
12694                 setup_preset(spec, &alc269_presets[board_config]);
12695
12696         spec->stream_name_analog = "ALC269 Analog";
12697         spec->stream_analog_playback = &alc269_pcm_analog_playback;
12698         spec->stream_analog_capture = &alc269_pcm_analog_capture;
12699
12700         spec->stream_name_digital = "ALC269 Digital";
12701         spec->stream_digital_playback = &alc269_pcm_digital_playback;
12702         spec->stream_digital_capture = &alc269_pcm_digital_capture;
12703
12704         spec->adc_nids = alc269_adc_nids;
12705         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12706         spec->capsrc_nids = alc269_capsrc_nids;
12707         if (!spec->cap_mixer)
12708                 set_capture_mixer(spec);
12709
12710         codec->patch_ops = alc_patch_ops;
12711         if (board_config == ALC269_AUTO)
12712                 spec->init_hook = alc269_auto_init;
12713 #ifdef CONFIG_SND_HDA_POWER_SAVE
12714         if (!spec->loopback.amplist)
12715                 spec->loopback.amplist = alc269_loopbacks;
12716 #endif
12717
12718         return 0;
12719 }
12720
12721 /*
12722  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
12723  */
12724
12725 /*
12726  * set the path ways for 2 channel output
12727  * need to set the codec line out and mic 1 pin widgets to inputs
12728  */
12729 static struct hda_verb alc861_threestack_ch2_init[] = {
12730         /* set pin widget 1Ah (line in) for input */
12731         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12732         /* set pin widget 18h (mic1/2) for input, for mic also enable
12733          * the vref
12734          */
12735         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12736
12737         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12738 #if 0
12739         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12740         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12741 #endif
12742         { } /* end */
12743 };
12744 /*
12745  * 6ch mode
12746  * need to set the codec line out and mic 1 pin widgets to outputs
12747  */
12748 static struct hda_verb alc861_threestack_ch6_init[] = {
12749         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12750         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12751         /* set pin widget 18h (mic1) for output (CLFE)*/
12752         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12753
12754         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12755         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12756
12757         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12758 #if 0
12759         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12760         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12761 #endif
12762         { } /* end */
12763 };
12764
12765 static struct hda_channel_mode alc861_threestack_modes[2] = {
12766         { 2, alc861_threestack_ch2_init },
12767         { 6, alc861_threestack_ch6_init },
12768 };
12769 /* Set mic1 as input and unmute the mixer */
12770 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
12771         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12772         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12773         { } /* end */
12774 };
12775 /* Set mic1 as output and mute mixer */
12776 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
12777         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12778         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12779         { } /* end */
12780 };
12781
12782 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
12783         { 2, alc861_uniwill_m31_ch2_init },
12784         { 4, alc861_uniwill_m31_ch4_init },
12785 };
12786
12787 /* Set mic1 and line-in as input and unmute the mixer */
12788 static struct hda_verb alc861_asus_ch2_init[] = {
12789         /* set pin widget 1Ah (line in) for input */
12790         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12791         /* set pin widget 18h (mic1/2) for input, for mic also enable
12792          * the vref
12793          */
12794         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12795
12796         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12797 #if 0
12798         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12799         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12800 #endif
12801         { } /* end */
12802 };
12803 /* Set mic1 nad line-in as output and mute mixer */
12804 static struct hda_verb alc861_asus_ch6_init[] = {
12805         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12806         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12807         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12808         /* set pin widget 18h (mic1) for output (CLFE)*/
12809         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12810         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12811         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12812         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12813
12814         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12815 #if 0
12816         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12817         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12818 #endif
12819         { } /* end */
12820 };
12821
12822 static struct hda_channel_mode alc861_asus_modes[2] = {
12823         { 2, alc861_asus_ch2_init },
12824         { 6, alc861_asus_ch6_init },
12825 };
12826
12827 /* patch-ALC861 */
12828
12829 static struct snd_kcontrol_new alc861_base_mixer[] = {
12830         /* output mixer control */
12831         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12832         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12833         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12834         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12835         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12836
12837         /*Input mixer control */
12838         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12839            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12840         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12841         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12842         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12843         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12844         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12845         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12846         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12847         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12848
12849         { } /* end */
12850 };
12851
12852 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12853         /* output mixer control */
12854         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12855         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12856         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12857         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12858         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12859
12860         /* Input mixer control */
12861         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12862            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12863         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12864         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12865         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12866         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12867         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12868         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12869         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12870         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12871
12872         {
12873                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12874                 .name = "Channel Mode",
12875                 .info = alc_ch_mode_info,
12876                 .get = alc_ch_mode_get,
12877                 .put = alc_ch_mode_put,
12878                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
12879         },
12880         { } /* end */
12881 };
12882
12883 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
12884         /* output mixer control */
12885         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12886         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12887         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12888
12889         { } /* end */
12890 };
12891
12892 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
12893         /* output mixer control */
12894         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12895         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12896         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12897         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12898         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12899
12900         /* Input mixer control */
12901         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12902            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12903         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12904         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12905         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12906         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12907         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12908         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12909         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12910         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12911
12912         {
12913                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12914                 .name = "Channel Mode",
12915                 .info = alc_ch_mode_info,
12916                 .get = alc_ch_mode_get,
12917                 .put = alc_ch_mode_put,
12918                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
12919         },
12920         { } /* end */
12921 };
12922
12923 static struct snd_kcontrol_new alc861_asus_mixer[] = {
12924         /* output mixer control */
12925         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12926         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12927         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12928         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12929         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12930
12931         /* Input mixer control */
12932         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12933         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12934         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12935         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12936         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12937         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12938         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12939         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12940         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12941         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
12942
12943         {
12944                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12945                 .name = "Channel Mode",
12946                 .info = alc_ch_mode_info,
12947                 .get = alc_ch_mode_get,
12948                 .put = alc_ch_mode_put,
12949                 .private_value = ARRAY_SIZE(alc861_asus_modes),
12950         },
12951         { }
12952 };
12953
12954 /* additional mixer */
12955 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
12956         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12957         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12958         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
12959         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
12960         { }
12961 };
12962
12963 /*
12964  * generic initialization of ADC, input mixers and output mixers
12965  */
12966 static struct hda_verb alc861_base_init_verbs[] = {
12967         /*
12968          * Unmute ADC0 and set the default input to mic-in
12969          */
12970         /* port-A for surround (rear panel) */
12971         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12972         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
12973         /* port-B for mic-in (rear panel) with vref */
12974         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12975         /* port-C for line-in (rear panel) */
12976         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12977         /* port-D for Front */
12978         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12979         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12980         /* port-E for HP out (front panel) */
12981         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
12982         /* route front PCM to HP */
12983         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12984         /* port-F for mic-in (front panel) with vref */
12985         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12986         /* port-G for CLFE (rear panel) */
12987         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12988         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12989         /* port-H for side (rear panel) */
12990         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12991         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
12992         /* CD-in */
12993         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12994         /* route front mic to ADC1*/
12995         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12996         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12997
12998         /* Unmute DAC0~3 & spdif out*/
12999         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13000         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13001         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13002         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13003         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13004
13005         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13006         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13007         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13008         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13009         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13010
13011         /* Unmute Stereo Mixer 15 */
13012         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13013         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13014         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13015         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13016
13017         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13018         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13019         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13020         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13021         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13022         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13023         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13024         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13025         /* hp used DAC 3 (Front) */
13026         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13027         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13028
13029         { }
13030 };
13031
13032 static struct hda_verb alc861_threestack_init_verbs[] = {
13033         /*
13034          * Unmute ADC0 and set the default input to mic-in
13035          */
13036         /* port-A for surround (rear panel) */
13037         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13038         /* port-B for mic-in (rear panel) with vref */
13039         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13040         /* port-C for line-in (rear panel) */
13041         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13042         /* port-D for Front */
13043         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13044         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13045         /* port-E for HP out (front panel) */
13046         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13047         /* route front PCM to HP */
13048         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13049         /* port-F for mic-in (front panel) with vref */
13050         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13051         /* port-G for CLFE (rear panel) */
13052         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13053         /* port-H for side (rear panel) */
13054         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13055         /* CD-in */
13056         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13057         /* route front mic to ADC1*/
13058         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13059         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13060         /* Unmute DAC0~3 & spdif out*/
13061         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13062         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13063         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13064         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13065         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13066
13067         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13068         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13069         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13070         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13071         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13072
13073         /* Unmute Stereo Mixer 15 */
13074         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13075         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13076         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13077         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13078
13079         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13080         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13081         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13082         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13083         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13084         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13085         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13086         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13087         /* hp used DAC 3 (Front) */
13088         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13089         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13090         { }
13091 };
13092
13093 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13094         /*
13095          * Unmute ADC0 and set the default input to mic-in
13096          */
13097         /* port-A for surround (rear panel) */
13098         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13099         /* port-B for mic-in (rear panel) with vref */
13100         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13101         /* port-C for line-in (rear panel) */
13102         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13103         /* port-D for Front */
13104         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13105         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13106         /* port-E for HP out (front panel) */
13107         /* this has to be set to VREF80 */
13108         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13109         /* route front PCM to HP */
13110         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13111         /* port-F for mic-in (front panel) with vref */
13112         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13113         /* port-G for CLFE (rear panel) */
13114         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13115         /* port-H for side (rear panel) */
13116         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13117         /* CD-in */
13118         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13119         /* route front mic to ADC1*/
13120         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13121         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13122         /* Unmute DAC0~3 & spdif out*/
13123         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13124         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13125         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13126         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13127         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13128
13129         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13130         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13131         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13132         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13133         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13134
13135         /* Unmute Stereo Mixer 15 */
13136         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13137         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13138         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13139         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13140
13141         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13142         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13143         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13144         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13145         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13146         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13147         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13148         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13149         /* hp used DAC 3 (Front) */
13150         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13151         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13152         { }
13153 };
13154
13155 static struct hda_verb alc861_asus_init_verbs[] = {
13156         /*
13157          * Unmute ADC0 and set the default input to mic-in
13158          */
13159         /* port-A for surround (rear panel)
13160          * according to codec#0 this is the HP jack
13161          */
13162         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
13163         /* route front PCM to HP */
13164         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
13165         /* port-B for mic-in (rear panel) with vref */
13166         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13167         /* port-C for line-in (rear panel) */
13168         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13169         /* port-D for Front */
13170         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13171         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13172         /* port-E for HP out (front panel) */
13173         /* this has to be set to VREF80 */
13174         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13175         /* route front PCM to HP */
13176         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13177         /* port-F for mic-in (front panel) with vref */
13178         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13179         /* port-G for CLFE (rear panel) */
13180         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13181         /* port-H for side (rear panel) */
13182         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13183         /* CD-in */
13184         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13185         /* route front mic to ADC1*/
13186         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13187         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13188         /* Unmute DAC0~3 & spdif out*/
13189         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13190         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13191         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13192         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13193         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13194         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13195         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13196         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13197         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13198         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13199
13200         /* Unmute Stereo Mixer 15 */
13201         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13202         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13203         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13204         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13205
13206         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13207         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13208         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13209         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13210         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13211         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13212         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13213         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13214         /* hp used DAC 3 (Front) */
13215         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13216         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13217         { }
13218 };
13219
13220 /* additional init verbs for ASUS laptops */
13221 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
13222         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
13223         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
13224         { }
13225 };
13226
13227 /*
13228  * generic initialization of ADC, input mixers and output mixers
13229  */
13230 static struct hda_verb alc861_auto_init_verbs[] = {
13231         /*
13232          * Unmute ADC0 and set the default input to mic-in
13233          */
13234         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
13235         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13236
13237         /* Unmute DAC0~3 & spdif out*/
13238         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13239         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13240         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13241         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13242         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13243
13244         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13245         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13246         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13247         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13248         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13249
13250         /* Unmute Stereo Mixer 15 */
13251         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13252         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13253         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13254         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
13255
13256         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13257         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13258         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13259         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13260         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13261         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13262         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13263         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13264
13265         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13266         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13267         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13268         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13269         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13270         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13271         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13272         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13273
13274         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
13275
13276         { }
13277 };
13278
13279 static struct hda_verb alc861_toshiba_init_verbs[] = {
13280         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13281
13282         { }
13283 };
13284
13285 /* toggle speaker-output according to the hp-jack state */
13286 static void alc861_toshiba_automute(struct hda_codec *codec)
13287 {
13288         unsigned int present;
13289
13290         present = snd_hda_codec_read(codec, 0x0f, 0,
13291                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13292         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
13293                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13294         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
13295                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
13296 }
13297
13298 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
13299                                        unsigned int res)
13300 {
13301         if ((res >> 26) == ALC880_HP_EVENT)
13302                 alc861_toshiba_automute(codec);
13303 }
13304
13305 /* pcm configuration: identiacal with ALC880 */
13306 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
13307 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
13308 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
13309 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
13310
13311
13312 #define ALC861_DIGOUT_NID       0x07
13313
13314 static struct hda_channel_mode alc861_8ch_modes[1] = {
13315         { 8, NULL }
13316 };
13317
13318 static hda_nid_t alc861_dac_nids[4] = {
13319         /* front, surround, clfe, side */
13320         0x03, 0x06, 0x05, 0x04
13321 };
13322
13323 static hda_nid_t alc660_dac_nids[3] = {
13324         /* front, clfe, surround */
13325         0x03, 0x05, 0x06
13326 };
13327
13328 static hda_nid_t alc861_adc_nids[1] = {
13329         /* ADC0-2 */
13330         0x08,
13331 };
13332
13333 static struct hda_input_mux alc861_capture_source = {
13334         .num_items = 5,
13335         .items = {
13336                 { "Mic", 0x0 },
13337                 { "Front Mic", 0x3 },
13338                 { "Line", 0x1 },
13339                 { "CD", 0x4 },
13340                 { "Mixer", 0x5 },
13341         },
13342 };
13343
13344 /* fill in the dac_nids table from the parsed pin configuration */
13345 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13346                                      const struct auto_pin_cfg *cfg)
13347 {
13348         int i;
13349         hda_nid_t nid;
13350
13351         spec->multiout.dac_nids = spec->private_dac_nids;
13352         for (i = 0; i < cfg->line_outs; i++) {
13353                 nid = cfg->line_out_pins[i];
13354                 if (nid) {
13355                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13356                                 continue;
13357                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13358                 }
13359         }
13360         spec->multiout.num_dacs = cfg->line_outs;
13361         return 0;
13362 }
13363
13364 /* add playback controls from the parsed DAC table */
13365 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13366                                              const struct auto_pin_cfg *cfg)
13367 {
13368         char name[32];
13369         static const char *chname[4] = {
13370                 "Front", "Surround", NULL /*CLFE*/, "Side"
13371         };
13372         hda_nid_t nid;
13373         int i, idx, err;
13374
13375         for (i = 0; i < cfg->line_outs; i++) {
13376                 nid = spec->multiout.dac_nids[i];
13377                 if (!nid)
13378                         continue;
13379                 if (nid == 0x05) {
13380                         /* Center/LFE */
13381                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13382                                           "Center Playback Switch",
13383                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13384                                                               HDA_OUTPUT));
13385                         if (err < 0)
13386                                 return err;
13387                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13388                                           "LFE Playback Switch",
13389                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13390                                                               HDA_OUTPUT));
13391                         if (err < 0)
13392                                 return err;
13393                 } else {
13394                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13395                              idx++)
13396                                 if (nid == alc861_dac_nids[idx])
13397                                         break;
13398                         sprintf(name, "%s Playback Switch", chname[idx]);
13399                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13400                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13401                                                               HDA_OUTPUT));
13402                         if (err < 0)
13403                                 return err;
13404                 }
13405         }
13406         return 0;
13407 }
13408
13409 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13410 {
13411         int err;
13412         hda_nid_t nid;
13413
13414         if (!pin)
13415                 return 0;
13416
13417         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13418                 nid = 0x03;
13419                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13420                                   "Headphone Playback Switch",
13421                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13422                 if (err < 0)
13423                         return err;
13424                 spec->multiout.hp_nid = nid;
13425         }
13426         return 0;
13427 }
13428
13429 /* create playback/capture controls for input pins */
13430 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13431                                                 const struct auto_pin_cfg *cfg)
13432 {
13433         struct hda_input_mux *imux = &spec->private_imux;
13434         int i, err, idx, idx1;
13435
13436         for (i = 0; i < AUTO_PIN_LAST; i++) {
13437                 switch (cfg->input_pins[i]) {
13438                 case 0x0c:
13439                         idx1 = 1;
13440                         idx = 2;        /* Line In */
13441                         break;
13442                 case 0x0f:
13443                         idx1 = 2;
13444                         idx = 2;        /* Line In */
13445                         break;
13446                 case 0x0d:
13447                         idx1 = 0;
13448                         idx = 1;        /* Mic In */
13449                         break;
13450                 case 0x10:
13451                         idx1 = 3;
13452                         idx = 1;        /* Mic In */
13453                         break;
13454                 case 0x11:
13455                         idx1 = 4;
13456                         idx = 0;        /* CD */
13457                         break;
13458                 default:
13459                         continue;
13460                 }
13461
13462                 err = new_analog_input(spec, cfg->input_pins[i],
13463                                        auto_pin_cfg_labels[i], idx, 0x15);
13464                 if (err < 0)
13465                         return err;
13466
13467                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13468                 imux->items[imux->num_items].index = idx1;
13469                 imux->num_items++;
13470         }
13471         return 0;
13472 }
13473
13474 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13475                                               hda_nid_t nid,
13476                                               int pin_type, int dac_idx)
13477 {
13478         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13479                             pin_type);
13480         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13481                             AMP_OUT_UNMUTE);
13482 }
13483
13484 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13485 {
13486         struct alc_spec *spec = codec->spec;
13487         int i;
13488
13489         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13490         for (i = 0; i < spec->autocfg.line_outs; i++) {
13491                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13492                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13493                 if (nid)
13494                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13495                                                           spec->multiout.dac_nids[i]);
13496         }
13497 }
13498
13499 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13500 {
13501         struct alc_spec *spec = codec->spec;
13502         hda_nid_t pin;
13503
13504         pin = spec->autocfg.hp_pins[0];
13505         if (pin) /* connect to front */
13506                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13507                                                   spec->multiout.dac_nids[0]);
13508         pin = spec->autocfg.speaker_pins[0];
13509         if (pin)
13510                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13511 }
13512
13513 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13514 {
13515         struct alc_spec *spec = codec->spec;
13516         int i;
13517
13518         for (i = 0; i < AUTO_PIN_LAST; i++) {
13519                 hda_nid_t nid = spec->autocfg.input_pins[i];
13520                 if (nid >= 0x0c && nid <= 0x11) {
13521                         snd_hda_codec_write(codec, nid, 0,
13522                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13523                                             i <= AUTO_PIN_FRONT_MIC ?
13524                                             PIN_VREF80 : PIN_IN);
13525                 }
13526         }
13527 }
13528
13529 /* parse the BIOS configuration and set up the alc_spec */
13530 /* return 1 if successful, 0 if the proper config is not found,
13531  * or a negative error code
13532  */
13533 static int alc861_parse_auto_config(struct hda_codec *codec)
13534 {
13535         struct alc_spec *spec = codec->spec;
13536         int err;
13537         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13538
13539         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13540                                            alc861_ignore);
13541         if (err < 0)
13542                 return err;
13543         if (!spec->autocfg.line_outs)
13544                 return 0; /* can't find valid BIOS pin config */
13545
13546         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13547         if (err < 0)
13548                 return err;
13549         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13550         if (err < 0)
13551                 return err;
13552         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13553         if (err < 0)
13554                 return err;
13555         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13556         if (err < 0)
13557                 return err;
13558
13559         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13560
13561         if (spec->autocfg.dig_out_pin)
13562                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13563
13564         if (spec->kctls.list)
13565                 add_mixer(spec, spec->kctls.list);
13566
13567         add_verb(spec, alc861_auto_init_verbs);
13568
13569         spec->num_mux_defs = 1;
13570         spec->input_mux = &spec->private_imux;
13571
13572         spec->adc_nids = alc861_adc_nids;
13573         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13574         set_capture_mixer(spec);
13575
13576         store_pin_configs(codec);
13577         return 1;
13578 }
13579
13580 /* additional initialization for auto-configuration model */
13581 static void alc861_auto_init(struct hda_codec *codec)
13582 {
13583         struct alc_spec *spec = codec->spec;
13584         alc861_auto_init_multi_out(codec);
13585         alc861_auto_init_hp_out(codec);
13586         alc861_auto_init_analog_input(codec);
13587         if (spec->unsol_event)
13588                 alc_inithook(codec);
13589 }
13590
13591 #ifdef CONFIG_SND_HDA_POWER_SAVE
13592 static struct hda_amp_list alc861_loopbacks[] = {
13593         { 0x15, HDA_INPUT, 0 },
13594         { 0x15, HDA_INPUT, 1 },
13595         { 0x15, HDA_INPUT, 2 },
13596         { 0x15, HDA_INPUT, 3 },
13597         { } /* end */
13598 };
13599 #endif
13600
13601
13602 /*
13603  * configuration and preset
13604  */
13605 static const char *alc861_models[ALC861_MODEL_LAST] = {
13606         [ALC861_3ST]            = "3stack",
13607         [ALC660_3ST]            = "3stack-660",
13608         [ALC861_3ST_DIG]        = "3stack-dig",
13609         [ALC861_6ST_DIG]        = "6stack-dig",
13610         [ALC861_UNIWILL_M31]    = "uniwill-m31",
13611         [ALC861_TOSHIBA]        = "toshiba",
13612         [ALC861_ASUS]           = "asus",
13613         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
13614         [ALC861_AUTO]           = "auto",
13615 };
13616
13617 static struct snd_pci_quirk alc861_cfg_tbl[] = {
13618         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
13619         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13620         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13621         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
13622         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
13623         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
13624         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
13625         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
13626          *        Any other models that need this preset?
13627          */
13628         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
13629         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
13630         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
13631         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
13632         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
13633         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
13634         /* FIXME: the below seems conflict */
13635         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
13636         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
13637         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
13638         {}
13639 };
13640
13641 static struct alc_config_preset alc861_presets[] = {
13642         [ALC861_3ST] = {
13643                 .mixers = { alc861_3ST_mixer },
13644                 .init_verbs = { alc861_threestack_init_verbs },
13645                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13646                 .dac_nids = alc861_dac_nids,
13647                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13648                 .channel_mode = alc861_threestack_modes,
13649                 .need_dac_fix = 1,
13650                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13651                 .adc_nids = alc861_adc_nids,
13652                 .input_mux = &alc861_capture_source,
13653         },
13654         [ALC861_3ST_DIG] = {
13655                 .mixers = { alc861_base_mixer },
13656                 .init_verbs = { alc861_threestack_init_verbs },
13657                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13658                 .dac_nids = alc861_dac_nids,
13659                 .dig_out_nid = ALC861_DIGOUT_NID,
13660                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13661                 .channel_mode = alc861_threestack_modes,
13662                 .need_dac_fix = 1,
13663                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13664                 .adc_nids = alc861_adc_nids,
13665                 .input_mux = &alc861_capture_source,
13666         },
13667         [ALC861_6ST_DIG] = {
13668                 .mixers = { alc861_base_mixer },
13669                 .init_verbs = { alc861_base_init_verbs },
13670                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13671                 .dac_nids = alc861_dac_nids,
13672                 .dig_out_nid = ALC861_DIGOUT_NID,
13673                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
13674                 .channel_mode = alc861_8ch_modes,
13675                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13676                 .adc_nids = alc861_adc_nids,
13677                 .input_mux = &alc861_capture_source,
13678         },
13679         [ALC660_3ST] = {
13680                 .mixers = { alc861_3ST_mixer },
13681                 .init_verbs = { alc861_threestack_init_verbs },
13682                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
13683                 .dac_nids = alc660_dac_nids,
13684                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13685                 .channel_mode = alc861_threestack_modes,
13686                 .need_dac_fix = 1,
13687                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13688                 .adc_nids = alc861_adc_nids,
13689                 .input_mux = &alc861_capture_source,
13690         },
13691         [ALC861_UNIWILL_M31] = {
13692                 .mixers = { alc861_uniwill_m31_mixer },
13693                 .init_verbs = { alc861_uniwill_m31_init_verbs },
13694                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13695                 .dac_nids = alc861_dac_nids,
13696                 .dig_out_nid = ALC861_DIGOUT_NID,
13697                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
13698                 .channel_mode = alc861_uniwill_m31_modes,
13699                 .need_dac_fix = 1,
13700                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13701                 .adc_nids = alc861_adc_nids,
13702                 .input_mux = &alc861_capture_source,
13703         },
13704         [ALC861_TOSHIBA] = {
13705                 .mixers = { alc861_toshiba_mixer },
13706                 .init_verbs = { alc861_base_init_verbs,
13707                                 alc861_toshiba_init_verbs },
13708                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13709                 .dac_nids = alc861_dac_nids,
13710                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13711                 .channel_mode = alc883_3ST_2ch_modes,
13712                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13713                 .adc_nids = alc861_adc_nids,
13714                 .input_mux = &alc861_capture_source,
13715                 .unsol_event = alc861_toshiba_unsol_event,
13716                 .init_hook = alc861_toshiba_automute,
13717         },
13718         [ALC861_ASUS] = {
13719                 .mixers = { alc861_asus_mixer },
13720                 .init_verbs = { alc861_asus_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_asus_modes),
13725                 .channel_mode = alc861_asus_modes,
13726                 .need_dac_fix = 1,
13727                 .hp_nid = 0x06,
13728                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13729                 .adc_nids = alc861_adc_nids,
13730                 .input_mux = &alc861_capture_source,
13731         },
13732         [ALC861_ASUS_LAPTOP] = {
13733                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
13734                 .init_verbs = { alc861_asus_init_verbs,
13735                                 alc861_asus_laptop_init_verbs },
13736                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13737                 .dac_nids = alc861_dac_nids,
13738                 .dig_out_nid = ALC861_DIGOUT_NID,
13739                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13740                 .channel_mode = alc883_3ST_2ch_modes,
13741                 .need_dac_fix = 1,
13742                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13743                 .adc_nids = alc861_adc_nids,
13744                 .input_mux = &alc861_capture_source,
13745         },
13746 };
13747
13748
13749 static int patch_alc861(struct hda_codec *codec)
13750 {
13751         struct alc_spec *spec;
13752         int board_config;
13753         int err;
13754
13755         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13756         if (spec == NULL)
13757                 return -ENOMEM;
13758
13759         codec->spec = spec;
13760
13761         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
13762                                                   alc861_models,
13763                                                   alc861_cfg_tbl);
13764
13765         if (board_config < 0) {
13766                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
13767                        "trying auto-probe from BIOS...\n");
13768                 board_config = ALC861_AUTO;
13769         }
13770
13771         if (board_config == ALC861_AUTO) {
13772                 /* automatic parse from the BIOS config */
13773                 err = alc861_parse_auto_config(codec);
13774                 if (err < 0) {
13775                         alc_free(codec);
13776                         return err;
13777                 } else if (!err) {
13778                         printk(KERN_INFO
13779                                "hda_codec: Cannot set up configuration "
13780                                "from BIOS.  Using base mode...\n");
13781                    board_config = ALC861_3ST_DIG;
13782                 }
13783         }
13784
13785         if (board_config != ALC861_AUTO)
13786                 setup_preset(spec, &alc861_presets[board_config]);
13787
13788         spec->stream_name_analog = "ALC861 Analog";
13789         spec->stream_analog_playback = &alc861_pcm_analog_playback;
13790         spec->stream_analog_capture = &alc861_pcm_analog_capture;
13791
13792         spec->stream_name_digital = "ALC861 Digital";
13793         spec->stream_digital_playback = &alc861_pcm_digital_playback;
13794         spec->stream_digital_capture = &alc861_pcm_digital_capture;
13795
13796         spec->vmaster_nid = 0x03;
13797
13798         codec->patch_ops = alc_patch_ops;
13799         if (board_config == ALC861_AUTO)
13800                 spec->init_hook = alc861_auto_init;
13801 #ifdef CONFIG_SND_HDA_POWER_SAVE
13802         if (!spec->loopback.amplist)
13803                 spec->loopback.amplist = alc861_loopbacks;
13804 #endif
13805
13806         return 0;
13807 }
13808
13809 /*
13810  * ALC861-VD support
13811  *
13812  * Based on ALC882
13813  *
13814  * In addition, an independent DAC
13815  */
13816 #define ALC861VD_DIGOUT_NID     0x06
13817
13818 static hda_nid_t alc861vd_dac_nids[4] = {
13819         /* front, surr, clfe, side surr */
13820         0x02, 0x03, 0x04, 0x05
13821 };
13822
13823 /* dac_nids for ALC660vd are in a different order - according to
13824  * Realtek's driver.
13825  * This should probably tesult in a different mixer for 6stack models
13826  * of ALC660vd codecs, but for now there is only 3stack mixer
13827  * - and it is the same as in 861vd.
13828  * adc_nids in ALC660vd are (is) the same as in 861vd
13829  */
13830 static hda_nid_t alc660vd_dac_nids[3] = {
13831         /* front, rear, clfe, rear_surr */
13832         0x02, 0x04, 0x03
13833 };
13834
13835 static hda_nid_t alc861vd_adc_nids[1] = {
13836         /* ADC0 */
13837         0x09,
13838 };
13839
13840 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
13841
13842 /* input MUX */
13843 /* FIXME: should be a matrix-type input source selection */
13844 static struct hda_input_mux alc861vd_capture_source = {
13845         .num_items = 4,
13846         .items = {
13847                 { "Mic", 0x0 },
13848                 { "Front Mic", 0x1 },
13849                 { "Line", 0x2 },
13850                 { "CD", 0x4 },
13851         },
13852 };
13853
13854 static struct hda_input_mux alc861vd_dallas_capture_source = {
13855         .num_items = 2,
13856         .items = {
13857                 { "Ext Mic", 0x0 },
13858                 { "Int Mic", 0x1 },
13859         },
13860 };
13861
13862 static struct hda_input_mux alc861vd_hp_capture_source = {
13863         .num_items = 2,
13864         .items = {
13865                 { "Front Mic", 0x0 },
13866                 { "ATAPI Mic", 0x1 },
13867         },
13868 };
13869
13870 /*
13871  * 2ch mode
13872  */
13873 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
13874         { 2, NULL }
13875 };
13876
13877 /*
13878  * 6ch mode
13879  */
13880 static struct hda_verb alc861vd_6stack_ch6_init[] = {
13881         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13882         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13883         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13884         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13885         { } /* end */
13886 };
13887
13888 /*
13889  * 8ch mode
13890  */
13891 static struct hda_verb alc861vd_6stack_ch8_init[] = {
13892         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13893         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13894         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13895         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13896         { } /* end */
13897 };
13898
13899 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
13900         { 6, alc861vd_6stack_ch6_init },
13901         { 8, alc861vd_6stack_ch8_init },
13902 };
13903
13904 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
13905         {
13906                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13907                 .name = "Channel Mode",
13908                 .info = alc_ch_mode_info,
13909                 .get = alc_ch_mode_get,
13910                 .put = alc_ch_mode_put,
13911         },
13912         { } /* end */
13913 };
13914
13915 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13916  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13917  */
13918 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
13919         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13920         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13921
13922         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13923         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
13924
13925         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
13926                                 HDA_OUTPUT),
13927         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
13928                                 HDA_OUTPUT),
13929         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
13930         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
13931
13932         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
13933         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
13934
13935         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13936
13937         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13938         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13939         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13940
13941         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13942         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13943         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13944
13945         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13946         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13947
13948         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13949         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13950
13951         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13952         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13953
13954         { } /* end */
13955 };
13956
13957 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
13958         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13959         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13960
13961         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13962
13963         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13964         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13965         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13966
13967         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13968         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13969         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13970
13971         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13972         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13973
13974         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13975         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13976
13977         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13978         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13979
13980         { } /* end */
13981 };
13982
13983 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
13984         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13985         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
13986         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13987
13988         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13989
13990         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13991         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13992         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13993
13994         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13995         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13996         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13997
13998         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13999         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14000
14001         { } /* end */
14002 };
14003
14004 /* Pin assignment: Speaker=0x14, HP = 0x15,
14005  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14006  */
14007 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14008         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14009         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14010         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14011         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14012         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14013         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14014         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14015         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14016         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14017         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14018         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
14019         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
14020         { } /* end */
14021 };
14022
14023 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14024  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14025  */
14026 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14027         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14028         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14029         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14030         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14031         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14032         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14033         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14034         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14035
14036         { } /* end */
14037 };
14038
14039 /*
14040  * generic initialization of ADC, input mixers and output mixers
14041  */
14042 static struct hda_verb alc861vd_volume_init_verbs[] = {
14043         /*
14044          * Unmute ADC0 and set the default input to mic-in
14045          */
14046         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14047         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14048
14049         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14050          * the analog-loopback mixer widget
14051          */
14052         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14053         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14054         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14055         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14056         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14057         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14058
14059         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14060         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14061         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14062         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14063         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14064
14065         /*
14066          * Set up output mixers (0x02 - 0x05)
14067          */
14068         /* set vol=0 to output mixers */
14069         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14070         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14071         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14072         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14073
14074         /* set up input amps for analog loopback */
14075         /* Amp Indices: DAC = 0, mixer = 1 */
14076         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14077         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14078         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14079         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14080         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14081         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14082         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14083         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14084
14085         { }
14086 };
14087
14088 /*
14089  * 3-stack pin configuration:
14090  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14091  */
14092 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14093         /*
14094          * Set pin mode and muting
14095          */
14096         /* set front pin widgets 0x14 for output */
14097         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14098         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14099         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14100
14101         /* Mic (rear) pin: input vref at 80% */
14102         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14103         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14104         /* Front Mic pin: input vref at 80% */
14105         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14106         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14107         /* Line In pin: input */
14108         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14109         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14110         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14111         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14112         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14113         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14114         /* CD pin widget for input */
14115         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14116
14117         { }
14118 };
14119
14120 /*
14121  * 6-stack pin configuration:
14122  */
14123 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14124         /*
14125          * Set pin mode and muting
14126          */
14127         /* set front pin widgets 0x14 for output */
14128         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14129         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14130         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14131
14132         /* Rear Pin: output 1 (0x0d) */
14133         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14134         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14135         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14136         /* CLFE Pin: output 2 (0x0e) */
14137         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14138         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14139         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14140         /* Side Pin: output 3 (0x0f) */
14141         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14142         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14143         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
14144
14145         /* Mic (rear) pin: input vref at 80% */
14146         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14147         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14148         /* Front Mic pin: input vref at 80% */
14149         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14150         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14151         /* Line In pin: input */
14152         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14153         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14154         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14155         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14156         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14157         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14158         /* CD pin widget for input */
14159         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14160
14161         { }
14162 };
14163
14164 static struct hda_verb alc861vd_eapd_verbs[] = {
14165         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14166         { }
14167 };
14168
14169 static struct hda_verb alc660vd_eapd_verbs[] = {
14170         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14171         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14172         { }
14173 };
14174
14175 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
14176         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14177         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14178         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
14179         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14180         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14181         {}
14182 };
14183
14184 /* toggle speaker-output according to the hp-jack state */
14185 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
14186 {
14187         unsigned int present;
14188         unsigned char bits;
14189
14190         present = snd_hda_codec_read(codec, 0x1b, 0,
14191                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14192         bits = present ? HDA_AMP_MUTE : 0;
14193         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14194                                  HDA_AMP_MUTE, bits);
14195 }
14196
14197 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
14198 {
14199         unsigned int present;
14200         unsigned char bits;
14201
14202         present = snd_hda_codec_read(codec, 0x18, 0,
14203                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14204         bits = present ? HDA_AMP_MUTE : 0;
14205         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
14206                                  HDA_AMP_MUTE, bits);
14207 }
14208
14209 static void alc861vd_lenovo_automute(struct hda_codec *codec)
14210 {
14211         alc861vd_lenovo_hp_automute(codec);
14212         alc861vd_lenovo_mic_automute(codec);
14213 }
14214
14215 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
14216                                         unsigned int res)
14217 {
14218         switch (res >> 26) {
14219         case ALC880_HP_EVENT:
14220                 alc861vd_lenovo_hp_automute(codec);
14221                 break;
14222         case ALC880_MIC_EVENT:
14223                 alc861vd_lenovo_mic_automute(codec);
14224                 break;
14225         }
14226 }
14227
14228 static struct hda_verb alc861vd_dallas_verbs[] = {
14229         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14230         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14231         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14232         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14233
14234         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14235         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14236         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14237         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14238         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14239         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14240         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14241         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14242
14243         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14244         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14245         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14246         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14247         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14248         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14249         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14250         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14251
14252         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14253         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14254         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14255         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14256         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14257         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14258         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14259         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14260
14261         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14262         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14263         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14264         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14265
14266         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14267         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14268         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14269
14270         { } /* end */
14271 };
14272
14273 /* toggle speaker-output according to the hp-jack state */
14274 static void alc861vd_dallas_automute(struct hda_codec *codec)
14275 {
14276         unsigned int present;
14277
14278         present = snd_hda_codec_read(codec, 0x15, 0,
14279                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14280         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14281                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14282 }
14283
14284 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
14285 {
14286         if ((res >> 26) == ALC880_HP_EVENT)
14287                 alc861vd_dallas_automute(codec);
14288 }
14289
14290 #ifdef CONFIG_SND_HDA_POWER_SAVE
14291 #define alc861vd_loopbacks      alc880_loopbacks
14292 #endif
14293
14294 /* pcm configuration: identiacal with ALC880 */
14295 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14296 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14297 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14298 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14299
14300 /*
14301  * configuration and preset
14302  */
14303 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14304         [ALC660VD_3ST]          = "3stack-660",
14305         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14306         [ALC660VD_ASUS_V1S]     = "asus-v1s",
14307         [ALC861VD_3ST]          = "3stack",
14308         [ALC861VD_3ST_DIG]      = "3stack-digout",
14309         [ALC861VD_6ST_DIG]      = "6stack-digout",
14310         [ALC861VD_LENOVO]       = "lenovo",
14311         [ALC861VD_DALLAS]       = "dallas",
14312         [ALC861VD_HP]           = "hp",
14313         [ALC861VD_AUTO]         = "auto",
14314 };
14315
14316 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14317         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14318         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14319         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14320         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14321         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
14322         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14323         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14324         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14325         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14326         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14327         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14328         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14329         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14330         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
14331         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
14332         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
14333         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14334         {}
14335 };
14336
14337 static struct alc_config_preset alc861vd_presets[] = {
14338         [ALC660VD_3ST] = {
14339                 .mixers = { alc861vd_3st_mixer },
14340                 .init_verbs = { alc861vd_volume_init_verbs,
14341                                  alc861vd_3stack_init_verbs },
14342                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14343                 .dac_nids = alc660vd_dac_nids,
14344                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14345                 .channel_mode = alc861vd_3stack_2ch_modes,
14346                 .input_mux = &alc861vd_capture_source,
14347         },
14348         [ALC660VD_3ST_DIG] = {
14349                 .mixers = { alc861vd_3st_mixer },
14350                 .init_verbs = { alc861vd_volume_init_verbs,
14351                                  alc861vd_3stack_init_verbs },
14352                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14353                 .dac_nids = alc660vd_dac_nids,
14354                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14355                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14356                 .channel_mode = alc861vd_3stack_2ch_modes,
14357                 .input_mux = &alc861vd_capture_source,
14358         },
14359         [ALC861VD_3ST] = {
14360                 .mixers = { alc861vd_3st_mixer },
14361                 .init_verbs = { alc861vd_volume_init_verbs,
14362                                  alc861vd_3stack_init_verbs },
14363                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14364                 .dac_nids = alc861vd_dac_nids,
14365                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14366                 .channel_mode = alc861vd_3stack_2ch_modes,
14367                 .input_mux = &alc861vd_capture_source,
14368         },
14369         [ALC861VD_3ST_DIG] = {
14370                 .mixers = { alc861vd_3st_mixer },
14371                 .init_verbs = { alc861vd_volume_init_verbs,
14372                                  alc861vd_3stack_init_verbs },
14373                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14374                 .dac_nids = alc861vd_dac_nids,
14375                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14376                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14377                 .channel_mode = alc861vd_3stack_2ch_modes,
14378                 .input_mux = &alc861vd_capture_source,
14379         },
14380         [ALC861VD_6ST_DIG] = {
14381                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14382                 .init_verbs = { alc861vd_volume_init_verbs,
14383                                 alc861vd_6stack_init_verbs },
14384                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14385                 .dac_nids = alc861vd_dac_nids,
14386                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14387                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14388                 .channel_mode = alc861vd_6stack_modes,
14389                 .input_mux = &alc861vd_capture_source,
14390         },
14391         [ALC861VD_LENOVO] = {
14392                 .mixers = { alc861vd_lenovo_mixer },
14393                 .init_verbs = { alc861vd_volume_init_verbs,
14394                                 alc861vd_3stack_init_verbs,
14395                                 alc861vd_eapd_verbs,
14396                                 alc861vd_lenovo_unsol_verbs },
14397                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14398                 .dac_nids = alc660vd_dac_nids,
14399                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14400                 .channel_mode = alc861vd_3stack_2ch_modes,
14401                 .input_mux = &alc861vd_capture_source,
14402                 .unsol_event = alc861vd_lenovo_unsol_event,
14403                 .init_hook = alc861vd_lenovo_automute,
14404         },
14405         [ALC861VD_DALLAS] = {
14406                 .mixers = { alc861vd_dallas_mixer },
14407                 .init_verbs = { alc861vd_dallas_verbs },
14408                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14409                 .dac_nids = alc861vd_dac_nids,
14410                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14411                 .channel_mode = alc861vd_3stack_2ch_modes,
14412                 .input_mux = &alc861vd_dallas_capture_source,
14413                 .unsol_event = alc861vd_dallas_unsol_event,
14414                 .init_hook = alc861vd_dallas_automute,
14415         },
14416         [ALC861VD_HP] = {
14417                 .mixers = { alc861vd_hp_mixer },
14418                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14419                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14420                 .dac_nids = alc861vd_dac_nids,
14421                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14422                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14423                 .channel_mode = alc861vd_3stack_2ch_modes,
14424                 .input_mux = &alc861vd_hp_capture_source,
14425                 .unsol_event = alc861vd_dallas_unsol_event,
14426                 .init_hook = alc861vd_dallas_automute,
14427         },
14428         [ALC660VD_ASUS_V1S] = {
14429                 .mixers = { alc861vd_lenovo_mixer },
14430                 .init_verbs = { alc861vd_volume_init_verbs,
14431                                 alc861vd_3stack_init_verbs,
14432                                 alc861vd_eapd_verbs,
14433                                 alc861vd_lenovo_unsol_verbs },
14434                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14435                 .dac_nids = alc660vd_dac_nids,
14436                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14437                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14438                 .channel_mode = alc861vd_3stack_2ch_modes,
14439                 .input_mux = &alc861vd_capture_source,
14440                 .unsol_event = alc861vd_lenovo_unsol_event,
14441                 .init_hook = alc861vd_lenovo_automute,
14442         },
14443 };
14444
14445 /*
14446  * BIOS auto configuration
14447  */
14448 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14449                                 hda_nid_t nid, int pin_type, int dac_idx)
14450 {
14451         alc_set_pin_output(codec, nid, pin_type);
14452 }
14453
14454 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14455 {
14456         struct alc_spec *spec = codec->spec;
14457         int i;
14458
14459         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14460         for (i = 0; i <= HDA_SIDE; i++) {
14461                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14462                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14463                 if (nid)
14464                         alc861vd_auto_set_output_and_unmute(codec, nid,
14465                                                             pin_type, i);
14466         }
14467 }
14468
14469
14470 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14471 {
14472         struct alc_spec *spec = codec->spec;
14473         hda_nid_t pin;
14474
14475         pin = spec->autocfg.hp_pins[0];
14476         if (pin) /* connect to front and  use dac 0 */
14477                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14478         pin = spec->autocfg.speaker_pins[0];
14479         if (pin)
14480                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14481 }
14482
14483 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14484 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14485
14486 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14487 {
14488         struct alc_spec *spec = codec->spec;
14489         int i;
14490
14491         for (i = 0; i < AUTO_PIN_LAST; i++) {
14492                 hda_nid_t nid = spec->autocfg.input_pins[i];
14493                 if (alc861vd_is_input_pin(nid)) {
14494                         snd_hda_codec_write(codec, nid, 0,
14495                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
14496                                         i <= AUTO_PIN_FRONT_MIC ?
14497                                                         PIN_VREF80 : PIN_IN);
14498                         if (nid != ALC861VD_PIN_CD_NID)
14499                                 snd_hda_codec_write(codec, nid, 0,
14500                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14501                                                 AMP_OUT_MUTE);
14502                 }
14503         }
14504 }
14505
14506 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14507
14508 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14509 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14510
14511 /* add playback controls from the parsed DAC table */
14512 /* Based on ALC880 version. But ALC861VD has separate,
14513  * different NIDs for mute/unmute switch and volume control */
14514 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14515                                              const struct auto_pin_cfg *cfg)
14516 {
14517         char name[32];
14518         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14519         hda_nid_t nid_v, nid_s;
14520         int i, err;
14521
14522         for (i = 0; i < cfg->line_outs; i++) {
14523                 if (!spec->multiout.dac_nids[i])
14524                         continue;
14525                 nid_v = alc861vd_idx_to_mixer_vol(
14526                                 alc880_dac_to_idx(
14527                                         spec->multiout.dac_nids[i]));
14528                 nid_s = alc861vd_idx_to_mixer_switch(
14529                                 alc880_dac_to_idx(
14530                                         spec->multiout.dac_nids[i]));
14531
14532                 if (i == 2) {
14533                         /* Center/LFE */
14534                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14535                                           "Center Playback Volume",
14536                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14537                                                               HDA_OUTPUT));
14538                         if (err < 0)
14539                                 return err;
14540                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14541                                           "LFE Playback Volume",
14542                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14543                                                               HDA_OUTPUT));
14544                         if (err < 0)
14545                                 return err;
14546                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14547                                           "Center Playback Switch",
14548                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14549                                                               HDA_INPUT));
14550                         if (err < 0)
14551                                 return err;
14552                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14553                                           "LFE Playback Switch",
14554                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14555                                                               HDA_INPUT));
14556                         if (err < 0)
14557                                 return err;
14558                 } else {
14559                         sprintf(name, "%s Playback Volume", chname[i]);
14560                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14561                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14562                                                               HDA_OUTPUT));
14563                         if (err < 0)
14564                                 return err;
14565                         sprintf(name, "%s Playback Switch", chname[i]);
14566                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14567                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14568                                                               HDA_INPUT));
14569                         if (err < 0)
14570                                 return err;
14571                 }
14572         }
14573         return 0;
14574 }
14575
14576 /* add playback controls for speaker and HP outputs */
14577 /* Based on ALC880 version. But ALC861VD has separate,
14578  * different NIDs for mute/unmute switch and volume control */
14579 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14580                                         hda_nid_t pin, const char *pfx)
14581 {
14582         hda_nid_t nid_v, nid_s;
14583         int err;
14584         char name[32];
14585
14586         if (!pin)
14587                 return 0;
14588
14589         if (alc880_is_fixed_pin(pin)) {
14590                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14591                 /* specify the DAC as the extra output */
14592                 if (!spec->multiout.hp_nid)
14593                         spec->multiout.hp_nid = nid_v;
14594                 else
14595                         spec->multiout.extra_out_nid[0] = nid_v;
14596                 /* control HP volume/switch on the output mixer amp */
14597                 nid_v = alc861vd_idx_to_mixer_vol(
14598                                 alc880_fixed_pin_idx(pin));
14599                 nid_s = alc861vd_idx_to_mixer_switch(
14600                                 alc880_fixed_pin_idx(pin));
14601
14602                 sprintf(name, "%s Playback Volume", pfx);
14603                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14604                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
14605                 if (err < 0)
14606                         return err;
14607                 sprintf(name, "%s Playback Switch", pfx);
14608                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14609                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
14610                 if (err < 0)
14611                         return err;
14612         } else if (alc880_is_multi_pin(pin)) {
14613                 /* set manual connection */
14614                 /* we have only a switch on HP-out PIN */
14615                 sprintf(name, "%s Playback Switch", pfx);
14616                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14617                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14618                 if (err < 0)
14619                         return err;
14620         }
14621         return 0;
14622 }
14623
14624 /* parse the BIOS configuration and set up the alc_spec
14625  * return 1 if successful, 0 if the proper config is not found,
14626  * or a negative error code
14627  * Based on ALC880 version - had to change it to override
14628  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
14629 static int alc861vd_parse_auto_config(struct hda_codec *codec)
14630 {
14631         struct alc_spec *spec = codec->spec;
14632         int err;
14633         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
14634
14635         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14636                                            alc861vd_ignore);
14637         if (err < 0)
14638                 return err;
14639         if (!spec->autocfg.line_outs)
14640                 return 0; /* can't find valid BIOS pin config */
14641
14642         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14643         if (err < 0)
14644                 return err;
14645         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
14646         if (err < 0)
14647                 return err;
14648         err = alc861vd_auto_create_extra_out(spec,
14649                                              spec->autocfg.speaker_pins[0],
14650                                              "Speaker");
14651         if (err < 0)
14652                 return err;
14653         err = alc861vd_auto_create_extra_out(spec,
14654                                              spec->autocfg.hp_pins[0],
14655                                              "Headphone");
14656         if (err < 0)
14657                 return err;
14658         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
14659         if (err < 0)
14660                 return err;
14661
14662         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14663
14664         if (spec->autocfg.dig_out_pin)
14665                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14666
14667         if (spec->kctls.list)
14668                 add_mixer(spec, spec->kctls.list);
14669
14670         add_verb(spec, alc861vd_volume_init_verbs);
14671
14672         spec->num_mux_defs = 1;
14673         spec->input_mux = &spec->private_imux;
14674
14675         err = alc_auto_add_mic_boost(codec);
14676         if (err < 0)
14677                 return err;
14678
14679         store_pin_configs(codec);
14680         return 1;
14681 }
14682
14683 /* additional initialization for auto-configuration model */
14684 static void alc861vd_auto_init(struct hda_codec *codec)
14685 {
14686         struct alc_spec *spec = codec->spec;
14687         alc861vd_auto_init_multi_out(codec);
14688         alc861vd_auto_init_hp_out(codec);
14689         alc861vd_auto_init_analog_input(codec);
14690         alc861vd_auto_init_input_src(codec);
14691         if (spec->unsol_event)
14692                 alc_inithook(codec);
14693 }
14694
14695 static int patch_alc861vd(struct hda_codec *codec)
14696 {
14697         struct alc_spec *spec;
14698         int err, board_config;
14699
14700         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14701         if (spec == NULL)
14702                 return -ENOMEM;
14703
14704         codec->spec = spec;
14705
14706         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
14707                                                   alc861vd_models,
14708                                                   alc861vd_cfg_tbl);
14709
14710         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
14711                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
14712                         "ALC861VD, trying auto-probe from BIOS...\n");
14713                 board_config = ALC861VD_AUTO;
14714         }
14715
14716         if (board_config == ALC861VD_AUTO) {
14717                 /* automatic parse from the BIOS config */
14718                 err = alc861vd_parse_auto_config(codec);
14719                 if (err < 0) {
14720                         alc_free(codec);
14721                         return err;
14722                 } else if (!err) {
14723                         printk(KERN_INFO
14724                                "hda_codec: Cannot set up configuration "
14725                                "from BIOS.  Using base mode...\n");
14726                         board_config = ALC861VD_3ST;
14727                 }
14728         }
14729
14730         if (board_config != ALC861VD_AUTO)
14731                 setup_preset(spec, &alc861vd_presets[board_config]);
14732
14733         if (codec->vendor_id == 0x10ec0660) {
14734                 spec->stream_name_analog = "ALC660-VD Analog";
14735                 spec->stream_name_digital = "ALC660-VD Digital";
14736                 /* always turn on EAPD */
14737                 add_verb(spec, alc660vd_eapd_verbs);
14738         } else {
14739                 spec->stream_name_analog = "ALC861VD Analog";
14740                 spec->stream_name_digital = "ALC861VD Digital";
14741         }
14742
14743         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
14744         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
14745
14746         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
14747         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
14748
14749         spec->adc_nids = alc861vd_adc_nids;
14750         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14751         spec->capsrc_nids = alc861vd_capsrc_nids;
14752         spec->is_mix_capture = 1;
14753
14754         set_capture_mixer(spec);
14755
14756         spec->vmaster_nid = 0x02;
14757
14758         codec->patch_ops = alc_patch_ops;
14759
14760         if (board_config == ALC861VD_AUTO)
14761                 spec->init_hook = alc861vd_auto_init;
14762 #ifdef CONFIG_SND_HDA_POWER_SAVE
14763         if (!spec->loopback.amplist)
14764                 spec->loopback.amplist = alc861vd_loopbacks;
14765 #endif
14766
14767         return 0;
14768 }
14769
14770 /*
14771  * ALC662 support
14772  *
14773  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
14774  * configuration.  Each pin widget can choose any input DACs and a mixer.
14775  * Each ADC is connected from a mixer of all inputs.  This makes possible
14776  * 6-channel independent captures.
14777  *
14778  * In addition, an independent DAC for the multi-playback (not used in this
14779  * driver yet).
14780  */
14781 #define ALC662_DIGOUT_NID       0x06
14782 #define ALC662_DIGIN_NID        0x0a
14783
14784 static hda_nid_t alc662_dac_nids[4] = {
14785         /* front, rear, clfe, rear_surr */
14786         0x02, 0x03, 0x04
14787 };
14788
14789 static hda_nid_t alc662_adc_nids[1] = {
14790         /* ADC1-2 */
14791         0x09,
14792 };
14793
14794 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
14795
14796 /* input MUX */
14797 /* FIXME: should be a matrix-type input source selection */
14798 static struct hda_input_mux alc662_capture_source = {
14799         .num_items = 4,
14800         .items = {
14801                 { "Mic", 0x0 },
14802                 { "Front Mic", 0x1 },
14803                 { "Line", 0x2 },
14804                 { "CD", 0x4 },
14805         },
14806 };
14807
14808 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
14809         .num_items = 2,
14810         .items = {
14811                 { "Mic", 0x1 },
14812                 { "Line", 0x2 },
14813         },
14814 };
14815
14816 static struct hda_input_mux alc662_eeepc_capture_source = {
14817         .num_items = 2,
14818         .items = {
14819                 { "i-Mic", 0x1 },
14820                 { "e-Mic", 0x0 },
14821         },
14822 };
14823
14824 static struct hda_input_mux alc663_capture_source = {
14825         .num_items = 3,
14826         .items = {
14827                 { "Mic", 0x0 },
14828                 { "Front Mic", 0x1 },
14829                 { "Line", 0x2 },
14830         },
14831 };
14832
14833 static struct hda_input_mux alc663_m51va_capture_source = {
14834         .num_items = 2,
14835         .items = {
14836                 { "Ext-Mic", 0x0 },
14837                 { "D-Mic", 0x9 },
14838         },
14839 };
14840
14841 /*
14842  * 2ch mode
14843  */
14844 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
14845         { 2, NULL }
14846 };
14847
14848 /*
14849  * 2ch mode
14850  */
14851 static struct hda_verb alc662_3ST_ch2_init[] = {
14852         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
14853         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14854         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
14855         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14856         { } /* end */
14857 };
14858
14859 /*
14860  * 6ch mode
14861  */
14862 static struct hda_verb alc662_3ST_ch6_init[] = {
14863         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14864         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14865         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
14866         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14867         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14868         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
14869         { } /* end */
14870 };
14871
14872 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
14873         { 2, alc662_3ST_ch2_init },
14874         { 6, alc662_3ST_ch6_init },
14875 };
14876
14877 /*
14878  * 2ch mode
14879  */
14880 static struct hda_verb alc662_sixstack_ch6_init[] = {
14881         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14882         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14883         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14884         { } /* end */
14885 };
14886
14887 /*
14888  * 6ch mode
14889  */
14890 static struct hda_verb alc662_sixstack_ch8_init[] = {
14891         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14892         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14893         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14894         { } /* end */
14895 };
14896
14897 static struct hda_channel_mode alc662_5stack_modes[2] = {
14898         { 2, alc662_sixstack_ch6_init },
14899         { 6, alc662_sixstack_ch8_init },
14900 };
14901
14902 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14903  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14904  */
14905
14906 static struct snd_kcontrol_new alc662_base_mixer[] = {
14907         /* output mixer control */
14908         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
14909         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14910         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
14911         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14912         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14913         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14914         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14915         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14916         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14917
14918         /*Input mixer control */
14919         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
14920         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
14921         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
14922         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
14923         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
14924         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
14925         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
14926         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
14927         { } /* end */
14928 };
14929
14930 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
14931         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14932         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14933         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14934         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14935         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14936         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14937         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14938         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14939         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14940         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14941         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14942         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14943         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14944         { } /* end */
14945 };
14946
14947 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
14948         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14949         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14950         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14951         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14952         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14953         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14954         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14955         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14956         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14957         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14958         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14959         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14960         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14961         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14962         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14963         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14964         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14965         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14966         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14967         { } /* end */
14968 };
14969
14970 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
14971         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14972         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
14973         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14974         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
14975         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14976         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14977         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14978         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14979         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14980         { } /* end */
14981 };
14982
14983 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
14984         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14985
14986         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14987         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14988
14989         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
14990         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14991         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14992
14993         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
14994         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14995         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14996         { } /* end */
14997 };
14998
14999 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15000         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15001         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15002         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15003         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
15004         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15005         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15006         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
15007         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
15008         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15009         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15010         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15011         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15012         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15013         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15014         { } /* end */
15015 };
15016
15017 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15018         .ops = &snd_hda_bind_vol,
15019         .values = {
15020                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15021                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15022                 0
15023         },
15024 };
15025
15026 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15027         .ops = &snd_hda_bind_sw,
15028         .values = {
15029                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15030                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15031                 0
15032         },
15033 };
15034
15035 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15036         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15037         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15038         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15039         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15040         { } /* end */
15041 };
15042
15043 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15044         .ops = &snd_hda_bind_sw,
15045         .values = {
15046                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15047                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15048                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15049                 0
15050         },
15051 };
15052
15053 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15054         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15055         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15056         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15057         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15058         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15059         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15060
15061         { } /* end */
15062 };
15063
15064 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15065         .ops = &snd_hda_bind_sw,
15066         .values = {
15067                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15068                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15069                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15070                 0
15071         },
15072 };
15073
15074 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15075         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15076         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15077         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15078         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15079         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15080         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15081         { } /* end */
15082 };
15083
15084 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15085         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15086         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15087         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15088         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15089         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15090         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15091         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15092         { } /* end */
15093 };
15094
15095 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15096         .ops = &snd_hda_bind_vol,
15097         .values = {
15098                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15099                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15100                 0
15101         },
15102 };
15103
15104 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15105         .ops = &snd_hda_bind_sw,
15106         .values = {
15107                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15108                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15109                 0
15110         },
15111 };
15112
15113 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15114         HDA_BIND_VOL("Master Playback Volume",
15115                                 &alc663_asus_two_bind_master_vol),
15116         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15117         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15118         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15119         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15120         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15121         { } /* end */
15122 };
15123
15124 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15125         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15126         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15127         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15128         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15129         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15130         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15131         { } /* end */
15132 };
15133
15134 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
15135         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15136         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15137         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15138         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15139         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15140
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("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15144         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15145         { } /* end */
15146 };
15147
15148 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
15149         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15150         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15151         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15152
15153         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15154         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15155         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15156         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15157         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15158         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15159         { } /* end */
15160 };
15161
15162 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
15163         {
15164                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15165                 .name = "Channel Mode",
15166                 .info = alc_ch_mode_info,
15167                 .get = alc_ch_mode_get,
15168                 .put = alc_ch_mode_put,
15169         },
15170         { } /* end */
15171 };
15172
15173 static struct hda_verb alc662_init_verbs[] = {
15174         /* ADC: mute amp left and right */
15175         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15176         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15177         /* Front mixer: unmute input/output amp left and right (volume = 0) */
15178
15179         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15180         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15181         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15182         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15183         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15184
15185         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15186         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15187         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15188         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15189         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15190         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15191
15192         /* Front Pin: output 0 (0x0c) */
15193         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15194         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15195
15196         /* Rear Pin: output 1 (0x0d) */
15197         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15198         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15199
15200         /* CLFE Pin: output 2 (0x0e) */
15201         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15202         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15203
15204         /* Mic (rear) pin: input vref at 80% */
15205         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15206         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15207         /* Front Mic pin: input vref at 80% */
15208         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15209         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15210         /* Line In pin: input */
15211         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15212         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15213         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15214         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15215         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15216         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15217         /* CD pin widget for input */
15218         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15219
15220         /* FIXME: use matrix-type input source selection */
15221         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15222         /* Input mixer */
15223         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15224         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15225         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15226         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15227
15228         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15229         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15230         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15231         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15232
15233         /* always trun on EAPD */
15234         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15235         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15236
15237         { }
15238 };
15239
15240 static struct hda_verb alc662_sue_init_verbs[] = {
15241         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15242         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15243         {}
15244 };
15245
15246 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
15247         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15248         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15249         {}
15250 };
15251
15252 /* Set Unsolicited Event*/
15253 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
15254         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15255         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15256         {}
15257 };
15258
15259 /*
15260  * generic initialization of ADC, input mixers and output mixers
15261  */
15262 static struct hda_verb alc662_auto_init_verbs[] = {
15263         /*
15264          * Unmute ADC and set the default input to mic-in
15265          */
15266         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15267         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15268
15269         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
15270          * mixer widget
15271          * Note: PASD motherboards uses the Line In 2 as the input for front
15272          * panel mic (mic 2)
15273          */
15274         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
15275         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15276         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15277         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15278         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15279         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15280
15281         /*
15282          * Set up output mixers (0x0c - 0x0f)
15283          */
15284         /* set vol=0 to output mixers */
15285         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15286         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15287         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15288
15289         /* set up input amps for analog loopback */
15290         /* Amp Indices: DAC = 0, mixer = 1 */
15291         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15292         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15293         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15294         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15295         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15296         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15297
15298
15299         /* FIXME: use matrix-type input source selection */
15300         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15301         /* Input mixer */
15302         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15303         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15304         { }
15305 };
15306
15307 /* additional verbs for ALC663 */
15308 static struct hda_verb alc663_auto_init_verbs[] = {
15309         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15310         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15311         { }
15312 };
15313
15314 static struct hda_verb alc663_m51va_init_verbs[] = {
15315         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15316         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15317         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15318         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15319         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15320         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15321         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15322         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15323         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15324         {}
15325 };
15326
15327 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15328         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15329         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15330         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15331         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15332         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15333         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15334         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15335         {}
15336 };
15337
15338 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15339         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15340         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15341         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15342         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15343         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15344         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15345         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15346         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15347         {}
15348 };
15349
15350 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15351         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15352         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15353         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15354         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15355         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15356         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15357         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15358         {}
15359 };
15360
15361 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15362         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15363         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15364         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15365         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15366         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15367         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15368         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15369         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15370         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15371         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15372         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15373         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15374         {}
15375 };
15376
15377 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15378         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15379         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15380         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15381         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15382         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15383         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15384         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15385         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15386         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15387         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15388         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15389         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15390         {}
15391 };
15392
15393 static struct hda_verb alc663_g71v_init_verbs[] = {
15394         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15395         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15396         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15397
15398         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15399         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15400         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15401
15402         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15403         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15404         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15405         {}
15406 };
15407
15408 static struct hda_verb alc663_g50v_init_verbs[] = {
15409         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15410         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15411         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15412
15413         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15414         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15415         {}
15416 };
15417
15418 static struct hda_verb alc662_ecs_init_verbs[] = {
15419         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15420         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15421         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15422         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15423         {}
15424 };
15425
15426 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15427         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15428         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15429         { } /* end */
15430 };
15431
15432 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15433 {
15434         unsigned int present;
15435         unsigned char bits;
15436
15437         present = snd_hda_codec_read(codec, 0x14, 0,
15438                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15439         bits = present ? HDA_AMP_MUTE : 0;
15440         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15441                                  HDA_AMP_MUTE, bits);
15442 }
15443
15444 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15445 {
15446         unsigned int present;
15447         unsigned char bits;
15448
15449         present = snd_hda_codec_read(codec, 0x1b, 0,
15450                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15451         bits = present ? HDA_AMP_MUTE : 0;
15452         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15453                                  HDA_AMP_MUTE, bits);
15454         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15455                                  HDA_AMP_MUTE, bits);
15456 }
15457
15458 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15459                                            unsigned int res)
15460 {
15461         if ((res >> 26) == ALC880_HP_EVENT)
15462                 alc662_lenovo_101e_all_automute(codec);
15463         if ((res >> 26) == ALC880_FRONT_EVENT)
15464                 alc662_lenovo_101e_ispeaker_automute(codec);
15465 }
15466
15467 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15468 {
15469         unsigned int present;
15470
15471         present = snd_hda_codec_read(codec, 0x18, 0,
15472                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15473         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15474                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15475         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15476                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15477         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15478                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15479         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15480                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15481 }
15482
15483 /* unsolicited event for HP jack sensing */
15484 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15485                                      unsigned int res)
15486 {
15487         if ((res >> 26) == ALC880_HP_EVENT)
15488                 alc262_hippo1_automute( codec );
15489
15490         if ((res >> 26) == ALC880_MIC_EVENT)
15491                 alc662_eeepc_mic_automute(codec);
15492 }
15493
15494 static void alc662_eeepc_inithook(struct hda_codec *codec)
15495 {
15496         alc262_hippo1_automute( codec );
15497         alc662_eeepc_mic_automute(codec);
15498 }
15499
15500 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15501 {
15502         unsigned int mute;
15503         unsigned int present;
15504
15505         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15506         present = snd_hda_codec_read(codec, 0x14, 0,
15507                                      AC_VERB_GET_PIN_SENSE, 0);
15508         present = (present & 0x80000000) != 0;
15509         if (present) {
15510                 /* mute internal speaker */
15511                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15512                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15513         } else {
15514                 /* unmute internal speaker if necessary */
15515                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15516                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15517                                         HDA_AMP_MUTE, mute);
15518         }
15519 }
15520
15521 /* unsolicited event for HP jack sensing */
15522 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15523                                           unsigned int res)
15524 {
15525         if ((res >> 26) == ALC880_HP_EVENT)
15526                 alc662_eeepc_ep20_automute(codec);
15527 }
15528
15529 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15530 {
15531         alc662_eeepc_ep20_automute(codec);
15532 }
15533
15534 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15535 {
15536         unsigned int present;
15537         unsigned char bits;
15538
15539         present = snd_hda_codec_read(codec, 0x21, 0,
15540                         AC_VERB_GET_PIN_SENSE, 0)
15541                         & AC_PINSENSE_PRESENCE;
15542         bits = present ? HDA_AMP_MUTE : 0;
15543         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15544                                 AMP_IN_MUTE(0), bits);
15545         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15546                                 AMP_IN_MUTE(0), bits);
15547 }
15548
15549 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15550 {
15551         unsigned int present;
15552         unsigned char bits;
15553
15554         present = snd_hda_codec_read(codec, 0x21, 0,
15555                         AC_VERB_GET_PIN_SENSE, 0)
15556                         & AC_PINSENSE_PRESENCE;
15557         bits = present ? HDA_AMP_MUTE : 0;
15558         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15559                                 AMP_IN_MUTE(0), bits);
15560         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15561                                 AMP_IN_MUTE(0), bits);
15562         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15563                                 AMP_IN_MUTE(0), bits);
15564         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15565                                 AMP_IN_MUTE(0), bits);
15566 }
15567
15568 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15569 {
15570         unsigned int present;
15571         unsigned char bits;
15572
15573         present = snd_hda_codec_read(codec, 0x15, 0,
15574                         AC_VERB_GET_PIN_SENSE, 0)
15575                         & AC_PINSENSE_PRESENCE;
15576         bits = present ? HDA_AMP_MUTE : 0;
15577         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15578                                 AMP_IN_MUTE(0), bits);
15579         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15580                                 AMP_IN_MUTE(0), bits);
15581         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15582                                 AMP_IN_MUTE(0), bits);
15583         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15584                                 AMP_IN_MUTE(0), bits);
15585 }
15586
15587 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15588 {
15589         unsigned int present;
15590         unsigned char bits;
15591
15592         present = snd_hda_codec_read(codec, 0x1b, 0,
15593                         AC_VERB_GET_PIN_SENSE, 0)
15594                         & AC_PINSENSE_PRESENCE;
15595         bits = present ? 0 : PIN_OUT;
15596         snd_hda_codec_write(codec, 0x14, 0,
15597                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15598 }
15599
15600 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15601 {
15602         unsigned int present1, present2;
15603
15604         present1 = snd_hda_codec_read(codec, 0x21, 0,
15605                         AC_VERB_GET_PIN_SENSE, 0)
15606                         & AC_PINSENSE_PRESENCE;
15607         present2 = snd_hda_codec_read(codec, 0x15, 0,
15608                         AC_VERB_GET_PIN_SENSE, 0)
15609                         & AC_PINSENSE_PRESENCE;
15610
15611         if (present1 || present2) {
15612                 snd_hda_codec_write_cache(codec, 0x14, 0,
15613                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15614         } else {
15615                 snd_hda_codec_write_cache(codec, 0x14, 0,
15616                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15617         }
15618 }
15619
15620 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15621 {
15622         unsigned int present1, present2;
15623
15624         present1 = snd_hda_codec_read(codec, 0x1b, 0,
15625                                 AC_VERB_GET_PIN_SENSE, 0)
15626                                 & AC_PINSENSE_PRESENCE;
15627         present2 = snd_hda_codec_read(codec, 0x15, 0,
15628                                 AC_VERB_GET_PIN_SENSE, 0)
15629                                 & AC_PINSENSE_PRESENCE;
15630
15631         if (present1 || present2) {
15632                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15633                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15634                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15635                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15636         } else {
15637                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15638                                 AMP_IN_MUTE(0), 0);
15639                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15640                                 AMP_IN_MUTE(0), 0);
15641         }
15642 }
15643
15644 static void alc663_m51va_mic_automute(struct hda_codec *codec)
15645 {
15646         unsigned int present;
15647
15648         present = snd_hda_codec_read(codec, 0x18, 0,
15649                         AC_VERB_GET_PIN_SENSE, 0)
15650                         & AC_PINSENSE_PRESENCE;
15651         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15652                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15653         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15654                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15655         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15656                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15657         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15658                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15659 }
15660
15661 static void alc663_m51va_unsol_event(struct hda_codec *codec,
15662                                            unsigned int res)
15663 {
15664         switch (res >> 26) {
15665         case ALC880_HP_EVENT:
15666                 alc663_m51va_speaker_automute(codec);
15667                 break;
15668         case ALC880_MIC_EVENT:
15669                 alc663_m51va_mic_automute(codec);
15670                 break;
15671         }
15672 }
15673
15674 static void alc663_m51va_inithook(struct hda_codec *codec)
15675 {
15676         alc663_m51va_speaker_automute(codec);
15677         alc663_m51va_mic_automute(codec);
15678 }
15679
15680 /* ***************** Mode1 ******************************/
15681 static void alc663_mode1_unsol_event(struct hda_codec *codec,
15682                                            unsigned int res)
15683 {
15684         switch (res >> 26) {
15685         case ALC880_HP_EVENT:
15686                 alc663_m51va_speaker_automute(codec);
15687                 break;
15688         case ALC880_MIC_EVENT:
15689                 alc662_eeepc_mic_automute(codec);
15690                 break;
15691         }
15692 }
15693
15694 static void alc663_mode1_inithook(struct hda_codec *codec)
15695 {
15696         alc663_m51va_speaker_automute(codec);
15697         alc662_eeepc_mic_automute(codec);
15698 }
15699 /* ***************** Mode2 ******************************/
15700 static void alc662_mode2_unsol_event(struct hda_codec *codec,
15701                                            unsigned int res)
15702 {
15703         switch (res >> 26) {
15704         case ALC880_HP_EVENT:
15705                 alc662_f5z_speaker_automute(codec);
15706                 break;
15707         case ALC880_MIC_EVENT:
15708                 alc662_eeepc_mic_automute(codec);
15709                 break;
15710         }
15711 }
15712
15713 static void alc662_mode2_inithook(struct hda_codec *codec)
15714 {
15715         alc662_f5z_speaker_automute(codec);
15716         alc662_eeepc_mic_automute(codec);
15717 }
15718 /* ***************** Mode3 ******************************/
15719 static void alc663_mode3_unsol_event(struct hda_codec *codec,
15720                                            unsigned int res)
15721 {
15722         switch (res >> 26) {
15723         case ALC880_HP_EVENT:
15724                 alc663_two_hp_m1_speaker_automute(codec);
15725                 break;
15726         case ALC880_MIC_EVENT:
15727                 alc662_eeepc_mic_automute(codec);
15728                 break;
15729         }
15730 }
15731
15732 static void alc663_mode3_inithook(struct hda_codec *codec)
15733 {
15734         alc663_two_hp_m1_speaker_automute(codec);
15735         alc662_eeepc_mic_automute(codec);
15736 }
15737 /* ***************** Mode4 ******************************/
15738 static void alc663_mode4_unsol_event(struct hda_codec *codec,
15739                                            unsigned int res)
15740 {
15741         switch (res >> 26) {
15742         case ALC880_HP_EVENT:
15743                 alc663_21jd_two_speaker_automute(codec);
15744                 break;
15745         case ALC880_MIC_EVENT:
15746                 alc662_eeepc_mic_automute(codec);
15747                 break;
15748         }
15749 }
15750
15751 static void alc663_mode4_inithook(struct hda_codec *codec)
15752 {
15753         alc663_21jd_two_speaker_automute(codec);
15754         alc662_eeepc_mic_automute(codec);
15755 }
15756 /* ***************** Mode5 ******************************/
15757 static void alc663_mode5_unsol_event(struct hda_codec *codec,
15758                                            unsigned int res)
15759 {
15760         switch (res >> 26) {
15761         case ALC880_HP_EVENT:
15762                 alc663_15jd_two_speaker_automute(codec);
15763                 break;
15764         case ALC880_MIC_EVENT:
15765                 alc662_eeepc_mic_automute(codec);
15766                 break;
15767         }
15768 }
15769
15770 static void alc663_mode5_inithook(struct hda_codec *codec)
15771 {
15772         alc663_15jd_two_speaker_automute(codec);
15773         alc662_eeepc_mic_automute(codec);
15774 }
15775 /* ***************** Mode6 ******************************/
15776 static void alc663_mode6_unsol_event(struct hda_codec *codec,
15777                                            unsigned int res)
15778 {
15779         switch (res >> 26) {
15780         case ALC880_HP_EVENT:
15781                 alc663_two_hp_m2_speaker_automute(codec);
15782                 break;
15783         case ALC880_MIC_EVENT:
15784                 alc662_eeepc_mic_automute(codec);
15785                 break;
15786         }
15787 }
15788
15789 static void alc663_mode6_inithook(struct hda_codec *codec)
15790 {
15791         alc663_two_hp_m2_speaker_automute(codec);
15792         alc662_eeepc_mic_automute(codec);
15793 }
15794
15795 static void alc663_g71v_hp_automute(struct hda_codec *codec)
15796 {
15797         unsigned int present;
15798         unsigned char bits;
15799
15800         present = snd_hda_codec_read(codec, 0x21, 0,
15801                                      AC_VERB_GET_PIN_SENSE, 0)
15802                 & AC_PINSENSE_PRESENCE;
15803         bits = present ? HDA_AMP_MUTE : 0;
15804         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15805                                  HDA_AMP_MUTE, bits);
15806         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15807                                  HDA_AMP_MUTE, bits);
15808 }
15809
15810 static void alc663_g71v_front_automute(struct hda_codec *codec)
15811 {
15812         unsigned int present;
15813         unsigned char bits;
15814
15815         present = snd_hda_codec_read(codec, 0x15, 0,
15816                                      AC_VERB_GET_PIN_SENSE, 0)
15817                 & AC_PINSENSE_PRESENCE;
15818         bits = present ? HDA_AMP_MUTE : 0;
15819         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15820                                  HDA_AMP_MUTE, bits);
15821 }
15822
15823 static void alc663_g71v_unsol_event(struct hda_codec *codec,
15824                                            unsigned int res)
15825 {
15826         switch (res >> 26) {
15827         case ALC880_HP_EVENT:
15828                 alc663_g71v_hp_automute(codec);
15829                 break;
15830         case ALC880_FRONT_EVENT:
15831                 alc663_g71v_front_automute(codec);
15832                 break;
15833         case ALC880_MIC_EVENT:
15834                 alc662_eeepc_mic_automute(codec);
15835                 break;
15836         }
15837 }
15838
15839 static void alc663_g71v_inithook(struct hda_codec *codec)
15840 {
15841         alc663_g71v_front_automute(codec);
15842         alc663_g71v_hp_automute(codec);
15843         alc662_eeepc_mic_automute(codec);
15844 }
15845
15846 static void alc663_g50v_unsol_event(struct hda_codec *codec,
15847                                            unsigned int res)
15848 {
15849         switch (res >> 26) {
15850         case ALC880_HP_EVENT:
15851                 alc663_m51va_speaker_automute(codec);
15852                 break;
15853         case ALC880_MIC_EVENT:
15854                 alc662_eeepc_mic_automute(codec);
15855                 break;
15856         }
15857 }
15858
15859 static void alc663_g50v_inithook(struct hda_codec *codec)
15860 {
15861         alc663_m51va_speaker_automute(codec);
15862         alc662_eeepc_mic_automute(codec);
15863 }
15864
15865 /* bind hp and internal speaker mute (with plug check) */
15866 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15867                                      struct snd_ctl_elem_value *ucontrol)
15868 {
15869         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15870         long *valp = ucontrol->value.integer.value;
15871         int change;
15872
15873         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15874                                           HDA_AMP_MUTE,
15875                                           valp[0] ? 0 : HDA_AMP_MUTE);
15876         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15877                                            HDA_AMP_MUTE,
15878                                            valp[1] ? 0 : HDA_AMP_MUTE);
15879         if (change)
15880                 alc262_hippo1_automute(codec);
15881         return change;
15882 }
15883
15884 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
15885         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15886         {
15887                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15888                 .name = "Master Playback Switch",
15889                 .info = snd_hda_mixer_amp_switch_info,
15890                 .get = snd_hda_mixer_amp_switch_get,
15891                 .put = alc662_ecs_master_sw_put,
15892                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15893         },
15894
15895         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
15896         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
15897         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
15898
15899         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15900         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15901         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15902         { } /* end */
15903 };
15904
15905 #ifdef CONFIG_SND_HDA_POWER_SAVE
15906 #define alc662_loopbacks        alc880_loopbacks
15907 #endif
15908
15909
15910 /* pcm configuration: identiacal with ALC880 */
15911 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
15912 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
15913 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
15914 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
15915
15916 /*
15917  * configuration and preset
15918  */
15919 static const char *alc662_models[ALC662_MODEL_LAST] = {
15920         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
15921         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
15922         [ALC662_3ST_6ch]        = "3stack-6ch",
15923         [ALC662_5ST_DIG]        = "6stack-dig",
15924         [ALC662_LENOVO_101E]    = "lenovo-101e",
15925         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
15926         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
15927         [ALC662_ECS] = "ecs",
15928         [ALC663_ASUS_M51VA] = "m51va",
15929         [ALC663_ASUS_G71V] = "g71v",
15930         [ALC663_ASUS_H13] = "h13",
15931         [ALC663_ASUS_G50V] = "g50v",
15932         [ALC663_ASUS_MODE1] = "asus-mode1",
15933         [ALC662_ASUS_MODE2] = "asus-mode2",
15934         [ALC663_ASUS_MODE3] = "asus-mode3",
15935         [ALC663_ASUS_MODE4] = "asus-mode4",
15936         [ALC663_ASUS_MODE5] = "asus-mode5",
15937         [ALC663_ASUS_MODE6] = "asus-mode6",
15938         [ALC662_AUTO]           = "auto",
15939 };
15940
15941 static struct snd_pci_quirk alc662_cfg_tbl[] = {
15942         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
15943         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
15944         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
15945         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
15946         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
15947         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
15948         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
15949         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
15950         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
15951         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
15952         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
15953         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
15954         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
15955         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
15956         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
15957         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
15958         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
15959         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
15960         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
15961         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
15962         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
15963         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
15964         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
15965         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
15966         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
15967         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
15968         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
15969         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
15970         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
15971         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
15972         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
15973         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
15974         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
15975         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
15976         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
15977         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
15978         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
15979         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
15980                       ALC662_3ST_6ch_DIG),
15981         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
15982         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
15983         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
15984         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
15985                       ALC662_3ST_6ch_DIG),
15986         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
15987         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
15988                                         ALC662_3ST_6ch_DIG),
15989         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
15990         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
15991         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
15992         {}
15993 };
15994
15995 static struct alc_config_preset alc662_presets[] = {
15996         [ALC662_3ST_2ch_DIG] = {
15997                 .mixers = { alc662_3ST_2ch_mixer },
15998                 .init_verbs = { alc662_init_verbs },
15999                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16000                 .dac_nids = alc662_dac_nids,
16001                 .dig_out_nid = ALC662_DIGOUT_NID,
16002                 .dig_in_nid = ALC662_DIGIN_NID,
16003                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16004                 .channel_mode = alc662_3ST_2ch_modes,
16005                 .input_mux = &alc662_capture_source,
16006         },
16007         [ALC662_3ST_6ch_DIG] = {
16008                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16009                 .init_verbs = { alc662_init_verbs },
16010                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16011                 .dac_nids = alc662_dac_nids,
16012                 .dig_out_nid = ALC662_DIGOUT_NID,
16013                 .dig_in_nid = ALC662_DIGIN_NID,
16014                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16015                 .channel_mode = alc662_3ST_6ch_modes,
16016                 .need_dac_fix = 1,
16017                 .input_mux = &alc662_capture_source,
16018         },
16019         [ALC662_3ST_6ch] = {
16020                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16021                 .init_verbs = { alc662_init_verbs },
16022                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16023                 .dac_nids = alc662_dac_nids,
16024                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16025                 .channel_mode = alc662_3ST_6ch_modes,
16026                 .need_dac_fix = 1,
16027                 .input_mux = &alc662_capture_source,
16028         },
16029         [ALC662_5ST_DIG] = {
16030                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16031                 .init_verbs = { alc662_init_verbs },
16032                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16033                 .dac_nids = alc662_dac_nids,
16034                 .dig_out_nid = ALC662_DIGOUT_NID,
16035                 .dig_in_nid = ALC662_DIGIN_NID,
16036                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16037                 .channel_mode = alc662_5stack_modes,
16038                 .input_mux = &alc662_capture_source,
16039         },
16040         [ALC662_LENOVO_101E] = {
16041                 .mixers = { alc662_lenovo_101e_mixer },
16042                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16043                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16044                 .dac_nids = alc662_dac_nids,
16045                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16046                 .channel_mode = alc662_3ST_2ch_modes,
16047                 .input_mux = &alc662_lenovo_101e_capture_source,
16048                 .unsol_event = alc662_lenovo_101e_unsol_event,
16049                 .init_hook = alc662_lenovo_101e_all_automute,
16050         },
16051         [ALC662_ASUS_EEEPC_P701] = {
16052                 .mixers = { alc662_eeepc_p701_mixer },
16053                 .init_verbs = { alc662_init_verbs,
16054                                 alc662_eeepc_sue_init_verbs },
16055                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16056                 .dac_nids = alc662_dac_nids,
16057                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16058                 .channel_mode = alc662_3ST_2ch_modes,
16059                 .input_mux = &alc662_eeepc_capture_source,
16060                 .unsol_event = alc662_eeepc_unsol_event,
16061                 .init_hook = alc662_eeepc_inithook,
16062         },
16063         [ALC662_ASUS_EEEPC_EP20] = {
16064                 .mixers = { alc662_eeepc_ep20_mixer,
16065                             alc662_chmode_mixer },
16066                 .init_verbs = { alc662_init_verbs,
16067                                 alc662_eeepc_ep20_sue_init_verbs },
16068                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16069                 .dac_nids = alc662_dac_nids,
16070                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16071                 .channel_mode = alc662_3ST_6ch_modes,
16072                 .input_mux = &alc662_lenovo_101e_capture_source,
16073                 .unsol_event = alc662_eeepc_ep20_unsol_event,
16074                 .init_hook = alc662_eeepc_ep20_inithook,
16075         },
16076         [ALC662_ECS] = {
16077                 .mixers = { alc662_ecs_mixer },
16078                 .init_verbs = { alc662_init_verbs,
16079                                 alc662_ecs_init_verbs },
16080                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16081                 .dac_nids = alc662_dac_nids,
16082                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16083                 .channel_mode = alc662_3ST_2ch_modes,
16084                 .input_mux = &alc662_eeepc_capture_source,
16085                 .unsol_event = alc662_eeepc_unsol_event,
16086                 .init_hook = alc662_eeepc_inithook,
16087         },
16088         [ALC663_ASUS_M51VA] = {
16089                 .mixers = { alc663_m51va_mixer },
16090                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16091                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16092                 .dac_nids = alc662_dac_nids,
16093                 .dig_out_nid = ALC662_DIGOUT_NID,
16094                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16095                 .channel_mode = alc662_3ST_2ch_modes,
16096                 .input_mux = &alc663_m51va_capture_source,
16097                 .unsol_event = alc663_m51va_unsol_event,
16098                 .init_hook = alc663_m51va_inithook,
16099         },
16100         [ALC663_ASUS_G71V] = {
16101                 .mixers = { alc663_g71v_mixer },
16102                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16103                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16104                 .dac_nids = alc662_dac_nids,
16105                 .dig_out_nid = ALC662_DIGOUT_NID,
16106                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16107                 .channel_mode = alc662_3ST_2ch_modes,
16108                 .input_mux = &alc662_eeepc_capture_source,
16109                 .unsol_event = alc663_g71v_unsol_event,
16110                 .init_hook = alc663_g71v_inithook,
16111         },
16112         [ALC663_ASUS_H13] = {
16113                 .mixers = { alc663_m51va_mixer },
16114                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16115                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16116                 .dac_nids = alc662_dac_nids,
16117                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16118                 .channel_mode = alc662_3ST_2ch_modes,
16119                 .input_mux = &alc663_m51va_capture_source,
16120                 .unsol_event = alc663_m51va_unsol_event,
16121                 .init_hook = alc663_m51va_inithook,
16122         },
16123         [ALC663_ASUS_G50V] = {
16124                 .mixers = { alc663_g50v_mixer },
16125                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
16126                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16127                 .dac_nids = alc662_dac_nids,
16128                 .dig_out_nid = ALC662_DIGOUT_NID,
16129                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16130                 .channel_mode = alc662_3ST_6ch_modes,
16131                 .input_mux = &alc663_capture_source,
16132                 .unsol_event = alc663_g50v_unsol_event,
16133                 .init_hook = alc663_g50v_inithook,
16134         },
16135         [ALC663_ASUS_MODE1] = {
16136                 .mixers = { alc663_m51va_mixer },
16137                 .cap_mixer = alc662_auto_capture_mixer,
16138                 .init_verbs = { alc662_init_verbs,
16139                                 alc663_21jd_amic_init_verbs },
16140                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16141                 .hp_nid = 0x03,
16142                 .dac_nids = alc662_dac_nids,
16143                 .dig_out_nid = ALC662_DIGOUT_NID,
16144                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16145                 .channel_mode = alc662_3ST_2ch_modes,
16146                 .input_mux = &alc662_eeepc_capture_source,
16147                 .unsol_event = alc663_mode1_unsol_event,
16148                 .init_hook = alc663_mode1_inithook,
16149         },
16150         [ALC662_ASUS_MODE2] = {
16151                 .mixers = { alc662_1bjd_mixer },
16152                 .cap_mixer = alc662_auto_capture_mixer,
16153                 .init_verbs = { alc662_init_verbs,
16154                                 alc662_1bjd_amic_init_verbs },
16155                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16156                 .dac_nids = alc662_dac_nids,
16157                 .dig_out_nid = ALC662_DIGOUT_NID,
16158                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16159                 .channel_mode = alc662_3ST_2ch_modes,
16160                 .input_mux = &alc662_eeepc_capture_source,
16161                 .unsol_event = alc662_mode2_unsol_event,
16162                 .init_hook = alc662_mode2_inithook,
16163         },
16164         [ALC663_ASUS_MODE3] = {
16165                 .mixers = { alc663_two_hp_m1_mixer },
16166                 .cap_mixer = alc662_auto_capture_mixer,
16167                 .init_verbs = { alc662_init_verbs,
16168                                 alc663_two_hp_amic_m1_init_verbs },
16169                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16170                 .hp_nid = 0x03,
16171                 .dac_nids = alc662_dac_nids,
16172                 .dig_out_nid = ALC662_DIGOUT_NID,
16173                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16174                 .channel_mode = alc662_3ST_2ch_modes,
16175                 .input_mux = &alc662_eeepc_capture_source,
16176                 .unsol_event = alc663_mode3_unsol_event,
16177                 .init_hook = alc663_mode3_inithook,
16178         },
16179         [ALC663_ASUS_MODE4] = {
16180                 .mixers = { alc663_asus_21jd_clfe_mixer },
16181                 .cap_mixer = alc662_auto_capture_mixer,
16182                 .init_verbs = { alc662_init_verbs,
16183                                 alc663_21jd_amic_init_verbs},
16184                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16185                 .hp_nid = 0x03,
16186                 .dac_nids = alc662_dac_nids,
16187                 .dig_out_nid = ALC662_DIGOUT_NID,
16188                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16189                 .channel_mode = alc662_3ST_2ch_modes,
16190                 .input_mux = &alc662_eeepc_capture_source,
16191                 .unsol_event = alc663_mode4_unsol_event,
16192                 .init_hook = alc663_mode4_inithook,
16193         },
16194         [ALC663_ASUS_MODE5] = {
16195                 .mixers = { alc663_asus_15jd_clfe_mixer },
16196                 .cap_mixer = alc662_auto_capture_mixer,
16197                 .init_verbs = { alc662_init_verbs,
16198                                 alc663_15jd_amic_init_verbs },
16199                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16200                 .hp_nid = 0x03,
16201                 .dac_nids = alc662_dac_nids,
16202                 .dig_out_nid = ALC662_DIGOUT_NID,
16203                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16204                 .channel_mode = alc662_3ST_2ch_modes,
16205                 .input_mux = &alc662_eeepc_capture_source,
16206                 .unsol_event = alc663_mode5_unsol_event,
16207                 .init_hook = alc663_mode5_inithook,
16208         },
16209         [ALC663_ASUS_MODE6] = {
16210                 .mixers = { alc663_two_hp_m2_mixer },
16211                 .cap_mixer = alc662_auto_capture_mixer,
16212                 .init_verbs = { alc662_init_verbs,
16213                                 alc663_two_hp_amic_m2_init_verbs },
16214                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16215                 .hp_nid = 0x03,
16216                 .dac_nids = alc662_dac_nids,
16217                 .dig_out_nid = ALC662_DIGOUT_NID,
16218                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16219                 .channel_mode = alc662_3ST_2ch_modes,
16220                 .input_mux = &alc662_eeepc_capture_source,
16221                 .unsol_event = alc663_mode6_unsol_event,
16222                 .init_hook = alc663_mode6_inithook,
16223         },
16224 };
16225
16226
16227 /*
16228  * BIOS auto configuration
16229  */
16230
16231 /* add playback controls from the parsed DAC table */
16232 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
16233                                              const struct auto_pin_cfg *cfg)
16234 {
16235         char name[32];
16236         static const char *chname[4] = {
16237                 "Front", "Surround", NULL /*CLFE*/, "Side"
16238         };
16239         hda_nid_t nid;
16240         int i, err;
16241
16242         for (i = 0; i < cfg->line_outs; i++) {
16243                 if (!spec->multiout.dac_nids[i])
16244                         continue;
16245                 nid = alc880_idx_to_dac(i);
16246                 if (i == 2) {
16247                         /* Center/LFE */
16248                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16249                                           "Center Playback Volume",
16250                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
16251                                                               HDA_OUTPUT));
16252                         if (err < 0)
16253                                 return err;
16254                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16255                                           "LFE Playback Volume",
16256                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
16257                                                               HDA_OUTPUT));
16258                         if (err < 0)
16259                                 return err;
16260                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16261                                           "Center Playback Switch",
16262                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
16263                                                               HDA_INPUT));
16264                         if (err < 0)
16265                                 return err;
16266                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16267                                           "LFE Playback Switch",
16268                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
16269                                                               HDA_INPUT));
16270                         if (err < 0)
16271                                 return err;
16272                 } else {
16273                         sprintf(name, "%s Playback Volume", chname[i]);
16274                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16275                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
16276                                                               HDA_OUTPUT));
16277                         if (err < 0)
16278                                 return err;
16279                         sprintf(name, "%s Playback Switch", chname[i]);
16280                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16281                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
16282                                                     3, 0, HDA_INPUT));
16283                         if (err < 0)
16284                                 return err;
16285                 }
16286         }
16287         return 0;
16288 }
16289
16290 /* add playback controls for speaker and HP outputs */
16291 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16292                                         const char *pfx)
16293 {
16294         hda_nid_t nid;
16295         int err;
16296         char name[32];
16297
16298         if (!pin)
16299                 return 0;
16300
16301         if (pin == 0x17) {
16302                 /* ALC663 has a mono output pin on 0x17 */
16303                 sprintf(name, "%s Playback Switch", pfx);
16304                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16305                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16306                 return err;
16307         }
16308
16309         if (alc880_is_fixed_pin(pin)) {
16310                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16311                 /* printk("DAC nid=%x\n",nid); */
16312                 /* specify the DAC as the extra output */
16313                 if (!spec->multiout.hp_nid)
16314                         spec->multiout.hp_nid = nid;
16315                 else
16316                         spec->multiout.extra_out_nid[0] = nid;
16317                 /* control HP volume/switch on the output mixer amp */
16318                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16319                 sprintf(name, "%s Playback Volume", pfx);
16320                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16321                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16322                 if (err < 0)
16323                         return err;
16324                 sprintf(name, "%s Playback Switch", pfx);
16325                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16326                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16327                 if (err < 0)
16328                         return err;
16329         } else if (alc880_is_multi_pin(pin)) {
16330                 /* set manual connection */
16331                 /* we have only a switch on HP-out PIN */
16332                 sprintf(name, "%s Playback Switch", pfx);
16333                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16334                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16335                 if (err < 0)
16336                         return err;
16337         }
16338         return 0;
16339 }
16340
16341 /* create playback/capture controls for input pins */
16342 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
16343                                                 const struct auto_pin_cfg *cfg)
16344 {
16345         struct hda_input_mux *imux = &spec->private_imux;
16346         int i, err, idx;
16347
16348         for (i = 0; i < AUTO_PIN_LAST; i++) {
16349                 if (alc880_is_input_pin(cfg->input_pins[i])) {
16350                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
16351                         err = new_analog_input(spec, cfg->input_pins[i],
16352                                                auto_pin_cfg_labels[i],
16353                                                idx, 0x0b);
16354                         if (err < 0)
16355                                 return err;
16356                         imux->items[imux->num_items].label =
16357                                 auto_pin_cfg_labels[i];
16358                         imux->items[imux->num_items].index =
16359                                 alc880_input_pin_idx(cfg->input_pins[i]);
16360                         imux->num_items++;
16361                 }
16362         }
16363         return 0;
16364 }
16365
16366 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16367                                               hda_nid_t nid, int pin_type,
16368                                               int dac_idx)
16369 {
16370         alc_set_pin_output(codec, nid, pin_type);
16371         /* need the manual connection? */
16372         if (alc880_is_multi_pin(nid)) {
16373                 struct alc_spec *spec = codec->spec;
16374                 int idx = alc880_multi_pin_idx(nid);
16375                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16376                                     AC_VERB_SET_CONNECT_SEL,
16377                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16378         }
16379 }
16380
16381 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16382 {
16383         struct alc_spec *spec = codec->spec;
16384         int i;
16385
16386         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16387         for (i = 0; i <= HDA_SIDE; i++) {
16388                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16389                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16390                 if (nid)
16391                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16392                                                           i);
16393         }
16394 }
16395
16396 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16397 {
16398         struct alc_spec *spec = codec->spec;
16399         hda_nid_t pin;
16400
16401         pin = spec->autocfg.hp_pins[0];
16402         if (pin) /* connect to front */
16403                 /* use dac 0 */
16404                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16405         pin = spec->autocfg.speaker_pins[0];
16406         if (pin)
16407                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16408 }
16409
16410 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
16411 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16412
16413 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16414 {
16415         struct alc_spec *spec = codec->spec;
16416         int i;
16417
16418         for (i = 0; i < AUTO_PIN_LAST; i++) {
16419                 hda_nid_t nid = spec->autocfg.input_pins[i];
16420                 if (alc662_is_input_pin(nid)) {
16421                         snd_hda_codec_write(codec, nid, 0,
16422                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
16423                                             (i <= AUTO_PIN_FRONT_MIC ?
16424                                              PIN_VREF80 : PIN_IN));
16425                         if (nid != ALC662_PIN_CD_NID)
16426                                 snd_hda_codec_write(codec, nid, 0,
16427                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16428                                                     AMP_OUT_MUTE);
16429                 }
16430         }
16431 }
16432
16433 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16434
16435 static int alc662_parse_auto_config(struct hda_codec *codec)
16436 {
16437         struct alc_spec *spec = codec->spec;
16438         int err;
16439         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16440
16441         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16442                                            alc662_ignore);
16443         if (err < 0)
16444                 return err;
16445         if (!spec->autocfg.line_outs)
16446                 return 0; /* can't find valid BIOS pin config */
16447
16448         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16449         if (err < 0)
16450                 return err;
16451         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16452         if (err < 0)
16453                 return err;
16454         err = alc662_auto_create_extra_out(spec,
16455                                            spec->autocfg.speaker_pins[0],
16456                                            "Speaker");
16457         if (err < 0)
16458                 return err;
16459         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
16460                                            "Headphone");
16461         if (err < 0)
16462                 return err;
16463         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
16464         if (err < 0)
16465                 return err;
16466
16467         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16468
16469         if (spec->autocfg.dig_out_pin)
16470                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16471
16472         if (spec->kctls.list)
16473                 add_mixer(spec, spec->kctls.list);
16474
16475         spec->num_mux_defs = 1;
16476         spec->input_mux = &spec->private_imux;
16477
16478         add_verb(spec, alc662_auto_init_verbs);
16479         if (codec->vendor_id == 0x10ec0663)
16480                 add_verb(spec, alc663_auto_init_verbs);
16481
16482         err = alc_auto_add_mic_boost(codec);
16483         if (err < 0)
16484                 return err;
16485
16486         store_pin_configs(codec);
16487         return 1;
16488 }
16489
16490 /* additional initialization for auto-configuration model */
16491 static void alc662_auto_init(struct hda_codec *codec)
16492 {
16493         struct alc_spec *spec = codec->spec;
16494         alc662_auto_init_multi_out(codec);
16495         alc662_auto_init_hp_out(codec);
16496         alc662_auto_init_analog_input(codec);
16497         alc662_auto_init_input_src(codec);
16498         if (spec->unsol_event)
16499                 alc_inithook(codec);
16500 }
16501
16502 static int patch_alc662(struct hda_codec *codec)
16503 {
16504         struct alc_spec *spec;
16505         int err, board_config;
16506
16507         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16508         if (!spec)
16509                 return -ENOMEM;
16510
16511         codec->spec = spec;
16512
16513         alc_fix_pll_init(codec, 0x20, 0x04, 15);
16514
16515         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
16516                                                   alc662_models,
16517                                                   alc662_cfg_tbl);
16518         if (board_config < 0) {
16519                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
16520                        "trying auto-probe from BIOS...\n");
16521                 board_config = ALC662_AUTO;
16522         }
16523
16524         if (board_config == ALC662_AUTO) {
16525                 /* automatic parse from the BIOS config */
16526                 err = alc662_parse_auto_config(codec);
16527                 if (err < 0) {
16528                         alc_free(codec);
16529                         return err;
16530                 } else if (!err) {
16531                         printk(KERN_INFO
16532                                "hda_codec: Cannot set up configuration "
16533                                "from BIOS.  Using base mode...\n");
16534                         board_config = ALC662_3ST_2ch_DIG;
16535                 }
16536         }
16537
16538         if (board_config != ALC662_AUTO)
16539                 setup_preset(spec, &alc662_presets[board_config]);
16540
16541         if (codec->vendor_id == 0x10ec0663) {
16542                 spec->stream_name_analog = "ALC663 Analog";
16543                 spec->stream_name_digital = "ALC663 Digital";
16544         } else if (codec->vendor_id == 0x10ec0272) {
16545                 spec->stream_name_analog = "ALC272 Analog";
16546                 spec->stream_name_digital = "ALC272 Digital";
16547         } else {
16548                 spec->stream_name_analog = "ALC662 Analog";
16549                 spec->stream_name_digital = "ALC662 Digital";
16550         }
16551
16552         spec->stream_analog_playback = &alc662_pcm_analog_playback;
16553         spec->stream_analog_capture = &alc662_pcm_analog_capture;
16554
16555         spec->stream_digital_playback = &alc662_pcm_digital_playback;
16556         spec->stream_digital_capture = &alc662_pcm_digital_capture;
16557
16558         spec->adc_nids = alc662_adc_nids;
16559         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16560         spec->capsrc_nids = alc662_capsrc_nids;
16561         spec->is_mix_capture = 1;
16562
16563         if (!spec->cap_mixer)
16564                 set_capture_mixer(spec);
16565
16566         spec->vmaster_nid = 0x02;
16567
16568         codec->patch_ops = alc_patch_ops;
16569         if (board_config == ALC662_AUTO)
16570                 spec->init_hook = alc662_auto_init;
16571 #ifdef CONFIG_SND_HDA_POWER_SAVE
16572         if (!spec->loopback.amplist)
16573                 spec->loopback.amplist = alc662_loopbacks;
16574 #endif
16575
16576         return 0;
16577 }
16578
16579 /*
16580  * patch entries
16581  */
16582 struct hda_codec_preset snd_hda_preset_realtek[] = {
16583         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16584         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16585         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
16586         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
16587         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
16588         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
16589         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
16590           .patch = patch_alc861 },
16591         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
16592         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
16593         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
16594         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
16595           .patch = patch_alc883 },
16596         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
16597           .patch = patch_alc662 },
16598         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
16599         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
16600         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
16601         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16602         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
16603           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16604         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
16605           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16606         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
16607         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
16608         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
16609         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
16610           .patch = patch_alc883 },
16611         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16612         {} /* terminator */
16613 };