ALSA: hda - Modularize HD-audio driver
[safe/jmp/linux-2.6] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33
34 #define ALC880_FRONT_EVENT              0x01
35 #define ALC880_DCVOL_EVENT              0x02
36 #define ALC880_HP_EVENT                 0x04
37 #define ALC880_MIC_EVENT                0x08
38
39 /* ALC880 board config type */
40 enum {
41         ALC880_3ST,
42         ALC880_3ST_DIG,
43         ALC880_5ST,
44         ALC880_5ST_DIG,
45         ALC880_W810,
46         ALC880_Z71V,
47         ALC880_6ST,
48         ALC880_6ST_DIG,
49         ALC880_F1734,
50         ALC880_ASUS,
51         ALC880_ASUS_DIG,
52         ALC880_ASUS_W1V,
53         ALC880_ASUS_DIG2,
54         ALC880_FUJITSU,
55         ALC880_UNIWILL_DIG,
56         ALC880_UNIWILL,
57         ALC880_UNIWILL_P53,
58         ALC880_CLEVO,
59         ALC880_TCL_S700,
60         ALC880_LG,
61         ALC880_LG_LW,
62         ALC880_MEDION_RIM,
63 #ifdef CONFIG_SND_DEBUG
64         ALC880_TEST,
65 #endif
66         ALC880_AUTO,
67         ALC880_MODEL_LAST /* last tag */
68 };
69
70 /* ALC260 models */
71 enum {
72         ALC260_BASIC,
73         ALC260_HP,
74         ALC260_HP_DC7600,
75         ALC260_HP_3013,
76         ALC260_FUJITSU_S702X,
77         ALC260_ACER,
78         ALC260_WILL,
79         ALC260_REPLACER_672V,
80 #ifdef CONFIG_SND_DEBUG
81         ALC260_TEST,
82 #endif
83         ALC260_AUTO,
84         ALC260_MODEL_LAST /* last tag */
85 };
86
87 /* ALC262 models */
88 enum {
89         ALC262_BASIC,
90         ALC262_HIPPO,
91         ALC262_HIPPO_1,
92         ALC262_FUJITSU,
93         ALC262_HP_BPC,
94         ALC262_HP_BPC_D7000_WL,
95         ALC262_HP_BPC_D7000_WF,
96         ALC262_HP_TC_T5735,
97         ALC262_HP_RP5700,
98         ALC262_BENQ_ED8,
99         ALC262_SONY_ASSAMD,
100         ALC262_BENQ_T31,
101         ALC262_ULTRA,
102         ALC262_LENOVO_3000,
103         ALC262_NEC,
104         ALC262_TOSHIBA_S06,
105         ALC262_TOSHIBA_RX1,
106         ALC262_AUTO,
107         ALC262_MODEL_LAST /* last tag */
108 };
109
110 /* ALC268 models */
111 enum {
112         ALC267_QUANTA_IL1,
113         ALC268_3ST,
114         ALC268_TOSHIBA,
115         ALC268_ACER,
116         ALC268_ACER_DMIC,
117         ALC268_ACER_ASPIRE_ONE,
118         ALC268_DELL,
119         ALC268_ZEPTO,
120 #ifdef CONFIG_SND_DEBUG
121         ALC268_TEST,
122 #endif
123         ALC268_AUTO,
124         ALC268_MODEL_LAST /* last tag */
125 };
126
127 /* ALC269 models */
128 enum {
129         ALC269_BASIC,
130         ALC269_QUANTA_FL1,
131         ALC269_ASUS_EEEPC_P703,
132         ALC269_ASUS_EEEPC_P901,
133         ALC269_FUJITSU,
134         ALC269_LIFEBOOK,
135         ALC269_AUTO,
136         ALC269_MODEL_LAST /* last tag */
137 };
138
139 /* ALC861 models */
140 enum {
141         ALC861_3ST,
142         ALC660_3ST,
143         ALC861_3ST_DIG,
144         ALC861_6ST_DIG,
145         ALC861_UNIWILL_M31,
146         ALC861_TOSHIBA,
147         ALC861_ASUS,
148         ALC861_ASUS_LAPTOP,
149         ALC861_AUTO,
150         ALC861_MODEL_LAST,
151 };
152
153 /* ALC861-VD models */
154 enum {
155         ALC660VD_3ST,
156         ALC660VD_3ST_DIG,
157         ALC660VD_ASUS_V1S,
158         ALC861VD_3ST,
159         ALC861VD_3ST_DIG,
160         ALC861VD_6ST_DIG,
161         ALC861VD_LENOVO,
162         ALC861VD_DALLAS,
163         ALC861VD_HP,
164         ALC861VD_AUTO,
165         ALC861VD_MODEL_LAST,
166 };
167
168 /* ALC662 models */
169 enum {
170         ALC662_3ST_2ch_DIG,
171         ALC662_3ST_6ch_DIG,
172         ALC662_3ST_6ch,
173         ALC662_5ST_DIG,
174         ALC662_LENOVO_101E,
175         ALC662_ASUS_EEEPC_P701,
176         ALC662_ASUS_EEEPC_EP20,
177         ALC663_ASUS_M51VA,
178         ALC663_ASUS_G71V,
179         ALC663_ASUS_H13,
180         ALC663_ASUS_G50V,
181         ALC662_ECS,
182         ALC663_ASUS_MODE1,
183         ALC662_ASUS_MODE2,
184         ALC663_ASUS_MODE3,
185         ALC663_ASUS_MODE4,
186         ALC663_ASUS_MODE5,
187         ALC663_ASUS_MODE6,
188         ALC662_AUTO,
189         ALC662_MODEL_LAST,
190 };
191
192 /* ALC882 models */
193 enum {
194         ALC882_3ST_DIG,
195         ALC882_6ST_DIG,
196         ALC882_ARIMA,
197         ALC882_W2JC,
198         ALC882_TARGA,
199         ALC882_ASUS_A7J,
200         ALC882_ASUS_A7M,
201         ALC885_MACPRO,
202         ALC885_MBP3,
203         ALC885_IMAC24,
204         ALC882_AUTO,
205         ALC882_MODEL_LAST,
206 };
207
208 /* ALC883 models */
209 enum {
210         ALC883_3ST_2ch_DIG,
211         ALC883_3ST_6ch_DIG,
212         ALC883_3ST_6ch,
213         ALC883_6ST_DIG,
214         ALC883_TARGA_DIG,
215         ALC883_TARGA_2ch_DIG,
216         ALC883_ACER,
217         ALC883_ACER_ASPIRE,
218         ALC888_ACER_ASPIRE_4930G,
219         ALC883_MEDION,
220         ALC883_MEDION_MD2,
221         ALC883_LAPTOP_EAPD,
222         ALC883_LENOVO_101E_2ch,
223         ALC883_LENOVO_NB0763,
224         ALC888_LENOVO_MS7195_DIG,
225         ALC888_LENOVO_SKY,
226         ALC883_HAIER_W66,
227         ALC888_3ST_HP,
228         ALC888_6ST_DELL,
229         ALC883_MITAC,
230         ALC883_CLEVO_M720,
231         ALC883_FUJITSU_PI2515,
232         ALC888_FUJITSU_XA3530,
233         ALC883_3ST_6ch_INTEL,
234         ALC888_ASUS_M90V,
235         ALC888_ASUS_EEE1601,
236         ALC1200_ASUS_P5Q,
237         ALC883_AUTO,
238         ALC883_MODEL_LAST,
239 };
240
241 /* for GPIO Poll */
242 #define GPIO_MASK       0x03
243
244 struct alc_spec {
245         /* codec parameterization */
246         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
247         unsigned int num_mixers;
248         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
249
250         const struct hda_verb *init_verbs[5];   /* initialization verbs
251                                                  * don't forget NULL
252                                                  * termination!
253                                                  */
254         unsigned int num_init_verbs;
255
256         char *stream_name_analog;       /* analog PCM stream */
257         struct hda_pcm_stream *stream_analog_playback;
258         struct hda_pcm_stream *stream_analog_capture;
259         struct hda_pcm_stream *stream_analog_alt_playback;
260         struct hda_pcm_stream *stream_analog_alt_capture;
261
262         char *stream_name_digital;      /* digital PCM stream */
263         struct hda_pcm_stream *stream_digital_playback;
264         struct hda_pcm_stream *stream_digital_capture;
265
266         /* playback */
267         struct hda_multi_out multiout;  /* playback set-up
268                                          * max_channels, dacs must be set
269                                          * dig_out_nid and hp_nid are optional
270                                          */
271         hda_nid_t alt_dac_nid;
272
273         /* capture */
274         unsigned int num_adc_nids;
275         hda_nid_t *adc_nids;
276         hda_nid_t *capsrc_nids;
277         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
278         unsigned char is_mix_capture;   /* matrix-style capture (non-mux) */
279
280         /* capture source */
281         unsigned int num_mux_defs;
282         const struct hda_input_mux *input_mux;
283         unsigned int cur_mux[3];
284
285         /* channel model */
286         const struct hda_channel_mode *channel_mode;
287         int num_channel_mode;
288         int need_dac_fix;
289
290         /* PCM information */
291         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
292
293         /* dynamic controls, init_verbs and input_mux */
294         struct auto_pin_cfg autocfg;
295         struct snd_array kctls;
296         struct hda_input_mux private_imux;
297         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
298
299         /* hooks */
300         void (*init_hook)(struct hda_codec *codec);
301         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
302
303         /* for pin sensing */
304         unsigned int sense_updated: 1;
305         unsigned int jack_present: 1;
306         unsigned int master_sw: 1;
307
308         /* for virtual master */
309         hda_nid_t vmaster_nid;
310 #ifdef CONFIG_SND_HDA_POWER_SAVE
311         struct hda_loopback_check loopback;
312 #endif
313
314         /* for PLL fix */
315         hda_nid_t pll_nid;
316         unsigned int pll_coef_idx, pll_coef_bit;
317
318 #ifdef SND_HDA_NEEDS_RESUME
319 #define ALC_MAX_PINS    16
320         unsigned int num_pins;
321         hda_nid_t pin_nids[ALC_MAX_PINS];
322         unsigned int pin_cfgs[ALC_MAX_PINS];
323 #endif
324 };
325
326 /*
327  * configuration template - to be copied to the spec instance
328  */
329 struct alc_config_preset {
330         struct snd_kcontrol_new *mixers[5]; /* should be identical size
331                                              * with spec
332                                              */
333         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
334         const struct hda_verb *init_verbs[5];
335         unsigned int num_dacs;
336         hda_nid_t *dac_nids;
337         hda_nid_t dig_out_nid;          /* optional */
338         hda_nid_t hp_nid;               /* optional */
339         unsigned int num_adc_nids;
340         hda_nid_t *adc_nids;
341         hda_nid_t *capsrc_nids;
342         hda_nid_t dig_in_nid;
343         unsigned int num_channel_mode;
344         const struct hda_channel_mode *channel_mode;
345         int need_dac_fix;
346         unsigned int num_mux_defs;
347         const struct hda_input_mux *input_mux;
348         void (*unsol_event)(struct hda_codec *, unsigned int);
349         void (*init_hook)(struct hda_codec *);
350 #ifdef CONFIG_SND_HDA_POWER_SAVE
351         struct hda_amp_list *loopbacks;
352 #endif
353 };
354
355
356 /*
357  * input MUX handling
358  */
359 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
360                              struct snd_ctl_elem_info *uinfo)
361 {
362         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
363         struct alc_spec *spec = codec->spec;
364         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
365         if (mux_idx >= spec->num_mux_defs)
366                 mux_idx = 0;
367         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
368 }
369
370 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
371                             struct snd_ctl_elem_value *ucontrol)
372 {
373         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
374         struct alc_spec *spec = codec->spec;
375         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
376
377         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
378         return 0;
379 }
380
381 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
382                             struct snd_ctl_elem_value *ucontrol)
383 {
384         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
385         struct alc_spec *spec = codec->spec;
386         const struct hda_input_mux *imux;
387         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
388         unsigned int mux_idx;
389         hda_nid_t nid = spec->capsrc_nids ?
390                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
391
392         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
393         imux = &spec->input_mux[mux_idx];
394
395         if (spec->is_mix_capture) {
396                 /* Matrix-mixer style (e.g. ALC882) */
397                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
398                 unsigned int i, idx;
399
400                 idx = ucontrol->value.enumerated.item[0];
401                 if (idx >= imux->num_items)
402                         idx = imux->num_items - 1;
403                 if (*cur_val == idx)
404                         return 0;
405                 for (i = 0; i < imux->num_items; i++) {
406                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
407                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
408                                                  imux->items[i].index,
409                                                  HDA_AMP_MUTE, v);
410                 }
411                 *cur_val = idx;
412                 return 1;
413         } else {
414                 /* MUX style (e.g. ALC880) */
415                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
416                                              &spec->cur_mux[adc_idx]);
417         }
418 }
419
420 /*
421  * channel mode setting
422  */
423 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
424                             struct snd_ctl_elem_info *uinfo)
425 {
426         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
427         struct alc_spec *spec = codec->spec;
428         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
429                                     spec->num_channel_mode);
430 }
431
432 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
433                            struct snd_ctl_elem_value *ucontrol)
434 {
435         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
436         struct alc_spec *spec = codec->spec;
437         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
438                                    spec->num_channel_mode,
439                                    spec->multiout.max_channels);
440 }
441
442 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
443                            struct snd_ctl_elem_value *ucontrol)
444 {
445         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
446         struct alc_spec *spec = codec->spec;
447         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
448                                       spec->num_channel_mode,
449                                       &spec->multiout.max_channels);
450         if (err >= 0 && spec->need_dac_fix)
451                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
452         return err;
453 }
454
455 /*
456  * Control the mode of pin widget settings via the mixer.  "pc" is used
457  * instead of "%" to avoid consequences of accidently treating the % as
458  * being part of a format specifier.  Maximum allowed length of a value is
459  * 63 characters plus NULL terminator.
460  *
461  * Note: some retasking pin complexes seem to ignore requests for input
462  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
463  * are requested.  Therefore order this list so that this behaviour will not
464  * cause problems when mixer clients move through the enum sequentially.
465  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
466  * March 2006.
467  */
468 static char *alc_pin_mode_names[] = {
469         "Mic 50pc bias", "Mic 80pc bias",
470         "Line in", "Line out", "Headphone out",
471 };
472 static unsigned char alc_pin_mode_values[] = {
473         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
474 };
475 /* The control can present all 5 options, or it can limit the options based
476  * in the pin being assumed to be exclusively an input or an output pin.  In
477  * addition, "input" pins may or may not process the mic bias option
478  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
479  * accept requests for bias as of chip versions up to March 2006) and/or
480  * wiring in the computer.
481  */
482 #define ALC_PIN_DIR_IN              0x00
483 #define ALC_PIN_DIR_OUT             0x01
484 #define ALC_PIN_DIR_INOUT           0x02
485 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
486 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
487
488 /* Info about the pin modes supported by the different pin direction modes.
489  * For each direction the minimum and maximum values are given.
490  */
491 static signed char alc_pin_mode_dir_info[5][2] = {
492         { 0, 2 },    /* ALC_PIN_DIR_IN */
493         { 3, 4 },    /* ALC_PIN_DIR_OUT */
494         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
495         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
496         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
497 };
498 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
499 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
500 #define alc_pin_mode_n_items(_dir) \
501         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
502
503 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
504                              struct snd_ctl_elem_info *uinfo)
505 {
506         unsigned int item_num = uinfo->value.enumerated.item;
507         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
508
509         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
510         uinfo->count = 1;
511         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
512
513         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
514                 item_num = alc_pin_mode_min(dir);
515         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
516         return 0;
517 }
518
519 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
520                             struct snd_ctl_elem_value *ucontrol)
521 {
522         unsigned int i;
523         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
524         hda_nid_t nid = kcontrol->private_value & 0xffff;
525         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
526         long *valp = ucontrol->value.integer.value;
527         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
528                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
529                                                  0x00);
530
531         /* Find enumerated value for current pinctl setting */
532         i = alc_pin_mode_min(dir);
533         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
534                 i++;
535         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
536         return 0;
537 }
538
539 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
540                             struct snd_ctl_elem_value *ucontrol)
541 {
542         signed int change;
543         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
544         hda_nid_t nid = kcontrol->private_value & 0xffff;
545         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
546         long val = *ucontrol->value.integer.value;
547         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
548                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
549                                                  0x00);
550
551         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
552                 val = alc_pin_mode_min(dir);
553
554         change = pinctl != alc_pin_mode_values[val];
555         if (change) {
556                 /* Set pin mode to that requested */
557                 snd_hda_codec_write_cache(codec, nid, 0,
558                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
559                                           alc_pin_mode_values[val]);
560
561                 /* Also enable the retasking pin's input/output as required
562                  * for the requested pin mode.  Enum values of 2 or less are
563                  * input modes.
564                  *
565                  * Dynamically switching the input/output buffers probably
566                  * reduces noise slightly (particularly on input) so we'll
567                  * do it.  However, having both input and output buffers
568                  * enabled simultaneously doesn't seem to be problematic if
569                  * this turns out to be necessary in the future.
570                  */
571                 if (val <= 2) {
572                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
573                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
574                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
575                                                  HDA_AMP_MUTE, 0);
576                 } else {
577                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
578                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
579                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
580                                                  HDA_AMP_MUTE, 0);
581                 }
582         }
583         return change;
584 }
585
586 #define ALC_PIN_MODE(xname, nid, dir) \
587         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
588           .info = alc_pin_mode_info, \
589           .get = alc_pin_mode_get, \
590           .put = alc_pin_mode_put, \
591           .private_value = nid | (dir<<16) }
592
593 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
594  * together using a mask with more than one bit set.  This control is
595  * currently used only by the ALC260 test model.  At this stage they are not
596  * needed for any "production" models.
597  */
598 #ifdef CONFIG_SND_DEBUG
599 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
600
601 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
602                              struct snd_ctl_elem_value *ucontrol)
603 {
604         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
605         hda_nid_t nid = kcontrol->private_value & 0xffff;
606         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
607         long *valp = ucontrol->value.integer.value;
608         unsigned int val = snd_hda_codec_read(codec, nid, 0,
609                                               AC_VERB_GET_GPIO_DATA, 0x00);
610
611         *valp = (val & mask) != 0;
612         return 0;
613 }
614 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
615                              struct snd_ctl_elem_value *ucontrol)
616 {
617         signed int change;
618         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
619         hda_nid_t nid = kcontrol->private_value & 0xffff;
620         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
621         long val = *ucontrol->value.integer.value;
622         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
623                                                     AC_VERB_GET_GPIO_DATA,
624                                                     0x00);
625
626         /* Set/unset the masked GPIO bit(s) as needed */
627         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
628         if (val == 0)
629                 gpio_data &= ~mask;
630         else
631                 gpio_data |= mask;
632         snd_hda_codec_write_cache(codec, nid, 0,
633                                   AC_VERB_SET_GPIO_DATA, gpio_data);
634
635         return change;
636 }
637 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
638         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
639           .info = alc_gpio_data_info, \
640           .get = alc_gpio_data_get, \
641           .put = alc_gpio_data_put, \
642           .private_value = nid | (mask<<16) }
643 #endif   /* CONFIG_SND_DEBUG */
644
645 /* A switch control to allow the enabling of the digital IO pins on the
646  * ALC260.  This is incredibly simplistic; the intention of this control is
647  * to provide something in the test model allowing digital outputs to be
648  * identified if present.  If models are found which can utilise these
649  * outputs a more complete mixer control can be devised for those models if
650  * necessary.
651  */
652 #ifdef CONFIG_SND_DEBUG
653 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
654
655 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
656                               struct snd_ctl_elem_value *ucontrol)
657 {
658         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
659         hda_nid_t nid = kcontrol->private_value & 0xffff;
660         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
661         long *valp = ucontrol->value.integer.value;
662         unsigned int val = snd_hda_codec_read(codec, nid, 0,
663                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
664
665         *valp = (val & mask) != 0;
666         return 0;
667 }
668 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
669                               struct snd_ctl_elem_value *ucontrol)
670 {
671         signed int change;
672         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
673         hda_nid_t nid = kcontrol->private_value & 0xffff;
674         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
675         long val = *ucontrol->value.integer.value;
676         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
677                                                     AC_VERB_GET_DIGI_CONVERT_1,
678                                                     0x00);
679
680         /* Set/unset the masked control bit(s) as needed */
681         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
682         if (val==0)
683                 ctrl_data &= ~mask;
684         else
685                 ctrl_data |= mask;
686         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
687                                   ctrl_data);
688
689         return change;
690 }
691 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
692         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
693           .info = alc_spdif_ctrl_info, \
694           .get = alc_spdif_ctrl_get, \
695           .put = alc_spdif_ctrl_put, \
696           .private_value = nid | (mask<<16) }
697 #endif   /* CONFIG_SND_DEBUG */
698
699 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
700  * Again, this is only used in the ALC26x test models to help identify when
701  * the EAPD line must be asserted for features to work.
702  */
703 #ifdef CONFIG_SND_DEBUG
704 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
705
706 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
707                               struct snd_ctl_elem_value *ucontrol)
708 {
709         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
710         hda_nid_t nid = kcontrol->private_value & 0xffff;
711         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
712         long *valp = ucontrol->value.integer.value;
713         unsigned int val = snd_hda_codec_read(codec, nid, 0,
714                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
715
716         *valp = (val & mask) != 0;
717         return 0;
718 }
719
720 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
721                               struct snd_ctl_elem_value *ucontrol)
722 {
723         int change;
724         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
725         hda_nid_t nid = kcontrol->private_value & 0xffff;
726         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
727         long val = *ucontrol->value.integer.value;
728         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
729                                                     AC_VERB_GET_EAPD_BTLENABLE,
730                                                     0x00);
731
732         /* Set/unset the masked control bit(s) as needed */
733         change = (!val ? 0 : mask) != (ctrl_data & mask);
734         if (!val)
735                 ctrl_data &= ~mask;
736         else
737                 ctrl_data |= mask;
738         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
739                                   ctrl_data);
740
741         return change;
742 }
743
744 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
745         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
746           .info = alc_eapd_ctrl_info, \
747           .get = alc_eapd_ctrl_get, \
748           .put = alc_eapd_ctrl_put, \
749           .private_value = nid | (mask<<16) }
750 #endif   /* CONFIG_SND_DEBUG */
751
752 /*
753  */
754 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
755 {
756         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
757                 return;
758         spec->mixers[spec->num_mixers++] = mix;
759 }
760
761 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
762 {
763         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
764                 return;
765         spec->init_verbs[spec->num_init_verbs++] = verb;
766 }
767
768 /*
769  * set up from the preset table
770  */
771 static void setup_preset(struct alc_spec *spec,
772                          const struct alc_config_preset *preset)
773 {
774         int i;
775
776         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
777                 add_mixer(spec, preset->mixers[i]);
778         spec->cap_mixer = preset->cap_mixer;
779         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
780              i++)
781                 add_verb(spec, preset->init_verbs[i]);
782
783         spec->channel_mode = preset->channel_mode;
784         spec->num_channel_mode = preset->num_channel_mode;
785         spec->need_dac_fix = preset->need_dac_fix;
786
787         spec->multiout.max_channels = spec->channel_mode[0].channels;
788
789         spec->multiout.num_dacs = preset->num_dacs;
790         spec->multiout.dac_nids = preset->dac_nids;
791         spec->multiout.dig_out_nid = preset->dig_out_nid;
792         spec->multiout.hp_nid = preset->hp_nid;
793
794         spec->num_mux_defs = preset->num_mux_defs;
795         if (!spec->num_mux_defs)
796                 spec->num_mux_defs = 1;
797         spec->input_mux = preset->input_mux;
798
799         spec->num_adc_nids = preset->num_adc_nids;
800         spec->adc_nids = preset->adc_nids;
801         spec->capsrc_nids = preset->capsrc_nids;
802         spec->dig_in_nid = preset->dig_in_nid;
803
804         spec->unsol_event = preset->unsol_event;
805         spec->init_hook = preset->init_hook;
806 #ifdef CONFIG_SND_HDA_POWER_SAVE
807         spec->loopback.amplist = preset->loopbacks;
808 #endif
809 }
810
811 /* Enable GPIO mask and set output */
812 static struct hda_verb alc_gpio1_init_verbs[] = {
813         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
814         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
815         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
816         { }
817 };
818
819 static struct hda_verb alc_gpio2_init_verbs[] = {
820         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
821         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
822         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
823         { }
824 };
825
826 static struct hda_verb alc_gpio3_init_verbs[] = {
827         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
828         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
829         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
830         { }
831 };
832
833 /*
834  * Fix hardware PLL issue
835  * On some codecs, the analog PLL gating control must be off while
836  * the default value is 1.
837  */
838 static void alc_fix_pll(struct hda_codec *codec)
839 {
840         struct alc_spec *spec = codec->spec;
841         unsigned int val;
842
843         if (!spec->pll_nid)
844                 return;
845         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
846                             spec->pll_coef_idx);
847         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
848                                  AC_VERB_GET_PROC_COEF, 0);
849         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
850                             spec->pll_coef_idx);
851         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
852                             val & ~(1 << spec->pll_coef_bit));
853 }
854
855 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
856                              unsigned int coef_idx, unsigned int coef_bit)
857 {
858         struct alc_spec *spec = codec->spec;
859         spec->pll_nid = nid;
860         spec->pll_coef_idx = coef_idx;
861         spec->pll_coef_bit = coef_bit;
862         alc_fix_pll(codec);
863 }
864
865 static void alc_sku_automute(struct hda_codec *codec)
866 {
867         struct alc_spec *spec = codec->spec;
868         unsigned int present;
869         unsigned int hp_nid = spec->autocfg.hp_pins[0];
870         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
871
872         /* need to execute and sync at first */
873         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
874         present = snd_hda_codec_read(codec, hp_nid, 0,
875                                      AC_VERB_GET_PIN_SENSE, 0);
876         spec->jack_present = (present & 0x80000000) != 0;
877         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
878                             spec->jack_present ? 0 : PIN_OUT);
879 }
880
881 #if 0 /* it's broken in some acses -- temporarily disabled */
882 static void alc_mic_automute(struct hda_codec *codec)
883 {
884         struct alc_spec *spec = codec->spec;
885         unsigned int present;
886         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
887         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
888         unsigned int mix_nid = spec->capsrc_nids[0];
889         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
890
891         capsrc_idx_mic = mic_nid - 0x18;
892         capsrc_idx_fmic = fmic_nid - 0x18;
893         present = snd_hda_codec_read(codec, mic_nid, 0,
894                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
895         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
896                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
897         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
898                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
899         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
900                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
901 }
902 #else
903 #define alc_mic_automute(codec) /* NOP */
904 #endif /* disabled */
905
906 /* unsolicited event for HP jack sensing */
907 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
908 {
909         if (codec->vendor_id == 0x10ec0880)
910                 res >>= 28;
911         else
912                 res >>= 26;
913         if (res == ALC880_HP_EVENT)
914                 alc_sku_automute(codec);
915
916         if (res == ALC880_MIC_EVENT)
917                 alc_mic_automute(codec);
918 }
919
920 static void alc_inithook(struct hda_codec *codec)
921 {
922         alc_sku_automute(codec);
923         alc_mic_automute(codec);
924 }
925
926 /* additional initialization for ALC888 variants */
927 static void alc888_coef_init(struct hda_codec *codec)
928 {
929         unsigned int tmp;
930
931         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
932         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
933         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
934         if ((tmp & 0xf0) == 2)
935                 /* alc888S-VC */
936                 snd_hda_codec_read(codec, 0x20, 0,
937                                    AC_VERB_SET_PROC_COEF, 0x830);
938          else
939                  /* alc888-VB */
940                  snd_hda_codec_read(codec, 0x20, 0,
941                                     AC_VERB_SET_PROC_COEF, 0x3030);
942 }
943
944 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
945  *      31 ~ 16 :       Manufacture ID
946  *      15 ~ 8  :       SKU ID
947  *      7  ~ 0  :       Assembly ID
948  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
949  */
950 static void alc_subsystem_id(struct hda_codec *codec,
951                              unsigned int porta, unsigned int porte,
952                              unsigned int portd)
953 {
954         unsigned int ass, tmp, i;
955         unsigned nid;
956         struct alc_spec *spec = codec->spec;
957
958         ass = codec->subsystem_id & 0xffff;
959         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
960                 goto do_sku;
961
962         /*
963          * 31~30        : port conetcivity
964          * 29~21        : reserve
965          * 20           : PCBEEP input
966          * 19~16        : Check sum (15:1)
967          * 15~1         : Custom
968          * 0            : override
969         */
970         nid = 0x1d;
971         if (codec->vendor_id == 0x10ec0260)
972                 nid = 0x17;
973         ass = snd_hda_codec_read(codec, nid, 0,
974                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
975         if (!(ass & 1) && !(ass & 0x100000))
976                 return;
977         if ((ass >> 30) != 1)   /* no physical connection */
978                 return;
979
980         /* check sum */
981         tmp = 0;
982         for (i = 1; i < 16; i++) {
983                 if ((ass >> i) & 1)
984                         tmp++;
985         }
986         if (((ass >> 16) & 0xf) != tmp)
987                 return;
988 do_sku:
989         /*
990          * 0 : override
991          * 1 :  Swap Jack
992          * 2 : 0 --> Desktop, 1 --> Laptop
993          * 3~5 : External Amplifier control
994          * 7~6 : Reserved
995         */
996         tmp = (ass & 0x38) >> 3;        /* external Amp control */
997         switch (tmp) {
998         case 1:
999                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1000                 break;
1001         case 3:
1002                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1003                 break;
1004         case 7:
1005                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1006                 break;
1007         case 5: /* set EAPD output high */
1008                 switch (codec->vendor_id) {
1009                 case 0x10ec0260:
1010                         snd_hda_codec_write(codec, 0x0f, 0,
1011                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1012                         snd_hda_codec_write(codec, 0x10, 0,
1013                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1014                         break;
1015                 case 0x10ec0262:
1016                 case 0x10ec0267:
1017                 case 0x10ec0268:
1018                 case 0x10ec0269:
1019                 case 0x10ec0660:
1020                 case 0x10ec0662:
1021                 case 0x10ec0663:
1022                 case 0x10ec0862:
1023                 case 0x10ec0889:
1024                         snd_hda_codec_write(codec, 0x14, 0,
1025                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1026                         snd_hda_codec_write(codec, 0x15, 0,
1027                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1028                         break;
1029                 }
1030                 switch (codec->vendor_id) {
1031                 case 0x10ec0260:
1032                         snd_hda_codec_write(codec, 0x1a, 0,
1033                                             AC_VERB_SET_COEF_INDEX, 7);
1034                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1035                                                  AC_VERB_GET_PROC_COEF, 0);
1036                         snd_hda_codec_write(codec, 0x1a, 0,
1037                                             AC_VERB_SET_COEF_INDEX, 7);
1038                         snd_hda_codec_write(codec, 0x1a, 0,
1039                                             AC_VERB_SET_PROC_COEF,
1040                                             tmp | 0x2010);
1041                         break;
1042                 case 0x10ec0262:
1043                 case 0x10ec0880:
1044                 case 0x10ec0882:
1045                 case 0x10ec0883:
1046                 case 0x10ec0885:
1047                 case 0x10ec0889:
1048                         snd_hda_codec_write(codec, 0x20, 0,
1049                                             AC_VERB_SET_COEF_INDEX, 7);
1050                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1051                                                  AC_VERB_GET_PROC_COEF, 0);
1052                         snd_hda_codec_write(codec, 0x20, 0,
1053                                             AC_VERB_SET_COEF_INDEX, 7);
1054                         snd_hda_codec_write(codec, 0x20, 0,
1055                                             AC_VERB_SET_PROC_COEF,
1056                                             tmp | 0x2010);
1057                         break;
1058                 case 0x10ec0888:
1059                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1060                         break;
1061                 case 0x10ec0267:
1062                 case 0x10ec0268:
1063                         snd_hda_codec_write(codec, 0x20, 0,
1064                                             AC_VERB_SET_COEF_INDEX, 7);
1065                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1066                                                  AC_VERB_GET_PROC_COEF, 0);
1067                         snd_hda_codec_write(codec, 0x20, 0,
1068                                             AC_VERB_SET_COEF_INDEX, 7);
1069                         snd_hda_codec_write(codec, 0x20, 0,
1070                                             AC_VERB_SET_PROC_COEF,
1071                                             tmp | 0x3000);
1072                         break;
1073                 }
1074         default:
1075                 break;
1076         }
1077
1078         /* is laptop or Desktop and enable the function "Mute internal speaker
1079          * when the external headphone out jack is plugged"
1080          */
1081         if (!(ass & 0x8000))
1082                 return;
1083         /*
1084          * 10~8 : Jack location
1085          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1086          * 14~13: Resvered
1087          * 15   : 1 --> enable the function "Mute internal speaker
1088          *              when the external headphone out jack is plugged"
1089          */
1090         if (!spec->autocfg.speaker_pins[0]) {
1091                 if (spec->autocfg.line_out_pins[0])
1092                         spec->autocfg.speaker_pins[0] =
1093                                 spec->autocfg.line_out_pins[0];
1094                 else
1095                         return;
1096         }
1097
1098         if (!spec->autocfg.hp_pins[0]) {
1099                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1100                 if (tmp == 0)
1101                         spec->autocfg.hp_pins[0] = porta;
1102                 else if (tmp == 1)
1103                         spec->autocfg.hp_pins[0] = porte;
1104                 else if (tmp == 2)
1105                         spec->autocfg.hp_pins[0] = portd;
1106                 else
1107                         return;
1108         }
1109         if (spec->autocfg.hp_pins[0])
1110                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1111                         AC_VERB_SET_UNSOLICITED_ENABLE,
1112                         AC_USRSP_EN | ALC880_HP_EVENT);
1113
1114 #if 0 /* it's broken in some acses -- temporarily disabled */
1115         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1116                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1117                 snd_hda_codec_write(codec,
1118                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1119                         AC_VERB_SET_UNSOLICITED_ENABLE,
1120                         AC_USRSP_EN | ALC880_MIC_EVENT);
1121 #endif /* disabled */
1122
1123         spec->unsol_event = alc_sku_unsol_event;
1124 }
1125
1126 /*
1127  * Fix-up pin default configurations
1128  */
1129
1130 struct alc_pincfg {
1131         hda_nid_t nid;
1132         u32 val;
1133 };
1134
1135 static void alc_fix_pincfg(struct hda_codec *codec,
1136                            const struct snd_pci_quirk *quirk,
1137                            const struct alc_pincfg **pinfix)
1138 {
1139         const struct alc_pincfg *cfg;
1140
1141         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1142         if (!quirk)
1143                 return;
1144
1145         cfg = pinfix[quirk->value];
1146         for (; cfg->nid; cfg++) {
1147                 int i;
1148                 u32 val = cfg->val;
1149                 for (i = 0; i < 4; i++) {
1150                         snd_hda_codec_write(codec, cfg->nid, 0,
1151                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1152                                     val & 0xff);
1153                         val >>= 8;
1154                 }
1155         }
1156 }
1157
1158 /*
1159  * ALC888
1160  */
1161
1162 /*
1163  * 2ch mode
1164  */
1165 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1166 /* Mic-in jack as mic in */
1167         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1168         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1169 /* Line-in jack as Line in */
1170         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1171         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1172 /* Line-Out as Front */
1173         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1174         { } /* end */
1175 };
1176
1177 /*
1178  * 4ch mode
1179  */
1180 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1181 /* Mic-in jack as mic in */
1182         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1183         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1184 /* Line-in jack as Surround */
1185         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1186         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1187 /* Line-Out as Front */
1188         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1189         { } /* end */
1190 };
1191
1192 /*
1193  * 6ch mode
1194  */
1195 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1196 /* Mic-in jack as CLFE */
1197         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1198         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1199 /* Line-in jack as Surround */
1200         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1201         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1202 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1203         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1204         { } /* end */
1205 };
1206
1207 /*
1208  * 8ch mode
1209  */
1210 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1211 /* Mic-in jack as CLFE */
1212         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1213         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1214 /* Line-in jack as Surround */
1215         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1216         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1217 /* Line-Out as Side */
1218         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1219         { } /* end */
1220 };
1221
1222 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1223         { 2, alc888_4ST_ch2_intel_init },
1224         { 4, alc888_4ST_ch4_intel_init },
1225         { 6, alc888_4ST_ch6_intel_init },
1226         { 8, alc888_4ST_ch8_intel_init },
1227 };
1228
1229 /*
1230  * ALC888 Fujitsu Siemens Amillo xa3530
1231  */
1232
1233 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1234 /* Front Mic: set to PIN_IN (empty by default) */
1235         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1236 /* Connect Internal HP to Front */
1237         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1238         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1239         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1240 /* Connect Bass HP to Front */
1241         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1242         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1243         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1244 /* Connect Line-Out side jack (SPDIF) to Side */
1245         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1246         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1247         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1248 /* Connect Mic jack to CLFE */
1249         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1250         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1251         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1252 /* Connect Line-in jack to Surround */
1253         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1254         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1255         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1256 /* Connect HP out jack to Front */
1257         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1258         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1259         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1260 /* Enable unsolicited event for HP jack and Line-out jack */
1261         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1262         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1263         {}
1264 };
1265
1266 static void alc888_fujitsu_xa3530_automute(struct hda_codec *codec)
1267 {
1268         unsigned int present;
1269         unsigned int bits;
1270         /* Line out presence */
1271         present = snd_hda_codec_read(codec, 0x17, 0,
1272                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1273         /* HP out presence */
1274         present = present || snd_hda_codec_read(codec, 0x1b, 0,
1275                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1276         bits = present ? HDA_AMP_MUTE : 0;
1277         /* Toggle internal speakers muting */
1278         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1279                                  HDA_AMP_MUTE, bits);
1280         /* Toggle internal bass muting */
1281         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1282                                  HDA_AMP_MUTE, bits);
1283 }
1284
1285 static void alc888_fujitsu_xa3530_unsol_event(struct hda_codec *codec,
1286                 unsigned int res)
1287 {
1288         if (res >> 26 == ALC880_HP_EVENT)
1289                 alc888_fujitsu_xa3530_automute(codec);
1290 }
1291
1292
1293 /*
1294  * ALC888 Acer Aspire 4930G model
1295  */
1296
1297 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1298 /* Front Mic: set to PIN_IN (empty by default) */
1299         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1300 /* Unselect Front Mic by default in input mixer 3 */
1301         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1302 /* Enable unsolicited event for HP jack */
1303         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1304 /* Connect Internal HP to front */
1305         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1306         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1307         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1308 /* Connect HP out to front */
1309         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1310         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1311         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1312         { }
1313 };
1314
1315 static struct hda_input_mux alc888_2_capture_sources[2] = {
1316         /* Front mic only available on one ADC */
1317         {
1318                 .num_items = 4,
1319                 .items = {
1320                         { "Mic", 0x0 },
1321                         { "Line", 0x2 },
1322                         { "CD", 0x4 },
1323                         { "Front Mic", 0xb },
1324                 },
1325         },
1326         {
1327                 .num_items = 3,
1328                 .items = {
1329                         { "Mic", 0x0 },
1330                         { "Line", 0x2 },
1331                         { "CD", 0x4 },
1332                 },
1333         }
1334 };
1335
1336 static struct snd_kcontrol_new alc888_base_mixer[] = {
1337         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1338         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1339         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1340         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1341         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1342                 HDA_OUTPUT),
1343         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1344         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1345         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1346         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1347         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1348         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1349         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1350         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1351         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1352         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1353         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1354         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1355         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1356         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1357         { } /* end */
1358 };
1359
1360 static void alc888_acer_aspire_4930g_automute(struct hda_codec *codec)
1361 {
1362         unsigned int present;
1363         unsigned int bits;
1364         present = snd_hda_codec_read(codec, 0x15, 0,
1365                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1366         bits = present ? HDA_AMP_MUTE : 0;
1367         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1368                                  HDA_AMP_MUTE, bits);
1369 }
1370
1371 static void alc888_acer_aspire_4930g_unsol_event(struct hda_codec *codec,
1372                 unsigned int res)
1373 {
1374         if (res >> 26 == ALC880_HP_EVENT)
1375                 alc888_acer_aspire_4930g_automute(codec);
1376 }
1377
1378 /*
1379  * ALC880 3-stack model
1380  *
1381  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1382  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1383  *                 F-Mic = 0x1b, HP = 0x19
1384  */
1385
1386 static hda_nid_t alc880_dac_nids[4] = {
1387         /* front, rear, clfe, rear_surr */
1388         0x02, 0x05, 0x04, 0x03
1389 };
1390
1391 static hda_nid_t alc880_adc_nids[3] = {
1392         /* ADC0-2 */
1393         0x07, 0x08, 0x09,
1394 };
1395
1396 /* The datasheet says the node 0x07 is connected from inputs,
1397  * but it shows zero connection in the real implementation on some devices.
1398  * Note: this is a 915GAV bug, fixed on 915GLV
1399  */
1400 static hda_nid_t alc880_adc_nids_alt[2] = {
1401         /* ADC1-2 */
1402         0x08, 0x09,
1403 };
1404
1405 #define ALC880_DIGOUT_NID       0x06
1406 #define ALC880_DIGIN_NID        0x0a
1407
1408 static struct hda_input_mux alc880_capture_source = {
1409         .num_items = 4,
1410         .items = {
1411                 { "Mic", 0x0 },
1412                 { "Front Mic", 0x3 },
1413                 { "Line", 0x2 },
1414                 { "CD", 0x4 },
1415         },
1416 };
1417
1418 /* channel source setting (2/6 channel selection for 3-stack) */
1419 /* 2ch mode */
1420 static struct hda_verb alc880_threestack_ch2_init[] = {
1421         /* set line-in to input, mute it */
1422         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1423         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1424         /* set mic-in to input vref 80%, mute it */
1425         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1426         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1427         { } /* end */
1428 };
1429
1430 /* 6ch mode */
1431 static struct hda_verb alc880_threestack_ch6_init[] = {
1432         /* set line-in to output, unmute it */
1433         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1434         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1435         /* set mic-in to output, unmute it */
1436         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1437         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1438         { } /* end */
1439 };
1440
1441 static struct hda_channel_mode alc880_threestack_modes[2] = {
1442         { 2, alc880_threestack_ch2_init },
1443         { 6, alc880_threestack_ch6_init },
1444 };
1445
1446 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1447         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1448         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1449         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1450         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1451         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1452         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1453         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1454         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1455         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1456         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1457         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1458         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1459         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1460         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1461         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1462         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1463         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1464         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1465         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1466         {
1467                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1468                 .name = "Channel Mode",
1469                 .info = alc_ch_mode_info,
1470                 .get = alc_ch_mode_get,
1471                 .put = alc_ch_mode_put,
1472         },
1473         { } /* end */
1474 };
1475
1476 /* capture mixer elements */
1477 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1478                             struct snd_ctl_elem_info *uinfo)
1479 {
1480         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1481         struct alc_spec *spec = codec->spec;
1482         int err;
1483
1484         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1485         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1486                                                       HDA_INPUT);
1487         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1488         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1489         return err;
1490 }
1491
1492 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1493                            unsigned int size, unsigned int __user *tlv)
1494 {
1495         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1496         struct alc_spec *spec = codec->spec;
1497         int err;
1498
1499         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1500         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1501                                                       HDA_INPUT);
1502         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1503         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1504         return err;
1505 }
1506
1507 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1508                              struct snd_ctl_elem_value *ucontrol);
1509
1510 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1511                                  struct snd_ctl_elem_value *ucontrol,
1512                                  getput_call_t func)
1513 {
1514         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1515         struct alc_spec *spec = codec->spec;
1516         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1517         int err;
1518
1519         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1520         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1521                                                       3, 0, HDA_INPUT);
1522         err = func(kcontrol, ucontrol);
1523         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1524         return err;
1525 }
1526
1527 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1528                            struct snd_ctl_elem_value *ucontrol)
1529 {
1530         return alc_cap_getput_caller(kcontrol, ucontrol,
1531                                      snd_hda_mixer_amp_volume_get);
1532 }
1533
1534 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1535                            struct snd_ctl_elem_value *ucontrol)
1536 {
1537         return alc_cap_getput_caller(kcontrol, ucontrol,
1538                                      snd_hda_mixer_amp_volume_put);
1539 }
1540
1541 /* capture mixer elements */
1542 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1543
1544 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1545                           struct snd_ctl_elem_value *ucontrol)
1546 {
1547         return alc_cap_getput_caller(kcontrol, ucontrol,
1548                                      snd_hda_mixer_amp_switch_get);
1549 }
1550
1551 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1552                           struct snd_ctl_elem_value *ucontrol)
1553 {
1554         return alc_cap_getput_caller(kcontrol, ucontrol,
1555                                      snd_hda_mixer_amp_switch_put);
1556 }
1557
1558 #define DEFINE_CAPMIX(num) \
1559 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1560         { \
1561                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1562                 .name = "Capture Switch", \
1563                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1564                 .count = num, \
1565                 .info = alc_cap_sw_info, \
1566                 .get = alc_cap_sw_get, \
1567                 .put = alc_cap_sw_put, \
1568         }, \
1569         { \
1570                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1571                 .name = "Capture Volume", \
1572                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1573                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1574                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1575                 .count = num, \
1576                 .info = alc_cap_vol_info, \
1577                 .get = alc_cap_vol_get, \
1578                 .put = alc_cap_vol_put, \
1579                 .tlv = { .c = alc_cap_vol_tlv }, \
1580         }, \
1581         { \
1582                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1583                 /* .name = "Capture Source", */ \
1584                 .name = "Input Source", \
1585                 .count = num, \
1586                 .info = alc_mux_enum_info, \
1587                 .get = alc_mux_enum_get, \
1588                 .put = alc_mux_enum_put, \
1589         }, \
1590         { } /* end */ \
1591 }
1592
1593 /* up to three ADCs */
1594 DEFINE_CAPMIX(1);
1595 DEFINE_CAPMIX(2);
1596 DEFINE_CAPMIX(3);
1597
1598
1599 /*
1600  * ALC880 5-stack model
1601  *
1602  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1603  *      Side = 0x02 (0xd)
1604  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1605  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1606  */
1607
1608 /* additional mixers to alc880_three_stack_mixer */
1609 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1610         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1611         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1612         { } /* end */
1613 };
1614
1615 /* channel source setting (6/8 channel selection for 5-stack) */
1616 /* 6ch mode */
1617 static struct hda_verb alc880_fivestack_ch6_init[] = {
1618         /* set line-in to input, mute it */
1619         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1620         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1621         { } /* end */
1622 };
1623
1624 /* 8ch mode */
1625 static struct hda_verb alc880_fivestack_ch8_init[] = {
1626         /* set line-in to output, unmute it */
1627         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1628         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1629         { } /* end */
1630 };
1631
1632 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1633         { 6, alc880_fivestack_ch6_init },
1634         { 8, alc880_fivestack_ch8_init },
1635 };
1636
1637
1638 /*
1639  * ALC880 6-stack model
1640  *
1641  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1642  *      Side = 0x05 (0x0f)
1643  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1644  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1645  */
1646
1647 static hda_nid_t alc880_6st_dac_nids[4] = {
1648         /* front, rear, clfe, rear_surr */
1649         0x02, 0x03, 0x04, 0x05
1650 };
1651
1652 static struct hda_input_mux alc880_6stack_capture_source = {
1653         .num_items = 4,
1654         .items = {
1655                 { "Mic", 0x0 },
1656                 { "Front Mic", 0x1 },
1657                 { "Line", 0x2 },
1658                 { "CD", 0x4 },
1659         },
1660 };
1661
1662 /* fixed 8-channels */
1663 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1664         { 8, NULL },
1665 };
1666
1667 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1668         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1669         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1670         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1671         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1672         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1673         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1674         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1675         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1676         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1677         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1678         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1679         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1680         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1681         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1682         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1683         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1684         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1685         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1686         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1687         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1688         {
1689                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1690                 .name = "Channel Mode",
1691                 .info = alc_ch_mode_info,
1692                 .get = alc_ch_mode_get,
1693                 .put = alc_ch_mode_put,
1694         },
1695         { } /* end */
1696 };
1697
1698
1699 /*
1700  * ALC880 W810 model
1701  *
1702  * W810 has rear IO for:
1703  * Front (DAC 02)
1704  * Surround (DAC 03)
1705  * Center/LFE (DAC 04)
1706  * Digital out (06)
1707  *
1708  * The system also has a pair of internal speakers, and a headphone jack.
1709  * These are both connected to Line2 on the codec, hence to DAC 02.
1710  *
1711  * There is a variable resistor to control the speaker or headphone
1712  * volume. This is a hardware-only device without a software API.
1713  *
1714  * Plugging headphones in will disable the internal speakers. This is
1715  * implemented in hardware, not via the driver using jack sense. In
1716  * a similar fashion, plugging into the rear socket marked "front" will
1717  * disable both the speakers and headphones.
1718  *
1719  * For input, there's a microphone jack, and an "audio in" jack.
1720  * These may not do anything useful with this driver yet, because I
1721  * haven't setup any initialization verbs for these yet...
1722  */
1723
1724 static hda_nid_t alc880_w810_dac_nids[3] = {
1725         /* front, rear/surround, clfe */
1726         0x02, 0x03, 0x04
1727 };
1728
1729 /* fixed 6 channels */
1730 static struct hda_channel_mode alc880_w810_modes[1] = {
1731         { 6, NULL }
1732 };
1733
1734 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1735 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1736         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1737         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1738         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1739         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1740         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1741         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1742         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1743         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1744         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1745         { } /* end */
1746 };
1747
1748
1749 /*
1750  * Z710V model
1751  *
1752  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1753  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1754  *                 Line = 0x1a
1755  */
1756
1757 static hda_nid_t alc880_z71v_dac_nids[1] = {
1758         0x02
1759 };
1760 #define ALC880_Z71V_HP_DAC      0x03
1761
1762 /* fixed 2 channels */
1763 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1764         { 2, NULL }
1765 };
1766
1767 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1768         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1769         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1770         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1771         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1772         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1773         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1774         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1775         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1776         { } /* end */
1777 };
1778
1779
1780 /*
1781  * ALC880 F1734 model
1782  *
1783  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1784  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1785  */
1786
1787 static hda_nid_t alc880_f1734_dac_nids[1] = {
1788         0x03
1789 };
1790 #define ALC880_F1734_HP_DAC     0x02
1791
1792 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1793         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1794         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1795         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1796         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1797         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1798         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1799         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1800         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1801         { } /* end */
1802 };
1803
1804 static struct hda_input_mux alc880_f1734_capture_source = {
1805         .num_items = 2,
1806         .items = {
1807                 { "Mic", 0x1 },
1808                 { "CD", 0x4 },
1809         },
1810 };
1811
1812
1813 /*
1814  * ALC880 ASUS model
1815  *
1816  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1817  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1818  *  Mic = 0x18, Line = 0x1a
1819  */
1820
1821 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1822 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1823
1824 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1825         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1826         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1827         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1828         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1829         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1830         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1831         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1832         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1833         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1834         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1835         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1836         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1837         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1838         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1839         {
1840                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1841                 .name = "Channel Mode",
1842                 .info = alc_ch_mode_info,
1843                 .get = alc_ch_mode_get,
1844                 .put = alc_ch_mode_put,
1845         },
1846         { } /* end */
1847 };
1848
1849 /*
1850  * ALC880 ASUS W1V model
1851  *
1852  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1853  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1854  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1855  */
1856
1857 /* additional mixers to alc880_asus_mixer */
1858 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1859         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1860         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1861         { } /* end */
1862 };
1863
1864 /* additional mixers to alc880_asus_mixer */
1865 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1866         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1867         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1868         { } /* end */
1869 };
1870
1871 /* TCL S700 */
1872 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1873         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1874         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1875         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1876         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1877         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1878         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1879         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1880         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1881         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1882         { } /* end */
1883 };
1884
1885 /* Uniwill */
1886 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1887         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1888         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1889         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1890         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1891         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1892         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1893         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1894         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1895         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1896         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1897         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1898         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1899         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1900         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1901         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1902         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1903         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1904         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1905         {
1906                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1907                 .name = "Channel Mode",
1908                 .info = alc_ch_mode_info,
1909                 .get = alc_ch_mode_get,
1910                 .put = alc_ch_mode_put,
1911         },
1912         { } /* end */
1913 };
1914
1915 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1916         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1917         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1918         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1919         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1920         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1921         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1922         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1923         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1924         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1925         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1926         { } /* end */
1927 };
1928
1929 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1930         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1931         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1932         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1933         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1934         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1935         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1936         { } /* end */
1937 };
1938
1939 /*
1940  * virtual master controls
1941  */
1942
1943 /*
1944  * slave controls for virtual master
1945  */
1946 static const char *alc_slave_vols[] = {
1947         "Front Playback Volume",
1948         "Surround Playback Volume",
1949         "Center Playback Volume",
1950         "LFE Playback Volume",
1951         "Side Playback Volume",
1952         "Headphone Playback Volume",
1953         "Speaker Playback Volume",
1954         "Mono Playback Volume",
1955         "Line-Out Playback Volume",
1956         "PCM Playback Volume",
1957         NULL,
1958 };
1959
1960 static const char *alc_slave_sws[] = {
1961         "Front Playback Switch",
1962         "Surround Playback Switch",
1963         "Center Playback Switch",
1964         "LFE Playback Switch",
1965         "Side Playback Switch",
1966         "Headphone Playback Switch",
1967         "Speaker Playback Switch",
1968         "Mono Playback Switch",
1969         "IEC958 Playback Switch",
1970         NULL,
1971 };
1972
1973 /*
1974  * build control elements
1975  */
1976
1977 static void alc_free_kctls(struct hda_codec *codec);
1978
1979 static int alc_build_controls(struct hda_codec *codec)
1980 {
1981         struct alc_spec *spec = codec->spec;
1982         int err;
1983         int i;
1984
1985         for (i = 0; i < spec->num_mixers; i++) {
1986                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1987                 if (err < 0)
1988                         return err;
1989         }
1990         if (spec->cap_mixer) {
1991                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1992                 if (err < 0)
1993                         return err;
1994         }
1995         if (spec->multiout.dig_out_nid) {
1996                 err = snd_hda_create_spdif_out_ctls(codec,
1997                                                     spec->multiout.dig_out_nid);
1998                 if (err < 0)
1999                         return err;
2000                 err = snd_hda_create_spdif_share_sw(codec,
2001                                                     &spec->multiout);
2002                 if (err < 0)
2003                         return err;
2004                 spec->multiout.share_spdif = 1;
2005         }
2006         if (spec->dig_in_nid) {
2007                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2008                 if (err < 0)
2009                         return err;
2010         }
2011
2012         /* if we have no master control, let's create it */
2013         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2014                 unsigned int vmaster_tlv[4];
2015                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2016                                         HDA_OUTPUT, vmaster_tlv);
2017                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2018                                           vmaster_tlv, alc_slave_vols);
2019                 if (err < 0)
2020                         return err;
2021         }
2022         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2023                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2024                                           NULL, alc_slave_sws);
2025                 if (err < 0)
2026                         return err;
2027         }
2028
2029         alc_free_kctls(codec); /* no longer needed */
2030         return 0;
2031 }
2032
2033
2034 /*
2035  * initialize the codec volumes, etc
2036  */
2037
2038 /*
2039  * generic initialization of ADC, input mixers and output mixers
2040  */
2041 static struct hda_verb alc880_volume_init_verbs[] = {
2042         /*
2043          * Unmute ADC0-2 and set the default input to mic-in
2044          */
2045         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2046         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2047         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2048         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2049         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2050         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2051
2052         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2053          * mixer widget
2054          * Note: PASD motherboards uses the Line In 2 as the input for front
2055          * panel mic (mic 2)
2056          */
2057         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2058         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2059         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2060         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2061         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2062         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2063         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2064         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2065
2066         /*
2067          * Set up output mixers (0x0c - 0x0f)
2068          */
2069         /* set vol=0 to output mixers */
2070         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2071         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2072         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2073         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2074         /* set up input amps for analog loopback */
2075         /* Amp Indices: DAC = 0, mixer = 1 */
2076         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2077         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2078         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2079         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2080         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2081         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2082         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2083         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2084
2085         { }
2086 };
2087
2088 /*
2089  * 3-stack pin configuration:
2090  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2091  */
2092 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2093         /*
2094          * preset connection lists of input pins
2095          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2096          */
2097         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2098         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2099         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2100
2101         /*
2102          * Set pin mode and muting
2103          */
2104         /* set front pin widgets 0x14 for output */
2105         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2106         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2107         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2108         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2109         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2110         /* Mic2 (as headphone out) for HP output */
2111         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2112         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2113         /* Line In pin widget for input */
2114         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2115         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2116         /* Line2 (as front mic) pin widget for input and vref at 80% */
2117         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2118         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2119         /* CD pin widget for input */
2120         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2121
2122         { }
2123 };
2124
2125 /*
2126  * 5-stack pin configuration:
2127  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2128  * line-in/side = 0x1a, f-mic = 0x1b
2129  */
2130 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2131         /*
2132          * preset connection lists of input pins
2133          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2134          */
2135         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2136         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2137
2138         /*
2139          * Set pin mode and muting
2140          */
2141         /* set pin widgets 0x14-0x17 for output */
2142         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2143         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2144         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2145         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2146         /* unmute pins for output (no gain on this amp) */
2147         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2148         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2149         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2150         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2151
2152         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2153         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2154         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2155         /* Mic2 (as headphone out) for HP output */
2156         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2157         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2158         /* Line In pin widget for input */
2159         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2160         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2161         /* Line2 (as front mic) pin widget for input and vref at 80% */
2162         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2163         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2164         /* CD pin widget for input */
2165         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2166
2167         { }
2168 };
2169
2170 /*
2171  * W810 pin configuration:
2172  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2173  */
2174 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2175         /* hphone/speaker input selector: front DAC */
2176         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2177
2178         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2179         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2180         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2181         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2182         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2183         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2184
2185         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2186         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2187
2188         { }
2189 };
2190
2191 /*
2192  * Z71V pin configuration:
2193  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2194  */
2195 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2196         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2197         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2198         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2199         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2200
2201         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2202         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2203         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2204         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2205
2206         { }
2207 };
2208
2209 /*
2210  * 6-stack pin configuration:
2211  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2212  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2213  */
2214 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2215         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2216
2217         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2218         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2219         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2220         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2221         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2222         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2223         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2224         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2225
2226         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2227         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2228         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2229         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2230         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2231         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2232         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2233         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2234         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2235
2236         { }
2237 };
2238
2239 /*
2240  * Uniwill pin configuration:
2241  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2242  * line = 0x1a
2243  */
2244 static struct hda_verb alc880_uniwill_init_verbs[] = {
2245         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2246
2247         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2248         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2249         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2250         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2251         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2252         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2253         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2254         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2255         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2256         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2257         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2258         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2259         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2260         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2261
2262         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2263         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2264         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2265         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2266         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2267         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2268         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2269         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2270         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2271
2272         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2273         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2274
2275         { }
2276 };
2277
2278 /*
2279 * Uniwill P53
2280 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2281  */
2282 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2283         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2284
2285         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2286         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2287         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2288         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2289         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2290         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2291         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2292         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2293         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2294         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2295         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2296         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2297
2298         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2299         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2300         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2301         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2302         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2303         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2304
2305         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2306         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2307
2308         { }
2309 };
2310
2311 static struct hda_verb alc880_beep_init_verbs[] = {
2312         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2313         { }
2314 };
2315
2316 /* toggle speaker-output according to the hp-jack state */
2317 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
2318 {
2319         unsigned int present;
2320         unsigned char bits;
2321
2322         present = snd_hda_codec_read(codec, 0x14, 0,
2323                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2324         bits = present ? HDA_AMP_MUTE : 0;
2325         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
2326                                  HDA_AMP_MUTE, bits);
2327         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
2328                                  HDA_AMP_MUTE, bits);
2329 }
2330
2331 /* auto-toggle front mic */
2332 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2333 {
2334         unsigned int present;
2335         unsigned char bits;
2336
2337         present = snd_hda_codec_read(codec, 0x18, 0,
2338                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2339         bits = present ? HDA_AMP_MUTE : 0;
2340         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2341 }
2342
2343 static void alc880_uniwill_automute(struct hda_codec *codec)
2344 {
2345         alc880_uniwill_hp_automute(codec);
2346         alc880_uniwill_mic_automute(codec);
2347 }
2348
2349 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2350                                        unsigned int res)
2351 {
2352         /* Looks like the unsol event is incompatible with the standard
2353          * definition.  4bit tag is placed at 28 bit!
2354          */
2355         switch (res >> 28) {
2356         case ALC880_HP_EVENT:
2357                 alc880_uniwill_hp_automute(codec);
2358                 break;
2359         case ALC880_MIC_EVENT:
2360                 alc880_uniwill_mic_automute(codec);
2361                 break;
2362         }
2363 }
2364
2365 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2366 {
2367         unsigned int present;
2368         unsigned char bits;
2369
2370         present = snd_hda_codec_read(codec, 0x14, 0,
2371                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2372         bits = present ? HDA_AMP_MUTE : 0;
2373         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2374 }
2375
2376 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2377 {
2378         unsigned int present;
2379
2380         present = snd_hda_codec_read(codec, 0x21, 0,
2381                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2382         present &= HDA_AMP_VOLMASK;
2383         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2384                                  HDA_AMP_VOLMASK, present);
2385         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2386                                  HDA_AMP_VOLMASK, present);
2387 }
2388
2389 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2390                                            unsigned int res)
2391 {
2392         /* Looks like the unsol event is incompatible with the standard
2393          * definition.  4bit tag is placed at 28 bit!
2394          */
2395         if ((res >> 28) == ALC880_HP_EVENT)
2396                 alc880_uniwill_p53_hp_automute(codec);
2397         if ((res >> 28) == ALC880_DCVOL_EVENT)
2398                 alc880_uniwill_p53_dcvol_automute(codec);
2399 }
2400
2401 /*
2402  * F1734 pin configuration:
2403  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2404  */
2405 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2406         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2407         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2408         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2409         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2410         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2411
2412         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2413         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2414         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2415         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2416
2417         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2418         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2419         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2420         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2421         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2422         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2423         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2424         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2425         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2426
2427         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2428         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2429
2430         { }
2431 };
2432
2433 /*
2434  * ASUS pin configuration:
2435  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2436  */
2437 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2438         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2439         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2440         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2441         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2442
2443         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2444         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2445         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2446         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2447         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2448         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2449         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2450         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2451
2452         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2453         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2454         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2455         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2456         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2457         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2458         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2459         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2460         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2461
2462         { }
2463 };
2464
2465 /* Enable GPIO mask and set output */
2466 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2467 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2468
2469 /* Clevo m520g init */
2470 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2471         /* headphone output */
2472         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2473         /* line-out */
2474         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2475         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2476         /* Line-in */
2477         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2478         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2479         /* CD */
2480         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2481         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2482         /* Mic1 (rear panel) */
2483         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2484         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2485         /* Mic2 (front panel) */
2486         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2487         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2488         /* headphone */
2489         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2490         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2491         /* change to EAPD mode */
2492         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2493         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2494
2495         { }
2496 };
2497
2498 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2499         /* change to EAPD mode */
2500         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2501         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2502
2503         /* Headphone output */
2504         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2505         /* Front output*/
2506         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2507         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2508
2509         /* Line In pin widget for input */
2510         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2511         /* CD pin widget for input */
2512         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2513         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2514         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2515
2516         /* change to EAPD mode */
2517         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2518         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2519
2520         { }
2521 };
2522
2523 /*
2524  * LG m1 express dual
2525  *
2526  * Pin assignment:
2527  *   Rear Line-In/Out (blue): 0x14
2528  *   Build-in Mic-In: 0x15
2529  *   Speaker-out: 0x17
2530  *   HP-Out (green): 0x1b
2531  *   Mic-In/Out (red): 0x19
2532  *   SPDIF-Out: 0x1e
2533  */
2534
2535 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2536 static hda_nid_t alc880_lg_dac_nids[3] = {
2537         0x05, 0x02, 0x03
2538 };
2539
2540 /* seems analog CD is not working */
2541 static struct hda_input_mux alc880_lg_capture_source = {
2542         .num_items = 3,
2543         .items = {
2544                 { "Mic", 0x1 },
2545                 { "Line", 0x5 },
2546                 { "Internal Mic", 0x6 },
2547         },
2548 };
2549
2550 /* 2,4,6 channel modes */
2551 static struct hda_verb alc880_lg_ch2_init[] = {
2552         /* set line-in and mic-in to input */
2553         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2554         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2555         { }
2556 };
2557
2558 static struct hda_verb alc880_lg_ch4_init[] = {
2559         /* set line-in to out and mic-in to input */
2560         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2561         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2562         { }
2563 };
2564
2565 static struct hda_verb alc880_lg_ch6_init[] = {
2566         /* set line-in and mic-in to output */
2567         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2568         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2569         { }
2570 };
2571
2572 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2573         { 2, alc880_lg_ch2_init },
2574         { 4, alc880_lg_ch4_init },
2575         { 6, alc880_lg_ch6_init },
2576 };
2577
2578 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2579         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2580         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2581         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2582         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2583         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2584         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2585         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2586         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2587         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2588         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2589         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2590         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2591         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2592         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2593         {
2594                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2595                 .name = "Channel Mode",
2596                 .info = alc_ch_mode_info,
2597                 .get = alc_ch_mode_get,
2598                 .put = alc_ch_mode_put,
2599         },
2600         { } /* end */
2601 };
2602
2603 static struct hda_verb alc880_lg_init_verbs[] = {
2604         /* set capture source to mic-in */
2605         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2606         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2607         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2608         /* mute all amp mixer inputs */
2609         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2610         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2611         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2612         /* line-in to input */
2613         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2614         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2615         /* built-in mic */
2616         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2617         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2618         /* speaker-out */
2619         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2620         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2621         /* mic-in to input */
2622         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2623         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2624         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2625         /* HP-out */
2626         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2627         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2628         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2629         /* jack sense */
2630         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2631         { }
2632 };
2633
2634 /* toggle speaker-output according to the hp-jack state */
2635 static void alc880_lg_automute(struct hda_codec *codec)
2636 {
2637         unsigned int present;
2638         unsigned char bits;
2639
2640         present = snd_hda_codec_read(codec, 0x1b, 0,
2641                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2642         bits = present ? HDA_AMP_MUTE : 0;
2643         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2644                                  HDA_AMP_MUTE, bits);
2645 }
2646
2647 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2648 {
2649         /* Looks like the unsol event is incompatible with the standard
2650          * definition.  4bit tag is placed at 28 bit!
2651          */
2652         if ((res >> 28) == 0x01)
2653                 alc880_lg_automute(codec);
2654 }
2655
2656 /*
2657  * LG LW20
2658  *
2659  * Pin assignment:
2660  *   Speaker-out: 0x14
2661  *   Mic-In: 0x18
2662  *   Built-in Mic-In: 0x19
2663  *   Line-In: 0x1b
2664  *   HP-Out: 0x1a
2665  *   SPDIF-Out: 0x1e
2666  */
2667
2668 static struct hda_input_mux alc880_lg_lw_capture_source = {
2669         .num_items = 3,
2670         .items = {
2671                 { "Mic", 0x0 },
2672                 { "Internal Mic", 0x1 },
2673                 { "Line In", 0x2 },
2674         },
2675 };
2676
2677 #define alc880_lg_lw_modes alc880_threestack_modes
2678
2679 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2680         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2681         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2682         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2683         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2684         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2685         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2686         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2687         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2688         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2689         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2690         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2691         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2692         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2693         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2694         {
2695                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2696                 .name = "Channel Mode",
2697                 .info = alc_ch_mode_info,
2698                 .get = alc_ch_mode_get,
2699                 .put = alc_ch_mode_put,
2700         },
2701         { } /* end */
2702 };
2703
2704 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2705         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2706         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2707         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2708
2709         /* set capture source to mic-in */
2710         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2711         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2712         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2713         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2714         /* speaker-out */
2715         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2716         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2717         /* HP-out */
2718         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2719         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2720         /* mic-in to input */
2721         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2722         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2723         /* built-in mic */
2724         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2725         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2726         /* jack sense */
2727         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2728         { }
2729 };
2730
2731 /* toggle speaker-output according to the hp-jack state */
2732 static void alc880_lg_lw_automute(struct hda_codec *codec)
2733 {
2734         unsigned int present;
2735         unsigned char bits;
2736
2737         present = snd_hda_codec_read(codec, 0x1b, 0,
2738                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2739         bits = present ? HDA_AMP_MUTE : 0;
2740         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2741                                  HDA_AMP_MUTE, bits);
2742 }
2743
2744 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2745 {
2746         /* Looks like the unsol event is incompatible with the standard
2747          * definition.  4bit tag is placed at 28 bit!
2748          */
2749         if ((res >> 28) == 0x01)
2750                 alc880_lg_lw_automute(codec);
2751 }
2752
2753 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2754         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2755         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2756         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2757         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2758         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2759         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2760         { } /* end */
2761 };
2762
2763 static struct hda_input_mux alc880_medion_rim_capture_source = {
2764         .num_items = 2,
2765         .items = {
2766                 { "Mic", 0x0 },
2767                 { "Internal Mic", 0x1 },
2768         },
2769 };
2770
2771 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2772         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2773
2774         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2775         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2776
2777         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2778         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2779         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2780         /* Mic2 (as headphone out) for HP output */
2781         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2782         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2783         /* Internal Speaker */
2784         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2785         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2786
2787         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2788         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2789
2790         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2791         { }
2792 };
2793
2794 /* toggle speaker-output according to the hp-jack state */
2795 static void alc880_medion_rim_automute(struct hda_codec *codec)
2796 {
2797         unsigned int present;
2798         unsigned char bits;
2799
2800         present = snd_hda_codec_read(codec, 0x14, 0,
2801                                      AC_VERB_GET_PIN_SENSE, 0)
2802                 & AC_PINSENSE_PRESENCE;
2803         bits = present ? HDA_AMP_MUTE : 0;
2804         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2805                                  HDA_AMP_MUTE, bits);
2806         if (present)
2807                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2808         else
2809                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2810 }
2811
2812 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2813                                           unsigned int res)
2814 {
2815         /* Looks like the unsol event is incompatible with the standard
2816          * definition.  4bit tag is placed at 28 bit!
2817          */
2818         if ((res >> 28) == ALC880_HP_EVENT)
2819                 alc880_medion_rim_automute(codec);
2820 }
2821
2822 #ifdef CONFIG_SND_HDA_POWER_SAVE
2823 static struct hda_amp_list alc880_loopbacks[] = {
2824         { 0x0b, HDA_INPUT, 0 },
2825         { 0x0b, HDA_INPUT, 1 },
2826         { 0x0b, HDA_INPUT, 2 },
2827         { 0x0b, HDA_INPUT, 3 },
2828         { 0x0b, HDA_INPUT, 4 },
2829         { } /* end */
2830 };
2831
2832 static struct hda_amp_list alc880_lg_loopbacks[] = {
2833         { 0x0b, HDA_INPUT, 1 },
2834         { 0x0b, HDA_INPUT, 6 },
2835         { 0x0b, HDA_INPUT, 7 },
2836         { } /* end */
2837 };
2838 #endif
2839
2840 /*
2841  * Common callbacks
2842  */
2843
2844 static int alc_init(struct hda_codec *codec)
2845 {
2846         struct alc_spec *spec = codec->spec;
2847         unsigned int i;
2848
2849         alc_fix_pll(codec);
2850         if (codec->vendor_id == 0x10ec0888)
2851                 alc888_coef_init(codec);
2852
2853         for (i = 0; i < spec->num_init_verbs; i++)
2854                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2855
2856         if (spec->init_hook)
2857                 spec->init_hook(codec);
2858
2859         return 0;
2860 }
2861
2862 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2863 {
2864         struct alc_spec *spec = codec->spec;
2865
2866         if (spec->unsol_event)
2867                 spec->unsol_event(codec, res);
2868 }
2869
2870 #ifdef CONFIG_SND_HDA_POWER_SAVE
2871 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2872 {
2873         struct alc_spec *spec = codec->spec;
2874         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2875 }
2876 #endif
2877
2878 /*
2879  * Analog playback callbacks
2880  */
2881 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2882                                     struct hda_codec *codec,
2883                                     struct snd_pcm_substream *substream)
2884 {
2885         struct alc_spec *spec = codec->spec;
2886         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2887                                              hinfo);
2888 }
2889
2890 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2891                                        struct hda_codec *codec,
2892                                        unsigned int stream_tag,
2893                                        unsigned int format,
2894                                        struct snd_pcm_substream *substream)
2895 {
2896         struct alc_spec *spec = codec->spec;
2897         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2898                                                 stream_tag, format, substream);
2899 }
2900
2901 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2902                                        struct hda_codec *codec,
2903                                        struct snd_pcm_substream *substream)
2904 {
2905         struct alc_spec *spec = codec->spec;
2906         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2907 }
2908
2909 /*
2910  * Digital out
2911  */
2912 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2913                                         struct hda_codec *codec,
2914                                         struct snd_pcm_substream *substream)
2915 {
2916         struct alc_spec *spec = codec->spec;
2917         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2918 }
2919
2920 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2921                                            struct hda_codec *codec,
2922                                            unsigned int stream_tag,
2923                                            unsigned int format,
2924                                            struct snd_pcm_substream *substream)
2925 {
2926         struct alc_spec *spec = codec->spec;
2927         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2928                                              stream_tag, format, substream);
2929 }
2930
2931 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2932                                          struct hda_codec *codec,
2933                                          struct snd_pcm_substream *substream)
2934 {
2935         struct alc_spec *spec = codec->spec;
2936         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2937 }
2938
2939 /*
2940  * Analog capture
2941  */
2942 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2943                                       struct hda_codec *codec,
2944                                       unsigned int stream_tag,
2945                                       unsigned int format,
2946                                       struct snd_pcm_substream *substream)
2947 {
2948         struct alc_spec *spec = codec->spec;
2949
2950         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2951                                    stream_tag, 0, format);
2952         return 0;
2953 }
2954
2955 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2956                                       struct hda_codec *codec,
2957                                       struct snd_pcm_substream *substream)
2958 {
2959         struct alc_spec *spec = codec->spec;
2960
2961         snd_hda_codec_cleanup_stream(codec,
2962                                      spec->adc_nids[substream->number + 1]);
2963         return 0;
2964 }
2965
2966
2967 /*
2968  */
2969 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2970         .substreams = 1,
2971         .channels_min = 2,
2972         .channels_max = 8,
2973         /* NID is set in alc_build_pcms */
2974         .ops = {
2975                 .open = alc880_playback_pcm_open,
2976                 .prepare = alc880_playback_pcm_prepare,
2977                 .cleanup = alc880_playback_pcm_cleanup
2978         },
2979 };
2980
2981 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2982         .substreams = 1,
2983         .channels_min = 2,
2984         .channels_max = 2,
2985         /* NID is set in alc_build_pcms */
2986 };
2987
2988 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
2989         .substreams = 1,
2990         .channels_min = 2,
2991         .channels_max = 2,
2992         /* NID is set in alc_build_pcms */
2993 };
2994
2995 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2996         .substreams = 2, /* can be overridden */
2997         .channels_min = 2,
2998         .channels_max = 2,
2999         /* NID is set in alc_build_pcms */
3000         .ops = {
3001                 .prepare = alc880_alt_capture_pcm_prepare,
3002                 .cleanup = alc880_alt_capture_pcm_cleanup
3003         },
3004 };
3005
3006 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3007         .substreams = 1,
3008         .channels_min = 2,
3009         .channels_max = 2,
3010         /* NID is set in alc_build_pcms */
3011         .ops = {
3012                 .open = alc880_dig_playback_pcm_open,
3013                 .close = alc880_dig_playback_pcm_close,
3014                 .prepare = alc880_dig_playback_pcm_prepare
3015         },
3016 };
3017
3018 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3019         .substreams = 1,
3020         .channels_min = 2,
3021         .channels_max = 2,
3022         /* NID is set in alc_build_pcms */
3023 };
3024
3025 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3026 static struct hda_pcm_stream alc_pcm_null_stream = {
3027         .substreams = 0,
3028         .channels_min = 0,
3029         .channels_max = 0,
3030 };
3031
3032 static int alc_build_pcms(struct hda_codec *codec)
3033 {
3034         struct alc_spec *spec = codec->spec;
3035         struct hda_pcm *info = spec->pcm_rec;
3036         int i;
3037
3038         codec->num_pcms = 1;
3039         codec->pcm_info = info;
3040
3041         info->name = spec->stream_name_analog;
3042         if (spec->stream_analog_playback) {
3043                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3044                         return -EINVAL;
3045                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3046                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3047         }
3048         if (spec->stream_analog_capture) {
3049                 if (snd_BUG_ON(!spec->adc_nids))
3050                         return -EINVAL;
3051                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3052                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3053         }
3054
3055         if (spec->channel_mode) {
3056                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3057                 for (i = 0; i < spec->num_channel_mode; i++) {
3058                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3059                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3060                         }
3061                 }
3062         }
3063
3064         /* SPDIF for stream index #1 */
3065         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3066                 codec->num_pcms = 2;
3067                 info = spec->pcm_rec + 1;
3068                 info->name = spec->stream_name_digital;
3069                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
3070                 if (spec->multiout.dig_out_nid &&
3071                     spec->stream_digital_playback) {
3072                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3073                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3074                 }
3075                 if (spec->dig_in_nid &&
3076                     spec->stream_digital_capture) {
3077                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3078                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3079                 }
3080                 /* FIXME: do we need this for all Realtek codec models? */
3081                 codec->spdif_status_reset = 1;
3082         }
3083
3084         /* If the use of more than one ADC is requested for the current
3085          * model, configure a second analog capture-only PCM.
3086          */
3087         /* Additional Analaog capture for index #2 */
3088         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3089             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3090                 codec->num_pcms = 3;
3091                 info = spec->pcm_rec + 2;
3092                 info->name = spec->stream_name_analog;
3093                 if (spec->alt_dac_nid) {
3094                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3095                                 *spec->stream_analog_alt_playback;
3096                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3097                                 spec->alt_dac_nid;
3098                 } else {
3099                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3100                                 alc_pcm_null_stream;
3101                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3102                 }
3103                 if (spec->num_adc_nids > 1) {
3104                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3105                                 *spec->stream_analog_alt_capture;
3106                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3107                                 spec->adc_nids[1];
3108                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3109                                 spec->num_adc_nids - 1;
3110                 } else {
3111                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3112                                 alc_pcm_null_stream;
3113                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3114                 }
3115         }
3116
3117         return 0;
3118 }
3119
3120 static void alc_free_kctls(struct hda_codec *codec)
3121 {
3122         struct alc_spec *spec = codec->spec;
3123
3124         if (spec->kctls.list) {
3125                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3126                 int i;
3127                 for (i = 0; i < spec->kctls.used; i++)
3128                         kfree(kctl[i].name);
3129         }
3130         snd_array_free(&spec->kctls);
3131 }
3132
3133 static void alc_free(struct hda_codec *codec)
3134 {
3135         struct alc_spec *spec = codec->spec;
3136
3137         if (!spec)
3138                 return;
3139
3140         alc_free_kctls(codec);
3141         kfree(spec);
3142         codec->spec = NULL; /* to be sure */
3143 }
3144
3145 #ifdef SND_HDA_NEEDS_RESUME
3146 static void store_pin_configs(struct hda_codec *codec)
3147 {
3148         struct alc_spec *spec = codec->spec;
3149         hda_nid_t nid, end_nid;
3150
3151         end_nid = codec->start_nid + codec->num_nodes;
3152         for (nid = codec->start_nid; nid < end_nid; nid++) {
3153                 unsigned int wid_caps = get_wcaps(codec, nid);
3154                 unsigned int wid_type =
3155                         (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3156                 if (wid_type != AC_WID_PIN)
3157                         continue;
3158                 if (spec->num_pins >= ARRAY_SIZE(spec->pin_nids))
3159                         break;
3160                 spec->pin_nids[spec->num_pins] = nid;
3161                 spec->pin_cfgs[spec->num_pins] =
3162                         snd_hda_codec_read(codec, nid, 0,
3163                                            AC_VERB_GET_CONFIG_DEFAULT, 0);
3164                 spec->num_pins++;
3165         }
3166 }
3167
3168 static void resume_pin_configs(struct hda_codec *codec)
3169 {
3170         struct alc_spec *spec = codec->spec;
3171         int i;
3172
3173         for (i = 0; i < spec->num_pins; i++) {
3174                 hda_nid_t pin_nid = spec->pin_nids[i];
3175                 unsigned int pin_config = spec->pin_cfgs[i];
3176                 snd_hda_codec_write(codec, pin_nid, 0,
3177                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
3178                                     pin_config & 0x000000ff);
3179                 snd_hda_codec_write(codec, pin_nid, 0,
3180                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
3181                                     (pin_config & 0x0000ff00) >> 8);
3182                 snd_hda_codec_write(codec, pin_nid, 0,
3183                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
3184                                     (pin_config & 0x00ff0000) >> 16);
3185                 snd_hda_codec_write(codec, pin_nid, 0,
3186                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
3187                                     pin_config >> 24);
3188         }
3189 }
3190
3191 static int alc_resume(struct hda_codec *codec)
3192 {
3193         resume_pin_configs(codec);
3194         codec->patch_ops.init(codec);
3195         snd_hda_codec_resume_amp(codec);
3196         snd_hda_codec_resume_cache(codec);
3197         return 0;
3198 }
3199 #else
3200 #define store_pin_configs(codec)
3201 #endif
3202
3203 /*
3204  */
3205 static struct hda_codec_ops alc_patch_ops = {
3206         .build_controls = alc_build_controls,
3207         .build_pcms = alc_build_pcms,
3208         .init = alc_init,
3209         .free = alc_free,
3210         .unsol_event = alc_unsol_event,
3211 #ifdef SND_HDA_NEEDS_RESUME
3212         .resume = alc_resume,
3213 #endif
3214 #ifdef CONFIG_SND_HDA_POWER_SAVE
3215         .check_power_status = alc_check_power_status,
3216 #endif
3217 };
3218
3219
3220 /*
3221  * Test configuration for debugging
3222  *
3223  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3224  * enum controls.
3225  */
3226 #ifdef CONFIG_SND_DEBUG
3227 static hda_nid_t alc880_test_dac_nids[4] = {
3228         0x02, 0x03, 0x04, 0x05
3229 };
3230
3231 static struct hda_input_mux alc880_test_capture_source = {
3232         .num_items = 7,
3233         .items = {
3234                 { "In-1", 0x0 },
3235                 { "In-2", 0x1 },
3236                 { "In-3", 0x2 },
3237                 { "In-4", 0x3 },
3238                 { "CD", 0x4 },
3239                 { "Front", 0x5 },
3240                 { "Surround", 0x6 },
3241         },
3242 };
3243
3244 static struct hda_channel_mode alc880_test_modes[4] = {
3245         { 2, NULL },
3246         { 4, NULL },
3247         { 6, NULL },
3248         { 8, NULL },
3249 };
3250
3251 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3252                                  struct snd_ctl_elem_info *uinfo)
3253 {
3254         static char *texts[] = {
3255                 "N/A", "Line Out", "HP Out",
3256                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3257         };
3258         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3259         uinfo->count = 1;
3260         uinfo->value.enumerated.items = 8;
3261         if (uinfo->value.enumerated.item >= 8)
3262                 uinfo->value.enumerated.item = 7;
3263         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3264         return 0;
3265 }
3266
3267 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3268                                 struct snd_ctl_elem_value *ucontrol)
3269 {
3270         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3271         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3272         unsigned int pin_ctl, item = 0;
3273
3274         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3275                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3276         if (pin_ctl & AC_PINCTL_OUT_EN) {
3277                 if (pin_ctl & AC_PINCTL_HP_EN)
3278                         item = 2;
3279                 else
3280                         item = 1;
3281         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3282                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3283                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3284                 case AC_PINCTL_VREF_50:  item = 4; break;
3285                 case AC_PINCTL_VREF_GRD: item = 5; break;
3286                 case AC_PINCTL_VREF_80:  item = 6; break;
3287                 case AC_PINCTL_VREF_100: item = 7; break;
3288                 }
3289         }
3290         ucontrol->value.enumerated.item[0] = item;
3291         return 0;
3292 }
3293
3294 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3295                                 struct snd_ctl_elem_value *ucontrol)
3296 {
3297         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3298         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3299         static unsigned int ctls[] = {
3300                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3301                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3302                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3303                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3304                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3305                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3306         };
3307         unsigned int old_ctl, new_ctl;
3308
3309         old_ctl = snd_hda_codec_read(codec, nid, 0,
3310                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3311         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3312         if (old_ctl != new_ctl) {
3313                 int val;
3314                 snd_hda_codec_write_cache(codec, nid, 0,
3315                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3316                                           new_ctl);
3317                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3318                         HDA_AMP_MUTE : 0;
3319                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3320                                          HDA_AMP_MUTE, val);
3321                 return 1;
3322         }
3323         return 0;
3324 }
3325
3326 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3327                                  struct snd_ctl_elem_info *uinfo)
3328 {
3329         static char *texts[] = {
3330                 "Front", "Surround", "CLFE", "Side"
3331         };
3332         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3333         uinfo->count = 1;
3334         uinfo->value.enumerated.items = 4;
3335         if (uinfo->value.enumerated.item >= 4)
3336                 uinfo->value.enumerated.item = 3;
3337         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3338         return 0;
3339 }
3340
3341 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3342                                 struct snd_ctl_elem_value *ucontrol)
3343 {
3344         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3345         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3346         unsigned int sel;
3347
3348         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3349         ucontrol->value.enumerated.item[0] = sel & 3;
3350         return 0;
3351 }
3352
3353 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3354                                 struct snd_ctl_elem_value *ucontrol)
3355 {
3356         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3357         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3358         unsigned int sel;
3359
3360         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3361         if (ucontrol->value.enumerated.item[0] != sel) {
3362                 sel = ucontrol->value.enumerated.item[0] & 3;
3363                 snd_hda_codec_write_cache(codec, nid, 0,
3364                                           AC_VERB_SET_CONNECT_SEL, sel);
3365                 return 1;
3366         }
3367         return 0;
3368 }
3369
3370 #define PIN_CTL_TEST(xname,nid) {                       \
3371                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3372                         .name = xname,                 \
3373                         .info = alc_test_pin_ctl_info, \
3374                         .get = alc_test_pin_ctl_get,   \
3375                         .put = alc_test_pin_ctl_put,   \
3376                         .private_value = nid           \
3377                         }
3378
3379 #define PIN_SRC_TEST(xname,nid) {                       \
3380                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3381                         .name = xname,                 \
3382                         .info = alc_test_pin_src_info, \
3383                         .get = alc_test_pin_src_get,   \
3384                         .put = alc_test_pin_src_put,   \
3385                         .private_value = nid           \
3386                         }
3387
3388 static struct snd_kcontrol_new alc880_test_mixer[] = {
3389         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3390         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3391         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3392         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3393         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3394         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3395         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3396         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3397         PIN_CTL_TEST("Front Pin Mode", 0x14),
3398         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3399         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3400         PIN_CTL_TEST("Side Pin Mode", 0x17),
3401         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3402         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3403         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3404         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3405         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3406         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3407         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3408         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3409         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3410         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3411         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3412         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3413         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3414         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3415         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3416         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3417         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3418         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3419         {
3420                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3421                 .name = "Channel Mode",
3422                 .info = alc_ch_mode_info,
3423                 .get = alc_ch_mode_get,
3424                 .put = alc_ch_mode_put,
3425         },
3426         { } /* end */
3427 };
3428
3429 static struct hda_verb alc880_test_init_verbs[] = {
3430         /* Unmute inputs of 0x0c - 0x0f */
3431         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3432         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3433         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3434         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3435         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3436         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3437         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3438         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3439         /* Vol output for 0x0c-0x0f */
3440         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3441         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3442         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3443         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3444         /* Set output pins 0x14-0x17 */
3445         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3446         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3447         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3448         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3449         /* Unmute output pins 0x14-0x17 */
3450         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3451         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3452         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3453         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3454         /* Set input pins 0x18-0x1c */
3455         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3456         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3457         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3458         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3459         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3460         /* Mute input pins 0x18-0x1b */
3461         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3462         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3463         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3464         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3465         /* ADC set up */
3466         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3467         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3468         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3469         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3470         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3471         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3472         /* Analog input/passthru */
3473         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3474         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3475         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3476         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3477         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3478         { }
3479 };
3480 #endif
3481
3482 /*
3483  */
3484
3485 static const char *alc880_models[ALC880_MODEL_LAST] = {
3486         [ALC880_3ST]            = "3stack",
3487         [ALC880_TCL_S700]       = "tcl",
3488         [ALC880_3ST_DIG]        = "3stack-digout",
3489         [ALC880_CLEVO]          = "clevo",
3490         [ALC880_5ST]            = "5stack",
3491         [ALC880_5ST_DIG]        = "5stack-digout",
3492         [ALC880_W810]           = "w810",
3493         [ALC880_Z71V]           = "z71v",
3494         [ALC880_6ST]            = "6stack",
3495         [ALC880_6ST_DIG]        = "6stack-digout",
3496         [ALC880_ASUS]           = "asus",
3497         [ALC880_ASUS_W1V]       = "asus-w1v",
3498         [ALC880_ASUS_DIG]       = "asus-dig",
3499         [ALC880_ASUS_DIG2]      = "asus-dig2",
3500         [ALC880_UNIWILL_DIG]    = "uniwill",
3501         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3502         [ALC880_FUJITSU]        = "fujitsu",
3503         [ALC880_F1734]          = "F1734",
3504         [ALC880_LG]             = "lg",
3505         [ALC880_LG_LW]          = "lg-lw",
3506         [ALC880_MEDION_RIM]     = "medion",
3507 #ifdef CONFIG_SND_DEBUG
3508         [ALC880_TEST]           = "test",
3509 #endif
3510         [ALC880_AUTO]           = "auto",
3511 };
3512
3513 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3514         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3515         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3516         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3517         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3518         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3519         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3520         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3521         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3522         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3523         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3524         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3525         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3526         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3527         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3528         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3529         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3530         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3531         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3532         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3533         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3534         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3535         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3536         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3537         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3538         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3539         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3540         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3541         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3542         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3543         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3544         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3545         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3546         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3547         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3548         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3549         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3550         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3551         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3552         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3553         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3554         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3555         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3556         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3557         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3558         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3559         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3560         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3561         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3562         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3563         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3564         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3565         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3566         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3567         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3568         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3569         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3570         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3571         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3572         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3573         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3574         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3575         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3576         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3577         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3578         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3579         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3580         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3581         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3582         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3583         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3584         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3585         {}
3586 };
3587
3588 /*
3589  * ALC880 codec presets
3590  */
3591 static struct alc_config_preset alc880_presets[] = {
3592         [ALC880_3ST] = {
3593                 .mixers = { alc880_three_stack_mixer },
3594                 .init_verbs = { alc880_volume_init_verbs,
3595                                 alc880_pin_3stack_init_verbs },
3596                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3597                 .dac_nids = alc880_dac_nids,
3598                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3599                 .channel_mode = alc880_threestack_modes,
3600                 .need_dac_fix = 1,
3601                 .input_mux = &alc880_capture_source,
3602         },
3603         [ALC880_3ST_DIG] = {
3604                 .mixers = { alc880_three_stack_mixer },
3605                 .init_verbs = { alc880_volume_init_verbs,
3606                                 alc880_pin_3stack_init_verbs },
3607                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3608                 .dac_nids = alc880_dac_nids,
3609                 .dig_out_nid = ALC880_DIGOUT_NID,
3610                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3611                 .channel_mode = alc880_threestack_modes,
3612                 .need_dac_fix = 1,
3613                 .input_mux = &alc880_capture_source,
3614         },
3615         [ALC880_TCL_S700] = {
3616                 .mixers = { alc880_tcl_s700_mixer },
3617                 .init_verbs = { alc880_volume_init_verbs,
3618                                 alc880_pin_tcl_S700_init_verbs,
3619                                 alc880_gpio2_init_verbs },
3620                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3621                 .dac_nids = alc880_dac_nids,
3622                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3623                 .num_adc_nids = 1, /* single ADC */
3624                 .hp_nid = 0x03,
3625                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3626                 .channel_mode = alc880_2_jack_modes,
3627                 .input_mux = &alc880_capture_source,
3628         },
3629         [ALC880_5ST] = {
3630                 .mixers = { alc880_three_stack_mixer,
3631                             alc880_five_stack_mixer},
3632                 .init_verbs = { alc880_volume_init_verbs,
3633                                 alc880_pin_5stack_init_verbs },
3634                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3635                 .dac_nids = alc880_dac_nids,
3636                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3637                 .channel_mode = alc880_fivestack_modes,
3638                 .input_mux = &alc880_capture_source,
3639         },
3640         [ALC880_5ST_DIG] = {
3641                 .mixers = { alc880_three_stack_mixer,
3642                             alc880_five_stack_mixer },
3643                 .init_verbs = { alc880_volume_init_verbs,
3644                                 alc880_pin_5stack_init_verbs },
3645                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3646                 .dac_nids = alc880_dac_nids,
3647                 .dig_out_nid = ALC880_DIGOUT_NID,
3648                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3649                 .channel_mode = alc880_fivestack_modes,
3650                 .input_mux = &alc880_capture_source,
3651         },
3652         [ALC880_6ST] = {
3653                 .mixers = { alc880_six_stack_mixer },
3654                 .init_verbs = { alc880_volume_init_verbs,
3655                                 alc880_pin_6stack_init_verbs },
3656                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3657                 .dac_nids = alc880_6st_dac_nids,
3658                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3659                 .channel_mode = alc880_sixstack_modes,
3660                 .input_mux = &alc880_6stack_capture_source,
3661         },
3662         [ALC880_6ST_DIG] = {
3663                 .mixers = { alc880_six_stack_mixer },
3664                 .init_verbs = { alc880_volume_init_verbs,
3665                                 alc880_pin_6stack_init_verbs },
3666                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3667                 .dac_nids = alc880_6st_dac_nids,
3668                 .dig_out_nid = ALC880_DIGOUT_NID,
3669                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3670                 .channel_mode = alc880_sixstack_modes,
3671                 .input_mux = &alc880_6stack_capture_source,
3672         },
3673         [ALC880_W810] = {
3674                 .mixers = { alc880_w810_base_mixer },
3675                 .init_verbs = { alc880_volume_init_verbs,
3676                                 alc880_pin_w810_init_verbs,
3677                                 alc880_gpio2_init_verbs },
3678                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3679                 .dac_nids = alc880_w810_dac_nids,
3680                 .dig_out_nid = ALC880_DIGOUT_NID,
3681                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3682                 .channel_mode = alc880_w810_modes,
3683                 .input_mux = &alc880_capture_source,
3684         },
3685         [ALC880_Z71V] = {
3686                 .mixers = { alc880_z71v_mixer },
3687                 .init_verbs = { alc880_volume_init_verbs,
3688                                 alc880_pin_z71v_init_verbs },
3689                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3690                 .dac_nids = alc880_z71v_dac_nids,
3691                 .dig_out_nid = ALC880_DIGOUT_NID,
3692                 .hp_nid = 0x03,
3693                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3694                 .channel_mode = alc880_2_jack_modes,
3695                 .input_mux = &alc880_capture_source,
3696         },
3697         [ALC880_F1734] = {
3698                 .mixers = { alc880_f1734_mixer },
3699                 .init_verbs = { alc880_volume_init_verbs,
3700                                 alc880_pin_f1734_init_verbs },
3701                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3702                 .dac_nids = alc880_f1734_dac_nids,
3703                 .hp_nid = 0x02,
3704                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3705                 .channel_mode = alc880_2_jack_modes,
3706                 .input_mux = &alc880_f1734_capture_source,
3707                 .unsol_event = alc880_uniwill_p53_unsol_event,
3708                 .init_hook = alc880_uniwill_p53_hp_automute,
3709         },
3710         [ALC880_ASUS] = {
3711                 .mixers = { alc880_asus_mixer },
3712                 .init_verbs = { alc880_volume_init_verbs,
3713                                 alc880_pin_asus_init_verbs,
3714                                 alc880_gpio1_init_verbs },
3715                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3716                 .dac_nids = alc880_asus_dac_nids,
3717                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3718                 .channel_mode = alc880_asus_modes,
3719                 .need_dac_fix = 1,
3720                 .input_mux = &alc880_capture_source,
3721         },
3722         [ALC880_ASUS_DIG] = {
3723                 .mixers = { alc880_asus_mixer },
3724                 .init_verbs = { alc880_volume_init_verbs,
3725                                 alc880_pin_asus_init_verbs,
3726                                 alc880_gpio1_init_verbs },
3727                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3728                 .dac_nids = alc880_asus_dac_nids,
3729                 .dig_out_nid = ALC880_DIGOUT_NID,
3730                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3731                 .channel_mode = alc880_asus_modes,
3732                 .need_dac_fix = 1,
3733                 .input_mux = &alc880_capture_source,
3734         },
3735         [ALC880_ASUS_DIG2] = {
3736                 .mixers = { alc880_asus_mixer },
3737                 .init_verbs = { alc880_volume_init_verbs,
3738                                 alc880_pin_asus_init_verbs,
3739                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3740                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3741                 .dac_nids = alc880_asus_dac_nids,
3742                 .dig_out_nid = ALC880_DIGOUT_NID,
3743                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3744                 .channel_mode = alc880_asus_modes,
3745                 .need_dac_fix = 1,
3746                 .input_mux = &alc880_capture_source,
3747         },
3748         [ALC880_ASUS_W1V] = {
3749                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3750                 .init_verbs = { alc880_volume_init_verbs,
3751                                 alc880_pin_asus_init_verbs,
3752                                 alc880_gpio1_init_verbs },
3753                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3754                 .dac_nids = alc880_asus_dac_nids,
3755                 .dig_out_nid = ALC880_DIGOUT_NID,
3756                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3757                 .channel_mode = alc880_asus_modes,
3758                 .need_dac_fix = 1,
3759                 .input_mux = &alc880_capture_source,
3760         },
3761         [ALC880_UNIWILL_DIG] = {
3762                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3763                 .init_verbs = { alc880_volume_init_verbs,
3764                                 alc880_pin_asus_init_verbs },
3765                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3766                 .dac_nids = alc880_asus_dac_nids,
3767                 .dig_out_nid = ALC880_DIGOUT_NID,
3768                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3769                 .channel_mode = alc880_asus_modes,
3770                 .need_dac_fix = 1,
3771                 .input_mux = &alc880_capture_source,
3772         },
3773         [ALC880_UNIWILL] = {
3774                 .mixers = { alc880_uniwill_mixer },
3775                 .init_verbs = { alc880_volume_init_verbs,
3776                                 alc880_uniwill_init_verbs },
3777                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3778                 .dac_nids = alc880_asus_dac_nids,
3779                 .dig_out_nid = ALC880_DIGOUT_NID,
3780                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3781                 .channel_mode = alc880_threestack_modes,
3782                 .need_dac_fix = 1,
3783                 .input_mux = &alc880_capture_source,
3784                 .unsol_event = alc880_uniwill_unsol_event,
3785                 .init_hook = alc880_uniwill_automute,
3786         },
3787         [ALC880_UNIWILL_P53] = {
3788                 .mixers = { alc880_uniwill_p53_mixer },
3789                 .init_verbs = { alc880_volume_init_verbs,
3790                                 alc880_uniwill_p53_init_verbs },
3791                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3792                 .dac_nids = alc880_asus_dac_nids,
3793                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3794                 .channel_mode = alc880_threestack_modes,
3795                 .input_mux = &alc880_capture_source,
3796                 .unsol_event = alc880_uniwill_p53_unsol_event,
3797                 .init_hook = alc880_uniwill_p53_hp_automute,
3798         },
3799         [ALC880_FUJITSU] = {
3800                 .mixers = { alc880_fujitsu_mixer,
3801                             alc880_pcbeep_mixer, },
3802                 .init_verbs = { alc880_volume_init_verbs,
3803                                 alc880_uniwill_p53_init_verbs,
3804                                 alc880_beep_init_verbs },
3805                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3806                 .dac_nids = alc880_dac_nids,
3807                 .dig_out_nid = ALC880_DIGOUT_NID,
3808                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3809                 .channel_mode = alc880_2_jack_modes,
3810                 .input_mux = &alc880_capture_source,
3811                 .unsol_event = alc880_uniwill_p53_unsol_event,
3812                 .init_hook = alc880_uniwill_p53_hp_automute,
3813         },
3814         [ALC880_CLEVO] = {
3815                 .mixers = { alc880_three_stack_mixer },
3816                 .init_verbs = { alc880_volume_init_verbs,
3817                                 alc880_pin_clevo_init_verbs },
3818                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3819                 .dac_nids = alc880_dac_nids,
3820                 .hp_nid = 0x03,
3821                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3822                 .channel_mode = alc880_threestack_modes,
3823                 .need_dac_fix = 1,
3824                 .input_mux = &alc880_capture_source,
3825         },
3826         [ALC880_LG] = {
3827                 .mixers = { alc880_lg_mixer },
3828                 .init_verbs = { alc880_volume_init_verbs,
3829                                 alc880_lg_init_verbs },
3830                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3831                 .dac_nids = alc880_lg_dac_nids,
3832                 .dig_out_nid = ALC880_DIGOUT_NID,
3833                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3834                 .channel_mode = alc880_lg_ch_modes,
3835                 .need_dac_fix = 1,
3836                 .input_mux = &alc880_lg_capture_source,
3837                 .unsol_event = alc880_lg_unsol_event,
3838                 .init_hook = alc880_lg_automute,
3839 #ifdef CONFIG_SND_HDA_POWER_SAVE
3840                 .loopbacks = alc880_lg_loopbacks,
3841 #endif
3842         },
3843         [ALC880_LG_LW] = {
3844                 .mixers = { alc880_lg_lw_mixer },
3845                 .init_verbs = { alc880_volume_init_verbs,
3846                                 alc880_lg_lw_init_verbs },
3847                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3848                 .dac_nids = alc880_dac_nids,
3849                 .dig_out_nid = ALC880_DIGOUT_NID,
3850                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3851                 .channel_mode = alc880_lg_lw_modes,
3852                 .input_mux = &alc880_lg_lw_capture_source,
3853                 .unsol_event = alc880_lg_lw_unsol_event,
3854                 .init_hook = alc880_lg_lw_automute,
3855         },
3856         [ALC880_MEDION_RIM] = {
3857                 .mixers = { alc880_medion_rim_mixer },
3858                 .init_verbs = { alc880_volume_init_verbs,
3859                                 alc880_medion_rim_init_verbs,
3860                                 alc_gpio2_init_verbs },
3861                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3862                 .dac_nids = alc880_dac_nids,
3863                 .dig_out_nid = ALC880_DIGOUT_NID,
3864                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3865                 .channel_mode = alc880_2_jack_modes,
3866                 .input_mux = &alc880_medion_rim_capture_source,
3867                 .unsol_event = alc880_medion_rim_unsol_event,
3868                 .init_hook = alc880_medion_rim_automute,
3869         },
3870 #ifdef CONFIG_SND_DEBUG
3871         [ALC880_TEST] = {
3872                 .mixers = { alc880_test_mixer },
3873                 .init_verbs = { alc880_test_init_verbs },
3874                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3875                 .dac_nids = alc880_test_dac_nids,
3876                 .dig_out_nid = ALC880_DIGOUT_NID,
3877                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3878                 .channel_mode = alc880_test_modes,
3879                 .input_mux = &alc880_test_capture_source,
3880         },
3881 #endif
3882 };
3883
3884 /*
3885  * Automatic parse of I/O pins from the BIOS configuration
3886  */
3887
3888 enum {
3889         ALC_CTL_WIDGET_VOL,
3890         ALC_CTL_WIDGET_MUTE,
3891         ALC_CTL_BIND_MUTE,
3892 };
3893 static struct snd_kcontrol_new alc880_control_templates[] = {
3894         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3895         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3896         HDA_BIND_MUTE(NULL, 0, 0, 0),
3897 };
3898
3899 /* add dynamic controls */
3900 static int add_control(struct alc_spec *spec, int type, const char *name,
3901                        unsigned long val)
3902 {
3903         struct snd_kcontrol_new *knew;
3904
3905         snd_array_init(&spec->kctls, sizeof(*knew), 32);
3906         knew = snd_array_new(&spec->kctls);
3907         if (!knew)
3908                 return -ENOMEM;
3909         *knew = alc880_control_templates[type];
3910         knew->name = kstrdup(name, GFP_KERNEL);
3911         if (!knew->name)
3912                 return -ENOMEM;
3913         knew->private_value = val;
3914         return 0;
3915 }
3916
3917 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3918 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3919 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3920 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3921 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3922 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3923 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3924 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3925 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3926 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3927 #define ALC880_PIN_CD_NID               0x1c
3928
3929 /* fill in the dac_nids table from the parsed pin configuration */
3930 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3931                                      const struct auto_pin_cfg *cfg)
3932 {
3933         hda_nid_t nid;
3934         int assigned[4];
3935         int i, j;
3936
3937         memset(assigned, 0, sizeof(assigned));
3938         spec->multiout.dac_nids = spec->private_dac_nids;
3939
3940         /* check the pins hardwired to audio widget */
3941         for (i = 0; i < cfg->line_outs; i++) {
3942                 nid = cfg->line_out_pins[i];
3943                 if (alc880_is_fixed_pin(nid)) {
3944                         int idx = alc880_fixed_pin_idx(nid);
3945                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3946                         assigned[idx] = 1;
3947                 }
3948         }
3949         /* left pins can be connect to any audio widget */
3950         for (i = 0; i < cfg->line_outs; i++) {
3951                 nid = cfg->line_out_pins[i];
3952                 if (alc880_is_fixed_pin(nid))
3953                         continue;
3954                 /* search for an empty channel */
3955                 for (j = 0; j < cfg->line_outs; j++) {
3956                         if (!assigned[j]) {
3957                                 spec->multiout.dac_nids[i] =
3958                                         alc880_idx_to_dac(j);
3959                                 assigned[j] = 1;
3960                                 break;
3961                         }
3962                 }
3963         }
3964         spec->multiout.num_dacs = cfg->line_outs;
3965         return 0;
3966 }
3967
3968 /* add playback controls from the parsed DAC table */
3969 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3970                                              const struct auto_pin_cfg *cfg)
3971 {
3972         char name[32];
3973         static const char *chname[4] = {
3974                 "Front", "Surround", NULL /*CLFE*/, "Side"
3975         };
3976         hda_nid_t nid;
3977         int i, err;
3978
3979         for (i = 0; i < cfg->line_outs; i++) {
3980                 if (!spec->multiout.dac_nids[i])
3981                         continue;
3982                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3983                 if (i == 2) {
3984                         /* Center/LFE */
3985                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3986                                           "Center Playback Volume",
3987                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3988                                                               HDA_OUTPUT));
3989                         if (err < 0)
3990                                 return err;
3991                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3992                                           "LFE Playback Volume",
3993                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3994                                                               HDA_OUTPUT));
3995                         if (err < 0)
3996                                 return err;
3997                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3998                                           "Center Playback Switch",
3999                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4000                                                               HDA_INPUT));
4001                         if (err < 0)
4002                                 return err;
4003                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4004                                           "LFE Playback Switch",
4005                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4006                                                               HDA_INPUT));
4007                         if (err < 0)
4008                                 return err;
4009                 } else {
4010                         sprintf(name, "%s Playback Volume", chname[i]);
4011                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4012                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4013                                                               HDA_OUTPUT));
4014                         if (err < 0)
4015                                 return err;
4016                         sprintf(name, "%s Playback Switch", chname[i]);
4017                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4018                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4019                                                               HDA_INPUT));
4020                         if (err < 0)
4021                                 return err;
4022                 }
4023         }
4024         return 0;
4025 }
4026
4027 /* add playback controls for speaker and HP outputs */
4028 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4029                                         const char *pfx)
4030 {
4031         hda_nid_t nid;
4032         int err;
4033         char name[32];
4034
4035         if (!pin)
4036                 return 0;
4037
4038         if (alc880_is_fixed_pin(pin)) {
4039                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4040                 /* specify the DAC as the extra output */
4041                 if (!spec->multiout.hp_nid)
4042                         spec->multiout.hp_nid = nid;
4043                 else
4044                         spec->multiout.extra_out_nid[0] = nid;
4045                 /* control HP volume/switch on the output mixer amp */
4046                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4047                 sprintf(name, "%s Playback Volume", pfx);
4048                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4049                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4050                 if (err < 0)
4051                         return err;
4052                 sprintf(name, "%s Playback Switch", pfx);
4053                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4054                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4055                 if (err < 0)
4056                         return err;
4057         } else if (alc880_is_multi_pin(pin)) {
4058                 /* set manual connection */
4059                 /* we have only a switch on HP-out PIN */
4060                 sprintf(name, "%s Playback Switch", pfx);
4061                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4062                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4063                 if (err < 0)
4064                         return err;
4065         }
4066         return 0;
4067 }
4068
4069 /* create input playback/capture controls for the given pin */
4070 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4071                             const char *ctlname,
4072                             int idx, hda_nid_t mix_nid)
4073 {
4074         char name[32];
4075         int err;
4076
4077         sprintf(name, "%s Playback Volume", ctlname);
4078         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4079                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4080         if (err < 0)
4081                 return err;
4082         sprintf(name, "%s Playback Switch", ctlname);
4083         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4084                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4085         if (err < 0)
4086                 return err;
4087         return 0;
4088 }
4089
4090 /* create playback/capture controls for input pins */
4091 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
4092                                                 const struct auto_pin_cfg *cfg)
4093 {
4094         struct hda_input_mux *imux = &spec->private_imux;
4095         int i, err, idx;
4096
4097         for (i = 0; i < AUTO_PIN_LAST; i++) {
4098                 if (alc880_is_input_pin(cfg->input_pins[i])) {
4099                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
4100                         err = new_analog_input(spec, cfg->input_pins[i],
4101                                                auto_pin_cfg_labels[i],
4102                                                idx, 0x0b);
4103                         if (err < 0)
4104                                 return err;
4105                         imux->items[imux->num_items].label =
4106                                 auto_pin_cfg_labels[i];
4107                         imux->items[imux->num_items].index =
4108                                 alc880_input_pin_idx(cfg->input_pins[i]);
4109                         imux->num_items++;
4110                 }
4111         }
4112         return 0;
4113 }
4114
4115 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4116                                unsigned int pin_type)
4117 {
4118         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4119                             pin_type);
4120         /* unmute pin */
4121         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4122                             AMP_OUT_UNMUTE);
4123 }
4124
4125 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4126                                               hda_nid_t nid, int pin_type,
4127                                               int dac_idx)
4128 {
4129         alc_set_pin_output(codec, nid, pin_type);
4130         /* need the manual connection? */
4131         if (alc880_is_multi_pin(nid)) {
4132                 struct alc_spec *spec = codec->spec;
4133                 int idx = alc880_multi_pin_idx(nid);
4134                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4135                                     AC_VERB_SET_CONNECT_SEL,
4136                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4137         }
4138 }
4139
4140 static int get_pin_type(int line_out_type)
4141 {
4142         if (line_out_type == AUTO_PIN_HP_OUT)
4143                 return PIN_HP;
4144         else
4145                 return PIN_OUT;
4146 }
4147
4148 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4149 {
4150         struct alc_spec *spec = codec->spec;
4151         int i;
4152
4153         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
4154         for (i = 0; i < spec->autocfg.line_outs; i++) {
4155                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4156                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4157                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4158         }
4159 }
4160
4161 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4162 {
4163         struct alc_spec *spec = codec->spec;
4164         hda_nid_t pin;
4165
4166         pin = spec->autocfg.speaker_pins[0];
4167         if (pin) /* connect to front */
4168                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4169         pin = spec->autocfg.hp_pins[0];
4170         if (pin) /* connect to front */
4171                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4172 }
4173
4174 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4175 {
4176         struct alc_spec *spec = codec->spec;
4177         int i;
4178
4179         for (i = 0; i < AUTO_PIN_LAST; i++) {
4180                 hda_nid_t nid = spec->autocfg.input_pins[i];
4181                 if (alc880_is_input_pin(nid)) {
4182                         snd_hda_codec_write(codec, nid, 0,
4183                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4184                                             i <= AUTO_PIN_FRONT_MIC ?
4185                                             PIN_VREF80 : PIN_IN);
4186                         if (nid != ALC880_PIN_CD_NID)
4187                                 snd_hda_codec_write(codec, nid, 0,
4188                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4189                                                     AMP_OUT_MUTE);
4190                 }
4191         }
4192 }
4193
4194 /* parse the BIOS configuration and set up the alc_spec */
4195 /* return 1 if successful, 0 if the proper config is not found,
4196  * or a negative error code
4197  */
4198 static int alc880_parse_auto_config(struct hda_codec *codec)
4199 {
4200         struct alc_spec *spec = codec->spec;
4201         int err;
4202         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4203
4204         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4205                                            alc880_ignore);
4206         if (err < 0)
4207                 return err;
4208         if (!spec->autocfg.line_outs)
4209                 return 0; /* can't find valid BIOS pin config */
4210
4211         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4212         if (err < 0)
4213                 return err;
4214         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4215         if (err < 0)
4216                 return err;
4217         err = alc880_auto_create_extra_out(spec,
4218                                            spec->autocfg.speaker_pins[0],
4219                                            "Speaker");
4220         if (err < 0)
4221                 return err;
4222         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4223                                            "Headphone");
4224         if (err < 0)
4225                 return err;
4226         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
4227         if (err < 0)
4228                 return err;
4229
4230         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4231
4232         if (spec->autocfg.dig_out_pin)
4233                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
4234         if (spec->autocfg.dig_in_pin)
4235                 spec->dig_in_nid = ALC880_DIGIN_NID;
4236
4237         if (spec->kctls.list)
4238                 add_mixer(spec, spec->kctls.list);
4239
4240         add_verb(spec, alc880_volume_init_verbs);
4241
4242         spec->num_mux_defs = 1;
4243         spec->input_mux = &spec->private_imux;
4244
4245         store_pin_configs(codec);
4246         return 1;
4247 }
4248
4249 /* additional initialization for auto-configuration model */
4250 static void alc880_auto_init(struct hda_codec *codec)
4251 {
4252         struct alc_spec *spec = codec->spec;
4253         alc880_auto_init_multi_out(codec);
4254         alc880_auto_init_extra_out(codec);
4255         alc880_auto_init_analog_input(codec);
4256         if (spec->unsol_event)
4257                 alc_inithook(codec);
4258 }
4259
4260 /*
4261  * OK, here we have finally the patch for ALC880
4262  */
4263
4264 static void set_capture_mixer(struct alc_spec *spec)
4265 {
4266         static struct snd_kcontrol_new *caps[3] = {
4267                 alc_capture_mixer1,
4268                 alc_capture_mixer2,
4269                 alc_capture_mixer3,
4270         };
4271         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3)
4272                 spec->cap_mixer = caps[spec->num_adc_nids - 1];
4273 }
4274
4275 static int patch_alc880(struct hda_codec *codec)
4276 {
4277         struct alc_spec *spec;
4278         int board_config;
4279         int err;
4280
4281         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4282         if (spec == NULL)
4283                 return -ENOMEM;
4284
4285         codec->spec = spec;
4286
4287         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4288                                                   alc880_models,
4289                                                   alc880_cfg_tbl);
4290         if (board_config < 0) {
4291                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
4292                        "trying auto-probe from BIOS...\n");
4293                 board_config = ALC880_AUTO;
4294         }
4295
4296         if (board_config == ALC880_AUTO) {
4297                 /* automatic parse from the BIOS config */
4298                 err = alc880_parse_auto_config(codec);
4299                 if (err < 0) {
4300                         alc_free(codec);
4301                         return err;
4302                 } else if (!err) {
4303                         printk(KERN_INFO
4304                                "hda_codec: Cannot set up configuration "
4305                                "from BIOS.  Using 3-stack mode...\n");
4306                         board_config = ALC880_3ST;
4307                 }
4308         }
4309
4310         if (board_config != ALC880_AUTO)
4311                 setup_preset(spec, &alc880_presets[board_config]);
4312
4313         spec->stream_name_analog = "ALC880 Analog";
4314         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4315         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4316         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4317
4318         spec->stream_name_digital = "ALC880 Digital";
4319         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4320         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4321
4322         if (!spec->adc_nids && spec->input_mux) {
4323                 /* check whether NID 0x07 is valid */
4324                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4325                 /* get type */
4326                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4327                 if (wcap != AC_WID_AUD_IN) {
4328                         spec->adc_nids = alc880_adc_nids_alt;
4329                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4330                 } else {
4331                         spec->adc_nids = alc880_adc_nids;
4332                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4333                 }
4334         }
4335         set_capture_mixer(spec);
4336
4337         spec->vmaster_nid = 0x0c;
4338
4339         codec->patch_ops = alc_patch_ops;
4340         if (board_config == ALC880_AUTO)
4341                 spec->init_hook = alc880_auto_init;
4342 #ifdef CONFIG_SND_HDA_POWER_SAVE
4343         if (!spec->loopback.amplist)
4344                 spec->loopback.amplist = alc880_loopbacks;
4345 #endif
4346
4347         return 0;
4348 }
4349
4350
4351 /*
4352  * ALC260 support
4353  */
4354
4355 static hda_nid_t alc260_dac_nids[1] = {
4356         /* front */
4357         0x02,
4358 };
4359
4360 static hda_nid_t alc260_adc_nids[1] = {
4361         /* ADC0 */
4362         0x04,
4363 };
4364
4365 static hda_nid_t alc260_adc_nids_alt[1] = {
4366         /* ADC1 */
4367         0x05,
4368 };
4369
4370 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4371  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4372  */
4373 static hda_nid_t alc260_dual_adc_nids[2] = {
4374         /* ADC0, ADC1 */
4375         0x04, 0x05
4376 };
4377
4378 #define ALC260_DIGOUT_NID       0x03
4379 #define ALC260_DIGIN_NID        0x06
4380
4381 static struct hda_input_mux alc260_capture_source = {
4382         .num_items = 4,
4383         .items = {
4384                 { "Mic", 0x0 },
4385                 { "Front Mic", 0x1 },
4386                 { "Line", 0x2 },
4387                 { "CD", 0x4 },
4388         },
4389 };
4390
4391 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4392  * headphone jack and the internal CD lines since these are the only pins at
4393  * which audio can appear.  For flexibility, also allow the option of
4394  * recording the mixer output on the second ADC (ADC0 doesn't have a
4395  * connection to the mixer output).
4396  */
4397 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4398         {
4399                 .num_items = 3,
4400                 .items = {
4401                         { "Mic/Line", 0x0 },
4402                         { "CD", 0x4 },
4403                         { "Headphone", 0x2 },
4404                 },
4405         },
4406         {
4407                 .num_items = 4,
4408                 .items = {
4409                         { "Mic/Line", 0x0 },
4410                         { "CD", 0x4 },
4411                         { "Headphone", 0x2 },
4412                         { "Mixer", 0x5 },
4413                 },
4414         },
4415
4416 };
4417
4418 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4419  * the Fujitsu S702x, but jacks are marked differently.
4420  */
4421 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4422         {
4423                 .num_items = 4,
4424                 .items = {
4425                         { "Mic", 0x0 },
4426                         { "Line", 0x2 },
4427                         { "CD", 0x4 },
4428                         { "Headphone", 0x5 },
4429                 },
4430         },
4431         {
4432                 .num_items = 5,
4433                 .items = {
4434                         { "Mic", 0x0 },
4435                         { "Line", 0x2 },
4436                         { "CD", 0x4 },
4437                         { "Headphone", 0x6 },
4438                         { "Mixer", 0x5 },
4439                 },
4440         },
4441 };
4442 /*
4443  * This is just place-holder, so there's something for alc_build_pcms to look
4444  * at when it calculates the maximum number of channels. ALC260 has no mixer
4445  * element which allows changing the channel mode, so the verb list is
4446  * never used.
4447  */
4448 static struct hda_channel_mode alc260_modes[1] = {
4449         { 2, NULL },
4450 };
4451
4452
4453 /* Mixer combinations
4454  *
4455  * basic: base_output + input + pc_beep + capture
4456  * HP: base_output + input + capture_alt
4457  * HP_3013: hp_3013 + input + capture
4458  * fujitsu: fujitsu + capture
4459  * acer: acer + capture
4460  */
4461
4462 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4463         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4464         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4465         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4466         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4467         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4468         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4469         { } /* end */
4470 };
4471
4472 static struct snd_kcontrol_new alc260_input_mixer[] = {
4473         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4474         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4475         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4476         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4477         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4478         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4479         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4480         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4481         { } /* end */
4482 };
4483
4484 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4485         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4486         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4487         { } /* end */
4488 };
4489
4490 /* update HP, line and mono out pins according to the master switch */
4491 static void alc260_hp_master_update(struct hda_codec *codec,
4492                                     hda_nid_t hp, hda_nid_t line,
4493                                     hda_nid_t mono)
4494 {
4495         struct alc_spec *spec = codec->spec;
4496         unsigned int val = spec->master_sw ? PIN_HP : 0;
4497         /* change HP and line-out pins */
4498         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4499                             val);
4500         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4501                             val);
4502         /* mono (speaker) depending on the HP jack sense */
4503         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4504         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4505                             val);
4506 }
4507
4508 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4509                                    struct snd_ctl_elem_value *ucontrol)
4510 {
4511         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4512         struct alc_spec *spec = codec->spec;
4513         *ucontrol->value.integer.value = spec->master_sw;
4514         return 0;
4515 }
4516
4517 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4518                                    struct snd_ctl_elem_value *ucontrol)
4519 {
4520         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4521         struct alc_spec *spec = codec->spec;
4522         int val = !!*ucontrol->value.integer.value;
4523         hda_nid_t hp, line, mono;
4524
4525         if (val == spec->master_sw)
4526                 return 0;
4527         spec->master_sw = val;
4528         hp = (kcontrol->private_value >> 16) & 0xff;
4529         line = (kcontrol->private_value >> 8) & 0xff;
4530         mono = kcontrol->private_value & 0xff;
4531         alc260_hp_master_update(codec, hp, line, mono);
4532         return 1;
4533 }
4534
4535 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4536         {
4537                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4538                 .name = "Master Playback Switch",
4539                 .info = snd_ctl_boolean_mono_info,
4540                 .get = alc260_hp_master_sw_get,
4541                 .put = alc260_hp_master_sw_put,
4542                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4543         },
4544         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4545         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4546         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4547         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4548         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4549                               HDA_OUTPUT),
4550         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4551         { } /* end */
4552 };
4553
4554 static struct hda_verb alc260_hp_unsol_verbs[] = {
4555         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4556         {},
4557 };
4558
4559 static void alc260_hp_automute(struct hda_codec *codec)
4560 {
4561         struct alc_spec *spec = codec->spec;
4562         unsigned int present;
4563
4564         present = snd_hda_codec_read(codec, 0x10, 0,
4565                                      AC_VERB_GET_PIN_SENSE, 0);
4566         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4567         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4568 }
4569
4570 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4571 {
4572         if ((res >> 26) == ALC880_HP_EVENT)
4573                 alc260_hp_automute(codec);
4574 }
4575
4576 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4577         {
4578                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4579                 .name = "Master Playback Switch",
4580                 .info = snd_ctl_boolean_mono_info,
4581                 .get = alc260_hp_master_sw_get,
4582                 .put = alc260_hp_master_sw_put,
4583                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4584         },
4585         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4586         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4587         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4588         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4589         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4590         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4591         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4592         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4593         { } /* end */
4594 };
4595
4596 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4597         .ops = &snd_hda_bind_vol,
4598         .values = {
4599                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4600                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4601                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4602                 0
4603         },
4604 };
4605
4606 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4607         .ops = &snd_hda_bind_sw,
4608         .values = {
4609                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4610                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4611                 0
4612         },
4613 };
4614
4615 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4616         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4617         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4618         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4619         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4620         { } /* end */
4621 };
4622
4623 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4624         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4625         {},
4626 };
4627
4628 static void alc260_hp_3013_automute(struct hda_codec *codec)
4629 {
4630         struct alc_spec *spec = codec->spec;
4631         unsigned int present;
4632
4633         present = snd_hda_codec_read(codec, 0x15, 0,
4634                                      AC_VERB_GET_PIN_SENSE, 0);
4635         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4636         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4637 }
4638
4639 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4640                                        unsigned int res)
4641 {
4642         if ((res >> 26) == ALC880_HP_EVENT)
4643                 alc260_hp_3013_automute(codec);
4644 }
4645
4646 static void alc260_hp_3012_automute(struct hda_codec *codec)
4647 {
4648         unsigned int present, bits;
4649
4650         present = snd_hda_codec_read(codec, 0x10, 0,
4651                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4652
4653         bits = present ? 0 : PIN_OUT;
4654         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4655                             bits);
4656         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4657                             bits);
4658         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4659                             bits);
4660 }
4661
4662 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4663                                        unsigned int res)
4664 {
4665         if ((res >> 26) == ALC880_HP_EVENT)
4666                 alc260_hp_3012_automute(codec);
4667 }
4668
4669 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4670  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4671  */
4672 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4673         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4674         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4675         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4676         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4677         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4678         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4679         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4680         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4681         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4682         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4683         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4684         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4685         { } /* end */
4686 };
4687
4688 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4689  * versions of the ALC260 don't act on requests to enable mic bias from NID
4690  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4691  * datasheet doesn't mention this restriction.  At this stage it's not clear
4692  * whether this behaviour is intentional or is a hardware bug in chip
4693  * revisions available in early 2006.  Therefore for now allow the
4694  * "Headphone Jack Mode" control to span all choices, but if it turns out
4695  * that the lack of mic bias for this NID is intentional we could change the
4696  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4697  *
4698  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4699  * don't appear to make the mic bias available from the "line" jack, even
4700  * though the NID used for this jack (0x14) can supply it.  The theory is
4701  * that perhaps Acer have included blocking capacitors between the ALC260
4702  * and the output jack.  If this turns out to be the case for all such
4703  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4704  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4705  *
4706  * The C20x Tablet series have a mono internal speaker which is controlled
4707  * via the chip's Mono sum widget and pin complex, so include the necessary
4708  * controls for such models.  On models without a "mono speaker" the control
4709  * won't do anything.
4710  */
4711 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4712         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4713         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4714         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4715         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4716                               HDA_OUTPUT),
4717         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4718                            HDA_INPUT),
4719         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4720         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4721         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4722         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4723         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4724         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4725         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4726         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4727         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4728         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4729         { } /* end */
4730 };
4731
4732 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4733  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4734  */
4735 static struct snd_kcontrol_new alc260_will_mixer[] = {
4736         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4737         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4738         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4739         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4740         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4741         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4742         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4743         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4744         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4745         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4746         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4747         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4748         { } /* end */
4749 };
4750
4751 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4752  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4753  */
4754 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4755         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4756         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4757         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4758         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4759         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4760         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4761         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4762         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4763         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4764         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4765         { } /* end */
4766 };
4767
4768 /*
4769  * initialization verbs
4770  */
4771 static struct hda_verb alc260_init_verbs[] = {
4772         /* Line In pin widget for input */
4773         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4774         /* CD pin widget for input */
4775         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4776         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4777         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4778         /* Mic2 (front panel) pin widget for input and vref at 80% */
4779         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4780         /* LINE-2 is used for line-out in rear */
4781         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4782         /* select line-out */
4783         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4784         /* LINE-OUT pin */
4785         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4786         /* enable HP */
4787         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4788         /* enable Mono */
4789         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4790         /* mute capture amp left and right */
4791         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4792         /* set connection select to line in (default select for this ADC) */
4793         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4794         /* mute capture amp left and right */
4795         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4796         /* set connection select to line in (default select for this ADC) */
4797         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4798         /* set vol=0 Line-Out mixer amp left and right */
4799         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4800         /* unmute pin widget amp left and right (no gain on this amp) */
4801         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4802         /* set vol=0 HP mixer amp left and right */
4803         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4804         /* unmute pin widget amp left and right (no gain on this amp) */
4805         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4806         /* set vol=0 Mono mixer amp left and right */
4807         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4808         /* unmute pin widget amp left and right (no gain on this amp) */
4809         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4810         /* unmute LINE-2 out pin */
4811         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4812         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4813          * Line In 2 = 0x03
4814          */
4815         /* mute analog inputs */
4816         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4817         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4818         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4819         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4820         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4821         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4822         /* mute Front out path */
4823         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4824         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4825         /* mute Headphone out path */
4826         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4827         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4828         /* mute Mono out path */
4829         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4830         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4831         { }
4832 };
4833
4834 #if 0 /* should be identical with alc260_init_verbs? */
4835 static struct hda_verb alc260_hp_init_verbs[] = {
4836         /* Headphone and output */
4837         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4838         /* mono output */
4839         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4840         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4841         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4842         /* Mic2 (front panel) pin widget for input and vref at 80% */
4843         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4844         /* Line In pin widget for input */
4845         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4846         /* Line-2 pin widget for output */
4847         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4848         /* CD pin widget for input */
4849         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4850         /* unmute amp left and right */
4851         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4852         /* set connection select to line in (default select for this ADC) */
4853         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4854         /* unmute Line-Out mixer amp left and right (volume = 0) */
4855         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4856         /* mute pin widget amp left and right (no gain on this amp) */
4857         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4858         /* unmute HP mixer amp left and right (volume = 0) */
4859         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4860         /* mute pin widget amp left and right (no gain on this amp) */
4861         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4862         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4863          * Line In 2 = 0x03
4864          */
4865         /* mute analog inputs */
4866         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4867         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4868         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4869         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4870         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4871         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4872         /* Unmute Front out path */
4873         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4874         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4875         /* Unmute Headphone out path */
4876         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4877         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4878         /* Unmute Mono out path */
4879         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4880         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4881         { }
4882 };
4883 #endif
4884
4885 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4886         /* Line out and output */
4887         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4888         /* mono output */
4889         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4890         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4891         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4892         /* Mic2 (front panel) pin widget for input and vref at 80% */
4893         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4894         /* Line In pin widget for input */
4895         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4896         /* Headphone pin widget for output */
4897         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4898         /* CD pin widget for input */
4899         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4900         /* unmute amp left and right */
4901         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4902         /* set connection select to line in (default select for this ADC) */
4903         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4904         /* unmute Line-Out mixer amp left and right (volume = 0) */
4905         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4906         /* mute pin widget amp left and right (no gain on this amp) */
4907         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4908         /* unmute HP mixer amp left and right (volume = 0) */
4909         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4910         /* mute pin widget amp left and right (no gain on this amp) */
4911         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4912         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4913          * Line In 2 = 0x03
4914          */
4915         /* mute analog inputs */
4916         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4917         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4918         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4919         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4920         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4921         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4922         /* Unmute Front out path */
4923         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4924         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4925         /* Unmute Headphone out path */
4926         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4927         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4928         /* Unmute Mono out path */
4929         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4930         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4931         { }
4932 };
4933
4934 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4935  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4936  * audio = 0x16, internal speaker = 0x10.
4937  */
4938 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4939         /* Disable all GPIOs */
4940         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4941         /* Internal speaker is connected to headphone pin */
4942         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4943         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4944         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4945         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4946         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4947         /* Ensure all other unused pins are disabled and muted. */
4948         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4949         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4950         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4951         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4952         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4953         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4954         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4955         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4956
4957         /* Disable digital (SPDIF) pins */
4958         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4959         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4960
4961         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
4962          * when acting as an output.
4963          */
4964         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4965
4966         /* Start with output sum widgets muted and their output gains at min */
4967         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4968         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4969         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4970         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4971         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4972         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4973         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4974         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4975         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4976
4977         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4978         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4979         /* Unmute Line1 pin widget output buffer since it starts as an output.
4980          * If the pin mode is changed by the user the pin mode control will
4981          * take care of enabling the pin's input/output buffers as needed.
4982          * Therefore there's no need to enable the input buffer at this
4983          * stage.
4984          */
4985         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4986         /* Unmute input buffer of pin widget used for Line-in (no equiv
4987          * mixer ctrl)
4988          */
4989         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4990
4991         /* Mute capture amp left and right */
4992         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4993         /* Set ADC connection select to match default mixer setting - line
4994          * in (on mic1 pin)
4995          */
4996         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4997
4998         /* Do the same for the second ADC: mute capture input amp and
4999          * set ADC connection to line in (on mic1 pin)
5000          */
5001         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5002         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5003
5004         /* Mute all inputs to mixer widget (even unconnected ones) */
5005         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5006         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5007         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5008         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5009         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5010         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5011         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5012         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5013
5014         { }
5015 };
5016
5017 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5018  * similar laptops (adapted from Fujitsu init verbs).
5019  */
5020 static struct hda_verb alc260_acer_init_verbs[] = {
5021         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5022          * the headphone jack.  Turn this on and rely on the standard mute
5023          * methods whenever the user wants to turn these outputs off.
5024          */
5025         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5026         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5027         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5028         /* Internal speaker/Headphone jack is connected to Line-out pin */
5029         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5030         /* Internal microphone/Mic jack is connected to Mic1 pin */
5031         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5032         /* Line In jack is connected to Line1 pin */
5033         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5034         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5035         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5036         /* Ensure all other unused pins are disabled and muted. */
5037         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5038         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5039         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5040         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5041         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5042         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5043         /* Disable digital (SPDIF) pins */
5044         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5045         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5046
5047         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5048          * bus when acting as outputs.
5049          */
5050         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5051         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5052
5053         /* Start with output sum widgets muted and their output gains at min */
5054         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5055         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5056         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5057         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5058         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5059         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5060         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5061         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5062         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5063
5064         /* Unmute Line-out pin widget amp left and right
5065          * (no equiv mixer ctrl)
5066          */
5067         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5068         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5069         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5070         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5071          * inputs. If the pin mode is changed by the user the pin mode control
5072          * will take care of enabling the pin's input/output buffers as needed.
5073          * Therefore there's no need to enable the input buffer at this
5074          * stage.
5075          */
5076         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5077         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5078
5079         /* Mute capture amp left and right */
5080         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5081         /* Set ADC connection select to match default mixer setting - mic
5082          * (on mic1 pin)
5083          */
5084         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5085
5086         /* Do similar with the second ADC: mute capture input amp and
5087          * set ADC connection to mic to match ALSA's default state.
5088          */
5089         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5090         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5091
5092         /* Mute all inputs to mixer widget (even unconnected ones) */
5093         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5094         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5095         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5096         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5097         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5098         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5099         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5100         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5101
5102         { }
5103 };
5104
5105 static struct hda_verb alc260_will_verbs[] = {
5106         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5107         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5108         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5109         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5110         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5111         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5112         {}
5113 };
5114
5115 static struct hda_verb alc260_replacer_672v_verbs[] = {
5116         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5117         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5118         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5119
5120         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5121         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5122         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5123
5124         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5125         {}
5126 };
5127
5128 /* toggle speaker-output according to the hp-jack state */
5129 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5130 {
5131         unsigned int present;
5132
5133         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5134         present = snd_hda_codec_read(codec, 0x0f, 0,
5135                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5136         if (present) {
5137                 snd_hda_codec_write_cache(codec, 0x01, 0,
5138                                           AC_VERB_SET_GPIO_DATA, 1);
5139                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5140                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5141                                           PIN_HP);
5142         } else {
5143                 snd_hda_codec_write_cache(codec, 0x01, 0,
5144                                           AC_VERB_SET_GPIO_DATA, 0);
5145                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5146                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5147                                           PIN_OUT);
5148         }
5149 }
5150
5151 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5152                                        unsigned int res)
5153 {
5154         if ((res >> 26) == ALC880_HP_EVENT)
5155                 alc260_replacer_672v_automute(codec);
5156 }
5157
5158 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5159         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5160         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5161         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5162         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5163         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5164         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5165         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5166         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5167         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5168         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5169         {}
5170 };
5171
5172 /* Test configuration for debugging, modelled after the ALC880 test
5173  * configuration.
5174  */
5175 #ifdef CONFIG_SND_DEBUG
5176 static hda_nid_t alc260_test_dac_nids[1] = {
5177         0x02,
5178 };
5179 static hda_nid_t alc260_test_adc_nids[2] = {
5180         0x04, 0x05,
5181 };
5182 /* For testing the ALC260, each input MUX needs its own definition since
5183  * the signal assignments are different.  This assumes that the first ADC
5184  * is NID 0x04.
5185  */
5186 static struct hda_input_mux alc260_test_capture_sources[2] = {
5187         {
5188                 .num_items = 7,
5189                 .items = {
5190                         { "MIC1 pin", 0x0 },
5191                         { "MIC2 pin", 0x1 },
5192                         { "LINE1 pin", 0x2 },
5193                         { "LINE2 pin", 0x3 },
5194                         { "CD pin", 0x4 },
5195                         { "LINE-OUT pin", 0x5 },
5196                         { "HP-OUT pin", 0x6 },
5197                 },
5198         },
5199         {
5200                 .num_items = 8,
5201                 .items = {
5202                         { "MIC1 pin", 0x0 },
5203                         { "MIC2 pin", 0x1 },
5204                         { "LINE1 pin", 0x2 },
5205                         { "LINE2 pin", 0x3 },
5206                         { "CD pin", 0x4 },
5207                         { "Mixer", 0x5 },
5208                         { "LINE-OUT pin", 0x6 },
5209                         { "HP-OUT pin", 0x7 },
5210                 },
5211         },
5212 };
5213 static struct snd_kcontrol_new alc260_test_mixer[] = {
5214         /* Output driver widgets */
5215         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5216         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5217         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5218         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5219         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5220         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5221
5222         /* Modes for retasking pin widgets
5223          * Note: the ALC260 doesn't seem to act on requests to enable mic
5224          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5225          * mention this restriction.  At this stage it's not clear whether
5226          * this behaviour is intentional or is a hardware bug in chip
5227          * revisions available at least up until early 2006.  Therefore for
5228          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5229          * choices, but if it turns out that the lack of mic bias for these
5230          * NIDs is intentional we could change their modes from
5231          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5232          */
5233         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5234         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5235         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5236         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5237         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5238         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5239
5240         /* Loopback mixer controls */
5241         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5242         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5243         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5244         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5245         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5246         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5247         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5248         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5249         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5250         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5251         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
5252         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
5253         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5254         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5255         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5256         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5257
5258         /* Controls for GPIO pins, assuming they are configured as outputs */
5259         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5260         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5261         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5262         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5263
5264         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5265          * is ambigious as to which NID is which; testing on laptops which
5266          * make this output available should provide clarification.
5267          */
5268         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5269         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5270
5271         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5272          * this output to turn on an external amplifier.
5273          */
5274         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5275         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5276
5277         { } /* end */
5278 };
5279 static struct hda_verb alc260_test_init_verbs[] = {
5280         /* Enable all GPIOs as outputs with an initial value of 0 */
5281         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5282         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5283         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5284
5285         /* Enable retasking pins as output, initially without power amp */
5286         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5287         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5288         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5289         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5290         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5291         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5292
5293         /* Disable digital (SPDIF) pins initially, but users can enable
5294          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5295          * payload also sets the generation to 0, output to be in "consumer"
5296          * PCM format, copyright asserted, no pre-emphasis and no validity
5297          * control.
5298          */
5299         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5300         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5301
5302         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5303          * OUT1 sum bus when acting as an output.
5304          */
5305         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5306         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5307         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5308         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5309
5310         /* Start with output sum widgets muted and their output gains at min */
5311         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5312         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5313         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5314         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5315         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5316         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5317         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5318         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5319         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5320
5321         /* Unmute retasking pin widget output buffers since the default
5322          * state appears to be output.  As the pin mode is changed by the
5323          * user the pin mode control will take care of enabling the pin's
5324          * input/output buffers as needed.
5325          */
5326         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5327         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5328         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5329         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5330         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5331         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5332         /* Also unmute the mono-out pin widget */
5333         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5334
5335         /* Mute capture amp left and right */
5336         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5337         /* Set ADC connection select to match default mixer setting (mic1
5338          * pin)
5339          */
5340         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5341
5342         /* Do the same for the second ADC: mute capture input amp and
5343          * set ADC connection to mic1 pin
5344          */
5345         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5346         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5347
5348         /* Mute all inputs to mixer widget (even unconnected ones) */
5349         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5350         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5351         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5352         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5353         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5354         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5355         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5356         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5357
5358         { }
5359 };
5360 #endif
5361
5362 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5363 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5364
5365 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5366 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5367
5368 /*
5369  * for BIOS auto-configuration
5370  */
5371
5372 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5373                                         const char *pfx, int *vol_bits)
5374 {
5375         hda_nid_t nid_vol;
5376         unsigned long vol_val, sw_val;
5377         char name[32];
5378         int err;
5379
5380         if (nid >= 0x0f && nid < 0x11) {
5381                 nid_vol = nid - 0x7;
5382                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5383                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5384         } else if (nid == 0x11) {
5385                 nid_vol = nid - 0x7;
5386                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5387                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5388         } else if (nid >= 0x12 && nid <= 0x15) {
5389                 nid_vol = 0x08;
5390                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5391                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5392         } else
5393                 return 0; /* N/A */
5394
5395         if (!(*vol_bits & (1 << nid_vol))) {
5396                 /* first control for the volume widget */
5397                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5398                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5399                 if (err < 0)
5400                         return err;
5401                 *vol_bits |= (1 << nid_vol);
5402         }
5403         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5404         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5405         if (err < 0)
5406                 return err;
5407         return 1;
5408 }
5409
5410 /* add playback controls from the parsed DAC table */
5411 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5412                                              const struct auto_pin_cfg *cfg)
5413 {
5414         hda_nid_t nid;
5415         int err;
5416         int vols = 0;
5417
5418         spec->multiout.num_dacs = 1;
5419         spec->multiout.dac_nids = spec->private_dac_nids;
5420         spec->multiout.dac_nids[0] = 0x02;
5421
5422         nid = cfg->line_out_pins[0];
5423         if (nid) {
5424                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5425                 if (err < 0)
5426                         return err;
5427         }
5428
5429         nid = cfg->speaker_pins[0];
5430         if (nid) {
5431                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5432                 if (err < 0)
5433                         return err;
5434         }
5435
5436         nid = cfg->hp_pins[0];
5437         if (nid) {
5438                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5439                                                    &vols);
5440                 if (err < 0)
5441                         return err;
5442         }
5443         return 0;
5444 }
5445
5446 /* create playback/capture controls for input pins */
5447 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5448                                                 const struct auto_pin_cfg *cfg)
5449 {
5450         struct hda_input_mux *imux = &spec->private_imux;
5451         int i, err, idx;
5452
5453         for (i = 0; i < AUTO_PIN_LAST; i++) {
5454                 if (cfg->input_pins[i] >= 0x12) {
5455                         idx = cfg->input_pins[i] - 0x12;
5456                         err = new_analog_input(spec, cfg->input_pins[i],
5457                                                auto_pin_cfg_labels[i], idx,
5458                                                0x07);
5459                         if (err < 0)
5460                                 return err;
5461                         imux->items[imux->num_items].label =
5462                                 auto_pin_cfg_labels[i];
5463                         imux->items[imux->num_items].index = idx;
5464                         imux->num_items++;
5465                 }
5466                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5467                         idx = cfg->input_pins[i] - 0x09;
5468                         err = new_analog_input(spec, cfg->input_pins[i],
5469                                                auto_pin_cfg_labels[i], idx,
5470                                                0x07);
5471                         if (err < 0)
5472                                 return err;
5473                         imux->items[imux->num_items].label =
5474                                 auto_pin_cfg_labels[i];
5475                         imux->items[imux->num_items].index = idx;
5476                         imux->num_items++;
5477                 }
5478         }
5479         return 0;
5480 }
5481
5482 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5483                                               hda_nid_t nid, int pin_type,
5484                                               int sel_idx)
5485 {
5486         alc_set_pin_output(codec, nid, pin_type);
5487         /* need the manual connection? */
5488         if (nid >= 0x12) {
5489                 int idx = nid - 0x12;
5490                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5491                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5492         }
5493 }
5494
5495 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5496 {
5497         struct alc_spec *spec = codec->spec;
5498         hda_nid_t nid;
5499
5500         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5501         nid = spec->autocfg.line_out_pins[0];
5502         if (nid) {
5503                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5504                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5505         }
5506
5507         nid = spec->autocfg.speaker_pins[0];
5508         if (nid)
5509                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5510
5511         nid = spec->autocfg.hp_pins[0];
5512         if (nid)
5513                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5514 }
5515
5516 #define ALC260_PIN_CD_NID               0x16
5517 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5518 {
5519         struct alc_spec *spec = codec->spec;
5520         int i;
5521
5522         for (i = 0; i < AUTO_PIN_LAST; i++) {
5523                 hda_nid_t nid = spec->autocfg.input_pins[i];
5524                 if (nid >= 0x12) {
5525                         snd_hda_codec_write(codec, nid, 0,
5526                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5527                                             i <= AUTO_PIN_FRONT_MIC ?
5528                                             PIN_VREF80 : PIN_IN);
5529                         if (nid != ALC260_PIN_CD_NID)
5530                                 snd_hda_codec_write(codec, nid, 0,
5531                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5532                                                     AMP_OUT_MUTE);
5533                 }
5534         }
5535 }
5536
5537 /*
5538  * generic initialization of ADC, input mixers and output mixers
5539  */
5540 static struct hda_verb alc260_volume_init_verbs[] = {
5541         /*
5542          * Unmute ADC0-1 and set the default input to mic-in
5543          */
5544         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5545         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5546         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5547         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5548
5549         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5550          * mixer widget
5551          * Note: PASD motherboards uses the Line In 2 as the input for
5552          * front panel mic (mic 2)
5553          */
5554         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5555         /* mute analog inputs */
5556         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5557         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5558         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5559         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5560         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5561
5562         /*
5563          * Set up output mixers (0x08 - 0x0a)
5564          */
5565         /* set vol=0 to output mixers */
5566         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5567         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5568         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5569         /* set up input amps for analog loopback */
5570         /* Amp Indices: DAC = 0, mixer = 1 */
5571         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5572         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5573         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5574         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5575         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5576         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5577
5578         { }
5579 };
5580
5581 static int alc260_parse_auto_config(struct hda_codec *codec)
5582 {
5583         struct alc_spec *spec = codec->spec;
5584         int err;
5585         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5586
5587         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5588                                            alc260_ignore);
5589         if (err < 0)
5590                 return err;
5591         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5592         if (err < 0)
5593                 return err;
5594         if (!spec->kctls.list)
5595                 return 0; /* can't find valid BIOS pin config */
5596         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5597         if (err < 0)
5598                 return err;
5599
5600         spec->multiout.max_channels = 2;
5601
5602         if (spec->autocfg.dig_out_pin)
5603                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5604         if (spec->kctls.list)
5605                 add_mixer(spec, spec->kctls.list);
5606
5607         add_verb(spec, alc260_volume_init_verbs);
5608
5609         spec->num_mux_defs = 1;
5610         spec->input_mux = &spec->private_imux;
5611
5612         store_pin_configs(codec);
5613         return 1;
5614 }
5615
5616 /* additional initialization for auto-configuration model */
5617 static void alc260_auto_init(struct hda_codec *codec)
5618 {
5619         struct alc_spec *spec = codec->spec;
5620         alc260_auto_init_multi_out(codec);
5621         alc260_auto_init_analog_input(codec);
5622         if (spec->unsol_event)
5623                 alc_inithook(codec);
5624 }
5625
5626 #ifdef CONFIG_SND_HDA_POWER_SAVE
5627 static struct hda_amp_list alc260_loopbacks[] = {
5628         { 0x07, HDA_INPUT, 0 },
5629         { 0x07, HDA_INPUT, 1 },
5630         { 0x07, HDA_INPUT, 2 },
5631         { 0x07, HDA_INPUT, 3 },
5632         { 0x07, HDA_INPUT, 4 },
5633         { } /* end */
5634 };
5635 #endif
5636
5637 /*
5638  * ALC260 configurations
5639  */
5640 static const char *alc260_models[ALC260_MODEL_LAST] = {
5641         [ALC260_BASIC]          = "basic",
5642         [ALC260_HP]             = "hp",
5643         [ALC260_HP_3013]        = "hp-3013",
5644         [ALC260_HP_DC7600]      = "hp-dc7600",
5645         [ALC260_FUJITSU_S702X]  = "fujitsu",
5646         [ALC260_ACER]           = "acer",
5647         [ALC260_WILL]           = "will",
5648         [ALC260_REPLACER_672V]  = "replacer",
5649 #ifdef CONFIG_SND_DEBUG
5650         [ALC260_TEST]           = "test",
5651 #endif
5652         [ALC260_AUTO]           = "auto",
5653 };
5654
5655 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5656         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5657         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5658         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5659         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5660         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5661         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5662         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5663         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5664         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5665         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5666         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5667         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5668         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5669         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5670         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5671         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5672         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5673         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5674         {}
5675 };
5676
5677 static struct alc_config_preset alc260_presets[] = {
5678         [ALC260_BASIC] = {
5679                 .mixers = { alc260_base_output_mixer,
5680                             alc260_input_mixer,
5681                             alc260_pc_beep_mixer },
5682                 .init_verbs = { alc260_init_verbs },
5683                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5684                 .dac_nids = alc260_dac_nids,
5685                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5686                 .adc_nids = alc260_adc_nids,
5687                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5688                 .channel_mode = alc260_modes,
5689                 .input_mux = &alc260_capture_source,
5690         },
5691         [ALC260_HP] = {
5692                 .mixers = { alc260_hp_output_mixer,
5693                             alc260_input_mixer },
5694                 .init_verbs = { alc260_init_verbs,
5695                                 alc260_hp_unsol_verbs },
5696                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5697                 .dac_nids = alc260_dac_nids,
5698                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5699                 .adc_nids = alc260_adc_nids_alt,
5700                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5701                 .channel_mode = alc260_modes,
5702                 .input_mux = &alc260_capture_source,
5703                 .unsol_event = alc260_hp_unsol_event,
5704                 .init_hook = alc260_hp_automute,
5705         },
5706         [ALC260_HP_DC7600] = {
5707                 .mixers = { alc260_hp_dc7600_mixer,
5708                             alc260_input_mixer },
5709                 .init_verbs = { alc260_init_verbs,
5710                                 alc260_hp_dc7600_verbs },
5711                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5712                 .dac_nids = alc260_dac_nids,
5713                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5714                 .adc_nids = alc260_adc_nids_alt,
5715                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5716                 .channel_mode = alc260_modes,
5717                 .input_mux = &alc260_capture_source,
5718                 .unsol_event = alc260_hp_3012_unsol_event,
5719                 .init_hook = alc260_hp_3012_automute,
5720         },
5721         [ALC260_HP_3013] = {
5722                 .mixers = { alc260_hp_3013_mixer,
5723                             alc260_input_mixer },
5724                 .init_verbs = { alc260_hp_3013_init_verbs,
5725                                 alc260_hp_3013_unsol_verbs },
5726                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5727                 .dac_nids = alc260_dac_nids,
5728                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5729                 .adc_nids = alc260_adc_nids_alt,
5730                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5731                 .channel_mode = alc260_modes,
5732                 .input_mux = &alc260_capture_source,
5733                 .unsol_event = alc260_hp_3013_unsol_event,
5734                 .init_hook = alc260_hp_3013_automute,
5735         },
5736         [ALC260_FUJITSU_S702X] = {
5737                 .mixers = { alc260_fujitsu_mixer },
5738                 .init_verbs = { alc260_fujitsu_init_verbs },
5739                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5740                 .dac_nids = alc260_dac_nids,
5741                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5742                 .adc_nids = alc260_dual_adc_nids,
5743                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5744                 .channel_mode = alc260_modes,
5745                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5746                 .input_mux = alc260_fujitsu_capture_sources,
5747         },
5748         [ALC260_ACER] = {
5749                 .mixers = { alc260_acer_mixer },
5750                 .init_verbs = { alc260_acer_init_verbs },
5751                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5752                 .dac_nids = alc260_dac_nids,
5753                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5754                 .adc_nids = alc260_dual_adc_nids,
5755                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5756                 .channel_mode = alc260_modes,
5757                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5758                 .input_mux = alc260_acer_capture_sources,
5759         },
5760         [ALC260_WILL] = {
5761                 .mixers = { alc260_will_mixer },
5762                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5763                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5764                 .dac_nids = alc260_dac_nids,
5765                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5766                 .adc_nids = alc260_adc_nids,
5767                 .dig_out_nid = ALC260_DIGOUT_NID,
5768                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5769                 .channel_mode = alc260_modes,
5770                 .input_mux = &alc260_capture_source,
5771         },
5772         [ALC260_REPLACER_672V] = {
5773                 .mixers = { alc260_replacer_672v_mixer },
5774                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5775                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5776                 .dac_nids = alc260_dac_nids,
5777                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5778                 .adc_nids = alc260_adc_nids,
5779                 .dig_out_nid = ALC260_DIGOUT_NID,
5780                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5781                 .channel_mode = alc260_modes,
5782                 .input_mux = &alc260_capture_source,
5783                 .unsol_event = alc260_replacer_672v_unsol_event,
5784                 .init_hook = alc260_replacer_672v_automute,
5785         },
5786 #ifdef CONFIG_SND_DEBUG
5787         [ALC260_TEST] = {
5788                 .mixers = { alc260_test_mixer },
5789                 .init_verbs = { alc260_test_init_verbs },
5790                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5791                 .dac_nids = alc260_test_dac_nids,
5792                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5793                 .adc_nids = alc260_test_adc_nids,
5794                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5795                 .channel_mode = alc260_modes,
5796                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5797                 .input_mux = alc260_test_capture_sources,
5798         },
5799 #endif
5800 };
5801
5802 static int patch_alc260(struct hda_codec *codec)
5803 {
5804         struct alc_spec *spec;
5805         int err, board_config;
5806
5807         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5808         if (spec == NULL)
5809                 return -ENOMEM;
5810
5811         codec->spec = spec;
5812
5813         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5814                                                   alc260_models,
5815                                                   alc260_cfg_tbl);
5816         if (board_config < 0) {
5817                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5818                            "trying auto-probe from BIOS...\n");
5819                 board_config = ALC260_AUTO;
5820         }
5821
5822         if (board_config == ALC260_AUTO) {
5823                 /* automatic parse from the BIOS config */
5824                 err = alc260_parse_auto_config(codec);
5825                 if (err < 0) {
5826                         alc_free(codec);
5827                         return err;
5828                 } else if (!err) {
5829                         printk(KERN_INFO
5830                                "hda_codec: Cannot set up configuration "
5831                                "from BIOS.  Using base mode...\n");
5832                         board_config = ALC260_BASIC;
5833                 }
5834         }
5835
5836         if (board_config != ALC260_AUTO)
5837                 setup_preset(spec, &alc260_presets[board_config]);
5838
5839         spec->stream_name_analog = "ALC260 Analog";
5840         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5841         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5842
5843         spec->stream_name_digital = "ALC260 Digital";
5844         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5845         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5846
5847         if (!spec->adc_nids && spec->input_mux) {
5848                 /* check whether NID 0x04 is valid */
5849                 unsigned int wcap = get_wcaps(codec, 0x04);
5850                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5851                 /* get type */
5852                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5853                         spec->adc_nids = alc260_adc_nids_alt;
5854                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5855                 } else {
5856                         spec->adc_nids = alc260_adc_nids;
5857                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5858                 }
5859         }
5860         set_capture_mixer(spec);
5861
5862         spec->vmaster_nid = 0x08;
5863
5864         codec->patch_ops = alc_patch_ops;
5865         if (board_config == ALC260_AUTO)
5866                 spec->init_hook = alc260_auto_init;
5867 #ifdef CONFIG_SND_HDA_POWER_SAVE
5868         if (!spec->loopback.amplist)
5869                 spec->loopback.amplist = alc260_loopbacks;
5870 #endif
5871
5872         return 0;
5873 }
5874
5875
5876 /*
5877  * ALC882 support
5878  *
5879  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5880  * configuration.  Each pin widget can choose any input DACs and a mixer.
5881  * Each ADC is connected from a mixer of all inputs.  This makes possible
5882  * 6-channel independent captures.
5883  *
5884  * In addition, an independent DAC for the multi-playback (not used in this
5885  * driver yet).
5886  */
5887 #define ALC882_DIGOUT_NID       0x06
5888 #define ALC882_DIGIN_NID        0x0a
5889
5890 static struct hda_channel_mode alc882_ch_modes[1] = {
5891         { 8, NULL }
5892 };
5893
5894 static hda_nid_t alc882_dac_nids[4] = {
5895         /* front, rear, clfe, rear_surr */
5896         0x02, 0x03, 0x04, 0x05
5897 };
5898
5899 /* identical with ALC880 */
5900 #define alc882_adc_nids         alc880_adc_nids
5901 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5902
5903 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5904 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5905
5906 /* input MUX */
5907 /* FIXME: should be a matrix-type input source selection */
5908
5909 static struct hda_input_mux alc882_capture_source = {
5910         .num_items = 4,
5911         .items = {
5912                 { "Mic", 0x0 },
5913                 { "Front Mic", 0x1 },
5914                 { "Line", 0x2 },
5915                 { "CD", 0x4 },
5916         },
5917 };
5918 /*
5919  * 2ch mode
5920  */
5921 static struct hda_verb alc882_3ST_ch2_init[] = {
5922         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5923         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5924         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5925         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5926         { } /* end */
5927 };
5928
5929 /*
5930  * 6ch mode
5931  */
5932 static struct hda_verb alc882_3ST_ch6_init[] = {
5933         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5934         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5935         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5936         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5937         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5938         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5939         { } /* end */
5940 };
5941
5942 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5943         { 2, alc882_3ST_ch2_init },
5944         { 6, alc882_3ST_ch6_init },
5945 };
5946
5947 /*
5948  * 6ch mode
5949  */
5950 static struct hda_verb alc882_sixstack_ch6_init[] = {
5951         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5952         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5953         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5954         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5955         { } /* end */
5956 };
5957
5958 /*
5959  * 8ch mode
5960  */
5961 static struct hda_verb alc882_sixstack_ch8_init[] = {
5962         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5963         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5964         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5965         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5966         { } /* end */
5967 };
5968
5969 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5970         { 6, alc882_sixstack_ch6_init },
5971         { 8, alc882_sixstack_ch8_init },
5972 };
5973
5974 /*
5975  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5976  */
5977
5978 /*
5979  * 2ch mode
5980  */
5981 static struct hda_verb alc885_mbp_ch2_init[] = {
5982         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5983         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5984         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5985         { } /* end */
5986 };
5987
5988 /*
5989  * 6ch mode
5990  */
5991 static struct hda_verb alc885_mbp_ch6_init[] = {
5992         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5993         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5994         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5995         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5996         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5997         { } /* end */
5998 };
5999
6000 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
6001         { 2, alc885_mbp_ch2_init },
6002         { 6, alc885_mbp_ch6_init },
6003 };
6004
6005
6006 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6007  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6008  */
6009 static struct snd_kcontrol_new alc882_base_mixer[] = {
6010         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6011         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6012         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6013         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6014         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6015         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6016         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6017         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6018         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6019         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6020         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6021         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6022         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6023         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6024         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6025         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6026         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6027         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6028         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6029         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6030         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6031         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6032         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6033         { } /* end */
6034 };
6035
6036 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6037         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6038         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6039         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
6040         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6041         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6042         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6043         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
6044         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
6045         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
6046         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
6047         { } /* end */
6048 };
6049 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6050         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6051         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6052         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6053         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6054         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6055         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6056         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6057         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6058         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6059         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6060         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6061         { } /* end */
6062 };
6063
6064 static struct snd_kcontrol_new alc882_targa_mixer[] = {
6065         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6066         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6067         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6068         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6069         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6070         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6071         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6072         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6073         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6074         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6075         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6076         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6077         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6078         { } /* end */
6079 };
6080
6081 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
6082  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
6083  */
6084 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
6085         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6086         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6087         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6088         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
6089         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6090         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6091         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6092         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6093         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
6094         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
6095         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6096         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6097         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6098         { } /* end */
6099 };
6100
6101 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6102         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6103         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6104         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6105         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6106         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6107         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6108         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6109         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6110         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6111         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6112         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6113         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6114         { } /* end */
6115 };
6116
6117 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6118         {
6119                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6120                 .name = "Channel Mode",
6121                 .info = alc_ch_mode_info,
6122                 .get = alc_ch_mode_get,
6123                 .put = alc_ch_mode_put,
6124         },
6125         { } /* end */
6126 };
6127
6128 static struct hda_verb alc882_init_verbs[] = {
6129         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6130         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6131         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6132         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6133         /* Rear mixer */
6134         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6135         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6136         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6137         /* CLFE mixer */
6138         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6139         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6140         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6141         /* Side mixer */
6142         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6143         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6144         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6145
6146         /* Front Pin: output 0 (0x0c) */
6147         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6148         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6149         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6150         /* Rear Pin: output 1 (0x0d) */
6151         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6152         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6153         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6154         /* CLFE Pin: output 2 (0x0e) */
6155         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6156         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6157         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6158         /* Side Pin: output 3 (0x0f) */
6159         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6160         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6161         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6162         /* Mic (rear) pin: input vref at 80% */
6163         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6164         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6165         /* Front Mic pin: input vref at 80% */
6166         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6167         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6168         /* Line In pin: input */
6169         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6170         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6171         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6172         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6173         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6174         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6175         /* CD pin widget for input */
6176         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6177
6178         /* FIXME: use matrix-type input source selection */
6179         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6180         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6181         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6182         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6183         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6184         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6185         /* Input mixer2 */
6186         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6187         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6188         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6189         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6190         /* Input mixer3 */
6191         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6192         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6193         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6194         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6195         /* ADC1: mute amp left and right */
6196         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6197         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6198         /* ADC2: mute amp left and right */
6199         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6200         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6201         /* ADC3: mute amp left and right */
6202         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6203         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6204
6205         { }
6206 };
6207
6208 static struct hda_verb alc882_eapd_verbs[] = {
6209         /* change to EAPD mode */
6210         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6211         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
6212         { }
6213 };
6214
6215 /* Mac Pro test */
6216 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6217         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6218         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6219         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6220         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6221         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6222         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6223         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6224         { } /* end */
6225 };
6226
6227 static struct hda_verb alc882_macpro_init_verbs[] = {
6228         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6229         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6230         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6231         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6232         /* Front Pin: output 0 (0x0c) */
6233         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6234         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6235         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6236         /* Front Mic pin: input vref at 80% */
6237         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6238         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6239         /* Speaker:  output */
6240         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6241         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6242         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6243         /* Headphone output (output 0 - 0x0c) */
6244         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6245         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6246         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6247
6248         /* FIXME: use matrix-type input source selection */
6249         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6250         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6251         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6252         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6253         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6254         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6255         /* Input mixer2 */
6256         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6257         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6258         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6259         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6260         /* Input mixer3 */
6261         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6262         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6263         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6264         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6265         /* ADC1: mute amp left and right */
6266         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6267         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6268         /* ADC2: mute amp left and right */
6269         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6270         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6271         /* ADC3: mute amp left and right */
6272         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6273         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6274
6275         { }
6276 };
6277
6278 /* Macbook Pro rev3 */
6279 static struct hda_verb alc885_mbp3_init_verbs[] = {
6280         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6281         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6282         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6283         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6284         /* Rear mixer */
6285         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6286         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6287         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6288         /* Front Pin: output 0 (0x0c) */
6289         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6290         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6291         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6292         /* HP Pin: output 0 (0x0d) */
6293         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6294         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6295         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6296         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6297         /* Mic (rear) pin: input vref at 80% */
6298         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6299         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6300         /* Front Mic pin: input vref at 80% */
6301         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6302         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6303         /* Line In pin: use output 1 when in LineOut mode */
6304         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6305         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6306         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6307
6308         /* FIXME: use matrix-type input source selection */
6309         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6310         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6311         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6312         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6313         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6314         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6315         /* Input mixer2 */
6316         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6317         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6318         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6319         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6320         /* Input mixer3 */
6321         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6322         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6323         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6324         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6325         /* ADC1: mute amp left and right */
6326         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6327         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6328         /* ADC2: mute amp left and right */
6329         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6330         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6331         /* ADC3: mute amp left and right */
6332         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6333         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6334
6335         { }
6336 };
6337
6338 /* iMac 24 mixer. */
6339 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6340         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6341         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6342         { } /* end */
6343 };
6344
6345 /* iMac 24 init verbs. */
6346 static struct hda_verb alc885_imac24_init_verbs[] = {
6347         /* Internal speakers: output 0 (0x0c) */
6348         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6349         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6350         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6351         /* Internal speakers: output 0 (0x0c) */
6352         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6353         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6354         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6355         /* Headphone: output 0 (0x0c) */
6356         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6357         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6358         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6359         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6360         /* Front Mic: input vref at 80% */
6361         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6362         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6363         { }
6364 };
6365
6366 /* Toggle speaker-output according to the hp-jack state */
6367 static void alc885_imac24_automute(struct hda_codec *codec)
6368 {
6369         unsigned int present;
6370
6371         present = snd_hda_codec_read(codec, 0x14, 0,
6372                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6373         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6374                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6375         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6376                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6377 }
6378
6379 /* Processes unsolicited events. */
6380 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6381                                       unsigned int res)
6382 {
6383         /* Headphone insertion or removal. */
6384         if ((res >> 26) == ALC880_HP_EVENT)
6385                 alc885_imac24_automute(codec);
6386 }
6387
6388 static void alc885_mbp3_automute(struct hda_codec *codec)
6389 {
6390         unsigned int present;
6391
6392         present = snd_hda_codec_read(codec, 0x15, 0,
6393                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6394         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6395                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6396         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6397                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6398
6399 }
6400 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6401                                     unsigned int res)
6402 {
6403         /* Headphone insertion or removal. */
6404         if ((res >> 26) == ALC880_HP_EVENT)
6405                 alc885_mbp3_automute(codec);
6406 }
6407
6408
6409 static struct hda_verb alc882_targa_verbs[] = {
6410         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6411         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6412
6413         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6414         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6415
6416         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6417         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6418         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6419
6420         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6421         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6422         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6423         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6424         { } /* end */
6425 };
6426
6427 /* toggle speaker-output according to the hp-jack state */
6428 static void alc882_targa_automute(struct hda_codec *codec)
6429 {
6430         unsigned int present;
6431
6432         present = snd_hda_codec_read(codec, 0x14, 0,
6433                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6434         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6435                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6436         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6437                                   present ? 1 : 3);
6438 }
6439
6440 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6441 {
6442         /* Looks like the unsol event is incompatible with the standard
6443          * definition.  4bit tag is placed at 26 bit!
6444          */
6445         if (((res >> 26) == ALC880_HP_EVENT)) {
6446                 alc882_targa_automute(codec);
6447         }
6448 }
6449
6450 static struct hda_verb alc882_asus_a7j_verbs[] = {
6451         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6452         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6453
6454         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6455         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6456         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6457
6458         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6459         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6460         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6461
6462         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6463         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6464         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6465         { } /* end */
6466 };
6467
6468 static struct hda_verb alc882_asus_a7m_verbs[] = {
6469         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6470         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6471
6472         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6473         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6474         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6475
6476         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6477         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6478         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6479
6480         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6481         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6482         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6483         { } /* end */
6484 };
6485
6486 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6487 {
6488         unsigned int gpiostate, gpiomask, gpiodir;
6489
6490         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6491                                        AC_VERB_GET_GPIO_DATA, 0);
6492
6493         if (!muted)
6494                 gpiostate |= (1 << pin);
6495         else
6496                 gpiostate &= ~(1 << pin);
6497
6498         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6499                                       AC_VERB_GET_GPIO_MASK, 0);
6500         gpiomask |= (1 << pin);
6501
6502         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6503                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6504         gpiodir |= (1 << pin);
6505
6506
6507         snd_hda_codec_write(codec, codec->afg, 0,
6508                             AC_VERB_SET_GPIO_MASK, gpiomask);
6509         snd_hda_codec_write(codec, codec->afg, 0,
6510                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6511
6512         msleep(1);
6513
6514         snd_hda_codec_write(codec, codec->afg, 0,
6515                             AC_VERB_SET_GPIO_DATA, gpiostate);
6516 }
6517
6518 /* set up GPIO at initialization */
6519 static void alc885_macpro_init_hook(struct hda_codec *codec)
6520 {
6521         alc882_gpio_mute(codec, 0, 0);
6522         alc882_gpio_mute(codec, 1, 0);
6523 }
6524
6525 /* set up GPIO and update auto-muting at initialization */
6526 static void alc885_imac24_init_hook(struct hda_codec *codec)
6527 {
6528         alc885_macpro_init_hook(codec);
6529         alc885_imac24_automute(codec);
6530 }
6531
6532 /*
6533  * generic initialization of ADC, input mixers and output mixers
6534  */
6535 static struct hda_verb alc882_auto_init_verbs[] = {
6536         /*
6537          * Unmute ADC0-2 and set the default input to mic-in
6538          */
6539         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6540         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6541         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6542         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6543         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6544         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6545
6546         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6547          * mixer widget
6548          * Note: PASD motherboards uses the Line In 2 as the input for
6549          * front panel mic (mic 2)
6550          */
6551         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6552         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6553         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6554         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6555         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6556         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6557
6558         /*
6559          * Set up output mixers (0x0c - 0x0f)
6560          */
6561         /* set vol=0 to output mixers */
6562         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6563         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6564         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6565         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6566         /* set up input amps for analog loopback */
6567         /* Amp Indices: DAC = 0, mixer = 1 */
6568         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6569         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6570         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6571         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6572         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6573         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6574         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6575         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6576         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6577         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6578
6579         /* FIXME: use matrix-type input source selection */
6580         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6581         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6582         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6583         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6584         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6585         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6586         /* Input mixer2 */
6587         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6588         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6589         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6590         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6591         /* Input mixer3 */
6592         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6593         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6594         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6595         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6596
6597         { }
6598 };
6599
6600 #ifdef CONFIG_SND_HDA_POWER_SAVE
6601 #define alc882_loopbacks        alc880_loopbacks
6602 #endif
6603
6604 /* pcm configuration: identiacal with ALC880 */
6605 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6606 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6607 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6608 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6609
6610 /*
6611  * configuration and preset
6612  */
6613 static const char *alc882_models[ALC882_MODEL_LAST] = {
6614         [ALC882_3ST_DIG]        = "3stack-dig",
6615         [ALC882_6ST_DIG]        = "6stack-dig",
6616         [ALC882_ARIMA]          = "arima",
6617         [ALC882_W2JC]           = "w2jc",
6618         [ALC882_TARGA]          = "targa",
6619         [ALC882_ASUS_A7J]       = "asus-a7j",
6620         [ALC882_ASUS_A7M]       = "asus-a7m",
6621         [ALC885_MACPRO]         = "macpro",
6622         [ALC885_MBP3]           = "mbp3",
6623         [ALC885_IMAC24]         = "imac24",
6624         [ALC882_AUTO]           = "auto",
6625 };
6626
6627 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6628         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6629         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6630         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6631         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6632         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6633         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6634         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6635         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6636         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6637         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6638         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6639         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6640         {}
6641 };
6642
6643 static struct alc_config_preset alc882_presets[] = {
6644         [ALC882_3ST_DIG] = {
6645                 .mixers = { alc882_base_mixer },
6646                 .init_verbs = { alc882_init_verbs },
6647                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6648                 .dac_nids = alc882_dac_nids,
6649                 .dig_out_nid = ALC882_DIGOUT_NID,
6650                 .dig_in_nid = ALC882_DIGIN_NID,
6651                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6652                 .channel_mode = alc882_ch_modes,
6653                 .need_dac_fix = 1,
6654                 .input_mux = &alc882_capture_source,
6655         },
6656         [ALC882_6ST_DIG] = {
6657                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6658                 .init_verbs = { alc882_init_verbs },
6659                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6660                 .dac_nids = alc882_dac_nids,
6661                 .dig_out_nid = ALC882_DIGOUT_NID,
6662                 .dig_in_nid = ALC882_DIGIN_NID,
6663                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6664                 .channel_mode = alc882_sixstack_modes,
6665                 .input_mux = &alc882_capture_source,
6666         },
6667         [ALC882_ARIMA] = {
6668                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6669                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6670                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6671                 .dac_nids = alc882_dac_nids,
6672                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6673                 .channel_mode = alc882_sixstack_modes,
6674                 .input_mux = &alc882_capture_source,
6675         },
6676         [ALC882_W2JC] = {
6677                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6678                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6679                                 alc880_gpio1_init_verbs },
6680                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6681                 .dac_nids = alc882_dac_nids,
6682                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6683                 .channel_mode = alc880_threestack_modes,
6684                 .need_dac_fix = 1,
6685                 .input_mux = &alc882_capture_source,
6686                 .dig_out_nid = ALC882_DIGOUT_NID,
6687         },
6688         [ALC885_MBP3] = {
6689                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6690                 .init_verbs = { alc885_mbp3_init_verbs,
6691                                 alc880_gpio1_init_verbs },
6692                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6693                 .dac_nids = alc882_dac_nids,
6694                 .channel_mode = alc885_mbp_6ch_modes,
6695                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6696                 .input_mux = &alc882_capture_source,
6697                 .dig_out_nid = ALC882_DIGOUT_NID,
6698                 .dig_in_nid = ALC882_DIGIN_NID,
6699                 .unsol_event = alc885_mbp3_unsol_event,
6700                 .init_hook = alc885_mbp3_automute,
6701         },
6702         [ALC885_MACPRO] = {
6703                 .mixers = { alc882_macpro_mixer },
6704                 .init_verbs = { alc882_macpro_init_verbs },
6705                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6706                 .dac_nids = alc882_dac_nids,
6707                 .dig_out_nid = ALC882_DIGOUT_NID,
6708                 .dig_in_nid = ALC882_DIGIN_NID,
6709                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6710                 .channel_mode = alc882_ch_modes,
6711                 .input_mux = &alc882_capture_source,
6712                 .init_hook = alc885_macpro_init_hook,
6713         },
6714         [ALC885_IMAC24] = {
6715                 .mixers = { alc885_imac24_mixer },
6716                 .init_verbs = { alc885_imac24_init_verbs },
6717                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6718                 .dac_nids = alc882_dac_nids,
6719                 .dig_out_nid = ALC882_DIGOUT_NID,
6720                 .dig_in_nid = ALC882_DIGIN_NID,
6721                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6722                 .channel_mode = alc882_ch_modes,
6723                 .input_mux = &alc882_capture_source,
6724                 .unsol_event = alc885_imac24_unsol_event,
6725                 .init_hook = alc885_imac24_init_hook,
6726         },
6727         [ALC882_TARGA] = {
6728                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
6729                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6730                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6731                 .dac_nids = alc882_dac_nids,
6732                 .dig_out_nid = ALC882_DIGOUT_NID,
6733                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6734                 .adc_nids = alc882_adc_nids,
6735                 .capsrc_nids = alc882_capsrc_nids,
6736                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6737                 .channel_mode = alc882_3ST_6ch_modes,
6738                 .need_dac_fix = 1,
6739                 .input_mux = &alc882_capture_source,
6740                 .unsol_event = alc882_targa_unsol_event,
6741                 .init_hook = alc882_targa_automute,
6742         },
6743         [ALC882_ASUS_A7J] = {
6744                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
6745                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6746                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6747                 .dac_nids = alc882_dac_nids,
6748                 .dig_out_nid = ALC882_DIGOUT_NID,
6749                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6750                 .adc_nids = alc882_adc_nids,
6751                 .capsrc_nids = alc882_capsrc_nids,
6752                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6753                 .channel_mode = alc882_3ST_6ch_modes,
6754                 .need_dac_fix = 1,
6755                 .input_mux = &alc882_capture_source,
6756         },
6757         [ALC882_ASUS_A7M] = {
6758                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6759                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6760                                 alc880_gpio1_init_verbs,
6761                                 alc882_asus_a7m_verbs },
6762                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6763                 .dac_nids = alc882_dac_nids,
6764                 .dig_out_nid = ALC882_DIGOUT_NID,
6765                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6766                 .channel_mode = alc880_threestack_modes,
6767                 .need_dac_fix = 1,
6768                 .input_mux = &alc882_capture_source,
6769         },
6770 };
6771
6772
6773 /*
6774  * Pin config fixes
6775  */
6776 enum {
6777         PINFIX_ABIT_AW9D_MAX
6778 };
6779
6780 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6781         { 0x15, 0x01080104 }, /* side */
6782         { 0x16, 0x01011012 }, /* rear */
6783         { 0x17, 0x01016011 }, /* clfe */
6784         { }
6785 };
6786
6787 static const struct alc_pincfg *alc882_pin_fixes[] = {
6788         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6789 };
6790
6791 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6792         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6793         {}
6794 };
6795
6796 /*
6797  * BIOS auto configuration
6798  */
6799 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6800                                               hda_nid_t nid, int pin_type,
6801                                               int dac_idx)
6802 {
6803         /* set as output */
6804         struct alc_spec *spec = codec->spec;
6805         int idx;
6806
6807         alc_set_pin_output(codec, nid, pin_type);
6808         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6809                 idx = 4;
6810         else
6811                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6812         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6813
6814 }
6815
6816 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6817 {
6818         struct alc_spec *spec = codec->spec;
6819         int i;
6820
6821         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6822         for (i = 0; i <= HDA_SIDE; i++) {
6823                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6824                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6825                 if (nid)
6826                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6827                                                           i);
6828         }
6829 }
6830
6831 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6832 {
6833         struct alc_spec *spec = codec->spec;
6834         hda_nid_t pin;
6835
6836         pin = spec->autocfg.hp_pins[0];
6837         if (pin) /* connect to front */
6838                 /* use dac 0 */
6839                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6840         pin = spec->autocfg.speaker_pins[0];
6841         if (pin)
6842                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6843 }
6844
6845 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6846 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6847
6848 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6849 {
6850         struct alc_spec *spec = codec->spec;
6851         int i;
6852
6853         for (i = 0; i < AUTO_PIN_LAST; i++) {
6854                 hda_nid_t nid = spec->autocfg.input_pins[i];
6855                 unsigned int vref;
6856                 if (!nid)
6857                         continue;
6858                 vref = PIN_IN;
6859                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6860                         unsigned int pincap;
6861                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6862                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6863                             AC_PINCAP_VREF_80)
6864                                 vref = PIN_VREF80;
6865                 }
6866                 snd_hda_codec_write(codec, nid, 0,
6867                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6868                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6869                         snd_hda_codec_write(codec, nid, 0,
6870                                             AC_VERB_SET_AMP_GAIN_MUTE,
6871                                             AMP_OUT_MUTE);
6872         }
6873 }
6874
6875 static void alc882_auto_init_input_src(struct hda_codec *codec)
6876 {
6877         struct alc_spec *spec = codec->spec;
6878         const struct hda_input_mux *imux = spec->input_mux;
6879         int c;
6880
6881         for (c = 0; c < spec->num_adc_nids; c++) {
6882                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6883                 hda_nid_t nid = spec->capsrc_nids[c];
6884                 int conns, mute, idx, item;
6885
6886                 conns = snd_hda_get_connections(codec, nid, conn_list,
6887                                                 ARRAY_SIZE(conn_list));
6888                 if (conns < 0)
6889                         continue;
6890                 for (idx = 0; idx < conns; idx++) {
6891                         /* if the current connection is the selected one,
6892                          * unmute it as default - otherwise mute it
6893                          */
6894                         mute = AMP_IN_MUTE(idx);
6895                         for (item = 0; item < imux->num_items; item++) {
6896                                 if (imux->items[item].index == idx) {
6897                                         if (spec->cur_mux[c] == item)
6898                                                 mute = AMP_IN_UNMUTE(idx);
6899                                         break;
6900                                 }
6901                         }
6902                         snd_hda_codec_write(codec, nid, 0,
6903                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6904                 }
6905         }
6906 }
6907
6908 /* add mic boosts if needed */
6909 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6910 {
6911         struct alc_spec *spec = codec->spec;
6912         int err;
6913         hda_nid_t nid;
6914
6915         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6916         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6917                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6918                                   "Mic Boost",
6919                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6920                 if (err < 0)
6921                         return err;
6922         }
6923         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6924         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6925                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6926                                   "Front Mic Boost",
6927                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6928                 if (err < 0)
6929                         return err;
6930         }
6931         return 0;
6932 }
6933
6934 /* almost identical with ALC880 parser... */
6935 static int alc882_parse_auto_config(struct hda_codec *codec)
6936 {
6937         struct alc_spec *spec = codec->spec;
6938         int err = alc880_parse_auto_config(codec);
6939
6940         if (err < 0)
6941                 return err;
6942         else if (!err)
6943                 return 0; /* no config found */
6944
6945         err = alc_auto_add_mic_boost(codec);
6946         if (err < 0)
6947                 return err;
6948
6949         /* hack - override the init verbs */
6950         spec->init_verbs[0] = alc882_auto_init_verbs;
6951
6952         return 1; /* config found */
6953 }
6954
6955 /* additional initialization for auto-configuration model */
6956 static void alc882_auto_init(struct hda_codec *codec)
6957 {
6958         struct alc_spec *spec = codec->spec;
6959         alc882_auto_init_multi_out(codec);
6960         alc882_auto_init_hp_out(codec);
6961         alc882_auto_init_analog_input(codec);
6962         alc882_auto_init_input_src(codec);
6963         if (spec->unsol_event)
6964                 alc_inithook(codec);
6965 }
6966
6967 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6968
6969 static int patch_alc882(struct hda_codec *codec)
6970 {
6971         struct alc_spec *spec;
6972         int err, board_config;
6973
6974         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6975         if (spec == NULL)
6976                 return -ENOMEM;
6977
6978         codec->spec = spec;
6979
6980         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6981                                                   alc882_models,
6982                                                   alc882_cfg_tbl);
6983
6984         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6985                 /* Pick up systems that don't supply PCI SSID */
6986                 switch (codec->subsystem_id) {
6987                 case 0x106b0c00: /* Mac Pro */
6988                         board_config = ALC885_MACPRO;
6989                         break;
6990                 case 0x106b1000: /* iMac 24 */
6991                 case 0x106b2800: /* AppleTV */
6992                         board_config = ALC885_IMAC24;
6993                         break;
6994                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
6995                 case 0x106b00a4: /* MacbookPro4,1 */
6996                 case 0x106b2c00: /* Macbook Pro rev3 */
6997                 case 0x106b3600: /* Macbook 3.1 */
6998                         board_config = ALC885_MBP3;
6999                         break;
7000                 default:
7001                         /* ALC889A is handled better as ALC888-compatible */
7002                         if (codec->revision_id == 0x100101 ||
7003                             codec->revision_id == 0x100103) {
7004                                 alc_free(codec);
7005                                 return patch_alc883(codec);
7006                         }
7007                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
7008                                          "trying auto-probe from BIOS...\n");
7009                         board_config = ALC882_AUTO;
7010                 }
7011         }
7012
7013         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7014
7015         if (board_config == ALC882_AUTO) {
7016                 /* automatic parse from the BIOS config */
7017                 err = alc882_parse_auto_config(codec);
7018                 if (err < 0) {
7019                         alc_free(codec);
7020                         return err;
7021                 } else if (!err) {
7022                         printk(KERN_INFO
7023                                "hda_codec: Cannot set up configuration "
7024                                "from BIOS.  Using base mode...\n");
7025                         board_config = ALC882_3ST_DIG;
7026                 }
7027         }
7028
7029         if (board_config != ALC882_AUTO)
7030                 setup_preset(spec, &alc882_presets[board_config]);
7031
7032         if (codec->vendor_id == 0x10ec0885) {
7033                 spec->stream_name_analog = "ALC885 Analog";
7034                 spec->stream_name_digital = "ALC885 Digital";
7035         } else {
7036                 spec->stream_name_analog = "ALC882 Analog";
7037                 spec->stream_name_digital = "ALC882 Digital";
7038         }
7039
7040         spec->stream_analog_playback = &alc882_pcm_analog_playback;
7041         spec->stream_analog_capture = &alc882_pcm_analog_capture;
7042         /* FIXME: setup DAC5 */
7043         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7044         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7045
7046         spec->stream_digital_playback = &alc882_pcm_digital_playback;
7047         spec->stream_digital_capture = &alc882_pcm_digital_capture;
7048
7049         spec->is_mix_capture = 1; /* matrix-style capture */
7050         if (!spec->adc_nids && spec->input_mux) {
7051                 /* check whether NID 0x07 is valid */
7052                 unsigned int wcap = get_wcaps(codec, 0x07);
7053                 /* get type */
7054                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7055                 if (wcap != AC_WID_AUD_IN) {
7056                         spec->adc_nids = alc882_adc_nids_alt;
7057                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7058                         spec->capsrc_nids = alc882_capsrc_nids_alt;
7059                 } else {
7060                         spec->adc_nids = alc882_adc_nids;
7061                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7062                         spec->capsrc_nids = alc882_capsrc_nids;
7063                 }
7064         }
7065         set_capture_mixer(spec);
7066
7067         spec->vmaster_nid = 0x0c;
7068
7069         codec->patch_ops = alc_patch_ops;
7070         if (board_config == ALC882_AUTO)
7071                 spec->init_hook = alc882_auto_init;
7072 #ifdef CONFIG_SND_HDA_POWER_SAVE
7073         if (!spec->loopback.amplist)
7074                 spec->loopback.amplist = alc882_loopbacks;
7075 #endif
7076
7077         return 0;
7078 }
7079
7080 /*
7081  * ALC883 support
7082  *
7083  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7084  * configuration.  Each pin widget can choose any input DACs and a mixer.
7085  * Each ADC is connected from a mixer of all inputs.  This makes possible
7086  * 6-channel independent captures.
7087  *
7088  * In addition, an independent DAC for the multi-playback (not used in this
7089  * driver yet).
7090  */
7091 #define ALC883_DIGOUT_NID       0x06
7092 #define ALC883_DIGIN_NID        0x0a
7093
7094 #define ALC1200_DIGOUT_NID      0x10
7095
7096 static hda_nid_t alc883_dac_nids[4] = {
7097         /* front, rear, clfe, rear_surr */
7098         0x02, 0x03, 0x04, 0x05
7099 };
7100
7101 static hda_nid_t alc883_adc_nids[2] = {
7102         /* ADC1-2 */
7103         0x08, 0x09,
7104 };
7105
7106 static hda_nid_t alc883_adc_nids_alt[1] = {
7107         /* ADC1 */
7108         0x08,
7109 };
7110
7111 static hda_nid_t alc883_adc_nids_rev[2] = {
7112         /* ADC2-1 */
7113         0x09, 0x08
7114 };
7115
7116 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7117
7118 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7119
7120 /* input MUX */
7121 /* FIXME: should be a matrix-type input source selection */
7122
7123 static struct hda_input_mux alc883_capture_source = {
7124         .num_items = 4,
7125         .items = {
7126                 { "Mic", 0x0 },
7127                 { "Front Mic", 0x1 },
7128                 { "Line", 0x2 },
7129                 { "CD", 0x4 },
7130         },
7131 };
7132
7133 static struct hda_input_mux alc883_3stack_6ch_intel = {
7134         .num_items = 4,
7135         .items = {
7136                 { "Mic", 0x1 },
7137                 { "Front Mic", 0x0 },
7138                 { "Line", 0x2 },
7139                 { "CD", 0x4 },
7140         },
7141 };
7142
7143 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7144         .num_items = 2,
7145         .items = {
7146                 { "Mic", 0x1 },
7147                 { "Line", 0x2 },
7148         },
7149 };
7150
7151 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7152         .num_items = 4,
7153         .items = {
7154                 { "Mic", 0x0 },
7155                 { "iMic", 0x1 },
7156                 { "Line", 0x2 },
7157                 { "CD", 0x4 },
7158         },
7159 };
7160
7161 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7162         .num_items = 2,
7163         .items = {
7164                 { "Mic", 0x0 },
7165                 { "Int Mic", 0x1 },
7166         },
7167 };
7168
7169 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7170         .num_items = 3,
7171         .items = {
7172                 { "Mic", 0x0 },
7173                 { "Front Mic", 0x1 },
7174                 { "Line", 0x4 },
7175         },
7176 };
7177
7178 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7179         .num_items = 2,
7180         .items = {
7181                 { "Mic", 0x0 },
7182                 { "Line", 0x2 },
7183         },
7184 };
7185
7186 /*
7187  * 2ch mode
7188  */
7189 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7190         { 2, NULL }
7191 };
7192
7193 /*
7194  * 2ch mode
7195  */
7196 static struct hda_verb alc883_3ST_ch2_init[] = {
7197         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7198         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7199         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7200         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7201         { } /* end */
7202 };
7203
7204 /*
7205  * 4ch mode
7206  */
7207 static struct hda_verb alc883_3ST_ch4_init[] = {
7208         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7209         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7210         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7211         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7212         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7213         { } /* end */
7214 };
7215
7216 /*
7217  * 6ch mode
7218  */
7219 static struct hda_verb alc883_3ST_ch6_init[] = {
7220         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7221         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7222         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7223         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7224         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7225         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7226         { } /* end */
7227 };
7228
7229 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7230         { 2, alc883_3ST_ch2_init },
7231         { 4, alc883_3ST_ch4_init },
7232         { 6, alc883_3ST_ch6_init },
7233 };
7234
7235 /*
7236  * 2ch mode
7237  */
7238 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7239         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7240         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7241         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7242         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7243         { } /* end */
7244 };
7245
7246 /*
7247  * 4ch mode
7248  */
7249 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7250         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7251         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7252         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7253         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7254         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7255         { } /* end */
7256 };
7257
7258 /*
7259  * 6ch mode
7260  */
7261 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7262         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7263         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7264         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7265         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7266         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7267         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7268         { } /* end */
7269 };
7270
7271 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7272         { 2, alc883_3ST_ch2_intel_init },
7273         { 4, alc883_3ST_ch4_intel_init },
7274         { 6, alc883_3ST_ch6_intel_init },
7275 };
7276
7277 /*
7278  * 6ch mode
7279  */
7280 static struct hda_verb alc883_sixstack_ch6_init[] = {
7281         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7282         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7283         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7284         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7285         { } /* end */
7286 };
7287
7288 /*
7289  * 8ch mode
7290  */
7291 static struct hda_verb alc883_sixstack_ch8_init[] = {
7292         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7293         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7294         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7295         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7296         { } /* end */
7297 };
7298
7299 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7300         { 6, alc883_sixstack_ch6_init },
7301         { 8, alc883_sixstack_ch8_init },
7302 };
7303
7304 static struct hda_verb alc883_medion_eapd_verbs[] = {
7305         /* eanable EAPD on medion laptop */
7306         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7307         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7308         { }
7309 };
7310
7311 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7312  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7313  */
7314
7315 static struct snd_kcontrol_new alc883_base_mixer[] = {
7316         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7317         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7318         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7319         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7320         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7321         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7322         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7323         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7324         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7325         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7326         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7327         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7328         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7329         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7330         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7331         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7332         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7333         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7334         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7335         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7336         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7337         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7338         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7339         { } /* end */
7340 };
7341
7342 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7343         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7344         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7345         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7346         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7347         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7348         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7349         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7350         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7351         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7352         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7353         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7354         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7355         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7356         { } /* end */
7357 };
7358
7359 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7360         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7361         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7362         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7363         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7364         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7365         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7366         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7367         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7368         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7369         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7370         { } /* end */
7371 };
7372
7373 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7374         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7375         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7376         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7377         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7378         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7379         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7380         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7381         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7382         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7383         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7384         { } /* end */
7385 };
7386
7387 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7388         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7389         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7390         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7391         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7392         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7393         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7394         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7395         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7396         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7397         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7398         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7399         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7400         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7401         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7402         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7403         { } /* end */
7404 };
7405
7406 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7407         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7408         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7409         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7410         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7411         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7412         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7413         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7414         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7415         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7416         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7417         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7418         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7419         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7420         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7421         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7422         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7423         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7424         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7425         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7426         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7427         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7428         { } /* end */
7429 };
7430
7431 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7432         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7433         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7434         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7435         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7436         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7437                               HDA_OUTPUT),
7438         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7439         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7440         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7441         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7442         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7443         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7444         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7445         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7446         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7447         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7448         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7449         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7450         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7451         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7452         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7453         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7454         { } /* end */
7455 };
7456
7457 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7458         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7459         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7460         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7461         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7462         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7463         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7464         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7465         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7466         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7467         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7468         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7469         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7470         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7471         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7472         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7473         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7474         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7475         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7476         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7477         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7478         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7479         { } /* end */
7480 };
7481
7482 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7483         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7484         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7485         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7486         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7487         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7488         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7489         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7490         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7491         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7492         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7493         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7494         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7495         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7496         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7497         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7498         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7499         { } /* end */
7500 };
7501
7502 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7503         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7504         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7505         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7506         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7507         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7508         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7509         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7510         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7511         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7512         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7513         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7514         { } /* end */
7515 };
7516
7517 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7518         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7519         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7520         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7521         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7522         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7523         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7524         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7525         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7526         { } /* end */
7527 };
7528
7529 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7530         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7531         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7532         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7533         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7534         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7535         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7536         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7537         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7538         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7539         { } /* end */
7540 };
7541
7542 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7543         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7544         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7545         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7546         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7547         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7548         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7549         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7550         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7551         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7552         { } /* end */
7553 };
7554
7555 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7556         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7557         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7558         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7559         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7560         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7561         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7562         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7563         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7564         { } /* end */
7565 };
7566
7567 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7568         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7569         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7570         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7571         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7572         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7573                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7574         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7575         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7576         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7577         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7578         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7579         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7580         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7581         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7582         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7583         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7584         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7585         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7586         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7587         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7588         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7589         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7590         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7591         { } /* end */
7592 };
7593
7594 static struct hda_bind_ctls alc883_bind_cap_vol = {
7595         .ops = &snd_hda_bind_vol,
7596         .values = {
7597                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7598                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7599                 0
7600         },
7601 };
7602
7603 static struct hda_bind_ctls alc883_bind_cap_switch = {
7604         .ops = &snd_hda_bind_sw,
7605         .values = {
7606                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7607                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7608                 0
7609         },
7610 };
7611
7612 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7613         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7614         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7615         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7616         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7617         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7618         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7619         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7620         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7621         { } /* end */
7622 };
7623
7624 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
7625         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7626         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7627         {
7628                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7629                 /* .name = "Capture Source", */
7630                 .name = "Input Source",
7631                 .count = 1,
7632                 .info = alc_mux_enum_info,
7633                 .get = alc_mux_enum_get,
7634                 .put = alc_mux_enum_put,
7635         },
7636         { } /* end */
7637 };
7638
7639 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7640         {
7641                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7642                 .name = "Channel Mode",
7643                 .info = alc_ch_mode_info,
7644                 .get = alc_ch_mode_get,
7645                 .put = alc_ch_mode_put,
7646         },
7647         { } /* end */
7648 };
7649
7650 static struct hda_verb alc883_init_verbs[] = {
7651         /* ADC1: mute amp left and right */
7652         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7653         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7654         /* ADC2: mute amp left and right */
7655         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7656         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7657         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7658         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7659         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7660         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7661         /* Rear mixer */
7662         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7663         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7664         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7665         /* CLFE mixer */
7666         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7667         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7668         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7669         /* Side mixer */
7670         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7671         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7672         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7673
7674         /* mute analog input loopbacks */
7675         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7676         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7677         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7678         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7679         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7680
7681         /* Front Pin: output 0 (0x0c) */
7682         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7683         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7684         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7685         /* Rear Pin: output 1 (0x0d) */
7686         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7687         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7688         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7689         /* CLFE Pin: output 2 (0x0e) */
7690         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7691         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7692         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7693         /* Side Pin: output 3 (0x0f) */
7694         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7695         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7696         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7697         /* Mic (rear) pin: input vref at 80% */
7698         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7699         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7700         /* Front Mic pin: input vref at 80% */
7701         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7702         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7703         /* Line In pin: input */
7704         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7705         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7706         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7707         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7708         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7709         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7710         /* CD pin widget for input */
7711         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7712
7713         /* FIXME: use matrix-type input source selection */
7714         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7715         /* Input mixer2 */
7716         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7717         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7718         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7719         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7720         /* Input mixer3 */
7721         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7722         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7723         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7724         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7725         { }
7726 };
7727
7728 /* toggle speaker-output according to the hp-jack state */
7729 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7730 {
7731         unsigned int present;
7732
7733         present = snd_hda_codec_read(codec, 0x15, 0,
7734                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7735         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7736                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7737         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7738                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7739 }
7740
7741 /* auto-toggle front mic */
7742 /*
7743 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7744 {
7745         unsigned int present;
7746         unsigned char bits;
7747
7748         present = snd_hda_codec_read(codec, 0x18, 0,
7749                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7750         bits = present ? HDA_AMP_MUTE : 0;
7751         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7752 }
7753 */
7754
7755 static void alc883_mitac_automute(struct hda_codec *codec)
7756 {
7757         alc883_mitac_hp_automute(codec);
7758         /* alc883_mitac_mic_automute(codec); */
7759 }
7760
7761 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7762                                            unsigned int res)
7763 {
7764         switch (res >> 26) {
7765         case ALC880_HP_EVENT:
7766                 alc883_mitac_hp_automute(codec);
7767                 break;
7768         case ALC880_MIC_EVENT:
7769                 /* alc883_mitac_mic_automute(codec); */
7770                 break;
7771         }
7772 }
7773
7774 static struct hda_verb alc883_mitac_verbs[] = {
7775         /* HP */
7776         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7777         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7778         /* Subwoofer */
7779         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7780         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7781
7782         /* enable unsolicited event */
7783         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7784         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7785
7786         { } /* end */
7787 };
7788
7789 static struct hda_verb alc883_clevo_m720_verbs[] = {
7790         /* HP */
7791         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7792         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7793         /* Int speaker */
7794         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7795         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7796
7797         /* enable unsolicited event */
7798         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7799         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7800
7801         { } /* end */
7802 };
7803
7804 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7805         /* HP */
7806         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7807         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7808         /* Subwoofer */
7809         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7810         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7811
7812         /* enable unsolicited event */
7813         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7814
7815         { } /* end */
7816 };
7817
7818 static struct hda_verb alc883_tagra_verbs[] = {
7819         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7820         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7821
7822         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7823         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7824
7825         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7826         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7827         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7828
7829         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7830         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7831         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7832         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7833
7834         { } /* end */
7835 };
7836
7837 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7838         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7839         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7840         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7841         { } /* end */
7842 };
7843
7844 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7845         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7846         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7847         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7848         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7849         { } /* end */
7850 };
7851
7852 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7853         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7854         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7855         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7856         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7857         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7858         { } /* end */
7859 };
7860
7861 static struct hda_verb alc883_haier_w66_verbs[] = {
7862         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7863         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7864
7865         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7866
7867         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7868         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7869         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7870         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7871         { } /* end */
7872 };
7873
7874 static struct hda_verb alc888_lenovo_sky_verbs[] = {
7875         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7876         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7877         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7878         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7879         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7880         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7881         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7882         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7883         { } /* end */
7884 };
7885
7886 static struct hda_verb alc888_3st_hp_verbs[] = {
7887         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7888         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7889         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7890         { }
7891 };
7892
7893 static struct hda_verb alc888_6st_dell_verbs[] = {
7894         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7895         { }
7896 };
7897
7898 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7899         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7900         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7901         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7902         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7903         { }
7904 };
7905
7906 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7907         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7908         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7909         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7910         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7911         { }
7912 };
7913
7914 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7915         { 2, alc888_3st_hp_2ch_init },
7916         { 6, alc888_3st_hp_6ch_init },
7917 };
7918
7919 /* toggle front-jack and RCA according to the hp-jack state */
7920 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7921 {
7922         unsigned int present;
7923
7924         present = snd_hda_codec_read(codec, 0x1b, 0,
7925                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7926         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7927                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7928         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7929                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7930 }
7931
7932 /* toggle RCA according to the front-jack state */
7933 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7934 {
7935         unsigned int present;
7936
7937         present = snd_hda_codec_read(codec, 0x14, 0,
7938                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7939         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7940                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7941 }
7942
7943 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7944                                              unsigned int res)
7945 {
7946         if ((res >> 26) == ALC880_HP_EVENT)
7947                 alc888_lenovo_ms7195_front_automute(codec);
7948         if ((res >> 26) == ALC880_FRONT_EVENT)
7949                 alc888_lenovo_ms7195_rca_automute(codec);
7950 }
7951
7952 static struct hda_verb alc883_medion_md2_verbs[] = {
7953         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7954         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7955
7956         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7957
7958         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7959         { } /* end */
7960 };
7961
7962 /* toggle speaker-output according to the hp-jack state */
7963 static void alc883_medion_md2_automute(struct hda_codec *codec)
7964 {
7965         unsigned int present;
7966
7967         present = snd_hda_codec_read(codec, 0x14, 0,
7968                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7969         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7970                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7971 }
7972
7973 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7974                                           unsigned int res)
7975 {
7976         if ((res >> 26) == ALC880_HP_EVENT)
7977                 alc883_medion_md2_automute(codec);
7978 }
7979
7980 /* toggle speaker-output according to the hp-jack state */
7981 static void alc883_tagra_automute(struct hda_codec *codec)
7982 {
7983         unsigned int present;
7984         unsigned char bits;
7985
7986         present = snd_hda_codec_read(codec, 0x14, 0,
7987                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7988         bits = present ? HDA_AMP_MUTE : 0;
7989         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7990                                  HDA_AMP_MUTE, bits);
7991         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7992                                   present ? 1 : 3);
7993 }
7994
7995 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7996 {
7997         if ((res >> 26) == ALC880_HP_EVENT)
7998                 alc883_tagra_automute(codec);
7999 }
8000
8001 /* toggle speaker-output according to the hp-jack state */
8002 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
8003 {
8004         unsigned int present;
8005         unsigned char bits;
8006
8007         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
8008                 & AC_PINSENSE_PRESENCE;
8009         bits = present ? HDA_AMP_MUTE : 0;
8010         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8011                                  HDA_AMP_MUTE, bits);
8012 }
8013
8014 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8015 {
8016         unsigned int present;
8017
8018         present = snd_hda_codec_read(codec, 0x18, 0,
8019                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8020         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8021                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8022 }
8023
8024 static void alc883_clevo_m720_automute(struct hda_codec *codec)
8025 {
8026         alc883_clevo_m720_hp_automute(codec);
8027         alc883_clevo_m720_mic_automute(codec);
8028 }
8029
8030 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8031                                            unsigned int res)
8032 {
8033         switch (res >> 26) {
8034         case ALC880_HP_EVENT:
8035                 alc883_clevo_m720_hp_automute(codec);
8036                 break;
8037         case ALC880_MIC_EVENT:
8038                 alc883_clevo_m720_mic_automute(codec);
8039                 break;
8040         }
8041 }
8042
8043 /* toggle speaker-output according to the hp-jack state */
8044 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
8045 {
8046         unsigned int present;
8047         unsigned char bits;
8048
8049         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8050                 & AC_PINSENSE_PRESENCE;
8051         bits = present ? HDA_AMP_MUTE : 0;
8052         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8053                                  HDA_AMP_MUTE, bits);
8054 }
8055
8056 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
8057                                                   unsigned int res)
8058 {
8059         if ((res >> 26) == ALC880_HP_EVENT)
8060                 alc883_2ch_fujitsu_pi2515_automute(codec);
8061 }
8062
8063 static void alc883_haier_w66_automute(struct hda_codec *codec)
8064 {
8065         unsigned int present;
8066         unsigned char bits;
8067
8068         present = snd_hda_codec_read(codec, 0x1b, 0,
8069                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8070         bits = present ? 0x80 : 0;
8071         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8072                                  0x80, bits);
8073 }
8074
8075 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
8076                                          unsigned int res)
8077 {
8078         if ((res >> 26) == ALC880_HP_EVENT)
8079                 alc883_haier_w66_automute(codec);
8080 }
8081
8082 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8083 {
8084         unsigned int present;
8085         unsigned char bits;
8086
8087         present = snd_hda_codec_read(codec, 0x14, 0,
8088                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8089         bits = present ? HDA_AMP_MUTE : 0;
8090         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8091                                  HDA_AMP_MUTE, bits);
8092 }
8093
8094 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8095 {
8096         unsigned int present;
8097         unsigned char bits;
8098
8099         present = snd_hda_codec_read(codec, 0x1b, 0,
8100                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8101         bits = present ? HDA_AMP_MUTE : 0;
8102         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8103                                  HDA_AMP_MUTE, bits);
8104         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8105                                  HDA_AMP_MUTE, bits);
8106 }
8107
8108 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8109                                            unsigned int res)
8110 {
8111         if ((res >> 26) == ALC880_HP_EVENT)
8112                 alc883_lenovo_101e_all_automute(codec);
8113         if ((res >> 26) == ALC880_FRONT_EVENT)
8114                 alc883_lenovo_101e_ispeaker_automute(codec);
8115 }
8116
8117 /* toggle speaker-output according to the hp-jack state */
8118 static void alc883_acer_aspire_automute(struct hda_codec *codec)
8119 {
8120         unsigned int present;
8121
8122         present = snd_hda_codec_read(codec, 0x14, 0,
8123                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8124         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8125                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8126         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8127                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8128 }
8129
8130 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
8131                                            unsigned int res)
8132 {
8133         if ((res >> 26) == ALC880_HP_EVENT)
8134                 alc883_acer_aspire_automute(codec);
8135 }
8136
8137 static struct hda_verb alc883_acer_eapd_verbs[] = {
8138         /* HP Pin: output 0 (0x0c) */
8139         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8140         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8141         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8142         /* Front Pin: output 0 (0x0c) */
8143         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8144         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8145         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8146         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8147         /* eanable EAPD on medion laptop */
8148         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8149         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8150         /* enable unsolicited event */
8151         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8152         { }
8153 };
8154
8155 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
8156 {
8157         unsigned int present;
8158
8159         present = snd_hda_codec_read(codec, 0x1b, 0,
8160                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8161         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8162                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8163         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8164                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8165         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8166                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8167         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8168                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8169 }
8170
8171 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8172                                              unsigned int res)
8173 {
8174         switch (res >> 26) {
8175         case ALC880_HP_EVENT:
8176                 printk("hp_event\n");
8177                 alc888_6st_dell_front_automute(codec);
8178                 break;
8179         }
8180 }
8181
8182 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8183 {
8184         unsigned int mute;
8185         unsigned int present;
8186
8187         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8188         present = snd_hda_codec_read(codec, 0x1b, 0,
8189                                      AC_VERB_GET_PIN_SENSE, 0);
8190         present = (present & 0x80000000) != 0;
8191         if (present) {
8192                 /* mute internal speaker */
8193                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8194                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8195                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8196                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8197                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8198                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8199                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8200                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8201                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8202                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8203         } else {
8204                 /* unmute internal speaker if necessary */
8205                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8206                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8207                                          HDA_AMP_MUTE, mute);
8208                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8209                                          HDA_AMP_MUTE, mute);
8210                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8211                                          HDA_AMP_MUTE, mute);
8212                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8213                                          HDA_AMP_MUTE, mute);
8214                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8215                                          HDA_AMP_MUTE, mute);
8216         }
8217 }
8218
8219 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8220                                              unsigned int res)
8221 {
8222         if ((res >> 26) == ALC880_HP_EVENT)
8223                 alc888_lenovo_sky_front_automute(codec);
8224 }
8225
8226 /*
8227  * generic initialization of ADC, input mixers and output mixers
8228  */
8229 static struct hda_verb alc883_auto_init_verbs[] = {
8230         /*
8231          * Unmute ADC0-2 and set the default input to mic-in
8232          */
8233         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8234         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8235         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8236         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8237
8238         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8239          * mixer widget
8240          * Note: PASD motherboards uses the Line In 2 as the input for
8241          * front panel mic (mic 2)
8242          */
8243         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8244         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8245         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8246         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8247         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8248         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8249
8250         /*
8251          * Set up output mixers (0x0c - 0x0f)
8252          */
8253         /* set vol=0 to output mixers */
8254         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8255         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8256         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8257         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8258         /* set up input amps for analog loopback */
8259         /* Amp Indices: DAC = 0, mixer = 1 */
8260         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8261         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8262         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8263         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8264         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8265         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8266         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8267         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8268         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8269         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8270
8271         /* FIXME: use matrix-type input source selection */
8272         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8273         /* Input mixer1 */
8274         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8275         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8276         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8277         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8278         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8279         /* Input mixer2 */
8280         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8281         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8282         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8283         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8284         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8285
8286         { }
8287 };
8288
8289 static struct hda_verb alc888_asus_m90v_verbs[] = {
8290         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8291         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8292         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8293         /* enable unsolicited event */
8294         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8295         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8296         { } /* end */
8297 };
8298
8299 static void alc883_nb_mic_automute(struct hda_codec *codec)
8300 {
8301         unsigned int present;
8302
8303         present = snd_hda_codec_read(codec, 0x18, 0,
8304                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8305         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8306                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8307         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8308                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8309 }
8310
8311 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8312 {
8313         unsigned int present;
8314         unsigned char bits;
8315
8316         present = snd_hda_codec_read(codec, 0x1b, 0,
8317                                      AC_VERB_GET_PIN_SENSE, 0)
8318                 & AC_PINSENSE_PRESENCE;
8319         bits = present ? 0 : PIN_OUT;
8320         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8321                             bits);
8322         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8323                             bits);
8324         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8325                             bits);
8326 }
8327
8328 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8329                                            unsigned int res)
8330 {
8331         switch (res >> 26) {
8332         case ALC880_HP_EVENT:
8333                 alc883_M90V_speaker_automute(codec);
8334                 break;
8335         case ALC880_MIC_EVENT:
8336                 alc883_nb_mic_automute(codec);
8337                 break;
8338         }
8339 }
8340
8341 static void alc883_mode2_inithook(struct hda_codec *codec)
8342 {
8343         alc883_M90V_speaker_automute(codec);
8344         alc883_nb_mic_automute(codec);
8345 }
8346
8347 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8348         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8349         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8350         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8351         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8352         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8353         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8354         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8355         /* enable unsolicited event */
8356         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8357         { } /* end */
8358 };
8359
8360 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8361 {
8362         unsigned int present;
8363         unsigned char bits;
8364
8365         present = snd_hda_codec_read(codec, 0x14, 0,
8366                                      AC_VERB_GET_PIN_SENSE, 0)
8367                 & AC_PINSENSE_PRESENCE;
8368         bits = present ? 0 : PIN_OUT;
8369         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8370                             bits);
8371 }
8372
8373 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8374                                            unsigned int res)
8375 {
8376         switch (res >> 26) {
8377         case ALC880_HP_EVENT:
8378                 alc883_eee1601_speaker_automute(codec);
8379                 break;
8380         }
8381 }
8382
8383 static void alc883_eee1601_inithook(struct hda_codec *codec)
8384 {
8385         alc883_eee1601_speaker_automute(codec);
8386 }
8387
8388 #ifdef CONFIG_SND_HDA_POWER_SAVE
8389 #define alc883_loopbacks        alc880_loopbacks
8390 #endif
8391
8392 /* pcm configuration: identiacal with ALC880 */
8393 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8394 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8395 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8396 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8397 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8398
8399 /*
8400  * configuration and preset
8401  */
8402 static const char *alc883_models[ALC883_MODEL_LAST] = {
8403         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8404         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8405         [ALC883_3ST_6ch]        = "3stack-6ch",
8406         [ALC883_6ST_DIG]        = "6stack-dig",
8407         [ALC883_TARGA_DIG]      = "targa-dig",
8408         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8409         [ALC883_ACER]           = "acer",
8410         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8411         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8412         [ALC883_MEDION]         = "medion",
8413         [ALC883_MEDION_MD2]     = "medion-md2",
8414         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8415         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8416         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8417         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8418         [ALC888_LENOVO_SKY] = "lenovo-sky",
8419         [ALC883_HAIER_W66]      = "haier-w66",
8420         [ALC888_3ST_HP]         = "3stack-hp",
8421         [ALC888_6ST_DELL]       = "6stack-dell",
8422         [ALC883_MITAC]          = "mitac",
8423         [ALC883_CLEVO_M720]     = "clevo-m720",
8424         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8425         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8426         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8427         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8428         [ALC883_AUTO]           = "auto",
8429 };
8430
8431 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8432         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8433         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8434         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8435         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8436         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8437         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8438         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8439                 ALC888_ACER_ASPIRE_4930G),
8440         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8441         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8442         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8443         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8444         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8445         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8446         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8447         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8448         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8449         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8450         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8451         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8452         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8453         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8454         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8455         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8456         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8457         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8458         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8459         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8460         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8461         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8462         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8463         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8464         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8465         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8466         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8467         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8468         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8469         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8470         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8471         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8472         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8473         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8474         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8475         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8476         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8477         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8478         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8479         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8480         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8481         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8482         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8483         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8484         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8485         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8486         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8487         SND_PCI_QUIRK(0x1734, 0x113d, "Fujitsu AMILO Xa3530",
8488                 ALC888_FUJITSU_XA3530),
8489         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8490         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8491         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8492         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8493         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8494         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8495         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8496         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8497         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8498         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8499         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8500         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8501         {}
8502 };
8503
8504 static struct alc_config_preset alc883_presets[] = {
8505         [ALC883_3ST_2ch_DIG] = {
8506                 .mixers = { alc883_3ST_2ch_mixer },
8507                 .init_verbs = { alc883_init_verbs },
8508                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8509                 .dac_nids = alc883_dac_nids,
8510                 .dig_out_nid = ALC883_DIGOUT_NID,
8511                 .dig_in_nid = ALC883_DIGIN_NID,
8512                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8513                 .channel_mode = alc883_3ST_2ch_modes,
8514                 .input_mux = &alc883_capture_source,
8515         },
8516         [ALC883_3ST_6ch_DIG] = {
8517                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8518                 .init_verbs = { alc883_init_verbs },
8519                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8520                 .dac_nids = alc883_dac_nids,
8521                 .dig_out_nid = ALC883_DIGOUT_NID,
8522                 .dig_in_nid = ALC883_DIGIN_NID,
8523                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8524                 .channel_mode = alc883_3ST_6ch_modes,
8525                 .need_dac_fix = 1,
8526                 .input_mux = &alc883_capture_source,
8527         },
8528         [ALC883_3ST_6ch] = {
8529                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8530                 .init_verbs = { alc883_init_verbs },
8531                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8532                 .dac_nids = alc883_dac_nids,
8533                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8534                 .channel_mode = alc883_3ST_6ch_modes,
8535                 .need_dac_fix = 1,
8536                 .input_mux = &alc883_capture_source,
8537         },
8538         [ALC883_3ST_6ch_INTEL] = {
8539                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8540                 .init_verbs = { alc883_init_verbs },
8541                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8542                 .dac_nids = alc883_dac_nids,
8543                 .dig_out_nid = ALC883_DIGOUT_NID,
8544                 .dig_in_nid = ALC883_DIGIN_NID,
8545                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8546                 .channel_mode = alc883_3ST_6ch_intel_modes,
8547                 .need_dac_fix = 1,
8548                 .input_mux = &alc883_3stack_6ch_intel,
8549         },
8550         [ALC883_6ST_DIG] = {
8551                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8552                 .init_verbs = { alc883_init_verbs },
8553                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8554                 .dac_nids = alc883_dac_nids,
8555                 .dig_out_nid = ALC883_DIGOUT_NID,
8556                 .dig_in_nid = ALC883_DIGIN_NID,
8557                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8558                 .channel_mode = alc883_sixstack_modes,
8559                 .input_mux = &alc883_capture_source,
8560         },
8561         [ALC883_TARGA_DIG] = {
8562                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8563                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8564                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8565                 .dac_nids = alc883_dac_nids,
8566                 .dig_out_nid = ALC883_DIGOUT_NID,
8567                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8568                 .channel_mode = alc883_3ST_6ch_modes,
8569                 .need_dac_fix = 1,
8570                 .input_mux = &alc883_capture_source,
8571                 .unsol_event = alc883_tagra_unsol_event,
8572                 .init_hook = alc883_tagra_automute,
8573         },
8574         [ALC883_TARGA_2ch_DIG] = {
8575                 .mixers = { alc883_tagra_2ch_mixer},
8576                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8577                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8578                 .dac_nids = alc883_dac_nids,
8579                 .adc_nids = alc883_adc_nids_alt,
8580                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8581                 .dig_out_nid = ALC883_DIGOUT_NID,
8582                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8583                 .channel_mode = alc883_3ST_2ch_modes,
8584                 .input_mux = &alc883_capture_source,
8585                 .unsol_event = alc883_tagra_unsol_event,
8586                 .init_hook = alc883_tagra_automute,
8587         },
8588         [ALC883_ACER] = {
8589                 .mixers = { alc883_base_mixer },
8590                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8591                  * and the headphone jack.  Turn this on and rely on the
8592                  * standard mute methods whenever the user wants to turn
8593                  * these outputs off.
8594                  */
8595                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8596                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8597                 .dac_nids = alc883_dac_nids,
8598                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8599                 .channel_mode = alc883_3ST_2ch_modes,
8600                 .input_mux = &alc883_capture_source,
8601         },
8602         [ALC883_ACER_ASPIRE] = {
8603                 .mixers = { alc883_acer_aspire_mixer },
8604                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8605                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8606                 .dac_nids = alc883_dac_nids,
8607                 .dig_out_nid = ALC883_DIGOUT_NID,
8608                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8609                 .channel_mode = alc883_3ST_2ch_modes,
8610                 .input_mux = &alc883_capture_source,
8611                 .unsol_event = alc883_acer_aspire_unsol_event,
8612                 .init_hook = alc883_acer_aspire_automute,
8613         },
8614         [ALC888_ACER_ASPIRE_4930G] = {
8615                 .mixers = { alc888_base_mixer,
8616                                 alc883_chmode_mixer },
8617                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
8618                                 alc888_acer_aspire_4930g_verbs },
8619                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8620                 .dac_nids = alc883_dac_nids,
8621                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8622                 .adc_nids = alc883_adc_nids_rev,
8623                 .capsrc_nids = alc883_capsrc_nids_rev,
8624                 .dig_out_nid = ALC883_DIGOUT_NID,
8625                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8626                 .channel_mode = alc883_3ST_6ch_modes,
8627                 .need_dac_fix = 1,
8628                 .num_mux_defs =
8629                         ARRAY_SIZE(alc888_2_capture_sources),
8630                 .input_mux = alc888_2_capture_sources,
8631                 .unsol_event = alc888_acer_aspire_4930g_unsol_event,
8632                 .init_hook = alc888_acer_aspire_4930g_automute,
8633         },
8634         [ALC883_MEDION] = {
8635                 .mixers = { alc883_fivestack_mixer,
8636                             alc883_chmode_mixer },
8637                 .init_verbs = { alc883_init_verbs,
8638                                 alc883_medion_eapd_verbs },
8639                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8640                 .dac_nids = alc883_dac_nids,
8641                 .adc_nids = alc883_adc_nids_alt,
8642                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8643                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8644                 .channel_mode = alc883_sixstack_modes,
8645                 .input_mux = &alc883_capture_source,
8646         },
8647         [ALC883_MEDION_MD2] = {
8648                 .mixers = { alc883_medion_md2_mixer},
8649                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8650                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8651                 .dac_nids = alc883_dac_nids,
8652                 .dig_out_nid = ALC883_DIGOUT_NID,
8653                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8654                 .channel_mode = alc883_3ST_2ch_modes,
8655                 .input_mux = &alc883_capture_source,
8656                 .unsol_event = alc883_medion_md2_unsol_event,
8657                 .init_hook = alc883_medion_md2_automute,
8658         },
8659         [ALC883_LAPTOP_EAPD] = {
8660                 .mixers = { alc883_base_mixer },
8661                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8662                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8663                 .dac_nids = alc883_dac_nids,
8664                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8665                 .channel_mode = alc883_3ST_2ch_modes,
8666                 .input_mux = &alc883_capture_source,
8667         },
8668         [ALC883_CLEVO_M720] = {
8669                 .mixers = { alc883_clevo_m720_mixer },
8670                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8671                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8672                 .dac_nids = alc883_dac_nids,
8673                 .dig_out_nid = ALC883_DIGOUT_NID,
8674                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8675                 .channel_mode = alc883_3ST_2ch_modes,
8676                 .input_mux = &alc883_capture_source,
8677                 .unsol_event = alc883_clevo_m720_unsol_event,
8678                 .init_hook = alc883_clevo_m720_automute,
8679         },
8680         [ALC883_LENOVO_101E_2ch] = {
8681                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8682                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8683                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8684                 .dac_nids = alc883_dac_nids,
8685                 .adc_nids = alc883_adc_nids_alt,
8686                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8687                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8688                 .channel_mode = alc883_3ST_2ch_modes,
8689                 .input_mux = &alc883_lenovo_101e_capture_source,
8690                 .unsol_event = alc883_lenovo_101e_unsol_event,
8691                 .init_hook = alc883_lenovo_101e_all_automute,
8692         },
8693         [ALC883_LENOVO_NB0763] = {
8694                 .mixers = { alc883_lenovo_nb0763_mixer },
8695                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8696                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8697                 .dac_nids = alc883_dac_nids,
8698                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8699                 .channel_mode = alc883_3ST_2ch_modes,
8700                 .need_dac_fix = 1,
8701                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8702                 .unsol_event = alc883_medion_md2_unsol_event,
8703                 .init_hook = alc883_medion_md2_automute,
8704         },
8705         [ALC888_LENOVO_MS7195_DIG] = {
8706                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8707                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8708                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8709                 .dac_nids = alc883_dac_nids,
8710                 .dig_out_nid = ALC883_DIGOUT_NID,
8711                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8712                 .channel_mode = alc883_3ST_6ch_modes,
8713                 .need_dac_fix = 1,
8714                 .input_mux = &alc883_capture_source,
8715                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8716                 .init_hook = alc888_lenovo_ms7195_front_automute,
8717         },
8718         [ALC883_HAIER_W66] = {
8719                 .mixers = { alc883_tagra_2ch_mixer},
8720                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8721                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8722                 .dac_nids = alc883_dac_nids,
8723                 .dig_out_nid = ALC883_DIGOUT_NID,
8724                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8725                 .channel_mode = alc883_3ST_2ch_modes,
8726                 .input_mux = &alc883_capture_source,
8727                 .unsol_event = alc883_haier_w66_unsol_event,
8728                 .init_hook = alc883_haier_w66_automute,
8729         },
8730         [ALC888_3ST_HP] = {
8731                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8732                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8733                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8734                 .dac_nids = alc883_dac_nids,
8735                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8736                 .channel_mode = alc888_3st_hp_modes,
8737                 .need_dac_fix = 1,
8738                 .input_mux = &alc883_capture_source,
8739         },
8740         [ALC888_6ST_DELL] = {
8741                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8742                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8743                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8744                 .dac_nids = alc883_dac_nids,
8745                 .dig_out_nid = ALC883_DIGOUT_NID,
8746                 .dig_in_nid = ALC883_DIGIN_NID,
8747                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8748                 .channel_mode = alc883_sixstack_modes,
8749                 .input_mux = &alc883_capture_source,
8750                 .unsol_event = alc888_6st_dell_unsol_event,
8751                 .init_hook = alc888_6st_dell_front_automute,
8752         },
8753         [ALC883_MITAC] = {
8754                 .mixers = { alc883_mitac_mixer },
8755                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8756                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8757                 .dac_nids = alc883_dac_nids,
8758                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8759                 .channel_mode = alc883_3ST_2ch_modes,
8760                 .input_mux = &alc883_capture_source,
8761                 .unsol_event = alc883_mitac_unsol_event,
8762                 .init_hook = alc883_mitac_automute,
8763         },
8764         [ALC883_FUJITSU_PI2515] = {
8765                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8766                 .init_verbs = { alc883_init_verbs,
8767                                 alc883_2ch_fujitsu_pi2515_verbs},
8768                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8769                 .dac_nids = alc883_dac_nids,
8770                 .dig_out_nid = ALC883_DIGOUT_NID,
8771                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8772                 .channel_mode = alc883_3ST_2ch_modes,
8773                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8774                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8775                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8776         },
8777         [ALC888_FUJITSU_XA3530] = {
8778                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
8779                 .init_verbs = { alc883_init_verbs,
8780                         alc888_fujitsu_xa3530_verbs },
8781                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8782                 .dac_nids = alc883_dac_nids,
8783                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8784                 .adc_nids = alc883_adc_nids_rev,
8785                 .capsrc_nids = alc883_capsrc_nids_rev,
8786                 .dig_out_nid = ALC883_DIGOUT_NID,
8787                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
8788                 .channel_mode = alc888_4ST_8ch_intel_modes,
8789                 .num_mux_defs =
8790                         ARRAY_SIZE(alc888_2_capture_sources),
8791                 .input_mux = alc888_2_capture_sources,
8792                 .unsol_event = alc888_fujitsu_xa3530_unsol_event,
8793                 .init_hook = alc888_fujitsu_xa3530_automute,
8794         },
8795         [ALC888_LENOVO_SKY] = {
8796                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8797                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8798                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8799                 .dac_nids = alc883_dac_nids,
8800                 .dig_out_nid = ALC883_DIGOUT_NID,
8801                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8802                 .channel_mode = alc883_sixstack_modes,
8803                 .need_dac_fix = 1,
8804                 .input_mux = &alc883_lenovo_sky_capture_source,
8805                 .unsol_event = alc883_lenovo_sky_unsol_event,
8806                 .init_hook = alc888_lenovo_sky_front_automute,
8807         },
8808         [ALC888_ASUS_M90V] = {
8809                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8810                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8811                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8812                 .dac_nids = alc883_dac_nids,
8813                 .dig_out_nid = ALC883_DIGOUT_NID,
8814                 .dig_in_nid = ALC883_DIGIN_NID,
8815                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8816                 .channel_mode = alc883_3ST_6ch_modes,
8817                 .need_dac_fix = 1,
8818                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8819                 .unsol_event = alc883_mode2_unsol_event,
8820                 .init_hook = alc883_mode2_inithook,
8821         },
8822         [ALC888_ASUS_EEE1601] = {
8823                 .mixers = { alc883_asus_eee1601_mixer },
8824                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
8825                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8826                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8827                 .dac_nids = alc883_dac_nids,
8828                 .dig_out_nid = ALC883_DIGOUT_NID,
8829                 .dig_in_nid = ALC883_DIGIN_NID,
8830                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8831                 .channel_mode = alc883_3ST_2ch_modes,
8832                 .need_dac_fix = 1,
8833                 .input_mux = &alc883_asus_eee1601_capture_source,
8834                 .unsol_event = alc883_eee1601_unsol_event,
8835                 .init_hook = alc883_eee1601_inithook,
8836         },
8837         [ALC1200_ASUS_P5Q] = {
8838                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8839                 .init_verbs = { alc883_init_verbs },
8840                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8841                 .dac_nids = alc883_dac_nids,
8842                 .dig_out_nid = ALC1200_DIGOUT_NID,
8843                 .dig_in_nid = ALC883_DIGIN_NID,
8844                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8845                 .channel_mode = alc883_sixstack_modes,
8846                 .input_mux = &alc883_capture_source,
8847         },
8848 };
8849
8850
8851 /*
8852  * BIOS auto configuration
8853  */
8854 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8855                                               hda_nid_t nid, int pin_type,
8856                                               int dac_idx)
8857 {
8858         /* set as output */
8859         struct alc_spec *spec = codec->spec;
8860         int idx;
8861
8862         alc_set_pin_output(codec, nid, pin_type);
8863         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8864                 idx = 4;
8865         else
8866                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8867         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8868
8869 }
8870
8871 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8872 {
8873         struct alc_spec *spec = codec->spec;
8874         int i;
8875
8876         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8877         for (i = 0; i <= HDA_SIDE; i++) {
8878                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8879                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8880                 if (nid)
8881                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8882                                                           i);
8883         }
8884 }
8885
8886 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8887 {
8888         struct alc_spec *spec = codec->spec;
8889         hda_nid_t pin;
8890
8891         pin = spec->autocfg.hp_pins[0];
8892         if (pin) /* connect to front */
8893                 /* use dac 0 */
8894                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8895         pin = spec->autocfg.speaker_pins[0];
8896         if (pin)
8897                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8898 }
8899
8900 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8901 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8902
8903 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8904 {
8905         struct alc_spec *spec = codec->spec;
8906         int i;
8907
8908         for (i = 0; i < AUTO_PIN_LAST; i++) {
8909                 hda_nid_t nid = spec->autocfg.input_pins[i];
8910                 if (alc883_is_input_pin(nid)) {
8911                         snd_hda_codec_write(codec, nid, 0,
8912                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8913                                             (i <= AUTO_PIN_FRONT_MIC ?
8914                                              PIN_VREF80 : PIN_IN));
8915                         if (nid != ALC883_PIN_CD_NID)
8916                                 snd_hda_codec_write(codec, nid, 0,
8917                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8918                                                     AMP_OUT_MUTE);
8919                 }
8920         }
8921 }
8922
8923 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8924
8925 /* almost identical with ALC880 parser... */
8926 static int alc883_parse_auto_config(struct hda_codec *codec)
8927 {
8928         struct alc_spec *spec = codec->spec;
8929         int err = alc880_parse_auto_config(codec);
8930
8931         if (err < 0)
8932                 return err;
8933         else if (!err)
8934                 return 0; /* no config found */
8935
8936         err = alc_auto_add_mic_boost(codec);
8937         if (err < 0)
8938                 return err;
8939
8940         /* hack - override the init verbs */
8941         spec->init_verbs[0] = alc883_auto_init_verbs;
8942
8943         return 1; /* config found */
8944 }
8945
8946 /* additional initialization for auto-configuration model */
8947 static void alc883_auto_init(struct hda_codec *codec)
8948 {
8949         struct alc_spec *spec = codec->spec;
8950         alc883_auto_init_multi_out(codec);
8951         alc883_auto_init_hp_out(codec);
8952         alc883_auto_init_analog_input(codec);
8953         alc883_auto_init_input_src(codec);
8954         if (spec->unsol_event)
8955                 alc_inithook(codec);
8956 }
8957
8958 static int patch_alc883(struct hda_codec *codec)
8959 {
8960         struct alc_spec *spec;
8961         int err, board_config;
8962
8963         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8964         if (spec == NULL)
8965                 return -ENOMEM;
8966
8967         codec->spec = spec;
8968
8969         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
8970
8971         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8972                                                   alc883_models,
8973                                                   alc883_cfg_tbl);
8974         if (board_config < 0) {
8975                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8976                        "trying auto-probe from BIOS...\n");
8977                 board_config = ALC883_AUTO;
8978         }
8979
8980         if (board_config == ALC883_AUTO) {
8981                 /* automatic parse from the BIOS config */
8982                 err = alc883_parse_auto_config(codec);
8983                 if (err < 0) {
8984                         alc_free(codec);
8985                         return err;
8986                 } else if (!err) {
8987                         printk(KERN_INFO
8988                                "hda_codec: Cannot set up configuration "
8989                                "from BIOS.  Using base mode...\n");
8990                         board_config = ALC883_3ST_2ch_DIG;
8991                 }
8992         }
8993
8994         if (board_config != ALC883_AUTO)
8995                 setup_preset(spec, &alc883_presets[board_config]);
8996
8997         switch (codec->vendor_id) {
8998         case 0x10ec0888:
8999                 if (codec->revision_id == 0x100101) {
9000                         spec->stream_name_analog = "ALC1200 Analog";
9001                         spec->stream_name_digital = "ALC1200 Digital";
9002                 } else {
9003                         spec->stream_name_analog = "ALC888 Analog";
9004                         spec->stream_name_digital = "ALC888 Digital";
9005                 }
9006                 break;
9007         case 0x10ec0889:
9008                 spec->stream_name_analog = "ALC889 Analog";
9009                 spec->stream_name_digital = "ALC889 Digital";
9010                 break;
9011         default:
9012                 spec->stream_name_analog = "ALC883 Analog";
9013                 spec->stream_name_digital = "ALC883 Digital";
9014                 break;
9015         }
9016
9017         spec->stream_analog_playback = &alc883_pcm_analog_playback;
9018         spec->stream_analog_capture = &alc883_pcm_analog_capture;
9019         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9020
9021         spec->stream_digital_playback = &alc883_pcm_digital_playback;
9022         spec->stream_digital_capture = &alc883_pcm_digital_capture;
9023
9024         if (!spec->num_adc_nids) {
9025                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9026                 spec->adc_nids = alc883_adc_nids;
9027         }
9028         if (!spec->capsrc_nids)
9029                 spec->capsrc_nids = alc883_capsrc_nids;
9030         spec->is_mix_capture = 1; /* matrix-style capture */
9031         if (!spec->cap_mixer)
9032                 set_capture_mixer(spec);
9033
9034         spec->vmaster_nid = 0x0c;
9035
9036         codec->patch_ops = alc_patch_ops;
9037         if (board_config == ALC883_AUTO)
9038                 spec->init_hook = alc883_auto_init;
9039
9040 #ifdef CONFIG_SND_HDA_POWER_SAVE
9041         if (!spec->loopback.amplist)
9042                 spec->loopback.amplist = alc883_loopbacks;
9043 #endif
9044
9045         return 0;
9046 }
9047
9048 /*
9049  * ALC262 support
9050  */
9051
9052 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9053 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9054
9055 #define alc262_dac_nids         alc260_dac_nids
9056 #define alc262_adc_nids         alc882_adc_nids
9057 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9058 #define alc262_capsrc_nids      alc882_capsrc_nids
9059 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9060
9061 #define alc262_modes            alc260_modes
9062 #define alc262_capture_source   alc882_capture_source
9063
9064 static hda_nid_t alc262_dmic_adc_nids[1] = {
9065         /* ADC0 */
9066         0x09
9067 };
9068
9069 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9070
9071 static struct snd_kcontrol_new alc262_base_mixer[] = {
9072         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9073         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9074         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9075         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9076         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9077         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9078         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9079         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9080         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9081         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9082         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9083         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9084         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9085            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9086         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9087         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9088         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9089         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9090         { } /* end */
9091 };
9092
9093 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
9094         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9095         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9096         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9097         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9098         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9099         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9100         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9101         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9102         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9103         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9104         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9105         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9106         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9107            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9108         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
9109         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9110         { } /* end */
9111 };
9112
9113 /* update HP, line and mono-out pins according to the master switch */
9114 static void alc262_hp_master_update(struct hda_codec *codec)
9115 {
9116         struct alc_spec *spec = codec->spec;
9117         int val = spec->master_sw;
9118
9119         /* HP & line-out */
9120         snd_hda_codec_write_cache(codec, 0x1b, 0,
9121                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9122                                   val ? PIN_HP : 0);
9123         snd_hda_codec_write_cache(codec, 0x15, 0,
9124                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9125                                   val ? PIN_HP : 0);
9126         /* mono (speaker) depending on the HP jack sense */
9127         val = val && !spec->jack_present;
9128         snd_hda_codec_write_cache(codec, 0x16, 0,
9129                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9130                                   val ? PIN_OUT : 0);
9131 }
9132
9133 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9134 {
9135         struct alc_spec *spec = codec->spec;
9136         unsigned int presence;
9137         presence = snd_hda_codec_read(codec, 0x1b, 0,
9138                                       AC_VERB_GET_PIN_SENSE, 0);
9139         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9140         alc262_hp_master_update(codec);
9141 }
9142
9143 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9144 {
9145         if ((res >> 26) != ALC880_HP_EVENT)
9146                 return;
9147         alc262_hp_bpc_automute(codec);
9148 }
9149
9150 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9151 {
9152         struct alc_spec *spec = codec->spec;
9153         unsigned int presence;
9154         presence = snd_hda_codec_read(codec, 0x15, 0,
9155                                       AC_VERB_GET_PIN_SENSE, 0);
9156         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9157         alc262_hp_master_update(codec);
9158 }
9159
9160 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9161                                            unsigned int res)
9162 {
9163         if ((res >> 26) != ALC880_HP_EVENT)
9164                 return;
9165         alc262_hp_wildwest_automute(codec);
9166 }
9167
9168 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
9169                                    struct snd_ctl_elem_value *ucontrol)
9170 {
9171         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9172         struct alc_spec *spec = codec->spec;
9173         *ucontrol->value.integer.value = spec->master_sw;
9174         return 0;
9175 }
9176
9177 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9178                                    struct snd_ctl_elem_value *ucontrol)
9179 {
9180         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9181         struct alc_spec *spec = codec->spec;
9182         int val = !!*ucontrol->value.integer.value;
9183
9184         if (val == spec->master_sw)
9185                 return 0;
9186         spec->master_sw = val;
9187         alc262_hp_master_update(codec);
9188         return 1;
9189 }
9190
9191 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9192         {
9193                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9194                 .name = "Master Playback Switch",
9195                 .info = snd_ctl_boolean_mono_info,
9196                 .get = alc262_hp_master_sw_get,
9197                 .put = alc262_hp_master_sw_put,
9198         },
9199         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9200         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9201         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9202         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9203                               HDA_OUTPUT),
9204         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9205                             HDA_OUTPUT),
9206         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9207         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9208         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9209         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9210         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9211         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9212         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9213         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9214         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9215         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9216         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9217         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9218         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9219         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9220         { } /* end */
9221 };
9222
9223 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9224         {
9225                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9226                 .name = "Master Playback Switch",
9227                 .info = snd_ctl_boolean_mono_info,
9228                 .get = alc262_hp_master_sw_get,
9229                 .put = alc262_hp_master_sw_put,
9230         },
9231         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9232         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9233         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9234         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9235         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9236                               HDA_OUTPUT),
9237         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9238                             HDA_OUTPUT),
9239         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9240         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9241         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9242         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9243         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9244         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9245         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9246         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9247         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9248         { } /* end */
9249 };
9250
9251 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9252         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9253         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9254         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9255         { } /* end */
9256 };
9257
9258 /* mute/unmute internal speaker according to the hp jack and mute state */
9259 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
9260 {
9261         struct alc_spec *spec = codec->spec;
9262
9263         if (force || !spec->sense_updated) {
9264                 unsigned int present;
9265                 present = snd_hda_codec_read(codec, 0x15, 0,
9266                                              AC_VERB_GET_PIN_SENSE, 0);
9267                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9268                 spec->sense_updated = 1;
9269         }
9270         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
9271                                  spec->jack_present ? HDA_AMP_MUTE : 0);
9272 }
9273
9274 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
9275                                         unsigned int res)
9276 {
9277         if ((res >> 26) != ALC880_HP_EVENT)
9278                 return;
9279         alc262_hp_t5735_automute(codec, 1);
9280 }
9281
9282 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9283 {
9284         alc262_hp_t5735_automute(codec, 1);
9285 }
9286
9287 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9288         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9289         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9290         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9291         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9292         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9293         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9294         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9295         { } /* end */
9296 };
9297
9298 static struct hda_verb alc262_hp_t5735_verbs[] = {
9299         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9300         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9301
9302         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9303         { }
9304 };
9305
9306 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9307         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9308         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9309         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9310         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9311         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9312         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9313         { } /* end */
9314 };
9315
9316 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9317         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9318         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9319         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9320         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9321         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9322         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9323         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9324         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9325         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9326         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9327         {}
9328 };
9329
9330 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9331         .num_items = 1,
9332         .items = {
9333                 { "Line", 0x1 },
9334         },
9335 };
9336
9337 /* bind hp and internal speaker mute (with plug check) */
9338 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9339                                      struct snd_ctl_elem_value *ucontrol)
9340 {
9341         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9342         long *valp = ucontrol->value.integer.value;
9343         int change;
9344
9345         /* change hp mute */
9346         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9347                                           HDA_AMP_MUTE,
9348                                           valp[0] ? 0 : HDA_AMP_MUTE);
9349         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9350                                            HDA_AMP_MUTE,
9351                                            valp[1] ? 0 : HDA_AMP_MUTE);
9352         if (change) {
9353                 /* change speaker according to HP jack state */
9354                 struct alc_spec *spec = codec->spec;
9355                 unsigned int mute;
9356                 if (spec->jack_present)
9357                         mute = HDA_AMP_MUTE;
9358                 else
9359                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9360                                                       HDA_OUTPUT, 0);
9361                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9362                                          HDA_AMP_MUTE, mute);
9363         }
9364         return change;
9365 }
9366
9367 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9368         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9369         {
9370                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9371                 .name = "Master Playback Switch",
9372                 .info = snd_hda_mixer_amp_switch_info,
9373                 .get = snd_hda_mixer_amp_switch_get,
9374                 .put = alc262_sony_master_sw_put,
9375                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9376         },
9377         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9378         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9379         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9380         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9381         { } /* end */
9382 };
9383
9384 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9385         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9386         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9387         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9388         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9389         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9390         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9391         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9392         { } /* end */
9393 };
9394
9395 #define alc262_capture_mixer            alc882_capture_mixer
9396 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9397
9398 /*
9399  * generic initialization of ADC, input mixers and output mixers
9400  */
9401 static struct hda_verb alc262_init_verbs[] = {
9402         /*
9403          * Unmute ADC0-2 and set the default input to mic-in
9404          */
9405         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9406         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9407         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9408         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9409         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9410         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9411
9412         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9413          * mixer widget
9414          * Note: PASD motherboards uses the Line In 2 as the input for
9415          * front panel mic (mic 2)
9416          */
9417         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9418         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9419         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9420         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9421         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9422         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9423
9424         /*
9425          * Set up output mixers (0x0c - 0x0e)
9426          */
9427         /* set vol=0 to output mixers */
9428         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9429         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9430         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9431         /* set up input amps for analog loopback */
9432         /* Amp Indices: DAC = 0, mixer = 1 */
9433         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9434         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9435         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9436         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9437         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9438         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9439
9440         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9441         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9442         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9443         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9444         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9445         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9446
9447         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9448         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9449         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9450         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9451         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9452
9453         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9454         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9455
9456         /* FIXME: use matrix-type input source selection */
9457         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9458         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9459         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9460         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9461         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9462         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9463         /* Input mixer2 */
9464         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9465         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9466         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9467         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9468         /* Input mixer3 */
9469         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9470         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9471         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9472         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9473
9474         { }
9475 };
9476
9477 static struct hda_verb alc262_eapd_verbs[] = {
9478         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9479         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9480         { }
9481 };
9482
9483 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9484         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9485         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9486         {}
9487 };
9488
9489 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9490         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9491         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9492         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9493
9494         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9495         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9496         {}
9497 };
9498
9499 static struct hda_verb alc262_sony_unsol_verbs[] = {
9500         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9501         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9502         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9503
9504         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9505         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9506         {}
9507 };
9508
9509 static struct hda_input_mux alc262_dmic_capture_source = {
9510         .num_items = 2,
9511         .items = {
9512                 { "Int DMic", 0x9 },
9513                 { "Mic", 0x0 },
9514         },
9515 };
9516
9517 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9518         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9519         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9520         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9521         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9522         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9523         { } /* end */
9524 };
9525
9526 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9527         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9528         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9529         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9530         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9531         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9532         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9533         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9534         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9535         {}
9536 };
9537
9538 static void alc262_dmic_automute(struct hda_codec *codec)
9539 {
9540         unsigned int present;
9541
9542         present = snd_hda_codec_read(codec, 0x18, 0,
9543                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9544         snd_hda_codec_write(codec, 0x22, 0,
9545                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9546 }
9547
9548 /* toggle speaker-output according to the hp-jack state */
9549 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9550 {
9551         unsigned int present;
9552         unsigned char bits;
9553
9554         present = snd_hda_codec_read(codec, 0x15, 0,
9555                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9556         bits = present ? 0 : PIN_OUT;
9557         snd_hda_codec_write(codec, 0x14, 0,
9558                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9559 }
9560
9561
9562
9563 /* unsolicited event for HP jack sensing */
9564 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9565                                        unsigned int res)
9566 {
9567         if ((res >> 26) == ALC880_HP_EVENT)
9568                 alc262_toshiba_s06_speaker_automute(codec);
9569         if ((res >> 26) == ALC880_MIC_EVENT)
9570                 alc262_dmic_automute(codec);
9571
9572 }
9573
9574 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9575 {
9576         alc262_toshiba_s06_speaker_automute(codec);
9577         alc262_dmic_automute(codec);
9578 }
9579
9580 /* mute/unmute internal speaker according to the hp jack and mute state */
9581 static void alc262_hippo_automute(struct hda_codec *codec)
9582 {
9583         struct alc_spec *spec = codec->spec;
9584         unsigned int mute;
9585         unsigned int present;
9586
9587         /* need to execute and sync at first */
9588         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9589         present = snd_hda_codec_read(codec, 0x15, 0,
9590                                      AC_VERB_GET_PIN_SENSE, 0);
9591         spec->jack_present = (present & 0x80000000) != 0;
9592         if (spec->jack_present) {
9593                 /* mute internal speaker */
9594                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9595                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9596         } else {
9597                 /* unmute internal speaker if necessary */
9598                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9599                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9600                                          HDA_AMP_MUTE, mute);
9601         }
9602 }
9603
9604 /* unsolicited event for HP jack sensing */
9605 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9606                                        unsigned int res)
9607 {
9608         if ((res >> 26) != ALC880_HP_EVENT)
9609                 return;
9610         alc262_hippo_automute(codec);
9611 }
9612
9613 static void alc262_hippo1_automute(struct hda_codec *codec)
9614 {
9615         unsigned int mute;
9616         unsigned int present;
9617
9618         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9619         present = snd_hda_codec_read(codec, 0x1b, 0,
9620                                      AC_VERB_GET_PIN_SENSE, 0);
9621         present = (present & 0x80000000) != 0;
9622         if (present) {
9623                 /* mute internal speaker */
9624                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9625                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9626         } else {
9627                 /* unmute internal speaker if necessary */
9628                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9629                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9630                                          HDA_AMP_MUTE, mute);
9631         }
9632 }
9633
9634 /* unsolicited event for HP jack sensing */
9635 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9636                                        unsigned int res)
9637 {
9638         if ((res >> 26) != ALC880_HP_EVENT)
9639                 return;
9640         alc262_hippo1_automute(codec);
9641 }
9642
9643 /*
9644  * nec model
9645  *  0x15 = headphone
9646  *  0x16 = internal speaker
9647  *  0x18 = external mic
9648  */
9649
9650 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9651         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9652         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9653
9654         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9655         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9656         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9657
9658         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9659         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9660         { } /* end */
9661 };
9662
9663 static struct hda_verb alc262_nec_verbs[] = {
9664         /* Unmute Speaker */
9665         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9666
9667         /* Headphone */
9668         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9669         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9670
9671         /* External mic to headphone */
9672         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9673         /* External mic to speaker */
9674         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9675         {}
9676 };
9677
9678 /*
9679  * fujitsu model
9680  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9681  *  0x1b = port replicator headphone out
9682  */
9683
9684 #define ALC_HP_EVENT    0x37
9685
9686 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9687         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9688         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9689         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9690         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9691         {}
9692 };
9693
9694 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9695         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9696         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9697         {}
9698 };
9699
9700 static struct hda_input_mux alc262_fujitsu_capture_source = {
9701         .num_items = 3,
9702         .items = {
9703                 { "Mic", 0x0 },
9704                 { "Int Mic", 0x1 },
9705                 { "CD", 0x4 },
9706         },
9707 };
9708
9709 static struct hda_input_mux alc262_HP_capture_source = {
9710         .num_items = 5,
9711         .items = {
9712                 { "Mic", 0x0 },
9713                 { "Front Mic", 0x1 },
9714                 { "Line", 0x2 },
9715                 { "CD", 0x4 },
9716                 { "AUX IN", 0x6 },
9717         },
9718 };
9719
9720 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9721         .num_items = 4,
9722         .items = {
9723                 { "Mic", 0x0 },
9724                 { "Front Mic", 0x2 },
9725                 { "Line", 0x1 },
9726                 { "CD", 0x4 },
9727         },
9728 };
9729
9730 /* mute/unmute internal speaker according to the hp jacks and mute state */
9731 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9732 {
9733         struct alc_spec *spec = codec->spec;
9734         unsigned int mute;
9735
9736         if (force || !spec->sense_updated) {
9737                 unsigned int present;
9738                 /* need to execute and sync at first */
9739                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9740                 /* check laptop HP jack */
9741                 present = snd_hda_codec_read(codec, 0x14, 0,
9742                                              AC_VERB_GET_PIN_SENSE, 0);
9743                 /* need to execute and sync at first */
9744                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9745                 /* check docking HP jack */
9746                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9747                                               AC_VERB_GET_PIN_SENSE, 0);
9748                 if (present & AC_PINSENSE_PRESENCE)
9749                         spec->jack_present = 1;
9750                 else
9751                         spec->jack_present = 0;
9752                 spec->sense_updated = 1;
9753         }
9754         /* unmute internal speaker only if both HPs are unplugged and
9755          * master switch is on
9756          */
9757         if (spec->jack_present)
9758                 mute = HDA_AMP_MUTE;
9759         else
9760                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9761         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9762                                  HDA_AMP_MUTE, mute);
9763 }
9764
9765 /* unsolicited event for HP jack sensing */
9766 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9767                                        unsigned int res)
9768 {
9769         if ((res >> 26) != ALC_HP_EVENT)
9770                 return;
9771         alc262_fujitsu_automute(codec, 1);
9772 }
9773
9774 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9775 {
9776         alc262_fujitsu_automute(codec, 1);
9777 }
9778
9779 /* bind volumes of both NID 0x0c and 0x0d */
9780 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9781         .ops = &snd_hda_bind_vol,
9782         .values = {
9783                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9784                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9785                 0
9786         },
9787 };
9788
9789 /* mute/unmute internal speaker according to the hp jack and mute state */
9790 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9791 {
9792         struct alc_spec *spec = codec->spec;
9793         unsigned int mute;
9794
9795         if (force || !spec->sense_updated) {
9796                 unsigned int present_int_hp;
9797                 /* need to execute and sync at first */
9798                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9799                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9800                                         AC_VERB_GET_PIN_SENSE, 0);
9801                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9802                 spec->sense_updated = 1;
9803         }
9804         if (spec->jack_present) {
9805                 /* mute internal speaker */
9806                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9807                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9808                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9809                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9810         } else {
9811                 /* unmute internal speaker if necessary */
9812                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9813                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9814                                          HDA_AMP_MUTE, mute);
9815                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9816                                          HDA_AMP_MUTE, mute);
9817         }
9818 }
9819
9820 /* unsolicited event for HP jack sensing */
9821 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9822                                        unsigned int res)
9823 {
9824         if ((res >> 26) != ALC_HP_EVENT)
9825                 return;
9826         alc262_lenovo_3000_automute(codec, 1);
9827 }
9828
9829 /* bind hp and internal speaker mute (with plug check) */
9830 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9831                                          struct snd_ctl_elem_value *ucontrol)
9832 {
9833         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9834         long *valp = ucontrol->value.integer.value;
9835         int change;
9836
9837         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9838                                                  HDA_AMP_MUTE,
9839                                                  valp ? 0 : HDA_AMP_MUTE);
9840         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9841                                                  HDA_AMP_MUTE,
9842                                                  valp ? 0 : HDA_AMP_MUTE);
9843
9844         if (change)
9845                 alc262_fujitsu_automute(codec, 0);
9846         return change;
9847 }
9848
9849 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9850         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9851         {
9852                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9853                 .name = "Master Playback Switch",
9854                 .info = snd_hda_mixer_amp_switch_info,
9855                 .get = snd_hda_mixer_amp_switch_get,
9856                 .put = alc262_fujitsu_master_sw_put,
9857                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9858         },
9859         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9860         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9861         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9862         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9863         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9864         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9865         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9866         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9867         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9868         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9869         { } /* end */
9870 };
9871
9872 /* bind hp and internal speaker mute (with plug check) */
9873 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9874                                          struct snd_ctl_elem_value *ucontrol)
9875 {
9876         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9877         long *valp = ucontrol->value.integer.value;
9878         int change;
9879
9880         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9881                                                  HDA_AMP_MUTE,
9882                                                  valp ? 0 : HDA_AMP_MUTE);
9883
9884         if (change)
9885                 alc262_lenovo_3000_automute(codec, 0);
9886         return change;
9887 }
9888
9889 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9890         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9891         {
9892                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9893                 .name = "Master Playback Switch",
9894                 .info = snd_hda_mixer_amp_switch_info,
9895                 .get = snd_hda_mixer_amp_switch_get,
9896                 .put = alc262_lenovo_3000_master_sw_put,
9897                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9898         },
9899         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9900         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9901         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9902         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9903         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9904         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9905         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9906         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9907         { } /* end */
9908 };
9909
9910 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
9911         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9912         {
9913                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9914                 .name = "Master Playback Switch",
9915                 .info = snd_hda_mixer_amp_switch_info,
9916                 .get = snd_hda_mixer_amp_switch_get,
9917                 .put = alc262_sony_master_sw_put,
9918                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9919         },
9920         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9921         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9922         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9923         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9924         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9925         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9926         { } /* end */
9927 };
9928
9929 /* additional init verbs for Benq laptops */
9930 static struct hda_verb alc262_EAPD_verbs[] = {
9931         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9932         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9933         {}
9934 };
9935
9936 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9937         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9938         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9939
9940         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9941         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9942         {}
9943 };
9944
9945 /* Samsung Q1 Ultra Vista model setup */
9946 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9947         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9948         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9949         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9950         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9951         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9952         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9953         { } /* end */
9954 };
9955
9956 static struct hda_verb alc262_ultra_verbs[] = {
9957         /* output mixer */
9958         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9959         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9960         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9961         /* speaker */
9962         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9963         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9964         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9965         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9966         /* HP */
9967         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9968         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9969         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9970         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9971         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9972         /* internal mic */
9973         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9974         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9975         /* ADC, choose mic */
9976         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9977         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9978         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9979         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9980         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9981         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9982         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9983         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9984         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9985         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
9986         {}
9987 };
9988
9989 /* mute/unmute internal speaker according to the hp jack and mute state */
9990 static void alc262_ultra_automute(struct hda_codec *codec)
9991 {
9992         struct alc_spec *spec = codec->spec;
9993         unsigned int mute;
9994
9995         mute = 0;
9996         /* auto-mute only when HP is used as HP */
9997         if (!spec->cur_mux[0]) {
9998                 unsigned int present;
9999                 /* need to execute and sync at first */
10000                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10001                 present = snd_hda_codec_read(codec, 0x15, 0,
10002                                              AC_VERB_GET_PIN_SENSE, 0);
10003                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10004                 if (spec->jack_present)
10005                         mute = HDA_AMP_MUTE;
10006         }
10007         /* mute/unmute internal speaker */
10008         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10009                                  HDA_AMP_MUTE, mute);
10010         /* mute/unmute HP */
10011         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10012                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10013 }
10014
10015 /* unsolicited event for HP jack sensing */
10016 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10017                                        unsigned int res)
10018 {
10019         if ((res >> 26) != ALC880_HP_EVENT)
10020                 return;
10021         alc262_ultra_automute(codec);
10022 }
10023
10024 static struct hda_input_mux alc262_ultra_capture_source = {
10025         .num_items = 2,
10026         .items = {
10027                 { "Mic", 0x1 },
10028                 { "Headphone", 0x7 },
10029         },
10030 };
10031
10032 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10033                                      struct snd_ctl_elem_value *ucontrol)
10034 {
10035         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10036         struct alc_spec *spec = codec->spec;
10037         int ret;
10038
10039         ret = alc_mux_enum_put(kcontrol, ucontrol);
10040         if (!ret)
10041                 return 0;
10042         /* reprogram the HP pin as mic or HP according to the input source */
10043         snd_hda_codec_write_cache(codec, 0x15, 0,
10044                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10045                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10046         alc262_ultra_automute(codec); /* mute/unmute HP */
10047         return ret;
10048 }
10049
10050 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10051         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10052         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10053         {
10054                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10055                 .name = "Capture Source",
10056                 .info = alc_mux_enum_info,
10057                 .get = alc_mux_enum_get,
10058                 .put = alc262_ultra_mux_enum_put,
10059         },
10060         { } /* end */
10061 };
10062
10063 /* add playback controls from the parsed DAC table */
10064 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10065                                              const struct auto_pin_cfg *cfg)
10066 {
10067         hda_nid_t nid;
10068         int err;
10069
10070         spec->multiout.num_dacs = 1;    /* only use one dac */
10071         spec->multiout.dac_nids = spec->private_dac_nids;
10072         spec->multiout.dac_nids[0] = 2;
10073
10074         nid = cfg->line_out_pins[0];
10075         if (nid) {
10076                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10077                                   "Front Playback Volume",
10078                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10079                 if (err < 0)
10080                         return err;
10081                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10082                                   "Front Playback Switch",
10083                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10084                 if (err < 0)
10085                         return err;
10086         }
10087
10088         nid = cfg->speaker_pins[0];
10089         if (nid) {
10090                 if (nid == 0x16) {
10091                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10092                                           "Speaker Playback Volume",
10093                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10094                                                               HDA_OUTPUT));
10095                         if (err < 0)
10096                                 return err;
10097                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10098                                           "Speaker Playback Switch",
10099                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10100                                                               HDA_OUTPUT));
10101                         if (err < 0)
10102                                 return err;
10103                 } else {
10104                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10105                                           "Speaker Playback Switch",
10106                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10107                                                               HDA_OUTPUT));
10108                         if (err < 0)
10109                                 return err;
10110                 }
10111         }
10112         nid = cfg->hp_pins[0];
10113         if (nid) {
10114                 /* spec->multiout.hp_nid = 2; */
10115                 if (nid == 0x16) {
10116                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10117                                           "Headphone Playback Volume",
10118                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10119                                                               HDA_OUTPUT));
10120                         if (err < 0)
10121                                 return err;
10122                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10123                                           "Headphone Playback Switch",
10124                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10125                                                               HDA_OUTPUT));
10126                         if (err < 0)
10127                                 return err;
10128                 } else {
10129                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10130                                           "Headphone Playback Switch",
10131                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10132                                                               HDA_OUTPUT));
10133                         if (err < 0)
10134                                 return err;
10135                 }
10136         }
10137         return 0;
10138 }
10139
10140 /* identical with ALC880 */
10141 #define alc262_auto_create_analog_input_ctls \
10142         alc880_auto_create_analog_input_ctls
10143
10144 /*
10145  * generic initialization of ADC, input mixers and output mixers
10146  */
10147 static struct hda_verb alc262_volume_init_verbs[] = {
10148         /*
10149          * Unmute ADC0-2 and set the default input to mic-in
10150          */
10151         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10152         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10153         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10154         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10155         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10156         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10157
10158         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10159          * mixer widget
10160          * Note: PASD motherboards uses the Line In 2 as the input for
10161          * front panel mic (mic 2)
10162          */
10163         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10164         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10165         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10166         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10167         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10168         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10169
10170         /*
10171          * Set up output mixers (0x0c - 0x0f)
10172          */
10173         /* set vol=0 to output mixers */
10174         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10175         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10176         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10177
10178         /* set up input amps for analog loopback */
10179         /* Amp Indices: DAC = 0, mixer = 1 */
10180         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10181         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10182         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10183         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10184         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10185         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10186
10187         /* FIXME: use matrix-type input source selection */
10188         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10189         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10190         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10191         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10192         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10193         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10194         /* Input mixer2 */
10195         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10196         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10197         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10198         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10199         /* Input mixer3 */
10200         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10201         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10202         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10203         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10204
10205         { }
10206 };
10207
10208 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10209         /*
10210          * Unmute ADC0-2 and set the default input to mic-in
10211          */
10212         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10213         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10214         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10215         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10216         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10217         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10218
10219         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10220          * mixer widget
10221          * Note: PASD motherboards uses the Line In 2 as the input for
10222          * front panel mic (mic 2)
10223          */
10224         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10225         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10226         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10227         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10228         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10229         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10230         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10231         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10232
10233         /*
10234          * Set up output mixers (0x0c - 0x0e)
10235          */
10236         /* set vol=0 to output mixers */
10237         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10238         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10239         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10240
10241         /* set up input amps for analog loopback */
10242         /* Amp Indices: DAC = 0, mixer = 1 */
10243         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10244         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10245         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10246         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10247         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10248         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10249
10250         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10251         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10252         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10253
10254         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10255         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10256
10257         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10258         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10259
10260         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10261         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10262         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10263         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10264         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10265
10266         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10267         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10268         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10269         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10270         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10271         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10272
10273
10274         /* FIXME: use matrix-type input source selection */
10275         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10276         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10277         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10278         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10279         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10280         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10281         /* Input mixer2 */
10282         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10283         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10284         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10285         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10286         /* Input mixer3 */
10287         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10288         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10289         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10290         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10291
10292         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10293
10294         { }
10295 };
10296
10297 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10298         /*
10299          * Unmute ADC0-2 and set the default input to mic-in
10300          */
10301         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10302         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10303         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10304         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10305         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10306         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10307
10308         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10309          * mixer widget
10310          * Note: PASD motherboards uses the Line In 2 as the input for front
10311          * panel mic (mic 2)
10312          */
10313         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10314         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10315         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10316         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10317         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10318         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10319         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10320         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10321         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10322         /*
10323          * Set up output mixers (0x0c - 0x0e)
10324          */
10325         /* set vol=0 to output mixers */
10326         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10327         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10328         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10329
10330         /* set up input amps for analog loopback */
10331         /* Amp Indices: DAC = 0, mixer = 1 */
10332         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10333         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10334         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10335         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10336         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10337         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10338
10339
10340         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10341         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10342         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10343         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10344         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10345         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10346         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10347
10348         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10349         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10350
10351         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10352         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10353
10354         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10355         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10356         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10357         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10358         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10359         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10360
10361         /* FIXME: use matrix-type input source selection */
10362         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10363         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10364         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10365         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10366         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10367         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10368         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10369         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10370         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10371         /* Input mixer2 */
10372         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10373         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10374         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10375         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10376         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10377         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10378         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10379         /* Input mixer3 */
10380         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10381         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10382         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10383         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10384         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10385         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10386         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10387
10388         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10389
10390         { }
10391 };
10392
10393 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10394
10395         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10396         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10397         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10398
10399         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10400         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10401         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10402         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10403
10404         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10405         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10406         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10407         {}
10408 };
10409
10410
10411 #ifdef CONFIG_SND_HDA_POWER_SAVE
10412 #define alc262_loopbacks        alc880_loopbacks
10413 #endif
10414
10415 /* pcm configuration: identiacal with ALC880 */
10416 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10417 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10418 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10419 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10420
10421 /*
10422  * BIOS auto configuration
10423  */
10424 static int alc262_parse_auto_config(struct hda_codec *codec)
10425 {
10426         struct alc_spec *spec = codec->spec;
10427         int err;
10428         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10429
10430         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10431                                            alc262_ignore);
10432         if (err < 0)
10433                 return err;
10434         if (!spec->autocfg.line_outs)
10435                 return 0; /* can't find valid BIOS pin config */
10436         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10437         if (err < 0)
10438                 return err;
10439         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10440         if (err < 0)
10441                 return err;
10442
10443         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10444
10445         if (spec->autocfg.dig_out_pin)
10446                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10447         if (spec->autocfg.dig_in_pin)
10448                 spec->dig_in_nid = ALC262_DIGIN_NID;
10449
10450         if (spec->kctls.list)
10451                 add_mixer(spec, spec->kctls.list);
10452
10453         add_verb(spec, alc262_volume_init_verbs);
10454         spec->num_mux_defs = 1;
10455         spec->input_mux = &spec->private_imux;
10456
10457         err = alc_auto_add_mic_boost(codec);
10458         if (err < 0)
10459                 return err;
10460
10461         store_pin_configs(codec);
10462         return 1;
10463 }
10464
10465 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10466 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10467 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10468 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10469
10470
10471 /* init callback for auto-configuration model -- overriding the default init */
10472 static void alc262_auto_init(struct hda_codec *codec)
10473 {
10474         struct alc_spec *spec = codec->spec;
10475         alc262_auto_init_multi_out(codec);
10476         alc262_auto_init_hp_out(codec);
10477         alc262_auto_init_analog_input(codec);
10478         alc262_auto_init_input_src(codec);
10479         if (spec->unsol_event)
10480                 alc_inithook(codec);
10481 }
10482
10483 /*
10484  * configuration and preset
10485  */
10486 static const char *alc262_models[ALC262_MODEL_LAST] = {
10487         [ALC262_BASIC]          = "basic",
10488         [ALC262_HIPPO]          = "hippo",
10489         [ALC262_HIPPO_1]        = "hippo_1",
10490         [ALC262_FUJITSU]        = "fujitsu",
10491         [ALC262_HP_BPC]         = "hp-bpc",
10492         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10493         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10494         [ALC262_HP_RP5700]      = "hp-rp5700",
10495         [ALC262_BENQ_ED8]       = "benq",
10496         [ALC262_BENQ_T31]       = "benq-t31",
10497         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10498         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10499         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10500         [ALC262_ULTRA]          = "ultra",
10501         [ALC262_LENOVO_3000]    = "lenovo-3000",
10502         [ALC262_NEC]            = "nec",
10503         [ALC262_AUTO]           = "auto",
10504 };
10505
10506 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10507         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10508         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10509         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
10510         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
10511         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
10512         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
10513         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
10514         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
10515         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10516         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10517         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10518         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10519         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10520         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10521         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10522         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10523         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10524         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10525         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10526         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10527         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10528         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10529                       ALC262_HP_TC_T5735),
10530         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10531         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10532         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10533         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10534         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10535         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10536         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10537                       ALC262_TOSHIBA_RX1),
10538         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10539         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10540         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10541         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
10542         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
10543         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10544         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10545         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10546         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10547         {}
10548 };
10549
10550 static struct alc_config_preset alc262_presets[] = {
10551         [ALC262_BASIC] = {
10552                 .mixers = { alc262_base_mixer },
10553                 .init_verbs = { alc262_init_verbs },
10554                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10555                 .dac_nids = alc262_dac_nids,
10556                 .hp_nid = 0x03,
10557                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10558                 .channel_mode = alc262_modes,
10559                 .input_mux = &alc262_capture_source,
10560         },
10561         [ALC262_HIPPO] = {
10562                 .mixers = { alc262_base_mixer },
10563                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10564                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10565                 .dac_nids = alc262_dac_nids,
10566                 .hp_nid = 0x03,
10567                 .dig_out_nid = ALC262_DIGOUT_NID,
10568                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10569                 .channel_mode = alc262_modes,
10570                 .input_mux = &alc262_capture_source,
10571                 .unsol_event = alc262_hippo_unsol_event,
10572                 .init_hook = alc262_hippo_automute,
10573         },
10574         [ALC262_HIPPO_1] = {
10575                 .mixers = { alc262_hippo1_mixer },
10576                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10577                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10578                 .dac_nids = alc262_dac_nids,
10579                 .hp_nid = 0x02,
10580                 .dig_out_nid = ALC262_DIGOUT_NID,
10581                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10582                 .channel_mode = alc262_modes,
10583                 .input_mux = &alc262_capture_source,
10584                 .unsol_event = alc262_hippo1_unsol_event,
10585                 .init_hook = alc262_hippo1_automute,
10586         },
10587         [ALC262_FUJITSU] = {
10588                 .mixers = { alc262_fujitsu_mixer },
10589                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10590                                 alc262_fujitsu_unsol_verbs },
10591                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10592                 .dac_nids = alc262_dac_nids,
10593                 .hp_nid = 0x03,
10594                 .dig_out_nid = ALC262_DIGOUT_NID,
10595                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10596                 .channel_mode = alc262_modes,
10597                 .input_mux = &alc262_fujitsu_capture_source,
10598                 .unsol_event = alc262_fujitsu_unsol_event,
10599                 .init_hook = alc262_fujitsu_init_hook,
10600         },
10601         [ALC262_HP_BPC] = {
10602                 .mixers = { alc262_HP_BPC_mixer },
10603                 .init_verbs = { alc262_HP_BPC_init_verbs },
10604                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10605                 .dac_nids = alc262_dac_nids,
10606                 .hp_nid = 0x03,
10607                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10608                 .channel_mode = alc262_modes,
10609                 .input_mux = &alc262_HP_capture_source,
10610                 .unsol_event = alc262_hp_bpc_unsol_event,
10611                 .init_hook = alc262_hp_bpc_automute,
10612         },
10613         [ALC262_HP_BPC_D7000_WF] = {
10614                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10615                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10616                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10617                 .dac_nids = alc262_dac_nids,
10618                 .hp_nid = 0x03,
10619                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10620                 .channel_mode = alc262_modes,
10621                 .input_mux = &alc262_HP_D7000_capture_source,
10622                 .unsol_event = alc262_hp_wildwest_unsol_event,
10623                 .init_hook = alc262_hp_wildwest_automute,
10624         },
10625         [ALC262_HP_BPC_D7000_WL] = {
10626                 .mixers = { alc262_HP_BPC_WildWest_mixer,
10627                             alc262_HP_BPC_WildWest_option_mixer },
10628                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10629                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10630                 .dac_nids = alc262_dac_nids,
10631                 .hp_nid = 0x03,
10632                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10633                 .channel_mode = alc262_modes,
10634                 .input_mux = &alc262_HP_D7000_capture_source,
10635                 .unsol_event = alc262_hp_wildwest_unsol_event,
10636                 .init_hook = alc262_hp_wildwest_automute,
10637         },
10638         [ALC262_HP_TC_T5735] = {
10639                 .mixers = { alc262_hp_t5735_mixer },
10640                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10641                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10642                 .dac_nids = alc262_dac_nids,
10643                 .hp_nid = 0x03,
10644                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10645                 .channel_mode = alc262_modes,
10646                 .input_mux = &alc262_capture_source,
10647                 .unsol_event = alc262_hp_t5735_unsol_event,
10648                 .init_hook = alc262_hp_t5735_init_hook,
10649         },
10650         [ALC262_HP_RP5700] = {
10651                 .mixers = { alc262_hp_rp5700_mixer },
10652                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10653                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10654                 .dac_nids = alc262_dac_nids,
10655                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10656                 .channel_mode = alc262_modes,
10657                 .input_mux = &alc262_hp_rp5700_capture_source,
10658         },
10659         [ALC262_BENQ_ED8] = {
10660                 .mixers = { alc262_base_mixer },
10661                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
10662                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10663                 .dac_nids = alc262_dac_nids,
10664                 .hp_nid = 0x03,
10665                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10666                 .channel_mode = alc262_modes,
10667                 .input_mux = &alc262_capture_source,
10668         },
10669         [ALC262_SONY_ASSAMD] = {
10670                 .mixers = { alc262_sony_mixer },
10671                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10672                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10673                 .dac_nids = alc262_dac_nids,
10674                 .hp_nid = 0x02,
10675                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10676                 .channel_mode = alc262_modes,
10677                 .input_mux = &alc262_capture_source,
10678                 .unsol_event = alc262_hippo_unsol_event,
10679                 .init_hook = alc262_hippo_automute,
10680         },
10681         [ALC262_BENQ_T31] = {
10682                 .mixers = { alc262_benq_t31_mixer },
10683                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10684                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10685                 .dac_nids = alc262_dac_nids,
10686                 .hp_nid = 0x03,
10687                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10688                 .channel_mode = alc262_modes,
10689                 .input_mux = &alc262_capture_source,
10690                 .unsol_event = alc262_hippo_unsol_event,
10691                 .init_hook = alc262_hippo_automute,
10692         },
10693         [ALC262_ULTRA] = {
10694                 .mixers = { alc262_ultra_mixer },
10695                 .cap_mixer = alc262_ultra_capture_mixer,
10696                 .init_verbs = { alc262_ultra_verbs },
10697                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10698                 .dac_nids = alc262_dac_nids,
10699                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10700                 .channel_mode = alc262_modes,
10701                 .input_mux = &alc262_ultra_capture_source,
10702                 .adc_nids = alc262_adc_nids, /* ADC0 */
10703                 .capsrc_nids = alc262_capsrc_nids,
10704                 .num_adc_nids = 1, /* single ADC */
10705                 .unsol_event = alc262_ultra_unsol_event,
10706                 .init_hook = alc262_ultra_automute,
10707         },
10708         [ALC262_LENOVO_3000] = {
10709                 .mixers = { alc262_lenovo_3000_mixer },
10710                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10711                                 alc262_lenovo_3000_unsol_verbs },
10712                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10713                 .dac_nids = alc262_dac_nids,
10714                 .hp_nid = 0x03,
10715                 .dig_out_nid = ALC262_DIGOUT_NID,
10716                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10717                 .channel_mode = alc262_modes,
10718                 .input_mux = &alc262_fujitsu_capture_source,
10719                 .unsol_event = alc262_lenovo_3000_unsol_event,
10720         },
10721         [ALC262_NEC] = {
10722                 .mixers = { alc262_nec_mixer },
10723                 .init_verbs = { alc262_nec_verbs },
10724                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10725                 .dac_nids = alc262_dac_nids,
10726                 .hp_nid = 0x03,
10727                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10728                 .channel_mode = alc262_modes,
10729                 .input_mux = &alc262_capture_source,
10730         },
10731         [ALC262_TOSHIBA_S06] = {
10732                 .mixers = { alc262_toshiba_s06_mixer },
10733                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10734                                                         alc262_eapd_verbs },
10735                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10736                 .capsrc_nids = alc262_dmic_capsrc_nids,
10737                 .dac_nids = alc262_dac_nids,
10738                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10739                 .dig_out_nid = ALC262_DIGOUT_NID,
10740                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10741                 .channel_mode = alc262_modes,
10742                 .input_mux = &alc262_dmic_capture_source,
10743                 .unsol_event = alc262_toshiba_s06_unsol_event,
10744                 .init_hook = alc262_toshiba_s06_init_hook,
10745         },
10746         [ALC262_TOSHIBA_RX1] = {
10747                 .mixers = { alc262_toshiba_rx1_mixer },
10748                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
10749                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10750                 .dac_nids = alc262_dac_nids,
10751                 .hp_nid = 0x03,
10752                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10753                 .channel_mode = alc262_modes,
10754                 .input_mux = &alc262_capture_source,
10755                 .unsol_event = alc262_hippo_unsol_event,
10756                 .init_hook = alc262_hippo_automute,
10757         },
10758 };
10759
10760 static int patch_alc262(struct hda_codec *codec)
10761 {
10762         struct alc_spec *spec;
10763         int board_config;
10764         int err;
10765
10766         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10767         if (spec == NULL)
10768                 return -ENOMEM;
10769
10770         codec->spec = spec;
10771 #if 0
10772         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10773          * under-run
10774          */
10775         {
10776         int tmp;
10777         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10778         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10779         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10780         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10781         }
10782 #endif
10783
10784         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10785
10786         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10787                                                   alc262_models,
10788                                                   alc262_cfg_tbl);
10789
10790         if (board_config < 0) {
10791                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10792                        "trying auto-probe from BIOS...\n");
10793                 board_config = ALC262_AUTO;
10794         }
10795
10796         if (board_config == ALC262_AUTO) {
10797                 /* automatic parse from the BIOS config */
10798                 err = alc262_parse_auto_config(codec);
10799                 if (err < 0) {
10800                         alc_free(codec);
10801                         return err;
10802                 } else if (!err) {
10803                         printk(KERN_INFO
10804                                "hda_codec: Cannot set up configuration "
10805                                "from BIOS.  Using base mode...\n");
10806                         board_config = ALC262_BASIC;
10807                 }
10808         }
10809
10810         if (board_config != ALC262_AUTO)
10811                 setup_preset(spec, &alc262_presets[board_config]);
10812
10813         spec->stream_name_analog = "ALC262 Analog";
10814         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10815         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10816
10817         spec->stream_name_digital = "ALC262 Digital";
10818         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10819         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10820
10821         spec->is_mix_capture = 1;
10822         if (!spec->adc_nids && spec->input_mux) {
10823                 /* check whether NID 0x07 is valid */
10824                 unsigned int wcap = get_wcaps(codec, 0x07);
10825
10826                 /* get type */
10827                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10828                 if (wcap != AC_WID_AUD_IN) {
10829                         spec->adc_nids = alc262_adc_nids_alt;
10830                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10831                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10832                 } else {
10833                         spec->adc_nids = alc262_adc_nids;
10834                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10835                         spec->capsrc_nids = alc262_capsrc_nids;
10836                 }
10837         }
10838         if (!spec->cap_mixer)
10839                 set_capture_mixer(spec);
10840
10841         spec->vmaster_nid = 0x0c;
10842
10843         codec->patch_ops = alc_patch_ops;
10844         if (board_config == ALC262_AUTO)
10845                 spec->init_hook = alc262_auto_init;
10846 #ifdef CONFIG_SND_HDA_POWER_SAVE
10847         if (!spec->loopback.amplist)
10848                 spec->loopback.amplist = alc262_loopbacks;
10849 #endif
10850
10851         return 0;
10852 }
10853
10854 /*
10855  *  ALC268 channel source setting (2 channel)
10856  */
10857 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10858 #define alc268_modes            alc260_modes
10859
10860 static hda_nid_t alc268_dac_nids[2] = {
10861         /* front, hp */
10862         0x02, 0x03
10863 };
10864
10865 static hda_nid_t alc268_adc_nids[2] = {
10866         /* ADC0-1 */
10867         0x08, 0x07
10868 };
10869
10870 static hda_nid_t alc268_adc_nids_alt[1] = {
10871         /* ADC0 */
10872         0x08
10873 };
10874
10875 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10876
10877 static struct snd_kcontrol_new alc268_base_mixer[] = {
10878         /* output mixer control */
10879         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10880         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10881         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10882         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10883         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10884         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10885         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10886         { }
10887 };
10888
10889 /* bind Beep switches of both NID 0x0f and 0x10 */
10890 static struct hda_bind_ctls alc268_bind_beep_sw = {
10891         .ops = &snd_hda_bind_sw,
10892         .values = {
10893                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10894                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10895                 0
10896         },
10897 };
10898
10899 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10900         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10901         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10902         { }
10903 };
10904
10905 static struct hda_verb alc268_eapd_verbs[] = {
10906         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10907         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10908         { }
10909 };
10910
10911 /* Toshiba specific */
10912 #define alc268_toshiba_automute alc262_hippo_automute
10913
10914 static struct hda_verb alc268_toshiba_verbs[] = {
10915         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10916         { } /* end */
10917 };
10918
10919 static struct hda_input_mux alc268_acer_lc_capture_source = {
10920         .num_items = 2,
10921         .items = {
10922                 { "i-Mic", 0x6 },
10923                 { "E-Mic", 0x0 },
10924         },
10925 };
10926
10927 /* Acer specific */
10928 /* bind volumes of both NID 0x02 and 0x03 */
10929 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10930         .ops = &snd_hda_bind_vol,
10931         .values = {
10932                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10933                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10934                 0
10935         },
10936 };
10937
10938 /* mute/unmute internal speaker according to the hp jack and mute state */
10939 static void alc268_acer_automute(struct hda_codec *codec, int force)
10940 {
10941         struct alc_spec *spec = codec->spec;
10942         unsigned int mute;
10943
10944         if (force || !spec->sense_updated) {
10945                 unsigned int present;
10946                 present = snd_hda_codec_read(codec, 0x14, 0,
10947                                          AC_VERB_GET_PIN_SENSE, 0);
10948                 spec->jack_present = (present & 0x80000000) != 0;
10949                 spec->sense_updated = 1;
10950         }
10951         if (spec->jack_present)
10952                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10953         else /* unmute internal speaker if necessary */
10954                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10955         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10956                                  HDA_AMP_MUTE, mute);
10957 }
10958
10959
10960 /* bind hp and internal speaker mute (with plug check) */
10961 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10962                                      struct snd_ctl_elem_value *ucontrol)
10963 {
10964         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10965         long *valp = ucontrol->value.integer.value;
10966         int change;
10967
10968         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10969                                           HDA_AMP_MUTE,
10970                                           valp[0] ? 0 : HDA_AMP_MUTE);
10971         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10972                                            HDA_AMP_MUTE,
10973                                            valp[1] ? 0 : HDA_AMP_MUTE);
10974         if (change)
10975                 alc268_acer_automute(codec, 0);
10976         return change;
10977 }
10978
10979 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
10980         /* output mixer control */
10981         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10982         {
10983                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10984                 .name = "Master Playback Switch",
10985                 .info = snd_hda_mixer_amp_switch_info,
10986                 .get = snd_hda_mixer_amp_switch_get,
10987                 .put = alc268_acer_master_sw_put,
10988                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10989         },
10990         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
10991         { }
10992 };
10993
10994 static struct snd_kcontrol_new alc268_acer_mixer[] = {
10995         /* output mixer control */
10996         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10997         {
10998                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10999                 .name = "Master Playback Switch",
11000                 .info = snd_hda_mixer_amp_switch_info,
11001                 .get = snd_hda_mixer_amp_switch_get,
11002                 .put = alc268_acer_master_sw_put,
11003                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11004         },
11005         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11006         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11007         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11008         { }
11009 };
11010
11011 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11012         /* output mixer control */
11013         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11014         {
11015                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11016                 .name = "Master Playback Switch",
11017                 .info = snd_hda_mixer_amp_switch_info,
11018                 .get = snd_hda_mixer_amp_switch_get,
11019                 .put = alc268_acer_master_sw_put,
11020                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11021         },
11022         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11023         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11024         { }
11025 };
11026
11027 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11028         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11029         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11030         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11031         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11032         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11033         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11034         { }
11035 };
11036
11037 static struct hda_verb alc268_acer_verbs[] = {
11038         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11039         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11040         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11041         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11042         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11043         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11044         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11045         { }
11046 };
11047
11048 /* unsolicited event for HP jack sensing */
11049 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
11050                                        unsigned int res)
11051 {
11052         if ((res >> 26) != ALC880_HP_EVENT)
11053                 return;
11054         alc268_toshiba_automute(codec);
11055 }
11056
11057 static void alc268_acer_unsol_event(struct hda_codec *codec,
11058                                        unsigned int res)
11059 {
11060         if ((res >> 26) != ALC880_HP_EVENT)
11061                 return;
11062         alc268_acer_automute(codec, 1);
11063 }
11064
11065 static void alc268_acer_init_hook(struct hda_codec *codec)
11066 {
11067         alc268_acer_automute(codec, 1);
11068 }
11069
11070 /* toggle speaker-output according to the hp-jack state */
11071 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11072 {
11073         unsigned int present;
11074         unsigned char bits;
11075
11076         present = snd_hda_codec_read(codec, 0x15, 0,
11077                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11078         bits = present ? AMP_IN_MUTE(0) : 0;
11079         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
11080                                 AMP_IN_MUTE(0), bits);
11081         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
11082                                 AMP_IN_MUTE(0), bits);
11083 }
11084
11085
11086 static void alc268_acer_mic_automute(struct hda_codec *codec)
11087 {
11088         unsigned int present;
11089
11090         present = snd_hda_codec_read(codec, 0x18, 0,
11091                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11092         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11093                             present ? 0x0 : 0x6);
11094 }
11095
11096 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11097                                     unsigned int res)
11098 {
11099         if ((res >> 26) == ALC880_HP_EVENT)
11100                 alc268_aspire_one_speaker_automute(codec);
11101         if ((res >> 26) == ALC880_MIC_EVENT)
11102                 alc268_acer_mic_automute(codec);
11103 }
11104
11105 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11106 {
11107         alc268_aspire_one_speaker_automute(codec);
11108         alc268_acer_mic_automute(codec);
11109 }
11110
11111 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11112         /* output mixer control */
11113         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11114         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11115         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11116         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11117         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11118         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11119         { }
11120 };
11121
11122 static struct hda_verb alc268_dell_verbs[] = {
11123         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11124         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11125         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11126         { }
11127 };
11128
11129 /* mute/unmute internal speaker according to the hp jack and mute state */
11130 static void alc268_dell_automute(struct hda_codec *codec)
11131 {
11132         unsigned int present;
11133         unsigned int mute;
11134
11135         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
11136         if (present & 0x80000000)
11137                 mute = HDA_AMP_MUTE;
11138         else
11139                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
11140         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11141                                  HDA_AMP_MUTE, mute);
11142 }
11143
11144 static void alc268_dell_unsol_event(struct hda_codec *codec,
11145                                     unsigned int res)
11146 {
11147         if ((res >> 26) != ALC880_HP_EVENT)
11148                 return;
11149         alc268_dell_automute(codec);
11150 }
11151
11152 #define alc268_dell_init_hook   alc268_dell_automute
11153
11154 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
11155         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11156         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11157         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11158         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11159         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11160         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
11161         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
11162         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
11163         { }
11164 };
11165
11166 static struct hda_verb alc267_quanta_il1_verbs[] = {
11167         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11168         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
11169         { }
11170 };
11171
11172 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
11173 {
11174         unsigned int present;
11175
11176         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
11177                 & AC_PINSENSE_PRESENCE;
11178         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11179                             present ? 0 : PIN_OUT);
11180 }
11181
11182 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
11183 {
11184         unsigned int present;
11185
11186         present = snd_hda_codec_read(codec, 0x18, 0,
11187                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11188         snd_hda_codec_write(codec, 0x23, 0,
11189                             AC_VERB_SET_CONNECT_SEL,
11190                             present ? 0x00 : 0x01);
11191 }
11192
11193 static void alc267_quanta_il1_automute(struct hda_codec *codec)
11194 {
11195         alc267_quanta_il1_hp_automute(codec);
11196         alc267_quanta_il1_mic_automute(codec);
11197 }
11198
11199 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11200                                            unsigned int res)
11201 {
11202         switch (res >> 26) {
11203         case ALC880_HP_EVENT:
11204                 alc267_quanta_il1_hp_automute(codec);
11205                 break;
11206         case ALC880_MIC_EVENT:
11207                 alc267_quanta_il1_mic_automute(codec);
11208                 break;
11209         }
11210 }
11211
11212 /*
11213  * generic initialization of ADC, input mixers and output mixers
11214  */
11215 static struct hda_verb alc268_base_init_verbs[] = {
11216         /* Unmute DAC0-1 and set vol = 0 */
11217         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11218         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11219         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11220         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11221         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11222         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11223
11224         /*
11225          * Set up output mixers (0x0c - 0x0e)
11226          */
11227         /* set vol=0 to output mixers */
11228         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11229         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11230         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11231         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11232
11233         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11234         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11235
11236         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11237         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11238         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11239         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11240         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11241         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11242         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11243         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11244
11245         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11246         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11247         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11248         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11249         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11250         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11251         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11252
11253         /* set PCBEEP vol = 0, mute connections */
11254         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11255         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11256         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11257
11258         /* Unmute Selector 23h,24h and set the default input to mic-in */
11259
11260         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11261         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11262         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11263         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11264
11265         { }
11266 };
11267
11268 /*
11269  * generic initialization of ADC, input mixers and output mixers
11270  */
11271 static struct hda_verb alc268_volume_init_verbs[] = {
11272         /* set output DAC */
11273         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11274         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11275         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11276         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11277
11278         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11279         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11280         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11281         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11282         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11283
11284         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11285         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11286         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11287         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11288         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11289
11290         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11291         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11292         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11293         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11294
11295         /* set PCBEEP vol = 0, mute connections */
11296         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11297         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11298         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11299
11300         { }
11301 };
11302
11303 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11304         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11305         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11306         {
11307                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11308                 /* The multiple "Capture Source" controls confuse alsamixer
11309                  * So call somewhat different..
11310                  */
11311                 /* .name = "Capture Source", */
11312                 .name = "Input Source",
11313                 .count = 1,
11314                 .info = alc_mux_enum_info,
11315                 .get = alc_mux_enum_get,
11316                 .put = alc_mux_enum_put,
11317         },
11318         { } /* end */
11319 };
11320
11321 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11322         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11323         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11324         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11325         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11326         {
11327                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11328                 /* The multiple "Capture Source" controls confuse alsamixer
11329                  * So call somewhat different..
11330                  */
11331                 /* .name = "Capture Source", */
11332                 .name = "Input Source",
11333                 .count = 2,
11334                 .info = alc_mux_enum_info,
11335                 .get = alc_mux_enum_get,
11336                 .put = alc_mux_enum_put,
11337         },
11338         { } /* end */
11339 };
11340
11341 static struct hda_input_mux alc268_capture_source = {
11342         .num_items = 4,
11343         .items = {
11344                 { "Mic", 0x0 },
11345                 { "Front Mic", 0x1 },
11346                 { "Line", 0x2 },
11347                 { "CD", 0x3 },
11348         },
11349 };
11350
11351 static struct hda_input_mux alc268_acer_capture_source = {
11352         .num_items = 3,
11353         .items = {
11354                 { "Mic", 0x0 },
11355                 { "Internal Mic", 0x1 },
11356                 { "Line", 0x2 },
11357         },
11358 };
11359
11360 static struct hda_input_mux alc268_acer_dmic_capture_source = {
11361         .num_items = 3,
11362         .items = {
11363                 { "Mic", 0x0 },
11364                 { "Internal Mic", 0x6 },
11365                 { "Line", 0x2 },
11366         },
11367 };
11368
11369 #ifdef CONFIG_SND_DEBUG
11370 static struct snd_kcontrol_new alc268_test_mixer[] = {
11371         /* Volume widgets */
11372         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11373         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11374         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11375         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11376         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11377         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11378         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11379         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11380         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11381         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11382         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11383         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11384         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11385         /* The below appears problematic on some hardwares */
11386         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11387         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11388         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11389         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11390         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11391
11392         /* Modes for retasking pin widgets */
11393         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11394         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11395         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11396         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11397
11398         /* Controls for GPIO pins, assuming they are configured as outputs */
11399         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11400         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11401         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11402         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11403
11404         /* Switches to allow the digital SPDIF output pin to be enabled.
11405          * The ALC268 does not have an SPDIF input.
11406          */
11407         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11408
11409         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11410          * this output to turn on an external amplifier.
11411          */
11412         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11413         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11414
11415         { } /* end */
11416 };
11417 #endif
11418
11419 /* create input playback/capture controls for the given pin */
11420 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11421                                     const char *ctlname, int idx)
11422 {
11423         char name[32];
11424         int err;
11425
11426         sprintf(name, "%s Playback Volume", ctlname);
11427         if (nid == 0x14) {
11428                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11429                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11430                                                       HDA_OUTPUT));
11431                 if (err < 0)
11432                         return err;
11433         } else if (nid == 0x15) {
11434                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11435                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11436                                                       HDA_OUTPUT));
11437                 if (err < 0)
11438                         return err;
11439         } else
11440                 return -1;
11441         sprintf(name, "%s Playback Switch", ctlname);
11442         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11443                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11444         if (err < 0)
11445                 return err;
11446         return 0;
11447 }
11448
11449 /* add playback controls from the parsed DAC table */
11450 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11451                                              const struct auto_pin_cfg *cfg)
11452 {
11453         hda_nid_t nid;
11454         int err;
11455
11456         spec->multiout.num_dacs = 2;    /* only use one dac */
11457         spec->multiout.dac_nids = spec->private_dac_nids;
11458         spec->multiout.dac_nids[0] = 2;
11459         spec->multiout.dac_nids[1] = 3;
11460
11461         nid = cfg->line_out_pins[0];
11462         if (nid)
11463                 alc268_new_analog_output(spec, nid, "Front", 0);
11464
11465         nid = cfg->speaker_pins[0];
11466         if (nid == 0x1d) {
11467                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11468                                   "Speaker Playback Volume",
11469                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11470                 if (err < 0)
11471                         return err;
11472         }
11473         nid = cfg->hp_pins[0];
11474         if (nid)
11475                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11476
11477         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11478         if (nid == 0x16) {
11479                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11480                                   "Mono Playback Switch",
11481                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11482                 if (err < 0)
11483                         return err;
11484         }
11485         return 0;
11486 }
11487
11488 /* create playback/capture controls for input pins */
11489 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11490                                                 const struct auto_pin_cfg *cfg)
11491 {
11492         struct hda_input_mux *imux = &spec->private_imux;
11493         int i, idx1;
11494
11495         for (i = 0; i < AUTO_PIN_LAST; i++) {
11496                 switch(cfg->input_pins[i]) {
11497                 case 0x18:
11498                         idx1 = 0;       /* Mic 1 */
11499                         break;
11500                 case 0x19:
11501                         idx1 = 1;       /* Mic 2 */
11502                         break;
11503                 case 0x1a:
11504                         idx1 = 2;       /* Line In */
11505                         break;
11506                 case 0x1c:
11507                         idx1 = 3;       /* CD */
11508                         break;
11509                 case 0x12:
11510                 case 0x13:
11511                         idx1 = 6;       /* digital mics */
11512                         break;
11513                 default:
11514                         continue;
11515                 }
11516                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11517                 imux->items[imux->num_items].index = idx1;
11518                 imux->num_items++;
11519         }
11520         return 0;
11521 }
11522
11523 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11524 {
11525         struct alc_spec *spec = codec->spec;
11526         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11527         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11528         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11529         unsigned int    dac_vol1, dac_vol2;
11530
11531         if (speaker_nid) {
11532                 snd_hda_codec_write(codec, speaker_nid, 0,
11533                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11534                 snd_hda_codec_write(codec, 0x0f, 0,
11535                                     AC_VERB_SET_AMP_GAIN_MUTE,
11536                                     AMP_IN_UNMUTE(1));
11537                 snd_hda_codec_write(codec, 0x10, 0,
11538                                     AC_VERB_SET_AMP_GAIN_MUTE,
11539                                     AMP_IN_UNMUTE(1));
11540         } else {
11541                 snd_hda_codec_write(codec, 0x0f, 0,
11542                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11543                 snd_hda_codec_write(codec, 0x10, 0,
11544                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11545         }
11546
11547         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11548         if (line_nid == 0x14)
11549                 dac_vol2 = AMP_OUT_ZERO;
11550         else if (line_nid == 0x15)
11551                 dac_vol1 = AMP_OUT_ZERO;
11552         if (hp_nid == 0x14)
11553                 dac_vol2 = AMP_OUT_ZERO;
11554         else if (hp_nid == 0x15)
11555                 dac_vol1 = AMP_OUT_ZERO;
11556         if (line_nid != 0x16 || hp_nid != 0x16 ||
11557             spec->autocfg.line_out_pins[1] != 0x16 ||
11558             spec->autocfg.line_out_pins[2] != 0x16)
11559                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11560
11561         snd_hda_codec_write(codec, 0x02, 0,
11562                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11563         snd_hda_codec_write(codec, 0x03, 0,
11564                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11565 }
11566
11567 /* pcm configuration: identiacal with ALC880 */
11568 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11569 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11570 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11571 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11572
11573 /*
11574  * BIOS auto configuration
11575  */
11576 static int alc268_parse_auto_config(struct hda_codec *codec)
11577 {
11578         struct alc_spec *spec = codec->spec;
11579         int err;
11580         static hda_nid_t alc268_ignore[] = { 0 };
11581
11582         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11583                                            alc268_ignore);
11584         if (err < 0)
11585                 return err;
11586         if (!spec->autocfg.line_outs)
11587                 return 0; /* can't find valid BIOS pin config */
11588
11589         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11590         if (err < 0)
11591                 return err;
11592         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11593         if (err < 0)
11594                 return err;
11595
11596         spec->multiout.max_channels = 2;
11597
11598         /* digital only support output */
11599         if (spec->autocfg.dig_out_pin)
11600                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11601
11602         if (spec->kctls.list)
11603                 add_mixer(spec, spec->kctls.list);
11604
11605         if (spec->autocfg.speaker_pins[0] != 0x1d)
11606                 add_mixer(spec, alc268_beep_mixer);
11607
11608         add_verb(spec, alc268_volume_init_verbs);
11609         spec->num_mux_defs = 1;
11610         spec->input_mux = &spec->private_imux;
11611
11612         err = alc_auto_add_mic_boost(codec);
11613         if (err < 0)
11614                 return err;
11615
11616         store_pin_configs(codec);
11617         return 1;
11618 }
11619
11620 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
11621 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
11622 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
11623
11624 /* init callback for auto-configuration model -- overriding the default init */
11625 static void alc268_auto_init(struct hda_codec *codec)
11626 {
11627         struct alc_spec *spec = codec->spec;
11628         alc268_auto_init_multi_out(codec);
11629         alc268_auto_init_hp_out(codec);
11630         alc268_auto_init_mono_speaker_out(codec);
11631         alc268_auto_init_analog_input(codec);
11632         if (spec->unsol_event)
11633                 alc_inithook(codec);
11634 }
11635
11636 /*
11637  * configuration and preset
11638  */
11639 static const char *alc268_models[ALC268_MODEL_LAST] = {
11640         [ALC267_QUANTA_IL1]     = "quanta-il1",
11641         [ALC268_3ST]            = "3stack",
11642         [ALC268_TOSHIBA]        = "toshiba",
11643         [ALC268_ACER]           = "acer",
11644         [ALC268_ACER_DMIC]      = "acer-dmic",
11645         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
11646         [ALC268_DELL]           = "dell",
11647         [ALC268_ZEPTO]          = "zepto",
11648 #ifdef CONFIG_SND_DEBUG
11649         [ALC268_TEST]           = "test",
11650 #endif
11651         [ALC268_AUTO]           = "auto",
11652 };
11653
11654 static struct snd_pci_quirk alc268_cfg_tbl[] = {
11655         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
11656         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
11657         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
11658         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
11659         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11660         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11661                                                 ALC268_ACER_ASPIRE_ONE),
11662         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
11663         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
11664         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
11665         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
11666         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11667         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
11668         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
11669         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
11670         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
11671         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
11672         {}
11673 };
11674
11675 static struct alc_config_preset alc268_presets[] = {
11676         [ALC267_QUANTA_IL1] = {
11677                 .mixers = { alc267_quanta_il1_mixer },
11678                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11679                                 alc267_quanta_il1_verbs },
11680                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11681                 .dac_nids = alc268_dac_nids,
11682                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11683                 .adc_nids = alc268_adc_nids_alt,
11684                 .hp_nid = 0x03,
11685                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11686                 .channel_mode = alc268_modes,
11687                 .input_mux = &alc268_capture_source,
11688                 .unsol_event = alc267_quanta_il1_unsol_event,
11689                 .init_hook = alc267_quanta_il1_automute,
11690         },
11691         [ALC268_3ST] = {
11692                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11693                             alc268_beep_mixer },
11694                 .init_verbs = { alc268_base_init_verbs },
11695                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11696                 .dac_nids = alc268_dac_nids,
11697                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11698                 .adc_nids = alc268_adc_nids_alt,
11699                 .capsrc_nids = alc268_capsrc_nids,
11700                 .hp_nid = 0x03,
11701                 .dig_out_nid = ALC268_DIGOUT_NID,
11702                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11703                 .channel_mode = alc268_modes,
11704                 .input_mux = &alc268_capture_source,
11705         },
11706         [ALC268_TOSHIBA] = {
11707                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11708                             alc268_beep_mixer },
11709                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11710                                 alc268_toshiba_verbs },
11711                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11712                 .dac_nids = alc268_dac_nids,
11713                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11714                 .adc_nids = alc268_adc_nids_alt,
11715                 .capsrc_nids = alc268_capsrc_nids,
11716                 .hp_nid = 0x03,
11717                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11718                 .channel_mode = alc268_modes,
11719                 .input_mux = &alc268_capture_source,
11720                 .unsol_event = alc268_toshiba_unsol_event,
11721                 .init_hook = alc268_toshiba_automute,
11722         },
11723         [ALC268_ACER] = {
11724                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
11725                             alc268_beep_mixer },
11726                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11727                                 alc268_acer_verbs },
11728                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11729                 .dac_nids = alc268_dac_nids,
11730                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11731                 .adc_nids = alc268_adc_nids_alt,
11732                 .capsrc_nids = alc268_capsrc_nids,
11733                 .hp_nid = 0x02,
11734                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11735                 .channel_mode = alc268_modes,
11736                 .input_mux = &alc268_acer_capture_source,
11737                 .unsol_event = alc268_acer_unsol_event,
11738                 .init_hook = alc268_acer_init_hook,
11739         },
11740         [ALC268_ACER_DMIC] = {
11741                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
11742                             alc268_beep_mixer },
11743                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11744                                 alc268_acer_verbs },
11745                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11746                 .dac_nids = alc268_dac_nids,
11747                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11748                 .adc_nids = alc268_adc_nids_alt,
11749                 .capsrc_nids = alc268_capsrc_nids,
11750                 .hp_nid = 0x02,
11751                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11752                 .channel_mode = alc268_modes,
11753                 .input_mux = &alc268_acer_dmic_capture_source,
11754                 .unsol_event = alc268_acer_unsol_event,
11755                 .init_hook = alc268_acer_init_hook,
11756         },
11757         [ALC268_ACER_ASPIRE_ONE] = {
11758                 .mixers = { alc268_acer_aspire_one_mixer,
11759                                 alc268_capture_alt_mixer },
11760                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11761                                 alc268_acer_aspire_one_verbs },
11762                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11763                 .dac_nids = alc268_dac_nids,
11764                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11765                 .adc_nids = alc268_adc_nids_alt,
11766                 .capsrc_nids = alc268_capsrc_nids,
11767                 .hp_nid = 0x03,
11768                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11769                 .channel_mode = alc268_modes,
11770                 .input_mux = &alc268_acer_lc_capture_source,
11771                 .unsol_event = alc268_acer_lc_unsol_event,
11772                 .init_hook = alc268_acer_lc_init_hook,
11773         },
11774         [ALC268_DELL] = {
11775                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
11776                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11777                                 alc268_dell_verbs },
11778                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11779                 .dac_nids = alc268_dac_nids,
11780                 .hp_nid = 0x02,
11781                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11782                 .channel_mode = alc268_modes,
11783                 .unsol_event = alc268_dell_unsol_event,
11784                 .init_hook = alc268_dell_init_hook,
11785                 .input_mux = &alc268_capture_source,
11786         },
11787         [ALC268_ZEPTO] = {
11788                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11789                             alc268_beep_mixer },
11790                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11791                                 alc268_toshiba_verbs },
11792                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11793                 .dac_nids = alc268_dac_nids,
11794                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11795                 .adc_nids = alc268_adc_nids_alt,
11796                 .capsrc_nids = alc268_capsrc_nids,
11797                 .hp_nid = 0x03,
11798                 .dig_out_nid = ALC268_DIGOUT_NID,
11799                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11800                 .channel_mode = alc268_modes,
11801                 .input_mux = &alc268_capture_source,
11802                 .unsol_event = alc268_toshiba_unsol_event,
11803                 .init_hook = alc268_toshiba_automute
11804         },
11805 #ifdef CONFIG_SND_DEBUG
11806         [ALC268_TEST] = {
11807                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11808                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11809                                 alc268_volume_init_verbs },
11810                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11811                 .dac_nids = alc268_dac_nids,
11812                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11813                 .adc_nids = alc268_adc_nids_alt,
11814                 .capsrc_nids = alc268_capsrc_nids,
11815                 .hp_nid = 0x03,
11816                 .dig_out_nid = ALC268_DIGOUT_NID,
11817                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11818                 .channel_mode = alc268_modes,
11819                 .input_mux = &alc268_capture_source,
11820         },
11821 #endif
11822 };
11823
11824 static int patch_alc268(struct hda_codec *codec)
11825 {
11826         struct alc_spec *spec;
11827         int board_config;
11828         int err;
11829
11830         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11831         if (spec == NULL)
11832                 return -ENOMEM;
11833
11834         codec->spec = spec;
11835
11836         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11837                                                   alc268_models,
11838                                                   alc268_cfg_tbl);
11839
11840         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11841                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11842                        "trying auto-probe from BIOS...\n");
11843                 board_config = ALC268_AUTO;
11844         }
11845
11846         if (board_config == ALC268_AUTO) {
11847                 /* automatic parse from the BIOS config */
11848                 err = alc268_parse_auto_config(codec);
11849                 if (err < 0) {
11850                         alc_free(codec);
11851                         return err;
11852                 } else if (!err) {
11853                         printk(KERN_INFO
11854                                "hda_codec: Cannot set up configuration "
11855                                "from BIOS.  Using base mode...\n");
11856                         board_config = ALC268_3ST;
11857                 }
11858         }
11859
11860         if (board_config != ALC268_AUTO)
11861                 setup_preset(spec, &alc268_presets[board_config]);
11862
11863         if (codec->vendor_id == 0x10ec0267) {
11864                 spec->stream_name_analog = "ALC267 Analog";
11865                 spec->stream_name_digital = "ALC267 Digital";
11866         } else {
11867                 spec->stream_name_analog = "ALC268 Analog";
11868                 spec->stream_name_digital = "ALC268 Digital";
11869         }
11870
11871         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11872         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11873         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11874
11875         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11876
11877         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11878                 /* override the amp caps for beep generator */
11879                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11880                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11881                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11882                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11883                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11884
11885         if (!spec->adc_nids && spec->input_mux) {
11886                 /* check whether NID 0x07 is valid */
11887                 unsigned int wcap = get_wcaps(codec, 0x07);
11888                 int i;
11889
11890                 /* get type */
11891                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11892                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11893                         spec->adc_nids = alc268_adc_nids_alt;
11894                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11895                         add_mixer(spec, alc268_capture_alt_mixer);
11896                 } else {
11897                         spec->adc_nids = alc268_adc_nids;
11898                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11899                         add_mixer(spec, alc268_capture_mixer);
11900                 }
11901                 spec->capsrc_nids = alc268_capsrc_nids;
11902                 /* set default input source */
11903                 for (i = 0; i < spec->num_adc_nids; i++)
11904                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11905                                 0, AC_VERB_SET_CONNECT_SEL,
11906                                 spec->input_mux->items[0].index);
11907         }
11908
11909         spec->vmaster_nid = 0x02;
11910
11911         codec->patch_ops = alc_patch_ops;
11912         if (board_config == ALC268_AUTO)
11913                 spec->init_hook = alc268_auto_init;
11914
11915         return 0;
11916 }
11917
11918 /*
11919  *  ALC269 channel source setting (2 channel)
11920  */
11921 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11922
11923 #define alc269_dac_nids         alc260_dac_nids
11924
11925 static hda_nid_t alc269_adc_nids[1] = {
11926         /* ADC1 */
11927         0x08,
11928 };
11929
11930 static hda_nid_t alc269_capsrc_nids[1] = {
11931         0x23,
11932 };
11933
11934 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11935  *       not a mux!
11936  */
11937
11938 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11939         .num_items = 2,
11940         .items = {
11941                 { "i-Mic", 0x5 },
11942                 { "e-Mic", 0x0 },
11943         },
11944 };
11945
11946 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11947         .num_items = 2,
11948         .items = {
11949                 { "i-Mic", 0x1 },
11950                 { "e-Mic", 0x0 },
11951         },
11952 };
11953
11954 #define alc269_modes            alc260_modes
11955 #define alc269_capture_source   alc880_lg_lw_capture_source
11956
11957 static struct snd_kcontrol_new alc269_base_mixer[] = {
11958         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11959         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11960         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11961         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11962         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11963         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11964         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11965         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11966         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11967         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11968         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11969         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11970         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11971         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
11972         { } /* end */
11973 };
11974
11975 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
11976         /* output mixer control */
11977         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11978         {
11979                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11980                 .name = "Master Playback Switch",
11981                 .info = snd_hda_mixer_amp_switch_info,
11982                 .get = snd_hda_mixer_amp_switch_get,
11983                 .put = alc268_acer_master_sw_put,
11984                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11985         },
11986         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11987         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11988         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11989         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11990         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11991         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11992         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
11993         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
11994         { }
11995 };
11996
11997 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
11998         /* output mixer control */
11999         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12000         {
12001                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12002                 .name = "Master Playback Switch",
12003                 .info = snd_hda_mixer_amp_switch_info,
12004                 .get = snd_hda_mixer_amp_switch_get,
12005                 .put = alc268_acer_master_sw_put,
12006                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12007         },
12008         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12009         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12010         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12011         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12012         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12013         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12014         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12015         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12016         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12017         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12018         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12019         { }
12020 };
12021
12022 /* bind volumes of both NID 0x0c and 0x0d */
12023 static struct hda_bind_ctls alc269_epc_bind_vol = {
12024         .ops = &snd_hda_bind_vol,
12025         .values = {
12026                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12027                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12028                 0
12029         },
12030 };
12031
12032 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12033         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12034         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
12035         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12036         { } /* end */
12037 };
12038
12039 /* capture mixer elements */
12040 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12041         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12042         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12043         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12044         { } /* end */
12045 };
12046
12047 /* FSC amilo */
12048 static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
12049         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12050         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12051         HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12052         { } /* end */
12053 };
12054
12055 /* beep control */
12056 static struct snd_kcontrol_new alc269_beep_mixer[] = {
12057         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12058         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12059         { } /* end */
12060 };
12061
12062 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12063         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12064         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12065         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12066         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12067         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12068         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12069         { }
12070 };
12071
12072 static struct hda_verb alc269_lifebook_verbs[] = {
12073         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12074         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12075         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12076         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12077         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12078         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12079         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12080         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12081         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12082         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12083         { }
12084 };
12085
12086 /* toggle speaker-output according to the hp-jack state */
12087 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
12088 {
12089         unsigned int present;
12090         unsigned char bits;
12091
12092         present = snd_hda_codec_read(codec, 0x15, 0,
12093                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12094         bits = present ? AMP_IN_MUTE(0) : 0;
12095         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12096                         AMP_IN_MUTE(0), bits);
12097         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12098                         AMP_IN_MUTE(0), bits);
12099
12100         snd_hda_codec_write(codec, 0x20, 0,
12101                         AC_VERB_SET_COEF_INDEX, 0x0c);
12102         snd_hda_codec_write(codec, 0x20, 0,
12103                         AC_VERB_SET_PROC_COEF, 0x680);
12104
12105         snd_hda_codec_write(codec, 0x20, 0,
12106                         AC_VERB_SET_COEF_INDEX, 0x0c);
12107         snd_hda_codec_write(codec, 0x20, 0,
12108                         AC_VERB_SET_PROC_COEF, 0x480);
12109 }
12110
12111 /* toggle speaker-output according to the hp-jacks state */
12112 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12113 {
12114         unsigned int present;
12115         unsigned char bits;
12116
12117         /* Check laptop headphone socket */
12118         present = snd_hda_codec_read(codec, 0x15, 0,
12119                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12120
12121         /* Check port replicator headphone socket */
12122         present |= snd_hda_codec_read(codec, 0x1a, 0,
12123                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12124
12125         bits = present ? AMP_IN_MUTE(0) : 0;
12126         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12127                         AMP_IN_MUTE(0), bits);
12128         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12129                         AMP_IN_MUTE(0), bits);
12130
12131         snd_hda_codec_write(codec, 0x20, 0,
12132                         AC_VERB_SET_COEF_INDEX, 0x0c);
12133         snd_hda_codec_write(codec, 0x20, 0,
12134                         AC_VERB_SET_PROC_COEF, 0x680);
12135
12136         snd_hda_codec_write(codec, 0x20, 0,
12137                         AC_VERB_SET_COEF_INDEX, 0x0c);
12138         snd_hda_codec_write(codec, 0x20, 0,
12139                         AC_VERB_SET_PROC_COEF, 0x480);
12140 }
12141
12142 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12143 {
12144         unsigned int present;
12145
12146         present = snd_hda_codec_read(codec, 0x18, 0,
12147                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12148         snd_hda_codec_write(codec, 0x23, 0,
12149                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
12150 }
12151
12152 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12153 {
12154         unsigned int present_laptop;
12155         unsigned int present_dock;
12156
12157         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
12158                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12159
12160         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
12161                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12162
12163         /* Laptop mic port overrides dock mic port, design decision */
12164         if (present_dock)
12165                 snd_hda_codec_write(codec, 0x23, 0,
12166                                 AC_VERB_SET_CONNECT_SEL, 0x3);
12167         if (present_laptop)
12168                 snd_hda_codec_write(codec, 0x23, 0,
12169                                 AC_VERB_SET_CONNECT_SEL, 0x0);
12170         if (!present_dock && !present_laptop)
12171                 snd_hda_codec_write(codec, 0x23, 0,
12172                                 AC_VERB_SET_CONNECT_SEL, 0x1);
12173 }
12174
12175 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
12176                                     unsigned int res)
12177 {
12178         if ((res >> 26) == ALC880_HP_EVENT)
12179                 alc269_quanta_fl1_speaker_automute(codec);
12180         if ((res >> 26) == ALC880_MIC_EVENT)
12181                 alc269_quanta_fl1_mic_automute(codec);
12182 }
12183
12184 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
12185                                         unsigned int res)
12186 {
12187         if ((res >> 26) == ALC880_HP_EVENT)
12188                 alc269_lifebook_speaker_automute(codec);
12189         if ((res >> 26) == ALC880_MIC_EVENT)
12190                 alc269_lifebook_mic_autoswitch(codec);
12191 }
12192
12193 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
12194 {
12195         alc269_quanta_fl1_speaker_automute(codec);
12196         alc269_quanta_fl1_mic_automute(codec);
12197 }
12198
12199 static void alc269_lifebook_init_hook(struct hda_codec *codec)
12200 {
12201         alc269_lifebook_speaker_automute(codec);
12202         alc269_lifebook_mic_autoswitch(codec);
12203 }
12204
12205 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
12206         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12207         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
12208         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12209         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
12210         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12211         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12212         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12213         {}
12214 };
12215
12216 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
12217         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12218         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
12219         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12220         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
12221         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12222         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12223         {}
12224 };
12225
12226 /* toggle speaker-output according to the hp-jack state */
12227 static void alc269_speaker_automute(struct hda_codec *codec)
12228 {
12229         unsigned int present;
12230         unsigned char bits;
12231
12232         present = snd_hda_codec_read(codec, 0x15, 0,
12233                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12234         bits = present ? AMP_IN_MUTE(0) : 0;
12235         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12236                                 AMP_IN_MUTE(0), bits);
12237         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12238                                 AMP_IN_MUTE(0), bits);
12239 }
12240
12241 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
12242 {
12243         unsigned int present;
12244
12245         present = snd_hda_codec_read(codec, 0x18, 0,
12246                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12247         snd_hda_codec_write(codec, 0x23, 0,
12248                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
12249 }
12250
12251 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
12252 {
12253         unsigned int present;
12254
12255         present = snd_hda_codec_read(codec, 0x18, 0,
12256                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12257         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12258                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12259         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12260                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12261 }
12262
12263 /* unsolicited event for HP jack sensing */
12264 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
12265                                      unsigned int res)
12266 {
12267         if ((res >> 26) == ALC880_HP_EVENT)
12268                 alc269_speaker_automute(codec);
12269
12270         if ((res >> 26) == ALC880_MIC_EVENT)
12271                 alc269_eeepc_dmic_automute(codec);
12272 }
12273
12274 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
12275 {
12276         alc269_speaker_automute(codec);
12277         alc269_eeepc_dmic_automute(codec);
12278 }
12279
12280 /* unsolicited event for HP jack sensing */
12281 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
12282                                      unsigned int res)
12283 {
12284         if ((res >> 26) == ALC880_HP_EVENT)
12285                 alc269_speaker_automute(codec);
12286
12287         if ((res >> 26) == ALC880_MIC_EVENT)
12288                 alc269_eeepc_amic_automute(codec);
12289 }
12290
12291 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
12292 {
12293         alc269_speaker_automute(codec);
12294         alc269_eeepc_amic_automute(codec);
12295 }
12296
12297 /*
12298  * generic initialization of ADC, input mixers and output mixers
12299  */
12300 static struct hda_verb alc269_init_verbs[] = {
12301         /*
12302          * Unmute ADC0 and set the default input to mic-in
12303          */
12304         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12305
12306         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
12307          * analog-loopback mixer widget
12308          * Note: PASD motherboards uses the Line In 2 as the input for
12309          * front panel mic (mic 2)
12310          */
12311         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12312         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12313         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12314         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12315         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12316         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12317
12318         /*
12319          * Set up output mixers (0x0c - 0x0e)
12320          */
12321         /* set vol=0 to output mixers */
12322         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12323         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12324
12325         /* set up input amps for analog loopback */
12326         /* Amp Indices: DAC = 0, mixer = 1 */
12327         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12328         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12329         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12330         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12331         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12332         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12333
12334         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12335         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12336         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12337         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12338         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12339         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12340         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12341
12342         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12343         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12344         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12345         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12346         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12347         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12348         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12349
12350         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12351         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12352
12353         /* FIXME: use matrix-type input source selection */
12354         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12355         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12356         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12357         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12358         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12359         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12360
12361         /* set EAPD */
12362         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12363         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12364         { }
12365 };
12366
12367 /* add playback controls from the parsed DAC table */
12368 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12369                                              const struct auto_pin_cfg *cfg)
12370 {
12371         hda_nid_t nid;
12372         int err;
12373
12374         spec->multiout.num_dacs = 1;    /* only use one dac */
12375         spec->multiout.dac_nids = spec->private_dac_nids;
12376         spec->multiout.dac_nids[0] = 2;
12377
12378         nid = cfg->line_out_pins[0];
12379         if (nid) {
12380                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12381                                   "Front Playback Volume",
12382                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12383                 if (err < 0)
12384                         return err;
12385                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12386                                   "Front Playback Switch",
12387                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12388                 if (err < 0)
12389                         return err;
12390         }
12391
12392         nid = cfg->speaker_pins[0];
12393         if (nid) {
12394                 if (!cfg->line_out_pins[0]) {
12395                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12396                                           "Speaker Playback Volume",
12397                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12398                                                               HDA_OUTPUT));
12399                         if (err < 0)
12400                                 return err;
12401                 }
12402                 if (nid == 0x16) {
12403                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12404                                           "Speaker Playback Switch",
12405                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12406                                                               HDA_OUTPUT));
12407                         if (err < 0)
12408                                 return err;
12409                 } else {
12410                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12411                                           "Speaker Playback Switch",
12412                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12413                                                               HDA_OUTPUT));
12414                         if (err < 0)
12415                                 return err;
12416                 }
12417         }
12418         nid = cfg->hp_pins[0];
12419         if (nid) {
12420                 /* spec->multiout.hp_nid = 2; */
12421                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12422                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12423                                           "Headphone Playback Volume",
12424                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12425                                                               HDA_OUTPUT));
12426                         if (err < 0)
12427                                 return err;
12428                 }
12429                 if (nid == 0x16) {
12430                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12431                                           "Headphone Playback Switch",
12432                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12433                                                               HDA_OUTPUT));
12434                         if (err < 0)
12435                                 return err;
12436                 } else {
12437                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12438                                           "Headphone Playback Switch",
12439                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12440                                                               HDA_OUTPUT));
12441                         if (err < 0)
12442                                 return err;
12443                 }
12444         }
12445         return 0;
12446 }
12447
12448 static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
12449                                                 const struct auto_pin_cfg *cfg)
12450 {
12451         int err;
12452
12453         err = alc880_auto_create_analog_input_ctls(spec, cfg);
12454         if (err < 0)
12455                 return err;
12456         /* digital-mic input pin is excluded in alc880_auto_create..()
12457          * because it's under 0x18
12458          */
12459         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
12460             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
12461                 struct hda_input_mux *imux = &spec->private_imux;
12462                 imux->items[imux->num_items].label = "Int Mic";
12463                 imux->items[imux->num_items].index = 0x05;
12464                 imux->num_items++;
12465         }
12466         return 0;
12467 }
12468
12469 #ifdef CONFIG_SND_HDA_POWER_SAVE
12470 #define alc269_loopbacks        alc880_loopbacks
12471 #endif
12472
12473 /* pcm configuration: identiacal with ALC880 */
12474 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12475 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12476 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12477 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12478
12479 /*
12480  * BIOS auto configuration
12481  */
12482 static int alc269_parse_auto_config(struct hda_codec *codec)
12483 {
12484         struct alc_spec *spec = codec->spec;
12485         int i, err;
12486         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12487
12488         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12489                                            alc269_ignore);
12490         if (err < 0)
12491                 return err;
12492
12493         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12494         if (err < 0)
12495                 return err;
12496         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12497         if (err < 0)
12498                 return err;
12499
12500         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12501
12502         if (spec->autocfg.dig_out_pin)
12503                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12504
12505         if (spec->kctls.list)
12506                 add_mixer(spec, spec->kctls.list);
12507
12508         /* create a beep mixer control if the pin 0x1d isn't assigned */
12509         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12510                 if (spec->autocfg.input_pins[i] == 0x1d)
12511                         break;
12512         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12513                 add_mixer(spec, alc269_beep_mixer);
12514
12515         add_verb(spec, alc269_init_verbs);
12516         spec->num_mux_defs = 1;
12517         spec->input_mux = &spec->private_imux;
12518         /* set default input source */
12519         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12520                                   0, AC_VERB_SET_CONNECT_SEL,
12521                                   spec->input_mux->items[0].index);
12522
12523         err = alc_auto_add_mic_boost(codec);
12524         if (err < 0)
12525                 return err;
12526
12527         if (!spec->cap_mixer)
12528                 set_capture_mixer(spec);
12529
12530         store_pin_configs(codec);
12531         return 1;
12532 }
12533
12534 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12535 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12536 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12537
12538
12539 /* init callback for auto-configuration model -- overriding the default init */
12540 static void alc269_auto_init(struct hda_codec *codec)
12541 {
12542         struct alc_spec *spec = codec->spec;
12543         alc269_auto_init_multi_out(codec);
12544         alc269_auto_init_hp_out(codec);
12545         alc269_auto_init_analog_input(codec);
12546         if (spec->unsol_event)
12547                 alc_inithook(codec);
12548 }
12549
12550 /*
12551  * configuration and preset
12552  */
12553 static const char *alc269_models[ALC269_MODEL_LAST] = {
12554         [ALC269_BASIC]                  = "basic",
12555         [ALC269_QUANTA_FL1]             = "quanta",
12556         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12557         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
12558         [ALC269_FUJITSU]                = "fujitsu",
12559         [ALC269_LIFEBOOK]               = "lifebook"
12560 };
12561
12562 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12563         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12564         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12565                       ALC269_ASUS_EEEPC_P703),
12566         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12567                       ALC269_ASUS_EEEPC_P901),
12568         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12569                       ALC269_ASUS_EEEPC_P901),
12570         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
12571         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
12572         {}
12573 };
12574
12575 static struct alc_config_preset alc269_presets[] = {
12576         [ALC269_BASIC] = {
12577                 .mixers = { alc269_base_mixer },
12578                 .init_verbs = { alc269_init_verbs },
12579                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12580                 .dac_nids = alc269_dac_nids,
12581                 .hp_nid = 0x03,
12582                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12583                 .channel_mode = alc269_modes,
12584                 .input_mux = &alc269_capture_source,
12585         },
12586         [ALC269_QUANTA_FL1] = {
12587                 .mixers = { alc269_quanta_fl1_mixer },
12588                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
12589                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12590                 .dac_nids = alc269_dac_nids,
12591                 .hp_nid = 0x03,
12592                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12593                 .channel_mode = alc269_modes,
12594                 .input_mux = &alc269_capture_source,
12595                 .unsol_event = alc269_quanta_fl1_unsol_event,
12596                 .init_hook = alc269_quanta_fl1_init_hook,
12597         },
12598         [ALC269_ASUS_EEEPC_P703] = {
12599                 .mixers = { alc269_eeepc_mixer },
12600                 .cap_mixer = alc269_epc_capture_mixer,
12601                 .init_verbs = { alc269_init_verbs,
12602                                 alc269_eeepc_amic_init_verbs },
12603                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12604                 .dac_nids = alc269_dac_nids,
12605                 .hp_nid = 0x03,
12606                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12607                 .channel_mode = alc269_modes,
12608                 .input_mux = &alc269_eeepc_amic_capture_source,
12609                 .unsol_event = alc269_eeepc_amic_unsol_event,
12610                 .init_hook = alc269_eeepc_amic_inithook,
12611         },
12612         [ALC269_ASUS_EEEPC_P901] = {
12613                 .mixers = { alc269_eeepc_mixer },
12614                 .cap_mixer = alc269_epc_capture_mixer,
12615                 .init_verbs = { alc269_init_verbs,
12616                                 alc269_eeepc_dmic_init_verbs },
12617                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12618                 .dac_nids = alc269_dac_nids,
12619                 .hp_nid = 0x03,
12620                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12621                 .channel_mode = alc269_modes,
12622                 .input_mux = &alc269_eeepc_dmic_capture_source,
12623                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12624                 .init_hook = alc269_eeepc_dmic_inithook,
12625         },
12626         [ALC269_FUJITSU] = {
12627                 .mixers = { alc269_fujitsu_mixer, alc269_beep_mixer },
12628                 .cap_mixer = alc269_epc_capture_mixer,
12629                 .init_verbs = { alc269_init_verbs,
12630                                 alc269_eeepc_dmic_init_verbs },
12631                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12632                 .dac_nids = alc269_dac_nids,
12633                 .hp_nid = 0x03,
12634                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12635                 .channel_mode = alc269_modes,
12636                 .input_mux = &alc269_eeepc_dmic_capture_source,
12637                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12638                 .init_hook = alc269_eeepc_dmic_inithook,
12639         },
12640         [ALC269_LIFEBOOK] = {
12641                 .mixers = { alc269_lifebook_mixer },
12642                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
12643                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12644                 .dac_nids = alc269_dac_nids,
12645                 .hp_nid = 0x03,
12646                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12647                 .channel_mode = alc269_modes,
12648                 .input_mux = &alc269_capture_source,
12649                 .unsol_event = alc269_lifebook_unsol_event,
12650                 .init_hook = alc269_lifebook_init_hook,
12651         },
12652 };
12653
12654 static int patch_alc269(struct hda_codec *codec)
12655 {
12656         struct alc_spec *spec;
12657         int board_config;
12658         int err;
12659
12660         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12661         if (spec == NULL)
12662                 return -ENOMEM;
12663
12664         codec->spec = spec;
12665
12666         alc_fix_pll_init(codec, 0x20, 0x04, 15);
12667
12668         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
12669                                                   alc269_models,
12670                                                   alc269_cfg_tbl);
12671
12672         if (board_config < 0) {
12673                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
12674                        "trying auto-probe from BIOS...\n");
12675                 board_config = ALC269_AUTO;
12676         }
12677
12678         if (board_config == ALC269_AUTO) {
12679                 /* automatic parse from the BIOS config */
12680                 err = alc269_parse_auto_config(codec);
12681                 if (err < 0) {
12682                         alc_free(codec);
12683                         return err;
12684                 } else if (!err) {
12685                         printk(KERN_INFO
12686                                "hda_codec: Cannot set up configuration "
12687                                "from BIOS.  Using base mode...\n");
12688                         board_config = ALC269_BASIC;
12689                 }
12690         }
12691
12692         if (board_config != ALC269_AUTO)
12693                 setup_preset(spec, &alc269_presets[board_config]);
12694
12695         spec->stream_name_analog = "ALC269 Analog";
12696         spec->stream_analog_playback = &alc269_pcm_analog_playback;
12697         spec->stream_analog_capture = &alc269_pcm_analog_capture;
12698
12699         spec->stream_name_digital = "ALC269 Digital";
12700         spec->stream_digital_playback = &alc269_pcm_digital_playback;
12701         spec->stream_digital_capture = &alc269_pcm_digital_capture;
12702
12703         spec->adc_nids = alc269_adc_nids;
12704         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12705         spec->capsrc_nids = alc269_capsrc_nids;
12706         if (!spec->cap_mixer)
12707                 set_capture_mixer(spec);
12708
12709         codec->patch_ops = alc_patch_ops;
12710         if (board_config == ALC269_AUTO)
12711                 spec->init_hook = alc269_auto_init;
12712 #ifdef CONFIG_SND_HDA_POWER_SAVE
12713         if (!spec->loopback.amplist)
12714                 spec->loopback.amplist = alc269_loopbacks;
12715 #endif
12716
12717         return 0;
12718 }
12719
12720 /*
12721  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
12722  */
12723
12724 /*
12725  * set the path ways for 2 channel output
12726  * need to set the codec line out and mic 1 pin widgets to inputs
12727  */
12728 static struct hda_verb alc861_threestack_ch2_init[] = {
12729         /* set pin widget 1Ah (line in) for input */
12730         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12731         /* set pin widget 18h (mic1/2) for input, for mic also enable
12732          * the vref
12733          */
12734         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12735
12736         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12737 #if 0
12738         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12739         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12740 #endif
12741         { } /* end */
12742 };
12743 /*
12744  * 6ch mode
12745  * need to set the codec line out and mic 1 pin widgets to outputs
12746  */
12747 static struct hda_verb alc861_threestack_ch6_init[] = {
12748         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12749         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12750         /* set pin widget 18h (mic1) for output (CLFE)*/
12751         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12752
12753         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12754         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12755
12756         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12757 #if 0
12758         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12759         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12760 #endif
12761         { } /* end */
12762 };
12763
12764 static struct hda_channel_mode alc861_threestack_modes[2] = {
12765         { 2, alc861_threestack_ch2_init },
12766         { 6, alc861_threestack_ch6_init },
12767 };
12768 /* Set mic1 as input and unmute the mixer */
12769 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
12770         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12771         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12772         { } /* end */
12773 };
12774 /* Set mic1 as output and mute mixer */
12775 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
12776         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12777         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12778         { } /* end */
12779 };
12780
12781 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
12782         { 2, alc861_uniwill_m31_ch2_init },
12783         { 4, alc861_uniwill_m31_ch4_init },
12784 };
12785
12786 /* Set mic1 and line-in as input and unmute the mixer */
12787 static struct hda_verb alc861_asus_ch2_init[] = {
12788         /* set pin widget 1Ah (line in) for input */
12789         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12790         /* set pin widget 18h (mic1/2) for input, for mic also enable
12791          * the vref
12792          */
12793         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12794
12795         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12796 #if 0
12797         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12798         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12799 #endif
12800         { } /* end */
12801 };
12802 /* Set mic1 nad line-in as output and mute mixer */
12803 static struct hda_verb alc861_asus_ch6_init[] = {
12804         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12805         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12806         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12807         /* set pin widget 18h (mic1) for output (CLFE)*/
12808         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12809         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12810         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12811         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12812
12813         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12814 #if 0
12815         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12816         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12817 #endif
12818         { } /* end */
12819 };
12820
12821 static struct hda_channel_mode alc861_asus_modes[2] = {
12822         { 2, alc861_asus_ch2_init },
12823         { 6, alc861_asus_ch6_init },
12824 };
12825
12826 /* patch-ALC861 */
12827
12828 static struct snd_kcontrol_new alc861_base_mixer[] = {
12829         /* output mixer control */
12830         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12831         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12832         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12833         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12834         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12835
12836         /*Input mixer control */
12837         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12838            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12839         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12840         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12841         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12842         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12843         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12844         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12845         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12846         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12847
12848         { } /* end */
12849 };
12850
12851 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12852         /* output mixer control */
12853         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12854         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12855         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12856         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12857         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12858
12859         /* Input mixer control */
12860         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12861            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12862         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12863         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12864         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12865         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12866         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12867         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12868         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12869         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12870
12871         {
12872                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12873                 .name = "Channel Mode",
12874                 .info = alc_ch_mode_info,
12875                 .get = alc_ch_mode_get,
12876                 .put = alc_ch_mode_put,
12877                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
12878         },
12879         { } /* end */
12880 };
12881
12882 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
12883         /* output mixer control */
12884         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12885         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12886         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12887
12888         { } /* end */
12889 };
12890
12891 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
12892         /* output mixer control */
12893         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12894         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12895         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12896         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12897         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12898
12899         /* Input mixer control */
12900         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12901            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12902         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12903         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12904         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12905         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12906         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12907         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12908         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12909         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12910
12911         {
12912                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12913                 .name = "Channel Mode",
12914                 .info = alc_ch_mode_info,
12915                 .get = alc_ch_mode_get,
12916                 .put = alc_ch_mode_put,
12917                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
12918         },
12919         { } /* end */
12920 };
12921
12922 static struct snd_kcontrol_new alc861_asus_mixer[] = {
12923         /* output mixer control */
12924         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12925         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12926         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12927         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12928         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12929
12930         /* Input mixer control */
12931         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12932         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12933         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12934         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12935         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12936         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12937         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12938         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12939         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12940         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
12941
12942         {
12943                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12944                 .name = "Channel Mode",
12945                 .info = alc_ch_mode_info,
12946                 .get = alc_ch_mode_get,
12947                 .put = alc_ch_mode_put,
12948                 .private_value = ARRAY_SIZE(alc861_asus_modes),
12949         },
12950         { }
12951 };
12952
12953 /* additional mixer */
12954 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
12955         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12956         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12957         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
12958         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
12959         { }
12960 };
12961
12962 /*
12963  * generic initialization of ADC, input mixers and output mixers
12964  */
12965 static struct hda_verb alc861_base_init_verbs[] = {
12966         /*
12967          * Unmute ADC0 and set the default input to mic-in
12968          */
12969         /* port-A for surround (rear panel) */
12970         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12971         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
12972         /* port-B for mic-in (rear panel) with vref */
12973         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12974         /* port-C for line-in (rear panel) */
12975         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12976         /* port-D for Front */
12977         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12978         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12979         /* port-E for HP out (front panel) */
12980         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
12981         /* route front PCM to HP */
12982         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12983         /* port-F for mic-in (front panel) with vref */
12984         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12985         /* port-G for CLFE (rear panel) */
12986         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12987         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12988         /* port-H for side (rear panel) */
12989         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12990         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
12991         /* CD-in */
12992         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12993         /* route front mic to ADC1*/
12994         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12995         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12996
12997         /* Unmute DAC0~3 & spdif out*/
12998         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12999         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13000         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13001         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13002         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13003
13004         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13005         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13006         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13007         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13008         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13009
13010         /* Unmute Stereo Mixer 15 */
13011         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13012         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13013         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13014         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13015
13016         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13017         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13018         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13019         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13020         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13021         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13022         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13023         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13024         /* hp used DAC 3 (Front) */
13025         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13026         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13027
13028         { }
13029 };
13030
13031 static struct hda_verb alc861_threestack_init_verbs[] = {
13032         /*
13033          * Unmute ADC0 and set the default input to mic-in
13034          */
13035         /* port-A for surround (rear panel) */
13036         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13037         /* port-B for mic-in (rear panel) with vref */
13038         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13039         /* port-C for line-in (rear panel) */
13040         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13041         /* port-D for Front */
13042         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13043         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13044         /* port-E for HP out (front panel) */
13045         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13046         /* route front PCM to HP */
13047         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13048         /* port-F for mic-in (front panel) with vref */
13049         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13050         /* port-G for CLFE (rear panel) */
13051         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13052         /* port-H for side (rear panel) */
13053         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13054         /* CD-in */
13055         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13056         /* route front mic to ADC1*/
13057         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13058         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13059         /* Unmute DAC0~3 & spdif out*/
13060         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13061         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13062         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13063         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13064         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13065
13066         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13067         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13068         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13069         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13070         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13071
13072         /* Unmute Stereo Mixer 15 */
13073         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13074         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13075         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13076         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13077
13078         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13079         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13080         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13081         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13082         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13083         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13084         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13085         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13086         /* hp used DAC 3 (Front) */
13087         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13088         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13089         { }
13090 };
13091
13092 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13093         /*
13094          * Unmute ADC0 and set the default input to mic-in
13095          */
13096         /* port-A for surround (rear panel) */
13097         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13098         /* port-B for mic-in (rear panel) with vref */
13099         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13100         /* port-C for line-in (rear panel) */
13101         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13102         /* port-D for Front */
13103         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13104         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13105         /* port-E for HP out (front panel) */
13106         /* this has to be set to VREF80 */
13107         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13108         /* route front PCM to HP */
13109         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13110         /* port-F for mic-in (front panel) with vref */
13111         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13112         /* port-G for CLFE (rear panel) */
13113         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13114         /* port-H for side (rear panel) */
13115         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13116         /* CD-in */
13117         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13118         /* route front mic to ADC1*/
13119         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13120         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13121         /* Unmute DAC0~3 & spdif out*/
13122         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13123         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13124         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13125         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13126         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13127
13128         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13129         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13130         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13131         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13132         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13133
13134         /* Unmute Stereo Mixer 15 */
13135         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13136         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13137         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13138         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13139
13140         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13141         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13142         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13143         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13144         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13145         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13146         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13147         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13148         /* hp used DAC 3 (Front) */
13149         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13150         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13151         { }
13152 };
13153
13154 static struct hda_verb alc861_asus_init_verbs[] = {
13155         /*
13156          * Unmute ADC0 and set the default input to mic-in
13157          */
13158         /* port-A for surround (rear panel)
13159          * according to codec#0 this is the HP jack
13160          */
13161         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
13162         /* route front PCM to HP */
13163         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
13164         /* port-B for mic-in (rear panel) with vref */
13165         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13166         /* port-C for line-in (rear panel) */
13167         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13168         /* port-D for Front */
13169         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13170         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13171         /* port-E for HP out (front panel) */
13172         /* this has to be set to VREF80 */
13173         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13174         /* route front PCM to HP */
13175         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13176         /* port-F for mic-in (front panel) with vref */
13177         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13178         /* port-G for CLFE (rear panel) */
13179         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13180         /* port-H for side (rear panel) */
13181         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13182         /* CD-in */
13183         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13184         /* route front mic to ADC1*/
13185         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13186         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13187         /* Unmute DAC0~3 & spdif out*/
13188         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13189         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13190         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13191         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13192         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13193         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13194         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13195         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13196         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13197         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13198
13199         /* Unmute Stereo Mixer 15 */
13200         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13201         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13202         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13203         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13204
13205         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13206         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13207         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13208         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13209         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13210         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13211         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13212         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13213         /* hp used DAC 3 (Front) */
13214         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13215         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13216         { }
13217 };
13218
13219 /* additional init verbs for ASUS laptops */
13220 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
13221         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
13222         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
13223         { }
13224 };
13225
13226 /*
13227  * generic initialization of ADC, input mixers and output mixers
13228  */
13229 static struct hda_verb alc861_auto_init_verbs[] = {
13230         /*
13231          * Unmute ADC0 and set the default input to mic-in
13232          */
13233         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
13234         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13235
13236         /* Unmute DAC0~3 & spdif out*/
13237         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13238         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13239         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13240         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13241         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13242
13243         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13244         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13245         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13246         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13247         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13248
13249         /* Unmute Stereo Mixer 15 */
13250         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13251         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13252         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13253         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
13254
13255         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13256         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13257         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13258         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13259         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13260         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13261         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13262         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13263
13264         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13265         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13266         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13267         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13268         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13269         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13270         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13271         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13272
13273         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
13274
13275         { }
13276 };
13277
13278 static struct hda_verb alc861_toshiba_init_verbs[] = {
13279         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13280
13281         { }
13282 };
13283
13284 /* toggle speaker-output according to the hp-jack state */
13285 static void alc861_toshiba_automute(struct hda_codec *codec)
13286 {
13287         unsigned int present;
13288
13289         present = snd_hda_codec_read(codec, 0x0f, 0,
13290                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13291         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
13292                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13293         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
13294                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
13295 }
13296
13297 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
13298                                        unsigned int res)
13299 {
13300         if ((res >> 26) == ALC880_HP_EVENT)
13301                 alc861_toshiba_automute(codec);
13302 }
13303
13304 /* pcm configuration: identiacal with ALC880 */
13305 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
13306 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
13307 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
13308 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
13309
13310
13311 #define ALC861_DIGOUT_NID       0x07
13312
13313 static struct hda_channel_mode alc861_8ch_modes[1] = {
13314         { 8, NULL }
13315 };
13316
13317 static hda_nid_t alc861_dac_nids[4] = {
13318         /* front, surround, clfe, side */
13319         0x03, 0x06, 0x05, 0x04
13320 };
13321
13322 static hda_nid_t alc660_dac_nids[3] = {
13323         /* front, clfe, surround */
13324         0x03, 0x05, 0x06
13325 };
13326
13327 static hda_nid_t alc861_adc_nids[1] = {
13328         /* ADC0-2 */
13329         0x08,
13330 };
13331
13332 static struct hda_input_mux alc861_capture_source = {
13333         .num_items = 5,
13334         .items = {
13335                 { "Mic", 0x0 },
13336                 { "Front Mic", 0x3 },
13337                 { "Line", 0x1 },
13338                 { "CD", 0x4 },
13339                 { "Mixer", 0x5 },
13340         },
13341 };
13342
13343 /* fill in the dac_nids table from the parsed pin configuration */
13344 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13345                                      const struct auto_pin_cfg *cfg)
13346 {
13347         int i;
13348         hda_nid_t nid;
13349
13350         spec->multiout.dac_nids = spec->private_dac_nids;
13351         for (i = 0; i < cfg->line_outs; i++) {
13352                 nid = cfg->line_out_pins[i];
13353                 if (nid) {
13354                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13355                                 continue;
13356                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13357                 }
13358         }
13359         spec->multiout.num_dacs = cfg->line_outs;
13360         return 0;
13361 }
13362
13363 /* add playback controls from the parsed DAC table */
13364 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13365                                              const struct auto_pin_cfg *cfg)
13366 {
13367         char name[32];
13368         static const char *chname[4] = {
13369                 "Front", "Surround", NULL /*CLFE*/, "Side"
13370         };
13371         hda_nid_t nid;
13372         int i, idx, err;
13373
13374         for (i = 0; i < cfg->line_outs; i++) {
13375                 nid = spec->multiout.dac_nids[i];
13376                 if (!nid)
13377                         continue;
13378                 if (nid == 0x05) {
13379                         /* Center/LFE */
13380                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13381                                           "Center Playback Switch",
13382                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13383                                                               HDA_OUTPUT));
13384                         if (err < 0)
13385                                 return err;
13386                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13387                                           "LFE Playback Switch",
13388                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13389                                                               HDA_OUTPUT));
13390                         if (err < 0)
13391                                 return err;
13392                 } else {
13393                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13394                              idx++)
13395                                 if (nid == alc861_dac_nids[idx])
13396                                         break;
13397                         sprintf(name, "%s Playback Switch", chname[idx]);
13398                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13399                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13400                                                               HDA_OUTPUT));
13401                         if (err < 0)
13402                                 return err;
13403                 }
13404         }
13405         return 0;
13406 }
13407
13408 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13409 {
13410         int err;
13411         hda_nid_t nid;
13412
13413         if (!pin)
13414                 return 0;
13415
13416         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13417                 nid = 0x03;
13418                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13419                                   "Headphone Playback Switch",
13420                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13421                 if (err < 0)
13422                         return err;
13423                 spec->multiout.hp_nid = nid;
13424         }
13425         return 0;
13426 }
13427
13428 /* create playback/capture controls for input pins */
13429 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13430                                                 const struct auto_pin_cfg *cfg)
13431 {
13432         struct hda_input_mux *imux = &spec->private_imux;
13433         int i, err, idx, idx1;
13434
13435         for (i = 0; i < AUTO_PIN_LAST; i++) {
13436                 switch (cfg->input_pins[i]) {
13437                 case 0x0c:
13438                         idx1 = 1;
13439                         idx = 2;        /* Line In */
13440                         break;
13441                 case 0x0f:
13442                         idx1 = 2;
13443                         idx = 2;        /* Line In */
13444                         break;
13445                 case 0x0d:
13446                         idx1 = 0;
13447                         idx = 1;        /* Mic In */
13448                         break;
13449                 case 0x10:
13450                         idx1 = 3;
13451                         idx = 1;        /* Mic In */
13452                         break;
13453                 case 0x11:
13454                         idx1 = 4;
13455                         idx = 0;        /* CD */
13456                         break;
13457                 default:
13458                         continue;
13459                 }
13460
13461                 err = new_analog_input(spec, cfg->input_pins[i],
13462                                        auto_pin_cfg_labels[i], idx, 0x15);
13463                 if (err < 0)
13464                         return err;
13465
13466                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13467                 imux->items[imux->num_items].index = idx1;
13468                 imux->num_items++;
13469         }
13470         return 0;
13471 }
13472
13473 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13474                                               hda_nid_t nid,
13475                                               int pin_type, int dac_idx)
13476 {
13477         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13478                             pin_type);
13479         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13480                             AMP_OUT_UNMUTE);
13481 }
13482
13483 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13484 {
13485         struct alc_spec *spec = codec->spec;
13486         int i;
13487
13488         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13489         for (i = 0; i < spec->autocfg.line_outs; i++) {
13490                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13491                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13492                 if (nid)
13493                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13494                                                           spec->multiout.dac_nids[i]);
13495         }
13496 }
13497
13498 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13499 {
13500         struct alc_spec *spec = codec->spec;
13501         hda_nid_t pin;
13502
13503         pin = spec->autocfg.hp_pins[0];
13504         if (pin) /* connect to front */
13505                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13506                                                   spec->multiout.dac_nids[0]);
13507         pin = spec->autocfg.speaker_pins[0];
13508         if (pin)
13509                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13510 }
13511
13512 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13513 {
13514         struct alc_spec *spec = codec->spec;
13515         int i;
13516
13517         for (i = 0; i < AUTO_PIN_LAST; i++) {
13518                 hda_nid_t nid = spec->autocfg.input_pins[i];
13519                 if (nid >= 0x0c && nid <= 0x11) {
13520                         snd_hda_codec_write(codec, nid, 0,
13521                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13522                                             i <= AUTO_PIN_FRONT_MIC ?
13523                                             PIN_VREF80 : PIN_IN);
13524                 }
13525         }
13526 }
13527
13528 /* parse the BIOS configuration and set up the alc_spec */
13529 /* return 1 if successful, 0 if the proper config is not found,
13530  * or a negative error code
13531  */
13532 static int alc861_parse_auto_config(struct hda_codec *codec)
13533 {
13534         struct alc_spec *spec = codec->spec;
13535         int err;
13536         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13537
13538         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13539                                            alc861_ignore);
13540         if (err < 0)
13541                 return err;
13542         if (!spec->autocfg.line_outs)
13543                 return 0; /* can't find valid BIOS pin config */
13544
13545         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13546         if (err < 0)
13547                 return err;
13548         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13549         if (err < 0)
13550                 return err;
13551         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13552         if (err < 0)
13553                 return err;
13554         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13555         if (err < 0)
13556                 return err;
13557
13558         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13559
13560         if (spec->autocfg.dig_out_pin)
13561                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13562
13563         if (spec->kctls.list)
13564                 add_mixer(spec, spec->kctls.list);
13565
13566         add_verb(spec, alc861_auto_init_verbs);
13567
13568         spec->num_mux_defs = 1;
13569         spec->input_mux = &spec->private_imux;
13570
13571         spec->adc_nids = alc861_adc_nids;
13572         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13573         set_capture_mixer(spec);
13574
13575         store_pin_configs(codec);
13576         return 1;
13577 }
13578
13579 /* additional initialization for auto-configuration model */
13580 static void alc861_auto_init(struct hda_codec *codec)
13581 {
13582         struct alc_spec *spec = codec->spec;
13583         alc861_auto_init_multi_out(codec);
13584         alc861_auto_init_hp_out(codec);
13585         alc861_auto_init_analog_input(codec);
13586         if (spec->unsol_event)
13587                 alc_inithook(codec);
13588 }
13589
13590 #ifdef CONFIG_SND_HDA_POWER_SAVE
13591 static struct hda_amp_list alc861_loopbacks[] = {
13592         { 0x15, HDA_INPUT, 0 },
13593         { 0x15, HDA_INPUT, 1 },
13594         { 0x15, HDA_INPUT, 2 },
13595         { 0x15, HDA_INPUT, 3 },
13596         { } /* end */
13597 };
13598 #endif
13599
13600
13601 /*
13602  * configuration and preset
13603  */
13604 static const char *alc861_models[ALC861_MODEL_LAST] = {
13605         [ALC861_3ST]            = "3stack",
13606         [ALC660_3ST]            = "3stack-660",
13607         [ALC861_3ST_DIG]        = "3stack-dig",
13608         [ALC861_6ST_DIG]        = "6stack-dig",
13609         [ALC861_UNIWILL_M31]    = "uniwill-m31",
13610         [ALC861_TOSHIBA]        = "toshiba",
13611         [ALC861_ASUS]           = "asus",
13612         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
13613         [ALC861_AUTO]           = "auto",
13614 };
13615
13616 static struct snd_pci_quirk alc861_cfg_tbl[] = {
13617         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
13618         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13619         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13620         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
13621         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
13622         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
13623         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
13624         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
13625          *        Any other models that need this preset?
13626          */
13627         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
13628         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
13629         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
13630         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
13631         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
13632         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
13633         /* FIXME: the below seems conflict */
13634         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
13635         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
13636         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
13637         {}
13638 };
13639
13640 static struct alc_config_preset alc861_presets[] = {
13641         [ALC861_3ST] = {
13642                 .mixers = { alc861_3ST_mixer },
13643                 .init_verbs = { alc861_threestack_init_verbs },
13644                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13645                 .dac_nids = alc861_dac_nids,
13646                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13647                 .channel_mode = alc861_threestack_modes,
13648                 .need_dac_fix = 1,
13649                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13650                 .adc_nids = alc861_adc_nids,
13651                 .input_mux = &alc861_capture_source,
13652         },
13653         [ALC861_3ST_DIG] = {
13654                 .mixers = { alc861_base_mixer },
13655                 .init_verbs = { alc861_threestack_init_verbs },
13656                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13657                 .dac_nids = alc861_dac_nids,
13658                 .dig_out_nid = ALC861_DIGOUT_NID,
13659                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13660                 .channel_mode = alc861_threestack_modes,
13661                 .need_dac_fix = 1,
13662                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13663                 .adc_nids = alc861_adc_nids,
13664                 .input_mux = &alc861_capture_source,
13665         },
13666         [ALC861_6ST_DIG] = {
13667                 .mixers = { alc861_base_mixer },
13668                 .init_verbs = { alc861_base_init_verbs },
13669                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13670                 .dac_nids = alc861_dac_nids,
13671                 .dig_out_nid = ALC861_DIGOUT_NID,
13672                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
13673                 .channel_mode = alc861_8ch_modes,
13674                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13675                 .adc_nids = alc861_adc_nids,
13676                 .input_mux = &alc861_capture_source,
13677         },
13678         [ALC660_3ST] = {
13679                 .mixers = { alc861_3ST_mixer },
13680                 .init_verbs = { alc861_threestack_init_verbs },
13681                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
13682                 .dac_nids = alc660_dac_nids,
13683                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13684                 .channel_mode = alc861_threestack_modes,
13685                 .need_dac_fix = 1,
13686                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13687                 .adc_nids = alc861_adc_nids,
13688                 .input_mux = &alc861_capture_source,
13689         },
13690         [ALC861_UNIWILL_M31] = {
13691                 .mixers = { alc861_uniwill_m31_mixer },
13692                 .init_verbs = { alc861_uniwill_m31_init_verbs },
13693                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13694                 .dac_nids = alc861_dac_nids,
13695                 .dig_out_nid = ALC861_DIGOUT_NID,
13696                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
13697                 .channel_mode = alc861_uniwill_m31_modes,
13698                 .need_dac_fix = 1,
13699                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13700                 .adc_nids = alc861_adc_nids,
13701                 .input_mux = &alc861_capture_source,
13702         },
13703         [ALC861_TOSHIBA] = {
13704                 .mixers = { alc861_toshiba_mixer },
13705                 .init_verbs = { alc861_base_init_verbs,
13706                                 alc861_toshiba_init_verbs },
13707                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13708                 .dac_nids = alc861_dac_nids,
13709                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13710                 .channel_mode = alc883_3ST_2ch_modes,
13711                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13712                 .adc_nids = alc861_adc_nids,
13713                 .input_mux = &alc861_capture_source,
13714                 .unsol_event = alc861_toshiba_unsol_event,
13715                 .init_hook = alc861_toshiba_automute,
13716         },
13717         [ALC861_ASUS] = {
13718                 .mixers = { alc861_asus_mixer },
13719                 .init_verbs = { alc861_asus_init_verbs },
13720                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13721                 .dac_nids = alc861_dac_nids,
13722                 .dig_out_nid = ALC861_DIGOUT_NID,
13723                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
13724                 .channel_mode = alc861_asus_modes,
13725                 .need_dac_fix = 1,
13726                 .hp_nid = 0x06,
13727                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13728                 .adc_nids = alc861_adc_nids,
13729                 .input_mux = &alc861_capture_source,
13730         },
13731         [ALC861_ASUS_LAPTOP] = {
13732                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
13733                 .init_verbs = { alc861_asus_init_verbs,
13734                                 alc861_asus_laptop_init_verbs },
13735                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13736                 .dac_nids = alc861_dac_nids,
13737                 .dig_out_nid = ALC861_DIGOUT_NID,
13738                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13739                 .channel_mode = alc883_3ST_2ch_modes,
13740                 .need_dac_fix = 1,
13741                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13742                 .adc_nids = alc861_adc_nids,
13743                 .input_mux = &alc861_capture_source,
13744         },
13745 };
13746
13747
13748 static int patch_alc861(struct hda_codec *codec)
13749 {
13750         struct alc_spec *spec;
13751         int board_config;
13752         int err;
13753
13754         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13755         if (spec == NULL)
13756                 return -ENOMEM;
13757
13758         codec->spec = spec;
13759
13760         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
13761                                                   alc861_models,
13762                                                   alc861_cfg_tbl);
13763
13764         if (board_config < 0) {
13765                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
13766                        "trying auto-probe from BIOS...\n");
13767                 board_config = ALC861_AUTO;
13768         }
13769
13770         if (board_config == ALC861_AUTO) {
13771                 /* automatic parse from the BIOS config */
13772                 err = alc861_parse_auto_config(codec);
13773                 if (err < 0) {
13774                         alc_free(codec);
13775                         return err;
13776                 } else if (!err) {
13777                         printk(KERN_INFO
13778                                "hda_codec: Cannot set up configuration "
13779                                "from BIOS.  Using base mode...\n");
13780                    board_config = ALC861_3ST_DIG;
13781                 }
13782         }
13783
13784         if (board_config != ALC861_AUTO)
13785                 setup_preset(spec, &alc861_presets[board_config]);
13786
13787         spec->stream_name_analog = "ALC861 Analog";
13788         spec->stream_analog_playback = &alc861_pcm_analog_playback;
13789         spec->stream_analog_capture = &alc861_pcm_analog_capture;
13790
13791         spec->stream_name_digital = "ALC861 Digital";
13792         spec->stream_digital_playback = &alc861_pcm_digital_playback;
13793         spec->stream_digital_capture = &alc861_pcm_digital_capture;
13794
13795         spec->vmaster_nid = 0x03;
13796
13797         codec->patch_ops = alc_patch_ops;
13798         if (board_config == ALC861_AUTO)
13799                 spec->init_hook = alc861_auto_init;
13800 #ifdef CONFIG_SND_HDA_POWER_SAVE
13801         if (!spec->loopback.amplist)
13802                 spec->loopback.amplist = alc861_loopbacks;
13803 #endif
13804
13805         return 0;
13806 }
13807
13808 /*
13809  * ALC861-VD support
13810  *
13811  * Based on ALC882
13812  *
13813  * In addition, an independent DAC
13814  */
13815 #define ALC861VD_DIGOUT_NID     0x06
13816
13817 static hda_nid_t alc861vd_dac_nids[4] = {
13818         /* front, surr, clfe, side surr */
13819         0x02, 0x03, 0x04, 0x05
13820 };
13821
13822 /* dac_nids for ALC660vd are in a different order - according to
13823  * Realtek's driver.
13824  * This should probably tesult in a different mixer for 6stack models
13825  * of ALC660vd codecs, but for now there is only 3stack mixer
13826  * - and it is the same as in 861vd.
13827  * adc_nids in ALC660vd are (is) the same as in 861vd
13828  */
13829 static hda_nid_t alc660vd_dac_nids[3] = {
13830         /* front, rear, clfe, rear_surr */
13831         0x02, 0x04, 0x03
13832 };
13833
13834 static hda_nid_t alc861vd_adc_nids[1] = {
13835         /* ADC0 */
13836         0x09,
13837 };
13838
13839 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
13840
13841 /* input MUX */
13842 /* FIXME: should be a matrix-type input source selection */
13843 static struct hda_input_mux alc861vd_capture_source = {
13844         .num_items = 4,
13845         .items = {
13846                 { "Mic", 0x0 },
13847                 { "Front Mic", 0x1 },
13848                 { "Line", 0x2 },
13849                 { "CD", 0x4 },
13850         },
13851 };
13852
13853 static struct hda_input_mux alc861vd_dallas_capture_source = {
13854         .num_items = 2,
13855         .items = {
13856                 { "Ext Mic", 0x0 },
13857                 { "Int Mic", 0x1 },
13858         },
13859 };
13860
13861 static struct hda_input_mux alc861vd_hp_capture_source = {
13862         .num_items = 2,
13863         .items = {
13864                 { "Front Mic", 0x0 },
13865                 { "ATAPI Mic", 0x1 },
13866         },
13867 };
13868
13869 /*
13870  * 2ch mode
13871  */
13872 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
13873         { 2, NULL }
13874 };
13875
13876 /*
13877  * 6ch mode
13878  */
13879 static struct hda_verb alc861vd_6stack_ch6_init[] = {
13880         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13881         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13882         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13883         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13884         { } /* end */
13885 };
13886
13887 /*
13888  * 8ch mode
13889  */
13890 static struct hda_verb alc861vd_6stack_ch8_init[] = {
13891         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13892         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13893         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13894         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13895         { } /* end */
13896 };
13897
13898 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
13899         { 6, alc861vd_6stack_ch6_init },
13900         { 8, alc861vd_6stack_ch8_init },
13901 };
13902
13903 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
13904         {
13905                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13906                 .name = "Channel Mode",
13907                 .info = alc_ch_mode_info,
13908                 .get = alc_ch_mode_get,
13909                 .put = alc_ch_mode_put,
13910         },
13911         { } /* end */
13912 };
13913
13914 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13915  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13916  */
13917 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
13918         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13919         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13920
13921         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13922         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
13923
13924         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
13925                                 HDA_OUTPUT),
13926         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
13927                                 HDA_OUTPUT),
13928         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
13929         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
13930
13931         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
13932         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
13933
13934         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13935
13936         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13937         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13938         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13939
13940         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13941         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13942         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13943
13944         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13945         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13946
13947         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13948         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13949
13950         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13951         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13952
13953         { } /* end */
13954 };
13955
13956 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
13957         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13958         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13959
13960         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13961
13962         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13963         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13964         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13965
13966         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13967         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13968         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13969
13970         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13971         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13972
13973         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13974         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13975
13976         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13977         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13978
13979         { } /* end */
13980 };
13981
13982 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
13983         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13984         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
13985         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13986
13987         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13988
13989         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13990         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13991         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13992
13993         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13994         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13995         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13996
13997         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13998         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13999
14000         { } /* end */
14001 };
14002
14003 /* Pin assignment: Speaker=0x14, HP = 0x15,
14004  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14005  */
14006 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14007         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14008         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14009         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14010         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14011         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14012         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14013         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14014         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14015         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14016         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14017         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
14018         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
14019         { } /* end */
14020 };
14021
14022 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14023  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14024  */
14025 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14026         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14027         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14028         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14029         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14030         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14031         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14032         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14033         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14034
14035         { } /* end */
14036 };
14037
14038 /*
14039  * generic initialization of ADC, input mixers and output mixers
14040  */
14041 static struct hda_verb alc861vd_volume_init_verbs[] = {
14042         /*
14043          * Unmute ADC0 and set the default input to mic-in
14044          */
14045         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14046         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14047
14048         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14049          * the analog-loopback mixer widget
14050          */
14051         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14052         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14053         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14054         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14055         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14056         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14057
14058         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14059         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14060         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14061         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14062         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14063
14064         /*
14065          * Set up output mixers (0x02 - 0x05)
14066          */
14067         /* set vol=0 to output mixers */
14068         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14069         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14070         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14071         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14072
14073         /* set up input amps for analog loopback */
14074         /* Amp Indices: DAC = 0, mixer = 1 */
14075         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14076         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14077         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14078         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14079         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14080         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14081         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14082         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14083
14084         { }
14085 };
14086
14087 /*
14088  * 3-stack pin configuration:
14089  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14090  */
14091 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14092         /*
14093          * Set pin mode and muting
14094          */
14095         /* set front pin widgets 0x14 for output */
14096         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14097         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14098         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14099
14100         /* Mic (rear) pin: input vref at 80% */
14101         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14102         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14103         /* Front Mic pin: input vref at 80% */
14104         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14105         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14106         /* Line In pin: input */
14107         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14108         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14109         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14110         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14111         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14112         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14113         /* CD pin widget for input */
14114         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14115
14116         { }
14117 };
14118
14119 /*
14120  * 6-stack pin configuration:
14121  */
14122 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14123         /*
14124          * Set pin mode and muting
14125          */
14126         /* set front pin widgets 0x14 for output */
14127         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14128         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14129         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14130
14131         /* Rear Pin: output 1 (0x0d) */
14132         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14133         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14134         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14135         /* CLFE Pin: output 2 (0x0e) */
14136         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14137         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14138         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14139         /* Side Pin: output 3 (0x0f) */
14140         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14141         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14142         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
14143
14144         /* Mic (rear) pin: input vref at 80% */
14145         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14146         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14147         /* Front Mic pin: input vref at 80% */
14148         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14149         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14150         /* Line In pin: input */
14151         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14152         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14153         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14154         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14155         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14156         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14157         /* CD pin widget for input */
14158         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14159
14160         { }
14161 };
14162
14163 static struct hda_verb alc861vd_eapd_verbs[] = {
14164         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14165         { }
14166 };
14167
14168 static struct hda_verb alc660vd_eapd_verbs[] = {
14169         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14170         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14171         { }
14172 };
14173
14174 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
14175         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14176         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14177         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
14178         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14179         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14180         {}
14181 };
14182
14183 /* toggle speaker-output according to the hp-jack state */
14184 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
14185 {
14186         unsigned int present;
14187         unsigned char bits;
14188
14189         present = snd_hda_codec_read(codec, 0x1b, 0,
14190                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14191         bits = present ? HDA_AMP_MUTE : 0;
14192         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14193                                  HDA_AMP_MUTE, bits);
14194 }
14195
14196 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
14197 {
14198         unsigned int present;
14199         unsigned char bits;
14200
14201         present = snd_hda_codec_read(codec, 0x18, 0,
14202                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14203         bits = present ? HDA_AMP_MUTE : 0;
14204         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
14205                                  HDA_AMP_MUTE, bits);
14206 }
14207
14208 static void alc861vd_lenovo_automute(struct hda_codec *codec)
14209 {
14210         alc861vd_lenovo_hp_automute(codec);
14211         alc861vd_lenovo_mic_automute(codec);
14212 }
14213
14214 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
14215                                         unsigned int res)
14216 {
14217         switch (res >> 26) {
14218         case ALC880_HP_EVENT:
14219                 alc861vd_lenovo_hp_automute(codec);
14220                 break;
14221         case ALC880_MIC_EVENT:
14222                 alc861vd_lenovo_mic_automute(codec);
14223                 break;
14224         }
14225 }
14226
14227 static struct hda_verb alc861vd_dallas_verbs[] = {
14228         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14229         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14230         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14231         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14232
14233         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14234         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14235         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14236         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14237         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14238         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14239         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14240         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14241
14242         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14243         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14244         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14245         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14246         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14247         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14248         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14249         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14250
14251         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14252         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14253         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14254         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14255         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14256         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14257         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14258         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14259
14260         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14261         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14262         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14263         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14264
14265         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14266         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14267         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14268
14269         { } /* end */
14270 };
14271
14272 /* toggle speaker-output according to the hp-jack state */
14273 static void alc861vd_dallas_automute(struct hda_codec *codec)
14274 {
14275         unsigned int present;
14276
14277         present = snd_hda_codec_read(codec, 0x15, 0,
14278                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14279         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14280                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14281 }
14282
14283 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
14284 {
14285         if ((res >> 26) == ALC880_HP_EVENT)
14286                 alc861vd_dallas_automute(codec);
14287 }
14288
14289 #ifdef CONFIG_SND_HDA_POWER_SAVE
14290 #define alc861vd_loopbacks      alc880_loopbacks
14291 #endif
14292
14293 /* pcm configuration: identiacal with ALC880 */
14294 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14295 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14296 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14297 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14298
14299 /*
14300  * configuration and preset
14301  */
14302 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14303         [ALC660VD_3ST]          = "3stack-660",
14304         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14305         [ALC660VD_ASUS_V1S]     = "asus-v1s",
14306         [ALC861VD_3ST]          = "3stack",
14307         [ALC861VD_3ST_DIG]      = "3stack-digout",
14308         [ALC861VD_6ST_DIG]      = "6stack-digout",
14309         [ALC861VD_LENOVO]       = "lenovo",
14310         [ALC861VD_DALLAS]       = "dallas",
14311         [ALC861VD_HP]           = "hp",
14312         [ALC861VD_AUTO]         = "auto",
14313 };
14314
14315 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14316         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14317         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14318         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14319         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14320         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
14321         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14322         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14323         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14324         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14325         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14326         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14327         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14328         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14329         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
14330         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
14331         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
14332         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14333         {}
14334 };
14335
14336 static struct alc_config_preset alc861vd_presets[] = {
14337         [ALC660VD_3ST] = {
14338                 .mixers = { alc861vd_3st_mixer },
14339                 .init_verbs = { alc861vd_volume_init_verbs,
14340                                  alc861vd_3stack_init_verbs },
14341                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14342                 .dac_nids = alc660vd_dac_nids,
14343                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14344                 .channel_mode = alc861vd_3stack_2ch_modes,
14345                 .input_mux = &alc861vd_capture_source,
14346         },
14347         [ALC660VD_3ST_DIG] = {
14348                 .mixers = { alc861vd_3st_mixer },
14349                 .init_verbs = { alc861vd_volume_init_verbs,
14350                                  alc861vd_3stack_init_verbs },
14351                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14352                 .dac_nids = alc660vd_dac_nids,
14353                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14354                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14355                 .channel_mode = alc861vd_3stack_2ch_modes,
14356                 .input_mux = &alc861vd_capture_source,
14357         },
14358         [ALC861VD_3ST] = {
14359                 .mixers = { alc861vd_3st_mixer },
14360                 .init_verbs = { alc861vd_volume_init_verbs,
14361                                  alc861vd_3stack_init_verbs },
14362                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14363                 .dac_nids = alc861vd_dac_nids,
14364                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14365                 .channel_mode = alc861vd_3stack_2ch_modes,
14366                 .input_mux = &alc861vd_capture_source,
14367         },
14368         [ALC861VD_3ST_DIG] = {
14369                 .mixers = { alc861vd_3st_mixer },
14370                 .init_verbs = { alc861vd_volume_init_verbs,
14371                                  alc861vd_3stack_init_verbs },
14372                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14373                 .dac_nids = alc861vd_dac_nids,
14374                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14375                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14376                 .channel_mode = alc861vd_3stack_2ch_modes,
14377                 .input_mux = &alc861vd_capture_source,
14378         },
14379         [ALC861VD_6ST_DIG] = {
14380                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14381                 .init_verbs = { alc861vd_volume_init_verbs,
14382                                 alc861vd_6stack_init_verbs },
14383                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14384                 .dac_nids = alc861vd_dac_nids,
14385                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14386                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14387                 .channel_mode = alc861vd_6stack_modes,
14388                 .input_mux = &alc861vd_capture_source,
14389         },
14390         [ALC861VD_LENOVO] = {
14391                 .mixers = { alc861vd_lenovo_mixer },
14392                 .init_verbs = { alc861vd_volume_init_verbs,
14393                                 alc861vd_3stack_init_verbs,
14394                                 alc861vd_eapd_verbs,
14395                                 alc861vd_lenovo_unsol_verbs },
14396                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14397                 .dac_nids = alc660vd_dac_nids,
14398                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14399                 .channel_mode = alc861vd_3stack_2ch_modes,
14400                 .input_mux = &alc861vd_capture_source,
14401                 .unsol_event = alc861vd_lenovo_unsol_event,
14402                 .init_hook = alc861vd_lenovo_automute,
14403         },
14404         [ALC861VD_DALLAS] = {
14405                 .mixers = { alc861vd_dallas_mixer },
14406                 .init_verbs = { alc861vd_dallas_verbs },
14407                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14408                 .dac_nids = alc861vd_dac_nids,
14409                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14410                 .channel_mode = alc861vd_3stack_2ch_modes,
14411                 .input_mux = &alc861vd_dallas_capture_source,
14412                 .unsol_event = alc861vd_dallas_unsol_event,
14413                 .init_hook = alc861vd_dallas_automute,
14414         },
14415         [ALC861VD_HP] = {
14416                 .mixers = { alc861vd_hp_mixer },
14417                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14418                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14419                 .dac_nids = alc861vd_dac_nids,
14420                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14421                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14422                 .channel_mode = alc861vd_3stack_2ch_modes,
14423                 .input_mux = &alc861vd_hp_capture_source,
14424                 .unsol_event = alc861vd_dallas_unsol_event,
14425                 .init_hook = alc861vd_dallas_automute,
14426         },
14427         [ALC660VD_ASUS_V1S] = {
14428                 .mixers = { alc861vd_lenovo_mixer },
14429                 .init_verbs = { alc861vd_volume_init_verbs,
14430                                 alc861vd_3stack_init_verbs,
14431                                 alc861vd_eapd_verbs,
14432                                 alc861vd_lenovo_unsol_verbs },
14433                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14434                 .dac_nids = alc660vd_dac_nids,
14435                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14436                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14437                 .channel_mode = alc861vd_3stack_2ch_modes,
14438                 .input_mux = &alc861vd_capture_source,
14439                 .unsol_event = alc861vd_lenovo_unsol_event,
14440                 .init_hook = alc861vd_lenovo_automute,
14441         },
14442 };
14443
14444 /*
14445  * BIOS auto configuration
14446  */
14447 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14448                                 hda_nid_t nid, int pin_type, int dac_idx)
14449 {
14450         alc_set_pin_output(codec, nid, pin_type);
14451 }
14452
14453 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14454 {
14455         struct alc_spec *spec = codec->spec;
14456         int i;
14457
14458         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14459         for (i = 0; i <= HDA_SIDE; i++) {
14460                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14461                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14462                 if (nid)
14463                         alc861vd_auto_set_output_and_unmute(codec, nid,
14464                                                             pin_type, i);
14465         }
14466 }
14467
14468
14469 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14470 {
14471         struct alc_spec *spec = codec->spec;
14472         hda_nid_t pin;
14473
14474         pin = spec->autocfg.hp_pins[0];
14475         if (pin) /* connect to front and  use dac 0 */
14476                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14477         pin = spec->autocfg.speaker_pins[0];
14478         if (pin)
14479                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14480 }
14481
14482 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14483 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14484
14485 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14486 {
14487         struct alc_spec *spec = codec->spec;
14488         int i;
14489
14490         for (i = 0; i < AUTO_PIN_LAST; i++) {
14491                 hda_nid_t nid = spec->autocfg.input_pins[i];
14492                 if (alc861vd_is_input_pin(nid)) {
14493                         snd_hda_codec_write(codec, nid, 0,
14494                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
14495                                         i <= AUTO_PIN_FRONT_MIC ?
14496                                                         PIN_VREF80 : PIN_IN);
14497                         if (nid != ALC861VD_PIN_CD_NID)
14498                                 snd_hda_codec_write(codec, nid, 0,
14499                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14500                                                 AMP_OUT_MUTE);
14501                 }
14502         }
14503 }
14504
14505 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14506
14507 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14508 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14509
14510 /* add playback controls from the parsed DAC table */
14511 /* Based on ALC880 version. But ALC861VD has separate,
14512  * different NIDs for mute/unmute switch and volume control */
14513 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14514                                              const struct auto_pin_cfg *cfg)
14515 {
14516         char name[32];
14517         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14518         hda_nid_t nid_v, nid_s;
14519         int i, err;
14520
14521         for (i = 0; i < cfg->line_outs; i++) {
14522                 if (!spec->multiout.dac_nids[i])
14523                         continue;
14524                 nid_v = alc861vd_idx_to_mixer_vol(
14525                                 alc880_dac_to_idx(
14526                                         spec->multiout.dac_nids[i]));
14527                 nid_s = alc861vd_idx_to_mixer_switch(
14528                                 alc880_dac_to_idx(
14529                                         spec->multiout.dac_nids[i]));
14530
14531                 if (i == 2) {
14532                         /* Center/LFE */
14533                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14534                                           "Center Playback Volume",
14535                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14536                                                               HDA_OUTPUT));
14537                         if (err < 0)
14538                                 return err;
14539                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14540                                           "LFE Playback Volume",
14541                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14542                                                               HDA_OUTPUT));
14543                         if (err < 0)
14544                                 return err;
14545                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14546                                           "Center Playback Switch",
14547                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14548                                                               HDA_INPUT));
14549                         if (err < 0)
14550                                 return err;
14551                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14552                                           "LFE Playback Switch",
14553                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14554                                                               HDA_INPUT));
14555                         if (err < 0)
14556                                 return err;
14557                 } else {
14558                         sprintf(name, "%s Playback Volume", chname[i]);
14559                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14560                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14561                                                               HDA_OUTPUT));
14562                         if (err < 0)
14563                                 return err;
14564                         sprintf(name, "%s Playback Switch", chname[i]);
14565                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14566                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14567                                                               HDA_INPUT));
14568                         if (err < 0)
14569                                 return err;
14570                 }
14571         }
14572         return 0;
14573 }
14574
14575 /* add playback controls for speaker and HP outputs */
14576 /* Based on ALC880 version. But ALC861VD has separate,
14577  * different NIDs for mute/unmute switch and volume control */
14578 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14579                                         hda_nid_t pin, const char *pfx)
14580 {
14581         hda_nid_t nid_v, nid_s;
14582         int err;
14583         char name[32];
14584
14585         if (!pin)
14586                 return 0;
14587
14588         if (alc880_is_fixed_pin(pin)) {
14589                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14590                 /* specify the DAC as the extra output */
14591                 if (!spec->multiout.hp_nid)
14592                         spec->multiout.hp_nid = nid_v;
14593                 else
14594                         spec->multiout.extra_out_nid[0] = nid_v;
14595                 /* control HP volume/switch on the output mixer amp */
14596                 nid_v = alc861vd_idx_to_mixer_vol(
14597                                 alc880_fixed_pin_idx(pin));
14598                 nid_s = alc861vd_idx_to_mixer_switch(
14599                                 alc880_fixed_pin_idx(pin));
14600
14601                 sprintf(name, "%s Playback Volume", pfx);
14602                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14603                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
14604                 if (err < 0)
14605                         return err;
14606                 sprintf(name, "%s Playback Switch", pfx);
14607                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14608                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
14609                 if (err < 0)
14610                         return err;
14611         } else if (alc880_is_multi_pin(pin)) {
14612                 /* set manual connection */
14613                 /* we have only a switch on HP-out PIN */
14614                 sprintf(name, "%s Playback Switch", pfx);
14615                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14616                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14617                 if (err < 0)
14618                         return err;
14619         }
14620         return 0;
14621 }
14622
14623 /* parse the BIOS configuration and set up the alc_spec
14624  * return 1 if successful, 0 if the proper config is not found,
14625  * or a negative error code
14626  * Based on ALC880 version - had to change it to override
14627  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
14628 static int alc861vd_parse_auto_config(struct hda_codec *codec)
14629 {
14630         struct alc_spec *spec = codec->spec;
14631         int err;
14632         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
14633
14634         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14635                                            alc861vd_ignore);
14636         if (err < 0)
14637                 return err;
14638         if (!spec->autocfg.line_outs)
14639                 return 0; /* can't find valid BIOS pin config */
14640
14641         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14642         if (err < 0)
14643                 return err;
14644         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
14645         if (err < 0)
14646                 return err;
14647         err = alc861vd_auto_create_extra_out(spec,
14648                                              spec->autocfg.speaker_pins[0],
14649                                              "Speaker");
14650         if (err < 0)
14651                 return err;
14652         err = alc861vd_auto_create_extra_out(spec,
14653                                              spec->autocfg.hp_pins[0],
14654                                              "Headphone");
14655         if (err < 0)
14656                 return err;
14657         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
14658         if (err < 0)
14659                 return err;
14660
14661         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14662
14663         if (spec->autocfg.dig_out_pin)
14664                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14665
14666         if (spec->kctls.list)
14667                 add_mixer(spec, spec->kctls.list);
14668
14669         add_verb(spec, alc861vd_volume_init_verbs);
14670
14671         spec->num_mux_defs = 1;
14672         spec->input_mux = &spec->private_imux;
14673
14674         err = alc_auto_add_mic_boost(codec);
14675         if (err < 0)
14676                 return err;
14677
14678         store_pin_configs(codec);
14679         return 1;
14680 }
14681
14682 /* additional initialization for auto-configuration model */
14683 static void alc861vd_auto_init(struct hda_codec *codec)
14684 {
14685         struct alc_spec *spec = codec->spec;
14686         alc861vd_auto_init_multi_out(codec);
14687         alc861vd_auto_init_hp_out(codec);
14688         alc861vd_auto_init_analog_input(codec);
14689         alc861vd_auto_init_input_src(codec);
14690         if (spec->unsol_event)
14691                 alc_inithook(codec);
14692 }
14693
14694 static int patch_alc861vd(struct hda_codec *codec)
14695 {
14696         struct alc_spec *spec;
14697         int err, board_config;
14698
14699         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14700         if (spec == NULL)
14701                 return -ENOMEM;
14702
14703         codec->spec = spec;
14704
14705         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
14706                                                   alc861vd_models,
14707                                                   alc861vd_cfg_tbl);
14708
14709         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
14710                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
14711                         "ALC861VD, trying auto-probe from BIOS...\n");
14712                 board_config = ALC861VD_AUTO;
14713         }
14714
14715         if (board_config == ALC861VD_AUTO) {
14716                 /* automatic parse from the BIOS config */
14717                 err = alc861vd_parse_auto_config(codec);
14718                 if (err < 0) {
14719                         alc_free(codec);
14720                         return err;
14721                 } else if (!err) {
14722                         printk(KERN_INFO
14723                                "hda_codec: Cannot set up configuration "
14724                                "from BIOS.  Using base mode...\n");
14725                         board_config = ALC861VD_3ST;
14726                 }
14727         }
14728
14729         if (board_config != ALC861VD_AUTO)
14730                 setup_preset(spec, &alc861vd_presets[board_config]);
14731
14732         if (codec->vendor_id == 0x10ec0660) {
14733                 spec->stream_name_analog = "ALC660-VD Analog";
14734                 spec->stream_name_digital = "ALC660-VD Digital";
14735                 /* always turn on EAPD */
14736                 add_verb(spec, alc660vd_eapd_verbs);
14737         } else {
14738                 spec->stream_name_analog = "ALC861VD Analog";
14739                 spec->stream_name_digital = "ALC861VD Digital";
14740         }
14741
14742         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
14743         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
14744
14745         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
14746         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
14747
14748         spec->adc_nids = alc861vd_adc_nids;
14749         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14750         spec->capsrc_nids = alc861vd_capsrc_nids;
14751         spec->is_mix_capture = 1;
14752
14753         set_capture_mixer(spec);
14754
14755         spec->vmaster_nid = 0x02;
14756
14757         codec->patch_ops = alc_patch_ops;
14758
14759         if (board_config == ALC861VD_AUTO)
14760                 spec->init_hook = alc861vd_auto_init;
14761 #ifdef CONFIG_SND_HDA_POWER_SAVE
14762         if (!spec->loopback.amplist)
14763                 spec->loopback.amplist = alc861vd_loopbacks;
14764 #endif
14765
14766         return 0;
14767 }
14768
14769 /*
14770  * ALC662 support
14771  *
14772  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
14773  * configuration.  Each pin widget can choose any input DACs and a mixer.
14774  * Each ADC is connected from a mixer of all inputs.  This makes possible
14775  * 6-channel independent captures.
14776  *
14777  * In addition, an independent DAC for the multi-playback (not used in this
14778  * driver yet).
14779  */
14780 #define ALC662_DIGOUT_NID       0x06
14781 #define ALC662_DIGIN_NID        0x0a
14782
14783 static hda_nid_t alc662_dac_nids[4] = {
14784         /* front, rear, clfe, rear_surr */
14785         0x02, 0x03, 0x04
14786 };
14787
14788 static hda_nid_t alc662_adc_nids[1] = {
14789         /* ADC1-2 */
14790         0x09,
14791 };
14792
14793 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
14794
14795 /* input MUX */
14796 /* FIXME: should be a matrix-type input source selection */
14797 static struct hda_input_mux alc662_capture_source = {
14798         .num_items = 4,
14799         .items = {
14800                 { "Mic", 0x0 },
14801                 { "Front Mic", 0x1 },
14802                 { "Line", 0x2 },
14803                 { "CD", 0x4 },
14804         },
14805 };
14806
14807 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
14808         .num_items = 2,
14809         .items = {
14810                 { "Mic", 0x1 },
14811                 { "Line", 0x2 },
14812         },
14813 };
14814
14815 static struct hda_input_mux alc662_eeepc_capture_source = {
14816         .num_items = 2,
14817         .items = {
14818                 { "i-Mic", 0x1 },
14819                 { "e-Mic", 0x0 },
14820         },
14821 };
14822
14823 static struct hda_input_mux alc663_capture_source = {
14824         .num_items = 3,
14825         .items = {
14826                 { "Mic", 0x0 },
14827                 { "Front Mic", 0x1 },
14828                 { "Line", 0x2 },
14829         },
14830 };
14831
14832 static struct hda_input_mux alc663_m51va_capture_source = {
14833         .num_items = 2,
14834         .items = {
14835                 { "Ext-Mic", 0x0 },
14836                 { "D-Mic", 0x9 },
14837         },
14838 };
14839
14840 /*
14841  * 2ch mode
14842  */
14843 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
14844         { 2, NULL }
14845 };
14846
14847 /*
14848  * 2ch mode
14849  */
14850 static struct hda_verb alc662_3ST_ch2_init[] = {
14851         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
14852         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14853         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
14854         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14855         { } /* end */
14856 };
14857
14858 /*
14859  * 6ch mode
14860  */
14861 static struct hda_verb alc662_3ST_ch6_init[] = {
14862         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14863         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14864         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
14865         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14866         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14867         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
14868         { } /* end */
14869 };
14870
14871 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
14872         { 2, alc662_3ST_ch2_init },
14873         { 6, alc662_3ST_ch6_init },
14874 };
14875
14876 /*
14877  * 2ch mode
14878  */
14879 static struct hda_verb alc662_sixstack_ch6_init[] = {
14880         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14881         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14882         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14883         { } /* end */
14884 };
14885
14886 /*
14887  * 6ch mode
14888  */
14889 static struct hda_verb alc662_sixstack_ch8_init[] = {
14890         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14891         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14892         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14893         { } /* end */
14894 };
14895
14896 static struct hda_channel_mode alc662_5stack_modes[2] = {
14897         { 2, alc662_sixstack_ch6_init },
14898         { 6, alc662_sixstack_ch8_init },
14899 };
14900
14901 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14902  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14903  */
14904
14905 static struct snd_kcontrol_new alc662_base_mixer[] = {
14906         /* output mixer control */
14907         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
14908         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14909         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
14910         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14911         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14912         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14913         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14914         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14915         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14916
14917         /*Input mixer control */
14918         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
14919         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
14920         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
14921         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
14922         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
14923         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
14924         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
14925         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
14926         { } /* end */
14927 };
14928
14929 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
14930         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14931         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14932         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14933         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14934         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14935         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14936         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14937         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14938         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14939         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14940         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14941         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14942         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14943         { } /* end */
14944 };
14945
14946 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
14947         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14948         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14949         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14950         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14951         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14952         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14953         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14954         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14955         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14956         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14957         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14958         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14959         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14960         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14961         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14962         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14963         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14964         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14965         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14966         { } /* end */
14967 };
14968
14969 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
14970         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14971         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
14972         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14973         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
14974         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14975         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14976         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14977         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14978         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14979         { } /* end */
14980 };
14981
14982 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
14983         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14984
14985         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14986         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14987
14988         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
14989         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14990         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14991
14992         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
14993         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14994         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14995         { } /* end */
14996 };
14997
14998 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
14999         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15000         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15001         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15002         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
15003         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15004         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15005         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
15006         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
15007         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15008         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15009         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15010         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15011         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15012         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15013         { } /* end */
15014 };
15015
15016 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15017         .ops = &snd_hda_bind_vol,
15018         .values = {
15019                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15020                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15021                 0
15022         },
15023 };
15024
15025 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15026         .ops = &snd_hda_bind_sw,
15027         .values = {
15028                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15029                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15030                 0
15031         },
15032 };
15033
15034 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15035         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15036         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15037         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15038         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15039         { } /* end */
15040 };
15041
15042 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15043         .ops = &snd_hda_bind_sw,
15044         .values = {
15045                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15046                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15047                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15048                 0
15049         },
15050 };
15051
15052 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15053         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15054         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15055         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15056         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15057         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15058         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15059
15060         { } /* end */
15061 };
15062
15063 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15064         .ops = &snd_hda_bind_sw,
15065         .values = {
15066                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15067                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15068                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15069                 0
15070         },
15071 };
15072
15073 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15074         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15075         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15076         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15077         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15078         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15079         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15080         { } /* end */
15081 };
15082
15083 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15084         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15085         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15086         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15087         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15088         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15089         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15090         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15091         { } /* end */
15092 };
15093
15094 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15095         .ops = &snd_hda_bind_vol,
15096         .values = {
15097                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15098                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15099                 0
15100         },
15101 };
15102
15103 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15104         .ops = &snd_hda_bind_sw,
15105         .values = {
15106                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15107                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15108                 0
15109         },
15110 };
15111
15112 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15113         HDA_BIND_VOL("Master Playback Volume",
15114                                 &alc663_asus_two_bind_master_vol),
15115         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15116         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15117         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15118         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15119         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15120         { } /* end */
15121 };
15122
15123 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15124         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15125         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15126         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15127         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15128         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15129         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15130         { } /* end */
15131 };
15132
15133 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
15134         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15135         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15136         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15137         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15138         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15139
15140         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15141         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15142         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15143         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15144         { } /* end */
15145 };
15146
15147 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
15148         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15149         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15150         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15151
15152         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15153         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15154         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15155         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15156         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15157         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15158         { } /* end */
15159 };
15160
15161 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
15162         {
15163                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15164                 .name = "Channel Mode",
15165                 .info = alc_ch_mode_info,
15166                 .get = alc_ch_mode_get,
15167                 .put = alc_ch_mode_put,
15168         },
15169         { } /* end */
15170 };
15171
15172 static struct hda_verb alc662_init_verbs[] = {
15173         /* ADC: mute amp left and right */
15174         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15175         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15176         /* Front mixer: unmute input/output amp left and right (volume = 0) */
15177
15178         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15179         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15180         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15181         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15182         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15183
15184         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15185         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15186         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15187         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15188         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15189         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15190
15191         /* Front Pin: output 0 (0x0c) */
15192         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15193         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15194
15195         /* Rear Pin: output 1 (0x0d) */
15196         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15197         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15198
15199         /* CLFE Pin: output 2 (0x0e) */
15200         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15201         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15202
15203         /* Mic (rear) pin: input vref at 80% */
15204         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15205         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15206         /* Front Mic pin: input vref at 80% */
15207         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15208         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15209         /* Line In pin: input */
15210         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15211         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15212         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15213         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15214         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15215         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15216         /* CD pin widget for input */
15217         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15218
15219         /* FIXME: use matrix-type input source selection */
15220         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15221         /* Input mixer */
15222         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15223         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15224         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15225         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15226
15227         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15228         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15229         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15230         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15231
15232         /* always trun on EAPD */
15233         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15234         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15235
15236         { }
15237 };
15238
15239 static struct hda_verb alc662_sue_init_verbs[] = {
15240         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15241         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15242         {}
15243 };
15244
15245 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
15246         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15247         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15248         {}
15249 };
15250
15251 /* Set Unsolicited Event*/
15252 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
15253         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15254         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15255         {}
15256 };
15257
15258 /*
15259  * generic initialization of ADC, input mixers and output mixers
15260  */
15261 static struct hda_verb alc662_auto_init_verbs[] = {
15262         /*
15263          * Unmute ADC and set the default input to mic-in
15264          */
15265         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15266         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15267
15268         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
15269          * mixer widget
15270          * Note: PASD motherboards uses the Line In 2 as the input for front
15271          * panel mic (mic 2)
15272          */
15273         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
15274         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15275         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15276         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15277         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15278         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15279
15280         /*
15281          * Set up output mixers (0x0c - 0x0f)
15282          */
15283         /* set vol=0 to output mixers */
15284         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15285         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15286         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15287
15288         /* set up input amps for analog loopback */
15289         /* Amp Indices: DAC = 0, mixer = 1 */
15290         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15291         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15292         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15293         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15294         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15295         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15296
15297
15298         /* FIXME: use matrix-type input source selection */
15299         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15300         /* Input mixer */
15301         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15302         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15303         { }
15304 };
15305
15306 /* additional verbs for ALC663 */
15307 static struct hda_verb alc663_auto_init_verbs[] = {
15308         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15309         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15310         { }
15311 };
15312
15313 static struct hda_verb alc663_m51va_init_verbs[] = {
15314         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15315         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15316         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15317         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15318         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15319         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15320         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15321         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15322         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15323         {}
15324 };
15325
15326 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15327         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15328         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15329         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15330         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15331         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15332         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15333         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15334         {}
15335 };
15336
15337 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15338         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15339         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15340         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15341         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15342         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15343         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15344         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15345         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15346         {}
15347 };
15348
15349 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15350         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15351         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15352         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15353         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15354         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15355         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15356         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15357         {}
15358 };
15359
15360 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15361         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15362         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15363         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15364         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15365         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15366         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15367         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15368         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15369         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15370         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15371         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15372         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15373         {}
15374 };
15375
15376 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15377         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15378         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15379         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15380         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15381         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15382         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15383         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15384         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15385         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15386         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15387         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15388         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15389         {}
15390 };
15391
15392 static struct hda_verb alc663_g71v_init_verbs[] = {
15393         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15394         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15395         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15396
15397         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15398         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15399         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15400
15401         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15402         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15403         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15404         {}
15405 };
15406
15407 static struct hda_verb alc663_g50v_init_verbs[] = {
15408         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15409         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15410         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15411
15412         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15413         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15414         {}
15415 };
15416
15417 static struct hda_verb alc662_ecs_init_verbs[] = {
15418         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15419         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15420         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15421         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15422         {}
15423 };
15424
15425 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15426         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15427         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15428         { } /* end */
15429 };
15430
15431 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15432 {
15433         unsigned int present;
15434         unsigned char bits;
15435
15436         present = snd_hda_codec_read(codec, 0x14, 0,
15437                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15438         bits = present ? HDA_AMP_MUTE : 0;
15439         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15440                                  HDA_AMP_MUTE, bits);
15441 }
15442
15443 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15444 {
15445         unsigned int present;
15446         unsigned char bits;
15447
15448         present = snd_hda_codec_read(codec, 0x1b, 0,
15449                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15450         bits = present ? HDA_AMP_MUTE : 0;
15451         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15452                                  HDA_AMP_MUTE, bits);
15453         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15454                                  HDA_AMP_MUTE, bits);
15455 }
15456
15457 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15458                                            unsigned int res)
15459 {
15460         if ((res >> 26) == ALC880_HP_EVENT)
15461                 alc662_lenovo_101e_all_automute(codec);
15462         if ((res >> 26) == ALC880_FRONT_EVENT)
15463                 alc662_lenovo_101e_ispeaker_automute(codec);
15464 }
15465
15466 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15467 {
15468         unsigned int present;
15469
15470         present = snd_hda_codec_read(codec, 0x18, 0,
15471                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15472         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15473                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15474         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15475                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15476         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15477                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15478         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15479                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15480 }
15481
15482 /* unsolicited event for HP jack sensing */
15483 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15484                                      unsigned int res)
15485 {
15486         if ((res >> 26) == ALC880_HP_EVENT)
15487                 alc262_hippo1_automute( codec );
15488
15489         if ((res >> 26) == ALC880_MIC_EVENT)
15490                 alc662_eeepc_mic_automute(codec);
15491 }
15492
15493 static void alc662_eeepc_inithook(struct hda_codec *codec)
15494 {
15495         alc262_hippo1_automute( codec );
15496         alc662_eeepc_mic_automute(codec);
15497 }
15498
15499 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15500 {
15501         unsigned int mute;
15502         unsigned int present;
15503
15504         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15505         present = snd_hda_codec_read(codec, 0x14, 0,
15506                                      AC_VERB_GET_PIN_SENSE, 0);
15507         present = (present & 0x80000000) != 0;
15508         if (present) {
15509                 /* mute internal speaker */
15510                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15511                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15512         } else {
15513                 /* unmute internal speaker if necessary */
15514                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15515                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15516                                         HDA_AMP_MUTE, mute);
15517         }
15518 }
15519
15520 /* unsolicited event for HP jack sensing */
15521 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15522                                           unsigned int res)
15523 {
15524         if ((res >> 26) == ALC880_HP_EVENT)
15525                 alc662_eeepc_ep20_automute(codec);
15526 }
15527
15528 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15529 {
15530         alc662_eeepc_ep20_automute(codec);
15531 }
15532
15533 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15534 {
15535         unsigned int present;
15536         unsigned char bits;
15537
15538         present = snd_hda_codec_read(codec, 0x21, 0,
15539                         AC_VERB_GET_PIN_SENSE, 0)
15540                         & AC_PINSENSE_PRESENCE;
15541         bits = present ? HDA_AMP_MUTE : 0;
15542         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15543                                 AMP_IN_MUTE(0), bits);
15544         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15545                                 AMP_IN_MUTE(0), bits);
15546 }
15547
15548 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15549 {
15550         unsigned int present;
15551         unsigned char bits;
15552
15553         present = snd_hda_codec_read(codec, 0x21, 0,
15554                         AC_VERB_GET_PIN_SENSE, 0)
15555                         & AC_PINSENSE_PRESENCE;
15556         bits = present ? HDA_AMP_MUTE : 0;
15557         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15558                                 AMP_IN_MUTE(0), bits);
15559         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15560                                 AMP_IN_MUTE(0), bits);
15561         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15562                                 AMP_IN_MUTE(0), bits);
15563         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15564                                 AMP_IN_MUTE(0), bits);
15565 }
15566
15567 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15568 {
15569         unsigned int present;
15570         unsigned char bits;
15571
15572         present = snd_hda_codec_read(codec, 0x15, 0,
15573                         AC_VERB_GET_PIN_SENSE, 0)
15574                         & AC_PINSENSE_PRESENCE;
15575         bits = present ? HDA_AMP_MUTE : 0;
15576         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15577                                 AMP_IN_MUTE(0), bits);
15578         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15579                                 AMP_IN_MUTE(0), bits);
15580         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15581                                 AMP_IN_MUTE(0), bits);
15582         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15583                                 AMP_IN_MUTE(0), bits);
15584 }
15585
15586 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15587 {
15588         unsigned int present;
15589         unsigned char bits;
15590
15591         present = snd_hda_codec_read(codec, 0x1b, 0,
15592                         AC_VERB_GET_PIN_SENSE, 0)
15593                         & AC_PINSENSE_PRESENCE;
15594         bits = present ? 0 : PIN_OUT;
15595         snd_hda_codec_write(codec, 0x14, 0,
15596                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15597 }
15598
15599 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15600 {
15601         unsigned int present1, present2;
15602
15603         present1 = snd_hda_codec_read(codec, 0x21, 0,
15604                         AC_VERB_GET_PIN_SENSE, 0)
15605                         & AC_PINSENSE_PRESENCE;
15606         present2 = snd_hda_codec_read(codec, 0x15, 0,
15607                         AC_VERB_GET_PIN_SENSE, 0)
15608                         & AC_PINSENSE_PRESENCE;
15609
15610         if (present1 || present2) {
15611                 snd_hda_codec_write_cache(codec, 0x14, 0,
15612                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15613         } else {
15614                 snd_hda_codec_write_cache(codec, 0x14, 0,
15615                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15616         }
15617 }
15618
15619 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15620 {
15621         unsigned int present1, present2;
15622
15623         present1 = snd_hda_codec_read(codec, 0x1b, 0,
15624                                 AC_VERB_GET_PIN_SENSE, 0)
15625                                 & AC_PINSENSE_PRESENCE;
15626         present2 = snd_hda_codec_read(codec, 0x15, 0,
15627                                 AC_VERB_GET_PIN_SENSE, 0)
15628                                 & AC_PINSENSE_PRESENCE;
15629
15630         if (present1 || present2) {
15631                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15632                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15633                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15634                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15635         } else {
15636                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15637                                 AMP_IN_MUTE(0), 0);
15638                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15639                                 AMP_IN_MUTE(0), 0);
15640         }
15641 }
15642
15643 static void alc663_m51va_mic_automute(struct hda_codec *codec)
15644 {
15645         unsigned int present;
15646
15647         present = snd_hda_codec_read(codec, 0x18, 0,
15648                         AC_VERB_GET_PIN_SENSE, 0)
15649                         & AC_PINSENSE_PRESENCE;
15650         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15651                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15652         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15653                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15654         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15655                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15656         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15657                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15658 }
15659
15660 static void alc663_m51va_unsol_event(struct hda_codec *codec,
15661                                            unsigned int res)
15662 {
15663         switch (res >> 26) {
15664         case ALC880_HP_EVENT:
15665                 alc663_m51va_speaker_automute(codec);
15666                 break;
15667         case ALC880_MIC_EVENT:
15668                 alc663_m51va_mic_automute(codec);
15669                 break;
15670         }
15671 }
15672
15673 static void alc663_m51va_inithook(struct hda_codec *codec)
15674 {
15675         alc663_m51va_speaker_automute(codec);
15676         alc663_m51va_mic_automute(codec);
15677 }
15678
15679 /* ***************** Mode1 ******************************/
15680 static void alc663_mode1_unsol_event(struct hda_codec *codec,
15681                                            unsigned int res)
15682 {
15683         switch (res >> 26) {
15684         case ALC880_HP_EVENT:
15685                 alc663_m51va_speaker_automute(codec);
15686                 break;
15687         case ALC880_MIC_EVENT:
15688                 alc662_eeepc_mic_automute(codec);
15689                 break;
15690         }
15691 }
15692
15693 static void alc663_mode1_inithook(struct hda_codec *codec)
15694 {
15695         alc663_m51va_speaker_automute(codec);
15696         alc662_eeepc_mic_automute(codec);
15697 }
15698 /* ***************** Mode2 ******************************/
15699 static void alc662_mode2_unsol_event(struct hda_codec *codec,
15700                                            unsigned int res)
15701 {
15702         switch (res >> 26) {
15703         case ALC880_HP_EVENT:
15704                 alc662_f5z_speaker_automute(codec);
15705                 break;
15706         case ALC880_MIC_EVENT:
15707                 alc662_eeepc_mic_automute(codec);
15708                 break;
15709         }
15710 }
15711
15712 static void alc662_mode2_inithook(struct hda_codec *codec)
15713 {
15714         alc662_f5z_speaker_automute(codec);
15715         alc662_eeepc_mic_automute(codec);
15716 }
15717 /* ***************** Mode3 ******************************/
15718 static void alc663_mode3_unsol_event(struct hda_codec *codec,
15719                                            unsigned int res)
15720 {
15721         switch (res >> 26) {
15722         case ALC880_HP_EVENT:
15723                 alc663_two_hp_m1_speaker_automute(codec);
15724                 break;
15725         case ALC880_MIC_EVENT:
15726                 alc662_eeepc_mic_automute(codec);
15727                 break;
15728         }
15729 }
15730
15731 static void alc663_mode3_inithook(struct hda_codec *codec)
15732 {
15733         alc663_two_hp_m1_speaker_automute(codec);
15734         alc662_eeepc_mic_automute(codec);
15735 }
15736 /* ***************** Mode4 ******************************/
15737 static void alc663_mode4_unsol_event(struct hda_codec *codec,
15738                                            unsigned int res)
15739 {
15740         switch (res >> 26) {
15741         case ALC880_HP_EVENT:
15742                 alc663_21jd_two_speaker_automute(codec);
15743                 break;
15744         case ALC880_MIC_EVENT:
15745                 alc662_eeepc_mic_automute(codec);
15746                 break;
15747         }
15748 }
15749
15750 static void alc663_mode4_inithook(struct hda_codec *codec)
15751 {
15752         alc663_21jd_two_speaker_automute(codec);
15753         alc662_eeepc_mic_automute(codec);
15754 }
15755 /* ***************** Mode5 ******************************/
15756 static void alc663_mode5_unsol_event(struct hda_codec *codec,
15757                                            unsigned int res)
15758 {
15759         switch (res >> 26) {
15760         case ALC880_HP_EVENT:
15761                 alc663_15jd_two_speaker_automute(codec);
15762                 break;
15763         case ALC880_MIC_EVENT:
15764                 alc662_eeepc_mic_automute(codec);
15765                 break;
15766         }
15767 }
15768
15769 static void alc663_mode5_inithook(struct hda_codec *codec)
15770 {
15771         alc663_15jd_two_speaker_automute(codec);
15772         alc662_eeepc_mic_automute(codec);
15773 }
15774 /* ***************** Mode6 ******************************/
15775 static void alc663_mode6_unsol_event(struct hda_codec *codec,
15776                                            unsigned int res)
15777 {
15778         switch (res >> 26) {
15779         case ALC880_HP_EVENT:
15780                 alc663_two_hp_m2_speaker_automute(codec);
15781                 break;
15782         case ALC880_MIC_EVENT:
15783                 alc662_eeepc_mic_automute(codec);
15784                 break;
15785         }
15786 }
15787
15788 static void alc663_mode6_inithook(struct hda_codec *codec)
15789 {
15790         alc663_two_hp_m2_speaker_automute(codec);
15791         alc662_eeepc_mic_automute(codec);
15792 }
15793
15794 static void alc663_g71v_hp_automute(struct hda_codec *codec)
15795 {
15796         unsigned int present;
15797         unsigned char bits;
15798
15799         present = snd_hda_codec_read(codec, 0x21, 0,
15800                                      AC_VERB_GET_PIN_SENSE, 0)
15801                 & AC_PINSENSE_PRESENCE;
15802         bits = present ? HDA_AMP_MUTE : 0;
15803         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15804                                  HDA_AMP_MUTE, bits);
15805         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15806                                  HDA_AMP_MUTE, bits);
15807 }
15808
15809 static void alc663_g71v_front_automute(struct hda_codec *codec)
15810 {
15811         unsigned int present;
15812         unsigned char bits;
15813
15814         present = snd_hda_codec_read(codec, 0x15, 0,
15815                                      AC_VERB_GET_PIN_SENSE, 0)
15816                 & AC_PINSENSE_PRESENCE;
15817         bits = present ? HDA_AMP_MUTE : 0;
15818         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15819                                  HDA_AMP_MUTE, bits);
15820 }
15821
15822 static void alc663_g71v_unsol_event(struct hda_codec *codec,
15823                                            unsigned int res)
15824 {
15825         switch (res >> 26) {
15826         case ALC880_HP_EVENT:
15827                 alc663_g71v_hp_automute(codec);
15828                 break;
15829         case ALC880_FRONT_EVENT:
15830                 alc663_g71v_front_automute(codec);
15831                 break;
15832         case ALC880_MIC_EVENT:
15833                 alc662_eeepc_mic_automute(codec);
15834                 break;
15835         }
15836 }
15837
15838 static void alc663_g71v_inithook(struct hda_codec *codec)
15839 {
15840         alc663_g71v_front_automute(codec);
15841         alc663_g71v_hp_automute(codec);
15842         alc662_eeepc_mic_automute(codec);
15843 }
15844
15845 static void alc663_g50v_unsol_event(struct hda_codec *codec,
15846                                            unsigned int res)
15847 {
15848         switch (res >> 26) {
15849         case ALC880_HP_EVENT:
15850                 alc663_m51va_speaker_automute(codec);
15851                 break;
15852         case ALC880_MIC_EVENT:
15853                 alc662_eeepc_mic_automute(codec);
15854                 break;
15855         }
15856 }
15857
15858 static void alc663_g50v_inithook(struct hda_codec *codec)
15859 {
15860         alc663_m51va_speaker_automute(codec);
15861         alc662_eeepc_mic_automute(codec);
15862 }
15863
15864 /* bind hp and internal speaker mute (with plug check) */
15865 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15866                                      struct snd_ctl_elem_value *ucontrol)
15867 {
15868         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15869         long *valp = ucontrol->value.integer.value;
15870         int change;
15871
15872         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15873                                           HDA_AMP_MUTE,
15874                                           valp[0] ? 0 : HDA_AMP_MUTE);
15875         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15876                                            HDA_AMP_MUTE,
15877                                            valp[1] ? 0 : HDA_AMP_MUTE);
15878         if (change)
15879                 alc262_hippo1_automute(codec);
15880         return change;
15881 }
15882
15883 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
15884         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15885         {
15886                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15887                 .name = "Master Playback Switch",
15888                 .info = snd_hda_mixer_amp_switch_info,
15889                 .get = snd_hda_mixer_amp_switch_get,
15890                 .put = alc662_ecs_master_sw_put,
15891                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15892         },
15893
15894         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
15895         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
15896         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
15897
15898         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15899         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15900         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15901         { } /* end */
15902 };
15903
15904 #ifdef CONFIG_SND_HDA_POWER_SAVE
15905 #define alc662_loopbacks        alc880_loopbacks
15906 #endif
15907
15908
15909 /* pcm configuration: identiacal with ALC880 */
15910 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
15911 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
15912 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
15913 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
15914
15915 /*
15916  * configuration and preset
15917  */
15918 static const char *alc662_models[ALC662_MODEL_LAST] = {
15919         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
15920         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
15921         [ALC662_3ST_6ch]        = "3stack-6ch",
15922         [ALC662_5ST_DIG]        = "6stack-dig",
15923         [ALC662_LENOVO_101E]    = "lenovo-101e",
15924         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
15925         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
15926         [ALC662_ECS] = "ecs",
15927         [ALC663_ASUS_M51VA] = "m51va",
15928         [ALC663_ASUS_G71V] = "g71v",
15929         [ALC663_ASUS_H13] = "h13",
15930         [ALC663_ASUS_G50V] = "g50v",
15931         [ALC663_ASUS_MODE1] = "asus-mode1",
15932         [ALC662_ASUS_MODE2] = "asus-mode2",
15933         [ALC663_ASUS_MODE3] = "asus-mode3",
15934         [ALC663_ASUS_MODE4] = "asus-mode4",
15935         [ALC663_ASUS_MODE5] = "asus-mode5",
15936         [ALC663_ASUS_MODE6] = "asus-mode6",
15937         [ALC662_AUTO]           = "auto",
15938 };
15939
15940 static struct snd_pci_quirk alc662_cfg_tbl[] = {
15941         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
15942         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
15943         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
15944         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
15945         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
15946         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
15947         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
15948         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
15949         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
15950         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
15951         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
15952         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
15953         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
15954         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
15955         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
15956         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
15957         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
15958         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
15959         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
15960         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
15961         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
15962         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
15963         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
15964         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
15965         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
15966         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
15967         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
15968         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
15969         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
15970         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
15971         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
15972         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
15973         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
15974         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
15975         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
15976         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
15977         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
15978         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
15979                       ALC662_3ST_6ch_DIG),
15980         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
15981         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
15982         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
15983         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
15984                       ALC662_3ST_6ch_DIG),
15985         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
15986         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
15987                                         ALC662_3ST_6ch_DIG),
15988         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
15989         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
15990         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
15991         {}
15992 };
15993
15994 static struct alc_config_preset alc662_presets[] = {
15995         [ALC662_3ST_2ch_DIG] = {
15996                 .mixers = { alc662_3ST_2ch_mixer },
15997                 .init_verbs = { alc662_init_verbs },
15998                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15999                 .dac_nids = alc662_dac_nids,
16000                 .dig_out_nid = ALC662_DIGOUT_NID,
16001                 .dig_in_nid = ALC662_DIGIN_NID,
16002                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16003                 .channel_mode = alc662_3ST_2ch_modes,
16004                 .input_mux = &alc662_capture_source,
16005         },
16006         [ALC662_3ST_6ch_DIG] = {
16007                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16008                 .init_verbs = { alc662_init_verbs },
16009                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16010                 .dac_nids = alc662_dac_nids,
16011                 .dig_out_nid = ALC662_DIGOUT_NID,
16012                 .dig_in_nid = ALC662_DIGIN_NID,
16013                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16014                 .channel_mode = alc662_3ST_6ch_modes,
16015                 .need_dac_fix = 1,
16016                 .input_mux = &alc662_capture_source,
16017         },
16018         [ALC662_3ST_6ch] = {
16019                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16020                 .init_verbs = { alc662_init_verbs },
16021                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16022                 .dac_nids = alc662_dac_nids,
16023                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16024                 .channel_mode = alc662_3ST_6ch_modes,
16025                 .need_dac_fix = 1,
16026                 .input_mux = &alc662_capture_source,
16027         },
16028         [ALC662_5ST_DIG] = {
16029                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16030                 .init_verbs = { alc662_init_verbs },
16031                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16032                 .dac_nids = alc662_dac_nids,
16033                 .dig_out_nid = ALC662_DIGOUT_NID,
16034                 .dig_in_nid = ALC662_DIGIN_NID,
16035                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16036                 .channel_mode = alc662_5stack_modes,
16037                 .input_mux = &alc662_capture_source,
16038         },
16039         [ALC662_LENOVO_101E] = {
16040                 .mixers = { alc662_lenovo_101e_mixer },
16041                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16042                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16043                 .dac_nids = alc662_dac_nids,
16044                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16045                 .channel_mode = alc662_3ST_2ch_modes,
16046                 .input_mux = &alc662_lenovo_101e_capture_source,
16047                 .unsol_event = alc662_lenovo_101e_unsol_event,
16048                 .init_hook = alc662_lenovo_101e_all_automute,
16049         },
16050         [ALC662_ASUS_EEEPC_P701] = {
16051                 .mixers = { alc662_eeepc_p701_mixer },
16052                 .init_verbs = { alc662_init_verbs,
16053                                 alc662_eeepc_sue_init_verbs },
16054                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16055                 .dac_nids = alc662_dac_nids,
16056                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16057                 .channel_mode = alc662_3ST_2ch_modes,
16058                 .input_mux = &alc662_eeepc_capture_source,
16059                 .unsol_event = alc662_eeepc_unsol_event,
16060                 .init_hook = alc662_eeepc_inithook,
16061         },
16062         [ALC662_ASUS_EEEPC_EP20] = {
16063                 .mixers = { alc662_eeepc_ep20_mixer,
16064                             alc662_chmode_mixer },
16065                 .init_verbs = { alc662_init_verbs,
16066                                 alc662_eeepc_ep20_sue_init_verbs },
16067                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16068                 .dac_nids = alc662_dac_nids,
16069                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16070                 .channel_mode = alc662_3ST_6ch_modes,
16071                 .input_mux = &alc662_lenovo_101e_capture_source,
16072                 .unsol_event = alc662_eeepc_ep20_unsol_event,
16073                 .init_hook = alc662_eeepc_ep20_inithook,
16074         },
16075         [ALC662_ECS] = {
16076                 .mixers = { alc662_ecs_mixer },
16077                 .init_verbs = { alc662_init_verbs,
16078                                 alc662_ecs_init_verbs },
16079                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16080                 .dac_nids = alc662_dac_nids,
16081                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16082                 .channel_mode = alc662_3ST_2ch_modes,
16083                 .input_mux = &alc662_eeepc_capture_source,
16084                 .unsol_event = alc662_eeepc_unsol_event,
16085                 .init_hook = alc662_eeepc_inithook,
16086         },
16087         [ALC663_ASUS_M51VA] = {
16088                 .mixers = { alc663_m51va_mixer },
16089                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16090                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16091                 .dac_nids = alc662_dac_nids,
16092                 .dig_out_nid = ALC662_DIGOUT_NID,
16093                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16094                 .channel_mode = alc662_3ST_2ch_modes,
16095                 .input_mux = &alc663_m51va_capture_source,
16096                 .unsol_event = alc663_m51va_unsol_event,
16097                 .init_hook = alc663_m51va_inithook,
16098         },
16099         [ALC663_ASUS_G71V] = {
16100                 .mixers = { alc663_g71v_mixer },
16101                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16102                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16103                 .dac_nids = alc662_dac_nids,
16104                 .dig_out_nid = ALC662_DIGOUT_NID,
16105                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16106                 .channel_mode = alc662_3ST_2ch_modes,
16107                 .input_mux = &alc662_eeepc_capture_source,
16108                 .unsol_event = alc663_g71v_unsol_event,
16109                 .init_hook = alc663_g71v_inithook,
16110         },
16111         [ALC663_ASUS_H13] = {
16112                 .mixers = { alc663_m51va_mixer },
16113                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16114                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16115                 .dac_nids = alc662_dac_nids,
16116                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16117                 .channel_mode = alc662_3ST_2ch_modes,
16118                 .input_mux = &alc663_m51va_capture_source,
16119                 .unsol_event = alc663_m51va_unsol_event,
16120                 .init_hook = alc663_m51va_inithook,
16121         },
16122         [ALC663_ASUS_G50V] = {
16123                 .mixers = { alc663_g50v_mixer },
16124                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
16125                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16126                 .dac_nids = alc662_dac_nids,
16127                 .dig_out_nid = ALC662_DIGOUT_NID,
16128                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16129                 .channel_mode = alc662_3ST_6ch_modes,
16130                 .input_mux = &alc663_capture_source,
16131                 .unsol_event = alc663_g50v_unsol_event,
16132                 .init_hook = alc663_g50v_inithook,
16133         },
16134         [ALC663_ASUS_MODE1] = {
16135                 .mixers = { alc663_m51va_mixer },
16136                 .cap_mixer = alc662_auto_capture_mixer,
16137                 .init_verbs = { alc662_init_verbs,
16138                                 alc663_21jd_amic_init_verbs },
16139                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16140                 .hp_nid = 0x03,
16141                 .dac_nids = alc662_dac_nids,
16142                 .dig_out_nid = ALC662_DIGOUT_NID,
16143                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16144                 .channel_mode = alc662_3ST_2ch_modes,
16145                 .input_mux = &alc662_eeepc_capture_source,
16146                 .unsol_event = alc663_mode1_unsol_event,
16147                 .init_hook = alc663_mode1_inithook,
16148         },
16149         [ALC662_ASUS_MODE2] = {
16150                 .mixers = { alc662_1bjd_mixer },
16151                 .cap_mixer = alc662_auto_capture_mixer,
16152                 .init_verbs = { alc662_init_verbs,
16153                                 alc662_1bjd_amic_init_verbs },
16154                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16155                 .dac_nids = alc662_dac_nids,
16156                 .dig_out_nid = ALC662_DIGOUT_NID,
16157                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16158                 .channel_mode = alc662_3ST_2ch_modes,
16159                 .input_mux = &alc662_eeepc_capture_source,
16160                 .unsol_event = alc662_mode2_unsol_event,
16161                 .init_hook = alc662_mode2_inithook,
16162         },
16163         [ALC663_ASUS_MODE3] = {
16164                 .mixers = { alc663_two_hp_m1_mixer },
16165                 .cap_mixer = alc662_auto_capture_mixer,
16166                 .init_verbs = { alc662_init_verbs,
16167                                 alc663_two_hp_amic_m1_init_verbs },
16168                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16169                 .hp_nid = 0x03,
16170                 .dac_nids = alc662_dac_nids,
16171                 .dig_out_nid = ALC662_DIGOUT_NID,
16172                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16173                 .channel_mode = alc662_3ST_2ch_modes,
16174                 .input_mux = &alc662_eeepc_capture_source,
16175                 .unsol_event = alc663_mode3_unsol_event,
16176                 .init_hook = alc663_mode3_inithook,
16177         },
16178         [ALC663_ASUS_MODE4] = {
16179                 .mixers = { alc663_asus_21jd_clfe_mixer },
16180                 .cap_mixer = alc662_auto_capture_mixer,
16181                 .init_verbs = { alc662_init_verbs,
16182                                 alc663_21jd_amic_init_verbs},
16183                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16184                 .hp_nid = 0x03,
16185                 .dac_nids = alc662_dac_nids,
16186                 .dig_out_nid = ALC662_DIGOUT_NID,
16187                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16188                 .channel_mode = alc662_3ST_2ch_modes,
16189                 .input_mux = &alc662_eeepc_capture_source,
16190                 .unsol_event = alc663_mode4_unsol_event,
16191                 .init_hook = alc663_mode4_inithook,
16192         },
16193         [ALC663_ASUS_MODE5] = {
16194                 .mixers = { alc663_asus_15jd_clfe_mixer },
16195                 .cap_mixer = alc662_auto_capture_mixer,
16196                 .init_verbs = { alc662_init_verbs,
16197                                 alc663_15jd_amic_init_verbs },
16198                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16199                 .hp_nid = 0x03,
16200                 .dac_nids = alc662_dac_nids,
16201                 .dig_out_nid = ALC662_DIGOUT_NID,
16202                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16203                 .channel_mode = alc662_3ST_2ch_modes,
16204                 .input_mux = &alc662_eeepc_capture_source,
16205                 .unsol_event = alc663_mode5_unsol_event,
16206                 .init_hook = alc663_mode5_inithook,
16207         },
16208         [ALC663_ASUS_MODE6] = {
16209                 .mixers = { alc663_two_hp_m2_mixer },
16210                 .cap_mixer = alc662_auto_capture_mixer,
16211                 .init_verbs = { alc662_init_verbs,
16212                                 alc663_two_hp_amic_m2_init_verbs },
16213                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16214                 .hp_nid = 0x03,
16215                 .dac_nids = alc662_dac_nids,
16216                 .dig_out_nid = ALC662_DIGOUT_NID,
16217                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16218                 .channel_mode = alc662_3ST_2ch_modes,
16219                 .input_mux = &alc662_eeepc_capture_source,
16220                 .unsol_event = alc663_mode6_unsol_event,
16221                 .init_hook = alc663_mode6_inithook,
16222         },
16223 };
16224
16225
16226 /*
16227  * BIOS auto configuration
16228  */
16229
16230 /* add playback controls from the parsed DAC table */
16231 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
16232                                              const struct auto_pin_cfg *cfg)
16233 {
16234         char name[32];
16235         static const char *chname[4] = {
16236                 "Front", "Surround", NULL /*CLFE*/, "Side"
16237         };
16238         hda_nid_t nid;
16239         int i, err;
16240
16241         for (i = 0; i < cfg->line_outs; i++) {
16242                 if (!spec->multiout.dac_nids[i])
16243                         continue;
16244                 nid = alc880_idx_to_dac(i);
16245                 if (i == 2) {
16246                         /* Center/LFE */
16247                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16248                                           "Center Playback Volume",
16249                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
16250                                                               HDA_OUTPUT));
16251                         if (err < 0)
16252                                 return err;
16253                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16254                                           "LFE Playback Volume",
16255                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
16256                                                               HDA_OUTPUT));
16257                         if (err < 0)
16258                                 return err;
16259                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16260                                           "Center Playback Switch",
16261                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
16262                                                               HDA_INPUT));
16263                         if (err < 0)
16264                                 return err;
16265                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16266                                           "LFE Playback Switch",
16267                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
16268                                                               HDA_INPUT));
16269                         if (err < 0)
16270                                 return err;
16271                 } else {
16272                         sprintf(name, "%s Playback Volume", chname[i]);
16273                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16274                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
16275                                                               HDA_OUTPUT));
16276                         if (err < 0)
16277                                 return err;
16278                         sprintf(name, "%s Playback Switch", chname[i]);
16279                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16280                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
16281                                                     3, 0, HDA_INPUT));
16282                         if (err < 0)
16283                                 return err;
16284                 }
16285         }
16286         return 0;
16287 }
16288
16289 /* add playback controls for speaker and HP outputs */
16290 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16291                                         const char *pfx)
16292 {
16293         hda_nid_t nid;
16294         int err;
16295         char name[32];
16296
16297         if (!pin)
16298                 return 0;
16299
16300         if (pin == 0x17) {
16301                 /* ALC663 has a mono output pin on 0x17 */
16302                 sprintf(name, "%s Playback Switch", pfx);
16303                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16304                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16305                 return err;
16306         }
16307
16308         if (alc880_is_fixed_pin(pin)) {
16309                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16310                 /* printk("DAC nid=%x\n",nid); */
16311                 /* specify the DAC as the extra output */
16312                 if (!spec->multiout.hp_nid)
16313                         spec->multiout.hp_nid = nid;
16314                 else
16315                         spec->multiout.extra_out_nid[0] = nid;
16316                 /* control HP volume/switch on the output mixer amp */
16317                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16318                 sprintf(name, "%s Playback Volume", pfx);
16319                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16320                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16321                 if (err < 0)
16322                         return err;
16323                 sprintf(name, "%s Playback Switch", pfx);
16324                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16325                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16326                 if (err < 0)
16327                         return err;
16328         } else if (alc880_is_multi_pin(pin)) {
16329                 /* set manual connection */
16330                 /* we have only a switch on HP-out PIN */
16331                 sprintf(name, "%s Playback Switch", pfx);
16332                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16333                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16334                 if (err < 0)
16335                         return err;
16336         }
16337         return 0;
16338 }
16339
16340 /* create playback/capture controls for input pins */
16341 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
16342                                                 const struct auto_pin_cfg *cfg)
16343 {
16344         struct hda_input_mux *imux = &spec->private_imux;
16345         int i, err, idx;
16346
16347         for (i = 0; i < AUTO_PIN_LAST; i++) {
16348                 if (alc880_is_input_pin(cfg->input_pins[i])) {
16349                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
16350                         err = new_analog_input(spec, cfg->input_pins[i],
16351                                                auto_pin_cfg_labels[i],
16352                                                idx, 0x0b);
16353                         if (err < 0)
16354                                 return err;
16355                         imux->items[imux->num_items].label =
16356                                 auto_pin_cfg_labels[i];
16357                         imux->items[imux->num_items].index =
16358                                 alc880_input_pin_idx(cfg->input_pins[i]);
16359                         imux->num_items++;
16360                 }
16361         }
16362         return 0;
16363 }
16364
16365 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16366                                               hda_nid_t nid, int pin_type,
16367                                               int dac_idx)
16368 {
16369         alc_set_pin_output(codec, nid, pin_type);
16370         /* need the manual connection? */
16371         if (alc880_is_multi_pin(nid)) {
16372                 struct alc_spec *spec = codec->spec;
16373                 int idx = alc880_multi_pin_idx(nid);
16374                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16375                                     AC_VERB_SET_CONNECT_SEL,
16376                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16377         }
16378 }
16379
16380 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16381 {
16382         struct alc_spec *spec = codec->spec;
16383         int i;
16384
16385         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16386         for (i = 0; i <= HDA_SIDE; i++) {
16387                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16388                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16389                 if (nid)
16390                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16391                                                           i);
16392         }
16393 }
16394
16395 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16396 {
16397         struct alc_spec *spec = codec->spec;
16398         hda_nid_t pin;
16399
16400         pin = spec->autocfg.hp_pins[0];
16401         if (pin) /* connect to front */
16402                 /* use dac 0 */
16403                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16404         pin = spec->autocfg.speaker_pins[0];
16405         if (pin)
16406                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16407 }
16408
16409 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
16410 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16411
16412 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16413 {
16414         struct alc_spec *spec = codec->spec;
16415         int i;
16416
16417         for (i = 0; i < AUTO_PIN_LAST; i++) {
16418                 hda_nid_t nid = spec->autocfg.input_pins[i];
16419                 if (alc662_is_input_pin(nid)) {
16420                         snd_hda_codec_write(codec, nid, 0,
16421                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
16422                                             (i <= AUTO_PIN_FRONT_MIC ?
16423                                              PIN_VREF80 : PIN_IN));
16424                         if (nid != ALC662_PIN_CD_NID)
16425                                 snd_hda_codec_write(codec, nid, 0,
16426                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16427                                                     AMP_OUT_MUTE);
16428                 }
16429         }
16430 }
16431
16432 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16433
16434 static int alc662_parse_auto_config(struct hda_codec *codec)
16435 {
16436         struct alc_spec *spec = codec->spec;
16437         int err;
16438         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16439
16440         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16441                                            alc662_ignore);
16442         if (err < 0)
16443                 return err;
16444         if (!spec->autocfg.line_outs)
16445                 return 0; /* can't find valid BIOS pin config */
16446
16447         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16448         if (err < 0)
16449                 return err;
16450         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16451         if (err < 0)
16452                 return err;
16453         err = alc662_auto_create_extra_out(spec,
16454                                            spec->autocfg.speaker_pins[0],
16455                                            "Speaker");
16456         if (err < 0)
16457                 return err;
16458         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
16459                                            "Headphone");
16460         if (err < 0)
16461                 return err;
16462         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
16463         if (err < 0)
16464                 return err;
16465
16466         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16467
16468         if (spec->autocfg.dig_out_pin)
16469                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16470
16471         if (spec->kctls.list)
16472                 add_mixer(spec, spec->kctls.list);
16473
16474         spec->num_mux_defs = 1;
16475         spec->input_mux = &spec->private_imux;
16476
16477         add_verb(spec, alc662_auto_init_verbs);
16478         if (codec->vendor_id == 0x10ec0663)
16479                 add_verb(spec, alc663_auto_init_verbs);
16480
16481         err = alc_auto_add_mic_boost(codec);
16482         if (err < 0)
16483                 return err;
16484
16485         store_pin_configs(codec);
16486         return 1;
16487 }
16488
16489 /* additional initialization for auto-configuration model */
16490 static void alc662_auto_init(struct hda_codec *codec)
16491 {
16492         struct alc_spec *spec = codec->spec;
16493         alc662_auto_init_multi_out(codec);
16494         alc662_auto_init_hp_out(codec);
16495         alc662_auto_init_analog_input(codec);
16496         alc662_auto_init_input_src(codec);
16497         if (spec->unsol_event)
16498                 alc_inithook(codec);
16499 }
16500
16501 static int patch_alc662(struct hda_codec *codec)
16502 {
16503         struct alc_spec *spec;
16504         int err, board_config;
16505
16506         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16507         if (!spec)
16508                 return -ENOMEM;
16509
16510         codec->spec = spec;
16511
16512         alc_fix_pll_init(codec, 0x20, 0x04, 15);
16513
16514         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
16515                                                   alc662_models,
16516                                                   alc662_cfg_tbl);
16517         if (board_config < 0) {
16518                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
16519                        "trying auto-probe from BIOS...\n");
16520                 board_config = ALC662_AUTO;
16521         }
16522
16523         if (board_config == ALC662_AUTO) {
16524                 /* automatic parse from the BIOS config */
16525                 err = alc662_parse_auto_config(codec);
16526                 if (err < 0) {
16527                         alc_free(codec);
16528                         return err;
16529                 } else if (!err) {
16530                         printk(KERN_INFO
16531                                "hda_codec: Cannot set up configuration "
16532                                "from BIOS.  Using base mode...\n");
16533                         board_config = ALC662_3ST_2ch_DIG;
16534                 }
16535         }
16536
16537         if (board_config != ALC662_AUTO)
16538                 setup_preset(spec, &alc662_presets[board_config]);
16539
16540         if (codec->vendor_id == 0x10ec0663) {
16541                 spec->stream_name_analog = "ALC663 Analog";
16542                 spec->stream_name_digital = "ALC663 Digital";
16543         } else if (codec->vendor_id == 0x10ec0272) {
16544                 spec->stream_name_analog = "ALC272 Analog";
16545                 spec->stream_name_digital = "ALC272 Digital";
16546         } else {
16547                 spec->stream_name_analog = "ALC662 Analog";
16548                 spec->stream_name_digital = "ALC662 Digital";
16549         }
16550
16551         spec->stream_analog_playback = &alc662_pcm_analog_playback;
16552         spec->stream_analog_capture = &alc662_pcm_analog_capture;
16553
16554         spec->stream_digital_playback = &alc662_pcm_digital_playback;
16555         spec->stream_digital_capture = &alc662_pcm_digital_capture;
16556
16557         spec->adc_nids = alc662_adc_nids;
16558         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16559         spec->capsrc_nids = alc662_capsrc_nids;
16560         spec->is_mix_capture = 1;
16561
16562         if (!spec->cap_mixer)
16563                 set_capture_mixer(spec);
16564
16565         spec->vmaster_nid = 0x02;
16566
16567         codec->patch_ops = alc_patch_ops;
16568         if (board_config == ALC662_AUTO)
16569                 spec->init_hook = alc662_auto_init;
16570 #ifdef CONFIG_SND_HDA_POWER_SAVE
16571         if (!spec->loopback.amplist)
16572                 spec->loopback.amplist = alc662_loopbacks;
16573 #endif
16574
16575         return 0;
16576 }
16577
16578 /*
16579  * patch entries
16580  */
16581 static struct hda_codec_preset snd_hda_preset_realtek[] = {
16582         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16583         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16584         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
16585         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
16586         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
16587         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
16588         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
16589           .patch = patch_alc861 },
16590         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
16591         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
16592         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
16593         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
16594           .patch = patch_alc883 },
16595         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
16596           .patch = patch_alc662 },
16597         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
16598         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
16599         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
16600         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16601         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
16602           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16603         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
16604           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16605         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
16606         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
16607         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
16608         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
16609           .patch = patch_alc883 },
16610         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16611         {} /* terminator */
16612 };
16613
16614 MODULE_ALIAS("snd-hda-codec-id:10ec*");
16615
16616 MODULE_LICENSE("GPL");
16617 MODULE_DESCRIPTION("Realtek HD-audio codec");
16618
16619 static struct hda_codec_preset_list realtek_list = {
16620         .preset = snd_hda_preset_realtek,
16621         .owner = THIS_MODULE,
16622 };
16623
16624 static int __init patch_realtek_init(void)
16625 {
16626         return snd_hda_add_codec_preset(&realtek_list);
16627 }
16628
16629 static void __exit patch_realtek_exit(void)
16630 {
16631         snd_hda_delete_codec_preset(&realtek_list);
16632 }
16633
16634 module_init(patch_realtek_init)
16635 module_exit(patch_realtek_exit)