ALSA: hda - Unify capture mixer creation in realtek codes
[pandora-kernel.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_ASPIRE_ONE,
118         ALC268_DELL,
119         ALC268_ZEPTO,
120 #ifdef CONFIG_SND_DEBUG
121         ALC268_TEST,
122 #endif
123         ALC268_AUTO,
124         ALC268_MODEL_LAST /* last tag */
125 };
126
127 /* ALC269 models */
128 enum {
129         ALC269_BASIC,
130         ALC269_QUANTA_FL1,
131         ALC269_ASUS_EEEPC_P703,
132         ALC269_ASUS_EEEPC_P901,
133         ALC269_AUTO,
134         ALC269_MODEL_LAST /* last tag */
135 };
136
137 /* ALC861 models */
138 enum {
139         ALC861_3ST,
140         ALC660_3ST,
141         ALC861_3ST_DIG,
142         ALC861_6ST_DIG,
143         ALC861_UNIWILL_M31,
144         ALC861_TOSHIBA,
145         ALC861_ASUS,
146         ALC861_ASUS_LAPTOP,
147         ALC861_AUTO,
148         ALC861_MODEL_LAST,
149 };
150
151 /* ALC861-VD models */
152 enum {
153         ALC660VD_3ST,
154         ALC660VD_3ST_DIG,
155         ALC861VD_3ST,
156         ALC861VD_3ST_DIG,
157         ALC861VD_6ST_DIG,
158         ALC861VD_LENOVO,
159         ALC861VD_DALLAS,
160         ALC861VD_HP,
161         ALC861VD_AUTO,
162         ALC861VD_MODEL_LAST,
163 };
164
165 /* ALC662 models */
166 enum {
167         ALC662_3ST_2ch_DIG,
168         ALC662_3ST_6ch_DIG,
169         ALC662_3ST_6ch,
170         ALC662_5ST_DIG,
171         ALC662_LENOVO_101E,
172         ALC662_ASUS_EEEPC_P701,
173         ALC662_ASUS_EEEPC_EP20,
174         ALC663_ASUS_M51VA,
175         ALC663_ASUS_G71V,
176         ALC663_ASUS_H13,
177         ALC663_ASUS_G50V,
178         ALC662_ECS,
179         ALC663_ASUS_MODE1,
180         ALC662_ASUS_MODE2,
181         ALC663_ASUS_MODE3,
182         ALC663_ASUS_MODE4,
183         ALC663_ASUS_MODE5,
184         ALC663_ASUS_MODE6,
185         ALC662_AUTO,
186         ALC662_MODEL_LAST,
187 };
188
189 /* ALC882 models */
190 enum {
191         ALC882_3ST_DIG,
192         ALC882_6ST_DIG,
193         ALC882_ARIMA,
194         ALC882_W2JC,
195         ALC882_TARGA,
196         ALC882_ASUS_A7J,
197         ALC882_ASUS_A7M,
198         ALC885_MACPRO,
199         ALC885_MBP3,
200         ALC885_IMAC24,
201         ALC882_AUTO,
202         ALC882_MODEL_LAST,
203 };
204
205 /* ALC883 models */
206 enum {
207         ALC883_3ST_2ch_DIG,
208         ALC883_3ST_6ch_DIG,
209         ALC883_3ST_6ch,
210         ALC883_6ST_DIG,
211         ALC883_TARGA_DIG,
212         ALC883_TARGA_2ch_DIG,
213         ALC883_ACER,
214         ALC883_ACER_ASPIRE,
215         ALC883_MEDION,
216         ALC883_MEDION_MD2,
217         ALC883_LAPTOP_EAPD,
218         ALC883_LENOVO_101E_2ch,
219         ALC883_LENOVO_NB0763,
220         ALC888_LENOVO_MS7195_DIG,
221         ALC888_LENOVO_SKY,
222         ALC883_HAIER_W66,
223         ALC888_3ST_HP,
224         ALC888_6ST_DELL,
225         ALC883_MITAC,
226         ALC883_CLEVO_M720,
227         ALC883_FUJITSU_PI2515,
228         ALC883_3ST_6ch_INTEL,
229         ALC888_ASUS_M90V,
230         ALC888_ASUS_EEE1601,
231         ALC883_AUTO,
232         ALC883_MODEL_LAST,
233 };
234
235 /* for GPIO Poll */
236 #define GPIO_MASK       0x03
237
238 struct alc_spec {
239         /* codec parameterization */
240         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
241         unsigned int num_mixers;
242         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
243
244         const struct hda_verb *init_verbs[5];   /* initialization verbs
245                                                  * don't forget NULL
246                                                  * termination!
247                                                  */
248         unsigned int num_init_verbs;
249
250         char *stream_name_analog;       /* analog PCM stream */
251         struct hda_pcm_stream *stream_analog_playback;
252         struct hda_pcm_stream *stream_analog_capture;
253         struct hda_pcm_stream *stream_analog_alt_playback;
254         struct hda_pcm_stream *stream_analog_alt_capture;
255
256         char *stream_name_digital;      /* digital PCM stream */
257         struct hda_pcm_stream *stream_digital_playback;
258         struct hda_pcm_stream *stream_digital_capture;
259
260         /* playback */
261         struct hda_multi_out multiout;  /* playback set-up
262                                          * max_channels, dacs must be set
263                                          * dig_out_nid and hp_nid are optional
264                                          */
265         hda_nid_t alt_dac_nid;
266
267         /* capture */
268         unsigned int num_adc_nids;
269         hda_nid_t *adc_nids;
270         hda_nid_t *capsrc_nids;
271         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
272         unsigned char is_mix_capture;   /* matrix-style capture (non-mux) */
273
274         /* capture source */
275         unsigned int num_mux_defs;
276         const struct hda_input_mux *input_mux;
277         unsigned int cur_mux[3];
278
279         /* channel model */
280         const struct hda_channel_mode *channel_mode;
281         int num_channel_mode;
282         int need_dac_fix;
283
284         /* PCM information */
285         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
286
287         /* dynamic controls, init_verbs and input_mux */
288         struct auto_pin_cfg autocfg;
289         struct snd_array kctls;
290         struct hda_input_mux private_imux;
291         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
292
293         /* hooks */
294         void (*init_hook)(struct hda_codec *codec);
295         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
296
297         /* for pin sensing */
298         unsigned int sense_updated: 1;
299         unsigned int jack_present: 1;
300         unsigned int master_sw: 1;
301
302         /* for virtual master */
303         hda_nid_t vmaster_nid;
304 #ifdef CONFIG_SND_HDA_POWER_SAVE
305         struct hda_loopback_check loopback;
306 #endif
307
308         /* for PLL fix */
309         hda_nid_t pll_nid;
310         unsigned int pll_coef_idx, pll_coef_bit;
311
312 #ifdef SND_HDA_NEEDS_RESUME
313 #define ALC_MAX_PINS    16
314         unsigned int num_pins;
315         hda_nid_t pin_nids[ALC_MAX_PINS];
316         unsigned int pin_cfgs[ALC_MAX_PINS];
317 #endif
318 };
319
320 /*
321  * configuration template - to be copied to the spec instance
322  */
323 struct alc_config_preset {
324         struct snd_kcontrol_new *mixers[5]; /* should be identical size
325                                              * with spec
326                                              */
327         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
328         const struct hda_verb *init_verbs[5];
329         unsigned int num_dacs;
330         hda_nid_t *dac_nids;
331         hda_nid_t dig_out_nid;          /* optional */
332         hda_nid_t hp_nid;               /* optional */
333         unsigned int num_adc_nids;
334         hda_nid_t *adc_nids;
335         hda_nid_t *capsrc_nids;
336         hda_nid_t dig_in_nid;
337         unsigned int num_channel_mode;
338         const struct hda_channel_mode *channel_mode;
339         int need_dac_fix;
340         unsigned int num_mux_defs;
341         const struct hda_input_mux *input_mux;
342         void (*unsol_event)(struct hda_codec *, unsigned int);
343         void (*init_hook)(struct hda_codec *);
344 #ifdef CONFIG_SND_HDA_POWER_SAVE
345         struct hda_amp_list *loopbacks;
346 #endif
347 };
348
349
350 /*
351  * input MUX handling
352  */
353 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
354                              struct snd_ctl_elem_info *uinfo)
355 {
356         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
357         struct alc_spec *spec = codec->spec;
358         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
359         if (mux_idx >= spec->num_mux_defs)
360                 mux_idx = 0;
361         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
362 }
363
364 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
365                             struct snd_ctl_elem_value *ucontrol)
366 {
367         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
368         struct alc_spec *spec = codec->spec;
369         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
370
371         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
372         return 0;
373 }
374
375 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
376                             struct snd_ctl_elem_value *ucontrol)
377 {
378         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
379         struct alc_spec *spec = codec->spec;
380         const struct hda_input_mux *imux = spec->input_mux;
381         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
382         hda_nid_t nid = spec->capsrc_nids ?
383                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
384
385         if (spec->is_mix_capture) {
386                 /* Matrix-mixer style (e.g. ALC882) */
387                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
388                 unsigned int i, idx;
389
390                 idx = ucontrol->value.enumerated.item[0];
391                 if (idx >= imux->num_items)
392                         idx = imux->num_items - 1;
393                 if (*cur_val == idx)
394                         return 0;
395                 for (i = 0; i < imux->num_items; i++) {
396                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
397                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
398                                                  imux->items[i].index,
399                                                  HDA_AMP_MUTE, v);
400                 }
401                 *cur_val = idx;
402                 return 1;
403         } else {
404                 /* MUX style (e.g. ALC880) */
405                 unsigned int mux_idx;
406                 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
407                 return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx],
408                                              ucontrol, nid,
409                                              &spec->cur_mux[adc_idx]);
410         }
411 }
412
413 /*
414  * channel mode setting
415  */
416 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
417                             struct snd_ctl_elem_info *uinfo)
418 {
419         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
420         struct alc_spec *spec = codec->spec;
421         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
422                                     spec->num_channel_mode);
423 }
424
425 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
426                            struct snd_ctl_elem_value *ucontrol)
427 {
428         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
429         struct alc_spec *spec = codec->spec;
430         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
431                                    spec->num_channel_mode,
432                                    spec->multiout.max_channels);
433 }
434
435 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
436                            struct snd_ctl_elem_value *ucontrol)
437 {
438         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
439         struct alc_spec *spec = codec->spec;
440         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
441                                       spec->num_channel_mode,
442                                       &spec->multiout.max_channels);
443         if (err >= 0 && spec->need_dac_fix)
444                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
445         return err;
446 }
447
448 /*
449  * Control the mode of pin widget settings via the mixer.  "pc" is used
450  * instead of "%" to avoid consequences of accidently treating the % as
451  * being part of a format specifier.  Maximum allowed length of a value is
452  * 63 characters plus NULL terminator.
453  *
454  * Note: some retasking pin complexes seem to ignore requests for input
455  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
456  * are requested.  Therefore order this list so that this behaviour will not
457  * cause problems when mixer clients move through the enum sequentially.
458  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
459  * March 2006.
460  */
461 static char *alc_pin_mode_names[] = {
462         "Mic 50pc bias", "Mic 80pc bias",
463         "Line in", "Line out", "Headphone out",
464 };
465 static unsigned char alc_pin_mode_values[] = {
466         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
467 };
468 /* The control can present all 5 options, or it can limit the options based
469  * in the pin being assumed to be exclusively an input or an output pin.  In
470  * addition, "input" pins may or may not process the mic bias option
471  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
472  * accept requests for bias as of chip versions up to March 2006) and/or
473  * wiring in the computer.
474  */
475 #define ALC_PIN_DIR_IN              0x00
476 #define ALC_PIN_DIR_OUT             0x01
477 #define ALC_PIN_DIR_INOUT           0x02
478 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
479 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
480
481 /* Info about the pin modes supported by the different pin direction modes.
482  * For each direction the minimum and maximum values are given.
483  */
484 static signed char alc_pin_mode_dir_info[5][2] = {
485         { 0, 2 },    /* ALC_PIN_DIR_IN */
486         { 3, 4 },    /* ALC_PIN_DIR_OUT */
487         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
488         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
489         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
490 };
491 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
492 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
493 #define alc_pin_mode_n_items(_dir) \
494         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
495
496 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
497                              struct snd_ctl_elem_info *uinfo)
498 {
499         unsigned int item_num = uinfo->value.enumerated.item;
500         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
501
502         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
503         uinfo->count = 1;
504         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
505
506         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
507                 item_num = alc_pin_mode_min(dir);
508         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
509         return 0;
510 }
511
512 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
513                             struct snd_ctl_elem_value *ucontrol)
514 {
515         unsigned int i;
516         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
517         hda_nid_t nid = kcontrol->private_value & 0xffff;
518         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
519         long *valp = ucontrol->value.integer.value;
520         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
521                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
522                                                  0x00);
523
524         /* Find enumerated value for current pinctl setting */
525         i = alc_pin_mode_min(dir);
526         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
527                 i++;
528         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
529         return 0;
530 }
531
532 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
533                             struct snd_ctl_elem_value *ucontrol)
534 {
535         signed int change;
536         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
537         hda_nid_t nid = kcontrol->private_value & 0xffff;
538         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
539         long val = *ucontrol->value.integer.value;
540         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
541                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
542                                                  0x00);
543
544         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
545                 val = alc_pin_mode_min(dir);
546
547         change = pinctl != alc_pin_mode_values[val];
548         if (change) {
549                 /* Set pin mode to that requested */
550                 snd_hda_codec_write_cache(codec, nid, 0,
551                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
552                                           alc_pin_mode_values[val]);
553
554                 /* Also enable the retasking pin's input/output as required
555                  * for the requested pin mode.  Enum values of 2 or less are
556                  * input modes.
557                  *
558                  * Dynamically switching the input/output buffers probably
559                  * reduces noise slightly (particularly on input) so we'll
560                  * do it.  However, having both input and output buffers
561                  * enabled simultaneously doesn't seem to be problematic if
562                  * this turns out to be necessary in the future.
563                  */
564                 if (val <= 2) {
565                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
566                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
567                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
568                                                  HDA_AMP_MUTE, 0);
569                 } else {
570                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
571                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
572                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
573                                                  HDA_AMP_MUTE, 0);
574                 }
575         }
576         return change;
577 }
578
579 #define ALC_PIN_MODE(xname, nid, dir) \
580         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
581           .info = alc_pin_mode_info, \
582           .get = alc_pin_mode_get, \
583           .put = alc_pin_mode_put, \
584           .private_value = nid | (dir<<16) }
585
586 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
587  * together using a mask with more than one bit set.  This control is
588  * currently used only by the ALC260 test model.  At this stage they are not
589  * needed for any "production" models.
590  */
591 #ifdef CONFIG_SND_DEBUG
592 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
593
594 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
595                              struct snd_ctl_elem_value *ucontrol)
596 {
597         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
598         hda_nid_t nid = kcontrol->private_value & 0xffff;
599         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
600         long *valp = ucontrol->value.integer.value;
601         unsigned int val = snd_hda_codec_read(codec, nid, 0,
602                                               AC_VERB_GET_GPIO_DATA, 0x00);
603
604         *valp = (val & mask) != 0;
605         return 0;
606 }
607 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
608                              struct snd_ctl_elem_value *ucontrol)
609 {
610         signed int change;
611         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
612         hda_nid_t nid = kcontrol->private_value & 0xffff;
613         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
614         long val = *ucontrol->value.integer.value;
615         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
616                                                     AC_VERB_GET_GPIO_DATA,
617                                                     0x00);
618
619         /* Set/unset the masked GPIO bit(s) as needed */
620         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
621         if (val == 0)
622                 gpio_data &= ~mask;
623         else
624                 gpio_data |= mask;
625         snd_hda_codec_write_cache(codec, nid, 0,
626                                   AC_VERB_SET_GPIO_DATA, gpio_data);
627
628         return change;
629 }
630 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
631         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
632           .info = alc_gpio_data_info, \
633           .get = alc_gpio_data_get, \
634           .put = alc_gpio_data_put, \
635           .private_value = nid | (mask<<16) }
636 #endif   /* CONFIG_SND_DEBUG */
637
638 /* A switch control to allow the enabling of the digital IO pins on the
639  * ALC260.  This is incredibly simplistic; the intention of this control is
640  * to provide something in the test model allowing digital outputs to be
641  * identified if present.  If models are found which can utilise these
642  * outputs a more complete mixer control can be devised for those models if
643  * necessary.
644  */
645 #ifdef CONFIG_SND_DEBUG
646 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
647
648 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
649                               struct snd_ctl_elem_value *ucontrol)
650 {
651         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652         hda_nid_t nid = kcontrol->private_value & 0xffff;
653         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
654         long *valp = ucontrol->value.integer.value;
655         unsigned int val = snd_hda_codec_read(codec, nid, 0,
656                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
657
658         *valp = (val & mask) != 0;
659         return 0;
660 }
661 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
662                               struct snd_ctl_elem_value *ucontrol)
663 {
664         signed int change;
665         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
666         hda_nid_t nid = kcontrol->private_value & 0xffff;
667         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
668         long val = *ucontrol->value.integer.value;
669         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
670                                                     AC_VERB_GET_DIGI_CONVERT_1,
671                                                     0x00);
672
673         /* Set/unset the masked control bit(s) as needed */
674         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
675         if (val==0)
676                 ctrl_data &= ~mask;
677         else
678                 ctrl_data |= mask;
679         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
680                                   ctrl_data);
681
682         return change;
683 }
684 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
685         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
686           .info = alc_spdif_ctrl_info, \
687           .get = alc_spdif_ctrl_get, \
688           .put = alc_spdif_ctrl_put, \
689           .private_value = nid | (mask<<16) }
690 #endif   /* CONFIG_SND_DEBUG */
691
692 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
693  * Again, this is only used in the ALC26x test models to help identify when
694  * the EAPD line must be asserted for features to work.
695  */
696 #ifdef CONFIG_SND_DEBUG
697 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
698
699 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
700                               struct snd_ctl_elem_value *ucontrol)
701 {
702         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
703         hda_nid_t nid = kcontrol->private_value & 0xffff;
704         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
705         long *valp = ucontrol->value.integer.value;
706         unsigned int val = snd_hda_codec_read(codec, nid, 0,
707                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
708
709         *valp = (val & mask) != 0;
710         return 0;
711 }
712
713 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
714                               struct snd_ctl_elem_value *ucontrol)
715 {
716         int change;
717         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
718         hda_nid_t nid = kcontrol->private_value & 0xffff;
719         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
720         long val = *ucontrol->value.integer.value;
721         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
722                                                     AC_VERB_GET_EAPD_BTLENABLE,
723                                                     0x00);
724
725         /* Set/unset the masked control bit(s) as needed */
726         change = (!val ? 0 : mask) != (ctrl_data & mask);
727         if (!val)
728                 ctrl_data &= ~mask;
729         else
730                 ctrl_data |= mask;
731         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
732                                   ctrl_data);
733
734         return change;
735 }
736
737 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
738         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
739           .info = alc_eapd_ctrl_info, \
740           .get = alc_eapd_ctrl_get, \
741           .put = alc_eapd_ctrl_put, \
742           .private_value = nid | (mask<<16) }
743 #endif   /* CONFIG_SND_DEBUG */
744
745 /*
746  */
747 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
748 {
749         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
750                 return;
751         spec->mixers[spec->num_mixers++] = mix;
752 }
753
754 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
755 {
756         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
757                 return;
758         spec->init_verbs[spec->num_init_verbs++] = verb;
759 }
760
761 /*
762  * set up from the preset table
763  */
764 static void setup_preset(struct alc_spec *spec,
765                          const struct alc_config_preset *preset)
766 {
767         int i;
768
769         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
770                 add_mixer(spec, preset->mixers[i]);
771         spec->cap_mixer = preset->cap_mixer;
772         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
773              i++)
774                 add_verb(spec, preset->init_verbs[i]);
775
776         spec->channel_mode = preset->channel_mode;
777         spec->num_channel_mode = preset->num_channel_mode;
778         spec->need_dac_fix = preset->need_dac_fix;
779
780         spec->multiout.max_channels = spec->channel_mode[0].channels;
781
782         spec->multiout.num_dacs = preset->num_dacs;
783         spec->multiout.dac_nids = preset->dac_nids;
784         spec->multiout.dig_out_nid = preset->dig_out_nid;
785         spec->multiout.hp_nid = preset->hp_nid;
786
787         spec->num_mux_defs = preset->num_mux_defs;
788         if (!spec->num_mux_defs)
789                 spec->num_mux_defs = 1;
790         spec->input_mux = preset->input_mux;
791
792         spec->num_adc_nids = preset->num_adc_nids;
793         spec->adc_nids = preset->adc_nids;
794         spec->capsrc_nids = preset->capsrc_nids;
795         spec->dig_in_nid = preset->dig_in_nid;
796
797         spec->unsol_event = preset->unsol_event;
798         spec->init_hook = preset->init_hook;
799 #ifdef CONFIG_SND_HDA_POWER_SAVE
800         spec->loopback.amplist = preset->loopbacks;
801 #endif
802 }
803
804 /* Enable GPIO mask and set output */
805 static struct hda_verb alc_gpio1_init_verbs[] = {
806         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
807         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
808         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
809         { }
810 };
811
812 static struct hda_verb alc_gpio2_init_verbs[] = {
813         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
814         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
815         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
816         { }
817 };
818
819 static struct hda_verb alc_gpio3_init_verbs[] = {
820         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
821         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
822         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
823         { }
824 };
825
826 /*
827  * Fix hardware PLL issue
828  * On some codecs, the analog PLL gating control must be off while
829  * the default value is 1.
830  */
831 static void alc_fix_pll(struct hda_codec *codec)
832 {
833         struct alc_spec *spec = codec->spec;
834         unsigned int val;
835
836         if (!spec->pll_nid)
837                 return;
838         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
839                             spec->pll_coef_idx);
840         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
841                                  AC_VERB_GET_PROC_COEF, 0);
842         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
843                             spec->pll_coef_idx);
844         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
845                             val & ~(1 << spec->pll_coef_bit));
846 }
847
848 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
849                              unsigned int coef_idx, unsigned int coef_bit)
850 {
851         struct alc_spec *spec = codec->spec;
852         spec->pll_nid = nid;
853         spec->pll_coef_idx = coef_idx;
854         spec->pll_coef_bit = coef_bit;
855         alc_fix_pll(codec);
856 }
857
858 static void alc_sku_automute(struct hda_codec *codec)
859 {
860         struct alc_spec *spec = codec->spec;
861         unsigned int present;
862         unsigned int hp_nid = spec->autocfg.hp_pins[0];
863         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
864
865         /* need to execute and sync at first */
866         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
867         present = snd_hda_codec_read(codec, hp_nid, 0,
868                                      AC_VERB_GET_PIN_SENSE, 0);
869         spec->jack_present = (present & 0x80000000) != 0;
870         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
871                             spec->jack_present ? 0 : PIN_OUT);
872 }
873
874 #if 0 /* it's broken in some acses -- temporarily disabled */
875 static void alc_mic_automute(struct hda_codec *codec)
876 {
877         struct alc_spec *spec = codec->spec;
878         unsigned int present;
879         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
880         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
881         unsigned int mix_nid = spec->capsrc_nids[0];
882         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
883
884         capsrc_idx_mic = mic_nid - 0x18;
885         capsrc_idx_fmic = fmic_nid - 0x18;
886         present = snd_hda_codec_read(codec, mic_nid, 0,
887                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
888         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
889                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
890         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
891                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
892         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
893                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
894 }
895 #else
896 #define alc_mic_automute(codec) /* NOP */
897 #endif /* disabled */
898
899 /* unsolicited event for HP jack sensing */
900 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
901 {
902         if (codec->vendor_id == 0x10ec0880)
903                 res >>= 28;
904         else
905                 res >>= 26;
906         if (res == ALC880_HP_EVENT)
907                 alc_sku_automute(codec);
908
909         if (res == ALC880_MIC_EVENT)
910                 alc_mic_automute(codec);
911 }
912
913 static void alc_inithook(struct hda_codec *codec)
914 {
915         alc_sku_automute(codec);
916         alc_mic_automute(codec);
917 }
918
919 /* additional initialization for ALC888 variants */
920 static void alc888_coef_init(struct hda_codec *codec)
921 {
922         unsigned int tmp;
923
924         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
925         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
926         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
927         if ((tmp & 0xf0) == 2)
928                 /* alc888S-VC */
929                 snd_hda_codec_read(codec, 0x20, 0,
930                                    AC_VERB_SET_PROC_COEF, 0x830);
931          else
932                  /* alc888-VB */
933                  snd_hda_codec_read(codec, 0x20, 0,
934                                     AC_VERB_SET_PROC_COEF, 0x3030);
935 }
936
937 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
938  *      31 ~ 16 :       Manufacture ID
939  *      15 ~ 8  :       SKU ID
940  *      7  ~ 0  :       Assembly ID
941  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
942  */
943 static void alc_subsystem_id(struct hda_codec *codec,
944                              unsigned int porta, unsigned int porte,
945                              unsigned int portd)
946 {
947         unsigned int ass, tmp, i;
948         unsigned nid;
949         struct alc_spec *spec = codec->spec;
950
951         ass = codec->subsystem_id & 0xffff;
952         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
953                 goto do_sku;
954
955         /*
956          * 31~30        : port conetcivity
957          * 29~21        : reserve
958          * 20           : PCBEEP input
959          * 19~16        : Check sum (15:1)
960          * 15~1         : Custom
961          * 0            : override
962         */
963         nid = 0x1d;
964         if (codec->vendor_id == 0x10ec0260)
965                 nid = 0x17;
966         ass = snd_hda_codec_read(codec, nid, 0,
967                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
968         if (!(ass & 1) && !(ass & 0x100000))
969                 return;
970         if ((ass >> 30) != 1)   /* no physical connection */
971                 return;
972
973         /* check sum */
974         tmp = 0;
975         for (i = 1; i < 16; i++) {
976                 if ((ass >> i) & 1)
977                         tmp++;
978         }
979         if (((ass >> 16) & 0xf) != tmp)
980                 return;
981 do_sku:
982         /*
983          * 0 : override
984          * 1 :  Swap Jack
985          * 2 : 0 --> Desktop, 1 --> Laptop
986          * 3~5 : External Amplifier control
987          * 7~6 : Reserved
988         */
989         tmp = (ass & 0x38) >> 3;        /* external Amp control */
990         switch (tmp) {
991         case 1:
992                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
993                 break;
994         case 3:
995                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
996                 break;
997         case 7:
998                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
999                 break;
1000         case 5: /* set EAPD output high */
1001                 switch (codec->vendor_id) {
1002                 case 0x10ec0260:
1003                         snd_hda_codec_write(codec, 0x0f, 0,
1004                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1005                         snd_hda_codec_write(codec, 0x10, 0,
1006                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1007                         break;
1008                 case 0x10ec0262:
1009                 case 0x10ec0267:
1010                 case 0x10ec0268:
1011                 case 0x10ec0269:
1012                 case 0x10ec0660:
1013                 case 0x10ec0662:
1014                 case 0x10ec0663:
1015                 case 0x10ec0862:
1016                 case 0x10ec0889:
1017                         snd_hda_codec_write(codec, 0x14, 0,
1018                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1019                         snd_hda_codec_write(codec, 0x15, 0,
1020                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1021                         break;
1022                 }
1023                 switch (codec->vendor_id) {
1024                 case 0x10ec0260:
1025                         snd_hda_codec_write(codec, 0x1a, 0,
1026                                             AC_VERB_SET_COEF_INDEX, 7);
1027                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1028                                                  AC_VERB_GET_PROC_COEF, 0);
1029                         snd_hda_codec_write(codec, 0x1a, 0,
1030                                             AC_VERB_SET_COEF_INDEX, 7);
1031                         snd_hda_codec_write(codec, 0x1a, 0,
1032                                             AC_VERB_SET_PROC_COEF,
1033                                             tmp | 0x2010);
1034                         break;
1035                 case 0x10ec0262:
1036                 case 0x10ec0880:
1037                 case 0x10ec0882:
1038                 case 0x10ec0883:
1039                 case 0x10ec0885:
1040                 case 0x10ec0889:
1041                         snd_hda_codec_write(codec, 0x20, 0,
1042                                             AC_VERB_SET_COEF_INDEX, 7);
1043                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1044                                                  AC_VERB_GET_PROC_COEF, 0);
1045                         snd_hda_codec_write(codec, 0x20, 0,
1046                                             AC_VERB_SET_COEF_INDEX, 7);
1047                         snd_hda_codec_write(codec, 0x20, 0,
1048                                             AC_VERB_SET_PROC_COEF,
1049                                             tmp | 0x2010);
1050                         break;
1051                 case 0x10ec0888:
1052                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1053                         break;
1054                 case 0x10ec0267:
1055                 case 0x10ec0268:
1056                         snd_hda_codec_write(codec, 0x20, 0,
1057                                             AC_VERB_SET_COEF_INDEX, 7);
1058                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1059                                                  AC_VERB_GET_PROC_COEF, 0);
1060                         snd_hda_codec_write(codec, 0x20, 0,
1061                                             AC_VERB_SET_COEF_INDEX, 7);
1062                         snd_hda_codec_write(codec, 0x20, 0,
1063                                             AC_VERB_SET_PROC_COEF,
1064                                             tmp | 0x3000);
1065                         break;
1066                 }
1067         default:
1068                 break;
1069         }
1070
1071         /* is laptop or Desktop and enable the function "Mute internal speaker
1072          * when the external headphone out jack is plugged"
1073          */
1074         if (!(ass & 0x8000))
1075                 return;
1076         /*
1077          * 10~8 : Jack location
1078          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1079          * 14~13: Resvered
1080          * 15   : 1 --> enable the function "Mute internal speaker
1081          *              when the external headphone out jack is plugged"
1082          */
1083         if (!spec->autocfg.speaker_pins[0]) {
1084                 if (spec->autocfg.line_out_pins[0])
1085                         spec->autocfg.speaker_pins[0] =
1086                                 spec->autocfg.line_out_pins[0];
1087                 else
1088                         return;
1089         }
1090
1091         if (!spec->autocfg.hp_pins[0]) {
1092                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1093                 if (tmp == 0)
1094                         spec->autocfg.hp_pins[0] = porta;
1095                 else if (tmp == 1)
1096                         spec->autocfg.hp_pins[0] = porte;
1097                 else if (tmp == 2)
1098                         spec->autocfg.hp_pins[0] = portd;
1099                 else
1100                         return;
1101         }
1102         if (spec->autocfg.hp_pins[0])
1103                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1104                         AC_VERB_SET_UNSOLICITED_ENABLE,
1105                         AC_USRSP_EN | ALC880_HP_EVENT);
1106
1107 #if 0 /* it's broken in some acses -- temporarily disabled */
1108         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1109                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1110                 snd_hda_codec_write(codec,
1111                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1112                         AC_VERB_SET_UNSOLICITED_ENABLE,
1113                         AC_USRSP_EN | ALC880_MIC_EVENT);
1114 #endif /* disabled */
1115
1116         spec->unsol_event = alc_sku_unsol_event;
1117 }
1118
1119 /*
1120  * Fix-up pin default configurations
1121  */
1122
1123 struct alc_pincfg {
1124         hda_nid_t nid;
1125         u32 val;
1126 };
1127
1128 static void alc_fix_pincfg(struct hda_codec *codec,
1129                            const struct snd_pci_quirk *quirk,
1130                            const struct alc_pincfg **pinfix)
1131 {
1132         const struct alc_pincfg *cfg;
1133
1134         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1135         if (!quirk)
1136                 return;
1137
1138         cfg = pinfix[quirk->value];
1139         for (; cfg->nid; cfg++) {
1140                 int i;
1141                 u32 val = cfg->val;
1142                 for (i = 0; i < 4; i++) {
1143                         snd_hda_codec_write(codec, cfg->nid, 0,
1144                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1145                                     val & 0xff);
1146                         val >>= 8;
1147                 }
1148         }
1149 }
1150
1151 /*
1152  * ALC880 3-stack model
1153  *
1154  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1155  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1156  *                 F-Mic = 0x1b, HP = 0x19
1157  */
1158
1159 static hda_nid_t alc880_dac_nids[4] = {
1160         /* front, rear, clfe, rear_surr */
1161         0x02, 0x05, 0x04, 0x03
1162 };
1163
1164 static hda_nid_t alc880_adc_nids[3] = {
1165         /* ADC0-2 */
1166         0x07, 0x08, 0x09,
1167 };
1168
1169 /* The datasheet says the node 0x07 is connected from inputs,
1170  * but it shows zero connection in the real implementation on some devices.
1171  * Note: this is a 915GAV bug, fixed on 915GLV
1172  */
1173 static hda_nid_t alc880_adc_nids_alt[2] = {
1174         /* ADC1-2 */
1175         0x08, 0x09,
1176 };
1177
1178 #define ALC880_DIGOUT_NID       0x06
1179 #define ALC880_DIGIN_NID        0x0a
1180
1181 static struct hda_input_mux alc880_capture_source = {
1182         .num_items = 4,
1183         .items = {
1184                 { "Mic", 0x0 },
1185                 { "Front Mic", 0x3 },
1186                 { "Line", 0x2 },
1187                 { "CD", 0x4 },
1188         },
1189 };
1190
1191 /* channel source setting (2/6 channel selection for 3-stack) */
1192 /* 2ch mode */
1193 static struct hda_verb alc880_threestack_ch2_init[] = {
1194         /* set line-in to input, mute it */
1195         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1196         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1197         /* set mic-in to input vref 80%, mute it */
1198         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1199         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1200         { } /* end */
1201 };
1202
1203 /* 6ch mode */
1204 static struct hda_verb alc880_threestack_ch6_init[] = {
1205         /* set line-in to output, unmute it */
1206         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1207         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1208         /* set mic-in to output, unmute it */
1209         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1210         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1211         { } /* end */
1212 };
1213
1214 static struct hda_channel_mode alc880_threestack_modes[2] = {
1215         { 2, alc880_threestack_ch2_init },
1216         { 6, alc880_threestack_ch6_init },
1217 };
1218
1219 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1220         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1221         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1222         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1223         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1224         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1225         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1226         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1227         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1228         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1229         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1230         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1231         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1232         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1233         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1234         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1235         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1236         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1237         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1238         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1239         {
1240                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1241                 .name = "Channel Mode",
1242                 .info = alc_ch_mode_info,
1243                 .get = alc_ch_mode_get,
1244                 .put = alc_ch_mode_put,
1245         },
1246         { } /* end */
1247 };
1248
1249 /* capture mixer elements */
1250 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1251                             struct snd_ctl_elem_info *uinfo)
1252 {
1253         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1254         struct alc_spec *spec = codec->spec;
1255         int err;
1256
1257         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1258         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1259                                                       HDA_INPUT);
1260         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1261         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1262         return err;
1263 }
1264
1265 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1266                            unsigned int size, unsigned int __user *tlv)
1267 {
1268         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1269         struct alc_spec *spec = codec->spec;
1270         int err;
1271
1272         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1273         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1274                                                       HDA_INPUT);
1275         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1276         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1277         return err;
1278 }
1279
1280 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1281                              struct snd_ctl_elem_value *ucontrol);
1282
1283 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1284                                  struct snd_ctl_elem_value *ucontrol,
1285                                  getput_call_t func)
1286 {
1287         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1288         struct alc_spec *spec = codec->spec;
1289         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1290         int err;
1291
1292         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1293         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1294                                                       3, 0, HDA_INPUT);
1295         err = func(kcontrol, ucontrol);
1296         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1297         return err;
1298 }
1299
1300 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1301                            struct snd_ctl_elem_value *ucontrol)
1302 {
1303         return alc_cap_getput_caller(kcontrol, ucontrol,
1304                                      snd_hda_mixer_amp_volume_get);
1305 }
1306
1307 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1308                            struct snd_ctl_elem_value *ucontrol)
1309 {
1310         return alc_cap_getput_caller(kcontrol, ucontrol,
1311                                      snd_hda_mixer_amp_volume_put);
1312 }
1313
1314 /* capture mixer elements */
1315 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1316
1317 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1318                           struct snd_ctl_elem_value *ucontrol)
1319 {
1320         return alc_cap_getput_caller(kcontrol, ucontrol,
1321                                      snd_hda_mixer_amp_switch_get);
1322 }
1323
1324 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1325                           struct snd_ctl_elem_value *ucontrol)
1326 {
1327         return alc_cap_getput_caller(kcontrol, ucontrol,
1328                                      snd_hda_mixer_amp_switch_put);
1329 }
1330
1331 #define DEFINE_CAPMIX(num) \
1332 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1333         { \
1334                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1335                 .name = "Capture Switch", \
1336                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1337                 .count = num, \
1338                 .info = alc_cap_sw_info, \
1339                 .get = alc_cap_sw_get, \
1340                 .put = alc_cap_sw_put, \
1341         }, \
1342         { \
1343                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1344                 .name = "Capture Volume", \
1345                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1346                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1347                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1348                 .count = num, \
1349                 .info = alc_cap_vol_info, \
1350                 .get = alc_cap_vol_get, \
1351                 .put = alc_cap_vol_put, \
1352                 .tlv = { .c = alc_cap_vol_tlv }, \
1353         }, \
1354         { } /* end */ \
1355 }
1356
1357 /* up to three ADCs */
1358 DEFINE_CAPMIX(1);
1359 DEFINE_CAPMIX(2);
1360 DEFINE_CAPMIX(3);
1361
1362
1363 /*
1364  * ALC880 5-stack model
1365  *
1366  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1367  *      Side = 0x02 (0xd)
1368  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1369  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1370  */
1371
1372 /* additional mixers to alc880_three_stack_mixer */
1373 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1374         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1375         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1376         { } /* end */
1377 };
1378
1379 /* channel source setting (6/8 channel selection for 5-stack) */
1380 /* 6ch mode */
1381 static struct hda_verb alc880_fivestack_ch6_init[] = {
1382         /* set line-in to input, mute it */
1383         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1384         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1385         { } /* end */
1386 };
1387
1388 /* 8ch mode */
1389 static struct hda_verb alc880_fivestack_ch8_init[] = {
1390         /* set line-in to output, unmute it */
1391         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1392         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1393         { } /* end */
1394 };
1395
1396 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1397         { 6, alc880_fivestack_ch6_init },
1398         { 8, alc880_fivestack_ch8_init },
1399 };
1400
1401
1402 /*
1403  * ALC880 6-stack model
1404  *
1405  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1406  *      Side = 0x05 (0x0f)
1407  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1408  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1409  */
1410
1411 static hda_nid_t alc880_6st_dac_nids[4] = {
1412         /* front, rear, clfe, rear_surr */
1413         0x02, 0x03, 0x04, 0x05
1414 };
1415
1416 static struct hda_input_mux alc880_6stack_capture_source = {
1417         .num_items = 4,
1418         .items = {
1419                 { "Mic", 0x0 },
1420                 { "Front Mic", 0x1 },
1421                 { "Line", 0x2 },
1422                 { "CD", 0x4 },
1423         },
1424 };
1425
1426 /* fixed 8-channels */
1427 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1428         { 8, NULL },
1429 };
1430
1431 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1432         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1433         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1434         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1435         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1436         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1437         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1438         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1439         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1440         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1441         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1442         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1443         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1444         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1445         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1446         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1447         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1448         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1449         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1450         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1451         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1452         {
1453                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1454                 .name = "Channel Mode",
1455                 .info = alc_ch_mode_info,
1456                 .get = alc_ch_mode_get,
1457                 .put = alc_ch_mode_put,
1458         },
1459         { } /* end */
1460 };
1461
1462
1463 /*
1464  * ALC880 W810 model
1465  *
1466  * W810 has rear IO for:
1467  * Front (DAC 02)
1468  * Surround (DAC 03)
1469  * Center/LFE (DAC 04)
1470  * Digital out (06)
1471  *
1472  * The system also has a pair of internal speakers, and a headphone jack.
1473  * These are both connected to Line2 on the codec, hence to DAC 02.
1474  *
1475  * There is a variable resistor to control the speaker or headphone
1476  * volume. This is a hardware-only device without a software API.
1477  *
1478  * Plugging headphones in will disable the internal speakers. This is
1479  * implemented in hardware, not via the driver using jack sense. In
1480  * a similar fashion, plugging into the rear socket marked "front" will
1481  * disable both the speakers and headphones.
1482  *
1483  * For input, there's a microphone jack, and an "audio in" jack.
1484  * These may not do anything useful with this driver yet, because I
1485  * haven't setup any initialization verbs for these yet...
1486  */
1487
1488 static hda_nid_t alc880_w810_dac_nids[3] = {
1489         /* front, rear/surround, clfe */
1490         0x02, 0x03, 0x04
1491 };
1492
1493 /* fixed 6 channels */
1494 static struct hda_channel_mode alc880_w810_modes[1] = {
1495         { 6, NULL }
1496 };
1497
1498 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1499 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1500         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1501         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1502         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1503         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1504         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1505         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1506         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1507         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1508         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1509         { } /* end */
1510 };
1511
1512
1513 /*
1514  * Z710V model
1515  *
1516  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1517  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1518  *                 Line = 0x1a
1519  */
1520
1521 static hda_nid_t alc880_z71v_dac_nids[1] = {
1522         0x02
1523 };
1524 #define ALC880_Z71V_HP_DAC      0x03
1525
1526 /* fixed 2 channels */
1527 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1528         { 2, NULL }
1529 };
1530
1531 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1532         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1533         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1534         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1535         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1536         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1537         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1538         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1539         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1540         { } /* end */
1541 };
1542
1543
1544 /*
1545  * ALC880 F1734 model
1546  *
1547  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1548  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1549  */
1550
1551 static hda_nid_t alc880_f1734_dac_nids[1] = {
1552         0x03
1553 };
1554 #define ALC880_F1734_HP_DAC     0x02
1555
1556 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1557         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1558         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1559         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1560         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1561         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1562         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1563         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1564         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1565         { } /* end */
1566 };
1567
1568 static struct hda_input_mux alc880_f1734_capture_source = {
1569         .num_items = 2,
1570         .items = {
1571                 { "Mic", 0x1 },
1572                 { "CD", 0x4 },
1573         },
1574 };
1575
1576
1577 /*
1578  * ALC880 ASUS model
1579  *
1580  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1581  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1582  *  Mic = 0x18, Line = 0x1a
1583  */
1584
1585 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1586 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1587
1588 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1589         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1590         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1591         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1592         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1593         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1594         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1595         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1596         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1597         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1598         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1599         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1600         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1601         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1602         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1603         {
1604                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1605                 .name = "Channel Mode",
1606                 .info = alc_ch_mode_info,
1607                 .get = alc_ch_mode_get,
1608                 .put = alc_ch_mode_put,
1609         },
1610         { } /* end */
1611 };
1612
1613 /*
1614  * ALC880 ASUS W1V model
1615  *
1616  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1617  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1618  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1619  */
1620
1621 /* additional mixers to alc880_asus_mixer */
1622 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1623         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1624         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1625         { } /* end */
1626 };
1627
1628 /* additional mixers to alc880_asus_mixer */
1629 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1630         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1631         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1632         { } /* end */
1633 };
1634
1635 /* TCL S700 */
1636 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1637         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1638         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1639         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1640         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1641         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1642         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1643         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1644         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1645         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1646         { } /* end */
1647 };
1648
1649 /* Uniwill */
1650 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1651         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1652         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1653         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1654         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1655         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1656         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1657         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1658         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1659         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1660         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1661         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1662         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1663         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1664         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1665         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1666         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1667         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1668         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1669         {
1670                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1671                 .name = "Channel Mode",
1672                 .info = alc_ch_mode_info,
1673                 .get = alc_ch_mode_get,
1674                 .put = alc_ch_mode_put,
1675         },
1676         { } /* end */
1677 };
1678
1679 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1680         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1681         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1682         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1683         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1684         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1685         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1686         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1687         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1688         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1689         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1690         { } /* end */
1691 };
1692
1693 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1694         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1695         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1696         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1697         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1698         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1699         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1700         { } /* end */
1701 };
1702
1703 /*
1704  * virtual master controls
1705  */
1706
1707 /*
1708  * slave controls for virtual master
1709  */
1710 static const char *alc_slave_vols[] = {
1711         "Front Playback Volume",
1712         "Surround Playback Volume",
1713         "Center Playback Volume",
1714         "LFE Playback Volume",
1715         "Side Playback Volume",
1716         "Headphone Playback Volume",
1717         "Speaker Playback Volume",
1718         "Mono Playback Volume",
1719         "Line-Out Playback Volume",
1720         NULL,
1721 };
1722
1723 static const char *alc_slave_sws[] = {
1724         "Front Playback Switch",
1725         "Surround Playback Switch",
1726         "Center Playback Switch",
1727         "LFE Playback Switch",
1728         "Side Playback Switch",
1729         "Headphone Playback Switch",
1730         "Speaker Playback Switch",
1731         "Mono Playback Switch",
1732         "IEC958 Playback Switch",
1733         NULL,
1734 };
1735
1736 /*
1737  * build control elements
1738  */
1739
1740 static void alc_free_kctls(struct hda_codec *codec);
1741
1742 static int alc_build_controls(struct hda_codec *codec)
1743 {
1744         struct alc_spec *spec = codec->spec;
1745         int err;
1746         int i;
1747
1748         for (i = 0; i < spec->num_mixers; i++) {
1749                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1750                 if (err < 0)
1751                         return err;
1752         }
1753         if (spec->cap_mixer) {
1754                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1755                 if (err < 0)
1756                         return err;
1757         }
1758         if (spec->multiout.dig_out_nid) {
1759                 err = snd_hda_create_spdif_out_ctls(codec,
1760                                                     spec->multiout.dig_out_nid);
1761                 if (err < 0)
1762                         return err;
1763                 err = snd_hda_create_spdif_share_sw(codec,
1764                                                     &spec->multiout);
1765                 if (err < 0)
1766                         return err;
1767                 spec->multiout.share_spdif = 1;
1768         }
1769         if (spec->dig_in_nid) {
1770                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1771                 if (err < 0)
1772                         return err;
1773         }
1774
1775         /* if we have no master control, let's create it */
1776         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1777                 unsigned int vmaster_tlv[4];
1778                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1779                                         HDA_OUTPUT, vmaster_tlv);
1780                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1781                                           vmaster_tlv, alc_slave_vols);
1782                 if (err < 0)
1783                         return err;
1784         }
1785         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1786                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1787                                           NULL, alc_slave_sws);
1788                 if (err < 0)
1789                         return err;
1790         }
1791
1792         alc_free_kctls(codec); /* no longer needed */
1793         return 0;
1794 }
1795
1796
1797 /*
1798  * initialize the codec volumes, etc
1799  */
1800
1801 /*
1802  * generic initialization of ADC, input mixers and output mixers
1803  */
1804 static struct hda_verb alc880_volume_init_verbs[] = {
1805         /*
1806          * Unmute ADC0-2 and set the default input to mic-in
1807          */
1808         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1809         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1810         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1811         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1812         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1813         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1814
1815         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1816          * mixer widget
1817          * Note: PASD motherboards uses the Line In 2 as the input for front
1818          * panel mic (mic 2)
1819          */
1820         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1821         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1822         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1823         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1824         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1825         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1826         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1827         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1828
1829         /*
1830          * Set up output mixers (0x0c - 0x0f)
1831          */
1832         /* set vol=0 to output mixers */
1833         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1834         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1835         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1836         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1837         /* set up input amps for analog loopback */
1838         /* Amp Indices: DAC = 0, mixer = 1 */
1839         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1840         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1841         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1842         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1843         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1844         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1845         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1846         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1847
1848         { }
1849 };
1850
1851 /*
1852  * 3-stack pin configuration:
1853  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1854  */
1855 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1856         /*
1857          * preset connection lists of input pins
1858          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1859          */
1860         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1861         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1862         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1863
1864         /*
1865          * Set pin mode and muting
1866          */
1867         /* set front pin widgets 0x14 for output */
1868         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1869         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1870         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1871         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1872         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1873         /* Mic2 (as headphone out) for HP output */
1874         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1875         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1876         /* Line In pin widget for input */
1877         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1878         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1879         /* Line2 (as front mic) pin widget for input and vref at 80% */
1880         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1881         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1882         /* CD pin widget for input */
1883         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1884
1885         { }
1886 };
1887
1888 /*
1889  * 5-stack pin configuration:
1890  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1891  * line-in/side = 0x1a, f-mic = 0x1b
1892  */
1893 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1894         /*
1895          * preset connection lists of input pins
1896          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1897          */
1898         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1899         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1900
1901         /*
1902          * Set pin mode and muting
1903          */
1904         /* set pin widgets 0x14-0x17 for output */
1905         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1906         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1907         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1908         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1909         /* unmute pins for output (no gain on this amp) */
1910         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1911         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1912         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1913         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1914
1915         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1916         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1917         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1918         /* Mic2 (as headphone out) for HP output */
1919         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1920         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1921         /* Line In pin widget for input */
1922         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1923         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1924         /* Line2 (as front mic) pin widget for input and vref at 80% */
1925         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1926         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1927         /* CD pin widget for input */
1928         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1929
1930         { }
1931 };
1932
1933 /*
1934  * W810 pin configuration:
1935  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1936  */
1937 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1938         /* hphone/speaker input selector: front DAC */
1939         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1940
1941         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1942         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1943         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1944         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1945         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1946         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1947
1948         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1949         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1950
1951         { }
1952 };
1953
1954 /*
1955  * Z71V pin configuration:
1956  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1957  */
1958 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1959         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1960         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1961         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1962         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1963
1964         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1965         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1966         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1967         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1968
1969         { }
1970 };
1971
1972 /*
1973  * 6-stack pin configuration:
1974  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1975  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1976  */
1977 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1978         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1979
1980         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1981         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1982         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1983         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1984         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1985         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1986         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1987         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1988
1989         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1990         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1991         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1992         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1993         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1994         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1995         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1996         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1997         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1998
1999         { }
2000 };
2001
2002 /*
2003  * Uniwill pin configuration:
2004  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2005  * line = 0x1a
2006  */
2007 static struct hda_verb alc880_uniwill_init_verbs[] = {
2008         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2009
2010         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2011         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2012         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2013         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2014         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2015         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2016         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2017         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2018         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2019         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2020         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2021         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2022         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2023         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2024
2025         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2026         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2027         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2028         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2029         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2030         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2031         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2032         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2033         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2034
2035         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2036         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2037
2038         { }
2039 };
2040
2041 /*
2042 * Uniwill P53
2043 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2044  */
2045 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2046         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2047
2048         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2049         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2050         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2051         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2052         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2053         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2054         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2055         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2056         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2057         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2058         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2059         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2060
2061         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2062         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2063         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2064         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2065         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2066         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2067
2068         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2069         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2070
2071         { }
2072 };
2073
2074 static struct hda_verb alc880_beep_init_verbs[] = {
2075         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2076         { }
2077 };
2078
2079 /* toggle speaker-output according to the hp-jack state */
2080 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
2081 {
2082         unsigned int present;
2083         unsigned char bits;
2084
2085         present = snd_hda_codec_read(codec, 0x14, 0,
2086                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2087         bits = present ? HDA_AMP_MUTE : 0;
2088         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
2089                                  HDA_AMP_MUTE, bits);
2090         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
2091                                  HDA_AMP_MUTE, bits);
2092 }
2093
2094 /* auto-toggle front mic */
2095 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2096 {
2097         unsigned int present;
2098         unsigned char bits;
2099
2100         present = snd_hda_codec_read(codec, 0x18, 0,
2101                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2102         bits = present ? HDA_AMP_MUTE : 0;
2103         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2104 }
2105
2106 static void alc880_uniwill_automute(struct hda_codec *codec)
2107 {
2108         alc880_uniwill_hp_automute(codec);
2109         alc880_uniwill_mic_automute(codec);
2110 }
2111
2112 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2113                                        unsigned int res)
2114 {
2115         /* Looks like the unsol event is incompatible with the standard
2116          * definition.  4bit tag is placed at 28 bit!
2117          */
2118         switch (res >> 28) {
2119         case ALC880_HP_EVENT:
2120                 alc880_uniwill_hp_automute(codec);
2121                 break;
2122         case ALC880_MIC_EVENT:
2123                 alc880_uniwill_mic_automute(codec);
2124                 break;
2125         }
2126 }
2127
2128 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2129 {
2130         unsigned int present;
2131         unsigned char bits;
2132
2133         present = snd_hda_codec_read(codec, 0x14, 0,
2134                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2135         bits = present ? HDA_AMP_MUTE : 0;
2136         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2137 }
2138
2139 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2140 {
2141         unsigned int present;
2142
2143         present = snd_hda_codec_read(codec, 0x21, 0,
2144                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2145         present &= HDA_AMP_VOLMASK;
2146         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2147                                  HDA_AMP_VOLMASK, present);
2148         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2149                                  HDA_AMP_VOLMASK, present);
2150 }
2151
2152 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2153                                            unsigned int res)
2154 {
2155         /* Looks like the unsol event is incompatible with the standard
2156          * definition.  4bit tag is placed at 28 bit!
2157          */
2158         if ((res >> 28) == ALC880_HP_EVENT)
2159                 alc880_uniwill_p53_hp_automute(codec);
2160         if ((res >> 28) == ALC880_DCVOL_EVENT)
2161                 alc880_uniwill_p53_dcvol_automute(codec);
2162 }
2163
2164 /*
2165  * F1734 pin configuration:
2166  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2167  */
2168 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2169         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2170         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2171         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2172         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2173         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2174
2175         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2176         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2177         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2178         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2179
2180         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2181         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2182         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2183         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2184         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2185         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2186         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2187         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2188         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2189
2190         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2191         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2192
2193         { }
2194 };
2195
2196 /*
2197  * ASUS pin configuration:
2198  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2199  */
2200 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2201         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2202         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2203         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2204         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2205
2206         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2207         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2208         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2209         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2210         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2211         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2212         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2213         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2214
2215         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2216         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2217         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2218         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2219         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2220         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2221         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2222         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2223         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2224
2225         { }
2226 };
2227
2228 /* Enable GPIO mask and set output */
2229 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2230 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2231
2232 /* Clevo m520g init */
2233 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2234         /* headphone output */
2235         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2236         /* line-out */
2237         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2238         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2239         /* Line-in */
2240         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2241         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2242         /* CD */
2243         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2244         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2245         /* Mic1 (rear panel) */
2246         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2247         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2248         /* Mic2 (front panel) */
2249         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2250         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2251         /* headphone */
2252         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2253         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2254         /* change to EAPD mode */
2255         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2256         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2257
2258         { }
2259 };
2260
2261 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2262         /* change to EAPD mode */
2263         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2264         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2265
2266         /* Headphone output */
2267         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2268         /* Front output*/
2269         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2270         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2271
2272         /* Line In pin widget for input */
2273         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2274         /* CD pin widget for input */
2275         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2276         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2277         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2278
2279         /* change to EAPD mode */
2280         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2281         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2282
2283         { }
2284 };
2285
2286 /*
2287  * LG m1 express dual
2288  *
2289  * Pin assignment:
2290  *   Rear Line-In/Out (blue): 0x14
2291  *   Build-in Mic-In: 0x15
2292  *   Speaker-out: 0x17
2293  *   HP-Out (green): 0x1b
2294  *   Mic-In/Out (red): 0x19
2295  *   SPDIF-Out: 0x1e
2296  */
2297
2298 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2299 static hda_nid_t alc880_lg_dac_nids[3] = {
2300         0x05, 0x02, 0x03
2301 };
2302
2303 /* seems analog CD is not working */
2304 static struct hda_input_mux alc880_lg_capture_source = {
2305         .num_items = 3,
2306         .items = {
2307                 { "Mic", 0x1 },
2308                 { "Line", 0x5 },
2309                 { "Internal Mic", 0x6 },
2310         },
2311 };
2312
2313 /* 2,4,6 channel modes */
2314 static struct hda_verb alc880_lg_ch2_init[] = {
2315         /* set line-in and mic-in to input */
2316         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2317         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2318         { }
2319 };
2320
2321 static struct hda_verb alc880_lg_ch4_init[] = {
2322         /* set line-in to out and mic-in to input */
2323         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2324         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2325         { }
2326 };
2327
2328 static struct hda_verb alc880_lg_ch6_init[] = {
2329         /* set line-in and mic-in to output */
2330         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2331         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2332         { }
2333 };
2334
2335 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2336         { 2, alc880_lg_ch2_init },
2337         { 4, alc880_lg_ch4_init },
2338         { 6, alc880_lg_ch6_init },
2339 };
2340
2341 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2342         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2343         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2344         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2345         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2346         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2347         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2348         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2349         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2350         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2351         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2352         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2353         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2354         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2355         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2356         {
2357                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2358                 .name = "Channel Mode",
2359                 .info = alc_ch_mode_info,
2360                 .get = alc_ch_mode_get,
2361                 .put = alc_ch_mode_put,
2362         },
2363         { } /* end */
2364 };
2365
2366 static struct hda_verb alc880_lg_init_verbs[] = {
2367         /* set capture source to mic-in */
2368         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2369         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2370         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2371         /* mute all amp mixer inputs */
2372         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2373         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2374         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2375         /* line-in to input */
2376         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2377         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2378         /* built-in mic */
2379         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2380         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2381         /* speaker-out */
2382         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2383         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2384         /* mic-in to input */
2385         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2386         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2387         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2388         /* HP-out */
2389         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2390         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2391         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2392         /* jack sense */
2393         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2394         { }
2395 };
2396
2397 /* toggle speaker-output according to the hp-jack state */
2398 static void alc880_lg_automute(struct hda_codec *codec)
2399 {
2400         unsigned int present;
2401         unsigned char bits;
2402
2403         present = snd_hda_codec_read(codec, 0x1b, 0,
2404                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2405         bits = present ? HDA_AMP_MUTE : 0;
2406         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2407                                  HDA_AMP_MUTE, bits);
2408 }
2409
2410 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2411 {
2412         /* Looks like the unsol event is incompatible with the standard
2413          * definition.  4bit tag is placed at 28 bit!
2414          */
2415         if ((res >> 28) == 0x01)
2416                 alc880_lg_automute(codec);
2417 }
2418
2419 /*
2420  * LG LW20
2421  *
2422  * Pin assignment:
2423  *   Speaker-out: 0x14
2424  *   Mic-In: 0x18
2425  *   Built-in Mic-In: 0x19
2426  *   Line-In: 0x1b
2427  *   HP-Out: 0x1a
2428  *   SPDIF-Out: 0x1e
2429  */
2430
2431 static struct hda_input_mux alc880_lg_lw_capture_source = {
2432         .num_items = 3,
2433         .items = {
2434                 { "Mic", 0x0 },
2435                 { "Internal Mic", 0x1 },
2436                 { "Line In", 0x2 },
2437         },
2438 };
2439
2440 #define alc880_lg_lw_modes alc880_threestack_modes
2441
2442 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2443         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2444         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2445         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2446         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2447         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2448         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2449         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2450         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2451         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2452         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2453         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2454         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2455         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2456         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2457         {
2458                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2459                 .name = "Channel Mode",
2460                 .info = alc_ch_mode_info,
2461                 .get = alc_ch_mode_get,
2462                 .put = alc_ch_mode_put,
2463         },
2464         { } /* end */
2465 };
2466
2467 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2468         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2469         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2470         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2471
2472         /* set capture source to mic-in */
2473         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2474         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2475         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2476         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2477         /* speaker-out */
2478         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2479         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2480         /* HP-out */
2481         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2482         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2483         /* mic-in to input */
2484         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2485         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2486         /* built-in mic */
2487         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2488         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2489         /* jack sense */
2490         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2491         { }
2492 };
2493
2494 /* toggle speaker-output according to the hp-jack state */
2495 static void alc880_lg_lw_automute(struct hda_codec *codec)
2496 {
2497         unsigned int present;
2498         unsigned char bits;
2499
2500         present = snd_hda_codec_read(codec, 0x1b, 0,
2501                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2502         bits = present ? HDA_AMP_MUTE : 0;
2503         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2504                                  HDA_AMP_MUTE, bits);
2505 }
2506
2507 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2508 {
2509         /* Looks like the unsol event is incompatible with the standard
2510          * definition.  4bit tag is placed at 28 bit!
2511          */
2512         if ((res >> 28) == 0x01)
2513                 alc880_lg_lw_automute(codec);
2514 }
2515
2516 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2517         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2518         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2519         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2520         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2521         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2522         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2523         { } /* end */
2524 };
2525
2526 static struct hda_input_mux alc880_medion_rim_capture_source = {
2527         .num_items = 2,
2528         .items = {
2529                 { "Mic", 0x0 },
2530                 { "Internal Mic", 0x1 },
2531         },
2532 };
2533
2534 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2535         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2536
2537         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2538         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2539
2540         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2541         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2542         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2543         /* Mic2 (as headphone out) for HP output */
2544         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2545         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2546         /* Internal Speaker */
2547         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2548         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2549
2550         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2551         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2552
2553         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2554         { }
2555 };
2556
2557 /* toggle speaker-output according to the hp-jack state */
2558 static void alc880_medion_rim_automute(struct hda_codec *codec)
2559 {
2560         unsigned int present;
2561         unsigned char bits;
2562
2563         present = snd_hda_codec_read(codec, 0x14, 0,
2564                                      AC_VERB_GET_PIN_SENSE, 0)
2565                 & AC_PINSENSE_PRESENCE;
2566         bits = present ? HDA_AMP_MUTE : 0;
2567         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2568                                  HDA_AMP_MUTE, bits);
2569         if (present)
2570                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2571         else
2572                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2573 }
2574
2575 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2576                                           unsigned int res)
2577 {
2578         /* Looks like the unsol event is incompatible with the standard
2579          * definition.  4bit tag is placed at 28 bit!
2580          */
2581         if ((res >> 28) == ALC880_HP_EVENT)
2582                 alc880_medion_rim_automute(codec);
2583 }
2584
2585 #ifdef CONFIG_SND_HDA_POWER_SAVE
2586 static struct hda_amp_list alc880_loopbacks[] = {
2587         { 0x0b, HDA_INPUT, 0 },
2588         { 0x0b, HDA_INPUT, 1 },
2589         { 0x0b, HDA_INPUT, 2 },
2590         { 0x0b, HDA_INPUT, 3 },
2591         { 0x0b, HDA_INPUT, 4 },
2592         { } /* end */
2593 };
2594
2595 static struct hda_amp_list alc880_lg_loopbacks[] = {
2596         { 0x0b, HDA_INPUT, 1 },
2597         { 0x0b, HDA_INPUT, 6 },
2598         { 0x0b, HDA_INPUT, 7 },
2599         { } /* end */
2600 };
2601 #endif
2602
2603 /*
2604  * Common callbacks
2605  */
2606
2607 static int alc_init(struct hda_codec *codec)
2608 {
2609         struct alc_spec *spec = codec->spec;
2610         unsigned int i;
2611
2612         alc_fix_pll(codec);
2613         if (codec->vendor_id == 0x10ec0888)
2614                 alc888_coef_init(codec);
2615
2616         for (i = 0; i < spec->num_init_verbs; i++)
2617                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2618
2619         if (spec->init_hook)
2620                 spec->init_hook(codec);
2621
2622         return 0;
2623 }
2624
2625 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2626 {
2627         struct alc_spec *spec = codec->spec;
2628
2629         if (spec->unsol_event)
2630                 spec->unsol_event(codec, res);
2631 }
2632
2633 #ifdef CONFIG_SND_HDA_POWER_SAVE
2634 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2635 {
2636         struct alc_spec *spec = codec->spec;
2637         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2638 }
2639 #endif
2640
2641 /*
2642  * Analog playback callbacks
2643  */
2644 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2645                                     struct hda_codec *codec,
2646                                     struct snd_pcm_substream *substream)
2647 {
2648         struct alc_spec *spec = codec->spec;
2649         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2650                                              hinfo);
2651 }
2652
2653 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2654                                        struct hda_codec *codec,
2655                                        unsigned int stream_tag,
2656                                        unsigned int format,
2657                                        struct snd_pcm_substream *substream)
2658 {
2659         struct alc_spec *spec = codec->spec;
2660         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2661                                                 stream_tag, format, substream);
2662 }
2663
2664 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2665                                        struct hda_codec *codec,
2666                                        struct snd_pcm_substream *substream)
2667 {
2668         struct alc_spec *spec = codec->spec;
2669         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2670 }
2671
2672 /*
2673  * Digital out
2674  */
2675 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2676                                         struct hda_codec *codec,
2677                                         struct snd_pcm_substream *substream)
2678 {
2679         struct alc_spec *spec = codec->spec;
2680         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2681 }
2682
2683 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2684                                            struct hda_codec *codec,
2685                                            unsigned int stream_tag,
2686                                            unsigned int format,
2687                                            struct snd_pcm_substream *substream)
2688 {
2689         struct alc_spec *spec = codec->spec;
2690         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2691                                              stream_tag, format, substream);
2692 }
2693
2694 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2695                                          struct hda_codec *codec,
2696                                          struct snd_pcm_substream *substream)
2697 {
2698         struct alc_spec *spec = codec->spec;
2699         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2700 }
2701
2702 /*
2703  * Analog capture
2704  */
2705 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2706                                       struct hda_codec *codec,
2707                                       unsigned int stream_tag,
2708                                       unsigned int format,
2709                                       struct snd_pcm_substream *substream)
2710 {
2711         struct alc_spec *spec = codec->spec;
2712
2713         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2714                                    stream_tag, 0, format);
2715         return 0;
2716 }
2717
2718 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2719                                       struct hda_codec *codec,
2720                                       struct snd_pcm_substream *substream)
2721 {
2722         struct alc_spec *spec = codec->spec;
2723
2724         snd_hda_codec_cleanup_stream(codec,
2725                                      spec->adc_nids[substream->number + 1]);
2726         return 0;
2727 }
2728
2729
2730 /*
2731  */
2732 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2733         .substreams = 1,
2734         .channels_min = 2,
2735         .channels_max = 8,
2736         /* NID is set in alc_build_pcms */
2737         .ops = {
2738                 .open = alc880_playback_pcm_open,
2739                 .prepare = alc880_playback_pcm_prepare,
2740                 .cleanup = alc880_playback_pcm_cleanup
2741         },
2742 };
2743
2744 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2745         .substreams = 1,
2746         .channels_min = 2,
2747         .channels_max = 2,
2748         /* NID is set in alc_build_pcms */
2749 };
2750
2751 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
2752         .substreams = 1,
2753         .channels_min = 2,
2754         .channels_max = 2,
2755         /* NID is set in alc_build_pcms */
2756 };
2757
2758 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2759         .substreams = 2, /* can be overridden */
2760         .channels_min = 2,
2761         .channels_max = 2,
2762         /* NID is set in alc_build_pcms */
2763         .ops = {
2764                 .prepare = alc880_alt_capture_pcm_prepare,
2765                 .cleanup = alc880_alt_capture_pcm_cleanup
2766         },
2767 };
2768
2769 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2770         .substreams = 1,
2771         .channels_min = 2,
2772         .channels_max = 2,
2773         /* NID is set in alc_build_pcms */
2774         .ops = {
2775                 .open = alc880_dig_playback_pcm_open,
2776                 .close = alc880_dig_playback_pcm_close,
2777                 .prepare = alc880_dig_playback_pcm_prepare
2778         },
2779 };
2780
2781 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2782         .substreams = 1,
2783         .channels_min = 2,
2784         .channels_max = 2,
2785         /* NID is set in alc_build_pcms */
2786 };
2787
2788 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2789 static struct hda_pcm_stream alc_pcm_null_stream = {
2790         .substreams = 0,
2791         .channels_min = 0,
2792         .channels_max = 0,
2793 };
2794
2795 static int alc_build_pcms(struct hda_codec *codec)
2796 {
2797         struct alc_spec *spec = codec->spec;
2798         struct hda_pcm *info = spec->pcm_rec;
2799         int i;
2800
2801         codec->num_pcms = 1;
2802         codec->pcm_info = info;
2803
2804         info->name = spec->stream_name_analog;
2805         if (spec->stream_analog_playback) {
2806                 if (snd_BUG_ON(!spec->multiout.dac_nids))
2807                         return -EINVAL;
2808                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2809                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2810         }
2811         if (spec->stream_analog_capture) {
2812                 if (snd_BUG_ON(!spec->adc_nids))
2813                         return -EINVAL;
2814                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2815                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2816         }
2817
2818         if (spec->channel_mode) {
2819                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2820                 for (i = 0; i < spec->num_channel_mode; i++) {
2821                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2822                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2823                         }
2824                 }
2825         }
2826
2827         /* SPDIF for stream index #1 */
2828         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2829                 codec->num_pcms = 2;
2830                 info = spec->pcm_rec + 1;
2831                 info->name = spec->stream_name_digital;
2832                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2833                 if (spec->multiout.dig_out_nid &&
2834                     spec->stream_digital_playback) {
2835                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2836                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2837                 }
2838                 if (spec->dig_in_nid &&
2839                     spec->stream_digital_capture) {
2840                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2841                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2842                 }
2843                 /* FIXME: do we need this for all Realtek codec models? */
2844                 codec->spdif_status_reset = 1;
2845         }
2846
2847         /* If the use of more than one ADC is requested for the current
2848          * model, configure a second analog capture-only PCM.
2849          */
2850         /* Additional Analaog capture for index #2 */
2851         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
2852             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
2853                 codec->num_pcms = 3;
2854                 info = spec->pcm_rec + 2;
2855                 info->name = spec->stream_name_analog;
2856                 if (spec->alt_dac_nid) {
2857                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2858                                 *spec->stream_analog_alt_playback;
2859                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2860                                 spec->alt_dac_nid;
2861                 } else {
2862                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2863                                 alc_pcm_null_stream;
2864                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2865                 }
2866                 if (spec->num_adc_nids > 1) {
2867                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2868                                 *spec->stream_analog_alt_capture;
2869                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2870                                 spec->adc_nids[1];
2871                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2872                                 spec->num_adc_nids - 1;
2873                 } else {
2874                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2875                                 alc_pcm_null_stream;
2876                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2877                 }
2878         }
2879
2880         return 0;
2881 }
2882
2883 static void alc_free_kctls(struct hda_codec *codec)
2884 {
2885         struct alc_spec *spec = codec->spec;
2886
2887         if (spec->kctls.list) {
2888                 struct snd_kcontrol_new *kctl = spec->kctls.list;
2889                 int i;
2890                 for (i = 0; i < spec->kctls.used; i++)
2891                         kfree(kctl[i].name);
2892         }
2893         snd_array_free(&spec->kctls);
2894 }
2895
2896 static void alc_free(struct hda_codec *codec)
2897 {
2898         struct alc_spec *spec = codec->spec;
2899
2900         if (!spec)
2901                 return;
2902
2903         alc_free_kctls(codec);
2904         kfree(spec);
2905         codec->spec = NULL; /* to be sure */
2906 }
2907
2908 #ifdef SND_HDA_NEEDS_RESUME
2909 static void store_pin_configs(struct hda_codec *codec)
2910 {
2911         struct alc_spec *spec = codec->spec;
2912         hda_nid_t nid, end_nid;
2913
2914         end_nid = codec->start_nid + codec->num_nodes;
2915         for (nid = codec->start_nid; nid < end_nid; nid++) {
2916                 unsigned int wid_caps = get_wcaps(codec, nid);
2917                 unsigned int wid_type =
2918                         (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2919                 if (wid_type != AC_WID_PIN)
2920                         continue;
2921                 if (spec->num_pins >= ARRAY_SIZE(spec->pin_nids))
2922                         break;
2923                 spec->pin_nids[spec->num_pins] = nid;
2924                 spec->pin_cfgs[spec->num_pins] =
2925                         snd_hda_codec_read(codec, nid, 0,
2926                                            AC_VERB_GET_CONFIG_DEFAULT, 0);
2927                 spec->num_pins++;
2928         }
2929 }
2930
2931 static void resume_pin_configs(struct hda_codec *codec)
2932 {
2933         struct alc_spec *spec = codec->spec;
2934         int i;
2935
2936         for (i = 0; i < spec->num_pins; i++) {
2937                 hda_nid_t pin_nid = spec->pin_nids[i];
2938                 unsigned int pin_config = spec->pin_cfgs[i];
2939                 snd_hda_codec_write(codec, pin_nid, 0,
2940                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2941                                     pin_config & 0x000000ff);
2942                 snd_hda_codec_write(codec, pin_nid, 0,
2943                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2944                                     (pin_config & 0x0000ff00) >> 8);
2945                 snd_hda_codec_write(codec, pin_nid, 0,
2946                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2947                                     (pin_config & 0x00ff0000) >> 16);
2948                 snd_hda_codec_write(codec, pin_nid, 0,
2949                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2950                                     pin_config >> 24);
2951         }
2952 }
2953
2954 static int alc_resume(struct hda_codec *codec)
2955 {
2956         resume_pin_configs(codec);
2957         codec->patch_ops.init(codec);
2958         snd_hda_codec_resume_amp(codec);
2959         snd_hda_codec_resume_cache(codec);
2960         return 0;
2961 }
2962 #else
2963 #define store_pin_configs(codec)
2964 #endif
2965
2966 /*
2967  */
2968 static struct hda_codec_ops alc_patch_ops = {
2969         .build_controls = alc_build_controls,
2970         .build_pcms = alc_build_pcms,
2971         .init = alc_init,
2972         .free = alc_free,
2973         .unsol_event = alc_unsol_event,
2974 #ifdef SND_HDA_NEEDS_RESUME
2975         .resume = alc_resume,
2976 #endif
2977 #ifdef CONFIG_SND_HDA_POWER_SAVE
2978         .check_power_status = alc_check_power_status,
2979 #endif
2980 };
2981
2982
2983 /*
2984  * Test configuration for debugging
2985  *
2986  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2987  * enum controls.
2988  */
2989 #ifdef CONFIG_SND_DEBUG
2990 static hda_nid_t alc880_test_dac_nids[4] = {
2991         0x02, 0x03, 0x04, 0x05
2992 };
2993
2994 static struct hda_input_mux alc880_test_capture_source = {
2995         .num_items = 7,
2996         .items = {
2997                 { "In-1", 0x0 },
2998                 { "In-2", 0x1 },
2999                 { "In-3", 0x2 },
3000                 { "In-4", 0x3 },
3001                 { "CD", 0x4 },
3002                 { "Front", 0x5 },
3003                 { "Surround", 0x6 },
3004         },
3005 };
3006
3007 static struct hda_channel_mode alc880_test_modes[4] = {
3008         { 2, NULL },
3009         { 4, NULL },
3010         { 6, NULL },
3011         { 8, NULL },
3012 };
3013
3014 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3015                                  struct snd_ctl_elem_info *uinfo)
3016 {
3017         static char *texts[] = {
3018                 "N/A", "Line Out", "HP Out",
3019                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3020         };
3021         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3022         uinfo->count = 1;
3023         uinfo->value.enumerated.items = 8;
3024         if (uinfo->value.enumerated.item >= 8)
3025                 uinfo->value.enumerated.item = 7;
3026         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3027         return 0;
3028 }
3029
3030 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3031                                 struct snd_ctl_elem_value *ucontrol)
3032 {
3033         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3034         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3035         unsigned int pin_ctl, item = 0;
3036
3037         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3038                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3039         if (pin_ctl & AC_PINCTL_OUT_EN) {
3040                 if (pin_ctl & AC_PINCTL_HP_EN)
3041                         item = 2;
3042                 else
3043                         item = 1;
3044         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3045                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3046                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3047                 case AC_PINCTL_VREF_50:  item = 4; break;
3048                 case AC_PINCTL_VREF_GRD: item = 5; break;
3049                 case AC_PINCTL_VREF_80:  item = 6; break;
3050                 case AC_PINCTL_VREF_100: item = 7; break;
3051                 }
3052         }
3053         ucontrol->value.enumerated.item[0] = item;
3054         return 0;
3055 }
3056
3057 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3058                                 struct snd_ctl_elem_value *ucontrol)
3059 {
3060         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3061         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3062         static unsigned int ctls[] = {
3063                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3064                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3065                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3066                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3067                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3068                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3069         };
3070         unsigned int old_ctl, new_ctl;
3071
3072         old_ctl = snd_hda_codec_read(codec, nid, 0,
3073                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3074         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3075         if (old_ctl != new_ctl) {
3076                 int val;
3077                 snd_hda_codec_write_cache(codec, nid, 0,
3078                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3079                                           new_ctl);
3080                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3081                         HDA_AMP_MUTE : 0;
3082                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3083                                          HDA_AMP_MUTE, val);
3084                 return 1;
3085         }
3086         return 0;
3087 }
3088
3089 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3090                                  struct snd_ctl_elem_info *uinfo)
3091 {
3092         static char *texts[] = {
3093                 "Front", "Surround", "CLFE", "Side"
3094         };
3095         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3096         uinfo->count = 1;
3097         uinfo->value.enumerated.items = 4;
3098         if (uinfo->value.enumerated.item >= 4)
3099                 uinfo->value.enumerated.item = 3;
3100         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3101         return 0;
3102 }
3103
3104 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3105                                 struct snd_ctl_elem_value *ucontrol)
3106 {
3107         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3108         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3109         unsigned int sel;
3110
3111         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3112         ucontrol->value.enumerated.item[0] = sel & 3;
3113         return 0;
3114 }
3115
3116 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3117                                 struct snd_ctl_elem_value *ucontrol)
3118 {
3119         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3120         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3121         unsigned int sel;
3122
3123         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3124         if (ucontrol->value.enumerated.item[0] != sel) {
3125                 sel = ucontrol->value.enumerated.item[0] & 3;
3126                 snd_hda_codec_write_cache(codec, nid, 0,
3127                                           AC_VERB_SET_CONNECT_SEL, sel);
3128                 return 1;
3129         }
3130         return 0;
3131 }
3132
3133 #define PIN_CTL_TEST(xname,nid) {                       \
3134                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3135                         .name = xname,                 \
3136                         .info = alc_test_pin_ctl_info, \
3137                         .get = alc_test_pin_ctl_get,   \
3138                         .put = alc_test_pin_ctl_put,   \
3139                         .private_value = nid           \
3140                         }
3141
3142 #define PIN_SRC_TEST(xname,nid) {                       \
3143                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3144                         .name = xname,                 \
3145                         .info = alc_test_pin_src_info, \
3146                         .get = alc_test_pin_src_get,   \
3147                         .put = alc_test_pin_src_put,   \
3148                         .private_value = nid           \
3149                         }
3150
3151 static struct snd_kcontrol_new alc880_test_mixer[] = {
3152         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3153         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3154         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3155         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3156         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3157         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3158         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3159         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3160         PIN_CTL_TEST("Front Pin Mode", 0x14),
3161         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3162         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3163         PIN_CTL_TEST("Side Pin Mode", 0x17),
3164         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3165         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3166         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3167         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3168         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3169         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3170         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3171         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3172         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3173         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3174         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3175         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3176         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3177         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3178         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3179         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3180         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3181         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3182         {
3183                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3184                 .name = "Channel Mode",
3185                 .info = alc_ch_mode_info,
3186                 .get = alc_ch_mode_get,
3187                 .put = alc_ch_mode_put,
3188         },
3189         { } /* end */
3190 };
3191
3192 static struct hda_verb alc880_test_init_verbs[] = {
3193         /* Unmute inputs of 0x0c - 0x0f */
3194         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3195         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3196         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3197         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3198         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3199         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3200         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3201         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3202         /* Vol output for 0x0c-0x0f */
3203         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3204         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3205         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3206         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3207         /* Set output pins 0x14-0x17 */
3208         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3209         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3210         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3211         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3212         /* Unmute output pins 0x14-0x17 */
3213         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3214         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3215         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3216         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3217         /* Set input pins 0x18-0x1c */
3218         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3219         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3220         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3221         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3222         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3223         /* Mute input pins 0x18-0x1b */
3224         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3225         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3226         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3227         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3228         /* ADC set up */
3229         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3230         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3231         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3232         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3233         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3234         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3235         /* Analog input/passthru */
3236         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3237         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3238         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3239         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3240         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3241         { }
3242 };
3243 #endif
3244
3245 /*
3246  */
3247
3248 static const char *alc880_models[ALC880_MODEL_LAST] = {
3249         [ALC880_3ST]            = "3stack",
3250         [ALC880_TCL_S700]       = "tcl",
3251         [ALC880_3ST_DIG]        = "3stack-digout",
3252         [ALC880_CLEVO]          = "clevo",
3253         [ALC880_5ST]            = "5stack",
3254         [ALC880_5ST_DIG]        = "5stack-digout",
3255         [ALC880_W810]           = "w810",
3256         [ALC880_Z71V]           = "z71v",
3257         [ALC880_6ST]            = "6stack",
3258         [ALC880_6ST_DIG]        = "6stack-digout",
3259         [ALC880_ASUS]           = "asus",
3260         [ALC880_ASUS_W1V]       = "asus-w1v",
3261         [ALC880_ASUS_DIG]       = "asus-dig",
3262         [ALC880_ASUS_DIG2]      = "asus-dig2",
3263         [ALC880_UNIWILL_DIG]    = "uniwill",
3264         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3265         [ALC880_FUJITSU]        = "fujitsu",
3266         [ALC880_F1734]          = "F1734",
3267         [ALC880_LG]             = "lg",
3268         [ALC880_LG_LW]          = "lg-lw",
3269         [ALC880_MEDION_RIM]     = "medion",
3270 #ifdef CONFIG_SND_DEBUG
3271         [ALC880_TEST]           = "test",
3272 #endif
3273         [ALC880_AUTO]           = "auto",
3274 };
3275
3276 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3277         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3278         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3279         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3280         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3281         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3282         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3283         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3284         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3285         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3286         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3287         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3288         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3289         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3290         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3291         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3292         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3293         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3294         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3295         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3296         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3297         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3298         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3299         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3300         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3301         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3302         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3303         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3304         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3305         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3306         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3307         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3308         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3309         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3310         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3311         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3312         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3313         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3314         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3315         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3316         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3317         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3318         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3319         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3320         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3321         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3322         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3323         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3324         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3325         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3326         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3327         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3328         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3329         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3330         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3331         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3332         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3333         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3334         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3335         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3336         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3337         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3338         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3339         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3340         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3341         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3342         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3343         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3344         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3345         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3346         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3347         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3348         {}
3349 };
3350
3351 /*
3352  * ALC880 codec presets
3353  */
3354 static struct alc_config_preset alc880_presets[] = {
3355         [ALC880_3ST] = {
3356                 .mixers = { alc880_three_stack_mixer },
3357                 .init_verbs = { alc880_volume_init_verbs,
3358                                 alc880_pin_3stack_init_verbs },
3359                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3360                 .dac_nids = alc880_dac_nids,
3361                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3362                 .channel_mode = alc880_threestack_modes,
3363                 .need_dac_fix = 1,
3364                 .input_mux = &alc880_capture_source,
3365         },
3366         [ALC880_3ST_DIG] = {
3367                 .mixers = { alc880_three_stack_mixer },
3368                 .init_verbs = { alc880_volume_init_verbs,
3369                                 alc880_pin_3stack_init_verbs },
3370                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3371                 .dac_nids = alc880_dac_nids,
3372                 .dig_out_nid = ALC880_DIGOUT_NID,
3373                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3374                 .channel_mode = alc880_threestack_modes,
3375                 .need_dac_fix = 1,
3376                 .input_mux = &alc880_capture_source,
3377         },
3378         [ALC880_TCL_S700] = {
3379                 .mixers = { alc880_tcl_s700_mixer },
3380                 .init_verbs = { alc880_volume_init_verbs,
3381                                 alc880_pin_tcl_S700_init_verbs,
3382                                 alc880_gpio2_init_verbs },
3383                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3384                 .dac_nids = alc880_dac_nids,
3385                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3386                 .num_adc_nids = 1, /* single ADC */
3387                 .hp_nid = 0x03,
3388                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3389                 .channel_mode = alc880_2_jack_modes,
3390                 .input_mux = &alc880_capture_source,
3391         },
3392         [ALC880_5ST] = {
3393                 .mixers = { alc880_three_stack_mixer,
3394                             alc880_five_stack_mixer},
3395                 .init_verbs = { alc880_volume_init_verbs,
3396                                 alc880_pin_5stack_init_verbs },
3397                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3398                 .dac_nids = alc880_dac_nids,
3399                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3400                 .channel_mode = alc880_fivestack_modes,
3401                 .input_mux = &alc880_capture_source,
3402         },
3403         [ALC880_5ST_DIG] = {
3404                 .mixers = { alc880_three_stack_mixer,
3405                             alc880_five_stack_mixer },
3406                 .init_verbs = { alc880_volume_init_verbs,
3407                                 alc880_pin_5stack_init_verbs },
3408                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3409                 .dac_nids = alc880_dac_nids,
3410                 .dig_out_nid = ALC880_DIGOUT_NID,
3411                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3412                 .channel_mode = alc880_fivestack_modes,
3413                 .input_mux = &alc880_capture_source,
3414         },
3415         [ALC880_6ST] = {
3416                 .mixers = { alc880_six_stack_mixer },
3417                 .init_verbs = { alc880_volume_init_verbs,
3418                                 alc880_pin_6stack_init_verbs },
3419                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3420                 .dac_nids = alc880_6st_dac_nids,
3421                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3422                 .channel_mode = alc880_sixstack_modes,
3423                 .input_mux = &alc880_6stack_capture_source,
3424         },
3425         [ALC880_6ST_DIG] = {
3426                 .mixers = { alc880_six_stack_mixer },
3427                 .init_verbs = { alc880_volume_init_verbs,
3428                                 alc880_pin_6stack_init_verbs },
3429                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3430                 .dac_nids = alc880_6st_dac_nids,
3431                 .dig_out_nid = ALC880_DIGOUT_NID,
3432                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3433                 .channel_mode = alc880_sixstack_modes,
3434                 .input_mux = &alc880_6stack_capture_source,
3435         },
3436         [ALC880_W810] = {
3437                 .mixers = { alc880_w810_base_mixer },
3438                 .init_verbs = { alc880_volume_init_verbs,
3439                                 alc880_pin_w810_init_verbs,
3440                                 alc880_gpio2_init_verbs },
3441                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3442                 .dac_nids = alc880_w810_dac_nids,
3443                 .dig_out_nid = ALC880_DIGOUT_NID,
3444                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3445                 .channel_mode = alc880_w810_modes,
3446                 .input_mux = &alc880_capture_source,
3447         },
3448         [ALC880_Z71V] = {
3449                 .mixers = { alc880_z71v_mixer },
3450                 .init_verbs = { alc880_volume_init_verbs,
3451                                 alc880_pin_z71v_init_verbs },
3452                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3453                 .dac_nids = alc880_z71v_dac_nids,
3454                 .dig_out_nid = ALC880_DIGOUT_NID,
3455                 .hp_nid = 0x03,
3456                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3457                 .channel_mode = alc880_2_jack_modes,
3458                 .input_mux = &alc880_capture_source,
3459         },
3460         [ALC880_F1734] = {
3461                 .mixers = { alc880_f1734_mixer },
3462                 .init_verbs = { alc880_volume_init_verbs,
3463                                 alc880_pin_f1734_init_verbs },
3464                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3465                 .dac_nids = alc880_f1734_dac_nids,
3466                 .hp_nid = 0x02,
3467                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3468                 .channel_mode = alc880_2_jack_modes,
3469                 .input_mux = &alc880_f1734_capture_source,
3470                 .unsol_event = alc880_uniwill_p53_unsol_event,
3471                 .init_hook = alc880_uniwill_p53_hp_automute,
3472         },
3473         [ALC880_ASUS] = {
3474                 .mixers = { alc880_asus_mixer },
3475                 .init_verbs = { alc880_volume_init_verbs,
3476                                 alc880_pin_asus_init_verbs,
3477                                 alc880_gpio1_init_verbs },
3478                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3479                 .dac_nids = alc880_asus_dac_nids,
3480                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3481                 .channel_mode = alc880_asus_modes,
3482                 .need_dac_fix = 1,
3483                 .input_mux = &alc880_capture_source,
3484         },
3485         [ALC880_ASUS_DIG] = {
3486                 .mixers = { alc880_asus_mixer },
3487                 .init_verbs = { alc880_volume_init_verbs,
3488                                 alc880_pin_asus_init_verbs,
3489                                 alc880_gpio1_init_verbs },
3490                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3491                 .dac_nids = alc880_asus_dac_nids,
3492                 .dig_out_nid = ALC880_DIGOUT_NID,
3493                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3494                 .channel_mode = alc880_asus_modes,
3495                 .need_dac_fix = 1,
3496                 .input_mux = &alc880_capture_source,
3497         },
3498         [ALC880_ASUS_DIG2] = {
3499                 .mixers = { alc880_asus_mixer },
3500                 .init_verbs = { alc880_volume_init_verbs,
3501                                 alc880_pin_asus_init_verbs,
3502                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3503                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3504                 .dac_nids = alc880_asus_dac_nids,
3505                 .dig_out_nid = ALC880_DIGOUT_NID,
3506                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3507                 .channel_mode = alc880_asus_modes,
3508                 .need_dac_fix = 1,
3509                 .input_mux = &alc880_capture_source,
3510         },
3511         [ALC880_ASUS_W1V] = {
3512                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3513                 .init_verbs = { alc880_volume_init_verbs,
3514                                 alc880_pin_asus_init_verbs,
3515                                 alc880_gpio1_init_verbs },
3516                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3517                 .dac_nids = alc880_asus_dac_nids,
3518                 .dig_out_nid = ALC880_DIGOUT_NID,
3519                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3520                 .channel_mode = alc880_asus_modes,
3521                 .need_dac_fix = 1,
3522                 .input_mux = &alc880_capture_source,
3523         },
3524         [ALC880_UNIWILL_DIG] = {
3525                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3526                 .init_verbs = { alc880_volume_init_verbs,
3527                                 alc880_pin_asus_init_verbs },
3528                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3529                 .dac_nids = alc880_asus_dac_nids,
3530                 .dig_out_nid = ALC880_DIGOUT_NID,
3531                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3532                 .channel_mode = alc880_asus_modes,
3533                 .need_dac_fix = 1,
3534                 .input_mux = &alc880_capture_source,
3535         },
3536         [ALC880_UNIWILL] = {
3537                 .mixers = { alc880_uniwill_mixer },
3538                 .init_verbs = { alc880_volume_init_verbs,
3539                                 alc880_uniwill_init_verbs },
3540                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3541                 .dac_nids = alc880_asus_dac_nids,
3542                 .dig_out_nid = ALC880_DIGOUT_NID,
3543                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3544                 .channel_mode = alc880_threestack_modes,
3545                 .need_dac_fix = 1,
3546                 .input_mux = &alc880_capture_source,
3547                 .unsol_event = alc880_uniwill_unsol_event,
3548                 .init_hook = alc880_uniwill_automute,
3549         },
3550         [ALC880_UNIWILL_P53] = {
3551                 .mixers = { alc880_uniwill_p53_mixer },
3552                 .init_verbs = { alc880_volume_init_verbs,
3553                                 alc880_uniwill_p53_init_verbs },
3554                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3555                 .dac_nids = alc880_asus_dac_nids,
3556                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3557                 .channel_mode = alc880_threestack_modes,
3558                 .input_mux = &alc880_capture_source,
3559                 .unsol_event = alc880_uniwill_p53_unsol_event,
3560                 .init_hook = alc880_uniwill_p53_hp_automute,
3561         },
3562         [ALC880_FUJITSU] = {
3563                 .mixers = { alc880_fujitsu_mixer,
3564                             alc880_pcbeep_mixer, },
3565                 .init_verbs = { alc880_volume_init_verbs,
3566                                 alc880_uniwill_p53_init_verbs,
3567                                 alc880_beep_init_verbs },
3568                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3569                 .dac_nids = alc880_dac_nids,
3570                 .dig_out_nid = ALC880_DIGOUT_NID,
3571                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3572                 .channel_mode = alc880_2_jack_modes,
3573                 .input_mux = &alc880_capture_source,
3574                 .unsol_event = alc880_uniwill_p53_unsol_event,
3575                 .init_hook = alc880_uniwill_p53_hp_automute,
3576         },
3577         [ALC880_CLEVO] = {
3578                 .mixers = { alc880_three_stack_mixer },
3579                 .init_verbs = { alc880_volume_init_verbs,
3580                                 alc880_pin_clevo_init_verbs },
3581                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3582                 .dac_nids = alc880_dac_nids,
3583                 .hp_nid = 0x03,
3584                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3585                 .channel_mode = alc880_threestack_modes,
3586                 .need_dac_fix = 1,
3587                 .input_mux = &alc880_capture_source,
3588         },
3589         [ALC880_LG] = {
3590                 .mixers = { alc880_lg_mixer },
3591                 .init_verbs = { alc880_volume_init_verbs,
3592                                 alc880_lg_init_verbs },
3593                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3594                 .dac_nids = alc880_lg_dac_nids,
3595                 .dig_out_nid = ALC880_DIGOUT_NID,
3596                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3597                 .channel_mode = alc880_lg_ch_modes,
3598                 .need_dac_fix = 1,
3599                 .input_mux = &alc880_lg_capture_source,
3600                 .unsol_event = alc880_lg_unsol_event,
3601                 .init_hook = alc880_lg_automute,
3602 #ifdef CONFIG_SND_HDA_POWER_SAVE
3603                 .loopbacks = alc880_lg_loopbacks,
3604 #endif
3605         },
3606         [ALC880_LG_LW] = {
3607                 .mixers = { alc880_lg_lw_mixer },
3608                 .init_verbs = { alc880_volume_init_verbs,
3609                                 alc880_lg_lw_init_verbs },
3610                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3611                 .dac_nids = alc880_dac_nids,
3612                 .dig_out_nid = ALC880_DIGOUT_NID,
3613                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3614                 .channel_mode = alc880_lg_lw_modes,
3615                 .input_mux = &alc880_lg_lw_capture_source,
3616                 .unsol_event = alc880_lg_lw_unsol_event,
3617                 .init_hook = alc880_lg_lw_automute,
3618         },
3619         [ALC880_MEDION_RIM] = {
3620                 .mixers = { alc880_medion_rim_mixer },
3621                 .init_verbs = { alc880_volume_init_verbs,
3622                                 alc880_medion_rim_init_verbs,
3623                                 alc_gpio2_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_2_jack_modes),
3628                 .channel_mode = alc880_2_jack_modes,
3629                 .input_mux = &alc880_medion_rim_capture_source,
3630                 .unsol_event = alc880_medion_rim_unsol_event,
3631                 .init_hook = alc880_medion_rim_automute,
3632         },
3633 #ifdef CONFIG_SND_DEBUG
3634         [ALC880_TEST] = {
3635                 .mixers = { alc880_test_mixer },
3636                 .init_verbs = { alc880_test_init_verbs },
3637                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3638                 .dac_nids = alc880_test_dac_nids,
3639                 .dig_out_nid = ALC880_DIGOUT_NID,
3640                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3641                 .channel_mode = alc880_test_modes,
3642                 .input_mux = &alc880_test_capture_source,
3643         },
3644 #endif
3645 };
3646
3647 /*
3648  * Automatic parse of I/O pins from the BIOS configuration
3649  */
3650
3651 enum {
3652         ALC_CTL_WIDGET_VOL,
3653         ALC_CTL_WIDGET_MUTE,
3654         ALC_CTL_BIND_MUTE,
3655 };
3656 static struct snd_kcontrol_new alc880_control_templates[] = {
3657         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3658         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3659         HDA_BIND_MUTE(NULL, 0, 0, 0),
3660 };
3661
3662 /* add dynamic controls */
3663 static int add_control(struct alc_spec *spec, int type, const char *name,
3664                        unsigned long val)
3665 {
3666         struct snd_kcontrol_new *knew;
3667
3668         snd_array_init(&spec->kctls, sizeof(*knew), 32);
3669         knew = snd_array_new(&spec->kctls);
3670         if (!knew)
3671                 return -ENOMEM;
3672         *knew = alc880_control_templates[type];
3673         knew->name = kstrdup(name, GFP_KERNEL);
3674         if (!knew->name)
3675                 return -ENOMEM;
3676         knew->private_value = val;
3677         return 0;
3678 }
3679
3680 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3681 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3682 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3683 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3684 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3685 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3686 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3687 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3688 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3689 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3690 #define ALC880_PIN_CD_NID               0x1c
3691
3692 /* fill in the dac_nids table from the parsed pin configuration */
3693 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3694                                      const struct auto_pin_cfg *cfg)
3695 {
3696         hda_nid_t nid;
3697         int assigned[4];
3698         int i, j;
3699
3700         memset(assigned, 0, sizeof(assigned));
3701         spec->multiout.dac_nids = spec->private_dac_nids;
3702
3703         /* check the pins hardwired to audio widget */
3704         for (i = 0; i < cfg->line_outs; i++) {
3705                 nid = cfg->line_out_pins[i];
3706                 if (alc880_is_fixed_pin(nid)) {
3707                         int idx = alc880_fixed_pin_idx(nid);
3708                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3709                         assigned[idx] = 1;
3710                 }
3711         }
3712         /* left pins can be connect to any audio widget */
3713         for (i = 0; i < cfg->line_outs; i++) {
3714                 nid = cfg->line_out_pins[i];
3715                 if (alc880_is_fixed_pin(nid))
3716                         continue;
3717                 /* search for an empty channel */
3718                 for (j = 0; j < cfg->line_outs; j++) {
3719                         if (!assigned[j]) {
3720                                 spec->multiout.dac_nids[i] =
3721                                         alc880_idx_to_dac(j);
3722                                 assigned[j] = 1;
3723                                 break;
3724                         }
3725                 }
3726         }
3727         spec->multiout.num_dacs = cfg->line_outs;
3728         return 0;
3729 }
3730
3731 /* add playback controls from the parsed DAC table */
3732 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3733                                              const struct auto_pin_cfg *cfg)
3734 {
3735         char name[32];
3736         static const char *chname[4] = {
3737                 "Front", "Surround", NULL /*CLFE*/, "Side"
3738         };
3739         hda_nid_t nid;
3740         int i, err;
3741
3742         for (i = 0; i < cfg->line_outs; i++) {
3743                 if (!spec->multiout.dac_nids[i])
3744                         continue;
3745                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3746                 if (i == 2) {
3747                         /* Center/LFE */
3748                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3749                                           "Center Playback Volume",
3750                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3751                                                               HDA_OUTPUT));
3752                         if (err < 0)
3753                                 return err;
3754                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3755                                           "LFE Playback Volume",
3756                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3757                                                               HDA_OUTPUT));
3758                         if (err < 0)
3759                                 return err;
3760                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3761                                           "Center Playback Switch",
3762                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3763                                                               HDA_INPUT));
3764                         if (err < 0)
3765                                 return err;
3766                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3767                                           "LFE Playback Switch",
3768                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3769                                                               HDA_INPUT));
3770                         if (err < 0)
3771                                 return err;
3772                 } else {
3773                         sprintf(name, "%s Playback Volume", chname[i]);
3774                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3775                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3776                                                               HDA_OUTPUT));
3777                         if (err < 0)
3778                                 return err;
3779                         sprintf(name, "%s Playback Switch", chname[i]);
3780                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3781                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3782                                                               HDA_INPUT));
3783                         if (err < 0)
3784                                 return err;
3785                 }
3786         }
3787         return 0;
3788 }
3789
3790 /* add playback controls for speaker and HP outputs */
3791 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3792                                         const char *pfx)
3793 {
3794         hda_nid_t nid;
3795         int err;
3796         char name[32];
3797
3798         if (!pin)
3799                 return 0;
3800
3801         if (alc880_is_fixed_pin(pin)) {
3802                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3803                 /* specify the DAC as the extra output */
3804                 if (!spec->multiout.hp_nid)
3805                         spec->multiout.hp_nid = nid;
3806                 else
3807                         spec->multiout.extra_out_nid[0] = nid;
3808                 /* control HP volume/switch on the output mixer amp */
3809                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3810                 sprintf(name, "%s Playback Volume", pfx);
3811                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3812                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3813                 if (err < 0)
3814                         return err;
3815                 sprintf(name, "%s Playback Switch", pfx);
3816                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3817                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3818                 if (err < 0)
3819                         return err;
3820         } else if (alc880_is_multi_pin(pin)) {
3821                 /* set manual connection */
3822                 /* we have only a switch on HP-out PIN */
3823                 sprintf(name, "%s Playback Switch", pfx);
3824                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3825                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3826                 if (err < 0)
3827                         return err;
3828         }
3829         return 0;
3830 }
3831
3832 /* create input playback/capture controls for the given pin */
3833 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3834                             const char *ctlname,
3835                             int idx, hda_nid_t mix_nid)
3836 {
3837         char name[32];
3838         int err;
3839
3840         sprintf(name, "%s Playback Volume", ctlname);
3841         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3842                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3843         if (err < 0)
3844                 return err;
3845         sprintf(name, "%s Playback Switch", ctlname);
3846         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3847                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3848         if (err < 0)
3849                 return err;
3850         return 0;
3851 }
3852
3853 /* create playback/capture controls for input pins */
3854 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3855                                                 const struct auto_pin_cfg *cfg)
3856 {
3857         struct hda_input_mux *imux = &spec->private_imux;
3858         int i, err, idx;
3859
3860         for (i = 0; i < AUTO_PIN_LAST; i++) {
3861                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3862                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3863                         err = new_analog_input(spec, cfg->input_pins[i],
3864                                                auto_pin_cfg_labels[i],
3865                                                idx, 0x0b);
3866                         if (err < 0)
3867                                 return err;
3868                         imux->items[imux->num_items].label =
3869                                 auto_pin_cfg_labels[i];
3870                         imux->items[imux->num_items].index =
3871                                 alc880_input_pin_idx(cfg->input_pins[i]);
3872                         imux->num_items++;
3873                 }
3874         }
3875         return 0;
3876 }
3877
3878 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3879                                unsigned int pin_type)
3880 {
3881         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3882                             pin_type);
3883         /* unmute pin */
3884         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3885                             AMP_OUT_UNMUTE);
3886 }
3887
3888 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3889                                               hda_nid_t nid, int pin_type,
3890                                               int dac_idx)
3891 {
3892         alc_set_pin_output(codec, nid, pin_type);
3893         /* need the manual connection? */
3894         if (alc880_is_multi_pin(nid)) {
3895                 struct alc_spec *spec = codec->spec;
3896                 int idx = alc880_multi_pin_idx(nid);
3897                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3898                                     AC_VERB_SET_CONNECT_SEL,
3899                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3900         }
3901 }
3902
3903 static int get_pin_type(int line_out_type)
3904 {
3905         if (line_out_type == AUTO_PIN_HP_OUT)
3906                 return PIN_HP;
3907         else
3908                 return PIN_OUT;
3909 }
3910
3911 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3912 {
3913         struct alc_spec *spec = codec->spec;
3914         int i;
3915
3916         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3917         for (i = 0; i < spec->autocfg.line_outs; i++) {
3918                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3919                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3920                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3921         }
3922 }
3923
3924 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3925 {
3926         struct alc_spec *spec = codec->spec;
3927         hda_nid_t pin;
3928
3929         pin = spec->autocfg.speaker_pins[0];
3930         if (pin) /* connect to front */
3931                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3932         pin = spec->autocfg.hp_pins[0];
3933         if (pin) /* connect to front */
3934                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3935 }
3936
3937 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3938 {
3939         struct alc_spec *spec = codec->spec;
3940         int i;
3941
3942         for (i = 0; i < AUTO_PIN_LAST; i++) {
3943                 hda_nid_t nid = spec->autocfg.input_pins[i];
3944                 if (alc880_is_input_pin(nid)) {
3945                         snd_hda_codec_write(codec, nid, 0,
3946                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3947                                             i <= AUTO_PIN_FRONT_MIC ?
3948                                             PIN_VREF80 : PIN_IN);
3949                         if (nid != ALC880_PIN_CD_NID)
3950                                 snd_hda_codec_write(codec, nid, 0,
3951                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3952                                                     AMP_OUT_MUTE);
3953                 }
3954         }
3955 }
3956
3957 /* parse the BIOS configuration and set up the alc_spec */
3958 /* return 1 if successful, 0 if the proper config is not found,
3959  * or a negative error code
3960  */
3961 static int alc880_parse_auto_config(struct hda_codec *codec)
3962 {
3963         struct alc_spec *spec = codec->spec;
3964         int err;
3965         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3966
3967         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3968                                            alc880_ignore);
3969         if (err < 0)
3970                 return err;
3971         if (!spec->autocfg.line_outs)
3972                 return 0; /* can't find valid BIOS pin config */
3973
3974         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3975         if (err < 0)
3976                 return err;
3977         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3978         if (err < 0)
3979                 return err;
3980         err = alc880_auto_create_extra_out(spec,
3981                                            spec->autocfg.speaker_pins[0],
3982                                            "Speaker");
3983         if (err < 0)
3984                 return err;
3985         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3986                                            "Headphone");
3987         if (err < 0)
3988                 return err;
3989         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3990         if (err < 0)
3991                 return err;
3992
3993         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3994
3995         if (spec->autocfg.dig_out_pin)
3996                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3997         if (spec->autocfg.dig_in_pin)
3998                 spec->dig_in_nid = ALC880_DIGIN_NID;
3999
4000         if (spec->kctls.list)
4001                 add_mixer(spec, spec->kctls.list);
4002
4003         add_verb(spec, alc880_volume_init_verbs);
4004
4005         spec->num_mux_defs = 1;
4006         spec->input_mux = &spec->private_imux;
4007
4008         store_pin_configs(codec);
4009         return 1;
4010 }
4011
4012 /* additional initialization for auto-configuration model */
4013 static void alc880_auto_init(struct hda_codec *codec)
4014 {
4015         struct alc_spec *spec = codec->spec;
4016         alc880_auto_init_multi_out(codec);
4017         alc880_auto_init_extra_out(codec);
4018         alc880_auto_init_analog_input(codec);
4019         if (spec->unsol_event)
4020                 alc_inithook(codec);
4021 }
4022
4023 /*
4024  * OK, here we have finally the patch for ALC880
4025  */
4026
4027 static void set_capture_mixer(struct alc_spec *spec)
4028 {
4029         static struct snd_kcontrol_new *caps[3] = {
4030                 alc_capture_mixer1,
4031                 alc_capture_mixer2,
4032                 alc_capture_mixer3,
4033         };
4034         if (spec->num_adc_nids > 0 && spec->num_adc_nids < 3)
4035                 spec->cap_mixer = caps[spec->num_adc_nids - 1];
4036 }
4037
4038 static int patch_alc880(struct hda_codec *codec)
4039 {
4040         struct alc_spec *spec;
4041         int board_config;
4042         int err;
4043
4044         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4045         if (spec == NULL)
4046                 return -ENOMEM;
4047
4048         codec->spec = spec;
4049
4050         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4051                                                   alc880_models,
4052                                                   alc880_cfg_tbl);
4053         if (board_config < 0) {
4054                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
4055                        "trying auto-probe from BIOS...\n");
4056                 board_config = ALC880_AUTO;
4057         }
4058
4059         if (board_config == ALC880_AUTO) {
4060                 /* automatic parse from the BIOS config */
4061                 err = alc880_parse_auto_config(codec);
4062                 if (err < 0) {
4063                         alc_free(codec);
4064                         return err;
4065                 } else if (!err) {
4066                         printk(KERN_INFO
4067                                "hda_codec: Cannot set up configuration "
4068                                "from BIOS.  Using 3-stack mode...\n");
4069                         board_config = ALC880_3ST;
4070                 }
4071         }
4072
4073         if (board_config != ALC880_AUTO)
4074                 setup_preset(spec, &alc880_presets[board_config]);
4075
4076         spec->stream_name_analog = "ALC880 Analog";
4077         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4078         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4079         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4080
4081         spec->stream_name_digital = "ALC880 Digital";
4082         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4083         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4084
4085         if (!spec->adc_nids && spec->input_mux) {
4086                 /* check whether NID 0x07 is valid */
4087                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4088                 /* get type */
4089                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4090                 if (wcap != AC_WID_AUD_IN) {
4091                         spec->adc_nids = alc880_adc_nids_alt;
4092                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4093                 } else {
4094                         spec->adc_nids = alc880_adc_nids;
4095                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4096                 }
4097         }
4098         set_capture_mixer(spec);
4099
4100         spec->vmaster_nid = 0x0c;
4101
4102         codec->patch_ops = alc_patch_ops;
4103         if (board_config == ALC880_AUTO)
4104                 spec->init_hook = alc880_auto_init;
4105 #ifdef CONFIG_SND_HDA_POWER_SAVE
4106         if (!spec->loopback.amplist)
4107                 spec->loopback.amplist = alc880_loopbacks;
4108 #endif
4109
4110         return 0;
4111 }
4112
4113
4114 /*
4115  * ALC260 support
4116  */
4117
4118 static hda_nid_t alc260_dac_nids[1] = {
4119         /* front */
4120         0x02,
4121 };
4122
4123 static hda_nid_t alc260_adc_nids[1] = {
4124         /* ADC0 */
4125         0x04,
4126 };
4127
4128 static hda_nid_t alc260_adc_nids_alt[1] = {
4129         /* ADC1 */
4130         0x05,
4131 };
4132
4133 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4134  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4135  */
4136 static hda_nid_t alc260_dual_adc_nids[2] = {
4137         /* ADC0, ADC1 */
4138         0x04, 0x05
4139 };
4140
4141 #define ALC260_DIGOUT_NID       0x03
4142 #define ALC260_DIGIN_NID        0x06
4143
4144 static struct hda_input_mux alc260_capture_source = {
4145         .num_items = 4,
4146         .items = {
4147                 { "Mic", 0x0 },
4148                 { "Front Mic", 0x1 },
4149                 { "Line", 0x2 },
4150                 { "CD", 0x4 },
4151         },
4152 };
4153
4154 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4155  * headphone jack and the internal CD lines since these are the only pins at
4156  * which audio can appear.  For flexibility, also allow the option of
4157  * recording the mixer output on the second ADC (ADC0 doesn't have a
4158  * connection to the mixer output).
4159  */
4160 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4161         {
4162                 .num_items = 3,
4163                 .items = {
4164                         { "Mic/Line", 0x0 },
4165                         { "CD", 0x4 },
4166                         { "Headphone", 0x2 },
4167                 },
4168         },
4169         {
4170                 .num_items = 4,
4171                 .items = {
4172                         { "Mic/Line", 0x0 },
4173                         { "CD", 0x4 },
4174                         { "Headphone", 0x2 },
4175                         { "Mixer", 0x5 },
4176                 },
4177         },
4178
4179 };
4180
4181 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4182  * the Fujitsu S702x, but jacks are marked differently.
4183  */
4184 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4185         {
4186                 .num_items = 4,
4187                 .items = {
4188                         { "Mic", 0x0 },
4189                         { "Line", 0x2 },
4190                         { "CD", 0x4 },
4191                         { "Headphone", 0x5 },
4192                 },
4193         },
4194         {
4195                 .num_items = 5,
4196                 .items = {
4197                         { "Mic", 0x0 },
4198                         { "Line", 0x2 },
4199                         { "CD", 0x4 },
4200                         { "Headphone", 0x6 },
4201                         { "Mixer", 0x5 },
4202                 },
4203         },
4204 };
4205 /*
4206  * This is just place-holder, so there's something for alc_build_pcms to look
4207  * at when it calculates the maximum number of channels. ALC260 has no mixer
4208  * element which allows changing the channel mode, so the verb list is
4209  * never used.
4210  */
4211 static struct hda_channel_mode alc260_modes[1] = {
4212         { 2, NULL },
4213 };
4214
4215
4216 /* Mixer combinations
4217  *
4218  * basic: base_output + input + pc_beep + capture
4219  * HP: base_output + input + capture_alt
4220  * HP_3013: hp_3013 + input + capture
4221  * fujitsu: fujitsu + capture
4222  * acer: acer + capture
4223  */
4224
4225 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4226         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4227         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4228         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4229         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4230         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4231         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4232         { } /* end */
4233 };
4234
4235 static struct snd_kcontrol_new alc260_input_mixer[] = {
4236         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4237         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4238         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4239         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4240         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4241         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4242         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4243         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4244         { } /* end */
4245 };
4246
4247 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4248         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4249         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4250         { } /* end */
4251 };
4252
4253 /* update HP, line and mono out pins according to the master switch */
4254 static void alc260_hp_master_update(struct hda_codec *codec,
4255                                     hda_nid_t hp, hda_nid_t line,
4256                                     hda_nid_t mono)
4257 {
4258         struct alc_spec *spec = codec->spec;
4259         unsigned int val = spec->master_sw ? PIN_HP : 0;
4260         /* change HP and line-out pins */
4261         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4262                             val);
4263         snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4264                             val);
4265         /* mono (speaker) depending on the HP jack sense */
4266         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4267         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4268                             val);
4269 }
4270
4271 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4272                                    struct snd_ctl_elem_value *ucontrol)
4273 {
4274         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4275         struct alc_spec *spec = codec->spec;
4276         *ucontrol->value.integer.value = spec->master_sw;
4277         return 0;
4278 }
4279
4280 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4281                                    struct snd_ctl_elem_value *ucontrol)
4282 {
4283         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4284         struct alc_spec *spec = codec->spec;
4285         int val = !!*ucontrol->value.integer.value;
4286         hda_nid_t hp, line, mono;
4287
4288         if (val == spec->master_sw)
4289                 return 0;
4290         spec->master_sw = val;
4291         hp = (kcontrol->private_value >> 16) & 0xff;
4292         line = (kcontrol->private_value >> 8) & 0xff;
4293         mono = kcontrol->private_value & 0xff;
4294         alc260_hp_master_update(codec, hp, line, mono);
4295         return 1;
4296 }
4297
4298 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4299         {
4300                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4301                 .name = "Master Playback Switch",
4302                 .info = snd_ctl_boolean_mono_info,
4303                 .get = alc260_hp_master_sw_get,
4304                 .put = alc260_hp_master_sw_put,
4305                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4306         },
4307         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4308         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4309         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4310         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4311         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4312                               HDA_OUTPUT),
4313         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4314         { } /* end */
4315 };
4316
4317 static struct hda_verb alc260_hp_unsol_verbs[] = {
4318         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4319         {},
4320 };
4321
4322 static void alc260_hp_automute(struct hda_codec *codec)
4323 {
4324         struct alc_spec *spec = codec->spec;
4325         unsigned int present;
4326
4327         present = snd_hda_codec_read(codec, 0x10, 0,
4328                                      AC_VERB_GET_PIN_SENSE, 0);
4329         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4330         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4331 }
4332
4333 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4334 {
4335         if ((res >> 26) == ALC880_HP_EVENT)
4336                 alc260_hp_automute(codec);
4337 }
4338
4339 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4340         {
4341                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4342                 .name = "Master Playback Switch",
4343                 .info = snd_ctl_boolean_mono_info,
4344                 .get = alc260_hp_master_sw_get,
4345                 .put = alc260_hp_master_sw_put,
4346                 .private_value = (0x10 << 16) | (0x15 << 8) | 0x11
4347         },
4348         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4349         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4350         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4351         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4352         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4353         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4354         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4355         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4356         { } /* end */
4357 };
4358
4359 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4360         .ops = &snd_hda_bind_vol,
4361         .values = {
4362                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4363                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4364                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4365                 0
4366         },
4367 };
4368
4369 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4370         .ops = &snd_hda_bind_sw,
4371         .values = {
4372                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4373                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4374                 0
4375         },
4376 };
4377
4378 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4379         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4380         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4381         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4382         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4383         { } /* end */
4384 };
4385
4386 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4387         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4388         {},
4389 };
4390
4391 static void alc260_hp_3013_automute(struct hda_codec *codec)
4392 {
4393         struct alc_spec *spec = codec->spec;
4394         unsigned int present;
4395
4396         present = snd_hda_codec_read(codec, 0x15, 0,
4397                                      AC_VERB_GET_PIN_SENSE, 0);
4398         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4399         alc260_hp_master_update(codec, 0x10, 0x15, 0x11);
4400 }
4401
4402 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4403                                        unsigned int res)
4404 {
4405         if ((res >> 26) == ALC880_HP_EVENT)
4406                 alc260_hp_3013_automute(codec);
4407 }
4408
4409 static void alc260_hp_3012_automute(struct hda_codec *codec)
4410 {
4411         unsigned int present, bits;
4412
4413         present = snd_hda_codec_read(codec, 0x10, 0,
4414                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4415
4416         bits = present ? 0 : PIN_OUT;
4417         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4418                             bits);
4419         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4420                             bits);
4421         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4422                             bits);
4423 }
4424
4425 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4426                                        unsigned int res)
4427 {
4428         if ((res >> 26) == ALC880_HP_EVENT)
4429                 alc260_hp_3012_automute(codec);
4430 }
4431
4432 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4433  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4434  */
4435 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4436         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4437         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4438         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4439         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4440         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4441         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4442         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4443         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4444         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4445         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4446         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4447         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4448         { } /* end */
4449 };
4450
4451 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4452  * versions of the ALC260 don't act on requests to enable mic bias from NID
4453  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4454  * datasheet doesn't mention this restriction.  At this stage it's not clear
4455  * whether this behaviour is intentional or is a hardware bug in chip
4456  * revisions available in early 2006.  Therefore for now allow the
4457  * "Headphone Jack Mode" control to span all choices, but if it turns out
4458  * that the lack of mic bias for this NID is intentional we could change the
4459  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4460  *
4461  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4462  * don't appear to make the mic bias available from the "line" jack, even
4463  * though the NID used for this jack (0x14) can supply it.  The theory is
4464  * that perhaps Acer have included blocking capacitors between the ALC260
4465  * and the output jack.  If this turns out to be the case for all such
4466  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4467  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4468  *
4469  * The C20x Tablet series have a mono internal speaker which is controlled
4470  * via the chip's Mono sum widget and pin complex, so include the necessary
4471  * controls for such models.  On models without a "mono speaker" the control
4472  * won't do anything.
4473  */
4474 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4475         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4476         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4477         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4478         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4479                               HDA_OUTPUT),
4480         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4481                            HDA_INPUT),
4482         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4483         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4484         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4485         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4486         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4487         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4488         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4489         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4490         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4491         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4492         { } /* end */
4493 };
4494
4495 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4496  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4497  */
4498 static struct snd_kcontrol_new alc260_will_mixer[] = {
4499         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4500         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4501         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4502         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4503         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4504         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4505         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4506         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4507         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4508         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4509         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4510         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4511         { } /* end */
4512 };
4513
4514 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4515  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4516  */
4517 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4518         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4519         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4520         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4521         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4522         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4523         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4524         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4525         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4526         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4527         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4528         { } /* end */
4529 };
4530
4531 /*
4532  * initialization verbs
4533  */
4534 static struct hda_verb alc260_init_verbs[] = {
4535         /* Line In pin widget for input */
4536         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4537         /* CD pin widget for input */
4538         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4539         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4540         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4541         /* Mic2 (front panel) pin widget for input and vref at 80% */
4542         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4543         /* LINE-2 is used for line-out in rear */
4544         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4545         /* select line-out */
4546         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4547         /* LINE-OUT pin */
4548         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4549         /* enable HP */
4550         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4551         /* enable Mono */
4552         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4553         /* mute capture amp left and right */
4554         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4555         /* set connection select to line in (default select for this ADC) */
4556         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4557         /* mute capture amp left and right */
4558         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4559         /* set connection select to line in (default select for this ADC) */
4560         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4561         /* set vol=0 Line-Out mixer amp left and right */
4562         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4563         /* unmute pin widget amp left and right (no gain on this amp) */
4564         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4565         /* set vol=0 HP mixer amp left and right */
4566         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4567         /* unmute pin widget amp left and right (no gain on this amp) */
4568         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4569         /* set vol=0 Mono mixer amp left and right */
4570         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4571         /* unmute pin widget amp left and right (no gain on this amp) */
4572         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4573         /* unmute LINE-2 out pin */
4574         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4575         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4576          * Line In 2 = 0x03
4577          */
4578         /* mute analog inputs */
4579         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4580         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4581         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4582         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4583         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4584         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4585         /* mute Front out path */
4586         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4587         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4588         /* mute Headphone out path */
4589         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4590         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4591         /* mute Mono out path */
4592         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4593         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4594         { }
4595 };
4596
4597 #if 0 /* should be identical with alc260_init_verbs? */
4598 static struct hda_verb alc260_hp_init_verbs[] = {
4599         /* Headphone and output */
4600         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4601         /* mono output */
4602         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4603         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4604         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4605         /* Mic2 (front panel) pin widget for input and vref at 80% */
4606         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4607         /* Line In pin widget for input */
4608         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4609         /* Line-2 pin widget for output */
4610         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4611         /* CD pin widget for input */
4612         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4613         /* unmute amp left and right */
4614         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4615         /* set connection select to line in (default select for this ADC) */
4616         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4617         /* unmute Line-Out mixer amp left and right (volume = 0) */
4618         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4619         /* mute pin widget amp left and right (no gain on this amp) */
4620         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4621         /* unmute HP mixer amp left and right (volume = 0) */
4622         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4623         /* mute pin widget amp left and right (no gain on this amp) */
4624         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4625         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4626          * Line In 2 = 0x03
4627          */
4628         /* mute analog inputs */
4629         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4630         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4631         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4632         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4633         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4634         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4635         /* Unmute Front out path */
4636         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4637         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4638         /* Unmute Headphone out path */
4639         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4640         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4641         /* Unmute Mono out path */
4642         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4643         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4644         { }
4645 };
4646 #endif
4647
4648 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4649         /* Line out and output */
4650         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4651         /* mono output */
4652         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4653         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4654         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4655         /* Mic2 (front panel) pin widget for input and vref at 80% */
4656         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4657         /* Line In pin widget for input */
4658         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4659         /* Headphone pin widget for output */
4660         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4661         /* CD pin widget for input */
4662         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4663         /* unmute amp left and right */
4664         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4665         /* set connection select to line in (default select for this ADC) */
4666         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4667         /* unmute Line-Out mixer amp left and right (volume = 0) */
4668         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4669         /* mute pin widget amp left and right (no gain on this amp) */
4670         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4671         /* unmute HP mixer amp left and right (volume = 0) */
4672         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4673         /* mute pin widget amp left and right (no gain on this amp) */
4674         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4675         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4676          * Line In 2 = 0x03
4677          */
4678         /* mute analog inputs */
4679         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4680         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4681         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4682         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4683         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4684         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4685         /* Unmute Front out path */
4686         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4687         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4688         /* Unmute Headphone out path */
4689         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4690         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4691         /* Unmute Mono out path */
4692         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4693         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4694         { }
4695 };
4696
4697 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4698  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4699  * audio = 0x16, internal speaker = 0x10.
4700  */
4701 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4702         /* Disable all GPIOs */
4703         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4704         /* Internal speaker is connected to headphone pin */
4705         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4706         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4707         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4708         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4709         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4710         /* Ensure all other unused pins are disabled and muted. */
4711         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4712         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4713         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4714         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4715         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4716         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4717         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4718         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4719
4720         /* Disable digital (SPDIF) pins */
4721         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4722         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4723
4724         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
4725          * when acting as an output.
4726          */
4727         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4728
4729         /* Start with output sum widgets muted and their output gains at min */
4730         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4731         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4732         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4733         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4734         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4735         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4736         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4737         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4738         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4739
4740         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4741         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4742         /* Unmute Line1 pin widget output buffer since it starts as an output.
4743          * If the pin mode is changed by the user the pin mode control will
4744          * take care of enabling the pin's input/output buffers as needed.
4745          * Therefore there's no need to enable the input buffer at this
4746          * stage.
4747          */
4748         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4749         /* Unmute input buffer of pin widget used for Line-in (no equiv
4750          * mixer ctrl)
4751          */
4752         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4753
4754         /* Mute capture amp left and right */
4755         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4756         /* Set ADC connection select to match default mixer setting - line
4757          * in (on mic1 pin)
4758          */
4759         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4760
4761         /* Do the same for the second ADC: mute capture input amp and
4762          * set ADC connection to line in (on mic1 pin)
4763          */
4764         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4765         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4766
4767         /* Mute all inputs to mixer widget (even unconnected ones) */
4768         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4769         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4770         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4771         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4772         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4773         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4774         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4775         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4776
4777         { }
4778 };
4779
4780 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4781  * similar laptops (adapted from Fujitsu init verbs).
4782  */
4783 static struct hda_verb alc260_acer_init_verbs[] = {
4784         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4785          * the headphone jack.  Turn this on and rely on the standard mute
4786          * methods whenever the user wants to turn these outputs off.
4787          */
4788         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4789         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4790         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4791         /* Internal speaker/Headphone jack is connected to Line-out pin */
4792         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4793         /* Internal microphone/Mic jack is connected to Mic1 pin */
4794         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4795         /* Line In jack is connected to Line1 pin */
4796         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4797         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4798         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4799         /* Ensure all other unused pins are disabled and muted. */
4800         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4801         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4802         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4803         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4804         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4805         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4806         /* Disable digital (SPDIF) pins */
4807         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4808         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4809
4810         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
4811          * bus when acting as outputs.
4812          */
4813         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4814         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4815
4816         /* Start with output sum widgets muted and their output gains at min */
4817         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4818         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4819         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4820         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4821         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4822         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4823         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4824         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4825         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4826
4827         /* Unmute Line-out pin widget amp left and right
4828          * (no equiv mixer ctrl)
4829          */
4830         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4831         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4832         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4833         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4834          * inputs. If the pin mode is changed by the user the pin mode control
4835          * will take care of enabling the pin's input/output buffers as needed.
4836          * Therefore there's no need to enable the input buffer at this
4837          * stage.
4838          */
4839         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4840         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4841
4842         /* Mute capture amp left and right */
4843         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4844         /* Set ADC connection select to match default mixer setting - mic
4845          * (on mic1 pin)
4846          */
4847         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4848
4849         /* Do similar with the second ADC: mute capture input amp and
4850          * set ADC connection to mic to match ALSA's default state.
4851          */
4852         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4853         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4854
4855         /* Mute all inputs to mixer widget (even unconnected ones) */
4856         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4857         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4858         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4859         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4860         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4861         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4862         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4863         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4864
4865         { }
4866 };
4867
4868 static struct hda_verb alc260_will_verbs[] = {
4869         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4870         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4871         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4872         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4873         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4874         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4875         {}
4876 };
4877
4878 static struct hda_verb alc260_replacer_672v_verbs[] = {
4879         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4880         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4881         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4882
4883         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4884         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4885         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4886
4887         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4888         {}
4889 };
4890
4891 /* toggle speaker-output according to the hp-jack state */
4892 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4893 {
4894         unsigned int present;
4895
4896         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4897         present = snd_hda_codec_read(codec, 0x0f, 0,
4898                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4899         if (present) {
4900                 snd_hda_codec_write_cache(codec, 0x01, 0,
4901                                           AC_VERB_SET_GPIO_DATA, 1);
4902                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4903                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4904                                           PIN_HP);
4905         } else {
4906                 snd_hda_codec_write_cache(codec, 0x01, 0,
4907                                           AC_VERB_SET_GPIO_DATA, 0);
4908                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4909                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4910                                           PIN_OUT);
4911         }
4912 }
4913
4914 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4915                                        unsigned int res)
4916 {
4917         if ((res >> 26) == ALC880_HP_EVENT)
4918                 alc260_replacer_672v_automute(codec);
4919 }
4920
4921 static struct hda_verb alc260_hp_dc7600_verbs[] = {
4922         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
4923         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
4924         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4925         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4926         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4927         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4928         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4929         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4930         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4931         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4932         {}
4933 };
4934
4935 /* Test configuration for debugging, modelled after the ALC880 test
4936  * configuration.
4937  */
4938 #ifdef CONFIG_SND_DEBUG
4939 static hda_nid_t alc260_test_dac_nids[1] = {
4940         0x02,
4941 };
4942 static hda_nid_t alc260_test_adc_nids[2] = {
4943         0x04, 0x05,
4944 };
4945 /* For testing the ALC260, each input MUX needs its own definition since
4946  * the signal assignments are different.  This assumes that the first ADC
4947  * is NID 0x04.
4948  */
4949 static struct hda_input_mux alc260_test_capture_sources[2] = {
4950         {
4951                 .num_items = 7,
4952                 .items = {
4953                         { "MIC1 pin", 0x0 },
4954                         { "MIC2 pin", 0x1 },
4955                         { "LINE1 pin", 0x2 },
4956                         { "LINE2 pin", 0x3 },
4957                         { "CD pin", 0x4 },
4958                         { "LINE-OUT pin", 0x5 },
4959                         { "HP-OUT pin", 0x6 },
4960                 },
4961         },
4962         {
4963                 .num_items = 8,
4964                 .items = {
4965                         { "MIC1 pin", 0x0 },
4966                         { "MIC2 pin", 0x1 },
4967                         { "LINE1 pin", 0x2 },
4968                         { "LINE2 pin", 0x3 },
4969                         { "CD pin", 0x4 },
4970                         { "Mixer", 0x5 },
4971                         { "LINE-OUT pin", 0x6 },
4972                         { "HP-OUT pin", 0x7 },
4973                 },
4974         },
4975 };
4976 static struct snd_kcontrol_new alc260_test_mixer[] = {
4977         /* Output driver widgets */
4978         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4979         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4980         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4981         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4982         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4983         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4984
4985         /* Modes for retasking pin widgets
4986          * Note: the ALC260 doesn't seem to act on requests to enable mic
4987          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4988          * mention this restriction.  At this stage it's not clear whether
4989          * this behaviour is intentional or is a hardware bug in chip
4990          * revisions available at least up until early 2006.  Therefore for
4991          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4992          * choices, but if it turns out that the lack of mic bias for these
4993          * NIDs is intentional we could change their modes from
4994          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4995          */
4996         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4997         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4998         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4999         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5000         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5001         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5002
5003         /* Loopback mixer controls */
5004         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5005         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5006         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5007         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5008         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5009         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5010         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5011         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5012         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5013         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5014         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
5015         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
5016         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5017         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5018         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5019         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5020
5021         /* Controls for GPIO pins, assuming they are configured as outputs */
5022         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5023         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5024         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5025         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5026
5027         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5028          * is ambigious as to which NID is which; testing on laptops which
5029          * make this output available should provide clarification.
5030          */
5031         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5032         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5033
5034         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5035          * this output to turn on an external amplifier.
5036          */
5037         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5038         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5039
5040         { } /* end */
5041 };
5042 static struct hda_verb alc260_test_init_verbs[] = {
5043         /* Enable all GPIOs as outputs with an initial value of 0 */
5044         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5045         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5046         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5047
5048         /* Enable retasking pins as output, initially without power amp */
5049         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5050         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5051         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5052         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5053         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5054         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5055
5056         /* Disable digital (SPDIF) pins initially, but users can enable
5057          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5058          * payload also sets the generation to 0, output to be in "consumer"
5059          * PCM format, copyright asserted, no pre-emphasis and no validity
5060          * control.
5061          */
5062         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5063         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5064
5065         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5066          * OUT1 sum bus when acting as an output.
5067          */
5068         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5069         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5070         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5071         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5072
5073         /* Start with output sum widgets muted and their output gains at min */
5074         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5075         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5076         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5077         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5078         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5079         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5080         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5081         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5082         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5083
5084         /* Unmute retasking pin widget output buffers since the default
5085          * state appears to be output.  As the pin mode is changed by the
5086          * user the pin mode control will take care of enabling the pin's
5087          * input/output buffers as needed.
5088          */
5089         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5090         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5091         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5092         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5093         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5094         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5095         /* Also unmute the mono-out pin widget */
5096         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5097
5098         /* Mute capture amp left and right */
5099         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5100         /* Set ADC connection select to match default mixer setting (mic1
5101          * pin)
5102          */
5103         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5104
5105         /* Do the same for the second ADC: mute capture input amp and
5106          * set ADC connection to mic1 pin
5107          */
5108         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5109         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5110
5111         /* Mute all inputs to mixer widget (even unconnected ones) */
5112         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5113         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5114         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5115         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5116         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5117         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5118         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5119         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5120
5121         { }
5122 };
5123 #endif
5124
5125 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5126 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5127
5128 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5129 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5130
5131 /*
5132  * for BIOS auto-configuration
5133  */
5134
5135 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5136                                         const char *pfx, int *vol_bits)
5137 {
5138         hda_nid_t nid_vol;
5139         unsigned long vol_val, sw_val;
5140         char name[32];
5141         int err;
5142
5143         if (nid >= 0x0f && nid < 0x11) {
5144                 nid_vol = nid - 0x7;
5145                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5146                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5147         } else if (nid == 0x11) {
5148                 nid_vol = nid - 0x7;
5149                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5150                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5151         } else if (nid >= 0x12 && nid <= 0x15) {
5152                 nid_vol = 0x08;
5153                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5154                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5155         } else
5156                 return 0; /* N/A */
5157
5158         if (!(*vol_bits & (1 << nid_vol))) {
5159                 /* first control for the volume widget */
5160                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5161                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5162                 if (err < 0)
5163                         return err;
5164                 *vol_bits |= (1 << nid_vol);
5165         }
5166         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5167         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5168         if (err < 0)
5169                 return err;
5170         return 1;
5171 }
5172
5173 /* add playback controls from the parsed DAC table */
5174 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5175                                              const struct auto_pin_cfg *cfg)
5176 {
5177         hda_nid_t nid;
5178         int err;
5179         int vols = 0;
5180
5181         spec->multiout.num_dacs = 1;
5182         spec->multiout.dac_nids = spec->private_dac_nids;
5183         spec->multiout.dac_nids[0] = 0x02;
5184
5185         nid = cfg->line_out_pins[0];
5186         if (nid) {
5187                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5188                 if (err < 0)
5189                         return err;
5190         }
5191
5192         nid = cfg->speaker_pins[0];
5193         if (nid) {
5194                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5195                 if (err < 0)
5196                         return err;
5197         }
5198
5199         nid = cfg->hp_pins[0];
5200         if (nid) {
5201                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5202                                                    &vols);
5203                 if (err < 0)
5204                         return err;
5205         }
5206         return 0;
5207 }
5208
5209 /* create playback/capture controls for input pins */
5210 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5211                                                 const struct auto_pin_cfg *cfg)
5212 {
5213         struct hda_input_mux *imux = &spec->private_imux;
5214         int i, err, idx;
5215
5216         for (i = 0; i < AUTO_PIN_LAST; i++) {
5217                 if (cfg->input_pins[i] >= 0x12) {
5218                         idx = cfg->input_pins[i] - 0x12;
5219                         err = new_analog_input(spec, cfg->input_pins[i],
5220                                                auto_pin_cfg_labels[i], idx,
5221                                                0x07);
5222                         if (err < 0)
5223                                 return err;
5224                         imux->items[imux->num_items].label =
5225                                 auto_pin_cfg_labels[i];
5226                         imux->items[imux->num_items].index = idx;
5227                         imux->num_items++;
5228                 }
5229                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5230                         idx = cfg->input_pins[i] - 0x09;
5231                         err = new_analog_input(spec, cfg->input_pins[i],
5232                                                auto_pin_cfg_labels[i], idx,
5233                                                0x07);
5234                         if (err < 0)
5235                                 return err;
5236                         imux->items[imux->num_items].label =
5237                                 auto_pin_cfg_labels[i];
5238                         imux->items[imux->num_items].index = idx;
5239                         imux->num_items++;
5240                 }
5241         }
5242         return 0;
5243 }
5244
5245 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5246                                               hda_nid_t nid, int pin_type,
5247                                               int sel_idx)
5248 {
5249         alc_set_pin_output(codec, nid, pin_type);
5250         /* need the manual connection? */
5251         if (nid >= 0x12) {
5252                 int idx = nid - 0x12;
5253                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5254                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5255         }
5256 }
5257
5258 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5259 {
5260         struct alc_spec *spec = codec->spec;
5261         hda_nid_t nid;
5262
5263         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5264         nid = spec->autocfg.line_out_pins[0];
5265         if (nid) {
5266                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5267                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5268         }
5269
5270         nid = spec->autocfg.speaker_pins[0];
5271         if (nid)
5272                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5273
5274         nid = spec->autocfg.hp_pins[0];
5275         if (nid)
5276                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5277 }
5278
5279 #define ALC260_PIN_CD_NID               0x16
5280 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5281 {
5282         struct alc_spec *spec = codec->spec;
5283         int i;
5284
5285         for (i = 0; i < AUTO_PIN_LAST; i++) {
5286                 hda_nid_t nid = spec->autocfg.input_pins[i];
5287                 if (nid >= 0x12) {
5288                         snd_hda_codec_write(codec, nid, 0,
5289                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5290                                             i <= AUTO_PIN_FRONT_MIC ?
5291                                             PIN_VREF80 : PIN_IN);
5292                         if (nid != ALC260_PIN_CD_NID)
5293                                 snd_hda_codec_write(codec, nid, 0,
5294                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5295                                                     AMP_OUT_MUTE);
5296                 }
5297         }
5298 }
5299
5300 /*
5301  * generic initialization of ADC, input mixers and output mixers
5302  */
5303 static struct hda_verb alc260_volume_init_verbs[] = {
5304         /*
5305          * Unmute ADC0-1 and set the default input to mic-in
5306          */
5307         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5308         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5309         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5310         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5311
5312         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5313          * mixer widget
5314          * Note: PASD motherboards uses the Line In 2 as the input for
5315          * front panel mic (mic 2)
5316          */
5317         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5318         /* mute analog inputs */
5319         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5320         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5321         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5322         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5323         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5324
5325         /*
5326          * Set up output mixers (0x08 - 0x0a)
5327          */
5328         /* set vol=0 to output mixers */
5329         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5330         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5331         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5332         /* set up input amps for analog loopback */
5333         /* Amp Indices: DAC = 0, mixer = 1 */
5334         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5335         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5336         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5337         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5338         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5339         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5340
5341         { }
5342 };
5343
5344 static int alc260_parse_auto_config(struct hda_codec *codec)
5345 {
5346         struct alc_spec *spec = codec->spec;
5347         int err;
5348         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5349
5350         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5351                                            alc260_ignore);
5352         if (err < 0)
5353                 return err;
5354         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5355         if (err < 0)
5356                 return err;
5357         if (!spec->kctls.list)
5358                 return 0; /* can't find valid BIOS pin config */
5359         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5360         if (err < 0)
5361                 return err;
5362
5363         spec->multiout.max_channels = 2;
5364
5365         if (spec->autocfg.dig_out_pin)
5366                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5367         if (spec->kctls.list)
5368                 add_mixer(spec, spec->kctls.list);
5369
5370         add_verb(spec, alc260_volume_init_verbs);
5371
5372         spec->num_mux_defs = 1;
5373         spec->input_mux = &spec->private_imux;
5374
5375         store_pin_configs(codec);
5376         return 1;
5377 }
5378
5379 /* additional initialization for auto-configuration model */
5380 static void alc260_auto_init(struct hda_codec *codec)
5381 {
5382         struct alc_spec *spec = codec->spec;
5383         alc260_auto_init_multi_out(codec);
5384         alc260_auto_init_analog_input(codec);
5385         if (spec->unsol_event)
5386                 alc_inithook(codec);
5387 }
5388
5389 #ifdef CONFIG_SND_HDA_POWER_SAVE
5390 static struct hda_amp_list alc260_loopbacks[] = {
5391         { 0x07, HDA_INPUT, 0 },
5392         { 0x07, HDA_INPUT, 1 },
5393         { 0x07, HDA_INPUT, 2 },
5394         { 0x07, HDA_INPUT, 3 },
5395         { 0x07, HDA_INPUT, 4 },
5396         { } /* end */
5397 };
5398 #endif
5399
5400 /*
5401  * ALC260 configurations
5402  */
5403 static const char *alc260_models[ALC260_MODEL_LAST] = {
5404         [ALC260_BASIC]          = "basic",
5405         [ALC260_HP]             = "hp",
5406         [ALC260_HP_3013]        = "hp-3013",
5407         [ALC260_HP_DC7600]      = "hp-dc7600",
5408         [ALC260_FUJITSU_S702X]  = "fujitsu",
5409         [ALC260_ACER]           = "acer",
5410         [ALC260_WILL]           = "will",
5411         [ALC260_REPLACER_672V]  = "replacer",
5412 #ifdef CONFIG_SND_DEBUG
5413         [ALC260_TEST]           = "test",
5414 #endif
5415         [ALC260_AUTO]           = "auto",
5416 };
5417
5418 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5419         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5420         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5421         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5422         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5423         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5424         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5425         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5426         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5427         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5428         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5429         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5430         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5431         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5432         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5433         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5434         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5435         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5436         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5437         {}
5438 };
5439
5440 static struct alc_config_preset alc260_presets[] = {
5441         [ALC260_BASIC] = {
5442                 .mixers = { alc260_base_output_mixer,
5443                             alc260_input_mixer,
5444                             alc260_pc_beep_mixer },
5445                 .init_verbs = { alc260_init_verbs },
5446                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5447                 .dac_nids = alc260_dac_nids,
5448                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5449                 .adc_nids = alc260_adc_nids,
5450                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5451                 .channel_mode = alc260_modes,
5452                 .input_mux = &alc260_capture_source,
5453         },
5454         [ALC260_HP] = {
5455                 .mixers = { alc260_hp_output_mixer,
5456                             alc260_input_mixer },
5457                 .init_verbs = { alc260_init_verbs,
5458                                 alc260_hp_unsol_verbs },
5459                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5460                 .dac_nids = alc260_dac_nids,
5461                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5462                 .adc_nids = alc260_adc_nids_alt,
5463                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5464                 .channel_mode = alc260_modes,
5465                 .input_mux = &alc260_capture_source,
5466                 .unsol_event = alc260_hp_unsol_event,
5467                 .init_hook = alc260_hp_automute,
5468         },
5469         [ALC260_HP_DC7600] = {
5470                 .mixers = { alc260_hp_dc7600_mixer,
5471                             alc260_input_mixer },
5472                 .init_verbs = { alc260_init_verbs,
5473                                 alc260_hp_dc7600_verbs },
5474                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5475                 .dac_nids = alc260_dac_nids,
5476                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5477                 .adc_nids = alc260_adc_nids_alt,
5478                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5479                 .channel_mode = alc260_modes,
5480                 .input_mux = &alc260_capture_source,
5481                 .unsol_event = alc260_hp_3012_unsol_event,
5482                 .init_hook = alc260_hp_3012_automute,
5483         },
5484         [ALC260_HP_3013] = {
5485                 .mixers = { alc260_hp_3013_mixer,
5486                             alc260_input_mixer },
5487                 .init_verbs = { alc260_hp_3013_init_verbs,
5488                                 alc260_hp_3013_unsol_verbs },
5489                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5490                 .dac_nids = alc260_dac_nids,
5491                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5492                 .adc_nids = alc260_adc_nids_alt,
5493                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5494                 .channel_mode = alc260_modes,
5495                 .input_mux = &alc260_capture_source,
5496                 .unsol_event = alc260_hp_3013_unsol_event,
5497                 .init_hook = alc260_hp_3013_automute,
5498         },
5499         [ALC260_FUJITSU_S702X] = {
5500                 .mixers = { alc260_fujitsu_mixer },
5501                 .init_verbs = { alc260_fujitsu_init_verbs },
5502                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5503                 .dac_nids = alc260_dac_nids,
5504                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5505                 .adc_nids = alc260_dual_adc_nids,
5506                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5507                 .channel_mode = alc260_modes,
5508                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5509                 .input_mux = alc260_fujitsu_capture_sources,
5510         },
5511         [ALC260_ACER] = {
5512                 .mixers = { alc260_acer_mixer },
5513                 .init_verbs = { alc260_acer_init_verbs },
5514                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5515                 .dac_nids = alc260_dac_nids,
5516                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5517                 .adc_nids = alc260_dual_adc_nids,
5518                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5519                 .channel_mode = alc260_modes,
5520                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5521                 .input_mux = alc260_acer_capture_sources,
5522         },
5523         [ALC260_WILL] = {
5524                 .mixers = { alc260_will_mixer },
5525                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5526                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5527                 .dac_nids = alc260_dac_nids,
5528                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5529                 .adc_nids = alc260_adc_nids,
5530                 .dig_out_nid = ALC260_DIGOUT_NID,
5531                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5532                 .channel_mode = alc260_modes,
5533                 .input_mux = &alc260_capture_source,
5534         },
5535         [ALC260_REPLACER_672V] = {
5536                 .mixers = { alc260_replacer_672v_mixer },
5537                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5538                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5539                 .dac_nids = alc260_dac_nids,
5540                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5541                 .adc_nids = alc260_adc_nids,
5542                 .dig_out_nid = ALC260_DIGOUT_NID,
5543                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5544                 .channel_mode = alc260_modes,
5545                 .input_mux = &alc260_capture_source,
5546                 .unsol_event = alc260_replacer_672v_unsol_event,
5547                 .init_hook = alc260_replacer_672v_automute,
5548         },
5549 #ifdef CONFIG_SND_DEBUG
5550         [ALC260_TEST] = {
5551                 .mixers = { alc260_test_mixer },
5552                 .init_verbs = { alc260_test_init_verbs },
5553                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5554                 .dac_nids = alc260_test_dac_nids,
5555                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5556                 .adc_nids = alc260_test_adc_nids,
5557                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5558                 .channel_mode = alc260_modes,
5559                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5560                 .input_mux = alc260_test_capture_sources,
5561         },
5562 #endif
5563 };
5564
5565 static int patch_alc260(struct hda_codec *codec)
5566 {
5567         struct alc_spec *spec;
5568         int err, board_config;
5569
5570         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5571         if (spec == NULL)
5572                 return -ENOMEM;
5573
5574         codec->spec = spec;
5575
5576         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5577                                                   alc260_models,
5578                                                   alc260_cfg_tbl);
5579         if (board_config < 0) {
5580                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5581                            "trying auto-probe from BIOS...\n");
5582                 board_config = ALC260_AUTO;
5583         }
5584
5585         if (board_config == ALC260_AUTO) {
5586                 /* automatic parse from the BIOS config */
5587                 err = alc260_parse_auto_config(codec);
5588                 if (err < 0) {
5589                         alc_free(codec);
5590                         return err;
5591                 } else if (!err) {
5592                         printk(KERN_INFO
5593                                "hda_codec: Cannot set up configuration "
5594                                "from BIOS.  Using base mode...\n");
5595                         board_config = ALC260_BASIC;
5596                 }
5597         }
5598
5599         if (board_config != ALC260_AUTO)
5600                 setup_preset(spec, &alc260_presets[board_config]);
5601
5602         spec->stream_name_analog = "ALC260 Analog";
5603         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5604         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5605
5606         spec->stream_name_digital = "ALC260 Digital";
5607         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5608         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5609
5610         set_capture_mixer(spec);
5611
5612         spec->vmaster_nid = 0x08;
5613
5614         codec->patch_ops = alc_patch_ops;
5615         if (board_config == ALC260_AUTO)
5616                 spec->init_hook = alc260_auto_init;
5617 #ifdef CONFIG_SND_HDA_POWER_SAVE
5618         if (!spec->loopback.amplist)
5619                 spec->loopback.amplist = alc260_loopbacks;
5620 #endif
5621
5622         return 0;
5623 }
5624
5625
5626 /*
5627  * ALC882 support
5628  *
5629  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5630  * configuration.  Each pin widget can choose any input DACs and a mixer.
5631  * Each ADC is connected from a mixer of all inputs.  This makes possible
5632  * 6-channel independent captures.
5633  *
5634  * In addition, an independent DAC for the multi-playback (not used in this
5635  * driver yet).
5636  */
5637 #define ALC882_DIGOUT_NID       0x06
5638 #define ALC882_DIGIN_NID        0x0a
5639
5640 static struct hda_channel_mode alc882_ch_modes[1] = {
5641         { 8, NULL }
5642 };
5643
5644 static hda_nid_t alc882_dac_nids[4] = {
5645         /* front, rear, clfe, rear_surr */
5646         0x02, 0x03, 0x04, 0x05
5647 };
5648
5649 /* identical with ALC880 */
5650 #define alc882_adc_nids         alc880_adc_nids
5651 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5652
5653 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5654 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5655
5656 /* input MUX */
5657 /* FIXME: should be a matrix-type input source selection */
5658
5659 static struct hda_input_mux alc882_capture_source = {
5660         .num_items = 4,
5661         .items = {
5662                 { "Mic", 0x0 },
5663                 { "Front Mic", 0x1 },
5664                 { "Line", 0x2 },
5665                 { "CD", 0x4 },
5666         },
5667 };
5668 /*
5669  * 2ch mode
5670  */
5671 static struct hda_verb alc882_3ST_ch2_init[] = {
5672         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5673         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5674         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5675         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5676         { } /* end */
5677 };
5678
5679 /*
5680  * 6ch mode
5681  */
5682 static struct hda_verb alc882_3ST_ch6_init[] = {
5683         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5684         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5685         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5686         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5687         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5688         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5689         { } /* end */
5690 };
5691
5692 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5693         { 2, alc882_3ST_ch2_init },
5694         { 6, alc882_3ST_ch6_init },
5695 };
5696
5697 /*
5698  * 6ch mode
5699  */
5700 static struct hda_verb alc882_sixstack_ch6_init[] = {
5701         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5702         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5703         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5704         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5705         { } /* end */
5706 };
5707
5708 /*
5709  * 8ch mode
5710  */
5711 static struct hda_verb alc882_sixstack_ch8_init[] = {
5712         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5713         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5714         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5715         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5716         { } /* end */
5717 };
5718
5719 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5720         { 6, alc882_sixstack_ch6_init },
5721         { 8, alc882_sixstack_ch8_init },
5722 };
5723
5724 /*
5725  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5726  */
5727
5728 /*
5729  * 2ch mode
5730  */
5731 static struct hda_verb alc885_mbp_ch2_init[] = {
5732         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5733         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5734         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5735         { } /* end */
5736 };
5737
5738 /*
5739  * 6ch mode
5740  */
5741 static struct hda_verb alc885_mbp_ch6_init[] = {
5742         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5743         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5744         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5745         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5746         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5747         { } /* end */
5748 };
5749
5750 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
5751         { 2, alc885_mbp_ch2_init },
5752         { 6, alc885_mbp_ch6_init },
5753 };
5754
5755
5756 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5757  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5758  */
5759 static struct snd_kcontrol_new alc882_base_mixer[] = {
5760         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5761         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5762         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5763         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5764         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5765         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5766         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5767         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5768         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5769         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5770         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5771         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5772         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5773         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5774         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5775         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5776         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5777         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5778         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5779         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5780         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5781         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5782         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5783         { } /* end */
5784 };
5785
5786 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5787         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5788         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
5789         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
5790         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
5791         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5792         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5793         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5794         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5795         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
5796         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5797         { } /* end */
5798 };
5799 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5800         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5801         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5802         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5803         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5804         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5805         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5806         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5807         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5808         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5809         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5810         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5811         { } /* end */
5812 };
5813
5814 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5815         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5816         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5817         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5818         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5819         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5820         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5821         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5822         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5823         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5824         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5825         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5826         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5827         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5828         { } /* end */
5829 };
5830
5831 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5832  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5833  */
5834 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5835         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5836         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5837         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5838         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5839         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5840         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5841         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5842         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5843         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5844         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5845         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5846         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5847         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5848         { } /* end */
5849 };
5850
5851 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5852         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5853         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5854         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5855         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5856         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5857         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5858         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5859         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5860         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5861         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5862         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5863         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5864         { } /* end */
5865 };
5866
5867 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5868         {
5869                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5870                 .name = "Channel Mode",
5871                 .info = alc_ch_mode_info,
5872                 .get = alc_ch_mode_get,
5873                 .put = alc_ch_mode_put,
5874         },
5875         { } /* end */
5876 };
5877
5878 static struct hda_verb alc882_init_verbs[] = {
5879         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5880         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5881         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5882         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5883         /* Rear mixer */
5884         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5885         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5886         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5887         /* CLFE mixer */
5888         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5889         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5890         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5891         /* Side mixer */
5892         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5893         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5894         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5895
5896         /* Front Pin: output 0 (0x0c) */
5897         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5898         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5899         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5900         /* Rear Pin: output 1 (0x0d) */
5901         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5902         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5903         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5904         /* CLFE Pin: output 2 (0x0e) */
5905         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5906         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5907         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5908         /* Side Pin: output 3 (0x0f) */
5909         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5910         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5911         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5912         /* Mic (rear) pin: input vref at 80% */
5913         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5914         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5915         /* Front Mic pin: input vref at 80% */
5916         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5917         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5918         /* Line In pin: input */
5919         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5920         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5921         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5922         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5923         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5924         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5925         /* CD pin widget for input */
5926         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5927
5928         /* FIXME: use matrix-type input source selection */
5929         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5930         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5931         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5932         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5933         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5934         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5935         /* Input mixer2 */
5936         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5937         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5938         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5939         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5940         /* Input mixer3 */
5941         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5942         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5943         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5944         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5945         /* ADC1: mute amp left and right */
5946         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5947         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5948         /* ADC2: mute amp left and right */
5949         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5950         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5951         /* ADC3: mute amp left and right */
5952         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5953         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5954
5955         { }
5956 };
5957
5958 static struct hda_verb alc882_eapd_verbs[] = {
5959         /* change to EAPD mode */
5960         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5961         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5962         { }
5963 };
5964
5965 /* Mac Pro test */
5966 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5967         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5968         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5969         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5970         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5971         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5972         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5973         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5974         { } /* end */
5975 };
5976
5977 static struct hda_verb alc882_macpro_init_verbs[] = {
5978         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5979         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5980         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5981         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5982         /* Front Pin: output 0 (0x0c) */
5983         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5984         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5985         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5986         /* Front Mic pin: input vref at 80% */
5987         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5988         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5989         /* Speaker:  output */
5990         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5991         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5992         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5993         /* Headphone output (output 0 - 0x0c) */
5994         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5995         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5996         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5997
5998         /* FIXME: use matrix-type input source selection */
5999         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6000         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6001         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6002         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6003         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6004         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6005         /* Input mixer2 */
6006         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6007         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6008         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6009         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6010         /* Input mixer3 */
6011         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6012         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6013         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6014         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6015         /* ADC1: mute amp left and right */
6016         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6017         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6018         /* ADC2: mute amp left and right */
6019         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6020         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6021         /* ADC3: mute amp left and right */
6022         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6023         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6024
6025         { }
6026 };
6027
6028 /* Macbook Pro rev3 */
6029 static struct hda_verb alc885_mbp3_init_verbs[] = {
6030         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6031         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6032         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6033         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6034         /* Rear mixer */
6035         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6036         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6037         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6038         /* Front Pin: output 0 (0x0c) */
6039         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6040         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6041         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6042         /* HP Pin: output 0 (0x0d) */
6043         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6044         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6045         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6046         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6047         /* Mic (rear) pin: input vref at 80% */
6048         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6049         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6050         /* Front Mic pin: input vref at 80% */
6051         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6052         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6053         /* Line In pin: use output 1 when in LineOut mode */
6054         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6055         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6056         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6057
6058         /* FIXME: use matrix-type input source selection */
6059         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6060         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6061         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6062         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6063         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6064         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6065         /* Input mixer2 */
6066         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6067         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6068         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6069         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6070         /* Input mixer3 */
6071         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6072         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6073         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6074         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6075         /* ADC1: mute amp left and right */
6076         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6077         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6078         /* ADC2: mute amp left and right */
6079         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6080         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6081         /* ADC3: mute amp left and right */
6082         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6083         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6084
6085         { }
6086 };
6087
6088 /* iMac 24 mixer. */
6089 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6090         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6091         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6092         { } /* end */
6093 };
6094
6095 /* iMac 24 init verbs. */
6096 static struct hda_verb alc885_imac24_init_verbs[] = {
6097         /* Internal speakers: output 0 (0x0c) */
6098         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6099         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6100         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6101         /* Internal speakers: output 0 (0x0c) */
6102         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6103         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6104         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6105         /* Headphone: output 0 (0x0c) */
6106         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6107         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6108         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6109         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6110         /* Front Mic: input vref at 80% */
6111         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6112         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6113         { }
6114 };
6115
6116 /* Toggle speaker-output according to the hp-jack state */
6117 static void alc885_imac24_automute(struct hda_codec *codec)
6118 {
6119         unsigned int present;
6120
6121         present = snd_hda_codec_read(codec, 0x14, 0,
6122                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6123         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6124                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6125         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6126                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6127 }
6128
6129 /* Processes unsolicited events. */
6130 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6131                                       unsigned int res)
6132 {
6133         /* Headphone insertion or removal. */
6134         if ((res >> 26) == ALC880_HP_EVENT)
6135                 alc885_imac24_automute(codec);
6136 }
6137
6138 static void alc885_mbp3_automute(struct hda_codec *codec)
6139 {
6140         unsigned int present;
6141
6142         present = snd_hda_codec_read(codec, 0x15, 0,
6143                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6144         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6145                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6146         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6147                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6148
6149 }
6150 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6151                                     unsigned int res)
6152 {
6153         /* Headphone insertion or removal. */
6154         if ((res >> 26) == ALC880_HP_EVENT)
6155                 alc885_mbp3_automute(codec);
6156 }
6157
6158
6159 static struct hda_verb alc882_targa_verbs[] = {
6160         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6161         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6162
6163         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6164         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6165
6166         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6167         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6168         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6169
6170         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6171         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6172         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6173         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6174         { } /* end */
6175 };
6176
6177 /* toggle speaker-output according to the hp-jack state */
6178 static void alc882_targa_automute(struct hda_codec *codec)
6179 {
6180         unsigned int present;
6181
6182         present = snd_hda_codec_read(codec, 0x14, 0,
6183                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6184         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6185                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6186         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6187                                   present ? 1 : 3);
6188 }
6189
6190 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6191 {
6192         /* Looks like the unsol event is incompatible with the standard
6193          * definition.  4bit tag is placed at 26 bit!
6194          */
6195         if (((res >> 26) == ALC880_HP_EVENT)) {
6196                 alc882_targa_automute(codec);
6197         }
6198 }
6199
6200 static struct hda_verb alc882_asus_a7j_verbs[] = {
6201         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6202         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6203
6204         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6205         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6206         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6207
6208         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6209         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6210         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6211
6212         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6213         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6214         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6215         { } /* end */
6216 };
6217
6218 static struct hda_verb alc882_asus_a7m_verbs[] = {
6219         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6220         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6221
6222         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6223         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6224         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6225
6226         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6227         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6228         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6229
6230         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6231         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6232         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6233         { } /* end */
6234 };
6235
6236 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6237 {
6238         unsigned int gpiostate, gpiomask, gpiodir;
6239
6240         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6241                                        AC_VERB_GET_GPIO_DATA, 0);
6242
6243         if (!muted)
6244                 gpiostate |= (1 << pin);
6245         else
6246                 gpiostate &= ~(1 << pin);
6247
6248         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6249                                       AC_VERB_GET_GPIO_MASK, 0);
6250         gpiomask |= (1 << pin);
6251
6252         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6253                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6254         gpiodir |= (1 << pin);
6255
6256
6257         snd_hda_codec_write(codec, codec->afg, 0,
6258                             AC_VERB_SET_GPIO_MASK, gpiomask);
6259         snd_hda_codec_write(codec, codec->afg, 0,
6260                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6261
6262         msleep(1);
6263
6264         snd_hda_codec_write(codec, codec->afg, 0,
6265                             AC_VERB_SET_GPIO_DATA, gpiostate);
6266 }
6267
6268 /* set up GPIO at initialization */
6269 static void alc885_macpro_init_hook(struct hda_codec *codec)
6270 {
6271         alc882_gpio_mute(codec, 0, 0);
6272         alc882_gpio_mute(codec, 1, 0);
6273 }
6274
6275 /* set up GPIO and update auto-muting at initialization */
6276 static void alc885_imac24_init_hook(struct hda_codec *codec)
6277 {
6278         alc885_macpro_init_hook(codec);
6279         alc885_imac24_automute(codec);
6280 }
6281
6282 /*
6283  * generic initialization of ADC, input mixers and output mixers
6284  */
6285 static struct hda_verb alc882_auto_init_verbs[] = {
6286         /*
6287          * Unmute ADC0-2 and set the default input to mic-in
6288          */
6289         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6290         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6291         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6292         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6293         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6294         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6295
6296         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6297          * mixer widget
6298          * Note: PASD motherboards uses the Line In 2 as the input for
6299          * front panel mic (mic 2)
6300          */
6301         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6302         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6303         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6304         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6305         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6306         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6307
6308         /*
6309          * Set up output mixers (0x0c - 0x0f)
6310          */
6311         /* set vol=0 to output mixers */
6312         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6313         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6314         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6315         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6316         /* set up input amps for analog loopback */
6317         /* Amp Indices: DAC = 0, mixer = 1 */
6318         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6319         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6320         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6321         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6322         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6323         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6324         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6325         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6326         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6327         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6328
6329         /* FIXME: use matrix-type input source selection */
6330         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6331         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6332         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6333         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6334         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6335         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6336         /* Input mixer2 */
6337         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6338         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6339         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6340         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6341         /* Input mixer3 */
6342         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6343         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6344         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6345         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6346
6347         { }
6348 };
6349
6350 #ifdef CONFIG_SND_HDA_POWER_SAVE
6351 #define alc882_loopbacks        alc880_loopbacks
6352 #endif
6353
6354 /* pcm configuration: identiacal with ALC880 */
6355 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6356 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6357 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6358 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6359
6360 /*
6361  * configuration and preset
6362  */
6363 static const char *alc882_models[ALC882_MODEL_LAST] = {
6364         [ALC882_3ST_DIG]        = "3stack-dig",
6365         [ALC882_6ST_DIG]        = "6stack-dig",
6366         [ALC882_ARIMA]          = "arima",
6367         [ALC882_W2JC]           = "w2jc",
6368         [ALC882_TARGA]          = "targa",
6369         [ALC882_ASUS_A7J]       = "asus-a7j",
6370         [ALC882_ASUS_A7M]       = "asus-a7m",
6371         [ALC885_MACPRO]         = "macpro",
6372         [ALC885_MBP3]           = "mbp3",
6373         [ALC885_IMAC24]         = "imac24",
6374         [ALC882_AUTO]           = "auto",
6375 };
6376
6377 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6378         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6379         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6380         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6381         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6382         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6383         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6384         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6385         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6386         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6387         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6388         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6389         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6390         {}
6391 };
6392
6393 static struct alc_config_preset alc882_presets[] = {
6394         [ALC882_3ST_DIG] = {
6395                 .mixers = { alc882_base_mixer },
6396                 .init_verbs = { alc882_init_verbs },
6397                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6398                 .dac_nids = alc882_dac_nids,
6399                 .dig_out_nid = ALC882_DIGOUT_NID,
6400                 .dig_in_nid = ALC882_DIGIN_NID,
6401                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6402                 .channel_mode = alc882_ch_modes,
6403                 .need_dac_fix = 1,
6404                 .input_mux = &alc882_capture_source,
6405         },
6406         [ALC882_6ST_DIG] = {
6407                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6408                 .init_verbs = { alc882_init_verbs },
6409                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6410                 .dac_nids = alc882_dac_nids,
6411                 .dig_out_nid = ALC882_DIGOUT_NID,
6412                 .dig_in_nid = ALC882_DIGIN_NID,
6413                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6414                 .channel_mode = alc882_sixstack_modes,
6415                 .input_mux = &alc882_capture_source,
6416         },
6417         [ALC882_ARIMA] = {
6418                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6419                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6420                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6421                 .dac_nids = alc882_dac_nids,
6422                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6423                 .channel_mode = alc882_sixstack_modes,
6424                 .input_mux = &alc882_capture_source,
6425         },
6426         [ALC882_W2JC] = {
6427                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6428                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6429                                 alc880_gpio1_init_verbs },
6430                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6431                 .dac_nids = alc882_dac_nids,
6432                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6433                 .channel_mode = alc880_threestack_modes,
6434                 .need_dac_fix = 1,
6435                 .input_mux = &alc882_capture_source,
6436                 .dig_out_nid = ALC882_DIGOUT_NID,
6437         },
6438         [ALC885_MBP3] = {
6439                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6440                 .init_verbs = { alc885_mbp3_init_verbs,
6441                                 alc880_gpio1_init_verbs },
6442                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6443                 .dac_nids = alc882_dac_nids,
6444                 .channel_mode = alc885_mbp_6ch_modes,
6445                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6446                 .input_mux = &alc882_capture_source,
6447                 .dig_out_nid = ALC882_DIGOUT_NID,
6448                 .dig_in_nid = ALC882_DIGIN_NID,
6449                 .unsol_event = alc885_mbp3_unsol_event,
6450                 .init_hook = alc885_mbp3_automute,
6451         },
6452         [ALC885_MACPRO] = {
6453                 .mixers = { alc882_macpro_mixer },
6454                 .init_verbs = { alc882_macpro_init_verbs },
6455                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6456                 .dac_nids = alc882_dac_nids,
6457                 .dig_out_nid = ALC882_DIGOUT_NID,
6458                 .dig_in_nid = ALC882_DIGIN_NID,
6459                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6460                 .channel_mode = alc882_ch_modes,
6461                 .input_mux = &alc882_capture_source,
6462                 .init_hook = alc885_macpro_init_hook,
6463         },
6464         [ALC885_IMAC24] = {
6465                 .mixers = { alc885_imac24_mixer },
6466                 .init_verbs = { alc885_imac24_init_verbs },
6467                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6468                 .dac_nids = alc882_dac_nids,
6469                 .dig_out_nid = ALC882_DIGOUT_NID,
6470                 .dig_in_nid = ALC882_DIGIN_NID,
6471                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6472                 .channel_mode = alc882_ch_modes,
6473                 .input_mux = &alc882_capture_source,
6474                 .unsol_event = alc885_imac24_unsol_event,
6475                 .init_hook = alc885_imac24_init_hook,
6476         },
6477         [ALC882_TARGA] = {
6478                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
6479                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6480                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6481                 .dac_nids = alc882_dac_nids,
6482                 .dig_out_nid = ALC882_DIGOUT_NID,
6483                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6484                 .adc_nids = alc882_adc_nids,
6485                 .capsrc_nids = alc882_capsrc_nids,
6486                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6487                 .channel_mode = alc882_3ST_6ch_modes,
6488                 .need_dac_fix = 1,
6489                 .input_mux = &alc882_capture_source,
6490                 .unsol_event = alc882_targa_unsol_event,
6491                 .init_hook = alc882_targa_automute,
6492         },
6493         [ALC882_ASUS_A7J] = {
6494                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
6495                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6496                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6497                 .dac_nids = alc882_dac_nids,
6498                 .dig_out_nid = ALC882_DIGOUT_NID,
6499                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6500                 .adc_nids = alc882_adc_nids,
6501                 .capsrc_nids = alc882_capsrc_nids,
6502                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6503                 .channel_mode = alc882_3ST_6ch_modes,
6504                 .need_dac_fix = 1,
6505                 .input_mux = &alc882_capture_source,
6506         },
6507         [ALC882_ASUS_A7M] = {
6508                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6509                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6510                                 alc880_gpio1_init_verbs,
6511                                 alc882_asus_a7m_verbs },
6512                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6513                 .dac_nids = alc882_dac_nids,
6514                 .dig_out_nid = ALC882_DIGOUT_NID,
6515                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6516                 .channel_mode = alc880_threestack_modes,
6517                 .need_dac_fix = 1,
6518                 .input_mux = &alc882_capture_source,
6519         },
6520 };
6521
6522
6523 /*
6524  * Pin config fixes
6525  */
6526 enum {
6527         PINFIX_ABIT_AW9D_MAX
6528 };
6529
6530 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6531         { 0x15, 0x01080104 }, /* side */
6532         { 0x16, 0x01011012 }, /* rear */
6533         { 0x17, 0x01016011 }, /* clfe */
6534         { }
6535 };
6536
6537 static const struct alc_pincfg *alc882_pin_fixes[] = {
6538         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6539 };
6540
6541 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6542         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6543         {}
6544 };
6545
6546 /*
6547  * BIOS auto configuration
6548  */
6549 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6550                                               hda_nid_t nid, int pin_type,
6551                                               int dac_idx)
6552 {
6553         /* set as output */
6554         struct alc_spec *spec = codec->spec;
6555         int idx;
6556
6557         alc_set_pin_output(codec, nid, pin_type);
6558         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6559                 idx = 4;
6560         else
6561                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6562         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6563
6564 }
6565
6566 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6567 {
6568         struct alc_spec *spec = codec->spec;
6569         int i;
6570
6571         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6572         for (i = 0; i <= HDA_SIDE; i++) {
6573                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6574                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6575                 if (nid)
6576                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6577                                                           i);
6578         }
6579 }
6580
6581 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6582 {
6583         struct alc_spec *spec = codec->spec;
6584         hda_nid_t pin;
6585
6586         pin = spec->autocfg.hp_pins[0];
6587         if (pin) /* connect to front */
6588                 /* use dac 0 */
6589                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6590         pin = spec->autocfg.speaker_pins[0];
6591         if (pin)
6592                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6593 }
6594
6595 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6596 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6597
6598 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6599 {
6600         struct alc_spec *spec = codec->spec;
6601         int i;
6602
6603         for (i = 0; i < AUTO_PIN_LAST; i++) {
6604                 hda_nid_t nid = spec->autocfg.input_pins[i];
6605                 unsigned int vref;
6606                 if (!nid)
6607                         continue;
6608                 vref = PIN_IN;
6609                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6610                         unsigned int pincap;
6611                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6612                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6613                             AC_PINCAP_VREF_80)
6614                                 vref = PIN_VREF80;
6615                 }
6616                 snd_hda_codec_write(codec, nid, 0,
6617                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6618                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6619                         snd_hda_codec_write(codec, nid, 0,
6620                                             AC_VERB_SET_AMP_GAIN_MUTE,
6621                                             AMP_OUT_MUTE);
6622         }
6623 }
6624
6625 static void alc882_auto_init_input_src(struct hda_codec *codec)
6626 {
6627         struct alc_spec *spec = codec->spec;
6628         const struct hda_input_mux *imux = spec->input_mux;
6629         int c;
6630
6631         for (c = 0; c < spec->num_adc_nids; c++) {
6632                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6633                 hda_nid_t nid = spec->capsrc_nids[c];
6634                 int conns, mute, idx, item;
6635
6636                 conns = snd_hda_get_connections(codec, nid, conn_list,
6637                                                 ARRAY_SIZE(conn_list));
6638                 if (conns < 0)
6639                         continue;
6640                 for (idx = 0; idx < conns; idx++) {
6641                         /* if the current connection is the selected one,
6642                          * unmute it as default - otherwise mute it
6643                          */
6644                         mute = AMP_IN_MUTE(idx);
6645                         for (item = 0; item < imux->num_items; item++) {
6646                                 if (imux->items[item].index == idx) {
6647                                         if (spec->cur_mux[c] == item)
6648                                                 mute = AMP_IN_UNMUTE(idx);
6649                                         break;
6650                                 }
6651                         }
6652                         snd_hda_codec_write(codec, nid, 0,
6653                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6654                 }
6655         }
6656 }
6657
6658 /* add mic boosts if needed */
6659 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6660 {
6661         struct alc_spec *spec = codec->spec;
6662         int err;
6663         hda_nid_t nid;
6664
6665         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6666         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6667                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6668                                   "Mic Boost",
6669                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6670                 if (err < 0)
6671                         return err;
6672         }
6673         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6674         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6675                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6676                                   "Front Mic Boost",
6677                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6678                 if (err < 0)
6679                         return err;
6680         }
6681         return 0;
6682 }
6683
6684 /* almost identical with ALC880 parser... */
6685 static int alc882_parse_auto_config(struct hda_codec *codec)
6686 {
6687         struct alc_spec *spec = codec->spec;
6688         int err = alc880_parse_auto_config(codec);
6689
6690         if (err < 0)
6691                 return err;
6692         else if (!err)
6693                 return 0; /* no config found */
6694
6695         err = alc_auto_add_mic_boost(codec);
6696         if (err < 0)
6697                 return err;
6698
6699         /* hack - override the init verbs */
6700         spec->init_verbs[0] = alc882_auto_init_verbs;
6701
6702         return 1; /* config found */
6703 }
6704
6705 /* additional initialization for auto-configuration model */
6706 static void alc882_auto_init(struct hda_codec *codec)
6707 {
6708         struct alc_spec *spec = codec->spec;
6709         alc882_auto_init_multi_out(codec);
6710         alc882_auto_init_hp_out(codec);
6711         alc882_auto_init_analog_input(codec);
6712         alc882_auto_init_input_src(codec);
6713         if (spec->unsol_event)
6714                 alc_inithook(codec);
6715 }
6716
6717 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6718
6719 static int patch_alc882(struct hda_codec *codec)
6720 {
6721         struct alc_spec *spec;
6722         int err, board_config;
6723
6724         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6725         if (spec == NULL)
6726                 return -ENOMEM;
6727
6728         codec->spec = spec;
6729
6730         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6731                                                   alc882_models,
6732                                                   alc882_cfg_tbl);
6733
6734         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6735                 /* Pick up systems that don't supply PCI SSID */
6736                 switch (codec->subsystem_id) {
6737                 case 0x106b0c00: /* Mac Pro */
6738                         board_config = ALC885_MACPRO;
6739                         break;
6740                 case 0x106b1000: /* iMac 24 */
6741                 case 0x106b2800: /* AppleTV */
6742                         board_config = ALC885_IMAC24;
6743                         break;
6744                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
6745                 case 0x106b00a4: /* MacbookPro4,1 */
6746                 case 0x106b2c00: /* Macbook Pro rev3 */
6747                 case 0x106b3600: /* Macbook 3.1 */
6748                         board_config = ALC885_MBP3;
6749                         break;
6750                 default:
6751                         /* ALC889A is handled better as ALC888-compatible */
6752                         if (codec->revision_id == 0x100101 ||
6753                             codec->revision_id == 0x100103) {
6754                                 alc_free(codec);
6755                                 return patch_alc883(codec);
6756                         }
6757                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6758                                          "trying auto-probe from BIOS...\n");
6759                         board_config = ALC882_AUTO;
6760                 }
6761         }
6762
6763         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6764
6765         if (board_config == ALC882_AUTO) {
6766                 /* automatic parse from the BIOS config */
6767                 err = alc882_parse_auto_config(codec);
6768                 if (err < 0) {
6769                         alc_free(codec);
6770                         return err;
6771                 } else if (!err) {
6772                         printk(KERN_INFO
6773                                "hda_codec: Cannot set up configuration "
6774                                "from BIOS.  Using base mode...\n");
6775                         board_config = ALC882_3ST_DIG;
6776                 }
6777         }
6778
6779         if (board_config != ALC882_AUTO)
6780                 setup_preset(spec, &alc882_presets[board_config]);
6781
6782         if (codec->vendor_id == 0x10ec0885) {
6783                 spec->stream_name_analog = "ALC885 Analog";
6784                 spec->stream_name_digital = "ALC885 Digital";
6785         } else {
6786                 spec->stream_name_analog = "ALC882 Analog";
6787                 spec->stream_name_digital = "ALC882 Digital";
6788         }
6789
6790         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6791         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6792         /* FIXME: setup DAC5 */
6793         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
6794         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6795
6796         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6797         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6798
6799         spec->is_mix_capture = 1; /* matrix-style capture */
6800         if (!spec->adc_nids && spec->input_mux) {
6801                 /* check whether NID 0x07 is valid */
6802                 unsigned int wcap = get_wcaps(codec, 0x07);
6803                 /* get type */
6804                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6805                 if (wcap != AC_WID_AUD_IN) {
6806                         spec->adc_nids = alc882_adc_nids_alt;
6807                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6808                         spec->capsrc_nids = alc882_capsrc_nids_alt;
6809                 } else {
6810                         spec->adc_nids = alc882_adc_nids;
6811                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6812                         spec->capsrc_nids = alc882_capsrc_nids;
6813                 }
6814         }
6815         set_capture_mixer(spec);
6816
6817         spec->vmaster_nid = 0x0c;
6818
6819         codec->patch_ops = alc_patch_ops;
6820         if (board_config == ALC882_AUTO)
6821                 spec->init_hook = alc882_auto_init;
6822 #ifdef CONFIG_SND_HDA_POWER_SAVE
6823         if (!spec->loopback.amplist)
6824                 spec->loopback.amplist = alc882_loopbacks;
6825 #endif
6826
6827         return 0;
6828 }
6829
6830 /*
6831  * ALC883 support
6832  *
6833  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6834  * configuration.  Each pin widget can choose any input DACs and a mixer.
6835  * Each ADC is connected from a mixer of all inputs.  This makes possible
6836  * 6-channel independent captures.
6837  *
6838  * In addition, an independent DAC for the multi-playback (not used in this
6839  * driver yet).
6840  */
6841 #define ALC883_DIGOUT_NID       0x06
6842 #define ALC883_DIGIN_NID        0x0a
6843
6844 static hda_nid_t alc883_dac_nids[4] = {
6845         /* front, rear, clfe, rear_surr */
6846         0x02, 0x03, 0x04, 0x05
6847 };
6848
6849 static hda_nid_t alc883_adc_nids[2] = {
6850         /* ADC1-2 */
6851         0x08, 0x09,
6852 };
6853
6854 static hda_nid_t alc883_adc_nids_alt[1] = {
6855         /* ADC1 */
6856         0x08,
6857 };
6858
6859 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6860
6861 /* input MUX */
6862 /* FIXME: should be a matrix-type input source selection */
6863
6864 static struct hda_input_mux alc883_capture_source = {
6865         .num_items = 4,
6866         .items = {
6867                 { "Mic", 0x0 },
6868                 { "Front Mic", 0x1 },
6869                 { "Line", 0x2 },
6870                 { "CD", 0x4 },
6871         },
6872 };
6873
6874 static struct hda_input_mux alc883_3stack_6ch_intel = {
6875         .num_items = 4,
6876         .items = {
6877                 { "Mic", 0x1 },
6878                 { "Front Mic", 0x0 },
6879                 { "Line", 0x2 },
6880                 { "CD", 0x4 },
6881         },
6882 };
6883
6884 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6885         .num_items = 2,
6886         .items = {
6887                 { "Mic", 0x1 },
6888                 { "Line", 0x2 },
6889         },
6890 };
6891
6892 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6893         .num_items = 4,
6894         .items = {
6895                 { "Mic", 0x0 },
6896                 { "iMic", 0x1 },
6897                 { "Line", 0x2 },
6898                 { "CD", 0x4 },
6899         },
6900 };
6901
6902 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6903         .num_items = 2,
6904         .items = {
6905                 { "Mic", 0x0 },
6906                 { "Int Mic", 0x1 },
6907         },
6908 };
6909
6910 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
6911         .num_items = 3,
6912         .items = {
6913                 { "Mic", 0x0 },
6914                 { "Front Mic", 0x1 },
6915                 { "Line", 0x4 },
6916         },
6917 };
6918
6919 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
6920         .num_items = 2,
6921         .items = {
6922                 { "Mic", 0x0 },
6923                 { "Line", 0x2 },
6924         },
6925 };
6926
6927 /*
6928  * 2ch mode
6929  */
6930 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6931         { 2, NULL }
6932 };
6933
6934 /*
6935  * 2ch mode
6936  */
6937 static struct hda_verb alc883_3ST_ch2_init[] = {
6938         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6939         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6940         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6941         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6942         { } /* end */
6943 };
6944
6945 /*
6946  * 4ch mode
6947  */
6948 static struct hda_verb alc883_3ST_ch4_init[] = {
6949         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6950         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6951         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6952         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6953         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6954         { } /* end */
6955 };
6956
6957 /*
6958  * 6ch mode
6959  */
6960 static struct hda_verb alc883_3ST_ch6_init[] = {
6961         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6962         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6963         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6964         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6965         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6966         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6967         { } /* end */
6968 };
6969
6970 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6971         { 2, alc883_3ST_ch2_init },
6972         { 4, alc883_3ST_ch4_init },
6973         { 6, alc883_3ST_ch6_init },
6974 };
6975
6976 /*
6977  * 2ch mode
6978  */
6979 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6980         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6981         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6982         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6983         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6984         { } /* end */
6985 };
6986
6987 /*
6988  * 4ch mode
6989  */
6990 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
6991         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6992         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6993         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6994         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6995         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6996         { } /* end */
6997 };
6998
6999 /*
7000  * 6ch mode
7001  */
7002 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7003         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7004         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7005         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7006         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7007         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7008         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7009         { } /* end */
7010 };
7011
7012 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7013         { 2, alc883_3ST_ch2_intel_init },
7014         { 4, alc883_3ST_ch4_intel_init },
7015         { 6, alc883_3ST_ch6_intel_init },
7016 };
7017
7018 /*
7019  * 6ch mode
7020  */
7021 static struct hda_verb alc883_sixstack_ch6_init[] = {
7022         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7023         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7024         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7025         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7026         { } /* end */
7027 };
7028
7029 /*
7030  * 8ch mode
7031  */
7032 static struct hda_verb alc883_sixstack_ch8_init[] = {
7033         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7034         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7035         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7036         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7037         { } /* end */
7038 };
7039
7040 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7041         { 6, alc883_sixstack_ch6_init },
7042         { 8, alc883_sixstack_ch8_init },
7043 };
7044
7045 static struct hda_verb alc883_medion_eapd_verbs[] = {
7046         /* eanable EAPD on medion laptop */
7047         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7048         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7049         { }
7050 };
7051
7052 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7053  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7054  */
7055
7056 static struct snd_kcontrol_new alc883_base_mixer[] = {
7057         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7058         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7059         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7060         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7061         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7062         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7063         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7064         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7065         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7066         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7067         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7068         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7069         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7070         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7071         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7072         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7073         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7074         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7075         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7076         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7077         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7078         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7079         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7080         { } /* end */
7081 };
7082
7083 static struct snd_kcontrol_new alc883_mitac_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_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7087         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7088         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7089         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7090         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7091         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7092         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7093         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7094         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7095         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7096         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7097         { } /* end */
7098 };
7099
7100 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7101         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7102         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7103         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7104         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7105         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7106         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7107         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7108         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7109         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7110         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7111         { } /* end */
7112 };
7113
7114 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7115         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7116         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7117         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7118         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7119         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7120         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7121         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7122         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7123         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7124         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7125         { } /* end */
7126 };
7127
7128 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7129         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7130         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7131         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7132         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7133         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7134         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7135         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7136         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7137         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7138         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7139         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7140         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7141         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7142         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7143         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7144         { } /* end */
7145 };
7146
7147 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7148         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7149         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7150         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7151         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7152         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7153         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7154         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7155         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7156         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7157         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7158         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7159         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7160         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7161         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7162         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7163         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7164         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7165         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7166         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7167         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7168         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7169         { } /* end */
7170 };
7171
7172 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7173         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7174         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7175         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7176         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7177         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7178                               HDA_OUTPUT),
7179         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7180         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7181         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7182         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7183         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7184         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7185         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7186         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7187         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7188         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7189         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7190         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7191         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7192         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7193         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7194         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7195         { } /* end */
7196 };
7197
7198 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7199         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7200         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7201         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7202         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7203         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7204         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7205         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7206         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7207         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7208         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7209         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7210         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7211         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7212         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7213         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7214         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7215         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7216         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7217         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7218         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7219         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7220         { } /* end */
7221 };
7222
7223 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7224         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7225         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7226         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7227         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7228         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7229         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7230         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7231         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7232         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7233         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7234         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7235         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7236         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7237         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7238         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7239         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7240         { } /* end */
7241 };
7242
7243 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7244         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7245         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7246         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7247         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7248         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7249         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7250         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7251         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7252         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7253         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7254         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7255         { } /* end */
7256 };
7257
7258 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7259         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7260         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7261         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7262         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7263         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7264         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7265         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7266         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7267         { } /* end */
7268 };
7269
7270 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7271         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7272         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7273         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 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_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7278         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7279         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7280         { } /* end */
7281 };
7282
7283 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7284         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7285         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7286         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7287         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7288         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7289         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7290         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7291         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7292         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7293         { } /* end */
7294 };
7295
7296 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7297         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7298         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7299         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7300         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7301         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7302         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7303         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7304         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7305         { } /* end */
7306 };
7307
7308 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7309         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7310         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7311         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7312         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7313         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7314                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7315         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7316         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7317         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7318         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7319         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7320         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7321         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7322         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7323         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7324         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7325         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7326         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7327         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7328         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7329         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7330         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7331         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7332         { } /* end */
7333 };
7334
7335 static struct hda_bind_ctls alc883_bind_cap_vol = {
7336         .ops = &snd_hda_bind_vol,
7337         .values = {
7338                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7339                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7340                 0
7341         },
7342 };
7343
7344 static struct hda_bind_ctls alc883_bind_cap_switch = {
7345         .ops = &snd_hda_bind_sw,
7346         .values = {
7347                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7348                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7349                 0
7350         },
7351 };
7352
7353 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7354         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7355         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7356         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7357         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7358         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7359         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7360         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7361         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7362         { } /* end */
7363 };
7364
7365 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
7366         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7367         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7368         {
7369                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7370                 /* .name = "Capture Source", */
7371                 .name = "Input Source",
7372                 .count = 1,
7373                 .info = alc_mux_enum_info,
7374                 .get = alc_mux_enum_get,
7375                 .put = alc_mux_enum_put,
7376         },
7377         { } /* end */
7378 };
7379
7380 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7381         {
7382                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7383                 .name = "Channel Mode",
7384                 .info = alc_ch_mode_info,
7385                 .get = alc_ch_mode_get,
7386                 .put = alc_ch_mode_put,
7387         },
7388         { } /* end */
7389 };
7390
7391 static struct hda_verb alc883_init_verbs[] = {
7392         /* ADC1: mute amp left and right */
7393         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7394         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7395         /* ADC2: mute amp left and right */
7396         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7397         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7398         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7399         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7400         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7401         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7402         /* Rear mixer */
7403         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7404         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7405         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7406         /* CLFE mixer */
7407         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7408         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7409         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7410         /* Side mixer */
7411         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7412         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7413         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7414
7415         /* mute analog input loopbacks */
7416         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7417         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7418         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7419         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7420         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7421
7422         /* Front Pin: output 0 (0x0c) */
7423         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7424         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7425         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7426         /* Rear Pin: output 1 (0x0d) */
7427         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7428         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7429         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7430         /* CLFE Pin: output 2 (0x0e) */
7431         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7432         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7433         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7434         /* Side Pin: output 3 (0x0f) */
7435         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7436         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7437         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7438         /* Mic (rear) pin: input vref at 80% */
7439         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7440         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7441         /* Front Mic pin: input vref at 80% */
7442         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7443         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7444         /* Line In pin: input */
7445         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7446         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7447         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7448         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7449         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7450         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7451         /* CD pin widget for input */
7452         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7453
7454         /* FIXME: use matrix-type input source selection */
7455         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7456         /* Input mixer2 */
7457         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7458         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7459         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7460         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7461         /* Input mixer3 */
7462         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7463         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7464         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7465         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7466         { }
7467 };
7468
7469 /* toggle speaker-output according to the hp-jack state */
7470 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7471 {
7472         unsigned int present;
7473
7474         present = snd_hda_codec_read(codec, 0x15, 0,
7475                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7476         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7477                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7478         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7479                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7480 }
7481
7482 /* auto-toggle front mic */
7483 /*
7484 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7485 {
7486         unsigned int present;
7487         unsigned char bits;
7488
7489         present = snd_hda_codec_read(codec, 0x18, 0,
7490                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7491         bits = present ? HDA_AMP_MUTE : 0;
7492         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7493 }
7494 */
7495
7496 static void alc883_mitac_automute(struct hda_codec *codec)
7497 {
7498         alc883_mitac_hp_automute(codec);
7499         /* alc883_mitac_mic_automute(codec); */
7500 }
7501
7502 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7503                                            unsigned int res)
7504 {
7505         switch (res >> 26) {
7506         case ALC880_HP_EVENT:
7507                 alc883_mitac_hp_automute(codec);
7508                 break;
7509         case ALC880_MIC_EVENT:
7510                 /* alc883_mitac_mic_automute(codec); */
7511                 break;
7512         }
7513 }
7514
7515 static struct hda_verb alc883_mitac_verbs[] = {
7516         /* HP */
7517         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7518         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7519         /* Subwoofer */
7520         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7521         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7522
7523         /* enable unsolicited event */
7524         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7525         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7526
7527         { } /* end */
7528 };
7529
7530 static struct hda_verb alc883_clevo_m720_verbs[] = {
7531         /* HP */
7532         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7533         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7534         /* Int speaker */
7535         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7536         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7537
7538         /* enable unsolicited event */
7539         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7540         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7541
7542         { } /* end */
7543 };
7544
7545 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7546         /* HP */
7547         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7548         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7549         /* Subwoofer */
7550         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7551         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7552
7553         /* enable unsolicited event */
7554         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7555
7556         { } /* end */
7557 };
7558
7559 static struct hda_verb alc883_tagra_verbs[] = {
7560         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7561         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7562
7563         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7564         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7565
7566         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7567         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7568         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7569
7570         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7571         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7572         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7573         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7574
7575         { } /* end */
7576 };
7577
7578 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7579         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7580         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7581         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7582         { } /* end */
7583 };
7584
7585 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7586         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7587         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7588         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7589         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7590         { } /* end */
7591 };
7592
7593 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7594         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7595         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7596         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7597         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7598         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7599         { } /* end */
7600 };
7601
7602 static struct hda_verb alc883_haier_w66_verbs[] = {
7603         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7604         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7605
7606         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7607
7608         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7609         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7610         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7611         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7612         { } /* end */
7613 };
7614
7615 static struct hda_verb alc888_lenovo_sky_verbs[] = {
7616         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7617         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7618         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7619         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7620         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7621         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7622         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7623         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7624         { } /* end */
7625 };
7626
7627 static struct hda_verb alc888_3st_hp_verbs[] = {
7628         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7629         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7630         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7631         { }
7632 };
7633
7634 static struct hda_verb alc888_6st_dell_verbs[] = {
7635         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7636         { }
7637 };
7638
7639 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7640         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7641         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7642         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7643         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7644         { }
7645 };
7646
7647 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7648         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7649         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7650         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7651         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7652         { }
7653 };
7654
7655 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7656         { 2, alc888_3st_hp_2ch_init },
7657         { 6, alc888_3st_hp_6ch_init },
7658 };
7659
7660 /* toggle front-jack and RCA according to the hp-jack state */
7661 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7662 {
7663         unsigned int present;
7664
7665         present = snd_hda_codec_read(codec, 0x1b, 0,
7666                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7667         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7668                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7669         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7670                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7671 }
7672
7673 /* toggle RCA according to the front-jack state */
7674 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7675 {
7676         unsigned int present;
7677
7678         present = snd_hda_codec_read(codec, 0x14, 0,
7679                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7680         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7681                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7682 }
7683
7684 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7685                                              unsigned int res)
7686 {
7687         if ((res >> 26) == ALC880_HP_EVENT)
7688                 alc888_lenovo_ms7195_front_automute(codec);
7689         if ((res >> 26) == ALC880_FRONT_EVENT)
7690                 alc888_lenovo_ms7195_rca_automute(codec);
7691 }
7692
7693 static struct hda_verb alc883_medion_md2_verbs[] = {
7694         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7695         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7696
7697         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7698
7699         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7700         { } /* end */
7701 };
7702
7703 /* toggle speaker-output according to the hp-jack state */
7704 static void alc883_medion_md2_automute(struct hda_codec *codec)
7705 {
7706         unsigned int present;
7707
7708         present = snd_hda_codec_read(codec, 0x14, 0,
7709                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7710         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7711                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7712 }
7713
7714 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7715                                           unsigned int res)
7716 {
7717         if ((res >> 26) == ALC880_HP_EVENT)
7718                 alc883_medion_md2_automute(codec);
7719 }
7720
7721 /* toggle speaker-output according to the hp-jack state */
7722 static void alc883_tagra_automute(struct hda_codec *codec)
7723 {
7724         unsigned int present;
7725         unsigned char bits;
7726
7727         present = snd_hda_codec_read(codec, 0x14, 0,
7728                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7729         bits = present ? HDA_AMP_MUTE : 0;
7730         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7731                                  HDA_AMP_MUTE, bits);
7732         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7733                                   present ? 1 : 3);
7734 }
7735
7736 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7737 {
7738         if ((res >> 26) == ALC880_HP_EVENT)
7739                 alc883_tagra_automute(codec);
7740 }
7741
7742 /* toggle speaker-output according to the hp-jack state */
7743 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7744 {
7745         unsigned int present;
7746         unsigned char bits;
7747
7748         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7749                 & AC_PINSENSE_PRESENCE;
7750         bits = present ? HDA_AMP_MUTE : 0;
7751         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7752                                  HDA_AMP_MUTE, bits);
7753 }
7754
7755 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7756 {
7757         unsigned int present;
7758
7759         present = snd_hda_codec_read(codec, 0x18, 0,
7760                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7761         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7762                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7763 }
7764
7765 static void alc883_clevo_m720_automute(struct hda_codec *codec)
7766 {
7767         alc883_clevo_m720_hp_automute(codec);
7768         alc883_clevo_m720_mic_automute(codec);
7769 }
7770
7771 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7772                                            unsigned int res)
7773 {
7774         switch (res >> 26) {
7775         case ALC880_HP_EVENT:
7776                 alc883_clevo_m720_hp_automute(codec);
7777                 break;
7778         case ALC880_MIC_EVENT:
7779                 alc883_clevo_m720_mic_automute(codec);
7780                 break;
7781         }
7782 }
7783
7784 /* toggle speaker-output according to the hp-jack state */
7785 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7786 {
7787         unsigned int present;
7788         unsigned char bits;
7789
7790         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7791                 & AC_PINSENSE_PRESENCE;
7792         bits = present ? HDA_AMP_MUTE : 0;
7793         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7794                                  HDA_AMP_MUTE, bits);
7795 }
7796
7797 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7798                                                   unsigned int res)
7799 {
7800         if ((res >> 26) == ALC880_HP_EVENT)
7801                 alc883_2ch_fujitsu_pi2515_automute(codec);
7802 }
7803
7804 static void alc883_haier_w66_automute(struct hda_codec *codec)
7805 {
7806         unsigned int present;
7807         unsigned char bits;
7808
7809         present = snd_hda_codec_read(codec, 0x1b, 0,
7810                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7811         bits = present ? 0x80 : 0;
7812         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7813                                  0x80, bits);
7814 }
7815
7816 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7817                                          unsigned int res)
7818 {
7819         if ((res >> 26) == ALC880_HP_EVENT)
7820                 alc883_haier_w66_automute(codec);
7821 }
7822
7823 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7824 {
7825         unsigned int present;
7826         unsigned char bits;
7827
7828         present = snd_hda_codec_read(codec, 0x14, 0,
7829                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7830         bits = present ? HDA_AMP_MUTE : 0;
7831         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7832                                  HDA_AMP_MUTE, bits);
7833 }
7834
7835 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7836 {
7837         unsigned int present;
7838         unsigned char bits;
7839
7840         present = snd_hda_codec_read(codec, 0x1b, 0,
7841                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7842         bits = present ? HDA_AMP_MUTE : 0;
7843         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7844                                  HDA_AMP_MUTE, bits);
7845         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7846                                  HDA_AMP_MUTE, bits);
7847 }
7848
7849 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7850                                            unsigned int res)
7851 {
7852         if ((res >> 26) == ALC880_HP_EVENT)
7853                 alc883_lenovo_101e_all_automute(codec);
7854         if ((res >> 26) == ALC880_FRONT_EVENT)
7855                 alc883_lenovo_101e_ispeaker_automute(codec);
7856 }
7857
7858 /* toggle speaker-output according to the hp-jack state */
7859 static void alc883_acer_aspire_automute(struct hda_codec *codec)
7860 {
7861         unsigned int present;
7862
7863         present = snd_hda_codec_read(codec, 0x14, 0,
7864                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7865         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7866                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7867         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7868                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7869 }
7870
7871 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
7872                                            unsigned int res)
7873 {
7874         if ((res >> 26) == ALC880_HP_EVENT)
7875                 alc883_acer_aspire_automute(codec);
7876 }
7877
7878 static struct hda_verb alc883_acer_eapd_verbs[] = {
7879         /* HP Pin: output 0 (0x0c) */
7880         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7881         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7882         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7883         /* Front Pin: output 0 (0x0c) */
7884         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7885         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7886         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7887         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
7888         /* eanable EAPD on medion laptop */
7889         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7890         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
7891         /* enable unsolicited event */
7892         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7893         { }
7894 };
7895
7896 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
7897 {
7898         unsigned int present;
7899
7900         present = snd_hda_codec_read(codec, 0x1b, 0,
7901                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7902         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7903                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7904         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7905                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7906         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7907                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7908         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7909                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7910 }
7911
7912 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
7913                                              unsigned int res)
7914 {
7915         switch (res >> 26) {
7916         case ALC880_HP_EVENT:
7917                 printk("hp_event\n");
7918                 alc888_6st_dell_front_automute(codec);
7919                 break;
7920         }
7921 }
7922
7923 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
7924 {
7925         unsigned int mute;
7926         unsigned int present;
7927
7928         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
7929         present = snd_hda_codec_read(codec, 0x1b, 0,
7930                                      AC_VERB_GET_PIN_SENSE, 0);
7931         present = (present & 0x80000000) != 0;
7932         if (present) {
7933                 /* mute internal speaker */
7934                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7935                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7936                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7937                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7938                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7939                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7940                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7941                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7942                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
7943                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7944         } else {
7945                 /* unmute internal speaker if necessary */
7946                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
7947                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7948                                          HDA_AMP_MUTE, mute);
7949                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7950                                          HDA_AMP_MUTE, mute);
7951                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7952                                          HDA_AMP_MUTE, mute);
7953                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7954                                          HDA_AMP_MUTE, mute);
7955                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
7956                                          HDA_AMP_MUTE, mute);
7957         }
7958 }
7959
7960 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
7961                                              unsigned int res)
7962 {
7963         if ((res >> 26) == ALC880_HP_EVENT)
7964                 alc888_lenovo_sky_front_automute(codec);
7965 }
7966
7967 /*
7968  * generic initialization of ADC, input mixers and output mixers
7969  */
7970 static struct hda_verb alc883_auto_init_verbs[] = {
7971         /*
7972          * Unmute ADC0-2 and set the default input to mic-in
7973          */
7974         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7975         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7976         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7977         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7978
7979         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7980          * mixer widget
7981          * Note: PASD motherboards uses the Line In 2 as the input for
7982          * front panel mic (mic 2)
7983          */
7984         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7985         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7986         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7987         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7988         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7989         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7990
7991         /*
7992          * Set up output mixers (0x0c - 0x0f)
7993          */
7994         /* set vol=0 to output mixers */
7995         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7996         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7997         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7998         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7999         /* set up input amps for analog loopback */
8000         /* Amp Indices: DAC = 0, mixer = 1 */
8001         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8002         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8003         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8004         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8005         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8006         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8007         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8008         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8009         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8010         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8011
8012         /* FIXME: use matrix-type input source selection */
8013         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8014         /* Input mixer1 */
8015         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8016         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8017         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8018         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8019         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8020         /* Input mixer2 */
8021         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8022         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8023         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8024         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8025         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8026
8027         { }
8028 };
8029
8030 static struct hda_verb alc888_asus_m90v_verbs[] = {
8031         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8032         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8033         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8034         /* enable unsolicited event */
8035         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8036         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8037         { } /* end */
8038 };
8039
8040 static void alc883_nb_mic_automute(struct hda_codec *codec)
8041 {
8042         unsigned int present;
8043
8044         present = snd_hda_codec_read(codec, 0x18, 0,
8045                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8046         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8047                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8048         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8049                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8050 }
8051
8052 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8053 {
8054         unsigned int present;
8055         unsigned char bits;
8056
8057         present = snd_hda_codec_read(codec, 0x1b, 0,
8058                                      AC_VERB_GET_PIN_SENSE, 0)
8059                 & AC_PINSENSE_PRESENCE;
8060         bits = present ? 0 : PIN_OUT;
8061         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8062                             bits);
8063         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8064                             bits);
8065         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8066                             bits);
8067 }
8068
8069 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8070                                            unsigned int res)
8071 {
8072         switch (res >> 26) {
8073         case ALC880_HP_EVENT:
8074                 alc883_M90V_speaker_automute(codec);
8075                 break;
8076         case ALC880_MIC_EVENT:
8077                 alc883_nb_mic_automute(codec);
8078                 break;
8079         }
8080 }
8081
8082 static void alc883_mode2_inithook(struct hda_codec *codec)
8083 {
8084         alc883_M90V_speaker_automute(codec);
8085         alc883_nb_mic_automute(codec);
8086 }
8087
8088 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8089         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8090         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8091         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8092         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8093         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8094         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8095         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8096         /* enable unsolicited event */
8097         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8098         { } /* end */
8099 };
8100
8101 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8102 {
8103         unsigned int present;
8104         unsigned char bits;
8105
8106         present = snd_hda_codec_read(codec, 0x14, 0,
8107                                      AC_VERB_GET_PIN_SENSE, 0)
8108                 & AC_PINSENSE_PRESENCE;
8109         bits = present ? 0 : PIN_OUT;
8110         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8111                             bits);
8112 }
8113
8114 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8115                                            unsigned int res)
8116 {
8117         switch (res >> 26) {
8118         case ALC880_HP_EVENT:
8119                 alc883_eee1601_speaker_automute(codec);
8120                 break;
8121         }
8122 }
8123
8124 static void alc883_eee1601_inithook(struct hda_codec *codec)
8125 {
8126         alc883_eee1601_speaker_automute(codec);
8127 }
8128
8129 #ifdef CONFIG_SND_HDA_POWER_SAVE
8130 #define alc883_loopbacks        alc880_loopbacks
8131 #endif
8132
8133 /* pcm configuration: identiacal with ALC880 */
8134 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8135 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8136 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8137 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8138 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8139
8140 /*
8141  * configuration and preset
8142  */
8143 static const char *alc883_models[ALC883_MODEL_LAST] = {
8144         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8145         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8146         [ALC883_3ST_6ch]        = "3stack-6ch",
8147         [ALC883_6ST_DIG]        = "6stack-dig",
8148         [ALC883_TARGA_DIG]      = "targa-dig",
8149         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8150         [ALC883_ACER]           = "acer",
8151         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8152         [ALC883_MEDION]         = "medion",
8153         [ALC883_MEDION_MD2]     = "medion-md2",
8154         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8155         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8156         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8157         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8158         [ALC888_LENOVO_SKY] = "lenovo-sky",
8159         [ALC883_HAIER_W66]      = "haier-w66",
8160         [ALC888_3ST_HP]         = "3stack-hp",
8161         [ALC888_6ST_DELL]       = "6stack-dell",
8162         [ALC883_MITAC]          = "mitac",
8163         [ALC883_CLEVO_M720]     = "clevo-m720",
8164         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8165         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8166         [ALC883_AUTO]           = "auto",
8167 };
8168
8169 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8170         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8171         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8172         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8173         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8174         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8175         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8176         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8177         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8178         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8179         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8180         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8181         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8182         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8183         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8184         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8185         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8186         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8187         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8188         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8189         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8190         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8191         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8192         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8193         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8194         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8195         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8196         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8197         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8198         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8199         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8200         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8201         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8202         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8203         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8204         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8205         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8206         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8207         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8208         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8209         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8210         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8211         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8212         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8213         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8214         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8215         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8216         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8217         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8218         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8219         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8220         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8221         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8222         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8223         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8224         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8225         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8226         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8227         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8228         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8229         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8230         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8231         {}
8232 };
8233
8234 static struct alc_config_preset alc883_presets[] = {
8235         [ALC883_3ST_2ch_DIG] = {
8236                 .mixers = { alc883_3ST_2ch_mixer },
8237                 .init_verbs = { alc883_init_verbs },
8238                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8239                 .dac_nids = alc883_dac_nids,
8240                 .dig_out_nid = ALC883_DIGOUT_NID,
8241                 .dig_in_nid = ALC883_DIGIN_NID,
8242                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8243                 .channel_mode = alc883_3ST_2ch_modes,
8244                 .input_mux = &alc883_capture_source,
8245         },
8246         [ALC883_3ST_6ch_DIG] = {
8247                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8248                 .init_verbs = { alc883_init_verbs },
8249                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8250                 .dac_nids = alc883_dac_nids,
8251                 .dig_out_nid = ALC883_DIGOUT_NID,
8252                 .dig_in_nid = ALC883_DIGIN_NID,
8253                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8254                 .channel_mode = alc883_3ST_6ch_modes,
8255                 .need_dac_fix = 1,
8256                 .input_mux = &alc883_capture_source,
8257         },
8258         [ALC883_3ST_6ch] = {
8259                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8260                 .init_verbs = { alc883_init_verbs },
8261                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8262                 .dac_nids = alc883_dac_nids,
8263                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8264                 .channel_mode = alc883_3ST_6ch_modes,
8265                 .need_dac_fix = 1,
8266                 .input_mux = &alc883_capture_source,
8267         },
8268         [ALC883_3ST_6ch_INTEL] = {
8269                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8270                 .init_verbs = { alc883_init_verbs },
8271                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8272                 .dac_nids = alc883_dac_nids,
8273                 .dig_out_nid = ALC883_DIGOUT_NID,
8274                 .dig_in_nid = ALC883_DIGIN_NID,
8275                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8276                 .channel_mode = alc883_3ST_6ch_intel_modes,
8277                 .need_dac_fix = 1,
8278                 .input_mux = &alc883_3stack_6ch_intel,
8279         },
8280         [ALC883_6ST_DIG] = {
8281                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8282                 .init_verbs = { alc883_init_verbs },
8283                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8284                 .dac_nids = alc883_dac_nids,
8285                 .dig_out_nid = ALC883_DIGOUT_NID,
8286                 .dig_in_nid = ALC883_DIGIN_NID,
8287                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8288                 .channel_mode = alc883_sixstack_modes,
8289                 .input_mux = &alc883_capture_source,
8290         },
8291         [ALC883_TARGA_DIG] = {
8292                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8293                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8294                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8295                 .dac_nids = alc883_dac_nids,
8296                 .dig_out_nid = ALC883_DIGOUT_NID,
8297                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8298                 .channel_mode = alc883_3ST_6ch_modes,
8299                 .need_dac_fix = 1,
8300                 .input_mux = &alc883_capture_source,
8301                 .unsol_event = alc883_tagra_unsol_event,
8302                 .init_hook = alc883_tagra_automute,
8303         },
8304         [ALC883_TARGA_2ch_DIG] = {
8305                 .mixers = { alc883_tagra_2ch_mixer},
8306                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8307                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8308                 .dac_nids = alc883_dac_nids,
8309                 .adc_nids = alc883_adc_nids_alt,
8310                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8311                 .dig_out_nid = ALC883_DIGOUT_NID,
8312                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8313                 .channel_mode = alc883_3ST_2ch_modes,
8314                 .input_mux = &alc883_capture_source,
8315                 .unsol_event = alc883_tagra_unsol_event,
8316                 .init_hook = alc883_tagra_automute,
8317         },
8318         [ALC883_ACER] = {
8319                 .mixers = { alc883_base_mixer },
8320                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8321                  * and the headphone jack.  Turn this on and rely on the
8322                  * standard mute methods whenever the user wants to turn
8323                  * these outputs off.
8324                  */
8325                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8326                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8327                 .dac_nids = alc883_dac_nids,
8328                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8329                 .channel_mode = alc883_3ST_2ch_modes,
8330                 .input_mux = &alc883_capture_source,
8331         },
8332         [ALC883_ACER_ASPIRE] = {
8333                 .mixers = { alc883_acer_aspire_mixer },
8334                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8335                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8336                 .dac_nids = alc883_dac_nids,
8337                 .dig_out_nid = ALC883_DIGOUT_NID,
8338                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8339                 .channel_mode = alc883_3ST_2ch_modes,
8340                 .input_mux = &alc883_capture_source,
8341                 .unsol_event = alc883_acer_aspire_unsol_event,
8342                 .init_hook = alc883_acer_aspire_automute,
8343         },
8344         [ALC883_MEDION] = {
8345                 .mixers = { alc883_fivestack_mixer,
8346                             alc883_chmode_mixer },
8347                 .init_verbs = { alc883_init_verbs,
8348                                 alc883_medion_eapd_verbs },
8349                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8350                 .dac_nids = alc883_dac_nids,
8351                 .adc_nids = alc883_adc_nids_alt,
8352                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8353                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8354                 .channel_mode = alc883_sixstack_modes,
8355                 .input_mux = &alc883_capture_source,
8356         },
8357         [ALC883_MEDION_MD2] = {
8358                 .mixers = { alc883_medion_md2_mixer},
8359                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8360                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8361                 .dac_nids = alc883_dac_nids,
8362                 .dig_out_nid = ALC883_DIGOUT_NID,
8363                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8364                 .channel_mode = alc883_3ST_2ch_modes,
8365                 .input_mux = &alc883_capture_source,
8366                 .unsol_event = alc883_medion_md2_unsol_event,
8367                 .init_hook = alc883_medion_md2_automute,
8368         },
8369         [ALC883_LAPTOP_EAPD] = {
8370                 .mixers = { alc883_base_mixer },
8371                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8372                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8373                 .dac_nids = alc883_dac_nids,
8374                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8375                 .channel_mode = alc883_3ST_2ch_modes,
8376                 .input_mux = &alc883_capture_source,
8377         },
8378         [ALC883_CLEVO_M720] = {
8379                 .mixers = { alc883_clevo_m720_mixer },
8380                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8381                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8382                 .dac_nids = alc883_dac_nids,
8383                 .dig_out_nid = ALC883_DIGOUT_NID,
8384                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8385                 .channel_mode = alc883_3ST_2ch_modes,
8386                 .input_mux = &alc883_capture_source,
8387                 .unsol_event = alc883_clevo_m720_unsol_event,
8388                 .init_hook = alc883_clevo_m720_automute,
8389         },
8390         [ALC883_LENOVO_101E_2ch] = {
8391                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8392                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8393                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8394                 .dac_nids = alc883_dac_nids,
8395                 .adc_nids = alc883_adc_nids_alt,
8396                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8397                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8398                 .channel_mode = alc883_3ST_2ch_modes,
8399                 .input_mux = &alc883_lenovo_101e_capture_source,
8400                 .unsol_event = alc883_lenovo_101e_unsol_event,
8401                 .init_hook = alc883_lenovo_101e_all_automute,
8402         },
8403         [ALC883_LENOVO_NB0763] = {
8404                 .mixers = { alc883_lenovo_nb0763_mixer },
8405                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8406                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8407                 .dac_nids = alc883_dac_nids,
8408                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8409                 .channel_mode = alc883_3ST_2ch_modes,
8410                 .need_dac_fix = 1,
8411                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8412                 .unsol_event = alc883_medion_md2_unsol_event,
8413                 .init_hook = alc883_medion_md2_automute,
8414         },
8415         [ALC888_LENOVO_MS7195_DIG] = {
8416                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8417                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8418                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8419                 .dac_nids = alc883_dac_nids,
8420                 .dig_out_nid = ALC883_DIGOUT_NID,
8421                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8422                 .channel_mode = alc883_3ST_6ch_modes,
8423                 .need_dac_fix = 1,
8424                 .input_mux = &alc883_capture_source,
8425                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8426                 .init_hook = alc888_lenovo_ms7195_front_automute,
8427         },
8428         [ALC883_HAIER_W66] = {
8429                 .mixers = { alc883_tagra_2ch_mixer},
8430                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8431                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8432                 .dac_nids = alc883_dac_nids,
8433                 .dig_out_nid = ALC883_DIGOUT_NID,
8434                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8435                 .channel_mode = alc883_3ST_2ch_modes,
8436                 .input_mux = &alc883_capture_source,
8437                 .unsol_event = alc883_haier_w66_unsol_event,
8438                 .init_hook = alc883_haier_w66_automute,
8439         },
8440         [ALC888_3ST_HP] = {
8441                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8442                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8443                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8444                 .dac_nids = alc883_dac_nids,
8445                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8446                 .channel_mode = alc888_3st_hp_modes,
8447                 .need_dac_fix = 1,
8448                 .input_mux = &alc883_capture_source,
8449         },
8450         [ALC888_6ST_DELL] = {
8451                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8452                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8453                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8454                 .dac_nids = alc883_dac_nids,
8455                 .dig_out_nid = ALC883_DIGOUT_NID,
8456                 .dig_in_nid = ALC883_DIGIN_NID,
8457                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8458                 .channel_mode = alc883_sixstack_modes,
8459                 .input_mux = &alc883_capture_source,
8460                 .unsol_event = alc888_6st_dell_unsol_event,
8461                 .init_hook = alc888_6st_dell_front_automute,
8462         },
8463         [ALC883_MITAC] = {
8464                 .mixers = { alc883_mitac_mixer },
8465                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8466                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8467                 .dac_nids = alc883_dac_nids,
8468                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8469                 .channel_mode = alc883_3ST_2ch_modes,
8470                 .input_mux = &alc883_capture_source,
8471                 .unsol_event = alc883_mitac_unsol_event,
8472                 .init_hook = alc883_mitac_automute,
8473         },
8474         [ALC883_FUJITSU_PI2515] = {
8475                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8476                 .init_verbs = { alc883_init_verbs,
8477                                 alc883_2ch_fujitsu_pi2515_verbs},
8478                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8479                 .dac_nids = alc883_dac_nids,
8480                 .dig_out_nid = ALC883_DIGOUT_NID,
8481                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8482                 .channel_mode = alc883_3ST_2ch_modes,
8483                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8484                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8485                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8486         },
8487         [ALC888_LENOVO_SKY] = {
8488                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8489                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8490                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8491                 .dac_nids = alc883_dac_nids,
8492                 .dig_out_nid = ALC883_DIGOUT_NID,
8493                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8494                 .channel_mode = alc883_sixstack_modes,
8495                 .need_dac_fix = 1,
8496                 .input_mux = &alc883_lenovo_sky_capture_source,
8497                 .unsol_event = alc883_lenovo_sky_unsol_event,
8498                 .init_hook = alc888_lenovo_sky_front_automute,
8499         },
8500         [ALC888_ASUS_M90V] = {
8501                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8502                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8503                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8504                 .dac_nids = alc883_dac_nids,
8505                 .dig_out_nid = ALC883_DIGOUT_NID,
8506                 .dig_in_nid = ALC883_DIGIN_NID,
8507                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8508                 .channel_mode = alc883_3ST_6ch_modes,
8509                 .need_dac_fix = 1,
8510                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8511                 .unsol_event = alc883_mode2_unsol_event,
8512                 .init_hook = alc883_mode2_inithook,
8513         },
8514         [ALC888_ASUS_EEE1601] = {
8515                 .mixers = { alc883_asus_eee1601_mixer },
8516                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
8517                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8518                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8519                 .dac_nids = alc883_dac_nids,
8520                 .dig_out_nid = ALC883_DIGOUT_NID,
8521                 .dig_in_nid = ALC883_DIGIN_NID,
8522                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8523                 .channel_mode = alc883_3ST_2ch_modes,
8524                 .need_dac_fix = 1,
8525                 .input_mux = &alc883_asus_eee1601_capture_source,
8526                 .unsol_event = alc883_eee1601_unsol_event,
8527                 .init_hook = alc883_eee1601_inithook,
8528         },
8529 };
8530
8531
8532 /*
8533  * BIOS auto configuration
8534  */
8535 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8536                                               hda_nid_t nid, int pin_type,
8537                                               int dac_idx)
8538 {
8539         /* set as output */
8540         struct alc_spec *spec = codec->spec;
8541         int idx;
8542
8543         alc_set_pin_output(codec, nid, pin_type);
8544         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8545                 idx = 4;
8546         else
8547                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8548         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8549
8550 }
8551
8552 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8553 {
8554         struct alc_spec *spec = codec->spec;
8555         int i;
8556
8557         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8558         for (i = 0; i <= HDA_SIDE; i++) {
8559                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8560                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8561                 if (nid)
8562                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8563                                                           i);
8564         }
8565 }
8566
8567 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8568 {
8569         struct alc_spec *spec = codec->spec;
8570         hda_nid_t pin;
8571
8572         pin = spec->autocfg.hp_pins[0];
8573         if (pin) /* connect to front */
8574                 /* use dac 0 */
8575                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8576         pin = spec->autocfg.speaker_pins[0];
8577         if (pin)
8578                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8579 }
8580
8581 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8582 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8583
8584 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8585 {
8586         struct alc_spec *spec = codec->spec;
8587         int i;
8588
8589         for (i = 0; i < AUTO_PIN_LAST; i++) {
8590                 hda_nid_t nid = spec->autocfg.input_pins[i];
8591                 if (alc883_is_input_pin(nid)) {
8592                         snd_hda_codec_write(codec, nid, 0,
8593                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8594                                             (i <= AUTO_PIN_FRONT_MIC ?
8595                                              PIN_VREF80 : PIN_IN));
8596                         if (nid != ALC883_PIN_CD_NID)
8597                                 snd_hda_codec_write(codec, nid, 0,
8598                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8599                                                     AMP_OUT_MUTE);
8600                 }
8601         }
8602 }
8603
8604 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8605
8606 /* almost identical with ALC880 parser... */
8607 static int alc883_parse_auto_config(struct hda_codec *codec)
8608 {
8609         struct alc_spec *spec = codec->spec;
8610         int err = alc880_parse_auto_config(codec);
8611
8612         if (err < 0)
8613                 return err;
8614         else if (!err)
8615                 return 0; /* no config found */
8616
8617         err = alc_auto_add_mic_boost(codec);
8618         if (err < 0)
8619                 return err;
8620
8621         /* hack - override the init verbs */
8622         spec->init_verbs[0] = alc883_auto_init_verbs;
8623
8624         return 1; /* config found */
8625 }
8626
8627 /* additional initialization for auto-configuration model */
8628 static void alc883_auto_init(struct hda_codec *codec)
8629 {
8630         struct alc_spec *spec = codec->spec;
8631         alc883_auto_init_multi_out(codec);
8632         alc883_auto_init_hp_out(codec);
8633         alc883_auto_init_analog_input(codec);
8634         alc883_auto_init_input_src(codec);
8635         if (spec->unsol_event)
8636                 alc_inithook(codec);
8637 }
8638
8639 static int patch_alc883(struct hda_codec *codec)
8640 {
8641         struct alc_spec *spec;
8642         int err, board_config;
8643
8644         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8645         if (spec == NULL)
8646                 return -ENOMEM;
8647
8648         codec->spec = spec;
8649
8650         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
8651
8652         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8653                                                   alc883_models,
8654                                                   alc883_cfg_tbl);
8655         if (board_config < 0) {
8656                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8657                        "trying auto-probe from BIOS...\n");
8658                 board_config = ALC883_AUTO;
8659         }
8660
8661         if (board_config == ALC883_AUTO) {
8662                 /* automatic parse from the BIOS config */
8663                 err = alc883_parse_auto_config(codec);
8664                 if (err < 0) {
8665                         alc_free(codec);
8666                         return err;
8667                 } else if (!err) {
8668                         printk(KERN_INFO
8669                                "hda_codec: Cannot set up configuration "
8670                                "from BIOS.  Using base mode...\n");
8671                         board_config = ALC883_3ST_2ch_DIG;
8672                 }
8673         }
8674
8675         if (board_config != ALC883_AUTO)
8676                 setup_preset(spec, &alc883_presets[board_config]);
8677
8678         switch (codec->vendor_id) {
8679         case 0x10ec0888:
8680                 if (codec->revision_id == 0x100101) {
8681                         spec->stream_name_analog = "ALC1200 Analog";
8682                         spec->stream_name_digital = "ALC1200 Digital";
8683                 } else {
8684                         spec->stream_name_analog = "ALC888 Analog";
8685                         spec->stream_name_digital = "ALC888 Digital";
8686                 }
8687                 break;
8688         case 0x10ec0889:
8689                 spec->stream_name_analog = "ALC889 Analog";
8690                 spec->stream_name_digital = "ALC889 Digital";
8691                 break;
8692         default:
8693                 spec->stream_name_analog = "ALC883 Analog";
8694                 spec->stream_name_digital = "ALC883 Digital";
8695                 break;
8696         }
8697
8698         spec->stream_analog_playback = &alc883_pcm_analog_playback;
8699         spec->stream_analog_capture = &alc883_pcm_analog_capture;
8700         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
8701
8702         spec->stream_digital_playback = &alc883_pcm_digital_playback;
8703         spec->stream_digital_capture = &alc883_pcm_digital_capture;
8704
8705         if (!spec->num_adc_nids) {
8706                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8707                 spec->adc_nids = alc883_adc_nids;
8708         }
8709         if (!spec->capsrc_nids)
8710                 spec->capsrc_nids = alc883_capsrc_nids;
8711         spec->is_mix_capture = 1; /* matrix-style capture */
8712         if (!spec->cap_mixer)
8713                 set_capture_mixer(spec);
8714
8715         spec->vmaster_nid = 0x0c;
8716
8717         codec->patch_ops = alc_patch_ops;
8718         if (board_config == ALC883_AUTO)
8719                 spec->init_hook = alc883_auto_init;
8720
8721 #ifdef CONFIG_SND_HDA_POWER_SAVE
8722         if (!spec->loopback.amplist)
8723                 spec->loopback.amplist = alc883_loopbacks;
8724 #endif
8725
8726         return 0;
8727 }
8728
8729 /*
8730  * ALC262 support
8731  */
8732
8733 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
8734 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
8735
8736 #define alc262_dac_nids         alc260_dac_nids
8737 #define alc262_adc_nids         alc882_adc_nids
8738 #define alc262_adc_nids_alt     alc882_adc_nids_alt
8739 #define alc262_capsrc_nids      alc882_capsrc_nids
8740 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
8741
8742 #define alc262_modes            alc260_modes
8743 #define alc262_capture_source   alc882_capture_source
8744
8745 static hda_nid_t alc262_dmic_adc_nids[1] = {
8746         /* ADC0 */
8747         0x09
8748 };
8749
8750 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
8751
8752 static struct snd_kcontrol_new alc262_base_mixer[] = {
8753         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8754         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8755         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8756         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8757         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8758         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8759         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8760         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8761         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8762         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8763         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8764         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8765         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8766            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8767         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
8768         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8769         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8770         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
8771         { } /* end */
8772 };
8773
8774 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
8775         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8776         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8777         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8778         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8779         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8780         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8781         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8782         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8783         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8784         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8785         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8786         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8787         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8788            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8789         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
8790         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8791         { } /* end */
8792 };
8793
8794 /* update HP, line and mono-out pins according to the master switch */
8795 static void alc262_hp_master_update(struct hda_codec *codec)
8796 {
8797         struct alc_spec *spec = codec->spec;
8798         int val = spec->master_sw;
8799
8800         /* HP & line-out */
8801         snd_hda_codec_write_cache(codec, 0x1b, 0,
8802                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8803                                   val ? PIN_HP : 0);
8804         snd_hda_codec_write_cache(codec, 0x15, 0,
8805                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8806                                   val ? PIN_HP : 0);
8807         /* mono (speaker) depending on the HP jack sense */
8808         val = val && !spec->jack_present;
8809         snd_hda_codec_write_cache(codec, 0x16, 0,
8810                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8811                                   val ? PIN_OUT : 0);
8812 }
8813
8814 static void alc262_hp_bpc_automute(struct hda_codec *codec)
8815 {
8816         struct alc_spec *spec = codec->spec;
8817         unsigned int presence;
8818         presence = snd_hda_codec_read(codec, 0x1b, 0,
8819                                       AC_VERB_GET_PIN_SENSE, 0);
8820         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8821         alc262_hp_master_update(codec);
8822 }
8823
8824 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
8825 {
8826         if ((res >> 26) != ALC880_HP_EVENT)
8827                 return;
8828         alc262_hp_bpc_automute(codec);
8829 }
8830
8831 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
8832 {
8833         struct alc_spec *spec = codec->spec;
8834         unsigned int presence;
8835         presence = snd_hda_codec_read(codec, 0x15, 0,
8836                                       AC_VERB_GET_PIN_SENSE, 0);
8837         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8838         alc262_hp_master_update(codec);
8839 }
8840
8841 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
8842                                            unsigned int res)
8843 {
8844         if ((res >> 26) != ALC880_HP_EVENT)
8845                 return;
8846         alc262_hp_wildwest_automute(codec);
8847 }
8848
8849 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
8850                                    struct snd_ctl_elem_value *ucontrol)
8851 {
8852         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8853         struct alc_spec *spec = codec->spec;
8854         *ucontrol->value.integer.value = spec->master_sw;
8855         return 0;
8856 }
8857
8858 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
8859                                    struct snd_ctl_elem_value *ucontrol)
8860 {
8861         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8862         struct alc_spec *spec = codec->spec;
8863         int val = !!*ucontrol->value.integer.value;
8864
8865         if (val == spec->master_sw)
8866                 return 0;
8867         spec->master_sw = val;
8868         alc262_hp_master_update(codec);
8869         return 1;
8870 }
8871
8872 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
8873         {
8874                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8875                 .name = "Master Playback Switch",
8876                 .info = snd_ctl_boolean_mono_info,
8877                 .get = alc262_hp_master_sw_get,
8878                 .put = alc262_hp_master_sw_put,
8879         },
8880         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8881         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8882         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8883         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8884                               HDA_OUTPUT),
8885         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8886                             HDA_OUTPUT),
8887         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8888         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8889         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8890         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8891         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8892         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8893         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8894         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8895         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8896         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8897         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8898         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8899         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
8900         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
8901         { } /* end */
8902 };
8903
8904 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
8905         {
8906                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8907                 .name = "Master Playback Switch",
8908                 .info = snd_ctl_boolean_mono_info,
8909                 .get = alc262_hp_master_sw_get,
8910                 .put = alc262_hp_master_sw_put,
8911         },
8912         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8913         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8914         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8915         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8916         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8917                               HDA_OUTPUT),
8918         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8919                             HDA_OUTPUT),
8920         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
8921         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
8922         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
8923         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8924         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8925         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8926         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8927         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8928         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8929         { } /* end */
8930 };
8931
8932 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
8933         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8934         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8935         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
8936         { } /* end */
8937 };
8938
8939 /* mute/unmute internal speaker according to the hp jack and mute state */
8940 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
8941 {
8942         struct alc_spec *spec = codec->spec;
8943
8944         if (force || !spec->sense_updated) {
8945                 unsigned int present;
8946                 present = snd_hda_codec_read(codec, 0x15, 0,
8947                                              AC_VERB_GET_PIN_SENSE, 0);
8948                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8949                 spec->sense_updated = 1;
8950         }
8951         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
8952                                  spec->jack_present ? HDA_AMP_MUTE : 0);
8953 }
8954
8955 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
8956                                         unsigned int res)
8957 {
8958         if ((res >> 26) != ALC880_HP_EVENT)
8959                 return;
8960         alc262_hp_t5735_automute(codec, 1);
8961 }
8962
8963 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
8964 {
8965         alc262_hp_t5735_automute(codec, 1);
8966 }
8967
8968 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
8969         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8970         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8971         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8972         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8973         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8974         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8975         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8976         { } /* end */
8977 };
8978
8979 static struct hda_verb alc262_hp_t5735_verbs[] = {
8980         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8981         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8982
8983         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8984         { }
8985 };
8986
8987 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
8988         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8989         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8990         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8991         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
8992         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8993         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8994         { } /* end */
8995 };
8996
8997 static struct hda_verb alc262_hp_rp5700_verbs[] = {
8998         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8999         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9000         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9001         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9002         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9003         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9004         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9005         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9006         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9007         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9008         {}
9009 };
9010
9011 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9012         .num_items = 1,
9013         .items = {
9014                 { "Line", 0x1 },
9015         },
9016 };
9017
9018 /* bind hp and internal speaker mute (with plug check) */
9019 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9020                                      struct snd_ctl_elem_value *ucontrol)
9021 {
9022         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9023         long *valp = ucontrol->value.integer.value;
9024         int change;
9025
9026         /* change hp mute */
9027         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9028                                           HDA_AMP_MUTE,
9029                                           valp[0] ? 0 : HDA_AMP_MUTE);
9030         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9031                                            HDA_AMP_MUTE,
9032                                            valp[1] ? 0 : HDA_AMP_MUTE);
9033         if (change) {
9034                 /* change speaker according to HP jack state */
9035                 struct alc_spec *spec = codec->spec;
9036                 unsigned int mute;
9037                 if (spec->jack_present)
9038                         mute = HDA_AMP_MUTE;
9039                 else
9040                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9041                                                       HDA_OUTPUT, 0);
9042                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9043                                          HDA_AMP_MUTE, mute);
9044         }
9045         return change;
9046 }
9047
9048 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9049         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9050         {
9051                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9052                 .name = "Master Playback Switch",
9053                 .info = snd_hda_mixer_amp_switch_info,
9054                 .get = snd_hda_mixer_amp_switch_get,
9055                 .put = alc262_sony_master_sw_put,
9056                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9057         },
9058         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9059         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9060         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9061         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9062         { } /* end */
9063 };
9064
9065 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9066         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9067         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9068         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9069         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9070         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9071         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9072         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9073         { } /* end */
9074 };
9075
9076 #define alc262_capture_mixer            alc882_capture_mixer
9077 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9078
9079 /*
9080  * generic initialization of ADC, input mixers and output mixers
9081  */
9082 static struct hda_verb alc262_init_verbs[] = {
9083         /*
9084          * Unmute ADC0-2 and set the default input to mic-in
9085          */
9086         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9087         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9088         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9089         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9090         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9091         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9092
9093         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9094          * mixer widget
9095          * Note: PASD motherboards uses the Line In 2 as the input for
9096          * front panel mic (mic 2)
9097          */
9098         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9099         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9100         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9101         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9102         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9103         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9104
9105         /*
9106          * Set up output mixers (0x0c - 0x0e)
9107          */
9108         /* set vol=0 to output mixers */
9109         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9110         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9111         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9112         /* set up input amps for analog loopback */
9113         /* Amp Indices: DAC = 0, mixer = 1 */
9114         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9115         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9116         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9117         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9118         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9119         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9120
9121         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9122         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9123         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9124         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9125         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9126         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9127
9128         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9129         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9130         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9131         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9132         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9133
9134         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9135         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9136
9137         /* FIXME: use matrix-type input source selection */
9138         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9139         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9140         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9141         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9142         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9143         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9144         /* Input mixer2 */
9145         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9146         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9147         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9148         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9149         /* Input mixer3 */
9150         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9151         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9152         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9153         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9154
9155         { }
9156 };
9157
9158 static struct hda_verb alc262_eapd_verbs[] = {
9159         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9160         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9161         { }
9162 };
9163
9164 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9165         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9166         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9167         {}
9168 };
9169
9170 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9171         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9172         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9173         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9174
9175         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9176         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9177         {}
9178 };
9179
9180 static struct hda_verb alc262_sony_unsol_verbs[] = {
9181         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9182         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9183         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9184
9185         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9186         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9187         {}
9188 };
9189
9190 static struct hda_input_mux alc262_dmic_capture_source = {
9191         .num_items = 2,
9192         .items = {
9193                 { "Int DMic", 0x9 },
9194                 { "Mic", 0x0 },
9195         },
9196 };
9197
9198 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9199         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9200         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9201         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9202         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9203         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9204         { } /* end */
9205 };
9206
9207 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9208         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9209         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9210         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9211         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9212         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9213         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9214         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9215         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9216         {}
9217 };
9218
9219 static void alc262_dmic_automute(struct hda_codec *codec)
9220 {
9221         unsigned int present;
9222
9223         present = snd_hda_codec_read(codec, 0x18, 0,
9224                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9225         snd_hda_codec_write(codec, 0x22, 0,
9226                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9227 }
9228
9229 /* toggle speaker-output according to the hp-jack state */
9230 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9231 {
9232         unsigned int present;
9233         unsigned char bits;
9234
9235         present = snd_hda_codec_read(codec, 0x15, 0,
9236                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9237         bits = present ? 0 : PIN_OUT;
9238         snd_hda_codec_write(codec, 0x14, 0,
9239                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9240 }
9241
9242
9243
9244 /* unsolicited event for HP jack sensing */
9245 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9246                                        unsigned int res)
9247 {
9248         if ((res >> 26) == ALC880_HP_EVENT)
9249                 alc262_toshiba_s06_speaker_automute(codec);
9250         if ((res >> 26) == ALC880_MIC_EVENT)
9251                 alc262_dmic_automute(codec);
9252
9253 }
9254
9255 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9256 {
9257         alc262_toshiba_s06_speaker_automute(codec);
9258         alc262_dmic_automute(codec);
9259 }
9260
9261 /* mute/unmute internal speaker according to the hp jack and mute state */
9262 static void alc262_hippo_automute(struct hda_codec *codec)
9263 {
9264         struct alc_spec *spec = codec->spec;
9265         unsigned int mute;
9266         unsigned int present;
9267
9268         /* need to execute and sync at first */
9269         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9270         present = snd_hda_codec_read(codec, 0x15, 0,
9271                                      AC_VERB_GET_PIN_SENSE, 0);
9272         spec->jack_present = (present & 0x80000000) != 0;
9273         if (spec->jack_present) {
9274                 /* mute internal speaker */
9275                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9276                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9277         } else {
9278                 /* unmute internal speaker if necessary */
9279                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9280                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9281                                          HDA_AMP_MUTE, mute);
9282         }
9283 }
9284
9285 /* unsolicited event for HP jack sensing */
9286 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9287                                        unsigned int res)
9288 {
9289         if ((res >> 26) != ALC880_HP_EVENT)
9290                 return;
9291         alc262_hippo_automute(codec);
9292 }
9293
9294 static void alc262_hippo1_automute(struct hda_codec *codec)
9295 {
9296         unsigned int mute;
9297         unsigned int present;
9298
9299         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9300         present = snd_hda_codec_read(codec, 0x1b, 0,
9301                                      AC_VERB_GET_PIN_SENSE, 0);
9302         present = (present & 0x80000000) != 0;
9303         if (present) {
9304                 /* mute internal speaker */
9305                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9306                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9307         } else {
9308                 /* unmute internal speaker if necessary */
9309                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9310                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9311                                          HDA_AMP_MUTE, mute);
9312         }
9313 }
9314
9315 /* unsolicited event for HP jack sensing */
9316 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9317                                        unsigned int res)
9318 {
9319         if ((res >> 26) != ALC880_HP_EVENT)
9320                 return;
9321         alc262_hippo1_automute(codec);
9322 }
9323
9324 /*
9325  * nec model
9326  *  0x15 = headphone
9327  *  0x16 = internal speaker
9328  *  0x18 = external mic
9329  */
9330
9331 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9332         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9333         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9334
9335         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9336         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9337         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9338
9339         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9340         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9341         { } /* end */
9342 };
9343
9344 static struct hda_verb alc262_nec_verbs[] = {
9345         /* Unmute Speaker */
9346         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9347
9348         /* Headphone */
9349         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9350         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9351
9352         /* External mic to headphone */
9353         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9354         /* External mic to speaker */
9355         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9356         {}
9357 };
9358
9359 /*
9360  * fujitsu model
9361  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9362  *  0x1b = port replicator headphone out
9363  */
9364
9365 #define ALC_HP_EVENT    0x37
9366
9367 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9368         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9369         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9370         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9371         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9372         {}
9373 };
9374
9375 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9376         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9377         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9378         {}
9379 };
9380
9381 static struct hda_input_mux alc262_fujitsu_capture_source = {
9382         .num_items = 3,
9383         .items = {
9384                 { "Mic", 0x0 },
9385                 { "Int Mic", 0x1 },
9386                 { "CD", 0x4 },
9387         },
9388 };
9389
9390 static struct hda_input_mux alc262_HP_capture_source = {
9391         .num_items = 5,
9392         .items = {
9393                 { "Mic", 0x0 },
9394                 { "Front Mic", 0x1 },
9395                 { "Line", 0x2 },
9396                 { "CD", 0x4 },
9397                 { "AUX IN", 0x6 },
9398         },
9399 };
9400
9401 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9402         .num_items = 4,
9403         .items = {
9404                 { "Mic", 0x0 },
9405                 { "Front Mic", 0x2 },
9406                 { "Line", 0x1 },
9407                 { "CD", 0x4 },
9408         },
9409 };
9410
9411 /* mute/unmute internal speaker according to the hp jacks and mute state */
9412 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9413 {
9414         struct alc_spec *spec = codec->spec;
9415         unsigned int mute;
9416
9417         if (force || !spec->sense_updated) {
9418                 unsigned int present;
9419                 /* need to execute and sync at first */
9420                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9421                 /* check laptop HP jack */
9422                 present = snd_hda_codec_read(codec, 0x14, 0,
9423                                              AC_VERB_GET_PIN_SENSE, 0);
9424                 /* need to execute and sync at first */
9425                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9426                 /* check docking HP jack */
9427                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9428                                               AC_VERB_GET_PIN_SENSE, 0);
9429                 if (present & AC_PINSENSE_PRESENCE)
9430                         spec->jack_present = 1;
9431                 else
9432                         spec->jack_present = 0;
9433                 spec->sense_updated = 1;
9434         }
9435         /* unmute internal speaker only if both HPs are unplugged and
9436          * master switch is on
9437          */
9438         if (spec->jack_present)
9439                 mute = HDA_AMP_MUTE;
9440         else
9441                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9442         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9443                                  HDA_AMP_MUTE, mute);
9444 }
9445
9446 /* unsolicited event for HP jack sensing */
9447 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9448                                        unsigned int res)
9449 {
9450         if ((res >> 26) != ALC_HP_EVENT)
9451                 return;
9452         alc262_fujitsu_automute(codec, 1);
9453 }
9454
9455 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9456 {
9457         alc262_fujitsu_automute(codec, 1);
9458 }
9459
9460 /* bind volumes of both NID 0x0c and 0x0d */
9461 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9462         .ops = &snd_hda_bind_vol,
9463         .values = {
9464                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9465                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9466                 0
9467         },
9468 };
9469
9470 /* mute/unmute internal speaker according to the hp jack and mute state */
9471 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9472 {
9473         struct alc_spec *spec = codec->spec;
9474         unsigned int mute;
9475
9476         if (force || !spec->sense_updated) {
9477                 unsigned int present_int_hp;
9478                 /* need to execute and sync at first */
9479                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9480                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9481                                         AC_VERB_GET_PIN_SENSE, 0);
9482                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9483                 spec->sense_updated = 1;
9484         }
9485         if (spec->jack_present) {
9486                 /* mute internal speaker */
9487                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9488                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9489                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9490                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9491         } else {
9492                 /* unmute internal speaker if necessary */
9493                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9494                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9495                                          HDA_AMP_MUTE, mute);
9496                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9497                                          HDA_AMP_MUTE, mute);
9498         }
9499 }
9500
9501 /* unsolicited event for HP jack sensing */
9502 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9503                                        unsigned int res)
9504 {
9505         if ((res >> 26) != ALC_HP_EVENT)
9506                 return;
9507         alc262_lenovo_3000_automute(codec, 1);
9508 }
9509
9510 /* bind hp and internal speaker mute (with plug check) */
9511 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9512                                          struct snd_ctl_elem_value *ucontrol)
9513 {
9514         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9515         long *valp = ucontrol->value.integer.value;
9516         int change;
9517
9518         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9519                                                  HDA_AMP_MUTE,
9520                                                  valp ? 0 : HDA_AMP_MUTE);
9521         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9522                                                  HDA_AMP_MUTE,
9523                                                  valp ? 0 : HDA_AMP_MUTE);
9524
9525         if (change)
9526                 alc262_fujitsu_automute(codec, 0);
9527         return change;
9528 }
9529
9530 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9531         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9532         {
9533                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9534                 .name = "Master Playback Switch",
9535                 .info = snd_hda_mixer_amp_switch_info,
9536                 .get = snd_hda_mixer_amp_switch_get,
9537                 .put = alc262_fujitsu_master_sw_put,
9538                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9539         },
9540         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9541         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9542         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9543         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9544         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9545         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9546         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9547         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9548         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9549         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9550         { } /* end */
9551 };
9552
9553 /* bind hp and internal speaker mute (with plug check) */
9554 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9555                                          struct snd_ctl_elem_value *ucontrol)
9556 {
9557         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9558         long *valp = ucontrol->value.integer.value;
9559         int change;
9560
9561         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9562                                                  HDA_AMP_MUTE,
9563                                                  valp ? 0 : HDA_AMP_MUTE);
9564
9565         if (change)
9566                 alc262_lenovo_3000_automute(codec, 0);
9567         return change;
9568 }
9569
9570 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9571         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9572         {
9573                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9574                 .name = "Master Playback Switch",
9575                 .info = snd_hda_mixer_amp_switch_info,
9576                 .get = snd_hda_mixer_amp_switch_get,
9577                 .put = alc262_lenovo_3000_master_sw_put,
9578                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9579         },
9580         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9581         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9582         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9583         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9584         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9585         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9586         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9587         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9588         { } /* end */
9589 };
9590
9591 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
9592         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9593         {
9594                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9595                 .name = "Master Playback Switch",
9596                 .info = snd_hda_mixer_amp_switch_info,
9597                 .get = snd_hda_mixer_amp_switch_get,
9598                 .put = alc262_sony_master_sw_put,
9599                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9600         },
9601         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9602         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9603         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9604         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9605         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9606         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9607         { } /* end */
9608 };
9609
9610 /* additional init verbs for Benq laptops */
9611 static struct hda_verb alc262_EAPD_verbs[] = {
9612         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9613         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9614         {}
9615 };
9616
9617 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9618         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9619         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9620
9621         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9622         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9623         {}
9624 };
9625
9626 /* Samsung Q1 Ultra Vista model setup */
9627 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9628         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9629         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9630         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9631         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9632         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9633         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9634         { } /* end */
9635 };
9636
9637 static struct hda_verb alc262_ultra_verbs[] = {
9638         /* output mixer */
9639         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9640         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9641         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9642         /* speaker */
9643         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9644         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9645         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9646         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9647         /* HP */
9648         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9649         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9650         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9651         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9652         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9653         /* internal mic */
9654         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9655         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9656         /* ADC, choose mic */
9657         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9658         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9659         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9660         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9661         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9662         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9663         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9664         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9665         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9666         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
9667         {}
9668 };
9669
9670 /* mute/unmute internal speaker according to the hp jack and mute state */
9671 static void alc262_ultra_automute(struct hda_codec *codec)
9672 {
9673         struct alc_spec *spec = codec->spec;
9674         unsigned int mute;
9675
9676         mute = 0;
9677         /* auto-mute only when HP is used as HP */
9678         if (!spec->cur_mux[0]) {
9679                 unsigned int present;
9680                 /* need to execute and sync at first */
9681                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9682                 present = snd_hda_codec_read(codec, 0x15, 0,
9683                                              AC_VERB_GET_PIN_SENSE, 0);
9684                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9685                 if (spec->jack_present)
9686                         mute = HDA_AMP_MUTE;
9687         }
9688         /* mute/unmute internal speaker */
9689         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9690                                  HDA_AMP_MUTE, mute);
9691         /* mute/unmute HP */
9692         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9693                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
9694 }
9695
9696 /* unsolicited event for HP jack sensing */
9697 static void alc262_ultra_unsol_event(struct hda_codec *codec,
9698                                        unsigned int res)
9699 {
9700         if ((res >> 26) != ALC880_HP_EVENT)
9701                 return;
9702         alc262_ultra_automute(codec);
9703 }
9704
9705 static struct hda_input_mux alc262_ultra_capture_source = {
9706         .num_items = 2,
9707         .items = {
9708                 { "Mic", 0x1 },
9709                 { "Headphone", 0x7 },
9710         },
9711 };
9712
9713 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
9714                                      struct snd_ctl_elem_value *ucontrol)
9715 {
9716         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9717         struct alc_spec *spec = codec->spec;
9718         int ret;
9719
9720         ret = alc_mux_enum_put(kcontrol, ucontrol);
9721         if (!ret)
9722                 return 0;
9723         /* reprogram the HP pin as mic or HP according to the input source */
9724         snd_hda_codec_write_cache(codec, 0x15, 0,
9725                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9726                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
9727         alc262_ultra_automute(codec); /* mute/unmute HP */
9728         return ret;
9729 }
9730
9731 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
9732         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
9733         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
9734         {
9735                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9736                 .name = "Capture Source",
9737                 .info = alc_mux_enum_info,
9738                 .get = alc_mux_enum_get,
9739                 .put = alc262_ultra_mux_enum_put,
9740         },
9741         { } /* end */
9742 };
9743
9744 /* add playback controls from the parsed DAC table */
9745 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
9746                                              const struct auto_pin_cfg *cfg)
9747 {
9748         hda_nid_t nid;
9749         int err;
9750
9751         spec->multiout.num_dacs = 1;    /* only use one dac */
9752         spec->multiout.dac_nids = spec->private_dac_nids;
9753         spec->multiout.dac_nids[0] = 2;
9754
9755         nid = cfg->line_out_pins[0];
9756         if (nid) {
9757                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9758                                   "Front Playback Volume",
9759                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
9760                 if (err < 0)
9761                         return err;
9762                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9763                                   "Front Playback Switch",
9764                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9765                 if (err < 0)
9766                         return err;
9767         }
9768
9769         nid = cfg->speaker_pins[0];
9770         if (nid) {
9771                 if (nid == 0x16) {
9772                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9773                                           "Speaker Playback Volume",
9774                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9775                                                               HDA_OUTPUT));
9776                         if (err < 0)
9777                                 return err;
9778                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9779                                           "Speaker Playback Switch",
9780                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9781                                                               HDA_OUTPUT));
9782                         if (err < 0)
9783                                 return err;
9784                 } else {
9785                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9786                                           "Speaker Playback Switch",
9787                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9788                                                               HDA_OUTPUT));
9789                         if (err < 0)
9790                                 return err;
9791                 }
9792         }
9793         nid = cfg->hp_pins[0];
9794         if (nid) {
9795                 /* spec->multiout.hp_nid = 2; */
9796                 if (nid == 0x16) {
9797                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9798                                           "Headphone Playback Volume",
9799                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9800                                                               HDA_OUTPUT));
9801                         if (err < 0)
9802                                 return err;
9803                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9804                                           "Headphone Playback Switch",
9805                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9806                                                               HDA_OUTPUT));
9807                         if (err < 0)
9808                                 return err;
9809                 } else {
9810                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9811                                           "Headphone Playback Switch",
9812                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9813                                                               HDA_OUTPUT));
9814                         if (err < 0)
9815                                 return err;
9816                 }
9817         }
9818         return 0;
9819 }
9820
9821 /* identical with ALC880 */
9822 #define alc262_auto_create_analog_input_ctls \
9823         alc880_auto_create_analog_input_ctls
9824
9825 /*
9826  * generic initialization of ADC, input mixers and output mixers
9827  */
9828 static struct hda_verb alc262_volume_init_verbs[] = {
9829         /*
9830          * Unmute ADC0-2 and set the default input to mic-in
9831          */
9832         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9833         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9834         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9835         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9836         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9837         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9838
9839         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9840          * mixer widget
9841          * Note: PASD motherboards uses the Line In 2 as the input for
9842          * front panel mic (mic 2)
9843          */
9844         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9845         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9846         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9847         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9848         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9849         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9850
9851         /*
9852          * Set up output mixers (0x0c - 0x0f)
9853          */
9854         /* set vol=0 to output mixers */
9855         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9856         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9857         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9858
9859         /* set up input amps for analog loopback */
9860         /* Amp Indices: DAC = 0, mixer = 1 */
9861         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9862         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9863         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9864         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9865         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9866         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9867
9868         /* FIXME: use matrix-type input source selection */
9869         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9870         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9871         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9872         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9873         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9874         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9875         /* Input mixer2 */
9876         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9877         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9878         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9879         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9880         /* Input mixer3 */
9881         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9882         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9883         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9884         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9885
9886         { }
9887 };
9888
9889 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
9890         /*
9891          * Unmute ADC0-2 and set the default input to mic-in
9892          */
9893         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9894         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9895         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9896         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9897         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9898         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9899
9900         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9901          * mixer widget
9902          * Note: PASD motherboards uses the Line In 2 as the input for
9903          * front panel mic (mic 2)
9904          */
9905         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9906         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9907         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9908         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9909         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9910         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9911         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9912         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9913
9914         /*
9915          * Set up output mixers (0x0c - 0x0e)
9916          */
9917         /* set vol=0 to output mixers */
9918         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9919         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9920         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9921
9922         /* set up input amps for analog loopback */
9923         /* Amp Indices: DAC = 0, mixer = 1 */
9924         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9925         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9926         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9927         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9928         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9929         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9930
9931         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9932         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9933         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9934
9935         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9936         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9937
9938         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9939         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9940
9941         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9942         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9943         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9944         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9945         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9946
9947         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9948         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9949         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9950         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9951         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9952         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9953
9954
9955         /* FIXME: use matrix-type input source selection */
9956         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9957         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9958         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9959         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9960         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9961         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9962         /* Input mixer2 */
9963         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9964         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9965         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9966         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9967         /* Input mixer3 */
9968         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9969         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9970         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9971         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9972
9973         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9974
9975         { }
9976 };
9977
9978 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
9979         /*
9980          * Unmute ADC0-2 and set the default input to mic-in
9981          */
9982         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9983         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9984         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9985         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9986         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9987         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9988
9989         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9990          * mixer widget
9991          * Note: PASD motherboards uses the Line In 2 as the input for front
9992          * panel mic (mic 2)
9993          */
9994         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9995         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9996         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9997         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9998         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9999         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10000         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10001         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10002         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10003         /*
10004          * Set up output mixers (0x0c - 0x0e)
10005          */
10006         /* set vol=0 to output mixers */
10007         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10008         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10009         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10010
10011         /* set up input amps for analog loopback */
10012         /* Amp Indices: DAC = 0, mixer = 1 */
10013         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10014         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10015         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10016         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10017         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10018         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10019
10020
10021         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10022         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10023         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10024         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10025         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10026         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10027         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10028
10029         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10030         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10031
10032         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10033         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10034
10035         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10036         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10037         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10038         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10039         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10040         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10041
10042         /* FIXME: use matrix-type input source selection */
10043         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10044         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10045         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10046         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10047         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10048         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10049         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10050         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10051         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10052         /* Input mixer2 */
10053         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10054         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10055         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10056         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10057         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10058         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10059         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10060         /* Input mixer3 */
10061         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10062         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10063         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10064         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10065         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10066         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10067         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10068
10069         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10070
10071         { }
10072 };
10073
10074 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10075
10076         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10077         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10078         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10079
10080         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10081         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10082         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10083         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10084
10085         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10086         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10087         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10088         {}
10089 };
10090
10091
10092 #ifdef CONFIG_SND_HDA_POWER_SAVE
10093 #define alc262_loopbacks        alc880_loopbacks
10094 #endif
10095
10096 /* pcm configuration: identiacal with ALC880 */
10097 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10098 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10099 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10100 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10101
10102 /*
10103  * BIOS auto configuration
10104  */
10105 static int alc262_parse_auto_config(struct hda_codec *codec)
10106 {
10107         struct alc_spec *spec = codec->spec;
10108         int err;
10109         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10110
10111         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10112                                            alc262_ignore);
10113         if (err < 0)
10114                 return err;
10115         if (!spec->autocfg.line_outs)
10116                 return 0; /* can't find valid BIOS pin config */
10117         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10118         if (err < 0)
10119                 return err;
10120         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10121         if (err < 0)
10122                 return err;
10123
10124         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10125
10126         if (spec->autocfg.dig_out_pin)
10127                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10128         if (spec->autocfg.dig_in_pin)
10129                 spec->dig_in_nid = ALC262_DIGIN_NID;
10130
10131         if (spec->kctls.list)
10132                 add_mixer(spec, spec->kctls.list);
10133
10134         add_verb(spec, alc262_volume_init_verbs);
10135         spec->num_mux_defs = 1;
10136         spec->input_mux = &spec->private_imux;
10137
10138         err = alc_auto_add_mic_boost(codec);
10139         if (err < 0)
10140                 return err;
10141
10142         store_pin_configs(codec);
10143         return 1;
10144 }
10145
10146 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10147 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10148 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10149 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10150
10151
10152 /* init callback for auto-configuration model -- overriding the default init */
10153 static void alc262_auto_init(struct hda_codec *codec)
10154 {
10155         struct alc_spec *spec = codec->spec;
10156         alc262_auto_init_multi_out(codec);
10157         alc262_auto_init_hp_out(codec);
10158         alc262_auto_init_analog_input(codec);
10159         alc262_auto_init_input_src(codec);
10160         if (spec->unsol_event)
10161                 alc_inithook(codec);
10162 }
10163
10164 /*
10165  * configuration and preset
10166  */
10167 static const char *alc262_models[ALC262_MODEL_LAST] = {
10168         [ALC262_BASIC]          = "basic",
10169         [ALC262_HIPPO]          = "hippo",
10170         [ALC262_HIPPO_1]        = "hippo_1",
10171         [ALC262_FUJITSU]        = "fujitsu",
10172         [ALC262_HP_BPC]         = "hp-bpc",
10173         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10174         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10175         [ALC262_HP_RP5700]      = "hp-rp5700",
10176         [ALC262_BENQ_ED8]       = "benq",
10177         [ALC262_BENQ_T31]       = "benq-t31",
10178         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10179         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10180         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10181         [ALC262_ULTRA]          = "ultra",
10182         [ALC262_LENOVO_3000]    = "lenovo-3000",
10183         [ALC262_NEC]            = "nec",
10184         [ALC262_AUTO]           = "auto",
10185 };
10186
10187 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10188         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10189         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10190         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
10191         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
10192         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
10193         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
10194         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
10195         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
10196         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10197         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10198         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10199         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10200         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10201         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10202         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10203         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10204         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10205         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10206         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10207         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10208         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10209         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10210                       ALC262_HP_TC_T5735),
10211         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10212         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10213         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10214         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10215         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10216         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10217         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10218                       ALC262_TOSHIBA_RX1),
10219         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10220         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10221         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10222         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
10223         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
10224         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10225         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10226         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10227         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10228         {}
10229 };
10230
10231 static struct alc_config_preset alc262_presets[] = {
10232         [ALC262_BASIC] = {
10233                 .mixers = { alc262_base_mixer },
10234                 .init_verbs = { alc262_init_verbs },
10235                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10236                 .dac_nids = alc262_dac_nids,
10237                 .hp_nid = 0x03,
10238                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10239                 .channel_mode = alc262_modes,
10240                 .input_mux = &alc262_capture_source,
10241         },
10242         [ALC262_HIPPO] = {
10243                 .mixers = { alc262_base_mixer },
10244                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10245                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10246                 .dac_nids = alc262_dac_nids,
10247                 .hp_nid = 0x03,
10248                 .dig_out_nid = ALC262_DIGOUT_NID,
10249                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10250                 .channel_mode = alc262_modes,
10251                 .input_mux = &alc262_capture_source,
10252                 .unsol_event = alc262_hippo_unsol_event,
10253                 .init_hook = alc262_hippo_automute,
10254         },
10255         [ALC262_HIPPO_1] = {
10256                 .mixers = { alc262_hippo1_mixer },
10257                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10258                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10259                 .dac_nids = alc262_dac_nids,
10260                 .hp_nid = 0x02,
10261                 .dig_out_nid = ALC262_DIGOUT_NID,
10262                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10263                 .channel_mode = alc262_modes,
10264                 .input_mux = &alc262_capture_source,
10265                 .unsol_event = alc262_hippo1_unsol_event,
10266                 .init_hook = alc262_hippo1_automute,
10267         },
10268         [ALC262_FUJITSU] = {
10269                 .mixers = { alc262_fujitsu_mixer },
10270                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10271                                 alc262_fujitsu_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_fujitsu_capture_source,
10279                 .unsol_event = alc262_fujitsu_unsol_event,
10280                 .init_hook = alc262_fujitsu_init_hook,
10281         },
10282         [ALC262_HP_BPC] = {
10283                 .mixers = { alc262_HP_BPC_mixer },
10284                 .init_verbs = { alc262_HP_BPC_init_verbs },
10285                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10286                 .dac_nids = alc262_dac_nids,
10287                 .hp_nid = 0x03,
10288                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10289                 .channel_mode = alc262_modes,
10290                 .input_mux = &alc262_HP_capture_source,
10291                 .unsol_event = alc262_hp_bpc_unsol_event,
10292                 .init_hook = alc262_hp_bpc_automute,
10293         },
10294         [ALC262_HP_BPC_D7000_WF] = {
10295                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10296                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10297                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10298                 .dac_nids = alc262_dac_nids,
10299                 .hp_nid = 0x03,
10300                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10301                 .channel_mode = alc262_modes,
10302                 .input_mux = &alc262_HP_D7000_capture_source,
10303                 .unsol_event = alc262_hp_wildwest_unsol_event,
10304                 .init_hook = alc262_hp_wildwest_automute,
10305         },
10306         [ALC262_HP_BPC_D7000_WL] = {
10307                 .mixers = { alc262_HP_BPC_WildWest_mixer,
10308                             alc262_HP_BPC_WildWest_option_mixer },
10309                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10310                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10311                 .dac_nids = alc262_dac_nids,
10312                 .hp_nid = 0x03,
10313                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10314                 .channel_mode = alc262_modes,
10315                 .input_mux = &alc262_HP_D7000_capture_source,
10316                 .unsol_event = alc262_hp_wildwest_unsol_event,
10317                 .init_hook = alc262_hp_wildwest_automute,
10318         },
10319         [ALC262_HP_TC_T5735] = {
10320                 .mixers = { alc262_hp_t5735_mixer },
10321                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10322                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10323                 .dac_nids = alc262_dac_nids,
10324                 .hp_nid = 0x03,
10325                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10326                 .channel_mode = alc262_modes,
10327                 .input_mux = &alc262_capture_source,
10328                 .unsol_event = alc262_hp_t5735_unsol_event,
10329                 .init_hook = alc262_hp_t5735_init_hook,
10330         },
10331         [ALC262_HP_RP5700] = {
10332                 .mixers = { alc262_hp_rp5700_mixer },
10333                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10334                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10335                 .dac_nids = alc262_dac_nids,
10336                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10337                 .channel_mode = alc262_modes,
10338                 .input_mux = &alc262_hp_rp5700_capture_source,
10339         },
10340         [ALC262_BENQ_ED8] = {
10341                 .mixers = { alc262_base_mixer },
10342                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
10343                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10344                 .dac_nids = alc262_dac_nids,
10345                 .hp_nid = 0x03,
10346                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10347                 .channel_mode = alc262_modes,
10348                 .input_mux = &alc262_capture_source,
10349         },
10350         [ALC262_SONY_ASSAMD] = {
10351                 .mixers = { alc262_sony_mixer },
10352                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10353                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10354                 .dac_nids = alc262_dac_nids,
10355                 .hp_nid = 0x02,
10356                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10357                 .channel_mode = alc262_modes,
10358                 .input_mux = &alc262_capture_source,
10359                 .unsol_event = alc262_hippo_unsol_event,
10360                 .init_hook = alc262_hippo_automute,
10361         },
10362         [ALC262_BENQ_T31] = {
10363                 .mixers = { alc262_benq_t31_mixer },
10364                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10365                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10366                 .dac_nids = alc262_dac_nids,
10367                 .hp_nid = 0x03,
10368                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10369                 .channel_mode = alc262_modes,
10370                 .input_mux = &alc262_capture_source,
10371                 .unsol_event = alc262_hippo_unsol_event,
10372                 .init_hook = alc262_hippo_automute,
10373         },
10374         [ALC262_ULTRA] = {
10375                 .mixers = { alc262_ultra_mixer },
10376                 .cap_mixer = alc262_ultra_capture_mixer,
10377                 .init_verbs = { alc262_ultra_verbs },
10378                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10379                 .dac_nids = alc262_dac_nids,
10380                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10381                 .channel_mode = alc262_modes,
10382                 .input_mux = &alc262_ultra_capture_source,
10383                 .adc_nids = alc262_adc_nids, /* ADC0 */
10384                 .capsrc_nids = alc262_capsrc_nids,
10385                 .num_adc_nids = 1, /* single ADC */
10386                 .unsol_event = alc262_ultra_unsol_event,
10387                 .init_hook = alc262_ultra_automute,
10388         },
10389         [ALC262_LENOVO_3000] = {
10390                 .mixers = { alc262_lenovo_3000_mixer },
10391                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10392                                 alc262_lenovo_3000_unsol_verbs },
10393                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10394                 .dac_nids = alc262_dac_nids,
10395                 .hp_nid = 0x03,
10396                 .dig_out_nid = ALC262_DIGOUT_NID,
10397                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10398                 .channel_mode = alc262_modes,
10399                 .input_mux = &alc262_fujitsu_capture_source,
10400                 .unsol_event = alc262_lenovo_3000_unsol_event,
10401         },
10402         [ALC262_NEC] = {
10403                 .mixers = { alc262_nec_mixer },
10404                 .init_verbs = { alc262_nec_verbs },
10405                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10406                 .dac_nids = alc262_dac_nids,
10407                 .hp_nid = 0x03,
10408                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10409                 .channel_mode = alc262_modes,
10410                 .input_mux = &alc262_capture_source,
10411         },
10412         [ALC262_TOSHIBA_S06] = {
10413                 .mixers = { alc262_toshiba_s06_mixer },
10414                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10415                                                         alc262_eapd_verbs },
10416                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10417                 .capsrc_nids = alc262_dmic_capsrc_nids,
10418                 .dac_nids = alc262_dac_nids,
10419                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10420                 .dig_out_nid = ALC262_DIGOUT_NID,
10421                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10422                 .channel_mode = alc262_modes,
10423                 .input_mux = &alc262_dmic_capture_source,
10424                 .unsol_event = alc262_toshiba_s06_unsol_event,
10425                 .init_hook = alc262_toshiba_s06_init_hook,
10426         },
10427         [ALC262_TOSHIBA_RX1] = {
10428                 .mixers = { alc262_toshiba_rx1_mixer },
10429                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
10430                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10431                 .dac_nids = alc262_dac_nids,
10432                 .hp_nid = 0x03,
10433                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10434                 .channel_mode = alc262_modes,
10435                 .input_mux = &alc262_capture_source,
10436                 .unsol_event = alc262_hippo_unsol_event,
10437                 .init_hook = alc262_hippo_automute,
10438         },
10439 };
10440
10441 static int patch_alc262(struct hda_codec *codec)
10442 {
10443         struct alc_spec *spec;
10444         int board_config;
10445         int err;
10446
10447         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10448         if (spec == NULL)
10449                 return -ENOMEM;
10450
10451         codec->spec = spec;
10452 #if 0
10453         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10454          * under-run
10455          */
10456         {
10457         int tmp;
10458         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10459         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10460         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10461         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10462         }
10463 #endif
10464
10465         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10466
10467         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10468                                                   alc262_models,
10469                                                   alc262_cfg_tbl);
10470
10471         if (board_config < 0) {
10472                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10473                        "trying auto-probe from BIOS...\n");
10474                 board_config = ALC262_AUTO;
10475         }
10476
10477         if (board_config == ALC262_AUTO) {
10478                 /* automatic parse from the BIOS config */
10479                 err = alc262_parse_auto_config(codec);
10480                 if (err < 0) {
10481                         alc_free(codec);
10482                         return err;
10483                 } else if (!err) {
10484                         printk(KERN_INFO
10485                                "hda_codec: Cannot set up configuration "
10486                                "from BIOS.  Using base mode...\n");
10487                         board_config = ALC262_BASIC;
10488                 }
10489         }
10490
10491         if (board_config != ALC262_AUTO)
10492                 setup_preset(spec, &alc262_presets[board_config]);
10493
10494         spec->stream_name_analog = "ALC262 Analog";
10495         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10496         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10497
10498         spec->stream_name_digital = "ALC262 Digital";
10499         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10500         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10501
10502         spec->is_mix_capture = 1;
10503         if (!spec->adc_nids && spec->input_mux) {
10504                 /* check whether NID 0x07 is valid */
10505                 unsigned int wcap = get_wcaps(codec, 0x07);
10506
10507                 /* get type */
10508                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10509                 if (wcap != AC_WID_AUD_IN) {
10510                         spec->adc_nids = alc262_adc_nids_alt;
10511                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10512                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10513                 } else {
10514                         spec->adc_nids = alc262_adc_nids;
10515                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10516                         spec->capsrc_nids = alc262_capsrc_nids;
10517                 }
10518         }
10519         if (!spec->cap_mixer)
10520                 set_capture_mixer(spec);
10521
10522         spec->vmaster_nid = 0x0c;
10523
10524         codec->patch_ops = alc_patch_ops;
10525         if (board_config == ALC262_AUTO)
10526                 spec->init_hook = alc262_auto_init;
10527 #ifdef CONFIG_SND_HDA_POWER_SAVE
10528         if (!spec->loopback.amplist)
10529                 spec->loopback.amplist = alc262_loopbacks;
10530 #endif
10531
10532         return 0;
10533 }
10534
10535 /*
10536  *  ALC268 channel source setting (2 channel)
10537  */
10538 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10539 #define alc268_modes            alc260_modes
10540
10541 static hda_nid_t alc268_dac_nids[2] = {
10542         /* front, hp */
10543         0x02, 0x03
10544 };
10545
10546 static hda_nid_t alc268_adc_nids[2] = {
10547         /* ADC0-1 */
10548         0x08, 0x07
10549 };
10550
10551 static hda_nid_t alc268_adc_nids_alt[1] = {
10552         /* ADC0 */
10553         0x08
10554 };
10555
10556 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10557
10558 static struct snd_kcontrol_new alc268_base_mixer[] = {
10559         /* output mixer control */
10560         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10561         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10562         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10563         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10564         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10565         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10566         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10567         { }
10568 };
10569
10570 /* bind Beep switches of both NID 0x0f and 0x10 */
10571 static struct hda_bind_ctls alc268_bind_beep_sw = {
10572         .ops = &snd_hda_bind_sw,
10573         .values = {
10574                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10575                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10576                 0
10577         },
10578 };
10579
10580 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10581         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10582         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10583         { }
10584 };
10585
10586 static struct hda_verb alc268_eapd_verbs[] = {
10587         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10588         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10589         { }
10590 };
10591
10592 /* Toshiba specific */
10593 #define alc268_toshiba_automute alc262_hippo_automute
10594
10595 static struct hda_verb alc268_toshiba_verbs[] = {
10596         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10597         { } /* end */
10598 };
10599
10600 static struct hda_input_mux alc268_acer_lc_capture_source = {
10601         .num_items = 2,
10602         .items = {
10603                 { "i-Mic", 0x6 },
10604                 { "E-Mic", 0x0 },
10605         },
10606 };
10607
10608 /* Acer specific */
10609 /* bind volumes of both NID 0x02 and 0x03 */
10610 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10611         .ops = &snd_hda_bind_vol,
10612         .values = {
10613                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10614                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10615                 0
10616         },
10617 };
10618
10619 /* mute/unmute internal speaker according to the hp jack and mute state */
10620 static void alc268_acer_automute(struct hda_codec *codec, int force)
10621 {
10622         struct alc_spec *spec = codec->spec;
10623         unsigned int mute;
10624
10625         if (force || !spec->sense_updated) {
10626                 unsigned int present;
10627                 present = snd_hda_codec_read(codec, 0x14, 0,
10628                                          AC_VERB_GET_PIN_SENSE, 0);
10629                 spec->jack_present = (present & 0x80000000) != 0;
10630                 spec->sense_updated = 1;
10631         }
10632         if (spec->jack_present)
10633                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10634         else /* unmute internal speaker if necessary */
10635                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10636         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10637                                  HDA_AMP_MUTE, mute);
10638 }
10639
10640
10641 /* bind hp and internal speaker mute (with plug check) */
10642 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10643                                      struct snd_ctl_elem_value *ucontrol)
10644 {
10645         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10646         long *valp = ucontrol->value.integer.value;
10647         int change;
10648
10649         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10650                                           HDA_AMP_MUTE,
10651                                           valp[0] ? 0 : HDA_AMP_MUTE);
10652         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10653                                            HDA_AMP_MUTE,
10654                                            valp[1] ? 0 : HDA_AMP_MUTE);
10655         if (change)
10656                 alc268_acer_automute(codec, 0);
10657         return change;
10658 }
10659
10660 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
10661         /* output mixer control */
10662         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10663         {
10664                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10665                 .name = "Master Playback Switch",
10666                 .info = snd_hda_mixer_amp_switch_info,
10667                 .get = snd_hda_mixer_amp_switch_get,
10668                 .put = alc268_acer_master_sw_put,
10669                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10670         },
10671         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
10672         { }
10673 };
10674
10675 static struct snd_kcontrol_new alc268_acer_mixer[] = {
10676         /* output mixer control */
10677         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10678         {
10679                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10680                 .name = "Master Playback Switch",
10681                 .info = snd_hda_mixer_amp_switch_info,
10682                 .get = snd_hda_mixer_amp_switch_get,
10683                 .put = alc268_acer_master_sw_put,
10684                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10685         },
10686         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10687         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10688         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10689         { }
10690 };
10691
10692 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
10693         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10694         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10695         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10696         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10697         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
10698         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
10699         { }
10700 };
10701
10702 static struct hda_verb alc268_acer_verbs[] = {
10703         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
10704         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10705         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10706         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10707         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10708         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10709         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10710         { }
10711 };
10712
10713 /* unsolicited event for HP jack sensing */
10714 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
10715                                        unsigned int res)
10716 {
10717         if ((res >> 26) != ALC880_HP_EVENT)
10718                 return;
10719         alc268_toshiba_automute(codec);
10720 }
10721
10722 static void alc268_acer_unsol_event(struct hda_codec *codec,
10723                                        unsigned int res)
10724 {
10725         if ((res >> 26) != ALC880_HP_EVENT)
10726                 return;
10727         alc268_acer_automute(codec, 1);
10728 }
10729
10730 static void alc268_acer_init_hook(struct hda_codec *codec)
10731 {
10732         alc268_acer_automute(codec, 1);
10733 }
10734
10735 /* toggle speaker-output according to the hp-jack state */
10736 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
10737 {
10738         unsigned int present;
10739         unsigned char bits;
10740
10741         present = snd_hda_codec_read(codec, 0x15, 0,
10742                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10743         bits = present ? AMP_IN_MUTE(0) : 0;
10744         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
10745                                 AMP_IN_MUTE(0), bits);
10746         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
10747                                 AMP_IN_MUTE(0), bits);
10748 }
10749
10750
10751 static void alc268_acer_mic_automute(struct hda_codec *codec)
10752 {
10753         unsigned int present;
10754
10755         present = snd_hda_codec_read(codec, 0x18, 0,
10756                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10757         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
10758                             present ? 0x0 : 0x6);
10759 }
10760
10761 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
10762                                     unsigned int res)
10763 {
10764         if ((res >> 26) == ALC880_HP_EVENT)
10765                 alc268_aspire_one_speaker_automute(codec);
10766         if ((res >> 26) == ALC880_MIC_EVENT)
10767                 alc268_acer_mic_automute(codec);
10768 }
10769
10770 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
10771 {
10772         alc268_aspire_one_speaker_automute(codec);
10773         alc268_acer_mic_automute(codec);
10774 }
10775
10776 static struct snd_kcontrol_new alc268_dell_mixer[] = {
10777         /* output mixer control */
10778         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10779         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10780         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10781         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10782         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10783         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10784         { }
10785 };
10786
10787 static struct hda_verb alc268_dell_verbs[] = {
10788         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10789         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10790         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10791         { }
10792 };
10793
10794 /* mute/unmute internal speaker according to the hp jack and mute state */
10795 static void alc268_dell_automute(struct hda_codec *codec)
10796 {
10797         unsigned int present;
10798         unsigned int mute;
10799
10800         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
10801         if (present & 0x80000000)
10802                 mute = HDA_AMP_MUTE;
10803         else
10804                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
10805         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10806                                  HDA_AMP_MUTE, mute);
10807 }
10808
10809 static void alc268_dell_unsol_event(struct hda_codec *codec,
10810                                     unsigned int res)
10811 {
10812         if ((res >> 26) != ALC880_HP_EVENT)
10813                 return;
10814         alc268_dell_automute(codec);
10815 }
10816
10817 #define alc268_dell_init_hook   alc268_dell_automute
10818
10819 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
10820         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10821         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10822         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10823         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10824         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10825         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
10826         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
10827         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10828         { }
10829 };
10830
10831 static struct hda_verb alc267_quanta_il1_verbs[] = {
10832         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10833         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
10834         { }
10835 };
10836
10837 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
10838 {
10839         unsigned int present;
10840
10841         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
10842                 & AC_PINSENSE_PRESENCE;
10843         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
10844                             present ? 0 : PIN_OUT);
10845 }
10846
10847 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
10848 {
10849         unsigned int present;
10850
10851         present = snd_hda_codec_read(codec, 0x18, 0,
10852                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10853         snd_hda_codec_write(codec, 0x23, 0,
10854                             AC_VERB_SET_CONNECT_SEL,
10855                             present ? 0x00 : 0x01);
10856 }
10857
10858 static void alc267_quanta_il1_automute(struct hda_codec *codec)
10859 {
10860         alc267_quanta_il1_hp_automute(codec);
10861         alc267_quanta_il1_mic_automute(codec);
10862 }
10863
10864 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
10865                                            unsigned int res)
10866 {
10867         switch (res >> 26) {
10868         case ALC880_HP_EVENT:
10869                 alc267_quanta_il1_hp_automute(codec);
10870                 break;
10871         case ALC880_MIC_EVENT:
10872                 alc267_quanta_il1_mic_automute(codec);
10873                 break;
10874         }
10875 }
10876
10877 /*
10878  * generic initialization of ADC, input mixers and output mixers
10879  */
10880 static struct hda_verb alc268_base_init_verbs[] = {
10881         /* Unmute DAC0-1 and set vol = 0 */
10882         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10883         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10884         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10885         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10886         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10887         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10888
10889         /*
10890          * Set up output mixers (0x0c - 0x0e)
10891          */
10892         /* set vol=0 to output mixers */
10893         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10894         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10895         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10896         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
10897
10898         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10899         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10900
10901         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10902         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10903         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10904         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10905         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10906         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10907         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10908         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10909
10910         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10911         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10912         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10913         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10914         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10915         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10916         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10917
10918         /* set PCBEEP vol = 0, mute connections */
10919         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10920         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10921         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10922
10923         /* Unmute Selector 23h,24h and set the default input to mic-in */
10924
10925         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
10926         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10927         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
10928         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10929
10930         { }
10931 };
10932
10933 /*
10934  * generic initialization of ADC, input mixers and output mixers
10935  */
10936 static struct hda_verb alc268_volume_init_verbs[] = {
10937         /* set output DAC */
10938         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10939         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10940         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10941         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10942
10943         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10944         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10945         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10946         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10947         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10948
10949         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10950         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10951         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10952         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10953         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10954
10955         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10956         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10957         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10958         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10959
10960         /* set PCBEEP vol = 0, mute connections */
10961         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10962         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10963         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10964
10965         { }
10966 };
10967
10968 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
10969         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10970         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10971         {
10972                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10973                 /* The multiple "Capture Source" controls confuse alsamixer
10974                  * So call somewhat different..
10975                  */
10976                 /* .name = "Capture Source", */
10977                 .name = "Input Source",
10978                 .count = 1,
10979                 .info = alc_mux_enum_info,
10980                 .get = alc_mux_enum_get,
10981                 .put = alc_mux_enum_put,
10982         },
10983         { } /* end */
10984 };
10985
10986 static struct snd_kcontrol_new alc268_capture_mixer[] = {
10987         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10988         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10989         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
10990         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
10991         {
10992                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10993                 /* The multiple "Capture Source" controls confuse alsamixer
10994                  * So call somewhat different..
10995                  */
10996                 /* .name = "Capture Source", */
10997                 .name = "Input Source",
10998                 .count = 2,
10999                 .info = alc_mux_enum_info,
11000                 .get = alc_mux_enum_get,
11001                 .put = alc_mux_enum_put,
11002         },
11003         { } /* end */
11004 };
11005
11006 static struct hda_input_mux alc268_capture_source = {
11007         .num_items = 4,
11008         .items = {
11009                 { "Mic", 0x0 },
11010                 { "Front Mic", 0x1 },
11011                 { "Line", 0x2 },
11012                 { "CD", 0x3 },
11013         },
11014 };
11015
11016 static struct hda_input_mux alc268_acer_capture_source = {
11017         .num_items = 3,
11018         .items = {
11019                 { "Mic", 0x0 },
11020                 { "Internal Mic", 0x6 },
11021                 { "Line", 0x2 },
11022         },
11023 };
11024
11025 #ifdef CONFIG_SND_DEBUG
11026 static struct snd_kcontrol_new alc268_test_mixer[] = {
11027         /* Volume widgets */
11028         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11029         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11030         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11031         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11032         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11033         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11034         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11035         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11036         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11037         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11038         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11039         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11040         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11041         /* The below appears problematic on some hardwares */
11042         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11043         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11044         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11045         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11046         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11047
11048         /* Modes for retasking pin widgets */
11049         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11050         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11051         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11052         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11053
11054         /* Controls for GPIO pins, assuming they are configured as outputs */
11055         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11056         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11057         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11058         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11059
11060         /* Switches to allow the digital SPDIF output pin to be enabled.
11061          * The ALC268 does not have an SPDIF input.
11062          */
11063         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11064
11065         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11066          * this output to turn on an external amplifier.
11067          */
11068         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11069         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11070
11071         { } /* end */
11072 };
11073 #endif
11074
11075 /* create input playback/capture controls for the given pin */
11076 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11077                                     const char *ctlname, int idx)
11078 {
11079         char name[32];
11080         int err;
11081
11082         sprintf(name, "%s Playback Volume", ctlname);
11083         if (nid == 0x14) {
11084                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11085                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11086                                                       HDA_OUTPUT));
11087                 if (err < 0)
11088                         return err;
11089         } else if (nid == 0x15) {
11090                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11091                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11092                                                       HDA_OUTPUT));
11093                 if (err < 0)
11094                         return err;
11095         } else
11096                 return -1;
11097         sprintf(name, "%s Playback Switch", ctlname);
11098         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11099                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11100         if (err < 0)
11101                 return err;
11102         return 0;
11103 }
11104
11105 /* add playback controls from the parsed DAC table */
11106 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11107                                              const struct auto_pin_cfg *cfg)
11108 {
11109         hda_nid_t nid;
11110         int err;
11111
11112         spec->multiout.num_dacs = 2;    /* only use one dac */
11113         spec->multiout.dac_nids = spec->private_dac_nids;
11114         spec->multiout.dac_nids[0] = 2;
11115         spec->multiout.dac_nids[1] = 3;
11116
11117         nid = cfg->line_out_pins[0];
11118         if (nid)
11119                 alc268_new_analog_output(spec, nid, "Front", 0);
11120
11121         nid = cfg->speaker_pins[0];
11122         if (nid == 0x1d) {
11123                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11124                                   "Speaker Playback Volume",
11125                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11126                 if (err < 0)
11127                         return err;
11128         }
11129         nid = cfg->hp_pins[0];
11130         if (nid)
11131                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11132
11133         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11134         if (nid == 0x16) {
11135                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11136                                   "Mono Playback Switch",
11137                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11138                 if (err < 0)
11139                         return err;
11140         }
11141         return 0;
11142 }
11143
11144 /* create playback/capture controls for input pins */
11145 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11146                                                 const struct auto_pin_cfg *cfg)
11147 {
11148         struct hda_input_mux *imux = &spec->private_imux;
11149         int i, idx1;
11150
11151         for (i = 0; i < AUTO_PIN_LAST; i++) {
11152                 switch(cfg->input_pins[i]) {
11153                 case 0x18:
11154                         idx1 = 0;       /* Mic 1 */
11155                         break;
11156                 case 0x19:
11157                         idx1 = 1;       /* Mic 2 */
11158                         break;
11159                 case 0x1a:
11160                         idx1 = 2;       /* Line In */
11161                         break;
11162                 case 0x1c:
11163                         idx1 = 3;       /* CD */
11164                         break;
11165                 case 0x12:
11166                 case 0x13:
11167                         idx1 = 6;       /* digital mics */
11168                         break;
11169                 default:
11170                         continue;
11171                 }
11172                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11173                 imux->items[imux->num_items].index = idx1;
11174                 imux->num_items++;
11175         }
11176         return 0;
11177 }
11178
11179 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11180 {
11181         struct alc_spec *spec = codec->spec;
11182         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11183         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11184         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11185         unsigned int    dac_vol1, dac_vol2;
11186
11187         if (speaker_nid) {
11188                 snd_hda_codec_write(codec, speaker_nid, 0,
11189                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11190                 snd_hda_codec_write(codec, 0x0f, 0,
11191                                     AC_VERB_SET_AMP_GAIN_MUTE,
11192                                     AMP_IN_UNMUTE(1));
11193                 snd_hda_codec_write(codec, 0x10, 0,
11194                                     AC_VERB_SET_AMP_GAIN_MUTE,
11195                                     AMP_IN_UNMUTE(1));
11196         } else {
11197                 snd_hda_codec_write(codec, 0x0f, 0,
11198                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11199                 snd_hda_codec_write(codec, 0x10, 0,
11200                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11201         }
11202
11203         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11204         if (line_nid == 0x14)
11205                 dac_vol2 = AMP_OUT_ZERO;
11206         else if (line_nid == 0x15)
11207                 dac_vol1 = AMP_OUT_ZERO;
11208         if (hp_nid == 0x14)
11209                 dac_vol2 = AMP_OUT_ZERO;
11210         else if (hp_nid == 0x15)
11211                 dac_vol1 = AMP_OUT_ZERO;
11212         if (line_nid != 0x16 || hp_nid != 0x16 ||
11213             spec->autocfg.line_out_pins[1] != 0x16 ||
11214             spec->autocfg.line_out_pins[2] != 0x16)
11215                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11216
11217         snd_hda_codec_write(codec, 0x02, 0,
11218                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11219         snd_hda_codec_write(codec, 0x03, 0,
11220                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11221 }
11222
11223 /* pcm configuration: identiacal with ALC880 */
11224 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11225 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11226 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11227 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11228
11229 /*
11230  * BIOS auto configuration
11231  */
11232 static int alc268_parse_auto_config(struct hda_codec *codec)
11233 {
11234         struct alc_spec *spec = codec->spec;
11235         int err;
11236         static hda_nid_t alc268_ignore[] = { 0 };
11237
11238         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11239                                            alc268_ignore);
11240         if (err < 0)
11241                 return err;
11242         if (!spec->autocfg.line_outs)
11243                 return 0; /* can't find valid BIOS pin config */
11244
11245         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11246         if (err < 0)
11247                 return err;
11248         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11249         if (err < 0)
11250                 return err;
11251
11252         spec->multiout.max_channels = 2;
11253
11254         /* digital only support output */
11255         if (spec->autocfg.dig_out_pin)
11256                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11257
11258         if (spec->kctls.list)
11259                 add_mixer(spec, spec->kctls.list);
11260
11261         if (spec->autocfg.speaker_pins[0] != 0x1d)
11262                 add_mixer(spec, alc268_beep_mixer);
11263
11264         add_verb(spec, alc268_volume_init_verbs);
11265         spec->num_mux_defs = 1;
11266         spec->input_mux = &spec->private_imux;
11267
11268         err = alc_auto_add_mic_boost(codec);
11269         if (err < 0)
11270                 return err;
11271
11272         store_pin_configs(codec);
11273         return 1;
11274 }
11275
11276 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
11277 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
11278 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
11279
11280 /* init callback for auto-configuration model -- overriding the default init */
11281 static void alc268_auto_init(struct hda_codec *codec)
11282 {
11283         struct alc_spec *spec = codec->spec;
11284         alc268_auto_init_multi_out(codec);
11285         alc268_auto_init_hp_out(codec);
11286         alc268_auto_init_mono_speaker_out(codec);
11287         alc268_auto_init_analog_input(codec);
11288         if (spec->unsol_event)
11289                 alc_inithook(codec);
11290 }
11291
11292 /*
11293  * configuration and preset
11294  */
11295 static const char *alc268_models[ALC268_MODEL_LAST] = {
11296         [ALC267_QUANTA_IL1]     = "quanta-il1",
11297         [ALC268_3ST]            = "3stack",
11298         [ALC268_TOSHIBA]        = "toshiba",
11299         [ALC268_ACER]           = "acer",
11300         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
11301         [ALC268_DELL]           = "dell",
11302         [ALC268_ZEPTO]          = "zepto",
11303 #ifdef CONFIG_SND_DEBUG
11304         [ALC268_TEST]           = "test",
11305 #endif
11306         [ALC268_AUTO]           = "auto",
11307 };
11308
11309 static struct snd_pci_quirk alc268_cfg_tbl[] = {
11310         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
11311         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
11312         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
11313         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
11314         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11315         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11316                                                 ALC268_ACER_ASPIRE_ONE),
11317         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
11318         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
11319         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
11320         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
11321         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11322         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
11323         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
11324         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
11325         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
11326         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
11327         {}
11328 };
11329
11330 static struct alc_config_preset alc268_presets[] = {
11331         [ALC267_QUANTA_IL1] = {
11332                 .mixers = { alc267_quanta_il1_mixer },
11333                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11334                                 alc267_quanta_il1_verbs },
11335                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11336                 .dac_nids = alc268_dac_nids,
11337                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11338                 .adc_nids = alc268_adc_nids_alt,
11339                 .hp_nid = 0x03,
11340                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11341                 .channel_mode = alc268_modes,
11342                 .input_mux = &alc268_capture_source,
11343                 .unsol_event = alc267_quanta_il1_unsol_event,
11344                 .init_hook = alc267_quanta_il1_automute,
11345         },
11346         [ALC268_3ST] = {
11347                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11348                             alc268_beep_mixer },
11349                 .init_verbs = { alc268_base_init_verbs },
11350                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11351                 .dac_nids = alc268_dac_nids,
11352                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11353                 .adc_nids = alc268_adc_nids_alt,
11354                 .capsrc_nids = alc268_capsrc_nids,
11355                 .hp_nid = 0x03,
11356                 .dig_out_nid = ALC268_DIGOUT_NID,
11357                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11358                 .channel_mode = alc268_modes,
11359                 .input_mux = &alc268_capture_source,
11360         },
11361         [ALC268_TOSHIBA] = {
11362                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11363                             alc268_beep_mixer },
11364                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11365                                 alc268_toshiba_verbs },
11366                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11367                 .dac_nids = alc268_dac_nids,
11368                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11369                 .adc_nids = alc268_adc_nids_alt,
11370                 .capsrc_nids = alc268_capsrc_nids,
11371                 .hp_nid = 0x03,
11372                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11373                 .channel_mode = alc268_modes,
11374                 .input_mux = &alc268_capture_source,
11375                 .unsol_event = alc268_toshiba_unsol_event,
11376                 .init_hook = alc268_toshiba_automute,
11377         },
11378         [ALC268_ACER] = {
11379                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
11380                             alc268_beep_mixer },
11381                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11382                                 alc268_acer_verbs },
11383                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11384                 .dac_nids = alc268_dac_nids,
11385                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11386                 .adc_nids = alc268_adc_nids_alt,
11387                 .capsrc_nids = alc268_capsrc_nids,
11388                 .hp_nid = 0x02,
11389                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11390                 .channel_mode = alc268_modes,
11391                 .input_mux = &alc268_acer_capture_source,
11392                 .unsol_event = alc268_acer_unsol_event,
11393                 .init_hook = alc268_acer_init_hook,
11394         },
11395         [ALC268_ACER_ASPIRE_ONE] = {
11396                 .mixers = { alc268_acer_aspire_one_mixer,
11397                                 alc268_capture_alt_mixer },
11398                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11399                                 alc268_acer_aspire_one_verbs },
11400                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11401                 .dac_nids = alc268_dac_nids,
11402                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11403                 .adc_nids = alc268_adc_nids_alt,
11404                 .capsrc_nids = alc268_capsrc_nids,
11405                 .hp_nid = 0x03,
11406                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11407                 .channel_mode = alc268_modes,
11408                 .input_mux = &alc268_acer_lc_capture_source,
11409                 .unsol_event = alc268_acer_lc_unsol_event,
11410                 .init_hook = alc268_acer_lc_init_hook,
11411         },
11412         [ALC268_DELL] = {
11413                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
11414                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11415                                 alc268_dell_verbs },
11416                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11417                 .dac_nids = alc268_dac_nids,
11418                 .hp_nid = 0x02,
11419                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11420                 .channel_mode = alc268_modes,
11421                 .unsol_event = alc268_dell_unsol_event,
11422                 .init_hook = alc268_dell_init_hook,
11423                 .input_mux = &alc268_capture_source,
11424         },
11425         [ALC268_ZEPTO] = {
11426                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11427                             alc268_beep_mixer },
11428                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11429                                 alc268_toshiba_verbs },
11430                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11431                 .dac_nids = alc268_dac_nids,
11432                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11433                 .adc_nids = alc268_adc_nids_alt,
11434                 .capsrc_nids = alc268_capsrc_nids,
11435                 .hp_nid = 0x03,
11436                 .dig_out_nid = ALC268_DIGOUT_NID,
11437                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11438                 .channel_mode = alc268_modes,
11439                 .input_mux = &alc268_capture_source,
11440                 .unsol_event = alc268_toshiba_unsol_event,
11441                 .init_hook = alc268_toshiba_automute
11442         },
11443 #ifdef CONFIG_SND_DEBUG
11444         [ALC268_TEST] = {
11445                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11446                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11447                                 alc268_volume_init_verbs },
11448                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11449                 .dac_nids = alc268_dac_nids,
11450                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11451                 .adc_nids = alc268_adc_nids_alt,
11452                 .capsrc_nids = alc268_capsrc_nids,
11453                 .hp_nid = 0x03,
11454                 .dig_out_nid = ALC268_DIGOUT_NID,
11455                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11456                 .channel_mode = alc268_modes,
11457                 .input_mux = &alc268_capture_source,
11458         },
11459 #endif
11460 };
11461
11462 static int patch_alc268(struct hda_codec *codec)
11463 {
11464         struct alc_spec *spec;
11465         int board_config;
11466         int err;
11467
11468         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11469         if (spec == NULL)
11470                 return -ENOMEM;
11471
11472         codec->spec = spec;
11473
11474         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11475                                                   alc268_models,
11476                                                   alc268_cfg_tbl);
11477
11478         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11479                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11480                        "trying auto-probe from BIOS...\n");
11481                 board_config = ALC268_AUTO;
11482         }
11483
11484         if (board_config == ALC268_AUTO) {
11485                 /* automatic parse from the BIOS config */
11486                 err = alc268_parse_auto_config(codec);
11487                 if (err < 0) {
11488                         alc_free(codec);
11489                         return err;
11490                 } else if (!err) {
11491                         printk(KERN_INFO
11492                                "hda_codec: Cannot set up configuration "
11493                                "from BIOS.  Using base mode...\n");
11494                         board_config = ALC268_3ST;
11495                 }
11496         }
11497
11498         if (board_config != ALC268_AUTO)
11499                 setup_preset(spec, &alc268_presets[board_config]);
11500
11501         if (codec->vendor_id == 0x10ec0267) {
11502                 spec->stream_name_analog = "ALC267 Analog";
11503                 spec->stream_name_digital = "ALC267 Digital";
11504         } else {
11505                 spec->stream_name_analog = "ALC268 Analog";
11506                 spec->stream_name_digital = "ALC268 Digital";
11507         }
11508
11509         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11510         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11511         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11512
11513         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11514
11515         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11516                 /* override the amp caps for beep generator */
11517                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11518                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11519                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11520                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11521                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11522
11523         if (!spec->adc_nids && spec->input_mux) {
11524                 /* check whether NID 0x07 is valid */
11525                 unsigned int wcap = get_wcaps(codec, 0x07);
11526                 int i;
11527
11528                 /* get type */
11529                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11530                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11531                         spec->adc_nids = alc268_adc_nids_alt;
11532                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11533                         add_mixer(spec, alc268_capture_alt_mixer);
11534                 } else {
11535                         spec->adc_nids = alc268_adc_nids;
11536                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11537                         add_mixer(spec, alc268_capture_mixer);
11538                 }
11539                 spec->capsrc_nids = alc268_capsrc_nids;
11540                 /* set default input source */
11541                 for (i = 0; i < spec->num_adc_nids; i++)
11542                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11543                                 0, AC_VERB_SET_CONNECT_SEL,
11544                                 spec->input_mux->items[0].index);
11545         }
11546
11547         spec->vmaster_nid = 0x02;
11548
11549         codec->patch_ops = alc_patch_ops;
11550         if (board_config == ALC268_AUTO)
11551                 spec->init_hook = alc268_auto_init;
11552
11553         return 0;
11554 }
11555
11556 /*
11557  *  ALC269 channel source setting (2 channel)
11558  */
11559 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11560
11561 #define alc269_dac_nids         alc260_dac_nids
11562
11563 static hda_nid_t alc269_adc_nids[1] = {
11564         /* ADC1 */
11565         0x08,
11566 };
11567
11568 static hda_nid_t alc269_capsrc_nids[1] = {
11569         0x23,
11570 };
11571
11572 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11573  *       not a mux!
11574  */
11575
11576 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11577         .num_items = 2,
11578         .items = {
11579                 { "i-Mic", 0x5 },
11580                 { "e-Mic", 0x0 },
11581         },
11582 };
11583
11584 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11585         .num_items = 2,
11586         .items = {
11587                 { "i-Mic", 0x1 },
11588                 { "e-Mic", 0x0 },
11589         },
11590 };
11591
11592 #define alc269_modes            alc260_modes
11593 #define alc269_capture_source   alc880_lg_lw_capture_source
11594
11595 static struct snd_kcontrol_new alc269_base_mixer[] = {
11596         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11597         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11598         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11599         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11600         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11601         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11602         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11603         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11604         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11605         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11606         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11607         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11608         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11609         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
11610         { } /* end */
11611 };
11612
11613 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
11614         /* output mixer control */
11615         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11616         {
11617                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11618                 .name = "Master Playback Switch",
11619                 .info = snd_hda_mixer_amp_switch_info,
11620                 .get = snd_hda_mixer_amp_switch_get,
11621                 .put = alc268_acer_master_sw_put,
11622                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11623         },
11624         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11625         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11626         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11627         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11628         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11629         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11630         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
11631         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
11632         { }
11633 };
11634
11635 /* bind volumes of both NID 0x0c and 0x0d */
11636 static struct hda_bind_ctls alc269_epc_bind_vol = {
11637         .ops = &snd_hda_bind_vol,
11638         .values = {
11639                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11640                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11641                 0
11642         },
11643 };
11644
11645 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
11646         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11647         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
11648         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11649         { } /* end */
11650 };
11651
11652 /* capture mixer elements */
11653 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
11654         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11655         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11656         { } /* end */
11657 };
11658
11659 /* beep control */
11660 static struct snd_kcontrol_new alc269_beep_mixer[] = {
11661         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11662         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11663         { } /* end */
11664 };
11665
11666 static struct hda_verb alc269_quanta_fl1_verbs[] = {
11667         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11668         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11669         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11670         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11671         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11672         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11673         { }
11674 };
11675
11676 /* toggle speaker-output according to the hp-jack state */
11677 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
11678 {
11679         unsigned int present;
11680         unsigned char bits;
11681
11682         present = snd_hda_codec_read(codec, 0x15, 0,
11683                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11684         bits = present ? AMP_IN_MUTE(0) : 0;
11685         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11686                         AMP_IN_MUTE(0), bits);
11687         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11688                         AMP_IN_MUTE(0), bits);
11689
11690         snd_hda_codec_write(codec, 0x20, 0,
11691                         AC_VERB_SET_COEF_INDEX, 0x0c);
11692         snd_hda_codec_write(codec, 0x20, 0,
11693                         AC_VERB_SET_PROC_COEF, 0x680);
11694
11695         snd_hda_codec_write(codec, 0x20, 0,
11696                         AC_VERB_SET_COEF_INDEX, 0x0c);
11697         snd_hda_codec_write(codec, 0x20, 0,
11698                         AC_VERB_SET_PROC_COEF, 0x480);
11699 }
11700
11701 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
11702 {
11703         unsigned int present;
11704
11705         present = snd_hda_codec_read(codec, 0x18, 0,
11706                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11707         snd_hda_codec_write(codec, 0x23, 0,
11708                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
11709 }
11710
11711 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
11712                                     unsigned int res)
11713 {
11714         if ((res >> 26) == ALC880_HP_EVENT)
11715                 alc269_quanta_fl1_speaker_automute(codec);
11716         if ((res >> 26) == ALC880_MIC_EVENT)
11717                 alc269_quanta_fl1_mic_automute(codec);
11718 }
11719
11720 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
11721 {
11722         alc269_quanta_fl1_speaker_automute(codec);
11723         alc269_quanta_fl1_mic_automute(codec);
11724 }
11725
11726 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
11727         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11728         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
11729         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11730         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
11731         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11732         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11733         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11734         {}
11735 };
11736
11737 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
11738         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11739         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
11740         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11741         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
11742         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11743         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11744         {}
11745 };
11746
11747 /* toggle speaker-output according to the hp-jack state */
11748 static void alc269_speaker_automute(struct hda_codec *codec)
11749 {
11750         unsigned int present;
11751         unsigned char bits;
11752
11753         present = snd_hda_codec_read(codec, 0x15, 0,
11754                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11755         bits = present ? AMP_IN_MUTE(0) : 0;
11756         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11757                                 AMP_IN_MUTE(0), bits);
11758         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11759                                 AMP_IN_MUTE(0), bits);
11760 }
11761
11762 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
11763 {
11764         unsigned int present;
11765
11766         present = snd_hda_codec_read(codec, 0x18, 0,
11767                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11768         snd_hda_codec_write(codec, 0x23, 0,
11769                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
11770 }
11771
11772 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
11773 {
11774         unsigned int present;
11775
11776         present = snd_hda_codec_read(codec, 0x18, 0,
11777                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11778         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11779                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
11780         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11781                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
11782 }
11783
11784 /* unsolicited event for HP jack sensing */
11785 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
11786                                      unsigned int res)
11787 {
11788         if ((res >> 26) == ALC880_HP_EVENT)
11789                 alc269_speaker_automute(codec);
11790
11791         if ((res >> 26) == ALC880_MIC_EVENT)
11792                 alc269_eeepc_dmic_automute(codec);
11793 }
11794
11795 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
11796 {
11797         alc269_speaker_automute(codec);
11798         alc269_eeepc_dmic_automute(codec);
11799 }
11800
11801 /* unsolicited event for HP jack sensing */
11802 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
11803                                      unsigned int res)
11804 {
11805         if ((res >> 26) == ALC880_HP_EVENT)
11806                 alc269_speaker_automute(codec);
11807
11808         if ((res >> 26) == ALC880_MIC_EVENT)
11809                 alc269_eeepc_amic_automute(codec);
11810 }
11811
11812 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
11813 {
11814         alc269_speaker_automute(codec);
11815         alc269_eeepc_amic_automute(codec);
11816 }
11817
11818 /*
11819  * generic initialization of ADC, input mixers and output mixers
11820  */
11821 static struct hda_verb alc269_init_verbs[] = {
11822         /*
11823          * Unmute ADC0 and set the default input to mic-in
11824          */
11825         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11826
11827         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
11828          * analog-loopback mixer widget
11829          * Note: PASD motherboards uses the Line In 2 as the input for
11830          * front panel mic (mic 2)
11831          */
11832         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11833         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11834         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11835         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11836         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11837         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11838
11839         /*
11840          * Set up output mixers (0x0c - 0x0e)
11841          */
11842         /* set vol=0 to output mixers */
11843         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11844         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11845
11846         /* set up input amps for analog loopback */
11847         /* Amp Indices: DAC = 0, mixer = 1 */
11848         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11849         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11850         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11851         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11852         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11853         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11854
11855         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11856         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11857         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11858         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11859         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11860         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11861         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11862
11863         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11864         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11865         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11866         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11867         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11868         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11869         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11870
11871         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
11872         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11873
11874         /* FIXME: use matrix-type input source selection */
11875         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
11876         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11877         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11878         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11879         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11880         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11881
11882         /* set EAPD */
11883         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11884         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11885         { }
11886 };
11887
11888 /* add playback controls from the parsed DAC table */
11889 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
11890                                              const struct auto_pin_cfg *cfg)
11891 {
11892         hda_nid_t nid;
11893         int err;
11894
11895         spec->multiout.num_dacs = 1;    /* only use one dac */
11896         spec->multiout.dac_nids = spec->private_dac_nids;
11897         spec->multiout.dac_nids[0] = 2;
11898
11899         nid = cfg->line_out_pins[0];
11900         if (nid) {
11901                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11902                                   "Front Playback Volume",
11903                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
11904                 if (err < 0)
11905                         return err;
11906                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11907                                   "Front Playback Switch",
11908                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11909                 if (err < 0)
11910                         return err;
11911         }
11912
11913         nid = cfg->speaker_pins[0];
11914         if (nid) {
11915                 if (!cfg->line_out_pins[0]) {
11916                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11917                                           "Speaker Playback Volume",
11918                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
11919                                                               HDA_OUTPUT));
11920                         if (err < 0)
11921                                 return err;
11922                 }
11923                 if (nid == 0x16) {
11924                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11925                                           "Speaker Playback Switch",
11926                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11927                                                               HDA_OUTPUT));
11928                         if (err < 0)
11929                                 return err;
11930                 } else {
11931                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11932                                           "Speaker Playback Switch",
11933                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11934                                                               HDA_OUTPUT));
11935                         if (err < 0)
11936                                 return err;
11937                 }
11938         }
11939         nid = cfg->hp_pins[0];
11940         if (nid) {
11941                 /* spec->multiout.hp_nid = 2; */
11942                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
11943                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11944                                           "Headphone Playback Volume",
11945                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
11946                                                               HDA_OUTPUT));
11947                         if (err < 0)
11948                                 return err;
11949                 }
11950                 if (nid == 0x16) {
11951                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11952                                           "Headphone Playback Switch",
11953                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11954                                                               HDA_OUTPUT));
11955                         if (err < 0)
11956                                 return err;
11957                 } else {
11958                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11959                                           "Headphone Playback Switch",
11960                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11961                                                               HDA_OUTPUT));
11962                         if (err < 0)
11963                                 return err;
11964                 }
11965         }
11966         return 0;
11967 }
11968
11969 static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
11970                                                 const struct auto_pin_cfg *cfg)
11971 {
11972         int err;
11973
11974         err = alc880_auto_create_analog_input_ctls(spec, cfg);
11975         if (err < 0)
11976                 return err;
11977         /* digital-mic input pin is excluded in alc880_auto_create..()
11978          * because it's under 0x18
11979          */
11980         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
11981             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
11982                 struct hda_input_mux *imux = &spec->private_imux;
11983                 imux->items[imux->num_items].label = "Int Mic";
11984                 imux->items[imux->num_items].index = 0x05;
11985                 imux->num_items++;
11986         }
11987         return 0;
11988 }
11989
11990 #ifdef CONFIG_SND_HDA_POWER_SAVE
11991 #define alc269_loopbacks        alc880_loopbacks
11992 #endif
11993
11994 /* pcm configuration: identiacal with ALC880 */
11995 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
11996 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
11997 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
11998 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
11999
12000 /*
12001  * BIOS auto configuration
12002  */
12003 static int alc269_parse_auto_config(struct hda_codec *codec)
12004 {
12005         struct alc_spec *spec = codec->spec;
12006         int i, err;
12007         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12008
12009         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12010                                            alc269_ignore);
12011         if (err < 0)
12012                 return err;
12013
12014         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12015         if (err < 0)
12016                 return err;
12017         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12018         if (err < 0)
12019                 return err;
12020
12021         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12022
12023         if (spec->autocfg.dig_out_pin)
12024                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12025
12026         if (spec->kctls.list)
12027                 add_mixer(spec, spec->kctls.list);
12028
12029         /* create a beep mixer control if the pin 0x1d isn't assigned */
12030         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12031                 if (spec->autocfg.input_pins[i] == 0x1d)
12032                         break;
12033         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12034                 add_mixer(spec, alc269_beep_mixer);
12035
12036         add_verb(spec, alc269_init_verbs);
12037         spec->num_mux_defs = 1;
12038         spec->input_mux = &spec->private_imux;
12039         /* set default input source */
12040         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12041                                   0, AC_VERB_SET_CONNECT_SEL,
12042                                   spec->input_mux->items[0].index);
12043
12044         err = alc_auto_add_mic_boost(codec);
12045         if (err < 0)
12046                 return err;
12047
12048         if (!spec->cap_mixer)
12049                 set_capture_mixer(spec);
12050
12051         store_pin_configs(codec);
12052         return 1;
12053 }
12054
12055 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12056 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12057 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12058
12059
12060 /* init callback for auto-configuration model -- overriding the default init */
12061 static void alc269_auto_init(struct hda_codec *codec)
12062 {
12063         struct alc_spec *spec = codec->spec;
12064         alc269_auto_init_multi_out(codec);
12065         alc269_auto_init_hp_out(codec);
12066         alc269_auto_init_analog_input(codec);
12067         if (spec->unsol_event)
12068                 alc_inithook(codec);
12069 }
12070
12071 /*
12072  * configuration and preset
12073  */
12074 static const char *alc269_models[ALC269_MODEL_LAST] = {
12075         [ALC269_BASIC]                  = "basic",
12076         [ALC269_QUANTA_FL1]             = "quanta",
12077         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12078         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901"
12079 };
12080
12081 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12082         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12083         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12084                       ALC269_ASUS_EEEPC_P703),
12085         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12086                       ALC269_ASUS_EEEPC_P901),
12087         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12088                       ALC269_ASUS_EEEPC_P901),
12089         {}
12090 };
12091
12092 static struct alc_config_preset alc269_presets[] = {
12093         [ALC269_BASIC] = {
12094                 .mixers = { alc269_base_mixer },
12095                 .init_verbs = { alc269_init_verbs },
12096                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12097                 .dac_nids = alc269_dac_nids,
12098                 .hp_nid = 0x03,
12099                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12100                 .channel_mode = alc269_modes,
12101                 .input_mux = &alc269_capture_source,
12102         },
12103         [ALC269_QUANTA_FL1] = {
12104                 .mixers = { alc269_quanta_fl1_mixer },
12105                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
12106                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12107                 .dac_nids = alc269_dac_nids,
12108                 .hp_nid = 0x03,
12109                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12110                 .channel_mode = alc269_modes,
12111                 .input_mux = &alc269_capture_source,
12112                 .unsol_event = alc269_quanta_fl1_unsol_event,
12113                 .init_hook = alc269_quanta_fl1_init_hook,
12114         },
12115         [ALC269_ASUS_EEEPC_P703] = {
12116                 .mixers = { alc269_eeepc_mixer },
12117                 .cap_mixer = alc269_epc_capture_mixer,
12118                 .init_verbs = { alc269_init_verbs,
12119                                 alc269_eeepc_amic_init_verbs },
12120                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12121                 .dac_nids = alc269_dac_nids,
12122                 .hp_nid = 0x03,
12123                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12124                 .channel_mode = alc269_modes,
12125                 .input_mux = &alc269_eeepc_amic_capture_source,
12126                 .unsol_event = alc269_eeepc_amic_unsol_event,
12127                 .init_hook = alc269_eeepc_amic_inithook,
12128         },
12129         [ALC269_ASUS_EEEPC_P901] = {
12130                 .mixers = { alc269_eeepc_mixer },
12131                 .cap_mixer = alc269_epc_capture_mixer,
12132                 .init_verbs = { alc269_init_verbs,
12133                                 alc269_eeepc_dmic_init_verbs },
12134                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12135                 .dac_nids = alc269_dac_nids,
12136                 .hp_nid = 0x03,
12137                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12138                 .channel_mode = alc269_modes,
12139                 .input_mux = &alc269_eeepc_dmic_capture_source,
12140                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12141                 .init_hook = alc269_eeepc_dmic_inithook,
12142         },
12143 };
12144
12145 static int patch_alc269(struct hda_codec *codec)
12146 {
12147         struct alc_spec *spec;
12148         int board_config;
12149         int err;
12150
12151         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12152         if (spec == NULL)
12153                 return -ENOMEM;
12154
12155         codec->spec = spec;
12156
12157         alc_fix_pll_init(codec, 0x20, 0x04, 15);
12158
12159         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
12160                                                   alc269_models,
12161                                                   alc269_cfg_tbl);
12162
12163         if (board_config < 0) {
12164                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
12165                        "trying auto-probe from BIOS...\n");
12166                 board_config = ALC269_AUTO;
12167         }
12168
12169         if (board_config == ALC269_AUTO) {
12170                 /* automatic parse from the BIOS config */
12171                 err = alc269_parse_auto_config(codec);
12172                 if (err < 0) {
12173                         alc_free(codec);
12174                         return err;
12175                 } else if (!err) {
12176                         printk(KERN_INFO
12177                                "hda_codec: Cannot set up configuration "
12178                                "from BIOS.  Using base mode...\n");
12179                         board_config = ALC269_BASIC;
12180                 }
12181         }
12182
12183         if (board_config != ALC269_AUTO)
12184                 setup_preset(spec, &alc269_presets[board_config]);
12185
12186         spec->stream_name_analog = "ALC269 Analog";
12187         spec->stream_analog_playback = &alc269_pcm_analog_playback;
12188         spec->stream_analog_capture = &alc269_pcm_analog_capture;
12189
12190         spec->stream_name_digital = "ALC269 Digital";
12191         spec->stream_digital_playback = &alc269_pcm_digital_playback;
12192         spec->stream_digital_capture = &alc269_pcm_digital_capture;
12193
12194         spec->adc_nids = alc269_adc_nids;
12195         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12196         spec->capsrc_nids = alc269_capsrc_nids;
12197         if (!spec->cap_mixer)
12198                 set_capture_mixer(spec);
12199
12200         codec->patch_ops = alc_patch_ops;
12201         if (board_config == ALC269_AUTO)
12202                 spec->init_hook = alc269_auto_init;
12203 #ifdef CONFIG_SND_HDA_POWER_SAVE
12204         if (!spec->loopback.amplist)
12205                 spec->loopback.amplist = alc269_loopbacks;
12206 #endif
12207
12208         return 0;
12209 }
12210
12211 /*
12212  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
12213  */
12214
12215 /*
12216  * set the path ways for 2 channel output
12217  * need to set the codec line out and mic 1 pin widgets to inputs
12218  */
12219 static struct hda_verb alc861_threestack_ch2_init[] = {
12220         /* set pin widget 1Ah (line in) for input */
12221         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12222         /* set pin widget 18h (mic1/2) for input, for mic also enable
12223          * the vref
12224          */
12225         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12226
12227         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12228 #if 0
12229         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12230         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12231 #endif
12232         { } /* end */
12233 };
12234 /*
12235  * 6ch mode
12236  * need to set the codec line out and mic 1 pin widgets to outputs
12237  */
12238 static struct hda_verb alc861_threestack_ch6_init[] = {
12239         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12240         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12241         /* set pin widget 18h (mic1) for output (CLFE)*/
12242         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12243
12244         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12245         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12246
12247         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12248 #if 0
12249         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12250         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12251 #endif
12252         { } /* end */
12253 };
12254
12255 static struct hda_channel_mode alc861_threestack_modes[2] = {
12256         { 2, alc861_threestack_ch2_init },
12257         { 6, alc861_threestack_ch6_init },
12258 };
12259 /* Set mic1 as input and unmute the mixer */
12260 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
12261         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12262         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12263         { } /* end */
12264 };
12265 /* Set mic1 as output and mute mixer */
12266 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
12267         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12268         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12269         { } /* end */
12270 };
12271
12272 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
12273         { 2, alc861_uniwill_m31_ch2_init },
12274         { 4, alc861_uniwill_m31_ch4_init },
12275 };
12276
12277 /* Set mic1 and line-in as input and unmute the mixer */
12278 static struct hda_verb alc861_asus_ch2_init[] = {
12279         /* set pin widget 1Ah (line in) for input */
12280         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12281         /* set pin widget 18h (mic1/2) for input, for mic also enable
12282          * the vref
12283          */
12284         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12285
12286         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12287 #if 0
12288         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12289         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12290 #endif
12291         { } /* end */
12292 };
12293 /* Set mic1 nad line-in as output and mute mixer */
12294 static struct hda_verb alc861_asus_ch6_init[] = {
12295         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12296         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12297         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12298         /* set pin widget 18h (mic1) for output (CLFE)*/
12299         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12300         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12301         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12302         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12303
12304         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12305 #if 0
12306         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12307         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12308 #endif
12309         { } /* end */
12310 };
12311
12312 static struct hda_channel_mode alc861_asus_modes[2] = {
12313         { 2, alc861_asus_ch2_init },
12314         { 6, alc861_asus_ch6_init },
12315 };
12316
12317 /* patch-ALC861 */
12318
12319 static struct snd_kcontrol_new alc861_base_mixer[] = {
12320         /* output mixer control */
12321         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12322         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12323         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12324         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12325         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12326
12327         /*Input mixer control */
12328         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12329            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12330         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12331         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12332         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12333         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12334         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12335         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12336         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12337         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12338
12339         { } /* end */
12340 };
12341
12342 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12343         /* output mixer control */
12344         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12345         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12346         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12347         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12348         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12349
12350         /* Input mixer control */
12351         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12352            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12353         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12354         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12355         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12356         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12357         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12358         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12359         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12360         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12361
12362         {
12363                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12364                 .name = "Channel Mode",
12365                 .info = alc_ch_mode_info,
12366                 .get = alc_ch_mode_get,
12367                 .put = alc_ch_mode_put,
12368                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
12369         },
12370         { } /* end */
12371 };
12372
12373 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
12374         /* output mixer control */
12375         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12376         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12377         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12378
12379         { } /* end */
12380 };
12381
12382 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
12383         /* output mixer control */
12384         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12385         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12386         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12387         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12388         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12389
12390         /* Input mixer control */
12391         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12392            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12393         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12394         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12395         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12396         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12397         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12398         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12399         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12400         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12401
12402         {
12403                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12404                 .name = "Channel Mode",
12405                 .info = alc_ch_mode_info,
12406                 .get = alc_ch_mode_get,
12407                 .put = alc_ch_mode_put,
12408                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
12409         },
12410         { } /* end */
12411 };
12412
12413 static struct snd_kcontrol_new alc861_asus_mixer[] = {
12414         /* output mixer control */
12415         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12416         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12417         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12418         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12419         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12420
12421         /* Input mixer control */
12422         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12423         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12424         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12425         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12426         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12427         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12428         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12429         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12430         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12431         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
12432
12433         {
12434                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12435                 .name = "Channel Mode",
12436                 .info = alc_ch_mode_info,
12437                 .get = alc_ch_mode_get,
12438                 .put = alc_ch_mode_put,
12439                 .private_value = ARRAY_SIZE(alc861_asus_modes),
12440         },
12441         { }
12442 };
12443
12444 /* additional mixer */
12445 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
12446         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12447         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12448         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
12449         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
12450         { }
12451 };
12452
12453 /*
12454  * generic initialization of ADC, input mixers and output mixers
12455  */
12456 static struct hda_verb alc861_base_init_verbs[] = {
12457         /*
12458          * Unmute ADC0 and set the default input to mic-in
12459          */
12460         /* port-A for surround (rear panel) */
12461         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12462         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
12463         /* port-B for mic-in (rear panel) with vref */
12464         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12465         /* port-C for line-in (rear panel) */
12466         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12467         /* port-D for Front */
12468         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12469         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12470         /* port-E for HP out (front panel) */
12471         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
12472         /* route front PCM to HP */
12473         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12474         /* port-F for mic-in (front panel) with vref */
12475         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12476         /* port-G for CLFE (rear panel) */
12477         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12478         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12479         /* port-H for side (rear panel) */
12480         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12481         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
12482         /* CD-in */
12483         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12484         /* route front mic to ADC1*/
12485         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12486         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12487
12488         /* Unmute DAC0~3 & spdif out*/
12489         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12490         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12491         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12492         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12493         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12494
12495         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12496         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12497         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12498         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12499         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12500
12501         /* Unmute Stereo Mixer 15 */
12502         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12503         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12504         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12505         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12506
12507         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12508         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12509         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12510         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12511         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12512         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12513         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12514         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12515         /* hp used DAC 3 (Front) */
12516         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12517         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12518
12519         { }
12520 };
12521
12522 static struct hda_verb alc861_threestack_init_verbs[] = {
12523         /*
12524          * Unmute ADC0 and set the default input to mic-in
12525          */
12526         /* port-A for surround (rear panel) */
12527         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12528         /* port-B for mic-in (rear panel) with vref */
12529         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12530         /* port-C for line-in (rear panel) */
12531         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12532         /* port-D for Front */
12533         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12534         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12535         /* port-E for HP out (front panel) */
12536         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
12537         /* route front PCM to HP */
12538         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12539         /* port-F for mic-in (front panel) with vref */
12540         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12541         /* port-G for CLFE (rear panel) */
12542         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12543         /* port-H for side (rear panel) */
12544         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12545         /* CD-in */
12546         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12547         /* route front mic to ADC1*/
12548         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12549         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12550         /* Unmute DAC0~3 & spdif out*/
12551         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12552         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12553         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12554         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12555         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12556
12557         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12558         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12559         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12560         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12561         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12562
12563         /* Unmute Stereo Mixer 15 */
12564         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12565         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12566         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12567         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12568
12569         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12570         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12571         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12572         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12573         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12574         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12575         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12576         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12577         /* hp used DAC 3 (Front) */
12578         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12579         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12580         { }
12581 };
12582
12583 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
12584         /*
12585          * Unmute ADC0 and set the default input to mic-in
12586          */
12587         /* port-A for surround (rear panel) */
12588         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12589         /* port-B for mic-in (rear panel) with vref */
12590         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12591         /* port-C for line-in (rear panel) */
12592         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12593         /* port-D for Front */
12594         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12595         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12596         /* port-E for HP out (front panel) */
12597         /* this has to be set to VREF80 */
12598         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12599         /* route front PCM to HP */
12600         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12601         /* port-F for mic-in (front panel) with vref */
12602         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12603         /* port-G for CLFE (rear panel) */
12604         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12605         /* port-H for side (rear panel) */
12606         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12607         /* CD-in */
12608         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12609         /* route front mic to ADC1*/
12610         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12611         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12612         /* Unmute DAC0~3 & spdif out*/
12613         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12614         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12615         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12616         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12617         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12618
12619         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12620         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12621         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12622         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12623         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12624
12625         /* Unmute Stereo Mixer 15 */
12626         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12627         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12628         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12629         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12630
12631         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12632         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12633         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12634         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12635         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12636         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12637         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12638         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12639         /* hp used DAC 3 (Front) */
12640         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12641         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12642         { }
12643 };
12644
12645 static struct hda_verb alc861_asus_init_verbs[] = {
12646         /*
12647          * Unmute ADC0 and set the default input to mic-in
12648          */
12649         /* port-A for surround (rear panel)
12650          * according to codec#0 this is the HP jack
12651          */
12652         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
12653         /* route front PCM to HP */
12654         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
12655         /* port-B for mic-in (rear panel) with vref */
12656         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12657         /* port-C for line-in (rear panel) */
12658         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12659         /* port-D for Front */
12660         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12661         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12662         /* port-E for HP out (front panel) */
12663         /* this has to be set to VREF80 */
12664         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12665         /* route front PCM to HP */
12666         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12667         /* port-F for mic-in (front panel) with vref */
12668         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12669         /* port-G for CLFE (rear panel) */
12670         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12671         /* port-H for side (rear panel) */
12672         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12673         /* CD-in */
12674         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12675         /* route front mic to ADC1*/
12676         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12677         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12678         /* Unmute DAC0~3 & spdif out*/
12679         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12680         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12681         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12682         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12683         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12684         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12685         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12686         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12687         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12688         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12689
12690         /* Unmute Stereo Mixer 15 */
12691         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12692         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12693         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12694         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12695
12696         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12697         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12698         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12699         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12700         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12701         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12702         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12703         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12704         /* hp used DAC 3 (Front) */
12705         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12706         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12707         { }
12708 };
12709
12710 /* additional init verbs for ASUS laptops */
12711 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
12712         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
12713         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
12714         { }
12715 };
12716
12717 /*
12718  * generic initialization of ADC, input mixers and output mixers
12719  */
12720 static struct hda_verb alc861_auto_init_verbs[] = {
12721         /*
12722          * Unmute ADC0 and set the default input to mic-in
12723          */
12724         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
12725         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12726
12727         /* Unmute DAC0~3 & spdif out*/
12728         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12729         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12730         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12731         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12732         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12733
12734         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12735         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12736         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12737         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12738         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12739
12740         /* Unmute Stereo Mixer 15 */
12741         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12742         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12743         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12744         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
12745
12746         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12747         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12748         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12749         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12750         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12751         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12752         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12753         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12754
12755         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12756         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12757         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12758         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12759         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12760         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12761         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12762         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12763
12764         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
12765
12766         { }
12767 };
12768
12769 static struct hda_verb alc861_toshiba_init_verbs[] = {
12770         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12771
12772         { }
12773 };
12774
12775 /* toggle speaker-output according to the hp-jack state */
12776 static void alc861_toshiba_automute(struct hda_codec *codec)
12777 {
12778         unsigned int present;
12779
12780         present = snd_hda_codec_read(codec, 0x0f, 0,
12781                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12782         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
12783                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
12784         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
12785                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
12786 }
12787
12788 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
12789                                        unsigned int res)
12790 {
12791         if ((res >> 26) == ALC880_HP_EVENT)
12792                 alc861_toshiba_automute(codec);
12793 }
12794
12795 /* pcm configuration: identiacal with ALC880 */
12796 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
12797 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
12798 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
12799 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
12800
12801
12802 #define ALC861_DIGOUT_NID       0x07
12803
12804 static struct hda_channel_mode alc861_8ch_modes[1] = {
12805         { 8, NULL }
12806 };
12807
12808 static hda_nid_t alc861_dac_nids[4] = {
12809         /* front, surround, clfe, side */
12810         0x03, 0x06, 0x05, 0x04
12811 };
12812
12813 static hda_nid_t alc660_dac_nids[3] = {
12814         /* front, clfe, surround */
12815         0x03, 0x05, 0x06
12816 };
12817
12818 static hda_nid_t alc861_adc_nids[1] = {
12819         /* ADC0-2 */
12820         0x08,
12821 };
12822
12823 static struct hda_input_mux alc861_capture_source = {
12824         .num_items = 5,
12825         .items = {
12826                 { "Mic", 0x0 },
12827                 { "Front Mic", 0x3 },
12828                 { "Line", 0x1 },
12829                 { "CD", 0x4 },
12830                 { "Mixer", 0x5 },
12831         },
12832 };
12833
12834 /* fill in the dac_nids table from the parsed pin configuration */
12835 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
12836                                      const struct auto_pin_cfg *cfg)
12837 {
12838         int i;
12839         hda_nid_t nid;
12840
12841         spec->multiout.dac_nids = spec->private_dac_nids;
12842         for (i = 0; i < cfg->line_outs; i++) {
12843                 nid = cfg->line_out_pins[i];
12844                 if (nid) {
12845                         if (i >= ARRAY_SIZE(alc861_dac_nids))
12846                                 continue;
12847                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
12848                 }
12849         }
12850         spec->multiout.num_dacs = cfg->line_outs;
12851         return 0;
12852 }
12853
12854 /* add playback controls from the parsed DAC table */
12855 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
12856                                              const struct auto_pin_cfg *cfg)
12857 {
12858         char name[32];
12859         static const char *chname[4] = {
12860                 "Front", "Surround", NULL /*CLFE*/, "Side"
12861         };
12862         hda_nid_t nid;
12863         int i, idx, err;
12864
12865         for (i = 0; i < cfg->line_outs; i++) {
12866                 nid = spec->multiout.dac_nids[i];
12867                 if (!nid)
12868                         continue;
12869                 if (nid == 0x05) {
12870                         /* Center/LFE */
12871                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12872                                           "Center Playback Switch",
12873                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
12874                                                               HDA_OUTPUT));
12875                         if (err < 0)
12876                                 return err;
12877                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12878                                           "LFE Playback Switch",
12879                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12880                                                               HDA_OUTPUT));
12881                         if (err < 0)
12882                                 return err;
12883                 } else {
12884                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
12885                              idx++)
12886                                 if (nid == alc861_dac_nids[idx])
12887                                         break;
12888                         sprintf(name, "%s Playback Switch", chname[idx]);
12889                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12890                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12891                                                               HDA_OUTPUT));
12892                         if (err < 0)
12893                                 return err;
12894                 }
12895         }
12896         return 0;
12897 }
12898
12899 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
12900 {
12901         int err;
12902         hda_nid_t nid;
12903
12904         if (!pin)
12905                 return 0;
12906
12907         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
12908                 nid = 0x03;
12909                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12910                                   "Headphone Playback Switch",
12911                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12912                 if (err < 0)
12913                         return err;
12914                 spec->multiout.hp_nid = nid;
12915         }
12916         return 0;
12917 }
12918
12919 /* create playback/capture controls for input pins */
12920 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
12921                                                 const struct auto_pin_cfg *cfg)
12922 {
12923         struct hda_input_mux *imux = &spec->private_imux;
12924         int i, err, idx, idx1;
12925
12926         for (i = 0; i < AUTO_PIN_LAST; i++) {
12927                 switch (cfg->input_pins[i]) {
12928                 case 0x0c:
12929                         idx1 = 1;
12930                         idx = 2;        /* Line In */
12931                         break;
12932                 case 0x0f:
12933                         idx1 = 2;
12934                         idx = 2;        /* Line In */
12935                         break;
12936                 case 0x0d:
12937                         idx1 = 0;
12938                         idx = 1;        /* Mic In */
12939                         break;
12940                 case 0x10:
12941                         idx1 = 3;
12942                         idx = 1;        /* Mic In */
12943                         break;
12944                 case 0x11:
12945                         idx1 = 4;
12946                         idx = 0;        /* CD */
12947                         break;
12948                 default:
12949                         continue;
12950                 }
12951
12952                 err = new_analog_input(spec, cfg->input_pins[i],
12953                                        auto_pin_cfg_labels[i], idx, 0x15);
12954                 if (err < 0)
12955                         return err;
12956
12957                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
12958                 imux->items[imux->num_items].index = idx1;
12959                 imux->num_items++;
12960         }
12961         return 0;
12962 }
12963
12964 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
12965                                               hda_nid_t nid,
12966                                               int pin_type, int dac_idx)
12967 {
12968         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
12969                             pin_type);
12970         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12971                             AMP_OUT_UNMUTE);
12972 }
12973
12974 static void alc861_auto_init_multi_out(struct hda_codec *codec)
12975 {
12976         struct alc_spec *spec = codec->spec;
12977         int i;
12978
12979         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
12980         for (i = 0; i < spec->autocfg.line_outs; i++) {
12981                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
12982                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12983                 if (nid)
12984                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
12985                                                           spec->multiout.dac_nids[i]);
12986         }
12987 }
12988
12989 static void alc861_auto_init_hp_out(struct hda_codec *codec)
12990 {
12991         struct alc_spec *spec = codec->spec;
12992         hda_nid_t pin;
12993
12994         pin = spec->autocfg.hp_pins[0];
12995         if (pin) /* connect to front */
12996                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
12997                                                   spec->multiout.dac_nids[0]);
12998         pin = spec->autocfg.speaker_pins[0];
12999         if (pin)
13000                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13001 }
13002
13003 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13004 {
13005         struct alc_spec *spec = codec->spec;
13006         int i;
13007
13008         for (i = 0; i < AUTO_PIN_LAST; i++) {
13009                 hda_nid_t nid = spec->autocfg.input_pins[i];
13010                 if (nid >= 0x0c && nid <= 0x11) {
13011                         snd_hda_codec_write(codec, nid, 0,
13012                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13013                                             i <= AUTO_PIN_FRONT_MIC ?
13014                                             PIN_VREF80 : PIN_IN);
13015                 }
13016         }
13017 }
13018
13019 /* parse the BIOS configuration and set up the alc_spec */
13020 /* return 1 if successful, 0 if the proper config is not found,
13021  * or a negative error code
13022  */
13023 static int alc861_parse_auto_config(struct hda_codec *codec)
13024 {
13025         struct alc_spec *spec = codec->spec;
13026         int err;
13027         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13028
13029         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13030                                            alc861_ignore);
13031         if (err < 0)
13032                 return err;
13033         if (!spec->autocfg.line_outs)
13034                 return 0; /* can't find valid BIOS pin config */
13035
13036         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13037         if (err < 0)
13038                 return err;
13039         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13040         if (err < 0)
13041                 return err;
13042         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13043         if (err < 0)
13044                 return err;
13045         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13046         if (err < 0)
13047                 return err;
13048
13049         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13050
13051         if (spec->autocfg.dig_out_pin)
13052                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13053
13054         if (spec->kctls.list)
13055                 add_mixer(spec, spec->kctls.list);
13056
13057         add_verb(spec, alc861_auto_init_verbs);
13058
13059         spec->num_mux_defs = 1;
13060         spec->input_mux = &spec->private_imux;
13061
13062         spec->adc_nids = alc861_adc_nids;
13063         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13064         set_capture_mixer(spec);
13065
13066         store_pin_configs(codec);
13067         return 1;
13068 }
13069
13070 /* additional initialization for auto-configuration model */
13071 static void alc861_auto_init(struct hda_codec *codec)
13072 {
13073         struct alc_spec *spec = codec->spec;
13074         alc861_auto_init_multi_out(codec);
13075         alc861_auto_init_hp_out(codec);
13076         alc861_auto_init_analog_input(codec);
13077         if (spec->unsol_event)
13078                 alc_inithook(codec);
13079 }
13080
13081 #ifdef CONFIG_SND_HDA_POWER_SAVE
13082 static struct hda_amp_list alc861_loopbacks[] = {
13083         { 0x15, HDA_INPUT, 0 },
13084         { 0x15, HDA_INPUT, 1 },
13085         { 0x15, HDA_INPUT, 2 },
13086         { 0x15, HDA_INPUT, 3 },
13087         { } /* end */
13088 };
13089 #endif
13090
13091
13092 /*
13093  * configuration and preset
13094  */
13095 static const char *alc861_models[ALC861_MODEL_LAST] = {
13096         [ALC861_3ST]            = "3stack",
13097         [ALC660_3ST]            = "3stack-660",
13098         [ALC861_3ST_DIG]        = "3stack-dig",
13099         [ALC861_6ST_DIG]        = "6stack-dig",
13100         [ALC861_UNIWILL_M31]    = "uniwill-m31",
13101         [ALC861_TOSHIBA]        = "toshiba",
13102         [ALC861_ASUS]           = "asus",
13103         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
13104         [ALC861_AUTO]           = "auto",
13105 };
13106
13107 static struct snd_pci_quirk alc861_cfg_tbl[] = {
13108         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
13109         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13110         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13111         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
13112         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
13113         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
13114         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
13115         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
13116          *        Any other models that need this preset?
13117          */
13118         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
13119         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
13120         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
13121         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
13122         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
13123         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
13124         /* FIXME: the below seems conflict */
13125         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
13126         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
13127         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
13128         {}
13129 };
13130
13131 static struct alc_config_preset alc861_presets[] = {
13132         [ALC861_3ST] = {
13133                 .mixers = { alc861_3ST_mixer },
13134                 .init_verbs = { alc861_threestack_init_verbs },
13135                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13136                 .dac_nids = alc861_dac_nids,
13137                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13138                 .channel_mode = alc861_threestack_modes,
13139                 .need_dac_fix = 1,
13140                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13141                 .adc_nids = alc861_adc_nids,
13142                 .input_mux = &alc861_capture_source,
13143         },
13144         [ALC861_3ST_DIG] = {
13145                 .mixers = { alc861_base_mixer },
13146                 .init_verbs = { alc861_threestack_init_verbs },
13147                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13148                 .dac_nids = alc861_dac_nids,
13149                 .dig_out_nid = ALC861_DIGOUT_NID,
13150                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13151                 .channel_mode = alc861_threestack_modes,
13152                 .need_dac_fix = 1,
13153                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13154                 .adc_nids = alc861_adc_nids,
13155                 .input_mux = &alc861_capture_source,
13156         },
13157         [ALC861_6ST_DIG] = {
13158                 .mixers = { alc861_base_mixer },
13159                 .init_verbs = { alc861_base_init_verbs },
13160                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13161                 .dac_nids = alc861_dac_nids,
13162                 .dig_out_nid = ALC861_DIGOUT_NID,
13163                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
13164                 .channel_mode = alc861_8ch_modes,
13165                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13166                 .adc_nids = alc861_adc_nids,
13167                 .input_mux = &alc861_capture_source,
13168         },
13169         [ALC660_3ST] = {
13170                 .mixers = { alc861_3ST_mixer },
13171                 .init_verbs = { alc861_threestack_init_verbs },
13172                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
13173                 .dac_nids = alc660_dac_nids,
13174                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13175                 .channel_mode = alc861_threestack_modes,
13176                 .need_dac_fix = 1,
13177                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13178                 .adc_nids = alc861_adc_nids,
13179                 .input_mux = &alc861_capture_source,
13180         },
13181         [ALC861_UNIWILL_M31] = {
13182                 .mixers = { alc861_uniwill_m31_mixer },
13183                 .init_verbs = { alc861_uniwill_m31_init_verbs },
13184                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13185                 .dac_nids = alc861_dac_nids,
13186                 .dig_out_nid = ALC861_DIGOUT_NID,
13187                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
13188                 .channel_mode = alc861_uniwill_m31_modes,
13189                 .need_dac_fix = 1,
13190                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13191                 .adc_nids = alc861_adc_nids,
13192                 .input_mux = &alc861_capture_source,
13193         },
13194         [ALC861_TOSHIBA] = {
13195                 .mixers = { alc861_toshiba_mixer },
13196                 .init_verbs = { alc861_base_init_verbs,
13197                                 alc861_toshiba_init_verbs },
13198                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13199                 .dac_nids = alc861_dac_nids,
13200                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13201                 .channel_mode = alc883_3ST_2ch_modes,
13202                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13203                 .adc_nids = alc861_adc_nids,
13204                 .input_mux = &alc861_capture_source,
13205                 .unsol_event = alc861_toshiba_unsol_event,
13206                 .init_hook = alc861_toshiba_automute,
13207         },
13208         [ALC861_ASUS] = {
13209                 .mixers = { alc861_asus_mixer },
13210                 .init_verbs = { alc861_asus_init_verbs },
13211                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13212                 .dac_nids = alc861_dac_nids,
13213                 .dig_out_nid = ALC861_DIGOUT_NID,
13214                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
13215                 .channel_mode = alc861_asus_modes,
13216                 .need_dac_fix = 1,
13217                 .hp_nid = 0x06,
13218                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13219                 .adc_nids = alc861_adc_nids,
13220                 .input_mux = &alc861_capture_source,
13221         },
13222         [ALC861_ASUS_LAPTOP] = {
13223                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
13224                 .init_verbs = { alc861_asus_init_verbs,
13225                                 alc861_asus_laptop_init_verbs },
13226                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13227                 .dac_nids = alc861_dac_nids,
13228                 .dig_out_nid = ALC861_DIGOUT_NID,
13229                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13230                 .channel_mode = alc883_3ST_2ch_modes,
13231                 .need_dac_fix = 1,
13232                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13233                 .adc_nids = alc861_adc_nids,
13234                 .input_mux = &alc861_capture_source,
13235         },
13236 };
13237
13238
13239 static int patch_alc861(struct hda_codec *codec)
13240 {
13241         struct alc_spec *spec;
13242         int board_config;
13243         int err;
13244
13245         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13246         if (spec == NULL)
13247                 return -ENOMEM;
13248
13249         codec->spec = spec;
13250
13251         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
13252                                                   alc861_models,
13253                                                   alc861_cfg_tbl);
13254
13255         if (board_config < 0) {
13256                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
13257                        "trying auto-probe from BIOS...\n");
13258                 board_config = ALC861_AUTO;
13259         }
13260
13261         if (board_config == ALC861_AUTO) {
13262                 /* automatic parse from the BIOS config */
13263                 err = alc861_parse_auto_config(codec);
13264                 if (err < 0) {
13265                         alc_free(codec);
13266                         return err;
13267                 } else if (!err) {
13268                         printk(KERN_INFO
13269                                "hda_codec: Cannot set up configuration "
13270                                "from BIOS.  Using base mode...\n");
13271                    board_config = ALC861_3ST_DIG;
13272                 }
13273         }
13274
13275         if (board_config != ALC861_AUTO)
13276                 setup_preset(spec, &alc861_presets[board_config]);
13277
13278         spec->stream_name_analog = "ALC861 Analog";
13279         spec->stream_analog_playback = &alc861_pcm_analog_playback;
13280         spec->stream_analog_capture = &alc861_pcm_analog_capture;
13281
13282         spec->stream_name_digital = "ALC861 Digital";
13283         spec->stream_digital_playback = &alc861_pcm_digital_playback;
13284         spec->stream_digital_capture = &alc861_pcm_digital_capture;
13285
13286         spec->vmaster_nid = 0x03;
13287
13288         codec->patch_ops = alc_patch_ops;
13289         if (board_config == ALC861_AUTO)
13290                 spec->init_hook = alc861_auto_init;
13291 #ifdef CONFIG_SND_HDA_POWER_SAVE
13292         if (!spec->loopback.amplist)
13293                 spec->loopback.amplist = alc861_loopbacks;
13294 #endif
13295
13296         return 0;
13297 }
13298
13299 /*
13300  * ALC861-VD support
13301  *
13302  * Based on ALC882
13303  *
13304  * In addition, an independent DAC
13305  */
13306 #define ALC861VD_DIGOUT_NID     0x06
13307
13308 static hda_nid_t alc861vd_dac_nids[4] = {
13309         /* front, surr, clfe, side surr */
13310         0x02, 0x03, 0x04, 0x05
13311 };
13312
13313 /* dac_nids for ALC660vd are in a different order - according to
13314  * Realtek's driver.
13315  * This should probably tesult in a different mixer for 6stack models
13316  * of ALC660vd codecs, but for now there is only 3stack mixer
13317  * - and it is the same as in 861vd.
13318  * adc_nids in ALC660vd are (is) the same as in 861vd
13319  */
13320 static hda_nid_t alc660vd_dac_nids[3] = {
13321         /* front, rear, clfe, rear_surr */
13322         0x02, 0x04, 0x03
13323 };
13324
13325 static hda_nid_t alc861vd_adc_nids[1] = {
13326         /* ADC0 */
13327         0x09,
13328 };
13329
13330 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
13331
13332 /* input MUX */
13333 /* FIXME: should be a matrix-type input source selection */
13334 static struct hda_input_mux alc861vd_capture_source = {
13335         .num_items = 4,
13336         .items = {
13337                 { "Mic", 0x0 },
13338                 { "Front Mic", 0x1 },
13339                 { "Line", 0x2 },
13340                 { "CD", 0x4 },
13341         },
13342 };
13343
13344 static struct hda_input_mux alc861vd_dallas_capture_source = {
13345         .num_items = 2,
13346         .items = {
13347                 { "Ext Mic", 0x0 },
13348                 { "Int Mic", 0x1 },
13349         },
13350 };
13351
13352 static struct hda_input_mux alc861vd_hp_capture_source = {
13353         .num_items = 2,
13354         .items = {
13355                 { "Front Mic", 0x0 },
13356                 { "ATAPI Mic", 0x1 },
13357         },
13358 };
13359
13360 /*
13361  * 2ch mode
13362  */
13363 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
13364         { 2, NULL }
13365 };
13366
13367 /*
13368  * 6ch mode
13369  */
13370 static struct hda_verb alc861vd_6stack_ch6_init[] = {
13371         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13372         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13373         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13374         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13375         { } /* end */
13376 };
13377
13378 /*
13379  * 8ch mode
13380  */
13381 static struct hda_verb alc861vd_6stack_ch8_init[] = {
13382         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13383         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13384         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13385         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13386         { } /* end */
13387 };
13388
13389 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
13390         { 6, alc861vd_6stack_ch6_init },
13391         { 8, alc861vd_6stack_ch8_init },
13392 };
13393
13394 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
13395         {
13396                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13397                 .name = "Channel Mode",
13398                 .info = alc_ch_mode_info,
13399                 .get = alc_ch_mode_get,
13400                 .put = alc_ch_mode_put,
13401         },
13402         { } /* end */
13403 };
13404
13405 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13406  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13407  */
13408 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
13409         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13410         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13411
13412         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13413         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
13414
13415         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
13416                                 HDA_OUTPUT),
13417         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
13418                                 HDA_OUTPUT),
13419         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
13420         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
13421
13422         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
13423         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
13424
13425         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13426
13427         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13428         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13429         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13430
13431         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13432         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13433         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13434
13435         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13436         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13437
13438         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13439         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13440
13441         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13442         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13443
13444         { } /* end */
13445 };
13446
13447 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
13448         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13449         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13450
13451         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13452
13453         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13454         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13455         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13456
13457         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13458         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13459         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13460
13461         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13462         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13463
13464         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13465         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13466
13467         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13468         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13469
13470         { } /* end */
13471 };
13472
13473 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
13474         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13475         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
13476         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13477
13478         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13479
13480         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13481         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13482         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13483
13484         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13485         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13486         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13487
13488         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13489         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13490
13491         { } /* end */
13492 };
13493
13494 /* Pin assignment: Speaker=0x14, HP = 0x15,
13495  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
13496  */
13497 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
13498         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13499         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
13500         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13501         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
13502         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
13503         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13504         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13505         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
13506         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13507         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13508         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
13509         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
13510         { } /* end */
13511 };
13512
13513 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
13514  *                 Front Mic=0x18, ATAPI Mic = 0x19,
13515  */
13516 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
13517         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13518         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13519         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13520         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
13521         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13522         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13523         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13524         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13525
13526         { } /* end */
13527 };
13528
13529 /*
13530  * generic initialization of ADC, input mixers and output mixers
13531  */
13532 static struct hda_verb alc861vd_volume_init_verbs[] = {
13533         /*
13534          * Unmute ADC0 and set the default input to mic-in
13535          */
13536         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13537         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13538
13539         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
13540          * the analog-loopback mixer widget
13541          */
13542         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13543         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13544         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13545         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13546         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13547         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13548
13549         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
13550         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13551         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13552         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13553         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13554
13555         /*
13556          * Set up output mixers (0x02 - 0x05)
13557          */
13558         /* set vol=0 to output mixers */
13559         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13560         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13561         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13562         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13563
13564         /* set up input amps for analog loopback */
13565         /* Amp Indices: DAC = 0, mixer = 1 */
13566         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13567         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13568         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13569         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13570         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13571         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13572         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13573         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13574
13575         { }
13576 };
13577
13578 /*
13579  * 3-stack pin configuration:
13580  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
13581  */
13582 static struct hda_verb alc861vd_3stack_init_verbs[] = {
13583         /*
13584          * Set pin mode and muting
13585          */
13586         /* set front pin widgets 0x14 for output */
13587         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13588         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13589         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13590
13591         /* Mic (rear) pin: input vref at 80% */
13592         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13593         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13594         /* Front Mic pin: input vref at 80% */
13595         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13596         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13597         /* Line In pin: input */
13598         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13599         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13600         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13601         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13602         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13603         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13604         /* CD pin widget for input */
13605         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13606
13607         { }
13608 };
13609
13610 /*
13611  * 6-stack pin configuration:
13612  */
13613 static struct hda_verb alc861vd_6stack_init_verbs[] = {
13614         /*
13615          * Set pin mode and muting
13616          */
13617         /* set front pin widgets 0x14 for output */
13618         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13619         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13620         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13621
13622         /* Rear Pin: output 1 (0x0d) */
13623         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13624         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13625         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13626         /* CLFE Pin: output 2 (0x0e) */
13627         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13628         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13629         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
13630         /* Side Pin: output 3 (0x0f) */
13631         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13632         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13633         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
13634
13635         /* Mic (rear) pin: input vref at 80% */
13636         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13637         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13638         /* Front Mic pin: input vref at 80% */
13639         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13640         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13641         /* Line In pin: input */
13642         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13643         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13644         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13645         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13646         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13647         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13648         /* CD pin widget for input */
13649         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13650
13651         { }
13652 };
13653
13654 static struct hda_verb alc861vd_eapd_verbs[] = {
13655         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13656         { }
13657 };
13658
13659 static struct hda_verb alc660vd_eapd_verbs[] = {
13660         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13661         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13662         { }
13663 };
13664
13665 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
13666         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13667         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13668         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
13669         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13670         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13671         {}
13672 };
13673
13674 /* toggle speaker-output according to the hp-jack state */
13675 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
13676 {
13677         unsigned int present;
13678         unsigned char bits;
13679
13680         present = snd_hda_codec_read(codec, 0x1b, 0,
13681                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13682         bits = present ? HDA_AMP_MUTE : 0;
13683         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13684                                  HDA_AMP_MUTE, bits);
13685 }
13686
13687 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
13688 {
13689         unsigned int present;
13690         unsigned char bits;
13691
13692         present = snd_hda_codec_read(codec, 0x18, 0,
13693                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13694         bits = present ? HDA_AMP_MUTE : 0;
13695         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
13696                                  HDA_AMP_MUTE, bits);
13697 }
13698
13699 static void alc861vd_lenovo_automute(struct hda_codec *codec)
13700 {
13701         alc861vd_lenovo_hp_automute(codec);
13702         alc861vd_lenovo_mic_automute(codec);
13703 }
13704
13705 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
13706                                         unsigned int res)
13707 {
13708         switch (res >> 26) {
13709         case ALC880_HP_EVENT:
13710                 alc861vd_lenovo_hp_automute(codec);
13711                 break;
13712         case ALC880_MIC_EVENT:
13713                 alc861vd_lenovo_mic_automute(codec);
13714                 break;
13715         }
13716 }
13717
13718 static struct hda_verb alc861vd_dallas_verbs[] = {
13719         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13720         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13721         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13722         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13723
13724         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13725         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13726         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13727         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13728         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13729         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13730         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13731         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13732
13733         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13734         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13735         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13736         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13737         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13738         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13739         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13740         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13741
13742         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13743         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13744         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13745         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13746         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13747         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13748         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13749         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13750
13751         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13752         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13753         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13754         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13755
13756         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13757         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13758         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13759
13760         { } /* end */
13761 };
13762
13763 /* toggle speaker-output according to the hp-jack state */
13764 static void alc861vd_dallas_automute(struct hda_codec *codec)
13765 {
13766         unsigned int present;
13767
13768         present = snd_hda_codec_read(codec, 0x15, 0,
13769                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13770         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13771                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13772 }
13773
13774 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
13775 {
13776         if ((res >> 26) == ALC880_HP_EVENT)
13777                 alc861vd_dallas_automute(codec);
13778 }
13779
13780 #ifdef CONFIG_SND_HDA_POWER_SAVE
13781 #define alc861vd_loopbacks      alc880_loopbacks
13782 #endif
13783
13784 /* pcm configuration: identiacal with ALC880 */
13785 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
13786 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
13787 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
13788 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
13789
13790 /*
13791  * configuration and preset
13792  */
13793 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
13794         [ALC660VD_3ST]          = "3stack-660",
13795         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
13796         [ALC861VD_3ST]          = "3stack",
13797         [ALC861VD_3ST_DIG]      = "3stack-digout",
13798         [ALC861VD_6ST_DIG]      = "6stack-digout",
13799         [ALC861VD_LENOVO]       = "lenovo",
13800         [ALC861VD_DALLAS]       = "dallas",
13801         [ALC861VD_HP]           = "hp",
13802         [ALC861VD_AUTO]         = "auto",
13803 };
13804
13805 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
13806         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
13807         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
13808         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
13809         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
13810         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC861VD_LENOVO),
13811         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
13812         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
13813         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
13814         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
13815         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
13816         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
13817         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
13818         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
13819         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
13820         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
13821         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
13822         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
13823         {}
13824 };
13825
13826 static struct alc_config_preset alc861vd_presets[] = {
13827         [ALC660VD_3ST] = {
13828                 .mixers = { alc861vd_3st_mixer },
13829                 .init_verbs = { alc861vd_volume_init_verbs,
13830                                  alc861vd_3stack_init_verbs },
13831                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13832                 .dac_nids = alc660vd_dac_nids,
13833                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13834                 .channel_mode = alc861vd_3stack_2ch_modes,
13835                 .input_mux = &alc861vd_capture_source,
13836         },
13837         [ALC660VD_3ST_DIG] = {
13838                 .mixers = { alc861vd_3st_mixer },
13839                 .init_verbs = { alc861vd_volume_init_verbs,
13840                                  alc861vd_3stack_init_verbs },
13841                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13842                 .dac_nids = alc660vd_dac_nids,
13843                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13844                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13845                 .channel_mode = alc861vd_3stack_2ch_modes,
13846                 .input_mux = &alc861vd_capture_source,
13847         },
13848         [ALC861VD_3ST] = {
13849                 .mixers = { alc861vd_3st_mixer },
13850                 .init_verbs = { alc861vd_volume_init_verbs,
13851                                  alc861vd_3stack_init_verbs },
13852                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13853                 .dac_nids = alc861vd_dac_nids,
13854                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13855                 .channel_mode = alc861vd_3stack_2ch_modes,
13856                 .input_mux = &alc861vd_capture_source,
13857         },
13858         [ALC861VD_3ST_DIG] = {
13859                 .mixers = { alc861vd_3st_mixer },
13860                 .init_verbs = { alc861vd_volume_init_verbs,
13861                                  alc861vd_3stack_init_verbs },
13862                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13863                 .dac_nids = alc861vd_dac_nids,
13864                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13865                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13866                 .channel_mode = alc861vd_3stack_2ch_modes,
13867                 .input_mux = &alc861vd_capture_source,
13868         },
13869         [ALC861VD_6ST_DIG] = {
13870                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
13871                 .init_verbs = { alc861vd_volume_init_verbs,
13872                                 alc861vd_6stack_init_verbs },
13873                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13874                 .dac_nids = alc861vd_dac_nids,
13875                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13876                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
13877                 .channel_mode = alc861vd_6stack_modes,
13878                 .input_mux = &alc861vd_capture_source,
13879         },
13880         [ALC861VD_LENOVO] = {
13881                 .mixers = { alc861vd_lenovo_mixer },
13882                 .init_verbs = { alc861vd_volume_init_verbs,
13883                                 alc861vd_3stack_init_verbs,
13884                                 alc861vd_eapd_verbs,
13885                                 alc861vd_lenovo_unsol_verbs },
13886                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13887                 .dac_nids = alc660vd_dac_nids,
13888                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13889                 .channel_mode = alc861vd_3stack_2ch_modes,
13890                 .input_mux = &alc861vd_capture_source,
13891                 .unsol_event = alc861vd_lenovo_unsol_event,
13892                 .init_hook = alc861vd_lenovo_automute,
13893         },
13894         [ALC861VD_DALLAS] = {
13895                 .mixers = { alc861vd_dallas_mixer },
13896                 .init_verbs = { alc861vd_dallas_verbs },
13897                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13898                 .dac_nids = alc861vd_dac_nids,
13899                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13900                 .channel_mode = alc861vd_3stack_2ch_modes,
13901                 .input_mux = &alc861vd_dallas_capture_source,
13902                 .unsol_event = alc861vd_dallas_unsol_event,
13903                 .init_hook = alc861vd_dallas_automute,
13904         },
13905         [ALC861VD_HP] = {
13906                 .mixers = { alc861vd_hp_mixer },
13907                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
13908                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13909                 .dac_nids = alc861vd_dac_nids,
13910                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13911                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13912                 .channel_mode = alc861vd_3stack_2ch_modes,
13913                 .input_mux = &alc861vd_hp_capture_source,
13914                 .unsol_event = alc861vd_dallas_unsol_event,
13915                 .init_hook = alc861vd_dallas_automute,
13916         },
13917 };
13918
13919 /*
13920  * BIOS auto configuration
13921  */
13922 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
13923                                 hda_nid_t nid, int pin_type, int dac_idx)
13924 {
13925         alc_set_pin_output(codec, nid, pin_type);
13926 }
13927
13928 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
13929 {
13930         struct alc_spec *spec = codec->spec;
13931         int i;
13932
13933         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
13934         for (i = 0; i <= HDA_SIDE; i++) {
13935                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13936                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13937                 if (nid)
13938                         alc861vd_auto_set_output_and_unmute(codec, nid,
13939                                                             pin_type, i);
13940         }
13941 }
13942
13943
13944 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
13945 {
13946         struct alc_spec *spec = codec->spec;
13947         hda_nid_t pin;
13948
13949         pin = spec->autocfg.hp_pins[0];
13950         if (pin) /* connect to front and  use dac 0 */
13951                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
13952         pin = spec->autocfg.speaker_pins[0];
13953         if (pin)
13954                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13955 }
13956
13957 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
13958 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
13959
13960 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
13961 {
13962         struct alc_spec *spec = codec->spec;
13963         int i;
13964
13965         for (i = 0; i < AUTO_PIN_LAST; i++) {
13966                 hda_nid_t nid = spec->autocfg.input_pins[i];
13967                 if (alc861vd_is_input_pin(nid)) {
13968                         snd_hda_codec_write(codec, nid, 0,
13969                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
13970                                         i <= AUTO_PIN_FRONT_MIC ?
13971                                                         PIN_VREF80 : PIN_IN);
13972                         if (nid != ALC861VD_PIN_CD_NID)
13973                                 snd_hda_codec_write(codec, nid, 0,
13974                                                 AC_VERB_SET_AMP_GAIN_MUTE,
13975                                                 AMP_OUT_MUTE);
13976                 }
13977         }
13978 }
13979
13980 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
13981
13982 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
13983 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
13984
13985 /* add playback controls from the parsed DAC table */
13986 /* Based on ALC880 version. But ALC861VD has separate,
13987  * different NIDs for mute/unmute switch and volume control */
13988 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
13989                                              const struct auto_pin_cfg *cfg)
13990 {
13991         char name[32];
13992         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
13993         hda_nid_t nid_v, nid_s;
13994         int i, err;
13995
13996         for (i = 0; i < cfg->line_outs; i++) {
13997                 if (!spec->multiout.dac_nids[i])
13998                         continue;
13999                 nid_v = alc861vd_idx_to_mixer_vol(
14000                                 alc880_dac_to_idx(
14001                                         spec->multiout.dac_nids[i]));
14002                 nid_s = alc861vd_idx_to_mixer_switch(
14003                                 alc880_dac_to_idx(
14004                                         spec->multiout.dac_nids[i]));
14005
14006                 if (i == 2) {
14007                         /* Center/LFE */
14008                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14009                                           "Center Playback Volume",
14010                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14011                                                               HDA_OUTPUT));
14012                         if (err < 0)
14013                                 return err;
14014                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14015                                           "LFE Playback Volume",
14016                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14017                                                               HDA_OUTPUT));
14018                         if (err < 0)
14019                                 return err;
14020                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14021                                           "Center Playback Switch",
14022                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14023                                                               HDA_INPUT));
14024                         if (err < 0)
14025                                 return err;
14026                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14027                                           "LFE Playback Switch",
14028                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14029                                                               HDA_INPUT));
14030                         if (err < 0)
14031                                 return err;
14032                 } else {
14033                         sprintf(name, "%s Playback Volume", chname[i]);
14034                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14035                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14036                                                               HDA_OUTPUT));
14037                         if (err < 0)
14038                                 return err;
14039                         sprintf(name, "%s Playback Switch", chname[i]);
14040                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14041                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14042                                                               HDA_INPUT));
14043                         if (err < 0)
14044                                 return err;
14045                 }
14046         }
14047         return 0;
14048 }
14049
14050 /* add playback controls for speaker and HP outputs */
14051 /* Based on ALC880 version. But ALC861VD has separate,
14052  * different NIDs for mute/unmute switch and volume control */
14053 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14054                                         hda_nid_t pin, const char *pfx)
14055 {
14056         hda_nid_t nid_v, nid_s;
14057         int err;
14058         char name[32];
14059
14060         if (!pin)
14061                 return 0;
14062
14063         if (alc880_is_fixed_pin(pin)) {
14064                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14065                 /* specify the DAC as the extra output */
14066                 if (!spec->multiout.hp_nid)
14067                         spec->multiout.hp_nid = nid_v;
14068                 else
14069                         spec->multiout.extra_out_nid[0] = nid_v;
14070                 /* control HP volume/switch on the output mixer amp */
14071                 nid_v = alc861vd_idx_to_mixer_vol(
14072                                 alc880_fixed_pin_idx(pin));
14073                 nid_s = alc861vd_idx_to_mixer_switch(
14074                                 alc880_fixed_pin_idx(pin));
14075
14076                 sprintf(name, "%s Playback Volume", pfx);
14077                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14078                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
14079                 if (err < 0)
14080                         return err;
14081                 sprintf(name, "%s Playback Switch", pfx);
14082                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14083                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
14084                 if (err < 0)
14085                         return err;
14086         } else if (alc880_is_multi_pin(pin)) {
14087                 /* set manual connection */
14088                 /* we have only a switch on HP-out PIN */
14089                 sprintf(name, "%s Playback Switch", pfx);
14090                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14091                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14092                 if (err < 0)
14093                         return err;
14094         }
14095         return 0;
14096 }
14097
14098 /* parse the BIOS configuration and set up the alc_spec
14099  * return 1 if successful, 0 if the proper config is not found,
14100  * or a negative error code
14101  * Based on ALC880 version - had to change it to override
14102  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
14103 static int alc861vd_parse_auto_config(struct hda_codec *codec)
14104 {
14105         struct alc_spec *spec = codec->spec;
14106         int err;
14107         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
14108
14109         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14110                                            alc861vd_ignore);
14111         if (err < 0)
14112                 return err;
14113         if (!spec->autocfg.line_outs)
14114                 return 0; /* can't find valid BIOS pin config */
14115
14116         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14117         if (err < 0)
14118                 return err;
14119         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
14120         if (err < 0)
14121                 return err;
14122         err = alc861vd_auto_create_extra_out(spec,
14123                                              spec->autocfg.speaker_pins[0],
14124                                              "Speaker");
14125         if (err < 0)
14126                 return err;
14127         err = alc861vd_auto_create_extra_out(spec,
14128                                              spec->autocfg.hp_pins[0],
14129                                              "Headphone");
14130         if (err < 0)
14131                 return err;
14132         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
14133         if (err < 0)
14134                 return err;
14135
14136         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14137
14138         if (spec->autocfg.dig_out_pin)
14139                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14140
14141         if (spec->kctls.list)
14142                 add_mixer(spec, spec->kctls.list);
14143
14144         add_verb(spec, alc861vd_volume_init_verbs);
14145
14146         spec->num_mux_defs = 1;
14147         spec->input_mux = &spec->private_imux;
14148
14149         err = alc_auto_add_mic_boost(codec);
14150         if (err < 0)
14151                 return err;
14152
14153         store_pin_configs(codec);
14154         return 1;
14155 }
14156
14157 /* additional initialization for auto-configuration model */
14158 static void alc861vd_auto_init(struct hda_codec *codec)
14159 {
14160         struct alc_spec *spec = codec->spec;
14161         alc861vd_auto_init_multi_out(codec);
14162         alc861vd_auto_init_hp_out(codec);
14163         alc861vd_auto_init_analog_input(codec);
14164         alc861vd_auto_init_input_src(codec);
14165         if (spec->unsol_event)
14166                 alc_inithook(codec);
14167 }
14168
14169 static int patch_alc861vd(struct hda_codec *codec)
14170 {
14171         struct alc_spec *spec;
14172         int err, board_config;
14173
14174         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14175         if (spec == NULL)
14176                 return -ENOMEM;
14177
14178         codec->spec = spec;
14179
14180         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
14181                                                   alc861vd_models,
14182                                                   alc861vd_cfg_tbl);
14183
14184         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
14185                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
14186                         "ALC861VD, trying auto-probe from BIOS...\n");
14187                 board_config = ALC861VD_AUTO;
14188         }
14189
14190         if (board_config == ALC861VD_AUTO) {
14191                 /* automatic parse from the BIOS config */
14192                 err = alc861vd_parse_auto_config(codec);
14193                 if (err < 0) {
14194                         alc_free(codec);
14195                         return err;
14196                 } else if (!err) {
14197                         printk(KERN_INFO
14198                                "hda_codec: Cannot set up configuration "
14199                                "from BIOS.  Using base mode...\n");
14200                         board_config = ALC861VD_3ST;
14201                 }
14202         }
14203
14204         if (board_config != ALC861VD_AUTO)
14205                 setup_preset(spec, &alc861vd_presets[board_config]);
14206
14207         if (codec->vendor_id == 0x10ec0660) {
14208                 spec->stream_name_analog = "ALC660-VD Analog";
14209                 spec->stream_name_digital = "ALC660-VD Digital";
14210                 /* always turn on EAPD */
14211                 add_verb(spec, alc660vd_eapd_verbs);
14212         } else {
14213                 spec->stream_name_analog = "ALC861VD Analog";
14214                 spec->stream_name_digital = "ALC861VD Digital";
14215         }
14216
14217         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
14218         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
14219
14220         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
14221         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
14222
14223         spec->adc_nids = alc861vd_adc_nids;
14224         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14225         spec->capsrc_nids = alc861vd_capsrc_nids;
14226         spec->is_mix_capture = 1;
14227
14228         set_capture_mixer(spec);
14229
14230         spec->vmaster_nid = 0x02;
14231
14232         codec->patch_ops = alc_patch_ops;
14233
14234         if (board_config == ALC861VD_AUTO)
14235                 spec->init_hook = alc861vd_auto_init;
14236 #ifdef CONFIG_SND_HDA_POWER_SAVE
14237         if (!spec->loopback.amplist)
14238                 spec->loopback.amplist = alc861vd_loopbacks;
14239 #endif
14240
14241         return 0;
14242 }
14243
14244 /*
14245  * ALC662 support
14246  *
14247  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
14248  * configuration.  Each pin widget can choose any input DACs and a mixer.
14249  * Each ADC is connected from a mixer of all inputs.  This makes possible
14250  * 6-channel independent captures.
14251  *
14252  * In addition, an independent DAC for the multi-playback (not used in this
14253  * driver yet).
14254  */
14255 #define ALC662_DIGOUT_NID       0x06
14256 #define ALC662_DIGIN_NID        0x0a
14257
14258 static hda_nid_t alc662_dac_nids[4] = {
14259         /* front, rear, clfe, rear_surr */
14260         0x02, 0x03, 0x04
14261 };
14262
14263 static hda_nid_t alc662_adc_nids[1] = {
14264         /* ADC1-2 */
14265         0x09,
14266 };
14267
14268 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
14269
14270 /* input MUX */
14271 /* FIXME: should be a matrix-type input source selection */
14272 static struct hda_input_mux alc662_capture_source = {
14273         .num_items = 4,
14274         .items = {
14275                 { "Mic", 0x0 },
14276                 { "Front Mic", 0x1 },
14277                 { "Line", 0x2 },
14278                 { "CD", 0x4 },
14279         },
14280 };
14281
14282 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
14283         .num_items = 2,
14284         .items = {
14285                 { "Mic", 0x1 },
14286                 { "Line", 0x2 },
14287         },
14288 };
14289
14290 static struct hda_input_mux alc662_eeepc_capture_source = {
14291         .num_items = 2,
14292         .items = {
14293                 { "i-Mic", 0x1 },
14294                 { "e-Mic", 0x0 },
14295         },
14296 };
14297
14298 static struct hda_input_mux alc663_capture_source = {
14299         .num_items = 3,
14300         .items = {
14301                 { "Mic", 0x0 },
14302                 { "Front Mic", 0x1 },
14303                 { "Line", 0x2 },
14304         },
14305 };
14306
14307 static struct hda_input_mux alc663_m51va_capture_source = {
14308         .num_items = 2,
14309         .items = {
14310                 { "Ext-Mic", 0x0 },
14311                 { "D-Mic", 0x9 },
14312         },
14313 };
14314
14315 /*
14316  * 2ch mode
14317  */
14318 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
14319         { 2, NULL }
14320 };
14321
14322 /*
14323  * 2ch mode
14324  */
14325 static struct hda_verb alc662_3ST_ch2_init[] = {
14326         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
14327         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14328         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
14329         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14330         { } /* end */
14331 };
14332
14333 /*
14334  * 6ch mode
14335  */
14336 static struct hda_verb alc662_3ST_ch6_init[] = {
14337         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14338         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14339         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
14340         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14341         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14342         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
14343         { } /* end */
14344 };
14345
14346 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
14347         { 2, alc662_3ST_ch2_init },
14348         { 6, alc662_3ST_ch6_init },
14349 };
14350
14351 /*
14352  * 2ch mode
14353  */
14354 static struct hda_verb alc662_sixstack_ch6_init[] = {
14355         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14356         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14357         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14358         { } /* end */
14359 };
14360
14361 /*
14362  * 6ch mode
14363  */
14364 static struct hda_verb alc662_sixstack_ch8_init[] = {
14365         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14366         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14367         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14368         { } /* end */
14369 };
14370
14371 static struct hda_channel_mode alc662_5stack_modes[2] = {
14372         { 2, alc662_sixstack_ch6_init },
14373         { 6, alc662_sixstack_ch8_init },
14374 };
14375
14376 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14377  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14378  */
14379
14380 static struct snd_kcontrol_new alc662_base_mixer[] = {
14381         /* output mixer control */
14382         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
14383         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14384         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
14385         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14386         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14387         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14388         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14389         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14390         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14391
14392         /*Input mixer control */
14393         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
14394         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
14395         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
14396         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
14397         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
14398         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
14399         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
14400         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
14401         { } /* end */
14402 };
14403
14404 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
14405         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14406         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14407         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14408         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14409         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14410         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14411         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14412         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14413         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14414         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14415         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14416         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14417         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14418         { } /* end */
14419 };
14420
14421 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
14422         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14423         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14424         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14425         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14426         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14427         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14428         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14429         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14430         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14431         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14432         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14433         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14434         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14435         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14436         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14437         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14438         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14439         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14440         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14441         { } /* end */
14442 };
14443
14444 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
14445         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14446         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
14447         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14448         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
14449         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14450         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14451         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14452         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14453         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14454         { } /* end */
14455 };
14456
14457 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
14458         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14459
14460         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14461         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14462
14463         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
14464         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14465         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14466
14467         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
14468         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14469         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14470         { } /* end */
14471 };
14472
14473 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
14474         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14475         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14476         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14477         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
14478         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14479         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14480         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
14481         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
14482         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14483         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
14484         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14485         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14486         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14487         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14488         { } /* end */
14489 };
14490
14491 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
14492         .ops = &snd_hda_bind_vol,
14493         .values = {
14494                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
14495                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
14496                 0
14497         },
14498 };
14499
14500 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
14501         .ops = &snd_hda_bind_sw,
14502         .values = {
14503                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14504                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
14505                 0
14506         },
14507 };
14508
14509 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
14510         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14511         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
14512         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14513         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14514         { } /* end */
14515 };
14516
14517 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
14518         .ops = &snd_hda_bind_sw,
14519         .values = {
14520                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14521                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
14522                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
14523                 0
14524         },
14525 };
14526
14527 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
14528         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14529         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
14530         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14531         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14532         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14533         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14534
14535         { } /* end */
14536 };
14537
14538 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
14539         .ops = &snd_hda_bind_sw,
14540         .values = {
14541                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14542                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
14543                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
14544                 0
14545         },
14546 };
14547
14548 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
14549         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14550         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
14551         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14552         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14553         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14554         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14555         { } /* end */
14556 };
14557
14558 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
14559         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14560         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14561         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14562         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14563         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14564         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14565         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14566         { } /* end */
14567 };
14568
14569 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
14570         .ops = &snd_hda_bind_vol,
14571         .values = {
14572                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
14573                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
14574                 0
14575         },
14576 };
14577
14578 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
14579         .ops = &snd_hda_bind_sw,
14580         .values = {
14581                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14582                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
14583                 0
14584         },
14585 };
14586
14587 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
14588         HDA_BIND_VOL("Master Playback Volume",
14589                                 &alc663_asus_two_bind_master_vol),
14590         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
14591         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14592         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14593         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14594         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14595         { } /* end */
14596 };
14597
14598 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
14599         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14600         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
14601         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14602         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14603         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14604         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14605         { } /* end */
14606 };
14607
14608 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
14609         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14610         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14611         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14612         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14613         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14614
14615         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14616         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14617         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14618         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14619         { } /* end */
14620 };
14621
14622 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
14623         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14624         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14625         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14626
14627         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14628         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14629         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14630         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14631         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14632         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14633         { } /* end */
14634 };
14635
14636 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
14637         {
14638                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14639                 .name = "Channel Mode",
14640                 .info = alc_ch_mode_info,
14641                 .get = alc_ch_mode_get,
14642                 .put = alc_ch_mode_put,
14643         },
14644         { } /* end */
14645 };
14646
14647 static struct hda_verb alc662_init_verbs[] = {
14648         /* ADC: mute amp left and right */
14649         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14650         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14651         /* Front mixer: unmute input/output amp left and right (volume = 0) */
14652
14653         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14654         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14655         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14656         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14657         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14658
14659         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14660         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14661         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14662         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14663         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14664         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14665
14666         /* Front Pin: output 0 (0x0c) */
14667         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14668         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14669
14670         /* Rear Pin: output 1 (0x0d) */
14671         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14672         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14673
14674         /* CLFE Pin: output 2 (0x0e) */
14675         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14676         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14677
14678         /* Mic (rear) pin: input vref at 80% */
14679         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14680         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14681         /* Front Mic pin: input vref at 80% */
14682         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14683         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14684         /* Line In pin: input */
14685         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14686         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14687         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14688         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14689         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14690         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14691         /* CD pin widget for input */
14692         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14693
14694         /* FIXME: use matrix-type input source selection */
14695         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
14696         /* Input mixer */
14697         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14698         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14699         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14700         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14701
14702         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14703         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14704         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14705         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14706
14707         /* always trun on EAPD */
14708         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14709         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14710
14711         { }
14712 };
14713
14714 static struct hda_verb alc662_sue_init_verbs[] = {
14715         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
14716         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
14717         {}
14718 };
14719
14720 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
14721         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14722         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14723         {}
14724 };
14725
14726 /* Set Unsolicited Event*/
14727 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
14728         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14729         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14730         {}
14731 };
14732
14733 /*
14734  * generic initialization of ADC, input mixers and output mixers
14735  */
14736 static struct hda_verb alc662_auto_init_verbs[] = {
14737         /*
14738          * Unmute ADC and set the default input to mic-in
14739          */
14740         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14741         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14742
14743         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
14744          * mixer widget
14745          * Note: PASD motherboards uses the Line In 2 as the input for front
14746          * panel mic (mic 2)
14747          */
14748         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14749         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14750         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14751         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14752         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14753         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14754
14755         /*
14756          * Set up output mixers (0x0c - 0x0f)
14757          */
14758         /* set vol=0 to output mixers */
14759         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14760         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14761         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14762
14763         /* set up input amps for analog loopback */
14764         /* Amp Indices: DAC = 0, mixer = 1 */
14765         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14766         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14767         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14768         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14769         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14770         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14771
14772
14773         /* FIXME: use matrix-type input source selection */
14774         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
14775         /* Input mixer */
14776         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14777         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14778         { }
14779 };
14780
14781 /* additional verbs for ALC663 */
14782 static struct hda_verb alc663_auto_init_verbs[] = {
14783         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14784         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14785         { }
14786 };
14787
14788 static struct hda_verb alc663_m51va_init_verbs[] = {
14789         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14790         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14791         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14792         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14793         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
14794         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14795         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
14796         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14797         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14798         {}
14799 };
14800
14801 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
14802         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14803         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14804         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
14805         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14806         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14807         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14808         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14809         {}
14810 };
14811
14812 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
14813         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14814         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14815         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14816         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14817         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14818         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14819         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14820         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14821         {}
14822 };
14823
14824 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
14825         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14826         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14827         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
14828         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14829         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14830         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14831         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14832         {}
14833 };
14834
14835 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
14836         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14837         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14838         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14839         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
14840         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14841         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14842         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
14843         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14844         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14845         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14846         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14847         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14848         {}
14849 };
14850
14851 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
14852         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14853         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14854         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14855         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
14856         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14857         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14858         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
14859         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14860         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14861         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14862         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14863         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14864         {}
14865 };
14866
14867 static struct hda_verb alc663_g71v_init_verbs[] = {
14868         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14869         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
14870         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
14871
14872         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14873         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14874         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14875
14876         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
14877         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
14878         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
14879         {}
14880 };
14881
14882 static struct hda_verb alc663_g50v_init_verbs[] = {
14883         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14884         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14885         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14886
14887         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14888         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14889         {}
14890 };
14891
14892 static struct hda_verb alc662_ecs_init_verbs[] = {
14893         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
14894         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14895         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14896         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14897         {}
14898 };
14899
14900 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
14901         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
14902         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
14903         { } /* end */
14904 };
14905
14906 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
14907 {
14908         unsigned int present;
14909         unsigned char bits;
14910
14911         present = snd_hda_codec_read(codec, 0x14, 0,
14912                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14913         bits = present ? HDA_AMP_MUTE : 0;
14914         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14915                                  HDA_AMP_MUTE, bits);
14916 }
14917
14918 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
14919 {
14920         unsigned int present;
14921         unsigned char bits;
14922
14923         present = snd_hda_codec_read(codec, 0x1b, 0,
14924                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14925         bits = present ? HDA_AMP_MUTE : 0;
14926         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14927                                  HDA_AMP_MUTE, bits);
14928         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14929                                  HDA_AMP_MUTE, bits);
14930 }
14931
14932 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
14933                                            unsigned int res)
14934 {
14935         if ((res >> 26) == ALC880_HP_EVENT)
14936                 alc662_lenovo_101e_all_automute(codec);
14937         if ((res >> 26) == ALC880_FRONT_EVENT)
14938                 alc662_lenovo_101e_ispeaker_automute(codec);
14939 }
14940
14941 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
14942 {
14943         unsigned int present;
14944
14945         present = snd_hda_codec_read(codec, 0x18, 0,
14946                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14947         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14948                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14949         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14950                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14951         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14952                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
14953         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14954                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
14955 }
14956
14957 /* unsolicited event for HP jack sensing */
14958 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
14959                                      unsigned int res)
14960 {
14961         if ((res >> 26) == ALC880_HP_EVENT)
14962                 alc262_hippo1_automute( codec );
14963
14964         if ((res >> 26) == ALC880_MIC_EVENT)
14965                 alc662_eeepc_mic_automute(codec);
14966 }
14967
14968 static void alc662_eeepc_inithook(struct hda_codec *codec)
14969 {
14970         alc262_hippo1_automute( codec );
14971         alc662_eeepc_mic_automute(codec);
14972 }
14973
14974 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
14975 {
14976         unsigned int mute;
14977         unsigned int present;
14978
14979         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
14980         present = snd_hda_codec_read(codec, 0x14, 0,
14981                                      AC_VERB_GET_PIN_SENSE, 0);
14982         present = (present & 0x80000000) != 0;
14983         if (present) {
14984                 /* mute internal speaker */
14985                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
14986                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
14987         } else {
14988                 /* unmute internal speaker if necessary */
14989                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
14990                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
14991                                         HDA_AMP_MUTE, mute);
14992         }
14993 }
14994
14995 /* unsolicited event for HP jack sensing */
14996 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
14997                                           unsigned int res)
14998 {
14999         if ((res >> 26) == ALC880_HP_EVENT)
15000                 alc662_eeepc_ep20_automute(codec);
15001 }
15002
15003 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15004 {
15005         alc662_eeepc_ep20_automute(codec);
15006 }
15007
15008 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15009 {
15010         unsigned int present;
15011         unsigned char bits;
15012
15013         present = snd_hda_codec_read(codec, 0x21, 0,
15014                         AC_VERB_GET_PIN_SENSE, 0)
15015                         & AC_PINSENSE_PRESENCE;
15016         bits = present ? HDA_AMP_MUTE : 0;
15017         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15018                                 AMP_IN_MUTE(0), bits);
15019         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15020                                 AMP_IN_MUTE(0), bits);
15021 }
15022
15023 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15024 {
15025         unsigned int present;
15026         unsigned char bits;
15027
15028         present = snd_hda_codec_read(codec, 0x21, 0,
15029                         AC_VERB_GET_PIN_SENSE, 0)
15030                         & AC_PINSENSE_PRESENCE;
15031         bits = present ? HDA_AMP_MUTE : 0;
15032         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15033                                 AMP_IN_MUTE(0), bits);
15034         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15035                                 AMP_IN_MUTE(0), bits);
15036         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15037                                 AMP_IN_MUTE(0), bits);
15038         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15039                                 AMP_IN_MUTE(0), bits);
15040 }
15041
15042 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15043 {
15044         unsigned int present;
15045         unsigned char bits;
15046
15047         present = snd_hda_codec_read(codec, 0x15, 0,
15048                         AC_VERB_GET_PIN_SENSE, 0)
15049                         & AC_PINSENSE_PRESENCE;
15050         bits = present ? HDA_AMP_MUTE : 0;
15051         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15052                                 AMP_IN_MUTE(0), bits);
15053         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15054                                 AMP_IN_MUTE(0), bits);
15055         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15056                                 AMP_IN_MUTE(0), bits);
15057         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15058                                 AMP_IN_MUTE(0), bits);
15059 }
15060
15061 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15062 {
15063         unsigned int present;
15064         unsigned char bits;
15065
15066         present = snd_hda_codec_read(codec, 0x1b, 0,
15067                         AC_VERB_GET_PIN_SENSE, 0)
15068                         & AC_PINSENSE_PRESENCE;
15069         bits = present ? 0 : PIN_OUT;
15070         snd_hda_codec_write(codec, 0x14, 0,
15071                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15072 }
15073
15074 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15075 {
15076         unsigned int present1, present2;
15077
15078         present1 = snd_hda_codec_read(codec, 0x21, 0,
15079                         AC_VERB_GET_PIN_SENSE, 0)
15080                         & AC_PINSENSE_PRESENCE;
15081         present2 = snd_hda_codec_read(codec, 0x15, 0,
15082                         AC_VERB_GET_PIN_SENSE, 0)
15083                         & AC_PINSENSE_PRESENCE;
15084
15085         if (present1 || present2) {
15086                 snd_hda_codec_write_cache(codec, 0x14, 0,
15087                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15088         } else {
15089                 snd_hda_codec_write_cache(codec, 0x14, 0,
15090                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15091         }
15092 }
15093
15094 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15095 {
15096         unsigned int present1, present2;
15097
15098         present1 = snd_hda_codec_read(codec, 0x1b, 0,
15099                                 AC_VERB_GET_PIN_SENSE, 0)
15100                                 & AC_PINSENSE_PRESENCE;
15101         present2 = snd_hda_codec_read(codec, 0x15, 0,
15102                                 AC_VERB_GET_PIN_SENSE, 0)
15103                                 & AC_PINSENSE_PRESENCE;
15104
15105         if (present1 || present2) {
15106                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15107                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15108                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15109                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15110         } else {
15111                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15112                                 AMP_IN_MUTE(0), 0);
15113                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15114                                 AMP_IN_MUTE(0), 0);
15115         }
15116 }
15117
15118 static void alc663_m51va_mic_automute(struct hda_codec *codec)
15119 {
15120         unsigned int present;
15121
15122         present = snd_hda_codec_read(codec, 0x18, 0,
15123                         AC_VERB_GET_PIN_SENSE, 0)
15124                         & AC_PINSENSE_PRESENCE;
15125         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15126                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15127         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15128                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15129         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15130                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15131         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15132                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15133 }
15134
15135 static void alc663_m51va_unsol_event(struct hda_codec *codec,
15136                                            unsigned int res)
15137 {
15138         switch (res >> 26) {
15139         case ALC880_HP_EVENT:
15140                 alc663_m51va_speaker_automute(codec);
15141                 break;
15142         case ALC880_MIC_EVENT:
15143                 alc663_m51va_mic_automute(codec);
15144                 break;
15145         }
15146 }
15147
15148 static void alc663_m51va_inithook(struct hda_codec *codec)
15149 {
15150         alc663_m51va_speaker_automute(codec);
15151         alc663_m51va_mic_automute(codec);
15152 }
15153
15154 /* ***************** Mode1 ******************************/
15155 static void alc663_mode1_unsol_event(struct hda_codec *codec,
15156                                            unsigned int res)
15157 {
15158         switch (res >> 26) {
15159         case ALC880_HP_EVENT:
15160                 alc663_m51va_speaker_automute(codec);
15161                 break;
15162         case ALC880_MIC_EVENT:
15163                 alc662_eeepc_mic_automute(codec);
15164                 break;
15165         }
15166 }
15167
15168 static void alc663_mode1_inithook(struct hda_codec *codec)
15169 {
15170         alc663_m51va_speaker_automute(codec);
15171         alc662_eeepc_mic_automute(codec);
15172 }
15173 /* ***************** Mode2 ******************************/
15174 static void alc662_mode2_unsol_event(struct hda_codec *codec,
15175                                            unsigned int res)
15176 {
15177         switch (res >> 26) {
15178         case ALC880_HP_EVENT:
15179                 alc662_f5z_speaker_automute(codec);
15180                 break;
15181         case ALC880_MIC_EVENT:
15182                 alc662_eeepc_mic_automute(codec);
15183                 break;
15184         }
15185 }
15186
15187 static void alc662_mode2_inithook(struct hda_codec *codec)
15188 {
15189         alc662_f5z_speaker_automute(codec);
15190         alc662_eeepc_mic_automute(codec);
15191 }
15192 /* ***************** Mode3 ******************************/
15193 static void alc663_mode3_unsol_event(struct hda_codec *codec,
15194                                            unsigned int res)
15195 {
15196         switch (res >> 26) {
15197         case ALC880_HP_EVENT:
15198                 alc663_two_hp_m1_speaker_automute(codec);
15199                 break;
15200         case ALC880_MIC_EVENT:
15201                 alc662_eeepc_mic_automute(codec);
15202                 break;
15203         }
15204 }
15205
15206 static void alc663_mode3_inithook(struct hda_codec *codec)
15207 {
15208         alc663_two_hp_m1_speaker_automute(codec);
15209         alc662_eeepc_mic_automute(codec);
15210 }
15211 /* ***************** Mode4 ******************************/
15212 static void alc663_mode4_unsol_event(struct hda_codec *codec,
15213                                            unsigned int res)
15214 {
15215         switch (res >> 26) {
15216         case ALC880_HP_EVENT:
15217                 alc663_21jd_two_speaker_automute(codec);
15218                 break;
15219         case ALC880_MIC_EVENT:
15220                 alc662_eeepc_mic_automute(codec);
15221                 break;
15222         }
15223 }
15224
15225 static void alc663_mode4_inithook(struct hda_codec *codec)
15226 {
15227         alc663_21jd_two_speaker_automute(codec);
15228         alc662_eeepc_mic_automute(codec);
15229 }
15230 /* ***************** Mode5 ******************************/
15231 static void alc663_mode5_unsol_event(struct hda_codec *codec,
15232                                            unsigned int res)
15233 {
15234         switch (res >> 26) {
15235         case ALC880_HP_EVENT:
15236                 alc663_15jd_two_speaker_automute(codec);
15237                 break;
15238         case ALC880_MIC_EVENT:
15239                 alc662_eeepc_mic_automute(codec);
15240                 break;
15241         }
15242 }
15243
15244 static void alc663_mode5_inithook(struct hda_codec *codec)
15245 {
15246         alc663_15jd_two_speaker_automute(codec);
15247         alc662_eeepc_mic_automute(codec);
15248 }
15249 /* ***************** Mode6 ******************************/
15250 static void alc663_mode6_unsol_event(struct hda_codec *codec,
15251                                            unsigned int res)
15252 {
15253         switch (res >> 26) {
15254         case ALC880_HP_EVENT:
15255                 alc663_two_hp_m2_speaker_automute(codec);
15256                 break;
15257         case ALC880_MIC_EVENT:
15258                 alc662_eeepc_mic_automute(codec);
15259                 break;
15260         }
15261 }
15262
15263 static void alc663_mode6_inithook(struct hda_codec *codec)
15264 {
15265         alc663_two_hp_m2_speaker_automute(codec);
15266         alc662_eeepc_mic_automute(codec);
15267 }
15268
15269 static void alc663_g71v_hp_automute(struct hda_codec *codec)
15270 {
15271         unsigned int present;
15272         unsigned char bits;
15273
15274         present = snd_hda_codec_read(codec, 0x21, 0,
15275                                      AC_VERB_GET_PIN_SENSE, 0)
15276                 & AC_PINSENSE_PRESENCE;
15277         bits = present ? HDA_AMP_MUTE : 0;
15278         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15279                                  HDA_AMP_MUTE, bits);
15280         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15281                                  HDA_AMP_MUTE, bits);
15282 }
15283
15284 static void alc663_g71v_front_automute(struct hda_codec *codec)
15285 {
15286         unsigned int present;
15287         unsigned char bits;
15288
15289         present = snd_hda_codec_read(codec, 0x15, 0,
15290                                      AC_VERB_GET_PIN_SENSE, 0)
15291                 & AC_PINSENSE_PRESENCE;
15292         bits = present ? HDA_AMP_MUTE : 0;
15293         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15294                                  HDA_AMP_MUTE, bits);
15295 }
15296
15297 static void alc663_g71v_unsol_event(struct hda_codec *codec,
15298                                            unsigned int res)
15299 {
15300         switch (res >> 26) {
15301         case ALC880_HP_EVENT:
15302                 alc663_g71v_hp_automute(codec);
15303                 break;
15304         case ALC880_FRONT_EVENT:
15305                 alc663_g71v_front_automute(codec);
15306                 break;
15307         case ALC880_MIC_EVENT:
15308                 alc662_eeepc_mic_automute(codec);
15309                 break;
15310         }
15311 }
15312
15313 static void alc663_g71v_inithook(struct hda_codec *codec)
15314 {
15315         alc663_g71v_front_automute(codec);
15316         alc663_g71v_hp_automute(codec);
15317         alc662_eeepc_mic_automute(codec);
15318 }
15319
15320 static void alc663_g50v_unsol_event(struct hda_codec *codec,
15321                                            unsigned int res)
15322 {
15323         switch (res >> 26) {
15324         case ALC880_HP_EVENT:
15325                 alc663_m51va_speaker_automute(codec);
15326                 break;
15327         case ALC880_MIC_EVENT:
15328                 alc662_eeepc_mic_automute(codec);
15329                 break;
15330         }
15331 }
15332
15333 static void alc663_g50v_inithook(struct hda_codec *codec)
15334 {
15335         alc663_m51va_speaker_automute(codec);
15336         alc662_eeepc_mic_automute(codec);
15337 }
15338
15339 /* bind hp and internal speaker mute (with plug check) */
15340 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15341                                      struct snd_ctl_elem_value *ucontrol)
15342 {
15343         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15344         long *valp = ucontrol->value.integer.value;
15345         int change;
15346
15347         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15348                                           HDA_AMP_MUTE,
15349                                           valp[0] ? 0 : HDA_AMP_MUTE);
15350         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15351                                            HDA_AMP_MUTE,
15352                                            valp[1] ? 0 : HDA_AMP_MUTE);
15353         if (change)
15354                 alc262_hippo1_automute(codec);
15355         return change;
15356 }
15357
15358 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
15359         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15360         {
15361                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15362                 .name = "Master Playback Switch",
15363                 .info = snd_hda_mixer_amp_switch_info,
15364                 .get = snd_hda_mixer_amp_switch_get,
15365                 .put = alc662_ecs_master_sw_put,
15366                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15367         },
15368
15369         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
15370         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
15371         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
15372
15373         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15374         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15375         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15376         { } /* end */
15377 };
15378
15379 #ifdef CONFIG_SND_HDA_POWER_SAVE
15380 #define alc662_loopbacks        alc880_loopbacks
15381 #endif
15382
15383
15384 /* pcm configuration: identiacal with ALC880 */
15385 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
15386 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
15387 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
15388 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
15389
15390 /*
15391  * configuration and preset
15392  */
15393 static const char *alc662_models[ALC662_MODEL_LAST] = {
15394         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
15395         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
15396         [ALC662_3ST_6ch]        = "3stack-6ch",
15397         [ALC662_5ST_DIG]        = "6stack-dig",
15398         [ALC662_LENOVO_101E]    = "lenovo-101e",
15399         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
15400         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
15401         [ALC662_ECS] = "ecs",
15402         [ALC663_ASUS_M51VA] = "m51va",
15403         [ALC663_ASUS_G71V] = "g71v",
15404         [ALC663_ASUS_H13] = "h13",
15405         [ALC663_ASUS_G50V] = "g50v",
15406         [ALC663_ASUS_MODE1] = "asus-mode1",
15407         [ALC662_ASUS_MODE2] = "asus-mode2",
15408         [ALC663_ASUS_MODE3] = "asus-mode3",
15409         [ALC663_ASUS_MODE4] = "asus-mode4",
15410         [ALC663_ASUS_MODE5] = "asus-mode5",
15411         [ALC663_ASUS_MODE6] = "asus-mode6",
15412         [ALC662_AUTO]           = "auto",
15413 };
15414
15415 static struct snd_pci_quirk alc662_cfg_tbl[] = {
15416         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
15417         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
15418         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
15419         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
15420         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
15421         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
15422         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
15423         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
15424         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
15425         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
15426         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
15427         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
15428         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
15429         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
15430         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
15431         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
15432         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
15433         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
15434         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
15435         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
15436         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
15437         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
15438         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
15439         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
15440         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
15441         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
15442         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
15443         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
15444         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
15445         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
15446         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
15447         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
15448         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
15449         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
15450         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
15451         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
15452         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
15453         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
15454                       ALC662_3ST_6ch_DIG),
15455         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
15456         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
15457         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
15458         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
15459                       ALC662_3ST_6ch_DIG),
15460         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
15461         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
15462                                         ALC662_3ST_6ch_DIG),
15463         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
15464         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
15465         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
15466         {}
15467 };
15468
15469 static struct alc_config_preset alc662_presets[] = {
15470         [ALC662_3ST_2ch_DIG] = {
15471                 .mixers = { alc662_3ST_2ch_mixer },
15472                 .init_verbs = { alc662_init_verbs },
15473                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15474                 .dac_nids = alc662_dac_nids,
15475                 .dig_out_nid = ALC662_DIGOUT_NID,
15476                 .dig_in_nid = ALC662_DIGIN_NID,
15477                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15478                 .channel_mode = alc662_3ST_2ch_modes,
15479                 .input_mux = &alc662_capture_source,
15480         },
15481         [ALC662_3ST_6ch_DIG] = {
15482                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
15483                 .init_verbs = { alc662_init_verbs },
15484                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15485                 .dac_nids = alc662_dac_nids,
15486                 .dig_out_nid = ALC662_DIGOUT_NID,
15487                 .dig_in_nid = ALC662_DIGIN_NID,
15488                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15489                 .channel_mode = alc662_3ST_6ch_modes,
15490                 .need_dac_fix = 1,
15491                 .input_mux = &alc662_capture_source,
15492         },
15493         [ALC662_3ST_6ch] = {
15494                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
15495                 .init_verbs = { alc662_init_verbs },
15496                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15497                 .dac_nids = alc662_dac_nids,
15498                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15499                 .channel_mode = alc662_3ST_6ch_modes,
15500                 .need_dac_fix = 1,
15501                 .input_mux = &alc662_capture_source,
15502         },
15503         [ALC662_5ST_DIG] = {
15504                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
15505                 .init_verbs = { alc662_init_verbs },
15506                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15507                 .dac_nids = alc662_dac_nids,
15508                 .dig_out_nid = ALC662_DIGOUT_NID,
15509                 .dig_in_nid = ALC662_DIGIN_NID,
15510                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
15511                 .channel_mode = alc662_5stack_modes,
15512                 .input_mux = &alc662_capture_source,
15513         },
15514         [ALC662_LENOVO_101E] = {
15515                 .mixers = { alc662_lenovo_101e_mixer },
15516                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
15517                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15518                 .dac_nids = alc662_dac_nids,
15519                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15520                 .channel_mode = alc662_3ST_2ch_modes,
15521                 .input_mux = &alc662_lenovo_101e_capture_source,
15522                 .unsol_event = alc662_lenovo_101e_unsol_event,
15523                 .init_hook = alc662_lenovo_101e_all_automute,
15524         },
15525         [ALC662_ASUS_EEEPC_P701] = {
15526                 .mixers = { alc662_eeepc_p701_mixer },
15527                 .init_verbs = { alc662_init_verbs,
15528                                 alc662_eeepc_sue_init_verbs },
15529                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15530                 .dac_nids = alc662_dac_nids,
15531                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15532                 .channel_mode = alc662_3ST_2ch_modes,
15533                 .input_mux = &alc662_eeepc_capture_source,
15534                 .unsol_event = alc662_eeepc_unsol_event,
15535                 .init_hook = alc662_eeepc_inithook,
15536         },
15537         [ALC662_ASUS_EEEPC_EP20] = {
15538                 .mixers = { alc662_eeepc_ep20_mixer,
15539                             alc662_chmode_mixer },
15540                 .init_verbs = { alc662_init_verbs,
15541                                 alc662_eeepc_ep20_sue_init_verbs },
15542                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15543                 .dac_nids = alc662_dac_nids,
15544                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15545                 .channel_mode = alc662_3ST_6ch_modes,
15546                 .input_mux = &alc662_lenovo_101e_capture_source,
15547                 .unsol_event = alc662_eeepc_ep20_unsol_event,
15548                 .init_hook = alc662_eeepc_ep20_inithook,
15549         },
15550         [ALC662_ECS] = {
15551                 .mixers = { alc662_ecs_mixer },
15552                 .init_verbs = { alc662_init_verbs,
15553                                 alc662_ecs_init_verbs },
15554                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15555                 .dac_nids = alc662_dac_nids,
15556                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15557                 .channel_mode = alc662_3ST_2ch_modes,
15558                 .input_mux = &alc662_eeepc_capture_source,
15559                 .unsol_event = alc662_eeepc_unsol_event,
15560                 .init_hook = alc662_eeepc_inithook,
15561         },
15562         [ALC663_ASUS_M51VA] = {
15563                 .mixers = { alc663_m51va_mixer },
15564                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
15565                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15566                 .dac_nids = alc662_dac_nids,
15567                 .dig_out_nid = ALC662_DIGOUT_NID,
15568                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15569                 .channel_mode = alc662_3ST_2ch_modes,
15570                 .input_mux = &alc663_m51va_capture_source,
15571                 .unsol_event = alc663_m51va_unsol_event,
15572                 .init_hook = alc663_m51va_inithook,
15573         },
15574         [ALC663_ASUS_G71V] = {
15575                 .mixers = { alc663_g71v_mixer },
15576                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
15577                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15578                 .dac_nids = alc662_dac_nids,
15579                 .dig_out_nid = ALC662_DIGOUT_NID,
15580                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15581                 .channel_mode = alc662_3ST_2ch_modes,
15582                 .input_mux = &alc662_eeepc_capture_source,
15583                 .unsol_event = alc663_g71v_unsol_event,
15584                 .init_hook = alc663_g71v_inithook,
15585         },
15586         [ALC663_ASUS_H13] = {
15587                 .mixers = { alc663_m51va_mixer },
15588                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
15589                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15590                 .dac_nids = alc662_dac_nids,
15591                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15592                 .channel_mode = alc662_3ST_2ch_modes,
15593                 .input_mux = &alc663_m51va_capture_source,
15594                 .unsol_event = alc663_m51va_unsol_event,
15595                 .init_hook = alc663_m51va_inithook,
15596         },
15597         [ALC663_ASUS_G50V] = {
15598                 .mixers = { alc663_g50v_mixer },
15599                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
15600                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15601                 .dac_nids = alc662_dac_nids,
15602                 .dig_out_nid = ALC662_DIGOUT_NID,
15603                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15604                 .channel_mode = alc662_3ST_6ch_modes,
15605                 .input_mux = &alc663_capture_source,
15606                 .unsol_event = alc663_g50v_unsol_event,
15607                 .init_hook = alc663_g50v_inithook,
15608         },
15609         [ALC663_ASUS_MODE1] = {
15610                 .mixers = { alc663_m51va_mixer },
15611                 .cap_mixer = alc662_auto_capture_mixer,
15612                 .init_verbs = { alc662_init_verbs,
15613                                 alc663_21jd_amic_init_verbs },
15614                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15615                 .hp_nid = 0x03,
15616                 .dac_nids = alc662_dac_nids,
15617                 .dig_out_nid = ALC662_DIGOUT_NID,
15618                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15619                 .channel_mode = alc662_3ST_2ch_modes,
15620                 .input_mux = &alc662_eeepc_capture_source,
15621                 .unsol_event = alc663_mode1_unsol_event,
15622                 .init_hook = alc663_mode1_inithook,
15623         },
15624         [ALC662_ASUS_MODE2] = {
15625                 .mixers = { alc662_1bjd_mixer },
15626                 .cap_mixer = alc662_auto_capture_mixer,
15627                 .init_verbs = { alc662_init_verbs,
15628                                 alc662_1bjd_amic_init_verbs },
15629                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15630                 .dac_nids = alc662_dac_nids,
15631                 .dig_out_nid = ALC662_DIGOUT_NID,
15632                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15633                 .channel_mode = alc662_3ST_2ch_modes,
15634                 .input_mux = &alc662_eeepc_capture_source,
15635                 .unsol_event = alc662_mode2_unsol_event,
15636                 .init_hook = alc662_mode2_inithook,
15637         },
15638         [ALC663_ASUS_MODE3] = {
15639                 .mixers = { alc663_two_hp_m1_mixer },
15640                 .cap_mixer = alc662_auto_capture_mixer,
15641                 .init_verbs = { alc662_init_verbs,
15642                                 alc663_two_hp_amic_m1_init_verbs },
15643                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15644                 .hp_nid = 0x03,
15645                 .dac_nids = alc662_dac_nids,
15646                 .dig_out_nid = ALC662_DIGOUT_NID,
15647                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15648                 .channel_mode = alc662_3ST_2ch_modes,
15649                 .input_mux = &alc662_eeepc_capture_source,
15650                 .unsol_event = alc663_mode3_unsol_event,
15651                 .init_hook = alc663_mode3_inithook,
15652         },
15653         [ALC663_ASUS_MODE4] = {
15654                 .mixers = { alc663_asus_21jd_clfe_mixer },
15655                 .cap_mixer = alc662_auto_capture_mixer,
15656                 .init_verbs = { alc662_init_verbs,
15657                                 alc663_21jd_amic_init_verbs},
15658                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15659                 .hp_nid = 0x03,
15660                 .dac_nids = alc662_dac_nids,
15661                 .dig_out_nid = ALC662_DIGOUT_NID,
15662                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15663                 .channel_mode = alc662_3ST_2ch_modes,
15664                 .input_mux = &alc662_eeepc_capture_source,
15665                 .unsol_event = alc663_mode4_unsol_event,
15666                 .init_hook = alc663_mode4_inithook,
15667         },
15668         [ALC663_ASUS_MODE5] = {
15669                 .mixers = { alc663_asus_15jd_clfe_mixer },
15670                 .cap_mixer = alc662_auto_capture_mixer,
15671                 .init_verbs = { alc662_init_verbs,
15672                                 alc663_15jd_amic_init_verbs },
15673                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15674                 .hp_nid = 0x03,
15675                 .dac_nids = alc662_dac_nids,
15676                 .dig_out_nid = ALC662_DIGOUT_NID,
15677                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15678                 .channel_mode = alc662_3ST_2ch_modes,
15679                 .input_mux = &alc662_eeepc_capture_source,
15680                 .unsol_event = alc663_mode5_unsol_event,
15681                 .init_hook = alc663_mode5_inithook,
15682         },
15683         [ALC663_ASUS_MODE6] = {
15684                 .mixers = { alc663_two_hp_m2_mixer },
15685                 .cap_mixer = alc662_auto_capture_mixer,
15686                 .init_verbs = { alc662_init_verbs,
15687                                 alc663_two_hp_amic_m2_init_verbs },
15688                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15689                 .hp_nid = 0x03,
15690                 .dac_nids = alc662_dac_nids,
15691                 .dig_out_nid = ALC662_DIGOUT_NID,
15692                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15693                 .channel_mode = alc662_3ST_2ch_modes,
15694                 .input_mux = &alc662_eeepc_capture_source,
15695                 .unsol_event = alc663_mode6_unsol_event,
15696                 .init_hook = alc663_mode6_inithook,
15697         },
15698 };
15699
15700
15701 /*
15702  * BIOS auto configuration
15703  */
15704
15705 /* add playback controls from the parsed DAC table */
15706 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
15707                                              const struct auto_pin_cfg *cfg)
15708 {
15709         char name[32];
15710         static const char *chname[4] = {
15711                 "Front", "Surround", NULL /*CLFE*/, "Side"
15712         };
15713         hda_nid_t nid;
15714         int i, err;
15715
15716         for (i = 0; i < cfg->line_outs; i++) {
15717                 if (!spec->multiout.dac_nids[i])
15718                         continue;
15719                 nid = alc880_idx_to_dac(i);
15720                 if (i == 2) {
15721                         /* Center/LFE */
15722                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
15723                                           "Center Playback Volume",
15724                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
15725                                                               HDA_OUTPUT));
15726                         if (err < 0)
15727                                 return err;
15728                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
15729                                           "LFE Playback Volume",
15730                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
15731                                                               HDA_OUTPUT));
15732                         if (err < 0)
15733                                 return err;
15734                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
15735                                           "Center Playback Switch",
15736                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
15737                                                               HDA_INPUT));
15738                         if (err < 0)
15739                                 return err;
15740                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
15741                                           "LFE Playback Switch",
15742                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
15743                                                               HDA_INPUT));
15744                         if (err < 0)
15745                                 return err;
15746                 } else {
15747                         sprintf(name, "%s Playback Volume", chname[i]);
15748                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15749                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
15750                                                               HDA_OUTPUT));
15751                         if (err < 0)
15752                                 return err;
15753                         sprintf(name, "%s Playback Switch", chname[i]);
15754                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
15755                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
15756                                                     3, 0, HDA_INPUT));
15757                         if (err < 0)
15758                                 return err;
15759                 }
15760         }
15761         return 0;
15762 }
15763
15764 /* add playback controls for speaker and HP outputs */
15765 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
15766                                         const char *pfx)
15767 {
15768         hda_nid_t nid;
15769         int err;
15770         char name[32];
15771
15772         if (!pin)
15773                 return 0;
15774
15775         if (pin == 0x17) {
15776                 /* ALC663 has a mono output pin on 0x17 */
15777                 sprintf(name, "%s Playback Switch", pfx);
15778                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
15779                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
15780                 return err;
15781         }
15782
15783         if (alc880_is_fixed_pin(pin)) {
15784                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
15785                 /* printk("DAC nid=%x\n",nid); */
15786                 /* specify the DAC as the extra output */
15787                 if (!spec->multiout.hp_nid)
15788                         spec->multiout.hp_nid = nid;
15789                 else
15790                         spec->multiout.extra_out_nid[0] = nid;
15791                 /* control HP volume/switch on the output mixer amp */
15792                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
15793                 sprintf(name, "%s Playback Volume", pfx);
15794                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15795                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
15796                 if (err < 0)
15797                         return err;
15798                 sprintf(name, "%s Playback Switch", pfx);
15799                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15800                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
15801                 if (err < 0)
15802                         return err;
15803         } else if (alc880_is_multi_pin(pin)) {
15804                 /* set manual connection */
15805                 /* we have only a switch on HP-out PIN */
15806                 sprintf(name, "%s Playback Switch", pfx);
15807                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
15808                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15809                 if (err < 0)
15810                         return err;
15811         }
15812         return 0;
15813 }
15814
15815 /* create playback/capture controls for input pins */
15816 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
15817                                                 const struct auto_pin_cfg *cfg)
15818 {
15819         struct hda_input_mux *imux = &spec->private_imux;
15820         int i, err, idx;
15821
15822         for (i = 0; i < AUTO_PIN_LAST; i++) {
15823                 if (alc880_is_input_pin(cfg->input_pins[i])) {
15824                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
15825                         err = new_analog_input(spec, cfg->input_pins[i],
15826                                                auto_pin_cfg_labels[i],
15827                                                idx, 0x0b);
15828                         if (err < 0)
15829                                 return err;
15830                         imux->items[imux->num_items].label =
15831                                 auto_pin_cfg_labels[i];
15832                         imux->items[imux->num_items].index =
15833                                 alc880_input_pin_idx(cfg->input_pins[i]);
15834                         imux->num_items++;
15835                 }
15836         }
15837         return 0;
15838 }
15839
15840 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
15841                                               hda_nid_t nid, int pin_type,
15842                                               int dac_idx)
15843 {
15844         alc_set_pin_output(codec, nid, pin_type);
15845         /* need the manual connection? */
15846         if (alc880_is_multi_pin(nid)) {
15847                 struct alc_spec *spec = codec->spec;
15848                 int idx = alc880_multi_pin_idx(nid);
15849                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
15850                                     AC_VERB_SET_CONNECT_SEL,
15851                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
15852         }
15853 }
15854
15855 static void alc662_auto_init_multi_out(struct hda_codec *codec)
15856 {
15857         struct alc_spec *spec = codec->spec;
15858         int i;
15859
15860         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
15861         for (i = 0; i <= HDA_SIDE; i++) {
15862                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
15863                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
15864                 if (nid)
15865                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
15866                                                           i);
15867         }
15868 }
15869
15870 static void alc662_auto_init_hp_out(struct hda_codec *codec)
15871 {
15872         struct alc_spec *spec = codec->spec;
15873         hda_nid_t pin;
15874
15875         pin = spec->autocfg.hp_pins[0];
15876         if (pin) /* connect to front */
15877                 /* use dac 0 */
15878                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
15879         pin = spec->autocfg.speaker_pins[0];
15880         if (pin)
15881                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
15882 }
15883
15884 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
15885 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
15886
15887 static void alc662_auto_init_analog_input(struct hda_codec *codec)
15888 {
15889         struct alc_spec *spec = codec->spec;
15890         int i;
15891
15892         for (i = 0; i < AUTO_PIN_LAST; i++) {
15893                 hda_nid_t nid = spec->autocfg.input_pins[i];
15894                 if (alc662_is_input_pin(nid)) {
15895                         snd_hda_codec_write(codec, nid, 0,
15896                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
15897                                             (i <= AUTO_PIN_FRONT_MIC ?
15898                                              PIN_VREF80 : PIN_IN));
15899                         if (nid != ALC662_PIN_CD_NID)
15900                                 snd_hda_codec_write(codec, nid, 0,
15901                                                     AC_VERB_SET_AMP_GAIN_MUTE,
15902                                                     AMP_OUT_MUTE);
15903                 }
15904         }
15905 }
15906
15907 #define alc662_auto_init_input_src      alc882_auto_init_input_src
15908
15909 static int alc662_parse_auto_config(struct hda_codec *codec)
15910 {
15911         struct alc_spec *spec = codec->spec;
15912         int err;
15913         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
15914
15915         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
15916                                            alc662_ignore);
15917         if (err < 0)
15918                 return err;
15919         if (!spec->autocfg.line_outs)
15920                 return 0; /* can't find valid BIOS pin config */
15921
15922         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
15923         if (err < 0)
15924                 return err;
15925         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
15926         if (err < 0)
15927                 return err;
15928         err = alc662_auto_create_extra_out(spec,
15929                                            spec->autocfg.speaker_pins[0],
15930                                            "Speaker");
15931         if (err < 0)
15932                 return err;
15933         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
15934                                            "Headphone");
15935         if (err < 0)
15936                 return err;
15937         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
15938         if (err < 0)
15939                 return err;
15940
15941         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
15942
15943         if (spec->autocfg.dig_out_pin)
15944                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
15945
15946         if (spec->kctls.list)
15947                 add_mixer(spec, spec->kctls.list);
15948
15949         spec->num_mux_defs = 1;
15950         spec->input_mux = &spec->private_imux;
15951
15952         add_verb(spec, alc662_auto_init_verbs);
15953         if (codec->vendor_id == 0x10ec0663)
15954                 add_verb(spec, alc663_auto_init_verbs);
15955
15956         err = alc_auto_add_mic_boost(codec);
15957         if (err < 0)
15958                 return err;
15959
15960         store_pin_configs(codec);
15961         return 1;
15962 }
15963
15964 /* additional initialization for auto-configuration model */
15965 static void alc662_auto_init(struct hda_codec *codec)
15966 {
15967         struct alc_spec *spec = codec->spec;
15968         alc662_auto_init_multi_out(codec);
15969         alc662_auto_init_hp_out(codec);
15970         alc662_auto_init_analog_input(codec);
15971         alc662_auto_init_input_src(codec);
15972         if (spec->unsol_event)
15973                 alc_inithook(codec);
15974 }
15975
15976 static int patch_alc662(struct hda_codec *codec)
15977 {
15978         struct alc_spec *spec;
15979         int err, board_config;
15980
15981         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15982         if (!spec)
15983                 return -ENOMEM;
15984
15985         codec->spec = spec;
15986
15987         alc_fix_pll_init(codec, 0x20, 0x04, 15);
15988
15989         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
15990                                                   alc662_models,
15991                                                   alc662_cfg_tbl);
15992         if (board_config < 0) {
15993                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
15994                        "trying auto-probe from BIOS...\n");
15995                 board_config = ALC662_AUTO;
15996         }
15997
15998         if (board_config == ALC662_AUTO) {
15999                 /* automatic parse from the BIOS config */
16000                 err = alc662_parse_auto_config(codec);
16001                 if (err < 0) {
16002                         alc_free(codec);
16003                         return err;
16004                 } else if (!err) {
16005                         printk(KERN_INFO
16006                                "hda_codec: Cannot set up configuration "
16007                                "from BIOS.  Using base mode...\n");
16008                         board_config = ALC662_3ST_2ch_DIG;
16009                 }
16010         }
16011
16012         if (board_config != ALC662_AUTO)
16013                 setup_preset(spec, &alc662_presets[board_config]);
16014
16015         if (codec->vendor_id == 0x10ec0663) {
16016                 spec->stream_name_analog = "ALC663 Analog";
16017                 spec->stream_name_digital = "ALC663 Digital";
16018         } else if (codec->vendor_id == 0x10ec0272) {
16019                 spec->stream_name_analog = "ALC272 Analog";
16020                 spec->stream_name_digital = "ALC272 Digital";
16021         } else {
16022                 spec->stream_name_analog = "ALC662 Analog";
16023                 spec->stream_name_digital = "ALC662 Digital";
16024         }
16025
16026         spec->stream_analog_playback = &alc662_pcm_analog_playback;
16027         spec->stream_analog_capture = &alc662_pcm_analog_capture;
16028
16029         spec->stream_digital_playback = &alc662_pcm_digital_playback;
16030         spec->stream_digital_capture = &alc662_pcm_digital_capture;
16031
16032         spec->adc_nids = alc662_adc_nids;
16033         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16034         spec->capsrc_nids = alc662_capsrc_nids;
16035         spec->is_mix_capture = 1;
16036
16037         if (!spec->cap_mixer)
16038                 set_capture_mixer(spec);
16039
16040         spec->vmaster_nid = 0x02;
16041
16042         codec->patch_ops = alc_patch_ops;
16043         if (board_config == ALC662_AUTO)
16044                 spec->init_hook = alc662_auto_init;
16045 #ifdef CONFIG_SND_HDA_POWER_SAVE
16046         if (!spec->loopback.amplist)
16047                 spec->loopback.amplist = alc662_loopbacks;
16048 #endif
16049
16050         return 0;
16051 }
16052
16053 /*
16054  * patch entries
16055  */
16056 struct hda_codec_preset snd_hda_preset_realtek[] = {
16057         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16058         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16059         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
16060         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
16061         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
16062         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
16063         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
16064           .patch = patch_alc861 },
16065         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
16066         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
16067         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
16068         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
16069           .patch = patch_alc883 },
16070         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
16071           .patch = patch_alc662 },
16072         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
16073         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
16074         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
16075         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16076         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
16077           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16078         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
16079           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16080         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
16081         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
16082         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
16083         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
16084           .patch = patch_alc883 },
16085         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16086         {} /* terminator */
16087 };