ALSA: hda - Add support of iMac 24 Aluminium
[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 #ifdef CONFIG_PROC_FS
769 /*
770  * hook for proc
771  */
772 static void print_realtek_coef(struct snd_info_buffer *buffer,
773                                struct hda_codec *codec, hda_nid_t nid)
774 {
775         int coeff;
776
777         if (nid != 0x20)
778                 return;
779         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
780         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
781         coeff = snd_hda_codec_read(codec, nid, 0,
782                                    AC_VERB_GET_COEF_INDEX, 0);
783         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
784 }
785 #else
786 #define print_realtek_coef      NULL
787 #endif
788
789 /*
790  * set up from the preset table
791  */
792 static void setup_preset(struct alc_spec *spec,
793                          const struct alc_config_preset *preset)
794 {
795         int i;
796
797         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
798                 add_mixer(spec, preset->mixers[i]);
799         spec->cap_mixer = preset->cap_mixer;
800         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
801              i++)
802                 add_verb(spec, preset->init_verbs[i]);
803
804         spec->channel_mode = preset->channel_mode;
805         spec->num_channel_mode = preset->num_channel_mode;
806         spec->need_dac_fix = preset->need_dac_fix;
807
808         spec->multiout.max_channels = spec->channel_mode[0].channels;
809
810         spec->multiout.num_dacs = preset->num_dacs;
811         spec->multiout.dac_nids = preset->dac_nids;
812         spec->multiout.dig_out_nid = preset->dig_out_nid;
813         spec->multiout.hp_nid = preset->hp_nid;
814
815         spec->num_mux_defs = preset->num_mux_defs;
816         if (!spec->num_mux_defs)
817                 spec->num_mux_defs = 1;
818         spec->input_mux = preset->input_mux;
819
820         spec->num_adc_nids = preset->num_adc_nids;
821         spec->adc_nids = preset->adc_nids;
822         spec->capsrc_nids = preset->capsrc_nids;
823         spec->dig_in_nid = preset->dig_in_nid;
824
825         spec->unsol_event = preset->unsol_event;
826         spec->init_hook = preset->init_hook;
827 #ifdef CONFIG_SND_HDA_POWER_SAVE
828         spec->loopback.amplist = preset->loopbacks;
829 #endif
830 }
831
832 /* Enable GPIO mask and set output */
833 static struct hda_verb alc_gpio1_init_verbs[] = {
834         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
835         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
836         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
837         { }
838 };
839
840 static struct hda_verb alc_gpio2_init_verbs[] = {
841         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
842         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
843         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
844         { }
845 };
846
847 static struct hda_verb alc_gpio3_init_verbs[] = {
848         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
849         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
850         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
851         { }
852 };
853
854 /*
855  * Fix hardware PLL issue
856  * On some codecs, the analog PLL gating control must be off while
857  * the default value is 1.
858  */
859 static void alc_fix_pll(struct hda_codec *codec)
860 {
861         struct alc_spec *spec = codec->spec;
862         unsigned int val;
863
864         if (!spec->pll_nid)
865                 return;
866         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
867                             spec->pll_coef_idx);
868         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
869                                  AC_VERB_GET_PROC_COEF, 0);
870         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
871                             spec->pll_coef_idx);
872         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
873                             val & ~(1 << spec->pll_coef_bit));
874 }
875
876 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
877                              unsigned int coef_idx, unsigned int coef_bit)
878 {
879         struct alc_spec *spec = codec->spec;
880         spec->pll_nid = nid;
881         spec->pll_coef_idx = coef_idx;
882         spec->pll_coef_bit = coef_bit;
883         alc_fix_pll(codec);
884 }
885
886 static void alc_sku_automute(struct hda_codec *codec)
887 {
888         struct alc_spec *spec = codec->spec;
889         unsigned int present;
890         unsigned int hp_nid = spec->autocfg.hp_pins[0];
891         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
892
893         /* need to execute and sync at first */
894         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
895         present = snd_hda_codec_read(codec, hp_nid, 0,
896                                      AC_VERB_GET_PIN_SENSE, 0);
897         spec->jack_present = (present & 0x80000000) != 0;
898         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
899                             spec->jack_present ? 0 : PIN_OUT);
900 }
901
902 #if 0 /* it's broken in some acses -- temporarily disabled */
903 static void alc_mic_automute(struct hda_codec *codec)
904 {
905         struct alc_spec *spec = codec->spec;
906         unsigned int present;
907         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
908         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
909         unsigned int mix_nid = spec->capsrc_nids[0];
910         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
911
912         capsrc_idx_mic = mic_nid - 0x18;
913         capsrc_idx_fmic = fmic_nid - 0x18;
914         present = snd_hda_codec_read(codec, mic_nid, 0,
915                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
916         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
917                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
918         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
919                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
920         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
921                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
922 }
923 #else
924 #define alc_mic_automute(codec) /* NOP */
925 #endif /* disabled */
926
927 /* unsolicited event for HP jack sensing */
928 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
929 {
930         if (codec->vendor_id == 0x10ec0880)
931                 res >>= 28;
932         else
933                 res >>= 26;
934         if (res == ALC880_HP_EVENT)
935                 alc_sku_automute(codec);
936
937         if (res == ALC880_MIC_EVENT)
938                 alc_mic_automute(codec);
939 }
940
941 static void alc_inithook(struct hda_codec *codec)
942 {
943         alc_sku_automute(codec);
944         alc_mic_automute(codec);
945 }
946
947 /* additional initialization for ALC888 variants */
948 static void alc888_coef_init(struct hda_codec *codec)
949 {
950         unsigned int tmp;
951
952         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
953         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
954         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
955         if ((tmp & 0xf0) == 2)
956                 /* alc888S-VC */
957                 snd_hda_codec_read(codec, 0x20, 0,
958                                    AC_VERB_SET_PROC_COEF, 0x830);
959          else
960                  /* alc888-VB */
961                  snd_hda_codec_read(codec, 0x20, 0,
962                                     AC_VERB_SET_PROC_COEF, 0x3030);
963 }
964
965 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
966  *      31 ~ 16 :       Manufacture ID
967  *      15 ~ 8  :       SKU ID
968  *      7  ~ 0  :       Assembly ID
969  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
970  */
971 static void alc_subsystem_id(struct hda_codec *codec,
972                              unsigned int porta, unsigned int porte,
973                              unsigned int portd)
974 {
975         unsigned int ass, tmp, i;
976         unsigned nid;
977         struct alc_spec *spec = codec->spec;
978
979         ass = codec->subsystem_id & 0xffff;
980         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
981                 goto do_sku;
982
983         /*
984          * 31~30        : port conetcivity
985          * 29~21        : reserve
986          * 20           : PCBEEP input
987          * 19~16        : Check sum (15:1)
988          * 15~1         : Custom
989          * 0            : override
990         */
991         nid = 0x1d;
992         if (codec->vendor_id == 0x10ec0260)
993                 nid = 0x17;
994         ass = snd_hda_codec_read(codec, nid, 0,
995                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
996         if (!(ass & 1) && !(ass & 0x100000))
997                 return;
998         if ((ass >> 30) != 1)   /* no physical connection */
999                 return;
1000
1001         /* check sum */
1002         tmp = 0;
1003         for (i = 1; i < 16; i++) {
1004                 if ((ass >> i) & 1)
1005                         tmp++;
1006         }
1007         if (((ass >> 16) & 0xf) != tmp)
1008                 return;
1009 do_sku:
1010         /*
1011          * 0 : override
1012          * 1 :  Swap Jack
1013          * 2 : 0 --> Desktop, 1 --> Laptop
1014          * 3~5 : External Amplifier control
1015          * 7~6 : Reserved
1016         */
1017         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1018         switch (tmp) {
1019         case 1:
1020                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1021                 break;
1022         case 3:
1023                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1024                 break;
1025         case 7:
1026                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1027                 break;
1028         case 5: /* set EAPD output high */
1029                 switch (codec->vendor_id) {
1030                 case 0x10ec0260:
1031                         snd_hda_codec_write(codec, 0x0f, 0,
1032                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1033                         snd_hda_codec_write(codec, 0x10, 0,
1034                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1035                         break;
1036                 case 0x10ec0262:
1037                 case 0x10ec0267:
1038                 case 0x10ec0268:
1039                 case 0x10ec0269:
1040                 case 0x10ec0660:
1041                 case 0x10ec0662:
1042                 case 0x10ec0663:
1043                 case 0x10ec0862:
1044                 case 0x10ec0889:
1045                         snd_hda_codec_write(codec, 0x14, 0,
1046                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1047                         snd_hda_codec_write(codec, 0x15, 0,
1048                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1049                         break;
1050                 }
1051                 switch (codec->vendor_id) {
1052                 case 0x10ec0260:
1053                         snd_hda_codec_write(codec, 0x1a, 0,
1054                                             AC_VERB_SET_COEF_INDEX, 7);
1055                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1056                                                  AC_VERB_GET_PROC_COEF, 0);
1057                         snd_hda_codec_write(codec, 0x1a, 0,
1058                                             AC_VERB_SET_COEF_INDEX, 7);
1059                         snd_hda_codec_write(codec, 0x1a, 0,
1060                                             AC_VERB_SET_PROC_COEF,
1061                                             tmp | 0x2010);
1062                         break;
1063                 case 0x10ec0262:
1064                 case 0x10ec0880:
1065                 case 0x10ec0882:
1066                 case 0x10ec0883:
1067                 case 0x10ec0885:
1068                 case 0x10ec0889:
1069                         snd_hda_codec_write(codec, 0x20, 0,
1070                                             AC_VERB_SET_COEF_INDEX, 7);
1071                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1072                                                  AC_VERB_GET_PROC_COEF, 0);
1073                         snd_hda_codec_write(codec, 0x20, 0,
1074                                             AC_VERB_SET_COEF_INDEX, 7);
1075                         snd_hda_codec_write(codec, 0x20, 0,
1076                                             AC_VERB_SET_PROC_COEF,
1077                                             tmp | 0x2010);
1078                         break;
1079                 case 0x10ec0888:
1080                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1081                         break;
1082                 case 0x10ec0267:
1083                 case 0x10ec0268:
1084                         snd_hda_codec_write(codec, 0x20, 0,
1085                                             AC_VERB_SET_COEF_INDEX, 7);
1086                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1087                                                  AC_VERB_GET_PROC_COEF, 0);
1088                         snd_hda_codec_write(codec, 0x20, 0,
1089                                             AC_VERB_SET_COEF_INDEX, 7);
1090                         snd_hda_codec_write(codec, 0x20, 0,
1091                                             AC_VERB_SET_PROC_COEF,
1092                                             tmp | 0x3000);
1093                         break;
1094                 }
1095         default:
1096                 break;
1097         }
1098
1099         /* is laptop or Desktop and enable the function "Mute internal speaker
1100          * when the external headphone out jack is plugged"
1101          */
1102         if (!(ass & 0x8000))
1103                 return;
1104         /*
1105          * 10~8 : Jack location
1106          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1107          * 14~13: Resvered
1108          * 15   : 1 --> enable the function "Mute internal speaker
1109          *              when the external headphone out jack is plugged"
1110          */
1111         if (!spec->autocfg.speaker_pins[0]) {
1112                 if (spec->autocfg.line_out_pins[0])
1113                         spec->autocfg.speaker_pins[0] =
1114                                 spec->autocfg.line_out_pins[0];
1115                 else
1116                         return;
1117         }
1118
1119         if (!spec->autocfg.hp_pins[0]) {
1120                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1121                 if (tmp == 0)
1122                         spec->autocfg.hp_pins[0] = porta;
1123                 else if (tmp == 1)
1124                         spec->autocfg.hp_pins[0] = porte;
1125                 else if (tmp == 2)
1126                         spec->autocfg.hp_pins[0] = portd;
1127                 else
1128                         return;
1129         }
1130         if (spec->autocfg.hp_pins[0])
1131                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1132                         AC_VERB_SET_UNSOLICITED_ENABLE,
1133                         AC_USRSP_EN | ALC880_HP_EVENT);
1134
1135 #if 0 /* it's broken in some acses -- temporarily disabled */
1136         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1137                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1138                 snd_hda_codec_write(codec,
1139                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1140                         AC_VERB_SET_UNSOLICITED_ENABLE,
1141                         AC_USRSP_EN | ALC880_MIC_EVENT);
1142 #endif /* disabled */
1143
1144         spec->unsol_event = alc_sku_unsol_event;
1145 }
1146
1147 /*
1148  * Fix-up pin default configurations
1149  */
1150
1151 struct alc_pincfg {
1152         hda_nid_t nid;
1153         u32 val;
1154 };
1155
1156 static void alc_fix_pincfg(struct hda_codec *codec,
1157                            const struct snd_pci_quirk *quirk,
1158                            const struct alc_pincfg **pinfix)
1159 {
1160         const struct alc_pincfg *cfg;
1161
1162         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1163         if (!quirk)
1164                 return;
1165
1166         cfg = pinfix[quirk->value];
1167         for (; cfg->nid; cfg++) {
1168                 int i;
1169                 u32 val = cfg->val;
1170                 for (i = 0; i < 4; i++) {
1171                         snd_hda_codec_write(codec, cfg->nid, 0,
1172                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1173                                     val & 0xff);
1174                         val >>= 8;
1175                 }
1176         }
1177 }
1178
1179 /*
1180  * ALC888
1181  */
1182
1183 /*
1184  * 2ch mode
1185  */
1186 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1187 /* Mic-in jack as mic in */
1188         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1189         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1190 /* Line-in jack as Line in */
1191         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1192         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1193 /* Line-Out as Front */
1194         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1195         { } /* end */
1196 };
1197
1198 /*
1199  * 4ch mode
1200  */
1201 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1202 /* Mic-in jack as mic in */
1203         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1204         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1205 /* Line-in jack as Surround */
1206         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1207         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1208 /* Line-Out as Front */
1209         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1210         { } /* end */
1211 };
1212
1213 /*
1214  * 6ch mode
1215  */
1216 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1217 /* Mic-in jack as CLFE */
1218         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1219         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1220 /* Line-in jack as Surround */
1221         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1222         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1223 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1224         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1225         { } /* end */
1226 };
1227
1228 /*
1229  * 8ch mode
1230  */
1231 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1232 /* Mic-in jack as CLFE */
1233         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1234         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1235 /* Line-in jack as Surround */
1236         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1237         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1238 /* Line-Out as Side */
1239         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1240         { } /* end */
1241 };
1242
1243 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1244         { 2, alc888_4ST_ch2_intel_init },
1245         { 4, alc888_4ST_ch4_intel_init },
1246         { 6, alc888_4ST_ch6_intel_init },
1247         { 8, alc888_4ST_ch8_intel_init },
1248 };
1249
1250 /*
1251  * ALC888 Fujitsu Siemens Amillo xa3530
1252  */
1253
1254 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1255 /* Front Mic: set to PIN_IN (empty by default) */
1256         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1257 /* Connect Internal HP to Front */
1258         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1259         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1260         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1261 /* Connect Bass HP to Front */
1262         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1263         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1264         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1265 /* Connect Line-Out side jack (SPDIF) to Side */
1266         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1267         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1268         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1269 /* Connect Mic jack to CLFE */
1270         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1271         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1272         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1273 /* Connect Line-in jack to Surround */
1274         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1275         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1276         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1277 /* Connect HP out jack to Front */
1278         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1279         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1280         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1281 /* Enable unsolicited event for HP jack and Line-out jack */
1282         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1283         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1284         {}
1285 };
1286
1287 static void alc888_fujitsu_xa3530_automute(struct hda_codec *codec)
1288 {
1289         unsigned int present;
1290         unsigned int bits;
1291         /* Line out presence */
1292         present = snd_hda_codec_read(codec, 0x17, 0,
1293                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1294         /* HP out presence */
1295         present = present || snd_hda_codec_read(codec, 0x1b, 0,
1296                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1297         bits = present ? HDA_AMP_MUTE : 0;
1298         /* Toggle internal speakers muting */
1299         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1300                                  HDA_AMP_MUTE, bits);
1301         /* Toggle internal bass muting */
1302         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1303                                  HDA_AMP_MUTE, bits);
1304 }
1305
1306 static void alc888_fujitsu_xa3530_unsol_event(struct hda_codec *codec,
1307                 unsigned int res)
1308 {
1309         if (res >> 26 == ALC880_HP_EVENT)
1310                 alc888_fujitsu_xa3530_automute(codec);
1311 }
1312
1313
1314 /*
1315  * ALC888 Acer Aspire 4930G model
1316  */
1317
1318 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1319 /* Front Mic: set to PIN_IN (empty by default) */
1320         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1321 /* Unselect Front Mic by default in input mixer 3 */
1322         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1323 /* Enable unsolicited event for HP jack */
1324         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1325 /* Connect Internal HP to front */
1326         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1327         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1328         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1329 /* Connect HP out to front */
1330         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1331         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1332         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1333         { }
1334 };
1335
1336 static struct hda_input_mux alc888_2_capture_sources[2] = {
1337         /* Front mic only available on one ADC */
1338         {
1339                 .num_items = 4,
1340                 .items = {
1341                         { "Mic", 0x0 },
1342                         { "Line", 0x2 },
1343                         { "CD", 0x4 },
1344                         { "Front Mic", 0xb },
1345                 },
1346         },
1347         {
1348                 .num_items = 3,
1349                 .items = {
1350                         { "Mic", 0x0 },
1351                         { "Line", 0x2 },
1352                         { "CD", 0x4 },
1353                 },
1354         }
1355 };
1356
1357 static struct snd_kcontrol_new alc888_base_mixer[] = {
1358         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1359         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1360         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1361         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1362         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1363                 HDA_OUTPUT),
1364         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1365         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1366         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1367         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1368         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1369         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1370         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1371         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1372         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1373         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1374         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1375         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1376         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1377         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1378         { } /* end */
1379 };
1380
1381 static void alc888_acer_aspire_4930g_automute(struct hda_codec *codec)
1382 {
1383         unsigned int present;
1384         unsigned int bits;
1385         present = snd_hda_codec_read(codec, 0x15, 0,
1386                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1387         bits = present ? HDA_AMP_MUTE : 0;
1388         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1389                                  HDA_AMP_MUTE, bits);
1390 }
1391
1392 static void alc888_acer_aspire_4930g_unsol_event(struct hda_codec *codec,
1393                 unsigned int res)
1394 {
1395         if (res >> 26 == ALC880_HP_EVENT)
1396                 alc888_acer_aspire_4930g_automute(codec);
1397 }
1398
1399 /*
1400  * ALC880 3-stack model
1401  *
1402  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1403  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1404  *                 F-Mic = 0x1b, HP = 0x19
1405  */
1406
1407 static hda_nid_t alc880_dac_nids[4] = {
1408         /* front, rear, clfe, rear_surr */
1409         0x02, 0x05, 0x04, 0x03
1410 };
1411
1412 static hda_nid_t alc880_adc_nids[3] = {
1413         /* ADC0-2 */
1414         0x07, 0x08, 0x09,
1415 };
1416
1417 /* The datasheet says the node 0x07 is connected from inputs,
1418  * but it shows zero connection in the real implementation on some devices.
1419  * Note: this is a 915GAV bug, fixed on 915GLV
1420  */
1421 static hda_nid_t alc880_adc_nids_alt[2] = {
1422         /* ADC1-2 */
1423         0x08, 0x09,
1424 };
1425
1426 #define ALC880_DIGOUT_NID       0x06
1427 #define ALC880_DIGIN_NID        0x0a
1428
1429 static struct hda_input_mux alc880_capture_source = {
1430         .num_items = 4,
1431         .items = {
1432                 { "Mic", 0x0 },
1433                 { "Front Mic", 0x3 },
1434                 { "Line", 0x2 },
1435                 { "CD", 0x4 },
1436         },
1437 };
1438
1439 /* channel source setting (2/6 channel selection for 3-stack) */
1440 /* 2ch mode */
1441 static struct hda_verb alc880_threestack_ch2_init[] = {
1442         /* set line-in to input, mute it */
1443         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1444         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1445         /* set mic-in to input vref 80%, mute it */
1446         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1447         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1448         { } /* end */
1449 };
1450
1451 /* 6ch mode */
1452 static struct hda_verb alc880_threestack_ch6_init[] = {
1453         /* set line-in to output, unmute it */
1454         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1455         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1456         /* set mic-in to output, unmute it */
1457         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1458         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1459         { } /* end */
1460 };
1461
1462 static struct hda_channel_mode alc880_threestack_modes[2] = {
1463         { 2, alc880_threestack_ch2_init },
1464         { 6, alc880_threestack_ch6_init },
1465 };
1466
1467 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1468         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1469         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1470         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1471         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1472         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1473         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1474         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1475         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1476         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1477         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1478         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1479         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1480         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1481         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1482         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1483         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1484         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1485         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1486         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1487         {
1488                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1489                 .name = "Channel Mode",
1490                 .info = alc_ch_mode_info,
1491                 .get = alc_ch_mode_get,
1492                 .put = alc_ch_mode_put,
1493         },
1494         { } /* end */
1495 };
1496
1497 /* capture mixer elements */
1498 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1499                             struct snd_ctl_elem_info *uinfo)
1500 {
1501         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1502         struct alc_spec *spec = codec->spec;
1503         int err;
1504
1505         mutex_lock(&codec->control_mutex);
1506         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1507                                                       HDA_INPUT);
1508         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1509         mutex_unlock(&codec->control_mutex);
1510         return err;
1511 }
1512
1513 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1514                            unsigned int size, unsigned int __user *tlv)
1515 {
1516         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1517         struct alc_spec *spec = codec->spec;
1518         int err;
1519
1520         mutex_lock(&codec->control_mutex);
1521         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1522                                                       HDA_INPUT);
1523         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1524         mutex_unlock(&codec->control_mutex);
1525         return err;
1526 }
1527
1528 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1529                              struct snd_ctl_elem_value *ucontrol);
1530
1531 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1532                                  struct snd_ctl_elem_value *ucontrol,
1533                                  getput_call_t func)
1534 {
1535         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1536         struct alc_spec *spec = codec->spec;
1537         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1538         int err;
1539
1540         mutex_lock(&codec->control_mutex);
1541         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1542                                                       3, 0, HDA_INPUT);
1543         err = func(kcontrol, ucontrol);
1544         mutex_unlock(&codec->control_mutex);
1545         return err;
1546 }
1547
1548 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1549                            struct snd_ctl_elem_value *ucontrol)
1550 {
1551         return alc_cap_getput_caller(kcontrol, ucontrol,
1552                                      snd_hda_mixer_amp_volume_get);
1553 }
1554
1555 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1556                            struct snd_ctl_elem_value *ucontrol)
1557 {
1558         return alc_cap_getput_caller(kcontrol, ucontrol,
1559                                      snd_hda_mixer_amp_volume_put);
1560 }
1561
1562 /* capture mixer elements */
1563 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1564
1565 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1566                           struct snd_ctl_elem_value *ucontrol)
1567 {
1568         return alc_cap_getput_caller(kcontrol, ucontrol,
1569                                      snd_hda_mixer_amp_switch_get);
1570 }
1571
1572 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1573                           struct snd_ctl_elem_value *ucontrol)
1574 {
1575         return alc_cap_getput_caller(kcontrol, ucontrol,
1576                                      snd_hda_mixer_amp_switch_put);
1577 }
1578
1579 #define DEFINE_CAPMIX(num) \
1580 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1581         { \
1582                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1583                 .name = "Capture Switch", \
1584                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1585                 .count = num, \
1586                 .info = alc_cap_sw_info, \
1587                 .get = alc_cap_sw_get, \
1588                 .put = alc_cap_sw_put, \
1589         }, \
1590         { \
1591                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1592                 .name = "Capture Volume", \
1593                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1594                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1595                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1596                 .count = num, \
1597                 .info = alc_cap_vol_info, \
1598                 .get = alc_cap_vol_get, \
1599                 .put = alc_cap_vol_put, \
1600                 .tlv = { .c = alc_cap_vol_tlv }, \
1601         }, \
1602         { \
1603                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1604                 /* .name = "Capture Source", */ \
1605                 .name = "Input Source", \
1606                 .count = num, \
1607                 .info = alc_mux_enum_info, \
1608                 .get = alc_mux_enum_get, \
1609                 .put = alc_mux_enum_put, \
1610         }, \
1611         { } /* end */ \
1612 }
1613
1614 /* up to three ADCs */
1615 DEFINE_CAPMIX(1);
1616 DEFINE_CAPMIX(2);
1617 DEFINE_CAPMIX(3);
1618
1619
1620 /*
1621  * ALC880 5-stack model
1622  *
1623  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1624  *      Side = 0x02 (0xd)
1625  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1626  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1627  */
1628
1629 /* additional mixers to alc880_three_stack_mixer */
1630 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1631         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1632         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1633         { } /* end */
1634 };
1635
1636 /* channel source setting (6/8 channel selection for 5-stack) */
1637 /* 6ch mode */
1638 static struct hda_verb alc880_fivestack_ch6_init[] = {
1639         /* set line-in to input, mute it */
1640         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1641         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1642         { } /* end */
1643 };
1644
1645 /* 8ch mode */
1646 static struct hda_verb alc880_fivestack_ch8_init[] = {
1647         /* set line-in to output, unmute it */
1648         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1649         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1650         { } /* end */
1651 };
1652
1653 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1654         { 6, alc880_fivestack_ch6_init },
1655         { 8, alc880_fivestack_ch8_init },
1656 };
1657
1658
1659 /*
1660  * ALC880 6-stack model
1661  *
1662  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1663  *      Side = 0x05 (0x0f)
1664  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1665  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1666  */
1667
1668 static hda_nid_t alc880_6st_dac_nids[4] = {
1669         /* front, rear, clfe, rear_surr */
1670         0x02, 0x03, 0x04, 0x05
1671 };
1672
1673 static struct hda_input_mux alc880_6stack_capture_source = {
1674         .num_items = 4,
1675         .items = {
1676                 { "Mic", 0x0 },
1677                 { "Front Mic", 0x1 },
1678                 { "Line", 0x2 },
1679                 { "CD", 0x4 },
1680         },
1681 };
1682
1683 /* fixed 8-channels */
1684 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1685         { 8, NULL },
1686 };
1687
1688 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1689         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1690         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1691         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1692         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1693         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1694         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1695         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1696         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1697         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1698         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1699         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1700         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1701         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1702         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1703         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1704         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1705         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1706         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1707         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1708         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1709         {
1710                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1711                 .name = "Channel Mode",
1712                 .info = alc_ch_mode_info,
1713                 .get = alc_ch_mode_get,
1714                 .put = alc_ch_mode_put,
1715         },
1716         { } /* end */
1717 };
1718
1719
1720 /*
1721  * ALC880 W810 model
1722  *
1723  * W810 has rear IO for:
1724  * Front (DAC 02)
1725  * Surround (DAC 03)
1726  * Center/LFE (DAC 04)
1727  * Digital out (06)
1728  *
1729  * The system also has a pair of internal speakers, and a headphone jack.
1730  * These are both connected to Line2 on the codec, hence to DAC 02.
1731  *
1732  * There is a variable resistor to control the speaker or headphone
1733  * volume. This is a hardware-only device without a software API.
1734  *
1735  * Plugging headphones in will disable the internal speakers. This is
1736  * implemented in hardware, not via the driver using jack sense. In
1737  * a similar fashion, plugging into the rear socket marked "front" will
1738  * disable both the speakers and headphones.
1739  *
1740  * For input, there's a microphone jack, and an "audio in" jack.
1741  * These may not do anything useful with this driver yet, because I
1742  * haven't setup any initialization verbs for these yet...
1743  */
1744
1745 static hda_nid_t alc880_w810_dac_nids[3] = {
1746         /* front, rear/surround, clfe */
1747         0x02, 0x03, 0x04
1748 };
1749
1750 /* fixed 6 channels */
1751 static struct hda_channel_mode alc880_w810_modes[1] = {
1752         { 6, NULL }
1753 };
1754
1755 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1756 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1757         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1758         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1759         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1760         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1761         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1762         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1763         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1764         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1765         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1766         { } /* end */
1767 };
1768
1769
1770 /*
1771  * Z710V model
1772  *
1773  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1774  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1775  *                 Line = 0x1a
1776  */
1777
1778 static hda_nid_t alc880_z71v_dac_nids[1] = {
1779         0x02
1780 };
1781 #define ALC880_Z71V_HP_DAC      0x03
1782
1783 /* fixed 2 channels */
1784 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1785         { 2, NULL }
1786 };
1787
1788 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1789         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1790         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1791         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1792         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1793         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1794         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1795         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1796         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1797         { } /* end */
1798 };
1799
1800
1801 /*
1802  * ALC880 F1734 model
1803  *
1804  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1805  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1806  */
1807
1808 static hda_nid_t alc880_f1734_dac_nids[1] = {
1809         0x03
1810 };
1811 #define ALC880_F1734_HP_DAC     0x02
1812
1813 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1814         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1815         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1816         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1817         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1818         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1819         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1820         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1821         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1822         { } /* end */
1823 };
1824
1825 static struct hda_input_mux alc880_f1734_capture_source = {
1826         .num_items = 2,
1827         .items = {
1828                 { "Mic", 0x1 },
1829                 { "CD", 0x4 },
1830         },
1831 };
1832
1833
1834 /*
1835  * ALC880 ASUS model
1836  *
1837  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1838  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1839  *  Mic = 0x18, Line = 0x1a
1840  */
1841
1842 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1843 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1844
1845 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1846         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1847         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1848         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1849         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1850         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1851         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1852         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1853         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1854         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1855         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1856         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1857         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1858         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1859         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1860         {
1861                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1862                 .name = "Channel Mode",
1863                 .info = alc_ch_mode_info,
1864                 .get = alc_ch_mode_get,
1865                 .put = alc_ch_mode_put,
1866         },
1867         { } /* end */
1868 };
1869
1870 /*
1871  * ALC880 ASUS W1V model
1872  *
1873  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1874  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1875  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1876  */
1877
1878 /* additional mixers to alc880_asus_mixer */
1879 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1880         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1881         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1882         { } /* end */
1883 };
1884
1885 /* additional mixers to alc880_asus_mixer */
1886 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1887         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1888         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1889         { } /* end */
1890 };
1891
1892 /* TCL S700 */
1893 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1894         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1895         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1896         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1897         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1898         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, 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("Capture Volume", 0x08, 0x0, HDA_INPUT),
1902         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1903         { } /* end */
1904 };
1905
1906 /* Uniwill */
1907 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1908         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1909         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1910         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1911         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1912         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1913         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1914         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1915         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1916         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1917         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1918         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1919         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1920         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1921         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1922         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1923         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1924         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1925         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1926         {
1927                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1928                 .name = "Channel Mode",
1929                 .info = alc_ch_mode_info,
1930                 .get = alc_ch_mode_get,
1931                 .put = alc_ch_mode_put,
1932         },
1933         { } /* end */
1934 };
1935
1936 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1937         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1938         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1939         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1940         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1941         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1942         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1943         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1944         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1945         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1946         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1947         { } /* end */
1948 };
1949
1950 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1951         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1952         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1953         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1954         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1955         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1956         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1957         { } /* end */
1958 };
1959
1960 /*
1961  * virtual master controls
1962  */
1963
1964 /*
1965  * slave controls for virtual master
1966  */
1967 static const char *alc_slave_vols[] = {
1968         "Front Playback Volume",
1969         "Surround Playback Volume",
1970         "Center Playback Volume",
1971         "LFE Playback Volume",
1972         "Side Playback Volume",
1973         "Headphone Playback Volume",
1974         "Speaker Playback Volume",
1975         "Mono Playback Volume",
1976         "Line-Out Playback Volume",
1977         "PCM Playback Volume",
1978         NULL,
1979 };
1980
1981 static const char *alc_slave_sws[] = {
1982         "Front Playback Switch",
1983         "Surround Playback Switch",
1984         "Center Playback Switch",
1985         "LFE Playback Switch",
1986         "Side Playback Switch",
1987         "Headphone Playback Switch",
1988         "Speaker Playback Switch",
1989         "Mono Playback Switch",
1990         "IEC958 Playback Switch",
1991         NULL,
1992 };
1993
1994 /*
1995  * build control elements
1996  */
1997
1998 static void alc_free_kctls(struct hda_codec *codec);
1999
2000 static int alc_build_controls(struct hda_codec *codec)
2001 {
2002         struct alc_spec *spec = codec->spec;
2003         int err;
2004         int i;
2005
2006         for (i = 0; i < spec->num_mixers; i++) {
2007                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2008                 if (err < 0)
2009                         return err;
2010         }
2011         if (spec->cap_mixer) {
2012                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2013                 if (err < 0)
2014                         return err;
2015         }
2016         if (spec->multiout.dig_out_nid) {
2017                 err = snd_hda_create_spdif_out_ctls(codec,
2018                                                     spec->multiout.dig_out_nid);
2019                 if (err < 0)
2020                         return err;
2021                 err = snd_hda_create_spdif_share_sw(codec,
2022                                                     &spec->multiout);
2023                 if (err < 0)
2024                         return err;
2025                 spec->multiout.share_spdif = 1;
2026         }
2027         if (spec->dig_in_nid) {
2028                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2029                 if (err < 0)
2030                         return err;
2031         }
2032
2033         /* if we have no master control, let's create it */
2034         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2035                 unsigned int vmaster_tlv[4];
2036                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2037                                         HDA_OUTPUT, vmaster_tlv);
2038                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2039                                           vmaster_tlv, alc_slave_vols);
2040                 if (err < 0)
2041                         return err;
2042         }
2043         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2044                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2045                                           NULL, alc_slave_sws);
2046                 if (err < 0)
2047                         return err;
2048         }
2049
2050         alc_free_kctls(codec); /* no longer needed */
2051         return 0;
2052 }
2053
2054
2055 /*
2056  * initialize the codec volumes, etc
2057  */
2058
2059 /*
2060  * generic initialization of ADC, input mixers and output mixers
2061  */
2062 static struct hda_verb alc880_volume_init_verbs[] = {
2063         /*
2064          * Unmute ADC0-2 and set the default input to mic-in
2065          */
2066         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2067         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2068         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2069         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2070         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2071         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2072
2073         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2074          * mixer widget
2075          * Note: PASD motherboards uses the Line In 2 as the input for front
2076          * panel mic (mic 2)
2077          */
2078         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2079         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2080         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2081         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2082         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2083         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2084         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2085         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2086
2087         /*
2088          * Set up output mixers (0x0c - 0x0f)
2089          */
2090         /* set vol=0 to output mixers */
2091         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2092         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2093         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2094         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2095         /* set up input amps for analog loopback */
2096         /* Amp Indices: DAC = 0, mixer = 1 */
2097         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2098         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2099         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2100         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2101         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2102         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2103         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2104         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2105
2106         { }
2107 };
2108
2109 /*
2110  * 3-stack pin configuration:
2111  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2112  */
2113 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2114         /*
2115          * preset connection lists of input pins
2116          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2117          */
2118         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2119         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2120         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2121
2122         /*
2123          * Set pin mode and muting
2124          */
2125         /* set front pin widgets 0x14 for output */
2126         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2127         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2128         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2129         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2130         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2131         /* Mic2 (as headphone out) for HP output */
2132         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2133         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2134         /* Line In pin widget for input */
2135         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2136         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2137         /* Line2 (as front mic) pin widget for input and vref at 80% */
2138         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2139         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2140         /* CD pin widget for input */
2141         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2142
2143         { }
2144 };
2145
2146 /*
2147  * 5-stack pin configuration:
2148  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2149  * line-in/side = 0x1a, f-mic = 0x1b
2150  */
2151 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2152         /*
2153          * preset connection lists of input pins
2154          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2155          */
2156         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2157         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2158
2159         /*
2160          * Set pin mode and muting
2161          */
2162         /* set pin widgets 0x14-0x17 for output */
2163         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2164         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2165         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2166         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2167         /* unmute pins for output (no gain on this amp) */
2168         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2169         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2170         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2171         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2172
2173         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2174         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2175         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2176         /* Mic2 (as headphone out) for HP output */
2177         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2178         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2179         /* Line In pin widget for input */
2180         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2181         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2182         /* Line2 (as front mic) pin widget for input and vref at 80% */
2183         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2184         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2185         /* CD pin widget for input */
2186         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2187
2188         { }
2189 };
2190
2191 /*
2192  * W810 pin configuration:
2193  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2194  */
2195 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2196         /* hphone/speaker input selector: front DAC */
2197         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2198
2199         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2200         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2201         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2202         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2203         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2204         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2205
2206         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2207         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2208
2209         { }
2210 };
2211
2212 /*
2213  * Z71V pin configuration:
2214  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2215  */
2216 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
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_HP},
2220         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2221
2222         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2223         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2224         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2225         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2226
2227         { }
2228 };
2229
2230 /*
2231  * 6-stack pin configuration:
2232  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2233  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2234  */
2235 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2236         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2237
2238         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2239         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2240         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2241         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2242         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2243         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2244         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2245         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2246
2247         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2248         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2249         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2250         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2251         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2252         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2253         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2254         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2255         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2256
2257         { }
2258 };
2259
2260 /*
2261  * Uniwill pin configuration:
2262  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2263  * line = 0x1a
2264  */
2265 static struct hda_verb alc880_uniwill_init_verbs[] = {
2266         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2267
2268         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2269         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2270         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2271         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2272         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2273         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2274         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2275         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2276         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2277         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2278         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2279         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2280         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2281         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2282
2283         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2284         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2285         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2286         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2287         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2288         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2289         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2290         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2291         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2292
2293         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2294         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2295
2296         { }
2297 };
2298
2299 /*
2300 * Uniwill P53
2301 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2302  */
2303 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2304         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2305
2306         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2307         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2308         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2309         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2310         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2311         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2312         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2313         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2314         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2315         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2316         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2317         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2318
2319         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2320         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2321         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2322         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2323         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2324         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2325
2326         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2327         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2328
2329         { }
2330 };
2331
2332 static struct hda_verb alc880_beep_init_verbs[] = {
2333         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2334         { }
2335 };
2336
2337 /* toggle speaker-output according to the hp-jack state */
2338 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
2339 {
2340         unsigned int present;
2341         unsigned char bits;
2342
2343         present = snd_hda_codec_read(codec, 0x14, 0,
2344                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2345         bits = present ? HDA_AMP_MUTE : 0;
2346         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
2347                                  HDA_AMP_MUTE, bits);
2348         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
2349                                  HDA_AMP_MUTE, bits);
2350 }
2351
2352 /* auto-toggle front mic */
2353 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2354 {
2355         unsigned int present;
2356         unsigned char bits;
2357
2358         present = snd_hda_codec_read(codec, 0x18, 0,
2359                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2360         bits = present ? HDA_AMP_MUTE : 0;
2361         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2362 }
2363
2364 static void alc880_uniwill_automute(struct hda_codec *codec)
2365 {
2366         alc880_uniwill_hp_automute(codec);
2367         alc880_uniwill_mic_automute(codec);
2368 }
2369
2370 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2371                                        unsigned int res)
2372 {
2373         /* Looks like the unsol event is incompatible with the standard
2374          * definition.  4bit tag is placed at 28 bit!
2375          */
2376         switch (res >> 28) {
2377         case ALC880_HP_EVENT:
2378                 alc880_uniwill_hp_automute(codec);
2379                 break;
2380         case ALC880_MIC_EVENT:
2381                 alc880_uniwill_mic_automute(codec);
2382                 break;
2383         }
2384 }
2385
2386 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2387 {
2388         unsigned int present;
2389         unsigned char bits;
2390
2391         present = snd_hda_codec_read(codec, 0x14, 0,
2392                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2393         bits = present ? HDA_AMP_MUTE : 0;
2394         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2395 }
2396
2397 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2398 {
2399         unsigned int present;
2400
2401         present = snd_hda_codec_read(codec, 0x21, 0,
2402                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2403         present &= HDA_AMP_VOLMASK;
2404         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2405                                  HDA_AMP_VOLMASK, present);
2406         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2407                                  HDA_AMP_VOLMASK, present);
2408 }
2409
2410 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2411                                            unsigned int res)
2412 {
2413         /* Looks like the unsol event is incompatible with the standard
2414          * definition.  4bit tag is placed at 28 bit!
2415          */
2416         if ((res >> 28) == ALC880_HP_EVENT)
2417                 alc880_uniwill_p53_hp_automute(codec);
2418         if ((res >> 28) == ALC880_DCVOL_EVENT)
2419                 alc880_uniwill_p53_dcvol_automute(codec);
2420 }
2421
2422 /*
2423  * F1734 pin configuration:
2424  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2425  */
2426 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2427         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2428         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2429         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2430         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2431         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2432
2433         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2434         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2435         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2436         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2437
2438         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2439         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2440         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2441         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2442         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2443         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2444         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2445         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2446         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2447
2448         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2449         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2450
2451         { }
2452 };
2453
2454 /*
2455  * ASUS pin configuration:
2456  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2457  */
2458 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2459         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2460         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2461         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2462         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2463
2464         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2465         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2466         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2467         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2468         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2469         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2470         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2471         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2472
2473         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2474         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2475         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2476         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2477         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2478         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2479         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2480         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2481         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2482
2483         { }
2484 };
2485
2486 /* Enable GPIO mask and set output */
2487 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2488 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2489
2490 /* Clevo m520g init */
2491 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2492         /* headphone output */
2493         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2494         /* line-out */
2495         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2496         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2497         /* Line-in */
2498         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2499         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2500         /* CD */
2501         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2502         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2503         /* Mic1 (rear panel) */
2504         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2505         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2506         /* Mic2 (front panel) */
2507         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2508         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2509         /* headphone */
2510         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2511         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2512         /* change to EAPD mode */
2513         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2514         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2515
2516         { }
2517 };
2518
2519 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2520         /* change to EAPD mode */
2521         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2522         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2523
2524         /* Headphone output */
2525         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2526         /* Front output*/
2527         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2528         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2529
2530         /* Line In pin widget for input */
2531         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2532         /* CD pin widget for input */
2533         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2534         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2535         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2536
2537         /* change to EAPD mode */
2538         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2539         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2540
2541         { }
2542 };
2543
2544 /*
2545  * LG m1 express dual
2546  *
2547  * Pin assignment:
2548  *   Rear Line-In/Out (blue): 0x14
2549  *   Build-in Mic-In: 0x15
2550  *   Speaker-out: 0x17
2551  *   HP-Out (green): 0x1b
2552  *   Mic-In/Out (red): 0x19
2553  *   SPDIF-Out: 0x1e
2554  */
2555
2556 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2557 static hda_nid_t alc880_lg_dac_nids[3] = {
2558         0x05, 0x02, 0x03
2559 };
2560
2561 /* seems analog CD is not working */
2562 static struct hda_input_mux alc880_lg_capture_source = {
2563         .num_items = 3,
2564         .items = {
2565                 { "Mic", 0x1 },
2566                 { "Line", 0x5 },
2567                 { "Internal Mic", 0x6 },
2568         },
2569 };
2570
2571 /* 2,4,6 channel modes */
2572 static struct hda_verb alc880_lg_ch2_init[] = {
2573         /* set line-in and mic-in to input */
2574         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2575         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2576         { }
2577 };
2578
2579 static struct hda_verb alc880_lg_ch4_init[] = {
2580         /* set line-in to out and mic-in to input */
2581         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2582         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2583         { }
2584 };
2585
2586 static struct hda_verb alc880_lg_ch6_init[] = {
2587         /* set line-in and mic-in to output */
2588         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2589         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2590         { }
2591 };
2592
2593 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2594         { 2, alc880_lg_ch2_init },
2595         { 4, alc880_lg_ch4_init },
2596         { 6, alc880_lg_ch6_init },
2597 };
2598
2599 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2600         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2601         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2602         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2603         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2604         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2605         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2606         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2607         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2608         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2609         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2610         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2611         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2612         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2613         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2614         {
2615                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2616                 .name = "Channel Mode",
2617                 .info = alc_ch_mode_info,
2618                 .get = alc_ch_mode_get,
2619                 .put = alc_ch_mode_put,
2620         },
2621         { } /* end */
2622 };
2623
2624 static struct hda_verb alc880_lg_init_verbs[] = {
2625         /* set capture source to mic-in */
2626         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2627         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2628         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2629         /* mute all amp mixer inputs */
2630         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2631         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2632         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2633         /* line-in to input */
2634         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2635         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2636         /* built-in mic */
2637         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2638         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2639         /* speaker-out */
2640         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2641         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2642         /* mic-in to input */
2643         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2644         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2645         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2646         /* HP-out */
2647         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2648         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2649         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2650         /* jack sense */
2651         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2652         { }
2653 };
2654
2655 /* toggle speaker-output according to the hp-jack state */
2656 static void alc880_lg_automute(struct hda_codec *codec)
2657 {
2658         unsigned int present;
2659         unsigned char bits;
2660
2661         present = snd_hda_codec_read(codec, 0x1b, 0,
2662                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2663         bits = present ? HDA_AMP_MUTE : 0;
2664         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2665                                  HDA_AMP_MUTE, bits);
2666 }
2667
2668 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2669 {
2670         /* Looks like the unsol event is incompatible with the standard
2671          * definition.  4bit tag is placed at 28 bit!
2672          */
2673         if ((res >> 28) == 0x01)
2674                 alc880_lg_automute(codec);
2675 }
2676
2677 /*
2678  * LG LW20
2679  *
2680  * Pin assignment:
2681  *   Speaker-out: 0x14
2682  *   Mic-In: 0x18
2683  *   Built-in Mic-In: 0x19
2684  *   Line-In: 0x1b
2685  *   HP-Out: 0x1a
2686  *   SPDIF-Out: 0x1e
2687  */
2688
2689 static struct hda_input_mux alc880_lg_lw_capture_source = {
2690         .num_items = 3,
2691         .items = {
2692                 { "Mic", 0x0 },
2693                 { "Internal Mic", 0x1 },
2694                 { "Line In", 0x2 },
2695         },
2696 };
2697
2698 #define alc880_lg_lw_modes alc880_threestack_modes
2699
2700 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2701         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2702         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2703         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2704         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2705         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2706         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2707         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2708         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2709         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2710         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2711         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2712         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2713         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2714         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2715         {
2716                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2717                 .name = "Channel Mode",
2718                 .info = alc_ch_mode_info,
2719                 .get = alc_ch_mode_get,
2720                 .put = alc_ch_mode_put,
2721         },
2722         { } /* end */
2723 };
2724
2725 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2726         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2727         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2728         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2729
2730         /* set capture source to mic-in */
2731         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2732         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2733         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2734         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2735         /* speaker-out */
2736         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2737         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2738         /* HP-out */
2739         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2740         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2741         /* mic-in to input */
2742         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2743         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2744         /* built-in mic */
2745         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2746         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2747         /* jack sense */
2748         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2749         { }
2750 };
2751
2752 /* toggle speaker-output according to the hp-jack state */
2753 static void alc880_lg_lw_automute(struct hda_codec *codec)
2754 {
2755         unsigned int present;
2756         unsigned char bits;
2757
2758         present = snd_hda_codec_read(codec, 0x1b, 0,
2759                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2760         bits = present ? HDA_AMP_MUTE : 0;
2761         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2762                                  HDA_AMP_MUTE, bits);
2763 }
2764
2765 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2766 {
2767         /* Looks like the unsol event is incompatible with the standard
2768          * definition.  4bit tag is placed at 28 bit!
2769          */
2770         if ((res >> 28) == 0x01)
2771                 alc880_lg_lw_automute(codec);
2772 }
2773
2774 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2775         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2776         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2777         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2778         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2779         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2780         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2781         { } /* end */
2782 };
2783
2784 static struct hda_input_mux alc880_medion_rim_capture_source = {
2785         .num_items = 2,
2786         .items = {
2787                 { "Mic", 0x0 },
2788                 { "Internal Mic", 0x1 },
2789         },
2790 };
2791
2792 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2793         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2794
2795         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2796         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2797
2798         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2799         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2800         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2801         /* Mic2 (as headphone out) for HP output */
2802         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2803         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2804         /* Internal Speaker */
2805         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2806         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2807
2808         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2809         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2810
2811         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2812         { }
2813 };
2814
2815 /* toggle speaker-output according to the hp-jack state */
2816 static void alc880_medion_rim_automute(struct hda_codec *codec)
2817 {
2818         unsigned int present;
2819         unsigned char bits;
2820
2821         present = snd_hda_codec_read(codec, 0x14, 0,
2822                                      AC_VERB_GET_PIN_SENSE, 0)
2823                 & AC_PINSENSE_PRESENCE;
2824         bits = present ? HDA_AMP_MUTE : 0;
2825         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2826                                  HDA_AMP_MUTE, bits);
2827         if (present)
2828                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2829         else
2830                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2831 }
2832
2833 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2834                                           unsigned int res)
2835 {
2836         /* Looks like the unsol event is incompatible with the standard
2837          * definition.  4bit tag is placed at 28 bit!
2838          */
2839         if ((res >> 28) == ALC880_HP_EVENT)
2840                 alc880_medion_rim_automute(codec);
2841 }
2842
2843 #ifdef CONFIG_SND_HDA_POWER_SAVE
2844 static struct hda_amp_list alc880_loopbacks[] = {
2845         { 0x0b, HDA_INPUT, 0 },
2846         { 0x0b, HDA_INPUT, 1 },
2847         { 0x0b, HDA_INPUT, 2 },
2848         { 0x0b, HDA_INPUT, 3 },
2849         { 0x0b, HDA_INPUT, 4 },
2850         { } /* end */
2851 };
2852
2853 static struct hda_amp_list alc880_lg_loopbacks[] = {
2854         { 0x0b, HDA_INPUT, 1 },
2855         { 0x0b, HDA_INPUT, 6 },
2856         { 0x0b, HDA_INPUT, 7 },
2857         { } /* end */
2858 };
2859 #endif
2860
2861 /*
2862  * Common callbacks
2863  */
2864
2865 static int alc_init(struct hda_codec *codec)
2866 {
2867         struct alc_spec *spec = codec->spec;
2868         unsigned int i;
2869
2870         alc_fix_pll(codec);
2871         if (codec->vendor_id == 0x10ec0888)
2872                 alc888_coef_init(codec);
2873
2874         for (i = 0; i < spec->num_init_verbs; i++)
2875                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2876
2877         if (spec->init_hook)
2878                 spec->init_hook(codec);
2879
2880         return 0;
2881 }
2882
2883 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2884 {
2885         struct alc_spec *spec = codec->spec;
2886
2887         if (spec->unsol_event)
2888                 spec->unsol_event(codec, res);
2889 }
2890
2891 #ifdef CONFIG_SND_HDA_POWER_SAVE
2892 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2893 {
2894         struct alc_spec *spec = codec->spec;
2895         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2896 }
2897 #endif
2898
2899 /*
2900  * Analog playback callbacks
2901  */
2902 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2903                                     struct hda_codec *codec,
2904                                     struct snd_pcm_substream *substream)
2905 {
2906         struct alc_spec *spec = codec->spec;
2907         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2908                                              hinfo);
2909 }
2910
2911 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2912                                        struct hda_codec *codec,
2913                                        unsigned int stream_tag,
2914                                        unsigned int format,
2915                                        struct snd_pcm_substream *substream)
2916 {
2917         struct alc_spec *spec = codec->spec;
2918         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2919                                                 stream_tag, format, substream);
2920 }
2921
2922 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2923                                        struct hda_codec *codec,
2924                                        struct snd_pcm_substream *substream)
2925 {
2926         struct alc_spec *spec = codec->spec;
2927         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2928 }
2929
2930 /*
2931  * Digital out
2932  */
2933 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2934                                         struct hda_codec *codec,
2935                                         struct snd_pcm_substream *substream)
2936 {
2937         struct alc_spec *spec = codec->spec;
2938         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2939 }
2940
2941 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2942                                            struct hda_codec *codec,
2943                                            unsigned int stream_tag,
2944                                            unsigned int format,
2945                                            struct snd_pcm_substream *substream)
2946 {
2947         struct alc_spec *spec = codec->spec;
2948         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2949                                              stream_tag, format, substream);
2950 }
2951
2952 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2953                                          struct hda_codec *codec,
2954                                          struct snd_pcm_substream *substream)
2955 {
2956         struct alc_spec *spec = codec->spec;
2957         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2958 }
2959
2960 /*
2961  * Analog capture
2962  */
2963 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2964                                       struct hda_codec *codec,
2965                                       unsigned int stream_tag,
2966                                       unsigned int format,
2967                                       struct snd_pcm_substream *substream)
2968 {
2969         struct alc_spec *spec = codec->spec;
2970
2971         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2972                                    stream_tag, 0, format);
2973         return 0;
2974 }
2975
2976 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2977                                       struct hda_codec *codec,
2978                                       struct snd_pcm_substream *substream)
2979 {
2980         struct alc_spec *spec = codec->spec;
2981
2982         snd_hda_codec_cleanup_stream(codec,
2983                                      spec->adc_nids[substream->number + 1]);
2984         return 0;
2985 }
2986
2987
2988 /*
2989  */
2990 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2991         .substreams = 1,
2992         .channels_min = 2,
2993         .channels_max = 8,
2994         /* NID is set in alc_build_pcms */
2995         .ops = {
2996                 .open = alc880_playback_pcm_open,
2997                 .prepare = alc880_playback_pcm_prepare,
2998                 .cleanup = alc880_playback_pcm_cleanup
2999         },
3000 };
3001
3002 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3003         .substreams = 1,
3004         .channels_min = 2,
3005         .channels_max = 2,
3006         /* NID is set in alc_build_pcms */
3007 };
3008
3009 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3010         .substreams = 1,
3011         .channels_min = 2,
3012         .channels_max = 2,
3013         /* NID is set in alc_build_pcms */
3014 };
3015
3016 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3017         .substreams = 2, /* can be overridden */
3018         .channels_min = 2,
3019         .channels_max = 2,
3020         /* NID is set in alc_build_pcms */
3021         .ops = {
3022                 .prepare = alc880_alt_capture_pcm_prepare,
3023                 .cleanup = alc880_alt_capture_pcm_cleanup
3024         },
3025 };
3026
3027 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3028         .substreams = 1,
3029         .channels_min = 2,
3030         .channels_max = 2,
3031         /* NID is set in alc_build_pcms */
3032         .ops = {
3033                 .open = alc880_dig_playback_pcm_open,
3034                 .close = alc880_dig_playback_pcm_close,
3035                 .prepare = alc880_dig_playback_pcm_prepare
3036         },
3037 };
3038
3039 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3040         .substreams = 1,
3041         .channels_min = 2,
3042         .channels_max = 2,
3043         /* NID is set in alc_build_pcms */
3044 };
3045
3046 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3047 static struct hda_pcm_stream alc_pcm_null_stream = {
3048         .substreams = 0,
3049         .channels_min = 0,
3050         .channels_max = 0,
3051 };
3052
3053 static int alc_build_pcms(struct hda_codec *codec)
3054 {
3055         struct alc_spec *spec = codec->spec;
3056         struct hda_pcm *info = spec->pcm_rec;
3057         int i;
3058
3059         codec->num_pcms = 1;
3060         codec->pcm_info = info;
3061
3062         info->name = spec->stream_name_analog;
3063         if (spec->stream_analog_playback) {
3064                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3065                         return -EINVAL;
3066                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3067                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3068         }
3069         if (spec->stream_analog_capture) {
3070                 if (snd_BUG_ON(!spec->adc_nids))
3071                         return -EINVAL;
3072                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3073                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3074         }
3075
3076         if (spec->channel_mode) {
3077                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3078                 for (i = 0; i < spec->num_channel_mode; i++) {
3079                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3080                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3081                         }
3082                 }
3083         }
3084
3085         /* SPDIF for stream index #1 */
3086         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3087                 codec->num_pcms = 2;
3088                 info = spec->pcm_rec + 1;
3089                 info->name = spec->stream_name_digital;
3090                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
3091                 if (spec->multiout.dig_out_nid &&
3092                     spec->stream_digital_playback) {
3093                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3094                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3095                 }
3096                 if (spec->dig_in_nid &&
3097                     spec->stream_digital_capture) {
3098                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3099                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3100                 }
3101                 /* FIXME: do we need this for all Realtek codec models? */
3102                 codec->spdif_status_reset = 1;
3103         }
3104
3105         /* If the use of more than one ADC is requested for the current
3106          * model, configure a second analog capture-only PCM.
3107          */
3108         /* Additional Analaog capture for index #2 */
3109         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3110             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3111                 codec->num_pcms = 3;
3112                 info = spec->pcm_rec + 2;
3113                 info->name = spec->stream_name_analog;
3114                 if (spec->alt_dac_nid) {
3115                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3116                                 *spec->stream_analog_alt_playback;
3117                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3118                                 spec->alt_dac_nid;
3119                 } else {
3120                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3121                                 alc_pcm_null_stream;
3122                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3123                 }
3124                 if (spec->num_adc_nids > 1) {
3125                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3126                                 *spec->stream_analog_alt_capture;
3127                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3128                                 spec->adc_nids[1];
3129                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3130                                 spec->num_adc_nids - 1;
3131                 } else {
3132                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3133                                 alc_pcm_null_stream;
3134                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3135                 }
3136         }
3137
3138         return 0;
3139 }
3140
3141 static void alc_free_kctls(struct hda_codec *codec)
3142 {
3143         struct alc_spec *spec = codec->spec;
3144
3145         if (spec->kctls.list) {
3146                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3147                 int i;
3148                 for (i = 0; i < spec->kctls.used; i++)
3149                         kfree(kctl[i].name);
3150         }
3151         snd_array_free(&spec->kctls);
3152 }
3153
3154 static void alc_free(struct hda_codec *codec)
3155 {
3156         struct alc_spec *spec = codec->spec;
3157
3158         if (!spec)
3159                 return;
3160
3161         alc_free_kctls(codec);
3162         kfree(spec);
3163         codec->spec = NULL; /* to be sure */
3164 }
3165
3166 #ifdef SND_HDA_NEEDS_RESUME
3167 static void store_pin_configs(struct hda_codec *codec)
3168 {
3169         struct alc_spec *spec = codec->spec;
3170         hda_nid_t nid, end_nid;
3171
3172         end_nid = codec->start_nid + codec->num_nodes;
3173         for (nid = codec->start_nid; nid < end_nid; nid++) {
3174                 unsigned int wid_caps = get_wcaps(codec, nid);
3175                 unsigned int wid_type =
3176                         (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3177                 if (wid_type != AC_WID_PIN)
3178                         continue;
3179                 if (spec->num_pins >= ARRAY_SIZE(spec->pin_nids))
3180                         break;
3181                 spec->pin_nids[spec->num_pins] = nid;
3182                 spec->pin_cfgs[spec->num_pins] =
3183                         snd_hda_codec_read(codec, nid, 0,
3184                                            AC_VERB_GET_CONFIG_DEFAULT, 0);
3185                 spec->num_pins++;
3186         }
3187 }
3188
3189 static void resume_pin_configs(struct hda_codec *codec)
3190 {
3191         struct alc_spec *spec = codec->spec;
3192         int i;
3193
3194         for (i = 0; i < spec->num_pins; i++) {
3195                 hda_nid_t pin_nid = spec->pin_nids[i];
3196                 unsigned int pin_config = spec->pin_cfgs[i];
3197                 snd_hda_codec_write(codec, pin_nid, 0,
3198                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
3199                                     pin_config & 0x000000ff);
3200                 snd_hda_codec_write(codec, pin_nid, 0,
3201                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
3202                                     (pin_config & 0x0000ff00) >> 8);
3203                 snd_hda_codec_write(codec, pin_nid, 0,
3204                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
3205                                     (pin_config & 0x00ff0000) >> 16);
3206                 snd_hda_codec_write(codec, pin_nid, 0,
3207                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
3208                                     pin_config >> 24);
3209         }
3210 }
3211
3212 static int alc_resume(struct hda_codec *codec)
3213 {
3214         resume_pin_configs(codec);
3215         codec->patch_ops.init(codec);
3216         snd_hda_codec_resume_amp(codec);
3217         snd_hda_codec_resume_cache(codec);
3218         return 0;
3219 }
3220 #else
3221 #define store_pin_configs(codec)
3222 #endif
3223
3224 /*
3225  */
3226 static struct hda_codec_ops alc_patch_ops = {
3227         .build_controls = alc_build_controls,
3228         .build_pcms = alc_build_pcms,
3229         .init = alc_init,
3230         .free = alc_free,
3231         .unsol_event = alc_unsol_event,
3232 #ifdef SND_HDA_NEEDS_RESUME
3233         .resume = alc_resume,
3234 #endif
3235 #ifdef CONFIG_SND_HDA_POWER_SAVE
3236         .check_power_status = alc_check_power_status,
3237 #endif
3238 };
3239
3240
3241 /*
3242  * Test configuration for debugging
3243  *
3244  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3245  * enum controls.
3246  */
3247 #ifdef CONFIG_SND_DEBUG
3248 static hda_nid_t alc880_test_dac_nids[4] = {
3249         0x02, 0x03, 0x04, 0x05
3250 };
3251
3252 static struct hda_input_mux alc880_test_capture_source = {
3253         .num_items = 7,
3254         .items = {
3255                 { "In-1", 0x0 },
3256                 { "In-2", 0x1 },
3257                 { "In-3", 0x2 },
3258                 { "In-4", 0x3 },
3259                 { "CD", 0x4 },
3260                 { "Front", 0x5 },
3261                 { "Surround", 0x6 },
3262         },
3263 };
3264
3265 static struct hda_channel_mode alc880_test_modes[4] = {
3266         { 2, NULL },
3267         { 4, NULL },
3268         { 6, NULL },
3269         { 8, NULL },
3270 };
3271
3272 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3273                                  struct snd_ctl_elem_info *uinfo)
3274 {
3275         static char *texts[] = {
3276                 "N/A", "Line Out", "HP Out",
3277                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3278         };
3279         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3280         uinfo->count = 1;
3281         uinfo->value.enumerated.items = 8;
3282         if (uinfo->value.enumerated.item >= 8)
3283                 uinfo->value.enumerated.item = 7;
3284         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3285         return 0;
3286 }
3287
3288 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3289                                 struct snd_ctl_elem_value *ucontrol)
3290 {
3291         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3292         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3293         unsigned int pin_ctl, item = 0;
3294
3295         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3296                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3297         if (pin_ctl & AC_PINCTL_OUT_EN) {
3298                 if (pin_ctl & AC_PINCTL_HP_EN)
3299                         item = 2;
3300                 else
3301                         item = 1;
3302         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3303                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3304                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3305                 case AC_PINCTL_VREF_50:  item = 4; break;
3306                 case AC_PINCTL_VREF_GRD: item = 5; break;
3307                 case AC_PINCTL_VREF_80:  item = 6; break;
3308                 case AC_PINCTL_VREF_100: item = 7; break;
3309                 }
3310         }
3311         ucontrol->value.enumerated.item[0] = item;
3312         return 0;
3313 }
3314
3315 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3316                                 struct snd_ctl_elem_value *ucontrol)
3317 {
3318         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3319         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3320         static unsigned int ctls[] = {
3321                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3322                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3323                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3324                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3325                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3326                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3327         };
3328         unsigned int old_ctl, new_ctl;
3329
3330         old_ctl = snd_hda_codec_read(codec, nid, 0,
3331                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3332         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3333         if (old_ctl != new_ctl) {
3334                 int val;
3335                 snd_hda_codec_write_cache(codec, nid, 0,
3336                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3337                                           new_ctl);
3338                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3339                         HDA_AMP_MUTE : 0;
3340                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3341                                          HDA_AMP_MUTE, val);
3342                 return 1;
3343         }
3344         return 0;
3345 }
3346
3347 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3348                                  struct snd_ctl_elem_info *uinfo)
3349 {
3350         static char *texts[] = {
3351                 "Front", "Surround", "CLFE", "Side"
3352         };
3353         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3354         uinfo->count = 1;
3355         uinfo->value.enumerated.items = 4;
3356         if (uinfo->value.enumerated.item >= 4)
3357                 uinfo->value.enumerated.item = 3;
3358         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3359         return 0;
3360 }
3361
3362 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3363                                 struct snd_ctl_elem_value *ucontrol)
3364 {
3365         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3366         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3367         unsigned int sel;
3368
3369         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3370         ucontrol->value.enumerated.item[0] = sel & 3;
3371         return 0;
3372 }
3373
3374 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3375                                 struct snd_ctl_elem_value *ucontrol)
3376 {
3377         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3378         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3379         unsigned int sel;
3380
3381         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3382         if (ucontrol->value.enumerated.item[0] != sel) {
3383                 sel = ucontrol->value.enumerated.item[0] & 3;
3384                 snd_hda_codec_write_cache(codec, nid, 0,
3385                                           AC_VERB_SET_CONNECT_SEL, sel);
3386                 return 1;
3387         }
3388         return 0;
3389 }
3390
3391 #define PIN_CTL_TEST(xname,nid) {                       \
3392                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3393                         .name = xname,                 \
3394                         .info = alc_test_pin_ctl_info, \
3395                         .get = alc_test_pin_ctl_get,   \
3396                         .put = alc_test_pin_ctl_put,   \
3397                         .private_value = nid           \
3398                         }
3399
3400 #define PIN_SRC_TEST(xname,nid) {                       \
3401                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3402                         .name = xname,                 \
3403                         .info = alc_test_pin_src_info, \
3404                         .get = alc_test_pin_src_get,   \
3405                         .put = alc_test_pin_src_put,   \
3406                         .private_value = nid           \
3407                         }
3408
3409 static struct snd_kcontrol_new alc880_test_mixer[] = {
3410         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3411         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3412         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3413         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3414         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3415         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3416         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3417         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3418         PIN_CTL_TEST("Front Pin Mode", 0x14),
3419         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3420         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3421         PIN_CTL_TEST("Side Pin Mode", 0x17),
3422         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3423         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3424         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3425         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3426         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3427         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3428         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3429         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3430         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3431         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3432         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3433         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3434         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3435         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3436         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3437         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3438         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3439         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3440         {
3441                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3442                 .name = "Channel Mode",
3443                 .info = alc_ch_mode_info,
3444                 .get = alc_ch_mode_get,
3445                 .put = alc_ch_mode_put,
3446         },
3447         { } /* end */
3448 };
3449
3450 static struct hda_verb alc880_test_init_verbs[] = {
3451         /* Unmute inputs of 0x0c - 0x0f */
3452         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3453         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3454         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3455         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3456         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3457         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3458         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3459         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3460         /* Vol output for 0x0c-0x0f */
3461         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3462         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3463         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3464         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3465         /* Set output pins 0x14-0x17 */
3466         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3467         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3468         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3469         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3470         /* Unmute output pins 0x14-0x17 */
3471         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3472         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3473         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3474         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3475         /* Set input pins 0x18-0x1c */
3476         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3477         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3478         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3479         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3480         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3481         /* Mute input pins 0x18-0x1b */
3482         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3483         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3484         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3485         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3486         /* ADC set up */
3487         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3488         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3489         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3490         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3491         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3492         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3493         /* Analog input/passthru */
3494         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3495         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3496         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3497         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3498         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3499         { }
3500 };
3501 #endif
3502
3503 /*
3504  */
3505
3506 static const char *alc880_models[ALC880_MODEL_LAST] = {
3507         [ALC880_3ST]            = "3stack",
3508         [ALC880_TCL_S700]       = "tcl",
3509         [ALC880_3ST_DIG]        = "3stack-digout",
3510         [ALC880_CLEVO]          = "clevo",
3511         [ALC880_5ST]            = "5stack",
3512         [ALC880_5ST_DIG]        = "5stack-digout",
3513         [ALC880_W810]           = "w810",
3514         [ALC880_Z71V]           = "z71v",
3515         [ALC880_6ST]            = "6stack",
3516         [ALC880_6ST_DIG]        = "6stack-digout",
3517         [ALC880_ASUS]           = "asus",
3518         [ALC880_ASUS_W1V]       = "asus-w1v",
3519         [ALC880_ASUS_DIG]       = "asus-dig",
3520         [ALC880_ASUS_DIG2]      = "asus-dig2",
3521         [ALC880_UNIWILL_DIG]    = "uniwill",
3522         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3523         [ALC880_FUJITSU]        = "fujitsu",
3524         [ALC880_F1734]          = "F1734",
3525         [ALC880_LG]             = "lg",
3526         [ALC880_LG_LW]          = "lg-lw",
3527         [ALC880_MEDION_RIM]     = "medion",
3528 #ifdef CONFIG_SND_DEBUG
3529         [ALC880_TEST]           = "test",
3530 #endif
3531         [ALC880_AUTO]           = "auto",
3532 };
3533
3534 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3535         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3536         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3537         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3538         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3539         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3540         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3541         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3542         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3543         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3544         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3545         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3546         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3547         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3548         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3549         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3550         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3551         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3552         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3553         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3554         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3555         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3556         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3557         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3558         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3559         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3560         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3561         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3562         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3563         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3564         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3565         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3566         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3567         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3568         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3569         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3570         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3571         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3572         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3573         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3574         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3575         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3576         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3577         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3578         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3579         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3580         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3581         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3582         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3583         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3584         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3585         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3586         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3587         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3588         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3589         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3590         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3591         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3592         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3593         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3594         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3595         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3596         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3597         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3598         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3599         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3600         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3601         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3602         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3603         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3604         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3605         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3606         {}
3607 };
3608
3609 /*
3610  * ALC880 codec presets
3611  */
3612 static struct alc_config_preset alc880_presets[] = {
3613         [ALC880_3ST] = {
3614                 .mixers = { alc880_three_stack_mixer },
3615                 .init_verbs = { alc880_volume_init_verbs,
3616                                 alc880_pin_3stack_init_verbs },
3617                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3618                 .dac_nids = alc880_dac_nids,
3619                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3620                 .channel_mode = alc880_threestack_modes,
3621                 .need_dac_fix = 1,
3622                 .input_mux = &alc880_capture_source,
3623         },
3624         [ALC880_3ST_DIG] = {
3625                 .mixers = { alc880_three_stack_mixer },
3626                 .init_verbs = { alc880_volume_init_verbs,
3627                                 alc880_pin_3stack_init_verbs },
3628                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3629                 .dac_nids = alc880_dac_nids,
3630                 .dig_out_nid = ALC880_DIGOUT_NID,
3631                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3632                 .channel_mode = alc880_threestack_modes,
3633                 .need_dac_fix = 1,
3634                 .input_mux = &alc880_capture_source,
3635         },
3636         [ALC880_TCL_S700] = {
3637                 .mixers = { alc880_tcl_s700_mixer },
3638                 .init_verbs = { alc880_volume_init_verbs,
3639                                 alc880_pin_tcl_S700_init_verbs,
3640                                 alc880_gpio2_init_verbs },
3641                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3642                 .dac_nids = alc880_dac_nids,
3643                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3644                 .num_adc_nids = 1, /* single ADC */
3645                 .hp_nid = 0x03,
3646                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3647                 .channel_mode = alc880_2_jack_modes,
3648                 .input_mux = &alc880_capture_source,
3649         },
3650         [ALC880_5ST] = {
3651                 .mixers = { alc880_three_stack_mixer,
3652                             alc880_five_stack_mixer},
3653                 .init_verbs = { alc880_volume_init_verbs,
3654                                 alc880_pin_5stack_init_verbs },
3655                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3656                 .dac_nids = alc880_dac_nids,
3657                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3658                 .channel_mode = alc880_fivestack_modes,
3659                 .input_mux = &alc880_capture_source,
3660         },
3661         [ALC880_5ST_DIG] = {
3662                 .mixers = { alc880_three_stack_mixer,
3663                             alc880_five_stack_mixer },
3664                 .init_verbs = { alc880_volume_init_verbs,
3665                                 alc880_pin_5stack_init_verbs },
3666                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3667                 .dac_nids = alc880_dac_nids,
3668                 .dig_out_nid = ALC880_DIGOUT_NID,
3669                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3670                 .channel_mode = alc880_fivestack_modes,
3671                 .input_mux = &alc880_capture_source,
3672         },
3673         [ALC880_6ST] = {
3674                 .mixers = { alc880_six_stack_mixer },
3675                 .init_verbs = { alc880_volume_init_verbs,
3676                                 alc880_pin_6stack_init_verbs },
3677                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3678                 .dac_nids = alc880_6st_dac_nids,
3679                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3680                 .channel_mode = alc880_sixstack_modes,
3681                 .input_mux = &alc880_6stack_capture_source,
3682         },
3683         [ALC880_6ST_DIG] = {
3684                 .mixers = { alc880_six_stack_mixer },
3685                 .init_verbs = { alc880_volume_init_verbs,
3686                                 alc880_pin_6stack_init_verbs },
3687                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3688                 .dac_nids = alc880_6st_dac_nids,
3689                 .dig_out_nid = ALC880_DIGOUT_NID,
3690                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3691                 .channel_mode = alc880_sixstack_modes,
3692                 .input_mux = &alc880_6stack_capture_source,
3693         },
3694         [ALC880_W810] = {
3695                 .mixers = { alc880_w810_base_mixer },
3696                 .init_verbs = { alc880_volume_init_verbs,
3697                                 alc880_pin_w810_init_verbs,
3698                                 alc880_gpio2_init_verbs },
3699                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3700                 .dac_nids = alc880_w810_dac_nids,
3701                 .dig_out_nid = ALC880_DIGOUT_NID,
3702                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3703                 .channel_mode = alc880_w810_modes,
3704                 .input_mux = &alc880_capture_source,
3705         },
3706         [ALC880_Z71V] = {
3707                 .mixers = { alc880_z71v_mixer },
3708                 .init_verbs = { alc880_volume_init_verbs,
3709                                 alc880_pin_z71v_init_verbs },
3710                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3711                 .dac_nids = alc880_z71v_dac_nids,
3712                 .dig_out_nid = ALC880_DIGOUT_NID,
3713                 .hp_nid = 0x03,
3714                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3715                 .channel_mode = alc880_2_jack_modes,
3716                 .input_mux = &alc880_capture_source,
3717         },
3718         [ALC880_F1734] = {
3719                 .mixers = { alc880_f1734_mixer },
3720                 .init_verbs = { alc880_volume_init_verbs,
3721                                 alc880_pin_f1734_init_verbs },
3722                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3723                 .dac_nids = alc880_f1734_dac_nids,
3724                 .hp_nid = 0x02,
3725                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3726                 .channel_mode = alc880_2_jack_modes,
3727                 .input_mux = &alc880_f1734_capture_source,
3728                 .unsol_event = alc880_uniwill_p53_unsol_event,
3729                 .init_hook = alc880_uniwill_p53_hp_automute,
3730         },
3731         [ALC880_ASUS] = {
3732                 .mixers = { alc880_asus_mixer },
3733                 .init_verbs = { alc880_volume_init_verbs,
3734                                 alc880_pin_asus_init_verbs,
3735                                 alc880_gpio1_init_verbs },
3736                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3737                 .dac_nids = alc880_asus_dac_nids,
3738                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3739                 .channel_mode = alc880_asus_modes,
3740                 .need_dac_fix = 1,
3741                 .input_mux = &alc880_capture_source,
3742         },
3743         [ALC880_ASUS_DIG] = {
3744                 .mixers = { alc880_asus_mixer },
3745                 .init_verbs = { alc880_volume_init_verbs,
3746                                 alc880_pin_asus_init_verbs,
3747                                 alc880_gpio1_init_verbs },
3748                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3749                 .dac_nids = alc880_asus_dac_nids,
3750                 .dig_out_nid = ALC880_DIGOUT_NID,
3751                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3752                 .channel_mode = alc880_asus_modes,
3753                 .need_dac_fix = 1,
3754                 .input_mux = &alc880_capture_source,
3755         },
3756         [ALC880_ASUS_DIG2] = {
3757                 .mixers = { alc880_asus_mixer },
3758                 .init_verbs = { alc880_volume_init_verbs,
3759                                 alc880_pin_asus_init_verbs,
3760                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3761                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3762                 .dac_nids = alc880_asus_dac_nids,
3763                 .dig_out_nid = ALC880_DIGOUT_NID,
3764                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3765                 .channel_mode = alc880_asus_modes,
3766                 .need_dac_fix = 1,
3767                 .input_mux = &alc880_capture_source,
3768         },
3769         [ALC880_ASUS_W1V] = {
3770                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3771                 .init_verbs = { alc880_volume_init_verbs,
3772                                 alc880_pin_asus_init_verbs,
3773                                 alc880_gpio1_init_verbs },
3774                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3775                 .dac_nids = alc880_asus_dac_nids,
3776                 .dig_out_nid = ALC880_DIGOUT_NID,
3777                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3778                 .channel_mode = alc880_asus_modes,
3779                 .need_dac_fix = 1,
3780                 .input_mux = &alc880_capture_source,
3781         },
3782         [ALC880_UNIWILL_DIG] = {
3783                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3784                 .init_verbs = { alc880_volume_init_verbs,
3785                                 alc880_pin_asus_init_verbs },
3786                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3787                 .dac_nids = alc880_asus_dac_nids,
3788                 .dig_out_nid = ALC880_DIGOUT_NID,
3789                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3790                 .channel_mode = alc880_asus_modes,
3791                 .need_dac_fix = 1,
3792                 .input_mux = &alc880_capture_source,
3793         },
3794         [ALC880_UNIWILL] = {
3795                 .mixers = { alc880_uniwill_mixer },
3796                 .init_verbs = { alc880_volume_init_verbs,
3797                                 alc880_uniwill_init_verbs },
3798                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3799                 .dac_nids = alc880_asus_dac_nids,
3800                 .dig_out_nid = ALC880_DIGOUT_NID,
3801                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3802                 .channel_mode = alc880_threestack_modes,
3803                 .need_dac_fix = 1,
3804                 .input_mux = &alc880_capture_source,
3805                 .unsol_event = alc880_uniwill_unsol_event,
3806                 .init_hook = alc880_uniwill_automute,
3807         },
3808         [ALC880_UNIWILL_P53] = {
3809                 .mixers = { alc880_uniwill_p53_mixer },
3810                 .init_verbs = { alc880_volume_init_verbs,
3811                                 alc880_uniwill_p53_init_verbs },
3812                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3813                 .dac_nids = alc880_asus_dac_nids,
3814                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3815                 .channel_mode = alc880_threestack_modes,
3816                 .input_mux = &alc880_capture_source,
3817                 .unsol_event = alc880_uniwill_p53_unsol_event,
3818                 .init_hook = alc880_uniwill_p53_hp_automute,
3819         },
3820         [ALC880_FUJITSU] = {
3821                 .mixers = { alc880_fujitsu_mixer,
3822                             alc880_pcbeep_mixer, },
3823                 .init_verbs = { alc880_volume_init_verbs,
3824                                 alc880_uniwill_p53_init_verbs,
3825                                 alc880_beep_init_verbs },
3826                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3827                 .dac_nids = alc880_dac_nids,
3828                 .dig_out_nid = ALC880_DIGOUT_NID,
3829                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3830                 .channel_mode = alc880_2_jack_modes,
3831                 .input_mux = &alc880_capture_source,
3832                 .unsol_event = alc880_uniwill_p53_unsol_event,
3833                 .init_hook = alc880_uniwill_p53_hp_automute,
3834         },
3835         [ALC880_CLEVO] = {
3836                 .mixers = { alc880_three_stack_mixer },
3837                 .init_verbs = { alc880_volume_init_verbs,
3838                                 alc880_pin_clevo_init_verbs },
3839                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3840                 .dac_nids = alc880_dac_nids,
3841                 .hp_nid = 0x03,
3842                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3843                 .channel_mode = alc880_threestack_modes,
3844                 .need_dac_fix = 1,
3845                 .input_mux = &alc880_capture_source,
3846         },
3847         [ALC880_LG] = {
3848                 .mixers = { alc880_lg_mixer },
3849                 .init_verbs = { alc880_volume_init_verbs,
3850                                 alc880_lg_init_verbs },
3851                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3852                 .dac_nids = alc880_lg_dac_nids,
3853                 .dig_out_nid = ALC880_DIGOUT_NID,
3854                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3855                 .channel_mode = alc880_lg_ch_modes,
3856                 .need_dac_fix = 1,
3857                 .input_mux = &alc880_lg_capture_source,
3858                 .unsol_event = alc880_lg_unsol_event,
3859                 .init_hook = alc880_lg_automute,
3860 #ifdef CONFIG_SND_HDA_POWER_SAVE
3861                 .loopbacks = alc880_lg_loopbacks,
3862 #endif
3863         },
3864         [ALC880_LG_LW] = {
3865                 .mixers = { alc880_lg_lw_mixer },
3866                 .init_verbs = { alc880_volume_init_verbs,
3867                                 alc880_lg_lw_init_verbs },
3868                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3869                 .dac_nids = alc880_dac_nids,
3870                 .dig_out_nid = ALC880_DIGOUT_NID,
3871                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3872                 .channel_mode = alc880_lg_lw_modes,
3873                 .input_mux = &alc880_lg_lw_capture_source,
3874                 .unsol_event = alc880_lg_lw_unsol_event,
3875                 .init_hook = alc880_lg_lw_automute,
3876         },
3877         [ALC880_MEDION_RIM] = {
3878                 .mixers = { alc880_medion_rim_mixer },
3879                 .init_verbs = { alc880_volume_init_verbs,
3880                                 alc880_medion_rim_init_verbs,
3881                                 alc_gpio2_init_verbs },
3882                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3883                 .dac_nids = alc880_dac_nids,
3884                 .dig_out_nid = ALC880_DIGOUT_NID,
3885                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3886                 .channel_mode = alc880_2_jack_modes,
3887                 .input_mux = &alc880_medion_rim_capture_source,
3888                 .unsol_event = alc880_medion_rim_unsol_event,
3889                 .init_hook = alc880_medion_rim_automute,
3890         },
3891 #ifdef CONFIG_SND_DEBUG
3892         [ALC880_TEST] = {
3893                 .mixers = { alc880_test_mixer },
3894                 .init_verbs = { alc880_test_init_verbs },
3895                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3896                 .dac_nids = alc880_test_dac_nids,
3897                 .dig_out_nid = ALC880_DIGOUT_NID,
3898                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3899                 .channel_mode = alc880_test_modes,
3900                 .input_mux = &alc880_test_capture_source,
3901         },
3902 #endif
3903 };
3904
3905 /*
3906  * Automatic parse of I/O pins from the BIOS configuration
3907  */
3908
3909 enum {
3910         ALC_CTL_WIDGET_VOL,
3911         ALC_CTL_WIDGET_MUTE,
3912         ALC_CTL_BIND_MUTE,
3913 };
3914 static struct snd_kcontrol_new alc880_control_templates[] = {
3915         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3916         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3917         HDA_BIND_MUTE(NULL, 0, 0, 0),
3918 };
3919
3920 /* add dynamic controls */
3921 static int add_control(struct alc_spec *spec, int type, const char *name,
3922                        unsigned long val)
3923 {
3924         struct snd_kcontrol_new *knew;
3925
3926         snd_array_init(&spec->kctls, sizeof(*knew), 32);
3927         knew = snd_array_new(&spec->kctls);
3928         if (!knew)
3929                 return -ENOMEM;
3930         *knew = alc880_control_templates[type];
3931         knew->name = kstrdup(name, GFP_KERNEL);
3932         if (!knew->name)
3933                 return -ENOMEM;
3934         knew->private_value = val;
3935         return 0;
3936 }
3937
3938 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3939 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3940 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3941 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3942 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3943 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3944 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3945 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3946 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3947 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3948 #define ALC880_PIN_CD_NID               0x1c
3949
3950 /* fill in the dac_nids table from the parsed pin configuration */
3951 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3952                                      const struct auto_pin_cfg *cfg)
3953 {
3954         hda_nid_t nid;
3955         int assigned[4];
3956         int i, j;
3957
3958         memset(assigned, 0, sizeof(assigned));
3959         spec->multiout.dac_nids = spec->private_dac_nids;
3960
3961         /* check the pins hardwired to audio widget */
3962         for (i = 0; i < cfg->line_outs; i++) {
3963                 nid = cfg->line_out_pins[i];
3964                 if (alc880_is_fixed_pin(nid)) {
3965                         int idx = alc880_fixed_pin_idx(nid);
3966                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3967                         assigned[idx] = 1;
3968                 }
3969         }
3970         /* left pins can be connect to any audio widget */
3971         for (i = 0; i < cfg->line_outs; i++) {
3972                 nid = cfg->line_out_pins[i];
3973                 if (alc880_is_fixed_pin(nid))
3974                         continue;
3975                 /* search for an empty channel */
3976                 for (j = 0; j < cfg->line_outs; j++) {
3977                         if (!assigned[j]) {
3978                                 spec->multiout.dac_nids[i] =
3979                                         alc880_idx_to_dac(j);
3980                                 assigned[j] = 1;
3981                                 break;
3982                         }
3983                 }
3984         }
3985         spec->multiout.num_dacs = cfg->line_outs;
3986         return 0;
3987 }
3988
3989 /* add playback controls from the parsed DAC table */
3990 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3991                                              const struct auto_pin_cfg *cfg)
3992 {
3993         char name[32];
3994         static const char *chname[4] = {
3995                 "Front", "Surround", NULL /*CLFE*/, "Side"
3996         };
3997         hda_nid_t nid;
3998         int i, err;
3999
4000         for (i = 0; i < cfg->line_outs; i++) {
4001                 if (!spec->multiout.dac_nids[i])
4002                         continue;
4003                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4004                 if (i == 2) {
4005                         /* Center/LFE */
4006                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4007                                           "Center Playback Volume",
4008                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4009                                                               HDA_OUTPUT));
4010                         if (err < 0)
4011                                 return err;
4012                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4013                                           "LFE Playback Volume",
4014                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4015                                                               HDA_OUTPUT));
4016                         if (err < 0)
4017                                 return err;
4018                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4019                                           "Center Playback Switch",
4020                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4021                                                               HDA_INPUT));
4022                         if (err < 0)
4023                                 return err;
4024                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4025                                           "LFE Playback Switch",
4026                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4027                                                               HDA_INPUT));
4028                         if (err < 0)
4029                                 return err;
4030                 } else {
4031                         sprintf(name, "%s Playback Volume", chname[i]);
4032                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4033                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4034                                                               HDA_OUTPUT));
4035                         if (err < 0)
4036                                 return err;
4037                         sprintf(name, "%s Playback Switch", chname[i]);
4038                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4039                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4040                                                               HDA_INPUT));
4041                         if (err < 0)
4042                                 return err;
4043                 }
4044         }
4045         return 0;
4046 }
4047
4048 /* add playback controls for speaker and HP outputs */
4049 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4050                                         const char *pfx)
4051 {
4052         hda_nid_t nid;
4053         int err;
4054         char name[32];
4055
4056         if (!pin)
4057                 return 0;
4058
4059         if (alc880_is_fixed_pin(pin)) {
4060                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4061                 /* specify the DAC as the extra output */
4062                 if (!spec->multiout.hp_nid)
4063                         spec->multiout.hp_nid = nid;
4064                 else
4065                         spec->multiout.extra_out_nid[0] = nid;
4066                 /* control HP volume/switch on the output mixer amp */
4067                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4068                 sprintf(name, "%s Playback Volume", pfx);
4069                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4070                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4071                 if (err < 0)
4072                         return err;
4073                 sprintf(name, "%s Playback Switch", pfx);
4074                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4075                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4076                 if (err < 0)
4077                         return err;
4078         } else if (alc880_is_multi_pin(pin)) {
4079                 /* set manual connection */
4080                 /* we have only a switch on HP-out PIN */
4081                 sprintf(name, "%s Playback Switch", pfx);
4082                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4083                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4084                 if (err < 0)
4085                         return err;
4086         }
4087         return 0;
4088 }
4089
4090 /* create input playback/capture controls for the given pin */
4091 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4092                             const char *ctlname,
4093                             int idx, hda_nid_t mix_nid)
4094 {
4095         char name[32];
4096         int err;
4097
4098         sprintf(name, "%s Playback Volume", ctlname);
4099         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4100                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4101         if (err < 0)
4102                 return err;
4103         sprintf(name, "%s Playback Switch", ctlname);
4104         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4105                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4106         if (err < 0)
4107                 return err;
4108         return 0;
4109 }
4110
4111 /* create playback/capture controls for input pins */
4112 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
4113                                                 const struct auto_pin_cfg *cfg)
4114 {
4115         struct hda_input_mux *imux = &spec->private_imux;
4116         int i, err, idx;
4117
4118         for (i = 0; i < AUTO_PIN_LAST; i++) {
4119                 if (alc880_is_input_pin(cfg->input_pins[i])) {
4120                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
4121                         err = new_analog_input(spec, cfg->input_pins[i],
4122                                                auto_pin_cfg_labels[i],
4123                                                idx, 0x0b);
4124                         if (err < 0)
4125                                 return err;
4126                         imux->items[imux->num_items].label =
4127                                 auto_pin_cfg_labels[i];
4128                         imux->items[imux->num_items].index =
4129                                 alc880_input_pin_idx(cfg->input_pins[i]);
4130                         imux->num_items++;
4131                 }
4132         }
4133         return 0;
4134 }
4135
4136 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4137                                unsigned int pin_type)
4138 {
4139         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4140                             pin_type);
4141         /* unmute pin */
4142         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4143                             AMP_OUT_UNMUTE);
4144 }
4145
4146 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4147                                               hda_nid_t nid, int pin_type,
4148                                               int dac_idx)
4149 {
4150         alc_set_pin_output(codec, nid, pin_type);
4151         /* need the manual connection? */
4152         if (alc880_is_multi_pin(nid)) {
4153                 struct alc_spec *spec = codec->spec;
4154                 int idx = alc880_multi_pin_idx(nid);
4155                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4156                                     AC_VERB_SET_CONNECT_SEL,
4157                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4158         }
4159 }
4160
4161 static int get_pin_type(int line_out_type)
4162 {
4163         if (line_out_type == AUTO_PIN_HP_OUT)
4164                 return PIN_HP;
4165         else
4166                 return PIN_OUT;
4167 }
4168
4169 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4170 {
4171         struct alc_spec *spec = codec->spec;
4172         int i;
4173
4174         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
4175         for (i = 0; i < spec->autocfg.line_outs; i++) {
4176                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4177                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4178                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4179         }
4180 }
4181
4182 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4183 {
4184         struct alc_spec *spec = codec->spec;
4185         hda_nid_t pin;
4186
4187         pin = spec->autocfg.speaker_pins[0];
4188         if (pin) /* connect to front */
4189                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4190         pin = spec->autocfg.hp_pins[0];
4191         if (pin) /* connect to front */
4192                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4193 }
4194
4195 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4196 {
4197         struct alc_spec *spec = codec->spec;
4198         int i;
4199
4200         for (i = 0; i < AUTO_PIN_LAST; i++) {
4201                 hda_nid_t nid = spec->autocfg.input_pins[i];
4202                 if (alc880_is_input_pin(nid)) {
4203                         snd_hda_codec_write(codec, nid, 0,
4204                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4205                                             i <= AUTO_PIN_FRONT_MIC ?
4206                                             PIN_VREF80 : PIN_IN);
4207                         if (nid != ALC880_PIN_CD_NID)
4208                                 snd_hda_codec_write(codec, nid, 0,
4209                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4210                                                     AMP_OUT_MUTE);
4211                 }
4212         }
4213 }
4214
4215 /* parse the BIOS configuration and set up the alc_spec */
4216 /* return 1 if successful, 0 if the proper config is not found,
4217  * or a negative error code
4218  */
4219 static int alc880_parse_auto_config(struct hda_codec *codec)
4220 {
4221         struct alc_spec *spec = codec->spec;
4222         int err;
4223         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4224
4225         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4226                                            alc880_ignore);
4227         if (err < 0)
4228                 return err;
4229         if (!spec->autocfg.line_outs)
4230                 return 0; /* can't find valid BIOS pin config */
4231
4232         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4233         if (err < 0)
4234                 return err;
4235         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4236         if (err < 0)
4237                 return err;
4238         err = alc880_auto_create_extra_out(spec,
4239                                            spec->autocfg.speaker_pins[0],
4240                                            "Speaker");
4241         if (err < 0)
4242                 return err;
4243         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4244                                            "Headphone");
4245         if (err < 0)
4246                 return err;
4247         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
4248         if (err < 0)
4249                 return err;
4250
4251         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4252
4253         if (spec->autocfg.dig_out_pin)
4254                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
4255         if (spec->autocfg.dig_in_pin)
4256                 spec->dig_in_nid = ALC880_DIGIN_NID;
4257
4258         if (spec->kctls.list)
4259                 add_mixer(spec, spec->kctls.list);
4260
4261         add_verb(spec, alc880_volume_init_verbs);
4262
4263         spec->num_mux_defs = 1;
4264         spec->input_mux = &spec->private_imux;
4265
4266         store_pin_configs(codec);
4267         return 1;
4268 }
4269
4270 /* additional initialization for auto-configuration model */
4271 static void alc880_auto_init(struct hda_codec *codec)
4272 {
4273         struct alc_spec *spec = codec->spec;
4274         alc880_auto_init_multi_out(codec);
4275         alc880_auto_init_extra_out(codec);
4276         alc880_auto_init_analog_input(codec);
4277         if (spec->unsol_event)
4278                 alc_inithook(codec);
4279 }
4280
4281 /*
4282  * OK, here we have finally the patch for ALC880
4283  */
4284
4285 static void set_capture_mixer(struct alc_spec *spec)
4286 {
4287         static struct snd_kcontrol_new *caps[3] = {
4288                 alc_capture_mixer1,
4289                 alc_capture_mixer2,
4290                 alc_capture_mixer3,
4291         };
4292         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3)
4293                 spec->cap_mixer = caps[spec->num_adc_nids - 1];
4294 }
4295
4296 static int patch_alc880(struct hda_codec *codec)
4297 {
4298         struct alc_spec *spec;
4299         int board_config;
4300         int err;
4301
4302         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4303         if (spec == NULL)
4304                 return -ENOMEM;
4305
4306         codec->spec = spec;
4307
4308         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4309                                                   alc880_models,
4310                                                   alc880_cfg_tbl);
4311         if (board_config < 0) {
4312                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
4313                        "trying auto-probe from BIOS...\n");
4314                 board_config = ALC880_AUTO;
4315         }
4316
4317         if (board_config == ALC880_AUTO) {
4318                 /* automatic parse from the BIOS config */
4319                 err = alc880_parse_auto_config(codec);
4320                 if (err < 0) {
4321                         alc_free(codec);
4322                         return err;
4323                 } else if (!err) {
4324                         printk(KERN_INFO
4325                                "hda_codec: Cannot set up configuration "
4326                                "from BIOS.  Using 3-stack mode...\n");
4327                         board_config = ALC880_3ST;
4328                 }
4329         }
4330
4331         if (board_config != ALC880_AUTO)
4332                 setup_preset(spec, &alc880_presets[board_config]);
4333
4334         spec->stream_name_analog = "ALC880 Analog";
4335         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4336         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4337         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4338
4339         spec->stream_name_digital = "ALC880 Digital";
4340         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4341         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4342
4343         if (!spec->adc_nids && spec->input_mux) {
4344                 /* check whether NID 0x07 is valid */
4345                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4346                 /* get type */
4347                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4348                 if (wcap != AC_WID_AUD_IN) {
4349                         spec->adc_nids = alc880_adc_nids_alt;
4350                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4351                 } else {
4352                         spec->adc_nids = alc880_adc_nids;
4353                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4354                 }
4355         }
4356         set_capture_mixer(spec);
4357
4358         spec->vmaster_nid = 0x0c;
4359
4360         codec->patch_ops = alc_patch_ops;
4361         if (board_config == ALC880_AUTO)
4362                 spec->init_hook = alc880_auto_init;
4363 #ifdef CONFIG_SND_HDA_POWER_SAVE
4364         if (!spec->loopback.amplist)
4365                 spec->loopback.amplist = alc880_loopbacks;
4366 #endif
4367         codec->proc_widget_hook = print_realtek_coef;
4368
4369         return 0;
4370 }
4371
4372
4373 /*
4374  * ALC260 support
4375  */
4376
4377 static hda_nid_t alc260_dac_nids[1] = {
4378         /* front */
4379         0x02,
4380 };
4381
4382 static hda_nid_t alc260_adc_nids[1] = {
4383         /* ADC0 */
4384         0x04,
4385 };
4386
4387 static hda_nid_t alc260_adc_nids_alt[1] = {
4388         /* ADC1 */
4389         0x05,
4390 };
4391
4392 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4393  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4394  */
4395 static hda_nid_t alc260_dual_adc_nids[2] = {
4396         /* ADC0, ADC1 */
4397         0x04, 0x05
4398 };
4399
4400 #define ALC260_DIGOUT_NID       0x03
4401 #define ALC260_DIGIN_NID        0x06
4402
4403 static struct hda_input_mux alc260_capture_source = {
4404         .num_items = 4,
4405         .items = {
4406                 { "Mic", 0x0 },
4407                 { "Front Mic", 0x1 },
4408                 { "Line", 0x2 },
4409                 { "CD", 0x4 },
4410         },
4411 };
4412
4413 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4414  * headphone jack and the internal CD lines since these are the only pins at
4415  * which audio can appear.  For flexibility, also allow the option of
4416  * recording the mixer output on the second ADC (ADC0 doesn't have a
4417  * connection to the mixer output).
4418  */
4419 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4420         {
4421                 .num_items = 3,
4422                 .items = {
4423                         { "Mic/Line", 0x0 },
4424                         { "CD", 0x4 },
4425                         { "Headphone", 0x2 },
4426                 },
4427         },
4428         {
4429                 .num_items = 4,
4430                 .items = {
4431                         { "Mic/Line", 0x0 },
4432                         { "CD", 0x4 },
4433                         { "Headphone", 0x2 },
4434                         { "Mixer", 0x5 },
4435                 },
4436         },
4437
4438 };
4439
4440 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4441  * the Fujitsu S702x, but jacks are marked differently.
4442  */
4443 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4444         {
4445                 .num_items = 4,
4446                 .items = {
4447                         { "Mic", 0x0 },
4448                         { "Line", 0x2 },
4449                         { "CD", 0x4 },
4450                         { "Headphone", 0x5 },
4451                 },
4452         },
4453         {
4454                 .num_items = 5,
4455                 .items = {
4456                         { "Mic", 0x0 },
4457                         { "Line", 0x2 },
4458                         { "CD", 0x4 },
4459                         { "Headphone", 0x6 },
4460                         { "Mixer", 0x5 },
4461                 },
4462         },
4463 };
4464 /*
4465  * This is just place-holder, so there's something for alc_build_pcms to look
4466  * at when it calculates the maximum number of channels. ALC260 has no mixer
4467  * element which allows changing the channel mode, so the verb list is
4468  * never used.
4469  */
4470 static struct hda_channel_mode alc260_modes[1] = {
4471         { 2, NULL },
4472 };
4473
4474
4475 /* Mixer combinations
4476  *
4477  * basic: base_output + input + pc_beep + capture
4478  * HP: base_output + input + capture_alt
4479  * HP_3013: hp_3013 + input + capture
4480  * fujitsu: fujitsu + capture
4481  * acer: acer + capture
4482  */
4483
4484 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4485         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4486         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4487         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4488         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4489         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4490         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4491         { } /* end */
4492 };
4493
4494 static struct snd_kcontrol_new alc260_input_mixer[] = {
4495         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4496         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4497         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4498         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4499         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4500         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4501         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4502         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4503         { } /* end */
4504 };
4505
4506 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4507         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4508         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4509         { } /* end */
4510 };
4511
4512 /* update HP, line and mono out pins according to the master switch */
4513 static void alc260_hp_master_update(struct hda_codec *codec,
4514                                     hda_nid_t hp, hda_nid_t line,
4515                                     hda_nid_t mono)
4516 {
4517         struct alc_spec *spec = codec->spec;
4518         unsigned int val = spec->master_sw ? PIN_HP : 0;
4519         /* change HP and line-out pins */
4520         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4521                             val);
4522         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4523                             val);
4524         /* mono (speaker) depending on the HP jack sense */
4525         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4526         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4527                             val);
4528 }
4529
4530 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4531                                    struct snd_ctl_elem_value *ucontrol)
4532 {
4533         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4534         struct alc_spec *spec = codec->spec;
4535         *ucontrol->value.integer.value = spec->master_sw;
4536         return 0;
4537 }
4538
4539 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4540                                    struct snd_ctl_elem_value *ucontrol)
4541 {
4542         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4543         struct alc_spec *spec = codec->spec;
4544         int val = !!*ucontrol->value.integer.value;
4545         hda_nid_t hp, line, mono;
4546
4547         if (val == spec->master_sw)
4548                 return 0;
4549         spec->master_sw = val;
4550         hp = (kcontrol->private_value >> 16) & 0xff;
4551         line = (kcontrol->private_value >> 8) & 0xff;
4552         mono = kcontrol->private_value & 0xff;
4553         alc260_hp_master_update(codec, hp, line, mono);
4554         return 1;
4555 }
4556
4557 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4558         {
4559                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4560                 .name = "Master Playback Switch",
4561                 .info = snd_ctl_boolean_mono_info,
4562                 .get = alc260_hp_master_sw_get,
4563                 .put = alc260_hp_master_sw_put,
4564                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4565         },
4566         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4567         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4568         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4569         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4570         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4571                               HDA_OUTPUT),
4572         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4573         { } /* end */
4574 };
4575
4576 static struct hda_verb alc260_hp_unsol_verbs[] = {
4577         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4578         {},
4579 };
4580
4581 static void alc260_hp_automute(struct hda_codec *codec)
4582 {
4583         struct alc_spec *spec = codec->spec;
4584         unsigned int present;
4585
4586         present = snd_hda_codec_read(codec, 0x10, 0,
4587                                      AC_VERB_GET_PIN_SENSE, 0);
4588         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4589         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4590 }
4591
4592 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4593 {
4594         if ((res >> 26) == ALC880_HP_EVENT)
4595                 alc260_hp_automute(codec);
4596 }
4597
4598 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4599         {
4600                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4601                 .name = "Master Playback Switch",
4602                 .info = snd_ctl_boolean_mono_info,
4603                 .get = alc260_hp_master_sw_get,
4604                 .put = alc260_hp_master_sw_put,
4605                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4606         },
4607         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4608         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4609         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4610         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4611         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4612         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4613         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4614         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4615         { } /* end */
4616 };
4617
4618 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4619         .ops = &snd_hda_bind_vol,
4620         .values = {
4621                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4622                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4623                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4624                 0
4625         },
4626 };
4627
4628 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4629         .ops = &snd_hda_bind_sw,
4630         .values = {
4631                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4632                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4633                 0
4634         },
4635 };
4636
4637 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4638         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4639         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4640         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4641         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4642         { } /* end */
4643 };
4644
4645 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4646         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4647         {},
4648 };
4649
4650 static void alc260_hp_3013_automute(struct hda_codec *codec)
4651 {
4652         struct alc_spec *spec = codec->spec;
4653         unsigned int present;
4654
4655         present = snd_hda_codec_read(codec, 0x15, 0,
4656                                      AC_VERB_GET_PIN_SENSE, 0);
4657         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4658         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4659 }
4660
4661 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4662                                        unsigned int res)
4663 {
4664         if ((res >> 26) == ALC880_HP_EVENT)
4665                 alc260_hp_3013_automute(codec);
4666 }
4667
4668 static void alc260_hp_3012_automute(struct hda_codec *codec)
4669 {
4670         unsigned int present, bits;
4671
4672         present = snd_hda_codec_read(codec, 0x10, 0,
4673                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4674
4675         bits = present ? 0 : PIN_OUT;
4676         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4677                             bits);
4678         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4679                             bits);
4680         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4681                             bits);
4682 }
4683
4684 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4685                                        unsigned int res)
4686 {
4687         if ((res >> 26) == ALC880_HP_EVENT)
4688                 alc260_hp_3012_automute(codec);
4689 }
4690
4691 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4692  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4693  */
4694 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4695         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4696         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4697         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4698         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4699         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4700         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4701         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4702         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4703         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4704         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4705         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4706         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4707         { } /* end */
4708 };
4709
4710 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4711  * versions of the ALC260 don't act on requests to enable mic bias from NID
4712  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4713  * datasheet doesn't mention this restriction.  At this stage it's not clear
4714  * whether this behaviour is intentional or is a hardware bug in chip
4715  * revisions available in early 2006.  Therefore for now allow the
4716  * "Headphone Jack Mode" control to span all choices, but if it turns out
4717  * that the lack of mic bias for this NID is intentional we could change the
4718  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4719  *
4720  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4721  * don't appear to make the mic bias available from the "line" jack, even
4722  * though the NID used for this jack (0x14) can supply it.  The theory is
4723  * that perhaps Acer have included blocking capacitors between the ALC260
4724  * and the output jack.  If this turns out to be the case for all such
4725  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4726  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4727  *
4728  * The C20x Tablet series have a mono internal speaker which is controlled
4729  * via the chip's Mono sum widget and pin complex, so include the necessary
4730  * controls for such models.  On models without a "mono speaker" the control
4731  * won't do anything.
4732  */
4733 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4734         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4735         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4736         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4737         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4738                               HDA_OUTPUT),
4739         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4740                            HDA_INPUT),
4741         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4742         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4743         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4744         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4745         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4746         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4747         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4748         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4749         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4750         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4751         { } /* end */
4752 };
4753
4754 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4755  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4756  */
4757 static struct snd_kcontrol_new alc260_will_mixer[] = {
4758         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4759         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4760         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4761         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4762         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4763         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4764         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4765         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4766         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4767         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4768         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4769         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4770         { } /* end */
4771 };
4772
4773 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4774  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4775  */
4776 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4777         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4778         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4779         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4780         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4781         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4782         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4783         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4784         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4785         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4786         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4787         { } /* end */
4788 };
4789
4790 /*
4791  * initialization verbs
4792  */
4793 static struct hda_verb alc260_init_verbs[] = {
4794         /* Line In pin widget for input */
4795         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4796         /* CD pin widget for input */
4797         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4798         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4799         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4800         /* Mic2 (front panel) pin widget for input and vref at 80% */
4801         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4802         /* LINE-2 is used for line-out in rear */
4803         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4804         /* select line-out */
4805         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4806         /* LINE-OUT pin */
4807         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4808         /* enable HP */
4809         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4810         /* enable Mono */
4811         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4812         /* mute capture amp left and right */
4813         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4814         /* set connection select to line in (default select for this ADC) */
4815         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4816         /* mute capture amp left and right */
4817         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4818         /* set connection select to line in (default select for this ADC) */
4819         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4820         /* set vol=0 Line-Out mixer amp left and right */
4821         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4822         /* unmute pin widget amp left and right (no gain on this amp) */
4823         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4824         /* set vol=0 HP mixer amp left and right */
4825         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4826         /* unmute pin widget amp left and right (no gain on this amp) */
4827         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4828         /* set vol=0 Mono mixer amp left and right */
4829         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4830         /* unmute pin widget amp left and right (no gain on this amp) */
4831         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4832         /* unmute LINE-2 out pin */
4833         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4834         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4835          * Line In 2 = 0x03
4836          */
4837         /* mute analog inputs */
4838         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4839         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4840         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4841         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4842         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4843         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4844         /* mute Front out path */
4845         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4846         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4847         /* mute Headphone out path */
4848         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4849         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4850         /* mute Mono out path */
4851         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4852         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4853         { }
4854 };
4855
4856 #if 0 /* should be identical with alc260_init_verbs? */
4857 static struct hda_verb alc260_hp_init_verbs[] = {
4858         /* Headphone and output */
4859         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4860         /* mono output */
4861         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4862         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4863         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4864         /* Mic2 (front panel) pin widget for input and vref at 80% */
4865         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4866         /* Line In pin widget for input */
4867         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4868         /* Line-2 pin widget for output */
4869         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4870         /* CD pin widget for input */
4871         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4872         /* unmute amp left and right */
4873         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4874         /* set connection select to line in (default select for this ADC) */
4875         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4876         /* unmute Line-Out mixer amp left and right (volume = 0) */
4877         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4878         /* mute pin widget amp left and right (no gain on this amp) */
4879         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4880         /* unmute HP mixer amp left and right (volume = 0) */
4881         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4882         /* mute pin widget amp left and right (no gain on this amp) */
4883         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4884         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4885          * Line In 2 = 0x03
4886          */
4887         /* mute analog inputs */
4888         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4889         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4890         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4891         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4892         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4893         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4894         /* Unmute Front out path */
4895         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4896         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4897         /* Unmute Headphone out path */
4898         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4899         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4900         /* Unmute Mono out path */
4901         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4902         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4903         { }
4904 };
4905 #endif
4906
4907 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4908         /* Line out and output */
4909         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4910         /* mono output */
4911         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4912         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4913         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4914         /* Mic2 (front panel) pin widget for input and vref at 80% */
4915         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4916         /* Line In pin widget for input */
4917         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4918         /* Headphone pin widget for output */
4919         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4920         /* CD pin widget for input */
4921         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4922         /* unmute amp left and right */
4923         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4924         /* set connection select to line in (default select for this ADC) */
4925         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4926         /* unmute Line-Out mixer amp left and right (volume = 0) */
4927         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4928         /* mute pin widget amp left and right (no gain on this amp) */
4929         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4930         /* unmute HP mixer amp left and right (volume = 0) */
4931         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4932         /* mute pin widget amp left and right (no gain on this amp) */
4933         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4934         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4935          * Line In 2 = 0x03
4936          */
4937         /* mute analog inputs */
4938         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4939         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4940         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4941         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4942         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4943         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4944         /* Unmute Front out path */
4945         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4946         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4947         /* Unmute Headphone out path */
4948         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4949         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4950         /* Unmute Mono out path */
4951         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4952         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4953         { }
4954 };
4955
4956 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4957  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4958  * audio = 0x16, internal speaker = 0x10.
4959  */
4960 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4961         /* Disable all GPIOs */
4962         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4963         /* Internal speaker is connected to headphone pin */
4964         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4965         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4966         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4967         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4968         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4969         /* Ensure all other unused pins are disabled and muted. */
4970         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4971         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4972         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4973         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4974         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4975         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4976         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4977         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4978
4979         /* Disable digital (SPDIF) pins */
4980         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4981         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4982
4983         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
4984          * when acting as an output.
4985          */
4986         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4987
4988         /* Start with output sum widgets muted and their output gains at min */
4989         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4990         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4991         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4992         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4993         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4994         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4995         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4996         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4997         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4998
4999         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5000         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5001         /* Unmute Line1 pin widget output buffer since it starts as an output.
5002          * If the pin mode is changed by the user the pin mode control will
5003          * take care of enabling the pin's input/output buffers as needed.
5004          * Therefore there's no need to enable the input buffer at this
5005          * stage.
5006          */
5007         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5008         /* Unmute input buffer of pin widget used for Line-in (no equiv
5009          * mixer ctrl)
5010          */
5011         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5012
5013         /* Mute capture amp left and right */
5014         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5015         /* Set ADC connection select to match default mixer setting - line
5016          * in (on mic1 pin)
5017          */
5018         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5019
5020         /* Do the same for the second ADC: mute capture input amp and
5021          * set ADC connection to line in (on mic1 pin)
5022          */
5023         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5024         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5025
5026         /* Mute all inputs to mixer widget (even unconnected ones) */
5027         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5028         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5029         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5030         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5031         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5032         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5033         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5034         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5035
5036         { }
5037 };
5038
5039 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5040  * similar laptops (adapted from Fujitsu init verbs).
5041  */
5042 static struct hda_verb alc260_acer_init_verbs[] = {
5043         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5044          * the headphone jack.  Turn this on and rely on the standard mute
5045          * methods whenever the user wants to turn these outputs off.
5046          */
5047         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5048         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5049         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5050         /* Internal speaker/Headphone jack is connected to Line-out pin */
5051         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5052         /* Internal microphone/Mic jack is connected to Mic1 pin */
5053         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5054         /* Line In jack is connected to Line1 pin */
5055         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5056         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5057         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5058         /* Ensure all other unused pins are disabled and muted. */
5059         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5060         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5061         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5062         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5063         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5064         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5065         /* Disable digital (SPDIF) pins */
5066         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5067         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5068
5069         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5070          * bus when acting as outputs.
5071          */
5072         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5073         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5074
5075         /* Start with output sum widgets muted and their output gains at min */
5076         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5077         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5078         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5079         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5080         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5081         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5082         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5083         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5084         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5085
5086         /* Unmute Line-out pin widget amp left and right
5087          * (no equiv mixer ctrl)
5088          */
5089         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5090         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5091         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5092         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5093          * inputs. If the pin mode is changed by the user the pin mode control
5094          * will take care of enabling the pin's input/output buffers as needed.
5095          * Therefore there's no need to enable the input buffer at this
5096          * stage.
5097          */
5098         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5099         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5100
5101         /* Mute capture amp left and right */
5102         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5103         /* Set ADC connection select to match default mixer setting - mic
5104          * (on mic1 pin)
5105          */
5106         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5107
5108         /* Do similar with the second ADC: mute capture input amp and
5109          * set ADC connection to mic to match ALSA's default state.
5110          */
5111         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5112         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5113
5114         /* Mute all inputs to mixer widget (even unconnected ones) */
5115         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5116         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5117         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5118         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5119         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5120         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5121         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5122         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5123
5124         { }
5125 };
5126
5127 static struct hda_verb alc260_will_verbs[] = {
5128         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5129         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5130         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5131         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5132         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5133         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5134         {}
5135 };
5136
5137 static struct hda_verb alc260_replacer_672v_verbs[] = {
5138         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5139         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5140         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5141
5142         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5143         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5144         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5145
5146         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5147         {}
5148 };
5149
5150 /* toggle speaker-output according to the hp-jack state */
5151 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5152 {
5153         unsigned int present;
5154
5155         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5156         present = snd_hda_codec_read(codec, 0x0f, 0,
5157                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5158         if (present) {
5159                 snd_hda_codec_write_cache(codec, 0x01, 0,
5160                                           AC_VERB_SET_GPIO_DATA, 1);
5161                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5162                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5163                                           PIN_HP);
5164         } else {
5165                 snd_hda_codec_write_cache(codec, 0x01, 0,
5166                                           AC_VERB_SET_GPIO_DATA, 0);
5167                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5168                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5169                                           PIN_OUT);
5170         }
5171 }
5172
5173 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5174                                        unsigned int res)
5175 {
5176         if ((res >> 26) == ALC880_HP_EVENT)
5177                 alc260_replacer_672v_automute(codec);
5178 }
5179
5180 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5181         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5182         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5183         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5184         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5185         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5186         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5187         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5188         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5189         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5190         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5191         {}
5192 };
5193
5194 /* Test configuration for debugging, modelled after the ALC880 test
5195  * configuration.
5196  */
5197 #ifdef CONFIG_SND_DEBUG
5198 static hda_nid_t alc260_test_dac_nids[1] = {
5199         0x02,
5200 };
5201 static hda_nid_t alc260_test_adc_nids[2] = {
5202         0x04, 0x05,
5203 };
5204 /* For testing the ALC260, each input MUX needs its own definition since
5205  * the signal assignments are different.  This assumes that the first ADC
5206  * is NID 0x04.
5207  */
5208 static struct hda_input_mux alc260_test_capture_sources[2] = {
5209         {
5210                 .num_items = 7,
5211                 .items = {
5212                         { "MIC1 pin", 0x0 },
5213                         { "MIC2 pin", 0x1 },
5214                         { "LINE1 pin", 0x2 },
5215                         { "LINE2 pin", 0x3 },
5216                         { "CD pin", 0x4 },
5217                         { "LINE-OUT pin", 0x5 },
5218                         { "HP-OUT pin", 0x6 },
5219                 },
5220         },
5221         {
5222                 .num_items = 8,
5223                 .items = {
5224                         { "MIC1 pin", 0x0 },
5225                         { "MIC2 pin", 0x1 },
5226                         { "LINE1 pin", 0x2 },
5227                         { "LINE2 pin", 0x3 },
5228                         { "CD pin", 0x4 },
5229                         { "Mixer", 0x5 },
5230                         { "LINE-OUT pin", 0x6 },
5231                         { "HP-OUT pin", 0x7 },
5232                 },
5233         },
5234 };
5235 static struct snd_kcontrol_new alc260_test_mixer[] = {
5236         /* Output driver widgets */
5237         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5238         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5239         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5240         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5241         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5242         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5243
5244         /* Modes for retasking pin widgets
5245          * Note: the ALC260 doesn't seem to act on requests to enable mic
5246          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5247          * mention this restriction.  At this stage it's not clear whether
5248          * this behaviour is intentional or is a hardware bug in chip
5249          * revisions available at least up until early 2006.  Therefore for
5250          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5251          * choices, but if it turns out that the lack of mic bias for these
5252          * NIDs is intentional we could change their modes from
5253          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5254          */
5255         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5256         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5257         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5258         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5259         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5260         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5261
5262         /* Loopback mixer controls */
5263         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5264         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5265         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5266         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5267         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5268         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5269         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5270         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5271         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5272         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5273         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
5274         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
5275         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5276         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5277         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5278         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5279
5280         /* Controls for GPIO pins, assuming they are configured as outputs */
5281         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5282         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5283         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5284         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5285
5286         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5287          * is ambigious as to which NID is which; testing on laptops which
5288          * make this output available should provide clarification.
5289          */
5290         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5291         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5292
5293         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5294          * this output to turn on an external amplifier.
5295          */
5296         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5297         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5298
5299         { } /* end */
5300 };
5301 static struct hda_verb alc260_test_init_verbs[] = {
5302         /* Enable all GPIOs as outputs with an initial value of 0 */
5303         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5304         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5305         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5306
5307         /* Enable retasking pins as output, initially without power amp */
5308         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5309         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5310         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5311         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5312         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5313         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5314
5315         /* Disable digital (SPDIF) pins initially, but users can enable
5316          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5317          * payload also sets the generation to 0, output to be in "consumer"
5318          * PCM format, copyright asserted, no pre-emphasis and no validity
5319          * control.
5320          */
5321         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5322         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5323
5324         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5325          * OUT1 sum bus when acting as an output.
5326          */
5327         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5328         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5329         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5330         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5331
5332         /* Start with output sum widgets muted and their output gains at min */
5333         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5334         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5335         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5336         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5337         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5338         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5339         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5340         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5341         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5342
5343         /* Unmute retasking pin widget output buffers since the default
5344          * state appears to be output.  As the pin mode is changed by the
5345          * user the pin mode control will take care of enabling the pin's
5346          * input/output buffers as needed.
5347          */
5348         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5349         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5350         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5351         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5352         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5353         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5354         /* Also unmute the mono-out pin widget */
5355         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5356
5357         /* Mute capture amp left and right */
5358         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5359         /* Set ADC connection select to match default mixer setting (mic1
5360          * pin)
5361          */
5362         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5363
5364         /* Do the same for the second ADC: mute capture input amp and
5365          * set ADC connection to mic1 pin
5366          */
5367         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5368         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5369
5370         /* Mute all inputs to mixer widget (even unconnected ones) */
5371         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5372         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5373         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5374         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5375         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5376         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5377         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5378         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5379
5380         { }
5381 };
5382 #endif
5383
5384 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5385 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5386
5387 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5388 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5389
5390 /*
5391  * for BIOS auto-configuration
5392  */
5393
5394 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5395                                         const char *pfx, int *vol_bits)
5396 {
5397         hda_nid_t nid_vol;
5398         unsigned long vol_val, sw_val;
5399         char name[32];
5400         int err;
5401
5402         if (nid >= 0x0f && nid < 0x11) {
5403                 nid_vol = nid - 0x7;
5404                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5405                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5406         } else if (nid == 0x11) {
5407                 nid_vol = nid - 0x7;
5408                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5409                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5410         } else if (nid >= 0x12 && nid <= 0x15) {
5411                 nid_vol = 0x08;
5412                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5413                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5414         } else
5415                 return 0; /* N/A */
5416
5417         if (!(*vol_bits & (1 << nid_vol))) {
5418                 /* first control for the volume widget */
5419                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5420                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5421                 if (err < 0)
5422                         return err;
5423                 *vol_bits |= (1 << nid_vol);
5424         }
5425         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5426         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5427         if (err < 0)
5428                 return err;
5429         return 1;
5430 }
5431
5432 /* add playback controls from the parsed DAC table */
5433 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5434                                              const struct auto_pin_cfg *cfg)
5435 {
5436         hda_nid_t nid;
5437         int err;
5438         int vols = 0;
5439
5440         spec->multiout.num_dacs = 1;
5441         spec->multiout.dac_nids = spec->private_dac_nids;
5442         spec->multiout.dac_nids[0] = 0x02;
5443
5444         nid = cfg->line_out_pins[0];
5445         if (nid) {
5446                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5447                 if (err < 0)
5448                         return err;
5449         }
5450
5451         nid = cfg->speaker_pins[0];
5452         if (nid) {
5453                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5454                 if (err < 0)
5455                         return err;
5456         }
5457
5458         nid = cfg->hp_pins[0];
5459         if (nid) {
5460                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5461                                                    &vols);
5462                 if (err < 0)
5463                         return err;
5464         }
5465         return 0;
5466 }
5467
5468 /* create playback/capture controls for input pins */
5469 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5470                                                 const struct auto_pin_cfg *cfg)
5471 {
5472         struct hda_input_mux *imux = &spec->private_imux;
5473         int i, err, idx;
5474
5475         for (i = 0; i < AUTO_PIN_LAST; i++) {
5476                 if (cfg->input_pins[i] >= 0x12) {
5477                         idx = cfg->input_pins[i] - 0x12;
5478                         err = new_analog_input(spec, cfg->input_pins[i],
5479                                                auto_pin_cfg_labels[i], idx,
5480                                                0x07);
5481                         if (err < 0)
5482                                 return err;
5483                         imux->items[imux->num_items].label =
5484                                 auto_pin_cfg_labels[i];
5485                         imux->items[imux->num_items].index = idx;
5486                         imux->num_items++;
5487                 }
5488                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5489                         idx = cfg->input_pins[i] - 0x09;
5490                         err = new_analog_input(spec, cfg->input_pins[i],
5491                                                auto_pin_cfg_labels[i], idx,
5492                                                0x07);
5493                         if (err < 0)
5494                                 return err;
5495                         imux->items[imux->num_items].label =
5496                                 auto_pin_cfg_labels[i];
5497                         imux->items[imux->num_items].index = idx;
5498                         imux->num_items++;
5499                 }
5500         }
5501         return 0;
5502 }
5503
5504 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5505                                               hda_nid_t nid, int pin_type,
5506                                               int sel_idx)
5507 {
5508         alc_set_pin_output(codec, nid, pin_type);
5509         /* need the manual connection? */
5510         if (nid >= 0x12) {
5511                 int idx = nid - 0x12;
5512                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5513                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5514         }
5515 }
5516
5517 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5518 {
5519         struct alc_spec *spec = codec->spec;
5520         hda_nid_t nid;
5521
5522         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5523         nid = spec->autocfg.line_out_pins[0];
5524         if (nid) {
5525                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5526                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5527         }
5528
5529         nid = spec->autocfg.speaker_pins[0];
5530         if (nid)
5531                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5532
5533         nid = spec->autocfg.hp_pins[0];
5534         if (nid)
5535                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5536 }
5537
5538 #define ALC260_PIN_CD_NID               0x16
5539 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5540 {
5541         struct alc_spec *spec = codec->spec;
5542         int i;
5543
5544         for (i = 0; i < AUTO_PIN_LAST; i++) {
5545                 hda_nid_t nid = spec->autocfg.input_pins[i];
5546                 if (nid >= 0x12) {
5547                         snd_hda_codec_write(codec, nid, 0,
5548                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5549                                             i <= AUTO_PIN_FRONT_MIC ?
5550                                             PIN_VREF80 : PIN_IN);
5551                         if (nid != ALC260_PIN_CD_NID)
5552                                 snd_hda_codec_write(codec, nid, 0,
5553                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5554                                                     AMP_OUT_MUTE);
5555                 }
5556         }
5557 }
5558
5559 /*
5560  * generic initialization of ADC, input mixers and output mixers
5561  */
5562 static struct hda_verb alc260_volume_init_verbs[] = {
5563         /*
5564          * Unmute ADC0-1 and set the default input to mic-in
5565          */
5566         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5567         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5568         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5569         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5570
5571         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5572          * mixer widget
5573          * Note: PASD motherboards uses the Line In 2 as the input for
5574          * front panel mic (mic 2)
5575          */
5576         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5577         /* mute analog inputs */
5578         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5579         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5580         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5581         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5582         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5583
5584         /*
5585          * Set up output mixers (0x08 - 0x0a)
5586          */
5587         /* set vol=0 to output mixers */
5588         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5589         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5590         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5591         /* set up input amps for analog loopback */
5592         /* Amp Indices: DAC = 0, mixer = 1 */
5593         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5594         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5595         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5596         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5597         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5598         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5599
5600         { }
5601 };
5602
5603 static int alc260_parse_auto_config(struct hda_codec *codec)
5604 {
5605         struct alc_spec *spec = codec->spec;
5606         int err;
5607         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5608
5609         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5610                                            alc260_ignore);
5611         if (err < 0)
5612                 return err;
5613         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5614         if (err < 0)
5615                 return err;
5616         if (!spec->kctls.list)
5617                 return 0; /* can't find valid BIOS pin config */
5618         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5619         if (err < 0)
5620                 return err;
5621
5622         spec->multiout.max_channels = 2;
5623
5624         if (spec->autocfg.dig_out_pin)
5625                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5626         if (spec->kctls.list)
5627                 add_mixer(spec, spec->kctls.list);
5628
5629         add_verb(spec, alc260_volume_init_verbs);
5630
5631         spec->num_mux_defs = 1;
5632         spec->input_mux = &spec->private_imux;
5633
5634         store_pin_configs(codec);
5635         return 1;
5636 }
5637
5638 /* additional initialization for auto-configuration model */
5639 static void alc260_auto_init(struct hda_codec *codec)
5640 {
5641         struct alc_spec *spec = codec->spec;
5642         alc260_auto_init_multi_out(codec);
5643         alc260_auto_init_analog_input(codec);
5644         if (spec->unsol_event)
5645                 alc_inithook(codec);
5646 }
5647
5648 #ifdef CONFIG_SND_HDA_POWER_SAVE
5649 static struct hda_amp_list alc260_loopbacks[] = {
5650         { 0x07, HDA_INPUT, 0 },
5651         { 0x07, HDA_INPUT, 1 },
5652         { 0x07, HDA_INPUT, 2 },
5653         { 0x07, HDA_INPUT, 3 },
5654         { 0x07, HDA_INPUT, 4 },
5655         { } /* end */
5656 };
5657 #endif
5658
5659 /*
5660  * ALC260 configurations
5661  */
5662 static const char *alc260_models[ALC260_MODEL_LAST] = {
5663         [ALC260_BASIC]          = "basic",
5664         [ALC260_HP]             = "hp",
5665         [ALC260_HP_3013]        = "hp-3013",
5666         [ALC260_HP_DC7600]      = "hp-dc7600",
5667         [ALC260_FUJITSU_S702X]  = "fujitsu",
5668         [ALC260_ACER]           = "acer",
5669         [ALC260_WILL]           = "will",
5670         [ALC260_REPLACER_672V]  = "replacer",
5671 #ifdef CONFIG_SND_DEBUG
5672         [ALC260_TEST]           = "test",
5673 #endif
5674         [ALC260_AUTO]           = "auto",
5675 };
5676
5677 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5678         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5679         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5680         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5681         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5682         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5683         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5684         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5685         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5686         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5687         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5688         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5689         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5690         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5691         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5692         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5693         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5694         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5695         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5696         {}
5697 };
5698
5699 static struct alc_config_preset alc260_presets[] = {
5700         [ALC260_BASIC] = {
5701                 .mixers = { alc260_base_output_mixer,
5702                             alc260_input_mixer,
5703                             alc260_pc_beep_mixer },
5704                 .init_verbs = { alc260_init_verbs },
5705                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5706                 .dac_nids = alc260_dac_nids,
5707                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5708                 .adc_nids = alc260_adc_nids,
5709                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5710                 .channel_mode = alc260_modes,
5711                 .input_mux = &alc260_capture_source,
5712         },
5713         [ALC260_HP] = {
5714                 .mixers = { alc260_hp_output_mixer,
5715                             alc260_input_mixer },
5716                 .init_verbs = { alc260_init_verbs,
5717                                 alc260_hp_unsol_verbs },
5718                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5719                 .dac_nids = alc260_dac_nids,
5720                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5721                 .adc_nids = alc260_adc_nids_alt,
5722                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5723                 .channel_mode = alc260_modes,
5724                 .input_mux = &alc260_capture_source,
5725                 .unsol_event = alc260_hp_unsol_event,
5726                 .init_hook = alc260_hp_automute,
5727         },
5728         [ALC260_HP_DC7600] = {
5729                 .mixers = { alc260_hp_dc7600_mixer,
5730                             alc260_input_mixer },
5731                 .init_verbs = { alc260_init_verbs,
5732                                 alc260_hp_dc7600_verbs },
5733                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5734                 .dac_nids = alc260_dac_nids,
5735                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5736                 .adc_nids = alc260_adc_nids_alt,
5737                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5738                 .channel_mode = alc260_modes,
5739                 .input_mux = &alc260_capture_source,
5740                 .unsol_event = alc260_hp_3012_unsol_event,
5741                 .init_hook = alc260_hp_3012_automute,
5742         },
5743         [ALC260_HP_3013] = {
5744                 .mixers = { alc260_hp_3013_mixer,
5745                             alc260_input_mixer },
5746                 .init_verbs = { alc260_hp_3013_init_verbs,
5747                                 alc260_hp_3013_unsol_verbs },
5748                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5749                 .dac_nids = alc260_dac_nids,
5750                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5751                 .adc_nids = alc260_adc_nids_alt,
5752                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5753                 .channel_mode = alc260_modes,
5754                 .input_mux = &alc260_capture_source,
5755                 .unsol_event = alc260_hp_3013_unsol_event,
5756                 .init_hook = alc260_hp_3013_automute,
5757         },
5758         [ALC260_FUJITSU_S702X] = {
5759                 .mixers = { alc260_fujitsu_mixer },
5760                 .init_verbs = { alc260_fujitsu_init_verbs },
5761                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5762                 .dac_nids = alc260_dac_nids,
5763                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5764                 .adc_nids = alc260_dual_adc_nids,
5765                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5766                 .channel_mode = alc260_modes,
5767                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5768                 .input_mux = alc260_fujitsu_capture_sources,
5769         },
5770         [ALC260_ACER] = {
5771                 .mixers = { alc260_acer_mixer },
5772                 .init_verbs = { alc260_acer_init_verbs },
5773                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5774                 .dac_nids = alc260_dac_nids,
5775                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5776                 .adc_nids = alc260_dual_adc_nids,
5777                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5778                 .channel_mode = alc260_modes,
5779                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5780                 .input_mux = alc260_acer_capture_sources,
5781         },
5782         [ALC260_WILL] = {
5783                 .mixers = { alc260_will_mixer },
5784                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5785                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5786                 .dac_nids = alc260_dac_nids,
5787                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5788                 .adc_nids = alc260_adc_nids,
5789                 .dig_out_nid = ALC260_DIGOUT_NID,
5790                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5791                 .channel_mode = alc260_modes,
5792                 .input_mux = &alc260_capture_source,
5793         },
5794         [ALC260_REPLACER_672V] = {
5795                 .mixers = { alc260_replacer_672v_mixer },
5796                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5797                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5798                 .dac_nids = alc260_dac_nids,
5799                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5800                 .adc_nids = alc260_adc_nids,
5801                 .dig_out_nid = ALC260_DIGOUT_NID,
5802                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5803                 .channel_mode = alc260_modes,
5804                 .input_mux = &alc260_capture_source,
5805                 .unsol_event = alc260_replacer_672v_unsol_event,
5806                 .init_hook = alc260_replacer_672v_automute,
5807         },
5808 #ifdef CONFIG_SND_DEBUG
5809         [ALC260_TEST] = {
5810                 .mixers = { alc260_test_mixer },
5811                 .init_verbs = { alc260_test_init_verbs },
5812                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5813                 .dac_nids = alc260_test_dac_nids,
5814                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5815                 .adc_nids = alc260_test_adc_nids,
5816                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5817                 .channel_mode = alc260_modes,
5818                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5819                 .input_mux = alc260_test_capture_sources,
5820         },
5821 #endif
5822 };
5823
5824 static int patch_alc260(struct hda_codec *codec)
5825 {
5826         struct alc_spec *spec;
5827         int err, board_config;
5828
5829         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5830         if (spec == NULL)
5831                 return -ENOMEM;
5832
5833         codec->spec = spec;
5834
5835         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5836                                                   alc260_models,
5837                                                   alc260_cfg_tbl);
5838         if (board_config < 0) {
5839                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5840                            "trying auto-probe from BIOS...\n");
5841                 board_config = ALC260_AUTO;
5842         }
5843
5844         if (board_config == ALC260_AUTO) {
5845                 /* automatic parse from the BIOS config */
5846                 err = alc260_parse_auto_config(codec);
5847                 if (err < 0) {
5848                         alc_free(codec);
5849                         return err;
5850                 } else if (!err) {
5851                         printk(KERN_INFO
5852                                "hda_codec: Cannot set up configuration "
5853                                "from BIOS.  Using base mode...\n");
5854                         board_config = ALC260_BASIC;
5855                 }
5856         }
5857
5858         if (board_config != ALC260_AUTO)
5859                 setup_preset(spec, &alc260_presets[board_config]);
5860
5861         spec->stream_name_analog = "ALC260 Analog";
5862         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5863         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5864
5865         spec->stream_name_digital = "ALC260 Digital";
5866         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5867         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5868
5869         if (!spec->adc_nids && spec->input_mux) {
5870                 /* check whether NID 0x04 is valid */
5871                 unsigned int wcap = get_wcaps(codec, 0x04);
5872                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5873                 /* get type */
5874                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5875                         spec->adc_nids = alc260_adc_nids_alt;
5876                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5877                 } else {
5878                         spec->adc_nids = alc260_adc_nids;
5879                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5880                 }
5881         }
5882         set_capture_mixer(spec);
5883
5884         spec->vmaster_nid = 0x08;
5885
5886         codec->patch_ops = alc_patch_ops;
5887         if (board_config == ALC260_AUTO)
5888                 spec->init_hook = alc260_auto_init;
5889 #ifdef CONFIG_SND_HDA_POWER_SAVE
5890         if (!spec->loopback.amplist)
5891                 spec->loopback.amplist = alc260_loopbacks;
5892 #endif
5893         codec->proc_widget_hook = print_realtek_coef;
5894
5895         return 0;
5896 }
5897
5898
5899 /*
5900  * ALC882 support
5901  *
5902  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5903  * configuration.  Each pin widget can choose any input DACs and a mixer.
5904  * Each ADC is connected from a mixer of all inputs.  This makes possible
5905  * 6-channel independent captures.
5906  *
5907  * In addition, an independent DAC for the multi-playback (not used in this
5908  * driver yet).
5909  */
5910 #define ALC882_DIGOUT_NID       0x06
5911 #define ALC882_DIGIN_NID        0x0a
5912
5913 static struct hda_channel_mode alc882_ch_modes[1] = {
5914         { 8, NULL }
5915 };
5916
5917 static hda_nid_t alc882_dac_nids[4] = {
5918         /* front, rear, clfe, rear_surr */
5919         0x02, 0x03, 0x04, 0x05
5920 };
5921
5922 /* identical with ALC880 */
5923 #define alc882_adc_nids         alc880_adc_nids
5924 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5925
5926 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5927 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5928
5929 /* input MUX */
5930 /* FIXME: should be a matrix-type input source selection */
5931
5932 static struct hda_input_mux alc882_capture_source = {
5933         .num_items = 4,
5934         .items = {
5935                 { "Mic", 0x0 },
5936                 { "Front Mic", 0x1 },
5937                 { "Line", 0x2 },
5938                 { "CD", 0x4 },
5939         },
5940 };
5941 /*
5942  * 2ch mode
5943  */
5944 static struct hda_verb alc882_3ST_ch2_init[] = {
5945         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5946         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5947         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5948         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5949         { } /* end */
5950 };
5951
5952 /*
5953  * 6ch mode
5954  */
5955 static struct hda_verb alc882_3ST_ch6_init[] = {
5956         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5957         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5958         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5959         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5960         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5961         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5962         { } /* end */
5963 };
5964
5965 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5966         { 2, alc882_3ST_ch2_init },
5967         { 6, alc882_3ST_ch6_init },
5968 };
5969
5970 /*
5971  * 6ch mode
5972  */
5973 static struct hda_verb alc882_sixstack_ch6_init[] = {
5974         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5975         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5976         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5977         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5978         { } /* end */
5979 };
5980
5981 /*
5982  * 8ch mode
5983  */
5984 static struct hda_verb alc882_sixstack_ch8_init[] = {
5985         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5986         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5987         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5988         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5989         { } /* end */
5990 };
5991
5992 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5993         { 6, alc882_sixstack_ch6_init },
5994         { 8, alc882_sixstack_ch8_init },
5995 };
5996
5997 /*
5998  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5999  */
6000
6001 /*
6002  * 2ch mode
6003  */
6004 static struct hda_verb alc885_mbp_ch2_init[] = {
6005         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6006         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6007         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6008         { } /* end */
6009 };
6010
6011 /*
6012  * 6ch mode
6013  */
6014 static struct hda_verb alc885_mbp_ch6_init[] = {
6015         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6016         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6017         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6018         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6019         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6020         { } /* end */
6021 };
6022
6023 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
6024         { 2, alc885_mbp_ch2_init },
6025         { 6, alc885_mbp_ch6_init },
6026 };
6027
6028
6029 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6030  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6031  */
6032 static struct snd_kcontrol_new alc882_base_mixer[] = {
6033         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6034         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6035         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6036         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6037         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6038         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6039         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6040         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6041         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6042         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6043         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6044         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6045         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6046         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6047         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6048         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6049         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6050         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6051         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6052         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6053         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6054         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6055         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6056         { } /* end */
6057 };
6058
6059 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6060         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6061         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6062         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
6063         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6064         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6065         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6066         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
6067         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
6068         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
6069         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
6070         { } /* end */
6071 };
6072 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6073         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6074         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6075         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6076         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6077         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6078         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6079         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6080         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6081         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6082         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6083         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6084         { } /* end */
6085 };
6086
6087 static struct snd_kcontrol_new alc882_targa_mixer[] = {
6088         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6089         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6090         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6091         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6092         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6093         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6094         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, 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         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6099         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6100         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6101         { } /* end */
6102 };
6103
6104 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
6105  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
6106  */
6107 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
6108         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6109         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6110         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6111         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
6112         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6113         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6114         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6115         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6116         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
6117         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
6118         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6119         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6120         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6121         { } /* end */
6122 };
6123
6124 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6125         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6126         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6127         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6128         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6129         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6130         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6131         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6132         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6133         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6134         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6135         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6136         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6137         { } /* end */
6138 };
6139
6140 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6141         {
6142                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6143                 .name = "Channel Mode",
6144                 .info = alc_ch_mode_info,
6145                 .get = alc_ch_mode_get,
6146                 .put = alc_ch_mode_put,
6147         },
6148         { } /* end */
6149 };
6150
6151 static struct hda_verb alc882_init_verbs[] = {
6152         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6153         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6154         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6155         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6156         /* Rear mixer */
6157         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6158         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6159         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6160         /* CLFE mixer */
6161         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6162         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6163         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6164         /* Side mixer */
6165         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6166         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6167         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6168
6169         /* Front Pin: output 0 (0x0c) */
6170         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6171         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6172         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6173         /* Rear Pin: output 1 (0x0d) */
6174         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6175         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6176         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6177         /* CLFE Pin: output 2 (0x0e) */
6178         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6179         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6180         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6181         /* Side Pin: output 3 (0x0f) */
6182         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6183         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6184         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6185         /* Mic (rear) pin: input vref at 80% */
6186         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6187         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6188         /* Front Mic pin: input vref at 80% */
6189         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6190         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6191         /* Line In pin: input */
6192         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6193         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6194         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6195         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6196         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6197         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6198         /* CD pin widget for input */
6199         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6200
6201         /* FIXME: use matrix-type input source selection */
6202         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6203         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6204         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6205         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6206         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6207         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6208         /* Input mixer2 */
6209         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6210         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6211         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6212         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6213         /* Input mixer3 */
6214         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6215         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6216         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6217         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6218         /* ADC1: mute amp left and right */
6219         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6220         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6221         /* ADC2: mute amp left and right */
6222         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6223         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6224         /* ADC3: mute amp left and right */
6225         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6226         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6227
6228         { }
6229 };
6230
6231 static struct hda_verb alc882_eapd_verbs[] = {
6232         /* change to EAPD mode */
6233         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6234         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
6235         { }
6236 };
6237
6238 /* Mac Pro test */
6239 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6240         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6241         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6242         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6243         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6244         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6245         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6246         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6247         { } /* end */
6248 };
6249
6250 static struct hda_verb alc882_macpro_init_verbs[] = {
6251         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6252         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6253         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6254         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6255         /* Front Pin: output 0 (0x0c) */
6256         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6257         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6258         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6259         /* Front Mic pin: input vref at 80% */
6260         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6261         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6262         /* Speaker:  output */
6263         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6264         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6265         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6266         /* Headphone output (output 0 - 0x0c) */
6267         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6268         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6269         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6270
6271         /* FIXME: use matrix-type input source selection */
6272         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6273         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6274         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6275         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6276         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6277         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6278         /* Input mixer2 */
6279         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6280         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6281         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6282         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6283         /* Input mixer3 */
6284         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6285         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6286         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6287         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6288         /* ADC1: mute amp left and right */
6289         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6290         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6291         /* ADC2: mute amp left and right */
6292         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6293         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6294         /* ADC3: mute amp left and right */
6295         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6296         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6297
6298         { }
6299 };
6300
6301 /* Macbook Pro rev3 */
6302 static struct hda_verb alc885_mbp3_init_verbs[] = {
6303         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6304         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6305         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6306         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6307         /* Rear mixer */
6308         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6309         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6310         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6311         /* Front Pin: output 0 (0x0c) */
6312         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6313         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6314         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6315         /* HP Pin: output 0 (0x0d) */
6316         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6317         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6318         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6319         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6320         /* Mic (rear) pin: input vref at 80% */
6321         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6322         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6323         /* Front Mic pin: input vref at 80% */
6324         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6325         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6326         /* Line In pin: use output 1 when in LineOut mode */
6327         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6328         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6329         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6330
6331         /* FIXME: use matrix-type input source selection */
6332         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6333         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6334         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6335         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6336         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6337         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6338         /* Input mixer2 */
6339         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6340         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6341         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6342         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6343         /* Input mixer3 */
6344         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6345         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6346         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6347         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6348         /* ADC1: mute amp left and right */
6349         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6350         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6351         /* ADC2: mute amp left and right */
6352         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6353         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6354         /* ADC3: mute amp left and right */
6355         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6356         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6357
6358         { }
6359 };
6360
6361 /* iMac 24 mixer. */
6362 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6363         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6364         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6365         { } /* end */
6366 };
6367
6368 /* iMac 24 init verbs. */
6369 static struct hda_verb alc885_imac24_init_verbs[] = {
6370         /* Internal speakers: output 0 (0x0c) */
6371         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6372         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6373         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6374         /* Internal speakers: output 0 (0x0c) */
6375         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6376         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6377         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6378         /* Headphone: output 0 (0x0c) */
6379         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6380         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6381         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6382         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6383         /* Front Mic: input vref at 80% */
6384         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6385         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6386         { }
6387 };
6388
6389 /* Toggle speaker-output according to the hp-jack state */
6390 static void alc885_imac24_automute(struct hda_codec *codec)
6391 {
6392         unsigned int present;
6393
6394         present = snd_hda_codec_read(codec, 0x14, 0,
6395                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6396         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6397                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6398         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6399                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6400 }
6401
6402 /* Processes unsolicited events. */
6403 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6404                                       unsigned int res)
6405 {
6406         /* Headphone insertion or removal. */
6407         if ((res >> 26) == ALC880_HP_EVENT)
6408                 alc885_imac24_automute(codec);
6409 }
6410
6411 static void alc885_mbp3_automute(struct hda_codec *codec)
6412 {
6413         unsigned int present;
6414
6415         present = snd_hda_codec_read(codec, 0x15, 0,
6416                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6417         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6418                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6419         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6420                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6421
6422 }
6423 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6424                                     unsigned int res)
6425 {
6426         /* Headphone insertion or removal. */
6427         if ((res >> 26) == ALC880_HP_EVENT)
6428                 alc885_mbp3_automute(codec);
6429 }
6430
6431
6432 static struct hda_verb alc882_targa_verbs[] = {
6433         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6434         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6435
6436         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6437         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6438
6439         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6440         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6441         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6442
6443         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6444         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6445         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6446         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6447         { } /* end */
6448 };
6449
6450 /* toggle speaker-output according to the hp-jack state */
6451 static void alc882_targa_automute(struct hda_codec *codec)
6452 {
6453         unsigned int present;
6454
6455         present = snd_hda_codec_read(codec, 0x14, 0,
6456                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6457         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6458                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6459         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6460                                   present ? 1 : 3);
6461 }
6462
6463 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6464 {
6465         /* Looks like the unsol event is incompatible with the standard
6466          * definition.  4bit tag is placed at 26 bit!
6467          */
6468         if (((res >> 26) == ALC880_HP_EVENT)) {
6469                 alc882_targa_automute(codec);
6470         }
6471 }
6472
6473 static struct hda_verb alc882_asus_a7j_verbs[] = {
6474         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6475         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6476
6477         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6478         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6479         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6480
6481         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6482         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6483         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6484
6485         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6486         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6487         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6488         { } /* end */
6489 };
6490
6491 static struct hda_verb alc882_asus_a7m_verbs[] = {
6492         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6493         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6494
6495         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6496         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6497         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6498
6499         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6500         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6501         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6502
6503         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6504         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6505         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6506         { } /* end */
6507 };
6508
6509 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6510 {
6511         unsigned int gpiostate, gpiomask, gpiodir;
6512
6513         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6514                                        AC_VERB_GET_GPIO_DATA, 0);
6515
6516         if (!muted)
6517                 gpiostate |= (1 << pin);
6518         else
6519                 gpiostate &= ~(1 << pin);
6520
6521         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6522                                       AC_VERB_GET_GPIO_MASK, 0);
6523         gpiomask |= (1 << pin);
6524
6525         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6526                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6527         gpiodir |= (1 << pin);
6528
6529
6530         snd_hda_codec_write(codec, codec->afg, 0,
6531                             AC_VERB_SET_GPIO_MASK, gpiomask);
6532         snd_hda_codec_write(codec, codec->afg, 0,
6533                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6534
6535         msleep(1);
6536
6537         snd_hda_codec_write(codec, codec->afg, 0,
6538                             AC_VERB_SET_GPIO_DATA, gpiostate);
6539 }
6540
6541 /* set up GPIO at initialization */
6542 static void alc885_macpro_init_hook(struct hda_codec *codec)
6543 {
6544         alc882_gpio_mute(codec, 0, 0);
6545         alc882_gpio_mute(codec, 1, 0);
6546 }
6547
6548 /* set up GPIO and update auto-muting at initialization */
6549 static void alc885_imac24_init_hook(struct hda_codec *codec)
6550 {
6551         alc885_macpro_init_hook(codec);
6552         alc885_imac24_automute(codec);
6553 }
6554
6555 /*
6556  * generic initialization of ADC, input mixers and output mixers
6557  */
6558 static struct hda_verb alc882_auto_init_verbs[] = {
6559         /*
6560          * Unmute ADC0-2 and set the default input to mic-in
6561          */
6562         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6563         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6564         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6565         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6566         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6567         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6568
6569         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6570          * mixer widget
6571          * Note: PASD motherboards uses the Line In 2 as the input for
6572          * front panel mic (mic 2)
6573          */
6574         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6575         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6576         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6577         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6578         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6579         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6580
6581         /*
6582          * Set up output mixers (0x0c - 0x0f)
6583          */
6584         /* set vol=0 to output mixers */
6585         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6586         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6587         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6588         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6589         /* set up input amps for analog loopback */
6590         /* Amp Indices: DAC = 0, mixer = 1 */
6591         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6592         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6593         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6594         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6595         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6596         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6597         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6598         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6599         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6600         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6601
6602         /* FIXME: use matrix-type input source selection */
6603         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6604         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6605         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6606         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6607         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6608         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6609         /* Input mixer2 */
6610         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6611         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6612         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6613         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6614         /* Input mixer3 */
6615         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6616         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6617         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6618         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6619
6620         { }
6621 };
6622
6623 #ifdef CONFIG_SND_HDA_POWER_SAVE
6624 #define alc882_loopbacks        alc880_loopbacks
6625 #endif
6626
6627 /* pcm configuration: identiacal with ALC880 */
6628 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6629 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6630 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6631 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6632
6633 /*
6634  * configuration and preset
6635  */
6636 static const char *alc882_models[ALC882_MODEL_LAST] = {
6637         [ALC882_3ST_DIG]        = "3stack-dig",
6638         [ALC882_6ST_DIG]        = "6stack-dig",
6639         [ALC882_ARIMA]          = "arima",
6640         [ALC882_W2JC]           = "w2jc",
6641         [ALC882_TARGA]          = "targa",
6642         [ALC882_ASUS_A7J]       = "asus-a7j",
6643         [ALC882_ASUS_A7M]       = "asus-a7m",
6644         [ALC885_MACPRO]         = "macpro",
6645         [ALC885_MBP3]           = "mbp3",
6646         [ALC885_IMAC24]         = "imac24",
6647         [ALC882_AUTO]           = "auto",
6648 };
6649
6650 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6651         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6652         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6653         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6654         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6655         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6656         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6657         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6658         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6659         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6660         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6661         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6662         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6663         {}
6664 };
6665
6666 static struct alc_config_preset alc882_presets[] = {
6667         [ALC882_3ST_DIG] = {
6668                 .mixers = { alc882_base_mixer },
6669                 .init_verbs = { alc882_init_verbs },
6670                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6671                 .dac_nids = alc882_dac_nids,
6672                 .dig_out_nid = ALC882_DIGOUT_NID,
6673                 .dig_in_nid = ALC882_DIGIN_NID,
6674                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6675                 .channel_mode = alc882_ch_modes,
6676                 .need_dac_fix = 1,
6677                 .input_mux = &alc882_capture_source,
6678         },
6679         [ALC882_6ST_DIG] = {
6680                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6681                 .init_verbs = { alc882_init_verbs },
6682                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6683                 .dac_nids = alc882_dac_nids,
6684                 .dig_out_nid = ALC882_DIGOUT_NID,
6685                 .dig_in_nid = ALC882_DIGIN_NID,
6686                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6687                 .channel_mode = alc882_sixstack_modes,
6688                 .input_mux = &alc882_capture_source,
6689         },
6690         [ALC882_ARIMA] = {
6691                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6692                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6693                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6694                 .dac_nids = alc882_dac_nids,
6695                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6696                 .channel_mode = alc882_sixstack_modes,
6697                 .input_mux = &alc882_capture_source,
6698         },
6699         [ALC882_W2JC] = {
6700                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6701                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6702                                 alc880_gpio1_init_verbs },
6703                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6704                 .dac_nids = alc882_dac_nids,
6705                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6706                 .channel_mode = alc880_threestack_modes,
6707                 .need_dac_fix = 1,
6708                 .input_mux = &alc882_capture_source,
6709                 .dig_out_nid = ALC882_DIGOUT_NID,
6710         },
6711         [ALC885_MBP3] = {
6712                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6713                 .init_verbs = { alc885_mbp3_init_verbs,
6714                                 alc880_gpio1_init_verbs },
6715                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6716                 .dac_nids = alc882_dac_nids,
6717                 .channel_mode = alc885_mbp_6ch_modes,
6718                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6719                 .input_mux = &alc882_capture_source,
6720                 .dig_out_nid = ALC882_DIGOUT_NID,
6721                 .dig_in_nid = ALC882_DIGIN_NID,
6722                 .unsol_event = alc885_mbp3_unsol_event,
6723                 .init_hook = alc885_mbp3_automute,
6724         },
6725         [ALC885_MACPRO] = {
6726                 .mixers = { alc882_macpro_mixer },
6727                 .init_verbs = { alc882_macpro_init_verbs },
6728                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6729                 .dac_nids = alc882_dac_nids,
6730                 .dig_out_nid = ALC882_DIGOUT_NID,
6731                 .dig_in_nid = ALC882_DIGIN_NID,
6732                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6733                 .channel_mode = alc882_ch_modes,
6734                 .input_mux = &alc882_capture_source,
6735                 .init_hook = alc885_macpro_init_hook,
6736         },
6737         [ALC885_IMAC24] = {
6738                 .mixers = { alc885_imac24_mixer },
6739                 .init_verbs = { alc885_imac24_init_verbs },
6740                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6741                 .dac_nids = alc882_dac_nids,
6742                 .dig_out_nid = ALC882_DIGOUT_NID,
6743                 .dig_in_nid = ALC882_DIGIN_NID,
6744                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6745                 .channel_mode = alc882_ch_modes,
6746                 .input_mux = &alc882_capture_source,
6747                 .unsol_event = alc885_imac24_unsol_event,
6748                 .init_hook = alc885_imac24_init_hook,
6749         },
6750         [ALC882_TARGA] = {
6751                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
6752                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6753                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6754                 .dac_nids = alc882_dac_nids,
6755                 .dig_out_nid = ALC882_DIGOUT_NID,
6756                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6757                 .adc_nids = alc882_adc_nids,
6758                 .capsrc_nids = alc882_capsrc_nids,
6759                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6760                 .channel_mode = alc882_3ST_6ch_modes,
6761                 .need_dac_fix = 1,
6762                 .input_mux = &alc882_capture_source,
6763                 .unsol_event = alc882_targa_unsol_event,
6764                 .init_hook = alc882_targa_automute,
6765         },
6766         [ALC882_ASUS_A7J] = {
6767                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
6768                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6769                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6770                 .dac_nids = alc882_dac_nids,
6771                 .dig_out_nid = ALC882_DIGOUT_NID,
6772                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6773                 .adc_nids = alc882_adc_nids,
6774                 .capsrc_nids = alc882_capsrc_nids,
6775                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6776                 .channel_mode = alc882_3ST_6ch_modes,
6777                 .need_dac_fix = 1,
6778                 .input_mux = &alc882_capture_source,
6779         },
6780         [ALC882_ASUS_A7M] = {
6781                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6782                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6783                                 alc880_gpio1_init_verbs,
6784                                 alc882_asus_a7m_verbs },
6785                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6786                 .dac_nids = alc882_dac_nids,
6787                 .dig_out_nid = ALC882_DIGOUT_NID,
6788                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6789                 .channel_mode = alc880_threestack_modes,
6790                 .need_dac_fix = 1,
6791                 .input_mux = &alc882_capture_source,
6792         },
6793 };
6794
6795
6796 /*
6797  * Pin config fixes
6798  */
6799 enum {
6800         PINFIX_ABIT_AW9D_MAX
6801 };
6802
6803 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6804         { 0x15, 0x01080104 }, /* side */
6805         { 0x16, 0x01011012 }, /* rear */
6806         { 0x17, 0x01016011 }, /* clfe */
6807         { }
6808 };
6809
6810 static const struct alc_pincfg *alc882_pin_fixes[] = {
6811         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6812 };
6813
6814 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6815         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6816         {}
6817 };
6818
6819 /*
6820  * BIOS auto configuration
6821  */
6822 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6823                                               hda_nid_t nid, int pin_type,
6824                                               int dac_idx)
6825 {
6826         /* set as output */
6827         struct alc_spec *spec = codec->spec;
6828         int idx;
6829
6830         alc_set_pin_output(codec, nid, pin_type);
6831         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6832                 idx = 4;
6833         else
6834                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6835         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6836
6837 }
6838
6839 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6840 {
6841         struct alc_spec *spec = codec->spec;
6842         int i;
6843
6844         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6845         for (i = 0; i <= HDA_SIDE; i++) {
6846                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6847                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6848                 if (nid)
6849                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6850                                                           i);
6851         }
6852 }
6853
6854 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6855 {
6856         struct alc_spec *spec = codec->spec;
6857         hda_nid_t pin;
6858
6859         pin = spec->autocfg.hp_pins[0];
6860         if (pin) /* connect to front */
6861                 /* use dac 0 */
6862                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6863         pin = spec->autocfg.speaker_pins[0];
6864         if (pin)
6865                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6866 }
6867
6868 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6869 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6870
6871 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6872 {
6873         struct alc_spec *spec = codec->spec;
6874         int i;
6875
6876         for (i = 0; i < AUTO_PIN_LAST; i++) {
6877                 hda_nid_t nid = spec->autocfg.input_pins[i];
6878                 unsigned int vref;
6879                 if (!nid)
6880                         continue;
6881                 vref = PIN_IN;
6882                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6883                         unsigned int pincap;
6884                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6885                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6886                             AC_PINCAP_VREF_80)
6887                                 vref = PIN_VREF80;
6888                 }
6889                 snd_hda_codec_write(codec, nid, 0,
6890                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6891                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6892                         snd_hda_codec_write(codec, nid, 0,
6893                                             AC_VERB_SET_AMP_GAIN_MUTE,
6894                                             AMP_OUT_MUTE);
6895         }
6896 }
6897
6898 static void alc882_auto_init_input_src(struct hda_codec *codec)
6899 {
6900         struct alc_spec *spec = codec->spec;
6901         const struct hda_input_mux *imux = spec->input_mux;
6902         int c;
6903
6904         for (c = 0; c < spec->num_adc_nids; c++) {
6905                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6906                 hda_nid_t nid = spec->capsrc_nids[c];
6907                 int conns, mute, idx, item;
6908
6909                 conns = snd_hda_get_connections(codec, nid, conn_list,
6910                                                 ARRAY_SIZE(conn_list));
6911                 if (conns < 0)
6912                         continue;
6913                 for (idx = 0; idx < conns; idx++) {
6914                         /* if the current connection is the selected one,
6915                          * unmute it as default - otherwise mute it
6916                          */
6917                         mute = AMP_IN_MUTE(idx);
6918                         for (item = 0; item < imux->num_items; item++) {
6919                                 if (imux->items[item].index == idx) {
6920                                         if (spec->cur_mux[c] == item)
6921                                                 mute = AMP_IN_UNMUTE(idx);
6922                                         break;
6923                                 }
6924                         }
6925                         snd_hda_codec_write(codec, nid, 0,
6926                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6927                 }
6928         }
6929 }
6930
6931 /* add mic boosts if needed */
6932 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6933 {
6934         struct alc_spec *spec = codec->spec;
6935         int err;
6936         hda_nid_t nid;
6937
6938         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6939         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6940                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6941                                   "Mic Boost",
6942                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6943                 if (err < 0)
6944                         return err;
6945         }
6946         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6947         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6948                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6949                                   "Front Mic Boost",
6950                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6951                 if (err < 0)
6952                         return err;
6953         }
6954         return 0;
6955 }
6956
6957 /* almost identical with ALC880 parser... */
6958 static int alc882_parse_auto_config(struct hda_codec *codec)
6959 {
6960         struct alc_spec *spec = codec->spec;
6961         int err = alc880_parse_auto_config(codec);
6962
6963         if (err < 0)
6964                 return err;
6965         else if (!err)
6966                 return 0; /* no config found */
6967
6968         err = alc_auto_add_mic_boost(codec);
6969         if (err < 0)
6970                 return err;
6971
6972         /* hack - override the init verbs */
6973         spec->init_verbs[0] = alc882_auto_init_verbs;
6974
6975         return 1; /* config found */
6976 }
6977
6978 /* additional initialization for auto-configuration model */
6979 static void alc882_auto_init(struct hda_codec *codec)
6980 {
6981         struct alc_spec *spec = codec->spec;
6982         alc882_auto_init_multi_out(codec);
6983         alc882_auto_init_hp_out(codec);
6984         alc882_auto_init_analog_input(codec);
6985         alc882_auto_init_input_src(codec);
6986         if (spec->unsol_event)
6987                 alc_inithook(codec);
6988 }
6989
6990 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6991
6992 static int patch_alc882(struct hda_codec *codec)
6993 {
6994         struct alc_spec *spec;
6995         int err, board_config;
6996
6997         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6998         if (spec == NULL)
6999                 return -ENOMEM;
7000
7001         codec->spec = spec;
7002
7003         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
7004                                                   alc882_models,
7005                                                   alc882_cfg_tbl);
7006
7007         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
7008                 /* Pick up systems that don't supply PCI SSID */
7009                 switch (codec->subsystem_id) {
7010                 case 0x106b0c00: /* Mac Pro */
7011                         board_config = ALC885_MACPRO;
7012                         break;
7013                 case 0x106b1000: /* iMac 24 */
7014                 case 0x106b2800: /* AppleTV */
7015                 case 0x106b3e00: /* iMac 24 Aluminium */
7016                         board_config = ALC885_IMAC24;
7017                         break;
7018                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
7019                 case 0x106b00a4: /* MacbookPro4,1 */
7020                 case 0x106b2c00: /* Macbook Pro rev3 */
7021                 case 0x106b3600: /* Macbook 3.1 */
7022                 case 0x106b3800: /* MacbookPro4,1 - latter revision */
7023                         board_config = ALC885_MBP3;
7024                         break;
7025                 default:
7026                         /* ALC889A is handled better as ALC888-compatible */
7027                         if (codec->revision_id == 0x100101 ||
7028                             codec->revision_id == 0x100103) {
7029                                 alc_free(codec);
7030                                 return patch_alc883(codec);
7031                         }
7032                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
7033                                          "trying auto-probe from BIOS...\n");
7034                         board_config = ALC882_AUTO;
7035                 }
7036         }
7037
7038         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7039
7040         if (board_config == ALC882_AUTO) {
7041                 /* automatic parse from the BIOS config */
7042                 err = alc882_parse_auto_config(codec);
7043                 if (err < 0) {
7044                         alc_free(codec);
7045                         return err;
7046                 } else if (!err) {
7047                         printk(KERN_INFO
7048                                "hda_codec: Cannot set up configuration "
7049                                "from BIOS.  Using base mode...\n");
7050                         board_config = ALC882_3ST_DIG;
7051                 }
7052         }
7053
7054         if (board_config != ALC882_AUTO)
7055                 setup_preset(spec, &alc882_presets[board_config]);
7056
7057         if (codec->vendor_id == 0x10ec0885) {
7058                 spec->stream_name_analog = "ALC885 Analog";
7059                 spec->stream_name_digital = "ALC885 Digital";
7060         } else {
7061                 spec->stream_name_analog = "ALC882 Analog";
7062                 spec->stream_name_digital = "ALC882 Digital";
7063         }
7064
7065         spec->stream_analog_playback = &alc882_pcm_analog_playback;
7066         spec->stream_analog_capture = &alc882_pcm_analog_capture;
7067         /* FIXME: setup DAC5 */
7068         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7069         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7070
7071         spec->stream_digital_playback = &alc882_pcm_digital_playback;
7072         spec->stream_digital_capture = &alc882_pcm_digital_capture;
7073
7074         spec->is_mix_capture = 1; /* matrix-style capture */
7075         if (!spec->adc_nids && spec->input_mux) {
7076                 /* check whether NID 0x07 is valid */
7077                 unsigned int wcap = get_wcaps(codec, 0x07);
7078                 /* get type */
7079                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7080                 if (wcap != AC_WID_AUD_IN) {
7081                         spec->adc_nids = alc882_adc_nids_alt;
7082                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7083                         spec->capsrc_nids = alc882_capsrc_nids_alt;
7084                 } else {
7085                         spec->adc_nids = alc882_adc_nids;
7086                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7087                         spec->capsrc_nids = alc882_capsrc_nids;
7088                 }
7089         }
7090         set_capture_mixer(spec);
7091
7092         spec->vmaster_nid = 0x0c;
7093
7094         codec->patch_ops = alc_patch_ops;
7095         if (board_config == ALC882_AUTO)
7096                 spec->init_hook = alc882_auto_init;
7097 #ifdef CONFIG_SND_HDA_POWER_SAVE
7098         if (!spec->loopback.amplist)
7099                 spec->loopback.amplist = alc882_loopbacks;
7100 #endif
7101         codec->proc_widget_hook = print_realtek_coef;
7102
7103         return 0;
7104 }
7105
7106 /*
7107  * ALC883 support
7108  *
7109  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7110  * configuration.  Each pin widget can choose any input DACs and a mixer.
7111  * Each ADC is connected from a mixer of all inputs.  This makes possible
7112  * 6-channel independent captures.
7113  *
7114  * In addition, an independent DAC for the multi-playback (not used in this
7115  * driver yet).
7116  */
7117 #define ALC883_DIGOUT_NID       0x06
7118 #define ALC883_DIGIN_NID        0x0a
7119
7120 #define ALC1200_DIGOUT_NID      0x10
7121
7122 static hda_nid_t alc883_dac_nids[4] = {
7123         /* front, rear, clfe, rear_surr */
7124         0x02, 0x03, 0x04, 0x05
7125 };
7126
7127 static hda_nid_t alc883_adc_nids[2] = {
7128         /* ADC1-2 */
7129         0x08, 0x09,
7130 };
7131
7132 static hda_nid_t alc883_adc_nids_alt[1] = {
7133         /* ADC1 */
7134         0x08,
7135 };
7136
7137 static hda_nid_t alc883_adc_nids_rev[2] = {
7138         /* ADC2-1 */
7139         0x09, 0x08
7140 };
7141
7142 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7143
7144 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7145
7146 /* input MUX */
7147 /* FIXME: should be a matrix-type input source selection */
7148
7149 static struct hda_input_mux alc883_capture_source = {
7150         .num_items = 4,
7151         .items = {
7152                 { "Mic", 0x0 },
7153                 { "Front Mic", 0x1 },
7154                 { "Line", 0x2 },
7155                 { "CD", 0x4 },
7156         },
7157 };
7158
7159 static struct hda_input_mux alc883_3stack_6ch_intel = {
7160         .num_items = 4,
7161         .items = {
7162                 { "Mic", 0x1 },
7163                 { "Front Mic", 0x0 },
7164                 { "Line", 0x2 },
7165                 { "CD", 0x4 },
7166         },
7167 };
7168
7169 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7170         .num_items = 2,
7171         .items = {
7172                 { "Mic", 0x1 },
7173                 { "Line", 0x2 },
7174         },
7175 };
7176
7177 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7178         .num_items = 4,
7179         .items = {
7180                 { "Mic", 0x0 },
7181                 { "iMic", 0x1 },
7182                 { "Line", 0x2 },
7183                 { "CD", 0x4 },
7184         },
7185 };
7186
7187 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7188         .num_items = 2,
7189         .items = {
7190                 { "Mic", 0x0 },
7191                 { "Int Mic", 0x1 },
7192         },
7193 };
7194
7195 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7196         .num_items = 3,
7197         .items = {
7198                 { "Mic", 0x0 },
7199                 { "Front Mic", 0x1 },
7200                 { "Line", 0x4 },
7201         },
7202 };
7203
7204 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7205         .num_items = 2,
7206         .items = {
7207                 { "Mic", 0x0 },
7208                 { "Line", 0x2 },
7209         },
7210 };
7211
7212 /*
7213  * 2ch mode
7214  */
7215 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7216         { 2, NULL }
7217 };
7218
7219 /*
7220  * 2ch mode
7221  */
7222 static struct hda_verb alc883_3ST_ch2_init[] = {
7223         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7224         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7225         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7226         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7227         { } /* end */
7228 };
7229
7230 /*
7231  * 4ch mode
7232  */
7233 static struct hda_verb alc883_3ST_ch4_init[] = {
7234         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7235         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7236         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7237         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7238         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7239         { } /* end */
7240 };
7241
7242 /*
7243  * 6ch mode
7244  */
7245 static struct hda_verb alc883_3ST_ch6_init[] = {
7246         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7247         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7248         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7249         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7250         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7251         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7252         { } /* end */
7253 };
7254
7255 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7256         { 2, alc883_3ST_ch2_init },
7257         { 4, alc883_3ST_ch4_init },
7258         { 6, alc883_3ST_ch6_init },
7259 };
7260
7261 /*
7262  * 2ch mode
7263  */
7264 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7265         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7266         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7267         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7268         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7269         { } /* end */
7270 };
7271
7272 /*
7273  * 4ch mode
7274  */
7275 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7276         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7277         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7278         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7279         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7280         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7281         { } /* end */
7282 };
7283
7284 /*
7285  * 6ch mode
7286  */
7287 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7288         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7289         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7290         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7291         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7292         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7293         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7294         { } /* end */
7295 };
7296
7297 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7298         { 2, alc883_3ST_ch2_intel_init },
7299         { 4, alc883_3ST_ch4_intel_init },
7300         { 6, alc883_3ST_ch6_intel_init },
7301 };
7302
7303 /*
7304  * 6ch mode
7305  */
7306 static struct hda_verb alc883_sixstack_ch6_init[] = {
7307         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7308         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7309         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7310         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7311         { } /* end */
7312 };
7313
7314 /*
7315  * 8ch mode
7316  */
7317 static struct hda_verb alc883_sixstack_ch8_init[] = {
7318         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7319         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7320         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7321         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7322         { } /* end */
7323 };
7324
7325 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7326         { 6, alc883_sixstack_ch6_init },
7327         { 8, alc883_sixstack_ch8_init },
7328 };
7329
7330 static struct hda_verb alc883_medion_eapd_verbs[] = {
7331         /* eanable EAPD on medion laptop */
7332         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7333         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7334         { }
7335 };
7336
7337 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7338  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7339  */
7340
7341 static struct snd_kcontrol_new alc883_base_mixer[] = {
7342         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7343         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7344         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7345         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7346         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7347         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7348         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7349         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7350         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7351         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7352         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7353         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7354         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7355         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7356         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7357         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7358         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7359         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7360         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7361         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7362         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7363         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7364         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7365         { } /* end */
7366 };
7367
7368 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7369         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7370         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7371         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7372         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7373         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7374         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7375         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7376         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7377         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7378         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7379         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7380         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7381         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7382         { } /* end */
7383 };
7384
7385 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7386         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7387         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7388         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7389         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7390         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7391         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7392         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7393         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7394         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7395         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7396         { } /* end */
7397 };
7398
7399 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7400         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7401         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7402         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7403         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7404         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7405         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7406         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7407         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7408         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7409         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7410         { } /* end */
7411 };
7412
7413 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7414         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7415         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7416         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7417         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7418         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7419         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7420         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7421         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7422         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7423         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7424         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7425         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7426         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7427         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7428         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7429         { } /* end */
7430 };
7431
7432 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7433         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7434         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7435         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7436         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7437         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, 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", 0x1b, 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, 0x0, HDA_INPUT),
7447         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7448         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7449         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7450         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7451         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, 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_3ST_6ch_intel_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,
7463                               HDA_OUTPUT),
7464         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7465         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7466         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7467         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7468         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7469         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7470         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7471         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7472         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7473         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7474         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7475         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7476         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7477         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7478         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7479         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7480         { } /* end */
7481 };
7482
7483 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7484         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7485         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
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_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7493         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7494         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7495         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7496         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7497         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7498         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7499         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7500         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7501         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7502         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7503         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7504         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7505         { } /* end */
7506 };
7507
7508 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7509         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7510         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7511         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7512         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7513         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7514         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7515         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7516         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7517         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7518         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7519         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7520         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7521         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7522         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7523         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7524         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7525         { } /* end */
7526 };
7527
7528 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7529         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7530         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7531         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7532         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7533         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7534         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7535         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7536         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7537         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7538         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7539         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7540         { } /* end */
7541 };
7542
7543 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7544         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7545         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7546         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7547         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7548         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7549         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7550         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7551         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7552         { } /* end */
7553 };
7554
7555 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7556         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7557         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7558         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7559         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7560         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7561         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7562         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7563         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7564         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7565         { } /* end */
7566 };
7567
7568 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7569         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7570         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7571         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7572         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7573         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7574         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7575         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7576         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7577         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7578         { } /* end */
7579 };
7580
7581 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7582         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7583         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7584         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7585         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7586         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7587         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7588         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7589         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7590         { } /* end */
7591 };
7592
7593 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7594         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7595         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7596         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7597         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7598         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7599                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7600         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7601         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7602         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7603         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7604         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7605         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7606         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7607         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7608         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7609         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7610         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7611         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7612         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7613         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7614         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7615         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7616         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7617         { } /* end */
7618 };
7619
7620 static struct hda_bind_ctls alc883_bind_cap_vol = {
7621         .ops = &snd_hda_bind_vol,
7622         .values = {
7623                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7624                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7625                 0
7626         },
7627 };
7628
7629 static struct hda_bind_ctls alc883_bind_cap_switch = {
7630         .ops = &snd_hda_bind_sw,
7631         .values = {
7632                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7633                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7634                 0
7635         },
7636 };
7637
7638 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7639         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7640         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7641         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7642         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7643         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7644         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7645         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7646         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7647         { } /* end */
7648 };
7649
7650 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
7651         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7652         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7653         {
7654                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7655                 /* .name = "Capture Source", */
7656                 .name = "Input Source",
7657                 .count = 1,
7658                 .info = alc_mux_enum_info,
7659                 .get = alc_mux_enum_get,
7660                 .put = alc_mux_enum_put,
7661         },
7662         { } /* end */
7663 };
7664
7665 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7666         {
7667                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7668                 .name = "Channel Mode",
7669                 .info = alc_ch_mode_info,
7670                 .get = alc_ch_mode_get,
7671                 .put = alc_ch_mode_put,
7672         },
7673         { } /* end */
7674 };
7675
7676 static struct hda_verb alc883_init_verbs[] = {
7677         /* ADC1: mute amp left and right */
7678         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7679         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7680         /* ADC2: mute amp left and right */
7681         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7682         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7683         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7684         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7685         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7686         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7687         /* Rear mixer */
7688         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7689         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7690         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7691         /* CLFE mixer */
7692         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7693         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7694         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7695         /* Side mixer */
7696         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7697         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7698         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7699
7700         /* mute analog input loopbacks */
7701         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7702         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7703         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7704         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7705         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7706
7707         /* Front Pin: output 0 (0x0c) */
7708         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7709         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7710         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7711         /* Rear Pin: output 1 (0x0d) */
7712         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7713         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7714         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7715         /* CLFE Pin: output 2 (0x0e) */
7716         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7717         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7718         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7719         /* Side Pin: output 3 (0x0f) */
7720         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7721         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7722         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7723         /* Mic (rear) pin: input vref at 80% */
7724         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7725         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7726         /* Front Mic pin: input vref at 80% */
7727         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7728         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7729         /* Line In pin: input */
7730         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7731         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7732         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7733         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7734         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7735         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7736         /* CD pin widget for input */
7737         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7738
7739         /* FIXME: use matrix-type input source selection */
7740         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7741         /* Input mixer2 */
7742         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7743         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7744         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7745         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7746         /* Input mixer3 */
7747         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7748         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7749         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7750         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7751         { }
7752 };
7753
7754 /* toggle speaker-output according to the hp-jack state */
7755 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7756 {
7757         unsigned int present;
7758
7759         present = snd_hda_codec_read(codec, 0x15, 0,
7760                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7761         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7762                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7763         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7764                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7765 }
7766
7767 /* auto-toggle front mic */
7768 /*
7769 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7770 {
7771         unsigned int present;
7772         unsigned char bits;
7773
7774         present = snd_hda_codec_read(codec, 0x18, 0,
7775                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7776         bits = present ? HDA_AMP_MUTE : 0;
7777         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7778 }
7779 */
7780
7781 static void alc883_mitac_automute(struct hda_codec *codec)
7782 {
7783         alc883_mitac_hp_automute(codec);
7784         /* alc883_mitac_mic_automute(codec); */
7785 }
7786
7787 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7788                                            unsigned int res)
7789 {
7790         switch (res >> 26) {
7791         case ALC880_HP_EVENT:
7792                 alc883_mitac_hp_automute(codec);
7793                 break;
7794         case ALC880_MIC_EVENT:
7795                 /* alc883_mitac_mic_automute(codec); */
7796                 break;
7797         }
7798 }
7799
7800 static struct hda_verb alc883_mitac_verbs[] = {
7801         /* HP */
7802         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7803         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7804         /* Subwoofer */
7805         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7806         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7807
7808         /* enable unsolicited event */
7809         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7810         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7811
7812         { } /* end */
7813 };
7814
7815 static struct hda_verb alc883_clevo_m720_verbs[] = {
7816         /* HP */
7817         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7818         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7819         /* Int speaker */
7820         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7821         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7822
7823         /* enable unsolicited event */
7824         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7825         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7826
7827         { } /* end */
7828 };
7829
7830 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7831         /* HP */
7832         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7833         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7834         /* Subwoofer */
7835         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7836         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7837
7838         /* enable unsolicited event */
7839         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7840
7841         { } /* end */
7842 };
7843
7844 static struct hda_verb alc883_tagra_verbs[] = {
7845         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7846         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7847
7848         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7849         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7850
7851         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7852         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7853         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7854
7855         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7856         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7857         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7858         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7859
7860         { } /* end */
7861 };
7862
7863 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7864         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7865         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7866         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7867         { } /* end */
7868 };
7869
7870 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7871         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7872         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7873         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7874         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7875         { } /* end */
7876 };
7877
7878 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7879         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7880         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7881         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7882         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7883         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7884         { } /* end */
7885 };
7886
7887 static struct hda_verb alc883_haier_w66_verbs[] = {
7888         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7889         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7890
7891         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7892
7893         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7894         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7895         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7896         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7897         { } /* end */
7898 };
7899
7900 static struct hda_verb alc888_lenovo_sky_verbs[] = {
7901         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7902         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7903         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7904         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7905         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7906         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7907         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7908         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7909         { } /* end */
7910 };
7911
7912 static struct hda_verb alc888_3st_hp_verbs[] = {
7913         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7914         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7915         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7916         { }
7917 };
7918
7919 static struct hda_verb alc888_6st_dell_verbs[] = {
7920         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7921         { }
7922 };
7923
7924 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7925         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7926         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7927         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7928         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7929         { }
7930 };
7931
7932 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7933         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7934         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7935         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7936         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7937         { }
7938 };
7939
7940 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7941         { 2, alc888_3st_hp_2ch_init },
7942         { 6, alc888_3st_hp_6ch_init },
7943 };
7944
7945 /* toggle front-jack and RCA according to the hp-jack state */
7946 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7947 {
7948         unsigned int present;
7949
7950         present = snd_hda_codec_read(codec, 0x1b, 0,
7951                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7952         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7953                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7954         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7955                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7956 }
7957
7958 /* toggle RCA according to the front-jack state */
7959 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7960 {
7961         unsigned int present;
7962
7963         present = snd_hda_codec_read(codec, 0x14, 0,
7964                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7965         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7966                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7967 }
7968
7969 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7970                                              unsigned int res)
7971 {
7972         if ((res >> 26) == ALC880_HP_EVENT)
7973                 alc888_lenovo_ms7195_front_automute(codec);
7974         if ((res >> 26) == ALC880_FRONT_EVENT)
7975                 alc888_lenovo_ms7195_rca_automute(codec);
7976 }
7977
7978 static struct hda_verb alc883_medion_md2_verbs[] = {
7979         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7980         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7981
7982         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7983
7984         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7985         { } /* end */
7986 };
7987
7988 /* toggle speaker-output according to the hp-jack state */
7989 static void alc883_medion_md2_automute(struct hda_codec *codec)
7990 {
7991         unsigned int present;
7992
7993         present = snd_hda_codec_read(codec, 0x14, 0,
7994                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7995         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7996                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7997 }
7998
7999 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
8000                                           unsigned int res)
8001 {
8002         if ((res >> 26) == ALC880_HP_EVENT)
8003                 alc883_medion_md2_automute(codec);
8004 }
8005
8006 /* toggle speaker-output according to the hp-jack state */
8007 static void alc883_tagra_automute(struct hda_codec *codec)
8008 {
8009         unsigned int present;
8010         unsigned char bits;
8011
8012         present = snd_hda_codec_read(codec, 0x14, 0,
8013                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8014         bits = present ? HDA_AMP_MUTE : 0;
8015         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8016                                  HDA_AMP_MUTE, bits);
8017         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
8018                                   present ? 1 : 3);
8019 }
8020
8021 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
8022 {
8023         if ((res >> 26) == ALC880_HP_EVENT)
8024                 alc883_tagra_automute(codec);
8025 }
8026
8027 /* toggle speaker-output according to the hp-jack state */
8028 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
8029 {
8030         unsigned int present;
8031         unsigned char bits;
8032
8033         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
8034                 & AC_PINSENSE_PRESENCE;
8035         bits = present ? HDA_AMP_MUTE : 0;
8036         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8037                                  HDA_AMP_MUTE, bits);
8038 }
8039
8040 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8041 {
8042         unsigned int present;
8043
8044         present = snd_hda_codec_read(codec, 0x18, 0,
8045                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8046         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8047                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8048 }
8049
8050 static void alc883_clevo_m720_automute(struct hda_codec *codec)
8051 {
8052         alc883_clevo_m720_hp_automute(codec);
8053         alc883_clevo_m720_mic_automute(codec);
8054 }
8055
8056 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8057                                            unsigned int res)
8058 {
8059         switch (res >> 26) {
8060         case ALC880_HP_EVENT:
8061                 alc883_clevo_m720_hp_automute(codec);
8062                 break;
8063         case ALC880_MIC_EVENT:
8064                 alc883_clevo_m720_mic_automute(codec);
8065                 break;
8066         }
8067 }
8068
8069 /* toggle speaker-output according to the hp-jack state */
8070 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
8071 {
8072         unsigned int present;
8073         unsigned char bits;
8074
8075         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8076                 & AC_PINSENSE_PRESENCE;
8077         bits = present ? HDA_AMP_MUTE : 0;
8078         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8079                                  HDA_AMP_MUTE, bits);
8080 }
8081
8082 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
8083                                                   unsigned int res)
8084 {
8085         if ((res >> 26) == ALC880_HP_EVENT)
8086                 alc883_2ch_fujitsu_pi2515_automute(codec);
8087 }
8088
8089 static void alc883_haier_w66_automute(struct hda_codec *codec)
8090 {
8091         unsigned int present;
8092         unsigned char bits;
8093
8094         present = snd_hda_codec_read(codec, 0x1b, 0,
8095                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8096         bits = present ? 0x80 : 0;
8097         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8098                                  0x80, bits);
8099 }
8100
8101 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
8102                                          unsigned int res)
8103 {
8104         if ((res >> 26) == ALC880_HP_EVENT)
8105                 alc883_haier_w66_automute(codec);
8106 }
8107
8108 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8109 {
8110         unsigned int present;
8111         unsigned char bits;
8112
8113         present = snd_hda_codec_read(codec, 0x14, 0,
8114                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8115         bits = present ? HDA_AMP_MUTE : 0;
8116         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8117                                  HDA_AMP_MUTE, bits);
8118 }
8119
8120 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8121 {
8122         unsigned int present;
8123         unsigned char bits;
8124
8125         present = snd_hda_codec_read(codec, 0x1b, 0,
8126                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8127         bits = present ? HDA_AMP_MUTE : 0;
8128         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8129                                  HDA_AMP_MUTE, bits);
8130         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8131                                  HDA_AMP_MUTE, bits);
8132 }
8133
8134 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8135                                            unsigned int res)
8136 {
8137         if ((res >> 26) == ALC880_HP_EVENT)
8138                 alc883_lenovo_101e_all_automute(codec);
8139         if ((res >> 26) == ALC880_FRONT_EVENT)
8140                 alc883_lenovo_101e_ispeaker_automute(codec);
8141 }
8142
8143 /* toggle speaker-output according to the hp-jack state */
8144 static void alc883_acer_aspire_automute(struct hda_codec *codec)
8145 {
8146         unsigned int present;
8147
8148         present = snd_hda_codec_read(codec, 0x14, 0,
8149                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8150         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8151                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8152         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8153                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8154 }
8155
8156 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
8157                                            unsigned int res)
8158 {
8159         if ((res >> 26) == ALC880_HP_EVENT)
8160                 alc883_acer_aspire_automute(codec);
8161 }
8162
8163 static struct hda_verb alc883_acer_eapd_verbs[] = {
8164         /* HP Pin: output 0 (0x0c) */
8165         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8166         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8167         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8168         /* Front Pin: output 0 (0x0c) */
8169         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8170         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8171         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8172         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8173         /* eanable EAPD on medion laptop */
8174         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8175         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8176         /* enable unsolicited event */
8177         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8178         { }
8179 };
8180
8181 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
8182 {
8183         unsigned int present;
8184
8185         present = snd_hda_codec_read(codec, 0x1b, 0,
8186                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8187         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8188                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8189         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8190                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8191         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8192                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8193         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8194                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8195 }
8196
8197 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8198                                              unsigned int res)
8199 {
8200         switch (res >> 26) {
8201         case ALC880_HP_EVENT:
8202                 printk("hp_event\n");
8203                 alc888_6st_dell_front_automute(codec);
8204                 break;
8205         }
8206 }
8207
8208 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8209 {
8210         unsigned int mute;
8211         unsigned int present;
8212
8213         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8214         present = snd_hda_codec_read(codec, 0x1b, 0,
8215                                      AC_VERB_GET_PIN_SENSE, 0);
8216         present = (present & 0x80000000) != 0;
8217         if (present) {
8218                 /* mute internal speaker */
8219                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8220                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8221                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8222                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8223                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8224                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8225                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8226                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8227                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8228                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8229         } else {
8230                 /* unmute internal speaker if necessary */
8231                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8232                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8233                                          HDA_AMP_MUTE, mute);
8234                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8235                                          HDA_AMP_MUTE, mute);
8236                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8237                                          HDA_AMP_MUTE, mute);
8238                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8239                                          HDA_AMP_MUTE, mute);
8240                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8241                                          HDA_AMP_MUTE, mute);
8242         }
8243 }
8244
8245 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8246                                              unsigned int res)
8247 {
8248         if ((res >> 26) == ALC880_HP_EVENT)
8249                 alc888_lenovo_sky_front_automute(codec);
8250 }
8251
8252 /*
8253  * generic initialization of ADC, input mixers and output mixers
8254  */
8255 static struct hda_verb alc883_auto_init_verbs[] = {
8256         /*
8257          * Unmute ADC0-2 and set the default input to mic-in
8258          */
8259         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8260         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8261         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8262         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8263
8264         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8265          * mixer widget
8266          * Note: PASD motherboards uses the Line In 2 as the input for
8267          * front panel mic (mic 2)
8268          */
8269         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8270         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8271         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8272         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8273         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8274         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8275
8276         /*
8277          * Set up output mixers (0x0c - 0x0f)
8278          */
8279         /* set vol=0 to output mixers */
8280         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8281         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8282         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8283         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8284         /* set up input amps for analog loopback */
8285         /* Amp Indices: DAC = 0, mixer = 1 */
8286         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8287         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8288         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8289         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8290         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8291         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8292         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8293         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8294         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8295         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8296
8297         /* FIXME: use matrix-type input source selection */
8298         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8299         /* Input mixer1 */
8300         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8301         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8302         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8303         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8304         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8305         /* Input mixer2 */
8306         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8307         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8308         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8309         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8310         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8311
8312         { }
8313 };
8314
8315 static struct hda_verb alc888_asus_m90v_verbs[] = {
8316         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8317         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8318         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8319         /* enable unsolicited event */
8320         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8321         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8322         { } /* end */
8323 };
8324
8325 static void alc883_nb_mic_automute(struct hda_codec *codec)
8326 {
8327         unsigned int present;
8328
8329         present = snd_hda_codec_read(codec, 0x18, 0,
8330                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8331         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8332                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8333         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8334                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8335 }
8336
8337 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8338 {
8339         unsigned int present;
8340         unsigned char bits;
8341
8342         present = snd_hda_codec_read(codec, 0x1b, 0,
8343                                      AC_VERB_GET_PIN_SENSE, 0)
8344                 & AC_PINSENSE_PRESENCE;
8345         bits = present ? 0 : PIN_OUT;
8346         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8347                             bits);
8348         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8349                             bits);
8350         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8351                             bits);
8352 }
8353
8354 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8355                                            unsigned int res)
8356 {
8357         switch (res >> 26) {
8358         case ALC880_HP_EVENT:
8359                 alc883_M90V_speaker_automute(codec);
8360                 break;
8361         case ALC880_MIC_EVENT:
8362                 alc883_nb_mic_automute(codec);
8363                 break;
8364         }
8365 }
8366
8367 static void alc883_mode2_inithook(struct hda_codec *codec)
8368 {
8369         alc883_M90V_speaker_automute(codec);
8370         alc883_nb_mic_automute(codec);
8371 }
8372
8373 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8374         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8375         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8376         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8377         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8378         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8379         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8380         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8381         /* enable unsolicited event */
8382         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8383         { } /* end */
8384 };
8385
8386 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8387 {
8388         unsigned int present;
8389         unsigned char bits;
8390
8391         present = snd_hda_codec_read(codec, 0x14, 0,
8392                                      AC_VERB_GET_PIN_SENSE, 0)
8393                 & AC_PINSENSE_PRESENCE;
8394         bits = present ? 0 : PIN_OUT;
8395         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8396                             bits);
8397 }
8398
8399 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8400                                            unsigned int res)
8401 {
8402         switch (res >> 26) {
8403         case ALC880_HP_EVENT:
8404                 alc883_eee1601_speaker_automute(codec);
8405                 break;
8406         }
8407 }
8408
8409 static void alc883_eee1601_inithook(struct hda_codec *codec)
8410 {
8411         alc883_eee1601_speaker_automute(codec);
8412 }
8413
8414 #ifdef CONFIG_SND_HDA_POWER_SAVE
8415 #define alc883_loopbacks        alc880_loopbacks
8416 #endif
8417
8418 /* pcm configuration: identiacal with ALC880 */
8419 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8420 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8421 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8422 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8423 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8424
8425 /*
8426  * configuration and preset
8427  */
8428 static const char *alc883_models[ALC883_MODEL_LAST] = {
8429         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8430         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8431         [ALC883_3ST_6ch]        = "3stack-6ch",
8432         [ALC883_6ST_DIG]        = "6stack-dig",
8433         [ALC883_TARGA_DIG]      = "targa-dig",
8434         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8435         [ALC883_ACER]           = "acer",
8436         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8437         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8438         [ALC883_MEDION]         = "medion",
8439         [ALC883_MEDION_MD2]     = "medion-md2",
8440         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8441         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8442         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8443         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8444         [ALC888_LENOVO_SKY] = "lenovo-sky",
8445         [ALC883_HAIER_W66]      = "haier-w66",
8446         [ALC888_3ST_HP]         = "3stack-hp",
8447         [ALC888_6ST_DELL]       = "6stack-dell",
8448         [ALC883_MITAC]          = "mitac",
8449         [ALC883_CLEVO_M720]     = "clevo-m720",
8450         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8451         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8452         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8453         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8454         [ALC883_AUTO]           = "auto",
8455 };
8456
8457 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8458         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8459         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8460         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8461         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8462         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8463         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8464         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8465                 ALC888_ACER_ASPIRE_4930G),
8466         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
8467                 ALC888_ACER_ASPIRE_4930G),
8468         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
8469                 ALC888_ACER_ASPIRE_4930G),
8470         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8471         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8472         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8473         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8474         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8475         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8476         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
8477         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8478         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8479         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8480         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8481         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8482         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8483         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
8484         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8485         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8486         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8487         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8488         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8489         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8490         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8491         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8492         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8493         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8494         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8495         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8496         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8497         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8498         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8499         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8500         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8501         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8502         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8503         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8504         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8505         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8506         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8507         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8508         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8509         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8510         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8511         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8512         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8513         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8514         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8515         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8516         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8517         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8518         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8519         SND_PCI_QUIRK(0x1734, 0x113d, "Fujitsu AMILO Xa3530",
8520                 ALC888_FUJITSU_XA3530),
8521         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8522         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8523         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8524         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8525         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8526         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8527         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8528         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8529         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8530         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8531         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8532         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
8533         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC883_3ST_6ch_INTEL),
8534         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8535         {}
8536 };
8537
8538 static struct alc_config_preset alc883_presets[] = {
8539         [ALC883_3ST_2ch_DIG] = {
8540                 .mixers = { alc883_3ST_2ch_mixer },
8541                 .init_verbs = { alc883_init_verbs },
8542                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8543                 .dac_nids = alc883_dac_nids,
8544                 .dig_out_nid = ALC883_DIGOUT_NID,
8545                 .dig_in_nid = ALC883_DIGIN_NID,
8546                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8547                 .channel_mode = alc883_3ST_2ch_modes,
8548                 .input_mux = &alc883_capture_source,
8549         },
8550         [ALC883_3ST_6ch_DIG] = {
8551                 .mixers = { alc883_3ST_6ch_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_3ST_6ch_modes),
8558                 .channel_mode = alc883_3ST_6ch_modes,
8559                 .need_dac_fix = 1,
8560                 .input_mux = &alc883_capture_source,
8561         },
8562         [ALC883_3ST_6ch] = {
8563                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8564                 .init_verbs = { alc883_init_verbs },
8565                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8566                 .dac_nids = alc883_dac_nids,
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         },
8572         [ALC883_3ST_6ch_INTEL] = {
8573                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8574                 .init_verbs = { alc883_init_verbs },
8575                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8576                 .dac_nids = alc883_dac_nids,
8577                 .dig_out_nid = ALC883_DIGOUT_NID,
8578                 .dig_in_nid = ALC883_DIGIN_NID,
8579                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8580                 .channel_mode = alc883_3ST_6ch_intel_modes,
8581                 .need_dac_fix = 1,
8582                 .input_mux = &alc883_3stack_6ch_intel,
8583         },
8584         [ALC883_6ST_DIG] = {
8585                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8586                 .init_verbs = { alc883_init_verbs },
8587                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8588                 .dac_nids = alc883_dac_nids,
8589                 .dig_out_nid = ALC883_DIGOUT_NID,
8590                 .dig_in_nid = ALC883_DIGIN_NID,
8591                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8592                 .channel_mode = alc883_sixstack_modes,
8593                 .input_mux = &alc883_capture_source,
8594         },
8595         [ALC883_TARGA_DIG] = {
8596                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8597                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8598                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8599                 .dac_nids = alc883_dac_nids,
8600                 .dig_out_nid = ALC883_DIGOUT_NID,
8601                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8602                 .channel_mode = alc883_3ST_6ch_modes,
8603                 .need_dac_fix = 1,
8604                 .input_mux = &alc883_capture_source,
8605                 .unsol_event = alc883_tagra_unsol_event,
8606                 .init_hook = alc883_tagra_automute,
8607         },
8608         [ALC883_TARGA_2ch_DIG] = {
8609                 .mixers = { alc883_tagra_2ch_mixer},
8610                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8611                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8612                 .dac_nids = alc883_dac_nids,
8613                 .adc_nids = alc883_adc_nids_alt,
8614                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8615                 .dig_out_nid = ALC883_DIGOUT_NID,
8616                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8617                 .channel_mode = alc883_3ST_2ch_modes,
8618                 .input_mux = &alc883_capture_source,
8619                 .unsol_event = alc883_tagra_unsol_event,
8620                 .init_hook = alc883_tagra_automute,
8621         },
8622         [ALC883_ACER] = {
8623                 .mixers = { alc883_base_mixer },
8624                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8625                  * and the headphone jack.  Turn this on and rely on the
8626                  * standard mute methods whenever the user wants to turn
8627                  * these outputs off.
8628                  */
8629                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8630                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8631                 .dac_nids = alc883_dac_nids,
8632                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8633                 .channel_mode = alc883_3ST_2ch_modes,
8634                 .input_mux = &alc883_capture_source,
8635         },
8636         [ALC883_ACER_ASPIRE] = {
8637                 .mixers = { alc883_acer_aspire_mixer },
8638                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8639                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8640                 .dac_nids = alc883_dac_nids,
8641                 .dig_out_nid = ALC883_DIGOUT_NID,
8642                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8643                 .channel_mode = alc883_3ST_2ch_modes,
8644                 .input_mux = &alc883_capture_source,
8645                 .unsol_event = alc883_acer_aspire_unsol_event,
8646                 .init_hook = alc883_acer_aspire_automute,
8647         },
8648         [ALC888_ACER_ASPIRE_4930G] = {
8649                 .mixers = { alc888_base_mixer,
8650                                 alc883_chmode_mixer },
8651                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
8652                                 alc888_acer_aspire_4930g_verbs },
8653                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8654                 .dac_nids = alc883_dac_nids,
8655                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8656                 .adc_nids = alc883_adc_nids_rev,
8657                 .capsrc_nids = alc883_capsrc_nids_rev,
8658                 .dig_out_nid = ALC883_DIGOUT_NID,
8659                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8660                 .channel_mode = alc883_3ST_6ch_modes,
8661                 .need_dac_fix = 1,
8662                 .num_mux_defs =
8663                         ARRAY_SIZE(alc888_2_capture_sources),
8664                 .input_mux = alc888_2_capture_sources,
8665                 .unsol_event = alc888_acer_aspire_4930g_unsol_event,
8666                 .init_hook = alc888_acer_aspire_4930g_automute,
8667         },
8668         [ALC883_MEDION] = {
8669                 .mixers = { alc883_fivestack_mixer,
8670                             alc883_chmode_mixer },
8671                 .init_verbs = { alc883_init_verbs,
8672                                 alc883_medion_eapd_verbs },
8673                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8674                 .dac_nids = alc883_dac_nids,
8675                 .adc_nids = alc883_adc_nids_alt,
8676                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8677                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8678                 .channel_mode = alc883_sixstack_modes,
8679                 .input_mux = &alc883_capture_source,
8680         },
8681         [ALC883_MEDION_MD2] = {
8682                 .mixers = { alc883_medion_md2_mixer},
8683                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8684                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8685                 .dac_nids = alc883_dac_nids,
8686                 .dig_out_nid = ALC883_DIGOUT_NID,
8687                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8688                 .channel_mode = alc883_3ST_2ch_modes,
8689                 .input_mux = &alc883_capture_source,
8690                 .unsol_event = alc883_medion_md2_unsol_event,
8691                 .init_hook = alc883_medion_md2_automute,
8692         },
8693         [ALC883_LAPTOP_EAPD] = {
8694                 .mixers = { alc883_base_mixer },
8695                 .init_verbs = { alc883_init_verbs, alc882_eapd_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                 .input_mux = &alc883_capture_source,
8701         },
8702         [ALC883_CLEVO_M720] = {
8703                 .mixers = { alc883_clevo_m720_mixer },
8704                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8705                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8706                 .dac_nids = alc883_dac_nids,
8707                 .dig_out_nid = ALC883_DIGOUT_NID,
8708                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8709                 .channel_mode = alc883_3ST_2ch_modes,
8710                 .input_mux = &alc883_capture_source,
8711                 .unsol_event = alc883_clevo_m720_unsol_event,
8712                 .init_hook = alc883_clevo_m720_automute,
8713         },
8714         [ALC883_LENOVO_101E_2ch] = {
8715                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8716                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8717                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8718                 .dac_nids = alc883_dac_nids,
8719                 .adc_nids = alc883_adc_nids_alt,
8720                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8721                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8722                 .channel_mode = alc883_3ST_2ch_modes,
8723                 .input_mux = &alc883_lenovo_101e_capture_source,
8724                 .unsol_event = alc883_lenovo_101e_unsol_event,
8725                 .init_hook = alc883_lenovo_101e_all_automute,
8726         },
8727         [ALC883_LENOVO_NB0763] = {
8728                 .mixers = { alc883_lenovo_nb0763_mixer },
8729                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8730                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8731                 .dac_nids = alc883_dac_nids,
8732                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8733                 .channel_mode = alc883_3ST_2ch_modes,
8734                 .need_dac_fix = 1,
8735                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8736                 .unsol_event = alc883_medion_md2_unsol_event,
8737                 .init_hook = alc883_medion_md2_automute,
8738         },
8739         [ALC888_LENOVO_MS7195_DIG] = {
8740                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8741                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8742                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8743                 .dac_nids = alc883_dac_nids,
8744                 .dig_out_nid = ALC883_DIGOUT_NID,
8745                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8746                 .channel_mode = alc883_3ST_6ch_modes,
8747                 .need_dac_fix = 1,
8748                 .input_mux = &alc883_capture_source,
8749                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8750                 .init_hook = alc888_lenovo_ms7195_front_automute,
8751         },
8752         [ALC883_HAIER_W66] = {
8753                 .mixers = { alc883_tagra_2ch_mixer},
8754                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8755                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8756                 .dac_nids = alc883_dac_nids,
8757                 .dig_out_nid = ALC883_DIGOUT_NID,
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_haier_w66_unsol_event,
8762                 .init_hook = alc883_haier_w66_automute,
8763         },
8764         [ALC888_3ST_HP] = {
8765                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8766                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8767                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8768                 .dac_nids = alc883_dac_nids,
8769                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8770                 .channel_mode = alc888_3st_hp_modes,
8771                 .need_dac_fix = 1,
8772                 .input_mux = &alc883_capture_source,
8773         },
8774         [ALC888_6ST_DELL] = {
8775                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8776                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8777                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8778                 .dac_nids = alc883_dac_nids,
8779                 .dig_out_nid = ALC883_DIGOUT_NID,
8780                 .dig_in_nid = ALC883_DIGIN_NID,
8781                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8782                 .channel_mode = alc883_sixstack_modes,
8783                 .input_mux = &alc883_capture_source,
8784                 .unsol_event = alc888_6st_dell_unsol_event,
8785                 .init_hook = alc888_6st_dell_front_automute,
8786         },
8787         [ALC883_MITAC] = {
8788                 .mixers = { alc883_mitac_mixer },
8789                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8790                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8791                 .dac_nids = alc883_dac_nids,
8792                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8793                 .channel_mode = alc883_3ST_2ch_modes,
8794                 .input_mux = &alc883_capture_source,
8795                 .unsol_event = alc883_mitac_unsol_event,
8796                 .init_hook = alc883_mitac_automute,
8797         },
8798         [ALC883_FUJITSU_PI2515] = {
8799                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8800                 .init_verbs = { alc883_init_verbs,
8801                                 alc883_2ch_fujitsu_pi2515_verbs},
8802                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8803                 .dac_nids = alc883_dac_nids,
8804                 .dig_out_nid = ALC883_DIGOUT_NID,
8805                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8806                 .channel_mode = alc883_3ST_2ch_modes,
8807                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8808                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8809                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8810         },
8811         [ALC888_FUJITSU_XA3530] = {
8812                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
8813                 .init_verbs = { alc883_init_verbs,
8814                         alc888_fujitsu_xa3530_verbs },
8815                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8816                 .dac_nids = alc883_dac_nids,
8817                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8818                 .adc_nids = alc883_adc_nids_rev,
8819                 .capsrc_nids = alc883_capsrc_nids_rev,
8820                 .dig_out_nid = ALC883_DIGOUT_NID,
8821                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
8822                 .channel_mode = alc888_4ST_8ch_intel_modes,
8823                 .num_mux_defs =
8824                         ARRAY_SIZE(alc888_2_capture_sources),
8825                 .input_mux = alc888_2_capture_sources,
8826                 .unsol_event = alc888_fujitsu_xa3530_unsol_event,
8827                 .init_hook = alc888_fujitsu_xa3530_automute,
8828         },
8829         [ALC888_LENOVO_SKY] = {
8830                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8831                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8832                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8833                 .dac_nids = alc883_dac_nids,
8834                 .dig_out_nid = ALC883_DIGOUT_NID,
8835                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8836                 .channel_mode = alc883_sixstack_modes,
8837                 .need_dac_fix = 1,
8838                 .input_mux = &alc883_lenovo_sky_capture_source,
8839                 .unsol_event = alc883_lenovo_sky_unsol_event,
8840                 .init_hook = alc888_lenovo_sky_front_automute,
8841         },
8842         [ALC888_ASUS_M90V] = {
8843                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8844                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8845                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8846                 .dac_nids = alc883_dac_nids,
8847                 .dig_out_nid = ALC883_DIGOUT_NID,
8848                 .dig_in_nid = ALC883_DIGIN_NID,
8849                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8850                 .channel_mode = alc883_3ST_6ch_modes,
8851                 .need_dac_fix = 1,
8852                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8853                 .unsol_event = alc883_mode2_unsol_event,
8854                 .init_hook = alc883_mode2_inithook,
8855         },
8856         [ALC888_ASUS_EEE1601] = {
8857                 .mixers = { alc883_asus_eee1601_mixer },
8858                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
8859                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8860                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8861                 .dac_nids = alc883_dac_nids,
8862                 .dig_out_nid = ALC883_DIGOUT_NID,
8863                 .dig_in_nid = ALC883_DIGIN_NID,
8864                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8865                 .channel_mode = alc883_3ST_2ch_modes,
8866                 .need_dac_fix = 1,
8867                 .input_mux = &alc883_asus_eee1601_capture_source,
8868                 .unsol_event = alc883_eee1601_unsol_event,
8869                 .init_hook = alc883_eee1601_inithook,
8870         },
8871         [ALC1200_ASUS_P5Q] = {
8872                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8873                 .init_verbs = { alc883_init_verbs },
8874                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8875                 .dac_nids = alc883_dac_nids,
8876                 .dig_out_nid = ALC1200_DIGOUT_NID,
8877                 .dig_in_nid = ALC883_DIGIN_NID,
8878                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8879                 .channel_mode = alc883_sixstack_modes,
8880                 .input_mux = &alc883_capture_source,
8881         },
8882 };
8883
8884
8885 /*
8886  * BIOS auto configuration
8887  */
8888 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8889                                               hda_nid_t nid, int pin_type,
8890                                               int dac_idx)
8891 {
8892         /* set as output */
8893         struct alc_spec *spec = codec->spec;
8894         int idx;
8895
8896         alc_set_pin_output(codec, nid, pin_type);
8897         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8898                 idx = 4;
8899         else
8900                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8901         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8902
8903 }
8904
8905 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8906 {
8907         struct alc_spec *spec = codec->spec;
8908         int i;
8909
8910         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8911         for (i = 0; i <= HDA_SIDE; i++) {
8912                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8913                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8914                 if (nid)
8915                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8916                                                           i);
8917         }
8918 }
8919
8920 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8921 {
8922         struct alc_spec *spec = codec->spec;
8923         hda_nid_t pin;
8924
8925         pin = spec->autocfg.hp_pins[0];
8926         if (pin) /* connect to front */
8927                 /* use dac 0 */
8928                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8929         pin = spec->autocfg.speaker_pins[0];
8930         if (pin)
8931                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8932 }
8933
8934 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8935 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8936
8937 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8938 {
8939         struct alc_spec *spec = codec->spec;
8940         int i;
8941
8942         for (i = 0; i < AUTO_PIN_LAST; i++) {
8943                 hda_nid_t nid = spec->autocfg.input_pins[i];
8944                 if (alc883_is_input_pin(nid)) {
8945                         snd_hda_codec_write(codec, nid, 0,
8946                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8947                                             (i <= AUTO_PIN_FRONT_MIC ?
8948                                              PIN_VREF80 : PIN_IN));
8949                         if (nid != ALC883_PIN_CD_NID)
8950                                 snd_hda_codec_write(codec, nid, 0,
8951                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8952                                                     AMP_OUT_MUTE);
8953                 }
8954         }
8955 }
8956
8957 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8958
8959 /* almost identical with ALC880 parser... */
8960 static int alc883_parse_auto_config(struct hda_codec *codec)
8961 {
8962         struct alc_spec *spec = codec->spec;
8963         int err = alc880_parse_auto_config(codec);
8964
8965         if (err < 0)
8966                 return err;
8967         else if (!err)
8968                 return 0; /* no config found */
8969
8970         err = alc_auto_add_mic_boost(codec);
8971         if (err < 0)
8972                 return err;
8973
8974         /* hack - override the init verbs */
8975         spec->init_verbs[0] = alc883_auto_init_verbs;
8976
8977         return 1; /* config found */
8978 }
8979
8980 /* additional initialization for auto-configuration model */
8981 static void alc883_auto_init(struct hda_codec *codec)
8982 {
8983         struct alc_spec *spec = codec->spec;
8984         alc883_auto_init_multi_out(codec);
8985         alc883_auto_init_hp_out(codec);
8986         alc883_auto_init_analog_input(codec);
8987         alc883_auto_init_input_src(codec);
8988         if (spec->unsol_event)
8989                 alc_inithook(codec);
8990 }
8991
8992 static int patch_alc883(struct hda_codec *codec)
8993 {
8994         struct alc_spec *spec;
8995         int err, board_config;
8996
8997         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8998         if (spec == NULL)
8999                 return -ENOMEM;
9000
9001         codec->spec = spec;
9002
9003         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9004
9005         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
9006                                                   alc883_models,
9007                                                   alc883_cfg_tbl);
9008         if (board_config < 0) {
9009                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
9010                        "trying auto-probe from BIOS...\n");
9011                 board_config = ALC883_AUTO;
9012         }
9013
9014         if (board_config == ALC883_AUTO) {
9015                 /* automatic parse from the BIOS config */
9016                 err = alc883_parse_auto_config(codec);
9017                 if (err < 0) {
9018                         alc_free(codec);
9019                         return err;
9020                 } else if (!err) {
9021                         printk(KERN_INFO
9022                                "hda_codec: Cannot set up configuration "
9023                                "from BIOS.  Using base mode...\n");
9024                         board_config = ALC883_3ST_2ch_DIG;
9025                 }
9026         }
9027
9028         if (board_config != ALC883_AUTO)
9029                 setup_preset(spec, &alc883_presets[board_config]);
9030
9031         switch (codec->vendor_id) {
9032         case 0x10ec0888:
9033                 if (codec->revision_id == 0x100101) {
9034                         spec->stream_name_analog = "ALC1200 Analog";
9035                         spec->stream_name_digital = "ALC1200 Digital";
9036                 } else {
9037                         spec->stream_name_analog = "ALC888 Analog";
9038                         spec->stream_name_digital = "ALC888 Digital";
9039                 }
9040                 break;
9041         case 0x10ec0889:
9042                 spec->stream_name_analog = "ALC889 Analog";
9043                 spec->stream_name_digital = "ALC889 Digital";
9044                 break;
9045         default:
9046                 spec->stream_name_analog = "ALC883 Analog";
9047                 spec->stream_name_digital = "ALC883 Digital";
9048                 break;
9049         }
9050
9051         spec->stream_analog_playback = &alc883_pcm_analog_playback;
9052         spec->stream_analog_capture = &alc883_pcm_analog_capture;
9053         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9054
9055         spec->stream_digital_playback = &alc883_pcm_digital_playback;
9056         spec->stream_digital_capture = &alc883_pcm_digital_capture;
9057
9058         if (!spec->num_adc_nids) {
9059                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9060                 spec->adc_nids = alc883_adc_nids;
9061         }
9062         if (!spec->capsrc_nids)
9063                 spec->capsrc_nids = alc883_capsrc_nids;
9064         spec->is_mix_capture = 1; /* matrix-style capture */
9065         if (!spec->cap_mixer)
9066                 set_capture_mixer(spec);
9067
9068         spec->vmaster_nid = 0x0c;
9069
9070         codec->patch_ops = alc_patch_ops;
9071         if (board_config == ALC883_AUTO)
9072                 spec->init_hook = alc883_auto_init;
9073
9074 #ifdef CONFIG_SND_HDA_POWER_SAVE
9075         if (!spec->loopback.amplist)
9076                 spec->loopback.amplist = alc883_loopbacks;
9077 #endif
9078         codec->proc_widget_hook = print_realtek_coef;
9079
9080         return 0;
9081 }
9082
9083 /*
9084  * ALC262 support
9085  */
9086
9087 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9088 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9089
9090 #define alc262_dac_nids         alc260_dac_nids
9091 #define alc262_adc_nids         alc882_adc_nids
9092 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9093 #define alc262_capsrc_nids      alc882_capsrc_nids
9094 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9095
9096 #define alc262_modes            alc260_modes
9097 #define alc262_capture_source   alc882_capture_source
9098
9099 static hda_nid_t alc262_dmic_adc_nids[1] = {
9100         /* ADC0 */
9101         0x09
9102 };
9103
9104 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9105
9106 static struct snd_kcontrol_new alc262_base_mixer[] = {
9107         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9108         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9109         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9110         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9111         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9112         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9113         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9114         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9115         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9116         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9117         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9118         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9119         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9120            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9121         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9122         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9123         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9124         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9125         { } /* end */
9126 };
9127
9128 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
9129         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9130         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9131         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9132         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9133         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9134         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9135         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9136         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9137         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9138         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9139         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9140         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9141         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9142            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9143         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
9144         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9145         { } /* end */
9146 };
9147
9148 /* update HP, line and mono-out pins according to the master switch */
9149 static void alc262_hp_master_update(struct hda_codec *codec)
9150 {
9151         struct alc_spec *spec = codec->spec;
9152         int val = spec->master_sw;
9153
9154         /* HP & line-out */
9155         snd_hda_codec_write_cache(codec, 0x1b, 0,
9156                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9157                                   val ? PIN_HP : 0);
9158         snd_hda_codec_write_cache(codec, 0x15, 0,
9159                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9160                                   val ? PIN_HP : 0);
9161         /* mono (speaker) depending on the HP jack sense */
9162         val = val && !spec->jack_present;
9163         snd_hda_codec_write_cache(codec, 0x16, 0,
9164                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9165                                   val ? PIN_OUT : 0);
9166 }
9167
9168 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9169 {
9170         struct alc_spec *spec = codec->spec;
9171         unsigned int presence;
9172         presence = snd_hda_codec_read(codec, 0x1b, 0,
9173                                       AC_VERB_GET_PIN_SENSE, 0);
9174         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9175         alc262_hp_master_update(codec);
9176 }
9177
9178 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9179 {
9180         if ((res >> 26) != ALC880_HP_EVENT)
9181                 return;
9182         alc262_hp_bpc_automute(codec);
9183 }
9184
9185 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9186 {
9187         struct alc_spec *spec = codec->spec;
9188         unsigned int presence;
9189         presence = snd_hda_codec_read(codec, 0x15, 0,
9190                                       AC_VERB_GET_PIN_SENSE, 0);
9191         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9192         alc262_hp_master_update(codec);
9193 }
9194
9195 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9196                                            unsigned int res)
9197 {
9198         if ((res >> 26) != ALC880_HP_EVENT)
9199                 return;
9200         alc262_hp_wildwest_automute(codec);
9201 }
9202
9203 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
9204                                    struct snd_ctl_elem_value *ucontrol)
9205 {
9206         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9207         struct alc_spec *spec = codec->spec;
9208         *ucontrol->value.integer.value = spec->master_sw;
9209         return 0;
9210 }
9211
9212 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9213                                    struct snd_ctl_elem_value *ucontrol)
9214 {
9215         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9216         struct alc_spec *spec = codec->spec;
9217         int val = !!*ucontrol->value.integer.value;
9218
9219         if (val == spec->master_sw)
9220                 return 0;
9221         spec->master_sw = val;
9222         alc262_hp_master_update(codec);
9223         return 1;
9224 }
9225
9226 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9227         {
9228                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9229                 .name = "Master Playback Switch",
9230                 .info = snd_ctl_boolean_mono_info,
9231                 .get = alc262_hp_master_sw_get,
9232                 .put = alc262_hp_master_sw_put,
9233         },
9234         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9235         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9236         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9237         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9238                               HDA_OUTPUT),
9239         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9240                             HDA_OUTPUT),
9241         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9242         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9243         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9244         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9245         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9246         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9247         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9248         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9249         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9250         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9251         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9252         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9253         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9254         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9255         { } /* end */
9256 };
9257
9258 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9259         {
9260                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9261                 .name = "Master Playback Switch",
9262                 .info = snd_ctl_boolean_mono_info,
9263                 .get = alc262_hp_master_sw_get,
9264                 .put = alc262_hp_master_sw_put,
9265         },
9266         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9267         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9268         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9269         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9270         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9271                               HDA_OUTPUT),
9272         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9273                             HDA_OUTPUT),
9274         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9275         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9276         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9277         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9278         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9279         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9280         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9281         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9282         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9283         { } /* end */
9284 };
9285
9286 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9287         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9288         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9289         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9290         { } /* end */
9291 };
9292
9293 /* mute/unmute internal speaker according to the hp jack and mute state */
9294 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
9295 {
9296         struct alc_spec *spec = codec->spec;
9297
9298         if (force || !spec->sense_updated) {
9299                 unsigned int present;
9300                 present = snd_hda_codec_read(codec, 0x15, 0,
9301                                              AC_VERB_GET_PIN_SENSE, 0);
9302                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9303                 spec->sense_updated = 1;
9304         }
9305         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
9306                                  spec->jack_present ? HDA_AMP_MUTE : 0);
9307 }
9308
9309 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
9310                                         unsigned int res)
9311 {
9312         if ((res >> 26) != ALC880_HP_EVENT)
9313                 return;
9314         alc262_hp_t5735_automute(codec, 1);
9315 }
9316
9317 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9318 {
9319         alc262_hp_t5735_automute(codec, 1);
9320 }
9321
9322 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9323         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9324         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9325         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9326         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9327         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9328         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9329         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9330         { } /* end */
9331 };
9332
9333 static struct hda_verb alc262_hp_t5735_verbs[] = {
9334         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9335         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9336
9337         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9338         { }
9339 };
9340
9341 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9342         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9343         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9344         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9345         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9346         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9347         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9348         { } /* end */
9349 };
9350
9351 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9352         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9353         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9354         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9355         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9356         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9357         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9358         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9359         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9360         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9361         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9362         {}
9363 };
9364
9365 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9366         .num_items = 1,
9367         .items = {
9368                 { "Line", 0x1 },
9369         },
9370 };
9371
9372 /* bind hp and internal speaker mute (with plug check) */
9373 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9374                                      struct snd_ctl_elem_value *ucontrol)
9375 {
9376         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9377         long *valp = ucontrol->value.integer.value;
9378         int change;
9379
9380         /* change hp mute */
9381         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9382                                           HDA_AMP_MUTE,
9383                                           valp[0] ? 0 : HDA_AMP_MUTE);
9384         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9385                                            HDA_AMP_MUTE,
9386                                            valp[1] ? 0 : HDA_AMP_MUTE);
9387         if (change) {
9388                 /* change speaker according to HP jack state */
9389                 struct alc_spec *spec = codec->spec;
9390                 unsigned int mute;
9391                 if (spec->jack_present)
9392                         mute = HDA_AMP_MUTE;
9393                 else
9394                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9395                                                       HDA_OUTPUT, 0);
9396                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9397                                          HDA_AMP_MUTE, mute);
9398         }
9399         return change;
9400 }
9401
9402 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9403         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9404         {
9405                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9406                 .name = "Master Playback Switch",
9407                 .info = snd_hda_mixer_amp_switch_info,
9408                 .get = snd_hda_mixer_amp_switch_get,
9409                 .put = alc262_sony_master_sw_put,
9410                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9411         },
9412         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9413         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9414         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9415         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9416         { } /* end */
9417 };
9418
9419 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9420         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9421         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9422         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9423         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9424         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9425         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9426         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9427         { } /* end */
9428 };
9429
9430 #define alc262_capture_mixer            alc882_capture_mixer
9431 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9432
9433 /*
9434  * generic initialization of ADC, input mixers and output mixers
9435  */
9436 static struct hda_verb alc262_init_verbs[] = {
9437         /*
9438          * Unmute ADC0-2 and set the default input to mic-in
9439          */
9440         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9441         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9442         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9443         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9444         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9445         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9446
9447         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9448          * mixer widget
9449          * Note: PASD motherboards uses the Line In 2 as the input for
9450          * front panel mic (mic 2)
9451          */
9452         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9453         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9454         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9455         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9456         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9457         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9458
9459         /*
9460          * Set up output mixers (0x0c - 0x0e)
9461          */
9462         /* set vol=0 to output mixers */
9463         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9464         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9465         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9466         /* set up input amps for analog loopback */
9467         /* Amp Indices: DAC = 0, mixer = 1 */
9468         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9469         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9470         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9471         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9472         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9473         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9474
9475         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9476         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9477         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9478         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9479         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9480         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9481
9482         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9483         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9484         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9485         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9486         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9487
9488         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9489         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9490
9491         /* FIXME: use matrix-type input source selection */
9492         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9493         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9494         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9495         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9496         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9497         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9498         /* Input mixer2 */
9499         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9500         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9501         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9502         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9503         /* Input mixer3 */
9504         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9505         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9506         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9507         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9508
9509         { }
9510 };
9511
9512 static struct hda_verb alc262_eapd_verbs[] = {
9513         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9514         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9515         { }
9516 };
9517
9518 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9519         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9520         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9521         {}
9522 };
9523
9524 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9525         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9526         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9527         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9528
9529         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9530         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9531         {}
9532 };
9533
9534 static struct hda_verb alc262_sony_unsol_verbs[] = {
9535         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9536         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9537         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9538
9539         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9540         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9541         {}
9542 };
9543
9544 static struct hda_input_mux alc262_dmic_capture_source = {
9545         .num_items = 2,
9546         .items = {
9547                 { "Int DMic", 0x9 },
9548                 { "Mic", 0x0 },
9549         },
9550 };
9551
9552 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9553         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9554         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9555         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9556         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9557         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9558         { } /* end */
9559 };
9560
9561 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9562         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9563         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9564         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9565         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9566         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9567         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9568         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9569         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9570         {}
9571 };
9572
9573 static void alc262_dmic_automute(struct hda_codec *codec)
9574 {
9575         unsigned int present;
9576
9577         present = snd_hda_codec_read(codec, 0x18, 0,
9578                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9579         snd_hda_codec_write(codec, 0x22, 0,
9580                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9581 }
9582
9583 /* toggle speaker-output according to the hp-jack state */
9584 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9585 {
9586         unsigned int present;
9587         unsigned char bits;
9588
9589         present = snd_hda_codec_read(codec, 0x15, 0,
9590                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9591         bits = present ? 0 : PIN_OUT;
9592         snd_hda_codec_write(codec, 0x14, 0,
9593                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9594 }
9595
9596
9597
9598 /* unsolicited event for HP jack sensing */
9599 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9600                                        unsigned int res)
9601 {
9602         if ((res >> 26) == ALC880_HP_EVENT)
9603                 alc262_toshiba_s06_speaker_automute(codec);
9604         if ((res >> 26) == ALC880_MIC_EVENT)
9605                 alc262_dmic_automute(codec);
9606
9607 }
9608
9609 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9610 {
9611         alc262_toshiba_s06_speaker_automute(codec);
9612         alc262_dmic_automute(codec);
9613 }
9614
9615 /* mute/unmute internal speaker according to the hp jack and mute state */
9616 static void alc262_hippo_automute(struct hda_codec *codec)
9617 {
9618         struct alc_spec *spec = codec->spec;
9619         unsigned int mute;
9620         unsigned int present;
9621
9622         /* need to execute and sync at first */
9623         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9624         present = snd_hda_codec_read(codec, 0x15, 0,
9625                                      AC_VERB_GET_PIN_SENSE, 0);
9626         spec->jack_present = (present & 0x80000000) != 0;
9627         if (spec->jack_present) {
9628                 /* mute internal speaker */
9629                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9630                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9631         } else {
9632                 /* unmute internal speaker if necessary */
9633                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9634                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9635                                          HDA_AMP_MUTE, mute);
9636         }
9637 }
9638
9639 /* unsolicited event for HP jack sensing */
9640 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9641                                        unsigned int res)
9642 {
9643         if ((res >> 26) != ALC880_HP_EVENT)
9644                 return;
9645         alc262_hippo_automute(codec);
9646 }
9647
9648 static void alc262_hippo1_automute(struct hda_codec *codec)
9649 {
9650         unsigned int mute;
9651         unsigned int present;
9652
9653         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9654         present = snd_hda_codec_read(codec, 0x1b, 0,
9655                                      AC_VERB_GET_PIN_SENSE, 0);
9656         present = (present & 0x80000000) != 0;
9657         if (present) {
9658                 /* mute internal speaker */
9659                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9660                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9661         } else {
9662                 /* unmute internal speaker if necessary */
9663                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9664                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9665                                          HDA_AMP_MUTE, mute);
9666         }
9667 }
9668
9669 /* unsolicited event for HP jack sensing */
9670 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9671                                        unsigned int res)
9672 {
9673         if ((res >> 26) != ALC880_HP_EVENT)
9674                 return;
9675         alc262_hippo1_automute(codec);
9676 }
9677
9678 /*
9679  * nec model
9680  *  0x15 = headphone
9681  *  0x16 = internal speaker
9682  *  0x18 = external mic
9683  */
9684
9685 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9686         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9687         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9688
9689         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9690         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9691         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9692
9693         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9694         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9695         { } /* end */
9696 };
9697
9698 static struct hda_verb alc262_nec_verbs[] = {
9699         /* Unmute Speaker */
9700         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9701
9702         /* Headphone */
9703         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9704         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9705
9706         /* External mic to headphone */
9707         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9708         /* External mic to speaker */
9709         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9710         {}
9711 };
9712
9713 /*
9714  * fujitsu model
9715  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9716  *  0x1b = port replicator headphone out
9717  */
9718
9719 #define ALC_HP_EVENT    0x37
9720
9721 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9722         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9723         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9724         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9725         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9726         {}
9727 };
9728
9729 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9730         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9731         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9732         {}
9733 };
9734
9735 static struct hda_input_mux alc262_fujitsu_capture_source = {
9736         .num_items = 3,
9737         .items = {
9738                 { "Mic", 0x0 },
9739                 { "Int Mic", 0x1 },
9740                 { "CD", 0x4 },
9741         },
9742 };
9743
9744 static struct hda_input_mux alc262_HP_capture_source = {
9745         .num_items = 5,
9746         .items = {
9747                 { "Mic", 0x0 },
9748                 { "Front Mic", 0x1 },
9749                 { "Line", 0x2 },
9750                 { "CD", 0x4 },
9751                 { "AUX IN", 0x6 },
9752         },
9753 };
9754
9755 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9756         .num_items = 4,
9757         .items = {
9758                 { "Mic", 0x0 },
9759                 { "Front Mic", 0x2 },
9760                 { "Line", 0x1 },
9761                 { "CD", 0x4 },
9762         },
9763 };
9764
9765 /* mute/unmute internal speaker according to the hp jacks and mute state */
9766 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9767 {
9768         struct alc_spec *spec = codec->spec;
9769         unsigned int mute;
9770
9771         if (force || !spec->sense_updated) {
9772                 unsigned int present;
9773                 /* need to execute and sync at first */
9774                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9775                 /* check laptop HP jack */
9776                 present = snd_hda_codec_read(codec, 0x14, 0,
9777                                              AC_VERB_GET_PIN_SENSE, 0);
9778                 /* need to execute and sync at first */
9779                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9780                 /* check docking HP jack */
9781                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9782                                               AC_VERB_GET_PIN_SENSE, 0);
9783                 if (present & AC_PINSENSE_PRESENCE)
9784                         spec->jack_present = 1;
9785                 else
9786                         spec->jack_present = 0;
9787                 spec->sense_updated = 1;
9788         }
9789         /* unmute internal speaker only if both HPs are unplugged and
9790          * master switch is on
9791          */
9792         if (spec->jack_present)
9793                 mute = HDA_AMP_MUTE;
9794         else
9795                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9796         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9797                                  HDA_AMP_MUTE, mute);
9798 }
9799
9800 /* unsolicited event for HP jack sensing */
9801 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9802                                        unsigned int res)
9803 {
9804         if ((res >> 26) != ALC_HP_EVENT)
9805                 return;
9806         alc262_fujitsu_automute(codec, 1);
9807 }
9808
9809 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9810 {
9811         alc262_fujitsu_automute(codec, 1);
9812 }
9813
9814 /* bind volumes of both NID 0x0c and 0x0d */
9815 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9816         .ops = &snd_hda_bind_vol,
9817         .values = {
9818                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9819                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9820                 0
9821         },
9822 };
9823
9824 /* mute/unmute internal speaker according to the hp jack and mute state */
9825 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9826 {
9827         struct alc_spec *spec = codec->spec;
9828         unsigned int mute;
9829
9830         if (force || !spec->sense_updated) {
9831                 unsigned int present_int_hp;
9832                 /* need to execute and sync at first */
9833                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9834                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9835                                         AC_VERB_GET_PIN_SENSE, 0);
9836                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9837                 spec->sense_updated = 1;
9838         }
9839         if (spec->jack_present) {
9840                 /* mute internal speaker */
9841                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9842                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9843                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9844                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9845         } else {
9846                 /* unmute internal speaker if necessary */
9847                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9848                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9849                                          HDA_AMP_MUTE, mute);
9850                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9851                                          HDA_AMP_MUTE, mute);
9852         }
9853 }
9854
9855 /* unsolicited event for HP jack sensing */
9856 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9857                                        unsigned int res)
9858 {
9859         if ((res >> 26) != ALC_HP_EVENT)
9860                 return;
9861         alc262_lenovo_3000_automute(codec, 1);
9862 }
9863
9864 /* bind hp and internal speaker mute (with plug check) */
9865 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9866                                          struct snd_ctl_elem_value *ucontrol)
9867 {
9868         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9869         long *valp = ucontrol->value.integer.value;
9870         int change;
9871
9872         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9873                                                  HDA_AMP_MUTE,
9874                                                  valp ? 0 : HDA_AMP_MUTE);
9875         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9876                                                  HDA_AMP_MUTE,
9877                                                  valp ? 0 : HDA_AMP_MUTE);
9878
9879         if (change)
9880                 alc262_fujitsu_automute(codec, 0);
9881         return change;
9882 }
9883
9884 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9885         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9886         {
9887                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9888                 .name = "Master Playback Switch",
9889                 .info = snd_hda_mixer_amp_switch_info,
9890                 .get = snd_hda_mixer_amp_switch_get,
9891                 .put = alc262_fujitsu_master_sw_put,
9892                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9893         },
9894         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9895         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9896         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9897         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9898         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9899         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9900         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9901         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9902         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9903         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9904         { } /* end */
9905 };
9906
9907 /* bind hp and internal speaker mute (with plug check) */
9908 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9909                                          struct snd_ctl_elem_value *ucontrol)
9910 {
9911         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9912         long *valp = ucontrol->value.integer.value;
9913         int change;
9914
9915         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9916                                                  HDA_AMP_MUTE,
9917                                                  valp ? 0 : HDA_AMP_MUTE);
9918
9919         if (change)
9920                 alc262_lenovo_3000_automute(codec, 0);
9921         return change;
9922 }
9923
9924 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9925         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9926         {
9927                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9928                 .name = "Master Playback Switch",
9929                 .info = snd_hda_mixer_amp_switch_info,
9930                 .get = snd_hda_mixer_amp_switch_get,
9931                 .put = alc262_lenovo_3000_master_sw_put,
9932                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9933         },
9934         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9935         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9936         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9937         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9938         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9939         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9940         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9941         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9942         { } /* end */
9943 };
9944
9945 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
9946         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9947         {
9948                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9949                 .name = "Master Playback Switch",
9950                 .info = snd_hda_mixer_amp_switch_info,
9951                 .get = snd_hda_mixer_amp_switch_get,
9952                 .put = alc262_sony_master_sw_put,
9953                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9954         },
9955         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9956         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9957         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9958         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9959         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9960         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9961         { } /* end */
9962 };
9963
9964 /* additional init verbs for Benq laptops */
9965 static struct hda_verb alc262_EAPD_verbs[] = {
9966         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9967         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9968         {}
9969 };
9970
9971 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9972         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9973         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9974
9975         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9976         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9977         {}
9978 };
9979
9980 /* Samsung Q1 Ultra Vista model setup */
9981 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9982         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9983         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9984         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9985         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9986         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9987         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9988         { } /* end */
9989 };
9990
9991 static struct hda_verb alc262_ultra_verbs[] = {
9992         /* output mixer */
9993         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9994         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9995         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9996         /* speaker */
9997         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9998         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9999         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10000         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10001         /* HP */
10002         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10003         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10004         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10005         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10006         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10007         /* internal mic */
10008         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10009         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10010         /* ADC, choose mic */
10011         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10012         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10013         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10014         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10015         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10016         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10017         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10018         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10019         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10020         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10021         {}
10022 };
10023
10024 /* mute/unmute internal speaker according to the hp jack and mute state */
10025 static void alc262_ultra_automute(struct hda_codec *codec)
10026 {
10027         struct alc_spec *spec = codec->spec;
10028         unsigned int mute;
10029
10030         mute = 0;
10031         /* auto-mute only when HP is used as HP */
10032         if (!spec->cur_mux[0]) {
10033                 unsigned int present;
10034                 /* need to execute and sync at first */
10035                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10036                 present = snd_hda_codec_read(codec, 0x15, 0,
10037                                              AC_VERB_GET_PIN_SENSE, 0);
10038                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10039                 if (spec->jack_present)
10040                         mute = HDA_AMP_MUTE;
10041         }
10042         /* mute/unmute internal speaker */
10043         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10044                                  HDA_AMP_MUTE, mute);
10045         /* mute/unmute HP */
10046         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10047                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10048 }
10049
10050 /* unsolicited event for HP jack sensing */
10051 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10052                                        unsigned int res)
10053 {
10054         if ((res >> 26) != ALC880_HP_EVENT)
10055                 return;
10056         alc262_ultra_automute(codec);
10057 }
10058
10059 static struct hda_input_mux alc262_ultra_capture_source = {
10060         .num_items = 2,
10061         .items = {
10062                 { "Mic", 0x1 },
10063                 { "Headphone", 0x7 },
10064         },
10065 };
10066
10067 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10068                                      struct snd_ctl_elem_value *ucontrol)
10069 {
10070         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10071         struct alc_spec *spec = codec->spec;
10072         int ret;
10073
10074         ret = alc_mux_enum_put(kcontrol, ucontrol);
10075         if (!ret)
10076                 return 0;
10077         /* reprogram the HP pin as mic or HP according to the input source */
10078         snd_hda_codec_write_cache(codec, 0x15, 0,
10079                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10080                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10081         alc262_ultra_automute(codec); /* mute/unmute HP */
10082         return ret;
10083 }
10084
10085 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10086         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10087         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10088         {
10089                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10090                 .name = "Capture Source",
10091                 .info = alc_mux_enum_info,
10092                 .get = alc_mux_enum_get,
10093                 .put = alc262_ultra_mux_enum_put,
10094         },
10095         { } /* end */
10096 };
10097
10098 /* add playback controls from the parsed DAC table */
10099 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10100                                              const struct auto_pin_cfg *cfg)
10101 {
10102         hda_nid_t nid;
10103         int err;
10104
10105         spec->multiout.num_dacs = 1;    /* only use one dac */
10106         spec->multiout.dac_nids = spec->private_dac_nids;
10107         spec->multiout.dac_nids[0] = 2;
10108
10109         nid = cfg->line_out_pins[0];
10110         if (nid) {
10111                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10112                                   "Front Playback Volume",
10113                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10114                 if (err < 0)
10115                         return err;
10116                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10117                                   "Front Playback Switch",
10118                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10119                 if (err < 0)
10120                         return err;
10121         }
10122
10123         nid = cfg->speaker_pins[0];
10124         if (nid) {
10125                 if (nid == 0x16) {
10126                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10127                                           "Speaker Playback Volume",
10128                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10129                                                               HDA_OUTPUT));
10130                         if (err < 0)
10131                                 return err;
10132                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10133                                           "Speaker Playback Switch",
10134                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10135                                                               HDA_OUTPUT));
10136                         if (err < 0)
10137                                 return err;
10138                 } else {
10139                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10140                                           "Speaker Playback Switch",
10141                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10142                                                               HDA_OUTPUT));
10143                         if (err < 0)
10144                                 return err;
10145                 }
10146         }
10147         nid = cfg->hp_pins[0];
10148         if (nid) {
10149                 /* spec->multiout.hp_nid = 2; */
10150                 if (nid == 0x16) {
10151                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10152                                           "Headphone Playback Volume",
10153                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10154                                                               HDA_OUTPUT));
10155                         if (err < 0)
10156                                 return err;
10157                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10158                                           "Headphone Playback Switch",
10159                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10160                                                               HDA_OUTPUT));
10161                         if (err < 0)
10162                                 return err;
10163                 } else {
10164                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10165                                           "Headphone Playback Switch",
10166                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10167                                                               HDA_OUTPUT));
10168                         if (err < 0)
10169                                 return err;
10170                 }
10171         }
10172         return 0;
10173 }
10174
10175 /* identical with ALC880 */
10176 #define alc262_auto_create_analog_input_ctls \
10177         alc880_auto_create_analog_input_ctls
10178
10179 /*
10180  * generic initialization of ADC, input mixers and output mixers
10181  */
10182 static struct hda_verb alc262_volume_init_verbs[] = {
10183         /*
10184          * Unmute ADC0-2 and set the default input to mic-in
10185          */
10186         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10187         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10188         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10189         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10190         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10191         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10192
10193         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10194          * mixer widget
10195          * Note: PASD motherboards uses the Line In 2 as the input for
10196          * front panel mic (mic 2)
10197          */
10198         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10199         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10200         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10201         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10202         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10203         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10204
10205         /*
10206          * Set up output mixers (0x0c - 0x0f)
10207          */
10208         /* set vol=0 to output mixers */
10209         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10210         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10211         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10212
10213         /* set up input amps for analog loopback */
10214         /* Amp Indices: DAC = 0, mixer = 1 */
10215         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10216         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10217         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10218         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10219         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10220         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10221
10222         /* FIXME: use matrix-type input source selection */
10223         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10224         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10225         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10226         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10227         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10228         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10229         /* Input mixer2 */
10230         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10231         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10232         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10233         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10234         /* Input mixer3 */
10235         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10236         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10237         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10238         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10239
10240         { }
10241 };
10242
10243 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10244         /*
10245          * Unmute ADC0-2 and set the default input to mic-in
10246          */
10247         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10248         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10249         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10250         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10251         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10252         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10253
10254         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10255          * mixer widget
10256          * Note: PASD motherboards uses the Line In 2 as the input for
10257          * front panel mic (mic 2)
10258          */
10259         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10260         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10261         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10262         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10263         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10264         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10265         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10266         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10267
10268         /*
10269          * Set up output mixers (0x0c - 0x0e)
10270          */
10271         /* set vol=0 to output mixers */
10272         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10273         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10274         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10275
10276         /* set up input amps for analog loopback */
10277         /* Amp Indices: DAC = 0, mixer = 1 */
10278         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10279         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10280         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10281         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10282         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10283         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10284
10285         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10286         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10287         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10288
10289         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10290         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10291
10292         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10293         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10294
10295         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10296         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10297         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10298         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10299         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10300
10301         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10302         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10303         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10304         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10305         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10306         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10307
10308
10309         /* FIXME: use matrix-type input source selection */
10310         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10311         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10312         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10313         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10314         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10315         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10316         /* Input mixer2 */
10317         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10318         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10319         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10320         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10321         /* Input mixer3 */
10322         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10323         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10324         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10325         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10326
10327         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10328
10329         { }
10330 };
10331
10332 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10333         /*
10334          * Unmute ADC0-2 and set the default input to mic-in
10335          */
10336         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10337         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10338         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10339         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10340         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10341         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10342
10343         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10344          * mixer widget
10345          * Note: PASD motherboards uses the Line In 2 as the input for front
10346          * panel mic (mic 2)
10347          */
10348         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10349         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10350         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10351         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10352         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10353         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10354         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10355         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10356         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10357         /*
10358          * Set up output mixers (0x0c - 0x0e)
10359          */
10360         /* set vol=0 to output mixers */
10361         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10362         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10363         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10364
10365         /* set up input amps for analog loopback */
10366         /* Amp Indices: DAC = 0, mixer = 1 */
10367         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10368         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10369         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10370         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10371         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10372         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10373
10374
10375         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10376         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10377         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10378         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10379         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10380         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10381         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10382
10383         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10384         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10385
10386         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10387         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10388
10389         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10390         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10391         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10392         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10393         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10394         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10395
10396         /* FIXME: use matrix-type input source selection */
10397         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10398         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10399         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10400         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10401         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10402         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10403         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10404         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10405         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10406         /* Input mixer2 */
10407         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10408         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10409         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10410         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10411         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10412         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10413         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10414         /* Input mixer3 */
10415         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10416         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10417         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10418         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10419         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10420         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10421         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10422
10423         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10424
10425         { }
10426 };
10427
10428 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10429
10430         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10431         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10432         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10433
10434         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10435         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10436         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10437         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10438
10439         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10440         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10441         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10442         {}
10443 };
10444
10445
10446 #ifdef CONFIG_SND_HDA_POWER_SAVE
10447 #define alc262_loopbacks        alc880_loopbacks
10448 #endif
10449
10450 /* pcm configuration: identiacal with ALC880 */
10451 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10452 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10453 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10454 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10455
10456 /*
10457  * BIOS auto configuration
10458  */
10459 static int alc262_parse_auto_config(struct hda_codec *codec)
10460 {
10461         struct alc_spec *spec = codec->spec;
10462         int err;
10463         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10464
10465         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10466                                            alc262_ignore);
10467         if (err < 0)
10468                 return err;
10469         if (!spec->autocfg.line_outs)
10470                 return 0; /* can't find valid BIOS pin config */
10471         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10472         if (err < 0)
10473                 return err;
10474         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10475         if (err < 0)
10476                 return err;
10477
10478         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10479
10480         if (spec->autocfg.dig_out_pin)
10481                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10482         if (spec->autocfg.dig_in_pin)
10483                 spec->dig_in_nid = ALC262_DIGIN_NID;
10484
10485         if (spec->kctls.list)
10486                 add_mixer(spec, spec->kctls.list);
10487
10488         add_verb(spec, alc262_volume_init_verbs);
10489         spec->num_mux_defs = 1;
10490         spec->input_mux = &spec->private_imux;
10491
10492         err = alc_auto_add_mic_boost(codec);
10493         if (err < 0)
10494                 return err;
10495
10496         store_pin_configs(codec);
10497         return 1;
10498 }
10499
10500 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10501 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10502 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10503 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10504
10505
10506 /* init callback for auto-configuration model -- overriding the default init */
10507 static void alc262_auto_init(struct hda_codec *codec)
10508 {
10509         struct alc_spec *spec = codec->spec;
10510         alc262_auto_init_multi_out(codec);
10511         alc262_auto_init_hp_out(codec);
10512         alc262_auto_init_analog_input(codec);
10513         alc262_auto_init_input_src(codec);
10514         if (spec->unsol_event)
10515                 alc_inithook(codec);
10516 }
10517
10518 /*
10519  * configuration and preset
10520  */
10521 static const char *alc262_models[ALC262_MODEL_LAST] = {
10522         [ALC262_BASIC]          = "basic",
10523         [ALC262_HIPPO]          = "hippo",
10524         [ALC262_HIPPO_1]        = "hippo_1",
10525         [ALC262_FUJITSU]        = "fujitsu",
10526         [ALC262_HP_BPC]         = "hp-bpc",
10527         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10528         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10529         [ALC262_HP_RP5700]      = "hp-rp5700",
10530         [ALC262_BENQ_ED8]       = "benq",
10531         [ALC262_BENQ_T31]       = "benq-t31",
10532         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10533         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10534         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10535         [ALC262_ULTRA]          = "ultra",
10536         [ALC262_LENOVO_3000]    = "lenovo-3000",
10537         [ALC262_NEC]            = "nec",
10538         [ALC262_AUTO]           = "auto",
10539 };
10540
10541 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10542         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10543         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10544         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
10545         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
10546         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
10547         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
10548         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
10549         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
10550         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10551         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10552         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10553         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10554         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10555         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10556         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10557         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10558         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10559         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10560         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10561         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10562         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10563         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10564                       ALC262_HP_TC_T5735),
10565         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10566         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10567         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10568         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10569         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10570         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10571         SND_PCI_QUIRK(0x104d, 0x9033, "Sony VAIO VGN-SR19XN",
10572                       ALC262_SONY_ASSAMD),
10573         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10574                       ALC262_TOSHIBA_RX1),
10575         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10576         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10577         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10578         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
10579         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
10580         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
10581         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10582         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10583         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10584         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10585         {}
10586 };
10587
10588 static struct alc_config_preset alc262_presets[] = {
10589         [ALC262_BASIC] = {
10590                 .mixers = { alc262_base_mixer },
10591                 .init_verbs = { alc262_init_verbs },
10592                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10593                 .dac_nids = alc262_dac_nids,
10594                 .hp_nid = 0x03,
10595                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10596                 .channel_mode = alc262_modes,
10597                 .input_mux = &alc262_capture_source,
10598         },
10599         [ALC262_HIPPO] = {
10600                 .mixers = { alc262_base_mixer },
10601                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10602                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10603                 .dac_nids = alc262_dac_nids,
10604                 .hp_nid = 0x03,
10605                 .dig_out_nid = ALC262_DIGOUT_NID,
10606                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10607                 .channel_mode = alc262_modes,
10608                 .input_mux = &alc262_capture_source,
10609                 .unsol_event = alc262_hippo_unsol_event,
10610                 .init_hook = alc262_hippo_automute,
10611         },
10612         [ALC262_HIPPO_1] = {
10613                 .mixers = { alc262_hippo1_mixer },
10614                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10615                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10616                 .dac_nids = alc262_dac_nids,
10617                 .hp_nid = 0x02,
10618                 .dig_out_nid = ALC262_DIGOUT_NID,
10619                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10620                 .channel_mode = alc262_modes,
10621                 .input_mux = &alc262_capture_source,
10622                 .unsol_event = alc262_hippo1_unsol_event,
10623                 .init_hook = alc262_hippo1_automute,
10624         },
10625         [ALC262_FUJITSU] = {
10626                 .mixers = { alc262_fujitsu_mixer },
10627                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10628                                 alc262_fujitsu_unsol_verbs },
10629                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10630                 .dac_nids = alc262_dac_nids,
10631                 .hp_nid = 0x03,
10632                 .dig_out_nid = ALC262_DIGOUT_NID,
10633                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10634                 .channel_mode = alc262_modes,
10635                 .input_mux = &alc262_fujitsu_capture_source,
10636                 .unsol_event = alc262_fujitsu_unsol_event,
10637                 .init_hook = alc262_fujitsu_init_hook,
10638         },
10639         [ALC262_HP_BPC] = {
10640                 .mixers = { alc262_HP_BPC_mixer },
10641                 .init_verbs = { alc262_HP_BPC_init_verbs },
10642                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10643                 .dac_nids = alc262_dac_nids,
10644                 .hp_nid = 0x03,
10645                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10646                 .channel_mode = alc262_modes,
10647                 .input_mux = &alc262_HP_capture_source,
10648                 .unsol_event = alc262_hp_bpc_unsol_event,
10649                 .init_hook = alc262_hp_bpc_automute,
10650         },
10651         [ALC262_HP_BPC_D7000_WF] = {
10652                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10653                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10654                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10655                 .dac_nids = alc262_dac_nids,
10656                 .hp_nid = 0x03,
10657                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10658                 .channel_mode = alc262_modes,
10659                 .input_mux = &alc262_HP_D7000_capture_source,
10660                 .unsol_event = alc262_hp_wildwest_unsol_event,
10661                 .init_hook = alc262_hp_wildwest_automute,
10662         },
10663         [ALC262_HP_BPC_D7000_WL] = {
10664                 .mixers = { alc262_HP_BPC_WildWest_mixer,
10665                             alc262_HP_BPC_WildWest_option_mixer },
10666                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10667                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10668                 .dac_nids = alc262_dac_nids,
10669                 .hp_nid = 0x03,
10670                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10671                 .channel_mode = alc262_modes,
10672                 .input_mux = &alc262_HP_D7000_capture_source,
10673                 .unsol_event = alc262_hp_wildwest_unsol_event,
10674                 .init_hook = alc262_hp_wildwest_automute,
10675         },
10676         [ALC262_HP_TC_T5735] = {
10677                 .mixers = { alc262_hp_t5735_mixer },
10678                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10679                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10680                 .dac_nids = alc262_dac_nids,
10681                 .hp_nid = 0x03,
10682                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10683                 .channel_mode = alc262_modes,
10684                 .input_mux = &alc262_capture_source,
10685                 .unsol_event = alc262_hp_t5735_unsol_event,
10686                 .init_hook = alc262_hp_t5735_init_hook,
10687         },
10688         [ALC262_HP_RP5700] = {
10689                 .mixers = { alc262_hp_rp5700_mixer },
10690                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10691                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10692                 .dac_nids = alc262_dac_nids,
10693                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10694                 .channel_mode = alc262_modes,
10695                 .input_mux = &alc262_hp_rp5700_capture_source,
10696         },
10697         [ALC262_BENQ_ED8] = {
10698                 .mixers = { alc262_base_mixer },
10699                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
10700                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10701                 .dac_nids = alc262_dac_nids,
10702                 .hp_nid = 0x03,
10703                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10704                 .channel_mode = alc262_modes,
10705                 .input_mux = &alc262_capture_source,
10706         },
10707         [ALC262_SONY_ASSAMD] = {
10708                 .mixers = { alc262_sony_mixer },
10709                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10710                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10711                 .dac_nids = alc262_dac_nids,
10712                 .hp_nid = 0x02,
10713                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10714                 .channel_mode = alc262_modes,
10715                 .input_mux = &alc262_capture_source,
10716                 .unsol_event = alc262_hippo_unsol_event,
10717                 .init_hook = alc262_hippo_automute,
10718         },
10719         [ALC262_BENQ_T31] = {
10720                 .mixers = { alc262_benq_t31_mixer },
10721                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10722                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10723                 .dac_nids = alc262_dac_nids,
10724                 .hp_nid = 0x03,
10725                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10726                 .channel_mode = alc262_modes,
10727                 .input_mux = &alc262_capture_source,
10728                 .unsol_event = alc262_hippo_unsol_event,
10729                 .init_hook = alc262_hippo_automute,
10730         },
10731         [ALC262_ULTRA] = {
10732                 .mixers = { alc262_ultra_mixer },
10733                 .cap_mixer = alc262_ultra_capture_mixer,
10734                 .init_verbs = { alc262_ultra_verbs },
10735                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10736                 .dac_nids = alc262_dac_nids,
10737                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10738                 .channel_mode = alc262_modes,
10739                 .input_mux = &alc262_ultra_capture_source,
10740                 .adc_nids = alc262_adc_nids, /* ADC0 */
10741                 .capsrc_nids = alc262_capsrc_nids,
10742                 .num_adc_nids = 1, /* single ADC */
10743                 .unsol_event = alc262_ultra_unsol_event,
10744                 .init_hook = alc262_ultra_automute,
10745         },
10746         [ALC262_LENOVO_3000] = {
10747                 .mixers = { alc262_lenovo_3000_mixer },
10748                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10749                                 alc262_lenovo_3000_unsol_verbs },
10750                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10751                 .dac_nids = alc262_dac_nids,
10752                 .hp_nid = 0x03,
10753                 .dig_out_nid = ALC262_DIGOUT_NID,
10754                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10755                 .channel_mode = alc262_modes,
10756                 .input_mux = &alc262_fujitsu_capture_source,
10757                 .unsol_event = alc262_lenovo_3000_unsol_event,
10758         },
10759         [ALC262_NEC] = {
10760                 .mixers = { alc262_nec_mixer },
10761                 .init_verbs = { alc262_nec_verbs },
10762                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10763                 .dac_nids = alc262_dac_nids,
10764                 .hp_nid = 0x03,
10765                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10766                 .channel_mode = alc262_modes,
10767                 .input_mux = &alc262_capture_source,
10768         },
10769         [ALC262_TOSHIBA_S06] = {
10770                 .mixers = { alc262_toshiba_s06_mixer },
10771                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10772                                                         alc262_eapd_verbs },
10773                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10774                 .capsrc_nids = alc262_dmic_capsrc_nids,
10775                 .dac_nids = alc262_dac_nids,
10776                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10777                 .dig_out_nid = ALC262_DIGOUT_NID,
10778                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10779                 .channel_mode = alc262_modes,
10780                 .input_mux = &alc262_dmic_capture_source,
10781                 .unsol_event = alc262_toshiba_s06_unsol_event,
10782                 .init_hook = alc262_toshiba_s06_init_hook,
10783         },
10784         [ALC262_TOSHIBA_RX1] = {
10785                 .mixers = { alc262_toshiba_rx1_mixer },
10786                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
10787                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10788                 .dac_nids = alc262_dac_nids,
10789                 .hp_nid = 0x03,
10790                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10791                 .channel_mode = alc262_modes,
10792                 .input_mux = &alc262_capture_source,
10793                 .unsol_event = alc262_hippo_unsol_event,
10794                 .init_hook = alc262_hippo_automute,
10795         },
10796 };
10797
10798 static int patch_alc262(struct hda_codec *codec)
10799 {
10800         struct alc_spec *spec;
10801         int board_config;
10802         int err;
10803
10804         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10805         if (spec == NULL)
10806                 return -ENOMEM;
10807
10808         codec->spec = spec;
10809 #if 0
10810         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10811          * under-run
10812          */
10813         {
10814         int tmp;
10815         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10816         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10817         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10818         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10819         }
10820 #endif
10821
10822         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10823
10824         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10825                                                   alc262_models,
10826                                                   alc262_cfg_tbl);
10827
10828         if (board_config < 0) {
10829                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10830                        "trying auto-probe from BIOS...\n");
10831                 board_config = ALC262_AUTO;
10832         }
10833
10834         if (board_config == ALC262_AUTO) {
10835                 /* automatic parse from the BIOS config */
10836                 err = alc262_parse_auto_config(codec);
10837                 if (err < 0) {
10838                         alc_free(codec);
10839                         return err;
10840                 } else if (!err) {
10841                         printk(KERN_INFO
10842                                "hda_codec: Cannot set up configuration "
10843                                "from BIOS.  Using base mode...\n");
10844                         board_config = ALC262_BASIC;
10845                 }
10846         }
10847
10848         if (board_config != ALC262_AUTO)
10849                 setup_preset(spec, &alc262_presets[board_config]);
10850
10851         spec->stream_name_analog = "ALC262 Analog";
10852         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10853         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10854
10855         spec->stream_name_digital = "ALC262 Digital";
10856         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10857         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10858
10859         spec->is_mix_capture = 1;
10860         if (!spec->adc_nids && spec->input_mux) {
10861                 /* check whether NID 0x07 is valid */
10862                 unsigned int wcap = get_wcaps(codec, 0x07);
10863
10864                 /* get type */
10865                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10866                 if (wcap != AC_WID_AUD_IN) {
10867                         spec->adc_nids = alc262_adc_nids_alt;
10868                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10869                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10870                 } else {
10871                         spec->adc_nids = alc262_adc_nids;
10872                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10873                         spec->capsrc_nids = alc262_capsrc_nids;
10874                 }
10875         }
10876         if (!spec->cap_mixer)
10877                 set_capture_mixer(spec);
10878
10879         spec->vmaster_nid = 0x0c;
10880
10881         codec->patch_ops = alc_patch_ops;
10882         if (board_config == ALC262_AUTO)
10883                 spec->init_hook = alc262_auto_init;
10884 #ifdef CONFIG_SND_HDA_POWER_SAVE
10885         if (!spec->loopback.amplist)
10886                 spec->loopback.amplist = alc262_loopbacks;
10887 #endif
10888         codec->proc_widget_hook = print_realtek_coef;
10889
10890         return 0;
10891 }
10892
10893 /*
10894  *  ALC268 channel source setting (2 channel)
10895  */
10896 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10897 #define alc268_modes            alc260_modes
10898
10899 static hda_nid_t alc268_dac_nids[2] = {
10900         /* front, hp */
10901         0x02, 0x03
10902 };
10903
10904 static hda_nid_t alc268_adc_nids[2] = {
10905         /* ADC0-1 */
10906         0x08, 0x07
10907 };
10908
10909 static hda_nid_t alc268_adc_nids_alt[1] = {
10910         /* ADC0 */
10911         0x08
10912 };
10913
10914 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10915
10916 static struct snd_kcontrol_new alc268_base_mixer[] = {
10917         /* output mixer control */
10918         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10919         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10920         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10921         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10922         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10923         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10924         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10925         { }
10926 };
10927
10928 /* bind Beep switches of both NID 0x0f and 0x10 */
10929 static struct hda_bind_ctls alc268_bind_beep_sw = {
10930         .ops = &snd_hda_bind_sw,
10931         .values = {
10932                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10933                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10934                 0
10935         },
10936 };
10937
10938 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10939         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10940         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10941         { }
10942 };
10943
10944 static struct hda_verb alc268_eapd_verbs[] = {
10945         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10946         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10947         { }
10948 };
10949
10950 /* Toshiba specific */
10951 #define alc268_toshiba_automute alc262_hippo_automute
10952
10953 static struct hda_verb alc268_toshiba_verbs[] = {
10954         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10955         { } /* end */
10956 };
10957
10958 static struct hda_input_mux alc268_acer_lc_capture_source = {
10959         .num_items = 2,
10960         .items = {
10961                 { "i-Mic", 0x6 },
10962                 { "E-Mic", 0x0 },
10963         },
10964 };
10965
10966 /* Acer specific */
10967 /* bind volumes of both NID 0x02 and 0x03 */
10968 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10969         .ops = &snd_hda_bind_vol,
10970         .values = {
10971                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10972                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10973                 0
10974         },
10975 };
10976
10977 /* mute/unmute internal speaker according to the hp jack and mute state */
10978 static void alc268_acer_automute(struct hda_codec *codec, int force)
10979 {
10980         struct alc_spec *spec = codec->spec;
10981         unsigned int mute;
10982
10983         if (force || !spec->sense_updated) {
10984                 unsigned int present;
10985                 present = snd_hda_codec_read(codec, 0x14, 0,
10986                                          AC_VERB_GET_PIN_SENSE, 0);
10987                 spec->jack_present = (present & 0x80000000) != 0;
10988                 spec->sense_updated = 1;
10989         }
10990         if (spec->jack_present)
10991                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10992         else /* unmute internal speaker if necessary */
10993                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10994         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10995                                  HDA_AMP_MUTE, mute);
10996 }
10997
10998
10999 /* bind hp and internal speaker mute (with plug check) */
11000 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11001                                      struct snd_ctl_elem_value *ucontrol)
11002 {
11003         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11004         long *valp = ucontrol->value.integer.value;
11005         int change;
11006
11007         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
11008                                           HDA_AMP_MUTE,
11009                                           valp[0] ? 0 : HDA_AMP_MUTE);
11010         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
11011                                            HDA_AMP_MUTE,
11012                                            valp[1] ? 0 : HDA_AMP_MUTE);
11013         if (change)
11014                 alc268_acer_automute(codec, 0);
11015         return change;
11016 }
11017
11018 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11019         /* output mixer control */
11020         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11021         {
11022                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11023                 .name = "Master Playback Switch",
11024                 .info = snd_hda_mixer_amp_switch_info,
11025                 .get = snd_hda_mixer_amp_switch_get,
11026                 .put = alc268_acer_master_sw_put,
11027                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11028         },
11029         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11030         { }
11031 };
11032
11033 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11034         /* output mixer control */
11035         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11036         {
11037                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11038                 .name = "Master Playback Switch",
11039                 .info = snd_hda_mixer_amp_switch_info,
11040                 .get = snd_hda_mixer_amp_switch_get,
11041                 .put = alc268_acer_master_sw_put,
11042                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11043         },
11044         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11045         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11046         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11047         { }
11048 };
11049
11050 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11051         /* output mixer control */
11052         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11053         {
11054                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11055                 .name = "Master Playback Switch",
11056                 .info = snd_hda_mixer_amp_switch_info,
11057                 .get = snd_hda_mixer_amp_switch_get,
11058                 .put = alc268_acer_master_sw_put,
11059                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11060         },
11061         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11062         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11063         { }
11064 };
11065
11066 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11067         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11068         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11069         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11070         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11071         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11072         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11073         { }
11074 };
11075
11076 static struct hda_verb alc268_acer_verbs[] = {
11077         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11078         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11079         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11080         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11081         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11082         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11083         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11084         { }
11085 };
11086
11087 /* unsolicited event for HP jack sensing */
11088 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
11089                                        unsigned int res)
11090 {
11091         if ((res >> 26) != ALC880_HP_EVENT)
11092                 return;
11093         alc268_toshiba_automute(codec);
11094 }
11095
11096 static void alc268_acer_unsol_event(struct hda_codec *codec,
11097                                        unsigned int res)
11098 {
11099         if ((res >> 26) != ALC880_HP_EVENT)
11100                 return;
11101         alc268_acer_automute(codec, 1);
11102 }
11103
11104 static void alc268_acer_init_hook(struct hda_codec *codec)
11105 {
11106         alc268_acer_automute(codec, 1);
11107 }
11108
11109 /* toggle speaker-output according to the hp-jack state */
11110 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11111 {
11112         unsigned int present;
11113         unsigned char bits;
11114
11115         present = snd_hda_codec_read(codec, 0x15, 0,
11116                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11117         bits = present ? AMP_IN_MUTE(0) : 0;
11118         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
11119                                 AMP_IN_MUTE(0), bits);
11120         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
11121                                 AMP_IN_MUTE(0), bits);
11122 }
11123
11124
11125 static void alc268_acer_mic_automute(struct hda_codec *codec)
11126 {
11127         unsigned int present;
11128
11129         present = snd_hda_codec_read(codec, 0x18, 0,
11130                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11131         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11132                             present ? 0x0 : 0x6);
11133 }
11134
11135 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11136                                     unsigned int res)
11137 {
11138         if ((res >> 26) == ALC880_HP_EVENT)
11139                 alc268_aspire_one_speaker_automute(codec);
11140         if ((res >> 26) == ALC880_MIC_EVENT)
11141                 alc268_acer_mic_automute(codec);
11142 }
11143
11144 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11145 {
11146         alc268_aspire_one_speaker_automute(codec);
11147         alc268_acer_mic_automute(codec);
11148 }
11149
11150 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11151         /* output mixer control */
11152         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11153         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11154         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11155         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11156         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11157         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11158         { }
11159 };
11160
11161 static struct hda_verb alc268_dell_verbs[] = {
11162         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11163         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11164         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11165         { }
11166 };
11167
11168 /* mute/unmute internal speaker according to the hp jack and mute state */
11169 static void alc268_dell_automute(struct hda_codec *codec)
11170 {
11171         unsigned int present;
11172         unsigned int mute;
11173
11174         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
11175         if (present & 0x80000000)
11176                 mute = HDA_AMP_MUTE;
11177         else
11178                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
11179         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11180                                  HDA_AMP_MUTE, mute);
11181 }
11182
11183 static void alc268_dell_unsol_event(struct hda_codec *codec,
11184                                     unsigned int res)
11185 {
11186         if ((res >> 26) != ALC880_HP_EVENT)
11187                 return;
11188         alc268_dell_automute(codec);
11189 }
11190
11191 #define alc268_dell_init_hook   alc268_dell_automute
11192
11193 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
11194         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11195         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11196         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11197         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11198         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11199         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
11200         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
11201         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
11202         { }
11203 };
11204
11205 static struct hda_verb alc267_quanta_il1_verbs[] = {
11206         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11207         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
11208         { }
11209 };
11210
11211 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
11212 {
11213         unsigned int present;
11214
11215         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
11216                 & AC_PINSENSE_PRESENCE;
11217         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11218                             present ? 0 : PIN_OUT);
11219 }
11220
11221 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
11222 {
11223         unsigned int present;
11224
11225         present = snd_hda_codec_read(codec, 0x18, 0,
11226                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11227         snd_hda_codec_write(codec, 0x23, 0,
11228                             AC_VERB_SET_CONNECT_SEL,
11229                             present ? 0x00 : 0x01);
11230 }
11231
11232 static void alc267_quanta_il1_automute(struct hda_codec *codec)
11233 {
11234         alc267_quanta_il1_hp_automute(codec);
11235         alc267_quanta_il1_mic_automute(codec);
11236 }
11237
11238 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11239                                            unsigned int res)
11240 {
11241         switch (res >> 26) {
11242         case ALC880_HP_EVENT:
11243                 alc267_quanta_il1_hp_automute(codec);
11244                 break;
11245         case ALC880_MIC_EVENT:
11246                 alc267_quanta_il1_mic_automute(codec);
11247                 break;
11248         }
11249 }
11250
11251 /*
11252  * generic initialization of ADC, input mixers and output mixers
11253  */
11254 static struct hda_verb alc268_base_init_verbs[] = {
11255         /* Unmute DAC0-1 and set vol = 0 */
11256         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11257         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11258         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11259         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11260         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11261         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11262
11263         /*
11264          * Set up output mixers (0x0c - 0x0e)
11265          */
11266         /* set vol=0 to output mixers */
11267         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11268         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11269         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11270         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11271
11272         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11273         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11274
11275         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11276         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11277         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
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         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11285         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11286         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11287         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11288         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11289         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11290         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11291
11292         /* set PCBEEP vol = 0, mute connections */
11293         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11294         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11295         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11296
11297         /* Unmute Selector 23h,24h and set the default input to mic-in */
11298
11299         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11300         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11301         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11302         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11303
11304         { }
11305 };
11306
11307 /*
11308  * generic initialization of ADC, input mixers and output mixers
11309  */
11310 static struct hda_verb alc268_volume_init_verbs[] = {
11311         /* set output DAC */
11312         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11313         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11314         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11315         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11316
11317         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11318         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11319         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11320         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11321         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11322
11323         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11324         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11325         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11326         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11327         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11328
11329         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11330         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11331         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11332         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11333
11334         /* set PCBEEP vol = 0, mute connections */
11335         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11336         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11337         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11338
11339         { }
11340 };
11341
11342 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11343         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11344         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11345         {
11346                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11347                 /* The multiple "Capture Source" controls confuse alsamixer
11348                  * So call somewhat different..
11349                  */
11350                 /* .name = "Capture Source", */
11351                 .name = "Input Source",
11352                 .count = 1,
11353                 .info = alc_mux_enum_info,
11354                 .get = alc_mux_enum_get,
11355                 .put = alc_mux_enum_put,
11356         },
11357         { } /* end */
11358 };
11359
11360 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11361         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11362         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11363         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11364         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11365         {
11366                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11367                 /* The multiple "Capture Source" controls confuse alsamixer
11368                  * So call somewhat different..
11369                  */
11370                 /* .name = "Capture Source", */
11371                 .name = "Input Source",
11372                 .count = 2,
11373                 .info = alc_mux_enum_info,
11374                 .get = alc_mux_enum_get,
11375                 .put = alc_mux_enum_put,
11376         },
11377         { } /* end */
11378 };
11379
11380 static struct hda_input_mux alc268_capture_source = {
11381         .num_items = 4,
11382         .items = {
11383                 { "Mic", 0x0 },
11384                 { "Front Mic", 0x1 },
11385                 { "Line", 0x2 },
11386                 { "CD", 0x3 },
11387         },
11388 };
11389
11390 static struct hda_input_mux alc268_acer_capture_source = {
11391         .num_items = 3,
11392         .items = {
11393                 { "Mic", 0x0 },
11394                 { "Internal Mic", 0x1 },
11395                 { "Line", 0x2 },
11396         },
11397 };
11398
11399 static struct hda_input_mux alc268_acer_dmic_capture_source = {
11400         .num_items = 3,
11401         .items = {
11402                 { "Mic", 0x0 },
11403                 { "Internal Mic", 0x6 },
11404                 { "Line", 0x2 },
11405         },
11406 };
11407
11408 #ifdef CONFIG_SND_DEBUG
11409 static struct snd_kcontrol_new alc268_test_mixer[] = {
11410         /* Volume widgets */
11411         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11412         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11413         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11414         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11415         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11416         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11417         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11418         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11419         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11420         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11421         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11422         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11423         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11424         /* The below appears problematic on some hardwares */
11425         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11426         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11427         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11428         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11429         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11430
11431         /* Modes for retasking pin widgets */
11432         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11433         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11434         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11435         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11436
11437         /* Controls for GPIO pins, assuming they are configured as outputs */
11438         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11439         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11440         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11441         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11442
11443         /* Switches to allow the digital SPDIF output pin to be enabled.
11444          * The ALC268 does not have an SPDIF input.
11445          */
11446         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11447
11448         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11449          * this output to turn on an external amplifier.
11450          */
11451         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11452         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11453
11454         { } /* end */
11455 };
11456 #endif
11457
11458 /* create input playback/capture controls for the given pin */
11459 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11460                                     const char *ctlname, int idx)
11461 {
11462         char name[32];
11463         int err;
11464
11465         sprintf(name, "%s Playback Volume", ctlname);
11466         if (nid == 0x14) {
11467                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11468                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11469                                                       HDA_OUTPUT));
11470                 if (err < 0)
11471                         return err;
11472         } else if (nid == 0x15) {
11473                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11474                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11475                                                       HDA_OUTPUT));
11476                 if (err < 0)
11477                         return err;
11478         } else
11479                 return -1;
11480         sprintf(name, "%s Playback Switch", ctlname);
11481         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11482                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11483         if (err < 0)
11484                 return err;
11485         return 0;
11486 }
11487
11488 /* add playback controls from the parsed DAC table */
11489 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11490                                              const struct auto_pin_cfg *cfg)
11491 {
11492         hda_nid_t nid;
11493         int err;
11494
11495         spec->multiout.num_dacs = 2;    /* only use one dac */
11496         spec->multiout.dac_nids = spec->private_dac_nids;
11497         spec->multiout.dac_nids[0] = 2;
11498         spec->multiout.dac_nids[1] = 3;
11499
11500         nid = cfg->line_out_pins[0];
11501         if (nid)
11502                 alc268_new_analog_output(spec, nid, "Front", 0);
11503
11504         nid = cfg->speaker_pins[0];
11505         if (nid == 0x1d) {
11506                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11507                                   "Speaker Playback Volume",
11508                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11509                 if (err < 0)
11510                         return err;
11511         }
11512         nid = cfg->hp_pins[0];
11513         if (nid)
11514                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11515
11516         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11517         if (nid == 0x16) {
11518                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11519                                   "Mono Playback Switch",
11520                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11521                 if (err < 0)
11522                         return err;
11523         }
11524         return 0;
11525 }
11526
11527 /* create playback/capture controls for input pins */
11528 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11529                                                 const struct auto_pin_cfg *cfg)
11530 {
11531         struct hda_input_mux *imux = &spec->private_imux;
11532         int i, idx1;
11533
11534         for (i = 0; i < AUTO_PIN_LAST; i++) {
11535                 switch(cfg->input_pins[i]) {
11536                 case 0x18:
11537                         idx1 = 0;       /* Mic 1 */
11538                         break;
11539                 case 0x19:
11540                         idx1 = 1;       /* Mic 2 */
11541                         break;
11542                 case 0x1a:
11543                         idx1 = 2;       /* Line In */
11544                         break;
11545                 case 0x1c:
11546                         idx1 = 3;       /* CD */
11547                         break;
11548                 case 0x12:
11549                 case 0x13:
11550                         idx1 = 6;       /* digital mics */
11551                         break;
11552                 default:
11553                         continue;
11554                 }
11555                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11556                 imux->items[imux->num_items].index = idx1;
11557                 imux->num_items++;
11558         }
11559         return 0;
11560 }
11561
11562 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11563 {
11564         struct alc_spec *spec = codec->spec;
11565         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11566         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11567         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11568         unsigned int    dac_vol1, dac_vol2;
11569
11570         if (speaker_nid) {
11571                 snd_hda_codec_write(codec, speaker_nid, 0,
11572                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11573                 snd_hda_codec_write(codec, 0x0f, 0,
11574                                     AC_VERB_SET_AMP_GAIN_MUTE,
11575                                     AMP_IN_UNMUTE(1));
11576                 snd_hda_codec_write(codec, 0x10, 0,
11577                                     AC_VERB_SET_AMP_GAIN_MUTE,
11578                                     AMP_IN_UNMUTE(1));
11579         } else {
11580                 snd_hda_codec_write(codec, 0x0f, 0,
11581                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11582                 snd_hda_codec_write(codec, 0x10, 0,
11583                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11584         }
11585
11586         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11587         if (line_nid == 0x14)
11588                 dac_vol2 = AMP_OUT_ZERO;
11589         else if (line_nid == 0x15)
11590                 dac_vol1 = AMP_OUT_ZERO;
11591         if (hp_nid == 0x14)
11592                 dac_vol2 = AMP_OUT_ZERO;
11593         else if (hp_nid == 0x15)
11594                 dac_vol1 = AMP_OUT_ZERO;
11595         if (line_nid != 0x16 || hp_nid != 0x16 ||
11596             spec->autocfg.line_out_pins[1] != 0x16 ||
11597             spec->autocfg.line_out_pins[2] != 0x16)
11598                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11599
11600         snd_hda_codec_write(codec, 0x02, 0,
11601                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11602         snd_hda_codec_write(codec, 0x03, 0,
11603                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11604 }
11605
11606 /* pcm configuration: identiacal with ALC880 */
11607 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11608 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11609 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11610 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11611
11612 /*
11613  * BIOS auto configuration
11614  */
11615 static int alc268_parse_auto_config(struct hda_codec *codec)
11616 {
11617         struct alc_spec *spec = codec->spec;
11618         int err;
11619         static hda_nid_t alc268_ignore[] = { 0 };
11620
11621         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11622                                            alc268_ignore);
11623         if (err < 0)
11624                 return err;
11625         if (!spec->autocfg.line_outs)
11626                 return 0; /* can't find valid BIOS pin config */
11627
11628         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11629         if (err < 0)
11630                 return err;
11631         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11632         if (err < 0)
11633                 return err;
11634
11635         spec->multiout.max_channels = 2;
11636
11637         /* digital only support output */
11638         if (spec->autocfg.dig_out_pin)
11639                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11640
11641         if (spec->kctls.list)
11642                 add_mixer(spec, spec->kctls.list);
11643
11644         if (spec->autocfg.speaker_pins[0] != 0x1d)
11645                 add_mixer(spec, alc268_beep_mixer);
11646
11647         add_verb(spec, alc268_volume_init_verbs);
11648         spec->num_mux_defs = 1;
11649         spec->input_mux = &spec->private_imux;
11650
11651         err = alc_auto_add_mic_boost(codec);
11652         if (err < 0)
11653                 return err;
11654
11655         store_pin_configs(codec);
11656         return 1;
11657 }
11658
11659 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
11660 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
11661 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
11662
11663 /* init callback for auto-configuration model -- overriding the default init */
11664 static void alc268_auto_init(struct hda_codec *codec)
11665 {
11666         struct alc_spec *spec = codec->spec;
11667         alc268_auto_init_multi_out(codec);
11668         alc268_auto_init_hp_out(codec);
11669         alc268_auto_init_mono_speaker_out(codec);
11670         alc268_auto_init_analog_input(codec);
11671         if (spec->unsol_event)
11672                 alc_inithook(codec);
11673 }
11674
11675 /*
11676  * configuration and preset
11677  */
11678 static const char *alc268_models[ALC268_MODEL_LAST] = {
11679         [ALC267_QUANTA_IL1]     = "quanta-il1",
11680         [ALC268_3ST]            = "3stack",
11681         [ALC268_TOSHIBA]        = "toshiba",
11682         [ALC268_ACER]           = "acer",
11683         [ALC268_ACER_DMIC]      = "acer-dmic",
11684         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
11685         [ALC268_DELL]           = "dell",
11686         [ALC268_ZEPTO]          = "zepto",
11687 #ifdef CONFIG_SND_DEBUG
11688         [ALC268_TEST]           = "test",
11689 #endif
11690         [ALC268_AUTO]           = "auto",
11691 };
11692
11693 static struct snd_pci_quirk alc268_cfg_tbl[] = {
11694         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
11695         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
11696         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
11697         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
11698         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11699         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11700                                                 ALC268_ACER_ASPIRE_ONE),
11701         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
11702         SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL),
11703         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
11704         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
11705         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
11706         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11707         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
11708         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
11709         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
11710         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
11711         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
11712         {}
11713 };
11714
11715 static struct alc_config_preset alc268_presets[] = {
11716         [ALC267_QUANTA_IL1] = {
11717                 .mixers = { alc267_quanta_il1_mixer },
11718                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11719                                 alc267_quanta_il1_verbs },
11720                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11721                 .dac_nids = alc268_dac_nids,
11722                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11723                 .adc_nids = alc268_adc_nids_alt,
11724                 .hp_nid = 0x03,
11725                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11726                 .channel_mode = alc268_modes,
11727                 .input_mux = &alc268_capture_source,
11728                 .unsol_event = alc267_quanta_il1_unsol_event,
11729                 .init_hook = alc267_quanta_il1_automute,
11730         },
11731         [ALC268_3ST] = {
11732                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11733                             alc268_beep_mixer },
11734                 .init_verbs = { alc268_base_init_verbs },
11735                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11736                 .dac_nids = alc268_dac_nids,
11737                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11738                 .adc_nids = alc268_adc_nids_alt,
11739                 .capsrc_nids = alc268_capsrc_nids,
11740                 .hp_nid = 0x03,
11741                 .dig_out_nid = ALC268_DIGOUT_NID,
11742                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11743                 .channel_mode = alc268_modes,
11744                 .input_mux = &alc268_capture_source,
11745         },
11746         [ALC268_TOSHIBA] = {
11747                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11748                             alc268_beep_mixer },
11749                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11750                                 alc268_toshiba_verbs },
11751                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11752                 .dac_nids = alc268_dac_nids,
11753                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11754                 .adc_nids = alc268_adc_nids_alt,
11755                 .capsrc_nids = alc268_capsrc_nids,
11756                 .hp_nid = 0x03,
11757                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11758                 .channel_mode = alc268_modes,
11759                 .input_mux = &alc268_capture_source,
11760                 .unsol_event = alc268_toshiba_unsol_event,
11761                 .init_hook = alc268_toshiba_automute,
11762         },
11763         [ALC268_ACER] = {
11764                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
11765                             alc268_beep_mixer },
11766                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11767                                 alc268_acer_verbs },
11768                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11769                 .dac_nids = alc268_dac_nids,
11770                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11771                 .adc_nids = alc268_adc_nids_alt,
11772                 .capsrc_nids = alc268_capsrc_nids,
11773                 .hp_nid = 0x02,
11774                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11775                 .channel_mode = alc268_modes,
11776                 .input_mux = &alc268_acer_capture_source,
11777                 .unsol_event = alc268_acer_unsol_event,
11778                 .init_hook = alc268_acer_init_hook,
11779         },
11780         [ALC268_ACER_DMIC] = {
11781                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
11782                             alc268_beep_mixer },
11783                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11784                                 alc268_acer_verbs },
11785                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11786                 .dac_nids = alc268_dac_nids,
11787                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11788                 .adc_nids = alc268_adc_nids_alt,
11789                 .capsrc_nids = alc268_capsrc_nids,
11790                 .hp_nid = 0x02,
11791                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11792                 .channel_mode = alc268_modes,
11793                 .input_mux = &alc268_acer_dmic_capture_source,
11794                 .unsol_event = alc268_acer_unsol_event,
11795                 .init_hook = alc268_acer_init_hook,
11796         },
11797         [ALC268_ACER_ASPIRE_ONE] = {
11798                 .mixers = { alc268_acer_aspire_one_mixer,
11799                                 alc268_capture_alt_mixer },
11800                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11801                                 alc268_acer_aspire_one_verbs },
11802                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11803                 .dac_nids = alc268_dac_nids,
11804                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11805                 .adc_nids = alc268_adc_nids_alt,
11806                 .capsrc_nids = alc268_capsrc_nids,
11807                 .hp_nid = 0x03,
11808                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11809                 .channel_mode = alc268_modes,
11810                 .input_mux = &alc268_acer_lc_capture_source,
11811                 .unsol_event = alc268_acer_lc_unsol_event,
11812                 .init_hook = alc268_acer_lc_init_hook,
11813         },
11814         [ALC268_DELL] = {
11815                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
11816                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11817                                 alc268_dell_verbs },
11818                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11819                 .dac_nids = alc268_dac_nids,
11820                 .hp_nid = 0x02,
11821                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11822                 .channel_mode = alc268_modes,
11823                 .unsol_event = alc268_dell_unsol_event,
11824                 .init_hook = alc268_dell_init_hook,
11825                 .input_mux = &alc268_capture_source,
11826         },
11827         [ALC268_ZEPTO] = {
11828                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11829                             alc268_beep_mixer },
11830                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11831                                 alc268_toshiba_verbs },
11832                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11833                 .dac_nids = alc268_dac_nids,
11834                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11835                 .adc_nids = alc268_adc_nids_alt,
11836                 .capsrc_nids = alc268_capsrc_nids,
11837                 .hp_nid = 0x03,
11838                 .dig_out_nid = ALC268_DIGOUT_NID,
11839                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11840                 .channel_mode = alc268_modes,
11841                 .input_mux = &alc268_capture_source,
11842                 .unsol_event = alc268_toshiba_unsol_event,
11843                 .init_hook = alc268_toshiba_automute
11844         },
11845 #ifdef CONFIG_SND_DEBUG
11846         [ALC268_TEST] = {
11847                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11848                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11849                                 alc268_volume_init_verbs },
11850                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11851                 .dac_nids = alc268_dac_nids,
11852                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11853                 .adc_nids = alc268_adc_nids_alt,
11854                 .capsrc_nids = alc268_capsrc_nids,
11855                 .hp_nid = 0x03,
11856                 .dig_out_nid = ALC268_DIGOUT_NID,
11857                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11858                 .channel_mode = alc268_modes,
11859                 .input_mux = &alc268_capture_source,
11860         },
11861 #endif
11862 };
11863
11864 static int patch_alc268(struct hda_codec *codec)
11865 {
11866         struct alc_spec *spec;
11867         int board_config;
11868         int err;
11869
11870         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11871         if (spec == NULL)
11872                 return -ENOMEM;
11873
11874         codec->spec = spec;
11875
11876         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11877                                                   alc268_models,
11878                                                   alc268_cfg_tbl);
11879
11880         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11881                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11882                        "trying auto-probe from BIOS...\n");
11883                 board_config = ALC268_AUTO;
11884         }
11885
11886         if (board_config == ALC268_AUTO) {
11887                 /* automatic parse from the BIOS config */
11888                 err = alc268_parse_auto_config(codec);
11889                 if (err < 0) {
11890                         alc_free(codec);
11891                         return err;
11892                 } else if (!err) {
11893                         printk(KERN_INFO
11894                                "hda_codec: Cannot set up configuration "
11895                                "from BIOS.  Using base mode...\n");
11896                         board_config = ALC268_3ST;
11897                 }
11898         }
11899
11900         if (board_config != ALC268_AUTO)
11901                 setup_preset(spec, &alc268_presets[board_config]);
11902
11903         if (codec->vendor_id == 0x10ec0267) {
11904                 spec->stream_name_analog = "ALC267 Analog";
11905                 spec->stream_name_digital = "ALC267 Digital";
11906         } else {
11907                 spec->stream_name_analog = "ALC268 Analog";
11908                 spec->stream_name_digital = "ALC268 Digital";
11909         }
11910
11911         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11912         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11913         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11914
11915         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11916
11917         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11918                 /* override the amp caps for beep generator */
11919                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11920                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11921                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11922                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11923                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11924
11925         if (!spec->adc_nids && spec->input_mux) {
11926                 /* check whether NID 0x07 is valid */
11927                 unsigned int wcap = get_wcaps(codec, 0x07);
11928                 int i;
11929
11930                 /* get type */
11931                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11932                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11933                         spec->adc_nids = alc268_adc_nids_alt;
11934                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11935                         add_mixer(spec, alc268_capture_alt_mixer);
11936                 } else {
11937                         spec->adc_nids = alc268_adc_nids;
11938                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11939                         add_mixer(spec, alc268_capture_mixer);
11940                 }
11941                 spec->capsrc_nids = alc268_capsrc_nids;
11942                 /* set default input source */
11943                 for (i = 0; i < spec->num_adc_nids; i++)
11944                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11945                                 0, AC_VERB_SET_CONNECT_SEL,
11946                                 spec->input_mux->items[0].index);
11947         }
11948
11949         spec->vmaster_nid = 0x02;
11950
11951         codec->patch_ops = alc_patch_ops;
11952         if (board_config == ALC268_AUTO)
11953                 spec->init_hook = alc268_auto_init;
11954
11955         codec->proc_widget_hook = print_realtek_coef;
11956
11957         return 0;
11958 }
11959
11960 /*
11961  *  ALC269 channel source setting (2 channel)
11962  */
11963 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11964
11965 #define alc269_dac_nids         alc260_dac_nids
11966
11967 static hda_nid_t alc269_adc_nids[1] = {
11968         /* ADC1 */
11969         0x08,
11970 };
11971
11972 static hda_nid_t alc269_capsrc_nids[1] = {
11973         0x23,
11974 };
11975
11976 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11977  *       not a mux!
11978  */
11979
11980 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11981         .num_items = 2,
11982         .items = {
11983                 { "i-Mic", 0x5 },
11984                 { "e-Mic", 0x0 },
11985         },
11986 };
11987
11988 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11989         .num_items = 2,
11990         .items = {
11991                 { "i-Mic", 0x1 },
11992                 { "e-Mic", 0x0 },
11993         },
11994 };
11995
11996 #define alc269_modes            alc260_modes
11997 #define alc269_capture_source   alc880_lg_lw_capture_source
11998
11999 static struct snd_kcontrol_new alc269_base_mixer[] = {
12000         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12001         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12002         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12003         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12004         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12005         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12006         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12007         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12008         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12009         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12010         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12011         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12012         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12013         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12014         { } /* end */
12015 };
12016
12017 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12018         /* output mixer control */
12019         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12020         {
12021                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12022                 .name = "Master Playback Switch",
12023                 .info = snd_hda_mixer_amp_switch_info,
12024                 .get = snd_hda_mixer_amp_switch_get,
12025                 .put = alc268_acer_master_sw_put,
12026                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12027         },
12028         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12029         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12030         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12031         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12032         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12033         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12034         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12035         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12036         { }
12037 };
12038
12039 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12040         /* output mixer control */
12041         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12042         {
12043                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12044                 .name = "Master Playback Switch",
12045                 .info = snd_hda_mixer_amp_switch_info,
12046                 .get = snd_hda_mixer_amp_switch_get,
12047                 .put = alc268_acer_master_sw_put,
12048                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12049         },
12050         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12051         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12052         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12053         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12054         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12055         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12056         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12057         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12058         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12059         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12060         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12061         { }
12062 };
12063
12064 /* bind volumes of both NID 0x0c and 0x0d */
12065 static struct hda_bind_ctls alc269_epc_bind_vol = {
12066         .ops = &snd_hda_bind_vol,
12067         .values = {
12068                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12069                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12070                 0
12071         },
12072 };
12073
12074 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12075         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12076         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
12077         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12078         { } /* end */
12079 };
12080
12081 /* capture mixer elements */
12082 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12083         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12084         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12085         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12086         { } /* end */
12087 };
12088
12089 /* FSC amilo */
12090 static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
12091         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12092         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12093         HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12094         { } /* end */
12095 };
12096
12097 /* beep control */
12098 static struct snd_kcontrol_new alc269_beep_mixer[] = {
12099         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12100         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12101         { } /* end */
12102 };
12103
12104 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12105         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12106         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12107         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12108         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12109         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12110         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12111         { }
12112 };
12113
12114 static struct hda_verb alc269_lifebook_verbs[] = {
12115         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12116         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12117         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12118         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12119         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12120         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12121         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12122         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12123         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12124         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12125         { }
12126 };
12127
12128 /* toggle speaker-output according to the hp-jack state */
12129 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
12130 {
12131         unsigned int present;
12132         unsigned char bits;
12133
12134         present = snd_hda_codec_read(codec, 0x15, 0,
12135                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12136         bits = present ? AMP_IN_MUTE(0) : 0;
12137         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12138                         AMP_IN_MUTE(0), bits);
12139         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12140                         AMP_IN_MUTE(0), bits);
12141
12142         snd_hda_codec_write(codec, 0x20, 0,
12143                         AC_VERB_SET_COEF_INDEX, 0x0c);
12144         snd_hda_codec_write(codec, 0x20, 0,
12145                         AC_VERB_SET_PROC_COEF, 0x680);
12146
12147         snd_hda_codec_write(codec, 0x20, 0,
12148                         AC_VERB_SET_COEF_INDEX, 0x0c);
12149         snd_hda_codec_write(codec, 0x20, 0,
12150                         AC_VERB_SET_PROC_COEF, 0x480);
12151 }
12152
12153 /* toggle speaker-output according to the hp-jacks state */
12154 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12155 {
12156         unsigned int present;
12157         unsigned char bits;
12158
12159         /* Check laptop headphone socket */
12160         present = snd_hda_codec_read(codec, 0x15, 0,
12161                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12162
12163         /* Check port replicator headphone socket */
12164         present |= snd_hda_codec_read(codec, 0x1a, 0,
12165                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12166
12167         bits = present ? AMP_IN_MUTE(0) : 0;
12168         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12169                         AMP_IN_MUTE(0), bits);
12170         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12171                         AMP_IN_MUTE(0), bits);
12172
12173         snd_hda_codec_write(codec, 0x20, 0,
12174                         AC_VERB_SET_COEF_INDEX, 0x0c);
12175         snd_hda_codec_write(codec, 0x20, 0,
12176                         AC_VERB_SET_PROC_COEF, 0x680);
12177
12178         snd_hda_codec_write(codec, 0x20, 0,
12179                         AC_VERB_SET_COEF_INDEX, 0x0c);
12180         snd_hda_codec_write(codec, 0x20, 0,
12181                         AC_VERB_SET_PROC_COEF, 0x480);
12182 }
12183
12184 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12185 {
12186         unsigned int present;
12187
12188         present = snd_hda_codec_read(codec, 0x18, 0,
12189                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12190         snd_hda_codec_write(codec, 0x23, 0,
12191                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
12192 }
12193
12194 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12195 {
12196         unsigned int present_laptop;
12197         unsigned int present_dock;
12198
12199         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
12200                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12201
12202         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
12203                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12204
12205         /* Laptop mic port overrides dock mic port, design decision */
12206         if (present_dock)
12207                 snd_hda_codec_write(codec, 0x23, 0,
12208                                 AC_VERB_SET_CONNECT_SEL, 0x3);
12209         if (present_laptop)
12210                 snd_hda_codec_write(codec, 0x23, 0,
12211                                 AC_VERB_SET_CONNECT_SEL, 0x0);
12212         if (!present_dock && !present_laptop)
12213                 snd_hda_codec_write(codec, 0x23, 0,
12214                                 AC_VERB_SET_CONNECT_SEL, 0x1);
12215 }
12216
12217 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
12218                                     unsigned int res)
12219 {
12220         if ((res >> 26) == ALC880_HP_EVENT)
12221                 alc269_quanta_fl1_speaker_automute(codec);
12222         if ((res >> 26) == ALC880_MIC_EVENT)
12223                 alc269_quanta_fl1_mic_automute(codec);
12224 }
12225
12226 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
12227                                         unsigned int res)
12228 {
12229         if ((res >> 26) == ALC880_HP_EVENT)
12230                 alc269_lifebook_speaker_automute(codec);
12231         if ((res >> 26) == ALC880_MIC_EVENT)
12232                 alc269_lifebook_mic_autoswitch(codec);
12233 }
12234
12235 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
12236 {
12237         alc269_quanta_fl1_speaker_automute(codec);
12238         alc269_quanta_fl1_mic_automute(codec);
12239 }
12240
12241 static void alc269_lifebook_init_hook(struct hda_codec *codec)
12242 {
12243         alc269_lifebook_speaker_automute(codec);
12244         alc269_lifebook_mic_autoswitch(codec);
12245 }
12246
12247 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
12248         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12249         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
12250         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12251         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
12252         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12253         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12254         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12255         {}
12256 };
12257
12258 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
12259         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12260         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
12261         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12262         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
12263         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12264         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12265         {}
12266 };
12267
12268 /* toggle speaker-output according to the hp-jack state */
12269 static void alc269_speaker_automute(struct hda_codec *codec)
12270 {
12271         unsigned int present;
12272         unsigned char bits;
12273
12274         present = snd_hda_codec_read(codec, 0x15, 0,
12275                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12276         bits = present ? AMP_IN_MUTE(0) : 0;
12277         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12278                                 AMP_IN_MUTE(0), bits);
12279         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12280                                 AMP_IN_MUTE(0), bits);
12281 }
12282
12283 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
12284 {
12285         unsigned int present;
12286
12287         present = snd_hda_codec_read(codec, 0x18, 0,
12288                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12289         snd_hda_codec_write(codec, 0x23, 0,
12290                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
12291 }
12292
12293 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
12294 {
12295         unsigned int present;
12296
12297         present = snd_hda_codec_read(codec, 0x18, 0,
12298                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12299         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12300                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12301         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12302                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12303 }
12304
12305 /* unsolicited event for HP jack sensing */
12306 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
12307                                      unsigned int res)
12308 {
12309         if ((res >> 26) == ALC880_HP_EVENT)
12310                 alc269_speaker_automute(codec);
12311
12312         if ((res >> 26) == ALC880_MIC_EVENT)
12313                 alc269_eeepc_dmic_automute(codec);
12314 }
12315
12316 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
12317 {
12318         alc269_speaker_automute(codec);
12319         alc269_eeepc_dmic_automute(codec);
12320 }
12321
12322 /* unsolicited event for HP jack sensing */
12323 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
12324                                      unsigned int res)
12325 {
12326         if ((res >> 26) == ALC880_HP_EVENT)
12327                 alc269_speaker_automute(codec);
12328
12329         if ((res >> 26) == ALC880_MIC_EVENT)
12330                 alc269_eeepc_amic_automute(codec);
12331 }
12332
12333 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
12334 {
12335         alc269_speaker_automute(codec);
12336         alc269_eeepc_amic_automute(codec);
12337 }
12338
12339 /*
12340  * generic initialization of ADC, input mixers and output mixers
12341  */
12342 static struct hda_verb alc269_init_verbs[] = {
12343         /*
12344          * Unmute ADC0 and set the default input to mic-in
12345          */
12346         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12347
12348         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
12349          * analog-loopback mixer widget
12350          * Note: PASD motherboards uses the Line In 2 as the input for
12351          * front panel mic (mic 2)
12352          */
12353         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12354         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12355         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12356         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12357         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12358         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12359
12360         /*
12361          * Set up output mixers (0x0c - 0x0e)
12362          */
12363         /* set vol=0 to output mixers */
12364         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12365         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12366
12367         /* set up input amps for analog loopback */
12368         /* Amp Indices: DAC = 0, mixer = 1 */
12369         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12370         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12371         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12372         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12373         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12374         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12375
12376         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12377         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12378         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12379         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12380         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12381         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12382         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12383
12384         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12385         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12386         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12387         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12388         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12389         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12390         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12391
12392         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12393         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12394
12395         /* FIXME: use matrix-type input source selection */
12396         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12397         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12398         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12399         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12400         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12401         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12402
12403         /* set EAPD */
12404         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12405         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12406         { }
12407 };
12408
12409 /* add playback controls from the parsed DAC table */
12410 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12411                                              const struct auto_pin_cfg *cfg)
12412 {
12413         hda_nid_t nid;
12414         int err;
12415
12416         spec->multiout.num_dacs = 1;    /* only use one dac */
12417         spec->multiout.dac_nids = spec->private_dac_nids;
12418         spec->multiout.dac_nids[0] = 2;
12419
12420         nid = cfg->line_out_pins[0];
12421         if (nid) {
12422                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12423                                   "Front Playback Volume",
12424                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12425                 if (err < 0)
12426                         return err;
12427                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12428                                   "Front Playback Switch",
12429                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12430                 if (err < 0)
12431                         return err;
12432         }
12433
12434         nid = cfg->speaker_pins[0];
12435         if (nid) {
12436                 if (!cfg->line_out_pins[0]) {
12437                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12438                                           "Speaker Playback Volume",
12439                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12440                                                               HDA_OUTPUT));
12441                         if (err < 0)
12442                                 return err;
12443                 }
12444                 if (nid == 0x16) {
12445                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12446                                           "Speaker Playback Switch",
12447                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12448                                                               HDA_OUTPUT));
12449                         if (err < 0)
12450                                 return err;
12451                 } else {
12452                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12453                                           "Speaker Playback Switch",
12454                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12455                                                               HDA_OUTPUT));
12456                         if (err < 0)
12457                                 return err;
12458                 }
12459         }
12460         nid = cfg->hp_pins[0];
12461         if (nid) {
12462                 /* spec->multiout.hp_nid = 2; */
12463                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12464                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12465                                           "Headphone Playback Volume",
12466                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12467                                                               HDA_OUTPUT));
12468                         if (err < 0)
12469                                 return err;
12470                 }
12471                 if (nid == 0x16) {
12472                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12473                                           "Headphone Playback Switch",
12474                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12475                                                               HDA_OUTPUT));
12476                         if (err < 0)
12477                                 return err;
12478                 } else {
12479                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12480                                           "Headphone Playback Switch",
12481                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12482                                                               HDA_OUTPUT));
12483                         if (err < 0)
12484                                 return err;
12485                 }
12486         }
12487         return 0;
12488 }
12489
12490 static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
12491                                                 const struct auto_pin_cfg *cfg)
12492 {
12493         int err;
12494
12495         err = alc880_auto_create_analog_input_ctls(spec, cfg);
12496         if (err < 0)
12497                 return err;
12498         /* digital-mic input pin is excluded in alc880_auto_create..()
12499          * because it's under 0x18
12500          */
12501         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
12502             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
12503                 struct hda_input_mux *imux = &spec->private_imux;
12504                 imux->items[imux->num_items].label = "Int Mic";
12505                 imux->items[imux->num_items].index = 0x05;
12506                 imux->num_items++;
12507         }
12508         return 0;
12509 }
12510
12511 #ifdef CONFIG_SND_HDA_POWER_SAVE
12512 #define alc269_loopbacks        alc880_loopbacks
12513 #endif
12514
12515 /* pcm configuration: identiacal with ALC880 */
12516 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12517 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12518 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12519 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12520
12521 /*
12522  * BIOS auto configuration
12523  */
12524 static int alc269_parse_auto_config(struct hda_codec *codec)
12525 {
12526         struct alc_spec *spec = codec->spec;
12527         int i, err;
12528         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12529
12530         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12531                                            alc269_ignore);
12532         if (err < 0)
12533                 return err;
12534
12535         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12536         if (err < 0)
12537                 return err;
12538         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12539         if (err < 0)
12540                 return err;
12541
12542         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12543
12544         if (spec->autocfg.dig_out_pin)
12545                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12546
12547         if (spec->kctls.list)
12548                 add_mixer(spec, spec->kctls.list);
12549
12550         /* create a beep mixer control if the pin 0x1d isn't assigned */
12551         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12552                 if (spec->autocfg.input_pins[i] == 0x1d)
12553                         break;
12554         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12555                 add_mixer(spec, alc269_beep_mixer);
12556
12557         add_verb(spec, alc269_init_verbs);
12558         spec->num_mux_defs = 1;
12559         spec->input_mux = &spec->private_imux;
12560         /* set default input source */
12561         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12562                                   0, AC_VERB_SET_CONNECT_SEL,
12563                                   spec->input_mux->items[0].index);
12564
12565         err = alc_auto_add_mic_boost(codec);
12566         if (err < 0)
12567                 return err;
12568
12569         if (!spec->cap_mixer)
12570                 set_capture_mixer(spec);
12571
12572         store_pin_configs(codec);
12573         return 1;
12574 }
12575
12576 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12577 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12578 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12579
12580
12581 /* init callback for auto-configuration model -- overriding the default init */
12582 static void alc269_auto_init(struct hda_codec *codec)
12583 {
12584         struct alc_spec *spec = codec->spec;
12585         alc269_auto_init_multi_out(codec);
12586         alc269_auto_init_hp_out(codec);
12587         alc269_auto_init_analog_input(codec);
12588         if (spec->unsol_event)
12589                 alc_inithook(codec);
12590 }
12591
12592 /*
12593  * configuration and preset
12594  */
12595 static const char *alc269_models[ALC269_MODEL_LAST] = {
12596         [ALC269_BASIC]                  = "basic",
12597         [ALC269_QUANTA_FL1]             = "quanta",
12598         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12599         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
12600         [ALC269_FUJITSU]                = "fujitsu",
12601         [ALC269_LIFEBOOK]               = "lifebook"
12602 };
12603
12604 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12605         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12606         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12607                       ALC269_ASUS_EEEPC_P703),
12608         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12609                       ALC269_ASUS_EEEPC_P901),
12610         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12611                       ALC269_ASUS_EEEPC_P901),
12612         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
12613         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
12614         {}
12615 };
12616
12617 static struct alc_config_preset alc269_presets[] = {
12618         [ALC269_BASIC] = {
12619                 .mixers = { alc269_base_mixer },
12620                 .init_verbs = { alc269_init_verbs },
12621                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12622                 .dac_nids = alc269_dac_nids,
12623                 .hp_nid = 0x03,
12624                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12625                 .channel_mode = alc269_modes,
12626                 .input_mux = &alc269_capture_source,
12627         },
12628         [ALC269_QUANTA_FL1] = {
12629                 .mixers = { alc269_quanta_fl1_mixer },
12630                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_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_capture_source,
12637                 .unsol_event = alc269_quanta_fl1_unsol_event,
12638                 .init_hook = alc269_quanta_fl1_init_hook,
12639         },
12640         [ALC269_ASUS_EEEPC_P703] = {
12641                 .mixers = { alc269_eeepc_mixer },
12642                 .cap_mixer = alc269_epc_capture_mixer,
12643                 .init_verbs = { alc269_init_verbs,
12644                                 alc269_eeepc_amic_init_verbs },
12645                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12646                 .dac_nids = alc269_dac_nids,
12647                 .hp_nid = 0x03,
12648                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12649                 .channel_mode = alc269_modes,
12650                 .input_mux = &alc269_eeepc_amic_capture_source,
12651                 .unsol_event = alc269_eeepc_amic_unsol_event,
12652                 .init_hook = alc269_eeepc_amic_inithook,
12653         },
12654         [ALC269_ASUS_EEEPC_P901] = {
12655                 .mixers = { alc269_eeepc_mixer },
12656                 .cap_mixer = alc269_epc_capture_mixer,
12657                 .init_verbs = { alc269_init_verbs,
12658                                 alc269_eeepc_dmic_init_verbs },
12659                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12660                 .dac_nids = alc269_dac_nids,
12661                 .hp_nid = 0x03,
12662                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12663                 .channel_mode = alc269_modes,
12664                 .input_mux = &alc269_eeepc_dmic_capture_source,
12665                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12666                 .init_hook = alc269_eeepc_dmic_inithook,
12667         },
12668         [ALC269_FUJITSU] = {
12669                 .mixers = { alc269_fujitsu_mixer, alc269_beep_mixer },
12670                 .cap_mixer = alc269_epc_capture_mixer,
12671                 .init_verbs = { alc269_init_verbs,
12672                                 alc269_eeepc_dmic_init_verbs },
12673                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12674                 .dac_nids = alc269_dac_nids,
12675                 .hp_nid = 0x03,
12676                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12677                 .channel_mode = alc269_modes,
12678                 .input_mux = &alc269_eeepc_dmic_capture_source,
12679                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12680                 .init_hook = alc269_eeepc_dmic_inithook,
12681         },
12682         [ALC269_LIFEBOOK] = {
12683                 .mixers = { alc269_lifebook_mixer },
12684                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
12685                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12686                 .dac_nids = alc269_dac_nids,
12687                 .hp_nid = 0x03,
12688                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12689                 .channel_mode = alc269_modes,
12690                 .input_mux = &alc269_capture_source,
12691                 .unsol_event = alc269_lifebook_unsol_event,
12692                 .init_hook = alc269_lifebook_init_hook,
12693         },
12694 };
12695
12696 static int patch_alc269(struct hda_codec *codec)
12697 {
12698         struct alc_spec *spec;
12699         int board_config;
12700         int err;
12701
12702         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12703         if (spec == NULL)
12704                 return -ENOMEM;
12705
12706         codec->spec = spec;
12707
12708         alc_fix_pll_init(codec, 0x20, 0x04, 15);
12709
12710         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
12711                                                   alc269_models,
12712                                                   alc269_cfg_tbl);
12713
12714         if (board_config < 0) {
12715                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
12716                        "trying auto-probe from BIOS...\n");
12717                 board_config = ALC269_AUTO;
12718         }
12719
12720         if (board_config == ALC269_AUTO) {
12721                 /* automatic parse from the BIOS config */
12722                 err = alc269_parse_auto_config(codec);
12723                 if (err < 0) {
12724                         alc_free(codec);
12725                         return err;
12726                 } else if (!err) {
12727                         printk(KERN_INFO
12728                                "hda_codec: Cannot set up configuration "
12729                                "from BIOS.  Using base mode...\n");
12730                         board_config = ALC269_BASIC;
12731                 }
12732         }
12733
12734         if (board_config != ALC269_AUTO)
12735                 setup_preset(spec, &alc269_presets[board_config]);
12736
12737         spec->stream_name_analog = "ALC269 Analog";
12738         spec->stream_analog_playback = &alc269_pcm_analog_playback;
12739         spec->stream_analog_capture = &alc269_pcm_analog_capture;
12740
12741         spec->stream_name_digital = "ALC269 Digital";
12742         spec->stream_digital_playback = &alc269_pcm_digital_playback;
12743         spec->stream_digital_capture = &alc269_pcm_digital_capture;
12744
12745         spec->adc_nids = alc269_adc_nids;
12746         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12747         spec->capsrc_nids = alc269_capsrc_nids;
12748         if (!spec->cap_mixer)
12749                 set_capture_mixer(spec);
12750
12751         codec->patch_ops = alc_patch_ops;
12752         if (board_config == ALC269_AUTO)
12753                 spec->init_hook = alc269_auto_init;
12754 #ifdef CONFIG_SND_HDA_POWER_SAVE
12755         if (!spec->loopback.amplist)
12756                 spec->loopback.amplist = alc269_loopbacks;
12757 #endif
12758         codec->proc_widget_hook = print_realtek_coef;
12759
12760         return 0;
12761 }
12762
12763 /*
12764  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
12765  */
12766
12767 /*
12768  * set the path ways for 2 channel output
12769  * need to set the codec line out and mic 1 pin widgets to inputs
12770  */
12771 static struct hda_verb alc861_threestack_ch2_init[] = {
12772         /* set pin widget 1Ah (line in) for input */
12773         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12774         /* set pin widget 18h (mic1/2) for input, for mic also enable
12775          * the vref
12776          */
12777         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12778
12779         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12780 #if 0
12781         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12782         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12783 #endif
12784         { } /* end */
12785 };
12786 /*
12787  * 6ch mode
12788  * need to set the codec line out and mic 1 pin widgets to outputs
12789  */
12790 static struct hda_verb alc861_threestack_ch6_init[] = {
12791         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12792         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12793         /* set pin widget 18h (mic1) for output (CLFE)*/
12794         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12795
12796         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12797         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12798
12799         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12800 #if 0
12801         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12802         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12803 #endif
12804         { } /* end */
12805 };
12806
12807 static struct hda_channel_mode alc861_threestack_modes[2] = {
12808         { 2, alc861_threestack_ch2_init },
12809         { 6, alc861_threestack_ch6_init },
12810 };
12811 /* Set mic1 as input and unmute the mixer */
12812 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
12813         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12814         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12815         { } /* end */
12816 };
12817 /* Set mic1 as output and mute mixer */
12818 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
12819         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12820         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12821         { } /* end */
12822 };
12823
12824 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
12825         { 2, alc861_uniwill_m31_ch2_init },
12826         { 4, alc861_uniwill_m31_ch4_init },
12827 };
12828
12829 /* Set mic1 and line-in as input and unmute the mixer */
12830 static struct hda_verb alc861_asus_ch2_init[] = {
12831         /* set pin widget 1Ah (line in) for input */
12832         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12833         /* set pin widget 18h (mic1/2) for input, for mic also enable
12834          * the vref
12835          */
12836         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12837
12838         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12839 #if 0
12840         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12841         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12842 #endif
12843         { } /* end */
12844 };
12845 /* Set mic1 nad line-in as output and mute mixer */
12846 static struct hda_verb alc861_asus_ch6_init[] = {
12847         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12848         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12849         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12850         /* set pin widget 18h (mic1) for output (CLFE)*/
12851         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12852         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12853         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12854         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12855
12856         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12857 #if 0
12858         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12859         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12860 #endif
12861         { } /* end */
12862 };
12863
12864 static struct hda_channel_mode alc861_asus_modes[2] = {
12865         { 2, alc861_asus_ch2_init },
12866         { 6, alc861_asus_ch6_init },
12867 };
12868
12869 /* patch-ALC861 */
12870
12871 static struct snd_kcontrol_new alc861_base_mixer[] = {
12872         /* output mixer control */
12873         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12874         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12875         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12876         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12877         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12878
12879         /*Input mixer control */
12880         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12881            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12882         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12883         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12884         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12885         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12886         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12887         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12888         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12889         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12890
12891         { } /* end */
12892 };
12893
12894 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12895         /* output mixer control */
12896         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12897         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12898         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12899         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12900         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12901
12902         /* Input mixer control */
12903         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12904            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12905         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12906         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12907         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12908         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12909         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12910         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12911         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12912         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12913
12914         {
12915                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12916                 .name = "Channel Mode",
12917                 .info = alc_ch_mode_info,
12918                 .get = alc_ch_mode_get,
12919                 .put = alc_ch_mode_put,
12920                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
12921         },
12922         { } /* end */
12923 };
12924
12925 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
12926         /* output mixer control */
12927         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12928         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12929         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12930
12931         { } /* end */
12932 };
12933
12934 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
12935         /* output mixer control */
12936         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12937         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12938         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12939         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12940         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12941
12942         /* Input mixer control */
12943         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12944            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12945         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12946         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12947         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12948         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12949         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12950         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12951         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12952         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12953
12954         {
12955                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12956                 .name = "Channel Mode",
12957                 .info = alc_ch_mode_info,
12958                 .get = alc_ch_mode_get,
12959                 .put = alc_ch_mode_put,
12960                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
12961         },
12962         { } /* end */
12963 };
12964
12965 static struct snd_kcontrol_new alc861_asus_mixer[] = {
12966         /* output mixer control */
12967         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12968         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12969         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12970         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12971         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12972
12973         /* Input mixer control */
12974         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12975         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12976         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12977         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12978         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12979         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12980         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12981         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12982         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12983         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
12984
12985         {
12986                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12987                 .name = "Channel Mode",
12988                 .info = alc_ch_mode_info,
12989                 .get = alc_ch_mode_get,
12990                 .put = alc_ch_mode_put,
12991                 .private_value = ARRAY_SIZE(alc861_asus_modes),
12992         },
12993         { }
12994 };
12995
12996 /* additional mixer */
12997 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
12998         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12999         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13000         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
13001         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
13002         { }
13003 };
13004
13005 /*
13006  * generic initialization of ADC, input mixers and output mixers
13007  */
13008 static struct hda_verb alc861_base_init_verbs[] = {
13009         /*
13010          * Unmute ADC0 and set the default input to mic-in
13011          */
13012         /* port-A for surround (rear panel) */
13013         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13014         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13015         /* port-B for mic-in (rear panel) with vref */
13016         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13017         /* port-C for line-in (rear panel) */
13018         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13019         /* port-D for Front */
13020         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13021         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13022         /* port-E for HP out (front panel) */
13023         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13024         /* route front PCM to HP */
13025         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13026         /* port-F for mic-in (front panel) with vref */
13027         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13028         /* port-G for CLFE (rear panel) */
13029         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13030         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13031         /* port-H for side (rear panel) */
13032         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13033         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13034         /* CD-in */
13035         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13036         /* route front mic to ADC1*/
13037         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13038         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13039
13040         /* Unmute DAC0~3 & spdif out*/
13041         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13042         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13043         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13044         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13045         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13046
13047         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13048         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13049         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13050         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13051         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13052
13053         /* Unmute Stereo Mixer 15 */
13054         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13055         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13056         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13057         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13058
13059         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13060         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13061         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13062         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13063         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13064         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13065         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13066         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13067         /* hp used DAC 3 (Front) */
13068         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13069         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13070
13071         { }
13072 };
13073
13074 static struct hda_verb alc861_threestack_init_verbs[] = {
13075         /*
13076          * Unmute ADC0 and set the default input to mic-in
13077          */
13078         /* port-A for surround (rear panel) */
13079         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13080         /* port-B for mic-in (rear panel) with vref */
13081         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13082         /* port-C for line-in (rear panel) */
13083         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13084         /* port-D for Front */
13085         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13086         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13087         /* port-E for HP out (front panel) */
13088         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13089         /* route front PCM to HP */
13090         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13091         /* port-F for mic-in (front panel) with vref */
13092         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13093         /* port-G for CLFE (rear panel) */
13094         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13095         /* port-H for side (rear panel) */
13096         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13097         /* CD-in */
13098         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13099         /* route front mic to ADC1*/
13100         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13101         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13102         /* Unmute DAC0~3 & spdif out*/
13103         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13104         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13105         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13106         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13107         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13108
13109         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13110         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13111         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13112         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13113         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13114
13115         /* Unmute Stereo Mixer 15 */
13116         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13117         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13118         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13119         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13120
13121         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13122         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13123         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13124         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13125         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13126         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13127         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13128         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13129         /* hp used DAC 3 (Front) */
13130         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13131         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13132         { }
13133 };
13134
13135 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13136         /*
13137          * Unmute ADC0 and set the default input to mic-in
13138          */
13139         /* port-A for surround (rear panel) */
13140         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13141         /* port-B for mic-in (rear panel) with vref */
13142         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13143         /* port-C for line-in (rear panel) */
13144         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13145         /* port-D for Front */
13146         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13147         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13148         /* port-E for HP out (front panel) */
13149         /* this has to be set to VREF80 */
13150         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13151         /* route front PCM to HP */
13152         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13153         /* port-F for mic-in (front panel) with vref */
13154         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13155         /* port-G for CLFE (rear panel) */
13156         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13157         /* port-H for side (rear panel) */
13158         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13159         /* CD-in */
13160         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13161         /* route front mic to ADC1*/
13162         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13163         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13164         /* Unmute DAC0~3 & spdif out*/
13165         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13166         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13167         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13168         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13169         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13170
13171         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13172         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13173         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13174         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13175         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13176
13177         /* Unmute Stereo Mixer 15 */
13178         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13179         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13180         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13181         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13182
13183         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13184         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13185         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13186         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13187         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13188         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13189         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13190         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13191         /* hp used DAC 3 (Front) */
13192         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13193         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13194         { }
13195 };
13196
13197 static struct hda_verb alc861_asus_init_verbs[] = {
13198         /*
13199          * Unmute ADC0 and set the default input to mic-in
13200          */
13201         /* port-A for surround (rear panel)
13202          * according to codec#0 this is the HP jack
13203          */
13204         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
13205         /* route front PCM to HP */
13206         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
13207         /* port-B for mic-in (rear panel) with vref */
13208         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13209         /* port-C for line-in (rear panel) */
13210         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13211         /* port-D for Front */
13212         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13213         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13214         /* port-E for HP out (front panel) */
13215         /* this has to be set to VREF80 */
13216         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13217         /* route front PCM to HP */
13218         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13219         /* port-F for mic-in (front panel) with vref */
13220         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13221         /* port-G for CLFE (rear panel) */
13222         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13223         /* port-H for side (rear panel) */
13224         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13225         /* CD-in */
13226         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13227         /* route front mic to ADC1*/
13228         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13229         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13230         /* Unmute DAC0~3 & spdif out*/
13231         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13232         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13233         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13234         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13235         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13236         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13237         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13238         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13239         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13240         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13241
13242         /* Unmute Stereo Mixer 15 */
13243         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13244         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13245         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13246         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13247
13248         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13249         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13250         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13251         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13252         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13253         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13254         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13255         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13256         /* hp used DAC 3 (Front) */
13257         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13258         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13259         { }
13260 };
13261
13262 /* additional init verbs for ASUS laptops */
13263 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
13264         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
13265         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
13266         { }
13267 };
13268
13269 /*
13270  * generic initialization of ADC, input mixers and output mixers
13271  */
13272 static struct hda_verb alc861_auto_init_verbs[] = {
13273         /*
13274          * Unmute ADC0 and set the default input to mic-in
13275          */
13276         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
13277         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13278
13279         /* Unmute DAC0~3 & spdif out*/
13280         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13281         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13282         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13283         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13284         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13285
13286         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13287         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13288         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13289         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13290         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13291
13292         /* Unmute Stereo Mixer 15 */
13293         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13294         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13295         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13296         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
13297
13298         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13299         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13300         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13301         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13302         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13303         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13304         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13305         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13306
13307         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13308         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13309         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13310         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13311         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13312         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13313         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13314         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13315
13316         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
13317
13318         { }
13319 };
13320
13321 static struct hda_verb alc861_toshiba_init_verbs[] = {
13322         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13323
13324         { }
13325 };
13326
13327 /* toggle speaker-output according to the hp-jack state */
13328 static void alc861_toshiba_automute(struct hda_codec *codec)
13329 {
13330         unsigned int present;
13331
13332         present = snd_hda_codec_read(codec, 0x0f, 0,
13333                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13334         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
13335                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13336         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
13337                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
13338 }
13339
13340 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
13341                                        unsigned int res)
13342 {
13343         if ((res >> 26) == ALC880_HP_EVENT)
13344                 alc861_toshiba_automute(codec);
13345 }
13346
13347 /* pcm configuration: identiacal with ALC880 */
13348 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
13349 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
13350 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
13351 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
13352
13353
13354 #define ALC861_DIGOUT_NID       0x07
13355
13356 static struct hda_channel_mode alc861_8ch_modes[1] = {
13357         { 8, NULL }
13358 };
13359
13360 static hda_nid_t alc861_dac_nids[4] = {
13361         /* front, surround, clfe, side */
13362         0x03, 0x06, 0x05, 0x04
13363 };
13364
13365 static hda_nid_t alc660_dac_nids[3] = {
13366         /* front, clfe, surround */
13367         0x03, 0x05, 0x06
13368 };
13369
13370 static hda_nid_t alc861_adc_nids[1] = {
13371         /* ADC0-2 */
13372         0x08,
13373 };
13374
13375 static struct hda_input_mux alc861_capture_source = {
13376         .num_items = 5,
13377         .items = {
13378                 { "Mic", 0x0 },
13379                 { "Front Mic", 0x3 },
13380                 { "Line", 0x1 },
13381                 { "CD", 0x4 },
13382                 { "Mixer", 0x5 },
13383         },
13384 };
13385
13386 /* fill in the dac_nids table from the parsed pin configuration */
13387 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13388                                      const struct auto_pin_cfg *cfg)
13389 {
13390         int i;
13391         hda_nid_t nid;
13392
13393         spec->multiout.dac_nids = spec->private_dac_nids;
13394         for (i = 0; i < cfg->line_outs; i++) {
13395                 nid = cfg->line_out_pins[i];
13396                 if (nid) {
13397                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13398                                 continue;
13399                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13400                 }
13401         }
13402         spec->multiout.num_dacs = cfg->line_outs;
13403         return 0;
13404 }
13405
13406 /* add playback controls from the parsed DAC table */
13407 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13408                                              const struct auto_pin_cfg *cfg)
13409 {
13410         char name[32];
13411         static const char *chname[4] = {
13412                 "Front", "Surround", NULL /*CLFE*/, "Side"
13413         };
13414         hda_nid_t nid;
13415         int i, idx, err;
13416
13417         for (i = 0; i < cfg->line_outs; i++) {
13418                 nid = spec->multiout.dac_nids[i];
13419                 if (!nid)
13420                         continue;
13421                 if (nid == 0x05) {
13422                         /* Center/LFE */
13423                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13424                                           "Center Playback Switch",
13425                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13426                                                               HDA_OUTPUT));
13427                         if (err < 0)
13428                                 return err;
13429                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13430                                           "LFE Playback Switch",
13431                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13432                                                               HDA_OUTPUT));
13433                         if (err < 0)
13434                                 return err;
13435                 } else {
13436                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13437                              idx++)
13438                                 if (nid == alc861_dac_nids[idx])
13439                                         break;
13440                         sprintf(name, "%s Playback Switch", chname[idx]);
13441                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13442                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13443                                                               HDA_OUTPUT));
13444                         if (err < 0)
13445                                 return err;
13446                 }
13447         }
13448         return 0;
13449 }
13450
13451 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13452 {
13453         int err;
13454         hda_nid_t nid;
13455
13456         if (!pin)
13457                 return 0;
13458
13459         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13460                 nid = 0x03;
13461                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13462                                   "Headphone Playback Switch",
13463                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13464                 if (err < 0)
13465                         return err;
13466                 spec->multiout.hp_nid = nid;
13467         }
13468         return 0;
13469 }
13470
13471 /* create playback/capture controls for input pins */
13472 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13473                                                 const struct auto_pin_cfg *cfg)
13474 {
13475         struct hda_input_mux *imux = &spec->private_imux;
13476         int i, err, idx, idx1;
13477
13478         for (i = 0; i < AUTO_PIN_LAST; i++) {
13479                 switch (cfg->input_pins[i]) {
13480                 case 0x0c:
13481                         idx1 = 1;
13482                         idx = 2;        /* Line In */
13483                         break;
13484                 case 0x0f:
13485                         idx1 = 2;
13486                         idx = 2;        /* Line In */
13487                         break;
13488                 case 0x0d:
13489                         idx1 = 0;
13490                         idx = 1;        /* Mic In */
13491                         break;
13492                 case 0x10:
13493                         idx1 = 3;
13494                         idx = 1;        /* Mic In */
13495                         break;
13496                 case 0x11:
13497                         idx1 = 4;
13498                         idx = 0;        /* CD */
13499                         break;
13500                 default:
13501                         continue;
13502                 }
13503
13504                 err = new_analog_input(spec, cfg->input_pins[i],
13505                                        auto_pin_cfg_labels[i], idx, 0x15);
13506                 if (err < 0)
13507                         return err;
13508
13509                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13510                 imux->items[imux->num_items].index = idx1;
13511                 imux->num_items++;
13512         }
13513         return 0;
13514 }
13515
13516 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13517                                               hda_nid_t nid,
13518                                               int pin_type, int dac_idx)
13519 {
13520         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13521                             pin_type);
13522         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13523                             AMP_OUT_UNMUTE);
13524 }
13525
13526 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13527 {
13528         struct alc_spec *spec = codec->spec;
13529         int i;
13530
13531         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13532         for (i = 0; i < spec->autocfg.line_outs; i++) {
13533                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13534                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13535                 if (nid)
13536                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13537                                                           spec->multiout.dac_nids[i]);
13538         }
13539 }
13540
13541 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13542 {
13543         struct alc_spec *spec = codec->spec;
13544         hda_nid_t pin;
13545
13546         pin = spec->autocfg.hp_pins[0];
13547         if (pin) /* connect to front */
13548                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13549                                                   spec->multiout.dac_nids[0]);
13550         pin = spec->autocfg.speaker_pins[0];
13551         if (pin)
13552                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13553 }
13554
13555 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13556 {
13557         struct alc_spec *spec = codec->spec;
13558         int i;
13559
13560         for (i = 0; i < AUTO_PIN_LAST; i++) {
13561                 hda_nid_t nid = spec->autocfg.input_pins[i];
13562                 if (nid >= 0x0c && nid <= 0x11) {
13563                         snd_hda_codec_write(codec, nid, 0,
13564                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13565                                             i <= AUTO_PIN_FRONT_MIC ?
13566                                             PIN_VREF80 : PIN_IN);
13567                 }
13568         }
13569 }
13570
13571 /* parse the BIOS configuration and set up the alc_spec */
13572 /* return 1 if successful, 0 if the proper config is not found,
13573  * or a negative error code
13574  */
13575 static int alc861_parse_auto_config(struct hda_codec *codec)
13576 {
13577         struct alc_spec *spec = codec->spec;
13578         int err;
13579         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13580
13581         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13582                                            alc861_ignore);
13583         if (err < 0)
13584                 return err;
13585         if (!spec->autocfg.line_outs)
13586                 return 0; /* can't find valid BIOS pin config */
13587
13588         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13589         if (err < 0)
13590                 return err;
13591         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13592         if (err < 0)
13593                 return err;
13594         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13595         if (err < 0)
13596                 return err;
13597         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13598         if (err < 0)
13599                 return err;
13600
13601         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13602
13603         if (spec->autocfg.dig_out_pin)
13604                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13605
13606         if (spec->kctls.list)
13607                 add_mixer(spec, spec->kctls.list);
13608
13609         add_verb(spec, alc861_auto_init_verbs);
13610
13611         spec->num_mux_defs = 1;
13612         spec->input_mux = &spec->private_imux;
13613
13614         spec->adc_nids = alc861_adc_nids;
13615         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13616         set_capture_mixer(spec);
13617
13618         store_pin_configs(codec);
13619         return 1;
13620 }
13621
13622 /* additional initialization for auto-configuration model */
13623 static void alc861_auto_init(struct hda_codec *codec)
13624 {
13625         struct alc_spec *spec = codec->spec;
13626         alc861_auto_init_multi_out(codec);
13627         alc861_auto_init_hp_out(codec);
13628         alc861_auto_init_analog_input(codec);
13629         if (spec->unsol_event)
13630                 alc_inithook(codec);
13631 }
13632
13633 #ifdef CONFIG_SND_HDA_POWER_SAVE
13634 static struct hda_amp_list alc861_loopbacks[] = {
13635         { 0x15, HDA_INPUT, 0 },
13636         { 0x15, HDA_INPUT, 1 },
13637         { 0x15, HDA_INPUT, 2 },
13638         { 0x15, HDA_INPUT, 3 },
13639         { } /* end */
13640 };
13641 #endif
13642
13643
13644 /*
13645  * configuration and preset
13646  */
13647 static const char *alc861_models[ALC861_MODEL_LAST] = {
13648         [ALC861_3ST]            = "3stack",
13649         [ALC660_3ST]            = "3stack-660",
13650         [ALC861_3ST_DIG]        = "3stack-dig",
13651         [ALC861_6ST_DIG]        = "6stack-dig",
13652         [ALC861_UNIWILL_M31]    = "uniwill-m31",
13653         [ALC861_TOSHIBA]        = "toshiba",
13654         [ALC861_ASUS]           = "asus",
13655         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
13656         [ALC861_AUTO]           = "auto",
13657 };
13658
13659 static struct snd_pci_quirk alc861_cfg_tbl[] = {
13660         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
13661         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13662         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13663         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
13664         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
13665         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
13666         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
13667         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
13668          *        Any other models that need this preset?
13669          */
13670         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
13671         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
13672         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
13673         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
13674         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
13675         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
13676         /* FIXME: the below seems conflict */
13677         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
13678         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
13679         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
13680         {}
13681 };
13682
13683 static struct alc_config_preset alc861_presets[] = {
13684         [ALC861_3ST] = {
13685                 .mixers = { alc861_3ST_mixer },
13686                 .init_verbs = { alc861_threestack_init_verbs },
13687                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13688                 .dac_nids = alc861_dac_nids,
13689                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13690                 .channel_mode = alc861_threestack_modes,
13691                 .need_dac_fix = 1,
13692                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13693                 .adc_nids = alc861_adc_nids,
13694                 .input_mux = &alc861_capture_source,
13695         },
13696         [ALC861_3ST_DIG] = {
13697                 .mixers = { alc861_base_mixer },
13698                 .init_verbs = { alc861_threestack_init_verbs },
13699                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13700                 .dac_nids = alc861_dac_nids,
13701                 .dig_out_nid = ALC861_DIGOUT_NID,
13702                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13703                 .channel_mode = alc861_threestack_modes,
13704                 .need_dac_fix = 1,
13705                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13706                 .adc_nids = alc861_adc_nids,
13707                 .input_mux = &alc861_capture_source,
13708         },
13709         [ALC861_6ST_DIG] = {
13710                 .mixers = { alc861_base_mixer },
13711                 .init_verbs = { alc861_base_init_verbs },
13712                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13713                 .dac_nids = alc861_dac_nids,
13714                 .dig_out_nid = ALC861_DIGOUT_NID,
13715                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
13716                 .channel_mode = alc861_8ch_modes,
13717                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13718                 .adc_nids = alc861_adc_nids,
13719                 .input_mux = &alc861_capture_source,
13720         },
13721         [ALC660_3ST] = {
13722                 .mixers = { alc861_3ST_mixer },
13723                 .init_verbs = { alc861_threestack_init_verbs },
13724                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
13725                 .dac_nids = alc660_dac_nids,
13726                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13727                 .channel_mode = alc861_threestack_modes,
13728                 .need_dac_fix = 1,
13729                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13730                 .adc_nids = alc861_adc_nids,
13731                 .input_mux = &alc861_capture_source,
13732         },
13733         [ALC861_UNIWILL_M31] = {
13734                 .mixers = { alc861_uniwill_m31_mixer },
13735                 .init_verbs = { alc861_uniwill_m31_init_verbs },
13736                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13737                 .dac_nids = alc861_dac_nids,
13738                 .dig_out_nid = ALC861_DIGOUT_NID,
13739                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
13740                 .channel_mode = alc861_uniwill_m31_modes,
13741                 .need_dac_fix = 1,
13742                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13743                 .adc_nids = alc861_adc_nids,
13744                 .input_mux = &alc861_capture_source,
13745         },
13746         [ALC861_TOSHIBA] = {
13747                 .mixers = { alc861_toshiba_mixer },
13748                 .init_verbs = { alc861_base_init_verbs,
13749                                 alc861_toshiba_init_verbs },
13750                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13751                 .dac_nids = alc861_dac_nids,
13752                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13753                 .channel_mode = alc883_3ST_2ch_modes,
13754                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13755                 .adc_nids = alc861_adc_nids,
13756                 .input_mux = &alc861_capture_source,
13757                 .unsol_event = alc861_toshiba_unsol_event,
13758                 .init_hook = alc861_toshiba_automute,
13759         },
13760         [ALC861_ASUS] = {
13761                 .mixers = { alc861_asus_mixer },
13762                 .init_verbs = { alc861_asus_init_verbs },
13763                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13764                 .dac_nids = alc861_dac_nids,
13765                 .dig_out_nid = ALC861_DIGOUT_NID,
13766                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
13767                 .channel_mode = alc861_asus_modes,
13768                 .need_dac_fix = 1,
13769                 .hp_nid = 0x06,
13770                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13771                 .adc_nids = alc861_adc_nids,
13772                 .input_mux = &alc861_capture_source,
13773         },
13774         [ALC861_ASUS_LAPTOP] = {
13775                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
13776                 .init_verbs = { alc861_asus_init_verbs,
13777                                 alc861_asus_laptop_init_verbs },
13778                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13779                 .dac_nids = alc861_dac_nids,
13780                 .dig_out_nid = ALC861_DIGOUT_NID,
13781                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13782                 .channel_mode = alc883_3ST_2ch_modes,
13783                 .need_dac_fix = 1,
13784                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13785                 .adc_nids = alc861_adc_nids,
13786                 .input_mux = &alc861_capture_source,
13787         },
13788 };
13789
13790
13791 static int patch_alc861(struct hda_codec *codec)
13792 {
13793         struct alc_spec *spec;
13794         int board_config;
13795         int err;
13796
13797         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13798         if (spec == NULL)
13799                 return -ENOMEM;
13800
13801         codec->spec = spec;
13802
13803         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
13804                                                   alc861_models,
13805                                                   alc861_cfg_tbl);
13806
13807         if (board_config < 0) {
13808                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
13809                        "trying auto-probe from BIOS...\n");
13810                 board_config = ALC861_AUTO;
13811         }
13812
13813         if (board_config == ALC861_AUTO) {
13814                 /* automatic parse from the BIOS config */
13815                 err = alc861_parse_auto_config(codec);
13816                 if (err < 0) {
13817                         alc_free(codec);
13818                         return err;
13819                 } else if (!err) {
13820                         printk(KERN_INFO
13821                                "hda_codec: Cannot set up configuration "
13822                                "from BIOS.  Using base mode...\n");
13823                    board_config = ALC861_3ST_DIG;
13824                 }
13825         }
13826
13827         if (board_config != ALC861_AUTO)
13828                 setup_preset(spec, &alc861_presets[board_config]);
13829
13830         spec->stream_name_analog = "ALC861 Analog";
13831         spec->stream_analog_playback = &alc861_pcm_analog_playback;
13832         spec->stream_analog_capture = &alc861_pcm_analog_capture;
13833
13834         spec->stream_name_digital = "ALC861 Digital";
13835         spec->stream_digital_playback = &alc861_pcm_digital_playback;
13836         spec->stream_digital_capture = &alc861_pcm_digital_capture;
13837
13838         spec->vmaster_nid = 0x03;
13839
13840         codec->patch_ops = alc_patch_ops;
13841         if (board_config == ALC861_AUTO)
13842                 spec->init_hook = alc861_auto_init;
13843 #ifdef CONFIG_SND_HDA_POWER_SAVE
13844         if (!spec->loopback.amplist)
13845                 spec->loopback.amplist = alc861_loopbacks;
13846 #endif
13847         codec->proc_widget_hook = print_realtek_coef;
13848
13849         return 0;
13850 }
13851
13852 /*
13853  * ALC861-VD support
13854  *
13855  * Based on ALC882
13856  *
13857  * In addition, an independent DAC
13858  */
13859 #define ALC861VD_DIGOUT_NID     0x06
13860
13861 static hda_nid_t alc861vd_dac_nids[4] = {
13862         /* front, surr, clfe, side surr */
13863         0x02, 0x03, 0x04, 0x05
13864 };
13865
13866 /* dac_nids for ALC660vd are in a different order - according to
13867  * Realtek's driver.
13868  * This should probably tesult in a different mixer for 6stack models
13869  * of ALC660vd codecs, but for now there is only 3stack mixer
13870  * - and it is the same as in 861vd.
13871  * adc_nids in ALC660vd are (is) the same as in 861vd
13872  */
13873 static hda_nid_t alc660vd_dac_nids[3] = {
13874         /* front, rear, clfe, rear_surr */
13875         0x02, 0x04, 0x03
13876 };
13877
13878 static hda_nid_t alc861vd_adc_nids[1] = {
13879         /* ADC0 */
13880         0x09,
13881 };
13882
13883 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
13884
13885 /* input MUX */
13886 /* FIXME: should be a matrix-type input source selection */
13887 static struct hda_input_mux alc861vd_capture_source = {
13888         .num_items = 4,
13889         .items = {
13890                 { "Mic", 0x0 },
13891                 { "Front Mic", 0x1 },
13892                 { "Line", 0x2 },
13893                 { "CD", 0x4 },
13894         },
13895 };
13896
13897 static struct hda_input_mux alc861vd_dallas_capture_source = {
13898         .num_items = 2,
13899         .items = {
13900                 { "Ext Mic", 0x0 },
13901                 { "Int Mic", 0x1 },
13902         },
13903 };
13904
13905 static struct hda_input_mux alc861vd_hp_capture_source = {
13906         .num_items = 2,
13907         .items = {
13908                 { "Front Mic", 0x0 },
13909                 { "ATAPI Mic", 0x1 },
13910         },
13911 };
13912
13913 /*
13914  * 2ch mode
13915  */
13916 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
13917         { 2, NULL }
13918 };
13919
13920 /*
13921  * 6ch mode
13922  */
13923 static struct hda_verb alc861vd_6stack_ch6_init[] = {
13924         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13925         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13926         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13927         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13928         { } /* end */
13929 };
13930
13931 /*
13932  * 8ch mode
13933  */
13934 static struct hda_verb alc861vd_6stack_ch8_init[] = {
13935         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13936         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13937         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13938         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13939         { } /* end */
13940 };
13941
13942 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
13943         { 6, alc861vd_6stack_ch6_init },
13944         { 8, alc861vd_6stack_ch8_init },
13945 };
13946
13947 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
13948         {
13949                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13950                 .name = "Channel Mode",
13951                 .info = alc_ch_mode_info,
13952                 .get = alc_ch_mode_get,
13953                 .put = alc_ch_mode_put,
13954         },
13955         { } /* end */
13956 };
13957
13958 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13959  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13960  */
13961 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
13962         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13963         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13964
13965         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13966         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
13967
13968         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
13969                                 HDA_OUTPUT),
13970         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
13971                                 HDA_OUTPUT),
13972         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
13973         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
13974
13975         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
13976         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
13977
13978         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13979
13980         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13981         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13982         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13983
13984         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13985         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13986         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13987
13988         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13989         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13990
13991         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13992         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13993
13994         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13995         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13996
13997         { } /* end */
13998 };
13999
14000 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14001         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14002         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14003
14004         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14005
14006         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14007         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14008         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14009
14010         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14011         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14012         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14013
14014         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14015         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14016
14017         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14018         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14019
14020         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14021         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14022
14023         { } /* end */
14024 };
14025
14026 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14027         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14028         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14029         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14030
14031         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14032
14033         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14034         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14035         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14036
14037         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14038         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14039         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14040
14041         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14042         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14043
14044         { } /* end */
14045 };
14046
14047 /* Pin assignment: Speaker=0x14, HP = 0x15,
14048  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14049  */
14050 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14051         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14052         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14053         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14054         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14055         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14056         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14057         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14058         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14059         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14060         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14061         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
14062         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
14063         { } /* end */
14064 };
14065
14066 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14067  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14068  */
14069 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14070         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14071         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14072         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14073         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14074         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14075         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14076         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14077         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14078
14079         { } /* end */
14080 };
14081
14082 /*
14083  * generic initialization of ADC, input mixers and output mixers
14084  */
14085 static struct hda_verb alc861vd_volume_init_verbs[] = {
14086         /*
14087          * Unmute ADC0 and set the default input to mic-in
14088          */
14089         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14090         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14091
14092         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14093          * the analog-loopback mixer widget
14094          */
14095         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14096         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14097         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14098         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14099         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14100         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14101
14102         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14103         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14104         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14105         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14106         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14107
14108         /*
14109          * Set up output mixers (0x02 - 0x05)
14110          */
14111         /* set vol=0 to output mixers */
14112         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14113         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14114         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14115         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14116
14117         /* set up input amps for analog loopback */
14118         /* Amp Indices: DAC = 0, mixer = 1 */
14119         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14120         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14121         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14122         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14123         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14124         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14125         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14126         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14127
14128         { }
14129 };
14130
14131 /*
14132  * 3-stack pin configuration:
14133  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14134  */
14135 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14136         /*
14137          * Set pin mode and muting
14138          */
14139         /* set front pin widgets 0x14 for output */
14140         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14141         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14142         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
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 /*
14164  * 6-stack pin configuration:
14165  */
14166 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14167         /*
14168          * Set pin mode and muting
14169          */
14170         /* set front pin widgets 0x14 for output */
14171         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14172         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14173         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14174
14175         /* Rear Pin: output 1 (0x0d) */
14176         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14177         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14178         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14179         /* CLFE Pin: output 2 (0x0e) */
14180         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14181         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14182         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14183         /* Side Pin: output 3 (0x0f) */
14184         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14185         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14186         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
14187
14188         /* Mic (rear) pin: input vref at 80% */
14189         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14190         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14191         /* Front Mic pin: input vref at 80% */
14192         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14193         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14194         /* Line In pin: input */
14195         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14196         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14197         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14198         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14199         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14200         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14201         /* CD pin widget for input */
14202         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14203
14204         { }
14205 };
14206
14207 static struct hda_verb alc861vd_eapd_verbs[] = {
14208         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14209         { }
14210 };
14211
14212 static struct hda_verb alc660vd_eapd_verbs[] = {
14213         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14214         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14215         { }
14216 };
14217
14218 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
14219         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14220         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14221         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
14222         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14223         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14224         {}
14225 };
14226
14227 /* toggle speaker-output according to the hp-jack state */
14228 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
14229 {
14230         unsigned int present;
14231         unsigned char bits;
14232
14233         present = snd_hda_codec_read(codec, 0x1b, 0,
14234                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14235         bits = present ? HDA_AMP_MUTE : 0;
14236         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14237                                  HDA_AMP_MUTE, bits);
14238 }
14239
14240 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
14241 {
14242         unsigned int present;
14243         unsigned char bits;
14244
14245         present = snd_hda_codec_read(codec, 0x18, 0,
14246                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14247         bits = present ? HDA_AMP_MUTE : 0;
14248         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
14249                                  HDA_AMP_MUTE, bits);
14250 }
14251
14252 static void alc861vd_lenovo_automute(struct hda_codec *codec)
14253 {
14254         alc861vd_lenovo_hp_automute(codec);
14255         alc861vd_lenovo_mic_automute(codec);
14256 }
14257
14258 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
14259                                         unsigned int res)
14260 {
14261         switch (res >> 26) {
14262         case ALC880_HP_EVENT:
14263                 alc861vd_lenovo_hp_automute(codec);
14264                 break;
14265         case ALC880_MIC_EVENT:
14266                 alc861vd_lenovo_mic_automute(codec);
14267                 break;
14268         }
14269 }
14270
14271 static struct hda_verb alc861vd_dallas_verbs[] = {
14272         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14273         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14274         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14275         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14276
14277         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14278         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14279         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14280         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14281         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14282         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14283         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14284         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14285
14286         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14287         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14288         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14289         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14290         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14291         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14292         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14293         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14294
14295         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14296         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14297         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14298         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14299         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14300         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14301         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14302         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14303
14304         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14305         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14306         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14307         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14308
14309         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14310         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14311         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14312
14313         { } /* end */
14314 };
14315
14316 /* toggle speaker-output according to the hp-jack state */
14317 static void alc861vd_dallas_automute(struct hda_codec *codec)
14318 {
14319         unsigned int present;
14320
14321         present = snd_hda_codec_read(codec, 0x15, 0,
14322                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14323         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14324                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14325 }
14326
14327 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
14328 {
14329         if ((res >> 26) == ALC880_HP_EVENT)
14330                 alc861vd_dallas_automute(codec);
14331 }
14332
14333 #ifdef CONFIG_SND_HDA_POWER_SAVE
14334 #define alc861vd_loopbacks      alc880_loopbacks
14335 #endif
14336
14337 /* pcm configuration: identiacal with ALC880 */
14338 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14339 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14340 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14341 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14342
14343 /*
14344  * configuration and preset
14345  */
14346 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14347         [ALC660VD_3ST]          = "3stack-660",
14348         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14349         [ALC660VD_ASUS_V1S]     = "asus-v1s",
14350         [ALC861VD_3ST]          = "3stack",
14351         [ALC861VD_3ST_DIG]      = "3stack-digout",
14352         [ALC861VD_6ST_DIG]      = "6stack-digout",
14353         [ALC861VD_LENOVO]       = "lenovo",
14354         [ALC861VD_DALLAS]       = "dallas",
14355         [ALC861VD_HP]           = "hp",
14356         [ALC861VD_AUTO]         = "auto",
14357 };
14358
14359 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14360         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14361         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14362         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14363         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14364         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
14365         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14366         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14367         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14368         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14369         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14370         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14371         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14372         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14373         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
14374         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
14375         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
14376         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14377         {}
14378 };
14379
14380 static struct alc_config_preset alc861vd_presets[] = {
14381         [ALC660VD_3ST] = {
14382                 .mixers = { alc861vd_3st_mixer },
14383                 .init_verbs = { alc861vd_volume_init_verbs,
14384                                  alc861vd_3stack_init_verbs },
14385                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14386                 .dac_nids = alc660vd_dac_nids,
14387                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14388                 .channel_mode = alc861vd_3stack_2ch_modes,
14389                 .input_mux = &alc861vd_capture_source,
14390         },
14391         [ALC660VD_3ST_DIG] = {
14392                 .mixers = { alc861vd_3st_mixer },
14393                 .init_verbs = { alc861vd_volume_init_verbs,
14394                                  alc861vd_3stack_init_verbs },
14395                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14396                 .dac_nids = alc660vd_dac_nids,
14397                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14398                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14399                 .channel_mode = alc861vd_3stack_2ch_modes,
14400                 .input_mux = &alc861vd_capture_source,
14401         },
14402         [ALC861VD_3ST] = {
14403                 .mixers = { alc861vd_3st_mixer },
14404                 .init_verbs = { alc861vd_volume_init_verbs,
14405                                  alc861vd_3stack_init_verbs },
14406                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14407                 .dac_nids = alc861vd_dac_nids,
14408                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14409                 .channel_mode = alc861vd_3stack_2ch_modes,
14410                 .input_mux = &alc861vd_capture_source,
14411         },
14412         [ALC861VD_3ST_DIG] = {
14413                 .mixers = { alc861vd_3st_mixer },
14414                 .init_verbs = { alc861vd_volume_init_verbs,
14415                                  alc861vd_3stack_init_verbs },
14416                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14417                 .dac_nids = alc861vd_dac_nids,
14418                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14419                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14420                 .channel_mode = alc861vd_3stack_2ch_modes,
14421                 .input_mux = &alc861vd_capture_source,
14422         },
14423         [ALC861VD_6ST_DIG] = {
14424                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14425                 .init_verbs = { alc861vd_volume_init_verbs,
14426                                 alc861vd_6stack_init_verbs },
14427                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14428                 .dac_nids = alc861vd_dac_nids,
14429                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14430                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14431                 .channel_mode = alc861vd_6stack_modes,
14432                 .input_mux = &alc861vd_capture_source,
14433         },
14434         [ALC861VD_LENOVO] = {
14435                 .mixers = { alc861vd_lenovo_mixer },
14436                 .init_verbs = { alc861vd_volume_init_verbs,
14437                                 alc861vd_3stack_init_verbs,
14438                                 alc861vd_eapd_verbs,
14439                                 alc861vd_lenovo_unsol_verbs },
14440                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14441                 .dac_nids = alc660vd_dac_nids,
14442                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14443                 .channel_mode = alc861vd_3stack_2ch_modes,
14444                 .input_mux = &alc861vd_capture_source,
14445                 .unsol_event = alc861vd_lenovo_unsol_event,
14446                 .init_hook = alc861vd_lenovo_automute,
14447         },
14448         [ALC861VD_DALLAS] = {
14449                 .mixers = { alc861vd_dallas_mixer },
14450                 .init_verbs = { alc861vd_dallas_verbs },
14451                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14452                 .dac_nids = alc861vd_dac_nids,
14453                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14454                 .channel_mode = alc861vd_3stack_2ch_modes,
14455                 .input_mux = &alc861vd_dallas_capture_source,
14456                 .unsol_event = alc861vd_dallas_unsol_event,
14457                 .init_hook = alc861vd_dallas_automute,
14458         },
14459         [ALC861VD_HP] = {
14460                 .mixers = { alc861vd_hp_mixer },
14461                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14462                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14463                 .dac_nids = alc861vd_dac_nids,
14464                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14465                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14466                 .channel_mode = alc861vd_3stack_2ch_modes,
14467                 .input_mux = &alc861vd_hp_capture_source,
14468                 .unsol_event = alc861vd_dallas_unsol_event,
14469                 .init_hook = alc861vd_dallas_automute,
14470         },
14471         [ALC660VD_ASUS_V1S] = {
14472                 .mixers = { alc861vd_lenovo_mixer },
14473                 .init_verbs = { alc861vd_volume_init_verbs,
14474                                 alc861vd_3stack_init_verbs,
14475                                 alc861vd_eapd_verbs,
14476                                 alc861vd_lenovo_unsol_verbs },
14477                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14478                 .dac_nids = alc660vd_dac_nids,
14479                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14480                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14481                 .channel_mode = alc861vd_3stack_2ch_modes,
14482                 .input_mux = &alc861vd_capture_source,
14483                 .unsol_event = alc861vd_lenovo_unsol_event,
14484                 .init_hook = alc861vd_lenovo_automute,
14485         },
14486 };
14487
14488 /*
14489  * BIOS auto configuration
14490  */
14491 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14492                                 hda_nid_t nid, int pin_type, int dac_idx)
14493 {
14494         alc_set_pin_output(codec, nid, pin_type);
14495 }
14496
14497 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14498 {
14499         struct alc_spec *spec = codec->spec;
14500         int i;
14501
14502         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14503         for (i = 0; i <= HDA_SIDE; i++) {
14504                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14505                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14506                 if (nid)
14507                         alc861vd_auto_set_output_and_unmute(codec, nid,
14508                                                             pin_type, i);
14509         }
14510 }
14511
14512
14513 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14514 {
14515         struct alc_spec *spec = codec->spec;
14516         hda_nid_t pin;
14517
14518         pin = spec->autocfg.hp_pins[0];
14519         if (pin) /* connect to front and  use dac 0 */
14520                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14521         pin = spec->autocfg.speaker_pins[0];
14522         if (pin)
14523                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14524 }
14525
14526 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14527 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14528
14529 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14530 {
14531         struct alc_spec *spec = codec->spec;
14532         int i;
14533
14534         for (i = 0; i < AUTO_PIN_LAST; i++) {
14535                 hda_nid_t nid = spec->autocfg.input_pins[i];
14536                 if (alc861vd_is_input_pin(nid)) {
14537                         snd_hda_codec_write(codec, nid, 0,
14538                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
14539                                         i <= AUTO_PIN_FRONT_MIC ?
14540                                                         PIN_VREF80 : PIN_IN);
14541                         if (nid != ALC861VD_PIN_CD_NID)
14542                                 snd_hda_codec_write(codec, nid, 0,
14543                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14544                                                 AMP_OUT_MUTE);
14545                 }
14546         }
14547 }
14548
14549 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14550
14551 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14552 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14553
14554 /* add playback controls from the parsed DAC table */
14555 /* Based on ALC880 version. But ALC861VD has separate,
14556  * different NIDs for mute/unmute switch and volume control */
14557 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14558                                              const struct auto_pin_cfg *cfg)
14559 {
14560         char name[32];
14561         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14562         hda_nid_t nid_v, nid_s;
14563         int i, err;
14564
14565         for (i = 0; i < cfg->line_outs; i++) {
14566                 if (!spec->multiout.dac_nids[i])
14567                         continue;
14568                 nid_v = alc861vd_idx_to_mixer_vol(
14569                                 alc880_dac_to_idx(
14570                                         spec->multiout.dac_nids[i]));
14571                 nid_s = alc861vd_idx_to_mixer_switch(
14572                                 alc880_dac_to_idx(
14573                                         spec->multiout.dac_nids[i]));
14574
14575                 if (i == 2) {
14576                         /* Center/LFE */
14577                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14578                                           "Center Playback Volume",
14579                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14580                                                               HDA_OUTPUT));
14581                         if (err < 0)
14582                                 return err;
14583                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14584                                           "LFE Playback Volume",
14585                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14586                                                               HDA_OUTPUT));
14587                         if (err < 0)
14588                                 return err;
14589                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14590                                           "Center Playback Switch",
14591                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14592                                                               HDA_INPUT));
14593                         if (err < 0)
14594                                 return err;
14595                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14596                                           "LFE Playback Switch",
14597                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14598                                                               HDA_INPUT));
14599                         if (err < 0)
14600                                 return err;
14601                 } else {
14602                         sprintf(name, "%s Playback Volume", chname[i]);
14603                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14604                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14605                                                               HDA_OUTPUT));
14606                         if (err < 0)
14607                                 return err;
14608                         sprintf(name, "%s Playback Switch", chname[i]);
14609                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14610                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14611                                                               HDA_INPUT));
14612                         if (err < 0)
14613                                 return err;
14614                 }
14615         }
14616         return 0;
14617 }
14618
14619 /* add playback controls for speaker and HP outputs */
14620 /* Based on ALC880 version. But ALC861VD has separate,
14621  * different NIDs for mute/unmute switch and volume control */
14622 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14623                                         hda_nid_t pin, const char *pfx)
14624 {
14625         hda_nid_t nid_v, nid_s;
14626         int err;
14627         char name[32];
14628
14629         if (!pin)
14630                 return 0;
14631
14632         if (alc880_is_fixed_pin(pin)) {
14633                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14634                 /* specify the DAC as the extra output */
14635                 if (!spec->multiout.hp_nid)
14636                         spec->multiout.hp_nid = nid_v;
14637                 else
14638                         spec->multiout.extra_out_nid[0] = nid_v;
14639                 /* control HP volume/switch on the output mixer amp */
14640                 nid_v = alc861vd_idx_to_mixer_vol(
14641                                 alc880_fixed_pin_idx(pin));
14642                 nid_s = alc861vd_idx_to_mixer_switch(
14643                                 alc880_fixed_pin_idx(pin));
14644
14645                 sprintf(name, "%s Playback Volume", pfx);
14646                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14647                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
14648                 if (err < 0)
14649                         return err;
14650                 sprintf(name, "%s Playback Switch", pfx);
14651                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14652                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
14653                 if (err < 0)
14654                         return err;
14655         } else if (alc880_is_multi_pin(pin)) {
14656                 /* set manual connection */
14657                 /* we have only a switch on HP-out PIN */
14658                 sprintf(name, "%s Playback Switch", pfx);
14659                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14660                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14661                 if (err < 0)
14662                         return err;
14663         }
14664         return 0;
14665 }
14666
14667 /* parse the BIOS configuration and set up the alc_spec
14668  * return 1 if successful, 0 if the proper config is not found,
14669  * or a negative error code
14670  * Based on ALC880 version - had to change it to override
14671  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
14672 static int alc861vd_parse_auto_config(struct hda_codec *codec)
14673 {
14674         struct alc_spec *spec = codec->spec;
14675         int err;
14676         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
14677
14678         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14679                                            alc861vd_ignore);
14680         if (err < 0)
14681                 return err;
14682         if (!spec->autocfg.line_outs)
14683                 return 0; /* can't find valid BIOS pin config */
14684
14685         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14686         if (err < 0)
14687                 return err;
14688         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
14689         if (err < 0)
14690                 return err;
14691         err = alc861vd_auto_create_extra_out(spec,
14692                                              spec->autocfg.speaker_pins[0],
14693                                              "Speaker");
14694         if (err < 0)
14695                 return err;
14696         err = alc861vd_auto_create_extra_out(spec,
14697                                              spec->autocfg.hp_pins[0],
14698                                              "Headphone");
14699         if (err < 0)
14700                 return err;
14701         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
14702         if (err < 0)
14703                 return err;
14704
14705         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14706
14707         if (spec->autocfg.dig_out_pin)
14708                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14709
14710         if (spec->kctls.list)
14711                 add_mixer(spec, spec->kctls.list);
14712
14713         add_verb(spec, alc861vd_volume_init_verbs);
14714
14715         spec->num_mux_defs = 1;
14716         spec->input_mux = &spec->private_imux;
14717
14718         err = alc_auto_add_mic_boost(codec);
14719         if (err < 0)
14720                 return err;
14721
14722         store_pin_configs(codec);
14723         return 1;
14724 }
14725
14726 /* additional initialization for auto-configuration model */
14727 static void alc861vd_auto_init(struct hda_codec *codec)
14728 {
14729         struct alc_spec *spec = codec->spec;
14730         alc861vd_auto_init_multi_out(codec);
14731         alc861vd_auto_init_hp_out(codec);
14732         alc861vd_auto_init_analog_input(codec);
14733         alc861vd_auto_init_input_src(codec);
14734         if (spec->unsol_event)
14735                 alc_inithook(codec);
14736 }
14737
14738 static int patch_alc861vd(struct hda_codec *codec)
14739 {
14740         struct alc_spec *spec;
14741         int err, board_config;
14742
14743         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14744         if (spec == NULL)
14745                 return -ENOMEM;
14746
14747         codec->spec = spec;
14748
14749         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
14750                                                   alc861vd_models,
14751                                                   alc861vd_cfg_tbl);
14752
14753         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
14754                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
14755                         "ALC861VD, trying auto-probe from BIOS...\n");
14756                 board_config = ALC861VD_AUTO;
14757         }
14758
14759         if (board_config == ALC861VD_AUTO) {
14760                 /* automatic parse from the BIOS config */
14761                 err = alc861vd_parse_auto_config(codec);
14762                 if (err < 0) {
14763                         alc_free(codec);
14764                         return err;
14765                 } else if (!err) {
14766                         printk(KERN_INFO
14767                                "hda_codec: Cannot set up configuration "
14768                                "from BIOS.  Using base mode...\n");
14769                         board_config = ALC861VD_3ST;
14770                 }
14771         }
14772
14773         if (board_config != ALC861VD_AUTO)
14774                 setup_preset(spec, &alc861vd_presets[board_config]);
14775
14776         if (codec->vendor_id == 0x10ec0660) {
14777                 spec->stream_name_analog = "ALC660-VD Analog";
14778                 spec->stream_name_digital = "ALC660-VD Digital";
14779                 /* always turn on EAPD */
14780                 add_verb(spec, alc660vd_eapd_verbs);
14781         } else {
14782                 spec->stream_name_analog = "ALC861VD Analog";
14783                 spec->stream_name_digital = "ALC861VD Digital";
14784         }
14785
14786         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
14787         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
14788
14789         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
14790         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
14791
14792         spec->adc_nids = alc861vd_adc_nids;
14793         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14794         spec->capsrc_nids = alc861vd_capsrc_nids;
14795         spec->is_mix_capture = 1;
14796
14797         set_capture_mixer(spec);
14798
14799         spec->vmaster_nid = 0x02;
14800
14801         codec->patch_ops = alc_patch_ops;
14802
14803         if (board_config == ALC861VD_AUTO)
14804                 spec->init_hook = alc861vd_auto_init;
14805 #ifdef CONFIG_SND_HDA_POWER_SAVE
14806         if (!spec->loopback.amplist)
14807                 spec->loopback.amplist = alc861vd_loopbacks;
14808 #endif
14809         codec->proc_widget_hook = print_realtek_coef;
14810
14811         return 0;
14812 }
14813
14814 /*
14815  * ALC662 support
14816  *
14817  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
14818  * configuration.  Each pin widget can choose any input DACs and a mixer.
14819  * Each ADC is connected from a mixer of all inputs.  This makes possible
14820  * 6-channel independent captures.
14821  *
14822  * In addition, an independent DAC for the multi-playback (not used in this
14823  * driver yet).
14824  */
14825 #define ALC662_DIGOUT_NID       0x06
14826 #define ALC662_DIGIN_NID        0x0a
14827
14828 static hda_nid_t alc662_dac_nids[4] = {
14829         /* front, rear, clfe, rear_surr */
14830         0x02, 0x03, 0x04
14831 };
14832
14833 static hda_nid_t alc662_adc_nids[1] = {
14834         /* ADC1-2 */
14835         0x09,
14836 };
14837
14838 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
14839
14840 /* input MUX */
14841 /* FIXME: should be a matrix-type input source selection */
14842 static struct hda_input_mux alc662_capture_source = {
14843         .num_items = 4,
14844         .items = {
14845                 { "Mic", 0x0 },
14846                 { "Front Mic", 0x1 },
14847                 { "Line", 0x2 },
14848                 { "CD", 0x4 },
14849         },
14850 };
14851
14852 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
14853         .num_items = 2,
14854         .items = {
14855                 { "Mic", 0x1 },
14856                 { "Line", 0x2 },
14857         },
14858 };
14859
14860 static struct hda_input_mux alc662_eeepc_capture_source = {
14861         .num_items = 2,
14862         .items = {
14863                 { "i-Mic", 0x1 },
14864                 { "e-Mic", 0x0 },
14865         },
14866 };
14867
14868 static struct hda_input_mux alc663_capture_source = {
14869         .num_items = 3,
14870         .items = {
14871                 { "Mic", 0x0 },
14872                 { "Front Mic", 0x1 },
14873                 { "Line", 0x2 },
14874         },
14875 };
14876
14877 static struct hda_input_mux alc663_m51va_capture_source = {
14878         .num_items = 2,
14879         .items = {
14880                 { "Ext-Mic", 0x0 },
14881                 { "D-Mic", 0x9 },
14882         },
14883 };
14884
14885 /*
14886  * 2ch mode
14887  */
14888 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
14889         { 2, NULL }
14890 };
14891
14892 /*
14893  * 2ch mode
14894  */
14895 static struct hda_verb alc662_3ST_ch2_init[] = {
14896         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
14897         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14898         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
14899         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14900         { } /* end */
14901 };
14902
14903 /*
14904  * 6ch mode
14905  */
14906 static struct hda_verb alc662_3ST_ch6_init[] = {
14907         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14908         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14909         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
14910         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14911         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14912         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
14913         { } /* end */
14914 };
14915
14916 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
14917         { 2, alc662_3ST_ch2_init },
14918         { 6, alc662_3ST_ch6_init },
14919 };
14920
14921 /*
14922  * 2ch mode
14923  */
14924 static struct hda_verb alc662_sixstack_ch6_init[] = {
14925         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14926         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14927         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14928         { } /* end */
14929 };
14930
14931 /*
14932  * 6ch mode
14933  */
14934 static struct hda_verb alc662_sixstack_ch8_init[] = {
14935         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14936         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14937         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14938         { } /* end */
14939 };
14940
14941 static struct hda_channel_mode alc662_5stack_modes[2] = {
14942         { 2, alc662_sixstack_ch6_init },
14943         { 6, alc662_sixstack_ch8_init },
14944 };
14945
14946 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14947  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14948  */
14949
14950 static struct snd_kcontrol_new alc662_base_mixer[] = {
14951         /* output mixer control */
14952         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
14953         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14954         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
14955         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14956         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14957         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14958         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14959         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14960         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14961
14962         /*Input mixer control */
14963         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
14964         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
14965         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
14966         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
14967         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
14968         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
14969         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
14970         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
14971         { } /* end */
14972 };
14973
14974 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
14975         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14976         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14977         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14978         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14979         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14980         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14981         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14982         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14983         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14984         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14985         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14986         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14987         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14988         { } /* end */
14989 };
14990
14991 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
14992         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14993         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14994         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14995         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14996         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14997         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14998         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14999         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15000         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15001         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15002         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15003         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15004         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15005         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15006         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15007         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15008         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15009         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
15010         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
15011         { } /* end */
15012 };
15013
15014 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15015         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15016         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15017         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15018         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15019         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15020         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15021         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15022         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15023         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15024         { } /* end */
15025 };
15026
15027 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15028         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15029
15030         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15031         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15032
15033         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15034         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15035         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15036
15037         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15038         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15039         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15040         { } /* end */
15041 };
15042
15043 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15044         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15045         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15046         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15047         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
15048         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15049         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15050         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
15051         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
15052         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15053         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15054         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15055         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15056         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15057         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15058         { } /* end */
15059 };
15060
15061 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15062         .ops = &snd_hda_bind_vol,
15063         .values = {
15064                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15065                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15066                 0
15067         },
15068 };
15069
15070 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15071         .ops = &snd_hda_bind_sw,
15072         .values = {
15073                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15074                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15075                 0
15076         },
15077 };
15078
15079 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15080         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15081         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15082         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15083         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15084         { } /* end */
15085 };
15086
15087 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15088         .ops = &snd_hda_bind_sw,
15089         .values = {
15090                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15091                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15092                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15093                 0
15094         },
15095 };
15096
15097 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15098         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15099         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15100         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15101         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15102         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15103         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15104
15105         { } /* end */
15106 };
15107
15108 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15109         .ops = &snd_hda_bind_sw,
15110         .values = {
15111                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15112                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15113                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15114                 0
15115         },
15116 };
15117
15118 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15119         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15120         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15121         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15122         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15123         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15124         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15125         { } /* end */
15126 };
15127
15128 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15129         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15130         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15131         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15132         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15133         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15134         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15135         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15136         { } /* end */
15137 };
15138
15139 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15140         .ops = &snd_hda_bind_vol,
15141         .values = {
15142                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15143                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15144                 0
15145         },
15146 };
15147
15148 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15149         .ops = &snd_hda_bind_sw,
15150         .values = {
15151                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15152                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15153                 0
15154         },
15155 };
15156
15157 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15158         HDA_BIND_VOL("Master Playback Volume",
15159                                 &alc663_asus_two_bind_master_vol),
15160         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15161         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15162         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15163         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15164         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15165         { } /* end */
15166 };
15167
15168 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15169         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15170         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15171         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15172         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15173         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15174         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15175         { } /* end */
15176 };
15177
15178 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
15179         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15180         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15181         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15182         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15183         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15184
15185         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15186         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15187         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15188         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15189         { } /* end */
15190 };
15191
15192 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
15193         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15194         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15195         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15196
15197         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15198         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15199         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15200         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15201         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15202         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15203         { } /* end */
15204 };
15205
15206 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
15207         {
15208                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15209                 .name = "Channel Mode",
15210                 .info = alc_ch_mode_info,
15211                 .get = alc_ch_mode_get,
15212                 .put = alc_ch_mode_put,
15213         },
15214         { } /* end */
15215 };
15216
15217 static struct hda_verb alc662_init_verbs[] = {
15218         /* ADC: mute amp left and right */
15219         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15220         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15221         /* Front mixer: unmute input/output amp left and right (volume = 0) */
15222
15223         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15224         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15225         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15226         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15227         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15228
15229         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15230         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15231         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15232         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15233         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15234         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15235
15236         /* Front Pin: output 0 (0x0c) */
15237         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15238         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15239
15240         /* Rear Pin: output 1 (0x0d) */
15241         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15242         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15243
15244         /* CLFE Pin: output 2 (0x0e) */
15245         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15246         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15247
15248         /* Mic (rear) pin: input vref at 80% */
15249         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15250         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15251         /* Front Mic pin: input vref at 80% */
15252         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15253         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15254         /* Line In pin: input */
15255         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15256         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15257         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15258         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15259         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15260         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15261         /* CD pin widget for input */
15262         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15263
15264         /* FIXME: use matrix-type input source selection */
15265         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15266         /* Input mixer */
15267         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15268         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15269         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15270         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15271
15272         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15273         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15274         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15275         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15276
15277         /* always trun on EAPD */
15278         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15279         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15280
15281         { }
15282 };
15283
15284 static struct hda_verb alc662_sue_init_verbs[] = {
15285         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15286         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15287         {}
15288 };
15289
15290 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
15291         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15292         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15293         {}
15294 };
15295
15296 /* Set Unsolicited Event*/
15297 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
15298         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15299         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15300         {}
15301 };
15302
15303 /*
15304  * generic initialization of ADC, input mixers and output mixers
15305  */
15306 static struct hda_verb alc662_auto_init_verbs[] = {
15307         /*
15308          * Unmute ADC and set the default input to mic-in
15309          */
15310         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15311         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15312
15313         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
15314          * mixer widget
15315          * Note: PASD motherboards uses the Line In 2 as the input for front
15316          * panel mic (mic 2)
15317          */
15318         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
15319         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15320         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15321         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15322         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15323         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15324
15325         /*
15326          * Set up output mixers (0x0c - 0x0f)
15327          */
15328         /* set vol=0 to output mixers */
15329         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15330         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15331         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15332
15333         /* set up input amps for analog loopback */
15334         /* Amp Indices: DAC = 0, mixer = 1 */
15335         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15336         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15337         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15338         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15339         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15340         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15341
15342
15343         /* FIXME: use matrix-type input source selection */
15344         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15345         /* Input mixer */
15346         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15347         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15348         { }
15349 };
15350
15351 /* additional verbs for ALC663 */
15352 static struct hda_verb alc663_auto_init_verbs[] = {
15353         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15354         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15355         { }
15356 };
15357
15358 static struct hda_verb alc663_m51va_init_verbs[] = {
15359         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15360         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15361         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15362         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15363         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15364         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15365         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15366         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15367         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15368         {}
15369 };
15370
15371 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15372         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15373         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15374         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15375         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15376         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15377         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15378         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15379         {}
15380 };
15381
15382 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15383         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15384         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15385         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15386         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15387         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15388         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15389         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15390         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15391         {}
15392 };
15393
15394 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15395         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15396         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15397         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15398         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15399         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15400         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15401         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15402         {}
15403 };
15404
15405 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15406         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15407         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15408         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15409         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15410         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15411         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15412         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15413         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15414         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15415         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15416         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15417         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15418         {}
15419 };
15420
15421 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15422         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15423         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15424         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15425         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15426         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15427         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15428         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15429         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15430         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15431         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15432         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15433         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15434         {}
15435 };
15436
15437 static struct hda_verb alc663_g71v_init_verbs[] = {
15438         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15439         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15440         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15441
15442         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15443         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15444         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15445
15446         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15447         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15448         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15449         {}
15450 };
15451
15452 static struct hda_verb alc663_g50v_init_verbs[] = {
15453         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15454         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15455         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15456
15457         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15458         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15459         {}
15460 };
15461
15462 static struct hda_verb alc662_ecs_init_verbs[] = {
15463         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15464         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15465         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15466         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15467         {}
15468 };
15469
15470 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15471         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15472         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15473         { } /* end */
15474 };
15475
15476 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15477 {
15478         unsigned int present;
15479         unsigned char bits;
15480
15481         present = snd_hda_codec_read(codec, 0x14, 0,
15482                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15483         bits = present ? HDA_AMP_MUTE : 0;
15484         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15485                                  HDA_AMP_MUTE, bits);
15486 }
15487
15488 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15489 {
15490         unsigned int present;
15491         unsigned char bits;
15492
15493         present = snd_hda_codec_read(codec, 0x1b, 0,
15494                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15495         bits = present ? HDA_AMP_MUTE : 0;
15496         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15497                                  HDA_AMP_MUTE, bits);
15498         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15499                                  HDA_AMP_MUTE, bits);
15500 }
15501
15502 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15503                                            unsigned int res)
15504 {
15505         if ((res >> 26) == ALC880_HP_EVENT)
15506                 alc662_lenovo_101e_all_automute(codec);
15507         if ((res >> 26) == ALC880_FRONT_EVENT)
15508                 alc662_lenovo_101e_ispeaker_automute(codec);
15509 }
15510
15511 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15512 {
15513         unsigned int present;
15514
15515         present = snd_hda_codec_read(codec, 0x18, 0,
15516                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15517         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15518                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15519         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15520                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15521         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15522                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15523         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15524                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15525 }
15526
15527 /* unsolicited event for HP jack sensing */
15528 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15529                                      unsigned int res)
15530 {
15531         if ((res >> 26) == ALC880_HP_EVENT)
15532                 alc262_hippo1_automute( codec );
15533
15534         if ((res >> 26) == ALC880_MIC_EVENT)
15535                 alc662_eeepc_mic_automute(codec);
15536 }
15537
15538 static void alc662_eeepc_inithook(struct hda_codec *codec)
15539 {
15540         alc262_hippo1_automute( codec );
15541         alc662_eeepc_mic_automute(codec);
15542 }
15543
15544 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15545 {
15546         unsigned int mute;
15547         unsigned int present;
15548
15549         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15550         present = snd_hda_codec_read(codec, 0x14, 0,
15551                                      AC_VERB_GET_PIN_SENSE, 0);
15552         present = (present & 0x80000000) != 0;
15553         if (present) {
15554                 /* mute internal speaker */
15555                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15556                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15557         } else {
15558                 /* unmute internal speaker if necessary */
15559                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15560                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15561                                         HDA_AMP_MUTE, mute);
15562         }
15563 }
15564
15565 /* unsolicited event for HP jack sensing */
15566 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15567                                           unsigned int res)
15568 {
15569         if ((res >> 26) == ALC880_HP_EVENT)
15570                 alc662_eeepc_ep20_automute(codec);
15571 }
15572
15573 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15574 {
15575         alc662_eeepc_ep20_automute(codec);
15576 }
15577
15578 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15579 {
15580         unsigned int present;
15581         unsigned char bits;
15582
15583         present = snd_hda_codec_read(codec, 0x21, 0,
15584                         AC_VERB_GET_PIN_SENSE, 0)
15585                         & AC_PINSENSE_PRESENCE;
15586         bits = present ? HDA_AMP_MUTE : 0;
15587         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15588                                 AMP_IN_MUTE(0), bits);
15589         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15590                                 AMP_IN_MUTE(0), bits);
15591 }
15592
15593 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15594 {
15595         unsigned int present;
15596         unsigned char bits;
15597
15598         present = snd_hda_codec_read(codec, 0x21, 0,
15599                         AC_VERB_GET_PIN_SENSE, 0)
15600                         & AC_PINSENSE_PRESENCE;
15601         bits = present ? HDA_AMP_MUTE : 0;
15602         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15603                                 AMP_IN_MUTE(0), bits);
15604         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15605                                 AMP_IN_MUTE(0), bits);
15606         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15607                                 AMP_IN_MUTE(0), bits);
15608         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15609                                 AMP_IN_MUTE(0), bits);
15610 }
15611
15612 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15613 {
15614         unsigned int present;
15615         unsigned char bits;
15616
15617         present = snd_hda_codec_read(codec, 0x15, 0,
15618                         AC_VERB_GET_PIN_SENSE, 0)
15619                         & AC_PINSENSE_PRESENCE;
15620         bits = present ? HDA_AMP_MUTE : 0;
15621         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15622                                 AMP_IN_MUTE(0), bits);
15623         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15624                                 AMP_IN_MUTE(0), bits);
15625         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15626                                 AMP_IN_MUTE(0), bits);
15627         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15628                                 AMP_IN_MUTE(0), bits);
15629 }
15630
15631 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15632 {
15633         unsigned int present;
15634         unsigned char bits;
15635
15636         present = snd_hda_codec_read(codec, 0x1b, 0,
15637                         AC_VERB_GET_PIN_SENSE, 0)
15638                         & AC_PINSENSE_PRESENCE;
15639         bits = present ? 0 : PIN_OUT;
15640         snd_hda_codec_write(codec, 0x14, 0,
15641                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15642 }
15643
15644 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15645 {
15646         unsigned int present1, present2;
15647
15648         present1 = snd_hda_codec_read(codec, 0x21, 0,
15649                         AC_VERB_GET_PIN_SENSE, 0)
15650                         & AC_PINSENSE_PRESENCE;
15651         present2 = snd_hda_codec_read(codec, 0x15, 0,
15652                         AC_VERB_GET_PIN_SENSE, 0)
15653                         & AC_PINSENSE_PRESENCE;
15654
15655         if (present1 || present2) {
15656                 snd_hda_codec_write_cache(codec, 0x14, 0,
15657                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15658         } else {
15659                 snd_hda_codec_write_cache(codec, 0x14, 0,
15660                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15661         }
15662 }
15663
15664 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15665 {
15666         unsigned int present1, present2;
15667
15668         present1 = snd_hda_codec_read(codec, 0x1b, 0,
15669                                 AC_VERB_GET_PIN_SENSE, 0)
15670                                 & AC_PINSENSE_PRESENCE;
15671         present2 = snd_hda_codec_read(codec, 0x15, 0,
15672                                 AC_VERB_GET_PIN_SENSE, 0)
15673                                 & AC_PINSENSE_PRESENCE;
15674
15675         if (present1 || present2) {
15676                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15677                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15678                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15679                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15680         } else {
15681                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15682                                 AMP_IN_MUTE(0), 0);
15683                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15684                                 AMP_IN_MUTE(0), 0);
15685         }
15686 }
15687
15688 static void alc663_m51va_mic_automute(struct hda_codec *codec)
15689 {
15690         unsigned int present;
15691
15692         present = snd_hda_codec_read(codec, 0x18, 0,
15693                         AC_VERB_GET_PIN_SENSE, 0)
15694                         & AC_PINSENSE_PRESENCE;
15695         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15696                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15697         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15698                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15699         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15700                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15701         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15702                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15703 }
15704
15705 static void alc663_m51va_unsol_event(struct hda_codec *codec,
15706                                            unsigned int res)
15707 {
15708         switch (res >> 26) {
15709         case ALC880_HP_EVENT:
15710                 alc663_m51va_speaker_automute(codec);
15711                 break;
15712         case ALC880_MIC_EVENT:
15713                 alc663_m51va_mic_automute(codec);
15714                 break;
15715         }
15716 }
15717
15718 static void alc663_m51va_inithook(struct hda_codec *codec)
15719 {
15720         alc663_m51va_speaker_automute(codec);
15721         alc663_m51va_mic_automute(codec);
15722 }
15723
15724 /* ***************** Mode1 ******************************/
15725 static void alc663_mode1_unsol_event(struct hda_codec *codec,
15726                                            unsigned int res)
15727 {
15728         switch (res >> 26) {
15729         case ALC880_HP_EVENT:
15730                 alc663_m51va_speaker_automute(codec);
15731                 break;
15732         case ALC880_MIC_EVENT:
15733                 alc662_eeepc_mic_automute(codec);
15734                 break;
15735         }
15736 }
15737
15738 static void alc663_mode1_inithook(struct hda_codec *codec)
15739 {
15740         alc663_m51va_speaker_automute(codec);
15741         alc662_eeepc_mic_automute(codec);
15742 }
15743 /* ***************** Mode2 ******************************/
15744 static void alc662_mode2_unsol_event(struct hda_codec *codec,
15745                                            unsigned int res)
15746 {
15747         switch (res >> 26) {
15748         case ALC880_HP_EVENT:
15749                 alc662_f5z_speaker_automute(codec);
15750                 break;
15751         case ALC880_MIC_EVENT:
15752                 alc662_eeepc_mic_automute(codec);
15753                 break;
15754         }
15755 }
15756
15757 static void alc662_mode2_inithook(struct hda_codec *codec)
15758 {
15759         alc662_f5z_speaker_automute(codec);
15760         alc662_eeepc_mic_automute(codec);
15761 }
15762 /* ***************** Mode3 ******************************/
15763 static void alc663_mode3_unsol_event(struct hda_codec *codec,
15764                                            unsigned int res)
15765 {
15766         switch (res >> 26) {
15767         case ALC880_HP_EVENT:
15768                 alc663_two_hp_m1_speaker_automute(codec);
15769                 break;
15770         case ALC880_MIC_EVENT:
15771                 alc662_eeepc_mic_automute(codec);
15772                 break;
15773         }
15774 }
15775
15776 static void alc663_mode3_inithook(struct hda_codec *codec)
15777 {
15778         alc663_two_hp_m1_speaker_automute(codec);
15779         alc662_eeepc_mic_automute(codec);
15780 }
15781 /* ***************** Mode4 ******************************/
15782 static void alc663_mode4_unsol_event(struct hda_codec *codec,
15783                                            unsigned int res)
15784 {
15785         switch (res >> 26) {
15786         case ALC880_HP_EVENT:
15787                 alc663_21jd_two_speaker_automute(codec);
15788                 break;
15789         case ALC880_MIC_EVENT:
15790                 alc662_eeepc_mic_automute(codec);
15791                 break;
15792         }
15793 }
15794
15795 static void alc663_mode4_inithook(struct hda_codec *codec)
15796 {
15797         alc663_21jd_two_speaker_automute(codec);
15798         alc662_eeepc_mic_automute(codec);
15799 }
15800 /* ***************** Mode5 ******************************/
15801 static void alc663_mode5_unsol_event(struct hda_codec *codec,
15802                                            unsigned int res)
15803 {
15804         switch (res >> 26) {
15805         case ALC880_HP_EVENT:
15806                 alc663_15jd_two_speaker_automute(codec);
15807                 break;
15808         case ALC880_MIC_EVENT:
15809                 alc662_eeepc_mic_automute(codec);
15810                 break;
15811         }
15812 }
15813
15814 static void alc663_mode5_inithook(struct hda_codec *codec)
15815 {
15816         alc663_15jd_two_speaker_automute(codec);
15817         alc662_eeepc_mic_automute(codec);
15818 }
15819 /* ***************** Mode6 ******************************/
15820 static void alc663_mode6_unsol_event(struct hda_codec *codec,
15821                                            unsigned int res)
15822 {
15823         switch (res >> 26) {
15824         case ALC880_HP_EVENT:
15825                 alc663_two_hp_m2_speaker_automute(codec);
15826                 break;
15827         case ALC880_MIC_EVENT:
15828                 alc662_eeepc_mic_automute(codec);
15829                 break;
15830         }
15831 }
15832
15833 static void alc663_mode6_inithook(struct hda_codec *codec)
15834 {
15835         alc663_two_hp_m2_speaker_automute(codec);
15836         alc662_eeepc_mic_automute(codec);
15837 }
15838
15839 static void alc663_g71v_hp_automute(struct hda_codec *codec)
15840 {
15841         unsigned int present;
15842         unsigned char bits;
15843
15844         present = snd_hda_codec_read(codec, 0x21, 0,
15845                                      AC_VERB_GET_PIN_SENSE, 0)
15846                 & AC_PINSENSE_PRESENCE;
15847         bits = present ? HDA_AMP_MUTE : 0;
15848         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15849                                  HDA_AMP_MUTE, bits);
15850         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15851                                  HDA_AMP_MUTE, bits);
15852 }
15853
15854 static void alc663_g71v_front_automute(struct hda_codec *codec)
15855 {
15856         unsigned int present;
15857         unsigned char bits;
15858
15859         present = snd_hda_codec_read(codec, 0x15, 0,
15860                                      AC_VERB_GET_PIN_SENSE, 0)
15861                 & AC_PINSENSE_PRESENCE;
15862         bits = present ? HDA_AMP_MUTE : 0;
15863         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15864                                  HDA_AMP_MUTE, bits);
15865 }
15866
15867 static void alc663_g71v_unsol_event(struct hda_codec *codec,
15868                                            unsigned int res)
15869 {
15870         switch (res >> 26) {
15871         case ALC880_HP_EVENT:
15872                 alc663_g71v_hp_automute(codec);
15873                 break;
15874         case ALC880_FRONT_EVENT:
15875                 alc663_g71v_front_automute(codec);
15876                 break;
15877         case ALC880_MIC_EVENT:
15878                 alc662_eeepc_mic_automute(codec);
15879                 break;
15880         }
15881 }
15882
15883 static void alc663_g71v_inithook(struct hda_codec *codec)
15884 {
15885         alc663_g71v_front_automute(codec);
15886         alc663_g71v_hp_automute(codec);
15887         alc662_eeepc_mic_automute(codec);
15888 }
15889
15890 static void alc663_g50v_unsol_event(struct hda_codec *codec,
15891                                            unsigned int res)
15892 {
15893         switch (res >> 26) {
15894         case ALC880_HP_EVENT:
15895                 alc663_m51va_speaker_automute(codec);
15896                 break;
15897         case ALC880_MIC_EVENT:
15898                 alc662_eeepc_mic_automute(codec);
15899                 break;
15900         }
15901 }
15902
15903 static void alc663_g50v_inithook(struct hda_codec *codec)
15904 {
15905         alc663_m51va_speaker_automute(codec);
15906         alc662_eeepc_mic_automute(codec);
15907 }
15908
15909 /* bind hp and internal speaker mute (with plug check) */
15910 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15911                                      struct snd_ctl_elem_value *ucontrol)
15912 {
15913         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15914         long *valp = ucontrol->value.integer.value;
15915         int change;
15916
15917         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15918                                           HDA_AMP_MUTE,
15919                                           valp[0] ? 0 : HDA_AMP_MUTE);
15920         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15921                                            HDA_AMP_MUTE,
15922                                            valp[1] ? 0 : HDA_AMP_MUTE);
15923         if (change)
15924                 alc262_hippo1_automute(codec);
15925         return change;
15926 }
15927
15928 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
15929         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15930         {
15931                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15932                 .name = "Master Playback Switch",
15933                 .info = snd_hda_mixer_amp_switch_info,
15934                 .get = snd_hda_mixer_amp_switch_get,
15935                 .put = alc662_ecs_master_sw_put,
15936                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15937         },
15938
15939         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
15940         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
15941         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
15942
15943         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15944         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15945         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15946         { } /* end */
15947 };
15948
15949 #ifdef CONFIG_SND_HDA_POWER_SAVE
15950 #define alc662_loopbacks        alc880_loopbacks
15951 #endif
15952
15953
15954 /* pcm configuration: identiacal with ALC880 */
15955 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
15956 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
15957 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
15958 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
15959
15960 /*
15961  * configuration and preset
15962  */
15963 static const char *alc662_models[ALC662_MODEL_LAST] = {
15964         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
15965         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
15966         [ALC662_3ST_6ch]        = "3stack-6ch",
15967         [ALC662_5ST_DIG]        = "6stack-dig",
15968         [ALC662_LENOVO_101E]    = "lenovo-101e",
15969         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
15970         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
15971         [ALC662_ECS] = "ecs",
15972         [ALC663_ASUS_M51VA] = "m51va",
15973         [ALC663_ASUS_G71V] = "g71v",
15974         [ALC663_ASUS_H13] = "h13",
15975         [ALC663_ASUS_G50V] = "g50v",
15976         [ALC663_ASUS_MODE1] = "asus-mode1",
15977         [ALC662_ASUS_MODE2] = "asus-mode2",
15978         [ALC663_ASUS_MODE3] = "asus-mode3",
15979         [ALC663_ASUS_MODE4] = "asus-mode4",
15980         [ALC663_ASUS_MODE5] = "asus-mode5",
15981         [ALC663_ASUS_MODE6] = "asus-mode6",
15982         [ALC662_AUTO]           = "auto",
15983 };
15984
15985 static struct snd_pci_quirk alc662_cfg_tbl[] = {
15986         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
15987         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
15988         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
15989         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
15990         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
15991         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
15992         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
15993         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
15994         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
15995         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
15996         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
15997         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
15998         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
15999         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16000         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16001         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16002         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16003         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16004         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16005         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16006         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16007         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16008         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16009         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16010         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16011         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16012         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16013         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16014         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16015         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16016         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16017         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16018         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16019         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16020         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16021         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16022         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16023         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16024                       ALC662_3ST_6ch_DIG),
16025         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16026         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16027         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16028         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16029                       ALC662_3ST_6ch_DIG),
16030         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16031         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16032                                         ALC662_3ST_6ch_DIG),
16033         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
16034         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
16035         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
16036         {}
16037 };
16038
16039 static struct alc_config_preset alc662_presets[] = {
16040         [ALC662_3ST_2ch_DIG] = {
16041                 .mixers = { alc662_3ST_2ch_mixer },
16042                 .init_verbs = { alc662_init_verbs },
16043                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16044                 .dac_nids = alc662_dac_nids,
16045                 .dig_out_nid = ALC662_DIGOUT_NID,
16046                 .dig_in_nid = ALC662_DIGIN_NID,
16047                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16048                 .channel_mode = alc662_3ST_2ch_modes,
16049                 .input_mux = &alc662_capture_source,
16050         },
16051         [ALC662_3ST_6ch_DIG] = {
16052                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16053                 .init_verbs = { alc662_init_verbs },
16054                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16055                 .dac_nids = alc662_dac_nids,
16056                 .dig_out_nid = ALC662_DIGOUT_NID,
16057                 .dig_in_nid = ALC662_DIGIN_NID,
16058                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16059                 .channel_mode = alc662_3ST_6ch_modes,
16060                 .need_dac_fix = 1,
16061                 .input_mux = &alc662_capture_source,
16062         },
16063         [ALC662_3ST_6ch] = {
16064                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16065                 .init_verbs = { alc662_init_verbs },
16066                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16067                 .dac_nids = alc662_dac_nids,
16068                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16069                 .channel_mode = alc662_3ST_6ch_modes,
16070                 .need_dac_fix = 1,
16071                 .input_mux = &alc662_capture_source,
16072         },
16073         [ALC662_5ST_DIG] = {
16074                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16075                 .init_verbs = { alc662_init_verbs },
16076                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16077                 .dac_nids = alc662_dac_nids,
16078                 .dig_out_nid = ALC662_DIGOUT_NID,
16079                 .dig_in_nid = ALC662_DIGIN_NID,
16080                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16081                 .channel_mode = alc662_5stack_modes,
16082                 .input_mux = &alc662_capture_source,
16083         },
16084         [ALC662_LENOVO_101E] = {
16085                 .mixers = { alc662_lenovo_101e_mixer },
16086                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16087                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16088                 .dac_nids = alc662_dac_nids,
16089                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16090                 .channel_mode = alc662_3ST_2ch_modes,
16091                 .input_mux = &alc662_lenovo_101e_capture_source,
16092                 .unsol_event = alc662_lenovo_101e_unsol_event,
16093                 .init_hook = alc662_lenovo_101e_all_automute,
16094         },
16095         [ALC662_ASUS_EEEPC_P701] = {
16096                 .mixers = { alc662_eeepc_p701_mixer },
16097                 .init_verbs = { alc662_init_verbs,
16098                                 alc662_eeepc_sue_init_verbs },
16099                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16100                 .dac_nids = alc662_dac_nids,
16101                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16102                 .channel_mode = alc662_3ST_2ch_modes,
16103                 .input_mux = &alc662_eeepc_capture_source,
16104                 .unsol_event = alc662_eeepc_unsol_event,
16105                 .init_hook = alc662_eeepc_inithook,
16106         },
16107         [ALC662_ASUS_EEEPC_EP20] = {
16108                 .mixers = { alc662_eeepc_ep20_mixer,
16109                             alc662_chmode_mixer },
16110                 .init_verbs = { alc662_init_verbs,
16111                                 alc662_eeepc_ep20_sue_init_verbs },
16112                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16113                 .dac_nids = alc662_dac_nids,
16114                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16115                 .channel_mode = alc662_3ST_6ch_modes,
16116                 .input_mux = &alc662_lenovo_101e_capture_source,
16117                 .unsol_event = alc662_eeepc_ep20_unsol_event,
16118                 .init_hook = alc662_eeepc_ep20_inithook,
16119         },
16120         [ALC662_ECS] = {
16121                 .mixers = { alc662_ecs_mixer },
16122                 .init_verbs = { alc662_init_verbs,
16123                                 alc662_ecs_init_verbs },
16124                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16125                 .dac_nids = alc662_dac_nids,
16126                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16127                 .channel_mode = alc662_3ST_2ch_modes,
16128                 .input_mux = &alc662_eeepc_capture_source,
16129                 .unsol_event = alc662_eeepc_unsol_event,
16130                 .init_hook = alc662_eeepc_inithook,
16131         },
16132         [ALC663_ASUS_M51VA] = {
16133                 .mixers = { alc663_m51va_mixer },
16134                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16135                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16136                 .dac_nids = alc662_dac_nids,
16137                 .dig_out_nid = ALC662_DIGOUT_NID,
16138                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16139                 .channel_mode = alc662_3ST_2ch_modes,
16140                 .input_mux = &alc663_m51va_capture_source,
16141                 .unsol_event = alc663_m51va_unsol_event,
16142                 .init_hook = alc663_m51va_inithook,
16143         },
16144         [ALC663_ASUS_G71V] = {
16145                 .mixers = { alc663_g71v_mixer },
16146                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16147                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16148                 .dac_nids = alc662_dac_nids,
16149                 .dig_out_nid = ALC662_DIGOUT_NID,
16150                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16151                 .channel_mode = alc662_3ST_2ch_modes,
16152                 .input_mux = &alc662_eeepc_capture_source,
16153                 .unsol_event = alc663_g71v_unsol_event,
16154                 .init_hook = alc663_g71v_inithook,
16155         },
16156         [ALC663_ASUS_H13] = {
16157                 .mixers = { alc663_m51va_mixer },
16158                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16159                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16160                 .dac_nids = alc662_dac_nids,
16161                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16162                 .channel_mode = alc662_3ST_2ch_modes,
16163                 .input_mux = &alc663_m51va_capture_source,
16164                 .unsol_event = alc663_m51va_unsol_event,
16165                 .init_hook = alc663_m51va_inithook,
16166         },
16167         [ALC663_ASUS_G50V] = {
16168                 .mixers = { alc663_g50v_mixer },
16169                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
16170                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16171                 .dac_nids = alc662_dac_nids,
16172                 .dig_out_nid = ALC662_DIGOUT_NID,
16173                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16174                 .channel_mode = alc662_3ST_6ch_modes,
16175                 .input_mux = &alc663_capture_source,
16176                 .unsol_event = alc663_g50v_unsol_event,
16177                 .init_hook = alc663_g50v_inithook,
16178         },
16179         [ALC663_ASUS_MODE1] = {
16180                 .mixers = { alc663_m51va_mixer },
16181                 .cap_mixer = alc662_auto_capture_mixer,
16182                 .init_verbs = { alc662_init_verbs,
16183                                 alc663_21jd_amic_init_verbs },
16184                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16185                 .hp_nid = 0x03,
16186                 .dac_nids = alc662_dac_nids,
16187                 .dig_out_nid = ALC662_DIGOUT_NID,
16188                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16189                 .channel_mode = alc662_3ST_2ch_modes,
16190                 .input_mux = &alc662_eeepc_capture_source,
16191                 .unsol_event = alc663_mode1_unsol_event,
16192                 .init_hook = alc663_mode1_inithook,
16193         },
16194         [ALC662_ASUS_MODE2] = {
16195                 .mixers = { alc662_1bjd_mixer },
16196                 .cap_mixer = alc662_auto_capture_mixer,
16197                 .init_verbs = { alc662_init_verbs,
16198                                 alc662_1bjd_amic_init_verbs },
16199                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
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 = alc662_mode2_unsol_event,
16206                 .init_hook = alc662_mode2_inithook,
16207         },
16208         [ALC663_ASUS_MODE3] = {
16209                 .mixers = { alc663_two_hp_m1_mixer },
16210                 .cap_mixer = alc662_auto_capture_mixer,
16211                 .init_verbs = { alc662_init_verbs,
16212                                 alc663_two_hp_amic_m1_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_mode3_unsol_event,
16221                 .init_hook = alc663_mode3_inithook,
16222         },
16223         [ALC663_ASUS_MODE4] = {
16224                 .mixers = { alc663_asus_21jd_clfe_mixer },
16225                 .cap_mixer = alc662_auto_capture_mixer,
16226                 .init_verbs = { alc662_init_verbs,
16227                                 alc663_21jd_amic_init_verbs},
16228                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16229                 .hp_nid = 0x03,
16230                 .dac_nids = alc662_dac_nids,
16231                 .dig_out_nid = ALC662_DIGOUT_NID,
16232                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16233                 .channel_mode = alc662_3ST_2ch_modes,
16234                 .input_mux = &alc662_eeepc_capture_source,
16235                 .unsol_event = alc663_mode4_unsol_event,
16236                 .init_hook = alc663_mode4_inithook,
16237         },
16238         [ALC663_ASUS_MODE5] = {
16239                 .mixers = { alc663_asus_15jd_clfe_mixer },
16240                 .cap_mixer = alc662_auto_capture_mixer,
16241                 .init_verbs = { alc662_init_verbs,
16242                                 alc663_15jd_amic_init_verbs },
16243                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16244                 .hp_nid = 0x03,
16245                 .dac_nids = alc662_dac_nids,
16246                 .dig_out_nid = ALC662_DIGOUT_NID,
16247                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16248                 .channel_mode = alc662_3ST_2ch_modes,
16249                 .input_mux = &alc662_eeepc_capture_source,
16250                 .unsol_event = alc663_mode5_unsol_event,
16251                 .init_hook = alc663_mode5_inithook,
16252         },
16253         [ALC663_ASUS_MODE6] = {
16254                 .mixers = { alc663_two_hp_m2_mixer },
16255                 .cap_mixer = alc662_auto_capture_mixer,
16256                 .init_verbs = { alc662_init_verbs,
16257                                 alc663_two_hp_amic_m2_init_verbs },
16258                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16259                 .hp_nid = 0x03,
16260                 .dac_nids = alc662_dac_nids,
16261                 .dig_out_nid = ALC662_DIGOUT_NID,
16262                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16263                 .channel_mode = alc662_3ST_2ch_modes,
16264                 .input_mux = &alc662_eeepc_capture_source,
16265                 .unsol_event = alc663_mode6_unsol_event,
16266                 .init_hook = alc663_mode6_inithook,
16267         },
16268 };
16269
16270
16271 /*
16272  * BIOS auto configuration
16273  */
16274
16275 /* add playback controls from the parsed DAC table */
16276 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
16277                                              const struct auto_pin_cfg *cfg)
16278 {
16279         char name[32];
16280         static const char *chname[4] = {
16281                 "Front", "Surround", NULL /*CLFE*/, "Side"
16282         };
16283         hda_nid_t nid;
16284         int i, err;
16285
16286         for (i = 0; i < cfg->line_outs; i++) {
16287                 if (!spec->multiout.dac_nids[i])
16288                         continue;
16289                 nid = alc880_idx_to_dac(i);
16290                 if (i == 2) {
16291                         /* Center/LFE */
16292                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16293                                           "Center Playback Volume",
16294                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
16295                                                               HDA_OUTPUT));
16296                         if (err < 0)
16297                                 return err;
16298                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16299                                           "LFE Playback Volume",
16300                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
16301                                                               HDA_OUTPUT));
16302                         if (err < 0)
16303                                 return err;
16304                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16305                                           "Center Playback Switch",
16306                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
16307                                                               HDA_INPUT));
16308                         if (err < 0)
16309                                 return err;
16310                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16311                                           "LFE Playback Switch",
16312                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
16313                                                               HDA_INPUT));
16314                         if (err < 0)
16315                                 return err;
16316                 } else {
16317                         sprintf(name, "%s Playback Volume", chname[i]);
16318                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16319                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
16320                                                               HDA_OUTPUT));
16321                         if (err < 0)
16322                                 return err;
16323                         sprintf(name, "%s Playback Switch", chname[i]);
16324                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16325                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
16326                                                     3, 0, HDA_INPUT));
16327                         if (err < 0)
16328                                 return err;
16329                 }
16330         }
16331         return 0;
16332 }
16333
16334 /* add playback controls for speaker and HP outputs */
16335 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16336                                         const char *pfx)
16337 {
16338         hda_nid_t nid;
16339         int err;
16340         char name[32];
16341
16342         if (!pin)
16343                 return 0;
16344
16345         if (pin == 0x17) {
16346                 /* ALC663 has a mono output pin on 0x17 */
16347                 sprintf(name, "%s Playback Switch", pfx);
16348                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16349                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16350                 return err;
16351         }
16352
16353         if (alc880_is_fixed_pin(pin)) {
16354                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16355                 /* printk("DAC nid=%x\n",nid); */
16356                 /* specify the DAC as the extra output */
16357                 if (!spec->multiout.hp_nid)
16358                         spec->multiout.hp_nid = nid;
16359                 else
16360                         spec->multiout.extra_out_nid[0] = nid;
16361                 /* control HP volume/switch on the output mixer amp */
16362                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16363                 sprintf(name, "%s Playback Volume", pfx);
16364                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16365                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16366                 if (err < 0)
16367                         return err;
16368                 sprintf(name, "%s Playback Switch", pfx);
16369                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16370                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16371                 if (err < 0)
16372                         return err;
16373         } else if (alc880_is_multi_pin(pin)) {
16374                 /* set manual connection */
16375                 /* we have only a switch on HP-out PIN */
16376                 sprintf(name, "%s Playback Switch", pfx);
16377                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16378                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16379                 if (err < 0)
16380                         return err;
16381         }
16382         return 0;
16383 }
16384
16385 /* create playback/capture controls for input pins */
16386 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
16387                                                 const struct auto_pin_cfg *cfg)
16388 {
16389         struct hda_input_mux *imux = &spec->private_imux;
16390         int i, err, idx;
16391
16392         for (i = 0; i < AUTO_PIN_LAST; i++) {
16393                 if (alc880_is_input_pin(cfg->input_pins[i])) {
16394                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
16395                         err = new_analog_input(spec, cfg->input_pins[i],
16396                                                auto_pin_cfg_labels[i],
16397                                                idx, 0x0b);
16398                         if (err < 0)
16399                                 return err;
16400                         imux->items[imux->num_items].label =
16401                                 auto_pin_cfg_labels[i];
16402                         imux->items[imux->num_items].index =
16403                                 alc880_input_pin_idx(cfg->input_pins[i]);
16404                         imux->num_items++;
16405                 }
16406         }
16407         return 0;
16408 }
16409
16410 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16411                                               hda_nid_t nid, int pin_type,
16412                                               int dac_idx)
16413 {
16414         alc_set_pin_output(codec, nid, pin_type);
16415         /* need the manual connection? */
16416         if (alc880_is_multi_pin(nid)) {
16417                 struct alc_spec *spec = codec->spec;
16418                 int idx = alc880_multi_pin_idx(nid);
16419                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16420                                     AC_VERB_SET_CONNECT_SEL,
16421                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16422         }
16423 }
16424
16425 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16426 {
16427         struct alc_spec *spec = codec->spec;
16428         int i;
16429
16430         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16431         for (i = 0; i <= HDA_SIDE; i++) {
16432                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16433                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16434                 if (nid)
16435                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16436                                                           i);
16437         }
16438 }
16439
16440 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16441 {
16442         struct alc_spec *spec = codec->spec;
16443         hda_nid_t pin;
16444
16445         pin = spec->autocfg.hp_pins[0];
16446         if (pin) /* connect to front */
16447                 /* use dac 0 */
16448                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16449         pin = spec->autocfg.speaker_pins[0];
16450         if (pin)
16451                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16452 }
16453
16454 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
16455 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16456
16457 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16458 {
16459         struct alc_spec *spec = codec->spec;
16460         int i;
16461
16462         for (i = 0; i < AUTO_PIN_LAST; i++) {
16463                 hda_nid_t nid = spec->autocfg.input_pins[i];
16464                 if (alc662_is_input_pin(nid)) {
16465                         snd_hda_codec_write(codec, nid, 0,
16466                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
16467                                             (i <= AUTO_PIN_FRONT_MIC ?
16468                                              PIN_VREF80 : PIN_IN));
16469                         if (nid != ALC662_PIN_CD_NID)
16470                                 snd_hda_codec_write(codec, nid, 0,
16471                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16472                                                     AMP_OUT_MUTE);
16473                 }
16474         }
16475 }
16476
16477 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16478
16479 static int alc662_parse_auto_config(struct hda_codec *codec)
16480 {
16481         struct alc_spec *spec = codec->spec;
16482         int err;
16483         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16484
16485         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16486                                            alc662_ignore);
16487         if (err < 0)
16488                 return err;
16489         if (!spec->autocfg.line_outs)
16490                 return 0; /* can't find valid BIOS pin config */
16491
16492         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16493         if (err < 0)
16494                 return err;
16495         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16496         if (err < 0)
16497                 return err;
16498         err = alc662_auto_create_extra_out(spec,
16499                                            spec->autocfg.speaker_pins[0],
16500                                            "Speaker");
16501         if (err < 0)
16502                 return err;
16503         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
16504                                            "Headphone");
16505         if (err < 0)
16506                 return err;
16507         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
16508         if (err < 0)
16509                 return err;
16510
16511         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16512
16513         if (spec->autocfg.dig_out_pin)
16514                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16515
16516         if (spec->kctls.list)
16517                 add_mixer(spec, spec->kctls.list);
16518
16519         spec->num_mux_defs = 1;
16520         spec->input_mux = &spec->private_imux;
16521
16522         add_verb(spec, alc662_auto_init_verbs);
16523         if (codec->vendor_id == 0x10ec0663)
16524                 add_verb(spec, alc663_auto_init_verbs);
16525
16526         err = alc_auto_add_mic_boost(codec);
16527         if (err < 0)
16528                 return err;
16529
16530         store_pin_configs(codec);
16531         return 1;
16532 }
16533
16534 /* additional initialization for auto-configuration model */
16535 static void alc662_auto_init(struct hda_codec *codec)
16536 {
16537         struct alc_spec *spec = codec->spec;
16538         alc662_auto_init_multi_out(codec);
16539         alc662_auto_init_hp_out(codec);
16540         alc662_auto_init_analog_input(codec);
16541         alc662_auto_init_input_src(codec);
16542         if (spec->unsol_event)
16543                 alc_inithook(codec);
16544 }
16545
16546 static int patch_alc662(struct hda_codec *codec)
16547 {
16548         struct alc_spec *spec;
16549         int err, board_config;
16550
16551         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16552         if (!spec)
16553                 return -ENOMEM;
16554
16555         codec->spec = spec;
16556
16557         alc_fix_pll_init(codec, 0x20, 0x04, 15);
16558
16559         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
16560                                                   alc662_models,
16561                                                   alc662_cfg_tbl);
16562         if (board_config < 0) {
16563                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
16564                        "trying auto-probe from BIOS...\n");
16565                 board_config = ALC662_AUTO;
16566         }
16567
16568         if (board_config == ALC662_AUTO) {
16569                 /* automatic parse from the BIOS config */
16570                 err = alc662_parse_auto_config(codec);
16571                 if (err < 0) {
16572                         alc_free(codec);
16573                         return err;
16574                 } else if (!err) {
16575                         printk(KERN_INFO
16576                                "hda_codec: Cannot set up configuration "
16577                                "from BIOS.  Using base mode...\n");
16578                         board_config = ALC662_3ST_2ch_DIG;
16579                 }
16580         }
16581
16582         if (board_config != ALC662_AUTO)
16583                 setup_preset(spec, &alc662_presets[board_config]);
16584
16585         if (codec->vendor_id == 0x10ec0663) {
16586                 spec->stream_name_analog = "ALC663 Analog";
16587                 spec->stream_name_digital = "ALC663 Digital";
16588         } else if (codec->vendor_id == 0x10ec0272) {
16589                 spec->stream_name_analog = "ALC272 Analog";
16590                 spec->stream_name_digital = "ALC272 Digital";
16591         } else {
16592                 spec->stream_name_analog = "ALC662 Analog";
16593                 spec->stream_name_digital = "ALC662 Digital";
16594         }
16595
16596         spec->stream_analog_playback = &alc662_pcm_analog_playback;
16597         spec->stream_analog_capture = &alc662_pcm_analog_capture;
16598
16599         spec->stream_digital_playback = &alc662_pcm_digital_playback;
16600         spec->stream_digital_capture = &alc662_pcm_digital_capture;
16601
16602         spec->adc_nids = alc662_adc_nids;
16603         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16604         spec->capsrc_nids = alc662_capsrc_nids;
16605         spec->is_mix_capture = 1;
16606
16607         if (!spec->cap_mixer)
16608                 set_capture_mixer(spec);
16609
16610         spec->vmaster_nid = 0x02;
16611
16612         codec->patch_ops = alc_patch_ops;
16613         if (board_config == ALC662_AUTO)
16614                 spec->init_hook = alc662_auto_init;
16615 #ifdef CONFIG_SND_HDA_POWER_SAVE
16616         if (!spec->loopback.amplist)
16617                 spec->loopback.amplist = alc662_loopbacks;
16618 #endif
16619         codec->proc_widget_hook = print_realtek_coef;
16620
16621         return 0;
16622 }
16623
16624 /*
16625  * patch entries
16626  */
16627 static struct hda_codec_preset snd_hda_preset_realtek[] = {
16628         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16629         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16630         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
16631         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
16632         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
16633         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
16634         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
16635           .patch = patch_alc861 },
16636         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
16637         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
16638         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
16639         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
16640           .patch = patch_alc883 },
16641         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
16642           .patch = patch_alc662 },
16643         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
16644         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
16645         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
16646         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16647         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
16648           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16649         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
16650           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16651         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
16652         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
16653         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
16654           .patch = patch_alc883 },
16655         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
16656         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16657         {} /* terminator */
16658 };
16659
16660 MODULE_ALIAS("snd-hda-codec-id:10ec*");
16661
16662 MODULE_LICENSE("GPL");
16663 MODULE_DESCRIPTION("Realtek HD-audio codec");
16664
16665 static struct hda_codec_preset_list realtek_list = {
16666         .preset = snd_hda_preset_realtek,
16667         .owner = THIS_MODULE,
16668 };
16669
16670 static int __init patch_realtek_init(void)
16671 {
16672         return snd_hda_add_codec_preset(&realtek_list);
16673 }
16674
16675 static void __exit patch_realtek_exit(void)
16676 {
16677         snd_hda_delete_codec_preset(&realtek_list);
16678 }
16679
16680 module_init(patch_realtek_init)
16681 module_exit(patch_realtek_exit)