]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - sound/pci/hda/patch_realtek.c
98a02fd1097ed4b00a356cc488d0bdd44ec13422
[linux-2.6-omap-h63xx.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_patch.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_DC7600,
76         ALC260_HP_3013,
77         ALC260_FUJITSU_S702X,
78         ALC260_ACER,
79         ALC260_WILL,
80         ALC260_REPLACER_672V,
81 #ifdef CONFIG_SND_DEBUG
82         ALC260_TEST,
83 #endif
84         ALC260_AUTO,
85         ALC260_MODEL_LAST /* last tag */
86 };
87
88 /* ALC262 models */
89 enum {
90         ALC262_BASIC,
91         ALC262_HIPPO,
92         ALC262_HIPPO_1,
93         ALC262_FUJITSU,
94         ALC262_HP_BPC,
95         ALC262_HP_BPC_D7000_WL,
96         ALC262_HP_BPC_D7000_WF,
97         ALC262_HP_TC_T5735,
98         ALC262_HP_RP5700,
99         ALC262_BENQ_ED8,
100         ALC262_SONY_ASSAMD,
101         ALC262_BENQ_T31,
102         ALC262_ULTRA,
103         ALC262_LENOVO_3000,
104         ALC262_NEC,
105         ALC262_TOSHIBA_S06,
106         ALC262_TOSHIBA_RX1,
107         ALC262_AUTO,
108         ALC262_MODEL_LAST /* last tag */
109 };
110
111 /* ALC268 models */
112 enum {
113         ALC267_QUANTA_IL1,
114         ALC268_3ST,
115         ALC268_TOSHIBA,
116         ALC268_ACER,
117         ALC268_ACER_DMIC,
118         ALC268_ACER_ASPIRE_ONE,
119         ALC268_DELL,
120         ALC268_ZEPTO,
121 #ifdef CONFIG_SND_DEBUG
122         ALC268_TEST,
123 #endif
124         ALC268_AUTO,
125         ALC268_MODEL_LAST /* last tag */
126 };
127
128 /* ALC269 models */
129 enum {
130         ALC269_BASIC,
131         ALC269_QUANTA_FL1,
132         ALC269_ASUS_EEEPC_P703,
133         ALC269_ASUS_EEEPC_P901,
134         ALC269_FUJITSU,
135         ALC269_LIFEBOOK,
136         ALC269_AUTO,
137         ALC269_MODEL_LAST /* last tag */
138 };
139
140 /* ALC861 models */
141 enum {
142         ALC861_3ST,
143         ALC660_3ST,
144         ALC861_3ST_DIG,
145         ALC861_6ST_DIG,
146         ALC861_UNIWILL_M31,
147         ALC861_TOSHIBA,
148         ALC861_ASUS,
149         ALC861_ASUS_LAPTOP,
150         ALC861_AUTO,
151         ALC861_MODEL_LAST,
152 };
153
154 /* ALC861-VD models */
155 enum {
156         ALC660VD_3ST,
157         ALC660VD_3ST_DIG,
158         ALC660VD_ASUS_V1S,
159         ALC861VD_3ST,
160         ALC861VD_3ST_DIG,
161         ALC861VD_6ST_DIG,
162         ALC861VD_LENOVO,
163         ALC861VD_DALLAS,
164         ALC861VD_HP,
165         ALC861VD_AUTO,
166         ALC861VD_MODEL_LAST,
167 };
168
169 /* ALC662 models */
170 enum {
171         ALC662_3ST_2ch_DIG,
172         ALC662_3ST_6ch_DIG,
173         ALC662_3ST_6ch,
174         ALC662_5ST_DIG,
175         ALC662_LENOVO_101E,
176         ALC662_ASUS_EEEPC_P701,
177         ALC662_ASUS_EEEPC_EP20,
178         ALC663_ASUS_M51VA,
179         ALC663_ASUS_G71V,
180         ALC663_ASUS_H13,
181         ALC663_ASUS_G50V,
182         ALC662_ECS,
183         ALC663_ASUS_MODE1,
184         ALC662_ASUS_MODE2,
185         ALC663_ASUS_MODE3,
186         ALC663_ASUS_MODE4,
187         ALC663_ASUS_MODE5,
188         ALC663_ASUS_MODE6,
189         ALC662_AUTO,
190         ALC662_MODEL_LAST,
191 };
192
193 /* ALC882 models */
194 enum {
195         ALC882_3ST_DIG,
196         ALC882_6ST_DIG,
197         ALC882_ARIMA,
198         ALC882_W2JC,
199         ALC882_TARGA,
200         ALC882_ASUS_A7J,
201         ALC882_ASUS_A7M,
202         ALC885_MACPRO,
203         ALC885_MBP3,
204         ALC885_IMAC24,
205         ALC882_AUTO,
206         ALC882_MODEL_LAST,
207 };
208
209 /* ALC883 models */
210 enum {
211         ALC883_3ST_2ch_DIG,
212         ALC883_3ST_6ch_DIG,
213         ALC883_3ST_6ch,
214         ALC883_6ST_DIG,
215         ALC883_TARGA_DIG,
216         ALC883_TARGA_2ch_DIG,
217         ALC883_ACER,
218         ALC883_ACER_ASPIRE,
219         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         ALC883_3ST_6ch_INTEL,
233         ALC888_ASUS_M90V,
234         ALC888_ASUS_EEE1601,
235         ALC883_AUTO,
236         ALC883_MODEL_LAST,
237 };
238
239 /* for GPIO Poll */
240 #define GPIO_MASK       0x03
241
242 struct alc_spec {
243         /* codec parameterization */
244         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
245         unsigned int num_mixers;
246         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
247
248         const struct hda_verb *init_verbs[5];   /* initialization verbs
249                                                  * don't forget NULL
250                                                  * termination!
251                                                  */
252         unsigned int num_init_verbs;
253
254         char *stream_name_analog;       /* analog PCM stream */
255         struct hda_pcm_stream *stream_analog_playback;
256         struct hda_pcm_stream *stream_analog_capture;
257         struct hda_pcm_stream *stream_analog_alt_playback;
258         struct hda_pcm_stream *stream_analog_alt_capture;
259
260         char *stream_name_digital;      /* digital PCM stream */
261         struct hda_pcm_stream *stream_digital_playback;
262         struct hda_pcm_stream *stream_digital_capture;
263
264         /* playback */
265         struct hda_multi_out multiout;  /* playback set-up
266                                          * max_channels, dacs must be set
267                                          * dig_out_nid and hp_nid are optional
268                                          */
269         hda_nid_t alt_dac_nid;
270
271         /* capture */
272         unsigned int num_adc_nids;
273         hda_nid_t *adc_nids;
274         hda_nid_t *capsrc_nids;
275         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
276         unsigned char is_mix_capture;   /* matrix-style capture (non-mux) */
277
278         /* capture source */
279         unsigned int num_mux_defs;
280         const struct hda_input_mux *input_mux;
281         unsigned int cur_mux[3];
282
283         /* channel model */
284         const struct hda_channel_mode *channel_mode;
285         int num_channel_mode;
286         int need_dac_fix;
287
288         /* PCM information */
289         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
290
291         /* dynamic controls, init_verbs and input_mux */
292         struct auto_pin_cfg autocfg;
293         struct snd_array kctls;
294         struct hda_input_mux private_imux;
295         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
296
297         /* hooks */
298         void (*init_hook)(struct hda_codec *codec);
299         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
300
301         /* for pin sensing */
302         unsigned int sense_updated: 1;
303         unsigned int jack_present: 1;
304         unsigned int master_sw: 1;
305
306         /* for virtual master */
307         hda_nid_t vmaster_nid;
308 #ifdef CONFIG_SND_HDA_POWER_SAVE
309         struct hda_loopback_check loopback;
310 #endif
311
312         /* for PLL fix */
313         hda_nid_t pll_nid;
314         unsigned int pll_coef_idx, pll_coef_bit;
315
316 #ifdef SND_HDA_NEEDS_RESUME
317 #define ALC_MAX_PINS    16
318         unsigned int num_pins;
319         hda_nid_t pin_nids[ALC_MAX_PINS];
320         unsigned int pin_cfgs[ALC_MAX_PINS];
321 #endif
322 };
323
324 /*
325  * configuration template - to be copied to the spec instance
326  */
327 struct alc_config_preset {
328         struct snd_kcontrol_new *mixers[5]; /* should be identical size
329                                              * with spec
330                                              */
331         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
332         const struct hda_verb *init_verbs[5];
333         unsigned int num_dacs;
334         hda_nid_t *dac_nids;
335         hda_nid_t dig_out_nid;          /* optional */
336         hda_nid_t hp_nid;               /* optional */
337         unsigned int num_adc_nids;
338         hda_nid_t *adc_nids;
339         hda_nid_t *capsrc_nids;
340         hda_nid_t dig_in_nid;
341         unsigned int num_channel_mode;
342         const struct hda_channel_mode *channel_mode;
343         int need_dac_fix;
344         unsigned int num_mux_defs;
345         const struct hda_input_mux *input_mux;
346         void (*unsol_event)(struct hda_codec *, unsigned int);
347         void (*init_hook)(struct hda_codec *);
348 #ifdef CONFIG_SND_HDA_POWER_SAVE
349         struct hda_amp_list *loopbacks;
350 #endif
351 };
352
353
354 /*
355  * input MUX handling
356  */
357 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
358                              struct snd_ctl_elem_info *uinfo)
359 {
360         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
361         struct alc_spec *spec = codec->spec;
362         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
363         if (mux_idx >= spec->num_mux_defs)
364                 mux_idx = 0;
365         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
366 }
367
368 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
369                             struct snd_ctl_elem_value *ucontrol)
370 {
371         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
372         struct alc_spec *spec = codec->spec;
373         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
374
375         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
376         return 0;
377 }
378
379 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
380                             struct snd_ctl_elem_value *ucontrol)
381 {
382         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
383         struct alc_spec *spec = codec->spec;
384         const struct hda_input_mux *imux = spec->input_mux;
385         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
386         hda_nid_t nid = spec->capsrc_nids ?
387                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
388
389         if (spec->is_mix_capture) {
390                 /* Matrix-mixer style (e.g. ALC882) */
391                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
392                 unsigned int i, idx;
393
394                 idx = ucontrol->value.enumerated.item[0];
395                 if (idx >= imux->num_items)
396                         idx = imux->num_items - 1;
397                 if (*cur_val == idx)
398                         return 0;
399                 for (i = 0; i < imux->num_items; i++) {
400                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
401                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
402                                                  imux->items[i].index,
403                                                  HDA_AMP_MUTE, v);
404                 }
405                 *cur_val = idx;
406                 return 1;
407         } else {
408                 /* MUX style (e.g. ALC880) */
409                 unsigned int mux_idx;
410                 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
411                 return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx],
412                                              ucontrol, nid,
413                                              &spec->cur_mux[adc_idx]);
414         }
415 }
416
417 /*
418  * channel mode setting
419  */
420 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
421                             struct snd_ctl_elem_info *uinfo)
422 {
423         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
424         struct alc_spec *spec = codec->spec;
425         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
426                                     spec->num_channel_mode);
427 }
428
429 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
430                            struct snd_ctl_elem_value *ucontrol)
431 {
432         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
433         struct alc_spec *spec = codec->spec;
434         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
435                                    spec->num_channel_mode,
436                                    spec->multiout.max_channels);
437 }
438
439 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
440                            struct snd_ctl_elem_value *ucontrol)
441 {
442         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
443         struct alc_spec *spec = codec->spec;
444         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
445                                       spec->num_channel_mode,
446                                       &spec->multiout.max_channels);
447         if (err >= 0 && spec->need_dac_fix)
448                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
449         return err;
450 }
451
452 /*
453  * Control the mode of pin widget settings via the mixer.  "pc" is used
454  * instead of "%" to avoid consequences of accidently treating the % as
455  * being part of a format specifier.  Maximum allowed length of a value is
456  * 63 characters plus NULL terminator.
457  *
458  * Note: some retasking pin complexes seem to ignore requests for input
459  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
460  * are requested.  Therefore order this list so that this behaviour will not
461  * cause problems when mixer clients move through the enum sequentially.
462  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
463  * March 2006.
464  */
465 static char *alc_pin_mode_names[] = {
466         "Mic 50pc bias", "Mic 80pc bias",
467         "Line in", "Line out", "Headphone out",
468 };
469 static unsigned char alc_pin_mode_values[] = {
470         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
471 };
472 /* The control can present all 5 options, or it can limit the options based
473  * in the pin being assumed to be exclusively an input or an output pin.  In
474  * addition, "input" pins may or may not process the mic bias option
475  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
476  * accept requests for bias as of chip versions up to March 2006) and/or
477  * wiring in the computer.
478  */
479 #define ALC_PIN_DIR_IN              0x00
480 #define ALC_PIN_DIR_OUT             0x01
481 #define ALC_PIN_DIR_INOUT           0x02
482 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
483 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
484
485 /* Info about the pin modes supported by the different pin direction modes.
486  * For each direction the minimum and maximum values are given.
487  */
488 static signed char alc_pin_mode_dir_info[5][2] = {
489         { 0, 2 },    /* ALC_PIN_DIR_IN */
490         { 3, 4 },    /* ALC_PIN_DIR_OUT */
491         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
492         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
493         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
494 };
495 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
496 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
497 #define alc_pin_mode_n_items(_dir) \
498         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
499
500 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
501                              struct snd_ctl_elem_info *uinfo)
502 {
503         unsigned int item_num = uinfo->value.enumerated.item;
504         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
505
506         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
507         uinfo->count = 1;
508         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
509
510         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
511                 item_num = alc_pin_mode_min(dir);
512         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
513         return 0;
514 }
515
516 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
517                             struct snd_ctl_elem_value *ucontrol)
518 {
519         unsigned int i;
520         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
521         hda_nid_t nid = kcontrol->private_value & 0xffff;
522         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
523         long *valp = ucontrol->value.integer.value;
524         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
525                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
526                                                  0x00);
527
528         /* Find enumerated value for current pinctl setting */
529         i = alc_pin_mode_min(dir);
530         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
531                 i++;
532         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
533         return 0;
534 }
535
536 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
537                             struct snd_ctl_elem_value *ucontrol)
538 {
539         signed int change;
540         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
541         hda_nid_t nid = kcontrol->private_value & 0xffff;
542         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
543         long val = *ucontrol->value.integer.value;
544         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
545                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
546                                                  0x00);
547
548         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
549                 val = alc_pin_mode_min(dir);
550
551         change = pinctl != alc_pin_mode_values[val];
552         if (change) {
553                 /* Set pin mode to that requested */
554                 snd_hda_codec_write_cache(codec, nid, 0,
555                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
556                                           alc_pin_mode_values[val]);
557
558                 /* Also enable the retasking pin's input/output as required
559                  * for the requested pin mode.  Enum values of 2 or less are
560                  * input modes.
561                  *
562                  * Dynamically switching the input/output buffers probably
563                  * reduces noise slightly (particularly on input) so we'll
564                  * do it.  However, having both input and output buffers
565                  * enabled simultaneously doesn't seem to be problematic if
566                  * this turns out to be necessary in the future.
567                  */
568                 if (val <= 2) {
569                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
570                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
571                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
572                                                  HDA_AMP_MUTE, 0);
573                 } else {
574                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
575                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
576                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
577                                                  HDA_AMP_MUTE, 0);
578                 }
579         }
580         return change;
581 }
582
583 #define ALC_PIN_MODE(xname, nid, dir) \
584         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
585           .info = alc_pin_mode_info, \
586           .get = alc_pin_mode_get, \
587           .put = alc_pin_mode_put, \
588           .private_value = nid | (dir<<16) }
589
590 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
591  * together using a mask with more than one bit set.  This control is
592  * currently used only by the ALC260 test model.  At this stage they are not
593  * needed for any "production" models.
594  */
595 #ifdef CONFIG_SND_DEBUG
596 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
597
598 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
599                              struct snd_ctl_elem_value *ucontrol)
600 {
601         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
602         hda_nid_t nid = kcontrol->private_value & 0xffff;
603         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
604         long *valp = ucontrol->value.integer.value;
605         unsigned int val = snd_hda_codec_read(codec, nid, 0,
606                                               AC_VERB_GET_GPIO_DATA, 0x00);
607
608         *valp = (val & mask) != 0;
609         return 0;
610 }
611 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
612                              struct snd_ctl_elem_value *ucontrol)
613 {
614         signed int change;
615         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
616         hda_nid_t nid = kcontrol->private_value & 0xffff;
617         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
618         long val = *ucontrol->value.integer.value;
619         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
620                                                     AC_VERB_GET_GPIO_DATA,
621                                                     0x00);
622
623         /* Set/unset the masked GPIO bit(s) as needed */
624         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
625         if (val == 0)
626                 gpio_data &= ~mask;
627         else
628                 gpio_data |= mask;
629         snd_hda_codec_write_cache(codec, nid, 0,
630                                   AC_VERB_SET_GPIO_DATA, gpio_data);
631
632         return change;
633 }
634 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
635         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
636           .info = alc_gpio_data_info, \
637           .get = alc_gpio_data_get, \
638           .put = alc_gpio_data_put, \
639           .private_value = nid | (mask<<16) }
640 #endif   /* CONFIG_SND_DEBUG */
641
642 /* A switch control to allow the enabling of the digital IO pins on the
643  * ALC260.  This is incredibly simplistic; the intention of this control is
644  * to provide something in the test model allowing digital outputs to be
645  * identified if present.  If models are found which can utilise these
646  * outputs a more complete mixer control can be devised for those models if
647  * necessary.
648  */
649 #ifdef CONFIG_SND_DEBUG
650 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
651
652 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
653                               struct snd_ctl_elem_value *ucontrol)
654 {
655         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
656         hda_nid_t nid = kcontrol->private_value & 0xffff;
657         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
658         long *valp = ucontrol->value.integer.value;
659         unsigned int val = snd_hda_codec_read(codec, nid, 0,
660                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
661
662         *valp = (val & mask) != 0;
663         return 0;
664 }
665 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
666                               struct snd_ctl_elem_value *ucontrol)
667 {
668         signed int change;
669         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670         hda_nid_t nid = kcontrol->private_value & 0xffff;
671         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
672         long val = *ucontrol->value.integer.value;
673         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
674                                                     AC_VERB_GET_DIGI_CONVERT_1,
675                                                     0x00);
676
677         /* Set/unset the masked control bit(s) as needed */
678         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
679         if (val==0)
680                 ctrl_data &= ~mask;
681         else
682                 ctrl_data |= mask;
683         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
684                                   ctrl_data);
685
686         return change;
687 }
688 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
689         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
690           .info = alc_spdif_ctrl_info, \
691           .get = alc_spdif_ctrl_get, \
692           .put = alc_spdif_ctrl_put, \
693           .private_value = nid | (mask<<16) }
694 #endif   /* CONFIG_SND_DEBUG */
695
696 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
697  * Again, this is only used in the ALC26x test models to help identify when
698  * the EAPD line must be asserted for features to work.
699  */
700 #ifdef CONFIG_SND_DEBUG
701 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
702
703 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
704                               struct snd_ctl_elem_value *ucontrol)
705 {
706         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
707         hda_nid_t nid = kcontrol->private_value & 0xffff;
708         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
709         long *valp = ucontrol->value.integer.value;
710         unsigned int val = snd_hda_codec_read(codec, nid, 0,
711                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
712
713         *valp = (val & mask) != 0;
714         return 0;
715 }
716
717 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
718                               struct snd_ctl_elem_value *ucontrol)
719 {
720         int change;
721         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
722         hda_nid_t nid = kcontrol->private_value & 0xffff;
723         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
724         long val = *ucontrol->value.integer.value;
725         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
726                                                     AC_VERB_GET_EAPD_BTLENABLE,
727                                                     0x00);
728
729         /* Set/unset the masked control bit(s) as needed */
730         change = (!val ? 0 : mask) != (ctrl_data & mask);
731         if (!val)
732                 ctrl_data &= ~mask;
733         else
734                 ctrl_data |= mask;
735         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
736                                   ctrl_data);
737
738         return change;
739 }
740
741 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
742         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
743           .info = alc_eapd_ctrl_info, \
744           .get = alc_eapd_ctrl_get, \
745           .put = alc_eapd_ctrl_put, \
746           .private_value = nid | (mask<<16) }
747 #endif   /* CONFIG_SND_DEBUG */
748
749 /*
750  */
751 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
752 {
753         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
754                 return;
755         spec->mixers[spec->num_mixers++] = mix;
756 }
757
758 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
759 {
760         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
761                 return;
762         spec->init_verbs[spec->num_init_verbs++] = verb;
763 }
764
765 /*
766  * set up from the preset table
767  */
768 static void setup_preset(struct alc_spec *spec,
769                          const struct alc_config_preset *preset)
770 {
771         int i;
772
773         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
774                 add_mixer(spec, preset->mixers[i]);
775         spec->cap_mixer = preset->cap_mixer;
776         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
777              i++)
778                 add_verb(spec, preset->init_verbs[i]);
779
780         spec->channel_mode = preset->channel_mode;
781         spec->num_channel_mode = preset->num_channel_mode;
782         spec->need_dac_fix = preset->need_dac_fix;
783
784         spec->multiout.max_channels = spec->channel_mode[0].channels;
785
786         spec->multiout.num_dacs = preset->num_dacs;
787         spec->multiout.dac_nids = preset->dac_nids;
788         spec->multiout.dig_out_nid = preset->dig_out_nid;
789         spec->multiout.hp_nid = preset->hp_nid;
790
791         spec->num_mux_defs = preset->num_mux_defs;
792         if (!spec->num_mux_defs)
793                 spec->num_mux_defs = 1;
794         spec->input_mux = preset->input_mux;
795
796         spec->num_adc_nids = preset->num_adc_nids;
797         spec->adc_nids = preset->adc_nids;
798         spec->capsrc_nids = preset->capsrc_nids;
799         spec->dig_in_nid = preset->dig_in_nid;
800
801         spec->unsol_event = preset->unsol_event;
802         spec->init_hook = preset->init_hook;
803 #ifdef CONFIG_SND_HDA_POWER_SAVE
804         spec->loopback.amplist = preset->loopbacks;
805 #endif
806 }
807
808 /* Enable GPIO mask and set output */
809 static struct hda_verb alc_gpio1_init_verbs[] = {
810         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
811         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
812         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
813         { }
814 };
815
816 static struct hda_verb alc_gpio2_init_verbs[] = {
817         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
818         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
819         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
820         { }
821 };
822
823 static struct hda_verb alc_gpio3_init_verbs[] = {
824         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
825         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
826         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
827         { }
828 };
829
830 /*
831  * Fix hardware PLL issue
832  * On some codecs, the analog PLL gating control must be off while
833  * the default value is 1.
834  */
835 static void alc_fix_pll(struct hda_codec *codec)
836 {
837         struct alc_spec *spec = codec->spec;
838         unsigned int val;
839
840         if (!spec->pll_nid)
841                 return;
842         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
843                             spec->pll_coef_idx);
844         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
845                                  AC_VERB_GET_PROC_COEF, 0);
846         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
847                             spec->pll_coef_idx);
848         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
849                             val & ~(1 << spec->pll_coef_bit));
850 }
851
852 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
853                              unsigned int coef_idx, unsigned int coef_bit)
854 {
855         struct alc_spec *spec = codec->spec;
856         spec->pll_nid = nid;
857         spec->pll_coef_idx = coef_idx;
858         spec->pll_coef_bit = coef_bit;
859         alc_fix_pll(codec);
860 }
861
862 static void alc_sku_automute(struct hda_codec *codec)
863 {
864         struct alc_spec *spec = codec->spec;
865         unsigned int present;
866         unsigned int hp_nid = spec->autocfg.hp_pins[0];
867         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
868
869         /* need to execute and sync at first */
870         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
871         present = snd_hda_codec_read(codec, hp_nid, 0,
872                                      AC_VERB_GET_PIN_SENSE, 0);
873         spec->jack_present = (present & 0x80000000) != 0;
874         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
875                             spec->jack_present ? 0 : PIN_OUT);
876 }
877
878 #if 0 /* it's broken in some acses -- temporarily disabled */
879 static void alc_mic_automute(struct hda_codec *codec)
880 {
881         struct alc_spec *spec = codec->spec;
882         unsigned int present;
883         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
884         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
885         unsigned int mix_nid = spec->capsrc_nids[0];
886         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
887
888         capsrc_idx_mic = mic_nid - 0x18;
889         capsrc_idx_fmic = fmic_nid - 0x18;
890         present = snd_hda_codec_read(codec, mic_nid, 0,
891                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
892         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
893                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
894         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
895                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
896         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
897                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
898 }
899 #else
900 #define alc_mic_automute(codec) /* NOP */
901 #endif /* disabled */
902
903 /* unsolicited event for HP jack sensing */
904 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
905 {
906         if (codec->vendor_id == 0x10ec0880)
907                 res >>= 28;
908         else
909                 res >>= 26;
910         if (res == ALC880_HP_EVENT)
911                 alc_sku_automute(codec);
912
913         if (res == ALC880_MIC_EVENT)
914                 alc_mic_automute(codec);
915 }
916
917 static void alc_inithook(struct hda_codec *codec)
918 {
919         alc_sku_automute(codec);
920         alc_mic_automute(codec);
921 }
922
923 /* additional initialization for ALC888 variants */
924 static void alc888_coef_init(struct hda_codec *codec)
925 {
926         unsigned int tmp;
927
928         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
929         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
930         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
931         if ((tmp & 0xf0) == 2)
932                 /* alc888S-VC */
933                 snd_hda_codec_read(codec, 0x20, 0,
934                                    AC_VERB_SET_PROC_COEF, 0x830);
935          else
936                  /* alc888-VB */
937                  snd_hda_codec_read(codec, 0x20, 0,
938                                     AC_VERB_SET_PROC_COEF, 0x3030);
939 }
940
941 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
942  *      31 ~ 16 :       Manufacture ID
943  *      15 ~ 8  :       SKU ID
944  *      7  ~ 0  :       Assembly ID
945  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
946  */
947 static void alc_subsystem_id(struct hda_codec *codec,
948                              unsigned int porta, unsigned int porte,
949                              unsigned int portd)
950 {
951         unsigned int ass, tmp, i;
952         unsigned nid;
953         struct alc_spec *spec = codec->spec;
954
955         ass = codec->subsystem_id & 0xffff;
956         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
957                 goto do_sku;
958
959         /*
960          * 31~30        : port conetcivity
961          * 29~21        : reserve
962          * 20           : PCBEEP input
963          * 19~16        : Check sum (15:1)
964          * 15~1         : Custom
965          * 0            : override
966         */
967         nid = 0x1d;
968         if (codec->vendor_id == 0x10ec0260)
969                 nid = 0x17;
970         ass = snd_hda_codec_read(codec, nid, 0,
971                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
972         if (!(ass & 1) && !(ass & 0x100000))
973                 return;
974         if ((ass >> 30) != 1)   /* no physical connection */
975                 return;
976
977         /* check sum */
978         tmp = 0;
979         for (i = 1; i < 16; i++) {
980                 if ((ass >> i) & 1)
981                         tmp++;
982         }
983         if (((ass >> 16) & 0xf) != tmp)
984                 return;
985 do_sku:
986         /*
987          * 0 : override
988          * 1 :  Swap Jack
989          * 2 : 0 --> Desktop, 1 --> Laptop
990          * 3~5 : External Amplifier control
991          * 7~6 : Reserved
992         */
993         tmp = (ass & 0x38) >> 3;        /* external Amp control */
994         switch (tmp) {
995         case 1:
996                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
997                 break;
998         case 3:
999                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1000                 break;
1001         case 7:
1002                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1003                 break;
1004         case 5: /* set EAPD output high */
1005                 switch (codec->vendor_id) {
1006                 case 0x10ec0260:
1007                         snd_hda_codec_write(codec, 0x0f, 0,
1008                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1009                         snd_hda_codec_write(codec, 0x10, 0,
1010                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1011                         break;
1012                 case 0x10ec0262:
1013                 case 0x10ec0267:
1014                 case 0x10ec0268:
1015                 case 0x10ec0269:
1016                 case 0x10ec0660:
1017                 case 0x10ec0662:
1018                 case 0x10ec0663:
1019                 case 0x10ec0862:
1020                 case 0x10ec0889:
1021                         snd_hda_codec_write(codec, 0x14, 0,
1022                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1023                         snd_hda_codec_write(codec, 0x15, 0,
1024                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1025                         break;
1026                 }
1027                 switch (codec->vendor_id) {
1028                 case 0x10ec0260:
1029                         snd_hda_codec_write(codec, 0x1a, 0,
1030                                             AC_VERB_SET_COEF_INDEX, 7);
1031                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1032                                                  AC_VERB_GET_PROC_COEF, 0);
1033                         snd_hda_codec_write(codec, 0x1a, 0,
1034                                             AC_VERB_SET_COEF_INDEX, 7);
1035                         snd_hda_codec_write(codec, 0x1a, 0,
1036                                             AC_VERB_SET_PROC_COEF,
1037                                             tmp | 0x2010);
1038                         break;
1039                 case 0x10ec0262:
1040                 case 0x10ec0880:
1041                 case 0x10ec0882:
1042                 case 0x10ec0883:
1043                 case 0x10ec0885:
1044                 case 0x10ec0889:
1045                         snd_hda_codec_write(codec, 0x20, 0,
1046                                             AC_VERB_SET_COEF_INDEX, 7);
1047                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1048                                                  AC_VERB_GET_PROC_COEF, 0);
1049                         snd_hda_codec_write(codec, 0x20, 0,
1050                                             AC_VERB_SET_COEF_INDEX, 7);
1051                         snd_hda_codec_write(codec, 0x20, 0,
1052                                             AC_VERB_SET_PROC_COEF,
1053                                             tmp | 0x2010);
1054                         break;
1055                 case 0x10ec0888:
1056                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1057                         break;
1058                 case 0x10ec0267:
1059                 case 0x10ec0268:
1060                         snd_hda_codec_write(codec, 0x20, 0,
1061                                             AC_VERB_SET_COEF_INDEX, 7);
1062                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1063                                                  AC_VERB_GET_PROC_COEF, 0);
1064                         snd_hda_codec_write(codec, 0x20, 0,
1065                                             AC_VERB_SET_COEF_INDEX, 7);
1066                         snd_hda_codec_write(codec, 0x20, 0,
1067                                             AC_VERB_SET_PROC_COEF,
1068                                             tmp | 0x3000);
1069                         break;
1070                 }
1071         default:
1072                 break;
1073         }
1074
1075         /* is laptop or Desktop and enable the function "Mute internal speaker
1076          * when the external headphone out jack is plugged"
1077          */
1078         if (!(ass & 0x8000))
1079                 return;
1080         /*
1081          * 10~8 : Jack location
1082          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1083          * 14~13: Resvered
1084          * 15   : 1 --> enable the function "Mute internal speaker
1085          *              when the external headphone out jack is plugged"
1086          */
1087         if (!spec->autocfg.speaker_pins[0]) {
1088                 if (spec->autocfg.line_out_pins[0])
1089                         spec->autocfg.speaker_pins[0] =
1090                                 spec->autocfg.line_out_pins[0];
1091                 else
1092                         return;
1093         }
1094
1095         if (!spec->autocfg.hp_pins[0]) {
1096                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1097                 if (tmp == 0)
1098                         spec->autocfg.hp_pins[0] = porta;
1099                 else if (tmp == 1)
1100                         spec->autocfg.hp_pins[0] = porte;
1101                 else if (tmp == 2)
1102                         spec->autocfg.hp_pins[0] = portd;
1103                 else
1104                         return;
1105         }
1106         if (spec->autocfg.hp_pins[0])
1107                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1108                         AC_VERB_SET_UNSOLICITED_ENABLE,
1109                         AC_USRSP_EN | ALC880_HP_EVENT);
1110
1111 #if 0 /* it's broken in some acses -- temporarily disabled */
1112         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1113                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1114                 snd_hda_codec_write(codec,
1115                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1116                         AC_VERB_SET_UNSOLICITED_ENABLE,
1117                         AC_USRSP_EN | ALC880_MIC_EVENT);
1118 #endif /* disabled */
1119
1120         spec->unsol_event = alc_sku_unsol_event;
1121 }
1122
1123 /*
1124  * Fix-up pin default configurations
1125  */
1126
1127 struct alc_pincfg {
1128         hda_nid_t nid;
1129         u32 val;
1130 };
1131
1132 static void alc_fix_pincfg(struct hda_codec *codec,
1133                            const struct snd_pci_quirk *quirk,
1134                            const struct alc_pincfg **pinfix)
1135 {
1136         const struct alc_pincfg *cfg;
1137
1138         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1139         if (!quirk)
1140                 return;
1141
1142         cfg = pinfix[quirk->value];
1143         for (; cfg->nid; cfg++) {
1144                 int i;
1145                 u32 val = cfg->val;
1146                 for (i = 0; i < 4; i++) {
1147                         snd_hda_codec_write(codec, cfg->nid, 0,
1148                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1149                                     val & 0xff);
1150                         val >>= 8;
1151                 }
1152         }
1153 }
1154
1155 /*
1156  * ALC880 3-stack model
1157  *
1158  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1159  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1160  *                 F-Mic = 0x1b, HP = 0x19
1161  */
1162
1163 static hda_nid_t alc880_dac_nids[4] = {
1164         /* front, rear, clfe, rear_surr */
1165         0x02, 0x05, 0x04, 0x03
1166 };
1167
1168 static hda_nid_t alc880_adc_nids[3] = {
1169         /* ADC0-2 */
1170         0x07, 0x08, 0x09,
1171 };
1172
1173 /* The datasheet says the node 0x07 is connected from inputs,
1174  * but it shows zero connection in the real implementation on some devices.
1175  * Note: this is a 915GAV bug, fixed on 915GLV
1176  */
1177 static hda_nid_t alc880_adc_nids_alt[2] = {
1178         /* ADC1-2 */
1179         0x08, 0x09,
1180 };
1181
1182 #define ALC880_DIGOUT_NID       0x06
1183 #define ALC880_DIGIN_NID        0x0a
1184
1185 static struct hda_input_mux alc880_capture_source = {
1186         .num_items = 4,
1187         .items = {
1188                 { "Mic", 0x0 },
1189                 { "Front Mic", 0x3 },
1190                 { "Line", 0x2 },
1191                 { "CD", 0x4 },
1192         },
1193 };
1194
1195 /* channel source setting (2/6 channel selection for 3-stack) */
1196 /* 2ch mode */
1197 static struct hda_verb alc880_threestack_ch2_init[] = {
1198         /* set line-in to input, mute it */
1199         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1200         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1201         /* set mic-in to input vref 80%, mute it */
1202         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1203         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1204         { } /* end */
1205 };
1206
1207 /* 6ch mode */
1208 static struct hda_verb alc880_threestack_ch6_init[] = {
1209         /* set line-in to output, unmute it */
1210         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1211         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1212         /* set mic-in to output, unmute it */
1213         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1214         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1215         { } /* end */
1216 };
1217
1218 static struct hda_channel_mode alc880_threestack_modes[2] = {
1219         { 2, alc880_threestack_ch2_init },
1220         { 6, alc880_threestack_ch6_init },
1221 };
1222
1223 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1224         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1225         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1226         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1227         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1228         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1229         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1230         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1231         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1232         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1233         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1234         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1235         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1236         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1237         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1238         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1239         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1240         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1241         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1242         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1243         {
1244                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1245                 .name = "Channel Mode",
1246                 .info = alc_ch_mode_info,
1247                 .get = alc_ch_mode_get,
1248                 .put = alc_ch_mode_put,
1249         },
1250         { } /* end */
1251 };
1252
1253 /* capture mixer elements */
1254 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1255                             struct snd_ctl_elem_info *uinfo)
1256 {
1257         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1258         struct alc_spec *spec = codec->spec;
1259         int err;
1260
1261         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1262         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1263                                                       HDA_INPUT);
1264         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1265         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1266         return err;
1267 }
1268
1269 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1270                            unsigned int size, unsigned int __user *tlv)
1271 {
1272         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1273         struct alc_spec *spec = codec->spec;
1274         int err;
1275
1276         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1277         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1278                                                       HDA_INPUT);
1279         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1280         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1281         return err;
1282 }
1283
1284 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1285                              struct snd_ctl_elem_value *ucontrol);
1286
1287 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1288                                  struct snd_ctl_elem_value *ucontrol,
1289                                  getput_call_t func)
1290 {
1291         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1292         struct alc_spec *spec = codec->spec;
1293         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1294         int err;
1295
1296         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1297         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1298                                                       3, 0, HDA_INPUT);
1299         err = func(kcontrol, ucontrol);
1300         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1301         return err;
1302 }
1303
1304 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1305                            struct snd_ctl_elem_value *ucontrol)
1306 {
1307         return alc_cap_getput_caller(kcontrol, ucontrol,
1308                                      snd_hda_mixer_amp_volume_get);
1309 }
1310
1311 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1312                            struct snd_ctl_elem_value *ucontrol)
1313 {
1314         return alc_cap_getput_caller(kcontrol, ucontrol,
1315                                      snd_hda_mixer_amp_volume_put);
1316 }
1317
1318 /* capture mixer elements */
1319 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1320
1321 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1322                           struct snd_ctl_elem_value *ucontrol)
1323 {
1324         return alc_cap_getput_caller(kcontrol, ucontrol,
1325                                      snd_hda_mixer_amp_switch_get);
1326 }
1327
1328 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1329                           struct snd_ctl_elem_value *ucontrol)
1330 {
1331         return alc_cap_getput_caller(kcontrol, ucontrol,
1332                                      snd_hda_mixer_amp_switch_put);
1333 }
1334
1335 #define DEFINE_CAPMIX(num) \
1336 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1337         { \
1338                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1339                 .name = "Capture Switch", \
1340                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1341                 .count = num, \
1342                 .info = alc_cap_sw_info, \
1343                 .get = alc_cap_sw_get, \
1344                 .put = alc_cap_sw_put, \
1345         }, \
1346         { \
1347                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1348                 .name = "Capture Volume", \
1349                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1350                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1351                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1352                 .count = num, \
1353                 .info = alc_cap_vol_info, \
1354                 .get = alc_cap_vol_get, \
1355                 .put = alc_cap_vol_put, \
1356                 .tlv = { .c = alc_cap_vol_tlv }, \
1357         }, \
1358         { \
1359                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1360                 /* .name = "Capture Source", */ \
1361                 .name = "Input Source", \
1362                 .count = num, \
1363                 .info = alc_mux_enum_info, \
1364                 .get = alc_mux_enum_get, \
1365                 .put = alc_mux_enum_put, \
1366         }, \
1367         { } /* end */ \
1368 }
1369
1370 /* up to three ADCs */
1371 DEFINE_CAPMIX(1);
1372 DEFINE_CAPMIX(2);
1373 DEFINE_CAPMIX(3);
1374
1375
1376 /*
1377  * ALC880 5-stack model
1378  *
1379  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1380  *      Side = 0x02 (0xd)
1381  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1382  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1383  */
1384
1385 /* additional mixers to alc880_three_stack_mixer */
1386 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1387         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1388         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1389         { } /* end */
1390 };
1391
1392 /* channel source setting (6/8 channel selection for 5-stack) */
1393 /* 6ch mode */
1394 static struct hda_verb alc880_fivestack_ch6_init[] = {
1395         /* set line-in to input, mute it */
1396         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1397         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1398         { } /* end */
1399 };
1400
1401 /* 8ch mode */
1402 static struct hda_verb alc880_fivestack_ch8_init[] = {
1403         /* set line-in to output, unmute it */
1404         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1405         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1406         { } /* end */
1407 };
1408
1409 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1410         { 6, alc880_fivestack_ch6_init },
1411         { 8, alc880_fivestack_ch8_init },
1412 };
1413
1414
1415 /*
1416  * ALC880 6-stack model
1417  *
1418  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1419  *      Side = 0x05 (0x0f)
1420  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1421  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1422  */
1423
1424 static hda_nid_t alc880_6st_dac_nids[4] = {
1425         /* front, rear, clfe, rear_surr */
1426         0x02, 0x03, 0x04, 0x05
1427 };
1428
1429 static struct hda_input_mux alc880_6stack_capture_source = {
1430         .num_items = 4,
1431         .items = {
1432                 { "Mic", 0x0 },
1433                 { "Front Mic", 0x1 },
1434                 { "Line", 0x2 },
1435                 { "CD", 0x4 },
1436         },
1437 };
1438
1439 /* fixed 8-channels */
1440 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1441         { 8, NULL },
1442 };
1443
1444 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1445         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1446         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1447         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1448         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1449         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1450         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1451         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1452         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1453         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1454         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1455         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1456         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1457         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1458         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1459         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1460         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1461         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1462         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1463         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1464         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1465         {
1466                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1467                 .name = "Channel Mode",
1468                 .info = alc_ch_mode_info,
1469                 .get = alc_ch_mode_get,
1470                 .put = alc_ch_mode_put,
1471         },
1472         { } /* end */
1473 };
1474
1475
1476 /*
1477  * ALC880 W810 model
1478  *
1479  * W810 has rear IO for:
1480  * Front (DAC 02)
1481  * Surround (DAC 03)
1482  * Center/LFE (DAC 04)
1483  * Digital out (06)
1484  *
1485  * The system also has a pair of internal speakers, and a headphone jack.
1486  * These are both connected to Line2 on the codec, hence to DAC 02.
1487  *
1488  * There is a variable resistor to control the speaker or headphone
1489  * volume. This is a hardware-only device without a software API.
1490  *
1491  * Plugging headphones in will disable the internal speakers. This is
1492  * implemented in hardware, not via the driver using jack sense. In
1493  * a similar fashion, plugging into the rear socket marked "front" will
1494  * disable both the speakers and headphones.
1495  *
1496  * For input, there's a microphone jack, and an "audio in" jack.
1497  * These may not do anything useful with this driver yet, because I
1498  * haven't setup any initialization verbs for these yet...
1499  */
1500
1501 static hda_nid_t alc880_w810_dac_nids[3] = {
1502         /* front, rear/surround, clfe */
1503         0x02, 0x03, 0x04
1504 };
1505
1506 /* fixed 6 channels */
1507 static struct hda_channel_mode alc880_w810_modes[1] = {
1508         { 6, NULL }
1509 };
1510
1511 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1512 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1513         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1514         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1515         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1516         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1517         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1518         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1519         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1520         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1521         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1522         { } /* end */
1523 };
1524
1525
1526 /*
1527  * Z710V model
1528  *
1529  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1530  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1531  *                 Line = 0x1a
1532  */
1533
1534 static hda_nid_t alc880_z71v_dac_nids[1] = {
1535         0x02
1536 };
1537 #define ALC880_Z71V_HP_DAC      0x03
1538
1539 /* fixed 2 channels */
1540 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1541         { 2, NULL }
1542 };
1543
1544 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1545         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1546         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1547         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1548         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1549         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1550         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1551         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1552         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1553         { } /* end */
1554 };
1555
1556
1557 /*
1558  * ALC880 F1734 model
1559  *
1560  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1561  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1562  */
1563
1564 static hda_nid_t alc880_f1734_dac_nids[1] = {
1565         0x03
1566 };
1567 #define ALC880_F1734_HP_DAC     0x02
1568
1569 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1570         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1571         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1572         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1573         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1574         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1575         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1576         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1577         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1578         { } /* end */
1579 };
1580
1581 static struct hda_input_mux alc880_f1734_capture_source = {
1582         .num_items = 2,
1583         .items = {
1584                 { "Mic", 0x1 },
1585                 { "CD", 0x4 },
1586         },
1587 };
1588
1589
1590 /*
1591  * ALC880 ASUS model
1592  *
1593  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1594  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1595  *  Mic = 0x18, Line = 0x1a
1596  */
1597
1598 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1599 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1600
1601 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1602         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1603         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1604         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1605         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1606         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1607         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1608         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1609         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1610         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1611         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1612         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1613         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1614         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1615         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1616         {
1617                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1618                 .name = "Channel Mode",
1619                 .info = alc_ch_mode_info,
1620                 .get = alc_ch_mode_get,
1621                 .put = alc_ch_mode_put,
1622         },
1623         { } /* end */
1624 };
1625
1626 /*
1627  * ALC880 ASUS W1V model
1628  *
1629  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1630  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1631  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1632  */
1633
1634 /* additional mixers to alc880_asus_mixer */
1635 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1636         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1637         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1638         { } /* end */
1639 };
1640
1641 /* additional mixers to alc880_asus_mixer */
1642 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1643         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1644         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1645         { } /* end */
1646 };
1647
1648 /* TCL S700 */
1649 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1650         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1651         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1652         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1653         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1654         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1655         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1656         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1657         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1658         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1659         { } /* end */
1660 };
1661
1662 /* Uniwill */
1663 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1664         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1665         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1666         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1667         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1668         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1669         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1670         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1671         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1672         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1673         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1674         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1675         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1676         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1677         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1678         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1679         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1680         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1681         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1682         {
1683                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1684                 .name = "Channel Mode",
1685                 .info = alc_ch_mode_info,
1686                 .get = alc_ch_mode_get,
1687                 .put = alc_ch_mode_put,
1688         },
1689         { } /* end */
1690 };
1691
1692 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1693         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1694         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1695         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1696         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1697         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1698         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1699         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1700         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1701         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1702         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1703         { } /* end */
1704 };
1705
1706 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1707         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1708         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1709         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1710         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1711         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1712         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1713         { } /* end */
1714 };
1715
1716 /*
1717  * virtual master controls
1718  */
1719
1720 /*
1721  * slave controls for virtual master
1722  */
1723 static const char *alc_slave_vols[] = {
1724         "Front Playback Volume",
1725         "Surround Playback Volume",
1726         "Center Playback Volume",
1727         "LFE Playback Volume",
1728         "Side Playback Volume",
1729         "Headphone Playback Volume",
1730         "Speaker Playback Volume",
1731         "Mono Playback Volume",
1732         "Line-Out Playback Volume",
1733         "PCM Playback Volume",
1734         NULL,
1735 };
1736
1737 static const char *alc_slave_sws[] = {
1738         "Front Playback Switch",
1739         "Surround Playback Switch",
1740         "Center Playback Switch",
1741         "LFE Playback Switch",
1742         "Side Playback Switch",
1743         "Headphone Playback Switch",
1744         "Speaker Playback Switch",
1745         "Mono Playback Switch",
1746         "IEC958 Playback Switch",
1747         NULL,
1748 };
1749
1750 /*
1751  * build control elements
1752  */
1753
1754 static void alc_free_kctls(struct hda_codec *codec);
1755
1756 static int alc_build_controls(struct hda_codec *codec)
1757 {
1758         struct alc_spec *spec = codec->spec;
1759         int err;
1760         int i;
1761
1762         for (i = 0; i < spec->num_mixers; i++) {
1763                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1764                 if (err < 0)
1765                         return err;
1766         }
1767         if (spec->cap_mixer) {
1768                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1769                 if (err < 0)
1770                         return err;
1771         }
1772         if (spec->multiout.dig_out_nid) {
1773                 err = snd_hda_create_spdif_out_ctls(codec,
1774                                                     spec->multiout.dig_out_nid);
1775                 if (err < 0)
1776                         return err;
1777                 err = snd_hda_create_spdif_share_sw(codec,
1778                                                     &spec->multiout);
1779                 if (err < 0)
1780                         return err;
1781                 spec->multiout.share_spdif = 1;
1782         }
1783         if (spec->dig_in_nid) {
1784                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1785                 if (err < 0)
1786                         return err;
1787         }
1788
1789         /* if we have no master control, let's create it */
1790         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1791                 unsigned int vmaster_tlv[4];
1792                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1793                                         HDA_OUTPUT, vmaster_tlv);
1794                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1795                                           vmaster_tlv, alc_slave_vols);
1796                 if (err < 0)
1797                         return err;
1798         }
1799         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1800                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1801                                           NULL, alc_slave_sws);
1802                 if (err < 0)
1803                         return err;
1804         }
1805
1806         alc_free_kctls(codec); /* no longer needed */
1807         return 0;
1808 }
1809
1810
1811 /*
1812  * initialize the codec volumes, etc
1813  */
1814
1815 /*
1816  * generic initialization of ADC, input mixers and output mixers
1817  */
1818 static struct hda_verb alc880_volume_init_verbs[] = {
1819         /*
1820          * Unmute ADC0-2 and set the default input to mic-in
1821          */
1822         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1823         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1824         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1825         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1826         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1827         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1828
1829         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1830          * mixer widget
1831          * Note: PASD motherboards uses the Line In 2 as the input for front
1832          * panel mic (mic 2)
1833          */
1834         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1835         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1836         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1837         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1838         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1839         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1840         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1841         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1842
1843         /*
1844          * Set up output mixers (0x0c - 0x0f)
1845          */
1846         /* set vol=0 to output mixers */
1847         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1848         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1849         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1850         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1851         /* set up input amps for analog loopback */
1852         /* Amp Indices: DAC = 0, mixer = 1 */
1853         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1854         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1855         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1856         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1857         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1858         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1859         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1860         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1861
1862         { }
1863 };
1864
1865 /*
1866  * 3-stack pin configuration:
1867  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1868  */
1869 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1870         /*
1871          * preset connection lists of input pins
1872          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1873          */
1874         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1875         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1876         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1877
1878         /*
1879          * Set pin mode and muting
1880          */
1881         /* set front pin widgets 0x14 for output */
1882         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1883         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1884         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1885         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1886         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1887         /* Mic2 (as headphone out) for HP output */
1888         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1889         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1890         /* Line In pin widget for input */
1891         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1892         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1893         /* Line2 (as front mic) pin widget for input and vref at 80% */
1894         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1895         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1896         /* CD pin widget for input */
1897         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1898
1899         { }
1900 };
1901
1902 /*
1903  * 5-stack pin configuration:
1904  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1905  * line-in/side = 0x1a, f-mic = 0x1b
1906  */
1907 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1908         /*
1909          * preset connection lists of input pins
1910          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1911          */
1912         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1913         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1914
1915         /*
1916          * Set pin mode and muting
1917          */
1918         /* set pin widgets 0x14-0x17 for output */
1919         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1920         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1921         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1922         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1923         /* unmute pins for output (no gain on this amp) */
1924         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1925         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1926         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1927         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1928
1929         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1930         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1931         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1932         /* Mic2 (as headphone out) for HP output */
1933         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1934         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1935         /* Line In pin widget for input */
1936         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1937         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1938         /* Line2 (as front mic) pin widget for input and vref at 80% */
1939         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1940         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1941         /* CD pin widget for input */
1942         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1943
1944         { }
1945 };
1946
1947 /*
1948  * W810 pin configuration:
1949  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1950  */
1951 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1952         /* hphone/speaker input selector: front DAC */
1953         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1954
1955         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1956         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1957         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1958         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1959         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1960         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1961
1962         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1963         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1964
1965         { }
1966 };
1967
1968 /*
1969  * Z71V pin configuration:
1970  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1971  */
1972 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1973         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1974         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1975         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1976         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1977
1978         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1979         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1980         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1981         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1982
1983         { }
1984 };
1985
1986 /*
1987  * 6-stack pin configuration:
1988  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1989  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1990  */
1991 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1992         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1993
1994         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1995         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1996         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1997         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1998         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1999         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2000         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2001         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2002
2003         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2004         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2005         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2006         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2007         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2008         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2009         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2010         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2011         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2012
2013         { }
2014 };
2015
2016 /*
2017  * Uniwill pin configuration:
2018  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2019  * line = 0x1a
2020  */
2021 static struct hda_verb alc880_uniwill_init_verbs[] = {
2022         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2023
2024         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2025         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2026         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2027         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2028         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2029         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2030         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2031         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2032         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2033         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2034         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2035         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2036         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2037         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2038
2039         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2040         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2041         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2042         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2043         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2044         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2045         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2046         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2047         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2048
2049         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2050         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2051
2052         { }
2053 };
2054
2055 /*
2056 * Uniwill P53
2057 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2058  */
2059 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2060         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2061
2062         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2063         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2064         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2065         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2066         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2067         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2068         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2069         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2070         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2071         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2072         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2073         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2074
2075         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2076         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2077         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2078         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2079         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2080         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2081
2082         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2083         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2084
2085         { }
2086 };
2087
2088 static struct hda_verb alc880_beep_init_verbs[] = {
2089         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2090         { }
2091 };
2092
2093 /* toggle speaker-output according to the hp-jack state */
2094 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
2095 {
2096         unsigned int present;
2097         unsigned char bits;
2098
2099         present = snd_hda_codec_read(codec, 0x14, 0,
2100                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2101         bits = present ? HDA_AMP_MUTE : 0;
2102         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
2103                                  HDA_AMP_MUTE, bits);
2104         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
2105                                  HDA_AMP_MUTE, bits);
2106 }
2107
2108 /* auto-toggle front mic */
2109 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2110 {
2111         unsigned int present;
2112         unsigned char bits;
2113
2114         present = snd_hda_codec_read(codec, 0x18, 0,
2115                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2116         bits = present ? HDA_AMP_MUTE : 0;
2117         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2118 }
2119
2120 static void alc880_uniwill_automute(struct hda_codec *codec)
2121 {
2122         alc880_uniwill_hp_automute(codec);
2123         alc880_uniwill_mic_automute(codec);
2124 }
2125
2126 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2127                                        unsigned int res)
2128 {
2129         /* Looks like the unsol event is incompatible with the standard
2130          * definition.  4bit tag is placed at 28 bit!
2131          */
2132         switch (res >> 28) {
2133         case ALC880_HP_EVENT:
2134                 alc880_uniwill_hp_automute(codec);
2135                 break;
2136         case ALC880_MIC_EVENT:
2137                 alc880_uniwill_mic_automute(codec);
2138                 break;
2139         }
2140 }
2141
2142 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2143 {
2144         unsigned int present;
2145         unsigned char bits;
2146
2147         present = snd_hda_codec_read(codec, 0x14, 0,
2148                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2149         bits = present ? HDA_AMP_MUTE : 0;
2150         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2151 }
2152
2153 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2154 {
2155         unsigned int present;
2156
2157         present = snd_hda_codec_read(codec, 0x21, 0,
2158                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2159         present &= HDA_AMP_VOLMASK;
2160         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2161                                  HDA_AMP_VOLMASK, present);
2162         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2163                                  HDA_AMP_VOLMASK, present);
2164 }
2165
2166 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2167                                            unsigned int res)
2168 {
2169         /* Looks like the unsol event is incompatible with the standard
2170          * definition.  4bit tag is placed at 28 bit!
2171          */
2172         if ((res >> 28) == ALC880_HP_EVENT)
2173                 alc880_uniwill_p53_hp_automute(codec);
2174         if ((res >> 28) == ALC880_DCVOL_EVENT)
2175                 alc880_uniwill_p53_dcvol_automute(codec);
2176 }
2177
2178 /*
2179  * F1734 pin configuration:
2180  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2181  */
2182 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2183         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2184         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2185         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2186         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2187         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2188
2189         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2190         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2191         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2192         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2193
2194         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2195         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2196         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2197         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2198         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2199         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2200         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2201         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2202         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2203
2204         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2205         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2206
2207         { }
2208 };
2209
2210 /*
2211  * ASUS pin configuration:
2212  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2213  */
2214 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2215         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2216         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2217         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2218         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2219
2220         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2221         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2222         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2223         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2224         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2225         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2226         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2227         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2228
2229         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2230         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2231         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2232         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2233         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2234         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2235         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2236         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2237         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2238
2239         { }
2240 };
2241
2242 /* Enable GPIO mask and set output */
2243 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2244 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2245
2246 /* Clevo m520g init */
2247 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2248         /* headphone output */
2249         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2250         /* line-out */
2251         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2252         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2253         /* Line-in */
2254         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2255         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2256         /* CD */
2257         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2258         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2259         /* Mic1 (rear panel) */
2260         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2261         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2262         /* Mic2 (front panel) */
2263         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2264         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2265         /* headphone */
2266         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2267         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2268         /* change to EAPD mode */
2269         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2270         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2271
2272         { }
2273 };
2274
2275 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2276         /* change to EAPD mode */
2277         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2278         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2279
2280         /* Headphone output */
2281         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2282         /* Front output*/
2283         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2284         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2285
2286         /* Line In pin widget for input */
2287         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2288         /* CD pin widget for input */
2289         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2290         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2291         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2292
2293         /* change to EAPD mode */
2294         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2295         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2296
2297         { }
2298 };
2299
2300 /*
2301  * LG m1 express dual
2302  *
2303  * Pin assignment:
2304  *   Rear Line-In/Out (blue): 0x14
2305  *   Build-in Mic-In: 0x15
2306  *   Speaker-out: 0x17
2307  *   HP-Out (green): 0x1b
2308  *   Mic-In/Out (red): 0x19
2309  *   SPDIF-Out: 0x1e
2310  */
2311
2312 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2313 static hda_nid_t alc880_lg_dac_nids[3] = {
2314         0x05, 0x02, 0x03
2315 };
2316
2317 /* seems analog CD is not working */
2318 static struct hda_input_mux alc880_lg_capture_source = {
2319         .num_items = 3,
2320         .items = {
2321                 { "Mic", 0x1 },
2322                 { "Line", 0x5 },
2323                 { "Internal Mic", 0x6 },
2324         },
2325 };
2326
2327 /* 2,4,6 channel modes */
2328 static struct hda_verb alc880_lg_ch2_init[] = {
2329         /* set line-in and mic-in to input */
2330         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2331         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2332         { }
2333 };
2334
2335 static struct hda_verb alc880_lg_ch4_init[] = {
2336         /* set line-in to out and mic-in to input */
2337         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2338         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2339         { }
2340 };
2341
2342 static struct hda_verb alc880_lg_ch6_init[] = {
2343         /* set line-in and mic-in to output */
2344         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2345         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2346         { }
2347 };
2348
2349 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2350         { 2, alc880_lg_ch2_init },
2351         { 4, alc880_lg_ch4_init },
2352         { 6, alc880_lg_ch6_init },
2353 };
2354
2355 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2356         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2357         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2358         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2359         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2360         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2361         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2362         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2363         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2364         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2365         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2366         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2367         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2368         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2369         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2370         {
2371                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2372                 .name = "Channel Mode",
2373                 .info = alc_ch_mode_info,
2374                 .get = alc_ch_mode_get,
2375                 .put = alc_ch_mode_put,
2376         },
2377         { } /* end */
2378 };
2379
2380 static struct hda_verb alc880_lg_init_verbs[] = {
2381         /* set capture source to mic-in */
2382         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2383         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2384         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2385         /* mute all amp mixer inputs */
2386         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2387         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2388         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2389         /* line-in to input */
2390         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2391         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2392         /* built-in mic */
2393         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2394         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2395         /* speaker-out */
2396         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2397         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2398         /* mic-in to input */
2399         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2400         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2401         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2402         /* HP-out */
2403         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2404         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2405         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2406         /* jack sense */
2407         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2408         { }
2409 };
2410
2411 /* toggle speaker-output according to the hp-jack state */
2412 static void alc880_lg_automute(struct hda_codec *codec)
2413 {
2414         unsigned int present;
2415         unsigned char bits;
2416
2417         present = snd_hda_codec_read(codec, 0x1b, 0,
2418                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2419         bits = present ? HDA_AMP_MUTE : 0;
2420         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2421                                  HDA_AMP_MUTE, bits);
2422 }
2423
2424 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2425 {
2426         /* Looks like the unsol event is incompatible with the standard
2427          * definition.  4bit tag is placed at 28 bit!
2428          */
2429         if ((res >> 28) == 0x01)
2430                 alc880_lg_automute(codec);
2431 }
2432
2433 /*
2434  * LG LW20
2435  *
2436  * Pin assignment:
2437  *   Speaker-out: 0x14
2438  *   Mic-In: 0x18
2439  *   Built-in Mic-In: 0x19
2440  *   Line-In: 0x1b
2441  *   HP-Out: 0x1a
2442  *   SPDIF-Out: 0x1e
2443  */
2444
2445 static struct hda_input_mux alc880_lg_lw_capture_source = {
2446         .num_items = 3,
2447         .items = {
2448                 { "Mic", 0x0 },
2449                 { "Internal Mic", 0x1 },
2450                 { "Line In", 0x2 },
2451         },
2452 };
2453
2454 #define alc880_lg_lw_modes alc880_threestack_modes
2455
2456 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2457         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2458         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2459         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2460         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2461         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2462         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2463         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2464         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2465         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2466         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2467         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2468         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2469         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2470         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2471         {
2472                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2473                 .name = "Channel Mode",
2474                 .info = alc_ch_mode_info,
2475                 .get = alc_ch_mode_get,
2476                 .put = alc_ch_mode_put,
2477         },
2478         { } /* end */
2479 };
2480
2481 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2482         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2483         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2484         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2485
2486         /* set capture source to mic-in */
2487         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2488         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2489         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2490         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2491         /* speaker-out */
2492         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2493         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2494         /* HP-out */
2495         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2496         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2497         /* mic-in to input */
2498         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2499         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2500         /* built-in mic */
2501         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2502         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2503         /* jack sense */
2504         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2505         { }
2506 };
2507
2508 /* toggle speaker-output according to the hp-jack state */
2509 static void alc880_lg_lw_automute(struct hda_codec *codec)
2510 {
2511         unsigned int present;
2512         unsigned char bits;
2513
2514         present = snd_hda_codec_read(codec, 0x1b, 0,
2515                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2516         bits = present ? HDA_AMP_MUTE : 0;
2517         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2518                                  HDA_AMP_MUTE, bits);
2519 }
2520
2521 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2522 {
2523         /* Looks like the unsol event is incompatible with the standard
2524          * definition.  4bit tag is placed at 28 bit!
2525          */
2526         if ((res >> 28) == 0x01)
2527                 alc880_lg_lw_automute(codec);
2528 }
2529
2530 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2531         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2532         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2533         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2534         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2535         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2536         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2537         { } /* end */
2538 };
2539
2540 static struct hda_input_mux alc880_medion_rim_capture_source = {
2541         .num_items = 2,
2542         .items = {
2543                 { "Mic", 0x0 },
2544                 { "Internal Mic", 0x1 },
2545         },
2546 };
2547
2548 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2549         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2550
2551         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2552         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2553
2554         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2555         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2556         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2557         /* Mic2 (as headphone out) for HP output */
2558         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2559         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2560         /* Internal Speaker */
2561         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2562         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2563
2564         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2565         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2566
2567         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2568         { }
2569 };
2570
2571 /* toggle speaker-output according to the hp-jack state */
2572 static void alc880_medion_rim_automute(struct hda_codec *codec)
2573 {
2574         unsigned int present;
2575         unsigned char bits;
2576
2577         present = snd_hda_codec_read(codec, 0x14, 0,
2578                                      AC_VERB_GET_PIN_SENSE, 0)
2579                 & AC_PINSENSE_PRESENCE;
2580         bits = present ? HDA_AMP_MUTE : 0;
2581         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2582                                  HDA_AMP_MUTE, bits);
2583         if (present)
2584                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2585         else
2586                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2587 }
2588
2589 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2590                                           unsigned int res)
2591 {
2592         /* Looks like the unsol event is incompatible with the standard
2593          * definition.  4bit tag is placed at 28 bit!
2594          */
2595         if ((res >> 28) == ALC880_HP_EVENT)
2596                 alc880_medion_rim_automute(codec);
2597 }
2598
2599 #ifdef CONFIG_SND_HDA_POWER_SAVE
2600 static struct hda_amp_list alc880_loopbacks[] = {
2601         { 0x0b, HDA_INPUT, 0 },
2602         { 0x0b, HDA_INPUT, 1 },
2603         { 0x0b, HDA_INPUT, 2 },
2604         { 0x0b, HDA_INPUT, 3 },
2605         { 0x0b, HDA_INPUT, 4 },
2606         { } /* end */
2607 };
2608
2609 static struct hda_amp_list alc880_lg_loopbacks[] = {
2610         { 0x0b, HDA_INPUT, 1 },
2611         { 0x0b, HDA_INPUT, 6 },
2612         { 0x0b, HDA_INPUT, 7 },
2613         { } /* end */
2614 };
2615 #endif
2616
2617 /*
2618  * Common callbacks
2619  */
2620
2621 static int alc_init(struct hda_codec *codec)
2622 {
2623         struct alc_spec *spec = codec->spec;
2624         unsigned int i;
2625
2626         alc_fix_pll(codec);
2627         if (codec->vendor_id == 0x10ec0888)
2628                 alc888_coef_init(codec);
2629
2630         for (i = 0; i < spec->num_init_verbs; i++)
2631                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2632
2633         if (spec->init_hook)
2634                 spec->init_hook(codec);
2635
2636         return 0;
2637 }
2638
2639 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2640 {
2641         struct alc_spec *spec = codec->spec;
2642
2643         if (spec->unsol_event)
2644                 spec->unsol_event(codec, res);
2645 }
2646
2647 #ifdef CONFIG_SND_HDA_POWER_SAVE
2648 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2649 {
2650         struct alc_spec *spec = codec->spec;
2651         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2652 }
2653 #endif
2654
2655 /*
2656  * Analog playback callbacks
2657  */
2658 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2659                                     struct hda_codec *codec,
2660                                     struct snd_pcm_substream *substream)
2661 {
2662         struct alc_spec *spec = codec->spec;
2663         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2664                                              hinfo);
2665 }
2666
2667 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2668                                        struct hda_codec *codec,
2669                                        unsigned int stream_tag,
2670                                        unsigned int format,
2671                                        struct snd_pcm_substream *substream)
2672 {
2673         struct alc_spec *spec = codec->spec;
2674         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2675                                                 stream_tag, format, substream);
2676 }
2677
2678 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2679                                        struct hda_codec *codec,
2680                                        struct snd_pcm_substream *substream)
2681 {
2682         struct alc_spec *spec = codec->spec;
2683         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2684 }
2685
2686 /*
2687  * Digital out
2688  */
2689 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2690                                         struct hda_codec *codec,
2691                                         struct snd_pcm_substream *substream)
2692 {
2693         struct alc_spec *spec = codec->spec;
2694         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2695 }
2696
2697 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2698                                            struct hda_codec *codec,
2699                                            unsigned int stream_tag,
2700                                            unsigned int format,
2701                                            struct snd_pcm_substream *substream)
2702 {
2703         struct alc_spec *spec = codec->spec;
2704         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2705                                              stream_tag, format, substream);
2706 }
2707
2708 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2709                                          struct hda_codec *codec,
2710                                          struct snd_pcm_substream *substream)
2711 {
2712         struct alc_spec *spec = codec->spec;
2713         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2714 }
2715
2716 /*
2717  * Analog capture
2718  */
2719 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2720                                       struct hda_codec *codec,
2721                                       unsigned int stream_tag,
2722                                       unsigned int format,
2723                                       struct snd_pcm_substream *substream)
2724 {
2725         struct alc_spec *spec = codec->spec;
2726
2727         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2728                                    stream_tag, 0, format);
2729         return 0;
2730 }
2731
2732 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2733                                       struct hda_codec *codec,
2734                                       struct snd_pcm_substream *substream)
2735 {
2736         struct alc_spec *spec = codec->spec;
2737
2738         snd_hda_codec_cleanup_stream(codec,
2739                                      spec->adc_nids[substream->number + 1]);
2740         return 0;
2741 }
2742
2743
2744 /*
2745  */
2746 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2747         .substreams = 1,
2748         .channels_min = 2,
2749         .channels_max = 8,
2750         /* NID is set in alc_build_pcms */
2751         .ops = {
2752                 .open = alc880_playback_pcm_open,
2753                 .prepare = alc880_playback_pcm_prepare,
2754                 .cleanup = alc880_playback_pcm_cleanup
2755         },
2756 };
2757
2758 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2759         .substreams = 1,
2760         .channels_min = 2,
2761         .channels_max = 2,
2762         /* NID is set in alc_build_pcms */
2763 };
2764
2765 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
2766         .substreams = 1,
2767         .channels_min = 2,
2768         .channels_max = 2,
2769         /* NID is set in alc_build_pcms */
2770 };
2771
2772 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2773         .substreams = 2, /* can be overridden */
2774         .channels_min = 2,
2775         .channels_max = 2,
2776         /* NID is set in alc_build_pcms */
2777         .ops = {
2778                 .prepare = alc880_alt_capture_pcm_prepare,
2779                 .cleanup = alc880_alt_capture_pcm_cleanup
2780         },
2781 };
2782
2783 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2784         .substreams = 1,
2785         .channels_min = 2,
2786         .channels_max = 2,
2787         /* NID is set in alc_build_pcms */
2788         .ops = {
2789                 .open = alc880_dig_playback_pcm_open,
2790                 .close = alc880_dig_playback_pcm_close,
2791                 .prepare = alc880_dig_playback_pcm_prepare
2792         },
2793 };
2794
2795 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2796         .substreams = 1,
2797         .channels_min = 2,
2798         .channels_max = 2,
2799         /* NID is set in alc_build_pcms */
2800 };
2801
2802 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2803 static struct hda_pcm_stream alc_pcm_null_stream = {
2804         .substreams = 0,
2805         .channels_min = 0,
2806         .channels_max = 0,
2807 };
2808
2809 static int alc_build_pcms(struct hda_codec *codec)
2810 {
2811         struct alc_spec *spec = codec->spec;
2812         struct hda_pcm *info = spec->pcm_rec;
2813         int i;
2814
2815         codec->num_pcms = 1;
2816         codec->pcm_info = info;
2817
2818         info->name = spec->stream_name_analog;
2819         if (spec->stream_analog_playback) {
2820                 if (snd_BUG_ON(!spec->multiout.dac_nids))
2821                         return -EINVAL;
2822                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2823                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2824         }
2825         if (spec->stream_analog_capture) {
2826                 if (snd_BUG_ON(!spec->adc_nids))
2827                         return -EINVAL;
2828                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2829                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2830         }
2831
2832         if (spec->channel_mode) {
2833                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2834                 for (i = 0; i < spec->num_channel_mode; i++) {
2835                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2836                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2837                         }
2838                 }
2839         }
2840
2841         /* SPDIF for stream index #1 */
2842         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2843                 codec->num_pcms = 2;
2844                 info = spec->pcm_rec + 1;
2845                 info->name = spec->stream_name_digital;
2846                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2847                 if (spec->multiout.dig_out_nid &&
2848                     spec->stream_digital_playback) {
2849                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2850                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2851                 }
2852                 if (spec->dig_in_nid &&
2853                     spec->stream_digital_capture) {
2854                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2855                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2856                 }
2857                 /* FIXME: do we need this for all Realtek codec models? */
2858                 codec->spdif_status_reset = 1;
2859         }
2860
2861         /* If the use of more than one ADC is requested for the current
2862          * model, configure a second analog capture-only PCM.
2863          */
2864         /* Additional Analaog capture for index #2 */
2865         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
2866             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
2867                 codec->num_pcms = 3;
2868                 info = spec->pcm_rec + 2;
2869                 info->name = spec->stream_name_analog;
2870                 if (spec->alt_dac_nid) {
2871                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2872                                 *spec->stream_analog_alt_playback;
2873                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2874                                 spec->alt_dac_nid;
2875                 } else {
2876                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2877                                 alc_pcm_null_stream;
2878                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2879                 }
2880                 if (spec->num_adc_nids > 1) {
2881                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2882                                 *spec->stream_analog_alt_capture;
2883                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2884                                 spec->adc_nids[1];
2885                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2886                                 spec->num_adc_nids - 1;
2887                 } else {
2888                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2889                                 alc_pcm_null_stream;
2890                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2891                 }
2892         }
2893
2894         return 0;
2895 }
2896
2897 static void alc_free_kctls(struct hda_codec *codec)
2898 {
2899         struct alc_spec *spec = codec->spec;
2900
2901         if (spec->kctls.list) {
2902                 struct snd_kcontrol_new *kctl = spec->kctls.list;
2903                 int i;
2904                 for (i = 0; i < spec->kctls.used; i++)
2905                         kfree(kctl[i].name);
2906         }
2907         snd_array_free(&spec->kctls);
2908 }
2909
2910 static void alc_free(struct hda_codec *codec)
2911 {
2912         struct alc_spec *spec = codec->spec;
2913
2914         if (!spec)
2915                 return;
2916
2917         alc_free_kctls(codec);
2918         kfree(spec);
2919         codec->spec = NULL; /* to be sure */
2920 }
2921
2922 #ifdef SND_HDA_NEEDS_RESUME
2923 static void store_pin_configs(struct hda_codec *codec)
2924 {
2925         struct alc_spec *spec = codec->spec;
2926         hda_nid_t nid, end_nid;
2927
2928         end_nid = codec->start_nid + codec->num_nodes;
2929         for (nid = codec->start_nid; nid < end_nid; nid++) {
2930                 unsigned int wid_caps = get_wcaps(codec, nid);
2931                 unsigned int wid_type =
2932                         (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2933                 if (wid_type != AC_WID_PIN)
2934                         continue;
2935                 if (spec->num_pins >= ARRAY_SIZE(spec->pin_nids))
2936                         break;
2937                 spec->pin_nids[spec->num_pins] = nid;
2938                 spec->pin_cfgs[spec->num_pins] =
2939                         snd_hda_codec_read(codec, nid, 0,
2940                                            AC_VERB_GET_CONFIG_DEFAULT, 0);
2941                 spec->num_pins++;
2942         }
2943 }
2944
2945 static void resume_pin_configs(struct hda_codec *codec)
2946 {
2947         struct alc_spec *spec = codec->spec;
2948         int i;
2949
2950         for (i = 0; i < spec->num_pins; i++) {
2951                 hda_nid_t pin_nid = spec->pin_nids[i];
2952                 unsigned int pin_config = spec->pin_cfgs[i];
2953                 snd_hda_codec_write(codec, pin_nid, 0,
2954                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2955                                     pin_config & 0x000000ff);
2956                 snd_hda_codec_write(codec, pin_nid, 0,
2957                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2958                                     (pin_config & 0x0000ff00) >> 8);
2959                 snd_hda_codec_write(codec, pin_nid, 0,
2960                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2961                                     (pin_config & 0x00ff0000) >> 16);
2962                 snd_hda_codec_write(codec, pin_nid, 0,
2963                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2964                                     pin_config >> 24);
2965         }
2966 }
2967
2968 static int alc_resume(struct hda_codec *codec)
2969 {
2970         resume_pin_configs(codec);
2971         codec->patch_ops.init(codec);
2972         snd_hda_codec_resume_amp(codec);
2973         snd_hda_codec_resume_cache(codec);
2974         return 0;
2975 }
2976 #else
2977 #define store_pin_configs(codec)
2978 #endif
2979
2980 /*
2981  */
2982 static struct hda_codec_ops alc_patch_ops = {
2983         .build_controls = alc_build_controls,
2984         .build_pcms = alc_build_pcms,
2985         .init = alc_init,
2986         .free = alc_free,
2987         .unsol_event = alc_unsol_event,
2988 #ifdef SND_HDA_NEEDS_RESUME
2989         .resume = alc_resume,
2990 #endif
2991 #ifdef CONFIG_SND_HDA_POWER_SAVE
2992         .check_power_status = alc_check_power_status,
2993 #endif
2994 };
2995
2996
2997 /*
2998  * Test configuration for debugging
2999  *
3000  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3001  * enum controls.
3002  */
3003 #ifdef CONFIG_SND_DEBUG
3004 static hda_nid_t alc880_test_dac_nids[4] = {
3005         0x02, 0x03, 0x04, 0x05
3006 };
3007
3008 static struct hda_input_mux alc880_test_capture_source = {
3009         .num_items = 7,
3010         .items = {
3011                 { "In-1", 0x0 },
3012                 { "In-2", 0x1 },
3013                 { "In-3", 0x2 },
3014                 { "In-4", 0x3 },
3015                 { "CD", 0x4 },
3016                 { "Front", 0x5 },
3017                 { "Surround", 0x6 },
3018         },
3019 };
3020
3021 static struct hda_channel_mode alc880_test_modes[4] = {
3022         { 2, NULL },
3023         { 4, NULL },
3024         { 6, NULL },
3025         { 8, NULL },
3026 };
3027
3028 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3029                                  struct snd_ctl_elem_info *uinfo)
3030 {
3031         static char *texts[] = {
3032                 "N/A", "Line Out", "HP Out",
3033                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3034         };
3035         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3036         uinfo->count = 1;
3037         uinfo->value.enumerated.items = 8;
3038         if (uinfo->value.enumerated.item >= 8)
3039                 uinfo->value.enumerated.item = 7;
3040         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3041         return 0;
3042 }
3043
3044 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3045                                 struct snd_ctl_elem_value *ucontrol)
3046 {
3047         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3048         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3049         unsigned int pin_ctl, item = 0;
3050
3051         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3052                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3053         if (pin_ctl & AC_PINCTL_OUT_EN) {
3054                 if (pin_ctl & AC_PINCTL_HP_EN)
3055                         item = 2;
3056                 else
3057                         item = 1;
3058         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3059                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3060                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3061                 case AC_PINCTL_VREF_50:  item = 4; break;
3062                 case AC_PINCTL_VREF_GRD: item = 5; break;
3063                 case AC_PINCTL_VREF_80:  item = 6; break;
3064                 case AC_PINCTL_VREF_100: item = 7; break;
3065                 }
3066         }
3067         ucontrol->value.enumerated.item[0] = item;
3068         return 0;
3069 }
3070
3071 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3072                                 struct snd_ctl_elem_value *ucontrol)
3073 {
3074         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3075         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3076         static unsigned int ctls[] = {
3077                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3078                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3079                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3080                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3081                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3082                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3083         };
3084         unsigned int old_ctl, new_ctl;
3085
3086         old_ctl = snd_hda_codec_read(codec, nid, 0,
3087                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3088         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3089         if (old_ctl != new_ctl) {
3090                 int val;
3091                 snd_hda_codec_write_cache(codec, nid, 0,
3092                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3093                                           new_ctl);
3094                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3095                         HDA_AMP_MUTE : 0;
3096                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3097                                          HDA_AMP_MUTE, val);
3098                 return 1;
3099         }
3100         return 0;
3101 }
3102
3103 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3104                                  struct snd_ctl_elem_info *uinfo)
3105 {
3106         static char *texts[] = {
3107                 "Front", "Surround", "CLFE", "Side"
3108         };
3109         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3110         uinfo->count = 1;
3111         uinfo->value.enumerated.items = 4;
3112         if (uinfo->value.enumerated.item >= 4)
3113                 uinfo->value.enumerated.item = 3;
3114         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3115         return 0;
3116 }
3117
3118 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3119                                 struct snd_ctl_elem_value *ucontrol)
3120 {
3121         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3122         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3123         unsigned int sel;
3124
3125         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3126         ucontrol->value.enumerated.item[0] = sel & 3;
3127         return 0;
3128 }
3129
3130 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3131                                 struct snd_ctl_elem_value *ucontrol)
3132 {
3133         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3134         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3135         unsigned int sel;
3136
3137         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3138         if (ucontrol->value.enumerated.item[0] != sel) {
3139                 sel = ucontrol->value.enumerated.item[0] & 3;
3140                 snd_hda_codec_write_cache(codec, nid, 0,
3141                                           AC_VERB_SET_CONNECT_SEL, sel);
3142                 return 1;
3143         }
3144         return 0;
3145 }
3146
3147 #define PIN_CTL_TEST(xname,nid) {                       \
3148                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3149                         .name = xname,                 \
3150                         .info = alc_test_pin_ctl_info, \
3151                         .get = alc_test_pin_ctl_get,   \
3152                         .put = alc_test_pin_ctl_put,   \
3153                         .private_value = nid           \
3154                         }
3155
3156 #define PIN_SRC_TEST(xname,nid) {                       \
3157                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3158                         .name = xname,                 \
3159                         .info = alc_test_pin_src_info, \
3160                         .get = alc_test_pin_src_get,   \
3161                         .put = alc_test_pin_src_put,   \
3162                         .private_value = nid           \
3163                         }
3164
3165 static struct snd_kcontrol_new alc880_test_mixer[] = {
3166         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3167         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3168         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3169         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3170         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3171         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3172         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3173         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3174         PIN_CTL_TEST("Front Pin Mode", 0x14),
3175         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3176         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3177         PIN_CTL_TEST("Side Pin Mode", 0x17),
3178         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3179         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3180         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3181         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3182         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3183         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3184         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3185         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3186         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3187         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3188         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3189         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3190         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3191         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3192         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3193         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3194         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3195         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3196         {
3197                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3198                 .name = "Channel Mode",
3199                 .info = alc_ch_mode_info,
3200                 .get = alc_ch_mode_get,
3201                 .put = alc_ch_mode_put,
3202         },
3203         { } /* end */
3204 };
3205
3206 static struct hda_verb alc880_test_init_verbs[] = {
3207         /* Unmute inputs of 0x0c - 0x0f */
3208         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3209         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3210         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3211         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3212         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3213         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3214         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3215         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3216         /* Vol output for 0x0c-0x0f */
3217         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3218         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3219         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3220         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3221         /* Set output pins 0x14-0x17 */
3222         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3223         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3224         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3225         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3226         /* Unmute output pins 0x14-0x17 */
3227         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3228         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3229         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3230         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3231         /* Set input pins 0x18-0x1c */
3232         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3233         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3234         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3235         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3236         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3237         /* Mute input pins 0x18-0x1b */
3238         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3239         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3240         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3241         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3242         /* ADC set up */
3243         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3244         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3245         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3246         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3247         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3248         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3249         /* Analog input/passthru */
3250         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3251         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3252         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3253         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3254         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3255         { }
3256 };
3257 #endif
3258
3259 /*
3260  */
3261
3262 static const char *alc880_models[ALC880_MODEL_LAST] = {
3263         [ALC880_3ST]            = "3stack",
3264         [ALC880_TCL_S700]       = "tcl",
3265         [ALC880_3ST_DIG]        = "3stack-digout",
3266         [ALC880_CLEVO]          = "clevo",
3267         [ALC880_5ST]            = "5stack",
3268         [ALC880_5ST_DIG]        = "5stack-digout",
3269         [ALC880_W810]           = "w810",
3270         [ALC880_Z71V]           = "z71v",
3271         [ALC880_6ST]            = "6stack",
3272         [ALC880_6ST_DIG]        = "6stack-digout",
3273         [ALC880_ASUS]           = "asus",
3274         [ALC880_ASUS_W1V]       = "asus-w1v",
3275         [ALC880_ASUS_DIG]       = "asus-dig",
3276         [ALC880_ASUS_DIG2]      = "asus-dig2",
3277         [ALC880_UNIWILL_DIG]    = "uniwill",
3278         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3279         [ALC880_FUJITSU]        = "fujitsu",
3280         [ALC880_F1734]          = "F1734",
3281         [ALC880_LG]             = "lg",
3282         [ALC880_LG_LW]          = "lg-lw",
3283         [ALC880_MEDION_RIM]     = "medion",
3284 #ifdef CONFIG_SND_DEBUG
3285         [ALC880_TEST]           = "test",
3286 #endif
3287         [ALC880_AUTO]           = "auto",
3288 };
3289
3290 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3291         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3292         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3293         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3294         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3295         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3296         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3297         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3298         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3299         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3300         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3301         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3302         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3303         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3304         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3305         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3306         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3307         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3308         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3309         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3310         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3311         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3312         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3313         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3314         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3315         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3316         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3317         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3318         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3319         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3320         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3321         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3322         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3323         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3324         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3325         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3326         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3327         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3328         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3329         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3330         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3331         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3332         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3333         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3334         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3335         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3336         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3337         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3338         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3339         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3340         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3341         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3342         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3343         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3344         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3345         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3346         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3347         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3348         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3349         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3350         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3351         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3352         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3353         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3354         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3355         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3356         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3357         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3358         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3359         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3360         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3361         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3362         {}
3363 };
3364
3365 /*
3366  * ALC880 codec presets
3367  */
3368 static struct alc_config_preset alc880_presets[] = {
3369         [ALC880_3ST] = {
3370                 .mixers = { alc880_three_stack_mixer },
3371                 .init_verbs = { alc880_volume_init_verbs,
3372                                 alc880_pin_3stack_init_verbs },
3373                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3374                 .dac_nids = alc880_dac_nids,
3375                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3376                 .channel_mode = alc880_threestack_modes,
3377                 .need_dac_fix = 1,
3378                 .input_mux = &alc880_capture_source,
3379         },
3380         [ALC880_3ST_DIG] = {
3381                 .mixers = { alc880_three_stack_mixer },
3382                 .init_verbs = { alc880_volume_init_verbs,
3383                                 alc880_pin_3stack_init_verbs },
3384                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3385                 .dac_nids = alc880_dac_nids,
3386                 .dig_out_nid = ALC880_DIGOUT_NID,
3387                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3388                 .channel_mode = alc880_threestack_modes,
3389                 .need_dac_fix = 1,
3390                 .input_mux = &alc880_capture_source,
3391         },
3392         [ALC880_TCL_S700] = {
3393                 .mixers = { alc880_tcl_s700_mixer },
3394                 .init_verbs = { alc880_volume_init_verbs,
3395                                 alc880_pin_tcl_S700_init_verbs,
3396                                 alc880_gpio2_init_verbs },
3397                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3398                 .dac_nids = alc880_dac_nids,
3399                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3400                 .num_adc_nids = 1, /* single ADC */
3401                 .hp_nid = 0x03,
3402                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3403                 .channel_mode = alc880_2_jack_modes,
3404                 .input_mux = &alc880_capture_source,
3405         },
3406         [ALC880_5ST] = {
3407                 .mixers = { alc880_three_stack_mixer,
3408                             alc880_five_stack_mixer},
3409                 .init_verbs = { alc880_volume_init_verbs,
3410                                 alc880_pin_5stack_init_verbs },
3411                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3412                 .dac_nids = alc880_dac_nids,
3413                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3414                 .channel_mode = alc880_fivestack_modes,
3415                 .input_mux = &alc880_capture_source,
3416         },
3417         [ALC880_5ST_DIG] = {
3418                 .mixers = { alc880_three_stack_mixer,
3419                             alc880_five_stack_mixer },
3420                 .init_verbs = { alc880_volume_init_verbs,
3421                                 alc880_pin_5stack_init_verbs },
3422                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3423                 .dac_nids = alc880_dac_nids,
3424                 .dig_out_nid = ALC880_DIGOUT_NID,
3425                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3426                 .channel_mode = alc880_fivestack_modes,
3427                 .input_mux = &alc880_capture_source,
3428         },
3429         [ALC880_6ST] = {
3430                 .mixers = { alc880_six_stack_mixer },
3431                 .init_verbs = { alc880_volume_init_verbs,
3432                                 alc880_pin_6stack_init_verbs },
3433                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3434                 .dac_nids = alc880_6st_dac_nids,
3435                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3436                 .channel_mode = alc880_sixstack_modes,
3437                 .input_mux = &alc880_6stack_capture_source,
3438         },
3439         [ALC880_6ST_DIG] = {
3440                 .mixers = { alc880_six_stack_mixer },
3441                 .init_verbs = { alc880_volume_init_verbs,
3442                                 alc880_pin_6stack_init_verbs },
3443                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3444                 .dac_nids = alc880_6st_dac_nids,
3445                 .dig_out_nid = ALC880_DIGOUT_NID,
3446                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3447                 .channel_mode = alc880_sixstack_modes,
3448                 .input_mux = &alc880_6stack_capture_source,
3449         },
3450         [ALC880_W810] = {
3451                 .mixers = { alc880_w810_base_mixer },
3452                 .init_verbs = { alc880_volume_init_verbs,
3453                                 alc880_pin_w810_init_verbs,
3454                                 alc880_gpio2_init_verbs },
3455                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3456                 .dac_nids = alc880_w810_dac_nids,
3457                 .dig_out_nid = ALC880_DIGOUT_NID,
3458                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3459                 .channel_mode = alc880_w810_modes,
3460                 .input_mux = &alc880_capture_source,
3461         },
3462         [ALC880_Z71V] = {
3463                 .mixers = { alc880_z71v_mixer },
3464                 .init_verbs = { alc880_volume_init_verbs,
3465                                 alc880_pin_z71v_init_verbs },
3466                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3467                 .dac_nids = alc880_z71v_dac_nids,
3468                 .dig_out_nid = ALC880_DIGOUT_NID,
3469                 .hp_nid = 0x03,
3470                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3471                 .channel_mode = alc880_2_jack_modes,
3472                 .input_mux = &alc880_capture_source,
3473         },
3474         [ALC880_F1734] = {
3475                 .mixers = { alc880_f1734_mixer },
3476                 .init_verbs = { alc880_volume_init_verbs,
3477                                 alc880_pin_f1734_init_verbs },
3478                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3479                 .dac_nids = alc880_f1734_dac_nids,
3480                 .hp_nid = 0x02,
3481                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3482                 .channel_mode = alc880_2_jack_modes,
3483                 .input_mux = &alc880_f1734_capture_source,
3484                 .unsol_event = alc880_uniwill_p53_unsol_event,
3485                 .init_hook = alc880_uniwill_p53_hp_automute,
3486         },
3487         [ALC880_ASUS] = {
3488                 .mixers = { alc880_asus_mixer },
3489                 .init_verbs = { alc880_volume_init_verbs,
3490                                 alc880_pin_asus_init_verbs,
3491                                 alc880_gpio1_init_verbs },
3492                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3493                 .dac_nids = alc880_asus_dac_nids,
3494                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3495                 .channel_mode = alc880_asus_modes,
3496                 .need_dac_fix = 1,
3497                 .input_mux = &alc880_capture_source,
3498         },
3499         [ALC880_ASUS_DIG] = {
3500                 .mixers = { alc880_asus_mixer },
3501                 .init_verbs = { alc880_volume_init_verbs,
3502                                 alc880_pin_asus_init_verbs,
3503                                 alc880_gpio1_init_verbs },
3504                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3505                 .dac_nids = alc880_asus_dac_nids,
3506                 .dig_out_nid = ALC880_DIGOUT_NID,
3507                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3508                 .channel_mode = alc880_asus_modes,
3509                 .need_dac_fix = 1,
3510                 .input_mux = &alc880_capture_source,
3511         },
3512         [ALC880_ASUS_DIG2] = {
3513                 .mixers = { alc880_asus_mixer },
3514                 .init_verbs = { alc880_volume_init_verbs,
3515                                 alc880_pin_asus_init_verbs,
3516                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3517                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3518                 .dac_nids = alc880_asus_dac_nids,
3519                 .dig_out_nid = ALC880_DIGOUT_NID,
3520                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3521                 .channel_mode = alc880_asus_modes,
3522                 .need_dac_fix = 1,
3523                 .input_mux = &alc880_capture_source,
3524         },
3525         [ALC880_ASUS_W1V] = {
3526                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3527                 .init_verbs = { alc880_volume_init_verbs,
3528                                 alc880_pin_asus_init_verbs,
3529                                 alc880_gpio1_init_verbs },
3530                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3531                 .dac_nids = alc880_asus_dac_nids,
3532                 .dig_out_nid = ALC880_DIGOUT_NID,
3533                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3534                 .channel_mode = alc880_asus_modes,
3535                 .need_dac_fix = 1,
3536                 .input_mux = &alc880_capture_source,
3537         },
3538         [ALC880_UNIWILL_DIG] = {
3539                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3540                 .init_verbs = { alc880_volume_init_verbs,
3541                                 alc880_pin_asus_init_verbs },
3542                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3543                 .dac_nids = alc880_asus_dac_nids,
3544                 .dig_out_nid = ALC880_DIGOUT_NID,
3545                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3546                 .channel_mode = alc880_asus_modes,
3547                 .need_dac_fix = 1,
3548                 .input_mux = &alc880_capture_source,
3549         },
3550         [ALC880_UNIWILL] = {
3551                 .mixers = { alc880_uniwill_mixer },
3552                 .init_verbs = { alc880_volume_init_verbs,
3553                                 alc880_uniwill_init_verbs },
3554                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3555                 .dac_nids = alc880_asus_dac_nids,
3556                 .dig_out_nid = ALC880_DIGOUT_NID,
3557                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3558                 .channel_mode = alc880_threestack_modes,
3559                 .need_dac_fix = 1,
3560                 .input_mux = &alc880_capture_source,
3561                 .unsol_event = alc880_uniwill_unsol_event,
3562                 .init_hook = alc880_uniwill_automute,
3563         },
3564         [ALC880_UNIWILL_P53] = {
3565                 .mixers = { alc880_uniwill_p53_mixer },
3566                 .init_verbs = { alc880_volume_init_verbs,
3567                                 alc880_uniwill_p53_init_verbs },
3568                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3569                 .dac_nids = alc880_asus_dac_nids,
3570                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3571                 .channel_mode = alc880_threestack_modes,
3572                 .input_mux = &alc880_capture_source,
3573                 .unsol_event = alc880_uniwill_p53_unsol_event,
3574                 .init_hook = alc880_uniwill_p53_hp_automute,
3575         },
3576         [ALC880_FUJITSU] = {
3577                 .mixers = { alc880_fujitsu_mixer,
3578                             alc880_pcbeep_mixer, },
3579                 .init_verbs = { alc880_volume_init_verbs,
3580                                 alc880_uniwill_p53_init_verbs,
3581                                 alc880_beep_init_verbs },
3582                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3583                 .dac_nids = alc880_dac_nids,
3584                 .dig_out_nid = ALC880_DIGOUT_NID,
3585                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3586                 .channel_mode = alc880_2_jack_modes,
3587                 .input_mux = &alc880_capture_source,
3588                 .unsol_event = alc880_uniwill_p53_unsol_event,
3589                 .init_hook = alc880_uniwill_p53_hp_automute,
3590         },
3591         [ALC880_CLEVO] = {
3592                 .mixers = { alc880_three_stack_mixer },
3593                 .init_verbs = { alc880_volume_init_verbs,
3594                                 alc880_pin_clevo_init_verbs },
3595                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3596                 .dac_nids = alc880_dac_nids,
3597                 .hp_nid = 0x03,
3598                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3599                 .channel_mode = alc880_threestack_modes,
3600                 .need_dac_fix = 1,
3601                 .input_mux = &alc880_capture_source,
3602         },
3603         [ALC880_LG] = {
3604                 .mixers = { alc880_lg_mixer },
3605                 .init_verbs = { alc880_volume_init_verbs,
3606                                 alc880_lg_init_verbs },
3607                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3608                 .dac_nids = alc880_lg_dac_nids,
3609                 .dig_out_nid = ALC880_DIGOUT_NID,
3610                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3611                 .channel_mode = alc880_lg_ch_modes,
3612                 .need_dac_fix = 1,
3613                 .input_mux = &alc880_lg_capture_source,
3614                 .unsol_event = alc880_lg_unsol_event,
3615                 .init_hook = alc880_lg_automute,
3616 #ifdef CONFIG_SND_HDA_POWER_SAVE
3617                 .loopbacks = alc880_lg_loopbacks,
3618 #endif
3619         },
3620         [ALC880_LG_LW] = {
3621                 .mixers = { alc880_lg_lw_mixer },
3622                 .init_verbs = { alc880_volume_init_verbs,
3623                                 alc880_lg_lw_init_verbs },
3624                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3625                 .dac_nids = alc880_dac_nids,
3626                 .dig_out_nid = ALC880_DIGOUT_NID,
3627                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3628                 .channel_mode = alc880_lg_lw_modes,
3629                 .input_mux = &alc880_lg_lw_capture_source,
3630                 .unsol_event = alc880_lg_lw_unsol_event,
3631                 .init_hook = alc880_lg_lw_automute,
3632         },
3633         [ALC880_MEDION_RIM] = {
3634                 .mixers = { alc880_medion_rim_mixer },
3635                 .init_verbs = { alc880_volume_init_verbs,
3636                                 alc880_medion_rim_init_verbs,
3637                                 alc_gpio2_init_verbs },
3638                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3639                 .dac_nids = alc880_dac_nids,
3640                 .dig_out_nid = ALC880_DIGOUT_NID,
3641                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3642                 .channel_mode = alc880_2_jack_modes,
3643                 .input_mux = &alc880_medion_rim_capture_source,
3644                 .unsol_event = alc880_medion_rim_unsol_event,
3645                 .init_hook = alc880_medion_rim_automute,
3646         },
3647 #ifdef CONFIG_SND_DEBUG
3648         [ALC880_TEST] = {
3649                 .mixers = { alc880_test_mixer },
3650                 .init_verbs = { alc880_test_init_verbs },
3651                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3652                 .dac_nids = alc880_test_dac_nids,
3653                 .dig_out_nid = ALC880_DIGOUT_NID,
3654                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3655                 .channel_mode = alc880_test_modes,
3656                 .input_mux = &alc880_test_capture_source,
3657         },
3658 #endif
3659 };
3660
3661 /*
3662  * Automatic parse of I/O pins from the BIOS configuration
3663  */
3664
3665 enum {
3666         ALC_CTL_WIDGET_VOL,
3667         ALC_CTL_WIDGET_MUTE,
3668         ALC_CTL_BIND_MUTE,
3669 };
3670 static struct snd_kcontrol_new alc880_control_templates[] = {
3671         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3672         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3673         HDA_BIND_MUTE(NULL, 0, 0, 0),
3674 };
3675
3676 /* add dynamic controls */
3677 static int add_control(struct alc_spec *spec, int type, const char *name,
3678                        unsigned long val)
3679 {
3680         struct snd_kcontrol_new *knew;
3681
3682         snd_array_init(&spec->kctls, sizeof(*knew), 32);
3683         knew = snd_array_new(&spec->kctls);
3684         if (!knew)
3685                 return -ENOMEM;
3686         *knew = alc880_control_templates[type];
3687         knew->name = kstrdup(name, GFP_KERNEL);
3688         if (!knew->name)
3689                 return -ENOMEM;
3690         knew->private_value = val;
3691         return 0;
3692 }
3693
3694 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3695 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3696 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3697 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3698 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3699 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3700 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3701 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3702 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3703 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3704 #define ALC880_PIN_CD_NID               0x1c
3705
3706 /* fill in the dac_nids table from the parsed pin configuration */
3707 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3708                                      const struct auto_pin_cfg *cfg)
3709 {
3710         hda_nid_t nid;
3711         int assigned[4];
3712         int i, j;
3713
3714         memset(assigned, 0, sizeof(assigned));
3715         spec->multiout.dac_nids = spec->private_dac_nids;
3716
3717         /* check the pins hardwired to audio widget */
3718         for (i = 0; i < cfg->line_outs; i++) {
3719                 nid = cfg->line_out_pins[i];
3720                 if (alc880_is_fixed_pin(nid)) {
3721                         int idx = alc880_fixed_pin_idx(nid);
3722                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3723                         assigned[idx] = 1;
3724                 }
3725         }
3726         /* left pins can be connect to any audio widget */
3727         for (i = 0; i < cfg->line_outs; i++) {
3728                 nid = cfg->line_out_pins[i];
3729                 if (alc880_is_fixed_pin(nid))
3730                         continue;
3731                 /* search for an empty channel */
3732                 for (j = 0; j < cfg->line_outs; j++) {
3733                         if (!assigned[j]) {
3734                                 spec->multiout.dac_nids[i] =
3735                                         alc880_idx_to_dac(j);
3736                                 assigned[j] = 1;
3737                                 break;
3738                         }
3739                 }
3740         }
3741         spec->multiout.num_dacs = cfg->line_outs;
3742         return 0;
3743 }
3744
3745 /* add playback controls from the parsed DAC table */
3746 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3747                                              const struct auto_pin_cfg *cfg)
3748 {
3749         char name[32];
3750         static const char *chname[4] = {
3751                 "Front", "Surround", NULL /*CLFE*/, "Side"
3752         };
3753         hda_nid_t nid;
3754         int i, err;
3755
3756         for (i = 0; i < cfg->line_outs; i++) {
3757                 if (!spec->multiout.dac_nids[i])
3758                         continue;
3759                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3760                 if (i == 2) {
3761                         /* Center/LFE */
3762                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3763                                           "Center Playback Volume",
3764                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3765                                                               HDA_OUTPUT));
3766                         if (err < 0)
3767                                 return err;
3768                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3769                                           "LFE Playback Volume",
3770                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3771                                                               HDA_OUTPUT));
3772                         if (err < 0)
3773                                 return err;
3774                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3775                                           "Center Playback Switch",
3776                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3777                                                               HDA_INPUT));
3778                         if (err < 0)
3779                                 return err;
3780                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3781                                           "LFE Playback Switch",
3782                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3783                                                               HDA_INPUT));
3784                         if (err < 0)
3785                                 return err;
3786                 } else {
3787                         sprintf(name, "%s Playback Volume", chname[i]);
3788                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3789                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3790                                                               HDA_OUTPUT));
3791                         if (err < 0)
3792                                 return err;
3793                         sprintf(name, "%s Playback Switch", chname[i]);
3794                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3795                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3796                                                               HDA_INPUT));
3797                         if (err < 0)
3798                                 return err;
3799                 }
3800         }
3801         return 0;
3802 }
3803
3804 /* add playback controls for speaker and HP outputs */
3805 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3806                                         const char *pfx)
3807 {
3808         hda_nid_t nid;
3809         int err;
3810         char name[32];
3811
3812         if (!pin)
3813                 return 0;
3814
3815         if (alc880_is_fixed_pin(pin)) {
3816                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3817                 /* specify the DAC as the extra output */
3818                 if (!spec->multiout.hp_nid)
3819                         spec->multiout.hp_nid = nid;
3820                 else
3821                         spec->multiout.extra_out_nid[0] = nid;
3822                 /* control HP volume/switch on the output mixer amp */
3823                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3824                 sprintf(name, "%s Playback Volume", pfx);
3825                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3826                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3827                 if (err < 0)
3828                         return err;
3829                 sprintf(name, "%s Playback Switch", pfx);
3830                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3831                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3832                 if (err < 0)
3833                         return err;
3834         } else if (alc880_is_multi_pin(pin)) {
3835                 /* set manual connection */
3836                 /* we have only a switch on HP-out PIN */
3837                 sprintf(name, "%s Playback Switch", pfx);
3838                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3839                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3840                 if (err < 0)
3841                         return err;
3842         }
3843         return 0;
3844 }
3845
3846 /* create input playback/capture controls for the given pin */
3847 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3848                             const char *ctlname,
3849                             int idx, hda_nid_t mix_nid)
3850 {
3851         char name[32];
3852         int err;
3853
3854         sprintf(name, "%s Playback Volume", ctlname);
3855         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3856                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3857         if (err < 0)
3858                 return err;
3859         sprintf(name, "%s Playback Switch", ctlname);
3860         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3861                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3862         if (err < 0)
3863                 return err;
3864         return 0;
3865 }
3866
3867 /* create playback/capture controls for input pins */
3868 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3869                                                 const struct auto_pin_cfg *cfg)
3870 {
3871         struct hda_input_mux *imux = &spec->private_imux;
3872         int i, err, idx;
3873
3874         for (i = 0; i < AUTO_PIN_LAST; i++) {
3875                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3876                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3877                         err = new_analog_input(spec, cfg->input_pins[i],
3878                                                auto_pin_cfg_labels[i],
3879                                                idx, 0x0b);
3880                         if (err < 0)
3881                                 return err;
3882                         imux->items[imux->num_items].label =
3883                                 auto_pin_cfg_labels[i];
3884                         imux->items[imux->num_items].index =
3885                                 alc880_input_pin_idx(cfg->input_pins[i]);
3886                         imux->num_items++;
3887                 }
3888         }
3889         return 0;
3890 }
3891
3892 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3893                                unsigned int pin_type)
3894 {
3895         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3896                             pin_type);
3897         /* unmute pin */
3898         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3899                             AMP_OUT_UNMUTE);
3900 }
3901
3902 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3903                                               hda_nid_t nid, int pin_type,
3904                                               int dac_idx)
3905 {
3906         alc_set_pin_output(codec, nid, pin_type);
3907         /* need the manual connection? */
3908         if (alc880_is_multi_pin(nid)) {
3909                 struct alc_spec *spec = codec->spec;
3910                 int idx = alc880_multi_pin_idx(nid);
3911                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3912                                     AC_VERB_SET_CONNECT_SEL,
3913                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3914         }
3915 }
3916
3917 static int get_pin_type(int line_out_type)
3918 {
3919         if (line_out_type == AUTO_PIN_HP_OUT)
3920                 return PIN_HP;
3921         else
3922                 return PIN_OUT;
3923 }
3924
3925 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3926 {
3927         struct alc_spec *spec = codec->spec;
3928         int i;
3929
3930         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3931         for (i = 0; i < spec->autocfg.line_outs; i++) {
3932                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3933                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3934                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3935         }
3936 }
3937
3938 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3939 {
3940         struct alc_spec *spec = codec->spec;
3941         hda_nid_t pin;
3942
3943         pin = spec->autocfg.speaker_pins[0];
3944         if (pin) /* connect to front */
3945                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3946         pin = spec->autocfg.hp_pins[0];
3947         if (pin) /* connect to front */
3948                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3949 }
3950
3951 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3952 {
3953         struct alc_spec *spec = codec->spec;
3954         int i;
3955
3956         for (i = 0; i < AUTO_PIN_LAST; i++) {
3957                 hda_nid_t nid = spec->autocfg.input_pins[i];
3958                 if (alc880_is_input_pin(nid)) {
3959                         snd_hda_codec_write(codec, nid, 0,
3960                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3961                                             i <= AUTO_PIN_FRONT_MIC ?
3962                                             PIN_VREF80 : PIN_IN);
3963                         if (nid != ALC880_PIN_CD_NID)
3964                                 snd_hda_codec_write(codec, nid, 0,
3965                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3966                                                     AMP_OUT_MUTE);
3967                 }
3968         }
3969 }
3970
3971 /* parse the BIOS configuration and set up the alc_spec */
3972 /* return 1 if successful, 0 if the proper config is not found,
3973  * or a negative error code
3974  */
3975 static int alc880_parse_auto_config(struct hda_codec *codec)
3976 {
3977         struct alc_spec *spec = codec->spec;
3978         int err;
3979         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3980
3981         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3982                                            alc880_ignore);
3983         if (err < 0)
3984                 return err;
3985         if (!spec->autocfg.line_outs)
3986                 return 0; /* can't find valid BIOS pin config */
3987
3988         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3989         if (err < 0)
3990                 return err;
3991         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3992         if (err < 0)
3993                 return err;
3994         err = alc880_auto_create_extra_out(spec,
3995                                            spec->autocfg.speaker_pins[0],
3996                                            "Speaker");
3997         if (err < 0)
3998                 return err;
3999         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4000                                            "Headphone");
4001         if (err < 0)
4002                 return err;
4003         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
4004         if (err < 0)
4005                 return err;
4006
4007         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4008
4009         if (spec->autocfg.dig_out_pin)
4010                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
4011         if (spec->autocfg.dig_in_pin)
4012                 spec->dig_in_nid = ALC880_DIGIN_NID;
4013
4014         if (spec->kctls.list)
4015                 add_mixer(spec, spec->kctls.list);
4016
4017         add_verb(spec, alc880_volume_init_verbs);
4018
4019         spec->num_mux_defs = 1;
4020         spec->input_mux = &spec->private_imux;
4021
4022         store_pin_configs(codec);
4023         return 1;
4024 }
4025
4026 /* additional initialization for auto-configuration model */
4027 static void alc880_auto_init(struct hda_codec *codec)
4028 {
4029         struct alc_spec *spec = codec->spec;
4030         alc880_auto_init_multi_out(codec);
4031         alc880_auto_init_extra_out(codec);
4032         alc880_auto_init_analog_input(codec);
4033         if (spec->unsol_event)
4034                 alc_inithook(codec);
4035 }
4036
4037 /*
4038  * OK, here we have finally the patch for ALC880
4039  */
4040
4041 static void set_capture_mixer(struct alc_spec *spec)
4042 {
4043         static struct snd_kcontrol_new *caps[3] = {
4044                 alc_capture_mixer1,
4045                 alc_capture_mixer2,
4046                 alc_capture_mixer3,
4047         };
4048         if (spec->num_adc_nids > 0 && spec->num_adc_nids < 3)
4049                 spec->cap_mixer = caps[spec->num_adc_nids - 1];
4050 }
4051
4052 static int patch_alc880(struct hda_codec *codec)
4053 {
4054         struct alc_spec *spec;
4055         int board_config;
4056         int err;
4057
4058         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4059         if (spec == NULL)
4060                 return -ENOMEM;
4061
4062         codec->spec = spec;
4063
4064         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4065                                                   alc880_models,
4066                                                   alc880_cfg_tbl);
4067         if (board_config < 0) {
4068                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
4069                        "trying auto-probe from BIOS...\n");
4070                 board_config = ALC880_AUTO;
4071         }
4072
4073         if (board_config == ALC880_AUTO) {
4074                 /* automatic parse from the BIOS config */
4075                 err = alc880_parse_auto_config(codec);
4076                 if (err < 0) {
4077                         alc_free(codec);
4078                         return err;
4079                 } else if (!err) {
4080                         printk(KERN_INFO
4081                                "hda_codec: Cannot set up configuration "
4082                                "from BIOS.  Using 3-stack mode...\n");
4083                         board_config = ALC880_3ST;
4084                 }
4085         }
4086
4087         if (board_config != ALC880_AUTO)
4088                 setup_preset(spec, &alc880_presets[board_config]);
4089
4090         spec->stream_name_analog = "ALC880 Analog";
4091         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4092         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4093         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4094
4095         spec->stream_name_digital = "ALC880 Digital";
4096         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4097         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4098
4099         if (!spec->adc_nids && spec->input_mux) {
4100                 /* check whether NID 0x07 is valid */
4101                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4102                 /* get type */
4103                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4104                 if (wcap != AC_WID_AUD_IN) {
4105                         spec->adc_nids = alc880_adc_nids_alt;
4106                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4107                 } else {
4108                         spec->adc_nids = alc880_adc_nids;
4109                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4110                 }
4111         }
4112         set_capture_mixer(spec);
4113
4114         spec->vmaster_nid = 0x0c;
4115
4116         codec->patch_ops = alc_patch_ops;
4117         if (board_config == ALC880_AUTO)
4118                 spec->init_hook = alc880_auto_init;
4119 #ifdef CONFIG_SND_HDA_POWER_SAVE
4120         if (!spec->loopback.amplist)
4121                 spec->loopback.amplist = alc880_loopbacks;
4122 #endif
4123
4124         return 0;
4125 }
4126
4127
4128 /*
4129  * ALC260 support
4130  */
4131
4132 static hda_nid_t alc260_dac_nids[1] = {
4133         /* front */
4134         0x02,
4135 };
4136
4137 static hda_nid_t alc260_adc_nids[1] = {
4138         /* ADC0 */
4139         0x04,
4140 };
4141
4142 static hda_nid_t alc260_adc_nids_alt[1] = {
4143         /* ADC1 */
4144         0x05,
4145 };
4146
4147 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4148  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4149  */
4150 static hda_nid_t alc260_dual_adc_nids[2] = {
4151         /* ADC0, ADC1 */
4152         0x04, 0x05
4153 };
4154
4155 #define ALC260_DIGOUT_NID       0x03
4156 #define ALC260_DIGIN_NID        0x06
4157
4158 static struct hda_input_mux alc260_capture_source = {
4159         .num_items = 4,
4160         .items = {
4161                 { "Mic", 0x0 },
4162                 { "Front Mic", 0x1 },
4163                 { "Line", 0x2 },
4164                 { "CD", 0x4 },
4165         },
4166 };
4167
4168 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4169  * headphone jack and the internal CD lines since these are the only pins at
4170  * which audio can appear.  For flexibility, also allow the option of
4171  * recording the mixer output on the second ADC (ADC0 doesn't have a
4172  * connection to the mixer output).
4173  */
4174 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4175         {
4176                 .num_items = 3,
4177                 .items = {
4178                         { "Mic/Line", 0x0 },
4179                         { "CD", 0x4 },
4180                         { "Headphone", 0x2 },
4181                 },
4182         },
4183         {
4184                 .num_items = 4,
4185                 .items = {
4186                         { "Mic/Line", 0x0 },
4187                         { "CD", 0x4 },
4188                         { "Headphone", 0x2 },
4189                         { "Mixer", 0x5 },
4190                 },
4191         },
4192
4193 };
4194
4195 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4196  * the Fujitsu S702x, but jacks are marked differently.
4197  */
4198 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4199         {
4200                 .num_items = 4,
4201                 .items = {
4202                         { "Mic", 0x0 },
4203                         { "Line", 0x2 },
4204                         { "CD", 0x4 },
4205                         { "Headphone", 0x5 },
4206                 },
4207         },
4208         {
4209                 .num_items = 5,
4210                 .items = {
4211                         { "Mic", 0x0 },
4212                         { "Line", 0x2 },
4213                         { "CD", 0x4 },
4214                         { "Headphone", 0x6 },
4215                         { "Mixer", 0x5 },
4216                 },
4217         },
4218 };
4219 /*
4220  * This is just place-holder, so there's something for alc_build_pcms to look
4221  * at when it calculates the maximum number of channels. ALC260 has no mixer
4222  * element which allows changing the channel mode, so the verb list is
4223  * never used.
4224  */
4225 static struct hda_channel_mode alc260_modes[1] = {
4226         { 2, NULL },
4227 };
4228
4229
4230 /* Mixer combinations
4231  *
4232  * basic: base_output + input + pc_beep + capture
4233  * HP: base_output + input + capture_alt
4234  * HP_3013: hp_3013 + input + capture
4235  * fujitsu: fujitsu + capture
4236  * acer: acer + capture
4237  */
4238
4239 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4240         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4241         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4242         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4243         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4244         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4245         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4246         { } /* end */
4247 };
4248
4249 static struct snd_kcontrol_new alc260_input_mixer[] = {
4250         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4251         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4252         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4253         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4254         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4255         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4256         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4257         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4258         { } /* end */
4259 };
4260
4261 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4262         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4263         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4264         { } /* end */
4265 };
4266
4267 /* update HP, line and mono out pins according to the master switch */
4268 static void alc260_hp_master_update(struct hda_codec *codec,
4269                                     hda_nid_t hp, hda_nid_t line,
4270                                     hda_nid_t mono)
4271 {
4272         struct alc_spec *spec = codec->spec;
4273         unsigned int val = spec->master_sw ? PIN_HP : 0;
4274         /* change HP and line-out pins */
4275         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4276                             val);
4277         snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4278                             val);
4279         /* mono (speaker) depending on the HP jack sense */
4280         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4281         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4282                             val);
4283 }
4284
4285 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4286                                    struct snd_ctl_elem_value *ucontrol)
4287 {
4288         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4289         struct alc_spec *spec = codec->spec;
4290         *ucontrol->value.integer.value = spec->master_sw;
4291         return 0;
4292 }
4293
4294 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4295                                    struct snd_ctl_elem_value *ucontrol)
4296 {
4297         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4298         struct alc_spec *spec = codec->spec;
4299         int val = !!*ucontrol->value.integer.value;
4300         hda_nid_t hp, line, mono;
4301
4302         if (val == spec->master_sw)
4303                 return 0;
4304         spec->master_sw = val;
4305         hp = (kcontrol->private_value >> 16) & 0xff;
4306         line = (kcontrol->private_value >> 8) & 0xff;
4307         mono = kcontrol->private_value & 0xff;
4308         alc260_hp_master_update(codec, hp, line, mono);
4309         return 1;
4310 }
4311
4312 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4313         {
4314                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4315                 .name = "Master Playback Switch",
4316                 .info = snd_ctl_boolean_mono_info,
4317                 .get = alc260_hp_master_sw_get,
4318                 .put = alc260_hp_master_sw_put,
4319                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4320         },
4321         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4322         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4323         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4324         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4325         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4326                               HDA_OUTPUT),
4327         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4328         { } /* end */
4329 };
4330
4331 static struct hda_verb alc260_hp_unsol_verbs[] = {
4332         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4333         {},
4334 };
4335
4336 static void alc260_hp_automute(struct hda_codec *codec)
4337 {
4338         struct alc_spec *spec = codec->spec;
4339         unsigned int present;
4340
4341         present = snd_hda_codec_read(codec, 0x10, 0,
4342                                      AC_VERB_GET_PIN_SENSE, 0);
4343         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4344         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4345 }
4346
4347 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4348 {
4349         if ((res >> 26) == ALC880_HP_EVENT)
4350                 alc260_hp_automute(codec);
4351 }
4352
4353 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4354         {
4355                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4356                 .name = "Master Playback Switch",
4357                 .info = snd_ctl_boolean_mono_info,
4358                 .get = alc260_hp_master_sw_get,
4359                 .put = alc260_hp_master_sw_put,
4360                 .private_value = (0x10 << 16) | (0x15 << 8) | 0x11
4361         },
4362         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4363         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4364         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4365         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4366         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4367         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4368         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4369         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4370         { } /* end */
4371 };
4372
4373 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4374         .ops = &snd_hda_bind_vol,
4375         .values = {
4376                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4377                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4378                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4379                 0
4380         },
4381 };
4382
4383 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4384         .ops = &snd_hda_bind_sw,
4385         .values = {
4386                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4387                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4388                 0
4389         },
4390 };
4391
4392 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4393         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4394         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4395         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4396         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4397         { } /* end */
4398 };
4399
4400 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4401         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4402         {},
4403 };
4404
4405 static void alc260_hp_3013_automute(struct hda_codec *codec)
4406 {
4407         struct alc_spec *spec = codec->spec;
4408         unsigned int present;
4409
4410         present = snd_hda_codec_read(codec, 0x15, 0,
4411                                      AC_VERB_GET_PIN_SENSE, 0);
4412         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4413         alc260_hp_master_update(codec, 0x10, 0x15, 0x11);
4414 }
4415
4416 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4417                                        unsigned int res)
4418 {
4419         if ((res >> 26) == ALC880_HP_EVENT)
4420                 alc260_hp_3013_automute(codec);
4421 }
4422
4423 static void alc260_hp_3012_automute(struct hda_codec *codec)
4424 {
4425         unsigned int present, bits;
4426
4427         present = snd_hda_codec_read(codec, 0x10, 0,
4428                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4429
4430         bits = present ? 0 : PIN_OUT;
4431         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4432                             bits);
4433         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4434                             bits);
4435         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4436                             bits);
4437 }
4438
4439 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4440                                        unsigned int res)
4441 {
4442         if ((res >> 26) == ALC880_HP_EVENT)
4443                 alc260_hp_3012_automute(codec);
4444 }
4445
4446 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4447  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4448  */
4449 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4450         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4451         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4452         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4453         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4454         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4455         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4456         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4457         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4458         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4459         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4460         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4461         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4462         { } /* end */
4463 };
4464
4465 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4466  * versions of the ALC260 don't act on requests to enable mic bias from NID
4467  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4468  * datasheet doesn't mention this restriction.  At this stage it's not clear
4469  * whether this behaviour is intentional or is a hardware bug in chip
4470  * revisions available in early 2006.  Therefore for now allow the
4471  * "Headphone Jack Mode" control to span all choices, but if it turns out
4472  * that the lack of mic bias for this NID is intentional we could change the
4473  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4474  *
4475  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4476  * don't appear to make the mic bias available from the "line" jack, even
4477  * though the NID used for this jack (0x14) can supply it.  The theory is
4478  * that perhaps Acer have included blocking capacitors between the ALC260
4479  * and the output jack.  If this turns out to be the case for all such
4480  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4481  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4482  *
4483  * The C20x Tablet series have a mono internal speaker which is controlled
4484  * via the chip's Mono sum widget and pin complex, so include the necessary
4485  * controls for such models.  On models without a "mono speaker" the control
4486  * won't do anything.
4487  */
4488 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4489         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4490         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4491         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4492         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4493                               HDA_OUTPUT),
4494         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4495                            HDA_INPUT),
4496         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4497         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4498         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4499         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4500         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4501         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4502         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4503         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4504         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4505         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4506         { } /* end */
4507 };
4508
4509 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4510  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4511  */
4512 static struct snd_kcontrol_new alc260_will_mixer[] = {
4513         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4514         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4515         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4516         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4517         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4518         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4519         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4520         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4521         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4522         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4523         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4524         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4525         { } /* end */
4526 };
4527
4528 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4529  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4530  */
4531 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4532         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4533         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4534         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4535         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4536         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4537         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4538         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4539         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4540         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4541         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4542         { } /* end */
4543 };
4544
4545 /*
4546  * initialization verbs
4547  */
4548 static struct hda_verb alc260_init_verbs[] = {
4549         /* Line In pin widget for input */
4550         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4551         /* CD pin widget for input */
4552         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4553         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4554         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4555         /* Mic2 (front panel) pin widget for input and vref at 80% */
4556         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4557         /* LINE-2 is used for line-out in rear */
4558         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4559         /* select line-out */
4560         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4561         /* LINE-OUT pin */
4562         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4563         /* enable HP */
4564         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4565         /* enable Mono */
4566         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4567         /* mute capture amp left and right */
4568         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4569         /* set connection select to line in (default select for this ADC) */
4570         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4571         /* mute capture amp left and right */
4572         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4573         /* set connection select to line in (default select for this ADC) */
4574         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4575         /* set vol=0 Line-Out mixer amp left and right */
4576         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4577         /* unmute pin widget amp left and right (no gain on this amp) */
4578         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4579         /* set vol=0 HP mixer amp left and right */
4580         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4581         /* unmute pin widget amp left and right (no gain on this amp) */
4582         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4583         /* set vol=0 Mono mixer amp left and right */
4584         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4585         /* unmute pin widget amp left and right (no gain on this amp) */
4586         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4587         /* unmute LINE-2 out pin */
4588         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4589         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4590          * Line In 2 = 0x03
4591          */
4592         /* mute analog inputs */
4593         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4594         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4595         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4596         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4597         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4598         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4599         /* mute Front out path */
4600         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4601         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4602         /* mute Headphone out path */
4603         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4604         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4605         /* mute Mono out path */
4606         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4607         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4608         { }
4609 };
4610
4611 #if 0 /* should be identical with alc260_init_verbs? */
4612 static struct hda_verb alc260_hp_init_verbs[] = {
4613         /* Headphone and output */
4614         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4615         /* mono output */
4616         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4617         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4618         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4619         /* Mic2 (front panel) pin widget for input and vref at 80% */
4620         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4621         /* Line In pin widget for input */
4622         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4623         /* Line-2 pin widget for output */
4624         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4625         /* CD pin widget for input */
4626         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4627         /* unmute amp left and right */
4628         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4629         /* set connection select to line in (default select for this ADC) */
4630         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4631         /* unmute Line-Out mixer amp left and right (volume = 0) */
4632         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4633         /* mute pin widget amp left and right (no gain on this amp) */
4634         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4635         /* unmute HP mixer amp left and right (volume = 0) */
4636         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4637         /* mute pin widget amp left and right (no gain on this amp) */
4638         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4639         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4640          * Line In 2 = 0x03
4641          */
4642         /* mute analog inputs */
4643         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4644         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4645         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4646         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4647         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4648         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4649         /* Unmute Front out path */
4650         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4651         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4652         /* Unmute Headphone out path */
4653         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4654         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4655         /* Unmute Mono out path */
4656         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4657         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4658         { }
4659 };
4660 #endif
4661
4662 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4663         /* Line out and output */
4664         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4665         /* mono output */
4666         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4667         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4668         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4669         /* Mic2 (front panel) pin widget for input and vref at 80% */
4670         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4671         /* Line In pin widget for input */
4672         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4673         /* Headphone pin widget for output */
4674         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4675         /* CD pin widget for input */
4676         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4677         /* unmute amp left and right */
4678         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4679         /* set connection select to line in (default select for this ADC) */
4680         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4681         /* unmute Line-Out mixer amp left and right (volume = 0) */
4682         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4683         /* mute pin widget amp left and right (no gain on this amp) */
4684         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4685         /* unmute HP mixer amp left and right (volume = 0) */
4686         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4687         /* mute pin widget amp left and right (no gain on this amp) */
4688         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4689         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4690          * Line In 2 = 0x03
4691          */
4692         /* mute analog inputs */
4693         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4694         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4695         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4696         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4697         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4698         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4699         /* Unmute Front out path */
4700         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4701         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4702         /* Unmute Headphone out path */
4703         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4704         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4705         /* Unmute Mono out path */
4706         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4707         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4708         { }
4709 };
4710
4711 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4712  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4713  * audio = 0x16, internal speaker = 0x10.
4714  */
4715 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4716         /* Disable all GPIOs */
4717         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4718         /* Internal speaker is connected to headphone pin */
4719         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4720         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4721         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4722         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4723         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4724         /* Ensure all other unused pins are disabled and muted. */
4725         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4726         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4727         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4728         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4729         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4730         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4731         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4732         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4733
4734         /* Disable digital (SPDIF) pins */
4735         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4736         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4737
4738         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
4739          * when acting as an output.
4740          */
4741         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4742
4743         /* Start with output sum widgets muted and their output gains at min */
4744         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4745         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4746         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4747         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4748         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4749         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4750         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4751         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4752         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4753
4754         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4755         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4756         /* Unmute Line1 pin widget output buffer since it starts as an output.
4757          * If the pin mode is changed by the user the pin mode control will
4758          * take care of enabling the pin's input/output buffers as needed.
4759          * Therefore there's no need to enable the input buffer at this
4760          * stage.
4761          */
4762         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4763         /* Unmute input buffer of pin widget used for Line-in (no equiv
4764          * mixer ctrl)
4765          */
4766         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4767
4768         /* Mute capture amp left and right */
4769         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4770         /* Set ADC connection select to match default mixer setting - line
4771          * in (on mic1 pin)
4772          */
4773         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4774
4775         /* Do the same for the second ADC: mute capture input amp and
4776          * set ADC connection to line in (on mic1 pin)
4777          */
4778         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4779         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4780
4781         /* Mute all inputs to mixer widget (even unconnected ones) */
4782         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4783         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4784         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4785         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4786         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4787         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4788         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4789         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4790
4791         { }
4792 };
4793
4794 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4795  * similar laptops (adapted from Fujitsu init verbs).
4796  */
4797 static struct hda_verb alc260_acer_init_verbs[] = {
4798         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4799          * the headphone jack.  Turn this on and rely on the standard mute
4800          * methods whenever the user wants to turn these outputs off.
4801          */
4802         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4803         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4804         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4805         /* Internal speaker/Headphone jack is connected to Line-out pin */
4806         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4807         /* Internal microphone/Mic jack is connected to Mic1 pin */
4808         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4809         /* Line In jack is connected to Line1 pin */
4810         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4811         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4812         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4813         /* Ensure all other unused pins are disabled and muted. */
4814         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4815         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4816         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4817         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4818         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4819         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4820         /* Disable digital (SPDIF) pins */
4821         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4822         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4823
4824         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
4825          * bus when acting as outputs.
4826          */
4827         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4828         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4829
4830         /* Start with output sum widgets muted and their output gains at min */
4831         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4832         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4833         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4834         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4835         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4836         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4837         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4838         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4839         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4840
4841         /* Unmute Line-out pin widget amp left and right
4842          * (no equiv mixer ctrl)
4843          */
4844         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4845         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4846         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4847         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4848          * inputs. If the pin mode is changed by the user the pin mode control
4849          * will take care of enabling the pin's input/output buffers as needed.
4850          * Therefore there's no need to enable the input buffer at this
4851          * stage.
4852          */
4853         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4854         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4855
4856         /* Mute capture amp left and right */
4857         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4858         /* Set ADC connection select to match default mixer setting - mic
4859          * (on mic1 pin)
4860          */
4861         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4862
4863         /* Do similar with the second ADC: mute capture input amp and
4864          * set ADC connection to mic to match ALSA's default state.
4865          */
4866         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4867         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4868
4869         /* Mute all inputs to mixer widget (even unconnected ones) */
4870         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4871         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4872         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4873         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4874         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4875         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4876         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4877         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4878
4879         { }
4880 };
4881
4882 static struct hda_verb alc260_will_verbs[] = {
4883         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4884         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4885         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4886         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4887         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4888         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4889         {}
4890 };
4891
4892 static struct hda_verb alc260_replacer_672v_verbs[] = {
4893         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4894         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4895         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4896
4897         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4898         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4899         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4900
4901         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4902         {}
4903 };
4904
4905 /* toggle speaker-output according to the hp-jack state */
4906 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4907 {
4908         unsigned int present;
4909
4910         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4911         present = snd_hda_codec_read(codec, 0x0f, 0,
4912                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4913         if (present) {
4914                 snd_hda_codec_write_cache(codec, 0x01, 0,
4915                                           AC_VERB_SET_GPIO_DATA, 1);
4916                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4917                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4918                                           PIN_HP);
4919         } else {
4920                 snd_hda_codec_write_cache(codec, 0x01, 0,
4921                                           AC_VERB_SET_GPIO_DATA, 0);
4922                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4923                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4924                                           PIN_OUT);
4925         }
4926 }
4927
4928 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4929                                        unsigned int res)
4930 {
4931         if ((res >> 26) == ALC880_HP_EVENT)
4932                 alc260_replacer_672v_automute(codec);
4933 }
4934
4935 static struct hda_verb alc260_hp_dc7600_verbs[] = {
4936         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
4937         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
4938         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4939         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4940         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4941         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4942         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4943         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4944         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4945         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4946         {}
4947 };
4948
4949 /* Test configuration for debugging, modelled after the ALC880 test
4950  * configuration.
4951  */
4952 #ifdef CONFIG_SND_DEBUG
4953 static hda_nid_t alc260_test_dac_nids[1] = {
4954         0x02,
4955 };
4956 static hda_nid_t alc260_test_adc_nids[2] = {
4957         0x04, 0x05,
4958 };
4959 /* For testing the ALC260, each input MUX needs its own definition since
4960  * the signal assignments are different.  This assumes that the first ADC
4961  * is NID 0x04.
4962  */
4963 static struct hda_input_mux alc260_test_capture_sources[2] = {
4964         {
4965                 .num_items = 7,
4966                 .items = {
4967                         { "MIC1 pin", 0x0 },
4968                         { "MIC2 pin", 0x1 },
4969                         { "LINE1 pin", 0x2 },
4970                         { "LINE2 pin", 0x3 },
4971                         { "CD pin", 0x4 },
4972                         { "LINE-OUT pin", 0x5 },
4973                         { "HP-OUT pin", 0x6 },
4974                 },
4975         },
4976         {
4977                 .num_items = 8,
4978                 .items = {
4979                         { "MIC1 pin", 0x0 },
4980                         { "MIC2 pin", 0x1 },
4981                         { "LINE1 pin", 0x2 },
4982                         { "LINE2 pin", 0x3 },
4983                         { "CD pin", 0x4 },
4984                         { "Mixer", 0x5 },
4985                         { "LINE-OUT pin", 0x6 },
4986                         { "HP-OUT pin", 0x7 },
4987                 },
4988         },
4989 };
4990 static struct snd_kcontrol_new alc260_test_mixer[] = {
4991         /* Output driver widgets */
4992         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4993         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4994         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4995         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4996         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4997         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4998
4999         /* Modes for retasking pin widgets
5000          * Note: the ALC260 doesn't seem to act on requests to enable mic
5001          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5002          * mention this restriction.  At this stage it's not clear whether
5003          * this behaviour is intentional or is a hardware bug in chip
5004          * revisions available at least up until early 2006.  Therefore for
5005          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5006          * choices, but if it turns out that the lack of mic bias for these
5007          * NIDs is intentional we could change their modes from
5008          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5009          */
5010         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5011         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5012         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5013         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5014         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5015         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5016
5017         /* Loopback mixer controls */
5018         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5019         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5020         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5021         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5022         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5023         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5024         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5025         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5026         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5027         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5028         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
5029         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
5030         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5031         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5032         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5033         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5034
5035         /* Controls for GPIO pins, assuming they are configured as outputs */
5036         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5037         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5038         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5039         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5040
5041         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5042          * is ambigious as to which NID is which; testing on laptops which
5043          * make this output available should provide clarification.
5044          */
5045         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5046         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5047
5048         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5049          * this output to turn on an external amplifier.
5050          */
5051         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5052         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5053
5054         { } /* end */
5055 };
5056 static struct hda_verb alc260_test_init_verbs[] = {
5057         /* Enable all GPIOs as outputs with an initial value of 0 */
5058         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5059         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5060         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5061
5062         /* Enable retasking pins as output, initially without power amp */
5063         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5064         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5065         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5066         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5067         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5068         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5069
5070         /* Disable digital (SPDIF) pins initially, but users can enable
5071          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5072          * payload also sets the generation to 0, output to be in "consumer"
5073          * PCM format, copyright asserted, no pre-emphasis and no validity
5074          * control.
5075          */
5076         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5077         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5078
5079         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5080          * OUT1 sum bus when acting as an output.
5081          */
5082         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5083         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5084         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5085         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5086
5087         /* Start with output sum widgets muted and their output gains at min */
5088         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5089         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5090         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5091         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5092         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5093         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5094         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5095         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5096         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5097
5098         /* Unmute retasking pin widget output buffers since the default
5099          * state appears to be output.  As the pin mode is changed by the
5100          * user the pin mode control will take care of enabling the pin's
5101          * input/output buffers as needed.
5102          */
5103         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5104         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5105         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5106         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5107         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5108         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5109         /* Also unmute the mono-out pin widget */
5110         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5111
5112         /* Mute capture amp left and right */
5113         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5114         /* Set ADC connection select to match default mixer setting (mic1
5115          * pin)
5116          */
5117         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5118
5119         /* Do the same for the second ADC: mute capture input amp and
5120          * set ADC connection to mic1 pin
5121          */
5122         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5123         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5124
5125         /* Mute all inputs to mixer widget (even unconnected ones) */
5126         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5127         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5128         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5129         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5130         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5131         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5132         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5133         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5134
5135         { }
5136 };
5137 #endif
5138
5139 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5140 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5141
5142 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5143 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5144
5145 /*
5146  * for BIOS auto-configuration
5147  */
5148
5149 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5150                                         const char *pfx, int *vol_bits)
5151 {
5152         hda_nid_t nid_vol;
5153         unsigned long vol_val, sw_val;
5154         char name[32];
5155         int err;
5156
5157         if (nid >= 0x0f && nid < 0x11) {
5158                 nid_vol = nid - 0x7;
5159                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5160                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5161         } else if (nid == 0x11) {
5162                 nid_vol = nid - 0x7;
5163                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5164                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5165         } else if (nid >= 0x12 && nid <= 0x15) {
5166                 nid_vol = 0x08;
5167                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5168                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5169         } else
5170                 return 0; /* N/A */
5171
5172         if (!(*vol_bits & (1 << nid_vol))) {
5173                 /* first control for the volume widget */
5174                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5175                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5176                 if (err < 0)
5177                         return err;
5178                 *vol_bits |= (1 << nid_vol);
5179         }
5180         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5181         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5182         if (err < 0)
5183                 return err;
5184         return 1;
5185 }
5186
5187 /* add playback controls from the parsed DAC table */
5188 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5189                                              const struct auto_pin_cfg *cfg)
5190 {
5191         hda_nid_t nid;
5192         int err;
5193         int vols = 0;
5194
5195         spec->multiout.num_dacs = 1;
5196         spec->multiout.dac_nids = spec->private_dac_nids;
5197         spec->multiout.dac_nids[0] = 0x02;
5198
5199         nid = cfg->line_out_pins[0];
5200         if (nid) {
5201                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5202                 if (err < 0)
5203                         return err;
5204         }
5205
5206         nid = cfg->speaker_pins[0];
5207         if (nid) {
5208                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5209                 if (err < 0)
5210                         return err;
5211         }
5212
5213         nid = cfg->hp_pins[0];
5214         if (nid) {
5215                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5216                                                    &vols);
5217                 if (err < 0)
5218                         return err;
5219         }
5220         return 0;
5221 }
5222
5223 /* create playback/capture controls for input pins */
5224 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5225                                                 const struct auto_pin_cfg *cfg)
5226 {
5227         struct hda_input_mux *imux = &spec->private_imux;
5228         int i, err, idx;
5229
5230         for (i = 0; i < AUTO_PIN_LAST; i++) {
5231                 if (cfg->input_pins[i] >= 0x12) {
5232                         idx = cfg->input_pins[i] - 0x12;
5233                         err = new_analog_input(spec, cfg->input_pins[i],
5234                                                auto_pin_cfg_labels[i], idx,
5235                                                0x07);
5236                         if (err < 0)
5237                                 return err;
5238                         imux->items[imux->num_items].label =
5239                                 auto_pin_cfg_labels[i];
5240                         imux->items[imux->num_items].index = idx;
5241                         imux->num_items++;
5242                 }
5243                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5244                         idx = cfg->input_pins[i] - 0x09;
5245                         err = new_analog_input(spec, cfg->input_pins[i],
5246                                                auto_pin_cfg_labels[i], idx,
5247                                                0x07);
5248                         if (err < 0)
5249                                 return err;
5250                         imux->items[imux->num_items].label =
5251                                 auto_pin_cfg_labels[i];
5252                         imux->items[imux->num_items].index = idx;
5253                         imux->num_items++;
5254                 }
5255         }
5256         return 0;
5257 }
5258
5259 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5260                                               hda_nid_t nid, int pin_type,
5261                                               int sel_idx)
5262 {
5263         alc_set_pin_output(codec, nid, pin_type);
5264         /* need the manual connection? */
5265         if (nid >= 0x12) {
5266                 int idx = nid - 0x12;
5267                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5268                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5269         }
5270 }
5271
5272 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5273 {
5274         struct alc_spec *spec = codec->spec;
5275         hda_nid_t nid;
5276
5277         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5278         nid = spec->autocfg.line_out_pins[0];
5279         if (nid) {
5280                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5281                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5282         }
5283
5284         nid = spec->autocfg.speaker_pins[0];
5285         if (nid)
5286                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5287
5288         nid = spec->autocfg.hp_pins[0];
5289         if (nid)
5290                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5291 }
5292
5293 #define ALC260_PIN_CD_NID               0x16
5294 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5295 {
5296         struct alc_spec *spec = codec->spec;
5297         int i;
5298
5299         for (i = 0; i < AUTO_PIN_LAST; i++) {
5300                 hda_nid_t nid = spec->autocfg.input_pins[i];
5301                 if (nid >= 0x12) {
5302                         snd_hda_codec_write(codec, nid, 0,
5303                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5304                                             i <= AUTO_PIN_FRONT_MIC ?
5305                                             PIN_VREF80 : PIN_IN);
5306                         if (nid != ALC260_PIN_CD_NID)
5307                                 snd_hda_codec_write(codec, nid, 0,
5308                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5309                                                     AMP_OUT_MUTE);
5310                 }
5311         }
5312 }
5313
5314 /*
5315  * generic initialization of ADC, input mixers and output mixers
5316  */
5317 static struct hda_verb alc260_volume_init_verbs[] = {
5318         /*
5319          * Unmute ADC0-1 and set the default input to mic-in
5320          */
5321         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5322         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5323         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5324         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5325
5326         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5327          * mixer widget
5328          * Note: PASD motherboards uses the Line In 2 as the input for
5329          * front panel mic (mic 2)
5330          */
5331         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5332         /* mute analog inputs */
5333         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5334         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5335         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5336         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5337         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5338
5339         /*
5340          * Set up output mixers (0x08 - 0x0a)
5341          */
5342         /* set vol=0 to output mixers */
5343         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5344         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5345         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5346         /* set up input amps for analog loopback */
5347         /* Amp Indices: DAC = 0, mixer = 1 */
5348         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5349         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5350         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5351         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5352         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5353         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5354
5355         { }
5356 };
5357
5358 static int alc260_parse_auto_config(struct hda_codec *codec)
5359 {
5360         struct alc_spec *spec = codec->spec;
5361         int err;
5362         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5363
5364         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5365                                            alc260_ignore);
5366         if (err < 0)
5367                 return err;
5368         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5369         if (err < 0)
5370                 return err;
5371         if (!spec->kctls.list)
5372                 return 0; /* can't find valid BIOS pin config */
5373         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5374         if (err < 0)
5375                 return err;
5376
5377         spec->multiout.max_channels = 2;
5378
5379         if (spec->autocfg.dig_out_pin)
5380                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5381         if (spec->kctls.list)
5382                 add_mixer(spec, spec->kctls.list);
5383
5384         add_verb(spec, alc260_volume_init_verbs);
5385
5386         spec->num_mux_defs = 1;
5387         spec->input_mux = &spec->private_imux;
5388
5389         store_pin_configs(codec);
5390         return 1;
5391 }
5392
5393 /* additional initialization for auto-configuration model */
5394 static void alc260_auto_init(struct hda_codec *codec)
5395 {
5396         struct alc_spec *spec = codec->spec;
5397         alc260_auto_init_multi_out(codec);
5398         alc260_auto_init_analog_input(codec);
5399         if (spec->unsol_event)
5400                 alc_inithook(codec);
5401 }
5402
5403 #ifdef CONFIG_SND_HDA_POWER_SAVE
5404 static struct hda_amp_list alc260_loopbacks[] = {
5405         { 0x07, HDA_INPUT, 0 },
5406         { 0x07, HDA_INPUT, 1 },
5407         { 0x07, HDA_INPUT, 2 },
5408         { 0x07, HDA_INPUT, 3 },
5409         { 0x07, HDA_INPUT, 4 },
5410         { } /* end */
5411 };
5412 #endif
5413
5414 /*
5415  * ALC260 configurations
5416  */
5417 static const char *alc260_models[ALC260_MODEL_LAST] = {
5418         [ALC260_BASIC]          = "basic",
5419         [ALC260_HP]             = "hp",
5420         [ALC260_HP_3013]        = "hp-3013",
5421         [ALC260_HP_DC7600]      = "hp-dc7600",
5422         [ALC260_FUJITSU_S702X]  = "fujitsu",
5423         [ALC260_ACER]           = "acer",
5424         [ALC260_WILL]           = "will",
5425         [ALC260_REPLACER_672V]  = "replacer",
5426 #ifdef CONFIG_SND_DEBUG
5427         [ALC260_TEST]           = "test",
5428 #endif
5429         [ALC260_AUTO]           = "auto",
5430 };
5431
5432 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5433         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5434         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5435         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5436         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5437         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5438         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5439         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5440         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5441         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5442         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5443         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5444         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5445         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5446         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5447         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5448         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5449         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5450         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5451         {}
5452 };
5453
5454 static struct alc_config_preset alc260_presets[] = {
5455         [ALC260_BASIC] = {
5456                 .mixers = { alc260_base_output_mixer,
5457                             alc260_input_mixer,
5458                             alc260_pc_beep_mixer },
5459                 .init_verbs = { alc260_init_verbs },
5460                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5461                 .dac_nids = alc260_dac_nids,
5462                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5463                 .adc_nids = alc260_adc_nids,
5464                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5465                 .channel_mode = alc260_modes,
5466                 .input_mux = &alc260_capture_source,
5467         },
5468         [ALC260_HP] = {
5469                 .mixers = { alc260_hp_output_mixer,
5470                             alc260_input_mixer },
5471                 .init_verbs = { alc260_init_verbs,
5472                                 alc260_hp_unsol_verbs },
5473                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5474                 .dac_nids = alc260_dac_nids,
5475                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5476                 .adc_nids = alc260_adc_nids_alt,
5477                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5478                 .channel_mode = alc260_modes,
5479                 .input_mux = &alc260_capture_source,
5480                 .unsol_event = alc260_hp_unsol_event,
5481                 .init_hook = alc260_hp_automute,
5482         },
5483         [ALC260_HP_DC7600] = {
5484                 .mixers = { alc260_hp_dc7600_mixer,
5485                             alc260_input_mixer },
5486                 .init_verbs = { alc260_init_verbs,
5487                                 alc260_hp_dc7600_verbs },
5488                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5489                 .dac_nids = alc260_dac_nids,
5490                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5491                 .adc_nids = alc260_adc_nids_alt,
5492                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5493                 .channel_mode = alc260_modes,
5494                 .input_mux = &alc260_capture_source,
5495                 .unsol_event = alc260_hp_3012_unsol_event,
5496                 .init_hook = alc260_hp_3012_automute,
5497         },
5498         [ALC260_HP_3013] = {
5499                 .mixers = { alc260_hp_3013_mixer,
5500                             alc260_input_mixer },
5501                 .init_verbs = { alc260_hp_3013_init_verbs,
5502                                 alc260_hp_3013_unsol_verbs },
5503                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5504                 .dac_nids = alc260_dac_nids,
5505                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5506                 .adc_nids = alc260_adc_nids_alt,
5507                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5508                 .channel_mode = alc260_modes,
5509                 .input_mux = &alc260_capture_source,
5510                 .unsol_event = alc260_hp_3013_unsol_event,
5511                 .init_hook = alc260_hp_3013_automute,
5512         },
5513         [ALC260_FUJITSU_S702X] = {
5514                 .mixers = { alc260_fujitsu_mixer },
5515                 .init_verbs = { alc260_fujitsu_init_verbs },
5516                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5517                 .dac_nids = alc260_dac_nids,
5518                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5519                 .adc_nids = alc260_dual_adc_nids,
5520                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5521                 .channel_mode = alc260_modes,
5522                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5523                 .input_mux = alc260_fujitsu_capture_sources,
5524         },
5525         [ALC260_ACER] = {
5526                 .mixers = { alc260_acer_mixer },
5527                 .init_verbs = { alc260_acer_init_verbs },
5528                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5529                 .dac_nids = alc260_dac_nids,
5530                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5531                 .adc_nids = alc260_dual_adc_nids,
5532                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5533                 .channel_mode = alc260_modes,
5534                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5535                 .input_mux = alc260_acer_capture_sources,
5536         },
5537         [ALC260_WILL] = {
5538                 .mixers = { alc260_will_mixer },
5539                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5540                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5541                 .dac_nids = alc260_dac_nids,
5542                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5543                 .adc_nids = alc260_adc_nids,
5544                 .dig_out_nid = ALC260_DIGOUT_NID,
5545                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5546                 .channel_mode = alc260_modes,
5547                 .input_mux = &alc260_capture_source,
5548         },
5549         [ALC260_REPLACER_672V] = {
5550                 .mixers = { alc260_replacer_672v_mixer },
5551                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5552                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5553                 .dac_nids = alc260_dac_nids,
5554                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5555                 .adc_nids = alc260_adc_nids,
5556                 .dig_out_nid = ALC260_DIGOUT_NID,
5557                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5558                 .channel_mode = alc260_modes,
5559                 .input_mux = &alc260_capture_source,
5560                 .unsol_event = alc260_replacer_672v_unsol_event,
5561                 .init_hook = alc260_replacer_672v_automute,
5562         },
5563 #ifdef CONFIG_SND_DEBUG
5564         [ALC260_TEST] = {
5565                 .mixers = { alc260_test_mixer },
5566                 .init_verbs = { alc260_test_init_verbs },
5567                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5568                 .dac_nids = alc260_test_dac_nids,
5569                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5570                 .adc_nids = alc260_test_adc_nids,
5571                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5572                 .channel_mode = alc260_modes,
5573                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5574                 .input_mux = alc260_test_capture_sources,
5575         },
5576 #endif
5577 };
5578
5579 static int patch_alc260(struct hda_codec *codec)
5580 {
5581         struct alc_spec *spec;
5582         int err, board_config;
5583
5584         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5585         if (spec == NULL)
5586                 return -ENOMEM;
5587
5588         codec->spec = spec;
5589
5590         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5591                                                   alc260_models,
5592                                                   alc260_cfg_tbl);
5593         if (board_config < 0) {
5594                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5595                            "trying auto-probe from BIOS...\n");
5596                 board_config = ALC260_AUTO;
5597         }
5598
5599         if (board_config == ALC260_AUTO) {
5600                 /* automatic parse from the BIOS config */
5601                 err = alc260_parse_auto_config(codec);
5602                 if (err < 0) {
5603                         alc_free(codec);
5604                         return err;
5605                 } else if (!err) {
5606                         printk(KERN_INFO
5607                                "hda_codec: Cannot set up configuration "
5608                                "from BIOS.  Using base mode...\n");
5609                         board_config = ALC260_BASIC;
5610                 }
5611         }
5612
5613         if (board_config != ALC260_AUTO)
5614                 setup_preset(spec, &alc260_presets[board_config]);
5615
5616         spec->stream_name_analog = "ALC260 Analog";
5617         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5618         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5619
5620         spec->stream_name_digital = "ALC260 Digital";
5621         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5622         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5623
5624         if (!spec->adc_nids && spec->input_mux) {
5625                 /* check whether NID 0x04 is valid */
5626                 unsigned int wcap = get_wcaps(codec, 0x04);
5627                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5628                 /* get type */
5629                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5630                         spec->adc_nids = alc260_adc_nids_alt;
5631                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5632                 } else {
5633                         spec->adc_nids = alc260_adc_nids;
5634                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5635                 }
5636         }
5637         set_capture_mixer(spec);
5638
5639         spec->vmaster_nid = 0x08;
5640
5641         codec->patch_ops = alc_patch_ops;
5642         if (board_config == ALC260_AUTO)
5643                 spec->init_hook = alc260_auto_init;
5644 #ifdef CONFIG_SND_HDA_POWER_SAVE
5645         if (!spec->loopback.amplist)
5646                 spec->loopback.amplist = alc260_loopbacks;
5647 #endif
5648
5649         return 0;
5650 }
5651
5652
5653 /*
5654  * ALC882 support
5655  *
5656  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5657  * configuration.  Each pin widget can choose any input DACs and a mixer.
5658  * Each ADC is connected from a mixer of all inputs.  This makes possible
5659  * 6-channel independent captures.
5660  *
5661  * In addition, an independent DAC for the multi-playback (not used in this
5662  * driver yet).
5663  */
5664 #define ALC882_DIGOUT_NID       0x06
5665 #define ALC882_DIGIN_NID        0x0a
5666
5667 static struct hda_channel_mode alc882_ch_modes[1] = {
5668         { 8, NULL }
5669 };
5670
5671 static hda_nid_t alc882_dac_nids[4] = {
5672         /* front, rear, clfe, rear_surr */
5673         0x02, 0x03, 0x04, 0x05
5674 };
5675
5676 /* identical with ALC880 */
5677 #define alc882_adc_nids         alc880_adc_nids
5678 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5679
5680 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5681 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5682
5683 /* input MUX */
5684 /* FIXME: should be a matrix-type input source selection */
5685
5686 static struct hda_input_mux alc882_capture_source = {
5687         .num_items = 4,
5688         .items = {
5689                 { "Mic", 0x0 },
5690                 { "Front Mic", 0x1 },
5691                 { "Line", 0x2 },
5692                 { "CD", 0x4 },
5693         },
5694 };
5695 /*
5696  * 2ch mode
5697  */
5698 static struct hda_verb alc882_3ST_ch2_init[] = {
5699         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5700         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5701         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5702         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5703         { } /* end */
5704 };
5705
5706 /*
5707  * 6ch mode
5708  */
5709 static struct hda_verb alc882_3ST_ch6_init[] = {
5710         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5711         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5712         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5713         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5714         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5715         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5716         { } /* end */
5717 };
5718
5719 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5720         { 2, alc882_3ST_ch2_init },
5721         { 6, alc882_3ST_ch6_init },
5722 };
5723
5724 /*
5725  * 6ch mode
5726  */
5727 static struct hda_verb alc882_sixstack_ch6_init[] = {
5728         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5729         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5730         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5731         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5732         { } /* end */
5733 };
5734
5735 /*
5736  * 8ch mode
5737  */
5738 static struct hda_verb alc882_sixstack_ch8_init[] = {
5739         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5740         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5741         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5742         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5743         { } /* end */
5744 };
5745
5746 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5747         { 6, alc882_sixstack_ch6_init },
5748         { 8, alc882_sixstack_ch8_init },
5749 };
5750
5751 /*
5752  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5753  */
5754
5755 /*
5756  * 2ch mode
5757  */
5758 static struct hda_verb alc885_mbp_ch2_init[] = {
5759         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5760         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5761         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5762         { } /* end */
5763 };
5764
5765 /*
5766  * 6ch mode
5767  */
5768 static struct hda_verb alc885_mbp_ch6_init[] = {
5769         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5770         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5771         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5772         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5773         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5774         { } /* end */
5775 };
5776
5777 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
5778         { 2, alc885_mbp_ch2_init },
5779         { 6, alc885_mbp_ch6_init },
5780 };
5781
5782
5783 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5784  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5785  */
5786 static struct snd_kcontrol_new alc882_base_mixer[] = {
5787         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5788         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5789         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5790         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5791         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5792         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5793         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5794         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5795         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5796         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5797         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5798         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5799         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5800         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5801         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5802         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5803         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5804         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5805         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5806         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5807         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5808         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5809         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5810         { } /* end */
5811 };
5812
5813 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5814         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5815         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
5816         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
5817         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
5818         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5819         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5820         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5821         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5822         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
5823         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5824         { } /* end */
5825 };
5826 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5827         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5828         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5829         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5830         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5831         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5832         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5833         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5834         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5835         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5836         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5837         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5838         { } /* end */
5839 };
5840
5841 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5842         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5843         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5844         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5845         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5846         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5847         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5848         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5849         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5850         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5851         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5852         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5853         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5854         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5855         { } /* end */
5856 };
5857
5858 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5859  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5860  */
5861 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5862         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5863         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5864         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5865         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5866         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5867         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5868         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5869         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5870         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5871         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5872         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5873         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5874         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5875         { } /* end */
5876 };
5877
5878 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5879         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5880         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5881         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5882         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5883         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5884         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5885         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5886         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5887         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5888         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5889         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5890         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5891         { } /* end */
5892 };
5893
5894 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5895         {
5896                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5897                 .name = "Channel Mode",
5898                 .info = alc_ch_mode_info,
5899                 .get = alc_ch_mode_get,
5900                 .put = alc_ch_mode_put,
5901         },
5902         { } /* end */
5903 };
5904
5905 static struct hda_verb alc882_init_verbs[] = {
5906         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5907         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5908         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5909         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5910         /* Rear mixer */
5911         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5912         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5913         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5914         /* CLFE mixer */
5915         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5916         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5917         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5918         /* Side mixer */
5919         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5920         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5921         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5922
5923         /* Front Pin: output 0 (0x0c) */
5924         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5925         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5926         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5927         /* Rear Pin: output 1 (0x0d) */
5928         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5929         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5930         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5931         /* CLFE Pin: output 2 (0x0e) */
5932         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5933         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5934         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5935         /* Side Pin: output 3 (0x0f) */
5936         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5937         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5938         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5939         /* Mic (rear) pin: input vref at 80% */
5940         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5941         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5942         /* Front Mic pin: input vref at 80% */
5943         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5944         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5945         /* Line In pin: input */
5946         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5947         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5948         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5949         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5950         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5951         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5952         /* CD pin widget for input */
5953         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5954
5955         /* FIXME: use matrix-type input source selection */
5956         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5957         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5958         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5959         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5960         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5961         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5962         /* Input mixer2 */
5963         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5964         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5965         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5966         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5967         /* Input mixer3 */
5968         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5969         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5970         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5971         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5972         /* ADC1: mute amp left and right */
5973         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5974         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5975         /* ADC2: mute amp left and right */
5976         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5977         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5978         /* ADC3: mute amp left and right */
5979         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5980         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5981
5982         { }
5983 };
5984
5985 static struct hda_verb alc882_eapd_verbs[] = {
5986         /* change to EAPD mode */
5987         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5988         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5989         { }
5990 };
5991
5992 /* Mac Pro test */
5993 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5994         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5995         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5996         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5997         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5998         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5999         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6000         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6001         { } /* end */
6002 };
6003
6004 static struct hda_verb alc882_macpro_init_verbs[] = {
6005         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6006         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6007         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6008         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6009         /* Front Pin: output 0 (0x0c) */
6010         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6011         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6012         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6013         /* Front Mic pin: input vref at 80% */
6014         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6015         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6016         /* Speaker:  output */
6017         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6018         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6019         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6020         /* Headphone output (output 0 - 0x0c) */
6021         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6022         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6023         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6024
6025         /* FIXME: use matrix-type input source selection */
6026         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6027         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6028         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6029         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6030         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6031         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6032         /* Input mixer2 */
6033         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6034         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6035         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6036         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6037         /* Input mixer3 */
6038         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6039         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6040         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6041         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6042         /* ADC1: mute amp left and right */
6043         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6044         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6045         /* ADC2: mute amp left and right */
6046         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6047         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6048         /* ADC3: mute amp left and right */
6049         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6050         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6051
6052         { }
6053 };
6054
6055 /* Macbook Pro rev3 */
6056 static struct hda_verb alc885_mbp3_init_verbs[] = {
6057         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6058         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6059         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6060         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6061         /* Rear mixer */
6062         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6063         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6064         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6065         /* Front Pin: output 0 (0x0c) */
6066         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6067         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6068         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6069         /* HP Pin: output 0 (0x0d) */
6070         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6071         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6072         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6073         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6074         /* Mic (rear) pin: input vref at 80% */
6075         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6076         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6077         /* Front Mic pin: input vref at 80% */
6078         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6079         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6080         /* Line In pin: use output 1 when in LineOut mode */
6081         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6082         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6083         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6084
6085         /* FIXME: use matrix-type input source selection */
6086         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6087         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6088         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6089         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6090         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6091         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6092         /* Input mixer2 */
6093         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6094         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6095         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6096         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6097         /* Input mixer3 */
6098         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6099         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6100         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6101         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6102         /* ADC1: mute amp left and right */
6103         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6104         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6105         /* ADC2: mute amp left and right */
6106         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6107         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6108         /* ADC3: mute amp left and right */
6109         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6110         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6111
6112         { }
6113 };
6114
6115 /* iMac 24 mixer. */
6116 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6117         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6118         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6119         { } /* end */
6120 };
6121
6122 /* iMac 24 init verbs. */
6123 static struct hda_verb alc885_imac24_init_verbs[] = {
6124         /* Internal speakers: output 0 (0x0c) */
6125         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6126         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6127         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6128         /* Internal speakers: output 0 (0x0c) */
6129         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6130         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6131         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6132         /* Headphone: output 0 (0x0c) */
6133         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6134         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6135         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6136         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6137         /* Front Mic: input vref at 80% */
6138         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6139         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6140         { }
6141 };
6142
6143 /* Toggle speaker-output according to the hp-jack state */
6144 static void alc885_imac24_automute(struct hda_codec *codec)
6145 {
6146         unsigned int present;
6147
6148         present = snd_hda_codec_read(codec, 0x14, 0,
6149                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6150         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6151                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6152         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6153                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6154 }
6155
6156 /* Processes unsolicited events. */
6157 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6158                                       unsigned int res)
6159 {
6160         /* Headphone insertion or removal. */
6161         if ((res >> 26) == ALC880_HP_EVENT)
6162                 alc885_imac24_automute(codec);
6163 }
6164
6165 static void alc885_mbp3_automute(struct hda_codec *codec)
6166 {
6167         unsigned int present;
6168
6169         present = snd_hda_codec_read(codec, 0x15, 0,
6170                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6171         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6172                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6173         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6174                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6175
6176 }
6177 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6178                                     unsigned int res)
6179 {
6180         /* Headphone insertion or removal. */
6181         if ((res >> 26) == ALC880_HP_EVENT)
6182                 alc885_mbp3_automute(codec);
6183 }
6184
6185
6186 static struct hda_verb alc882_targa_verbs[] = {
6187         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6188         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6189
6190         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6191         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6192
6193         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6194         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6195         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6196
6197         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6198         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6199         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6200         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6201         { } /* end */
6202 };
6203
6204 /* toggle speaker-output according to the hp-jack state */
6205 static void alc882_targa_automute(struct hda_codec *codec)
6206 {
6207         unsigned int present;
6208
6209         present = snd_hda_codec_read(codec, 0x14, 0,
6210                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6211         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6212                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6213         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6214                                   present ? 1 : 3);
6215 }
6216
6217 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6218 {
6219         /* Looks like the unsol event is incompatible with the standard
6220          * definition.  4bit tag is placed at 26 bit!
6221          */
6222         if (((res >> 26) == ALC880_HP_EVENT)) {
6223                 alc882_targa_automute(codec);
6224         }
6225 }
6226
6227 static struct hda_verb alc882_asus_a7j_verbs[] = {
6228         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6229         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6230
6231         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6232         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6233         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6234
6235         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6236         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6237         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6238
6239         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6240         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6241         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6242         { } /* end */
6243 };
6244
6245 static struct hda_verb alc882_asus_a7m_verbs[] = {
6246         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6247         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6248
6249         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6250         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6251         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6252
6253         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6254         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6255         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6256
6257         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6258         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6259         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6260         { } /* end */
6261 };
6262
6263 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6264 {
6265         unsigned int gpiostate, gpiomask, gpiodir;
6266
6267         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6268                                        AC_VERB_GET_GPIO_DATA, 0);
6269
6270         if (!muted)
6271                 gpiostate |= (1 << pin);
6272         else
6273                 gpiostate &= ~(1 << pin);
6274
6275         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6276                                       AC_VERB_GET_GPIO_MASK, 0);
6277         gpiomask |= (1 << pin);
6278
6279         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6280                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6281         gpiodir |= (1 << pin);
6282
6283
6284         snd_hda_codec_write(codec, codec->afg, 0,
6285                             AC_VERB_SET_GPIO_MASK, gpiomask);
6286         snd_hda_codec_write(codec, codec->afg, 0,
6287                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6288
6289         msleep(1);
6290
6291         snd_hda_codec_write(codec, codec->afg, 0,
6292                             AC_VERB_SET_GPIO_DATA, gpiostate);
6293 }
6294
6295 /* set up GPIO at initialization */
6296 static void alc885_macpro_init_hook(struct hda_codec *codec)
6297 {
6298         alc882_gpio_mute(codec, 0, 0);
6299         alc882_gpio_mute(codec, 1, 0);
6300 }
6301
6302 /* set up GPIO and update auto-muting at initialization */
6303 static void alc885_imac24_init_hook(struct hda_codec *codec)
6304 {
6305         alc885_macpro_init_hook(codec);
6306         alc885_imac24_automute(codec);
6307 }
6308
6309 /*
6310  * generic initialization of ADC, input mixers and output mixers
6311  */
6312 static struct hda_verb alc882_auto_init_verbs[] = {
6313         /*
6314          * Unmute ADC0-2 and set the default input to mic-in
6315          */
6316         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6317         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6318         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6319         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6320         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6321         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6322
6323         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6324          * mixer widget
6325          * Note: PASD motherboards uses the Line In 2 as the input for
6326          * front panel mic (mic 2)
6327          */
6328         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6329         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6330         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6331         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6332         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6333         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6334
6335         /*
6336          * Set up output mixers (0x0c - 0x0f)
6337          */
6338         /* set vol=0 to output mixers */
6339         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6340         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6341         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6342         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6343         /* set up input amps for analog loopback */
6344         /* Amp Indices: DAC = 0, mixer = 1 */
6345         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6346         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6347         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6348         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6349         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6350         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6351         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6352         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6353         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6354         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6355
6356         /* FIXME: use matrix-type input source selection */
6357         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6358         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6359         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6360         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6361         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6362         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6363         /* Input mixer2 */
6364         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6365         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6366         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6367         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6368         /* Input mixer3 */
6369         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6370         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6371         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6372         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6373
6374         { }
6375 };
6376
6377 #ifdef CONFIG_SND_HDA_POWER_SAVE
6378 #define alc882_loopbacks        alc880_loopbacks
6379 #endif
6380
6381 /* pcm configuration: identiacal with ALC880 */
6382 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6383 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6384 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6385 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6386
6387 /*
6388  * configuration and preset
6389  */
6390 static const char *alc882_models[ALC882_MODEL_LAST] = {
6391         [ALC882_3ST_DIG]        = "3stack-dig",
6392         [ALC882_6ST_DIG]        = "6stack-dig",
6393         [ALC882_ARIMA]          = "arima",
6394         [ALC882_W2JC]           = "w2jc",
6395         [ALC882_TARGA]          = "targa",
6396         [ALC882_ASUS_A7J]       = "asus-a7j",
6397         [ALC882_ASUS_A7M]       = "asus-a7m",
6398         [ALC885_MACPRO]         = "macpro",
6399         [ALC885_MBP3]           = "mbp3",
6400         [ALC885_IMAC24]         = "imac24",
6401         [ALC882_AUTO]           = "auto",
6402 };
6403
6404 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6405         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6406         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6407         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6408         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6409         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6410         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6411         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6412         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6413         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6414         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6415         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6416         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6417         {}
6418 };
6419
6420 static struct alc_config_preset alc882_presets[] = {
6421         [ALC882_3ST_DIG] = {
6422                 .mixers = { alc882_base_mixer },
6423                 .init_verbs = { alc882_init_verbs },
6424                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6425                 .dac_nids = alc882_dac_nids,
6426                 .dig_out_nid = ALC882_DIGOUT_NID,
6427                 .dig_in_nid = ALC882_DIGIN_NID,
6428                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6429                 .channel_mode = alc882_ch_modes,
6430                 .need_dac_fix = 1,
6431                 .input_mux = &alc882_capture_source,
6432         },
6433         [ALC882_6ST_DIG] = {
6434                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6435                 .init_verbs = { alc882_init_verbs },
6436                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6437                 .dac_nids = alc882_dac_nids,
6438                 .dig_out_nid = ALC882_DIGOUT_NID,
6439                 .dig_in_nid = ALC882_DIGIN_NID,
6440                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6441                 .channel_mode = alc882_sixstack_modes,
6442                 .input_mux = &alc882_capture_source,
6443         },
6444         [ALC882_ARIMA] = {
6445                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6446                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6447                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6448                 .dac_nids = alc882_dac_nids,
6449                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6450                 .channel_mode = alc882_sixstack_modes,
6451                 .input_mux = &alc882_capture_source,
6452         },
6453         [ALC882_W2JC] = {
6454                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6455                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6456                                 alc880_gpio1_init_verbs },
6457                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6458                 .dac_nids = alc882_dac_nids,
6459                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6460                 .channel_mode = alc880_threestack_modes,
6461                 .need_dac_fix = 1,
6462                 .input_mux = &alc882_capture_source,
6463                 .dig_out_nid = ALC882_DIGOUT_NID,
6464         },
6465         [ALC885_MBP3] = {
6466                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6467                 .init_verbs = { alc885_mbp3_init_verbs,
6468                                 alc880_gpio1_init_verbs },
6469                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6470                 .dac_nids = alc882_dac_nids,
6471                 .channel_mode = alc885_mbp_6ch_modes,
6472                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6473                 .input_mux = &alc882_capture_source,
6474                 .dig_out_nid = ALC882_DIGOUT_NID,
6475                 .dig_in_nid = ALC882_DIGIN_NID,
6476                 .unsol_event = alc885_mbp3_unsol_event,
6477                 .init_hook = alc885_mbp3_automute,
6478         },
6479         [ALC885_MACPRO] = {
6480                 .mixers = { alc882_macpro_mixer },
6481                 .init_verbs = { alc882_macpro_init_verbs },
6482                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6483                 .dac_nids = alc882_dac_nids,
6484                 .dig_out_nid = ALC882_DIGOUT_NID,
6485                 .dig_in_nid = ALC882_DIGIN_NID,
6486                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6487                 .channel_mode = alc882_ch_modes,
6488                 .input_mux = &alc882_capture_source,
6489                 .init_hook = alc885_macpro_init_hook,
6490         },
6491         [ALC885_IMAC24] = {
6492                 .mixers = { alc885_imac24_mixer },
6493                 .init_verbs = { alc885_imac24_init_verbs },
6494                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6495                 .dac_nids = alc882_dac_nids,
6496                 .dig_out_nid = ALC882_DIGOUT_NID,
6497                 .dig_in_nid = ALC882_DIGIN_NID,
6498                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6499                 .channel_mode = alc882_ch_modes,
6500                 .input_mux = &alc882_capture_source,
6501                 .unsol_event = alc885_imac24_unsol_event,
6502                 .init_hook = alc885_imac24_init_hook,
6503         },
6504         [ALC882_TARGA] = {
6505                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
6506                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6507                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6508                 .dac_nids = alc882_dac_nids,
6509                 .dig_out_nid = ALC882_DIGOUT_NID,
6510                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6511                 .adc_nids = alc882_adc_nids,
6512                 .capsrc_nids = alc882_capsrc_nids,
6513                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6514                 .channel_mode = alc882_3ST_6ch_modes,
6515                 .need_dac_fix = 1,
6516                 .input_mux = &alc882_capture_source,
6517                 .unsol_event = alc882_targa_unsol_event,
6518                 .init_hook = alc882_targa_automute,
6519         },
6520         [ALC882_ASUS_A7J] = {
6521                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
6522                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6523                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6524                 .dac_nids = alc882_dac_nids,
6525                 .dig_out_nid = ALC882_DIGOUT_NID,
6526                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6527                 .adc_nids = alc882_adc_nids,
6528                 .capsrc_nids = alc882_capsrc_nids,
6529                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6530                 .channel_mode = alc882_3ST_6ch_modes,
6531                 .need_dac_fix = 1,
6532                 .input_mux = &alc882_capture_source,
6533         },
6534         [ALC882_ASUS_A7M] = {
6535                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6536                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6537                                 alc880_gpio1_init_verbs,
6538                                 alc882_asus_a7m_verbs },
6539                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6540                 .dac_nids = alc882_dac_nids,
6541                 .dig_out_nid = ALC882_DIGOUT_NID,
6542                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6543                 .channel_mode = alc880_threestack_modes,
6544                 .need_dac_fix = 1,
6545                 .input_mux = &alc882_capture_source,
6546         },
6547 };
6548
6549
6550 /*
6551  * Pin config fixes
6552  */
6553 enum {
6554         PINFIX_ABIT_AW9D_MAX
6555 };
6556
6557 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6558         { 0x15, 0x01080104 }, /* side */
6559         { 0x16, 0x01011012 }, /* rear */
6560         { 0x17, 0x01016011 }, /* clfe */
6561         { }
6562 };
6563
6564 static const struct alc_pincfg *alc882_pin_fixes[] = {
6565         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6566 };
6567
6568 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6569         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6570         {}
6571 };
6572
6573 /*
6574  * BIOS auto configuration
6575  */
6576 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6577                                               hda_nid_t nid, int pin_type,
6578                                               int dac_idx)
6579 {
6580         /* set as output */
6581         struct alc_spec *spec = codec->spec;
6582         int idx;
6583
6584         alc_set_pin_output(codec, nid, pin_type);
6585         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6586                 idx = 4;
6587         else
6588                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6589         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6590
6591 }
6592
6593 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6594 {
6595         struct alc_spec *spec = codec->spec;
6596         int i;
6597
6598         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6599         for (i = 0; i <= HDA_SIDE; i++) {
6600                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6601                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6602                 if (nid)
6603                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6604                                                           i);
6605         }
6606 }
6607
6608 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6609 {
6610         struct alc_spec *spec = codec->spec;
6611         hda_nid_t pin;
6612
6613         pin = spec->autocfg.hp_pins[0];
6614         if (pin) /* connect to front */
6615                 /* use dac 0 */
6616                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6617         pin = spec->autocfg.speaker_pins[0];
6618         if (pin)
6619                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6620 }
6621
6622 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6623 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6624
6625 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6626 {
6627         struct alc_spec *spec = codec->spec;
6628         int i;
6629
6630         for (i = 0; i < AUTO_PIN_LAST; i++) {
6631                 hda_nid_t nid = spec->autocfg.input_pins[i];
6632                 unsigned int vref;
6633                 if (!nid)
6634                         continue;
6635                 vref = PIN_IN;
6636                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6637                         unsigned int pincap;
6638                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6639                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6640                             AC_PINCAP_VREF_80)
6641                                 vref = PIN_VREF80;
6642                 }
6643                 snd_hda_codec_write(codec, nid, 0,
6644                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6645                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6646                         snd_hda_codec_write(codec, nid, 0,
6647                                             AC_VERB_SET_AMP_GAIN_MUTE,
6648                                             AMP_OUT_MUTE);
6649         }
6650 }
6651
6652 static void alc882_auto_init_input_src(struct hda_codec *codec)
6653 {
6654         struct alc_spec *spec = codec->spec;
6655         const struct hda_input_mux *imux = spec->input_mux;
6656         int c;
6657
6658         for (c = 0; c < spec->num_adc_nids; c++) {
6659                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6660                 hda_nid_t nid = spec->capsrc_nids[c];
6661                 int conns, mute, idx, item;
6662
6663                 conns = snd_hda_get_connections(codec, nid, conn_list,
6664                                                 ARRAY_SIZE(conn_list));
6665                 if (conns < 0)
6666                         continue;
6667                 for (idx = 0; idx < conns; idx++) {
6668                         /* if the current connection is the selected one,
6669                          * unmute it as default - otherwise mute it
6670                          */
6671                         mute = AMP_IN_MUTE(idx);
6672                         for (item = 0; item < imux->num_items; item++) {
6673                                 if (imux->items[item].index == idx) {
6674                                         if (spec->cur_mux[c] == item)
6675                                                 mute = AMP_IN_UNMUTE(idx);
6676                                         break;
6677                                 }
6678                         }
6679                         snd_hda_codec_write(codec, nid, 0,
6680                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6681                 }
6682         }
6683 }
6684
6685 /* add mic boosts if needed */
6686 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6687 {
6688         struct alc_spec *spec = codec->spec;
6689         int err;
6690         hda_nid_t nid;
6691
6692         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6693         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6694                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6695                                   "Mic Boost",
6696                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6697                 if (err < 0)
6698                         return err;
6699         }
6700         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6701         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6702                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6703                                   "Front Mic Boost",
6704                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6705                 if (err < 0)
6706                         return err;
6707         }
6708         return 0;
6709 }
6710
6711 /* almost identical with ALC880 parser... */
6712 static int alc882_parse_auto_config(struct hda_codec *codec)
6713 {
6714         struct alc_spec *spec = codec->spec;
6715         int err = alc880_parse_auto_config(codec);
6716
6717         if (err < 0)
6718                 return err;
6719         else if (!err)
6720                 return 0; /* no config found */
6721
6722         err = alc_auto_add_mic_boost(codec);
6723         if (err < 0)
6724                 return err;
6725
6726         /* hack - override the init verbs */
6727         spec->init_verbs[0] = alc882_auto_init_verbs;
6728
6729         return 1; /* config found */
6730 }
6731
6732 /* additional initialization for auto-configuration model */
6733 static void alc882_auto_init(struct hda_codec *codec)
6734 {
6735         struct alc_spec *spec = codec->spec;
6736         alc882_auto_init_multi_out(codec);
6737         alc882_auto_init_hp_out(codec);
6738         alc882_auto_init_analog_input(codec);
6739         alc882_auto_init_input_src(codec);
6740         if (spec->unsol_event)
6741                 alc_inithook(codec);
6742 }
6743
6744 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6745
6746 static int patch_alc882(struct hda_codec *codec)
6747 {
6748         struct alc_spec *spec;
6749         int err, board_config;
6750
6751         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6752         if (spec == NULL)
6753                 return -ENOMEM;
6754
6755         codec->spec = spec;
6756
6757         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6758                                                   alc882_models,
6759                                                   alc882_cfg_tbl);
6760
6761         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6762                 /* Pick up systems that don't supply PCI SSID */
6763                 switch (codec->subsystem_id) {
6764                 case 0x106b0c00: /* Mac Pro */
6765                         board_config = ALC885_MACPRO;
6766                         break;
6767                 case 0x106b1000: /* iMac 24 */
6768                 case 0x106b2800: /* AppleTV */
6769                         board_config = ALC885_IMAC24;
6770                         break;
6771                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
6772                 case 0x106b00a4: /* MacbookPro4,1 */
6773                 case 0x106b2c00: /* Macbook Pro rev3 */
6774                 case 0x106b3600: /* Macbook 3.1 */
6775                         board_config = ALC885_MBP3;
6776                         break;
6777                 default:
6778                         /* ALC889A is handled better as ALC888-compatible */
6779                         if (codec->revision_id == 0x100101 ||
6780                             codec->revision_id == 0x100103) {
6781                                 alc_free(codec);
6782                                 return patch_alc883(codec);
6783                         }
6784                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6785                                          "trying auto-probe from BIOS...\n");
6786                         board_config = ALC882_AUTO;
6787                 }
6788         }
6789
6790         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6791
6792         if (board_config == ALC882_AUTO) {
6793                 /* automatic parse from the BIOS config */
6794                 err = alc882_parse_auto_config(codec);
6795                 if (err < 0) {
6796                         alc_free(codec);
6797                         return err;
6798                 } else if (!err) {
6799                         printk(KERN_INFO
6800                                "hda_codec: Cannot set up configuration "
6801                                "from BIOS.  Using base mode...\n");
6802                         board_config = ALC882_3ST_DIG;
6803                 }
6804         }
6805
6806         if (board_config != ALC882_AUTO)
6807                 setup_preset(spec, &alc882_presets[board_config]);
6808
6809         if (codec->vendor_id == 0x10ec0885) {
6810                 spec->stream_name_analog = "ALC885 Analog";
6811                 spec->stream_name_digital = "ALC885 Digital";
6812         } else {
6813                 spec->stream_name_analog = "ALC882 Analog";
6814                 spec->stream_name_digital = "ALC882 Digital";
6815         }
6816
6817         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6818         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6819         /* FIXME: setup DAC5 */
6820         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
6821         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6822
6823         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6824         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6825
6826         spec->is_mix_capture = 1; /* matrix-style capture */
6827         if (!spec->adc_nids && spec->input_mux) {
6828                 /* check whether NID 0x07 is valid */
6829                 unsigned int wcap = get_wcaps(codec, 0x07);
6830                 /* get type */
6831                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6832                 if (wcap != AC_WID_AUD_IN) {
6833                         spec->adc_nids = alc882_adc_nids_alt;
6834                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6835                         spec->capsrc_nids = alc882_capsrc_nids_alt;
6836                 } else {
6837                         spec->adc_nids = alc882_adc_nids;
6838                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6839                         spec->capsrc_nids = alc882_capsrc_nids;
6840                 }
6841         }
6842         set_capture_mixer(spec);
6843
6844         spec->vmaster_nid = 0x0c;
6845
6846         codec->patch_ops = alc_patch_ops;
6847         if (board_config == ALC882_AUTO)
6848                 spec->init_hook = alc882_auto_init;
6849 #ifdef CONFIG_SND_HDA_POWER_SAVE
6850         if (!spec->loopback.amplist)
6851                 spec->loopback.amplist = alc882_loopbacks;
6852 #endif
6853
6854         return 0;
6855 }
6856
6857 /*
6858  * ALC883 support
6859  *
6860  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6861  * configuration.  Each pin widget can choose any input DACs and a mixer.
6862  * Each ADC is connected from a mixer of all inputs.  This makes possible
6863  * 6-channel independent captures.
6864  *
6865  * In addition, an independent DAC for the multi-playback (not used in this
6866  * driver yet).
6867  */
6868 #define ALC883_DIGOUT_NID       0x06
6869 #define ALC883_DIGIN_NID        0x0a
6870
6871 static hda_nid_t alc883_dac_nids[4] = {
6872         /* front, rear, clfe, rear_surr */
6873         0x02, 0x03, 0x04, 0x05
6874 };
6875
6876 static hda_nid_t alc883_adc_nids[2] = {
6877         /* ADC1-2 */
6878         0x08, 0x09,
6879 };
6880
6881 static hda_nid_t alc883_adc_nids_alt[1] = {
6882         /* ADC1 */
6883         0x08,
6884 };
6885
6886 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6887
6888 /* input MUX */
6889 /* FIXME: should be a matrix-type input source selection */
6890
6891 static struct hda_input_mux alc883_capture_source = {
6892         .num_items = 4,
6893         .items = {
6894                 { "Mic", 0x0 },
6895                 { "Front Mic", 0x1 },
6896                 { "Line", 0x2 },
6897                 { "CD", 0x4 },
6898         },
6899 };
6900
6901 static struct hda_input_mux alc883_3stack_6ch_intel = {
6902         .num_items = 4,
6903         .items = {
6904                 { "Mic", 0x1 },
6905                 { "Front Mic", 0x0 },
6906                 { "Line", 0x2 },
6907                 { "CD", 0x4 },
6908         },
6909 };
6910
6911 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6912         .num_items = 2,
6913         .items = {
6914                 { "Mic", 0x1 },
6915                 { "Line", 0x2 },
6916         },
6917 };
6918
6919 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6920         .num_items = 4,
6921         .items = {
6922                 { "Mic", 0x0 },
6923                 { "iMic", 0x1 },
6924                 { "Line", 0x2 },
6925                 { "CD", 0x4 },
6926         },
6927 };
6928
6929 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6930         .num_items = 2,
6931         .items = {
6932                 { "Mic", 0x0 },
6933                 { "Int Mic", 0x1 },
6934         },
6935 };
6936
6937 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
6938         .num_items = 3,
6939         .items = {
6940                 { "Mic", 0x0 },
6941                 { "Front Mic", 0x1 },
6942                 { "Line", 0x4 },
6943         },
6944 };
6945
6946 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
6947         .num_items = 2,
6948         .items = {
6949                 { "Mic", 0x0 },
6950                 { "Line", 0x2 },
6951         },
6952 };
6953
6954 /*
6955  * 2ch mode
6956  */
6957 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6958         { 2, NULL }
6959 };
6960
6961 /*
6962  * 2ch mode
6963  */
6964 static struct hda_verb alc883_3ST_ch2_init[] = {
6965         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6966         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6967         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6968         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6969         { } /* end */
6970 };
6971
6972 /*
6973  * 4ch mode
6974  */
6975 static struct hda_verb alc883_3ST_ch4_init[] = {
6976         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6977         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6978         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6979         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6980         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6981         { } /* end */
6982 };
6983
6984 /*
6985  * 6ch mode
6986  */
6987 static struct hda_verb alc883_3ST_ch6_init[] = {
6988         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6989         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6990         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6991         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6992         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6993         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6994         { } /* end */
6995 };
6996
6997 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6998         { 2, alc883_3ST_ch2_init },
6999         { 4, alc883_3ST_ch4_init },
7000         { 6, alc883_3ST_ch6_init },
7001 };
7002
7003 /*
7004  * 2ch mode
7005  */
7006 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7007         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7008         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7009         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7010         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7011         { } /* end */
7012 };
7013
7014 /*
7015  * 4ch mode
7016  */
7017 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7018         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7019         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7020         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7021         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7022         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7023         { } /* end */
7024 };
7025
7026 /*
7027  * 6ch mode
7028  */
7029 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7030         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7031         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7032         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7033         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7034         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7035         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7036         { } /* end */
7037 };
7038
7039 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7040         { 2, alc883_3ST_ch2_intel_init },
7041         { 4, alc883_3ST_ch4_intel_init },
7042         { 6, alc883_3ST_ch6_intel_init },
7043 };
7044
7045 /*
7046  * 6ch mode
7047  */
7048 static struct hda_verb alc883_sixstack_ch6_init[] = {
7049         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7050         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7051         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7052         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7053         { } /* end */
7054 };
7055
7056 /*
7057  * 8ch mode
7058  */
7059 static struct hda_verb alc883_sixstack_ch8_init[] = {
7060         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7061         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7062         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7063         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7064         { } /* end */
7065 };
7066
7067 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7068         { 6, alc883_sixstack_ch6_init },
7069         { 8, alc883_sixstack_ch8_init },
7070 };
7071
7072 static struct hda_verb alc883_medion_eapd_verbs[] = {
7073         /* eanable EAPD on medion laptop */
7074         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7075         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7076         { }
7077 };
7078
7079 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7080  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7081  */
7082
7083 static struct snd_kcontrol_new alc883_base_mixer[] = {
7084         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7085         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7086         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7087         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7088         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7089         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7090         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7091         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7092         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7093         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7094         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7095         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7096         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7097         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7098         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7099         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7100         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7101         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7102         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7103         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7104         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7105         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7106         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7107         { } /* end */
7108 };
7109
7110 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7111         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7112         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7113         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7114         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7115         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7116         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7117         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7118         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7119         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7120         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7121         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7122         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7123         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7124         { } /* end */
7125 };
7126
7127 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7128         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7129         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7130         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7131         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7132         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7133         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7134         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7135         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7136         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7137         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7138         { } /* end */
7139 };
7140
7141 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7142         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7143         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7144         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7145         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7146         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7147         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7148         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7149         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7150         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7151         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7152         { } /* end */
7153 };
7154
7155 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7156         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7157         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7158         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7159         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7160         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7161         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7162         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7163         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7164         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7165         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7166         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7167         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7168         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7169         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7170         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7171         { } /* end */
7172 };
7173
7174 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7175         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7176         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7177         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7178         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7179         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7180         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7181         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7182         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7183         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7184         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7185         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7186         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7187         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7188         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7189         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7190         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7191         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7192         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7193         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7194         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7195         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7196         { } /* end */
7197 };
7198
7199 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7200         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7201         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7202         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7203         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7204         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7205                               HDA_OUTPUT),
7206         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7207         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7208         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7209         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7210         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7211         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7212         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7213         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7214         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7215         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7216         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7217         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7218         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7219         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7220         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7221         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7222         { } /* end */
7223 };
7224
7225 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7226         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7227         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7228         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7229         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7230         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7231         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7232         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7233         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7234         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7235         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7236         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7237         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7238         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7239         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7240         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7241         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7242         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7243         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7244         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7245         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7246         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7247         { } /* end */
7248 };
7249
7250 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7251         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7252         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7253         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7254         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7255         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7256         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7257         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7258         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7259         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7260         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7261         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7262         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7263         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7264         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7265         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7266         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7267         { } /* end */
7268 };
7269
7270 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7271         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7272         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7273         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7274         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7275         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7276         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7277         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7278         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7279         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7280         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7281         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7282         { } /* end */
7283 };
7284
7285 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7286         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7287         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7288         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7289         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7290         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7291         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7292         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7293         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7294         { } /* end */
7295 };
7296
7297 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7298         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7299         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7300         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7301         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7302         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7303         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7304         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7305         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7306         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7307         { } /* end */
7308 };
7309
7310 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7311         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7312         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7313         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7314         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7315         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7316         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7317         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7318         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7319         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7320         { } /* end */
7321 };
7322
7323 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7324         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7325         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7326         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7327         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7328         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7329         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7330         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7331         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7332         { } /* end */
7333 };
7334
7335 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7336         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7337         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7338         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7339         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7340         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7341                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7342         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7343         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7344         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7345         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7346         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7347         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7348         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7349         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7350         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7351         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7352         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7353         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7354         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7355         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7356         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7357         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7358         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7359         { } /* end */
7360 };
7361
7362 static struct hda_bind_ctls alc883_bind_cap_vol = {
7363         .ops = &snd_hda_bind_vol,
7364         .values = {
7365                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7366                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7367                 0
7368         },
7369 };
7370
7371 static struct hda_bind_ctls alc883_bind_cap_switch = {
7372         .ops = &snd_hda_bind_sw,
7373         .values = {
7374                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7375                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7376                 0
7377         },
7378 };
7379
7380 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7381         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7382         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7383         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7384         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7385         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7386         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7387         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7388         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7389         { } /* end */
7390 };
7391
7392 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
7393         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7394         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7395         {
7396                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7397                 /* .name = "Capture Source", */
7398                 .name = "Input Source",
7399                 .count = 1,
7400                 .info = alc_mux_enum_info,
7401                 .get = alc_mux_enum_get,
7402                 .put = alc_mux_enum_put,
7403         },
7404         { } /* end */
7405 };
7406
7407 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7408         {
7409                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7410                 .name = "Channel Mode",
7411                 .info = alc_ch_mode_info,
7412                 .get = alc_ch_mode_get,
7413                 .put = alc_ch_mode_put,
7414         },
7415         { } /* end */
7416 };
7417
7418 static struct hda_verb alc883_init_verbs[] = {
7419         /* ADC1: mute amp left and right */
7420         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7421         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7422         /* ADC2: mute amp left and right */
7423         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7424         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7425         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7426         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7427         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7428         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7429         /* Rear mixer */
7430         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7431         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7432         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7433         /* CLFE mixer */
7434         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7435         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7436         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7437         /* Side mixer */
7438         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7439         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7440         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7441
7442         /* mute analog input loopbacks */
7443         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7444         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7445         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7446         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7447         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7448
7449         /* Front Pin: output 0 (0x0c) */
7450         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7451         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7452         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7453         /* Rear Pin: output 1 (0x0d) */
7454         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7455         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7456         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7457         /* CLFE Pin: output 2 (0x0e) */
7458         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7459         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7460         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7461         /* Side Pin: output 3 (0x0f) */
7462         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7463         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7464         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7465         /* Mic (rear) pin: input vref at 80% */
7466         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7467         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7468         /* Front Mic pin: input vref at 80% */
7469         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7470         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7471         /* Line In pin: input */
7472         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7473         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7474         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7475         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7476         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7477         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7478         /* CD pin widget for input */
7479         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7480
7481         /* FIXME: use matrix-type input source selection */
7482         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7483         /* Input mixer2 */
7484         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7485         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7486         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7487         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7488         /* Input mixer3 */
7489         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7490         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7491         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7492         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7493         { }
7494 };
7495
7496 /* toggle speaker-output according to the hp-jack state */
7497 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7498 {
7499         unsigned int present;
7500
7501         present = snd_hda_codec_read(codec, 0x15, 0,
7502                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7503         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7504                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7505         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7506                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7507 }
7508
7509 /* auto-toggle front mic */
7510 /*
7511 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7512 {
7513         unsigned int present;
7514         unsigned char bits;
7515
7516         present = snd_hda_codec_read(codec, 0x18, 0,
7517                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7518         bits = present ? HDA_AMP_MUTE : 0;
7519         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7520 }
7521 */
7522
7523 static void alc883_mitac_automute(struct hda_codec *codec)
7524 {
7525         alc883_mitac_hp_automute(codec);
7526         /* alc883_mitac_mic_automute(codec); */
7527 }
7528
7529 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7530                                            unsigned int res)
7531 {
7532         switch (res >> 26) {
7533         case ALC880_HP_EVENT:
7534                 alc883_mitac_hp_automute(codec);
7535                 break;
7536         case ALC880_MIC_EVENT:
7537                 /* alc883_mitac_mic_automute(codec); */
7538                 break;
7539         }
7540 }
7541
7542 static struct hda_verb alc883_mitac_verbs[] = {
7543         /* HP */
7544         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7545         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7546         /* Subwoofer */
7547         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7548         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7549
7550         /* enable unsolicited event */
7551         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7552         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7553
7554         { } /* end */
7555 };
7556
7557 static struct hda_verb alc883_clevo_m720_verbs[] = {
7558         /* HP */
7559         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7560         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7561         /* Int speaker */
7562         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7563         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7564
7565         /* enable unsolicited event */
7566         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7567         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7568
7569         { } /* end */
7570 };
7571
7572 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7573         /* HP */
7574         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7575         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7576         /* Subwoofer */
7577         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7578         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7579
7580         /* enable unsolicited event */
7581         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7582
7583         { } /* end */
7584 };
7585
7586 static struct hda_verb alc883_tagra_verbs[] = {
7587         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7588         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7589
7590         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7591         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7592
7593         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7594         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7595         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7596
7597         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7598         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7599         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7600         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7601
7602         { } /* end */
7603 };
7604
7605 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7606         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7607         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7608         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7609         { } /* end */
7610 };
7611
7612 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7613         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7614         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7615         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7616         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7617         { } /* end */
7618 };
7619
7620 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7621         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7622         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7623         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7624         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7625         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7626         { } /* end */
7627 };
7628
7629 static struct hda_verb alc883_haier_w66_verbs[] = {
7630         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7631         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7632
7633         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7634
7635         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7636         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7637         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7638         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7639         { } /* end */
7640 };
7641
7642 static struct hda_verb alc888_lenovo_sky_verbs[] = {
7643         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7644         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7645         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7646         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7647         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7648         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7649         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7650         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7651         { } /* end */
7652 };
7653
7654 static struct hda_verb alc888_3st_hp_verbs[] = {
7655         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7656         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7657         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7658         { }
7659 };
7660
7661 static struct hda_verb alc888_6st_dell_verbs[] = {
7662         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7663         { }
7664 };
7665
7666 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7667         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7668         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7669         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7670         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7671         { }
7672 };
7673
7674 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7675         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7676         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7677         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7678         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7679         { }
7680 };
7681
7682 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7683         { 2, alc888_3st_hp_2ch_init },
7684         { 6, alc888_3st_hp_6ch_init },
7685 };
7686
7687 /* toggle front-jack and RCA according to the hp-jack state */
7688 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7689 {
7690         unsigned int present;
7691
7692         present = snd_hda_codec_read(codec, 0x1b, 0,
7693                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7694         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7695                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7696         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7697                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7698 }
7699
7700 /* toggle RCA according to the front-jack state */
7701 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7702 {
7703         unsigned int present;
7704
7705         present = snd_hda_codec_read(codec, 0x14, 0,
7706                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7707         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7708                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7709 }
7710
7711 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7712                                              unsigned int res)
7713 {
7714         if ((res >> 26) == ALC880_HP_EVENT)
7715                 alc888_lenovo_ms7195_front_automute(codec);
7716         if ((res >> 26) == ALC880_FRONT_EVENT)
7717                 alc888_lenovo_ms7195_rca_automute(codec);
7718 }
7719
7720 static struct hda_verb alc883_medion_md2_verbs[] = {
7721         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7722         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7723
7724         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7725
7726         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7727         { } /* end */
7728 };
7729
7730 /* toggle speaker-output according to the hp-jack state */
7731 static void alc883_medion_md2_automute(struct hda_codec *codec)
7732 {
7733         unsigned int present;
7734
7735         present = snd_hda_codec_read(codec, 0x14, 0,
7736                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7737         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7738                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7739 }
7740
7741 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7742                                           unsigned int res)
7743 {
7744         if ((res >> 26) == ALC880_HP_EVENT)
7745                 alc883_medion_md2_automute(codec);
7746 }
7747
7748 /* toggle speaker-output according to the hp-jack state */
7749 static void alc883_tagra_automute(struct hda_codec *codec)
7750 {
7751         unsigned int present;
7752         unsigned char bits;
7753
7754         present = snd_hda_codec_read(codec, 0x14, 0,
7755                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7756         bits = present ? HDA_AMP_MUTE : 0;
7757         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7758                                  HDA_AMP_MUTE, bits);
7759         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7760                                   present ? 1 : 3);
7761 }
7762
7763 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7764 {
7765         if ((res >> 26) == ALC880_HP_EVENT)
7766                 alc883_tagra_automute(codec);
7767 }
7768
7769 /* toggle speaker-output according to the hp-jack state */
7770 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7771 {
7772         unsigned int present;
7773         unsigned char bits;
7774
7775         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7776                 & AC_PINSENSE_PRESENCE;
7777         bits = present ? HDA_AMP_MUTE : 0;
7778         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7779                                  HDA_AMP_MUTE, bits);
7780 }
7781
7782 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7783 {
7784         unsigned int present;
7785
7786         present = snd_hda_codec_read(codec, 0x18, 0,
7787                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7788         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7789                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7790 }
7791
7792 static void alc883_clevo_m720_automute(struct hda_codec *codec)
7793 {
7794         alc883_clevo_m720_hp_automute(codec);
7795         alc883_clevo_m720_mic_automute(codec);
7796 }
7797
7798 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7799                                            unsigned int res)
7800 {
7801         switch (res >> 26) {
7802         case ALC880_HP_EVENT:
7803                 alc883_clevo_m720_hp_automute(codec);
7804                 break;
7805         case ALC880_MIC_EVENT:
7806                 alc883_clevo_m720_mic_automute(codec);
7807                 break;
7808         }
7809 }
7810
7811 /* toggle speaker-output according to the hp-jack state */
7812 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7813 {
7814         unsigned int present;
7815         unsigned char bits;
7816
7817         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7818                 & AC_PINSENSE_PRESENCE;
7819         bits = present ? HDA_AMP_MUTE : 0;
7820         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7821                                  HDA_AMP_MUTE, bits);
7822 }
7823
7824 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7825                                                   unsigned int res)
7826 {
7827         if ((res >> 26) == ALC880_HP_EVENT)
7828                 alc883_2ch_fujitsu_pi2515_automute(codec);
7829 }
7830
7831 static void alc883_haier_w66_automute(struct hda_codec *codec)
7832 {
7833         unsigned int present;
7834         unsigned char bits;
7835
7836         present = snd_hda_codec_read(codec, 0x1b, 0,
7837                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7838         bits = present ? 0x80 : 0;
7839         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7840                                  0x80, bits);
7841 }
7842
7843 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7844                                          unsigned int res)
7845 {
7846         if ((res >> 26) == ALC880_HP_EVENT)
7847                 alc883_haier_w66_automute(codec);
7848 }
7849
7850 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7851 {
7852         unsigned int present;
7853         unsigned char bits;
7854
7855         present = snd_hda_codec_read(codec, 0x14, 0,
7856                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7857         bits = present ? HDA_AMP_MUTE : 0;
7858         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7859                                  HDA_AMP_MUTE, bits);
7860 }
7861
7862 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7863 {
7864         unsigned int present;
7865         unsigned char bits;
7866
7867         present = snd_hda_codec_read(codec, 0x1b, 0,
7868                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7869         bits = present ? HDA_AMP_MUTE : 0;
7870         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7871                                  HDA_AMP_MUTE, bits);
7872         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7873                                  HDA_AMP_MUTE, bits);
7874 }
7875
7876 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7877                                            unsigned int res)
7878 {
7879         if ((res >> 26) == ALC880_HP_EVENT)
7880                 alc883_lenovo_101e_all_automute(codec);
7881         if ((res >> 26) == ALC880_FRONT_EVENT)
7882                 alc883_lenovo_101e_ispeaker_automute(codec);
7883 }
7884
7885 /* toggle speaker-output according to the hp-jack state */
7886 static void alc883_acer_aspire_automute(struct hda_codec *codec)
7887 {
7888         unsigned int present;
7889
7890         present = snd_hda_codec_read(codec, 0x14, 0,
7891                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7892         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7893                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7894         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7895                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7896 }
7897
7898 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
7899                                            unsigned int res)
7900 {
7901         if ((res >> 26) == ALC880_HP_EVENT)
7902                 alc883_acer_aspire_automute(codec);
7903 }
7904
7905 static struct hda_verb alc883_acer_eapd_verbs[] = {
7906         /* HP Pin: output 0 (0x0c) */
7907         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7908         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7909         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7910         /* Front Pin: output 0 (0x0c) */
7911         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7912         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7913         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7914         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
7915         /* eanable EAPD on medion laptop */
7916         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7917         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
7918         /* enable unsolicited event */
7919         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7920         { }
7921 };
7922
7923 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
7924 {
7925         unsigned int present;
7926
7927         present = snd_hda_codec_read(codec, 0x1b, 0,
7928                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7929         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7930                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7931         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7932                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7933         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7934                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7935         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7936                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7937 }
7938
7939 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
7940                                              unsigned int res)
7941 {
7942         switch (res >> 26) {
7943         case ALC880_HP_EVENT:
7944                 printk("hp_event\n");
7945                 alc888_6st_dell_front_automute(codec);
7946                 break;
7947         }
7948 }
7949
7950 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
7951 {
7952         unsigned int mute;
7953         unsigned int present;
7954
7955         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
7956         present = snd_hda_codec_read(codec, 0x1b, 0,
7957                                      AC_VERB_GET_PIN_SENSE, 0);
7958         present = (present & 0x80000000) != 0;
7959         if (present) {
7960                 /* mute internal speaker */
7961                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7962                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7963                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7964                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7965                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7966                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7967                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7968                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7969                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
7970                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7971         } else {
7972                 /* unmute internal speaker if necessary */
7973                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
7974                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7975                                          HDA_AMP_MUTE, mute);
7976                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7977                                          HDA_AMP_MUTE, mute);
7978                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7979                                          HDA_AMP_MUTE, mute);
7980                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7981                                          HDA_AMP_MUTE, mute);
7982                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
7983                                          HDA_AMP_MUTE, mute);
7984         }
7985 }
7986
7987 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
7988                                              unsigned int res)
7989 {
7990         if ((res >> 26) == ALC880_HP_EVENT)
7991                 alc888_lenovo_sky_front_automute(codec);
7992 }
7993
7994 /*
7995  * generic initialization of ADC, input mixers and output mixers
7996  */
7997 static struct hda_verb alc883_auto_init_verbs[] = {
7998         /*
7999          * Unmute ADC0-2 and set the default input to mic-in
8000          */
8001         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8002         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8003         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8004         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8005
8006         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8007          * mixer widget
8008          * Note: PASD motherboards uses the Line In 2 as the input for
8009          * front panel mic (mic 2)
8010          */
8011         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8012         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8013         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8014         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8015         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8016         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8017
8018         /*
8019          * Set up output mixers (0x0c - 0x0f)
8020          */
8021         /* set vol=0 to output mixers */
8022         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8023         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8024         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8025         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8026         /* set up input amps for analog loopback */
8027         /* Amp Indices: DAC = 0, mixer = 1 */
8028         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8029         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8030         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8031         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8032         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8033         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8034         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8035         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8036         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8037         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8038
8039         /* FIXME: use matrix-type input source selection */
8040         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8041         /* Input mixer1 */
8042         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8043         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8044         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8045         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8046         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8047         /* Input mixer2 */
8048         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8049         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8050         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8051         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8052         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8053
8054         { }
8055 };
8056
8057 static struct hda_verb alc888_asus_m90v_verbs[] = {
8058         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8059         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8060         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8061         /* enable unsolicited event */
8062         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8063         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8064         { } /* end */
8065 };
8066
8067 static void alc883_nb_mic_automute(struct hda_codec *codec)
8068 {
8069         unsigned int present;
8070
8071         present = snd_hda_codec_read(codec, 0x18, 0,
8072                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8073         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8074                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8075         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8076                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8077 }
8078
8079 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8080 {
8081         unsigned int present;
8082         unsigned char bits;
8083
8084         present = snd_hda_codec_read(codec, 0x1b, 0,
8085                                      AC_VERB_GET_PIN_SENSE, 0)
8086                 & AC_PINSENSE_PRESENCE;
8087         bits = present ? 0 : PIN_OUT;
8088         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8089                             bits);
8090         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8091                             bits);
8092         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8093                             bits);
8094 }
8095
8096 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8097                                            unsigned int res)
8098 {
8099         switch (res >> 26) {
8100         case ALC880_HP_EVENT:
8101                 alc883_M90V_speaker_automute(codec);
8102                 break;
8103         case ALC880_MIC_EVENT:
8104                 alc883_nb_mic_automute(codec);
8105                 break;
8106         }
8107 }
8108
8109 static void alc883_mode2_inithook(struct hda_codec *codec)
8110 {
8111         alc883_M90V_speaker_automute(codec);
8112         alc883_nb_mic_automute(codec);
8113 }
8114
8115 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8116         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8117         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8118         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8119         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8120         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8121         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8122         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8123         /* enable unsolicited event */
8124         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8125         { } /* end */
8126 };
8127
8128 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8129 {
8130         unsigned int present;
8131         unsigned char bits;
8132
8133         present = snd_hda_codec_read(codec, 0x14, 0,
8134                                      AC_VERB_GET_PIN_SENSE, 0)
8135                 & AC_PINSENSE_PRESENCE;
8136         bits = present ? 0 : PIN_OUT;
8137         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8138                             bits);
8139 }
8140
8141 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8142                                            unsigned int res)
8143 {
8144         switch (res >> 26) {
8145         case ALC880_HP_EVENT:
8146                 alc883_eee1601_speaker_automute(codec);
8147                 break;
8148         }
8149 }
8150
8151 static void alc883_eee1601_inithook(struct hda_codec *codec)
8152 {
8153         alc883_eee1601_speaker_automute(codec);
8154 }
8155
8156 #ifdef CONFIG_SND_HDA_POWER_SAVE
8157 #define alc883_loopbacks        alc880_loopbacks
8158 #endif
8159
8160 /* pcm configuration: identiacal with ALC880 */
8161 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8162 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8163 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8164 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8165 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8166
8167 /*
8168  * configuration and preset
8169  */
8170 static const char *alc883_models[ALC883_MODEL_LAST] = {
8171         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8172         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8173         [ALC883_3ST_6ch]        = "3stack-6ch",
8174         [ALC883_6ST_DIG]        = "6stack-dig",
8175         [ALC883_TARGA_DIG]      = "targa-dig",
8176         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8177         [ALC883_ACER]           = "acer",
8178         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8179         [ALC883_MEDION]         = "medion",
8180         [ALC883_MEDION_MD2]     = "medion-md2",
8181         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8182         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8183         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8184         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8185         [ALC888_LENOVO_SKY] = "lenovo-sky",
8186         [ALC883_HAIER_W66]      = "haier-w66",
8187         [ALC888_3ST_HP]         = "3stack-hp",
8188         [ALC888_6ST_DELL]       = "6stack-dell",
8189         [ALC883_MITAC]          = "mitac",
8190         [ALC883_CLEVO_M720]     = "clevo-m720",
8191         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8192         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8193         [ALC883_AUTO]           = "auto",
8194 };
8195
8196 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8197         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8198         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8199         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8200         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8201         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8202         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8203         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8204         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8205         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8206         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8207         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8208         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8209         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8210         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8211         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8212         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8213         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8214         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8215         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8216         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8217         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8218         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8219         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8220         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8221         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8222         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8223         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8224         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8225         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8226         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8227         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8228         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8229         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8230         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8231         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8232         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8233         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8234         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8235         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8236         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8237         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8238         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8239         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8240         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8241         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8242         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8243         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8244         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8245         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8246         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8247         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8248         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8249         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8250         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8251         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8252         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8253         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8254         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8255         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8256         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8257         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8258         {}
8259 };
8260
8261 static struct alc_config_preset alc883_presets[] = {
8262         [ALC883_3ST_2ch_DIG] = {
8263                 .mixers = { alc883_3ST_2ch_mixer },
8264                 .init_verbs = { alc883_init_verbs },
8265                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8266                 .dac_nids = alc883_dac_nids,
8267                 .dig_out_nid = ALC883_DIGOUT_NID,
8268                 .dig_in_nid = ALC883_DIGIN_NID,
8269                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8270                 .channel_mode = alc883_3ST_2ch_modes,
8271                 .input_mux = &alc883_capture_source,
8272         },
8273         [ALC883_3ST_6ch_DIG] = {
8274                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8275                 .init_verbs = { alc883_init_verbs },
8276                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8277                 .dac_nids = alc883_dac_nids,
8278                 .dig_out_nid = ALC883_DIGOUT_NID,
8279                 .dig_in_nid = ALC883_DIGIN_NID,
8280                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8281                 .channel_mode = alc883_3ST_6ch_modes,
8282                 .need_dac_fix = 1,
8283                 .input_mux = &alc883_capture_source,
8284         },
8285         [ALC883_3ST_6ch] = {
8286                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8287                 .init_verbs = { alc883_init_verbs },
8288                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8289                 .dac_nids = alc883_dac_nids,
8290                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8291                 .channel_mode = alc883_3ST_6ch_modes,
8292                 .need_dac_fix = 1,
8293                 .input_mux = &alc883_capture_source,
8294         },
8295         [ALC883_3ST_6ch_INTEL] = {
8296                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8297                 .init_verbs = { alc883_init_verbs },
8298                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8299                 .dac_nids = alc883_dac_nids,
8300                 .dig_out_nid = ALC883_DIGOUT_NID,
8301                 .dig_in_nid = ALC883_DIGIN_NID,
8302                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8303                 .channel_mode = alc883_3ST_6ch_intel_modes,
8304                 .need_dac_fix = 1,
8305                 .input_mux = &alc883_3stack_6ch_intel,
8306         },
8307         [ALC883_6ST_DIG] = {
8308                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8309                 .init_verbs = { alc883_init_verbs },
8310                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8311                 .dac_nids = alc883_dac_nids,
8312                 .dig_out_nid = ALC883_DIGOUT_NID,
8313                 .dig_in_nid = ALC883_DIGIN_NID,
8314                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8315                 .channel_mode = alc883_sixstack_modes,
8316                 .input_mux = &alc883_capture_source,
8317         },
8318         [ALC883_TARGA_DIG] = {
8319                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8320                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8321                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8322                 .dac_nids = alc883_dac_nids,
8323                 .dig_out_nid = ALC883_DIGOUT_NID,
8324                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8325                 .channel_mode = alc883_3ST_6ch_modes,
8326                 .need_dac_fix = 1,
8327                 .input_mux = &alc883_capture_source,
8328                 .unsol_event = alc883_tagra_unsol_event,
8329                 .init_hook = alc883_tagra_automute,
8330         },
8331         [ALC883_TARGA_2ch_DIG] = {
8332                 .mixers = { alc883_tagra_2ch_mixer},
8333                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8334                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8335                 .dac_nids = alc883_dac_nids,
8336                 .adc_nids = alc883_adc_nids_alt,
8337                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8338                 .dig_out_nid = ALC883_DIGOUT_NID,
8339                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8340                 .channel_mode = alc883_3ST_2ch_modes,
8341                 .input_mux = &alc883_capture_source,
8342                 .unsol_event = alc883_tagra_unsol_event,
8343                 .init_hook = alc883_tagra_automute,
8344         },
8345         [ALC883_ACER] = {
8346                 .mixers = { alc883_base_mixer },
8347                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8348                  * and the headphone jack.  Turn this on and rely on the
8349                  * standard mute methods whenever the user wants to turn
8350                  * these outputs off.
8351                  */
8352                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8353                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8354                 .dac_nids = alc883_dac_nids,
8355                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8356                 .channel_mode = alc883_3ST_2ch_modes,
8357                 .input_mux = &alc883_capture_source,
8358         },
8359         [ALC883_ACER_ASPIRE] = {
8360                 .mixers = { alc883_acer_aspire_mixer },
8361                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8362                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8363                 .dac_nids = alc883_dac_nids,
8364                 .dig_out_nid = ALC883_DIGOUT_NID,
8365                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8366                 .channel_mode = alc883_3ST_2ch_modes,
8367                 .input_mux = &alc883_capture_source,
8368                 .unsol_event = alc883_acer_aspire_unsol_event,
8369                 .init_hook = alc883_acer_aspire_automute,
8370         },
8371         [ALC883_MEDION] = {
8372                 .mixers = { alc883_fivestack_mixer,
8373                             alc883_chmode_mixer },
8374                 .init_verbs = { alc883_init_verbs,
8375                                 alc883_medion_eapd_verbs },
8376                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8377                 .dac_nids = alc883_dac_nids,
8378                 .adc_nids = alc883_adc_nids_alt,
8379                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8380                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8381                 .channel_mode = alc883_sixstack_modes,
8382                 .input_mux = &alc883_capture_source,
8383         },
8384         [ALC883_MEDION_MD2] = {
8385                 .mixers = { alc883_medion_md2_mixer},
8386                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8387                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8388                 .dac_nids = alc883_dac_nids,
8389                 .dig_out_nid = ALC883_DIGOUT_NID,
8390                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8391                 .channel_mode = alc883_3ST_2ch_modes,
8392                 .input_mux = &alc883_capture_source,
8393                 .unsol_event = alc883_medion_md2_unsol_event,
8394                 .init_hook = alc883_medion_md2_automute,
8395         },
8396         [ALC883_LAPTOP_EAPD] = {
8397                 .mixers = { alc883_base_mixer },
8398                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8399                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8400                 .dac_nids = alc883_dac_nids,
8401                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8402                 .channel_mode = alc883_3ST_2ch_modes,
8403                 .input_mux = &alc883_capture_source,
8404         },
8405         [ALC883_CLEVO_M720] = {
8406                 .mixers = { alc883_clevo_m720_mixer },
8407                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8408                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8409                 .dac_nids = alc883_dac_nids,
8410                 .dig_out_nid = ALC883_DIGOUT_NID,
8411                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8412                 .channel_mode = alc883_3ST_2ch_modes,
8413                 .input_mux = &alc883_capture_source,
8414                 .unsol_event = alc883_clevo_m720_unsol_event,
8415                 .init_hook = alc883_clevo_m720_automute,
8416         },
8417         [ALC883_LENOVO_101E_2ch] = {
8418                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8419                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8420                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8421                 .dac_nids = alc883_dac_nids,
8422                 .adc_nids = alc883_adc_nids_alt,
8423                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8424                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8425                 .channel_mode = alc883_3ST_2ch_modes,
8426                 .input_mux = &alc883_lenovo_101e_capture_source,
8427                 .unsol_event = alc883_lenovo_101e_unsol_event,
8428                 .init_hook = alc883_lenovo_101e_all_automute,
8429         },
8430         [ALC883_LENOVO_NB0763] = {
8431                 .mixers = { alc883_lenovo_nb0763_mixer },
8432                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8433                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8434                 .dac_nids = alc883_dac_nids,
8435                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8436                 .channel_mode = alc883_3ST_2ch_modes,
8437                 .need_dac_fix = 1,
8438                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8439                 .unsol_event = alc883_medion_md2_unsol_event,
8440                 .init_hook = alc883_medion_md2_automute,
8441         },
8442         [ALC888_LENOVO_MS7195_DIG] = {
8443                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8444                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8445                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8446                 .dac_nids = alc883_dac_nids,
8447                 .dig_out_nid = ALC883_DIGOUT_NID,
8448                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8449                 .channel_mode = alc883_3ST_6ch_modes,
8450                 .need_dac_fix = 1,
8451                 .input_mux = &alc883_capture_source,
8452                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8453                 .init_hook = alc888_lenovo_ms7195_front_automute,
8454         },
8455         [ALC883_HAIER_W66] = {
8456                 .mixers = { alc883_tagra_2ch_mixer},
8457                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8458                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8459                 .dac_nids = alc883_dac_nids,
8460                 .dig_out_nid = ALC883_DIGOUT_NID,
8461                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8462                 .channel_mode = alc883_3ST_2ch_modes,
8463                 .input_mux = &alc883_capture_source,
8464                 .unsol_event = alc883_haier_w66_unsol_event,
8465                 .init_hook = alc883_haier_w66_automute,
8466         },
8467         [ALC888_3ST_HP] = {
8468                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8469                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8470                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8471                 .dac_nids = alc883_dac_nids,
8472                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8473                 .channel_mode = alc888_3st_hp_modes,
8474                 .need_dac_fix = 1,
8475                 .input_mux = &alc883_capture_source,
8476         },
8477         [ALC888_6ST_DELL] = {
8478                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8479                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8480                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8481                 .dac_nids = alc883_dac_nids,
8482                 .dig_out_nid = ALC883_DIGOUT_NID,
8483                 .dig_in_nid = ALC883_DIGIN_NID,
8484                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8485                 .channel_mode = alc883_sixstack_modes,
8486                 .input_mux = &alc883_capture_source,
8487                 .unsol_event = alc888_6st_dell_unsol_event,
8488                 .init_hook = alc888_6st_dell_front_automute,
8489         },
8490         [ALC883_MITAC] = {
8491                 .mixers = { alc883_mitac_mixer },
8492                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8493                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8494                 .dac_nids = alc883_dac_nids,
8495                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8496                 .channel_mode = alc883_3ST_2ch_modes,
8497                 .input_mux = &alc883_capture_source,
8498                 .unsol_event = alc883_mitac_unsol_event,
8499                 .init_hook = alc883_mitac_automute,
8500         },
8501         [ALC883_FUJITSU_PI2515] = {
8502                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8503                 .init_verbs = { alc883_init_verbs,
8504                                 alc883_2ch_fujitsu_pi2515_verbs},
8505                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8506                 .dac_nids = alc883_dac_nids,
8507                 .dig_out_nid = ALC883_DIGOUT_NID,
8508                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8509                 .channel_mode = alc883_3ST_2ch_modes,
8510                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8511                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8512                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8513         },
8514         [ALC888_LENOVO_SKY] = {
8515                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8516                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8517                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8518                 .dac_nids = alc883_dac_nids,
8519                 .dig_out_nid = ALC883_DIGOUT_NID,
8520                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8521                 .channel_mode = alc883_sixstack_modes,
8522                 .need_dac_fix = 1,
8523                 .input_mux = &alc883_lenovo_sky_capture_source,
8524                 .unsol_event = alc883_lenovo_sky_unsol_event,
8525                 .init_hook = alc888_lenovo_sky_front_automute,
8526         },
8527         [ALC888_ASUS_M90V] = {
8528                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8529                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8530                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8531                 .dac_nids = alc883_dac_nids,
8532                 .dig_out_nid = ALC883_DIGOUT_NID,
8533                 .dig_in_nid = ALC883_DIGIN_NID,
8534                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8535                 .channel_mode = alc883_3ST_6ch_modes,
8536                 .need_dac_fix = 1,
8537                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8538                 .unsol_event = alc883_mode2_unsol_event,
8539                 .init_hook = alc883_mode2_inithook,
8540         },
8541         [ALC888_ASUS_EEE1601] = {
8542                 .mixers = { alc883_asus_eee1601_mixer },
8543                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
8544                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8545                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8546                 .dac_nids = alc883_dac_nids,
8547                 .dig_out_nid = ALC883_DIGOUT_NID,
8548                 .dig_in_nid = ALC883_DIGIN_NID,
8549                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8550                 .channel_mode = alc883_3ST_2ch_modes,
8551                 .need_dac_fix = 1,
8552                 .input_mux = &alc883_asus_eee1601_capture_source,
8553                 .unsol_event = alc883_eee1601_unsol_event,
8554                 .init_hook = alc883_eee1601_inithook,
8555         },
8556 };
8557
8558
8559 /*
8560  * BIOS auto configuration
8561  */
8562 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8563                                               hda_nid_t nid, int pin_type,
8564                                               int dac_idx)
8565 {
8566         /* set as output */
8567         struct alc_spec *spec = codec->spec;
8568         int idx;
8569
8570         alc_set_pin_output(codec, nid, pin_type);
8571         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8572                 idx = 4;
8573         else
8574                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8575         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8576
8577 }
8578
8579 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8580 {
8581         struct alc_spec *spec = codec->spec;
8582         int i;
8583
8584         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8585         for (i = 0; i <= HDA_SIDE; i++) {
8586                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8587                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8588                 if (nid)
8589                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8590                                                           i);
8591         }
8592 }
8593
8594 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8595 {
8596         struct alc_spec *spec = codec->spec;
8597         hda_nid_t pin;
8598
8599         pin = spec->autocfg.hp_pins[0];
8600         if (pin) /* connect to front */
8601                 /* use dac 0 */
8602                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8603         pin = spec->autocfg.speaker_pins[0];
8604         if (pin)
8605                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8606 }
8607
8608 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8609 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8610
8611 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8612 {
8613         struct alc_spec *spec = codec->spec;
8614         int i;
8615
8616         for (i = 0; i < AUTO_PIN_LAST; i++) {
8617                 hda_nid_t nid = spec->autocfg.input_pins[i];
8618                 if (alc883_is_input_pin(nid)) {
8619                         snd_hda_codec_write(codec, nid, 0,
8620                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8621                                             (i <= AUTO_PIN_FRONT_MIC ?
8622                                              PIN_VREF80 : PIN_IN));
8623                         if (nid != ALC883_PIN_CD_NID)
8624                                 snd_hda_codec_write(codec, nid, 0,
8625                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8626                                                     AMP_OUT_MUTE);
8627                 }
8628         }
8629 }
8630
8631 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8632
8633 /* almost identical with ALC880 parser... */
8634 static int alc883_parse_auto_config(struct hda_codec *codec)
8635 {
8636         struct alc_spec *spec = codec->spec;
8637         int err = alc880_parse_auto_config(codec);
8638
8639         if (err < 0)
8640                 return err;
8641         else if (!err)
8642                 return 0; /* no config found */
8643
8644         err = alc_auto_add_mic_boost(codec);
8645         if (err < 0)
8646                 return err;
8647
8648         /* hack - override the init verbs */
8649         spec->init_verbs[0] = alc883_auto_init_verbs;
8650
8651         return 1; /* config found */
8652 }
8653
8654 /* additional initialization for auto-configuration model */
8655 static void alc883_auto_init(struct hda_codec *codec)
8656 {
8657         struct alc_spec *spec = codec->spec;
8658         alc883_auto_init_multi_out(codec);
8659         alc883_auto_init_hp_out(codec);
8660         alc883_auto_init_analog_input(codec);
8661         alc883_auto_init_input_src(codec);
8662         if (spec->unsol_event)
8663                 alc_inithook(codec);
8664 }
8665
8666 static int patch_alc883(struct hda_codec *codec)
8667 {
8668         struct alc_spec *spec;
8669         int err, board_config;
8670
8671         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8672         if (spec == NULL)
8673                 return -ENOMEM;
8674
8675         codec->spec = spec;
8676
8677         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
8678
8679         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8680                                                   alc883_models,
8681                                                   alc883_cfg_tbl);
8682         if (board_config < 0) {
8683                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8684                        "trying auto-probe from BIOS...\n");
8685                 board_config = ALC883_AUTO;
8686         }
8687
8688         if (board_config == ALC883_AUTO) {
8689                 /* automatic parse from the BIOS config */
8690                 err = alc883_parse_auto_config(codec);
8691                 if (err < 0) {
8692                         alc_free(codec);
8693                         return err;
8694                 } else if (!err) {
8695                         printk(KERN_INFO
8696                                "hda_codec: Cannot set up configuration "
8697                                "from BIOS.  Using base mode...\n");
8698                         board_config = ALC883_3ST_2ch_DIG;
8699                 }
8700         }
8701
8702         if (board_config != ALC883_AUTO)
8703                 setup_preset(spec, &alc883_presets[board_config]);
8704
8705         switch (codec->vendor_id) {
8706         case 0x10ec0888:
8707                 if (codec->revision_id == 0x100101) {
8708                         spec->stream_name_analog = "ALC1200 Analog";
8709                         spec->stream_name_digital = "ALC1200 Digital";
8710                 } else {
8711                         spec->stream_name_analog = "ALC888 Analog";
8712                         spec->stream_name_digital = "ALC888 Digital";
8713                 }
8714                 break;
8715         case 0x10ec0889:
8716                 spec->stream_name_analog = "ALC889 Analog";
8717                 spec->stream_name_digital = "ALC889 Digital";
8718                 break;
8719         default:
8720                 spec->stream_name_analog = "ALC883 Analog";
8721                 spec->stream_name_digital = "ALC883 Digital";
8722                 break;
8723         }
8724
8725         spec->stream_analog_playback = &alc883_pcm_analog_playback;
8726         spec->stream_analog_capture = &alc883_pcm_analog_capture;
8727         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
8728
8729         spec->stream_digital_playback = &alc883_pcm_digital_playback;
8730         spec->stream_digital_capture = &alc883_pcm_digital_capture;
8731
8732         if (!spec->num_adc_nids) {
8733                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8734                 spec->adc_nids = alc883_adc_nids;
8735         }
8736         if (!spec->capsrc_nids)
8737                 spec->capsrc_nids = alc883_capsrc_nids;
8738         spec->is_mix_capture = 1; /* matrix-style capture */
8739         if (!spec->cap_mixer)
8740                 set_capture_mixer(spec);
8741
8742         spec->vmaster_nid = 0x0c;
8743
8744         codec->patch_ops = alc_patch_ops;
8745         if (board_config == ALC883_AUTO)
8746                 spec->init_hook = alc883_auto_init;
8747
8748 #ifdef CONFIG_SND_HDA_POWER_SAVE
8749         if (!spec->loopback.amplist)
8750                 spec->loopback.amplist = alc883_loopbacks;
8751 #endif
8752
8753         return 0;
8754 }
8755
8756 /*
8757  * ALC262 support
8758  */
8759
8760 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
8761 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
8762
8763 #define alc262_dac_nids         alc260_dac_nids
8764 #define alc262_adc_nids         alc882_adc_nids
8765 #define alc262_adc_nids_alt     alc882_adc_nids_alt
8766 #define alc262_capsrc_nids      alc882_capsrc_nids
8767 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
8768
8769 #define alc262_modes            alc260_modes
8770 #define alc262_capture_source   alc882_capture_source
8771
8772 static hda_nid_t alc262_dmic_adc_nids[1] = {
8773         /* ADC0 */
8774         0x09
8775 };
8776
8777 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
8778
8779 static struct snd_kcontrol_new alc262_base_mixer[] = {
8780         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8781         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8782         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8783         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8784         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8785         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8786         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8787         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8788         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8789         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8790         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8791         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8792         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8793            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8794         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
8795         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8796         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8797         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
8798         { } /* end */
8799 };
8800
8801 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
8802         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8803         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8804         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8805         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8806         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8807         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8808         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8809         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8810         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8811         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8812         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8813         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8814         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8815            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8816         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
8817         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8818         { } /* end */
8819 };
8820
8821 /* update HP, line and mono-out pins according to the master switch */
8822 static void alc262_hp_master_update(struct hda_codec *codec)
8823 {
8824         struct alc_spec *spec = codec->spec;
8825         int val = spec->master_sw;
8826
8827         /* HP & line-out */
8828         snd_hda_codec_write_cache(codec, 0x1b, 0,
8829                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8830                                   val ? PIN_HP : 0);
8831         snd_hda_codec_write_cache(codec, 0x15, 0,
8832                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8833                                   val ? PIN_HP : 0);
8834         /* mono (speaker) depending on the HP jack sense */
8835         val = val && !spec->jack_present;
8836         snd_hda_codec_write_cache(codec, 0x16, 0,
8837                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8838                                   val ? PIN_OUT : 0);
8839 }
8840
8841 static void alc262_hp_bpc_automute(struct hda_codec *codec)
8842 {
8843         struct alc_spec *spec = codec->spec;
8844         unsigned int presence;
8845         presence = snd_hda_codec_read(codec, 0x1b, 0,
8846                                       AC_VERB_GET_PIN_SENSE, 0);
8847         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8848         alc262_hp_master_update(codec);
8849 }
8850
8851 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
8852 {
8853         if ((res >> 26) != ALC880_HP_EVENT)
8854                 return;
8855         alc262_hp_bpc_automute(codec);
8856 }
8857
8858 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
8859 {
8860         struct alc_spec *spec = codec->spec;
8861         unsigned int presence;
8862         presence = snd_hda_codec_read(codec, 0x15, 0,
8863                                       AC_VERB_GET_PIN_SENSE, 0);
8864         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8865         alc262_hp_master_update(codec);
8866 }
8867
8868 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
8869                                            unsigned int res)
8870 {
8871         if ((res >> 26) != ALC880_HP_EVENT)
8872                 return;
8873         alc262_hp_wildwest_automute(codec);
8874 }
8875
8876 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
8877                                    struct snd_ctl_elem_value *ucontrol)
8878 {
8879         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8880         struct alc_spec *spec = codec->spec;
8881         *ucontrol->value.integer.value = spec->master_sw;
8882         return 0;
8883 }
8884
8885 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
8886                                    struct snd_ctl_elem_value *ucontrol)
8887 {
8888         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8889         struct alc_spec *spec = codec->spec;
8890         int val = !!*ucontrol->value.integer.value;
8891
8892         if (val == spec->master_sw)
8893                 return 0;
8894         spec->master_sw = val;
8895         alc262_hp_master_update(codec);
8896         return 1;
8897 }
8898
8899 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
8900         {
8901                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8902                 .name = "Master Playback Switch",
8903                 .info = snd_ctl_boolean_mono_info,
8904                 .get = alc262_hp_master_sw_get,
8905                 .put = alc262_hp_master_sw_put,
8906         },
8907         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8908         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8909         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8910         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8911                               HDA_OUTPUT),
8912         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8913                             HDA_OUTPUT),
8914         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8915         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8916         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8917         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8918         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8919         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8920         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8921         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8922         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8923         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8924         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8925         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8926         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
8927         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
8928         { } /* end */
8929 };
8930
8931 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
8932         {
8933                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8934                 .name = "Master Playback Switch",
8935                 .info = snd_ctl_boolean_mono_info,
8936                 .get = alc262_hp_master_sw_get,
8937                 .put = alc262_hp_master_sw_put,
8938         },
8939         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8940         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8941         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8942         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8943         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8944                               HDA_OUTPUT),
8945         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8946                             HDA_OUTPUT),
8947         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
8948         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
8949         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
8950         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8951         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8952         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8953         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8954         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8955         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8956         { } /* end */
8957 };
8958
8959 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
8960         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8961         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8962         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
8963         { } /* end */
8964 };
8965
8966 /* mute/unmute internal speaker according to the hp jack and mute state */
8967 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
8968 {
8969         struct alc_spec *spec = codec->spec;
8970
8971         if (force || !spec->sense_updated) {
8972                 unsigned int present;
8973                 present = snd_hda_codec_read(codec, 0x15, 0,
8974                                              AC_VERB_GET_PIN_SENSE, 0);
8975                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8976                 spec->sense_updated = 1;
8977         }
8978         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
8979                                  spec->jack_present ? HDA_AMP_MUTE : 0);
8980 }
8981
8982 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
8983                                         unsigned int res)
8984 {
8985         if ((res >> 26) != ALC880_HP_EVENT)
8986                 return;
8987         alc262_hp_t5735_automute(codec, 1);
8988 }
8989
8990 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
8991 {
8992         alc262_hp_t5735_automute(codec, 1);
8993 }
8994
8995 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
8996         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8997         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8998         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8999         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9000         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9001         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9002         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9003         { } /* end */
9004 };
9005
9006 static struct hda_verb alc262_hp_t5735_verbs[] = {
9007         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9008         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9009
9010         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9011         { }
9012 };
9013
9014 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9015         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9016         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9017         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9018         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9019         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9020         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9021         { } /* end */
9022 };
9023
9024 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9025         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9026         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9027         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9028         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9029         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9030         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9031         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9032         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9033         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9034         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9035         {}
9036 };
9037
9038 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9039         .num_items = 1,
9040         .items = {
9041                 { "Line", 0x1 },
9042         },
9043 };
9044
9045 /* bind hp and internal speaker mute (with plug check) */
9046 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9047                                      struct snd_ctl_elem_value *ucontrol)
9048 {
9049         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9050         long *valp = ucontrol->value.integer.value;
9051         int change;
9052
9053         /* change hp mute */
9054         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9055                                           HDA_AMP_MUTE,
9056                                           valp[0] ? 0 : HDA_AMP_MUTE);
9057         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9058                                            HDA_AMP_MUTE,
9059                                            valp[1] ? 0 : HDA_AMP_MUTE);
9060         if (change) {
9061                 /* change speaker according to HP jack state */
9062                 struct alc_spec *spec = codec->spec;
9063                 unsigned int mute;
9064                 if (spec->jack_present)
9065                         mute = HDA_AMP_MUTE;
9066                 else
9067                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9068                                                       HDA_OUTPUT, 0);
9069                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9070                                          HDA_AMP_MUTE, mute);
9071         }
9072         return change;
9073 }
9074
9075 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9076         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9077         {
9078                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9079                 .name = "Master Playback Switch",
9080                 .info = snd_hda_mixer_amp_switch_info,
9081                 .get = snd_hda_mixer_amp_switch_get,
9082                 .put = alc262_sony_master_sw_put,
9083                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9084         },
9085         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9086         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9087         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9088         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9089         { } /* end */
9090 };
9091
9092 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9093         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9094         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9095         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9096         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9097         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9098         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9099         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9100         { } /* end */
9101 };
9102
9103 #define alc262_capture_mixer            alc882_capture_mixer
9104 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9105
9106 /*
9107  * generic initialization of ADC, input mixers and output mixers
9108  */
9109 static struct hda_verb alc262_init_verbs[] = {
9110         /*
9111          * Unmute ADC0-2 and set the default input to mic-in
9112          */
9113         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9114         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9115         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9116         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9117         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9118         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9119
9120         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9121          * mixer widget
9122          * Note: PASD motherboards uses the Line In 2 as the input for
9123          * front panel mic (mic 2)
9124          */
9125         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9126         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9127         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9128         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9129         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9130         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9131
9132         /*
9133          * Set up output mixers (0x0c - 0x0e)
9134          */
9135         /* set vol=0 to output mixers */
9136         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9137         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9138         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9139         /* set up input amps for analog loopback */
9140         /* Amp Indices: DAC = 0, mixer = 1 */
9141         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9142         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9143         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9144         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9145         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9146         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9147
9148         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9149         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9150         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9151         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9152         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9153         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9154
9155         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9156         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9157         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9158         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9159         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9160
9161         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9162         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9163
9164         /* FIXME: use matrix-type input source selection */
9165         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9166         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9167         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9168         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9169         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9170         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9171         /* Input mixer2 */
9172         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9173         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9174         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9175         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9176         /* Input mixer3 */
9177         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9178         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9179         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9180         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9181
9182         { }
9183 };
9184
9185 static struct hda_verb alc262_eapd_verbs[] = {
9186         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9187         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9188         { }
9189 };
9190
9191 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9192         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9193         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9194         {}
9195 };
9196
9197 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9198         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9199         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9200         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9201
9202         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9203         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9204         {}
9205 };
9206
9207 static struct hda_verb alc262_sony_unsol_verbs[] = {
9208         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9209         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9210         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9211
9212         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9213         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9214         {}
9215 };
9216
9217 static struct hda_input_mux alc262_dmic_capture_source = {
9218         .num_items = 2,
9219         .items = {
9220                 { "Int DMic", 0x9 },
9221                 { "Mic", 0x0 },
9222         },
9223 };
9224
9225 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9226         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9227         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9228         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9229         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9230         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9231         { } /* end */
9232 };
9233
9234 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9235         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9236         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9237         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9238         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9239         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9240         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9241         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9242         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9243         {}
9244 };
9245
9246 static void alc262_dmic_automute(struct hda_codec *codec)
9247 {
9248         unsigned int present;
9249
9250         present = snd_hda_codec_read(codec, 0x18, 0,
9251                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9252         snd_hda_codec_write(codec, 0x22, 0,
9253                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9254 }
9255
9256 /* toggle speaker-output according to the hp-jack state */
9257 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9258 {
9259         unsigned int present;
9260         unsigned char bits;
9261
9262         present = snd_hda_codec_read(codec, 0x15, 0,
9263                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9264         bits = present ? 0 : PIN_OUT;
9265         snd_hda_codec_write(codec, 0x14, 0,
9266                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9267 }
9268
9269
9270
9271 /* unsolicited event for HP jack sensing */
9272 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9273                                        unsigned int res)
9274 {
9275         if ((res >> 26) == ALC880_HP_EVENT)
9276                 alc262_toshiba_s06_speaker_automute(codec);
9277         if ((res >> 26) == ALC880_MIC_EVENT)
9278                 alc262_dmic_automute(codec);
9279
9280 }
9281
9282 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9283 {
9284         alc262_toshiba_s06_speaker_automute(codec);
9285         alc262_dmic_automute(codec);
9286 }
9287
9288 /* mute/unmute internal speaker according to the hp jack and mute state */
9289 static void alc262_hippo_automute(struct hda_codec *codec)
9290 {
9291         struct alc_spec *spec = codec->spec;
9292         unsigned int mute;
9293         unsigned int present;
9294
9295         /* need to execute and sync at first */
9296         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9297         present = snd_hda_codec_read(codec, 0x15, 0,
9298                                      AC_VERB_GET_PIN_SENSE, 0);
9299         spec->jack_present = (present & 0x80000000) != 0;
9300         if (spec->jack_present) {
9301                 /* mute internal speaker */
9302                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9303                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9304         } else {
9305                 /* unmute internal speaker if necessary */
9306                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9307                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9308                                          HDA_AMP_MUTE, mute);
9309         }
9310 }
9311
9312 /* unsolicited event for HP jack sensing */
9313 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9314                                        unsigned int res)
9315 {
9316         if ((res >> 26) != ALC880_HP_EVENT)
9317                 return;
9318         alc262_hippo_automute(codec);
9319 }
9320
9321 static void alc262_hippo1_automute(struct hda_codec *codec)
9322 {
9323         unsigned int mute;
9324         unsigned int present;
9325
9326         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9327         present = snd_hda_codec_read(codec, 0x1b, 0,
9328                                      AC_VERB_GET_PIN_SENSE, 0);
9329         present = (present & 0x80000000) != 0;
9330         if (present) {
9331                 /* mute internal speaker */
9332                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9333                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9334         } else {
9335                 /* unmute internal speaker if necessary */
9336                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9337                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9338                                          HDA_AMP_MUTE, mute);
9339         }
9340 }
9341
9342 /* unsolicited event for HP jack sensing */
9343 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9344                                        unsigned int res)
9345 {
9346         if ((res >> 26) != ALC880_HP_EVENT)
9347                 return;
9348         alc262_hippo1_automute(codec);
9349 }
9350
9351 /*
9352  * nec model
9353  *  0x15 = headphone
9354  *  0x16 = internal speaker
9355  *  0x18 = external mic
9356  */
9357
9358 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9359         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9360         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9361
9362         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9363         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9364         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9365
9366         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9367         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9368         { } /* end */
9369 };
9370
9371 static struct hda_verb alc262_nec_verbs[] = {
9372         /* Unmute Speaker */
9373         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9374
9375         /* Headphone */
9376         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9377         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9378
9379         /* External mic to headphone */
9380         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9381         /* External mic to speaker */
9382         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9383         {}
9384 };
9385
9386 /*
9387  * fujitsu model
9388  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9389  *  0x1b = port replicator headphone out
9390  */
9391
9392 #define ALC_HP_EVENT    0x37
9393
9394 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9395         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9396         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9397         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9398         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9399         {}
9400 };
9401
9402 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9403         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9404         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9405         {}
9406 };
9407
9408 static struct hda_input_mux alc262_fujitsu_capture_source = {
9409         .num_items = 3,
9410         .items = {
9411                 { "Mic", 0x0 },
9412                 { "Int Mic", 0x1 },
9413                 { "CD", 0x4 },
9414         },
9415 };
9416
9417 static struct hda_input_mux alc262_HP_capture_source = {
9418         .num_items = 5,
9419         .items = {
9420                 { "Mic", 0x0 },
9421                 { "Front Mic", 0x1 },
9422                 { "Line", 0x2 },
9423                 { "CD", 0x4 },
9424                 { "AUX IN", 0x6 },
9425         },
9426 };
9427
9428 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9429         .num_items = 4,
9430         .items = {
9431                 { "Mic", 0x0 },
9432                 { "Front Mic", 0x2 },
9433                 { "Line", 0x1 },
9434                 { "CD", 0x4 },
9435         },
9436 };
9437
9438 /* mute/unmute internal speaker according to the hp jacks and mute state */
9439 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9440 {
9441         struct alc_spec *spec = codec->spec;
9442         unsigned int mute;
9443
9444         if (force || !spec->sense_updated) {
9445                 unsigned int present;
9446                 /* need to execute and sync at first */
9447                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9448                 /* check laptop HP jack */
9449                 present = snd_hda_codec_read(codec, 0x14, 0,
9450                                              AC_VERB_GET_PIN_SENSE, 0);
9451                 /* need to execute and sync at first */
9452                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9453                 /* check docking HP jack */
9454                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9455                                               AC_VERB_GET_PIN_SENSE, 0);
9456                 if (present & AC_PINSENSE_PRESENCE)
9457                         spec->jack_present = 1;
9458                 else
9459                         spec->jack_present = 0;
9460                 spec->sense_updated = 1;
9461         }
9462         /* unmute internal speaker only if both HPs are unplugged and
9463          * master switch is on
9464          */
9465         if (spec->jack_present)
9466                 mute = HDA_AMP_MUTE;
9467         else
9468                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9469         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9470                                  HDA_AMP_MUTE, mute);
9471 }
9472
9473 /* unsolicited event for HP jack sensing */
9474 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9475                                        unsigned int res)
9476 {
9477         if ((res >> 26) != ALC_HP_EVENT)
9478                 return;
9479         alc262_fujitsu_automute(codec, 1);
9480 }
9481
9482 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9483 {
9484         alc262_fujitsu_automute(codec, 1);
9485 }
9486
9487 /* bind volumes of both NID 0x0c and 0x0d */
9488 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9489         .ops = &snd_hda_bind_vol,
9490         .values = {
9491                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9492                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9493                 0
9494         },
9495 };
9496
9497 /* mute/unmute internal speaker according to the hp jack and mute state */
9498 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9499 {
9500         struct alc_spec *spec = codec->spec;
9501         unsigned int mute;
9502
9503         if (force || !spec->sense_updated) {
9504                 unsigned int present_int_hp;
9505                 /* need to execute and sync at first */
9506                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9507                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9508                                         AC_VERB_GET_PIN_SENSE, 0);
9509                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9510                 spec->sense_updated = 1;
9511         }
9512         if (spec->jack_present) {
9513                 /* mute internal speaker */
9514                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9515                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9516                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9517                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9518         } else {
9519                 /* unmute internal speaker if necessary */
9520                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9521                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9522                                          HDA_AMP_MUTE, mute);
9523                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9524                                          HDA_AMP_MUTE, mute);
9525         }
9526 }
9527
9528 /* unsolicited event for HP jack sensing */
9529 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9530                                        unsigned int res)
9531 {
9532         if ((res >> 26) != ALC_HP_EVENT)
9533                 return;
9534         alc262_lenovo_3000_automute(codec, 1);
9535 }
9536
9537 /* bind hp and internal speaker mute (with plug check) */
9538 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9539                                          struct snd_ctl_elem_value *ucontrol)
9540 {
9541         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9542         long *valp = ucontrol->value.integer.value;
9543         int change;
9544
9545         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9546                                                  HDA_AMP_MUTE,
9547                                                  valp ? 0 : HDA_AMP_MUTE);
9548         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9549                                                  HDA_AMP_MUTE,
9550                                                  valp ? 0 : HDA_AMP_MUTE);
9551
9552         if (change)
9553                 alc262_fujitsu_automute(codec, 0);
9554         return change;
9555 }
9556
9557 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9558         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9559         {
9560                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9561                 .name = "Master Playback Switch",
9562                 .info = snd_hda_mixer_amp_switch_info,
9563                 .get = snd_hda_mixer_amp_switch_get,
9564                 .put = alc262_fujitsu_master_sw_put,
9565                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9566         },
9567         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9568         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9569         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9570         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9571         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9572         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9573         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9574         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9575         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9576         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9577         { } /* end */
9578 };
9579
9580 /* bind hp and internal speaker mute (with plug check) */
9581 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9582                                          struct snd_ctl_elem_value *ucontrol)
9583 {
9584         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9585         long *valp = ucontrol->value.integer.value;
9586         int change;
9587
9588         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9589                                                  HDA_AMP_MUTE,
9590                                                  valp ? 0 : HDA_AMP_MUTE);
9591
9592         if (change)
9593                 alc262_lenovo_3000_automute(codec, 0);
9594         return change;
9595 }
9596
9597 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9598         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9599         {
9600                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9601                 .name = "Master Playback Switch",
9602                 .info = snd_hda_mixer_amp_switch_info,
9603                 .get = snd_hda_mixer_amp_switch_get,
9604                 .put = alc262_lenovo_3000_master_sw_put,
9605                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9606         },
9607         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9608         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9609         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9610         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9611         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9612         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9613         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9614         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9615         { } /* end */
9616 };
9617
9618 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
9619         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9620         {
9621                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9622                 .name = "Master Playback Switch",
9623                 .info = snd_hda_mixer_amp_switch_info,
9624                 .get = snd_hda_mixer_amp_switch_get,
9625                 .put = alc262_sony_master_sw_put,
9626                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9627         },
9628         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9629         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9630         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9631         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9632         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9633         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9634         { } /* end */
9635 };
9636
9637 /* additional init verbs for Benq laptops */
9638 static struct hda_verb alc262_EAPD_verbs[] = {
9639         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9640         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9641         {}
9642 };
9643
9644 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9645         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9646         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9647
9648         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9649         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9650         {}
9651 };
9652
9653 /* Samsung Q1 Ultra Vista model setup */
9654 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9655         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9656         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9657         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9658         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9659         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9660         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9661         { } /* end */
9662 };
9663
9664 static struct hda_verb alc262_ultra_verbs[] = {
9665         /* output mixer */
9666         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9667         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9668         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9669         /* speaker */
9670         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9671         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9672         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9673         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9674         /* HP */
9675         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9676         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9677         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9678         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9679         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9680         /* internal mic */
9681         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9682         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9683         /* ADC, choose mic */
9684         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9685         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9686         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9687         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9688         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9689         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9690         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9691         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9692         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9693         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
9694         {}
9695 };
9696
9697 /* mute/unmute internal speaker according to the hp jack and mute state */
9698 static void alc262_ultra_automute(struct hda_codec *codec)
9699 {
9700         struct alc_spec *spec = codec->spec;
9701         unsigned int mute;
9702
9703         mute = 0;
9704         /* auto-mute only when HP is used as HP */
9705         if (!spec->cur_mux[0]) {
9706                 unsigned int present;
9707                 /* need to execute and sync at first */
9708                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9709                 present = snd_hda_codec_read(codec, 0x15, 0,
9710                                              AC_VERB_GET_PIN_SENSE, 0);
9711                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9712                 if (spec->jack_present)
9713                         mute = HDA_AMP_MUTE;
9714         }
9715         /* mute/unmute internal speaker */
9716         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9717                                  HDA_AMP_MUTE, mute);
9718         /* mute/unmute HP */
9719         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9720                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
9721 }
9722
9723 /* unsolicited event for HP jack sensing */
9724 static void alc262_ultra_unsol_event(struct hda_codec *codec,
9725                                        unsigned int res)
9726 {
9727         if ((res >> 26) != ALC880_HP_EVENT)
9728                 return;
9729         alc262_ultra_automute(codec);
9730 }
9731
9732 static struct hda_input_mux alc262_ultra_capture_source = {
9733         .num_items = 2,
9734         .items = {
9735                 { "Mic", 0x1 },
9736                 { "Headphone", 0x7 },
9737         },
9738 };
9739
9740 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
9741                                      struct snd_ctl_elem_value *ucontrol)
9742 {
9743         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9744         struct alc_spec *spec = codec->spec;
9745         int ret;
9746
9747         ret = alc_mux_enum_put(kcontrol, ucontrol);
9748         if (!ret)
9749                 return 0;
9750         /* reprogram the HP pin as mic or HP according to the input source */
9751         snd_hda_codec_write_cache(codec, 0x15, 0,
9752                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9753                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
9754         alc262_ultra_automute(codec); /* mute/unmute HP */
9755         return ret;
9756 }
9757
9758 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
9759         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
9760         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
9761         {
9762                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9763                 .name = "Capture Source",
9764                 .info = alc_mux_enum_info,
9765                 .get = alc_mux_enum_get,
9766                 .put = alc262_ultra_mux_enum_put,
9767         },
9768         { } /* end */
9769 };
9770
9771 /* add playback controls from the parsed DAC table */
9772 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
9773                                              const struct auto_pin_cfg *cfg)
9774 {
9775         hda_nid_t nid;
9776         int err;
9777
9778         spec->multiout.num_dacs = 1;    /* only use one dac */
9779         spec->multiout.dac_nids = spec->private_dac_nids;
9780         spec->multiout.dac_nids[0] = 2;
9781
9782         nid = cfg->line_out_pins[0];
9783         if (nid) {
9784                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9785                                   "Front Playback Volume",
9786                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
9787                 if (err < 0)
9788                         return err;
9789                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9790                                   "Front Playback Switch",
9791                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9792                 if (err < 0)
9793                         return err;
9794         }
9795
9796         nid = cfg->speaker_pins[0];
9797         if (nid) {
9798                 if (nid == 0x16) {
9799                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9800                                           "Speaker Playback Volume",
9801                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9802                                                               HDA_OUTPUT));
9803                         if (err < 0)
9804                                 return err;
9805                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9806                                           "Speaker Playback Switch",
9807                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9808                                                               HDA_OUTPUT));
9809                         if (err < 0)
9810                                 return err;
9811                 } else {
9812                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9813                                           "Speaker Playback Switch",
9814                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9815                                                               HDA_OUTPUT));
9816                         if (err < 0)
9817                                 return err;
9818                 }
9819         }
9820         nid = cfg->hp_pins[0];
9821         if (nid) {
9822                 /* spec->multiout.hp_nid = 2; */
9823                 if (nid == 0x16) {
9824                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9825                                           "Headphone Playback Volume",
9826                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9827                                                               HDA_OUTPUT));
9828                         if (err < 0)
9829                                 return err;
9830                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9831                                           "Headphone Playback Switch",
9832                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9833                                                               HDA_OUTPUT));
9834                         if (err < 0)
9835                                 return err;
9836                 } else {
9837                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9838                                           "Headphone Playback Switch",
9839                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9840                                                               HDA_OUTPUT));
9841                         if (err < 0)
9842                                 return err;
9843                 }
9844         }
9845         return 0;
9846 }
9847
9848 /* identical with ALC880 */
9849 #define alc262_auto_create_analog_input_ctls \
9850         alc880_auto_create_analog_input_ctls
9851
9852 /*
9853  * generic initialization of ADC, input mixers and output mixers
9854  */
9855 static struct hda_verb alc262_volume_init_verbs[] = {
9856         /*
9857          * Unmute ADC0-2 and set the default input to mic-in
9858          */
9859         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9860         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9861         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9862         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9863         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9864         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9865
9866         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9867          * mixer widget
9868          * Note: PASD motherboards uses the Line In 2 as the input for
9869          * front panel mic (mic 2)
9870          */
9871         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9872         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9873         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9874         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9875         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9876         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9877
9878         /*
9879          * Set up output mixers (0x0c - 0x0f)
9880          */
9881         /* set vol=0 to output mixers */
9882         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9883         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9884         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9885
9886         /* set up input amps for analog loopback */
9887         /* Amp Indices: DAC = 0, mixer = 1 */
9888         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9889         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9890         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9891         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9892         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9893         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9894
9895         /* FIXME: use matrix-type input source selection */
9896         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9897         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9898         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9899         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9900         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9901         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9902         /* Input mixer2 */
9903         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9904         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9905         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9906         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9907         /* Input mixer3 */
9908         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9909         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9910         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9911         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9912
9913         { }
9914 };
9915
9916 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
9917         /*
9918          * Unmute ADC0-2 and set the default input to mic-in
9919          */
9920         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9921         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9922         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9923         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9924         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9925         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9926
9927         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9928          * mixer widget
9929          * Note: PASD motherboards uses the Line In 2 as the input for
9930          * front panel mic (mic 2)
9931          */
9932         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9933         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9934         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9935         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9936         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9937         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9938         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9939         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9940
9941         /*
9942          * Set up output mixers (0x0c - 0x0e)
9943          */
9944         /* set vol=0 to output mixers */
9945         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9946         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9947         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9948
9949         /* set up input amps for analog loopback */
9950         /* Amp Indices: DAC = 0, mixer = 1 */
9951         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9952         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9953         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9954         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9955         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9956         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9957
9958         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9959         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9960         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9961
9962         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9963         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9964
9965         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9966         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9967
9968         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9969         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9970         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9971         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9972         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9973
9974         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9975         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9976         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9977         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9978         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9979         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9980
9981
9982         /* FIXME: use matrix-type input source selection */
9983         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9984         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9985         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9986         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9987         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9988         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9989         /* Input mixer2 */
9990         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9991         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9992         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9993         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9994         /* Input mixer3 */
9995         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9996         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9997         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9998         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9999
10000         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10001
10002         { }
10003 };
10004
10005 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10006         /*
10007          * Unmute ADC0-2 and set the default input to mic-in
10008          */
10009         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10010         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10011         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10012         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10013         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10014         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10015
10016         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10017          * mixer widget
10018          * Note: PASD motherboards uses the Line In 2 as the input for front
10019          * panel mic (mic 2)
10020          */
10021         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10022         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10023         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10024         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10025         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10026         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10027         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10028         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10029         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10030         /*
10031          * Set up output mixers (0x0c - 0x0e)
10032          */
10033         /* set vol=0 to output mixers */
10034         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10035         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10036         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10037
10038         /* set up input amps for analog loopback */
10039         /* Amp Indices: DAC = 0, mixer = 1 */
10040         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10041         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10042         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10043         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10044         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10045         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10046
10047
10048         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10049         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10050         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10051         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10052         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10053         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10054         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10055
10056         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10057         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10058
10059         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10060         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10061
10062         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10063         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10064         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10065         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10066         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10067         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10068
10069         /* FIXME: use matrix-type input source selection */
10070         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10071         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10072         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10073         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10074         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10075         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10076         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10077         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10078         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10079         /* Input mixer2 */
10080         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10081         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10082         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10083         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10084         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10085         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10086         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10087         /* Input mixer3 */
10088         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10089         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10090         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10091         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10092         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10093         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10094         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10095
10096         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10097
10098         { }
10099 };
10100
10101 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10102
10103         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10104         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10105         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10106
10107         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10108         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10109         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10110         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10111
10112         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10113         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10114         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10115         {}
10116 };
10117
10118
10119 #ifdef CONFIG_SND_HDA_POWER_SAVE
10120 #define alc262_loopbacks        alc880_loopbacks
10121 #endif
10122
10123 /* pcm configuration: identiacal with ALC880 */
10124 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10125 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10126 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10127 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10128
10129 /*
10130  * BIOS auto configuration
10131  */
10132 static int alc262_parse_auto_config(struct hda_codec *codec)
10133 {
10134         struct alc_spec *spec = codec->spec;
10135         int err;
10136         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10137
10138         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10139                                            alc262_ignore);
10140         if (err < 0)
10141                 return err;
10142         if (!spec->autocfg.line_outs)
10143                 return 0; /* can't find valid BIOS pin config */
10144         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10145         if (err < 0)
10146                 return err;
10147         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10148         if (err < 0)
10149                 return err;
10150
10151         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10152
10153         if (spec->autocfg.dig_out_pin)
10154                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10155         if (spec->autocfg.dig_in_pin)
10156                 spec->dig_in_nid = ALC262_DIGIN_NID;
10157
10158         if (spec->kctls.list)
10159                 add_mixer(spec, spec->kctls.list);
10160
10161         add_verb(spec, alc262_volume_init_verbs);
10162         spec->num_mux_defs = 1;
10163         spec->input_mux = &spec->private_imux;
10164
10165         err = alc_auto_add_mic_boost(codec);
10166         if (err < 0)
10167                 return err;
10168
10169         store_pin_configs(codec);
10170         return 1;
10171 }
10172
10173 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10174 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10175 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10176 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10177
10178
10179 /* init callback for auto-configuration model -- overriding the default init */
10180 static void alc262_auto_init(struct hda_codec *codec)
10181 {
10182         struct alc_spec *spec = codec->spec;
10183         alc262_auto_init_multi_out(codec);
10184         alc262_auto_init_hp_out(codec);
10185         alc262_auto_init_analog_input(codec);
10186         alc262_auto_init_input_src(codec);
10187         if (spec->unsol_event)
10188                 alc_inithook(codec);
10189 }
10190
10191 /*
10192  * configuration and preset
10193  */
10194 static const char *alc262_models[ALC262_MODEL_LAST] = {
10195         [ALC262_BASIC]          = "basic",
10196         [ALC262_HIPPO]          = "hippo",
10197         [ALC262_HIPPO_1]        = "hippo_1",
10198         [ALC262_FUJITSU]        = "fujitsu",
10199         [ALC262_HP_BPC]         = "hp-bpc",
10200         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10201         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10202         [ALC262_HP_RP5700]      = "hp-rp5700",
10203         [ALC262_BENQ_ED8]       = "benq",
10204         [ALC262_BENQ_T31]       = "benq-t31",
10205         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10206         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10207         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10208         [ALC262_ULTRA]          = "ultra",
10209         [ALC262_LENOVO_3000]    = "lenovo-3000",
10210         [ALC262_NEC]            = "nec",
10211         [ALC262_AUTO]           = "auto",
10212 };
10213
10214 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10215         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10216         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10217         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
10218         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
10219         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
10220         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
10221         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
10222         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
10223         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10224         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10225         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10226         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10227         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10228         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10229         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10230         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10231         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10232         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10233         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10234         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10235         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10236         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10237                       ALC262_HP_TC_T5735),
10238         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10239         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10240         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10241         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10242         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10243         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10244         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10245                       ALC262_TOSHIBA_RX1),
10246         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10247         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10248         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10249         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
10250         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
10251         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10252         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10253         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10254         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10255         {}
10256 };
10257
10258 static struct alc_config_preset alc262_presets[] = {
10259         [ALC262_BASIC] = {
10260                 .mixers = { alc262_base_mixer },
10261                 .init_verbs = { alc262_init_verbs },
10262                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10263                 .dac_nids = alc262_dac_nids,
10264                 .hp_nid = 0x03,
10265                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10266                 .channel_mode = alc262_modes,
10267                 .input_mux = &alc262_capture_source,
10268         },
10269         [ALC262_HIPPO] = {
10270                 .mixers = { alc262_base_mixer },
10271                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10272                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10273                 .dac_nids = alc262_dac_nids,
10274                 .hp_nid = 0x03,
10275                 .dig_out_nid = ALC262_DIGOUT_NID,
10276                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10277                 .channel_mode = alc262_modes,
10278                 .input_mux = &alc262_capture_source,
10279                 .unsol_event = alc262_hippo_unsol_event,
10280                 .init_hook = alc262_hippo_automute,
10281         },
10282         [ALC262_HIPPO_1] = {
10283                 .mixers = { alc262_hippo1_mixer },
10284                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10285                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10286                 .dac_nids = alc262_dac_nids,
10287                 .hp_nid = 0x02,
10288                 .dig_out_nid = ALC262_DIGOUT_NID,
10289                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10290                 .channel_mode = alc262_modes,
10291                 .input_mux = &alc262_capture_source,
10292                 .unsol_event = alc262_hippo1_unsol_event,
10293                 .init_hook = alc262_hippo1_automute,
10294         },
10295         [ALC262_FUJITSU] = {
10296                 .mixers = { alc262_fujitsu_mixer },
10297                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10298                                 alc262_fujitsu_unsol_verbs },
10299                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10300                 .dac_nids = alc262_dac_nids,
10301                 .hp_nid = 0x03,
10302                 .dig_out_nid = ALC262_DIGOUT_NID,
10303                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10304                 .channel_mode = alc262_modes,
10305                 .input_mux = &alc262_fujitsu_capture_source,
10306                 .unsol_event = alc262_fujitsu_unsol_event,
10307                 .init_hook = alc262_fujitsu_init_hook,
10308         },
10309         [ALC262_HP_BPC] = {
10310                 .mixers = { alc262_HP_BPC_mixer },
10311                 .init_verbs = { alc262_HP_BPC_init_verbs },
10312                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10313                 .dac_nids = alc262_dac_nids,
10314                 .hp_nid = 0x03,
10315                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10316                 .channel_mode = alc262_modes,
10317                 .input_mux = &alc262_HP_capture_source,
10318                 .unsol_event = alc262_hp_bpc_unsol_event,
10319                 .init_hook = alc262_hp_bpc_automute,
10320         },
10321         [ALC262_HP_BPC_D7000_WF] = {
10322                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10323                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10324                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10325                 .dac_nids = alc262_dac_nids,
10326                 .hp_nid = 0x03,
10327                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10328                 .channel_mode = alc262_modes,
10329                 .input_mux = &alc262_HP_D7000_capture_source,
10330                 .unsol_event = alc262_hp_wildwest_unsol_event,
10331                 .init_hook = alc262_hp_wildwest_automute,
10332         },
10333         [ALC262_HP_BPC_D7000_WL] = {
10334                 .mixers = { alc262_HP_BPC_WildWest_mixer,
10335                             alc262_HP_BPC_WildWest_option_mixer },
10336                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10337                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10338                 .dac_nids = alc262_dac_nids,
10339                 .hp_nid = 0x03,
10340                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10341                 .channel_mode = alc262_modes,
10342                 .input_mux = &alc262_HP_D7000_capture_source,
10343                 .unsol_event = alc262_hp_wildwest_unsol_event,
10344                 .init_hook = alc262_hp_wildwest_automute,
10345         },
10346         [ALC262_HP_TC_T5735] = {
10347                 .mixers = { alc262_hp_t5735_mixer },
10348                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10349                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10350                 .dac_nids = alc262_dac_nids,
10351                 .hp_nid = 0x03,
10352                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10353                 .channel_mode = alc262_modes,
10354                 .input_mux = &alc262_capture_source,
10355                 .unsol_event = alc262_hp_t5735_unsol_event,
10356                 .init_hook = alc262_hp_t5735_init_hook,
10357         },
10358         [ALC262_HP_RP5700] = {
10359                 .mixers = { alc262_hp_rp5700_mixer },
10360                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10361                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10362                 .dac_nids = alc262_dac_nids,
10363                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10364                 .channel_mode = alc262_modes,
10365                 .input_mux = &alc262_hp_rp5700_capture_source,
10366         },
10367         [ALC262_BENQ_ED8] = {
10368                 .mixers = { alc262_base_mixer },
10369                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
10370                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10371                 .dac_nids = alc262_dac_nids,
10372                 .hp_nid = 0x03,
10373                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10374                 .channel_mode = alc262_modes,
10375                 .input_mux = &alc262_capture_source,
10376         },
10377         [ALC262_SONY_ASSAMD] = {
10378                 .mixers = { alc262_sony_mixer },
10379                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10380                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10381                 .dac_nids = alc262_dac_nids,
10382                 .hp_nid = 0x02,
10383                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10384                 .channel_mode = alc262_modes,
10385                 .input_mux = &alc262_capture_source,
10386                 .unsol_event = alc262_hippo_unsol_event,
10387                 .init_hook = alc262_hippo_automute,
10388         },
10389         [ALC262_BENQ_T31] = {
10390                 .mixers = { alc262_benq_t31_mixer },
10391                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10392                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10393                 .dac_nids = alc262_dac_nids,
10394                 .hp_nid = 0x03,
10395                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10396                 .channel_mode = alc262_modes,
10397                 .input_mux = &alc262_capture_source,
10398                 .unsol_event = alc262_hippo_unsol_event,
10399                 .init_hook = alc262_hippo_automute,
10400         },
10401         [ALC262_ULTRA] = {
10402                 .mixers = { alc262_ultra_mixer },
10403                 .cap_mixer = alc262_ultra_capture_mixer,
10404                 .init_verbs = { alc262_ultra_verbs },
10405                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10406                 .dac_nids = alc262_dac_nids,
10407                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10408                 .channel_mode = alc262_modes,
10409                 .input_mux = &alc262_ultra_capture_source,
10410                 .adc_nids = alc262_adc_nids, /* ADC0 */
10411                 .capsrc_nids = alc262_capsrc_nids,
10412                 .num_adc_nids = 1, /* single ADC */
10413                 .unsol_event = alc262_ultra_unsol_event,
10414                 .init_hook = alc262_ultra_automute,
10415         },
10416         [ALC262_LENOVO_3000] = {
10417                 .mixers = { alc262_lenovo_3000_mixer },
10418                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10419                                 alc262_lenovo_3000_unsol_verbs },
10420                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10421                 .dac_nids = alc262_dac_nids,
10422                 .hp_nid = 0x03,
10423                 .dig_out_nid = ALC262_DIGOUT_NID,
10424                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10425                 .channel_mode = alc262_modes,
10426                 .input_mux = &alc262_fujitsu_capture_source,
10427                 .unsol_event = alc262_lenovo_3000_unsol_event,
10428         },
10429         [ALC262_NEC] = {
10430                 .mixers = { alc262_nec_mixer },
10431                 .init_verbs = { alc262_nec_verbs },
10432                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10433                 .dac_nids = alc262_dac_nids,
10434                 .hp_nid = 0x03,
10435                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10436                 .channel_mode = alc262_modes,
10437                 .input_mux = &alc262_capture_source,
10438         },
10439         [ALC262_TOSHIBA_S06] = {
10440                 .mixers = { alc262_toshiba_s06_mixer },
10441                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10442                                                         alc262_eapd_verbs },
10443                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10444                 .capsrc_nids = alc262_dmic_capsrc_nids,
10445                 .dac_nids = alc262_dac_nids,
10446                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10447                 .dig_out_nid = ALC262_DIGOUT_NID,
10448                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10449                 .channel_mode = alc262_modes,
10450                 .input_mux = &alc262_dmic_capture_source,
10451                 .unsol_event = alc262_toshiba_s06_unsol_event,
10452                 .init_hook = alc262_toshiba_s06_init_hook,
10453         },
10454         [ALC262_TOSHIBA_RX1] = {
10455                 .mixers = { alc262_toshiba_rx1_mixer },
10456                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
10457                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10458                 .dac_nids = alc262_dac_nids,
10459                 .hp_nid = 0x03,
10460                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10461                 .channel_mode = alc262_modes,
10462                 .input_mux = &alc262_capture_source,
10463                 .unsol_event = alc262_hippo_unsol_event,
10464                 .init_hook = alc262_hippo_automute,
10465         },
10466 };
10467
10468 static int patch_alc262(struct hda_codec *codec)
10469 {
10470         struct alc_spec *spec;
10471         int board_config;
10472         int err;
10473
10474         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10475         if (spec == NULL)
10476                 return -ENOMEM;
10477
10478         codec->spec = spec;
10479 #if 0
10480         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10481          * under-run
10482          */
10483         {
10484         int tmp;
10485         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10486         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10487         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10488         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10489         }
10490 #endif
10491
10492         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10493
10494         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10495                                                   alc262_models,
10496                                                   alc262_cfg_tbl);
10497
10498         if (board_config < 0) {
10499                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10500                        "trying auto-probe from BIOS...\n");
10501                 board_config = ALC262_AUTO;
10502         }
10503
10504         if (board_config == ALC262_AUTO) {
10505                 /* automatic parse from the BIOS config */
10506                 err = alc262_parse_auto_config(codec);
10507                 if (err < 0) {
10508                         alc_free(codec);
10509                         return err;
10510                 } else if (!err) {
10511                         printk(KERN_INFO
10512                                "hda_codec: Cannot set up configuration "
10513                                "from BIOS.  Using base mode...\n");
10514                         board_config = ALC262_BASIC;
10515                 }
10516         }
10517
10518         if (board_config != ALC262_AUTO)
10519                 setup_preset(spec, &alc262_presets[board_config]);
10520
10521         spec->stream_name_analog = "ALC262 Analog";
10522         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10523         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10524
10525         spec->stream_name_digital = "ALC262 Digital";
10526         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10527         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10528
10529         spec->is_mix_capture = 1;
10530         if (!spec->adc_nids && spec->input_mux) {
10531                 /* check whether NID 0x07 is valid */
10532                 unsigned int wcap = get_wcaps(codec, 0x07);
10533
10534                 /* get type */
10535                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10536                 if (wcap != AC_WID_AUD_IN) {
10537                         spec->adc_nids = alc262_adc_nids_alt;
10538                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10539                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10540                 } else {
10541                         spec->adc_nids = alc262_adc_nids;
10542                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10543                         spec->capsrc_nids = alc262_capsrc_nids;
10544                 }
10545         }
10546         if (!spec->cap_mixer)
10547                 set_capture_mixer(spec);
10548
10549         spec->vmaster_nid = 0x0c;
10550
10551         codec->patch_ops = alc_patch_ops;
10552         if (board_config == ALC262_AUTO)
10553                 spec->init_hook = alc262_auto_init;
10554 #ifdef CONFIG_SND_HDA_POWER_SAVE
10555         if (!spec->loopback.amplist)
10556                 spec->loopback.amplist = alc262_loopbacks;
10557 #endif
10558
10559         return 0;
10560 }
10561
10562 /*
10563  *  ALC268 channel source setting (2 channel)
10564  */
10565 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10566 #define alc268_modes            alc260_modes
10567
10568 static hda_nid_t alc268_dac_nids[2] = {
10569         /* front, hp */
10570         0x02, 0x03
10571 };
10572
10573 static hda_nid_t alc268_adc_nids[2] = {
10574         /* ADC0-1 */
10575         0x08, 0x07
10576 };
10577
10578 static hda_nid_t alc268_adc_nids_alt[1] = {
10579         /* ADC0 */
10580         0x08
10581 };
10582
10583 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10584
10585 static struct snd_kcontrol_new alc268_base_mixer[] = {
10586         /* output mixer control */
10587         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10588         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10589         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10590         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10591         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10592         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10593         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10594         { }
10595 };
10596
10597 /* bind Beep switches of both NID 0x0f and 0x10 */
10598 static struct hda_bind_ctls alc268_bind_beep_sw = {
10599         .ops = &snd_hda_bind_sw,
10600         .values = {
10601                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10602                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10603                 0
10604         },
10605 };
10606
10607 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10608         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10609         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10610         { }
10611 };
10612
10613 static struct hda_verb alc268_eapd_verbs[] = {
10614         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10615         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10616         { }
10617 };
10618
10619 /* Toshiba specific */
10620 #define alc268_toshiba_automute alc262_hippo_automute
10621
10622 static struct hda_verb alc268_toshiba_verbs[] = {
10623         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10624         { } /* end */
10625 };
10626
10627 static struct hda_input_mux alc268_acer_lc_capture_source = {
10628         .num_items = 2,
10629         .items = {
10630                 { "i-Mic", 0x6 },
10631                 { "E-Mic", 0x0 },
10632         },
10633 };
10634
10635 /* Acer specific */
10636 /* bind volumes of both NID 0x02 and 0x03 */
10637 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10638         .ops = &snd_hda_bind_vol,
10639         .values = {
10640                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10641                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10642                 0
10643         },
10644 };
10645
10646 /* mute/unmute internal speaker according to the hp jack and mute state */
10647 static void alc268_acer_automute(struct hda_codec *codec, int force)
10648 {
10649         struct alc_spec *spec = codec->spec;
10650         unsigned int mute;
10651
10652         if (force || !spec->sense_updated) {
10653                 unsigned int present;
10654                 present = snd_hda_codec_read(codec, 0x14, 0,
10655                                          AC_VERB_GET_PIN_SENSE, 0);
10656                 spec->jack_present = (present & 0x80000000) != 0;
10657                 spec->sense_updated = 1;
10658         }
10659         if (spec->jack_present)
10660                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10661         else /* unmute internal speaker if necessary */
10662                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10663         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10664                                  HDA_AMP_MUTE, mute);
10665 }
10666
10667
10668 /* bind hp and internal speaker mute (with plug check) */
10669 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10670                                      struct snd_ctl_elem_value *ucontrol)
10671 {
10672         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10673         long *valp = ucontrol->value.integer.value;
10674         int change;
10675
10676         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10677                                           HDA_AMP_MUTE,
10678                                           valp[0] ? 0 : HDA_AMP_MUTE);
10679         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10680                                            HDA_AMP_MUTE,
10681                                            valp[1] ? 0 : HDA_AMP_MUTE);
10682         if (change)
10683                 alc268_acer_automute(codec, 0);
10684         return change;
10685 }
10686
10687 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
10688         /* output mixer control */
10689         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10690         {
10691                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10692                 .name = "Master Playback Switch",
10693                 .info = snd_hda_mixer_amp_switch_info,
10694                 .get = snd_hda_mixer_amp_switch_get,
10695                 .put = alc268_acer_master_sw_put,
10696                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10697         },
10698         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
10699         { }
10700 };
10701
10702 static struct snd_kcontrol_new alc268_acer_mixer[] = {
10703         /* output mixer control */
10704         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10705         {
10706                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10707                 .name = "Master Playback Switch",
10708                 .info = snd_hda_mixer_amp_switch_info,
10709                 .get = snd_hda_mixer_amp_switch_get,
10710                 .put = alc268_acer_master_sw_put,
10711                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10712         },
10713         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10714         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10715         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10716         { }
10717 };
10718
10719 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
10720         /* output mixer control */
10721         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10722         {
10723                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10724                 .name = "Master Playback Switch",
10725                 .info = snd_hda_mixer_amp_switch_info,
10726                 .get = snd_hda_mixer_amp_switch_get,
10727                 .put = alc268_acer_master_sw_put,
10728                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10729         },
10730         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10731         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10732         { }
10733 };
10734
10735 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
10736         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10737         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10738         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10739         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10740         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
10741         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
10742         { }
10743 };
10744
10745 static struct hda_verb alc268_acer_verbs[] = {
10746         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
10747         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10748         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10749         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10750         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10751         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10752         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10753         { }
10754 };
10755
10756 /* unsolicited event for HP jack sensing */
10757 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
10758                                        unsigned int res)
10759 {
10760         if ((res >> 26) != ALC880_HP_EVENT)
10761                 return;
10762         alc268_toshiba_automute(codec);
10763 }
10764
10765 static void alc268_acer_unsol_event(struct hda_codec *codec,
10766                                        unsigned int res)
10767 {
10768         if ((res >> 26) != ALC880_HP_EVENT)
10769                 return;
10770         alc268_acer_automute(codec, 1);
10771 }
10772
10773 static void alc268_acer_init_hook(struct hda_codec *codec)
10774 {
10775         alc268_acer_automute(codec, 1);
10776 }
10777
10778 /* toggle speaker-output according to the hp-jack state */
10779 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
10780 {
10781         unsigned int present;
10782         unsigned char bits;
10783
10784         present = snd_hda_codec_read(codec, 0x15, 0,
10785                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10786         bits = present ? AMP_IN_MUTE(0) : 0;
10787         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
10788                                 AMP_IN_MUTE(0), bits);
10789         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
10790                                 AMP_IN_MUTE(0), bits);
10791 }
10792
10793
10794 static void alc268_acer_mic_automute(struct hda_codec *codec)
10795 {
10796         unsigned int present;
10797
10798         present = snd_hda_codec_read(codec, 0x18, 0,
10799                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10800         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
10801                             present ? 0x0 : 0x6);
10802 }
10803
10804 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
10805                                     unsigned int res)
10806 {
10807         if ((res >> 26) == ALC880_HP_EVENT)
10808                 alc268_aspire_one_speaker_automute(codec);
10809         if ((res >> 26) == ALC880_MIC_EVENT)
10810                 alc268_acer_mic_automute(codec);
10811 }
10812
10813 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
10814 {
10815         alc268_aspire_one_speaker_automute(codec);
10816         alc268_acer_mic_automute(codec);
10817 }
10818
10819 static struct snd_kcontrol_new alc268_dell_mixer[] = {
10820         /* output mixer control */
10821         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10822         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10823         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10824         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10825         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10826         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10827         { }
10828 };
10829
10830 static struct hda_verb alc268_dell_verbs[] = {
10831         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10832         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10833         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10834         { }
10835 };
10836
10837 /* mute/unmute internal speaker according to the hp jack and mute state */
10838 static void alc268_dell_automute(struct hda_codec *codec)
10839 {
10840         unsigned int present;
10841         unsigned int mute;
10842
10843         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
10844         if (present & 0x80000000)
10845                 mute = HDA_AMP_MUTE;
10846         else
10847                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
10848         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10849                                  HDA_AMP_MUTE, mute);
10850 }
10851
10852 static void alc268_dell_unsol_event(struct hda_codec *codec,
10853                                     unsigned int res)
10854 {
10855         if ((res >> 26) != ALC880_HP_EVENT)
10856                 return;
10857         alc268_dell_automute(codec);
10858 }
10859
10860 #define alc268_dell_init_hook   alc268_dell_automute
10861
10862 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
10863         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10864         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10865         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10866         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10867         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10868         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
10869         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
10870         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10871         { }
10872 };
10873
10874 static struct hda_verb alc267_quanta_il1_verbs[] = {
10875         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10876         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
10877         { }
10878 };
10879
10880 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
10881 {
10882         unsigned int present;
10883
10884         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
10885                 & AC_PINSENSE_PRESENCE;
10886         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
10887                             present ? 0 : PIN_OUT);
10888 }
10889
10890 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
10891 {
10892         unsigned int present;
10893
10894         present = snd_hda_codec_read(codec, 0x18, 0,
10895                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10896         snd_hda_codec_write(codec, 0x23, 0,
10897                             AC_VERB_SET_CONNECT_SEL,
10898                             present ? 0x00 : 0x01);
10899 }
10900
10901 static void alc267_quanta_il1_automute(struct hda_codec *codec)
10902 {
10903         alc267_quanta_il1_hp_automute(codec);
10904         alc267_quanta_il1_mic_automute(codec);
10905 }
10906
10907 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
10908                                            unsigned int res)
10909 {
10910         switch (res >> 26) {
10911         case ALC880_HP_EVENT:
10912                 alc267_quanta_il1_hp_automute(codec);
10913                 break;
10914         case ALC880_MIC_EVENT:
10915                 alc267_quanta_il1_mic_automute(codec);
10916                 break;
10917         }
10918 }
10919
10920 /*
10921  * generic initialization of ADC, input mixers and output mixers
10922  */
10923 static struct hda_verb alc268_base_init_verbs[] = {
10924         /* Unmute DAC0-1 and set vol = 0 */
10925         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10926         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10927         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10928         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10929         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10930         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10931
10932         /*
10933          * Set up output mixers (0x0c - 0x0e)
10934          */
10935         /* set vol=0 to output mixers */
10936         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10937         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10938         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10939         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
10940
10941         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10942         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10943
10944         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10945         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10946         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10947         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10948         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10949         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10950         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10951         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10952
10953         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10954         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10955         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10956         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10957         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10958         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10959         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10960
10961         /* set PCBEEP vol = 0, mute connections */
10962         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10963         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10964         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10965
10966         /* Unmute Selector 23h,24h and set the default input to mic-in */
10967
10968         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
10969         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10970         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
10971         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10972
10973         { }
10974 };
10975
10976 /*
10977  * generic initialization of ADC, input mixers and output mixers
10978  */
10979 static struct hda_verb alc268_volume_init_verbs[] = {
10980         /* set output DAC */
10981         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10982         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10983         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10984         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10985
10986         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10987         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10988         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10989         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10990         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10991
10992         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10993         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10994         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10995         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10996         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10997
10998         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10999         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11000         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11001         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11002
11003         /* set PCBEEP vol = 0, mute connections */
11004         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11005         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11006         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11007
11008         { }
11009 };
11010
11011 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11012         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11013         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11014         {
11015                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11016                 /* The multiple "Capture Source" controls confuse alsamixer
11017                  * So call somewhat different..
11018                  */
11019                 /* .name = "Capture Source", */
11020                 .name = "Input Source",
11021                 .count = 1,
11022                 .info = alc_mux_enum_info,
11023                 .get = alc_mux_enum_get,
11024                 .put = alc_mux_enum_put,
11025         },
11026         { } /* end */
11027 };
11028
11029 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11030         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11031         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11032         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11033         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11034         {
11035                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11036                 /* The multiple "Capture Source" controls confuse alsamixer
11037                  * So call somewhat different..
11038                  */
11039                 /* .name = "Capture Source", */
11040                 .name = "Input Source",
11041                 .count = 2,
11042                 .info = alc_mux_enum_info,
11043                 .get = alc_mux_enum_get,
11044                 .put = alc_mux_enum_put,
11045         },
11046         { } /* end */
11047 };
11048
11049 static struct hda_input_mux alc268_capture_source = {
11050         .num_items = 4,
11051         .items = {
11052                 { "Mic", 0x0 },
11053                 { "Front Mic", 0x1 },
11054                 { "Line", 0x2 },
11055                 { "CD", 0x3 },
11056         },
11057 };
11058
11059 static struct hda_input_mux alc268_acer_capture_source = {
11060         .num_items = 3,
11061         .items = {
11062                 { "Mic", 0x0 },
11063                 { "Internal Mic", 0x1 },
11064                 { "Line", 0x2 },
11065         },
11066 };
11067
11068 static struct hda_input_mux alc268_acer_dmic_capture_source = {
11069         .num_items = 3,
11070         .items = {
11071                 { "Mic", 0x0 },
11072                 { "Internal Mic", 0x6 },
11073                 { "Line", 0x2 },
11074         },
11075 };
11076
11077 #ifdef CONFIG_SND_DEBUG
11078 static struct snd_kcontrol_new alc268_test_mixer[] = {
11079         /* Volume widgets */
11080         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11081         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11082         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11083         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11084         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11085         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11086         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11087         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11088         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11089         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11090         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11091         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11092         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11093         /* The below appears problematic on some hardwares */
11094         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11095         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11096         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11097         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11098         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11099
11100         /* Modes for retasking pin widgets */
11101         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11102         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11103         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11104         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11105
11106         /* Controls for GPIO pins, assuming they are configured as outputs */
11107         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11108         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11109         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11110         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11111
11112         /* Switches to allow the digital SPDIF output pin to be enabled.
11113          * The ALC268 does not have an SPDIF input.
11114          */
11115         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11116
11117         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11118          * this output to turn on an external amplifier.
11119          */
11120         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11121         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11122
11123         { } /* end */
11124 };
11125 #endif
11126
11127 /* create input playback/capture controls for the given pin */
11128 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11129                                     const char *ctlname, int idx)
11130 {
11131         char name[32];
11132         int err;
11133
11134         sprintf(name, "%s Playback Volume", ctlname);
11135         if (nid == 0x14) {
11136                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11137                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11138                                                       HDA_OUTPUT));
11139                 if (err < 0)
11140                         return err;
11141         } else if (nid == 0x15) {
11142                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11143                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11144                                                       HDA_OUTPUT));
11145                 if (err < 0)
11146                         return err;
11147         } else
11148                 return -1;
11149         sprintf(name, "%s Playback Switch", ctlname);
11150         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11151                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11152         if (err < 0)
11153                 return err;
11154         return 0;
11155 }
11156
11157 /* add playback controls from the parsed DAC table */
11158 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11159                                              const struct auto_pin_cfg *cfg)
11160 {
11161         hda_nid_t nid;
11162         int err;
11163
11164         spec->multiout.num_dacs = 2;    /* only use one dac */
11165         spec->multiout.dac_nids = spec->private_dac_nids;
11166         spec->multiout.dac_nids[0] = 2;
11167         spec->multiout.dac_nids[1] = 3;
11168
11169         nid = cfg->line_out_pins[0];
11170         if (nid)
11171                 alc268_new_analog_output(spec, nid, "Front", 0);
11172
11173         nid = cfg->speaker_pins[0];
11174         if (nid == 0x1d) {
11175                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11176                                   "Speaker Playback Volume",
11177                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11178                 if (err < 0)
11179                         return err;
11180         }
11181         nid = cfg->hp_pins[0];
11182         if (nid)
11183                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11184
11185         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11186         if (nid == 0x16) {
11187                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11188                                   "Mono Playback Switch",
11189                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11190                 if (err < 0)
11191                         return err;
11192         }
11193         return 0;
11194 }
11195
11196 /* create playback/capture controls for input pins */
11197 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11198                                                 const struct auto_pin_cfg *cfg)
11199 {
11200         struct hda_input_mux *imux = &spec->private_imux;
11201         int i, idx1;
11202
11203         for (i = 0; i < AUTO_PIN_LAST; i++) {
11204                 switch(cfg->input_pins[i]) {
11205                 case 0x18:
11206                         idx1 = 0;       /* Mic 1 */
11207                         break;
11208                 case 0x19:
11209                         idx1 = 1;       /* Mic 2 */
11210                         break;
11211                 case 0x1a:
11212                         idx1 = 2;       /* Line In */
11213                         break;
11214                 case 0x1c:
11215                         idx1 = 3;       /* CD */
11216                         break;
11217                 case 0x12:
11218                 case 0x13:
11219                         idx1 = 6;       /* digital mics */
11220                         break;
11221                 default:
11222                         continue;
11223                 }
11224                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11225                 imux->items[imux->num_items].index = idx1;
11226                 imux->num_items++;
11227         }
11228         return 0;
11229 }
11230
11231 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11232 {
11233         struct alc_spec *spec = codec->spec;
11234         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11235         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11236         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11237         unsigned int    dac_vol1, dac_vol2;
11238
11239         if (speaker_nid) {
11240                 snd_hda_codec_write(codec, speaker_nid, 0,
11241                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11242                 snd_hda_codec_write(codec, 0x0f, 0,
11243                                     AC_VERB_SET_AMP_GAIN_MUTE,
11244                                     AMP_IN_UNMUTE(1));
11245                 snd_hda_codec_write(codec, 0x10, 0,
11246                                     AC_VERB_SET_AMP_GAIN_MUTE,
11247                                     AMP_IN_UNMUTE(1));
11248         } else {
11249                 snd_hda_codec_write(codec, 0x0f, 0,
11250                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11251                 snd_hda_codec_write(codec, 0x10, 0,
11252                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11253         }
11254
11255         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11256         if (line_nid == 0x14)
11257                 dac_vol2 = AMP_OUT_ZERO;
11258         else if (line_nid == 0x15)
11259                 dac_vol1 = AMP_OUT_ZERO;
11260         if (hp_nid == 0x14)
11261                 dac_vol2 = AMP_OUT_ZERO;
11262         else if (hp_nid == 0x15)
11263                 dac_vol1 = AMP_OUT_ZERO;
11264         if (line_nid != 0x16 || hp_nid != 0x16 ||
11265             spec->autocfg.line_out_pins[1] != 0x16 ||
11266             spec->autocfg.line_out_pins[2] != 0x16)
11267                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11268
11269         snd_hda_codec_write(codec, 0x02, 0,
11270                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11271         snd_hda_codec_write(codec, 0x03, 0,
11272                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11273 }
11274
11275 /* pcm configuration: identiacal with ALC880 */
11276 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11277 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11278 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11279 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11280
11281 /*
11282  * BIOS auto configuration
11283  */
11284 static int alc268_parse_auto_config(struct hda_codec *codec)
11285 {
11286         struct alc_spec *spec = codec->spec;
11287         int err;
11288         static hda_nid_t alc268_ignore[] = { 0 };
11289
11290         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11291                                            alc268_ignore);
11292         if (err < 0)
11293                 return err;
11294         if (!spec->autocfg.line_outs)
11295                 return 0; /* can't find valid BIOS pin config */
11296
11297         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11298         if (err < 0)
11299                 return err;
11300         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11301         if (err < 0)
11302                 return err;
11303
11304         spec->multiout.max_channels = 2;
11305
11306         /* digital only support output */
11307         if (spec->autocfg.dig_out_pin)
11308                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11309
11310         if (spec->kctls.list)
11311                 add_mixer(spec, spec->kctls.list);
11312
11313         if (spec->autocfg.speaker_pins[0] != 0x1d)
11314                 add_mixer(spec, alc268_beep_mixer);
11315
11316         add_verb(spec, alc268_volume_init_verbs);
11317         spec->num_mux_defs = 1;
11318         spec->input_mux = &spec->private_imux;
11319
11320         err = alc_auto_add_mic_boost(codec);
11321         if (err < 0)
11322                 return err;
11323
11324         store_pin_configs(codec);
11325         return 1;
11326 }
11327
11328 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
11329 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
11330 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
11331
11332 /* init callback for auto-configuration model -- overriding the default init */
11333 static void alc268_auto_init(struct hda_codec *codec)
11334 {
11335         struct alc_spec *spec = codec->spec;
11336         alc268_auto_init_multi_out(codec);
11337         alc268_auto_init_hp_out(codec);
11338         alc268_auto_init_mono_speaker_out(codec);
11339         alc268_auto_init_analog_input(codec);
11340         if (spec->unsol_event)
11341                 alc_inithook(codec);
11342 }
11343
11344 /*
11345  * configuration and preset
11346  */
11347 static const char *alc268_models[ALC268_MODEL_LAST] = {
11348         [ALC267_QUANTA_IL1]     = "quanta-il1",
11349         [ALC268_3ST]            = "3stack",
11350         [ALC268_TOSHIBA]        = "toshiba",
11351         [ALC268_ACER]           = "acer",
11352         [ALC268_ACER_DMIC]      = "acer-dmic",
11353         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
11354         [ALC268_DELL]           = "dell",
11355         [ALC268_ZEPTO]          = "zepto",
11356 #ifdef CONFIG_SND_DEBUG
11357         [ALC268_TEST]           = "test",
11358 #endif
11359         [ALC268_AUTO]           = "auto",
11360 };
11361
11362 static struct snd_pci_quirk alc268_cfg_tbl[] = {
11363         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
11364         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
11365         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
11366         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
11367         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11368         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11369                                                 ALC268_ACER_ASPIRE_ONE),
11370         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
11371         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
11372         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
11373         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
11374         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11375         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
11376         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
11377         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
11378         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
11379         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
11380         {}
11381 };
11382
11383 static struct alc_config_preset alc268_presets[] = {
11384         [ALC267_QUANTA_IL1] = {
11385                 .mixers = { alc267_quanta_il1_mixer },
11386                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11387                                 alc267_quanta_il1_verbs },
11388                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11389                 .dac_nids = alc268_dac_nids,
11390                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11391                 .adc_nids = alc268_adc_nids_alt,
11392                 .hp_nid = 0x03,
11393                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11394                 .channel_mode = alc268_modes,
11395                 .input_mux = &alc268_capture_source,
11396                 .unsol_event = alc267_quanta_il1_unsol_event,
11397                 .init_hook = alc267_quanta_il1_automute,
11398         },
11399         [ALC268_3ST] = {
11400                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11401                             alc268_beep_mixer },
11402                 .init_verbs = { alc268_base_init_verbs },
11403                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11404                 .dac_nids = alc268_dac_nids,
11405                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11406                 .adc_nids = alc268_adc_nids_alt,
11407                 .capsrc_nids = alc268_capsrc_nids,
11408                 .hp_nid = 0x03,
11409                 .dig_out_nid = ALC268_DIGOUT_NID,
11410                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11411                 .channel_mode = alc268_modes,
11412                 .input_mux = &alc268_capture_source,
11413         },
11414         [ALC268_TOSHIBA] = {
11415                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11416                             alc268_beep_mixer },
11417                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11418                                 alc268_toshiba_verbs },
11419                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11420                 .dac_nids = alc268_dac_nids,
11421                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11422                 .adc_nids = alc268_adc_nids_alt,
11423                 .capsrc_nids = alc268_capsrc_nids,
11424                 .hp_nid = 0x03,
11425                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11426                 .channel_mode = alc268_modes,
11427                 .input_mux = &alc268_capture_source,
11428                 .unsol_event = alc268_toshiba_unsol_event,
11429                 .init_hook = alc268_toshiba_automute,
11430         },
11431         [ALC268_ACER] = {
11432                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
11433                             alc268_beep_mixer },
11434                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11435                                 alc268_acer_verbs },
11436                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11437                 .dac_nids = alc268_dac_nids,
11438                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11439                 .adc_nids = alc268_adc_nids_alt,
11440                 .capsrc_nids = alc268_capsrc_nids,
11441                 .hp_nid = 0x02,
11442                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11443                 .channel_mode = alc268_modes,
11444                 .input_mux = &alc268_acer_capture_source,
11445                 .unsol_event = alc268_acer_unsol_event,
11446                 .init_hook = alc268_acer_init_hook,
11447         },
11448         [ALC268_ACER_DMIC] = {
11449                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
11450                             alc268_beep_mixer },
11451                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11452                                 alc268_acer_verbs },
11453                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11454                 .dac_nids = alc268_dac_nids,
11455                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11456                 .adc_nids = alc268_adc_nids_alt,
11457                 .capsrc_nids = alc268_capsrc_nids,
11458                 .hp_nid = 0x02,
11459                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11460                 .channel_mode = alc268_modes,
11461                 .input_mux = &alc268_acer_dmic_capture_source,
11462                 .unsol_event = alc268_acer_unsol_event,
11463                 .init_hook = alc268_acer_init_hook,
11464         },
11465         [ALC268_ACER_ASPIRE_ONE] = {
11466                 .mixers = { alc268_acer_aspire_one_mixer,
11467                                 alc268_capture_alt_mixer },
11468                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11469                                 alc268_acer_aspire_one_verbs },
11470                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11471                 .dac_nids = alc268_dac_nids,
11472                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11473                 .adc_nids = alc268_adc_nids_alt,
11474                 .capsrc_nids = alc268_capsrc_nids,
11475                 .hp_nid = 0x03,
11476                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11477                 .channel_mode = alc268_modes,
11478                 .input_mux = &alc268_acer_lc_capture_source,
11479                 .unsol_event = alc268_acer_lc_unsol_event,
11480                 .init_hook = alc268_acer_lc_init_hook,
11481         },
11482         [ALC268_DELL] = {
11483                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
11484                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11485                                 alc268_dell_verbs },
11486                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11487                 .dac_nids = alc268_dac_nids,
11488                 .hp_nid = 0x02,
11489                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11490                 .channel_mode = alc268_modes,
11491                 .unsol_event = alc268_dell_unsol_event,
11492                 .init_hook = alc268_dell_init_hook,
11493                 .input_mux = &alc268_capture_source,
11494         },
11495         [ALC268_ZEPTO] = {
11496                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11497                             alc268_beep_mixer },
11498                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11499                                 alc268_toshiba_verbs },
11500                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11501                 .dac_nids = alc268_dac_nids,
11502                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11503                 .adc_nids = alc268_adc_nids_alt,
11504                 .capsrc_nids = alc268_capsrc_nids,
11505                 .hp_nid = 0x03,
11506                 .dig_out_nid = ALC268_DIGOUT_NID,
11507                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11508                 .channel_mode = alc268_modes,
11509                 .input_mux = &alc268_capture_source,
11510                 .unsol_event = alc268_toshiba_unsol_event,
11511                 .init_hook = alc268_toshiba_automute
11512         },
11513 #ifdef CONFIG_SND_DEBUG
11514         [ALC268_TEST] = {
11515                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11516                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11517                                 alc268_volume_init_verbs },
11518                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11519                 .dac_nids = alc268_dac_nids,
11520                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11521                 .adc_nids = alc268_adc_nids_alt,
11522                 .capsrc_nids = alc268_capsrc_nids,
11523                 .hp_nid = 0x03,
11524                 .dig_out_nid = ALC268_DIGOUT_NID,
11525                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11526                 .channel_mode = alc268_modes,
11527                 .input_mux = &alc268_capture_source,
11528         },
11529 #endif
11530 };
11531
11532 static int patch_alc268(struct hda_codec *codec)
11533 {
11534         struct alc_spec *spec;
11535         int board_config;
11536         int err;
11537
11538         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11539         if (spec == NULL)
11540                 return -ENOMEM;
11541
11542         codec->spec = spec;
11543
11544         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11545                                                   alc268_models,
11546                                                   alc268_cfg_tbl);
11547
11548         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11549                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11550                        "trying auto-probe from BIOS...\n");
11551                 board_config = ALC268_AUTO;
11552         }
11553
11554         if (board_config == ALC268_AUTO) {
11555                 /* automatic parse from the BIOS config */
11556                 err = alc268_parse_auto_config(codec);
11557                 if (err < 0) {
11558                         alc_free(codec);
11559                         return err;
11560                 } else if (!err) {
11561                         printk(KERN_INFO
11562                                "hda_codec: Cannot set up configuration "
11563                                "from BIOS.  Using base mode...\n");
11564                         board_config = ALC268_3ST;
11565                 }
11566         }
11567
11568         if (board_config != ALC268_AUTO)
11569                 setup_preset(spec, &alc268_presets[board_config]);
11570
11571         if (codec->vendor_id == 0x10ec0267) {
11572                 spec->stream_name_analog = "ALC267 Analog";
11573                 spec->stream_name_digital = "ALC267 Digital";
11574         } else {
11575                 spec->stream_name_analog = "ALC268 Analog";
11576                 spec->stream_name_digital = "ALC268 Digital";
11577         }
11578
11579         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11580         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11581         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11582
11583         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11584
11585         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11586                 /* override the amp caps for beep generator */
11587                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11588                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11589                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11590                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11591                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11592
11593         if (!spec->adc_nids && spec->input_mux) {
11594                 /* check whether NID 0x07 is valid */
11595                 unsigned int wcap = get_wcaps(codec, 0x07);
11596                 int i;
11597
11598                 /* get type */
11599                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11600                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11601                         spec->adc_nids = alc268_adc_nids_alt;
11602                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11603                         add_mixer(spec, alc268_capture_alt_mixer);
11604                 } else {
11605                         spec->adc_nids = alc268_adc_nids;
11606                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11607                         add_mixer(spec, alc268_capture_mixer);
11608                 }
11609                 spec->capsrc_nids = alc268_capsrc_nids;
11610                 /* set default input source */
11611                 for (i = 0; i < spec->num_adc_nids; i++)
11612                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11613                                 0, AC_VERB_SET_CONNECT_SEL,
11614                                 spec->input_mux->items[0].index);
11615         }
11616
11617         spec->vmaster_nid = 0x02;
11618
11619         codec->patch_ops = alc_patch_ops;
11620         if (board_config == ALC268_AUTO)
11621                 spec->init_hook = alc268_auto_init;
11622
11623         return 0;
11624 }
11625
11626 /*
11627  *  ALC269 channel source setting (2 channel)
11628  */
11629 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11630
11631 #define alc269_dac_nids         alc260_dac_nids
11632
11633 static hda_nid_t alc269_adc_nids[1] = {
11634         /* ADC1 */
11635         0x08,
11636 };
11637
11638 static hda_nid_t alc269_capsrc_nids[1] = {
11639         0x23,
11640 };
11641
11642 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11643  *       not a mux!
11644  */
11645
11646 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11647         .num_items = 2,
11648         .items = {
11649                 { "i-Mic", 0x5 },
11650                 { "e-Mic", 0x0 },
11651         },
11652 };
11653
11654 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11655         .num_items = 2,
11656         .items = {
11657                 { "i-Mic", 0x1 },
11658                 { "e-Mic", 0x0 },
11659         },
11660 };
11661
11662 #define alc269_modes            alc260_modes
11663 #define alc269_capture_source   alc880_lg_lw_capture_source
11664
11665 static struct snd_kcontrol_new alc269_base_mixer[] = {
11666         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11667         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11668         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11669         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11670         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11671         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11672         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11673         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11674         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11675         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11676         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11677         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11678         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11679         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
11680         { } /* end */
11681 };
11682
11683 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
11684         /* output mixer control */
11685         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11686         {
11687                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11688                 .name = "Master Playback Switch",
11689                 .info = snd_hda_mixer_amp_switch_info,
11690                 .get = snd_hda_mixer_amp_switch_get,
11691                 .put = alc268_acer_master_sw_put,
11692                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11693         },
11694         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11695         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11696         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11697         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11698         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11699         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11700         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
11701         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
11702         { }
11703 };
11704
11705 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
11706         /* output mixer control */
11707         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11708         {
11709                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11710                 .name = "Master Playback Switch",
11711                 .info = snd_hda_mixer_amp_switch_info,
11712                 .get = snd_hda_mixer_amp_switch_get,
11713                 .put = alc268_acer_master_sw_put,
11714                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11715         },
11716         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11717         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11718         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11719         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11720         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11721         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11722         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
11723         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
11724         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
11725         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
11726         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
11727         { }
11728 };
11729
11730 /* bind volumes of both NID 0x0c and 0x0d */
11731 static struct hda_bind_ctls alc269_epc_bind_vol = {
11732         .ops = &snd_hda_bind_vol,
11733         .values = {
11734                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11735                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11736                 0
11737         },
11738 };
11739
11740 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
11741         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11742         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
11743         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11744         { } /* end */
11745 };
11746
11747 /* capture mixer elements */
11748 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
11749         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11750         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11751         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11752         { } /* end */
11753 };
11754
11755 /* FSC amilo */
11756 static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
11757         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11758         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11759         HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
11760         { } /* end */
11761 };
11762
11763 /* beep control */
11764 static struct snd_kcontrol_new alc269_beep_mixer[] = {
11765         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11766         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11767         { } /* end */
11768 };
11769
11770 static struct hda_verb alc269_quanta_fl1_verbs[] = {
11771         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11772         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11773         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11774         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11775         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11776         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11777         { }
11778 };
11779
11780 static struct hda_verb alc269_lifebook_verbs[] = {
11781         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11782         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
11783         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11784         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11785         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11786         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11787         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11788         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11789         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11790         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11791         { }
11792 };
11793
11794 /* toggle speaker-output according to the hp-jack state */
11795 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
11796 {
11797         unsigned int present;
11798         unsigned char bits;
11799
11800         present = snd_hda_codec_read(codec, 0x15, 0,
11801                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11802         bits = present ? AMP_IN_MUTE(0) : 0;
11803         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11804                         AMP_IN_MUTE(0), bits);
11805         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11806                         AMP_IN_MUTE(0), bits);
11807
11808         snd_hda_codec_write(codec, 0x20, 0,
11809                         AC_VERB_SET_COEF_INDEX, 0x0c);
11810         snd_hda_codec_write(codec, 0x20, 0,
11811                         AC_VERB_SET_PROC_COEF, 0x680);
11812
11813         snd_hda_codec_write(codec, 0x20, 0,
11814                         AC_VERB_SET_COEF_INDEX, 0x0c);
11815         snd_hda_codec_write(codec, 0x20, 0,
11816                         AC_VERB_SET_PROC_COEF, 0x480);
11817 }
11818
11819 /* toggle speaker-output according to the hp-jacks state */
11820 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
11821 {
11822         unsigned int present;
11823         unsigned char bits;
11824
11825         /* Check laptop headphone socket */
11826         present = snd_hda_codec_read(codec, 0x15, 0,
11827                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11828
11829         /* Check port replicator headphone socket */
11830         present |= snd_hda_codec_read(codec, 0x1a, 0,
11831                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11832
11833         bits = present ? AMP_IN_MUTE(0) : 0;
11834         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11835                         AMP_IN_MUTE(0), bits);
11836         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11837                         AMP_IN_MUTE(0), bits);
11838
11839         snd_hda_codec_write(codec, 0x20, 0,
11840                         AC_VERB_SET_COEF_INDEX, 0x0c);
11841         snd_hda_codec_write(codec, 0x20, 0,
11842                         AC_VERB_SET_PROC_COEF, 0x680);
11843
11844         snd_hda_codec_write(codec, 0x20, 0,
11845                         AC_VERB_SET_COEF_INDEX, 0x0c);
11846         snd_hda_codec_write(codec, 0x20, 0,
11847                         AC_VERB_SET_PROC_COEF, 0x480);
11848 }
11849
11850 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
11851 {
11852         unsigned int present;
11853
11854         present = snd_hda_codec_read(codec, 0x18, 0,
11855                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11856         snd_hda_codec_write(codec, 0x23, 0,
11857                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
11858 }
11859
11860 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
11861 {
11862         unsigned int present_laptop;
11863         unsigned int present_dock;
11864
11865         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
11866                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11867
11868         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
11869                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11870
11871         /* Laptop mic port overrides dock mic port, design decision */
11872         if (present_dock)
11873                 snd_hda_codec_write(codec, 0x23, 0,
11874                                 AC_VERB_SET_CONNECT_SEL, 0x3);
11875         if (present_laptop)
11876                 snd_hda_codec_write(codec, 0x23, 0,
11877                                 AC_VERB_SET_CONNECT_SEL, 0x0);
11878         if (!present_dock && !present_laptop)
11879                 snd_hda_codec_write(codec, 0x23, 0,
11880                                 AC_VERB_SET_CONNECT_SEL, 0x1);
11881 }
11882
11883 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
11884                                     unsigned int res)
11885 {
11886         if ((res >> 26) == ALC880_HP_EVENT)
11887                 alc269_quanta_fl1_speaker_automute(codec);
11888         if ((res >> 26) == ALC880_MIC_EVENT)
11889                 alc269_quanta_fl1_mic_automute(codec);
11890 }
11891
11892 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
11893                                         unsigned int res)
11894 {
11895         if ((res >> 26) == ALC880_HP_EVENT)
11896                 alc269_lifebook_speaker_automute(codec);
11897         if ((res >> 26) == ALC880_MIC_EVENT)
11898                 alc269_lifebook_mic_autoswitch(codec);
11899 }
11900
11901 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
11902 {
11903         alc269_quanta_fl1_speaker_automute(codec);
11904         alc269_quanta_fl1_mic_automute(codec);
11905 }
11906
11907 static void alc269_lifebook_init_hook(struct hda_codec *codec)
11908 {
11909         alc269_lifebook_speaker_automute(codec);
11910         alc269_lifebook_mic_autoswitch(codec);
11911 }
11912
11913 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
11914         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11915         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
11916         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11917         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
11918         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11919         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11920         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11921         {}
11922 };
11923
11924 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
11925         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11926         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
11927         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11928         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
11929         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11930         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11931         {}
11932 };
11933
11934 /* toggle speaker-output according to the hp-jack state */
11935 static void alc269_speaker_automute(struct hda_codec *codec)
11936 {
11937         unsigned int present;
11938         unsigned char bits;
11939
11940         present = snd_hda_codec_read(codec, 0x15, 0,
11941                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11942         bits = present ? AMP_IN_MUTE(0) : 0;
11943         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11944                                 AMP_IN_MUTE(0), bits);
11945         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11946                                 AMP_IN_MUTE(0), bits);
11947 }
11948
11949 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
11950 {
11951         unsigned int present;
11952
11953         present = snd_hda_codec_read(codec, 0x18, 0,
11954                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11955         snd_hda_codec_write(codec, 0x23, 0,
11956                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
11957 }
11958
11959 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
11960 {
11961         unsigned int present;
11962
11963         present = snd_hda_codec_read(codec, 0x18, 0,
11964                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11965         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11966                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
11967         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11968                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
11969 }
11970
11971 /* unsolicited event for HP jack sensing */
11972 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
11973                                      unsigned int res)
11974 {
11975         if ((res >> 26) == ALC880_HP_EVENT)
11976                 alc269_speaker_automute(codec);
11977
11978         if ((res >> 26) == ALC880_MIC_EVENT)
11979                 alc269_eeepc_dmic_automute(codec);
11980 }
11981
11982 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
11983 {
11984         alc269_speaker_automute(codec);
11985         alc269_eeepc_dmic_automute(codec);
11986 }
11987
11988 /* unsolicited event for HP jack sensing */
11989 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
11990                                      unsigned int res)
11991 {
11992         if ((res >> 26) == ALC880_HP_EVENT)
11993                 alc269_speaker_automute(codec);
11994
11995         if ((res >> 26) == ALC880_MIC_EVENT)
11996                 alc269_eeepc_amic_automute(codec);
11997 }
11998
11999 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
12000 {
12001         alc269_speaker_automute(codec);
12002         alc269_eeepc_amic_automute(codec);
12003 }
12004
12005 /*
12006  * generic initialization of ADC, input mixers and output mixers
12007  */
12008 static struct hda_verb alc269_init_verbs[] = {
12009         /*
12010          * Unmute ADC0 and set the default input to mic-in
12011          */
12012         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12013
12014         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
12015          * analog-loopback mixer widget
12016          * Note: PASD motherboards uses the Line In 2 as the input for
12017          * front panel mic (mic 2)
12018          */
12019         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12020         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12021         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12022         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12023         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12024         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12025
12026         /*
12027          * Set up output mixers (0x0c - 0x0e)
12028          */
12029         /* set vol=0 to output mixers */
12030         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12031         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12032
12033         /* set up input amps for analog loopback */
12034         /* Amp Indices: DAC = 0, mixer = 1 */
12035         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12036         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12037         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12038         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12039         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12040         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12041
12042         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12043         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12044         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12045         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12046         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12047         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12048         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12049
12050         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12051         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12052         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12053         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12054         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12055         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12056         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12057
12058         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12059         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12060
12061         /* FIXME: use matrix-type input source selection */
12062         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12063         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12064         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12065         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12066         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12067         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12068
12069         /* set EAPD */
12070         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12071         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12072         { }
12073 };
12074
12075 /* add playback controls from the parsed DAC table */
12076 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12077                                              const struct auto_pin_cfg *cfg)
12078 {
12079         hda_nid_t nid;
12080         int err;
12081
12082         spec->multiout.num_dacs = 1;    /* only use one dac */
12083         spec->multiout.dac_nids = spec->private_dac_nids;
12084         spec->multiout.dac_nids[0] = 2;
12085
12086         nid = cfg->line_out_pins[0];
12087         if (nid) {
12088                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12089                                   "Front Playback Volume",
12090                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12091                 if (err < 0)
12092                         return err;
12093                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12094                                   "Front Playback Switch",
12095                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12096                 if (err < 0)
12097                         return err;
12098         }
12099
12100         nid = cfg->speaker_pins[0];
12101         if (nid) {
12102                 if (!cfg->line_out_pins[0]) {
12103                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12104                                           "Speaker Playback Volume",
12105                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12106                                                               HDA_OUTPUT));
12107                         if (err < 0)
12108                                 return err;
12109                 }
12110                 if (nid == 0x16) {
12111                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12112                                           "Speaker Playback Switch",
12113                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12114                                                               HDA_OUTPUT));
12115                         if (err < 0)
12116                                 return err;
12117                 } else {
12118                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12119                                           "Speaker Playback Switch",
12120                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12121                                                               HDA_OUTPUT));
12122                         if (err < 0)
12123                                 return err;
12124                 }
12125         }
12126         nid = cfg->hp_pins[0];
12127         if (nid) {
12128                 /* spec->multiout.hp_nid = 2; */
12129                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12130                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12131                                           "Headphone Playback Volume",
12132                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12133                                                               HDA_OUTPUT));
12134                         if (err < 0)
12135                                 return err;
12136                 }
12137                 if (nid == 0x16) {
12138                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12139                                           "Headphone Playback Switch",
12140                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12141                                                               HDA_OUTPUT));
12142                         if (err < 0)
12143                                 return err;
12144                 } else {
12145                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12146                                           "Headphone Playback Switch",
12147                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12148                                                               HDA_OUTPUT));
12149                         if (err < 0)
12150                                 return err;
12151                 }
12152         }
12153         return 0;
12154 }
12155
12156 static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
12157                                                 const struct auto_pin_cfg *cfg)
12158 {
12159         int err;
12160
12161         err = alc880_auto_create_analog_input_ctls(spec, cfg);
12162         if (err < 0)
12163                 return err;
12164         /* digital-mic input pin is excluded in alc880_auto_create..()
12165          * because it's under 0x18
12166          */
12167         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
12168             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
12169                 struct hda_input_mux *imux = &spec->private_imux;
12170                 imux->items[imux->num_items].label = "Int Mic";
12171                 imux->items[imux->num_items].index = 0x05;
12172                 imux->num_items++;
12173         }
12174         return 0;
12175 }
12176
12177 #ifdef CONFIG_SND_HDA_POWER_SAVE
12178 #define alc269_loopbacks        alc880_loopbacks
12179 #endif
12180
12181 /* pcm configuration: identiacal with ALC880 */
12182 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12183 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12184 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12185 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12186
12187 /*
12188  * BIOS auto configuration
12189  */
12190 static int alc269_parse_auto_config(struct hda_codec *codec)
12191 {
12192         struct alc_spec *spec = codec->spec;
12193         int i, err;
12194         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12195
12196         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12197                                            alc269_ignore);
12198         if (err < 0)
12199                 return err;
12200
12201         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12202         if (err < 0)
12203                 return err;
12204         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12205         if (err < 0)
12206                 return err;
12207
12208         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12209
12210         if (spec->autocfg.dig_out_pin)
12211                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12212
12213         if (spec->kctls.list)
12214                 add_mixer(spec, spec->kctls.list);
12215
12216         /* create a beep mixer control if the pin 0x1d isn't assigned */
12217         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12218                 if (spec->autocfg.input_pins[i] == 0x1d)
12219                         break;
12220         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12221                 add_mixer(spec, alc269_beep_mixer);
12222
12223         add_verb(spec, alc269_init_verbs);
12224         spec->num_mux_defs = 1;
12225         spec->input_mux = &spec->private_imux;
12226         /* set default input source */
12227         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12228                                   0, AC_VERB_SET_CONNECT_SEL,
12229                                   spec->input_mux->items[0].index);
12230
12231         err = alc_auto_add_mic_boost(codec);
12232         if (err < 0)
12233                 return err;
12234
12235         if (!spec->cap_mixer)
12236                 set_capture_mixer(spec);
12237
12238         store_pin_configs(codec);
12239         return 1;
12240 }
12241
12242 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12243 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12244 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12245
12246
12247 /* init callback for auto-configuration model -- overriding the default init */
12248 static void alc269_auto_init(struct hda_codec *codec)
12249 {
12250         struct alc_spec *spec = codec->spec;
12251         alc269_auto_init_multi_out(codec);
12252         alc269_auto_init_hp_out(codec);
12253         alc269_auto_init_analog_input(codec);
12254         if (spec->unsol_event)
12255                 alc_inithook(codec);
12256 }
12257
12258 /*
12259  * configuration and preset
12260  */
12261 static const char *alc269_models[ALC269_MODEL_LAST] = {
12262         [ALC269_BASIC]                  = "basic",
12263         [ALC269_QUANTA_FL1]             = "quanta",
12264         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12265         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
12266         [ALC269_FUJITSU]                = "fujitsu",
12267         [ALC269_LIFEBOOK]               = "lifebook"
12268 };
12269
12270 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12271         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12272         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12273                       ALC269_ASUS_EEEPC_P703),
12274         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12275                       ALC269_ASUS_EEEPC_P901),
12276         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12277                       ALC269_ASUS_EEEPC_P901),
12278         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
12279         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
12280         {}
12281 };
12282
12283 static struct alc_config_preset alc269_presets[] = {
12284         [ALC269_BASIC] = {
12285                 .mixers = { alc269_base_mixer },
12286                 .init_verbs = { alc269_init_verbs },
12287                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12288                 .dac_nids = alc269_dac_nids,
12289                 .hp_nid = 0x03,
12290                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12291                 .channel_mode = alc269_modes,
12292                 .input_mux = &alc269_capture_source,
12293         },
12294         [ALC269_QUANTA_FL1] = {
12295                 .mixers = { alc269_quanta_fl1_mixer },
12296                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
12297                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12298                 .dac_nids = alc269_dac_nids,
12299                 .hp_nid = 0x03,
12300                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12301                 .channel_mode = alc269_modes,
12302                 .input_mux = &alc269_capture_source,
12303                 .unsol_event = alc269_quanta_fl1_unsol_event,
12304                 .init_hook = alc269_quanta_fl1_init_hook,
12305         },
12306         [ALC269_ASUS_EEEPC_P703] = {
12307                 .mixers = { alc269_eeepc_mixer },
12308                 .cap_mixer = alc269_epc_capture_mixer,
12309                 .init_verbs = { alc269_init_verbs,
12310                                 alc269_eeepc_amic_init_verbs },
12311                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12312                 .dac_nids = alc269_dac_nids,
12313                 .hp_nid = 0x03,
12314                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12315                 .channel_mode = alc269_modes,
12316                 .input_mux = &alc269_eeepc_amic_capture_source,
12317                 .unsol_event = alc269_eeepc_amic_unsol_event,
12318                 .init_hook = alc269_eeepc_amic_inithook,
12319         },
12320         [ALC269_ASUS_EEEPC_P901] = {
12321                 .mixers = { alc269_eeepc_mixer },
12322                 .cap_mixer = alc269_epc_capture_mixer,
12323                 .init_verbs = { alc269_init_verbs,
12324                                 alc269_eeepc_dmic_init_verbs },
12325                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12326                 .dac_nids = alc269_dac_nids,
12327                 .hp_nid = 0x03,
12328                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12329                 .channel_mode = alc269_modes,
12330                 .input_mux = &alc269_eeepc_dmic_capture_source,
12331                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12332                 .init_hook = alc269_eeepc_dmic_inithook,
12333         },
12334         [ALC269_FUJITSU] = {
12335                 .mixers = { alc269_fujitsu_mixer, alc269_beep_mixer },
12336                 .cap_mixer = alc269_epc_capture_mixer,
12337                 .init_verbs = { alc269_init_verbs,
12338                                 alc269_eeepc_dmic_init_verbs },
12339                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12340                 .dac_nids = alc269_dac_nids,
12341                 .hp_nid = 0x03,
12342                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12343                 .channel_mode = alc269_modes,
12344                 .input_mux = &alc269_eeepc_dmic_capture_source,
12345                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12346                 .init_hook = alc269_eeepc_dmic_inithook,
12347         },
12348         [ALC269_LIFEBOOK] = {
12349                 .mixers = { alc269_lifebook_mixer },
12350                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
12351                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12352                 .dac_nids = alc269_dac_nids,
12353                 .hp_nid = 0x03,
12354                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12355                 .channel_mode = alc269_modes,
12356                 .input_mux = &alc269_capture_source,
12357                 .unsol_event = alc269_lifebook_unsol_event,
12358                 .init_hook = alc269_lifebook_init_hook,
12359         },
12360 };
12361
12362 static int patch_alc269(struct hda_codec *codec)
12363 {
12364         struct alc_spec *spec;
12365         int board_config;
12366         int err;
12367
12368         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12369         if (spec == NULL)
12370                 return -ENOMEM;
12371
12372         codec->spec = spec;
12373
12374         alc_fix_pll_init(codec, 0x20, 0x04, 15);
12375
12376         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
12377                                                   alc269_models,
12378                                                   alc269_cfg_tbl);
12379
12380         if (board_config < 0) {
12381                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
12382                        "trying auto-probe from BIOS...\n");
12383                 board_config = ALC269_AUTO;
12384         }
12385
12386         if (board_config == ALC269_AUTO) {
12387                 /* automatic parse from the BIOS config */
12388                 err = alc269_parse_auto_config(codec);
12389                 if (err < 0) {
12390                         alc_free(codec);
12391                         return err;
12392                 } else if (!err) {
12393                         printk(KERN_INFO
12394                                "hda_codec: Cannot set up configuration "
12395                                "from BIOS.  Using base mode...\n");
12396                         board_config = ALC269_BASIC;
12397                 }
12398         }
12399
12400         if (board_config != ALC269_AUTO)
12401                 setup_preset(spec, &alc269_presets[board_config]);
12402
12403         spec->stream_name_analog = "ALC269 Analog";
12404         spec->stream_analog_playback = &alc269_pcm_analog_playback;
12405         spec->stream_analog_capture = &alc269_pcm_analog_capture;
12406
12407         spec->stream_name_digital = "ALC269 Digital";
12408         spec->stream_digital_playback = &alc269_pcm_digital_playback;
12409         spec->stream_digital_capture = &alc269_pcm_digital_capture;
12410
12411         spec->adc_nids = alc269_adc_nids;
12412         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12413         spec->capsrc_nids = alc269_capsrc_nids;
12414         if (!spec->cap_mixer)
12415                 set_capture_mixer(spec);
12416
12417         codec->patch_ops = alc_patch_ops;
12418         if (board_config == ALC269_AUTO)
12419                 spec->init_hook = alc269_auto_init;
12420 #ifdef CONFIG_SND_HDA_POWER_SAVE
12421         if (!spec->loopback.amplist)
12422                 spec->loopback.amplist = alc269_loopbacks;
12423 #endif
12424
12425         return 0;
12426 }
12427
12428 /*
12429  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
12430  */
12431
12432 /*
12433  * set the path ways for 2 channel output
12434  * need to set the codec line out and mic 1 pin widgets to inputs
12435  */
12436 static struct hda_verb alc861_threestack_ch2_init[] = {
12437         /* set pin widget 1Ah (line in) for input */
12438         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12439         /* set pin widget 18h (mic1/2) for input, for mic also enable
12440          * the vref
12441          */
12442         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12443
12444         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12445 #if 0
12446         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12447         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12448 #endif
12449         { } /* end */
12450 };
12451 /*
12452  * 6ch mode
12453  * need to set the codec line out and mic 1 pin widgets to outputs
12454  */
12455 static struct hda_verb alc861_threestack_ch6_init[] = {
12456         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12457         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12458         /* set pin widget 18h (mic1) for output (CLFE)*/
12459         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12460
12461         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12462         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12463
12464         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12465 #if 0
12466         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12467         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12468 #endif
12469         { } /* end */
12470 };
12471
12472 static struct hda_channel_mode alc861_threestack_modes[2] = {
12473         { 2, alc861_threestack_ch2_init },
12474         { 6, alc861_threestack_ch6_init },
12475 };
12476 /* Set mic1 as input and unmute the mixer */
12477 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
12478         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12479         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12480         { } /* end */
12481 };
12482 /* Set mic1 as output and mute mixer */
12483 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
12484         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12485         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12486         { } /* end */
12487 };
12488
12489 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
12490         { 2, alc861_uniwill_m31_ch2_init },
12491         { 4, alc861_uniwill_m31_ch4_init },
12492 };
12493
12494 /* Set mic1 and line-in as input and unmute the mixer */
12495 static struct hda_verb alc861_asus_ch2_init[] = {
12496         /* set pin widget 1Ah (line in) for input */
12497         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12498         /* set pin widget 18h (mic1/2) for input, for mic also enable
12499          * the vref
12500          */
12501         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12502
12503         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12504 #if 0
12505         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12506         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12507 #endif
12508         { } /* end */
12509 };
12510 /* Set mic1 nad line-in as output and mute mixer */
12511 static struct hda_verb alc861_asus_ch6_init[] = {
12512         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12513         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12514         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12515         /* set pin widget 18h (mic1) for output (CLFE)*/
12516         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12517         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12518         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12519         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12520
12521         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12522 #if 0
12523         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12524         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12525 #endif
12526         { } /* end */
12527 };
12528
12529 static struct hda_channel_mode alc861_asus_modes[2] = {
12530         { 2, alc861_asus_ch2_init },
12531         { 6, alc861_asus_ch6_init },
12532 };
12533
12534 /* patch-ALC861 */
12535
12536 static struct snd_kcontrol_new alc861_base_mixer[] = {
12537         /* output mixer control */
12538         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12539         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12540         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12541         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12542         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12543
12544         /*Input mixer control */
12545         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12546            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12547         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12548         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12549         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12550         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12551         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12552         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12553         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12554         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12555
12556         { } /* end */
12557 };
12558
12559 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12560         /* output mixer control */
12561         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12562         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12563         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12564         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12565         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12566
12567         /* Input mixer control */
12568         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12569            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12570         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12571         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12572         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12573         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12574         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12575         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12576         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12577         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12578
12579         {
12580                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12581                 .name = "Channel Mode",
12582                 .info = alc_ch_mode_info,
12583                 .get = alc_ch_mode_get,
12584                 .put = alc_ch_mode_put,
12585                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
12586         },
12587         { } /* end */
12588 };
12589
12590 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
12591         /* output mixer control */
12592         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12593         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12594         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12595
12596         { } /* end */
12597 };
12598
12599 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
12600         /* output mixer control */
12601         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12602         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12603         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12604         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12605         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12606
12607         /* Input mixer control */
12608         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12609            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12610         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12611         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12612         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12613         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12614         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12615         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12616         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12617         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12618
12619         {
12620                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12621                 .name = "Channel Mode",
12622                 .info = alc_ch_mode_info,
12623                 .get = alc_ch_mode_get,
12624                 .put = alc_ch_mode_put,
12625                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
12626         },
12627         { } /* end */
12628 };
12629
12630 static struct snd_kcontrol_new alc861_asus_mixer[] = {
12631         /* output mixer control */
12632         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12633         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12634         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12635         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12636         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12637
12638         /* Input mixer control */
12639         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12640         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12641         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12642         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12643         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12644         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12645         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12646         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12647         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12648         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
12649
12650         {
12651                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12652                 .name = "Channel Mode",
12653                 .info = alc_ch_mode_info,
12654                 .get = alc_ch_mode_get,
12655                 .put = alc_ch_mode_put,
12656                 .private_value = ARRAY_SIZE(alc861_asus_modes),
12657         },
12658         { }
12659 };
12660
12661 /* additional mixer */
12662 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
12663         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12664         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12665         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
12666         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
12667         { }
12668 };
12669
12670 /*
12671  * generic initialization of ADC, input mixers and output mixers
12672  */
12673 static struct hda_verb alc861_base_init_verbs[] = {
12674         /*
12675          * Unmute ADC0 and set the default input to mic-in
12676          */
12677         /* port-A for surround (rear panel) */
12678         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12679         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
12680         /* port-B for mic-in (rear panel) with vref */
12681         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12682         /* port-C for line-in (rear panel) */
12683         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12684         /* port-D for Front */
12685         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12686         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12687         /* port-E for HP out (front panel) */
12688         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
12689         /* route front PCM to HP */
12690         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12691         /* port-F for mic-in (front panel) with vref */
12692         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12693         /* port-G for CLFE (rear panel) */
12694         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12695         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12696         /* port-H for side (rear panel) */
12697         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12698         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
12699         /* CD-in */
12700         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12701         /* route front mic to ADC1*/
12702         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12703         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12704
12705         /* Unmute DAC0~3 & spdif out*/
12706         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12707         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12708         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12709         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12710         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12711
12712         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12713         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12714         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12715         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12716         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12717
12718         /* Unmute Stereo Mixer 15 */
12719         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12720         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12721         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12722         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12723
12724         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12725         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12726         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12727         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12728         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12729         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12730         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12731         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12732         /* hp used DAC 3 (Front) */
12733         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12734         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12735
12736         { }
12737 };
12738
12739 static struct hda_verb alc861_threestack_init_verbs[] = {
12740         /*
12741          * Unmute ADC0 and set the default input to mic-in
12742          */
12743         /* port-A for surround (rear panel) */
12744         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12745         /* port-B for mic-in (rear panel) with vref */
12746         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12747         /* port-C for line-in (rear panel) */
12748         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12749         /* port-D for Front */
12750         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12751         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12752         /* port-E for HP out (front panel) */
12753         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
12754         /* route front PCM to HP */
12755         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12756         /* port-F for mic-in (front panel) with vref */
12757         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12758         /* port-G for CLFE (rear panel) */
12759         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12760         /* port-H for side (rear panel) */
12761         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12762         /* CD-in */
12763         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12764         /* route front mic to ADC1*/
12765         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12766         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12767         /* Unmute DAC0~3 & spdif out*/
12768         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12769         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12770         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12771         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12772         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12773
12774         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12775         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12776         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12777         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12778         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12779
12780         /* Unmute Stereo Mixer 15 */
12781         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12782         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12783         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12784         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12785
12786         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12787         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12788         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12789         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12790         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12791         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12792         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12793         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12794         /* hp used DAC 3 (Front) */
12795         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12796         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12797         { }
12798 };
12799
12800 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
12801         /*
12802          * Unmute ADC0 and set the default input to mic-in
12803          */
12804         /* port-A for surround (rear panel) */
12805         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12806         /* port-B for mic-in (rear panel) with vref */
12807         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12808         /* port-C for line-in (rear panel) */
12809         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12810         /* port-D for Front */
12811         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12812         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12813         /* port-E for HP out (front panel) */
12814         /* this has to be set to VREF80 */
12815         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12816         /* route front PCM to HP */
12817         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12818         /* port-F for mic-in (front panel) with vref */
12819         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12820         /* port-G for CLFE (rear panel) */
12821         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12822         /* port-H for side (rear panel) */
12823         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12824         /* CD-in */
12825         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12826         /* route front mic to ADC1*/
12827         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12828         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12829         /* Unmute DAC0~3 & spdif out*/
12830         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12831         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12832         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12833         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12834         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12835
12836         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12837         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12838         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12839         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12840         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12841
12842         /* Unmute Stereo Mixer 15 */
12843         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12844         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12845         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12846         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12847
12848         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12849         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12850         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12851         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12852         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12853         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12854         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12855         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12856         /* hp used DAC 3 (Front) */
12857         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12858         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12859         { }
12860 };
12861
12862 static struct hda_verb alc861_asus_init_verbs[] = {
12863         /*
12864          * Unmute ADC0 and set the default input to mic-in
12865          */
12866         /* port-A for surround (rear panel)
12867          * according to codec#0 this is the HP jack
12868          */
12869         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
12870         /* route front PCM to HP */
12871         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
12872         /* port-B for mic-in (rear panel) with vref */
12873         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12874         /* port-C for line-in (rear panel) */
12875         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12876         /* port-D for Front */
12877         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12878         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12879         /* port-E for HP out (front panel) */
12880         /* this has to be set to VREF80 */
12881         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12882         /* route front PCM to HP */
12883         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12884         /* port-F for mic-in (front panel) with vref */
12885         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12886         /* port-G for CLFE (rear panel) */
12887         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12888         /* port-H for side (rear panel) */
12889         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12890         /* CD-in */
12891         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12892         /* route front mic to ADC1*/
12893         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12894         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12895         /* Unmute DAC0~3 & spdif out*/
12896         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12897         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12898         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12899         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12900         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12901         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12902         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12903         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12904         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12905         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12906
12907         /* Unmute Stereo Mixer 15 */
12908         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12909         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12910         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12911         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12912
12913         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12914         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12915         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12916         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12917         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12918         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12919         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12920         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12921         /* hp used DAC 3 (Front) */
12922         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12923         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12924         { }
12925 };
12926
12927 /* additional init verbs for ASUS laptops */
12928 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
12929         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
12930         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
12931         { }
12932 };
12933
12934 /*
12935  * generic initialization of ADC, input mixers and output mixers
12936  */
12937 static struct hda_verb alc861_auto_init_verbs[] = {
12938         /*
12939          * Unmute ADC0 and set the default input to mic-in
12940          */
12941         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
12942         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12943
12944         /* Unmute DAC0~3 & spdif out*/
12945         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12946         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12947         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12948         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12949         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12950
12951         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12952         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12953         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12954         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12955         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12956
12957         /* Unmute Stereo Mixer 15 */
12958         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12959         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12960         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12961         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
12962
12963         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12964         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12965         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12966         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12967         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12968         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12969         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12970         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12971
12972         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12973         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12974         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12975         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12976         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12977         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12978         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12979         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12980
12981         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
12982
12983         { }
12984 };
12985
12986 static struct hda_verb alc861_toshiba_init_verbs[] = {
12987         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12988
12989         { }
12990 };
12991
12992 /* toggle speaker-output according to the hp-jack state */
12993 static void alc861_toshiba_automute(struct hda_codec *codec)
12994 {
12995         unsigned int present;
12996
12997         present = snd_hda_codec_read(codec, 0x0f, 0,
12998                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12999         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
13000                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13001         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
13002                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
13003 }
13004
13005 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
13006                                        unsigned int res)
13007 {
13008         if ((res >> 26) == ALC880_HP_EVENT)
13009                 alc861_toshiba_automute(codec);
13010 }
13011
13012 /* pcm configuration: identiacal with ALC880 */
13013 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
13014 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
13015 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
13016 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
13017
13018
13019 #define ALC861_DIGOUT_NID       0x07
13020
13021 static struct hda_channel_mode alc861_8ch_modes[1] = {
13022         { 8, NULL }
13023 };
13024
13025 static hda_nid_t alc861_dac_nids[4] = {
13026         /* front, surround, clfe, side */
13027         0x03, 0x06, 0x05, 0x04
13028 };
13029
13030 static hda_nid_t alc660_dac_nids[3] = {
13031         /* front, clfe, surround */
13032         0x03, 0x05, 0x06
13033 };
13034
13035 static hda_nid_t alc861_adc_nids[1] = {
13036         /* ADC0-2 */
13037         0x08,
13038 };
13039
13040 static struct hda_input_mux alc861_capture_source = {
13041         .num_items = 5,
13042         .items = {
13043                 { "Mic", 0x0 },
13044                 { "Front Mic", 0x3 },
13045                 { "Line", 0x1 },
13046                 { "CD", 0x4 },
13047                 { "Mixer", 0x5 },
13048         },
13049 };
13050
13051 /* fill in the dac_nids table from the parsed pin configuration */
13052 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13053                                      const struct auto_pin_cfg *cfg)
13054 {
13055         int i;
13056         hda_nid_t nid;
13057
13058         spec->multiout.dac_nids = spec->private_dac_nids;
13059         for (i = 0; i < cfg->line_outs; i++) {
13060                 nid = cfg->line_out_pins[i];
13061                 if (nid) {
13062                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13063                                 continue;
13064                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13065                 }
13066         }
13067         spec->multiout.num_dacs = cfg->line_outs;
13068         return 0;
13069 }
13070
13071 /* add playback controls from the parsed DAC table */
13072 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13073                                              const struct auto_pin_cfg *cfg)
13074 {
13075         char name[32];
13076         static const char *chname[4] = {
13077                 "Front", "Surround", NULL /*CLFE*/, "Side"
13078         };
13079         hda_nid_t nid;
13080         int i, idx, err;
13081
13082         for (i = 0; i < cfg->line_outs; i++) {
13083                 nid = spec->multiout.dac_nids[i];
13084                 if (!nid)
13085                         continue;
13086                 if (nid == 0x05) {
13087                         /* Center/LFE */
13088                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13089                                           "Center Playback Switch",
13090                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13091                                                               HDA_OUTPUT));
13092                         if (err < 0)
13093                                 return err;
13094                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13095                                           "LFE Playback Switch",
13096                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13097                                                               HDA_OUTPUT));
13098                         if (err < 0)
13099                                 return err;
13100                 } else {
13101                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13102                              idx++)
13103                                 if (nid == alc861_dac_nids[idx])
13104                                         break;
13105                         sprintf(name, "%s Playback Switch", chname[idx]);
13106                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13107                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13108                                                               HDA_OUTPUT));
13109                         if (err < 0)
13110                                 return err;
13111                 }
13112         }
13113         return 0;
13114 }
13115
13116 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13117 {
13118         int err;
13119         hda_nid_t nid;
13120
13121         if (!pin)
13122                 return 0;
13123
13124         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13125                 nid = 0x03;
13126                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13127                                   "Headphone Playback Switch",
13128                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13129                 if (err < 0)
13130                         return err;
13131                 spec->multiout.hp_nid = nid;
13132         }
13133         return 0;
13134 }
13135
13136 /* create playback/capture controls for input pins */
13137 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13138                                                 const struct auto_pin_cfg *cfg)
13139 {
13140         struct hda_input_mux *imux = &spec->private_imux;
13141         int i, err, idx, idx1;
13142
13143         for (i = 0; i < AUTO_PIN_LAST; i++) {
13144                 switch (cfg->input_pins[i]) {
13145                 case 0x0c:
13146                         idx1 = 1;
13147                         idx = 2;        /* Line In */
13148                         break;
13149                 case 0x0f:
13150                         idx1 = 2;
13151                         idx = 2;        /* Line In */
13152                         break;
13153                 case 0x0d:
13154                         idx1 = 0;
13155                         idx = 1;        /* Mic In */
13156                         break;
13157                 case 0x10:
13158                         idx1 = 3;
13159                         idx = 1;        /* Mic In */
13160                         break;
13161                 case 0x11:
13162                         idx1 = 4;
13163                         idx = 0;        /* CD */
13164                         break;
13165                 default:
13166                         continue;
13167                 }
13168
13169                 err = new_analog_input(spec, cfg->input_pins[i],
13170                                        auto_pin_cfg_labels[i], idx, 0x15);
13171                 if (err < 0)
13172                         return err;
13173
13174                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13175                 imux->items[imux->num_items].index = idx1;
13176                 imux->num_items++;
13177         }
13178         return 0;
13179 }
13180
13181 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13182                                               hda_nid_t nid,
13183                                               int pin_type, int dac_idx)
13184 {
13185         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13186                             pin_type);
13187         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13188                             AMP_OUT_UNMUTE);
13189 }
13190
13191 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13192 {
13193         struct alc_spec *spec = codec->spec;
13194         int i;
13195
13196         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13197         for (i = 0; i < spec->autocfg.line_outs; i++) {
13198                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13199                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13200                 if (nid)
13201                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13202                                                           spec->multiout.dac_nids[i]);
13203         }
13204 }
13205
13206 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13207 {
13208         struct alc_spec *spec = codec->spec;
13209         hda_nid_t pin;
13210
13211         pin = spec->autocfg.hp_pins[0];
13212         if (pin) /* connect to front */
13213                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13214                                                   spec->multiout.dac_nids[0]);
13215         pin = spec->autocfg.speaker_pins[0];
13216         if (pin)
13217                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13218 }
13219
13220 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13221 {
13222         struct alc_spec *spec = codec->spec;
13223         int i;
13224
13225         for (i = 0; i < AUTO_PIN_LAST; i++) {
13226                 hda_nid_t nid = spec->autocfg.input_pins[i];
13227                 if (nid >= 0x0c && nid <= 0x11) {
13228                         snd_hda_codec_write(codec, nid, 0,
13229                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13230                                             i <= AUTO_PIN_FRONT_MIC ?
13231                                             PIN_VREF80 : PIN_IN);
13232                 }
13233         }
13234 }
13235
13236 /* parse the BIOS configuration and set up the alc_spec */
13237 /* return 1 if successful, 0 if the proper config is not found,
13238  * or a negative error code
13239  */
13240 static int alc861_parse_auto_config(struct hda_codec *codec)
13241 {
13242         struct alc_spec *spec = codec->spec;
13243         int err;
13244         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13245
13246         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13247                                            alc861_ignore);
13248         if (err < 0)
13249                 return err;
13250         if (!spec->autocfg.line_outs)
13251                 return 0; /* can't find valid BIOS pin config */
13252
13253         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13254         if (err < 0)
13255                 return err;
13256         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13257         if (err < 0)
13258                 return err;
13259         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13260         if (err < 0)
13261                 return err;
13262         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13263         if (err < 0)
13264                 return err;
13265
13266         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13267
13268         if (spec->autocfg.dig_out_pin)
13269                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13270
13271         if (spec->kctls.list)
13272                 add_mixer(spec, spec->kctls.list);
13273
13274         add_verb(spec, alc861_auto_init_verbs);
13275
13276         spec->num_mux_defs = 1;
13277         spec->input_mux = &spec->private_imux;
13278
13279         spec->adc_nids = alc861_adc_nids;
13280         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13281         set_capture_mixer(spec);
13282
13283         store_pin_configs(codec);
13284         return 1;
13285 }
13286
13287 /* additional initialization for auto-configuration model */
13288 static void alc861_auto_init(struct hda_codec *codec)
13289 {
13290         struct alc_spec *spec = codec->spec;
13291         alc861_auto_init_multi_out(codec);
13292         alc861_auto_init_hp_out(codec);
13293         alc861_auto_init_analog_input(codec);
13294         if (spec->unsol_event)
13295                 alc_inithook(codec);
13296 }
13297
13298 #ifdef CONFIG_SND_HDA_POWER_SAVE
13299 static struct hda_amp_list alc861_loopbacks[] = {
13300         { 0x15, HDA_INPUT, 0 },
13301         { 0x15, HDA_INPUT, 1 },
13302         { 0x15, HDA_INPUT, 2 },
13303         { 0x15, HDA_INPUT, 3 },
13304         { } /* end */
13305 };
13306 #endif
13307
13308
13309 /*
13310  * configuration and preset
13311  */
13312 static const char *alc861_models[ALC861_MODEL_LAST] = {
13313         [ALC861_3ST]            = "3stack",
13314         [ALC660_3ST]            = "3stack-660",
13315         [ALC861_3ST_DIG]        = "3stack-dig",
13316         [ALC861_6ST_DIG]        = "6stack-dig",
13317         [ALC861_UNIWILL_M31]    = "uniwill-m31",
13318         [ALC861_TOSHIBA]        = "toshiba",
13319         [ALC861_ASUS]           = "asus",
13320         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
13321         [ALC861_AUTO]           = "auto",
13322 };
13323
13324 static struct snd_pci_quirk alc861_cfg_tbl[] = {
13325         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
13326         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13327         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13328         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
13329         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
13330         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
13331         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
13332         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
13333          *        Any other models that need this preset?
13334          */
13335         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
13336         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
13337         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
13338         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
13339         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
13340         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
13341         /* FIXME: the below seems conflict */
13342         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
13343         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
13344         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
13345         {}
13346 };
13347
13348 static struct alc_config_preset alc861_presets[] = {
13349         [ALC861_3ST] = {
13350                 .mixers = { alc861_3ST_mixer },
13351                 .init_verbs = { alc861_threestack_init_verbs },
13352                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13353                 .dac_nids = alc861_dac_nids,
13354                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13355                 .channel_mode = alc861_threestack_modes,
13356                 .need_dac_fix = 1,
13357                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13358                 .adc_nids = alc861_adc_nids,
13359                 .input_mux = &alc861_capture_source,
13360         },
13361         [ALC861_3ST_DIG] = {
13362                 .mixers = { alc861_base_mixer },
13363                 .init_verbs = { alc861_threestack_init_verbs },
13364                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13365                 .dac_nids = alc861_dac_nids,
13366                 .dig_out_nid = ALC861_DIGOUT_NID,
13367                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13368                 .channel_mode = alc861_threestack_modes,
13369                 .need_dac_fix = 1,
13370                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13371                 .adc_nids = alc861_adc_nids,
13372                 .input_mux = &alc861_capture_source,
13373         },
13374         [ALC861_6ST_DIG] = {
13375                 .mixers = { alc861_base_mixer },
13376                 .init_verbs = { alc861_base_init_verbs },
13377                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13378                 .dac_nids = alc861_dac_nids,
13379                 .dig_out_nid = ALC861_DIGOUT_NID,
13380                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
13381                 .channel_mode = alc861_8ch_modes,
13382                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13383                 .adc_nids = alc861_adc_nids,
13384                 .input_mux = &alc861_capture_source,
13385         },
13386         [ALC660_3ST] = {
13387                 .mixers = { alc861_3ST_mixer },
13388                 .init_verbs = { alc861_threestack_init_verbs },
13389                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
13390                 .dac_nids = alc660_dac_nids,
13391                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13392                 .channel_mode = alc861_threestack_modes,
13393                 .need_dac_fix = 1,
13394                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13395                 .adc_nids = alc861_adc_nids,
13396                 .input_mux = &alc861_capture_source,
13397         },
13398         [ALC861_UNIWILL_M31] = {
13399                 .mixers = { alc861_uniwill_m31_mixer },
13400                 .init_verbs = { alc861_uniwill_m31_init_verbs },
13401                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13402                 .dac_nids = alc861_dac_nids,
13403                 .dig_out_nid = ALC861_DIGOUT_NID,
13404                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
13405                 .channel_mode = alc861_uniwill_m31_modes,
13406                 .need_dac_fix = 1,
13407                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13408                 .adc_nids = alc861_adc_nids,
13409                 .input_mux = &alc861_capture_source,
13410         },
13411         [ALC861_TOSHIBA] = {
13412                 .mixers = { alc861_toshiba_mixer },
13413                 .init_verbs = { alc861_base_init_verbs,
13414                                 alc861_toshiba_init_verbs },
13415                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13416                 .dac_nids = alc861_dac_nids,
13417                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13418                 .channel_mode = alc883_3ST_2ch_modes,
13419                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13420                 .adc_nids = alc861_adc_nids,
13421                 .input_mux = &alc861_capture_source,
13422                 .unsol_event = alc861_toshiba_unsol_event,
13423                 .init_hook = alc861_toshiba_automute,
13424         },
13425         [ALC861_ASUS] = {
13426                 .mixers = { alc861_asus_mixer },
13427                 .init_verbs = { alc861_asus_init_verbs },
13428                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13429                 .dac_nids = alc861_dac_nids,
13430                 .dig_out_nid = ALC861_DIGOUT_NID,
13431                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
13432                 .channel_mode = alc861_asus_modes,
13433                 .need_dac_fix = 1,
13434                 .hp_nid = 0x06,
13435                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13436                 .adc_nids = alc861_adc_nids,
13437                 .input_mux = &alc861_capture_source,
13438         },
13439         [ALC861_ASUS_LAPTOP] = {
13440                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
13441                 .init_verbs = { alc861_asus_init_verbs,
13442                                 alc861_asus_laptop_init_verbs },
13443                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13444                 .dac_nids = alc861_dac_nids,
13445                 .dig_out_nid = ALC861_DIGOUT_NID,
13446                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13447                 .channel_mode = alc883_3ST_2ch_modes,
13448                 .need_dac_fix = 1,
13449                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13450                 .adc_nids = alc861_adc_nids,
13451                 .input_mux = &alc861_capture_source,
13452         },
13453 };
13454
13455
13456 static int patch_alc861(struct hda_codec *codec)
13457 {
13458         struct alc_spec *spec;
13459         int board_config;
13460         int err;
13461
13462         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13463         if (spec == NULL)
13464                 return -ENOMEM;
13465
13466         codec->spec = spec;
13467
13468         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
13469                                                   alc861_models,
13470                                                   alc861_cfg_tbl);
13471
13472         if (board_config < 0) {
13473                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
13474                        "trying auto-probe from BIOS...\n");
13475                 board_config = ALC861_AUTO;
13476         }
13477
13478         if (board_config == ALC861_AUTO) {
13479                 /* automatic parse from the BIOS config */
13480                 err = alc861_parse_auto_config(codec);
13481                 if (err < 0) {
13482                         alc_free(codec);
13483                         return err;
13484                 } else if (!err) {
13485                         printk(KERN_INFO
13486                                "hda_codec: Cannot set up configuration "
13487                                "from BIOS.  Using base mode...\n");
13488                    board_config = ALC861_3ST_DIG;
13489                 }
13490         }
13491
13492         if (board_config != ALC861_AUTO)
13493                 setup_preset(spec, &alc861_presets[board_config]);
13494
13495         spec->stream_name_analog = "ALC861 Analog";
13496         spec->stream_analog_playback = &alc861_pcm_analog_playback;
13497         spec->stream_analog_capture = &alc861_pcm_analog_capture;
13498
13499         spec->stream_name_digital = "ALC861 Digital";
13500         spec->stream_digital_playback = &alc861_pcm_digital_playback;
13501         spec->stream_digital_capture = &alc861_pcm_digital_capture;
13502
13503         spec->vmaster_nid = 0x03;
13504
13505         codec->patch_ops = alc_patch_ops;
13506         if (board_config == ALC861_AUTO)
13507                 spec->init_hook = alc861_auto_init;
13508 #ifdef CONFIG_SND_HDA_POWER_SAVE
13509         if (!spec->loopback.amplist)
13510                 spec->loopback.amplist = alc861_loopbacks;
13511 #endif
13512
13513         return 0;
13514 }
13515
13516 /*
13517  * ALC861-VD support
13518  *
13519  * Based on ALC882
13520  *
13521  * In addition, an independent DAC
13522  */
13523 #define ALC861VD_DIGOUT_NID     0x06
13524
13525 static hda_nid_t alc861vd_dac_nids[4] = {
13526         /* front, surr, clfe, side surr */
13527         0x02, 0x03, 0x04, 0x05
13528 };
13529
13530 /* dac_nids for ALC660vd are in a different order - according to
13531  * Realtek's driver.
13532  * This should probably tesult in a different mixer for 6stack models
13533  * of ALC660vd codecs, but for now there is only 3stack mixer
13534  * - and it is the same as in 861vd.
13535  * adc_nids in ALC660vd are (is) the same as in 861vd
13536  */
13537 static hda_nid_t alc660vd_dac_nids[3] = {
13538         /* front, rear, clfe, rear_surr */
13539         0x02, 0x04, 0x03
13540 };
13541
13542 static hda_nid_t alc861vd_adc_nids[1] = {
13543         /* ADC0 */
13544         0x09,
13545 };
13546
13547 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
13548
13549 /* input MUX */
13550 /* FIXME: should be a matrix-type input source selection */
13551 static struct hda_input_mux alc861vd_capture_source = {
13552         .num_items = 4,
13553         .items = {
13554                 { "Mic", 0x0 },
13555                 { "Front Mic", 0x1 },
13556                 { "Line", 0x2 },
13557                 { "CD", 0x4 },
13558         },
13559 };
13560
13561 static struct hda_input_mux alc861vd_dallas_capture_source = {
13562         .num_items = 2,
13563         .items = {
13564                 { "Ext Mic", 0x0 },
13565                 { "Int Mic", 0x1 },
13566         },
13567 };
13568
13569 static struct hda_input_mux alc861vd_hp_capture_source = {
13570         .num_items = 2,
13571         .items = {
13572                 { "Front Mic", 0x0 },
13573                 { "ATAPI Mic", 0x1 },
13574         },
13575 };
13576
13577 /*
13578  * 2ch mode
13579  */
13580 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
13581         { 2, NULL }
13582 };
13583
13584 /*
13585  * 6ch mode
13586  */
13587 static struct hda_verb alc861vd_6stack_ch6_init[] = {
13588         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13589         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13590         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13591         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13592         { } /* end */
13593 };
13594
13595 /*
13596  * 8ch mode
13597  */
13598 static struct hda_verb alc861vd_6stack_ch8_init[] = {
13599         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13600         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13601         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13602         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13603         { } /* end */
13604 };
13605
13606 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
13607         { 6, alc861vd_6stack_ch6_init },
13608         { 8, alc861vd_6stack_ch8_init },
13609 };
13610
13611 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
13612         {
13613                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13614                 .name = "Channel Mode",
13615                 .info = alc_ch_mode_info,
13616                 .get = alc_ch_mode_get,
13617                 .put = alc_ch_mode_put,
13618         },
13619         { } /* end */
13620 };
13621
13622 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13623  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13624  */
13625 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
13626         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13627         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13628
13629         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13630         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
13631
13632         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
13633                                 HDA_OUTPUT),
13634         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
13635                                 HDA_OUTPUT),
13636         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
13637         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
13638
13639         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
13640         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
13641
13642         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13643
13644         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13645         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13646         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13647
13648         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13649         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13650         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13651
13652         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13653         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13654
13655         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13656         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13657
13658         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13659         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13660
13661         { } /* end */
13662 };
13663
13664 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
13665         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13666         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13667
13668         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13669
13670         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13671         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13672         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13673
13674         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13675         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13676         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13677
13678         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13679         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13680
13681         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13682         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13683
13684         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13685         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13686
13687         { } /* end */
13688 };
13689
13690 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
13691         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13692         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
13693         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13694
13695         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13696
13697         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13698         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13699         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13700
13701         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13702         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13703         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13704
13705         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13706         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13707
13708         { } /* end */
13709 };
13710
13711 /* Pin assignment: Speaker=0x14, HP = 0x15,
13712  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
13713  */
13714 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
13715         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13716         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
13717         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13718         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
13719         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
13720         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13721         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13722         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
13723         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13724         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13725         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
13726         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
13727         { } /* end */
13728 };
13729
13730 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
13731  *                 Front Mic=0x18, ATAPI Mic = 0x19,
13732  */
13733 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
13734         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13735         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13736         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13737         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
13738         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13739         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13740         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13741         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13742
13743         { } /* end */
13744 };
13745
13746 /*
13747  * generic initialization of ADC, input mixers and output mixers
13748  */
13749 static struct hda_verb alc861vd_volume_init_verbs[] = {
13750         /*
13751          * Unmute ADC0 and set the default input to mic-in
13752          */
13753         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13754         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13755
13756         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
13757          * the analog-loopback mixer widget
13758          */
13759         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13760         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13761         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13762         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13763         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13764         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13765
13766         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
13767         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13768         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13769         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13770         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13771
13772         /*
13773          * Set up output mixers (0x02 - 0x05)
13774          */
13775         /* set vol=0 to output mixers */
13776         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13777         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13778         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13779         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13780
13781         /* set up input amps for analog loopback */
13782         /* Amp Indices: DAC = 0, mixer = 1 */
13783         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13784         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13785         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13786         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13787         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13788         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13789         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13790         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13791
13792         { }
13793 };
13794
13795 /*
13796  * 3-stack pin configuration:
13797  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
13798  */
13799 static struct hda_verb alc861vd_3stack_init_verbs[] = {
13800         /*
13801          * Set pin mode and muting
13802          */
13803         /* set front pin widgets 0x14 for output */
13804         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13805         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13806         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13807
13808         /* Mic (rear) pin: input vref at 80% */
13809         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13810         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13811         /* Front Mic pin: input vref at 80% */
13812         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13813         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13814         /* Line In pin: input */
13815         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13816         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13817         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13818         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13819         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13820         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13821         /* CD pin widget for input */
13822         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13823
13824         { }
13825 };
13826
13827 /*
13828  * 6-stack pin configuration:
13829  */
13830 static struct hda_verb alc861vd_6stack_init_verbs[] = {
13831         /*
13832          * Set pin mode and muting
13833          */
13834         /* set front pin widgets 0x14 for output */
13835         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13836         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13837         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13838
13839         /* Rear Pin: output 1 (0x0d) */
13840         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13841         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13842         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13843         /* CLFE Pin: output 2 (0x0e) */
13844         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13845         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13846         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
13847         /* Side Pin: output 3 (0x0f) */
13848         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13849         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13850         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
13851
13852         /* Mic (rear) pin: input vref at 80% */
13853         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13854         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13855         /* Front Mic pin: input vref at 80% */
13856         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13857         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13858         /* Line In pin: input */
13859         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13860         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13861         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13862         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13863         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13864         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13865         /* CD pin widget for input */
13866         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13867
13868         { }
13869 };
13870
13871 static struct hda_verb alc861vd_eapd_verbs[] = {
13872         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13873         { }
13874 };
13875
13876 static struct hda_verb alc660vd_eapd_verbs[] = {
13877         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13878         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13879         { }
13880 };
13881
13882 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
13883         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13884         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13885         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
13886         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13887         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13888         {}
13889 };
13890
13891 /* toggle speaker-output according to the hp-jack state */
13892 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
13893 {
13894         unsigned int present;
13895         unsigned char bits;
13896
13897         present = snd_hda_codec_read(codec, 0x1b, 0,
13898                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13899         bits = present ? HDA_AMP_MUTE : 0;
13900         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13901                                  HDA_AMP_MUTE, bits);
13902 }
13903
13904 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
13905 {
13906         unsigned int present;
13907         unsigned char bits;
13908
13909         present = snd_hda_codec_read(codec, 0x18, 0,
13910                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13911         bits = present ? HDA_AMP_MUTE : 0;
13912         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
13913                                  HDA_AMP_MUTE, bits);
13914 }
13915
13916 static void alc861vd_lenovo_automute(struct hda_codec *codec)
13917 {
13918         alc861vd_lenovo_hp_automute(codec);
13919         alc861vd_lenovo_mic_automute(codec);
13920 }
13921
13922 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
13923                                         unsigned int res)
13924 {
13925         switch (res >> 26) {
13926         case ALC880_HP_EVENT:
13927                 alc861vd_lenovo_hp_automute(codec);
13928                 break;
13929         case ALC880_MIC_EVENT:
13930                 alc861vd_lenovo_mic_automute(codec);
13931                 break;
13932         }
13933 }
13934
13935 static struct hda_verb alc861vd_dallas_verbs[] = {
13936         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13937         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13938         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13939         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13940
13941         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13942         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13943         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13944         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13945         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13946         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13947         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13948         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13949
13950         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13951         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13952         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13953         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13954         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13955         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13956         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13957         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13958
13959         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13960         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13961         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13962         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13963         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13964         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13965         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13966         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13967
13968         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13969         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13970         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13971         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13972
13973         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13974         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13975         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13976
13977         { } /* end */
13978 };
13979
13980 /* toggle speaker-output according to the hp-jack state */
13981 static void alc861vd_dallas_automute(struct hda_codec *codec)
13982 {
13983         unsigned int present;
13984
13985         present = snd_hda_codec_read(codec, 0x15, 0,
13986                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13987         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13988                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13989 }
13990
13991 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
13992 {
13993         if ((res >> 26) == ALC880_HP_EVENT)
13994                 alc861vd_dallas_automute(codec);
13995 }
13996
13997 #ifdef CONFIG_SND_HDA_POWER_SAVE
13998 #define alc861vd_loopbacks      alc880_loopbacks
13999 #endif
14000
14001 /* pcm configuration: identiacal with ALC880 */
14002 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14003 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14004 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14005 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14006
14007 /*
14008  * configuration and preset
14009  */
14010 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14011         [ALC660VD_3ST]          = "3stack-660",
14012         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14013         [ALC660VD_ASUS_V1S]     = "asus-v1s",
14014         [ALC861VD_3ST]          = "3stack",
14015         [ALC861VD_3ST_DIG]      = "3stack-digout",
14016         [ALC861VD_6ST_DIG]      = "6stack-digout",
14017         [ALC861VD_LENOVO]       = "lenovo",
14018         [ALC861VD_DALLAS]       = "dallas",
14019         [ALC861VD_HP]           = "hp",
14020         [ALC861VD_AUTO]         = "auto",
14021 };
14022
14023 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14024         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14025         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14026         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14027         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14028         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
14029         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14030         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14031         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14032         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14033         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14034         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14035         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14036         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14037         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
14038         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
14039         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
14040         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14041         {}
14042 };
14043
14044 static struct alc_config_preset alc861vd_presets[] = {
14045         [ALC660VD_3ST] = {
14046                 .mixers = { alc861vd_3st_mixer },
14047                 .init_verbs = { alc861vd_volume_init_verbs,
14048                                  alc861vd_3stack_init_verbs },
14049                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14050                 .dac_nids = alc660vd_dac_nids,
14051                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14052                 .channel_mode = alc861vd_3stack_2ch_modes,
14053                 .input_mux = &alc861vd_capture_source,
14054         },
14055         [ALC660VD_3ST_DIG] = {
14056                 .mixers = { alc861vd_3st_mixer },
14057                 .init_verbs = { alc861vd_volume_init_verbs,
14058                                  alc861vd_3stack_init_verbs },
14059                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14060                 .dac_nids = alc660vd_dac_nids,
14061                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14062                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14063                 .channel_mode = alc861vd_3stack_2ch_modes,
14064                 .input_mux = &alc861vd_capture_source,
14065         },
14066         [ALC861VD_3ST] = {
14067                 .mixers = { alc861vd_3st_mixer },
14068                 .init_verbs = { alc861vd_volume_init_verbs,
14069                                  alc861vd_3stack_init_verbs },
14070                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14071                 .dac_nids = alc861vd_dac_nids,
14072                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14073                 .channel_mode = alc861vd_3stack_2ch_modes,
14074                 .input_mux = &alc861vd_capture_source,
14075         },
14076         [ALC861VD_3ST_DIG] = {
14077                 .mixers = { alc861vd_3st_mixer },
14078                 .init_verbs = { alc861vd_volume_init_verbs,
14079                                  alc861vd_3stack_init_verbs },
14080                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14081                 .dac_nids = alc861vd_dac_nids,
14082                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14083                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14084                 .channel_mode = alc861vd_3stack_2ch_modes,
14085                 .input_mux = &alc861vd_capture_source,
14086         },
14087         [ALC861VD_6ST_DIG] = {
14088                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14089                 .init_verbs = { alc861vd_volume_init_verbs,
14090                                 alc861vd_6stack_init_verbs },
14091                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14092                 .dac_nids = alc861vd_dac_nids,
14093                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14094                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14095                 .channel_mode = alc861vd_6stack_modes,
14096                 .input_mux = &alc861vd_capture_source,
14097         },
14098         [ALC861VD_LENOVO] = {
14099                 .mixers = { alc861vd_lenovo_mixer },
14100                 .init_verbs = { alc861vd_volume_init_verbs,
14101                                 alc861vd_3stack_init_verbs,
14102                                 alc861vd_eapd_verbs,
14103                                 alc861vd_lenovo_unsol_verbs },
14104                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14105                 .dac_nids = alc660vd_dac_nids,
14106                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14107                 .channel_mode = alc861vd_3stack_2ch_modes,
14108                 .input_mux = &alc861vd_capture_source,
14109                 .unsol_event = alc861vd_lenovo_unsol_event,
14110                 .init_hook = alc861vd_lenovo_automute,
14111         },
14112         [ALC861VD_DALLAS] = {
14113                 .mixers = { alc861vd_dallas_mixer },
14114                 .init_verbs = { alc861vd_dallas_verbs },
14115                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14116                 .dac_nids = alc861vd_dac_nids,
14117                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14118                 .channel_mode = alc861vd_3stack_2ch_modes,
14119                 .input_mux = &alc861vd_dallas_capture_source,
14120                 .unsol_event = alc861vd_dallas_unsol_event,
14121                 .init_hook = alc861vd_dallas_automute,
14122         },
14123         [ALC861VD_HP] = {
14124                 .mixers = { alc861vd_hp_mixer },
14125                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14126                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14127                 .dac_nids = alc861vd_dac_nids,
14128                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14129                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14130                 .channel_mode = alc861vd_3stack_2ch_modes,
14131                 .input_mux = &alc861vd_hp_capture_source,
14132                 .unsol_event = alc861vd_dallas_unsol_event,
14133                 .init_hook = alc861vd_dallas_automute,
14134         },
14135         [ALC660VD_ASUS_V1S] = {
14136                 .mixers = { alc861vd_lenovo_mixer },
14137                 .init_verbs = { alc861vd_volume_init_verbs,
14138                                 alc861vd_3stack_init_verbs,
14139                                 alc861vd_eapd_verbs,
14140                                 alc861vd_lenovo_unsol_verbs },
14141                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14142                 .dac_nids = alc660vd_dac_nids,
14143                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14144                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14145                 .channel_mode = alc861vd_3stack_2ch_modes,
14146                 .input_mux = &alc861vd_capture_source,
14147                 .unsol_event = alc861vd_lenovo_unsol_event,
14148                 .init_hook = alc861vd_lenovo_automute,
14149         },
14150 };
14151
14152 /*
14153  * BIOS auto configuration
14154  */
14155 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14156                                 hda_nid_t nid, int pin_type, int dac_idx)
14157 {
14158         alc_set_pin_output(codec, nid, pin_type);
14159 }
14160
14161 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14162 {
14163         struct alc_spec *spec = codec->spec;
14164         int i;
14165
14166         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14167         for (i = 0; i <= HDA_SIDE; i++) {
14168                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14169                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14170                 if (nid)
14171                         alc861vd_auto_set_output_and_unmute(codec, nid,
14172                                                             pin_type, i);
14173         }
14174 }
14175
14176
14177 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14178 {
14179         struct alc_spec *spec = codec->spec;
14180         hda_nid_t pin;
14181
14182         pin = spec->autocfg.hp_pins[0];
14183         if (pin) /* connect to front and  use dac 0 */
14184                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14185         pin = spec->autocfg.speaker_pins[0];
14186         if (pin)
14187                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14188 }
14189
14190 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14191 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14192
14193 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14194 {
14195         struct alc_spec *spec = codec->spec;
14196         int i;
14197
14198         for (i = 0; i < AUTO_PIN_LAST; i++) {
14199                 hda_nid_t nid = spec->autocfg.input_pins[i];
14200                 if (alc861vd_is_input_pin(nid)) {
14201                         snd_hda_codec_write(codec, nid, 0,
14202                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
14203                                         i <= AUTO_PIN_FRONT_MIC ?
14204                                                         PIN_VREF80 : PIN_IN);
14205                         if (nid != ALC861VD_PIN_CD_NID)
14206                                 snd_hda_codec_write(codec, nid, 0,
14207                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14208                                                 AMP_OUT_MUTE);
14209                 }
14210         }
14211 }
14212
14213 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14214
14215 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14216 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14217
14218 /* add playback controls from the parsed DAC table */
14219 /* Based on ALC880 version. But ALC861VD has separate,
14220  * different NIDs for mute/unmute switch and volume control */
14221 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14222                                              const struct auto_pin_cfg *cfg)
14223 {
14224         char name[32];
14225         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14226         hda_nid_t nid_v, nid_s;
14227         int i, err;
14228
14229         for (i = 0; i < cfg->line_outs; i++) {
14230                 if (!spec->multiout.dac_nids[i])
14231                         continue;
14232                 nid_v = alc861vd_idx_to_mixer_vol(
14233                                 alc880_dac_to_idx(
14234                                         spec->multiout.dac_nids[i]));
14235                 nid_s = alc861vd_idx_to_mixer_switch(
14236                                 alc880_dac_to_idx(
14237                                         spec->multiout.dac_nids[i]));
14238
14239                 if (i == 2) {
14240                         /* Center/LFE */
14241                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14242                                           "Center Playback Volume",
14243                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14244                                                               HDA_OUTPUT));
14245                         if (err < 0)
14246                                 return err;
14247                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14248                                           "LFE Playback Volume",
14249                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14250                                                               HDA_OUTPUT));
14251                         if (err < 0)
14252                                 return err;
14253                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14254                                           "Center Playback Switch",
14255                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14256                                                               HDA_INPUT));
14257                         if (err < 0)
14258                                 return err;
14259                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14260                                           "LFE Playback Switch",
14261                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14262                                                               HDA_INPUT));
14263                         if (err < 0)
14264                                 return err;
14265                 } else {
14266                         sprintf(name, "%s Playback Volume", chname[i]);
14267                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14268                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14269                                                               HDA_OUTPUT));
14270                         if (err < 0)
14271                                 return err;
14272                         sprintf(name, "%s Playback Switch", chname[i]);
14273                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14274                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14275                                                               HDA_INPUT));
14276                         if (err < 0)
14277                                 return err;
14278                 }
14279         }
14280         return 0;
14281 }
14282
14283 /* add playback controls for speaker and HP outputs */
14284 /* Based on ALC880 version. But ALC861VD has separate,
14285  * different NIDs for mute/unmute switch and volume control */
14286 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14287                                         hda_nid_t pin, const char *pfx)
14288 {
14289         hda_nid_t nid_v, nid_s;
14290         int err;
14291         char name[32];
14292
14293         if (!pin)
14294                 return 0;
14295
14296         if (alc880_is_fixed_pin(pin)) {
14297                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14298                 /* specify the DAC as the extra output */
14299                 if (!spec->multiout.hp_nid)
14300                         spec->multiout.hp_nid = nid_v;
14301                 else
14302                         spec->multiout.extra_out_nid[0] = nid_v;
14303                 /* control HP volume/switch on the output mixer amp */
14304                 nid_v = alc861vd_idx_to_mixer_vol(
14305                                 alc880_fixed_pin_idx(pin));
14306                 nid_s = alc861vd_idx_to_mixer_switch(
14307                                 alc880_fixed_pin_idx(pin));
14308
14309                 sprintf(name, "%s Playback Volume", pfx);
14310                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14311                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
14312                 if (err < 0)
14313                         return err;
14314                 sprintf(name, "%s Playback Switch", pfx);
14315                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14316                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
14317                 if (err < 0)
14318                         return err;
14319         } else if (alc880_is_multi_pin(pin)) {
14320                 /* set manual connection */
14321                 /* we have only a switch on HP-out PIN */
14322                 sprintf(name, "%s Playback Switch", pfx);
14323                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14324                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14325                 if (err < 0)
14326                         return err;
14327         }
14328         return 0;
14329 }
14330
14331 /* parse the BIOS configuration and set up the alc_spec
14332  * return 1 if successful, 0 if the proper config is not found,
14333  * or a negative error code
14334  * Based on ALC880 version - had to change it to override
14335  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
14336 static int alc861vd_parse_auto_config(struct hda_codec *codec)
14337 {
14338         struct alc_spec *spec = codec->spec;
14339         int err;
14340         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
14341
14342         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14343                                            alc861vd_ignore);
14344         if (err < 0)
14345                 return err;
14346         if (!spec->autocfg.line_outs)
14347                 return 0; /* can't find valid BIOS pin config */
14348
14349         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14350         if (err < 0)
14351                 return err;
14352         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
14353         if (err < 0)
14354                 return err;
14355         err = alc861vd_auto_create_extra_out(spec,
14356                                              spec->autocfg.speaker_pins[0],
14357                                              "Speaker");
14358         if (err < 0)
14359                 return err;
14360         err = alc861vd_auto_create_extra_out(spec,
14361                                              spec->autocfg.hp_pins[0],
14362                                              "Headphone");
14363         if (err < 0)
14364                 return err;
14365         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
14366         if (err < 0)
14367                 return err;
14368
14369         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14370
14371         if (spec->autocfg.dig_out_pin)
14372                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14373
14374         if (spec->kctls.list)
14375                 add_mixer(spec, spec->kctls.list);
14376
14377         add_verb(spec, alc861vd_volume_init_verbs);
14378
14379         spec->num_mux_defs = 1;
14380         spec->input_mux = &spec->private_imux;
14381
14382         err = alc_auto_add_mic_boost(codec);
14383         if (err < 0)
14384                 return err;
14385
14386         store_pin_configs(codec);
14387         return 1;
14388 }
14389
14390 /* additional initialization for auto-configuration model */
14391 static void alc861vd_auto_init(struct hda_codec *codec)
14392 {
14393         struct alc_spec *spec = codec->spec;
14394         alc861vd_auto_init_multi_out(codec);
14395         alc861vd_auto_init_hp_out(codec);
14396         alc861vd_auto_init_analog_input(codec);
14397         alc861vd_auto_init_input_src(codec);
14398         if (spec->unsol_event)
14399                 alc_inithook(codec);
14400 }
14401
14402 static int patch_alc861vd(struct hda_codec *codec)
14403 {
14404         struct alc_spec *spec;
14405         int err, board_config;
14406
14407         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14408         if (spec == NULL)
14409                 return -ENOMEM;
14410
14411         codec->spec = spec;
14412
14413         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
14414                                                   alc861vd_models,
14415                                                   alc861vd_cfg_tbl);
14416
14417         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
14418                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
14419                         "ALC861VD, trying auto-probe from BIOS...\n");
14420                 board_config = ALC861VD_AUTO;
14421         }
14422
14423         if (board_config == ALC861VD_AUTO) {
14424                 /* automatic parse from the BIOS config */
14425                 err = alc861vd_parse_auto_config(codec);
14426                 if (err < 0) {
14427                         alc_free(codec);
14428                         return err;
14429                 } else if (!err) {
14430                         printk(KERN_INFO
14431                                "hda_codec: Cannot set up configuration "
14432                                "from BIOS.  Using base mode...\n");
14433                         board_config = ALC861VD_3ST;
14434                 }
14435         }
14436
14437         if (board_config != ALC861VD_AUTO)
14438                 setup_preset(spec, &alc861vd_presets[board_config]);
14439
14440         if (codec->vendor_id == 0x10ec0660) {
14441                 spec->stream_name_analog = "ALC660-VD Analog";
14442                 spec->stream_name_digital = "ALC660-VD Digital";
14443                 /* always turn on EAPD */
14444                 add_verb(spec, alc660vd_eapd_verbs);
14445         } else {
14446                 spec->stream_name_analog = "ALC861VD Analog";
14447                 spec->stream_name_digital = "ALC861VD Digital";
14448         }
14449
14450         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
14451         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
14452
14453         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
14454         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
14455
14456         spec->adc_nids = alc861vd_adc_nids;
14457         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14458         spec->capsrc_nids = alc861vd_capsrc_nids;
14459         spec->is_mix_capture = 1;
14460
14461         set_capture_mixer(spec);
14462
14463         spec->vmaster_nid = 0x02;
14464
14465         codec->patch_ops = alc_patch_ops;
14466
14467         if (board_config == ALC861VD_AUTO)
14468                 spec->init_hook = alc861vd_auto_init;
14469 #ifdef CONFIG_SND_HDA_POWER_SAVE
14470         if (!spec->loopback.amplist)
14471                 spec->loopback.amplist = alc861vd_loopbacks;
14472 #endif
14473
14474         return 0;
14475 }
14476
14477 /*
14478  * ALC662 support
14479  *
14480  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
14481  * configuration.  Each pin widget can choose any input DACs and a mixer.
14482  * Each ADC is connected from a mixer of all inputs.  This makes possible
14483  * 6-channel independent captures.
14484  *
14485  * In addition, an independent DAC for the multi-playback (not used in this
14486  * driver yet).
14487  */
14488 #define ALC662_DIGOUT_NID       0x06
14489 #define ALC662_DIGIN_NID        0x0a
14490
14491 static hda_nid_t alc662_dac_nids[4] = {
14492         /* front, rear, clfe, rear_surr */
14493         0x02, 0x03, 0x04
14494 };
14495
14496 static hda_nid_t alc662_adc_nids[1] = {
14497         /* ADC1-2 */
14498         0x09,
14499 };
14500
14501 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
14502
14503 /* input MUX */
14504 /* FIXME: should be a matrix-type input source selection */
14505 static struct hda_input_mux alc662_capture_source = {
14506         .num_items = 4,
14507         .items = {
14508                 { "Mic", 0x0 },
14509                 { "Front Mic", 0x1 },
14510                 { "Line", 0x2 },
14511                 { "CD", 0x4 },
14512         },
14513 };
14514
14515 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
14516         .num_items = 2,
14517         .items = {
14518                 { "Mic", 0x1 },
14519                 { "Line", 0x2 },
14520         },
14521 };
14522
14523 static struct hda_input_mux alc662_eeepc_capture_source = {
14524         .num_items = 2,
14525         .items = {
14526                 { "i-Mic", 0x1 },
14527                 { "e-Mic", 0x0 },
14528         },
14529 };
14530
14531 static struct hda_input_mux alc663_capture_source = {
14532         .num_items = 3,
14533         .items = {
14534                 { "Mic", 0x0 },
14535                 { "Front Mic", 0x1 },
14536                 { "Line", 0x2 },
14537         },
14538 };
14539
14540 static struct hda_input_mux alc663_m51va_capture_source = {
14541         .num_items = 2,
14542         .items = {
14543                 { "Ext-Mic", 0x0 },
14544                 { "D-Mic", 0x9 },
14545         },
14546 };
14547
14548 /*
14549  * 2ch mode
14550  */
14551 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
14552         { 2, NULL }
14553 };
14554
14555 /*
14556  * 2ch mode
14557  */
14558 static struct hda_verb alc662_3ST_ch2_init[] = {
14559         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
14560         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14561         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
14562         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14563         { } /* end */
14564 };
14565
14566 /*
14567  * 6ch mode
14568  */
14569 static struct hda_verb alc662_3ST_ch6_init[] = {
14570         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14571         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14572         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
14573         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14574         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14575         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
14576         { } /* end */
14577 };
14578
14579 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
14580         { 2, alc662_3ST_ch2_init },
14581         { 6, alc662_3ST_ch6_init },
14582 };
14583
14584 /*
14585  * 2ch mode
14586  */
14587 static struct hda_verb alc662_sixstack_ch6_init[] = {
14588         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14589         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14590         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14591         { } /* end */
14592 };
14593
14594 /*
14595  * 6ch mode
14596  */
14597 static struct hda_verb alc662_sixstack_ch8_init[] = {
14598         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14599         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14600         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14601         { } /* end */
14602 };
14603
14604 static struct hda_channel_mode alc662_5stack_modes[2] = {
14605         { 2, alc662_sixstack_ch6_init },
14606         { 6, alc662_sixstack_ch8_init },
14607 };
14608
14609 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14610  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14611  */
14612
14613 static struct snd_kcontrol_new alc662_base_mixer[] = {
14614         /* output mixer control */
14615         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
14616         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14617         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
14618         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14619         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14620         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14621         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14622         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14623         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14624
14625         /*Input mixer control */
14626         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
14627         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
14628         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
14629         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
14630         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
14631         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
14632         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
14633         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
14634         { } /* end */
14635 };
14636
14637 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
14638         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14639         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14640         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14641         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14642         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14643         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14644         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14645         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14646         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14647         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14648         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14649         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14650         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14651         { } /* end */
14652 };
14653
14654 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
14655         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14656         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14657         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14658         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14659         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14660         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14661         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14662         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14663         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14664         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14665         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14666         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14667         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14668         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14669         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14670         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14671         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14672         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14673         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14674         { } /* end */
14675 };
14676
14677 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
14678         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14679         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
14680         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14681         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
14682         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14683         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14684         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14685         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14686         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14687         { } /* end */
14688 };
14689
14690 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
14691         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14692
14693         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14694         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14695
14696         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
14697         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14698         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14699
14700         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
14701         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14702         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14703         { } /* end */
14704 };
14705
14706 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
14707         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14708         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14709         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14710         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
14711         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14712         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14713         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
14714         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
14715         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14716         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
14717         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14718         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14719         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14720         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14721         { } /* end */
14722 };
14723
14724 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
14725         .ops = &snd_hda_bind_vol,
14726         .values = {
14727                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
14728                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
14729                 0
14730         },
14731 };
14732
14733 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
14734         .ops = &snd_hda_bind_sw,
14735         .values = {
14736                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14737                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
14738                 0
14739         },
14740 };
14741
14742 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
14743         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14744         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
14745         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14746         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14747         { } /* end */
14748 };
14749
14750 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
14751         .ops = &snd_hda_bind_sw,
14752         .values = {
14753                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14754                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
14755                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
14756                 0
14757         },
14758 };
14759
14760 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
14761         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14762         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
14763         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14764         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14765         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14766         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14767
14768         { } /* end */
14769 };
14770
14771 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
14772         .ops = &snd_hda_bind_sw,
14773         .values = {
14774                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14775                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
14776                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
14777                 0
14778         },
14779 };
14780
14781 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
14782         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14783         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
14784         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14785         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14786         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14787         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14788         { } /* end */
14789 };
14790
14791 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
14792         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14793         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14794         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14795         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14796         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14797         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14798         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14799         { } /* end */
14800 };
14801
14802 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
14803         .ops = &snd_hda_bind_vol,
14804         .values = {
14805                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
14806                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
14807                 0
14808         },
14809 };
14810
14811 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
14812         .ops = &snd_hda_bind_sw,
14813         .values = {
14814                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14815                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
14816                 0
14817         },
14818 };
14819
14820 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
14821         HDA_BIND_VOL("Master Playback Volume",
14822                                 &alc663_asus_two_bind_master_vol),
14823         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
14824         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14825         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14826         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14827         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14828         { } /* end */
14829 };
14830
14831 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
14832         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14833         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
14834         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14835         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14836         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14837         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14838         { } /* end */
14839 };
14840
14841 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
14842         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14843         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14844         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14845         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14846         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14847
14848         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14849         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14850         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14851         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14852         { } /* end */
14853 };
14854
14855 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
14856         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14857         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14858         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14859
14860         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14861         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14862         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14863         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14864         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14865         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14866         { } /* end */
14867 };
14868
14869 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
14870         {
14871                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14872                 .name = "Channel Mode",
14873                 .info = alc_ch_mode_info,
14874                 .get = alc_ch_mode_get,
14875                 .put = alc_ch_mode_put,
14876         },
14877         { } /* end */
14878 };
14879
14880 static struct hda_verb alc662_init_verbs[] = {
14881         /* ADC: mute amp left and right */
14882         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14883         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14884         /* Front mixer: unmute input/output amp left and right (volume = 0) */
14885
14886         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14887         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14888         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14889         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14890         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14891
14892         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14893         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14894         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14895         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14896         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14897         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14898
14899         /* Front Pin: output 0 (0x0c) */
14900         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14901         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14902
14903         /* Rear Pin: output 1 (0x0d) */
14904         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14905         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14906
14907         /* CLFE Pin: output 2 (0x0e) */
14908         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14909         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14910
14911         /* Mic (rear) pin: input vref at 80% */
14912         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14913         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14914         /* Front Mic pin: input vref at 80% */
14915         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14916         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14917         /* Line In pin: input */
14918         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14919         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14920         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14921         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14922         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14923         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14924         /* CD pin widget for input */
14925         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14926
14927         /* FIXME: use matrix-type input source selection */
14928         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
14929         /* Input mixer */
14930         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14931         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14932         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14933         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14934
14935         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14936         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14937         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14938         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14939
14940         /* always trun on EAPD */
14941         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14942         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14943
14944         { }
14945 };
14946
14947 static struct hda_verb alc662_sue_init_verbs[] = {
14948         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
14949         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
14950         {}
14951 };
14952
14953 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
14954         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14955         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14956         {}
14957 };
14958
14959 /* Set Unsolicited Event*/
14960 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
14961         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14962         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14963         {}
14964 };
14965
14966 /*
14967  * generic initialization of ADC, input mixers and output mixers
14968  */
14969 static struct hda_verb alc662_auto_init_verbs[] = {
14970         /*
14971          * Unmute ADC and set the default input to mic-in
14972          */
14973         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14974         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14975
14976         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
14977          * mixer widget
14978          * Note: PASD motherboards uses the Line In 2 as the input for front
14979          * panel mic (mic 2)
14980          */
14981         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14982         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14983         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14984         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14985         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14986         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14987
14988         /*
14989          * Set up output mixers (0x0c - 0x0f)
14990          */
14991         /* set vol=0 to output mixers */
14992         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14993         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14994         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14995
14996         /* set up input amps for analog loopback */
14997         /* Amp Indices: DAC = 0, mixer = 1 */
14998         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14999         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15000         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15001         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15002         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15003         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15004
15005
15006         /* FIXME: use matrix-type input source selection */
15007         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15008         /* Input mixer */
15009         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15010         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15011         { }
15012 };
15013
15014 /* additional verbs for ALC663 */
15015 static struct hda_verb alc663_auto_init_verbs[] = {
15016         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15017         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15018         { }
15019 };
15020
15021 static struct hda_verb alc663_m51va_init_verbs[] = {
15022         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15023         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15024         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15025         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15026         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15027         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15028         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15029         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15030         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15031         {}
15032 };
15033
15034 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15035         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15036         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15037         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15038         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15039         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15040         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15041         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15042         {}
15043 };
15044
15045 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15046         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15047         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15048         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15049         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15050         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15051         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15052         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15053         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15054         {}
15055 };
15056
15057 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15058         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15059         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15060         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15061         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15062         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15063         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15064         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15065         {}
15066 };
15067
15068 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15069         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15070         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15071         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15072         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15073         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15074         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15075         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15076         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15077         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15078         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15079         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15080         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15081         {}
15082 };
15083
15084 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15085         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15086         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15087         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15088         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15089         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15090         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15091         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15092         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15093         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15094         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15095         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15096         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15097         {}
15098 };
15099
15100 static struct hda_verb alc663_g71v_init_verbs[] = {
15101         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15102         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15103         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15104
15105         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15106         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15107         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15108
15109         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15110         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15111         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15112         {}
15113 };
15114
15115 static struct hda_verb alc663_g50v_init_verbs[] = {
15116         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15117         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15118         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15119
15120         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15121         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15122         {}
15123 };
15124
15125 static struct hda_verb alc662_ecs_init_verbs[] = {
15126         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15127         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15128         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15129         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15130         {}
15131 };
15132
15133 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15134         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15135         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15136         { } /* end */
15137 };
15138
15139 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15140 {
15141         unsigned int present;
15142         unsigned char bits;
15143
15144         present = snd_hda_codec_read(codec, 0x14, 0,
15145                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15146         bits = present ? HDA_AMP_MUTE : 0;
15147         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15148                                  HDA_AMP_MUTE, bits);
15149 }
15150
15151 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15152 {
15153         unsigned int present;
15154         unsigned char bits;
15155
15156         present = snd_hda_codec_read(codec, 0x1b, 0,
15157                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15158         bits = present ? HDA_AMP_MUTE : 0;
15159         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15160                                  HDA_AMP_MUTE, bits);
15161         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15162                                  HDA_AMP_MUTE, bits);
15163 }
15164
15165 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15166                                            unsigned int res)
15167 {
15168         if ((res >> 26) == ALC880_HP_EVENT)
15169                 alc662_lenovo_101e_all_automute(codec);
15170         if ((res >> 26) == ALC880_FRONT_EVENT)
15171                 alc662_lenovo_101e_ispeaker_automute(codec);
15172 }
15173
15174 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15175 {
15176         unsigned int present;
15177
15178         present = snd_hda_codec_read(codec, 0x18, 0,
15179                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15180         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15181                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15182         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15183                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15184         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15185                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15186         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15187                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15188 }
15189
15190 /* unsolicited event for HP jack sensing */
15191 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15192                                      unsigned int res)
15193 {
15194         if ((res >> 26) == ALC880_HP_EVENT)
15195                 alc262_hippo1_automute( codec );
15196
15197         if ((res >> 26) == ALC880_MIC_EVENT)
15198                 alc662_eeepc_mic_automute(codec);
15199 }
15200
15201 static void alc662_eeepc_inithook(struct hda_codec *codec)
15202 {
15203         alc262_hippo1_automute( codec );
15204         alc662_eeepc_mic_automute(codec);
15205 }
15206
15207 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15208 {
15209         unsigned int mute;
15210         unsigned int present;
15211
15212         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15213         present = snd_hda_codec_read(codec, 0x14, 0,
15214                                      AC_VERB_GET_PIN_SENSE, 0);
15215         present = (present & 0x80000000) != 0;
15216         if (present) {
15217                 /* mute internal speaker */
15218                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15219                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15220         } else {
15221                 /* unmute internal speaker if necessary */
15222                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15223                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15224                                         HDA_AMP_MUTE, mute);
15225         }
15226 }
15227
15228 /* unsolicited event for HP jack sensing */
15229 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15230                                           unsigned int res)
15231 {
15232         if ((res >> 26) == ALC880_HP_EVENT)
15233                 alc662_eeepc_ep20_automute(codec);
15234 }
15235
15236 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15237 {
15238         alc662_eeepc_ep20_automute(codec);
15239 }
15240
15241 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15242 {
15243         unsigned int present;
15244         unsigned char bits;
15245
15246         present = snd_hda_codec_read(codec, 0x21, 0,
15247                         AC_VERB_GET_PIN_SENSE, 0)
15248                         & AC_PINSENSE_PRESENCE;
15249         bits = present ? HDA_AMP_MUTE : 0;
15250         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15251                                 AMP_IN_MUTE(0), bits);
15252         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15253                                 AMP_IN_MUTE(0), bits);
15254 }
15255
15256 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15257 {
15258         unsigned int present;
15259         unsigned char bits;
15260
15261         present = snd_hda_codec_read(codec, 0x21, 0,
15262                         AC_VERB_GET_PIN_SENSE, 0)
15263                         & AC_PINSENSE_PRESENCE;
15264         bits = present ? HDA_AMP_MUTE : 0;
15265         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15266                                 AMP_IN_MUTE(0), bits);
15267         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15268                                 AMP_IN_MUTE(0), bits);
15269         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15270                                 AMP_IN_MUTE(0), bits);
15271         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15272                                 AMP_IN_MUTE(0), bits);
15273 }
15274
15275 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15276 {
15277         unsigned int present;
15278         unsigned char bits;
15279
15280         present = snd_hda_codec_read(codec, 0x15, 0,
15281                         AC_VERB_GET_PIN_SENSE, 0)
15282                         & AC_PINSENSE_PRESENCE;
15283         bits = present ? HDA_AMP_MUTE : 0;
15284         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15285                                 AMP_IN_MUTE(0), bits);
15286         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15287                                 AMP_IN_MUTE(0), bits);
15288         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15289                                 AMP_IN_MUTE(0), bits);
15290         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15291                                 AMP_IN_MUTE(0), bits);
15292 }
15293
15294 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15295 {
15296         unsigned int present;
15297         unsigned char bits;
15298
15299         present = snd_hda_codec_read(codec, 0x1b, 0,
15300                         AC_VERB_GET_PIN_SENSE, 0)
15301                         & AC_PINSENSE_PRESENCE;
15302         bits = present ? 0 : PIN_OUT;
15303         snd_hda_codec_write(codec, 0x14, 0,
15304                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15305 }
15306
15307 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15308 {
15309         unsigned int present1, present2;
15310
15311         present1 = snd_hda_codec_read(codec, 0x21, 0,
15312                         AC_VERB_GET_PIN_SENSE, 0)
15313                         & AC_PINSENSE_PRESENCE;
15314         present2 = snd_hda_codec_read(codec, 0x15, 0,
15315                         AC_VERB_GET_PIN_SENSE, 0)
15316                         & AC_PINSENSE_PRESENCE;
15317
15318         if (present1 || present2) {
15319                 snd_hda_codec_write_cache(codec, 0x14, 0,
15320                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15321         } else {
15322                 snd_hda_codec_write_cache(codec, 0x14, 0,
15323                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15324         }
15325 }
15326
15327 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15328 {
15329         unsigned int present1, present2;
15330
15331         present1 = snd_hda_codec_read(codec, 0x1b, 0,
15332                                 AC_VERB_GET_PIN_SENSE, 0)
15333                                 & AC_PINSENSE_PRESENCE;
15334         present2 = snd_hda_codec_read(codec, 0x15, 0,
15335                                 AC_VERB_GET_PIN_SENSE, 0)
15336                                 & AC_PINSENSE_PRESENCE;
15337
15338         if (present1 || present2) {
15339                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15340                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15341                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15342                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15343         } else {
15344                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15345                                 AMP_IN_MUTE(0), 0);
15346                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15347                                 AMP_IN_MUTE(0), 0);
15348         }
15349 }
15350
15351 static void alc663_m51va_mic_automute(struct hda_codec *codec)
15352 {
15353         unsigned int present;
15354
15355         present = snd_hda_codec_read(codec, 0x18, 0,
15356                         AC_VERB_GET_PIN_SENSE, 0)
15357                         & AC_PINSENSE_PRESENCE;
15358         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15359                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15360         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15361                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15362         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15363                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15364         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15365                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15366 }
15367
15368 static void alc663_m51va_unsol_event(struct hda_codec *codec,
15369                                            unsigned int res)
15370 {
15371         switch (res >> 26) {
15372         case ALC880_HP_EVENT:
15373                 alc663_m51va_speaker_automute(codec);
15374                 break;
15375         case ALC880_MIC_EVENT:
15376                 alc663_m51va_mic_automute(codec);
15377                 break;
15378         }
15379 }
15380
15381 static void alc663_m51va_inithook(struct hda_codec *codec)
15382 {
15383         alc663_m51va_speaker_automute(codec);
15384         alc663_m51va_mic_automute(codec);
15385 }
15386
15387 /* ***************** Mode1 ******************************/
15388 static void alc663_mode1_unsol_event(struct hda_codec *codec,
15389                                            unsigned int res)
15390 {
15391         switch (res >> 26) {
15392         case ALC880_HP_EVENT:
15393                 alc663_m51va_speaker_automute(codec);
15394                 break;
15395         case ALC880_MIC_EVENT:
15396                 alc662_eeepc_mic_automute(codec);
15397                 break;
15398         }
15399 }
15400
15401 static void alc663_mode1_inithook(struct hda_codec *codec)
15402 {
15403         alc663_m51va_speaker_automute(codec);
15404         alc662_eeepc_mic_automute(codec);
15405 }
15406 /* ***************** Mode2 ******************************/
15407 static void alc662_mode2_unsol_event(struct hda_codec *codec,
15408                                            unsigned int res)
15409 {
15410         switch (res >> 26) {
15411         case ALC880_HP_EVENT:
15412                 alc662_f5z_speaker_automute(codec);
15413                 break;
15414         case ALC880_MIC_EVENT:
15415                 alc662_eeepc_mic_automute(codec);
15416                 break;
15417         }
15418 }
15419
15420 static void alc662_mode2_inithook(struct hda_codec *codec)
15421 {
15422         alc662_f5z_speaker_automute(codec);
15423         alc662_eeepc_mic_automute(codec);
15424 }
15425 /* ***************** Mode3 ******************************/
15426 static void alc663_mode3_unsol_event(struct hda_codec *codec,
15427                                            unsigned int res)
15428 {
15429         switch (res >> 26) {
15430         case ALC880_HP_EVENT:
15431                 alc663_two_hp_m1_speaker_automute(codec);
15432                 break;
15433         case ALC880_MIC_EVENT:
15434                 alc662_eeepc_mic_automute(codec);
15435                 break;
15436         }
15437 }
15438
15439 static void alc663_mode3_inithook(struct hda_codec *codec)
15440 {
15441         alc663_two_hp_m1_speaker_automute(codec);
15442         alc662_eeepc_mic_automute(codec);
15443 }
15444 /* ***************** Mode4 ******************************/
15445 static void alc663_mode4_unsol_event(struct hda_codec *codec,
15446                                            unsigned int res)
15447 {
15448         switch (res >> 26) {
15449         case ALC880_HP_EVENT:
15450                 alc663_21jd_two_speaker_automute(codec);
15451                 break;
15452         case ALC880_MIC_EVENT:
15453                 alc662_eeepc_mic_automute(codec);
15454                 break;
15455         }
15456 }
15457
15458 static void alc663_mode4_inithook(struct hda_codec *codec)
15459 {
15460         alc663_21jd_two_speaker_automute(codec);
15461         alc662_eeepc_mic_automute(codec);
15462 }
15463 /* ***************** Mode5 ******************************/
15464 static void alc663_mode5_unsol_event(struct hda_codec *codec,
15465                                            unsigned int res)
15466 {
15467         switch (res >> 26) {
15468         case ALC880_HP_EVENT:
15469                 alc663_15jd_two_speaker_automute(codec);
15470                 break;
15471         case ALC880_MIC_EVENT:
15472                 alc662_eeepc_mic_automute(codec);
15473                 break;
15474         }
15475 }
15476
15477 static void alc663_mode5_inithook(struct hda_codec *codec)
15478 {
15479         alc663_15jd_two_speaker_automute(codec);
15480         alc662_eeepc_mic_automute(codec);
15481 }
15482 /* ***************** Mode6 ******************************/
15483 static void alc663_mode6_unsol_event(struct hda_codec *codec,
15484                                            unsigned int res)
15485 {
15486         switch (res >> 26) {
15487         case ALC880_HP_EVENT:
15488                 alc663_two_hp_m2_speaker_automute(codec);
15489                 break;
15490         case ALC880_MIC_EVENT:
15491                 alc662_eeepc_mic_automute(codec);
15492                 break;
15493         }
15494 }
15495
15496 static void alc663_mode6_inithook(struct hda_codec *codec)
15497 {
15498         alc663_two_hp_m2_speaker_automute(codec);
15499         alc662_eeepc_mic_automute(codec);
15500 }
15501
15502 static void alc663_g71v_hp_automute(struct hda_codec *codec)
15503 {
15504         unsigned int present;
15505         unsigned char bits;
15506
15507         present = snd_hda_codec_read(codec, 0x21, 0,
15508                                      AC_VERB_GET_PIN_SENSE, 0)
15509                 & AC_PINSENSE_PRESENCE;
15510         bits = present ? HDA_AMP_MUTE : 0;
15511         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15512                                  HDA_AMP_MUTE, bits);
15513         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15514                                  HDA_AMP_MUTE, bits);
15515 }
15516
15517 static void alc663_g71v_front_automute(struct hda_codec *codec)
15518 {
15519         unsigned int present;
15520         unsigned char bits;
15521
15522         present = snd_hda_codec_read(codec, 0x15, 0,
15523                                      AC_VERB_GET_PIN_SENSE, 0)
15524                 & AC_PINSENSE_PRESENCE;
15525         bits = present ? HDA_AMP_MUTE : 0;
15526         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15527                                  HDA_AMP_MUTE, bits);
15528 }
15529
15530 static void alc663_g71v_unsol_event(struct hda_codec *codec,
15531                                            unsigned int res)
15532 {
15533         switch (res >> 26) {
15534         case ALC880_HP_EVENT:
15535                 alc663_g71v_hp_automute(codec);
15536                 break;
15537         case ALC880_FRONT_EVENT:
15538                 alc663_g71v_front_automute(codec);
15539                 break;
15540         case ALC880_MIC_EVENT:
15541                 alc662_eeepc_mic_automute(codec);
15542                 break;
15543         }
15544 }
15545
15546 static void alc663_g71v_inithook(struct hda_codec *codec)
15547 {
15548         alc663_g71v_front_automute(codec);
15549         alc663_g71v_hp_automute(codec);
15550         alc662_eeepc_mic_automute(codec);
15551 }
15552
15553 static void alc663_g50v_unsol_event(struct hda_codec *codec,
15554                                            unsigned int res)
15555 {
15556         switch (res >> 26) {
15557         case ALC880_HP_EVENT:
15558                 alc663_m51va_speaker_automute(codec);
15559                 break;
15560         case ALC880_MIC_EVENT:
15561                 alc662_eeepc_mic_automute(codec);
15562                 break;
15563         }
15564 }
15565
15566 static void alc663_g50v_inithook(struct hda_codec *codec)
15567 {
15568         alc663_m51va_speaker_automute(codec);
15569         alc662_eeepc_mic_automute(codec);
15570 }
15571
15572 /* bind hp and internal speaker mute (with plug check) */
15573 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15574                                      struct snd_ctl_elem_value *ucontrol)
15575 {
15576         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15577         long *valp = ucontrol->value.integer.value;
15578         int change;
15579
15580         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15581                                           HDA_AMP_MUTE,
15582                                           valp[0] ? 0 : HDA_AMP_MUTE);
15583         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15584                                            HDA_AMP_MUTE,
15585                                            valp[1] ? 0 : HDA_AMP_MUTE);
15586         if (change)
15587                 alc262_hippo1_automute(codec);
15588         return change;
15589 }
15590
15591 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
15592         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15593         {
15594                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15595                 .name = "Master Playback Switch",
15596                 .info = snd_hda_mixer_amp_switch_info,
15597                 .get = snd_hda_mixer_amp_switch_get,
15598                 .put = alc662_ecs_master_sw_put,
15599                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15600         },
15601
15602         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
15603         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
15604         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
15605
15606         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15607         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15608         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15609         { } /* end */
15610 };
15611
15612 #ifdef CONFIG_SND_HDA_POWER_SAVE
15613 #define alc662_loopbacks        alc880_loopbacks
15614 #endif
15615
15616
15617 /* pcm configuration: identiacal with ALC880 */
15618 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
15619 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
15620 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
15621 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
15622
15623 /*
15624  * configuration and preset
15625  */
15626 static const char *alc662_models[ALC662_MODEL_LAST] = {
15627         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
15628         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
15629         [ALC662_3ST_6ch]        = "3stack-6ch",
15630         [ALC662_5ST_DIG]        = "6stack-dig",
15631         [ALC662_LENOVO_101E]    = "lenovo-101e",
15632         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
15633         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
15634         [ALC662_ECS] = "ecs",
15635         [ALC663_ASUS_M51VA] = "m51va",
15636         [ALC663_ASUS_G71V] = "g71v",
15637         [ALC663_ASUS_H13] = "h13",
15638         [ALC663_ASUS_G50V] = "g50v",
15639         [ALC663_ASUS_MODE1] = "asus-mode1",
15640         [ALC662_ASUS_MODE2] = "asus-mode2",
15641         [ALC663_ASUS_MODE3] = "asus-mode3",
15642         [ALC663_ASUS_MODE4] = "asus-mode4",
15643         [ALC663_ASUS_MODE5] = "asus-mode5",
15644         [ALC663_ASUS_MODE6] = "asus-mode6",
15645         [ALC662_AUTO]           = "auto",
15646 };
15647
15648 static struct snd_pci_quirk alc662_cfg_tbl[] = {
15649         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
15650         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
15651         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
15652         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
15653         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
15654         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
15655         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
15656         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
15657         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
15658         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
15659         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
15660         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
15661         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
15662         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
15663         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
15664         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
15665         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
15666         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
15667         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
15668         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
15669         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
15670         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
15671         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
15672         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
15673         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
15674         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
15675         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
15676         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
15677         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
15678         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
15679         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
15680         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
15681         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
15682         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
15683         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
15684         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
15685         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
15686         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
15687                       ALC662_3ST_6ch_DIG),
15688         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
15689         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
15690         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
15691         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
15692                       ALC662_3ST_6ch_DIG),
15693         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
15694         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
15695                                         ALC662_3ST_6ch_DIG),
15696         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
15697         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
15698         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
15699         {}
15700 };
15701
15702 static struct alc_config_preset alc662_presets[] = {
15703         [ALC662_3ST_2ch_DIG] = {
15704                 .mixers = { alc662_3ST_2ch_mixer },
15705                 .init_verbs = { alc662_init_verbs },
15706                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15707                 .dac_nids = alc662_dac_nids,
15708                 .dig_out_nid = ALC662_DIGOUT_NID,
15709                 .dig_in_nid = ALC662_DIGIN_NID,
15710                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15711                 .channel_mode = alc662_3ST_2ch_modes,
15712                 .input_mux = &alc662_capture_source,
15713         },
15714         [ALC662_3ST_6ch_DIG] = {
15715                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
15716                 .init_verbs = { alc662_init_verbs },
15717                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15718                 .dac_nids = alc662_dac_nids,
15719                 .dig_out_nid = ALC662_DIGOUT_NID,
15720                 .dig_in_nid = ALC662_DIGIN_NID,
15721                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15722                 .channel_mode = alc662_3ST_6ch_modes,
15723                 .need_dac_fix = 1,
15724                 .input_mux = &alc662_capture_source,
15725         },
15726         [ALC662_3ST_6ch] = {
15727                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
15728                 .init_verbs = { alc662_init_verbs },
15729                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15730                 .dac_nids = alc662_dac_nids,
15731                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15732                 .channel_mode = alc662_3ST_6ch_modes,
15733                 .need_dac_fix = 1,
15734                 .input_mux = &alc662_capture_source,
15735         },
15736         [ALC662_5ST_DIG] = {
15737                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
15738                 .init_verbs = { alc662_init_verbs },
15739                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15740                 .dac_nids = alc662_dac_nids,
15741                 .dig_out_nid = ALC662_DIGOUT_NID,
15742                 .dig_in_nid = ALC662_DIGIN_NID,
15743                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
15744                 .channel_mode = alc662_5stack_modes,
15745                 .input_mux = &alc662_capture_source,
15746         },
15747         [ALC662_LENOVO_101E] = {
15748                 .mixers = { alc662_lenovo_101e_mixer },
15749                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
15750                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15751                 .dac_nids = alc662_dac_nids,
15752                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15753                 .channel_mode = alc662_3ST_2ch_modes,
15754                 .input_mux = &alc662_lenovo_101e_capture_source,
15755                 .unsol_event = alc662_lenovo_101e_unsol_event,
15756                 .init_hook = alc662_lenovo_101e_all_automute,
15757         },
15758         [ALC662_ASUS_EEEPC_P701] = {
15759                 .mixers = { alc662_eeepc_p701_mixer },
15760                 .init_verbs = { alc662_init_verbs,
15761                                 alc662_eeepc_sue_init_verbs },
15762                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15763                 .dac_nids = alc662_dac_nids,
15764                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15765                 .channel_mode = alc662_3ST_2ch_modes,
15766                 .input_mux = &alc662_eeepc_capture_source,
15767                 .unsol_event = alc662_eeepc_unsol_event,
15768                 .init_hook = alc662_eeepc_inithook,
15769         },
15770         [ALC662_ASUS_EEEPC_EP20] = {
15771                 .mixers = { alc662_eeepc_ep20_mixer,
15772                             alc662_chmode_mixer },
15773                 .init_verbs = { alc662_init_verbs,
15774                                 alc662_eeepc_ep20_sue_init_verbs },
15775                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15776                 .dac_nids = alc662_dac_nids,
15777                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15778                 .channel_mode = alc662_3ST_6ch_modes,
15779                 .input_mux = &alc662_lenovo_101e_capture_source,
15780                 .unsol_event = alc662_eeepc_ep20_unsol_event,
15781                 .init_hook = alc662_eeepc_ep20_inithook,
15782         },
15783         [ALC662_ECS] = {
15784                 .mixers = { alc662_ecs_mixer },
15785                 .init_verbs = { alc662_init_verbs,
15786                                 alc662_ecs_init_verbs },
15787                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15788                 .dac_nids = alc662_dac_nids,
15789                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15790                 .channel_mode = alc662_3ST_2ch_modes,
15791                 .input_mux = &alc662_eeepc_capture_source,
15792                 .unsol_event = alc662_eeepc_unsol_event,
15793                 .init_hook = alc662_eeepc_inithook,
15794         },
15795         [ALC663_ASUS_M51VA] = {
15796                 .mixers = { alc663_m51va_mixer },
15797                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
15798                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15799                 .dac_nids = alc662_dac_nids,
15800                 .dig_out_nid = ALC662_DIGOUT_NID,
15801                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15802                 .channel_mode = alc662_3ST_2ch_modes,
15803                 .input_mux = &alc663_m51va_capture_source,
15804                 .unsol_event = alc663_m51va_unsol_event,
15805                 .init_hook = alc663_m51va_inithook,
15806         },
15807         [ALC663_ASUS_G71V] = {
15808                 .mixers = { alc663_g71v_mixer },
15809                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
15810                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15811                 .dac_nids = alc662_dac_nids,
15812                 .dig_out_nid = ALC662_DIGOUT_NID,
15813                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15814                 .channel_mode = alc662_3ST_2ch_modes,
15815                 .input_mux = &alc662_eeepc_capture_source,
15816                 .unsol_event = alc663_g71v_unsol_event,
15817                 .init_hook = alc663_g71v_inithook,
15818         },
15819         [ALC663_ASUS_H13] = {
15820                 .mixers = { alc663_m51va_mixer },
15821                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
15822                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15823                 .dac_nids = alc662_dac_nids,
15824                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15825                 .channel_mode = alc662_3ST_2ch_modes,
15826                 .input_mux = &alc663_m51va_capture_source,
15827                 .unsol_event = alc663_m51va_unsol_event,
15828                 .init_hook = alc663_m51va_inithook,
15829         },
15830         [ALC663_ASUS_G50V] = {
15831                 .mixers = { alc663_g50v_mixer },
15832                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
15833                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15834                 .dac_nids = alc662_dac_nids,
15835                 .dig_out_nid = ALC662_DIGOUT_NID,
15836                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15837                 .channel_mode = alc662_3ST_6ch_modes,
15838                 .input_mux = &alc663_capture_source,
15839                 .unsol_event = alc663_g50v_unsol_event,
15840                 .init_hook = alc663_g50v_inithook,
15841         },
15842         [ALC663_ASUS_MODE1] = {
15843                 .mixers = { alc663_m51va_mixer },
15844                 .cap_mixer = alc662_auto_capture_mixer,
15845                 .init_verbs = { alc662_init_verbs,
15846                                 alc663_21jd_amic_init_verbs },
15847                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15848                 .hp_nid = 0x03,
15849                 .dac_nids = alc662_dac_nids,
15850                 .dig_out_nid = ALC662_DIGOUT_NID,
15851                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15852                 .channel_mode = alc662_3ST_2ch_modes,
15853                 .input_mux = &alc662_eeepc_capture_source,
15854                 .unsol_event = alc663_mode1_unsol_event,
15855                 .init_hook = alc663_mode1_inithook,
15856         },
15857         [ALC662_ASUS_MODE2] = {
15858                 .mixers = { alc662_1bjd_mixer },
15859                 .cap_mixer = alc662_auto_capture_mixer,
15860                 .init_verbs = { alc662_init_verbs,
15861                                 alc662_1bjd_amic_init_verbs },
15862                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15863                 .dac_nids = alc662_dac_nids,
15864                 .dig_out_nid = ALC662_DIGOUT_NID,
15865                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15866                 .channel_mode = alc662_3ST_2ch_modes,
15867                 .input_mux = &alc662_eeepc_capture_source,
15868                 .unsol_event = alc662_mode2_unsol_event,
15869                 .init_hook = alc662_mode2_inithook,
15870         },
15871         [ALC663_ASUS_MODE3] = {
15872                 .mixers = { alc663_two_hp_m1_mixer },
15873                 .cap_mixer = alc662_auto_capture_mixer,
15874                 .init_verbs = { alc662_init_verbs,
15875                                 alc663_two_hp_amic_m1_init_verbs },
15876                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15877                 .hp_nid = 0x03,
15878                 .dac_nids = alc662_dac_nids,
15879                 .dig_out_nid = ALC662_DIGOUT_NID,
15880                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15881                 .channel_mode = alc662_3ST_2ch_modes,
15882                 .input_mux = &alc662_eeepc_capture_source,
15883                 .unsol_event = alc663_mode3_unsol_event,
15884                 .init_hook = alc663_mode3_inithook,
15885         },
15886         [ALC663_ASUS_MODE4] = {
15887                 .mixers = { alc663_asus_21jd_clfe_mixer },
15888                 .cap_mixer = alc662_auto_capture_mixer,
15889                 .init_verbs = { alc662_init_verbs,
15890                                 alc663_21jd_amic_init_verbs},
15891                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15892                 .hp_nid = 0x03,
15893                 .dac_nids = alc662_dac_nids,
15894                 .dig_out_nid = ALC662_DIGOUT_NID,
15895                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15896                 .channel_mode = alc662_3ST_2ch_modes,
15897                 .input_mux = &alc662_eeepc_capture_source,
15898                 .unsol_event = alc663_mode4_unsol_event,
15899                 .init_hook = alc663_mode4_inithook,
15900         },
15901         [ALC663_ASUS_MODE5] = {
15902                 .mixers = { alc663_asus_15jd_clfe_mixer },
15903                 .cap_mixer = alc662_auto_capture_mixer,
15904                 .init_verbs = { alc662_init_verbs,
15905                                 alc663_15jd_amic_init_verbs },
15906                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15907                 .hp_nid = 0x03,
15908                 .dac_nids = alc662_dac_nids,
15909                 .dig_out_nid = ALC662_DIGOUT_NID,
15910                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15911                 .channel_mode = alc662_3ST_2ch_modes,
15912                 .input_mux = &alc662_eeepc_capture_source,
15913                 .unsol_event = alc663_mode5_unsol_event,
15914                 .init_hook = alc663_mode5_inithook,
15915         },
15916         [ALC663_ASUS_MODE6] = {
15917                 .mixers = { alc663_two_hp_m2_mixer },
15918                 .cap_mixer = alc662_auto_capture_mixer,
15919                 .init_verbs = { alc662_init_verbs,
15920                                 alc663_two_hp_amic_m2_init_verbs },
15921                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15922                 .hp_nid = 0x03,
15923                 .dac_nids = alc662_dac_nids,
15924                 .dig_out_nid = ALC662_DIGOUT_NID,
15925                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15926                 .channel_mode = alc662_3ST_2ch_modes,
15927                 .input_mux = &alc662_eeepc_capture_source,
15928                 .unsol_event = alc663_mode6_unsol_event,
15929                 .init_hook = alc663_mode6_inithook,
15930         },
15931 };
15932
15933
15934 /*
15935  * BIOS auto configuration
15936  */
15937
15938 /* add playback controls from the parsed DAC table */
15939 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
15940                                              const struct auto_pin_cfg *cfg)
15941 {
15942         char name[32];
15943         static const char *chname[4] = {
15944                 "Front", "Surround", NULL /*CLFE*/, "Side"
15945         };
15946         hda_nid_t nid;
15947         int i, err;
15948
15949         for (i = 0; i < cfg->line_outs; i++) {
15950                 if (!spec->multiout.dac_nids[i])
15951                         continue;
15952                 nid = alc880_idx_to_dac(i);
15953                 if (i == 2) {
15954                         /* Center/LFE */
15955                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
15956                                           "Center Playback Volume",
15957                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
15958                                                               HDA_OUTPUT));
15959                         if (err < 0)
15960                                 return err;
15961                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
15962                                           "LFE Playback Volume",
15963                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
15964                                                               HDA_OUTPUT));
15965                         if (err < 0)
15966                                 return err;
15967                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
15968                                           "Center Playback Switch",
15969                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
15970                                                               HDA_INPUT));
15971                         if (err < 0)
15972                                 return err;
15973                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
15974                                           "LFE Playback Switch",
15975                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
15976                                                               HDA_INPUT));
15977                         if (err < 0)
15978                                 return err;
15979                 } else {
15980                         sprintf(name, "%s Playback Volume", chname[i]);
15981                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15982                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
15983                                                               HDA_OUTPUT));
15984                         if (err < 0)
15985                                 return err;
15986                         sprintf(name, "%s Playback Switch", chname[i]);
15987                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
15988                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
15989                                                     3, 0, HDA_INPUT));
15990                         if (err < 0)
15991                                 return err;
15992                 }
15993         }
15994         return 0;
15995 }
15996
15997 /* add playback controls for speaker and HP outputs */
15998 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
15999                                         const char *pfx)
16000 {
16001         hda_nid_t nid;
16002         int err;
16003         char name[32];
16004
16005         if (!pin)
16006                 return 0;
16007
16008         if (pin == 0x17) {
16009                 /* ALC663 has a mono output pin on 0x17 */
16010                 sprintf(name, "%s Playback Switch", pfx);
16011                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16012                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16013                 return err;
16014         }
16015
16016         if (alc880_is_fixed_pin(pin)) {
16017                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16018                 /* printk("DAC nid=%x\n",nid); */
16019                 /* specify the DAC as the extra output */
16020                 if (!spec->multiout.hp_nid)
16021                         spec->multiout.hp_nid = nid;
16022                 else
16023                         spec->multiout.extra_out_nid[0] = nid;
16024                 /* control HP volume/switch on the output mixer amp */
16025                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16026                 sprintf(name, "%s Playback Volume", pfx);
16027                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16028                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16029                 if (err < 0)
16030                         return err;
16031                 sprintf(name, "%s Playback Switch", pfx);
16032                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16033                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16034                 if (err < 0)
16035                         return err;
16036         } else if (alc880_is_multi_pin(pin)) {
16037                 /* set manual connection */
16038                 /* we have only a switch on HP-out PIN */
16039                 sprintf(name, "%s Playback Switch", pfx);
16040                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16041                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16042                 if (err < 0)
16043                         return err;
16044         }
16045         return 0;
16046 }
16047
16048 /* create playback/capture controls for input pins */
16049 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
16050                                                 const struct auto_pin_cfg *cfg)
16051 {
16052         struct hda_input_mux *imux = &spec->private_imux;
16053         int i, err, idx;
16054
16055         for (i = 0; i < AUTO_PIN_LAST; i++) {
16056                 if (alc880_is_input_pin(cfg->input_pins[i])) {
16057                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
16058                         err = new_analog_input(spec, cfg->input_pins[i],
16059                                                auto_pin_cfg_labels[i],
16060                                                idx, 0x0b);
16061                         if (err < 0)
16062                                 return err;
16063                         imux->items[imux->num_items].label =
16064                                 auto_pin_cfg_labels[i];
16065                         imux->items[imux->num_items].index =
16066                                 alc880_input_pin_idx(cfg->input_pins[i]);
16067                         imux->num_items++;
16068                 }
16069         }
16070         return 0;
16071 }
16072
16073 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16074                                               hda_nid_t nid, int pin_type,
16075                                               int dac_idx)
16076 {
16077         alc_set_pin_output(codec, nid, pin_type);
16078         /* need the manual connection? */
16079         if (alc880_is_multi_pin(nid)) {
16080                 struct alc_spec *spec = codec->spec;
16081                 int idx = alc880_multi_pin_idx(nid);
16082                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16083                                     AC_VERB_SET_CONNECT_SEL,
16084                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16085         }
16086 }
16087
16088 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16089 {
16090         struct alc_spec *spec = codec->spec;
16091         int i;
16092
16093         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16094         for (i = 0; i <= HDA_SIDE; i++) {
16095                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16096                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16097                 if (nid)
16098                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16099                                                           i);
16100         }
16101 }
16102
16103 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16104 {
16105         struct alc_spec *spec = codec->spec;
16106         hda_nid_t pin;
16107
16108         pin = spec->autocfg.hp_pins[0];
16109         if (pin) /* connect to front */
16110                 /* use dac 0 */
16111                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16112         pin = spec->autocfg.speaker_pins[0];
16113         if (pin)
16114                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16115 }
16116
16117 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
16118 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16119
16120 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16121 {
16122         struct alc_spec *spec = codec->spec;
16123         int i;
16124
16125         for (i = 0; i < AUTO_PIN_LAST; i++) {
16126                 hda_nid_t nid = spec->autocfg.input_pins[i];
16127                 if (alc662_is_input_pin(nid)) {
16128                         snd_hda_codec_write(codec, nid, 0,
16129                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
16130                                             (i <= AUTO_PIN_FRONT_MIC ?
16131                                              PIN_VREF80 : PIN_IN));
16132                         if (nid != ALC662_PIN_CD_NID)
16133                                 snd_hda_codec_write(codec, nid, 0,
16134                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16135                                                     AMP_OUT_MUTE);
16136                 }
16137         }
16138 }
16139
16140 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16141
16142 static int alc662_parse_auto_config(struct hda_codec *codec)
16143 {
16144         struct alc_spec *spec = codec->spec;
16145         int err;
16146         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16147
16148         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16149                                            alc662_ignore);
16150         if (err < 0)
16151                 return err;
16152         if (!spec->autocfg.line_outs)
16153                 return 0; /* can't find valid BIOS pin config */
16154
16155         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16156         if (err < 0)
16157                 return err;
16158         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16159         if (err < 0)
16160                 return err;
16161         err = alc662_auto_create_extra_out(spec,
16162                                            spec->autocfg.speaker_pins[0],
16163                                            "Speaker");
16164         if (err < 0)
16165                 return err;
16166         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
16167                                            "Headphone");
16168         if (err < 0)
16169                 return err;
16170         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
16171         if (err < 0)
16172                 return err;
16173
16174         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16175
16176         if (spec->autocfg.dig_out_pin)
16177                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16178
16179         if (spec->kctls.list)
16180                 add_mixer(spec, spec->kctls.list);
16181
16182         spec->num_mux_defs = 1;
16183         spec->input_mux = &spec->private_imux;
16184
16185         add_verb(spec, alc662_auto_init_verbs);
16186         if (codec->vendor_id == 0x10ec0663)
16187                 add_verb(spec, alc663_auto_init_verbs);
16188
16189         err = alc_auto_add_mic_boost(codec);
16190         if (err < 0)
16191                 return err;
16192
16193         store_pin_configs(codec);
16194         return 1;
16195 }
16196
16197 /* additional initialization for auto-configuration model */
16198 static void alc662_auto_init(struct hda_codec *codec)
16199 {
16200         struct alc_spec *spec = codec->spec;
16201         alc662_auto_init_multi_out(codec);
16202         alc662_auto_init_hp_out(codec);
16203         alc662_auto_init_analog_input(codec);
16204         alc662_auto_init_input_src(codec);
16205         if (spec->unsol_event)
16206                 alc_inithook(codec);
16207 }
16208
16209 static int patch_alc662(struct hda_codec *codec)
16210 {
16211         struct alc_spec *spec;
16212         int err, board_config;
16213
16214         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16215         if (!spec)
16216                 return -ENOMEM;
16217
16218         codec->spec = spec;
16219
16220         alc_fix_pll_init(codec, 0x20, 0x04, 15);
16221
16222         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
16223                                                   alc662_models,
16224                                                   alc662_cfg_tbl);
16225         if (board_config < 0) {
16226                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
16227                        "trying auto-probe from BIOS...\n");
16228                 board_config = ALC662_AUTO;
16229         }
16230
16231         if (board_config == ALC662_AUTO) {
16232                 /* automatic parse from the BIOS config */
16233                 err = alc662_parse_auto_config(codec);
16234                 if (err < 0) {
16235                         alc_free(codec);
16236                         return err;
16237                 } else if (!err) {
16238                         printk(KERN_INFO
16239                                "hda_codec: Cannot set up configuration "
16240                                "from BIOS.  Using base mode...\n");
16241                         board_config = ALC662_3ST_2ch_DIG;
16242                 }
16243         }
16244
16245         if (board_config != ALC662_AUTO)
16246                 setup_preset(spec, &alc662_presets[board_config]);
16247
16248         if (codec->vendor_id == 0x10ec0663) {
16249                 spec->stream_name_analog = "ALC663 Analog";
16250                 spec->stream_name_digital = "ALC663 Digital";
16251         } else if (codec->vendor_id == 0x10ec0272) {
16252                 spec->stream_name_analog = "ALC272 Analog";
16253                 spec->stream_name_digital = "ALC272 Digital";
16254         } else {
16255                 spec->stream_name_analog = "ALC662 Analog";
16256                 spec->stream_name_digital = "ALC662 Digital";
16257         }
16258
16259         spec->stream_analog_playback = &alc662_pcm_analog_playback;
16260         spec->stream_analog_capture = &alc662_pcm_analog_capture;
16261
16262         spec->stream_digital_playback = &alc662_pcm_digital_playback;
16263         spec->stream_digital_capture = &alc662_pcm_digital_capture;
16264
16265         spec->adc_nids = alc662_adc_nids;
16266         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16267         spec->capsrc_nids = alc662_capsrc_nids;
16268         spec->is_mix_capture = 1;
16269
16270         if (!spec->cap_mixer)
16271                 set_capture_mixer(spec);
16272
16273         spec->vmaster_nid = 0x02;
16274
16275         codec->patch_ops = alc_patch_ops;
16276         if (board_config == ALC662_AUTO)
16277                 spec->init_hook = alc662_auto_init;
16278 #ifdef CONFIG_SND_HDA_POWER_SAVE
16279         if (!spec->loopback.amplist)
16280                 spec->loopback.amplist = alc662_loopbacks;
16281 #endif
16282
16283         return 0;
16284 }
16285
16286 /*
16287  * patch entries
16288  */
16289 struct hda_codec_preset snd_hda_preset_realtek[] = {
16290         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16291         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16292         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
16293         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
16294         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
16295         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
16296         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
16297           .patch = patch_alc861 },
16298         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
16299         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
16300         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
16301         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
16302           .patch = patch_alc883 },
16303         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
16304           .patch = patch_alc662 },
16305         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
16306         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
16307         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
16308         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16309         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
16310           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16311         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
16312           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16313         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
16314         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
16315         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
16316         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
16317           .patch = patch_alc883 },
16318         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16319         {} /* terminator */
16320 };