]> git.karo-electronics.de Git - karo-tx-linux.git/blob - sound/pci/hda/patch_realtek.c
ALSA: hda - Add model for Toshiba L305 laptop
[karo-tx-linux.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
243         const struct hda_verb *init_verbs[5];   /* initialization verbs
244                                                  * don't forget NULL
245                                                  * termination!
246                                                  */
247         unsigned int num_init_verbs;
248
249         char *stream_name_analog;       /* analog PCM stream */
250         struct hda_pcm_stream *stream_analog_playback;
251         struct hda_pcm_stream *stream_analog_capture;
252         struct hda_pcm_stream *stream_analog_alt_playback;
253         struct hda_pcm_stream *stream_analog_alt_capture;
254
255         char *stream_name_digital;      /* digital PCM stream */
256         struct hda_pcm_stream *stream_digital_playback;
257         struct hda_pcm_stream *stream_digital_capture;
258
259         /* playback */
260         struct hda_multi_out multiout;  /* playback set-up
261                                          * max_channels, dacs must be set
262                                          * dig_out_nid and hp_nid are optional
263                                          */
264         hda_nid_t alt_dac_nid;
265
266         /* capture */
267         unsigned int num_adc_nids;
268         hda_nid_t *adc_nids;
269         hda_nid_t *capsrc_nids;
270         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
271
272         /* capture source */
273         unsigned int num_mux_defs;
274         const struct hda_input_mux *input_mux;
275         unsigned int cur_mux[3];
276
277         /* channel model */
278         const struct hda_channel_mode *channel_mode;
279         int num_channel_mode;
280         int need_dac_fix;
281
282         /* PCM information */
283         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
284
285         /* dynamic controls, init_verbs and input_mux */
286         struct auto_pin_cfg autocfg;
287         unsigned int num_kctl_alloc, num_kctl_used;
288         struct snd_kcontrol_new *kctl_alloc;
289         struct hda_input_mux private_imux;
290         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
291
292         /* hooks */
293         void (*init_hook)(struct hda_codec *codec);
294         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
295
296         /* for pin sensing */
297         unsigned int sense_updated: 1;
298         unsigned int jack_present: 1;
299         unsigned int master_sw: 1;
300
301         /* for virtual master */
302         hda_nid_t vmaster_nid;
303 #ifdef CONFIG_SND_HDA_POWER_SAVE
304         struct hda_loopback_check loopback;
305 #endif
306
307         /* for PLL fix */
308         hda_nid_t pll_nid;
309         unsigned int pll_coef_idx, pll_coef_bit;
310 };
311
312 /*
313  * configuration template - to be copied to the spec instance
314  */
315 struct alc_config_preset {
316         struct snd_kcontrol_new *mixers[5]; /* should be identical size
317                                              * with spec
318                                              */
319         const struct hda_verb *init_verbs[5];
320         unsigned int num_dacs;
321         hda_nid_t *dac_nids;
322         hda_nid_t dig_out_nid;          /* optional */
323         hda_nid_t hp_nid;               /* optional */
324         unsigned int num_adc_nids;
325         hda_nid_t *adc_nids;
326         hda_nid_t *capsrc_nids;
327         hda_nid_t dig_in_nid;
328         unsigned int num_channel_mode;
329         const struct hda_channel_mode *channel_mode;
330         int need_dac_fix;
331         unsigned int num_mux_defs;
332         const struct hda_input_mux *input_mux;
333         void (*unsol_event)(struct hda_codec *, unsigned int);
334         void (*init_hook)(struct hda_codec *);
335 #ifdef CONFIG_SND_HDA_POWER_SAVE
336         struct hda_amp_list *loopbacks;
337 #endif
338 };
339
340
341 /*
342  * input MUX handling
343  */
344 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
345                              struct snd_ctl_elem_info *uinfo)
346 {
347         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
348         struct alc_spec *spec = codec->spec;
349         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
350         if (mux_idx >= spec->num_mux_defs)
351                 mux_idx = 0;
352         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
353 }
354
355 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
356                             struct snd_ctl_elem_value *ucontrol)
357 {
358         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
359         struct alc_spec *spec = codec->spec;
360         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
361
362         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
363         return 0;
364 }
365
366 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
367                             struct snd_ctl_elem_value *ucontrol)
368 {
369         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
370         struct alc_spec *spec = codec->spec;
371         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
372         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
373         hda_nid_t nid = spec->capsrc_nids ?
374                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
375         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
376                                      nid, &spec->cur_mux[adc_idx]);
377 }
378
379
380 /*
381  * channel mode setting
382  */
383 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
384                             struct snd_ctl_elem_info *uinfo)
385 {
386         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
387         struct alc_spec *spec = codec->spec;
388         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
389                                     spec->num_channel_mode);
390 }
391
392 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
393                            struct snd_ctl_elem_value *ucontrol)
394 {
395         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
396         struct alc_spec *spec = codec->spec;
397         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
398                                    spec->num_channel_mode,
399                                    spec->multiout.max_channels);
400 }
401
402 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
403                            struct snd_ctl_elem_value *ucontrol)
404 {
405         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
406         struct alc_spec *spec = codec->spec;
407         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
408                                       spec->num_channel_mode,
409                                       &spec->multiout.max_channels);
410         if (err >= 0 && spec->need_dac_fix)
411                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
412         return err;
413 }
414
415 /*
416  * Control the mode of pin widget settings via the mixer.  "pc" is used
417  * instead of "%" to avoid consequences of accidently treating the % as
418  * being part of a format specifier.  Maximum allowed length of a value is
419  * 63 characters plus NULL terminator.
420  *
421  * Note: some retasking pin complexes seem to ignore requests for input
422  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
423  * are requested.  Therefore order this list so that this behaviour will not
424  * cause problems when mixer clients move through the enum sequentially.
425  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
426  * March 2006.
427  */
428 static char *alc_pin_mode_names[] = {
429         "Mic 50pc bias", "Mic 80pc bias",
430         "Line in", "Line out", "Headphone out",
431 };
432 static unsigned char alc_pin_mode_values[] = {
433         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
434 };
435 /* The control can present all 5 options, or it can limit the options based
436  * in the pin being assumed to be exclusively an input or an output pin.  In
437  * addition, "input" pins may or may not process the mic bias option
438  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
439  * accept requests for bias as of chip versions up to March 2006) and/or
440  * wiring in the computer.
441  */
442 #define ALC_PIN_DIR_IN              0x00
443 #define ALC_PIN_DIR_OUT             0x01
444 #define ALC_PIN_DIR_INOUT           0x02
445 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
446 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
447
448 /* Info about the pin modes supported by the different pin direction modes.
449  * For each direction the minimum and maximum values are given.
450  */
451 static signed char alc_pin_mode_dir_info[5][2] = {
452         { 0, 2 },    /* ALC_PIN_DIR_IN */
453         { 3, 4 },    /* ALC_PIN_DIR_OUT */
454         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
455         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
456         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
457 };
458 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
459 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
460 #define alc_pin_mode_n_items(_dir) \
461         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
462
463 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
464                              struct snd_ctl_elem_info *uinfo)
465 {
466         unsigned int item_num = uinfo->value.enumerated.item;
467         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
468
469         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
470         uinfo->count = 1;
471         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
472
473         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
474                 item_num = alc_pin_mode_min(dir);
475         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
476         return 0;
477 }
478
479 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
480                             struct snd_ctl_elem_value *ucontrol)
481 {
482         unsigned int i;
483         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
484         hda_nid_t nid = kcontrol->private_value & 0xffff;
485         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
486         long *valp = ucontrol->value.integer.value;
487         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
488                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
489                                                  0x00);
490
491         /* Find enumerated value for current pinctl setting */
492         i = alc_pin_mode_min(dir);
493         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
494                 i++;
495         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
496         return 0;
497 }
498
499 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
500                             struct snd_ctl_elem_value *ucontrol)
501 {
502         signed int change;
503         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
504         hda_nid_t nid = kcontrol->private_value & 0xffff;
505         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
506         long val = *ucontrol->value.integer.value;
507         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
508                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
509                                                  0x00);
510
511         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
512                 val = alc_pin_mode_min(dir);
513
514         change = pinctl != alc_pin_mode_values[val];
515         if (change) {
516                 /* Set pin mode to that requested */
517                 snd_hda_codec_write_cache(codec, nid, 0,
518                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
519                                           alc_pin_mode_values[val]);
520
521                 /* Also enable the retasking pin's input/output as required
522                  * for the requested pin mode.  Enum values of 2 or less are
523                  * input modes.
524                  *
525                  * Dynamically switching the input/output buffers probably
526                  * reduces noise slightly (particularly on input) so we'll
527                  * do it.  However, having both input and output buffers
528                  * enabled simultaneously doesn't seem to be problematic if
529                  * this turns out to be necessary in the future.
530                  */
531                 if (val <= 2) {
532                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
533                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
534                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
535                                                  HDA_AMP_MUTE, 0);
536                 } else {
537                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
538                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
539                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
540                                                  HDA_AMP_MUTE, 0);
541                 }
542         }
543         return change;
544 }
545
546 #define ALC_PIN_MODE(xname, nid, dir) \
547         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
548           .info = alc_pin_mode_info, \
549           .get = alc_pin_mode_get, \
550           .put = alc_pin_mode_put, \
551           .private_value = nid | (dir<<16) }
552
553 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
554  * together using a mask with more than one bit set.  This control is
555  * currently used only by the ALC260 test model.  At this stage they are not
556  * needed for any "production" models.
557  */
558 #ifdef CONFIG_SND_DEBUG
559 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
560
561 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
562                              struct snd_ctl_elem_value *ucontrol)
563 {
564         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
565         hda_nid_t nid = kcontrol->private_value & 0xffff;
566         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
567         long *valp = ucontrol->value.integer.value;
568         unsigned int val = snd_hda_codec_read(codec, nid, 0,
569                                               AC_VERB_GET_GPIO_DATA, 0x00);
570
571         *valp = (val & mask) != 0;
572         return 0;
573 }
574 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
575                              struct snd_ctl_elem_value *ucontrol)
576 {
577         signed int change;
578         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
579         hda_nid_t nid = kcontrol->private_value & 0xffff;
580         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
581         long val = *ucontrol->value.integer.value;
582         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
583                                                     AC_VERB_GET_GPIO_DATA,
584                                                     0x00);
585
586         /* Set/unset the masked GPIO bit(s) as needed */
587         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
588         if (val == 0)
589                 gpio_data &= ~mask;
590         else
591                 gpio_data |= mask;
592         snd_hda_codec_write_cache(codec, nid, 0,
593                                   AC_VERB_SET_GPIO_DATA, gpio_data);
594
595         return change;
596 }
597 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
598         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
599           .info = alc_gpio_data_info, \
600           .get = alc_gpio_data_get, \
601           .put = alc_gpio_data_put, \
602           .private_value = nid | (mask<<16) }
603 #endif   /* CONFIG_SND_DEBUG */
604
605 /* A switch control to allow the enabling of the digital IO pins on the
606  * ALC260.  This is incredibly simplistic; the intention of this control is
607  * to provide something in the test model allowing digital outputs to be
608  * identified if present.  If models are found which can utilise these
609  * outputs a more complete mixer control can be devised for those models if
610  * necessary.
611  */
612 #ifdef CONFIG_SND_DEBUG
613 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
614
615 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
616                               struct snd_ctl_elem_value *ucontrol)
617 {
618         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
619         hda_nid_t nid = kcontrol->private_value & 0xffff;
620         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
621         long *valp = ucontrol->value.integer.value;
622         unsigned int val = snd_hda_codec_read(codec, nid, 0,
623                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
624
625         *valp = (val & mask) != 0;
626         return 0;
627 }
628 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
629                               struct snd_ctl_elem_value *ucontrol)
630 {
631         signed int change;
632         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
633         hda_nid_t nid = kcontrol->private_value & 0xffff;
634         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
635         long val = *ucontrol->value.integer.value;
636         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
637                                                     AC_VERB_GET_DIGI_CONVERT_1,
638                                                     0x00);
639
640         /* Set/unset the masked control bit(s) as needed */
641         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
642         if (val==0)
643                 ctrl_data &= ~mask;
644         else
645                 ctrl_data |= mask;
646         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
647                                   ctrl_data);
648
649         return change;
650 }
651 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
652         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
653           .info = alc_spdif_ctrl_info, \
654           .get = alc_spdif_ctrl_get, \
655           .put = alc_spdif_ctrl_put, \
656           .private_value = nid | (mask<<16) }
657 #endif   /* CONFIG_SND_DEBUG */
658
659 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
660  * Again, this is only used in the ALC26x test models to help identify when
661  * the EAPD line must be asserted for features to work.
662  */
663 #ifdef CONFIG_SND_DEBUG
664 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
665
666 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
667                               struct snd_ctl_elem_value *ucontrol)
668 {
669         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670         hda_nid_t nid = kcontrol->private_value & 0xffff;
671         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
672         long *valp = ucontrol->value.integer.value;
673         unsigned int val = snd_hda_codec_read(codec, nid, 0,
674                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
675
676         *valp = (val & mask) != 0;
677         return 0;
678 }
679
680 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
681                               struct snd_ctl_elem_value *ucontrol)
682 {
683         int change;
684         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
685         hda_nid_t nid = kcontrol->private_value & 0xffff;
686         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
687         long val = *ucontrol->value.integer.value;
688         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
689                                                     AC_VERB_GET_EAPD_BTLENABLE,
690                                                     0x00);
691
692         /* Set/unset the masked control bit(s) as needed */
693         change = (!val ? 0 : mask) != (ctrl_data & mask);
694         if (!val)
695                 ctrl_data &= ~mask;
696         else
697                 ctrl_data |= mask;
698         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
699                                   ctrl_data);
700
701         return change;
702 }
703
704 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
705         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
706           .info = alc_eapd_ctrl_info, \
707           .get = alc_eapd_ctrl_get, \
708           .put = alc_eapd_ctrl_put, \
709           .private_value = nid | (mask<<16) }
710 #endif   /* CONFIG_SND_DEBUG */
711
712 /*
713  * set up from the preset table
714  */
715 static void setup_preset(struct alc_spec *spec,
716                          const struct alc_config_preset *preset)
717 {
718         int i;
719
720         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
721                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
722         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
723              i++)
724                 spec->init_verbs[spec->num_init_verbs++] =
725                         preset->init_verbs[i];
726
727         spec->channel_mode = preset->channel_mode;
728         spec->num_channel_mode = preset->num_channel_mode;
729         spec->need_dac_fix = preset->need_dac_fix;
730
731         spec->multiout.max_channels = spec->channel_mode[0].channels;
732
733         spec->multiout.num_dacs = preset->num_dacs;
734         spec->multiout.dac_nids = preset->dac_nids;
735         spec->multiout.dig_out_nid = preset->dig_out_nid;
736         spec->multiout.hp_nid = preset->hp_nid;
737
738         spec->num_mux_defs = preset->num_mux_defs;
739         if (!spec->num_mux_defs)
740                 spec->num_mux_defs = 1;
741         spec->input_mux = preset->input_mux;
742
743         spec->num_adc_nids = preset->num_adc_nids;
744         spec->adc_nids = preset->adc_nids;
745         spec->capsrc_nids = preset->capsrc_nids;
746         spec->dig_in_nid = preset->dig_in_nid;
747
748         spec->unsol_event = preset->unsol_event;
749         spec->init_hook = preset->init_hook;
750 #ifdef CONFIG_SND_HDA_POWER_SAVE
751         spec->loopback.amplist = preset->loopbacks;
752 #endif
753 }
754
755 /* Enable GPIO mask and set output */
756 static struct hda_verb alc_gpio1_init_verbs[] = {
757         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
758         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
759         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
760         { }
761 };
762
763 static struct hda_verb alc_gpio2_init_verbs[] = {
764         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
765         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
766         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
767         { }
768 };
769
770 static struct hda_verb alc_gpio3_init_verbs[] = {
771         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
772         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
773         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
774         { }
775 };
776
777 /*
778  * Fix hardware PLL issue
779  * On some codecs, the analog PLL gating control must be off while
780  * the default value is 1.
781  */
782 static void alc_fix_pll(struct hda_codec *codec)
783 {
784         struct alc_spec *spec = codec->spec;
785         unsigned int val;
786
787         if (!spec->pll_nid)
788                 return;
789         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
790                             spec->pll_coef_idx);
791         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
792                                  AC_VERB_GET_PROC_COEF, 0);
793         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
794                             spec->pll_coef_idx);
795         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
796                             val & ~(1 << spec->pll_coef_bit));
797 }
798
799 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
800                              unsigned int coef_idx, unsigned int coef_bit)
801 {
802         struct alc_spec *spec = codec->spec;
803         spec->pll_nid = nid;
804         spec->pll_coef_idx = coef_idx;
805         spec->pll_coef_bit = coef_bit;
806         alc_fix_pll(codec);
807 }
808
809 static void alc_sku_automute(struct hda_codec *codec)
810 {
811         struct alc_spec *spec = codec->spec;
812         unsigned int present;
813         unsigned int hp_nid = spec->autocfg.hp_pins[0];
814         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
815
816         /* need to execute and sync at first */
817         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
818         present = snd_hda_codec_read(codec, hp_nid, 0,
819                                      AC_VERB_GET_PIN_SENSE, 0);
820         spec->jack_present = (present & 0x80000000) != 0;
821         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
822                             spec->jack_present ? 0 : PIN_OUT);
823 }
824
825 /* unsolicited event for HP jack sensing */
826 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
827 {
828         if (codec->vendor_id == 0x10ec0880)
829                 res >>= 28;
830         else
831                 res >>= 26;
832         if (res != ALC880_HP_EVENT)
833                 return;
834
835         alc_sku_automute(codec);
836 }
837
838 /* additional initialization for ALC888 variants */
839 static void alc888_coef_init(struct hda_codec *codec)
840 {
841         unsigned int tmp;
842
843         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
844         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
845         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
846         if ((tmp & 0xf0) == 2)
847                 /* alc888S-VC */
848                 snd_hda_codec_read(codec, 0x20, 0,
849                                    AC_VERB_SET_PROC_COEF, 0x830);
850          else
851                  /* alc888-VB */
852                  snd_hda_codec_read(codec, 0x20, 0,
853                                     AC_VERB_SET_PROC_COEF, 0x3030);
854 }
855
856 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
857  *      31 ~ 16 :       Manufacture ID
858  *      15 ~ 8  :       SKU ID
859  *      7  ~ 0  :       Assembly ID
860  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
861  */
862 static void alc_subsystem_id(struct hda_codec *codec,
863                              unsigned int porta, unsigned int porte,
864                              unsigned int portd)
865 {
866         unsigned int ass, tmp, i;
867         unsigned nid;
868         struct alc_spec *spec = codec->spec;
869
870         ass = codec->subsystem_id & 0xffff;
871         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
872                 goto do_sku;
873
874         /*
875          * 31~30        : port conetcivity
876          * 29~21        : reserve
877          * 20           : PCBEEP input
878          * 19~16        : Check sum (15:1)
879          * 15~1         : Custom
880          * 0            : override
881         */
882         nid = 0x1d;
883         if (codec->vendor_id == 0x10ec0260)
884                 nid = 0x17;
885         ass = snd_hda_codec_read(codec, nid, 0,
886                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
887         if (!(ass & 1) && !(ass & 0x100000))
888                 return;
889         if ((ass >> 30) != 1)   /* no physical connection */
890                 return;
891
892         /* check sum */
893         tmp = 0;
894         for (i = 1; i < 16; i++) {
895                 if ((ass >> i) & 1)
896                         tmp++;
897         }
898         if (((ass >> 16) & 0xf) != tmp)
899                 return;
900 do_sku:
901         /*
902          * 0 : override
903          * 1 :  Swap Jack
904          * 2 : 0 --> Desktop, 1 --> Laptop
905          * 3~5 : External Amplifier control
906          * 7~6 : Reserved
907         */
908         tmp = (ass & 0x38) >> 3;        /* external Amp control */
909         switch (tmp) {
910         case 1:
911                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
912                 break;
913         case 3:
914                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
915                 break;
916         case 7:
917                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
918                 break;
919         case 5: /* set EAPD output high */
920                 switch (codec->vendor_id) {
921                 case 0x10ec0260:
922                         snd_hda_codec_write(codec, 0x0f, 0,
923                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
924                         snd_hda_codec_write(codec, 0x10, 0,
925                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
926                         break;
927                 case 0x10ec0262:
928                 case 0x10ec0267:
929                 case 0x10ec0268:
930                 case 0x10ec0269:
931                 case 0x10ec0660:
932                 case 0x10ec0662:
933                 case 0x10ec0663:
934                 case 0x10ec0862:
935                 case 0x10ec0889:
936                         snd_hda_codec_write(codec, 0x14, 0,
937                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
938                         snd_hda_codec_write(codec, 0x15, 0,
939                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
940                         break;
941                 }
942                 switch (codec->vendor_id) {
943                 case 0x10ec0260:
944                         snd_hda_codec_write(codec, 0x1a, 0,
945                                             AC_VERB_SET_COEF_INDEX, 7);
946                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
947                                                  AC_VERB_GET_PROC_COEF, 0);
948                         snd_hda_codec_write(codec, 0x1a, 0,
949                                             AC_VERB_SET_COEF_INDEX, 7);
950                         snd_hda_codec_write(codec, 0x1a, 0,
951                                             AC_VERB_SET_PROC_COEF,
952                                             tmp | 0x2010);
953                         break;
954                 case 0x10ec0262:
955                 case 0x10ec0880:
956                 case 0x10ec0882:
957                 case 0x10ec0883:
958                 case 0x10ec0885:
959                 case 0x10ec0889:
960                         snd_hda_codec_write(codec, 0x20, 0,
961                                             AC_VERB_SET_COEF_INDEX, 7);
962                         tmp = snd_hda_codec_read(codec, 0x20, 0,
963                                                  AC_VERB_GET_PROC_COEF, 0);
964                         snd_hda_codec_write(codec, 0x20, 0,
965                                             AC_VERB_SET_COEF_INDEX, 7);
966                         snd_hda_codec_write(codec, 0x20, 0,
967                                             AC_VERB_SET_PROC_COEF,
968                                             tmp | 0x2010);
969                         break;
970                 case 0x10ec0888:
971                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
972                         break;
973                 case 0x10ec0267:
974                 case 0x10ec0268:
975                         snd_hda_codec_write(codec, 0x20, 0,
976                                             AC_VERB_SET_COEF_INDEX, 7);
977                         tmp = snd_hda_codec_read(codec, 0x20, 0,
978                                                  AC_VERB_GET_PROC_COEF, 0);
979                         snd_hda_codec_write(codec, 0x20, 0,
980                                             AC_VERB_SET_COEF_INDEX, 7);
981                         snd_hda_codec_write(codec, 0x20, 0,
982                                             AC_VERB_SET_PROC_COEF,
983                                             tmp | 0x3000);
984                         break;
985                 }
986         default:
987                 break;
988         }
989
990         /* is laptop or Desktop and enable the function "Mute internal speaker
991          * when the external headphone out jack is plugged"
992          */
993         if (!(ass & 0x8000))
994                 return;
995         /*
996          * 10~8 : Jack location
997          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
998          * 14~13: Resvered
999          * 15   : 1 --> enable the function "Mute internal speaker
1000          *              when the external headphone out jack is plugged"
1001          */
1002         if (!spec->autocfg.speaker_pins[0]) {
1003                 if (spec->autocfg.line_out_pins[0])
1004                         spec->autocfg.speaker_pins[0] =
1005                                 spec->autocfg.line_out_pins[0];
1006                 else
1007                         return;
1008         }
1009
1010         if (!spec->autocfg.hp_pins[0]) {
1011                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1012                 if (tmp == 0)
1013                         spec->autocfg.hp_pins[0] = porta;
1014                 else if (tmp == 1)
1015                         spec->autocfg.hp_pins[0] = porte;
1016                 else if (tmp == 2)
1017                         spec->autocfg.hp_pins[0] = portd;
1018                 else
1019                         return;
1020         }
1021
1022         snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1023                             AC_VERB_SET_UNSOLICITED_ENABLE,
1024                             AC_USRSP_EN | ALC880_HP_EVENT);
1025
1026         spec->unsol_event = alc_sku_unsol_event;
1027 }
1028
1029 /*
1030  * Fix-up pin default configurations
1031  */
1032
1033 struct alc_pincfg {
1034         hda_nid_t nid;
1035         u32 val;
1036 };
1037
1038 static void alc_fix_pincfg(struct hda_codec *codec,
1039                            const struct snd_pci_quirk *quirk,
1040                            const struct alc_pincfg **pinfix)
1041 {
1042         const struct alc_pincfg *cfg;
1043
1044         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1045         if (!quirk)
1046                 return;
1047
1048         cfg = pinfix[quirk->value];
1049         for (; cfg->nid; cfg++) {
1050                 int i;
1051                 u32 val = cfg->val;
1052                 for (i = 0; i < 4; i++) {
1053                         snd_hda_codec_write(codec, cfg->nid, 0,
1054                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1055                                     val & 0xff);
1056                         val >>= 8;
1057                 }
1058         }
1059 }
1060
1061 /*
1062  * ALC880 3-stack model
1063  *
1064  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1065  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1066  *                 F-Mic = 0x1b, HP = 0x19
1067  */
1068
1069 static hda_nid_t alc880_dac_nids[4] = {
1070         /* front, rear, clfe, rear_surr */
1071         0x02, 0x05, 0x04, 0x03
1072 };
1073
1074 static hda_nid_t alc880_adc_nids[3] = {
1075         /* ADC0-2 */
1076         0x07, 0x08, 0x09,
1077 };
1078
1079 /* The datasheet says the node 0x07 is connected from inputs,
1080  * but it shows zero connection in the real implementation on some devices.
1081  * Note: this is a 915GAV bug, fixed on 915GLV
1082  */
1083 static hda_nid_t alc880_adc_nids_alt[2] = {
1084         /* ADC1-2 */
1085         0x08, 0x09,
1086 };
1087
1088 #define ALC880_DIGOUT_NID       0x06
1089 #define ALC880_DIGIN_NID        0x0a
1090
1091 static struct hda_input_mux alc880_capture_source = {
1092         .num_items = 4,
1093         .items = {
1094                 { "Mic", 0x0 },
1095                 { "Front Mic", 0x3 },
1096                 { "Line", 0x2 },
1097                 { "CD", 0x4 },
1098         },
1099 };
1100
1101 /* channel source setting (2/6 channel selection for 3-stack) */
1102 /* 2ch mode */
1103 static struct hda_verb alc880_threestack_ch2_init[] = {
1104         /* set line-in to input, mute it */
1105         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1106         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1107         /* set mic-in to input vref 80%, mute it */
1108         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1109         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1110         { } /* end */
1111 };
1112
1113 /* 6ch mode */
1114 static struct hda_verb alc880_threestack_ch6_init[] = {
1115         /* set line-in to output, unmute it */
1116         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1117         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1118         /* set mic-in to output, unmute it */
1119         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1120         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1121         { } /* end */
1122 };
1123
1124 static struct hda_channel_mode alc880_threestack_modes[2] = {
1125         { 2, alc880_threestack_ch2_init },
1126         { 6, alc880_threestack_ch6_init },
1127 };
1128
1129 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1130         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1131         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1132         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1133         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1134         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1135         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1136         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1137         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1138         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1139         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1140         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1141         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1142         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1143         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1144         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1145         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1146         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1147         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1148         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1149         {
1150                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1151                 .name = "Channel Mode",
1152                 .info = alc_ch_mode_info,
1153                 .get = alc_ch_mode_get,
1154                 .put = alc_ch_mode_put,
1155         },
1156         { } /* end */
1157 };
1158
1159 /* capture mixer elements */
1160 static struct snd_kcontrol_new alc880_capture_mixer[] = {
1161         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
1162         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
1163         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
1164         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
1165         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
1166         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1167         {
1168                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1169                 /* The multiple "Capture Source" controls confuse alsamixer
1170                  * So call somewhat different..
1171                  */
1172                 /* .name = "Capture Source", */
1173                 .name = "Input Source",
1174                 .count = 3,
1175                 .info = alc_mux_enum_info,
1176                 .get = alc_mux_enum_get,
1177                 .put = alc_mux_enum_put,
1178         },
1179         { } /* end */
1180 };
1181
1182 /* capture mixer elements (in case NID 0x07 not available) */
1183 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1184         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1185         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1186         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1187         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1188         {
1189                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1190                 /* The multiple "Capture Source" controls confuse alsamixer
1191                  * So call somewhat different..
1192                  */
1193                 /* .name = "Capture Source", */
1194                 .name = "Input Source",
1195                 .count = 2,
1196                 .info = alc_mux_enum_info,
1197                 .get = alc_mux_enum_get,
1198                 .put = alc_mux_enum_put,
1199         },
1200         { } /* end */
1201 };
1202
1203
1204
1205 /*
1206  * ALC880 5-stack model
1207  *
1208  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1209  *      Side = 0x02 (0xd)
1210  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1211  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1212  */
1213
1214 /* additional mixers to alc880_three_stack_mixer */
1215 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1216         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1217         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1218         { } /* end */
1219 };
1220
1221 /* channel source setting (6/8 channel selection for 5-stack) */
1222 /* 6ch mode */
1223 static struct hda_verb alc880_fivestack_ch6_init[] = {
1224         /* set line-in to input, mute it */
1225         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1226         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1227         { } /* end */
1228 };
1229
1230 /* 8ch mode */
1231 static struct hda_verb alc880_fivestack_ch8_init[] = {
1232         /* set line-in to output, unmute it */
1233         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1234         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1235         { } /* end */
1236 };
1237
1238 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1239         { 6, alc880_fivestack_ch6_init },
1240         { 8, alc880_fivestack_ch8_init },
1241 };
1242
1243
1244 /*
1245  * ALC880 6-stack model
1246  *
1247  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1248  *      Side = 0x05 (0x0f)
1249  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1250  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1251  */
1252
1253 static hda_nid_t alc880_6st_dac_nids[4] = {
1254         /* front, rear, clfe, rear_surr */
1255         0x02, 0x03, 0x04, 0x05
1256 };
1257
1258 static struct hda_input_mux alc880_6stack_capture_source = {
1259         .num_items = 4,
1260         .items = {
1261                 { "Mic", 0x0 },
1262                 { "Front Mic", 0x1 },
1263                 { "Line", 0x2 },
1264                 { "CD", 0x4 },
1265         },
1266 };
1267
1268 /* fixed 8-channels */
1269 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1270         { 8, NULL },
1271 };
1272
1273 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1274         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1275         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1276         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1277         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1278         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1279         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1280         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1281         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1282         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1283         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1284         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1285         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1286         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1287         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1288         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1289         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1290         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1291         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1292         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1293         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1294         {
1295                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1296                 .name = "Channel Mode",
1297                 .info = alc_ch_mode_info,
1298                 .get = alc_ch_mode_get,
1299                 .put = alc_ch_mode_put,
1300         },
1301         { } /* end */
1302 };
1303
1304
1305 /*
1306  * ALC880 W810 model
1307  *
1308  * W810 has rear IO for:
1309  * Front (DAC 02)
1310  * Surround (DAC 03)
1311  * Center/LFE (DAC 04)
1312  * Digital out (06)
1313  *
1314  * The system also has a pair of internal speakers, and a headphone jack.
1315  * These are both connected to Line2 on the codec, hence to DAC 02.
1316  *
1317  * There is a variable resistor to control the speaker or headphone
1318  * volume. This is a hardware-only device without a software API.
1319  *
1320  * Plugging headphones in will disable the internal speakers. This is
1321  * implemented in hardware, not via the driver using jack sense. In
1322  * a similar fashion, plugging into the rear socket marked "front" will
1323  * disable both the speakers and headphones.
1324  *
1325  * For input, there's a microphone jack, and an "audio in" jack.
1326  * These may not do anything useful with this driver yet, because I
1327  * haven't setup any initialization verbs for these yet...
1328  */
1329
1330 static hda_nid_t alc880_w810_dac_nids[3] = {
1331         /* front, rear/surround, clfe */
1332         0x02, 0x03, 0x04
1333 };
1334
1335 /* fixed 6 channels */
1336 static struct hda_channel_mode alc880_w810_modes[1] = {
1337         { 6, NULL }
1338 };
1339
1340 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1341 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1342         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1343         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1344         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1345         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1346         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1347         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1348         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1349         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1350         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1351         { } /* end */
1352 };
1353
1354
1355 /*
1356  * Z710V model
1357  *
1358  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1359  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1360  *                 Line = 0x1a
1361  */
1362
1363 static hda_nid_t alc880_z71v_dac_nids[1] = {
1364         0x02
1365 };
1366 #define ALC880_Z71V_HP_DAC      0x03
1367
1368 /* fixed 2 channels */
1369 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1370         { 2, NULL }
1371 };
1372
1373 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1374         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1375         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1376         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1377         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1378         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1379         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1380         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1381         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1382         { } /* end */
1383 };
1384
1385
1386 /*
1387  * ALC880 F1734 model
1388  *
1389  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1390  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1391  */
1392
1393 static hda_nid_t alc880_f1734_dac_nids[1] = {
1394         0x03
1395 };
1396 #define ALC880_F1734_HP_DAC     0x02
1397
1398 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1399         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1400         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1401         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1402         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1403         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1404         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1405         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1406         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1407         { } /* end */
1408 };
1409
1410 static struct hda_input_mux alc880_f1734_capture_source = {
1411         .num_items = 2,
1412         .items = {
1413                 { "Mic", 0x1 },
1414                 { "CD", 0x4 },
1415         },
1416 };
1417
1418
1419 /*
1420  * ALC880 ASUS model
1421  *
1422  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1423  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1424  *  Mic = 0x18, Line = 0x1a
1425  */
1426
1427 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1428 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1429
1430 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1431         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1432         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1433         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1434         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1435         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1436         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1437         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1438         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1439         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1440         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1441         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1442         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1443         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1444         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1445         {
1446                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1447                 .name = "Channel Mode",
1448                 .info = alc_ch_mode_info,
1449                 .get = alc_ch_mode_get,
1450                 .put = alc_ch_mode_put,
1451         },
1452         { } /* end */
1453 };
1454
1455 /*
1456  * ALC880 ASUS W1V model
1457  *
1458  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1459  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1460  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1461  */
1462
1463 /* additional mixers to alc880_asus_mixer */
1464 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1465         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1466         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1467         { } /* end */
1468 };
1469
1470 /* additional mixers to alc880_asus_mixer */
1471 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1472         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1473         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1474         { } /* end */
1475 };
1476
1477 /* TCL S700 */
1478 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1479         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1480         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1481         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1482         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1483         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1484         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1485         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1486         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1487         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1488         {
1489                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1490                 /* The multiple "Capture Source" controls confuse alsamixer
1491                  * So call somewhat different..
1492                  */
1493                 /* .name = "Capture Source", */
1494                 .name = "Input Source",
1495                 .count = 1,
1496                 .info = alc_mux_enum_info,
1497                 .get = alc_mux_enum_get,
1498                 .put = alc_mux_enum_put,
1499         },
1500         { } /* end */
1501 };
1502
1503 /* Uniwill */
1504 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1505         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1506         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1507         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1508         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1509         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1510         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1511         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1512         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1513         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1514         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1515         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1516         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1517         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1518         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1519         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1520         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1521         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1522         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1523         {
1524                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1525                 .name = "Channel Mode",
1526                 .info = alc_ch_mode_info,
1527                 .get = alc_ch_mode_get,
1528                 .put = alc_ch_mode_put,
1529         },
1530         { } /* end */
1531 };
1532
1533 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1534         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1535         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1536         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1537         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1538         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1539         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1540         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1541         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1542         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1543         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1544         { } /* end */
1545 };
1546
1547 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1548         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1549         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1550         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1551         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1552         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1553         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1554         { } /* end */
1555 };
1556
1557 /*
1558  * virtual master controls
1559  */
1560
1561 /*
1562  * slave controls for virtual master
1563  */
1564 static const char *alc_slave_vols[] = {
1565         "Front Playback Volume",
1566         "Surround Playback Volume",
1567         "Center Playback Volume",
1568         "LFE Playback Volume",
1569         "Side Playback Volume",
1570         "Headphone Playback Volume",
1571         "Speaker Playback Volume",
1572         "Mono Playback Volume",
1573         "Line-Out Playback Volume",
1574         NULL,
1575 };
1576
1577 static const char *alc_slave_sws[] = {
1578         "Front Playback Switch",
1579         "Surround Playback Switch",
1580         "Center Playback Switch",
1581         "LFE Playback Switch",
1582         "Side Playback Switch",
1583         "Headphone Playback Switch",
1584         "Speaker Playback Switch",
1585         "Mono Playback Switch",
1586         "IEC958 Playback Switch",
1587         NULL,
1588 };
1589
1590 /*
1591  * build control elements
1592  */
1593 static int alc_build_controls(struct hda_codec *codec)
1594 {
1595         struct alc_spec *spec = codec->spec;
1596         int err;
1597         int i;
1598
1599         for (i = 0; i < spec->num_mixers; i++) {
1600                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1601                 if (err < 0)
1602                         return err;
1603         }
1604
1605         if (spec->multiout.dig_out_nid) {
1606                 err = snd_hda_create_spdif_out_ctls(codec,
1607                                                     spec->multiout.dig_out_nid);
1608                 if (err < 0)
1609                         return err;
1610                 err = snd_hda_create_spdif_share_sw(codec,
1611                                                     &spec->multiout);
1612                 if (err < 0)
1613                         return err;
1614                 spec->multiout.share_spdif = 1;
1615         }
1616         if (spec->dig_in_nid) {
1617                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1618                 if (err < 0)
1619                         return err;
1620         }
1621
1622         /* if we have no master control, let's create it */
1623         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1624                 unsigned int vmaster_tlv[4];
1625                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1626                                         HDA_OUTPUT, vmaster_tlv);
1627                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1628                                           vmaster_tlv, alc_slave_vols);
1629                 if (err < 0)
1630                         return err;
1631         }
1632         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1633                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1634                                           NULL, alc_slave_sws);
1635                 if (err < 0)
1636                         return err;
1637         }
1638
1639         return 0;
1640 }
1641
1642
1643 /*
1644  * initialize the codec volumes, etc
1645  */
1646
1647 /*
1648  * generic initialization of ADC, input mixers and output mixers
1649  */
1650 static struct hda_verb alc880_volume_init_verbs[] = {
1651         /*
1652          * Unmute ADC0-2 and set the default input to mic-in
1653          */
1654         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1655         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1656         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1657         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1658         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1659         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1660
1661         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1662          * mixer widget
1663          * Note: PASD motherboards uses the Line In 2 as the input for front
1664          * panel mic (mic 2)
1665          */
1666         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1667         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1668         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1669         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1670         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1671         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1672         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1673         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1674
1675         /*
1676          * Set up output mixers (0x0c - 0x0f)
1677          */
1678         /* set vol=0 to output mixers */
1679         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1680         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1681         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1682         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1683         /* set up input amps for analog loopback */
1684         /* Amp Indices: DAC = 0, mixer = 1 */
1685         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1686         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1687         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1688         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1689         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1690         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1691         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1692         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1693
1694         { }
1695 };
1696
1697 /*
1698  * 3-stack pin configuration:
1699  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1700  */
1701 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1702         /*
1703          * preset connection lists of input pins
1704          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1705          */
1706         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1707         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1708         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1709
1710         /*
1711          * Set pin mode and muting
1712          */
1713         /* set front pin widgets 0x14 for output */
1714         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1715         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1716         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1717         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1718         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1719         /* Mic2 (as headphone out) for HP output */
1720         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1721         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1722         /* Line In pin widget for input */
1723         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1724         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1725         /* Line2 (as front mic) pin widget for input and vref at 80% */
1726         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1727         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1728         /* CD pin widget for input */
1729         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1730
1731         { }
1732 };
1733
1734 /*
1735  * 5-stack pin configuration:
1736  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1737  * line-in/side = 0x1a, f-mic = 0x1b
1738  */
1739 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1740         /*
1741          * preset connection lists of input pins
1742          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1743          */
1744         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1745         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1746
1747         /*
1748          * Set pin mode and muting
1749          */
1750         /* set pin widgets 0x14-0x17 for output */
1751         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1752         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1753         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1754         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1755         /* unmute pins for output (no gain on this amp) */
1756         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1757         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1758         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1759         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1760
1761         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1762         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1763         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1764         /* Mic2 (as headphone out) for HP output */
1765         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1766         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1767         /* Line In pin widget for input */
1768         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1769         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1770         /* Line2 (as front mic) pin widget for input and vref at 80% */
1771         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1772         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1773         /* CD pin widget for input */
1774         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1775
1776         { }
1777 };
1778
1779 /*
1780  * W810 pin configuration:
1781  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1782  */
1783 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1784         /* hphone/speaker input selector: front DAC */
1785         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1786
1787         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1788         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1789         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1790         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1791         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1792         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1793
1794         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1795         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1796
1797         { }
1798 };
1799
1800 /*
1801  * Z71V pin configuration:
1802  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1803  */
1804 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1805         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1806         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1807         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1808         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1809
1810         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1811         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1812         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1813         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1814
1815         { }
1816 };
1817
1818 /*
1819  * 6-stack pin configuration:
1820  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1821  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1822  */
1823 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1824         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1825
1826         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1827         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1828         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1829         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1830         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1831         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1832         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1833         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1834
1835         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1836         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1837         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1838         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1839         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1840         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1841         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1842         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1843         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1844
1845         { }
1846 };
1847
1848 /*
1849  * Uniwill pin configuration:
1850  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1851  * line = 0x1a
1852  */
1853 static struct hda_verb alc880_uniwill_init_verbs[] = {
1854         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1855
1856         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1857         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1858         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1859         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1860         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1861         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1862         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1863         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1864         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1865         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1866         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1867         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1868         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1869         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1870
1871         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1872         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1873         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1874         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1875         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1876         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1877         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1878         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1879         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1880
1881         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1882         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1883
1884         { }
1885 };
1886
1887 /*
1888 * Uniwill P53
1889 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
1890  */
1891 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1892         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1893
1894         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1895         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1896         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1897         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1898         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1899         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1900         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1901         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1902         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1903         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1904         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1905         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1906
1907         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1908         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1909         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1910         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1911         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1912         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1913
1914         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1915         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1916
1917         { }
1918 };
1919
1920 static struct hda_verb alc880_beep_init_verbs[] = {
1921         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1922         { }
1923 };
1924
1925 /* toggle speaker-output according to the hp-jack state */
1926 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1927 {
1928         unsigned int present;
1929         unsigned char bits;
1930
1931         present = snd_hda_codec_read(codec, 0x14, 0,
1932                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1933         bits = present ? HDA_AMP_MUTE : 0;
1934         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1935                                  HDA_AMP_MUTE, bits);
1936         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1937                                  HDA_AMP_MUTE, bits);
1938 }
1939
1940 /* auto-toggle front mic */
1941 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1942 {
1943         unsigned int present;
1944         unsigned char bits;
1945
1946         present = snd_hda_codec_read(codec, 0x18, 0,
1947                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1948         bits = present ? HDA_AMP_MUTE : 0;
1949         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1950 }
1951
1952 static void alc880_uniwill_automute(struct hda_codec *codec)
1953 {
1954         alc880_uniwill_hp_automute(codec);
1955         alc880_uniwill_mic_automute(codec);
1956 }
1957
1958 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1959                                        unsigned int res)
1960 {
1961         /* Looks like the unsol event is incompatible with the standard
1962          * definition.  4bit tag is placed at 28 bit!
1963          */
1964         switch (res >> 28) {
1965         case ALC880_HP_EVENT:
1966                 alc880_uniwill_hp_automute(codec);
1967                 break;
1968         case ALC880_MIC_EVENT:
1969                 alc880_uniwill_mic_automute(codec);
1970                 break;
1971         }
1972 }
1973
1974 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1975 {
1976         unsigned int present;
1977         unsigned char bits;
1978
1979         present = snd_hda_codec_read(codec, 0x14, 0,
1980                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1981         bits = present ? HDA_AMP_MUTE : 0;
1982         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
1983 }
1984
1985 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1986 {
1987         unsigned int present;
1988
1989         present = snd_hda_codec_read(codec, 0x21, 0,
1990                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1991         present &= HDA_AMP_VOLMASK;
1992         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
1993                                  HDA_AMP_VOLMASK, present);
1994         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
1995                                  HDA_AMP_VOLMASK, present);
1996 }
1997
1998 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1999                                            unsigned int res)
2000 {
2001         /* Looks like the unsol event is incompatible with the standard
2002          * definition.  4bit tag is placed at 28 bit!
2003          */
2004         if ((res >> 28) == ALC880_HP_EVENT)
2005                 alc880_uniwill_p53_hp_automute(codec);
2006         if ((res >> 28) == ALC880_DCVOL_EVENT)
2007                 alc880_uniwill_p53_dcvol_automute(codec);
2008 }
2009
2010 /*
2011  * F1734 pin configuration:
2012  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2013  */
2014 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2015         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2016         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2017         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2018         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2019         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2020
2021         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2022         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2023         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2024         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2025
2026         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2027         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2028         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2029         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2030         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2031         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2032         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2033         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2034         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2035
2036         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2037         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2038
2039         { }
2040 };
2041
2042 /*
2043  * ASUS pin configuration:
2044  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2045  */
2046 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2047         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2048         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2049         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2050         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2051
2052         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2053         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2054         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2055         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2056         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2057         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2058         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2059         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2060
2061         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2062         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2063         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2064         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2065         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2066         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2067         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2068         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2069         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2070
2071         { }
2072 };
2073
2074 /* Enable GPIO mask and set output */
2075 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2076 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2077
2078 /* Clevo m520g init */
2079 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2080         /* headphone output */
2081         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2082         /* line-out */
2083         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2084         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2085         /* Line-in */
2086         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2087         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2088         /* CD */
2089         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2090         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2091         /* Mic1 (rear panel) */
2092         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2093         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2094         /* Mic2 (front panel) */
2095         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2096         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2097         /* headphone */
2098         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2099         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2100         /* change to EAPD mode */
2101         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2102         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2103
2104         { }
2105 };
2106
2107 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2108         /* change to EAPD mode */
2109         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2110         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2111
2112         /* Headphone output */
2113         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2114         /* Front output*/
2115         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2116         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2117
2118         /* Line In pin widget for input */
2119         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2120         /* CD pin widget for input */
2121         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2122         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2123         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2124
2125         /* change to EAPD mode */
2126         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2127         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2128
2129         { }
2130 };
2131
2132 /*
2133  * LG m1 express dual
2134  *
2135  * Pin assignment:
2136  *   Rear Line-In/Out (blue): 0x14
2137  *   Build-in Mic-In: 0x15
2138  *   Speaker-out: 0x17
2139  *   HP-Out (green): 0x1b
2140  *   Mic-In/Out (red): 0x19
2141  *   SPDIF-Out: 0x1e
2142  */
2143
2144 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2145 static hda_nid_t alc880_lg_dac_nids[3] = {
2146         0x05, 0x02, 0x03
2147 };
2148
2149 /* seems analog CD is not working */
2150 static struct hda_input_mux alc880_lg_capture_source = {
2151         .num_items = 3,
2152         .items = {
2153                 { "Mic", 0x1 },
2154                 { "Line", 0x5 },
2155                 { "Internal Mic", 0x6 },
2156         },
2157 };
2158
2159 /* 2,4,6 channel modes */
2160 static struct hda_verb alc880_lg_ch2_init[] = {
2161         /* set line-in and mic-in to input */
2162         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2163         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2164         { }
2165 };
2166
2167 static struct hda_verb alc880_lg_ch4_init[] = {
2168         /* set line-in to out and mic-in to input */
2169         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2170         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2171         { }
2172 };
2173
2174 static struct hda_verb alc880_lg_ch6_init[] = {
2175         /* set line-in and mic-in to output */
2176         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2177         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2178         { }
2179 };
2180
2181 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2182         { 2, alc880_lg_ch2_init },
2183         { 4, alc880_lg_ch4_init },
2184         { 6, alc880_lg_ch6_init },
2185 };
2186
2187 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2188         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2189         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2190         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2191         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2192         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2193         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2194         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2195         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2196         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2197         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2198         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2199         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2200         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2201         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2202         {
2203                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2204                 .name = "Channel Mode",
2205                 .info = alc_ch_mode_info,
2206                 .get = alc_ch_mode_get,
2207                 .put = alc_ch_mode_put,
2208         },
2209         { } /* end */
2210 };
2211
2212 static struct hda_verb alc880_lg_init_verbs[] = {
2213         /* set capture source to mic-in */
2214         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2215         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2216         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2217         /* mute all amp mixer inputs */
2218         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2219         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2220         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2221         /* line-in to input */
2222         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2223         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2224         /* built-in mic */
2225         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2226         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2227         /* speaker-out */
2228         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2229         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2230         /* mic-in to input */
2231         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2232         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2233         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2234         /* HP-out */
2235         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2236         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2237         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2238         /* jack sense */
2239         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2240         { }
2241 };
2242
2243 /* toggle speaker-output according to the hp-jack state */
2244 static void alc880_lg_automute(struct hda_codec *codec)
2245 {
2246         unsigned int present;
2247         unsigned char bits;
2248
2249         present = snd_hda_codec_read(codec, 0x1b, 0,
2250                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2251         bits = present ? HDA_AMP_MUTE : 0;
2252         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2253                                  HDA_AMP_MUTE, bits);
2254 }
2255
2256 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2257 {
2258         /* Looks like the unsol event is incompatible with the standard
2259          * definition.  4bit tag is placed at 28 bit!
2260          */
2261         if ((res >> 28) == 0x01)
2262                 alc880_lg_automute(codec);
2263 }
2264
2265 /*
2266  * LG LW20
2267  *
2268  * Pin assignment:
2269  *   Speaker-out: 0x14
2270  *   Mic-In: 0x18
2271  *   Built-in Mic-In: 0x19
2272  *   Line-In: 0x1b
2273  *   HP-Out: 0x1a
2274  *   SPDIF-Out: 0x1e
2275  */
2276
2277 static struct hda_input_mux alc880_lg_lw_capture_source = {
2278         .num_items = 3,
2279         .items = {
2280                 { "Mic", 0x0 },
2281                 { "Internal Mic", 0x1 },
2282                 { "Line In", 0x2 },
2283         },
2284 };
2285
2286 #define alc880_lg_lw_modes alc880_threestack_modes
2287
2288 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2289         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2290         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2291         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2292         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2293         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2294         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2295         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2296         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2297         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2298         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2299         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2300         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2301         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2302         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2303         {
2304                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2305                 .name = "Channel Mode",
2306                 .info = alc_ch_mode_info,
2307                 .get = alc_ch_mode_get,
2308                 .put = alc_ch_mode_put,
2309         },
2310         { } /* end */
2311 };
2312
2313 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2314         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2315         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2316         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2317
2318         /* set capture source to mic-in */
2319         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2320         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2321         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2322         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2323         /* speaker-out */
2324         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2325         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2326         /* HP-out */
2327         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2328         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2329         /* mic-in to input */
2330         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2331         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2332         /* built-in mic */
2333         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2334         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2335         /* jack sense */
2336         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2337         { }
2338 };
2339
2340 /* toggle speaker-output according to the hp-jack state */
2341 static void alc880_lg_lw_automute(struct hda_codec *codec)
2342 {
2343         unsigned int present;
2344         unsigned char bits;
2345
2346         present = snd_hda_codec_read(codec, 0x1b, 0,
2347                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2348         bits = present ? HDA_AMP_MUTE : 0;
2349         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2350                                  HDA_AMP_MUTE, bits);
2351 }
2352
2353 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2354 {
2355         /* Looks like the unsol event is incompatible with the standard
2356          * definition.  4bit tag is placed at 28 bit!
2357          */
2358         if ((res >> 28) == 0x01)
2359                 alc880_lg_lw_automute(codec);
2360 }
2361
2362 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2363         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2364         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2365         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2366         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2367         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2368         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2369         { } /* end */
2370 };
2371
2372 static struct hda_input_mux alc880_medion_rim_capture_source = {
2373         .num_items = 2,
2374         .items = {
2375                 { "Mic", 0x0 },
2376                 { "Internal Mic", 0x1 },
2377         },
2378 };
2379
2380 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2381         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2382
2383         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2384         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2385
2386         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2387         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2388         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2389         /* Mic2 (as headphone out) for HP output */
2390         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2391         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2392         /* Internal Speaker */
2393         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2394         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2395
2396         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2397         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2398
2399         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2400         { }
2401 };
2402
2403 /* toggle speaker-output according to the hp-jack state */
2404 static void alc880_medion_rim_automute(struct hda_codec *codec)
2405 {
2406         unsigned int present;
2407         unsigned char bits;
2408
2409         present = snd_hda_codec_read(codec, 0x14, 0,
2410                                      AC_VERB_GET_PIN_SENSE, 0)
2411                 & AC_PINSENSE_PRESENCE;
2412         bits = present ? HDA_AMP_MUTE : 0;
2413         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2414                                  HDA_AMP_MUTE, bits);
2415         if (present)
2416                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2417         else
2418                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2419 }
2420
2421 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2422                                           unsigned int res)
2423 {
2424         /* Looks like the unsol event is incompatible with the standard
2425          * definition.  4bit tag is placed at 28 bit!
2426          */
2427         if ((res >> 28) == ALC880_HP_EVENT)
2428                 alc880_medion_rim_automute(codec);
2429 }
2430
2431 #ifdef CONFIG_SND_HDA_POWER_SAVE
2432 static struct hda_amp_list alc880_loopbacks[] = {
2433         { 0x0b, HDA_INPUT, 0 },
2434         { 0x0b, HDA_INPUT, 1 },
2435         { 0x0b, HDA_INPUT, 2 },
2436         { 0x0b, HDA_INPUT, 3 },
2437         { 0x0b, HDA_INPUT, 4 },
2438         { } /* end */
2439 };
2440
2441 static struct hda_amp_list alc880_lg_loopbacks[] = {
2442         { 0x0b, HDA_INPUT, 1 },
2443         { 0x0b, HDA_INPUT, 6 },
2444         { 0x0b, HDA_INPUT, 7 },
2445         { } /* end */
2446 };
2447 #endif
2448
2449 /*
2450  * Common callbacks
2451  */
2452
2453 static int alc_init(struct hda_codec *codec)
2454 {
2455         struct alc_spec *spec = codec->spec;
2456         unsigned int i;
2457
2458         alc_fix_pll(codec);
2459         if (codec->vendor_id == 0x10ec0888)
2460                 alc888_coef_init(codec);
2461
2462         for (i = 0; i < spec->num_init_verbs; i++)
2463                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2464
2465         if (spec->init_hook)
2466                 spec->init_hook(codec);
2467
2468         return 0;
2469 }
2470
2471 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2472 {
2473         struct alc_spec *spec = codec->spec;
2474
2475         if (spec->unsol_event)
2476                 spec->unsol_event(codec, res);
2477 }
2478
2479 #ifdef CONFIG_SND_HDA_POWER_SAVE
2480 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2481 {
2482         struct alc_spec *spec = codec->spec;
2483         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2484 }
2485 #endif
2486
2487 /*
2488  * Analog playback callbacks
2489  */
2490 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2491                                     struct hda_codec *codec,
2492                                     struct snd_pcm_substream *substream)
2493 {
2494         struct alc_spec *spec = codec->spec;
2495         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2496                                              hinfo);
2497 }
2498
2499 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2500                                        struct hda_codec *codec,
2501                                        unsigned int stream_tag,
2502                                        unsigned int format,
2503                                        struct snd_pcm_substream *substream)
2504 {
2505         struct alc_spec *spec = codec->spec;
2506         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2507                                                 stream_tag, format, substream);
2508 }
2509
2510 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2511                                        struct hda_codec *codec,
2512                                        struct snd_pcm_substream *substream)
2513 {
2514         struct alc_spec *spec = codec->spec;
2515         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2516 }
2517
2518 /*
2519  * Digital out
2520  */
2521 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2522                                         struct hda_codec *codec,
2523                                         struct snd_pcm_substream *substream)
2524 {
2525         struct alc_spec *spec = codec->spec;
2526         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2527 }
2528
2529 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2530                                            struct hda_codec *codec,
2531                                            unsigned int stream_tag,
2532                                            unsigned int format,
2533                                            struct snd_pcm_substream *substream)
2534 {
2535         struct alc_spec *spec = codec->spec;
2536         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2537                                              stream_tag, format, substream);
2538 }
2539
2540 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2541                                          struct hda_codec *codec,
2542                                          struct snd_pcm_substream *substream)
2543 {
2544         struct alc_spec *spec = codec->spec;
2545         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2546 }
2547
2548 /*
2549  * Analog capture
2550  */
2551 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2552                                       struct hda_codec *codec,
2553                                       unsigned int stream_tag,
2554                                       unsigned int format,
2555                                       struct snd_pcm_substream *substream)
2556 {
2557         struct alc_spec *spec = codec->spec;
2558
2559         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2560                                    stream_tag, 0, format);
2561         return 0;
2562 }
2563
2564 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2565                                       struct hda_codec *codec,
2566                                       struct snd_pcm_substream *substream)
2567 {
2568         struct alc_spec *spec = codec->spec;
2569
2570         snd_hda_codec_cleanup_stream(codec,
2571                                      spec->adc_nids[substream->number + 1]);
2572         return 0;
2573 }
2574
2575
2576 /*
2577  */
2578 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2579         .substreams = 1,
2580         .channels_min = 2,
2581         .channels_max = 8,
2582         /* NID is set in alc_build_pcms */
2583         .ops = {
2584                 .open = alc880_playback_pcm_open,
2585                 .prepare = alc880_playback_pcm_prepare,
2586                 .cleanup = alc880_playback_pcm_cleanup
2587         },
2588 };
2589
2590 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2591         .substreams = 1,
2592         .channels_min = 2,
2593         .channels_max = 2,
2594         /* NID is set in alc_build_pcms */
2595 };
2596
2597 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
2598         .substreams = 1,
2599         .channels_min = 2,
2600         .channels_max = 2,
2601         /* NID is set in alc_build_pcms */
2602 };
2603
2604 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2605         .substreams = 2, /* can be overridden */
2606         .channels_min = 2,
2607         .channels_max = 2,
2608         /* NID is set in alc_build_pcms */
2609         .ops = {
2610                 .prepare = alc880_alt_capture_pcm_prepare,
2611                 .cleanup = alc880_alt_capture_pcm_cleanup
2612         },
2613 };
2614
2615 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2616         .substreams = 1,
2617         .channels_min = 2,
2618         .channels_max = 2,
2619         /* NID is set in alc_build_pcms */
2620         .ops = {
2621                 .open = alc880_dig_playback_pcm_open,
2622                 .close = alc880_dig_playback_pcm_close,
2623                 .prepare = alc880_dig_playback_pcm_prepare
2624         },
2625 };
2626
2627 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2628         .substreams = 1,
2629         .channels_min = 2,
2630         .channels_max = 2,
2631         /* NID is set in alc_build_pcms */
2632 };
2633
2634 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2635 static struct hda_pcm_stream alc_pcm_null_stream = {
2636         .substreams = 0,
2637         .channels_min = 0,
2638         .channels_max = 0,
2639 };
2640
2641 static int alc_build_pcms(struct hda_codec *codec)
2642 {
2643         struct alc_spec *spec = codec->spec;
2644         struct hda_pcm *info = spec->pcm_rec;
2645         int i;
2646
2647         codec->num_pcms = 1;
2648         codec->pcm_info = info;
2649
2650         info->name = spec->stream_name_analog;
2651         if (spec->stream_analog_playback) {
2652                 if (snd_BUG_ON(!spec->multiout.dac_nids))
2653                         return -EINVAL;
2654                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2655                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2656         }
2657         if (spec->stream_analog_capture) {
2658                 if (snd_BUG_ON(!spec->adc_nids))
2659                         return -EINVAL;
2660                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2661                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2662         }
2663
2664         if (spec->channel_mode) {
2665                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2666                 for (i = 0; i < spec->num_channel_mode; i++) {
2667                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2668                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2669                         }
2670                 }
2671         }
2672
2673         /* SPDIF for stream index #1 */
2674         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2675                 codec->num_pcms = 2;
2676                 info = spec->pcm_rec + 1;
2677                 info->name = spec->stream_name_digital;
2678                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2679                 if (spec->multiout.dig_out_nid &&
2680                     spec->stream_digital_playback) {
2681                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2682                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2683                 }
2684                 if (spec->dig_in_nid &&
2685                     spec->stream_digital_capture) {
2686                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2687                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2688                 }
2689                 /* FIXME: do we need this for all Realtek codec models? */
2690                 codec->spdif_status_reset = 1;
2691         }
2692
2693         /* If the use of more than one ADC is requested for the current
2694          * model, configure a second analog capture-only PCM.
2695          */
2696         /* Additional Analaog capture for index #2 */
2697         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
2698             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
2699                 codec->num_pcms = 3;
2700                 info = spec->pcm_rec + 2;
2701                 info->name = spec->stream_name_analog;
2702                 if (spec->alt_dac_nid) {
2703                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2704                                 *spec->stream_analog_alt_playback;
2705                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2706                                 spec->alt_dac_nid;
2707                 } else {
2708                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2709                                 alc_pcm_null_stream;
2710                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2711                 }
2712                 if (spec->num_adc_nids > 1) {
2713                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2714                                 *spec->stream_analog_alt_capture;
2715                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2716                                 spec->adc_nids[1];
2717                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2718                                 spec->num_adc_nids - 1;
2719                 } else {
2720                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2721                                 alc_pcm_null_stream;
2722                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2723                 }
2724         }
2725
2726         return 0;
2727 }
2728
2729 static void alc_free(struct hda_codec *codec)
2730 {
2731         struct alc_spec *spec = codec->spec;
2732         unsigned int i;
2733
2734         if (!spec)
2735                 return;
2736
2737         if (spec->kctl_alloc) {
2738                 for (i = 0; i < spec->num_kctl_used; i++)
2739                         kfree(spec->kctl_alloc[i].name);
2740                 kfree(spec->kctl_alloc);
2741         }
2742         kfree(spec);
2743         codec->spec = NULL; /* to be sure */
2744 }
2745
2746 /*
2747  */
2748 static struct hda_codec_ops alc_patch_ops = {
2749         .build_controls = alc_build_controls,
2750         .build_pcms = alc_build_pcms,
2751         .init = alc_init,
2752         .free = alc_free,
2753         .unsol_event = alc_unsol_event,
2754 #ifdef CONFIG_SND_HDA_POWER_SAVE
2755         .check_power_status = alc_check_power_status,
2756 #endif
2757 };
2758
2759
2760 /*
2761  * Test configuration for debugging
2762  *
2763  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2764  * enum controls.
2765  */
2766 #ifdef CONFIG_SND_DEBUG
2767 static hda_nid_t alc880_test_dac_nids[4] = {
2768         0x02, 0x03, 0x04, 0x05
2769 };
2770
2771 static struct hda_input_mux alc880_test_capture_source = {
2772         .num_items = 7,
2773         .items = {
2774                 { "In-1", 0x0 },
2775                 { "In-2", 0x1 },
2776                 { "In-3", 0x2 },
2777                 { "In-4", 0x3 },
2778                 { "CD", 0x4 },
2779                 { "Front", 0x5 },
2780                 { "Surround", 0x6 },
2781         },
2782 };
2783
2784 static struct hda_channel_mode alc880_test_modes[4] = {
2785         { 2, NULL },
2786         { 4, NULL },
2787         { 6, NULL },
2788         { 8, NULL },
2789 };
2790
2791 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2792                                  struct snd_ctl_elem_info *uinfo)
2793 {
2794         static char *texts[] = {
2795                 "N/A", "Line Out", "HP Out",
2796                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2797         };
2798         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2799         uinfo->count = 1;
2800         uinfo->value.enumerated.items = 8;
2801         if (uinfo->value.enumerated.item >= 8)
2802                 uinfo->value.enumerated.item = 7;
2803         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2804         return 0;
2805 }
2806
2807 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2808                                 struct snd_ctl_elem_value *ucontrol)
2809 {
2810         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2811         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2812         unsigned int pin_ctl, item = 0;
2813
2814         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2815                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2816         if (pin_ctl & AC_PINCTL_OUT_EN) {
2817                 if (pin_ctl & AC_PINCTL_HP_EN)
2818                         item = 2;
2819                 else
2820                         item = 1;
2821         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2822                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2823                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2824                 case AC_PINCTL_VREF_50:  item = 4; break;
2825                 case AC_PINCTL_VREF_GRD: item = 5; break;
2826                 case AC_PINCTL_VREF_80:  item = 6; break;
2827                 case AC_PINCTL_VREF_100: item = 7; break;
2828                 }
2829         }
2830         ucontrol->value.enumerated.item[0] = item;
2831         return 0;
2832 }
2833
2834 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2835                                 struct snd_ctl_elem_value *ucontrol)
2836 {
2837         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2838         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2839         static unsigned int ctls[] = {
2840                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2841                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2842                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2843                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2844                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2845                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2846         };
2847         unsigned int old_ctl, new_ctl;
2848
2849         old_ctl = snd_hda_codec_read(codec, nid, 0,
2850                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2851         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2852         if (old_ctl != new_ctl) {
2853                 int val;
2854                 snd_hda_codec_write_cache(codec, nid, 0,
2855                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2856                                           new_ctl);
2857                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2858                         HDA_AMP_MUTE : 0;
2859                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2860                                          HDA_AMP_MUTE, val);
2861                 return 1;
2862         }
2863         return 0;
2864 }
2865
2866 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2867                                  struct snd_ctl_elem_info *uinfo)
2868 {
2869         static char *texts[] = {
2870                 "Front", "Surround", "CLFE", "Side"
2871         };
2872         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2873         uinfo->count = 1;
2874         uinfo->value.enumerated.items = 4;
2875         if (uinfo->value.enumerated.item >= 4)
2876                 uinfo->value.enumerated.item = 3;
2877         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2878         return 0;
2879 }
2880
2881 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2882                                 struct snd_ctl_elem_value *ucontrol)
2883 {
2884         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2885         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2886         unsigned int sel;
2887
2888         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2889         ucontrol->value.enumerated.item[0] = sel & 3;
2890         return 0;
2891 }
2892
2893 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2894                                 struct snd_ctl_elem_value *ucontrol)
2895 {
2896         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2897         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2898         unsigned int sel;
2899
2900         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2901         if (ucontrol->value.enumerated.item[0] != sel) {
2902                 sel = ucontrol->value.enumerated.item[0] & 3;
2903                 snd_hda_codec_write_cache(codec, nid, 0,
2904                                           AC_VERB_SET_CONNECT_SEL, sel);
2905                 return 1;
2906         }
2907         return 0;
2908 }
2909
2910 #define PIN_CTL_TEST(xname,nid) {                       \
2911                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2912                         .name = xname,                 \
2913                         .info = alc_test_pin_ctl_info, \
2914                         .get = alc_test_pin_ctl_get,   \
2915                         .put = alc_test_pin_ctl_put,   \
2916                         .private_value = nid           \
2917                         }
2918
2919 #define PIN_SRC_TEST(xname,nid) {                       \
2920                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2921                         .name = xname,                 \
2922                         .info = alc_test_pin_src_info, \
2923                         .get = alc_test_pin_src_get,   \
2924                         .put = alc_test_pin_src_put,   \
2925                         .private_value = nid           \
2926                         }
2927
2928 static struct snd_kcontrol_new alc880_test_mixer[] = {
2929         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2930         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2931         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2932         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2933         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2934         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2935         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2936         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2937         PIN_CTL_TEST("Front Pin Mode", 0x14),
2938         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2939         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2940         PIN_CTL_TEST("Side Pin Mode", 0x17),
2941         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2942         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2943         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2944         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2945         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2946         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2947         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2948         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2949         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2950         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2951         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2952         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2953         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2954         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2955         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2956         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2957         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2958         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2959         {
2960                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2961                 .name = "Channel Mode",
2962                 .info = alc_ch_mode_info,
2963                 .get = alc_ch_mode_get,
2964                 .put = alc_ch_mode_put,
2965         },
2966         { } /* end */
2967 };
2968
2969 static struct hda_verb alc880_test_init_verbs[] = {
2970         /* Unmute inputs of 0x0c - 0x0f */
2971         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2972         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2973         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2974         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2975         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2976         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2977         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2978         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2979         /* Vol output for 0x0c-0x0f */
2980         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2981         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2982         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2983         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2984         /* Set output pins 0x14-0x17 */
2985         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2986         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2987         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2988         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2989         /* Unmute output pins 0x14-0x17 */
2990         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2991         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2992         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2993         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2994         /* Set input pins 0x18-0x1c */
2995         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2996         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2997         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2998         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2999         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3000         /* Mute input pins 0x18-0x1b */
3001         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3002         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3003         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3004         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3005         /* ADC set up */
3006         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3007         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3008         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3009         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3010         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3011         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3012         /* Analog input/passthru */
3013         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3014         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3015         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3016         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3017         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3018         { }
3019 };
3020 #endif
3021
3022 /*
3023  */
3024
3025 static const char *alc880_models[ALC880_MODEL_LAST] = {
3026         [ALC880_3ST]            = "3stack",
3027         [ALC880_TCL_S700]       = "tcl",
3028         [ALC880_3ST_DIG]        = "3stack-digout",
3029         [ALC880_CLEVO]          = "clevo",
3030         [ALC880_5ST]            = "5stack",
3031         [ALC880_5ST_DIG]        = "5stack-digout",
3032         [ALC880_W810]           = "w810",
3033         [ALC880_Z71V]           = "z71v",
3034         [ALC880_6ST]            = "6stack",
3035         [ALC880_6ST_DIG]        = "6stack-digout",
3036         [ALC880_ASUS]           = "asus",
3037         [ALC880_ASUS_W1V]       = "asus-w1v",
3038         [ALC880_ASUS_DIG]       = "asus-dig",
3039         [ALC880_ASUS_DIG2]      = "asus-dig2",
3040         [ALC880_UNIWILL_DIG]    = "uniwill",
3041         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3042         [ALC880_FUJITSU]        = "fujitsu",
3043         [ALC880_F1734]          = "F1734",
3044         [ALC880_LG]             = "lg",
3045         [ALC880_LG_LW]          = "lg-lw",
3046         [ALC880_MEDION_RIM]     = "medion",
3047 #ifdef CONFIG_SND_DEBUG
3048         [ALC880_TEST]           = "test",
3049 #endif
3050         [ALC880_AUTO]           = "auto",
3051 };
3052
3053 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3054         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3055         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3056         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3057         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3058         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3059         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3060         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3061         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3062         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3063         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3064         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3065         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3066         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3067         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3068         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3069         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3070         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3071         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3072         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3073         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3074         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3075         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3076         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3077         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3078         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3079         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3080         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3081         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3082         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3083         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3084         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3085         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3086         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3087         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3088         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3089         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3090         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3091         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3092         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3093         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3094         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3095         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3096         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3097         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3098         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3099         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3100         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3101         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3102         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3103         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3104         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3105         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3106         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3107         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3108         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3109         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3110         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3111         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3112         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3113         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3114         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3115         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3116         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3117         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3118         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3119         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3120         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3121         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3122         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3123         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3124         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3125         {}
3126 };
3127
3128 /*
3129  * ALC880 codec presets
3130  */
3131 static struct alc_config_preset alc880_presets[] = {
3132         [ALC880_3ST] = {
3133                 .mixers = { alc880_three_stack_mixer },
3134                 .init_verbs = { alc880_volume_init_verbs,
3135                                 alc880_pin_3stack_init_verbs },
3136                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3137                 .dac_nids = alc880_dac_nids,
3138                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3139                 .channel_mode = alc880_threestack_modes,
3140                 .need_dac_fix = 1,
3141                 .input_mux = &alc880_capture_source,
3142         },
3143         [ALC880_3ST_DIG] = {
3144                 .mixers = { alc880_three_stack_mixer },
3145                 .init_verbs = { alc880_volume_init_verbs,
3146                                 alc880_pin_3stack_init_verbs },
3147                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3148                 .dac_nids = alc880_dac_nids,
3149                 .dig_out_nid = ALC880_DIGOUT_NID,
3150                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3151                 .channel_mode = alc880_threestack_modes,
3152                 .need_dac_fix = 1,
3153                 .input_mux = &alc880_capture_source,
3154         },
3155         [ALC880_TCL_S700] = {
3156                 .mixers = { alc880_tcl_s700_mixer },
3157                 .init_verbs = { alc880_volume_init_verbs,
3158                                 alc880_pin_tcl_S700_init_verbs,
3159                                 alc880_gpio2_init_verbs },
3160                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3161                 .dac_nids = alc880_dac_nids,
3162                 .hp_nid = 0x03,
3163                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3164                 .channel_mode = alc880_2_jack_modes,
3165                 .input_mux = &alc880_capture_source,
3166         },
3167         [ALC880_5ST] = {
3168                 .mixers = { alc880_three_stack_mixer,
3169                             alc880_five_stack_mixer},
3170                 .init_verbs = { alc880_volume_init_verbs,
3171                                 alc880_pin_5stack_init_verbs },
3172                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3173                 .dac_nids = alc880_dac_nids,
3174                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3175                 .channel_mode = alc880_fivestack_modes,
3176                 .input_mux = &alc880_capture_source,
3177         },
3178         [ALC880_5ST_DIG] = {
3179                 .mixers = { alc880_three_stack_mixer,
3180                             alc880_five_stack_mixer },
3181                 .init_verbs = { alc880_volume_init_verbs,
3182                                 alc880_pin_5stack_init_verbs },
3183                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3184                 .dac_nids = alc880_dac_nids,
3185                 .dig_out_nid = ALC880_DIGOUT_NID,
3186                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3187                 .channel_mode = alc880_fivestack_modes,
3188                 .input_mux = &alc880_capture_source,
3189         },
3190         [ALC880_6ST] = {
3191                 .mixers = { alc880_six_stack_mixer },
3192                 .init_verbs = { alc880_volume_init_verbs,
3193                                 alc880_pin_6stack_init_verbs },
3194                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3195                 .dac_nids = alc880_6st_dac_nids,
3196                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3197                 .channel_mode = alc880_sixstack_modes,
3198                 .input_mux = &alc880_6stack_capture_source,
3199         },
3200         [ALC880_6ST_DIG] = {
3201                 .mixers = { alc880_six_stack_mixer },
3202                 .init_verbs = { alc880_volume_init_verbs,
3203                                 alc880_pin_6stack_init_verbs },
3204                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3205                 .dac_nids = alc880_6st_dac_nids,
3206                 .dig_out_nid = ALC880_DIGOUT_NID,
3207                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3208                 .channel_mode = alc880_sixstack_modes,
3209                 .input_mux = &alc880_6stack_capture_source,
3210         },
3211         [ALC880_W810] = {
3212                 .mixers = { alc880_w810_base_mixer },
3213                 .init_verbs = { alc880_volume_init_verbs,
3214                                 alc880_pin_w810_init_verbs,
3215                                 alc880_gpio2_init_verbs },
3216                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3217                 .dac_nids = alc880_w810_dac_nids,
3218                 .dig_out_nid = ALC880_DIGOUT_NID,
3219                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3220                 .channel_mode = alc880_w810_modes,
3221                 .input_mux = &alc880_capture_source,
3222         },
3223         [ALC880_Z71V] = {
3224                 .mixers = { alc880_z71v_mixer },
3225                 .init_verbs = { alc880_volume_init_verbs,
3226                                 alc880_pin_z71v_init_verbs },
3227                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3228                 .dac_nids = alc880_z71v_dac_nids,
3229                 .dig_out_nid = ALC880_DIGOUT_NID,
3230                 .hp_nid = 0x03,
3231                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3232                 .channel_mode = alc880_2_jack_modes,
3233                 .input_mux = &alc880_capture_source,
3234         },
3235         [ALC880_F1734] = {
3236                 .mixers = { alc880_f1734_mixer },
3237                 .init_verbs = { alc880_volume_init_verbs,
3238                                 alc880_pin_f1734_init_verbs },
3239                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3240                 .dac_nids = alc880_f1734_dac_nids,
3241                 .hp_nid = 0x02,
3242                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3243                 .channel_mode = alc880_2_jack_modes,
3244                 .input_mux = &alc880_f1734_capture_source,
3245                 .unsol_event = alc880_uniwill_p53_unsol_event,
3246                 .init_hook = alc880_uniwill_p53_hp_automute,
3247         },
3248         [ALC880_ASUS] = {
3249                 .mixers = { alc880_asus_mixer },
3250                 .init_verbs = { alc880_volume_init_verbs,
3251                                 alc880_pin_asus_init_verbs,
3252                                 alc880_gpio1_init_verbs },
3253                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3254                 .dac_nids = alc880_asus_dac_nids,
3255                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3256                 .channel_mode = alc880_asus_modes,
3257                 .need_dac_fix = 1,
3258                 .input_mux = &alc880_capture_source,
3259         },
3260         [ALC880_ASUS_DIG] = {
3261                 .mixers = { alc880_asus_mixer },
3262                 .init_verbs = { alc880_volume_init_verbs,
3263                                 alc880_pin_asus_init_verbs,
3264                                 alc880_gpio1_init_verbs },
3265                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3266                 .dac_nids = alc880_asus_dac_nids,
3267                 .dig_out_nid = ALC880_DIGOUT_NID,
3268                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3269                 .channel_mode = alc880_asus_modes,
3270                 .need_dac_fix = 1,
3271                 .input_mux = &alc880_capture_source,
3272         },
3273         [ALC880_ASUS_DIG2] = {
3274                 .mixers = { alc880_asus_mixer },
3275                 .init_verbs = { alc880_volume_init_verbs,
3276                                 alc880_pin_asus_init_verbs,
3277                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3278                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3279                 .dac_nids = alc880_asus_dac_nids,
3280                 .dig_out_nid = ALC880_DIGOUT_NID,
3281                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3282                 .channel_mode = alc880_asus_modes,
3283                 .need_dac_fix = 1,
3284                 .input_mux = &alc880_capture_source,
3285         },
3286         [ALC880_ASUS_W1V] = {
3287                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3288                 .init_verbs = { alc880_volume_init_verbs,
3289                                 alc880_pin_asus_init_verbs,
3290                                 alc880_gpio1_init_verbs },
3291                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3292                 .dac_nids = alc880_asus_dac_nids,
3293                 .dig_out_nid = ALC880_DIGOUT_NID,
3294                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3295                 .channel_mode = alc880_asus_modes,
3296                 .need_dac_fix = 1,
3297                 .input_mux = &alc880_capture_source,
3298         },
3299         [ALC880_UNIWILL_DIG] = {
3300                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3301                 .init_verbs = { alc880_volume_init_verbs,
3302                                 alc880_pin_asus_init_verbs },
3303                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3304                 .dac_nids = alc880_asus_dac_nids,
3305                 .dig_out_nid = ALC880_DIGOUT_NID,
3306                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3307                 .channel_mode = alc880_asus_modes,
3308                 .need_dac_fix = 1,
3309                 .input_mux = &alc880_capture_source,
3310         },
3311         [ALC880_UNIWILL] = {
3312                 .mixers = { alc880_uniwill_mixer },
3313                 .init_verbs = { alc880_volume_init_verbs,
3314                                 alc880_uniwill_init_verbs },
3315                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3316                 .dac_nids = alc880_asus_dac_nids,
3317                 .dig_out_nid = ALC880_DIGOUT_NID,
3318                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3319                 .channel_mode = alc880_threestack_modes,
3320                 .need_dac_fix = 1,
3321                 .input_mux = &alc880_capture_source,
3322                 .unsol_event = alc880_uniwill_unsol_event,
3323                 .init_hook = alc880_uniwill_automute,
3324         },
3325         [ALC880_UNIWILL_P53] = {
3326                 .mixers = { alc880_uniwill_p53_mixer },
3327                 .init_verbs = { alc880_volume_init_verbs,
3328                                 alc880_uniwill_p53_init_verbs },
3329                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3330                 .dac_nids = alc880_asus_dac_nids,
3331                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3332                 .channel_mode = alc880_threestack_modes,
3333                 .input_mux = &alc880_capture_source,
3334                 .unsol_event = alc880_uniwill_p53_unsol_event,
3335                 .init_hook = alc880_uniwill_p53_hp_automute,
3336         },
3337         [ALC880_FUJITSU] = {
3338                 .mixers = { alc880_fujitsu_mixer,
3339                             alc880_pcbeep_mixer, },
3340                 .init_verbs = { alc880_volume_init_verbs,
3341                                 alc880_uniwill_p53_init_verbs,
3342                                 alc880_beep_init_verbs },
3343                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3344                 .dac_nids = alc880_dac_nids,
3345                 .dig_out_nid = ALC880_DIGOUT_NID,
3346                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3347                 .channel_mode = alc880_2_jack_modes,
3348                 .input_mux = &alc880_capture_source,
3349                 .unsol_event = alc880_uniwill_p53_unsol_event,
3350                 .init_hook = alc880_uniwill_p53_hp_automute,
3351         },
3352         [ALC880_CLEVO] = {
3353                 .mixers = { alc880_three_stack_mixer },
3354                 .init_verbs = { alc880_volume_init_verbs,
3355                                 alc880_pin_clevo_init_verbs },
3356                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3357                 .dac_nids = alc880_dac_nids,
3358                 .hp_nid = 0x03,
3359                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3360                 .channel_mode = alc880_threestack_modes,
3361                 .need_dac_fix = 1,
3362                 .input_mux = &alc880_capture_source,
3363         },
3364         [ALC880_LG] = {
3365                 .mixers = { alc880_lg_mixer },
3366                 .init_verbs = { alc880_volume_init_verbs,
3367                                 alc880_lg_init_verbs },
3368                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3369                 .dac_nids = alc880_lg_dac_nids,
3370                 .dig_out_nid = ALC880_DIGOUT_NID,
3371                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3372                 .channel_mode = alc880_lg_ch_modes,
3373                 .need_dac_fix = 1,
3374                 .input_mux = &alc880_lg_capture_source,
3375                 .unsol_event = alc880_lg_unsol_event,
3376                 .init_hook = alc880_lg_automute,
3377 #ifdef CONFIG_SND_HDA_POWER_SAVE
3378                 .loopbacks = alc880_lg_loopbacks,
3379 #endif
3380         },
3381         [ALC880_LG_LW] = {
3382                 .mixers = { alc880_lg_lw_mixer },
3383                 .init_verbs = { alc880_volume_init_verbs,
3384                                 alc880_lg_lw_init_verbs },
3385                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3386                 .dac_nids = alc880_dac_nids,
3387                 .dig_out_nid = ALC880_DIGOUT_NID,
3388                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3389                 .channel_mode = alc880_lg_lw_modes,
3390                 .input_mux = &alc880_lg_lw_capture_source,
3391                 .unsol_event = alc880_lg_lw_unsol_event,
3392                 .init_hook = alc880_lg_lw_automute,
3393         },
3394         [ALC880_MEDION_RIM] = {
3395                 .mixers = { alc880_medion_rim_mixer },
3396                 .init_verbs = { alc880_volume_init_verbs,
3397                                 alc880_medion_rim_init_verbs,
3398                                 alc_gpio2_init_verbs },
3399                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3400                 .dac_nids = alc880_dac_nids,
3401                 .dig_out_nid = ALC880_DIGOUT_NID,
3402                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3403                 .channel_mode = alc880_2_jack_modes,
3404                 .input_mux = &alc880_medion_rim_capture_source,
3405                 .unsol_event = alc880_medion_rim_unsol_event,
3406                 .init_hook = alc880_medion_rim_automute,
3407         },
3408 #ifdef CONFIG_SND_DEBUG
3409         [ALC880_TEST] = {
3410                 .mixers = { alc880_test_mixer },
3411                 .init_verbs = { alc880_test_init_verbs },
3412                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3413                 .dac_nids = alc880_test_dac_nids,
3414                 .dig_out_nid = ALC880_DIGOUT_NID,
3415                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3416                 .channel_mode = alc880_test_modes,
3417                 .input_mux = &alc880_test_capture_source,
3418         },
3419 #endif
3420 };
3421
3422 /*
3423  * Automatic parse of I/O pins from the BIOS configuration
3424  */
3425
3426 #define NUM_CONTROL_ALLOC       32
3427 #define NUM_VERB_ALLOC          32
3428
3429 enum {
3430         ALC_CTL_WIDGET_VOL,
3431         ALC_CTL_WIDGET_MUTE,
3432         ALC_CTL_BIND_MUTE,
3433 };
3434 static struct snd_kcontrol_new alc880_control_templates[] = {
3435         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3436         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3437         HDA_BIND_MUTE(NULL, 0, 0, 0),
3438 };
3439
3440 /* add dynamic controls */
3441 static int add_control(struct alc_spec *spec, int type, const char *name,
3442                        unsigned long val)
3443 {
3444         struct snd_kcontrol_new *knew;
3445
3446         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
3447                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
3448
3449                 /* array + terminator */
3450                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3451                 if (!knew)
3452                         return -ENOMEM;
3453                 if (spec->kctl_alloc) {
3454                         memcpy(knew, spec->kctl_alloc,
3455                                sizeof(*knew) * spec->num_kctl_alloc);
3456                         kfree(spec->kctl_alloc);
3457                 }
3458                 spec->kctl_alloc = knew;
3459                 spec->num_kctl_alloc = num;
3460         }
3461
3462         knew = &spec->kctl_alloc[spec->num_kctl_used];
3463         *knew = alc880_control_templates[type];
3464         knew->name = kstrdup(name, GFP_KERNEL);
3465         if (!knew->name)
3466                 return -ENOMEM;
3467         knew->private_value = val;
3468         spec->num_kctl_used++;
3469         return 0;
3470 }
3471
3472 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3473 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3474 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3475 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3476 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3477 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3478 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3479 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3480 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3481 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3482 #define ALC880_PIN_CD_NID               0x1c
3483
3484 /* fill in the dac_nids table from the parsed pin configuration */
3485 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3486                                      const struct auto_pin_cfg *cfg)
3487 {
3488         hda_nid_t nid;
3489         int assigned[4];
3490         int i, j;
3491
3492         memset(assigned, 0, sizeof(assigned));
3493         spec->multiout.dac_nids = spec->private_dac_nids;
3494
3495         /* check the pins hardwired to audio widget */
3496         for (i = 0; i < cfg->line_outs; i++) {
3497                 nid = cfg->line_out_pins[i];
3498                 if (alc880_is_fixed_pin(nid)) {
3499                         int idx = alc880_fixed_pin_idx(nid);
3500                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3501                         assigned[idx] = 1;
3502                 }
3503         }
3504         /* left pins can be connect to any audio widget */
3505         for (i = 0; i < cfg->line_outs; i++) {
3506                 nid = cfg->line_out_pins[i];
3507                 if (alc880_is_fixed_pin(nid))
3508                         continue;
3509                 /* search for an empty channel */
3510                 for (j = 0; j < cfg->line_outs; j++) {
3511                         if (!assigned[j]) {
3512                                 spec->multiout.dac_nids[i] =
3513                                         alc880_idx_to_dac(j);
3514                                 assigned[j] = 1;
3515                                 break;
3516                         }
3517                 }
3518         }
3519         spec->multiout.num_dacs = cfg->line_outs;
3520         return 0;
3521 }
3522
3523 /* add playback controls from the parsed DAC table */
3524 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3525                                              const struct auto_pin_cfg *cfg)
3526 {
3527         char name[32];
3528         static const char *chname[4] = {
3529                 "Front", "Surround", NULL /*CLFE*/, "Side"
3530         };
3531         hda_nid_t nid;
3532         int i, err;
3533
3534         for (i = 0; i < cfg->line_outs; i++) {
3535                 if (!spec->multiout.dac_nids[i])
3536                         continue;
3537                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3538                 if (i == 2) {
3539                         /* Center/LFE */
3540                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3541                                           "Center Playback Volume",
3542                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3543                                                               HDA_OUTPUT));
3544                         if (err < 0)
3545                                 return err;
3546                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3547                                           "LFE Playback Volume",
3548                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3549                                                               HDA_OUTPUT));
3550                         if (err < 0)
3551                                 return err;
3552                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3553                                           "Center Playback Switch",
3554                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3555                                                               HDA_INPUT));
3556                         if (err < 0)
3557                                 return err;
3558                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3559                                           "LFE Playback Switch",
3560                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3561                                                               HDA_INPUT));
3562                         if (err < 0)
3563                                 return err;
3564                 } else {
3565                         sprintf(name, "%s Playback Volume", chname[i]);
3566                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3567                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3568                                                               HDA_OUTPUT));
3569                         if (err < 0)
3570                                 return err;
3571                         sprintf(name, "%s Playback Switch", chname[i]);
3572                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3573                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3574                                                               HDA_INPUT));
3575                         if (err < 0)
3576                                 return err;
3577                 }
3578         }
3579         return 0;
3580 }
3581
3582 /* add playback controls for speaker and HP outputs */
3583 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3584                                         const char *pfx)
3585 {
3586         hda_nid_t nid;
3587         int err;
3588         char name[32];
3589
3590         if (!pin)
3591                 return 0;
3592
3593         if (alc880_is_fixed_pin(pin)) {
3594                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3595                 /* specify the DAC as the extra output */
3596                 if (!spec->multiout.hp_nid)
3597                         spec->multiout.hp_nid = nid;
3598                 else
3599                         spec->multiout.extra_out_nid[0] = nid;
3600                 /* control HP volume/switch on the output mixer amp */
3601                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3602                 sprintf(name, "%s Playback Volume", pfx);
3603                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3604                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3605                 if (err < 0)
3606                         return err;
3607                 sprintf(name, "%s Playback Switch", pfx);
3608                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3609                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3610                 if (err < 0)
3611                         return err;
3612         } else if (alc880_is_multi_pin(pin)) {
3613                 /* set manual connection */
3614                 /* we have only a switch on HP-out PIN */
3615                 sprintf(name, "%s Playback Switch", pfx);
3616                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3617                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3618                 if (err < 0)
3619                         return err;
3620         }
3621         return 0;
3622 }
3623
3624 /* create input playback/capture controls for the given pin */
3625 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3626                             const char *ctlname,
3627                             int idx, hda_nid_t mix_nid)
3628 {
3629         char name[32];
3630         int err;
3631
3632         sprintf(name, "%s Playback Volume", ctlname);
3633         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3634                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3635         if (err < 0)
3636                 return err;
3637         sprintf(name, "%s Playback Switch", ctlname);
3638         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3639                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3640         if (err < 0)
3641                 return err;
3642         return 0;
3643 }
3644
3645 /* create playback/capture controls for input pins */
3646 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3647                                                 const struct auto_pin_cfg *cfg)
3648 {
3649         struct hda_input_mux *imux = &spec->private_imux;
3650         int i, err, idx;
3651
3652         for (i = 0; i < AUTO_PIN_LAST; i++) {
3653                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3654                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3655                         err = new_analog_input(spec, cfg->input_pins[i],
3656                                                auto_pin_cfg_labels[i],
3657                                                idx, 0x0b);
3658                         if (err < 0)
3659                                 return err;
3660                         imux->items[imux->num_items].label =
3661                                 auto_pin_cfg_labels[i];
3662                         imux->items[imux->num_items].index =
3663                                 alc880_input_pin_idx(cfg->input_pins[i]);
3664                         imux->num_items++;
3665                 }
3666         }
3667         return 0;
3668 }
3669
3670 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3671                                unsigned int pin_type)
3672 {
3673         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3674                             pin_type);
3675         /* unmute pin */
3676         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3677                             AMP_OUT_UNMUTE);
3678 }
3679
3680 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3681                                               hda_nid_t nid, int pin_type,
3682                                               int dac_idx)
3683 {
3684         alc_set_pin_output(codec, nid, pin_type);
3685         /* need the manual connection? */
3686         if (alc880_is_multi_pin(nid)) {
3687                 struct alc_spec *spec = codec->spec;
3688                 int idx = alc880_multi_pin_idx(nid);
3689                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3690                                     AC_VERB_SET_CONNECT_SEL,
3691                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3692         }
3693 }
3694
3695 static int get_pin_type(int line_out_type)
3696 {
3697         if (line_out_type == AUTO_PIN_HP_OUT)
3698                 return PIN_HP;
3699         else
3700                 return PIN_OUT;
3701 }
3702
3703 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3704 {
3705         struct alc_spec *spec = codec->spec;
3706         int i;
3707
3708         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3709         for (i = 0; i < spec->autocfg.line_outs; i++) {
3710                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3711                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3712                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3713         }
3714 }
3715
3716 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3717 {
3718         struct alc_spec *spec = codec->spec;
3719         hda_nid_t pin;
3720
3721         pin = spec->autocfg.speaker_pins[0];
3722         if (pin) /* connect to front */
3723                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3724         pin = spec->autocfg.hp_pins[0];
3725         if (pin) /* connect to front */
3726                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3727 }
3728
3729 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3730 {
3731         struct alc_spec *spec = codec->spec;
3732         int i;
3733
3734         for (i = 0; i < AUTO_PIN_LAST; i++) {
3735                 hda_nid_t nid = spec->autocfg.input_pins[i];
3736                 if (alc880_is_input_pin(nid)) {
3737                         snd_hda_codec_write(codec, nid, 0,
3738                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3739                                             i <= AUTO_PIN_FRONT_MIC ?
3740                                             PIN_VREF80 : PIN_IN);
3741                         if (nid != ALC880_PIN_CD_NID)
3742                                 snd_hda_codec_write(codec, nid, 0,
3743                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3744                                                     AMP_OUT_MUTE);
3745                 }
3746         }
3747 }
3748
3749 /* parse the BIOS configuration and set up the alc_spec */
3750 /* return 1 if successful, 0 if the proper config is not found,
3751  * or a negative error code
3752  */
3753 static int alc880_parse_auto_config(struct hda_codec *codec)
3754 {
3755         struct alc_spec *spec = codec->spec;
3756         int err;
3757         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3758
3759         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3760                                            alc880_ignore);
3761         if (err < 0)
3762                 return err;
3763         if (!spec->autocfg.line_outs)
3764                 return 0; /* can't find valid BIOS pin config */
3765
3766         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3767         if (err < 0)
3768                 return err;
3769         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3770         if (err < 0)
3771                 return err;
3772         err = alc880_auto_create_extra_out(spec,
3773                                            spec->autocfg.speaker_pins[0],
3774                                            "Speaker");
3775         if (err < 0)
3776                 return err;
3777         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3778                                            "Headphone");
3779         if (err < 0)
3780                 return err;
3781         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3782         if (err < 0)
3783                 return err;
3784
3785         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3786
3787         if (spec->autocfg.dig_out_pin)
3788                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3789         if (spec->autocfg.dig_in_pin)
3790                 spec->dig_in_nid = ALC880_DIGIN_NID;
3791
3792         if (spec->kctl_alloc)
3793                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3794
3795         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3796
3797         spec->num_mux_defs = 1;
3798         spec->input_mux = &spec->private_imux;
3799
3800         return 1;
3801 }
3802
3803 /* additional initialization for auto-configuration model */
3804 static void alc880_auto_init(struct hda_codec *codec)
3805 {
3806         struct alc_spec *spec = codec->spec;
3807         alc880_auto_init_multi_out(codec);
3808         alc880_auto_init_extra_out(codec);
3809         alc880_auto_init_analog_input(codec);
3810         if (spec->unsol_event)
3811                 alc_sku_automute(codec);
3812 }
3813
3814 /*
3815  * OK, here we have finally the patch for ALC880
3816  */
3817
3818 static int patch_alc880(struct hda_codec *codec)
3819 {
3820         struct alc_spec *spec;
3821         int board_config;
3822         int err;
3823
3824         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3825         if (spec == NULL)
3826                 return -ENOMEM;
3827
3828         codec->spec = spec;
3829
3830         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3831                                                   alc880_models,
3832                                                   alc880_cfg_tbl);
3833         if (board_config < 0) {
3834                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3835                        "trying auto-probe from BIOS...\n");
3836                 board_config = ALC880_AUTO;
3837         }
3838
3839         if (board_config == ALC880_AUTO) {
3840                 /* automatic parse from the BIOS config */
3841                 err = alc880_parse_auto_config(codec);
3842                 if (err < 0) {
3843                         alc_free(codec);
3844                         return err;
3845                 } else if (!err) {
3846                         printk(KERN_INFO
3847                                "hda_codec: Cannot set up configuration "
3848                                "from BIOS.  Using 3-stack mode...\n");
3849                         board_config = ALC880_3ST;
3850                 }
3851         }
3852
3853         if (board_config != ALC880_AUTO)
3854                 setup_preset(spec, &alc880_presets[board_config]);
3855
3856         spec->stream_name_analog = "ALC880 Analog";
3857         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3858         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3859         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
3860
3861         spec->stream_name_digital = "ALC880 Digital";
3862         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3863         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3864
3865         if (!spec->adc_nids && spec->input_mux) {
3866                 /* check whether NID 0x07 is valid */
3867                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3868                 /* get type */
3869                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3870                 if (wcap != AC_WID_AUD_IN) {
3871                         spec->adc_nids = alc880_adc_nids_alt;
3872                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3873                         spec->mixers[spec->num_mixers] =
3874                                 alc880_capture_alt_mixer;
3875                         spec->num_mixers++;
3876                 } else {
3877                         spec->adc_nids = alc880_adc_nids;
3878                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3879                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3880                         spec->num_mixers++;
3881                 }
3882         }
3883
3884         spec->vmaster_nid = 0x0c;
3885
3886         codec->patch_ops = alc_patch_ops;
3887         if (board_config == ALC880_AUTO)
3888                 spec->init_hook = alc880_auto_init;
3889 #ifdef CONFIG_SND_HDA_POWER_SAVE
3890         if (!spec->loopback.amplist)
3891                 spec->loopback.amplist = alc880_loopbacks;
3892 #endif
3893
3894         return 0;
3895 }
3896
3897
3898 /*
3899  * ALC260 support
3900  */
3901
3902 static hda_nid_t alc260_dac_nids[1] = {
3903         /* front */
3904         0x02,
3905 };
3906
3907 static hda_nid_t alc260_adc_nids[1] = {
3908         /* ADC0 */
3909         0x04,
3910 };
3911
3912 static hda_nid_t alc260_adc_nids_alt[1] = {
3913         /* ADC1 */
3914         0x05,
3915 };
3916
3917 static hda_nid_t alc260_hp_adc_nids[2] = {
3918         /* ADC1, 0 */
3919         0x05, 0x04
3920 };
3921
3922 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3923  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3924  */
3925 static hda_nid_t alc260_dual_adc_nids[2] = {
3926         /* ADC0, ADC1 */
3927         0x04, 0x05
3928 };
3929
3930 #define ALC260_DIGOUT_NID       0x03
3931 #define ALC260_DIGIN_NID        0x06
3932
3933 static struct hda_input_mux alc260_capture_source = {
3934         .num_items = 4,
3935         .items = {
3936                 { "Mic", 0x0 },
3937                 { "Front Mic", 0x1 },
3938                 { "Line", 0x2 },
3939                 { "CD", 0x4 },
3940         },
3941 };
3942
3943 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3944  * headphone jack and the internal CD lines since these are the only pins at
3945  * which audio can appear.  For flexibility, also allow the option of
3946  * recording the mixer output on the second ADC (ADC0 doesn't have a
3947  * connection to the mixer output).
3948  */
3949 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3950         {
3951                 .num_items = 3,
3952                 .items = {
3953                         { "Mic/Line", 0x0 },
3954                         { "CD", 0x4 },
3955                         { "Headphone", 0x2 },
3956                 },
3957         },
3958         {
3959                 .num_items = 4,
3960                 .items = {
3961                         { "Mic/Line", 0x0 },
3962                         { "CD", 0x4 },
3963                         { "Headphone", 0x2 },
3964                         { "Mixer", 0x5 },
3965                 },
3966         },
3967
3968 };
3969
3970 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3971  * the Fujitsu S702x, but jacks are marked differently.
3972  */
3973 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3974         {
3975                 .num_items = 4,
3976                 .items = {
3977                         { "Mic", 0x0 },
3978                         { "Line", 0x2 },
3979                         { "CD", 0x4 },
3980                         { "Headphone", 0x5 },
3981                 },
3982         },
3983         {
3984                 .num_items = 5,
3985                 .items = {
3986                         { "Mic", 0x0 },
3987                         { "Line", 0x2 },
3988                         { "CD", 0x4 },
3989                         { "Headphone", 0x6 },
3990                         { "Mixer", 0x5 },
3991                 },
3992         },
3993 };
3994 /*
3995  * This is just place-holder, so there's something for alc_build_pcms to look
3996  * at when it calculates the maximum number of channels. ALC260 has no mixer
3997  * element which allows changing the channel mode, so the verb list is
3998  * never used.
3999  */
4000 static struct hda_channel_mode alc260_modes[1] = {
4001         { 2, NULL },
4002 };
4003
4004
4005 /* Mixer combinations
4006  *
4007  * basic: base_output + input + pc_beep + capture
4008  * HP: base_output + input + capture_alt
4009  * HP_3013: hp_3013 + input + capture
4010  * fujitsu: fujitsu + capture
4011  * acer: acer + capture
4012  */
4013
4014 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4015         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4016         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4017         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4018         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4019         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4020         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4021         { } /* end */
4022 };
4023
4024 static struct snd_kcontrol_new alc260_input_mixer[] = {
4025         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4026         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4027         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4028         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4029         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4030         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4031         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4032         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4033         { } /* end */
4034 };
4035
4036 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4037         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4038         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4039         { } /* end */
4040 };
4041
4042 /* update HP, line and mono out pins according to the master switch */
4043 static void alc260_hp_master_update(struct hda_codec *codec,
4044                                     hda_nid_t hp, hda_nid_t line,
4045                                     hda_nid_t mono)
4046 {
4047         struct alc_spec *spec = codec->spec;
4048         unsigned int val = spec->master_sw ? PIN_HP : 0;
4049         /* change HP and line-out pins */
4050         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4051                             val);
4052         snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4053                             val);
4054         /* mono (speaker) depending on the HP jack sense */
4055         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4056         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4057                             val);
4058 }
4059
4060 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4061                                    struct snd_ctl_elem_value *ucontrol)
4062 {
4063         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4064         struct alc_spec *spec = codec->spec;
4065         *ucontrol->value.integer.value = spec->master_sw;
4066         return 0;
4067 }
4068
4069 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4070                                    struct snd_ctl_elem_value *ucontrol)
4071 {
4072         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4073         struct alc_spec *spec = codec->spec;
4074         int val = !!*ucontrol->value.integer.value;
4075         hda_nid_t hp, line, mono;
4076
4077         if (val == spec->master_sw)
4078                 return 0;
4079         spec->master_sw = val;
4080         hp = (kcontrol->private_value >> 16) & 0xff;
4081         line = (kcontrol->private_value >> 8) & 0xff;
4082         mono = kcontrol->private_value & 0xff;
4083         alc260_hp_master_update(codec, hp, line, mono);
4084         return 1;
4085 }
4086
4087 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4088         {
4089                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4090                 .name = "Master Playback Switch",
4091                 .info = snd_ctl_boolean_mono_info,
4092                 .get = alc260_hp_master_sw_get,
4093                 .put = alc260_hp_master_sw_put,
4094                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4095         },
4096         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4097         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4098         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4099         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4100         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4101                               HDA_OUTPUT),
4102         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4103         { } /* end */
4104 };
4105
4106 static struct hda_verb alc260_hp_unsol_verbs[] = {
4107         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4108         {},
4109 };
4110
4111 static void alc260_hp_automute(struct hda_codec *codec)
4112 {
4113         struct alc_spec *spec = codec->spec;
4114         unsigned int present;
4115
4116         present = snd_hda_codec_read(codec, 0x10, 0,
4117                                      AC_VERB_GET_PIN_SENSE, 0);
4118         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4119         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4120 }
4121
4122 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4123 {
4124         if ((res >> 26) == ALC880_HP_EVENT)
4125                 alc260_hp_automute(codec);
4126 }
4127
4128 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4129         {
4130                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4131                 .name = "Master Playback Switch",
4132                 .info = snd_ctl_boolean_mono_info,
4133                 .get = alc260_hp_master_sw_get,
4134                 .put = alc260_hp_master_sw_put,
4135                 .private_value = (0x10 << 16) | (0x15 << 8) | 0x11
4136         },
4137         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4138         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4139         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4140         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4141         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4142         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4143         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4144         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4145         { } /* end */
4146 };
4147
4148 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4149         .ops = &snd_hda_bind_vol,
4150         .values = {
4151                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4152                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4153                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4154                 0
4155         },
4156 };
4157
4158 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4159         .ops = &snd_hda_bind_sw,
4160         .values = {
4161                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4162                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4163                 0
4164         },
4165 };
4166
4167 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4168         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4169         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4170         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4171         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4172         { } /* end */
4173 };
4174
4175 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4176         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4177         {},
4178 };
4179
4180 static void alc260_hp_3013_automute(struct hda_codec *codec)
4181 {
4182         struct alc_spec *spec = codec->spec;
4183         unsigned int present;
4184
4185         present = snd_hda_codec_read(codec, 0x15, 0,
4186                                      AC_VERB_GET_PIN_SENSE, 0);
4187         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4188         alc260_hp_master_update(codec, 0x10, 0x15, 0x11);
4189 }
4190
4191 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4192                                        unsigned int res)
4193 {
4194         if ((res >> 26) == ALC880_HP_EVENT)
4195                 alc260_hp_3013_automute(codec);
4196 }
4197
4198 static void alc260_hp_3012_automute(struct hda_codec *codec)
4199 {
4200         unsigned int present, bits;
4201
4202         present = snd_hda_codec_read(codec, 0x10, 0,
4203                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4204
4205         bits = present ? 0 : PIN_OUT;
4206         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4207                             bits);
4208         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4209                             bits);
4210         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4211                             bits);
4212 }
4213
4214 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4215                                        unsigned int res)
4216 {
4217         if ((res >> 26) == ALC880_HP_EVENT)
4218                 alc260_hp_3012_automute(codec);
4219 }
4220
4221 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4222  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4223  */
4224 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4225         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4226         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4227         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4228         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4229         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4230         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4231         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4232         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4233         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4234         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4235         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4236         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4237         { } /* end */
4238 };
4239
4240 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4241  * versions of the ALC260 don't act on requests to enable mic bias from NID
4242  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4243  * datasheet doesn't mention this restriction.  At this stage it's not clear
4244  * whether this behaviour is intentional or is a hardware bug in chip
4245  * revisions available in early 2006.  Therefore for now allow the
4246  * "Headphone Jack Mode" control to span all choices, but if it turns out
4247  * that the lack of mic bias for this NID is intentional we could change the
4248  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4249  *
4250  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4251  * don't appear to make the mic bias available from the "line" jack, even
4252  * though the NID used for this jack (0x14) can supply it.  The theory is
4253  * that perhaps Acer have included blocking capacitors between the ALC260
4254  * and the output jack.  If this turns out to be the case for all such
4255  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4256  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4257  *
4258  * The C20x Tablet series have a mono internal speaker which is controlled
4259  * via the chip's Mono sum widget and pin complex, so include the necessary
4260  * controls for such models.  On models without a "mono speaker" the control
4261  * won't do anything.
4262  */
4263 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4264         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4265         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4266         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4267         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4268                               HDA_OUTPUT),
4269         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4270                            HDA_INPUT),
4271         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4272         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4273         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4274         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4275         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4276         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4277         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4278         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4279         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4280         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4281         { } /* end */
4282 };
4283
4284 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4285  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4286  */
4287 static struct snd_kcontrol_new alc260_will_mixer[] = {
4288         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4289         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4290         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4291         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4292         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4293         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4294         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4295         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4296         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4297         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4298         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4299         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4300         { } /* end */
4301 };
4302
4303 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4304  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4305  */
4306 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4307         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4308         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4309         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4310         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4311         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4312         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4313         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4314         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4315         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4316         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4317         { } /* end */
4318 };
4319
4320 /* capture mixer elements */
4321 static struct snd_kcontrol_new alc260_capture_mixer[] = {
4322         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
4323         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
4324         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
4325         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
4326         {
4327                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4328                 /* The multiple "Capture Source" controls confuse alsamixer
4329                  * So call somewhat different..
4330                  */
4331                 /* .name = "Capture Source", */
4332                 .name = "Input Source",
4333                 .count = 2,
4334                 .info = alc_mux_enum_info,
4335                 .get = alc_mux_enum_get,
4336                 .put = alc_mux_enum_put,
4337         },
4338         { } /* end */
4339 };
4340
4341 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
4342         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
4343         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
4344         {
4345                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4346                 /* The multiple "Capture Source" controls confuse alsamixer
4347                  * So call somewhat different..
4348                  */
4349                 /* .name = "Capture Source", */
4350                 .name = "Input Source",
4351                 .count = 1,
4352                 .info = alc_mux_enum_info,
4353                 .get = alc_mux_enum_get,
4354                 .put = alc_mux_enum_put,
4355         },
4356         { } /* end */
4357 };
4358
4359 /*
4360  * initialization verbs
4361  */
4362 static struct hda_verb alc260_init_verbs[] = {
4363         /* Line In pin widget for input */
4364         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4365         /* CD pin widget for input */
4366         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4367         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4368         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4369         /* Mic2 (front panel) pin widget for input and vref at 80% */
4370         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4371         /* LINE-2 is used for line-out in rear */
4372         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4373         /* select line-out */
4374         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4375         /* LINE-OUT pin */
4376         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4377         /* enable HP */
4378         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4379         /* enable Mono */
4380         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4381         /* mute capture amp left and right */
4382         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4383         /* set connection select to line in (default select for this ADC) */
4384         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4385         /* mute capture amp left and right */
4386         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4387         /* set connection select to line in (default select for this ADC) */
4388         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4389         /* set vol=0 Line-Out mixer amp left and right */
4390         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4391         /* unmute pin widget amp left and right (no gain on this amp) */
4392         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4393         /* set vol=0 HP mixer amp left and right */
4394         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4395         /* unmute pin widget amp left and right (no gain on this amp) */
4396         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4397         /* set vol=0 Mono mixer amp left and right */
4398         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4399         /* unmute pin widget amp left and right (no gain on this amp) */
4400         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4401         /* unmute LINE-2 out pin */
4402         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4403         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4404          * Line In 2 = 0x03
4405          */
4406         /* mute analog inputs */
4407         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4408         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4409         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4410         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4411         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4412         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4413         /* mute Front out path */
4414         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4415         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4416         /* mute Headphone out path */
4417         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4418         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4419         /* mute Mono out path */
4420         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4421         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4422         { }
4423 };
4424
4425 #if 0 /* should be identical with alc260_init_verbs? */
4426 static struct hda_verb alc260_hp_init_verbs[] = {
4427         /* Headphone and output */
4428         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4429         /* mono output */
4430         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4431         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4432         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4433         /* Mic2 (front panel) pin widget for input and vref at 80% */
4434         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4435         /* Line In pin widget for input */
4436         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4437         /* Line-2 pin widget for output */
4438         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4439         /* CD pin widget for input */
4440         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4441         /* unmute amp left and right */
4442         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4443         /* set connection select to line in (default select for this ADC) */
4444         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4445         /* unmute Line-Out mixer amp left and right (volume = 0) */
4446         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4447         /* mute pin widget amp left and right (no gain on this amp) */
4448         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4449         /* unmute HP mixer amp left and right (volume = 0) */
4450         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4451         /* mute pin widget amp left and right (no gain on this amp) */
4452         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4453         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4454          * Line In 2 = 0x03
4455          */
4456         /* mute analog inputs */
4457         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4458         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4459         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4460         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4461         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4462         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4463         /* Unmute Front out path */
4464         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4465         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4466         /* Unmute Headphone out path */
4467         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4468         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4469         /* Unmute Mono out path */
4470         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4471         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4472         { }
4473 };
4474 #endif
4475
4476 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4477         /* Line out and output */
4478         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4479         /* mono output */
4480         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4481         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4482         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4483         /* Mic2 (front panel) pin widget for input and vref at 80% */
4484         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4485         /* Line In pin widget for input */
4486         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4487         /* Headphone pin widget for output */
4488         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4489         /* CD pin widget for input */
4490         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4491         /* unmute amp left and right */
4492         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4493         /* set connection select to line in (default select for this ADC) */
4494         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4495         /* unmute Line-Out mixer amp left and right (volume = 0) */
4496         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4497         /* mute pin widget amp left and right (no gain on this amp) */
4498         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4499         /* unmute HP mixer amp left and right (volume = 0) */
4500         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4501         /* mute pin widget amp left and right (no gain on this amp) */
4502         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4503         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4504          * Line In 2 = 0x03
4505          */
4506         /* mute analog inputs */
4507         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4508         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4509         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4510         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4511         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4512         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4513         /* Unmute Front out path */
4514         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4515         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4516         /* Unmute Headphone out path */
4517         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4518         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4519         /* Unmute Mono out path */
4520         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4521         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4522         { }
4523 };
4524
4525 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4526  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4527  * audio = 0x16, internal speaker = 0x10.
4528  */
4529 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4530         /* Disable all GPIOs */
4531         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4532         /* Internal speaker is connected to headphone pin */
4533         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4534         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4535         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4536         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4537         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4538         /* Ensure all other unused pins are disabled and muted. */
4539         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4540         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4541         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4542         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4543         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4544         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4545         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4546         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4547
4548         /* Disable digital (SPDIF) pins */
4549         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4550         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4551
4552         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
4553          * when acting as an output.
4554          */
4555         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4556
4557         /* Start with output sum widgets muted and their output gains at min */
4558         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4559         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4560         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4561         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4562         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4563         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4564         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4565         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4566         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4567
4568         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4569         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4570         /* Unmute Line1 pin widget output buffer since it starts as an output.
4571          * If the pin mode is changed by the user the pin mode control will
4572          * take care of enabling the pin's input/output buffers as needed.
4573          * Therefore there's no need to enable the input buffer at this
4574          * stage.
4575          */
4576         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4577         /* Unmute input buffer of pin widget used for Line-in (no equiv
4578          * mixer ctrl)
4579          */
4580         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4581
4582         /* Mute capture amp left and right */
4583         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4584         /* Set ADC connection select to match default mixer setting - line
4585          * in (on mic1 pin)
4586          */
4587         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4588
4589         /* Do the same for the second ADC: mute capture input amp and
4590          * set ADC connection to line in (on mic1 pin)
4591          */
4592         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4593         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4594
4595         /* Mute all inputs to mixer widget (even unconnected ones) */
4596         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4597         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4598         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4599         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4600         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4601         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4602         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4603         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4604
4605         { }
4606 };
4607
4608 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4609  * similar laptops (adapted from Fujitsu init verbs).
4610  */
4611 static struct hda_verb alc260_acer_init_verbs[] = {
4612         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4613          * the headphone jack.  Turn this on and rely on the standard mute
4614          * methods whenever the user wants to turn these outputs off.
4615          */
4616         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4617         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4618         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4619         /* Internal speaker/Headphone jack is connected to Line-out pin */
4620         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4621         /* Internal microphone/Mic jack is connected to Mic1 pin */
4622         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4623         /* Line In jack is connected to Line1 pin */
4624         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4625         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4626         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4627         /* Ensure all other unused pins are disabled and muted. */
4628         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4629         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4630         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4631         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4632         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4633         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4634         /* Disable digital (SPDIF) pins */
4635         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4636         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4637
4638         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
4639          * bus when acting as outputs.
4640          */
4641         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4642         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4643
4644         /* Start with output sum widgets muted and their output gains at min */
4645         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4646         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4647         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4648         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4649         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4650         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4651         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4652         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4653         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4654
4655         /* Unmute Line-out pin widget amp left and right
4656          * (no equiv mixer ctrl)
4657          */
4658         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4659         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4660         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4661         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4662          * inputs. If the pin mode is changed by the user the pin mode control
4663          * will take care of enabling the pin's input/output buffers as needed.
4664          * Therefore there's no need to enable the input buffer at this
4665          * stage.
4666          */
4667         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4668         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4669
4670         /* Mute capture amp left and right */
4671         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4672         /* Set ADC connection select to match default mixer setting - mic
4673          * (on mic1 pin)
4674          */
4675         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4676
4677         /* Do similar with the second ADC: mute capture input amp and
4678          * set ADC connection to mic to match ALSA's default state.
4679          */
4680         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4681         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4682
4683         /* Mute all inputs to mixer widget (even unconnected ones) */
4684         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4685         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4686         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4687         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4688         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4689         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4690         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4691         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4692
4693         { }
4694 };
4695
4696 static struct hda_verb alc260_will_verbs[] = {
4697         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4698         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4699         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4700         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4701         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4702         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4703         {}
4704 };
4705
4706 static struct hda_verb alc260_replacer_672v_verbs[] = {
4707         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4708         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4709         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4710
4711         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4712         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4713         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4714
4715         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4716         {}
4717 };
4718
4719 /* toggle speaker-output according to the hp-jack state */
4720 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4721 {
4722         unsigned int present;
4723
4724         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4725         present = snd_hda_codec_read(codec, 0x0f, 0,
4726                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4727         if (present) {
4728                 snd_hda_codec_write_cache(codec, 0x01, 0,
4729                                           AC_VERB_SET_GPIO_DATA, 1);
4730                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4731                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4732                                           PIN_HP);
4733         } else {
4734                 snd_hda_codec_write_cache(codec, 0x01, 0,
4735                                           AC_VERB_SET_GPIO_DATA, 0);
4736                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4737                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4738                                           PIN_OUT);
4739         }
4740 }
4741
4742 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4743                                        unsigned int res)
4744 {
4745         if ((res >> 26) == ALC880_HP_EVENT)
4746                 alc260_replacer_672v_automute(codec);
4747 }
4748
4749 static struct hda_verb alc260_hp_dc7600_verbs[] = {
4750         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
4751         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
4752         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4753         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4754         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4755         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4756         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4757         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4758         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4759         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4760         {}
4761 };
4762
4763 /* Test configuration for debugging, modelled after the ALC880 test
4764  * configuration.
4765  */
4766 #ifdef CONFIG_SND_DEBUG
4767 static hda_nid_t alc260_test_dac_nids[1] = {
4768         0x02,
4769 };
4770 static hda_nid_t alc260_test_adc_nids[2] = {
4771         0x04, 0x05,
4772 };
4773 /* For testing the ALC260, each input MUX needs its own definition since
4774  * the signal assignments are different.  This assumes that the first ADC
4775  * is NID 0x04.
4776  */
4777 static struct hda_input_mux alc260_test_capture_sources[2] = {
4778         {
4779                 .num_items = 7,
4780                 .items = {
4781                         { "MIC1 pin", 0x0 },
4782                         { "MIC2 pin", 0x1 },
4783                         { "LINE1 pin", 0x2 },
4784                         { "LINE2 pin", 0x3 },
4785                         { "CD pin", 0x4 },
4786                         { "LINE-OUT pin", 0x5 },
4787                         { "HP-OUT pin", 0x6 },
4788                 },
4789         },
4790         {
4791                 .num_items = 8,
4792                 .items = {
4793                         { "MIC1 pin", 0x0 },
4794                         { "MIC2 pin", 0x1 },
4795                         { "LINE1 pin", 0x2 },
4796                         { "LINE2 pin", 0x3 },
4797                         { "CD pin", 0x4 },
4798                         { "Mixer", 0x5 },
4799                         { "LINE-OUT pin", 0x6 },
4800                         { "HP-OUT pin", 0x7 },
4801                 },
4802         },
4803 };
4804 static struct snd_kcontrol_new alc260_test_mixer[] = {
4805         /* Output driver widgets */
4806         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4807         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4808         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4809         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4810         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4811         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4812
4813         /* Modes for retasking pin widgets
4814          * Note: the ALC260 doesn't seem to act on requests to enable mic
4815          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4816          * mention this restriction.  At this stage it's not clear whether
4817          * this behaviour is intentional or is a hardware bug in chip
4818          * revisions available at least up until early 2006.  Therefore for
4819          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4820          * choices, but if it turns out that the lack of mic bias for these
4821          * NIDs is intentional we could change their modes from
4822          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4823          */
4824         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4825         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4826         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4827         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4828         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4829         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4830
4831         /* Loopback mixer controls */
4832         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4833         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4834         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4835         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4836         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4837         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4838         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4839         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4840         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4841         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4842         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4843         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4844         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4845         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4846         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4847         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4848
4849         /* Controls for GPIO pins, assuming they are configured as outputs */
4850         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4851         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4852         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4853         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4854
4855         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4856          * is ambigious as to which NID is which; testing on laptops which
4857          * make this output available should provide clarification.
4858          */
4859         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4860         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4861
4862         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
4863          * this output to turn on an external amplifier.
4864          */
4865         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
4866         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
4867
4868         { } /* end */
4869 };
4870 static struct hda_verb alc260_test_init_verbs[] = {
4871         /* Enable all GPIOs as outputs with an initial value of 0 */
4872         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4873         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4874         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4875
4876         /* Enable retasking pins as output, initially without power amp */
4877         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4878         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4879         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4880         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4881         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4882         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4883
4884         /* Disable digital (SPDIF) pins initially, but users can enable
4885          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4886          * payload also sets the generation to 0, output to be in "consumer"
4887          * PCM format, copyright asserted, no pre-emphasis and no validity
4888          * control.
4889          */
4890         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4891         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4892
4893         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
4894          * OUT1 sum bus when acting as an output.
4895          */
4896         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4897         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4898         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4899         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4900
4901         /* Start with output sum widgets muted and their output gains at min */
4902         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4903         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4904         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4905         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4906         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4907         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4908         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4909         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4910         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4911
4912         /* Unmute retasking pin widget output buffers since the default
4913          * state appears to be output.  As the pin mode is changed by the
4914          * user the pin mode control will take care of enabling the pin's
4915          * input/output buffers as needed.
4916          */
4917         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4918         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4919         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4920         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4921         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4922         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4923         /* Also unmute the mono-out pin widget */
4924         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4925
4926         /* Mute capture amp left and right */
4927         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4928         /* Set ADC connection select to match default mixer setting (mic1
4929          * pin)
4930          */
4931         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4932
4933         /* Do the same for the second ADC: mute capture input amp and
4934          * set ADC connection to mic1 pin
4935          */
4936         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4937         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4938
4939         /* Mute all inputs to mixer widget (even unconnected ones) */
4940         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4941         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4942         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4943         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4944         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4945         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4946         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4947         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4948
4949         { }
4950 };
4951 #endif
4952
4953 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
4954 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
4955
4956 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4957 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4958
4959 /*
4960  * for BIOS auto-configuration
4961  */
4962
4963 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4964                                         const char *pfx)
4965 {
4966         hda_nid_t nid_vol;
4967         unsigned long vol_val, sw_val;
4968         char name[32];
4969         int err;
4970
4971         if (nid >= 0x0f && nid < 0x11) {
4972                 nid_vol = nid - 0x7;
4973                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4974                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4975         } else if (nid == 0x11) {
4976                 nid_vol = nid - 0x7;
4977                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4978                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4979         } else if (nid >= 0x12 && nid <= 0x15) {
4980                 nid_vol = 0x08;
4981                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4982                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4983         } else
4984                 return 0; /* N/A */
4985
4986         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4987         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4988         if (err < 0)
4989                 return err;
4990         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4991         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4992         if (err < 0)
4993                 return err;
4994         return 1;
4995 }
4996
4997 /* add playback controls from the parsed DAC table */
4998 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4999                                              const struct auto_pin_cfg *cfg)
5000 {
5001         hda_nid_t nid;
5002         int err;
5003
5004         spec->multiout.num_dacs = 1;
5005         spec->multiout.dac_nids = spec->private_dac_nids;
5006         spec->multiout.dac_nids[0] = 0x02;
5007
5008         nid = cfg->line_out_pins[0];
5009         if (nid) {
5010                 err = alc260_add_playback_controls(spec, nid, "Front");
5011                 if (err < 0)
5012                         return err;
5013         }
5014
5015         nid = cfg->speaker_pins[0];
5016         if (nid) {
5017                 err = alc260_add_playback_controls(spec, nid, "Speaker");
5018                 if (err < 0)
5019                         return err;
5020         }
5021
5022         nid = cfg->hp_pins[0];
5023         if (nid) {
5024                 err = alc260_add_playback_controls(spec, nid, "Headphone");
5025                 if (err < 0)
5026                         return err;
5027         }
5028         return 0;
5029 }
5030
5031 /* create playback/capture controls for input pins */
5032 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5033                                                 const struct auto_pin_cfg *cfg)
5034 {
5035         struct hda_input_mux *imux = &spec->private_imux;
5036         int i, err, idx;
5037
5038         for (i = 0; i < AUTO_PIN_LAST; i++) {
5039                 if (cfg->input_pins[i] >= 0x12) {
5040                         idx = cfg->input_pins[i] - 0x12;
5041                         err = new_analog_input(spec, cfg->input_pins[i],
5042                                                auto_pin_cfg_labels[i], idx,
5043                                                0x07);
5044                         if (err < 0)
5045                                 return err;
5046                         imux->items[imux->num_items].label =
5047                                 auto_pin_cfg_labels[i];
5048                         imux->items[imux->num_items].index = idx;
5049                         imux->num_items++;
5050                 }
5051                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5052                         idx = cfg->input_pins[i] - 0x09;
5053                         err = new_analog_input(spec, cfg->input_pins[i],
5054                                                auto_pin_cfg_labels[i], idx,
5055                                                0x07);
5056                         if (err < 0)
5057                                 return err;
5058                         imux->items[imux->num_items].label =
5059                                 auto_pin_cfg_labels[i];
5060                         imux->items[imux->num_items].index = idx;
5061                         imux->num_items++;
5062                 }
5063         }
5064         return 0;
5065 }
5066
5067 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5068                                               hda_nid_t nid, int pin_type,
5069                                               int sel_idx)
5070 {
5071         alc_set_pin_output(codec, nid, pin_type);
5072         /* need the manual connection? */
5073         if (nid >= 0x12) {
5074                 int idx = nid - 0x12;
5075                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5076                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5077         }
5078 }
5079
5080 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5081 {
5082         struct alc_spec *spec = codec->spec;
5083         hda_nid_t nid;
5084
5085         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5086         nid = spec->autocfg.line_out_pins[0];
5087         if (nid) {
5088                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5089                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5090         }
5091
5092         nid = spec->autocfg.speaker_pins[0];
5093         if (nid)
5094                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5095
5096         nid = spec->autocfg.hp_pins[0];
5097         if (nid)
5098                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5099 }
5100
5101 #define ALC260_PIN_CD_NID               0x16
5102 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5103 {
5104         struct alc_spec *spec = codec->spec;
5105         int i;
5106
5107         for (i = 0; i < AUTO_PIN_LAST; i++) {
5108                 hda_nid_t nid = spec->autocfg.input_pins[i];
5109                 if (nid >= 0x12) {
5110                         snd_hda_codec_write(codec, nid, 0,
5111                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5112                                             i <= AUTO_PIN_FRONT_MIC ?
5113                                             PIN_VREF80 : PIN_IN);
5114                         if (nid != ALC260_PIN_CD_NID)
5115                                 snd_hda_codec_write(codec, nid, 0,
5116                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5117                                                     AMP_OUT_MUTE);
5118                 }
5119         }
5120 }
5121
5122 /*
5123  * generic initialization of ADC, input mixers and output mixers
5124  */
5125 static struct hda_verb alc260_volume_init_verbs[] = {
5126         /*
5127          * Unmute ADC0-1 and set the default input to mic-in
5128          */
5129         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5130         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5131         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5132         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5133
5134         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5135          * mixer widget
5136          * Note: PASD motherboards uses the Line In 2 as the input for
5137          * front panel mic (mic 2)
5138          */
5139         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5140         /* mute analog inputs */
5141         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5142         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5143         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5144         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5145         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5146
5147         /*
5148          * Set up output mixers (0x08 - 0x0a)
5149          */
5150         /* set vol=0 to output mixers */
5151         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5152         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5153         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5154         /* set up input amps for analog loopback */
5155         /* Amp Indices: DAC = 0, mixer = 1 */
5156         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5157         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5158         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5159         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5160         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5161         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5162
5163         { }
5164 };
5165
5166 static int alc260_parse_auto_config(struct hda_codec *codec)
5167 {
5168         struct alc_spec *spec = codec->spec;
5169         unsigned int wcap;
5170         int err;
5171         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5172
5173         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5174                                            alc260_ignore);
5175         if (err < 0)
5176                 return err;
5177         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5178         if (err < 0)
5179                 return err;
5180         if (!spec->kctl_alloc)
5181                 return 0; /* can't find valid BIOS pin config */
5182         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5183         if (err < 0)
5184                 return err;
5185
5186         spec->multiout.max_channels = 2;
5187
5188         if (spec->autocfg.dig_out_pin)
5189                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5190         if (spec->kctl_alloc)
5191                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
5192
5193         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
5194
5195         spec->num_mux_defs = 1;
5196         spec->input_mux = &spec->private_imux;
5197
5198         /* check whether NID 0x04 is valid */
5199         wcap = get_wcaps(codec, 0x04);
5200         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
5201         if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5202                 spec->adc_nids = alc260_adc_nids_alt;
5203                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5204                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
5205         } else {
5206                 spec->adc_nids = alc260_adc_nids;
5207                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5208                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
5209         }
5210         spec->num_mixers++;
5211
5212         return 1;
5213 }
5214
5215 /* additional initialization for auto-configuration model */
5216 static void alc260_auto_init(struct hda_codec *codec)
5217 {
5218         struct alc_spec *spec = codec->spec;
5219         alc260_auto_init_multi_out(codec);
5220         alc260_auto_init_analog_input(codec);
5221         if (spec->unsol_event)
5222                 alc_sku_automute(codec);
5223 }
5224
5225 #ifdef CONFIG_SND_HDA_POWER_SAVE
5226 static struct hda_amp_list alc260_loopbacks[] = {
5227         { 0x07, HDA_INPUT, 0 },
5228         { 0x07, HDA_INPUT, 1 },
5229         { 0x07, HDA_INPUT, 2 },
5230         { 0x07, HDA_INPUT, 3 },
5231         { 0x07, HDA_INPUT, 4 },
5232         { } /* end */
5233 };
5234 #endif
5235
5236 /*
5237  * ALC260 configurations
5238  */
5239 static const char *alc260_models[ALC260_MODEL_LAST] = {
5240         [ALC260_BASIC]          = "basic",
5241         [ALC260_HP]             = "hp",
5242         [ALC260_HP_3013]        = "hp-3013",
5243         [ALC260_HP_DC7600]      = "hp-dc7600",
5244         [ALC260_FUJITSU_S702X]  = "fujitsu",
5245         [ALC260_ACER]           = "acer",
5246         [ALC260_WILL]           = "will",
5247         [ALC260_REPLACER_672V]  = "replacer",
5248 #ifdef CONFIG_SND_DEBUG
5249         [ALC260_TEST]           = "test",
5250 #endif
5251         [ALC260_AUTO]           = "auto",
5252 };
5253
5254 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5255         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5256         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5257         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5258         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5259         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5260         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5261         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5262         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5263         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5264         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5265         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5266         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5267         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5268         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5269         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5270         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5271         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5272         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5273         {}
5274 };
5275
5276 static struct alc_config_preset alc260_presets[] = {
5277         [ALC260_BASIC] = {
5278                 .mixers = { alc260_base_output_mixer,
5279                             alc260_input_mixer,
5280                             alc260_pc_beep_mixer,
5281                             alc260_capture_mixer },
5282                 .init_verbs = { alc260_init_verbs },
5283                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5284                 .dac_nids = alc260_dac_nids,
5285                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5286                 .adc_nids = alc260_adc_nids,
5287                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5288                 .channel_mode = alc260_modes,
5289                 .input_mux = &alc260_capture_source,
5290         },
5291         [ALC260_HP] = {
5292                 .mixers = { alc260_hp_output_mixer,
5293                             alc260_input_mixer,
5294                             alc260_capture_alt_mixer },
5295                 .init_verbs = { alc260_init_verbs,
5296                                 alc260_hp_unsol_verbs },
5297                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5298                 .dac_nids = alc260_dac_nids,
5299                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5300                 .adc_nids = alc260_hp_adc_nids,
5301                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5302                 .channel_mode = alc260_modes,
5303                 .input_mux = &alc260_capture_source,
5304                 .unsol_event = alc260_hp_unsol_event,
5305                 .init_hook = alc260_hp_automute,
5306         },
5307         [ALC260_HP_DC7600] = {
5308                 .mixers = { alc260_hp_dc7600_mixer,
5309                             alc260_input_mixer,
5310                             alc260_capture_alt_mixer },
5311                 .init_verbs = { alc260_init_verbs,
5312                                 alc260_hp_dc7600_verbs },
5313                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5314                 .dac_nids = alc260_dac_nids,
5315                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5316                 .adc_nids = alc260_hp_adc_nids,
5317                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5318                 .channel_mode = alc260_modes,
5319                 .input_mux = &alc260_capture_source,
5320                 .unsol_event = alc260_hp_3012_unsol_event,
5321                 .init_hook = alc260_hp_3012_automute,
5322         },
5323         [ALC260_HP_3013] = {
5324                 .mixers = { alc260_hp_3013_mixer,
5325                             alc260_input_mixer,
5326                             alc260_capture_alt_mixer },
5327                 .init_verbs = { alc260_hp_3013_init_verbs,
5328                                 alc260_hp_3013_unsol_verbs },
5329                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5330                 .dac_nids = alc260_dac_nids,
5331                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5332                 .adc_nids = alc260_hp_adc_nids,
5333                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5334                 .channel_mode = alc260_modes,
5335                 .input_mux = &alc260_capture_source,
5336                 .unsol_event = alc260_hp_3013_unsol_event,
5337                 .init_hook = alc260_hp_3013_automute,
5338         },
5339         [ALC260_FUJITSU_S702X] = {
5340                 .mixers = { alc260_fujitsu_mixer,
5341                             alc260_capture_mixer },
5342                 .init_verbs = { alc260_fujitsu_init_verbs },
5343                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5344                 .dac_nids = alc260_dac_nids,
5345                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5346                 .adc_nids = alc260_dual_adc_nids,
5347                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5348                 .channel_mode = alc260_modes,
5349                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5350                 .input_mux = alc260_fujitsu_capture_sources,
5351         },
5352         [ALC260_ACER] = {
5353                 .mixers = { alc260_acer_mixer,
5354                             alc260_capture_mixer },
5355                 .init_verbs = { alc260_acer_init_verbs },
5356                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5357                 .dac_nids = alc260_dac_nids,
5358                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5359                 .adc_nids = alc260_dual_adc_nids,
5360                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5361                 .channel_mode = alc260_modes,
5362                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5363                 .input_mux = alc260_acer_capture_sources,
5364         },
5365         [ALC260_WILL] = {
5366                 .mixers = { alc260_will_mixer,
5367                             alc260_capture_mixer },
5368                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5369                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5370                 .dac_nids = alc260_dac_nids,
5371                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5372                 .adc_nids = alc260_adc_nids,
5373                 .dig_out_nid = ALC260_DIGOUT_NID,
5374                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5375                 .channel_mode = alc260_modes,
5376                 .input_mux = &alc260_capture_source,
5377         },
5378         [ALC260_REPLACER_672V] = {
5379                 .mixers = { alc260_replacer_672v_mixer,
5380                             alc260_capture_mixer },
5381                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5382                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5383                 .dac_nids = alc260_dac_nids,
5384                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5385                 .adc_nids = alc260_adc_nids,
5386                 .dig_out_nid = ALC260_DIGOUT_NID,
5387                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5388                 .channel_mode = alc260_modes,
5389                 .input_mux = &alc260_capture_source,
5390                 .unsol_event = alc260_replacer_672v_unsol_event,
5391                 .init_hook = alc260_replacer_672v_automute,
5392         },
5393 #ifdef CONFIG_SND_DEBUG
5394         [ALC260_TEST] = {
5395                 .mixers = { alc260_test_mixer,
5396                             alc260_capture_mixer },
5397                 .init_verbs = { alc260_test_init_verbs },
5398                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5399                 .dac_nids = alc260_test_dac_nids,
5400                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5401                 .adc_nids = alc260_test_adc_nids,
5402                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5403                 .channel_mode = alc260_modes,
5404                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5405                 .input_mux = alc260_test_capture_sources,
5406         },
5407 #endif
5408 };
5409
5410 static int patch_alc260(struct hda_codec *codec)
5411 {
5412         struct alc_spec *spec;
5413         int err, board_config;
5414
5415         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5416         if (spec == NULL)
5417                 return -ENOMEM;
5418
5419         codec->spec = spec;
5420
5421         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5422                                                   alc260_models,
5423                                                   alc260_cfg_tbl);
5424         if (board_config < 0) {
5425                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5426                            "trying auto-probe from BIOS...\n");
5427                 board_config = ALC260_AUTO;
5428         }
5429
5430         if (board_config == ALC260_AUTO) {
5431                 /* automatic parse from the BIOS config */
5432                 err = alc260_parse_auto_config(codec);
5433                 if (err < 0) {
5434                         alc_free(codec);
5435                         return err;
5436                 } else if (!err) {
5437                         printk(KERN_INFO
5438                                "hda_codec: Cannot set up configuration "
5439                                "from BIOS.  Using base mode...\n");
5440                         board_config = ALC260_BASIC;
5441                 }
5442         }
5443
5444         if (board_config != ALC260_AUTO)
5445                 setup_preset(spec, &alc260_presets[board_config]);
5446
5447         spec->stream_name_analog = "ALC260 Analog";
5448         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5449         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5450
5451         spec->stream_name_digital = "ALC260 Digital";
5452         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5453         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5454
5455         spec->vmaster_nid = 0x08;
5456
5457         codec->patch_ops = alc_patch_ops;
5458         if (board_config == ALC260_AUTO)
5459                 spec->init_hook = alc260_auto_init;
5460 #ifdef CONFIG_SND_HDA_POWER_SAVE
5461         if (!spec->loopback.amplist)
5462                 spec->loopback.amplist = alc260_loopbacks;
5463 #endif
5464
5465         return 0;
5466 }
5467
5468
5469 /*
5470  * ALC882 support
5471  *
5472  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5473  * configuration.  Each pin widget can choose any input DACs and a mixer.
5474  * Each ADC is connected from a mixer of all inputs.  This makes possible
5475  * 6-channel independent captures.
5476  *
5477  * In addition, an independent DAC for the multi-playback (not used in this
5478  * driver yet).
5479  */
5480 #define ALC882_DIGOUT_NID       0x06
5481 #define ALC882_DIGIN_NID        0x0a
5482
5483 static struct hda_channel_mode alc882_ch_modes[1] = {
5484         { 8, NULL }
5485 };
5486
5487 static hda_nid_t alc882_dac_nids[4] = {
5488         /* front, rear, clfe, rear_surr */
5489         0x02, 0x03, 0x04, 0x05
5490 };
5491
5492 /* identical with ALC880 */
5493 #define alc882_adc_nids         alc880_adc_nids
5494 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5495
5496 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5497 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5498
5499 /* input MUX */
5500 /* FIXME: should be a matrix-type input source selection */
5501
5502 static struct hda_input_mux alc882_capture_source = {
5503         .num_items = 4,
5504         .items = {
5505                 { "Mic", 0x0 },
5506                 { "Front Mic", 0x1 },
5507                 { "Line", 0x2 },
5508                 { "CD", 0x4 },
5509         },
5510 };
5511 #define alc882_mux_enum_info alc_mux_enum_info
5512 #define alc882_mux_enum_get alc_mux_enum_get
5513
5514 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5515                                struct snd_ctl_elem_value *ucontrol)
5516 {
5517         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5518         struct alc_spec *spec = codec->spec;
5519         const struct hda_input_mux *imux = spec->input_mux;
5520         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5521         hda_nid_t nid = spec->capsrc_nids ?
5522                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
5523         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5524         unsigned int i, idx;
5525
5526         idx = ucontrol->value.enumerated.item[0];
5527         if (idx >= imux->num_items)
5528                 idx = imux->num_items - 1;
5529         if (*cur_val == idx)
5530                 return 0;
5531         for (i = 0; i < imux->num_items; i++) {
5532                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
5533                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
5534                                          imux->items[i].index,
5535                                          HDA_AMP_MUTE, v);
5536         }
5537         *cur_val = idx;
5538         return 1;
5539 }
5540
5541 /*
5542  * 2ch mode
5543  */
5544 static struct hda_verb alc882_3ST_ch2_init[] = {
5545         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5546         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5547         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5548         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5549         { } /* end */
5550 };
5551
5552 /*
5553  * 6ch mode
5554  */
5555 static struct hda_verb alc882_3ST_ch6_init[] = {
5556         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5557         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5558         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5559         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5560         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5561         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5562         { } /* end */
5563 };
5564
5565 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5566         { 2, alc882_3ST_ch2_init },
5567         { 6, alc882_3ST_ch6_init },
5568 };
5569
5570 /*
5571  * 6ch mode
5572  */
5573 static struct hda_verb alc882_sixstack_ch6_init[] = {
5574         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5575         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5576         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5577         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5578         { } /* end */
5579 };
5580
5581 /*
5582  * 8ch mode
5583  */
5584 static struct hda_verb alc882_sixstack_ch8_init[] = {
5585         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5586         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5587         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5588         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5589         { } /* end */
5590 };
5591
5592 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5593         { 6, alc882_sixstack_ch6_init },
5594         { 8, alc882_sixstack_ch8_init },
5595 };
5596
5597 /*
5598  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5599  */
5600
5601 /*
5602  * 2ch mode
5603  */
5604 static struct hda_verb alc885_mbp_ch2_init[] = {
5605         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5606         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5607         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5608         { } /* end */
5609 };
5610
5611 /*
5612  * 6ch mode
5613  */
5614 static struct hda_verb alc885_mbp_ch6_init[] = {
5615         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5616         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5617         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5618         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5619         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5620         { } /* end */
5621 };
5622
5623 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
5624         { 2, alc885_mbp_ch2_init },
5625         { 6, alc885_mbp_ch6_init },
5626 };
5627
5628
5629 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5630  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5631  */
5632 static struct snd_kcontrol_new alc882_base_mixer[] = {
5633         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5634         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5635         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5636         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5637         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5638         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5639         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5640         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5641         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5642         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5643         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5644         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5645         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5646         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5647         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5648         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5649         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5650         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5651         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5652         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5653         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5654         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5655         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5656         { } /* end */
5657 };
5658
5659 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5660         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5661         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
5662         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
5663         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
5664         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5665         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5666         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5667         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5668         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
5669         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5670         { } /* end */
5671 };
5672 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5673         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5674         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5675         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5676         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5677         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5678         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5679         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5680         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5681         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5682         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5683         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5684         { } /* end */
5685 };
5686
5687 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5688         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5689         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5690         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5691         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5692         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5693         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5694         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5695         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5696         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5697         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5698         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5699         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5700         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5701         { } /* end */
5702 };
5703
5704 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5705  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5706  */
5707 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5708         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5709         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5710         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5711         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5712         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5713         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5714         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5715         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5716         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5717         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5718         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5719         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5720         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5721         { } /* end */
5722 };
5723
5724 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5725         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5726         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5727         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5728         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5729         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5730         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5731         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5732         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5733         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5734         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5735         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5736         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5737         { } /* end */
5738 };
5739
5740 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5741         {
5742                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5743                 .name = "Channel Mode",
5744                 .info = alc_ch_mode_info,
5745                 .get = alc_ch_mode_get,
5746                 .put = alc_ch_mode_put,
5747         },
5748         { } /* end */
5749 };
5750
5751 static struct hda_verb alc882_init_verbs[] = {
5752         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5753         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5754         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5755         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5756         /* Rear mixer */
5757         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5758         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5759         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5760         /* CLFE mixer */
5761         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5762         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5763         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5764         /* Side mixer */
5765         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5766         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5767         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5768
5769         /* Front Pin: output 0 (0x0c) */
5770         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5771         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5772         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5773         /* Rear Pin: output 1 (0x0d) */
5774         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5775         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5776         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5777         /* CLFE Pin: output 2 (0x0e) */
5778         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5779         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5780         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5781         /* Side Pin: output 3 (0x0f) */
5782         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5783         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5784         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5785         /* Mic (rear) pin: input vref at 80% */
5786         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5787         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5788         /* Front Mic pin: input vref at 80% */
5789         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5790         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5791         /* Line In pin: input */
5792         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5793         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5794         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5795         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5796         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5797         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5798         /* CD pin widget for input */
5799         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5800
5801         /* FIXME: use matrix-type input source selection */
5802         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5803         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5804         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5805         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5806         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5807         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5808         /* Input mixer2 */
5809         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5810         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5811         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5812         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5813         /* Input mixer3 */
5814         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5815         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5816         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5817         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5818         /* ADC1: mute amp left and right */
5819         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5820         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5821         /* ADC2: mute amp left and right */
5822         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5823         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5824         /* ADC3: mute amp left and right */
5825         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5826         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5827
5828         { }
5829 };
5830
5831 static struct hda_verb alc882_eapd_verbs[] = {
5832         /* change to EAPD mode */
5833         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5834         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5835         { }
5836 };
5837
5838 /* Mac Pro test */
5839 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5840         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5841         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5842         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5843         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5844         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5845         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5846         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5847         { } /* end */
5848 };
5849
5850 static struct hda_verb alc882_macpro_init_verbs[] = {
5851         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5852         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5853         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5854         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5855         /* Front Pin: output 0 (0x0c) */
5856         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5857         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5858         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5859         /* Front Mic pin: input vref at 80% */
5860         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5861         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5862         /* Speaker:  output */
5863         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5864         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5865         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5866         /* Headphone output (output 0 - 0x0c) */
5867         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5868         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5869         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5870
5871         /* FIXME: use matrix-type input source selection */
5872         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5873         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5874         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5875         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5876         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5877         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5878         /* Input mixer2 */
5879         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5880         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5881         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5882         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5883         /* Input mixer3 */
5884         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5885         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5886         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5887         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5888         /* ADC1: mute amp left and right */
5889         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5890         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5891         /* ADC2: mute amp left and right */
5892         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5893         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5894         /* ADC3: mute amp left and right */
5895         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5896         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5897
5898         { }
5899 };
5900
5901 /* Macbook Pro rev3 */
5902 static struct hda_verb alc885_mbp3_init_verbs[] = {
5903         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5904         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5905         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5906         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5907         /* Rear mixer */
5908         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5909         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5910         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5911         /* Front Pin: output 0 (0x0c) */
5912         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5913         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5914         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5915         /* HP Pin: output 0 (0x0d) */
5916         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5917         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5918         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5919         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5920         /* Mic (rear) pin: input vref at 80% */
5921         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5922         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5923         /* Front Mic pin: input vref at 80% */
5924         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5925         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5926         /* Line In pin: use output 1 when in LineOut mode */
5927         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5928         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5929         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5930
5931         /* FIXME: use matrix-type input source selection */
5932         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5933         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5934         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5935         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5936         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5937         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5938         /* Input mixer2 */
5939         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5940         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5941         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5942         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5943         /* Input mixer3 */
5944         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5945         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5946         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5947         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5948         /* ADC1: mute amp left and right */
5949         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5950         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5951         /* ADC2: mute amp left and right */
5952         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5953         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5954         /* ADC3: mute amp left and right */
5955         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5956         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5957
5958         { }
5959 };
5960
5961 /* iMac 24 mixer. */
5962 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
5963         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5964         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
5965         { } /* end */
5966 };
5967
5968 /* iMac 24 init verbs. */
5969 static struct hda_verb alc885_imac24_init_verbs[] = {
5970         /* Internal speakers: output 0 (0x0c) */
5971         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5972         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5973         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5974         /* Internal speakers: output 0 (0x0c) */
5975         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5976         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5977         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
5978         /* Headphone: output 0 (0x0c) */
5979         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5980         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5981         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5982         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5983         /* Front Mic: input vref at 80% */
5984         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5985         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5986         { }
5987 };
5988
5989 /* Toggle speaker-output according to the hp-jack state */
5990 static void alc885_imac24_automute(struct hda_codec *codec)
5991 {
5992         unsigned int present;
5993
5994         present = snd_hda_codec_read(codec, 0x14, 0,
5995                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5996         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
5997                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5998         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
5999                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6000 }
6001
6002 /* Processes unsolicited events. */
6003 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6004                                       unsigned int res)
6005 {
6006         /* Headphone insertion or removal. */
6007         if ((res >> 26) == ALC880_HP_EVENT)
6008                 alc885_imac24_automute(codec);
6009 }
6010
6011 static void alc885_mbp3_automute(struct hda_codec *codec)
6012 {
6013         unsigned int present;
6014
6015         present = snd_hda_codec_read(codec, 0x15, 0,
6016                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6017         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6018                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6019         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6020                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6021
6022 }
6023 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6024                                     unsigned int res)
6025 {
6026         /* Headphone insertion or removal. */
6027         if ((res >> 26) == ALC880_HP_EVENT)
6028                 alc885_mbp3_automute(codec);
6029 }
6030
6031
6032 static struct hda_verb alc882_targa_verbs[] = {
6033         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6034         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6035
6036         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6037         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6038
6039         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6040         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6041         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6042
6043         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6044         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6045         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6046         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6047         { } /* end */
6048 };
6049
6050 /* toggle speaker-output according to the hp-jack state */
6051 static void alc882_targa_automute(struct hda_codec *codec)
6052 {
6053         unsigned int present;
6054
6055         present = snd_hda_codec_read(codec, 0x14, 0,
6056                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6057         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6058                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6059         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6060                                   present ? 1 : 3);
6061 }
6062
6063 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6064 {
6065         /* Looks like the unsol event is incompatible with the standard
6066          * definition.  4bit tag is placed at 26 bit!
6067          */
6068         if (((res >> 26) == ALC880_HP_EVENT)) {
6069                 alc882_targa_automute(codec);
6070         }
6071 }
6072
6073 static struct hda_verb alc882_asus_a7j_verbs[] = {
6074         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6075         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6076
6077         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6078         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6079         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6080
6081         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6082         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6083         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6084
6085         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6086         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6087         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6088         { } /* end */
6089 };
6090
6091 static struct hda_verb alc882_asus_a7m_verbs[] = {
6092         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6093         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6094
6095         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6096         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6097         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6098
6099         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6100         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6101         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6102
6103         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6104         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6105         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6106         { } /* end */
6107 };
6108
6109 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6110 {
6111         unsigned int gpiostate, gpiomask, gpiodir;
6112
6113         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6114                                        AC_VERB_GET_GPIO_DATA, 0);
6115
6116         if (!muted)
6117                 gpiostate |= (1 << pin);
6118         else
6119                 gpiostate &= ~(1 << pin);
6120
6121         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6122                                       AC_VERB_GET_GPIO_MASK, 0);
6123         gpiomask |= (1 << pin);
6124
6125         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6126                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6127         gpiodir |= (1 << pin);
6128
6129
6130         snd_hda_codec_write(codec, codec->afg, 0,
6131                             AC_VERB_SET_GPIO_MASK, gpiomask);
6132         snd_hda_codec_write(codec, codec->afg, 0,
6133                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6134
6135         msleep(1);
6136
6137         snd_hda_codec_write(codec, codec->afg, 0,
6138                             AC_VERB_SET_GPIO_DATA, gpiostate);
6139 }
6140
6141 /* set up GPIO at initialization */
6142 static void alc885_macpro_init_hook(struct hda_codec *codec)
6143 {
6144         alc882_gpio_mute(codec, 0, 0);
6145         alc882_gpio_mute(codec, 1, 0);
6146 }
6147
6148 /* set up GPIO and update auto-muting at initialization */
6149 static void alc885_imac24_init_hook(struct hda_codec *codec)
6150 {
6151         alc885_macpro_init_hook(codec);
6152         alc885_imac24_automute(codec);
6153 }
6154
6155 /*
6156  * generic initialization of ADC, input mixers and output mixers
6157  */
6158 static struct hda_verb alc882_auto_init_verbs[] = {
6159         /*
6160          * Unmute ADC0-2 and set the default input to mic-in
6161          */
6162         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6163         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6164         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6165         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6166         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6167         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6168
6169         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6170          * mixer widget
6171          * Note: PASD motherboards uses the Line In 2 as the input for
6172          * front panel mic (mic 2)
6173          */
6174         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6175         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6176         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6177         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6178         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6179         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6180
6181         /*
6182          * Set up output mixers (0x0c - 0x0f)
6183          */
6184         /* set vol=0 to output mixers */
6185         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6186         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6187         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6188         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6189         /* set up input amps for analog loopback */
6190         /* Amp Indices: DAC = 0, mixer = 1 */
6191         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6192         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6193         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6194         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6195         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6196         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6197         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6198         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6199         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6200         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6201
6202         /* FIXME: use matrix-type input source selection */
6203         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6204         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6205         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6206         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6207         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6208         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6209         /* Input mixer2 */
6210         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6211         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6212         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6213         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6214         /* Input mixer3 */
6215         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6216         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6217         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6218         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6219
6220         { }
6221 };
6222
6223 /* capture mixer elements */
6224 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
6225         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6226         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6227         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6228         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6229         {
6230                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6231                 /* The multiple "Capture Source" controls confuse alsamixer
6232                  * So call somewhat different..
6233                  */
6234                 /* .name = "Capture Source", */
6235                 .name = "Input Source",
6236                 .count = 2,
6237                 .info = alc882_mux_enum_info,
6238                 .get = alc882_mux_enum_get,
6239                 .put = alc882_mux_enum_put,
6240         },
6241         { } /* end */
6242 };
6243
6244 static struct snd_kcontrol_new alc882_capture_mixer[] = {
6245         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
6246         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
6247         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
6248         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
6249         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
6250         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
6251         {
6252                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6253                 /* The multiple "Capture Source" controls confuse alsamixer
6254                  * So call somewhat different..
6255                  */
6256                 /* .name = "Capture Source", */
6257                 .name = "Input Source",
6258                 .count = 3,
6259                 .info = alc882_mux_enum_info,
6260                 .get = alc882_mux_enum_get,
6261                 .put = alc882_mux_enum_put,
6262         },
6263         { } /* end */
6264 };
6265
6266 #ifdef CONFIG_SND_HDA_POWER_SAVE
6267 #define alc882_loopbacks        alc880_loopbacks
6268 #endif
6269
6270 /* pcm configuration: identiacal with ALC880 */
6271 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6272 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6273 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6274 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6275
6276 /*
6277  * configuration and preset
6278  */
6279 static const char *alc882_models[ALC882_MODEL_LAST] = {
6280         [ALC882_3ST_DIG]        = "3stack-dig",
6281         [ALC882_6ST_DIG]        = "6stack-dig",
6282         [ALC882_ARIMA]          = "arima",
6283         [ALC882_W2JC]           = "w2jc",
6284         [ALC882_TARGA]          = "targa",
6285         [ALC882_ASUS_A7J]       = "asus-a7j",
6286         [ALC882_ASUS_A7M]       = "asus-a7m",
6287         [ALC885_MACPRO]         = "macpro",
6288         [ALC885_MBP3]           = "mbp3",
6289         [ALC885_IMAC24]         = "imac24",
6290         [ALC882_AUTO]           = "auto",
6291 };
6292
6293 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6294         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6295         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6296         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6297         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6298         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6299         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6300         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6301         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6302         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6303         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6304         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6305         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6306         {}
6307 };
6308
6309 static struct alc_config_preset alc882_presets[] = {
6310         [ALC882_3ST_DIG] = {
6311                 .mixers = { alc882_base_mixer },
6312                 .init_verbs = { alc882_init_verbs },
6313                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6314                 .dac_nids = alc882_dac_nids,
6315                 .dig_out_nid = ALC882_DIGOUT_NID,
6316                 .dig_in_nid = ALC882_DIGIN_NID,
6317                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6318                 .channel_mode = alc882_ch_modes,
6319                 .need_dac_fix = 1,
6320                 .input_mux = &alc882_capture_source,
6321         },
6322         [ALC882_6ST_DIG] = {
6323                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6324                 .init_verbs = { alc882_init_verbs },
6325                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6326                 .dac_nids = alc882_dac_nids,
6327                 .dig_out_nid = ALC882_DIGOUT_NID,
6328                 .dig_in_nid = ALC882_DIGIN_NID,
6329                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6330                 .channel_mode = alc882_sixstack_modes,
6331                 .input_mux = &alc882_capture_source,
6332         },
6333         [ALC882_ARIMA] = {
6334                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6335                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6336                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6337                 .dac_nids = alc882_dac_nids,
6338                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6339                 .channel_mode = alc882_sixstack_modes,
6340                 .input_mux = &alc882_capture_source,
6341         },
6342         [ALC882_W2JC] = {
6343                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6344                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6345                                 alc880_gpio1_init_verbs },
6346                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6347                 .dac_nids = alc882_dac_nids,
6348                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6349                 .channel_mode = alc880_threestack_modes,
6350                 .need_dac_fix = 1,
6351                 .input_mux = &alc882_capture_source,
6352                 .dig_out_nid = ALC882_DIGOUT_NID,
6353         },
6354         [ALC885_MBP3] = {
6355                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6356                 .init_verbs = { alc885_mbp3_init_verbs,
6357                                 alc880_gpio1_init_verbs },
6358                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6359                 .dac_nids = alc882_dac_nids,
6360                 .channel_mode = alc885_mbp_6ch_modes,
6361                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6362                 .input_mux = &alc882_capture_source,
6363                 .dig_out_nid = ALC882_DIGOUT_NID,
6364                 .dig_in_nid = ALC882_DIGIN_NID,
6365                 .unsol_event = alc885_mbp3_unsol_event,
6366                 .init_hook = alc885_mbp3_automute,
6367         },
6368         [ALC885_MACPRO] = {
6369                 .mixers = { alc882_macpro_mixer },
6370                 .init_verbs = { alc882_macpro_init_verbs },
6371                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6372                 .dac_nids = alc882_dac_nids,
6373                 .dig_out_nid = ALC882_DIGOUT_NID,
6374                 .dig_in_nid = ALC882_DIGIN_NID,
6375                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6376                 .channel_mode = alc882_ch_modes,
6377                 .input_mux = &alc882_capture_source,
6378                 .init_hook = alc885_macpro_init_hook,
6379         },
6380         [ALC885_IMAC24] = {
6381                 .mixers = { alc885_imac24_mixer },
6382                 .init_verbs = { alc885_imac24_init_verbs },
6383                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6384                 .dac_nids = alc882_dac_nids,
6385                 .dig_out_nid = ALC882_DIGOUT_NID,
6386                 .dig_in_nid = ALC882_DIGIN_NID,
6387                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6388                 .channel_mode = alc882_ch_modes,
6389                 .input_mux = &alc882_capture_source,
6390                 .unsol_event = alc885_imac24_unsol_event,
6391                 .init_hook = alc885_imac24_init_hook,
6392         },
6393         [ALC882_TARGA] = {
6394                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
6395                             alc882_capture_mixer },
6396                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6397                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6398                 .dac_nids = alc882_dac_nids,
6399                 .dig_out_nid = ALC882_DIGOUT_NID,
6400                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6401                 .adc_nids = alc882_adc_nids,
6402                 .capsrc_nids = alc882_capsrc_nids,
6403                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6404                 .channel_mode = alc882_3ST_6ch_modes,
6405                 .need_dac_fix = 1,
6406                 .input_mux = &alc882_capture_source,
6407                 .unsol_event = alc882_targa_unsol_event,
6408                 .init_hook = alc882_targa_automute,
6409         },
6410         [ALC882_ASUS_A7J] = {
6411                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
6412                             alc882_capture_mixer },
6413                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6414                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6415                 .dac_nids = alc882_dac_nids,
6416                 .dig_out_nid = ALC882_DIGOUT_NID,
6417                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6418                 .adc_nids = alc882_adc_nids,
6419                 .capsrc_nids = alc882_capsrc_nids,
6420                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6421                 .channel_mode = alc882_3ST_6ch_modes,
6422                 .need_dac_fix = 1,
6423                 .input_mux = &alc882_capture_source,
6424         },
6425         [ALC882_ASUS_A7M] = {
6426                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6427                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6428                                 alc880_gpio1_init_verbs,
6429                                 alc882_asus_a7m_verbs },
6430                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6431                 .dac_nids = alc882_dac_nids,
6432                 .dig_out_nid = ALC882_DIGOUT_NID,
6433                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6434                 .channel_mode = alc880_threestack_modes,
6435                 .need_dac_fix = 1,
6436                 .input_mux = &alc882_capture_source,
6437         },
6438 };
6439
6440
6441 /*
6442  * Pin config fixes
6443  */
6444 enum {
6445         PINFIX_ABIT_AW9D_MAX
6446 };
6447
6448 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6449         { 0x15, 0x01080104 }, /* side */
6450         { 0x16, 0x01011012 }, /* rear */
6451         { 0x17, 0x01016011 }, /* clfe */
6452         { }
6453 };
6454
6455 static const struct alc_pincfg *alc882_pin_fixes[] = {
6456         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6457 };
6458
6459 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6460         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6461         {}
6462 };
6463
6464 /*
6465  * BIOS auto configuration
6466  */
6467 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6468                                               hda_nid_t nid, int pin_type,
6469                                               int dac_idx)
6470 {
6471         /* set as output */
6472         struct alc_spec *spec = codec->spec;
6473         int idx;
6474
6475         alc_set_pin_output(codec, nid, pin_type);
6476         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6477                 idx = 4;
6478         else
6479                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6480         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6481
6482 }
6483
6484 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6485 {
6486         struct alc_spec *spec = codec->spec;
6487         int i;
6488
6489         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6490         for (i = 0; i <= HDA_SIDE; i++) {
6491                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6492                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6493                 if (nid)
6494                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6495                                                           i);
6496         }
6497 }
6498
6499 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6500 {
6501         struct alc_spec *spec = codec->spec;
6502         hda_nid_t pin;
6503
6504         pin = spec->autocfg.hp_pins[0];
6505         if (pin) /* connect to front */
6506                 /* use dac 0 */
6507                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6508         pin = spec->autocfg.speaker_pins[0];
6509         if (pin)
6510                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6511 }
6512
6513 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6514 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6515
6516 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6517 {
6518         struct alc_spec *spec = codec->spec;
6519         int i;
6520
6521         for (i = 0; i < AUTO_PIN_LAST; i++) {
6522                 hda_nid_t nid = spec->autocfg.input_pins[i];
6523                 unsigned int vref;
6524                 if (!nid)
6525                         continue;
6526                 vref = PIN_IN;
6527                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6528                         unsigned int pincap;
6529                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6530                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6531                             AC_PINCAP_VREF_80)
6532                                 vref = PIN_VREF80;
6533                 }
6534                 snd_hda_codec_write(codec, nid, 0,
6535                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6536                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6537                         snd_hda_codec_write(codec, nid, 0,
6538                                             AC_VERB_SET_AMP_GAIN_MUTE,
6539                                             AMP_OUT_MUTE);
6540         }
6541 }
6542
6543 static void alc882_auto_init_input_src(struct hda_codec *codec)
6544 {
6545         struct alc_spec *spec = codec->spec;
6546         const struct hda_input_mux *imux = spec->input_mux;
6547         int c;
6548
6549         for (c = 0; c < spec->num_adc_nids; c++) {
6550                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6551                 hda_nid_t nid = spec->capsrc_nids[c];
6552                 int conns, mute, idx, item;
6553
6554                 conns = snd_hda_get_connections(codec, nid, conn_list,
6555                                                 ARRAY_SIZE(conn_list));
6556                 if (conns < 0)
6557                         continue;
6558                 for (idx = 0; idx < conns; idx++) {
6559                         /* if the current connection is the selected one,
6560                          * unmute it as default - otherwise mute it
6561                          */
6562                         mute = AMP_IN_MUTE(idx);
6563                         for (item = 0; item < imux->num_items; item++) {
6564                                 if (imux->items[item].index == idx) {
6565                                         if (spec->cur_mux[c] == item)
6566                                                 mute = AMP_IN_UNMUTE(idx);
6567                                         break;
6568                                 }
6569                         }
6570                         snd_hda_codec_write(codec, nid, 0,
6571                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6572                 }
6573         }
6574 }
6575
6576 /* add mic boosts if needed */
6577 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6578 {
6579         struct alc_spec *spec = codec->spec;
6580         int err;
6581         hda_nid_t nid;
6582
6583         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6584         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6585                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6586                                   "Mic Boost",
6587                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6588                 if (err < 0)
6589                         return err;
6590         }
6591         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6592         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6593                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6594                                   "Front Mic Boost",
6595                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6596                 if (err < 0)
6597                         return err;
6598         }
6599         return 0;
6600 }
6601
6602 /* almost identical with ALC880 parser... */
6603 static int alc882_parse_auto_config(struct hda_codec *codec)
6604 {
6605         struct alc_spec *spec = codec->spec;
6606         int err = alc880_parse_auto_config(codec);
6607
6608         if (err < 0)
6609                 return err;
6610         else if (!err)
6611                 return 0; /* no config found */
6612
6613         err = alc_auto_add_mic_boost(codec);
6614         if (err < 0)
6615                 return err;
6616
6617         /* hack - override the init verbs */
6618         spec->init_verbs[0] = alc882_auto_init_verbs;
6619
6620         return 1; /* config found */
6621 }
6622
6623 /* additional initialization for auto-configuration model */
6624 static void alc882_auto_init(struct hda_codec *codec)
6625 {
6626         struct alc_spec *spec = codec->spec;
6627         alc882_auto_init_multi_out(codec);
6628         alc882_auto_init_hp_out(codec);
6629         alc882_auto_init_analog_input(codec);
6630         alc882_auto_init_input_src(codec);
6631         if (spec->unsol_event)
6632                 alc_sku_automute(codec);
6633 }
6634
6635 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6636
6637 static int patch_alc882(struct hda_codec *codec)
6638 {
6639         struct alc_spec *spec;
6640         int err, board_config;
6641
6642         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6643         if (spec == NULL)
6644                 return -ENOMEM;
6645
6646         codec->spec = spec;
6647
6648         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6649                                                   alc882_models,
6650                                                   alc882_cfg_tbl);
6651
6652         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6653                 /* Pick up systems that don't supply PCI SSID */
6654                 switch (codec->subsystem_id) {
6655                 case 0x106b0c00: /* Mac Pro */
6656                         board_config = ALC885_MACPRO;
6657                         break;
6658                 case 0x106b1000: /* iMac 24 */
6659                         board_config = ALC885_IMAC24;
6660                         break;
6661                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
6662                 case 0x106b2c00: /* Macbook Pro rev3 */
6663                 case 0x106b3600: /* Macbook 3.1 */
6664                         board_config = ALC885_MBP3;
6665                         break;
6666                 default:
6667                         /* ALC889A is handled better as ALC888-compatible */
6668                         if (codec->revision_id == 0x100103) {
6669                                 alc_free(codec);
6670                                 return patch_alc883(codec);
6671                         }
6672                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6673                                          "trying auto-probe from BIOS...\n");
6674                         board_config = ALC882_AUTO;
6675                 }
6676         }
6677
6678         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6679
6680         if (board_config == ALC882_AUTO) {
6681                 /* automatic parse from the BIOS config */
6682                 err = alc882_parse_auto_config(codec);
6683                 if (err < 0) {
6684                         alc_free(codec);
6685                         return err;
6686                 } else if (!err) {
6687                         printk(KERN_INFO
6688                                "hda_codec: Cannot set up configuration "
6689                                "from BIOS.  Using base mode...\n");
6690                         board_config = ALC882_3ST_DIG;
6691                 }
6692         }
6693
6694         if (board_config != ALC882_AUTO)
6695                 setup_preset(spec, &alc882_presets[board_config]);
6696
6697         if (codec->vendor_id == 0x10ec0885) {
6698                 spec->stream_name_analog = "ALC885 Analog";
6699                 spec->stream_name_digital = "ALC885 Digital";
6700         } else {
6701                 spec->stream_name_analog = "ALC882 Analog";
6702                 spec->stream_name_digital = "ALC882 Digital";
6703         }
6704
6705         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6706         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6707         /* FIXME: setup DAC5 */
6708         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
6709         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6710
6711         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6712         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6713
6714         if (!spec->adc_nids && spec->input_mux) {
6715                 /* check whether NID 0x07 is valid */
6716                 unsigned int wcap = get_wcaps(codec, 0x07);
6717                 /* get type */
6718                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6719                 if (wcap != AC_WID_AUD_IN) {
6720                         spec->adc_nids = alc882_adc_nids_alt;
6721                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6722                         spec->capsrc_nids = alc882_capsrc_nids_alt;
6723                         spec->mixers[spec->num_mixers] =
6724                                 alc882_capture_alt_mixer;
6725                         spec->num_mixers++;
6726                 } else {
6727                         spec->adc_nids = alc882_adc_nids;
6728                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6729                         spec->capsrc_nids = alc882_capsrc_nids;
6730                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6731                         spec->num_mixers++;
6732                 }
6733         }
6734
6735         spec->vmaster_nid = 0x0c;
6736
6737         codec->patch_ops = alc_patch_ops;
6738         if (board_config == ALC882_AUTO)
6739                 spec->init_hook = alc882_auto_init;
6740 #ifdef CONFIG_SND_HDA_POWER_SAVE
6741         if (!spec->loopback.amplist)
6742                 spec->loopback.amplist = alc882_loopbacks;
6743 #endif
6744
6745         return 0;
6746 }
6747
6748 /*
6749  * ALC883 support
6750  *
6751  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6752  * configuration.  Each pin widget can choose any input DACs and a mixer.
6753  * Each ADC is connected from a mixer of all inputs.  This makes possible
6754  * 6-channel independent captures.
6755  *
6756  * In addition, an independent DAC for the multi-playback (not used in this
6757  * driver yet).
6758  */
6759 #define ALC883_DIGOUT_NID       0x06
6760 #define ALC883_DIGIN_NID        0x0a
6761
6762 static hda_nid_t alc883_dac_nids[4] = {
6763         /* front, rear, clfe, rear_surr */
6764         0x02, 0x03, 0x04, 0x05
6765 };
6766
6767 static hda_nid_t alc883_adc_nids[2] = {
6768         /* ADC1-2 */
6769         0x08, 0x09,
6770 };
6771
6772 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6773
6774 /* input MUX */
6775 /* FIXME: should be a matrix-type input source selection */
6776
6777 static struct hda_input_mux alc883_capture_source = {
6778         .num_items = 4,
6779         .items = {
6780                 { "Mic", 0x0 },
6781                 { "Front Mic", 0x1 },
6782                 { "Line", 0x2 },
6783                 { "CD", 0x4 },
6784         },
6785 };
6786
6787 static struct hda_input_mux alc883_3stack_6ch_intel = {
6788         .num_items = 4,
6789         .items = {
6790                 { "Mic", 0x1 },
6791                 { "Front Mic", 0x0 },
6792                 { "Line", 0x2 },
6793                 { "CD", 0x4 },
6794         },
6795 };
6796
6797 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6798         .num_items = 2,
6799         .items = {
6800                 { "Mic", 0x1 },
6801                 { "Line", 0x2 },
6802         },
6803 };
6804
6805 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6806         .num_items = 4,
6807         .items = {
6808                 { "Mic", 0x0 },
6809                 { "iMic", 0x1 },
6810                 { "Line", 0x2 },
6811                 { "CD", 0x4 },
6812         },
6813 };
6814
6815 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6816         .num_items = 2,
6817         .items = {
6818                 { "Mic", 0x0 },
6819                 { "Int Mic", 0x1 },
6820         },
6821 };
6822
6823 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
6824         .num_items = 3,
6825         .items = {
6826                 { "Mic", 0x0 },
6827                 { "Front Mic", 0x1 },
6828                 { "Line", 0x4 },
6829         },
6830 };
6831
6832 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
6833         .num_items = 2,
6834         .items = {
6835                 { "Mic", 0x0 },
6836                 { "Line", 0x2 },
6837         },
6838 };
6839
6840 #define alc883_mux_enum_info alc_mux_enum_info
6841 #define alc883_mux_enum_get alc_mux_enum_get
6842 /* ALC883 has the ALC882-type input selection */
6843 #define alc883_mux_enum_put alc882_mux_enum_put
6844
6845 /*
6846  * 2ch mode
6847  */
6848 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6849         { 2, NULL }
6850 };
6851
6852 /*
6853  * 2ch mode
6854  */
6855 static struct hda_verb alc883_3ST_ch2_init[] = {
6856         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6857         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6858         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6859         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6860         { } /* end */
6861 };
6862
6863 /*
6864  * 4ch mode
6865  */
6866 static struct hda_verb alc883_3ST_ch4_init[] = {
6867         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6868         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6869         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6870         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6871         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6872         { } /* end */
6873 };
6874
6875 /*
6876  * 6ch mode
6877  */
6878 static struct hda_verb alc883_3ST_ch6_init[] = {
6879         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6880         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6881         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6882         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6883         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6884         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6885         { } /* end */
6886 };
6887
6888 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6889         { 2, alc883_3ST_ch2_init },
6890         { 4, alc883_3ST_ch4_init },
6891         { 6, alc883_3ST_ch6_init },
6892 };
6893
6894 /*
6895  * 2ch mode
6896  */
6897 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6898         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6899         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6900         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6901         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6902         { } /* end */
6903 };
6904
6905 /*
6906  * 4ch mode
6907  */
6908 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
6909         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6910         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6911         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6912         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6913         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6914         { } /* end */
6915 };
6916
6917 /*
6918  * 6ch mode
6919  */
6920 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
6921         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6922         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6923         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
6924         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6925         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6926         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6927         { } /* end */
6928 };
6929
6930 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
6931         { 2, alc883_3ST_ch2_intel_init },
6932         { 4, alc883_3ST_ch4_intel_init },
6933         { 6, alc883_3ST_ch6_intel_init },
6934 };
6935
6936 /*
6937  * 6ch mode
6938  */
6939 static struct hda_verb alc883_sixstack_ch6_init[] = {
6940         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6941         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6942         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6943         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6944         { } /* end */
6945 };
6946
6947 /*
6948  * 8ch mode
6949  */
6950 static struct hda_verb alc883_sixstack_ch8_init[] = {
6951         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6952         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6953         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6954         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6955         { } /* end */
6956 };
6957
6958 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6959         { 6, alc883_sixstack_ch6_init },
6960         { 8, alc883_sixstack_ch8_init },
6961 };
6962
6963 static struct hda_verb alc883_medion_eapd_verbs[] = {
6964         /* eanable EAPD on medion laptop */
6965         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6966         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6967         { }
6968 };
6969
6970 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6971  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6972  */
6973
6974 static struct snd_kcontrol_new alc883_base_mixer[] = {
6975         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6976         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6977         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6978         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6979         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6980         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6981         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6982         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6983         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6984         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6985         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6986         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6987         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6988         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6989         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6990         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6991         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6992         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6993         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6994         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6995         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6996         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6997         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6998         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6999         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7000         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7001         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7002         {
7003                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7004                 /* .name = "Capture Source", */
7005                 .name = "Input Source",
7006                 .count = 2,
7007                 .info = alc883_mux_enum_info,
7008                 .get = alc883_mux_enum_get,
7009                 .put = alc883_mux_enum_put,
7010         },
7011         { } /* end */
7012 };
7013
7014 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7015         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7016         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7017         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7018         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7019         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7020         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7021         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7022         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7023         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7024         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7025         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7026         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7027         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7028         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7029         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7030         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7031         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7032         {
7033                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7034                 /* .name = "Capture Source", */
7035                 .name = "Input Source",
7036                 .count = 2,
7037                 .info = alc883_mux_enum_info,
7038                 .get = alc883_mux_enum_get,
7039                 .put = alc883_mux_enum_put,
7040         },
7041         { } /* end */
7042 };
7043
7044 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7045         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7046         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7047         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7048         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7049         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7050         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7051         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7052         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7053         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7054         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7055         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7056         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7057         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7058         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7059         {
7060                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7061                 /* .name = "Capture Source", */
7062                 .name = "Input Source",
7063                 .count = 2,
7064                 .info = alc883_mux_enum_info,
7065                 .get = alc883_mux_enum_get,
7066                 .put = alc883_mux_enum_put,
7067         },
7068         { } /* end */
7069 };
7070
7071 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7072         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7073         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7074         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7075         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7076         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7077         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7078         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7079         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7080         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7081         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7082         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7083         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7084         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7085         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7086         {
7087                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7088                 /* .name = "Capture Source", */
7089                 .name = "Input Source",
7090                 .count = 2,
7091                 .info = alc883_mux_enum_info,
7092                 .get = alc883_mux_enum_get,
7093                 .put = alc883_mux_enum_put,
7094         },
7095         { } /* end */
7096 };
7097
7098 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7099         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7100         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7101         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7102         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7103         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7104         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7105         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7106         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7107         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7108         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7109         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7110         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7111         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7112         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7113         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7114         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7115         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7116         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7117         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7118         {
7119                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7120                 /* .name = "Capture Source", */
7121                 .name = "Input Source",
7122                 .count = 2,
7123                 .info = alc883_mux_enum_info,
7124                 .get = alc883_mux_enum_get,
7125                 .put = alc883_mux_enum_put,
7126         },
7127         { } /* end */
7128 };
7129
7130 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7131         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7132         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7133         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7134         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7135         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7136         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7137         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7138         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7139         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7140         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7141         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7142         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7143         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7144         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7145         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7146         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7147         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7148         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7149         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7150         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7151         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7152         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7153         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7154         {
7155                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7156                 /* .name = "Capture Source", */
7157                 .name = "Input Source",
7158                 .count = 1,
7159                 .info = alc883_mux_enum_info,
7160                 .get = alc883_mux_enum_get,
7161                 .put = alc883_mux_enum_put,
7162         },
7163         { } /* end */
7164 };
7165
7166 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7167         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7168         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7169         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7170         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7171         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7172                               HDA_OUTPUT),
7173         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7174         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7175         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7176         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7177         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7178         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7179         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7180         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7181         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7182         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7183         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7184         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7185         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7186         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7187         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7188         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7189         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7190         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7191         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7192         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7193         {
7194                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7195                 /* .name = "Capture Source", */
7196                 .name = "Input Source",
7197                 .count = 2,
7198                 .info = alc883_mux_enum_info,
7199                 .get = alc883_mux_enum_get,
7200                 .put = alc883_mux_enum_put,
7201         },
7202         { } /* end */
7203 };
7204
7205 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7206         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7207         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7208         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7209         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7210         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7211         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7212         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7213         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7214         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7215         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7216         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7217         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7218         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7219         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7220         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7221         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7222         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7223         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7224         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7225         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7226         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7227         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7228         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7229
7230         {
7231                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7232                 /* .name = "Capture Source", */
7233                 .name = "Input Source",
7234                 .count = 1,
7235                 .info = alc883_mux_enum_info,
7236                 .get = alc883_mux_enum_get,
7237                 .put = alc883_mux_enum_put,
7238         },
7239         { } /* end */
7240 };
7241
7242 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7243         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7244         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7245         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7246         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7247         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7248         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7249         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7250         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7251         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7252         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7253         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7254         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7255         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7256         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7257         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7258         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7259         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7260         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7261         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7262         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7263         {
7264                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7265                 /* .name = "Capture Source", */
7266                 .name = "Input Source",
7267                 .count = 2,
7268                 .info = alc883_mux_enum_info,
7269                 .get = alc883_mux_enum_get,
7270                 .put = alc883_mux_enum_put,
7271         },
7272         { } /* end */
7273 };
7274
7275 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7276         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7277         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7278         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7279         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7280         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7281         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7282         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7283         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7284         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7285         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7286         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7287         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7288         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7289         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7290         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7291         {
7292                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7293                 /* .name = "Capture Source", */
7294                 .name = "Input Source",
7295                 .count = 2,
7296                 .info = alc883_mux_enum_info,
7297                 .get = alc883_mux_enum_get,
7298                 .put = alc883_mux_enum_put,
7299         },
7300         { } /* end */
7301 };
7302
7303 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7304         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7305         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7306         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7307         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7308         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7309         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7310         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7311         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7312         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7313         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7314         {
7315                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7316                 /* .name = "Capture Source", */
7317                 .name = "Input Source",
7318                 .count = 1,
7319                 .info = alc883_mux_enum_info,
7320                 .get = alc883_mux_enum_get,
7321                 .put = alc883_mux_enum_put,
7322         },
7323         { } /* end */
7324 };
7325
7326 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7327         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7328         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7329         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7330         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7331         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7332         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7333         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7334         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7335         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7336         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7337         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7338         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7339         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7340         {
7341                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7342                 /* .name = "Capture Source", */
7343                 .name = "Input Source",
7344                 .count = 2,
7345                 .info = alc883_mux_enum_info,
7346                 .get = alc883_mux_enum_get,
7347                 .put = alc883_mux_enum_put,
7348         },
7349         { } /* end */
7350 };
7351
7352 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7353         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7354         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7355         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7356         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7357         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7358         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7359         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7360         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7361         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7362         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7363         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7364         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7365         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7366         {
7367                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7368                 /* .name = "Capture Source", */
7369                 .name = "Input Source",
7370                 .count = 2,
7371                 .info = alc883_mux_enum_info,
7372                 .get = alc883_mux_enum_get,
7373                 .put = alc883_mux_enum_put,
7374         },
7375         { } /* end */
7376 };
7377
7378 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7379         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7380         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7381         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7382         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7383         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7384         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7385         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7386         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7387         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7388         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7389         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7390         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7391         {
7392                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7393                 /* .name = "Capture Source", */
7394                 .name = "Input Source",
7395                 .count = 2,
7396                 .info = alc883_mux_enum_info,
7397                 .get = alc883_mux_enum_get,
7398                 .put = alc883_mux_enum_put,
7399         },
7400         { } /* end */
7401 };
7402
7403 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7404         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7405         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7406         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7407         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7408         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7409                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7410         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7411         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7412         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7413         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7414         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7415         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7416         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7417         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7418         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7419         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7420         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7421         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7422         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7423         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7424         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7425         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7426         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7427         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7428         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7429         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7430         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7431         {
7432                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7433                 /* .name = "Capture Source", */
7434                 .name = "Input Source",
7435                 .count = 2,
7436                 .info = alc883_mux_enum_info,
7437                 .get = alc883_mux_enum_get,
7438                 .put = alc883_mux_enum_put,
7439         },
7440         { } /* end */
7441 };
7442
7443 static struct hda_bind_ctls alc883_bind_cap_vol = {
7444         .ops = &snd_hda_bind_vol,
7445         .values = {
7446                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7447                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7448                 0
7449         },
7450 };
7451
7452 static struct hda_bind_ctls alc883_bind_cap_switch = {
7453         .ops = &snd_hda_bind_sw,
7454         .values = {
7455                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7456                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7457                 0
7458         },
7459 };
7460
7461 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7462         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7463         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7464         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7465         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7466         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7467         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7468         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7469         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7470         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7471         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7472         {
7473                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7474                 /* .name = "Capture Source", */
7475                 .name = "Input Source",
7476                 .count = 1,
7477                 .info = alc883_mux_enum_info,
7478                 .get = alc883_mux_enum_get,
7479                 .put = alc883_mux_enum_put,
7480         },
7481         { } /* end */
7482 };
7483
7484 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7485         {
7486                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7487                 .name = "Channel Mode",
7488                 .info = alc_ch_mode_info,
7489                 .get = alc_ch_mode_get,
7490                 .put = alc_ch_mode_put,
7491         },
7492         { } /* end */
7493 };
7494
7495 static struct hda_verb alc883_init_verbs[] = {
7496         /* ADC1: mute amp left and right */
7497         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7498         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7499         /* ADC2: mute amp left and right */
7500         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7501         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7502         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7503         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7504         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7505         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7506         /* Rear mixer */
7507         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7508         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7509         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7510         /* CLFE mixer */
7511         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7512         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7513         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7514         /* Side mixer */
7515         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7516         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7517         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7518
7519         /* mute analog input loopbacks */
7520         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7521         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7522         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7523         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7524         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7525
7526         /* Front Pin: output 0 (0x0c) */
7527         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7528         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7529         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7530         /* Rear Pin: output 1 (0x0d) */
7531         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7532         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7533         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7534         /* CLFE Pin: output 2 (0x0e) */
7535         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7536         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7537         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7538         /* Side Pin: output 3 (0x0f) */
7539         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7540         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7541         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7542         /* Mic (rear) pin: input vref at 80% */
7543         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7544         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7545         /* Front Mic pin: input vref at 80% */
7546         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7547         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7548         /* Line In pin: input */
7549         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7550         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7551         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7552         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7553         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7554         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7555         /* CD pin widget for input */
7556         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7557
7558         /* FIXME: use matrix-type input source selection */
7559         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7560         /* Input mixer2 */
7561         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7562         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7563         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7564         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7565         /* Input mixer3 */
7566         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7567         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7568         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7569         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7570         { }
7571 };
7572
7573 /* toggle speaker-output according to the hp-jack state */
7574 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7575 {
7576         unsigned int present;
7577
7578         present = snd_hda_codec_read(codec, 0x15, 0,
7579                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7580         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7581                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7582         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7583                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7584 }
7585
7586 /* auto-toggle front mic */
7587 /*
7588 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7589 {
7590         unsigned int present;
7591         unsigned char bits;
7592
7593         present = snd_hda_codec_read(codec, 0x18, 0,
7594                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7595         bits = present ? HDA_AMP_MUTE : 0;
7596         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7597 }
7598 */
7599
7600 static void alc883_mitac_automute(struct hda_codec *codec)
7601 {
7602         alc883_mitac_hp_automute(codec);
7603         /* alc883_mitac_mic_automute(codec); */
7604 }
7605
7606 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7607                                            unsigned int res)
7608 {
7609         switch (res >> 26) {
7610         case ALC880_HP_EVENT:
7611                 alc883_mitac_hp_automute(codec);
7612                 break;
7613         case ALC880_MIC_EVENT:
7614                 /* alc883_mitac_mic_automute(codec); */
7615                 break;
7616         }
7617 }
7618
7619 static struct hda_verb alc883_mitac_verbs[] = {
7620         /* HP */
7621         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7622         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7623         /* Subwoofer */
7624         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7625         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7626
7627         /* enable unsolicited event */
7628         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7629         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7630
7631         { } /* end */
7632 };
7633
7634 static struct hda_verb alc883_clevo_m720_verbs[] = {
7635         /* HP */
7636         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7637         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7638         /* Int speaker */
7639         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7640         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7641
7642         /* enable unsolicited event */
7643         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7644         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7645
7646         { } /* end */
7647 };
7648
7649 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7650         /* HP */
7651         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7652         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7653         /* Subwoofer */
7654         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7655         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7656
7657         /* enable unsolicited event */
7658         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7659
7660         { } /* end */
7661 };
7662
7663 static struct hda_verb alc883_tagra_verbs[] = {
7664         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7665         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7666
7667         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7668         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7669
7670         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7671         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7672         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7673
7674         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7675         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7676         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7677         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7678
7679         { } /* end */
7680 };
7681
7682 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7683         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7684         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7685         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7686         { } /* end */
7687 };
7688
7689 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7690         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7691         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7692         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7693         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7694         { } /* end */
7695 };
7696
7697 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7698         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7699         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7700         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7701         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7702         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7703         { } /* end */
7704 };
7705
7706 static struct hda_verb alc883_haier_w66_verbs[] = {
7707         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7708         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7709
7710         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7711
7712         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7713         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7714         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7715         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7716         { } /* end */
7717 };
7718
7719 static struct hda_verb alc888_lenovo_sky_verbs[] = {
7720         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7721         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7722         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7723         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7724         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7725         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7726         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7727         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7728         { } /* end */
7729 };
7730
7731 static struct hda_verb alc888_3st_hp_verbs[] = {
7732         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7733         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7734         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7735         { }
7736 };
7737
7738 static struct hda_verb alc888_6st_dell_verbs[] = {
7739         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7740         { }
7741 };
7742
7743 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7744         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7745         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7746         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7747         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7748         { }
7749 };
7750
7751 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7752         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7753         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7754         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7755         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7756         { }
7757 };
7758
7759 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7760         { 2, alc888_3st_hp_2ch_init },
7761         { 6, alc888_3st_hp_6ch_init },
7762 };
7763
7764 /* toggle front-jack and RCA according to the hp-jack state */
7765 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7766 {
7767         unsigned int present;
7768
7769         present = snd_hda_codec_read(codec, 0x1b, 0,
7770                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7771         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7772                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7773         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7774                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7775 }
7776
7777 /* toggle RCA according to the front-jack state */
7778 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7779 {
7780         unsigned int present;
7781
7782         present = snd_hda_codec_read(codec, 0x14, 0,
7783                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7784         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7785                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7786 }
7787
7788 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7789                                              unsigned int res)
7790 {
7791         if ((res >> 26) == ALC880_HP_EVENT)
7792                 alc888_lenovo_ms7195_front_automute(codec);
7793         if ((res >> 26) == ALC880_FRONT_EVENT)
7794                 alc888_lenovo_ms7195_rca_automute(codec);
7795 }
7796
7797 static struct hda_verb alc883_medion_md2_verbs[] = {
7798         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7799         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7800
7801         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7802
7803         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7804         { } /* end */
7805 };
7806
7807 /* toggle speaker-output according to the hp-jack state */
7808 static void alc883_medion_md2_automute(struct hda_codec *codec)
7809 {
7810         unsigned int present;
7811
7812         present = snd_hda_codec_read(codec, 0x14, 0,
7813                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7814         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7815                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7816 }
7817
7818 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7819                                           unsigned int res)
7820 {
7821         if ((res >> 26) == ALC880_HP_EVENT)
7822                 alc883_medion_md2_automute(codec);
7823 }
7824
7825 /* toggle speaker-output according to the hp-jack state */
7826 static void alc883_tagra_automute(struct hda_codec *codec)
7827 {
7828         unsigned int present;
7829         unsigned char bits;
7830
7831         present = snd_hda_codec_read(codec, 0x14, 0,
7832                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7833         bits = present ? HDA_AMP_MUTE : 0;
7834         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7835                                  HDA_AMP_MUTE, bits);
7836         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7837                                   present ? 1 : 3);
7838 }
7839
7840 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7841 {
7842         if ((res >> 26) == ALC880_HP_EVENT)
7843                 alc883_tagra_automute(codec);
7844 }
7845
7846 /* toggle speaker-output according to the hp-jack state */
7847 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7848 {
7849         unsigned int present;
7850         unsigned char bits;
7851
7852         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7853                 & AC_PINSENSE_PRESENCE;
7854         bits = present ? HDA_AMP_MUTE : 0;
7855         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7856                                  HDA_AMP_MUTE, bits);
7857 }
7858
7859 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7860 {
7861         unsigned int present;
7862
7863         present = snd_hda_codec_read(codec, 0x18, 0,
7864                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7865         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7866                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7867 }
7868
7869 static void alc883_clevo_m720_automute(struct hda_codec *codec)
7870 {
7871         alc883_clevo_m720_hp_automute(codec);
7872         alc883_clevo_m720_mic_automute(codec);
7873 }
7874
7875 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7876                                            unsigned int res)
7877 {
7878         switch (res >> 26) {
7879         case ALC880_HP_EVENT:
7880                 alc883_clevo_m720_hp_automute(codec);
7881                 break;
7882         case ALC880_MIC_EVENT:
7883                 alc883_clevo_m720_mic_automute(codec);
7884                 break;
7885         }
7886 }
7887
7888 /* toggle speaker-output according to the hp-jack state */
7889 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7890 {
7891         unsigned int present;
7892         unsigned char bits;
7893
7894         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7895                 & AC_PINSENSE_PRESENCE;
7896         bits = present ? HDA_AMP_MUTE : 0;
7897         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7898                                  HDA_AMP_MUTE, bits);
7899 }
7900
7901 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7902                                                   unsigned int res)
7903 {
7904         if ((res >> 26) == ALC880_HP_EVENT)
7905                 alc883_2ch_fujitsu_pi2515_automute(codec);
7906 }
7907
7908 static void alc883_haier_w66_automute(struct hda_codec *codec)
7909 {
7910         unsigned int present;
7911         unsigned char bits;
7912
7913         present = snd_hda_codec_read(codec, 0x1b, 0,
7914                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7915         bits = present ? 0x80 : 0;
7916         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7917                                  0x80, bits);
7918 }
7919
7920 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7921                                          unsigned int res)
7922 {
7923         if ((res >> 26) == ALC880_HP_EVENT)
7924                 alc883_haier_w66_automute(codec);
7925 }
7926
7927 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7928 {
7929         unsigned int present;
7930         unsigned char bits;
7931
7932         present = snd_hda_codec_read(codec, 0x14, 0,
7933                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7934         bits = present ? HDA_AMP_MUTE : 0;
7935         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7936                                  HDA_AMP_MUTE, bits);
7937 }
7938
7939 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7940 {
7941         unsigned int present;
7942         unsigned char bits;
7943
7944         present = snd_hda_codec_read(codec, 0x1b, 0,
7945                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7946         bits = present ? HDA_AMP_MUTE : 0;
7947         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7948                                  HDA_AMP_MUTE, bits);
7949         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7950                                  HDA_AMP_MUTE, bits);
7951 }
7952
7953 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7954                                            unsigned int res)
7955 {
7956         if ((res >> 26) == ALC880_HP_EVENT)
7957                 alc883_lenovo_101e_all_automute(codec);
7958         if ((res >> 26) == ALC880_FRONT_EVENT)
7959                 alc883_lenovo_101e_ispeaker_automute(codec);
7960 }
7961
7962 /* toggle speaker-output according to the hp-jack state */
7963 static void alc883_acer_aspire_automute(struct hda_codec *codec)
7964 {
7965         unsigned int present;
7966
7967         present = snd_hda_codec_read(codec, 0x14, 0,
7968                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7969         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7970                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7971         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7972                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7973 }
7974
7975 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
7976                                            unsigned int res)
7977 {
7978         if ((res >> 26) == ALC880_HP_EVENT)
7979                 alc883_acer_aspire_automute(codec);
7980 }
7981
7982 static struct hda_verb alc883_acer_eapd_verbs[] = {
7983         /* HP Pin: output 0 (0x0c) */
7984         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7985         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7986         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7987         /* Front Pin: output 0 (0x0c) */
7988         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7989         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7990         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7991         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
7992         /* eanable EAPD on medion laptop */
7993         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7994         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
7995         /* enable unsolicited event */
7996         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7997         { }
7998 };
7999
8000 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
8001 {
8002         unsigned int present;
8003
8004         present = snd_hda_codec_read(codec, 0x1b, 0,
8005                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8006         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8007                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8008         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8009                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8010         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8011                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8012         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8013                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8014 }
8015
8016 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8017                                              unsigned int res)
8018 {
8019         switch (res >> 26) {
8020         case ALC880_HP_EVENT:
8021                 printk("hp_event\n");
8022                 alc888_6st_dell_front_automute(codec);
8023                 break;
8024         }
8025 }
8026
8027 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8028 {
8029         unsigned int mute;
8030         unsigned int present;
8031
8032         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8033         present = snd_hda_codec_read(codec, 0x1b, 0,
8034                                      AC_VERB_GET_PIN_SENSE, 0);
8035         present = (present & 0x80000000) != 0;
8036         if (present) {
8037                 /* mute internal speaker */
8038                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8039                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8040                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8041                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8042                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8043                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8044                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8045                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8046                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8047                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8048         } else {
8049                 /* unmute internal speaker if necessary */
8050                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8051                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8052                                          HDA_AMP_MUTE, mute);
8053                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8054                                          HDA_AMP_MUTE, mute);
8055                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8056                                          HDA_AMP_MUTE, mute);
8057                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8058                                          HDA_AMP_MUTE, mute);
8059                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8060                                          HDA_AMP_MUTE, mute);
8061         }
8062 }
8063
8064 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8065                                              unsigned int res)
8066 {
8067         if ((res >> 26) == ALC880_HP_EVENT)
8068                 alc888_lenovo_sky_front_automute(codec);
8069 }
8070
8071 /*
8072  * generic initialization of ADC, input mixers and output mixers
8073  */
8074 static struct hda_verb alc883_auto_init_verbs[] = {
8075         /*
8076          * Unmute ADC0-2 and set the default input to mic-in
8077          */
8078         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8079         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8080         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8081         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8082
8083         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8084          * mixer widget
8085          * Note: PASD motherboards uses the Line In 2 as the input for
8086          * front panel mic (mic 2)
8087          */
8088         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8089         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8090         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8091         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8092         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8093         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8094
8095         /*
8096          * Set up output mixers (0x0c - 0x0f)
8097          */
8098         /* set vol=0 to output mixers */
8099         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8100         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8101         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8102         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8103         /* set up input amps for analog loopback */
8104         /* Amp Indices: DAC = 0, mixer = 1 */
8105         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8106         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8107         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8108         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8109         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8110         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8111         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8112         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8113         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8114         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8115
8116         /* FIXME: use matrix-type input source selection */
8117         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8118         /* Input mixer1 */
8119         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8120         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8121         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8122         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8123         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8124         /* Input mixer2 */
8125         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8126         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8127         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8128         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8129         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8130
8131         { }
8132 };
8133
8134 /* capture mixer elements */
8135 static struct snd_kcontrol_new alc883_capture_mixer[] = {
8136         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
8137         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
8138         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
8139         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
8140         {
8141                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8142                 /* The multiple "Capture Source" controls confuse alsamixer
8143                  * So call somewhat different..
8144                  */
8145                 /* .name = "Capture Source", */
8146                 .name = "Input Source",
8147                 .count = 2,
8148                 .info = alc882_mux_enum_info,
8149                 .get = alc882_mux_enum_get,
8150                 .put = alc882_mux_enum_put,
8151         },
8152         { } /* end */
8153 };
8154
8155 static struct hda_verb alc888_asus_m90v_verbs[] = {
8156         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8157         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8158         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8159         /* enable unsolicited event */
8160         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8161         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8162         { } /* end */
8163 };
8164
8165 static void alc883_nb_mic_automute(struct hda_codec *codec)
8166 {
8167         unsigned int present;
8168
8169         present = snd_hda_codec_read(codec, 0x18, 0,
8170                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8171         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8172                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8173         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8174                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8175 }
8176
8177 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8178 {
8179         unsigned int present;
8180         unsigned char bits;
8181
8182         present = snd_hda_codec_read(codec, 0x1b, 0,
8183                                      AC_VERB_GET_PIN_SENSE, 0)
8184                 & AC_PINSENSE_PRESENCE;
8185         bits = present ? 0 : PIN_OUT;
8186         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8187                             bits);
8188         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8189                             bits);
8190         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8191                             bits);
8192 }
8193
8194 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8195                                            unsigned int res)
8196 {
8197         switch (res >> 26) {
8198         case ALC880_HP_EVENT:
8199                 alc883_M90V_speaker_automute(codec);
8200                 break;
8201         case ALC880_MIC_EVENT:
8202                 alc883_nb_mic_automute(codec);
8203                 break;
8204         }
8205 }
8206
8207 static void alc883_mode2_inithook(struct hda_codec *codec)
8208 {
8209         alc883_M90V_speaker_automute(codec);
8210         alc883_nb_mic_automute(codec);
8211 }
8212
8213 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8214         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8215         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8216         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8217         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8218         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8219         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8220         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8221         /* enable unsolicited event */
8222         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8223         { } /* end */
8224 };
8225
8226 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8227 {
8228         unsigned int present;
8229         unsigned char bits;
8230
8231         present = snd_hda_codec_read(codec, 0x14, 0,
8232                                      AC_VERB_GET_PIN_SENSE, 0)
8233                 & AC_PINSENSE_PRESENCE;
8234         bits = present ? 0 : PIN_OUT;
8235         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8236                             bits);
8237 }
8238
8239 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8240                                            unsigned int res)
8241 {
8242         switch (res >> 26) {
8243         case ALC880_HP_EVENT:
8244                 alc883_eee1601_speaker_automute(codec);
8245                 break;
8246         }
8247 }
8248
8249 static void alc883_eee1601_inithook(struct hda_codec *codec)
8250 {
8251         alc883_eee1601_speaker_automute(codec);
8252 }
8253
8254 #ifdef CONFIG_SND_HDA_POWER_SAVE
8255 #define alc883_loopbacks        alc880_loopbacks
8256 #endif
8257
8258 /* pcm configuration: identiacal with ALC880 */
8259 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8260 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8261 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8262 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8263 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8264
8265 /*
8266  * configuration and preset
8267  */
8268 static const char *alc883_models[ALC883_MODEL_LAST] = {
8269         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8270         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8271         [ALC883_3ST_6ch]        = "3stack-6ch",
8272         [ALC883_6ST_DIG]        = "6stack-dig",
8273         [ALC883_TARGA_DIG]      = "targa-dig",
8274         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8275         [ALC883_ACER]           = "acer",
8276         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8277         [ALC883_MEDION]         = "medion",
8278         [ALC883_MEDION_MD2]     = "medion-md2",
8279         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8280         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8281         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8282         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8283         [ALC888_LENOVO_SKY] = "lenovo-sky",
8284         [ALC883_HAIER_W66]      = "haier-w66",
8285         [ALC888_3ST_HP]         = "3stack-hp",
8286         [ALC888_6ST_DELL]       = "6stack-dell",
8287         [ALC883_MITAC]          = "mitac",
8288         [ALC883_CLEVO_M720]     = "clevo-m720",
8289         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8290         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8291         [ALC883_AUTO]           = "auto",
8292 };
8293
8294 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8295         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8296         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8297         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8298         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8299         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8300         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8301         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8302         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8303         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8304         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8305         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8306         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8307         SND_PCI_QUIRK(0x1043, 0x8317, "Asus M90V", ALC888_ASUS_M90V),
8308         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8309         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8310         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8311         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8312         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8313         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8314         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8315         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8316         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8317         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8318         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8319         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8320         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8321         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8322         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8323         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8324         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8325         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8326         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8327         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8328         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8329         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8330         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8331         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8332         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8333         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8334         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8335         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8336         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8337         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8338         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8339         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8340         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8341         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8342         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8343         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8344         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8345         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8346         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8347         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8348         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8349         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8350         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8351         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8352         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8353         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8354         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8355         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8356         {}
8357 };
8358
8359 static struct alc_config_preset alc883_presets[] = {
8360         [ALC883_3ST_2ch_DIG] = {
8361                 .mixers = { alc883_3ST_2ch_mixer },
8362                 .init_verbs = { alc883_init_verbs },
8363                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8364                 .dac_nids = alc883_dac_nids,
8365                 .dig_out_nid = ALC883_DIGOUT_NID,
8366                 .dig_in_nid = ALC883_DIGIN_NID,
8367                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8368                 .channel_mode = alc883_3ST_2ch_modes,
8369                 .input_mux = &alc883_capture_source,
8370         },
8371         [ALC883_3ST_6ch_DIG] = {
8372                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8373                 .init_verbs = { alc883_init_verbs },
8374                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8375                 .dac_nids = alc883_dac_nids,
8376                 .dig_out_nid = ALC883_DIGOUT_NID,
8377                 .dig_in_nid = ALC883_DIGIN_NID,
8378                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8379                 .channel_mode = alc883_3ST_6ch_modes,
8380                 .need_dac_fix = 1,
8381                 .input_mux = &alc883_capture_source,
8382         },
8383         [ALC883_3ST_6ch] = {
8384                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8385                 .init_verbs = { alc883_init_verbs },
8386                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8387                 .dac_nids = alc883_dac_nids,
8388                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8389                 .channel_mode = alc883_3ST_6ch_modes,
8390                 .need_dac_fix = 1,
8391                 .input_mux = &alc883_capture_source,
8392         },
8393         [ALC883_3ST_6ch_INTEL] = {
8394                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8395                 .init_verbs = { alc883_init_verbs },
8396                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8397                 .dac_nids = alc883_dac_nids,
8398                 .dig_out_nid = ALC883_DIGOUT_NID,
8399                 .dig_in_nid = ALC883_DIGIN_NID,
8400                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8401                 .channel_mode = alc883_3ST_6ch_intel_modes,
8402                 .need_dac_fix = 1,
8403                 .input_mux = &alc883_3stack_6ch_intel,
8404         },
8405         [ALC883_6ST_DIG] = {
8406                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8407                 .init_verbs = { alc883_init_verbs },
8408                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8409                 .dac_nids = alc883_dac_nids,
8410                 .dig_out_nid = ALC883_DIGOUT_NID,
8411                 .dig_in_nid = ALC883_DIGIN_NID,
8412                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8413                 .channel_mode = alc883_sixstack_modes,
8414                 .input_mux = &alc883_capture_source,
8415         },
8416         [ALC883_TARGA_DIG] = {
8417                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8418                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8419                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8420                 .dac_nids = alc883_dac_nids,
8421                 .dig_out_nid = ALC883_DIGOUT_NID,
8422                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8423                 .channel_mode = alc883_3ST_6ch_modes,
8424                 .need_dac_fix = 1,
8425                 .input_mux = &alc883_capture_source,
8426                 .unsol_event = alc883_tagra_unsol_event,
8427                 .init_hook = alc883_tagra_automute,
8428         },
8429         [ALC883_TARGA_2ch_DIG] = {
8430                 .mixers = { alc883_tagra_2ch_mixer},
8431                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8432                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8433                 .dac_nids = alc883_dac_nids,
8434                 .dig_out_nid = ALC883_DIGOUT_NID,
8435                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8436                 .channel_mode = alc883_3ST_2ch_modes,
8437                 .input_mux = &alc883_capture_source,
8438                 .unsol_event = alc883_tagra_unsol_event,
8439                 .init_hook = alc883_tagra_automute,
8440         },
8441         [ALC883_ACER] = {
8442                 .mixers = { alc883_base_mixer },
8443                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8444                  * and the headphone jack.  Turn this on and rely on the
8445                  * standard mute methods whenever the user wants to turn
8446                  * these outputs off.
8447                  */
8448                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8449                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8450                 .dac_nids = alc883_dac_nids,
8451                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8452                 .channel_mode = alc883_3ST_2ch_modes,
8453                 .input_mux = &alc883_capture_source,
8454         },
8455         [ALC883_ACER_ASPIRE] = {
8456                 .mixers = { alc883_acer_aspire_mixer },
8457                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8458                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8459                 .dac_nids = alc883_dac_nids,
8460                 .dig_out_nid = ALC883_DIGOUT_NID,
8461                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8462                 .channel_mode = alc883_3ST_2ch_modes,
8463                 .input_mux = &alc883_capture_source,
8464                 .unsol_event = alc883_acer_aspire_unsol_event,
8465                 .init_hook = alc883_acer_aspire_automute,
8466         },
8467         [ALC883_MEDION] = {
8468                 .mixers = { alc883_fivestack_mixer,
8469                             alc883_chmode_mixer },
8470                 .init_verbs = { alc883_init_verbs,
8471                                 alc883_medion_eapd_verbs },
8472                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8473                 .dac_nids = alc883_dac_nids,
8474                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8475                 .channel_mode = alc883_sixstack_modes,
8476                 .input_mux = &alc883_capture_source,
8477         },
8478         [ALC883_MEDION_MD2] = {
8479                 .mixers = { alc883_medion_md2_mixer},
8480                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8481                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8482                 .dac_nids = alc883_dac_nids,
8483                 .dig_out_nid = ALC883_DIGOUT_NID,
8484                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8485                 .channel_mode = alc883_3ST_2ch_modes,
8486                 .input_mux = &alc883_capture_source,
8487                 .unsol_event = alc883_medion_md2_unsol_event,
8488                 .init_hook = alc883_medion_md2_automute,
8489         },
8490         [ALC883_LAPTOP_EAPD] = {
8491                 .mixers = { alc883_base_mixer },
8492                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8493                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8494                 .dac_nids = alc883_dac_nids,
8495                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8496                 .channel_mode = alc883_3ST_2ch_modes,
8497                 .input_mux = &alc883_capture_source,
8498         },
8499         [ALC883_CLEVO_M720] = {
8500                 .mixers = { alc883_clevo_m720_mixer },
8501                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8502                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8503                 .dac_nids = alc883_dac_nids,
8504                 .dig_out_nid = ALC883_DIGOUT_NID,
8505                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8506                 .channel_mode = alc883_3ST_2ch_modes,
8507                 .input_mux = &alc883_capture_source,
8508                 .unsol_event = alc883_clevo_m720_unsol_event,
8509                 .init_hook = alc883_clevo_m720_automute,
8510         },
8511         [ALC883_LENOVO_101E_2ch] = {
8512                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8513                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8514                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8515                 .dac_nids = alc883_dac_nids,
8516                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8517                 .channel_mode = alc883_3ST_2ch_modes,
8518                 .input_mux = &alc883_lenovo_101e_capture_source,
8519                 .unsol_event = alc883_lenovo_101e_unsol_event,
8520                 .init_hook = alc883_lenovo_101e_all_automute,
8521         },
8522         [ALC883_LENOVO_NB0763] = {
8523                 .mixers = { alc883_lenovo_nb0763_mixer },
8524                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8525                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8526                 .dac_nids = alc883_dac_nids,
8527                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8528                 .channel_mode = alc883_3ST_2ch_modes,
8529                 .need_dac_fix = 1,
8530                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8531                 .unsol_event = alc883_medion_md2_unsol_event,
8532                 .init_hook = alc883_medion_md2_automute,
8533         },
8534         [ALC888_LENOVO_MS7195_DIG] = {
8535                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8536                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8537                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8538                 .dac_nids = alc883_dac_nids,
8539                 .dig_out_nid = ALC883_DIGOUT_NID,
8540                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8541                 .channel_mode = alc883_3ST_6ch_modes,
8542                 .need_dac_fix = 1,
8543                 .input_mux = &alc883_capture_source,
8544                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8545                 .init_hook = alc888_lenovo_ms7195_front_automute,
8546         },
8547         [ALC883_HAIER_W66] = {
8548                 .mixers = { alc883_tagra_2ch_mixer},
8549                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8550                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8551                 .dac_nids = alc883_dac_nids,
8552                 .dig_out_nid = ALC883_DIGOUT_NID,
8553                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8554                 .channel_mode = alc883_3ST_2ch_modes,
8555                 .input_mux = &alc883_capture_source,
8556                 .unsol_event = alc883_haier_w66_unsol_event,
8557                 .init_hook = alc883_haier_w66_automute,
8558         },
8559         [ALC888_3ST_HP] = {
8560                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8561                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8562                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8563                 .dac_nids = alc883_dac_nids,
8564                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8565                 .channel_mode = alc888_3st_hp_modes,
8566                 .need_dac_fix = 1,
8567                 .input_mux = &alc883_capture_source,
8568         },
8569         [ALC888_6ST_DELL] = {
8570                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8571                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8572                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8573                 .dac_nids = alc883_dac_nids,
8574                 .dig_out_nid = ALC883_DIGOUT_NID,
8575                 .dig_in_nid = ALC883_DIGIN_NID,
8576                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8577                 .channel_mode = alc883_sixstack_modes,
8578                 .input_mux = &alc883_capture_source,
8579                 .unsol_event = alc888_6st_dell_unsol_event,
8580                 .init_hook = alc888_6st_dell_front_automute,
8581         },
8582         [ALC883_MITAC] = {
8583                 .mixers = { alc883_mitac_mixer },
8584                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8585                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8586                 .dac_nids = alc883_dac_nids,
8587                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8588                 .channel_mode = alc883_3ST_2ch_modes,
8589                 .input_mux = &alc883_capture_source,
8590                 .unsol_event = alc883_mitac_unsol_event,
8591                 .init_hook = alc883_mitac_automute,
8592         },
8593         [ALC883_FUJITSU_PI2515] = {
8594                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8595                 .init_verbs = { alc883_init_verbs,
8596                                 alc883_2ch_fujitsu_pi2515_verbs},
8597                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8598                 .dac_nids = alc883_dac_nids,
8599                 .dig_out_nid = ALC883_DIGOUT_NID,
8600                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8601                 .channel_mode = alc883_3ST_2ch_modes,
8602                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8603                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8604                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8605         },
8606         [ALC888_LENOVO_SKY] = {
8607                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8608                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8609                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8610                 .dac_nids = alc883_dac_nids,
8611                 .dig_out_nid = ALC883_DIGOUT_NID,
8612                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
8613                 .adc_nids = alc883_adc_nids,
8614                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8615                 .channel_mode = alc883_sixstack_modes,
8616                 .need_dac_fix = 1,
8617                 .input_mux = &alc883_lenovo_sky_capture_source,
8618                 .unsol_event = alc883_lenovo_sky_unsol_event,
8619                 .init_hook = alc888_lenovo_sky_front_automute,
8620         },
8621         [ALC888_ASUS_M90V] = {
8622                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8623                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8624                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8625                 .dac_nids = alc883_dac_nids,
8626                 .dig_out_nid = ALC883_DIGOUT_NID,
8627                 .dig_in_nid = ALC883_DIGIN_NID,
8628                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8629                 .channel_mode = alc883_3ST_6ch_modes,
8630                 .need_dac_fix = 1,
8631                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8632                 .unsol_event = alc883_mode2_unsol_event,
8633                 .init_hook = alc883_mode2_inithook,
8634         },
8635         [ALC888_ASUS_EEE1601] = {
8636                 .mixers = { alc883_asus_eee1601_mixer },
8637                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8638                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8639                 .dac_nids = alc883_dac_nids,
8640                 .dig_out_nid = ALC883_DIGOUT_NID,
8641                 .dig_in_nid = ALC883_DIGIN_NID,
8642                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8643                 .channel_mode = alc883_3ST_2ch_modes,
8644                 .need_dac_fix = 1,
8645                 .input_mux = &alc883_asus_eee1601_capture_source,
8646                 .unsol_event = alc883_eee1601_unsol_event,
8647                 .init_hook = alc883_eee1601_inithook,
8648         },
8649 };
8650
8651
8652 /*
8653  * BIOS auto configuration
8654  */
8655 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8656                                               hda_nid_t nid, int pin_type,
8657                                               int dac_idx)
8658 {
8659         /* set as output */
8660         struct alc_spec *spec = codec->spec;
8661         int idx;
8662
8663         alc_set_pin_output(codec, nid, pin_type);
8664         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8665                 idx = 4;
8666         else
8667                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8668         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8669
8670 }
8671
8672 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8673 {
8674         struct alc_spec *spec = codec->spec;
8675         int i;
8676
8677         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8678         for (i = 0; i <= HDA_SIDE; i++) {
8679                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8680                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8681                 if (nid)
8682                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8683                                                           i);
8684         }
8685 }
8686
8687 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8688 {
8689         struct alc_spec *spec = codec->spec;
8690         hda_nid_t pin;
8691
8692         pin = spec->autocfg.hp_pins[0];
8693         if (pin) /* connect to front */
8694                 /* use dac 0 */
8695                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8696         pin = spec->autocfg.speaker_pins[0];
8697         if (pin)
8698                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8699 }
8700
8701 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8702 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8703
8704 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8705 {
8706         struct alc_spec *spec = codec->spec;
8707         int i;
8708
8709         for (i = 0; i < AUTO_PIN_LAST; i++) {
8710                 hda_nid_t nid = spec->autocfg.input_pins[i];
8711                 if (alc883_is_input_pin(nid)) {
8712                         snd_hda_codec_write(codec, nid, 0,
8713                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8714                                             (i <= AUTO_PIN_FRONT_MIC ?
8715                                              PIN_VREF80 : PIN_IN));
8716                         if (nid != ALC883_PIN_CD_NID)
8717                                 snd_hda_codec_write(codec, nid, 0,
8718                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8719                                                     AMP_OUT_MUTE);
8720                 }
8721         }
8722 }
8723
8724 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8725
8726 /* almost identical with ALC880 parser... */
8727 static int alc883_parse_auto_config(struct hda_codec *codec)
8728 {
8729         struct alc_spec *spec = codec->spec;
8730         int err = alc880_parse_auto_config(codec);
8731
8732         if (err < 0)
8733                 return err;
8734         else if (!err)
8735                 return 0; /* no config found */
8736
8737         err = alc_auto_add_mic_boost(codec);
8738         if (err < 0)
8739                 return err;
8740
8741         /* hack - override the init verbs */
8742         spec->init_verbs[0] = alc883_auto_init_verbs;
8743         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
8744         spec->num_mixers++;
8745
8746         return 1; /* config found */
8747 }
8748
8749 /* additional initialization for auto-configuration model */
8750 static void alc883_auto_init(struct hda_codec *codec)
8751 {
8752         struct alc_spec *spec = codec->spec;
8753         alc883_auto_init_multi_out(codec);
8754         alc883_auto_init_hp_out(codec);
8755         alc883_auto_init_analog_input(codec);
8756         alc883_auto_init_input_src(codec);
8757         if (spec->unsol_event)
8758                 alc_sku_automute(codec);
8759 }
8760
8761 static int patch_alc883(struct hda_codec *codec)
8762 {
8763         struct alc_spec *spec;
8764         int err, board_config;
8765
8766         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8767         if (spec == NULL)
8768                 return -ENOMEM;
8769
8770         codec->spec = spec;
8771
8772         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
8773
8774         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8775                                                   alc883_models,
8776                                                   alc883_cfg_tbl);
8777         if (board_config < 0) {
8778                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8779                        "trying auto-probe from BIOS...\n");
8780                 board_config = ALC883_AUTO;
8781         }
8782
8783         if (board_config == ALC883_AUTO) {
8784                 /* automatic parse from the BIOS config */
8785                 err = alc883_parse_auto_config(codec);
8786                 if (err < 0) {
8787                         alc_free(codec);
8788                         return err;
8789                 } else if (!err) {
8790                         printk(KERN_INFO
8791                                "hda_codec: Cannot set up configuration "
8792                                "from BIOS.  Using base mode...\n");
8793                         board_config = ALC883_3ST_2ch_DIG;
8794                 }
8795         }
8796
8797         if (board_config != ALC883_AUTO)
8798                 setup_preset(spec, &alc883_presets[board_config]);
8799
8800         switch (codec->vendor_id) {
8801         case 0x10ec0888:
8802                 spec->stream_name_analog = "ALC888 Analog";
8803                 spec->stream_name_digital = "ALC888 Digital";
8804                 break;
8805         case 0x10ec0889:
8806                 spec->stream_name_analog = "ALC889 Analog";
8807                 spec->stream_name_digital = "ALC889 Digital";
8808                 break;
8809         default:
8810                 spec->stream_name_analog = "ALC883 Analog";
8811                 spec->stream_name_digital = "ALC883 Digital";
8812                 break;
8813         }
8814
8815         spec->stream_analog_playback = &alc883_pcm_analog_playback;
8816         spec->stream_analog_capture = &alc883_pcm_analog_capture;
8817         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
8818
8819         spec->stream_digital_playback = &alc883_pcm_digital_playback;
8820         spec->stream_digital_capture = &alc883_pcm_digital_capture;
8821
8822         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8823         spec->adc_nids = alc883_adc_nids;
8824         spec->capsrc_nids = alc883_capsrc_nids;
8825
8826         spec->vmaster_nid = 0x0c;
8827
8828         codec->patch_ops = alc_patch_ops;
8829         if (board_config == ALC883_AUTO)
8830                 spec->init_hook = alc883_auto_init;
8831
8832 #ifdef CONFIG_SND_HDA_POWER_SAVE
8833         if (!spec->loopback.amplist)
8834                 spec->loopback.amplist = alc883_loopbacks;
8835 #endif
8836
8837         return 0;
8838 }
8839
8840 /*
8841  * ALC262 support
8842  */
8843
8844 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
8845 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
8846
8847 #define alc262_dac_nids         alc260_dac_nids
8848 #define alc262_adc_nids         alc882_adc_nids
8849 #define alc262_adc_nids_alt     alc882_adc_nids_alt
8850 #define alc262_capsrc_nids      alc882_capsrc_nids
8851 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
8852
8853 #define alc262_modes            alc260_modes
8854 #define alc262_capture_source   alc882_capture_source
8855
8856 static hda_nid_t alc262_dmic_adc_nids[1] = {
8857         /* ADC0 */
8858         0x09
8859 };
8860
8861 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
8862
8863 static struct snd_kcontrol_new alc262_base_mixer[] = {
8864         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8865         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8866         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8867         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8868         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8869         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8870         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8871         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8872         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8873         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8874         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8875         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8876         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8877            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8878         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
8879         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8880         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8881         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
8882         { } /* end */
8883 };
8884
8885 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
8886         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8887         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8888         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8889         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8890         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8891         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8892         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8893         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8894         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8895         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8896         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8897         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8898         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8899            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8900         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
8901         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8902         { } /* end */
8903 };
8904
8905 /* update HP, line and mono-out pins according to the master switch */
8906 static void alc262_hp_master_update(struct hda_codec *codec)
8907 {
8908         struct alc_spec *spec = codec->spec;
8909         int val = spec->master_sw;
8910
8911         /* HP & line-out */
8912         snd_hda_codec_write_cache(codec, 0x1b, 0,
8913                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8914                                   val ? PIN_HP : 0);
8915         snd_hda_codec_write_cache(codec, 0x15, 0,
8916                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8917                                   val ? PIN_HP : 0);
8918         /* mono (speaker) depending on the HP jack sense */
8919         val = val && !spec->jack_present;
8920         snd_hda_codec_write_cache(codec, 0x16, 0,
8921                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8922                                   val ? PIN_OUT : 0);
8923 }
8924
8925 static void alc262_hp_bpc_automute(struct hda_codec *codec)
8926 {
8927         struct alc_spec *spec = codec->spec;
8928         unsigned int presence;
8929         presence = snd_hda_codec_read(codec, 0x1b, 0,
8930                                       AC_VERB_GET_PIN_SENSE, 0);
8931         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8932         alc262_hp_master_update(codec);
8933 }
8934
8935 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
8936 {
8937         if ((res >> 26) != ALC880_HP_EVENT)
8938                 return;
8939         alc262_hp_bpc_automute(codec);
8940 }
8941
8942 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
8943 {
8944         struct alc_spec *spec = codec->spec;
8945         unsigned int presence;
8946         presence = snd_hda_codec_read(codec, 0x15, 0,
8947                                       AC_VERB_GET_PIN_SENSE, 0);
8948         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8949         alc262_hp_master_update(codec);
8950 }
8951
8952 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
8953                                            unsigned int res)
8954 {
8955         if ((res >> 26) != ALC880_HP_EVENT)
8956                 return;
8957         alc262_hp_wildwest_automute(codec);
8958 }
8959
8960 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
8961                                    struct snd_ctl_elem_value *ucontrol)
8962 {
8963         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8964         struct alc_spec *spec = codec->spec;
8965         *ucontrol->value.integer.value = spec->master_sw;
8966         return 0;
8967 }
8968
8969 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
8970                                    struct snd_ctl_elem_value *ucontrol)
8971 {
8972         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8973         struct alc_spec *spec = codec->spec;
8974         int val = !!*ucontrol->value.integer.value;
8975
8976         if (val == spec->master_sw)
8977                 return 0;
8978         spec->master_sw = val;
8979         alc262_hp_master_update(codec);
8980         return 1;
8981 }
8982
8983 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
8984         {
8985                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8986                 .name = "Master Playback Switch",
8987                 .info = snd_ctl_boolean_mono_info,
8988                 .get = alc262_hp_master_sw_get,
8989                 .put = alc262_hp_master_sw_put,
8990         },
8991         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8992         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8993         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8994         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8995                               HDA_OUTPUT),
8996         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8997                             HDA_OUTPUT),
8998         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8999         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9000         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9001         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9002         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9003         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9004         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9005         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9006         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9007         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9008         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9009         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9010         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9011         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9012         { } /* end */
9013 };
9014
9015 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9016         {
9017                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9018                 .name = "Master Playback Switch",
9019                 .info = snd_ctl_boolean_mono_info,
9020                 .get = alc262_hp_master_sw_get,
9021                 .put = alc262_hp_master_sw_put,
9022         },
9023         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9024         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9025         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9026         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9027         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9028                               HDA_OUTPUT),
9029         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9030                             HDA_OUTPUT),
9031         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9032         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9033         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9034         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9035         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9036         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9037         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9038         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9039         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9040         { } /* end */
9041 };
9042
9043 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9044         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9045         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9046         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9047         { } /* end */
9048 };
9049
9050 /* mute/unmute internal speaker according to the hp jack and mute state */
9051 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
9052 {
9053         struct alc_spec *spec = codec->spec;
9054
9055         if (force || !spec->sense_updated) {
9056                 unsigned int present;
9057                 present = snd_hda_codec_read(codec, 0x15, 0,
9058                                              AC_VERB_GET_PIN_SENSE, 0);
9059                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9060                 spec->sense_updated = 1;
9061         }
9062         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
9063                                  spec->jack_present ? HDA_AMP_MUTE : 0);
9064 }
9065
9066 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
9067                                         unsigned int res)
9068 {
9069         if ((res >> 26) != ALC880_HP_EVENT)
9070                 return;
9071         alc262_hp_t5735_automute(codec, 1);
9072 }
9073
9074 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9075 {
9076         alc262_hp_t5735_automute(codec, 1);
9077 }
9078
9079 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9080         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9081         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9082         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9083         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9084         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9085         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9086         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9087         { } /* end */
9088 };
9089
9090 static struct hda_verb alc262_hp_t5735_verbs[] = {
9091         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9092         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9093
9094         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9095         { }
9096 };
9097
9098 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9099         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9100         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9101         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9102         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9103         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9104         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9105         { } /* end */
9106 };
9107
9108 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9109         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9110         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9111         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9112         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9113         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9114         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9115         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9116         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9117         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9118         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9119         {}
9120 };
9121
9122 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9123         .num_items = 1,
9124         .items = {
9125                 { "Line", 0x1 },
9126         },
9127 };
9128
9129 /* bind hp and internal speaker mute (with plug check) */
9130 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9131                                      struct snd_ctl_elem_value *ucontrol)
9132 {
9133         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9134         long *valp = ucontrol->value.integer.value;
9135         int change;
9136
9137         /* change hp mute */
9138         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9139                                           HDA_AMP_MUTE,
9140                                           valp[0] ? 0 : HDA_AMP_MUTE);
9141         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9142                                            HDA_AMP_MUTE,
9143                                            valp[1] ? 0 : HDA_AMP_MUTE);
9144         if (change) {
9145                 /* change speaker according to HP jack state */
9146                 struct alc_spec *spec = codec->spec;
9147                 unsigned int mute;
9148                 if (spec->jack_present)
9149                         mute = HDA_AMP_MUTE;
9150                 else
9151                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9152                                                       HDA_OUTPUT, 0);
9153                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9154                                          HDA_AMP_MUTE, mute);
9155         }
9156         return change;
9157 }
9158
9159 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9160         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9161         {
9162                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9163                 .name = "Master Playback Switch",
9164                 .info = snd_hda_mixer_amp_switch_info,
9165                 .get = snd_hda_mixer_amp_switch_get,
9166                 .put = alc262_sony_master_sw_put,
9167                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9168         },
9169         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9170         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9171         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9172         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9173         { } /* end */
9174 };
9175
9176 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9177         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9178         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9179         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9180         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9181         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9182         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9183         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9184         { } /* end */
9185 };
9186
9187 #define alc262_capture_mixer            alc882_capture_mixer
9188 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9189
9190 /*
9191  * generic initialization of ADC, input mixers and output mixers
9192  */
9193 static struct hda_verb alc262_init_verbs[] = {
9194         /*
9195          * Unmute ADC0-2 and set the default input to mic-in
9196          */
9197         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9198         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9199         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9200         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9201         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9202         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9203
9204         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9205          * mixer widget
9206          * Note: PASD motherboards uses the Line In 2 as the input for
9207          * front panel mic (mic 2)
9208          */
9209         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9210         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9211         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9212         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9213         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9214         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9215
9216         /*
9217          * Set up output mixers (0x0c - 0x0e)
9218          */
9219         /* set vol=0 to output mixers */
9220         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9221         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9222         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9223         /* set up input amps for analog loopback */
9224         /* Amp Indices: DAC = 0, mixer = 1 */
9225         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9226         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9227         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9228         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9229         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9230         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9231
9232         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9233         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9234         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9235         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9236         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9237         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9238
9239         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9240         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9241         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9242         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9243         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9244
9245         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9246         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9247
9248         /* FIXME: use matrix-type input source selection */
9249         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9250         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9251         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9252         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9253         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9254         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9255         /* Input mixer2 */
9256         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9257         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9258         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9259         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9260         /* Input mixer3 */
9261         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9262         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9263         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9264         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9265
9266         { }
9267 };
9268
9269 static struct hda_verb alc262_eapd_verbs[] = {
9270         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9271         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9272         { }
9273 };
9274
9275 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9276         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9277         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9278         {}
9279 };
9280
9281 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9282         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9283         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9284         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9285
9286         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9287         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9288         {}
9289 };
9290
9291 static struct hda_verb alc262_sony_unsol_verbs[] = {
9292         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9293         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9294         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9295
9296         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9297         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9298         {}
9299 };
9300
9301 static struct hda_input_mux alc262_dmic_capture_source = {
9302         .num_items = 2,
9303         .items = {
9304                 { "Int DMic", 0x9 },
9305                 { "Mic", 0x0 },
9306         },
9307 };
9308
9309 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9310         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9311         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9312         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9313         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9314         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9315         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
9316         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
9317         {
9318                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9319                 /* The multiple "Capture Source" controls confuse alsamixer
9320                  * So call somewhat different..
9321                  */
9322                 /* .name = "Capture Source", */
9323                 .name = "Input Source",
9324                 .count = 1,
9325                 .info = alc_mux_enum_info,
9326                 .get = alc_mux_enum_get,
9327                 .put = alc_mux_enum_put,
9328         },
9329         { } /* end */
9330 };
9331
9332 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9333         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9334         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9335         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9336         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9337         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9338         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9339         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9340         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9341         {}
9342 };
9343
9344 static void alc262_dmic_automute(struct hda_codec *codec)
9345 {
9346         unsigned int present;
9347
9348         present = snd_hda_codec_read(codec, 0x18, 0,
9349                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9350         snd_hda_codec_write(codec, 0x22, 0,
9351                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9352 }
9353
9354 /* toggle speaker-output according to the hp-jack state */
9355 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9356 {
9357         unsigned int present;
9358         unsigned char bits;
9359
9360         present = snd_hda_codec_read(codec, 0x15, 0,
9361                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9362         bits = present ? 0 : PIN_OUT;
9363         snd_hda_codec_write(codec, 0x14, 0,
9364                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9365 }
9366
9367
9368
9369 /* unsolicited event for HP jack sensing */
9370 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9371                                        unsigned int res)
9372 {
9373         if ((res >> 26) == ALC880_HP_EVENT)
9374                 alc262_toshiba_s06_speaker_automute(codec);
9375         if ((res >> 26) == ALC880_MIC_EVENT)
9376                 alc262_dmic_automute(codec);
9377
9378 }
9379
9380 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9381 {
9382         alc262_toshiba_s06_speaker_automute(codec);
9383         alc262_dmic_automute(codec);
9384 }
9385
9386 /* mute/unmute internal speaker according to the hp jack and mute state */
9387 static void alc262_hippo_automute(struct hda_codec *codec)
9388 {
9389         struct alc_spec *spec = codec->spec;
9390         unsigned int mute;
9391         unsigned int present;
9392
9393         /* need to execute and sync at first */
9394         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9395         present = snd_hda_codec_read(codec, 0x15, 0,
9396                                      AC_VERB_GET_PIN_SENSE, 0);
9397         spec->jack_present = (present & 0x80000000) != 0;
9398         if (spec->jack_present) {
9399                 /* mute internal speaker */
9400                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9401                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9402         } else {
9403                 /* unmute internal speaker if necessary */
9404                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9405                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9406                                          HDA_AMP_MUTE, mute);
9407         }
9408 }
9409
9410 /* unsolicited event for HP jack sensing */
9411 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9412                                        unsigned int res)
9413 {
9414         if ((res >> 26) != ALC880_HP_EVENT)
9415                 return;
9416         alc262_hippo_automute(codec);
9417 }
9418
9419 static void alc262_hippo1_automute(struct hda_codec *codec)
9420 {
9421         unsigned int mute;
9422         unsigned int present;
9423
9424         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9425         present = snd_hda_codec_read(codec, 0x1b, 0,
9426                                      AC_VERB_GET_PIN_SENSE, 0);
9427         present = (present & 0x80000000) != 0;
9428         if (present) {
9429                 /* mute internal speaker */
9430                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9431                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9432         } else {
9433                 /* unmute internal speaker if necessary */
9434                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9435                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9436                                          HDA_AMP_MUTE, mute);
9437         }
9438 }
9439
9440 /* unsolicited event for HP jack sensing */
9441 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9442                                        unsigned int res)
9443 {
9444         if ((res >> 26) != ALC880_HP_EVENT)
9445                 return;
9446         alc262_hippo1_automute(codec);
9447 }
9448
9449 /*
9450  * nec model
9451  *  0x15 = headphone
9452  *  0x16 = internal speaker
9453  *  0x18 = external mic
9454  */
9455
9456 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9457         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9458         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9459
9460         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9461         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9462         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9463
9464         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9465         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9466         { } /* end */
9467 };
9468
9469 static struct hda_verb alc262_nec_verbs[] = {
9470         /* Unmute Speaker */
9471         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9472
9473         /* Headphone */
9474         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9475         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9476
9477         /* External mic to headphone */
9478         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9479         /* External mic to speaker */
9480         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9481         {}
9482 };
9483
9484 /*
9485  * fujitsu model
9486  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9487  *  0x1b = port replicator headphone out
9488  */
9489
9490 #define ALC_HP_EVENT    0x37
9491
9492 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9493         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9494         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9495         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9496         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9497         {}
9498 };
9499
9500 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9501         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9502         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9503         {}
9504 };
9505
9506 static struct hda_input_mux alc262_fujitsu_capture_source = {
9507         .num_items = 3,
9508         .items = {
9509                 { "Mic", 0x0 },
9510                 { "Int Mic", 0x1 },
9511                 { "CD", 0x4 },
9512         },
9513 };
9514
9515 static struct hda_input_mux alc262_HP_capture_source = {
9516         .num_items = 5,
9517         .items = {
9518                 { "Mic", 0x0 },
9519                 { "Front Mic", 0x1 },
9520                 { "Line", 0x2 },
9521                 { "CD", 0x4 },
9522                 { "AUX IN", 0x6 },
9523         },
9524 };
9525
9526 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9527         .num_items = 4,
9528         .items = {
9529                 { "Mic", 0x0 },
9530                 { "Front Mic", 0x2 },
9531                 { "Line", 0x1 },
9532                 { "CD", 0x4 },
9533         },
9534 };
9535
9536 /* mute/unmute internal speaker according to the hp jacks and mute state */
9537 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9538 {
9539         struct alc_spec *spec = codec->spec;
9540         unsigned int mute;
9541
9542         if (force || !spec->sense_updated) {
9543                 unsigned int present;
9544                 /* need to execute and sync at first */
9545                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9546                 /* check laptop HP jack */
9547                 present = snd_hda_codec_read(codec, 0x14, 0,
9548                                              AC_VERB_GET_PIN_SENSE, 0);
9549                 /* need to execute and sync at first */
9550                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9551                 /* check docking HP jack */
9552                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9553                                               AC_VERB_GET_PIN_SENSE, 0);
9554                 if (present & AC_PINSENSE_PRESENCE)
9555                         spec->jack_present = 1;
9556                 else
9557                         spec->jack_present = 0;
9558                 spec->sense_updated = 1;
9559         }
9560         /* unmute internal speaker only if both HPs are unplugged and
9561          * master switch is on
9562          */
9563         if (spec->jack_present)
9564                 mute = HDA_AMP_MUTE;
9565         else
9566                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9567         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9568                                  HDA_AMP_MUTE, mute);
9569 }
9570
9571 /* unsolicited event for HP jack sensing */
9572 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9573                                        unsigned int res)
9574 {
9575         if ((res >> 26) != ALC_HP_EVENT)
9576                 return;
9577         alc262_fujitsu_automute(codec, 1);
9578 }
9579
9580 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9581 {
9582         alc262_fujitsu_automute(codec, 1);
9583 }
9584
9585 /* bind volumes of both NID 0x0c and 0x0d */
9586 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9587         .ops = &snd_hda_bind_vol,
9588         .values = {
9589                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9590                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9591                 0
9592         },
9593 };
9594
9595 /* mute/unmute internal speaker according to the hp jack and mute state */
9596 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9597 {
9598         struct alc_spec *spec = codec->spec;
9599         unsigned int mute;
9600
9601         if (force || !spec->sense_updated) {
9602                 unsigned int present_int_hp;
9603                 /* need to execute and sync at first */
9604                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9605                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9606                                         AC_VERB_GET_PIN_SENSE, 0);
9607                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9608                 spec->sense_updated = 1;
9609         }
9610         if (spec->jack_present) {
9611                 /* mute internal speaker */
9612                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9613                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9614                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9615                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9616         } else {
9617                 /* unmute internal speaker if necessary */
9618                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9619                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9620                                          HDA_AMP_MUTE, mute);
9621                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9622                                          HDA_AMP_MUTE, mute);
9623         }
9624 }
9625
9626 /* unsolicited event for HP jack sensing */
9627 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9628                                        unsigned int res)
9629 {
9630         if ((res >> 26) != ALC_HP_EVENT)
9631                 return;
9632         alc262_lenovo_3000_automute(codec, 1);
9633 }
9634
9635 /* bind hp and internal speaker mute (with plug check) */
9636 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9637                                          struct snd_ctl_elem_value *ucontrol)
9638 {
9639         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9640         long *valp = ucontrol->value.integer.value;
9641         int change;
9642
9643         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9644                                                  HDA_AMP_MUTE,
9645                                                  valp ? 0 : HDA_AMP_MUTE);
9646         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9647                                                  HDA_AMP_MUTE,
9648                                                  valp ? 0 : HDA_AMP_MUTE);
9649
9650         if (change)
9651                 alc262_fujitsu_automute(codec, 0);
9652         return change;
9653 }
9654
9655 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9656         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9657         {
9658                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9659                 .name = "Master Playback Switch",
9660                 .info = snd_hda_mixer_amp_switch_info,
9661                 .get = snd_hda_mixer_amp_switch_get,
9662                 .put = alc262_fujitsu_master_sw_put,
9663                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9664         },
9665         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9666         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9667         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9668         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9669         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9670         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9671         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9672         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9673         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9674         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9675         { } /* end */
9676 };
9677
9678 /* bind hp and internal speaker mute (with plug check) */
9679 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9680                                          struct snd_ctl_elem_value *ucontrol)
9681 {
9682         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9683         long *valp = ucontrol->value.integer.value;
9684         int change;
9685
9686         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9687                                                  HDA_AMP_MUTE,
9688                                                  valp ? 0 : HDA_AMP_MUTE);
9689
9690         if (change)
9691                 alc262_lenovo_3000_automute(codec, 0);
9692         return change;
9693 }
9694
9695 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9696         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9697         {
9698                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9699                 .name = "Master Playback Switch",
9700                 .info = snd_hda_mixer_amp_switch_info,
9701                 .get = snd_hda_mixer_amp_switch_get,
9702                 .put = alc262_lenovo_3000_master_sw_put,
9703                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9704         },
9705         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9706         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9707         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9708         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9709         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9710         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9711         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9712         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9713         { } /* end */
9714 };
9715
9716 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
9717         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9718         {
9719                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9720                 .name = "Master Playback Switch",
9721                 .info = snd_hda_mixer_amp_switch_info,
9722                 .get = snd_hda_mixer_amp_switch_get,
9723                 .put = alc262_sony_master_sw_put,
9724                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9725         },
9726         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9727         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9728         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9729         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9730         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9731         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9732         { } /* end */
9733 };
9734
9735 /* additional init verbs for Benq laptops */
9736 static struct hda_verb alc262_EAPD_verbs[] = {
9737         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9738         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9739         {}
9740 };
9741
9742 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9743         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9744         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9745
9746         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9747         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9748         {}
9749 };
9750
9751 /* Samsung Q1 Ultra Vista model setup */
9752 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9753         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9754         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9755         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9756         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9757         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9758         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9759         { } /* end */
9760 };
9761
9762 static struct hda_verb alc262_ultra_verbs[] = {
9763         /* output mixer */
9764         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9765         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9766         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9767         /* speaker */
9768         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9769         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9770         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9771         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9772         /* HP */
9773         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9774         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9775         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9776         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9777         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9778         /* internal mic */
9779         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9780         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9781         /* ADC, choose mic */
9782         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9783         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9784         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9785         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9786         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9787         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9788         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9789         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9790         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9791         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
9792         {}
9793 };
9794
9795 /* mute/unmute internal speaker according to the hp jack and mute state */
9796 static void alc262_ultra_automute(struct hda_codec *codec)
9797 {
9798         struct alc_spec *spec = codec->spec;
9799         unsigned int mute;
9800
9801         mute = 0;
9802         /* auto-mute only when HP is used as HP */
9803         if (!spec->cur_mux[0]) {
9804                 unsigned int present;
9805                 /* need to execute and sync at first */
9806                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9807                 present = snd_hda_codec_read(codec, 0x15, 0,
9808                                              AC_VERB_GET_PIN_SENSE, 0);
9809                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9810                 if (spec->jack_present)
9811                         mute = HDA_AMP_MUTE;
9812         }
9813         /* mute/unmute internal speaker */
9814         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9815                                  HDA_AMP_MUTE, mute);
9816         /* mute/unmute HP */
9817         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9818                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
9819 }
9820
9821 /* unsolicited event for HP jack sensing */
9822 static void alc262_ultra_unsol_event(struct hda_codec *codec,
9823                                        unsigned int res)
9824 {
9825         if ((res >> 26) != ALC880_HP_EVENT)
9826                 return;
9827         alc262_ultra_automute(codec);
9828 }
9829
9830 static struct hda_input_mux alc262_ultra_capture_source = {
9831         .num_items = 2,
9832         .items = {
9833                 { "Mic", 0x1 },
9834                 { "Headphone", 0x7 },
9835         },
9836 };
9837
9838 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
9839                                      struct snd_ctl_elem_value *ucontrol)
9840 {
9841         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9842         struct alc_spec *spec = codec->spec;
9843         int ret;
9844
9845         ret = alc882_mux_enum_put(kcontrol, ucontrol);
9846         if (!ret)
9847                 return 0;
9848         /* reprogram the HP pin as mic or HP according to the input source */
9849         snd_hda_codec_write_cache(codec, 0x15, 0,
9850                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9851                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
9852         alc262_ultra_automute(codec); /* mute/unmute HP */
9853         return ret;
9854 }
9855
9856 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
9857         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
9858         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
9859         {
9860                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9861                 .name = "Capture Source",
9862                 .info = alc882_mux_enum_info,
9863                 .get = alc882_mux_enum_get,
9864                 .put = alc262_ultra_mux_enum_put,
9865         },
9866         { } /* end */
9867 };
9868
9869 /* add playback controls from the parsed DAC table */
9870 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
9871                                              const struct auto_pin_cfg *cfg)
9872 {
9873         hda_nid_t nid;
9874         int err;
9875
9876         spec->multiout.num_dacs = 1;    /* only use one dac */
9877         spec->multiout.dac_nids = spec->private_dac_nids;
9878         spec->multiout.dac_nids[0] = 2;
9879
9880         nid = cfg->line_out_pins[0];
9881         if (nid) {
9882                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9883                                   "Front Playback Volume",
9884                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
9885                 if (err < 0)
9886                         return err;
9887                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9888                                   "Front Playback Switch",
9889                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9890                 if (err < 0)
9891                         return err;
9892         }
9893
9894         nid = cfg->speaker_pins[0];
9895         if (nid) {
9896                 if (nid == 0x16) {
9897                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9898                                           "Speaker Playback Volume",
9899                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9900                                                               HDA_OUTPUT));
9901                         if (err < 0)
9902                                 return err;
9903                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9904                                           "Speaker Playback Switch",
9905                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9906                                                               HDA_OUTPUT));
9907                         if (err < 0)
9908                                 return err;
9909                 } else {
9910                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9911                                           "Speaker Playback Switch",
9912                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9913                                                               HDA_OUTPUT));
9914                         if (err < 0)
9915                                 return err;
9916                 }
9917         }
9918         nid = cfg->hp_pins[0];
9919         if (nid) {
9920                 /* spec->multiout.hp_nid = 2; */
9921                 if (nid == 0x16) {
9922                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9923                                           "Headphone Playback Volume",
9924                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9925                                                               HDA_OUTPUT));
9926                         if (err < 0)
9927                                 return err;
9928                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9929                                           "Headphone Playback Switch",
9930                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9931                                                               HDA_OUTPUT));
9932                         if (err < 0)
9933                                 return err;
9934                 } else {
9935                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9936                                           "Headphone Playback Switch",
9937                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9938                                                               HDA_OUTPUT));
9939                         if (err < 0)
9940                                 return err;
9941                 }
9942         }
9943         return 0;
9944 }
9945
9946 /* identical with ALC880 */
9947 #define alc262_auto_create_analog_input_ctls \
9948         alc880_auto_create_analog_input_ctls
9949
9950 /*
9951  * generic initialization of ADC, input mixers and output mixers
9952  */
9953 static struct hda_verb alc262_volume_init_verbs[] = {
9954         /*
9955          * Unmute ADC0-2 and set the default input to mic-in
9956          */
9957         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9958         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9959         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9960         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9961         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9962         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9963
9964         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9965          * mixer widget
9966          * Note: PASD motherboards uses the Line In 2 as the input for
9967          * front panel mic (mic 2)
9968          */
9969         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9970         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9971         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9972         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9973         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9974         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9975
9976         /*
9977          * Set up output mixers (0x0c - 0x0f)
9978          */
9979         /* set vol=0 to output mixers */
9980         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9981         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9982         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9983
9984         /* set up input amps for analog loopback */
9985         /* Amp Indices: DAC = 0, mixer = 1 */
9986         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9987         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9988         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9989         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9990         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9991         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9992
9993         /* FIXME: use matrix-type input source selection */
9994         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9995         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9996         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9997         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9998         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9999         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10000         /* Input mixer2 */
10001         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10002         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10003         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10004         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10005         /* Input mixer3 */
10006         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10007         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10008         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10009         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10010
10011         { }
10012 };
10013
10014 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10015         /*
10016          * Unmute ADC0-2 and set the default input to mic-in
10017          */
10018         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10019         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10020         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10021         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10022         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10023         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10024
10025         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10026          * mixer widget
10027          * Note: PASD motherboards uses the Line In 2 as the input for
10028          * front panel mic (mic 2)
10029          */
10030         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10031         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10032         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10033         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10034         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10035         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10036         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10037         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10038
10039         /*
10040          * Set up output mixers (0x0c - 0x0e)
10041          */
10042         /* set vol=0 to output mixers */
10043         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10044         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10045         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10046
10047         /* set up input amps for analog loopback */
10048         /* Amp Indices: DAC = 0, mixer = 1 */
10049         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10050         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10051         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10052         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10053         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10054         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10055
10056         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10057         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10058         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10059
10060         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10061         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10062
10063         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10064         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10065
10066         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10067         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10068         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10069         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10070         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10071
10072         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10073         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10074         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10075         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10076         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10077         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10078
10079
10080         /* FIXME: use matrix-type input source selection */
10081         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10082         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10083         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10084         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10085         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10086         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10087         /* Input mixer2 */
10088         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10089         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10090         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10091         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10092         /* Input mixer3 */
10093         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10094         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10095         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10096         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10097
10098         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10099
10100         { }
10101 };
10102
10103 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10104         /*
10105          * Unmute ADC0-2 and set the default input to mic-in
10106          */
10107         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10108         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10109         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10110         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10111         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10112         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10113
10114         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10115          * mixer widget
10116          * Note: PASD motherboards uses the Line In 2 as the input for front
10117          * panel mic (mic 2)
10118          */
10119         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10120         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10121         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10122         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10123         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10124         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10125         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10126         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10127         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10128         /*
10129          * Set up output mixers (0x0c - 0x0e)
10130          */
10131         /* set vol=0 to output mixers */
10132         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10133         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10134         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10135
10136         /* set up input amps for analog loopback */
10137         /* Amp Indices: DAC = 0, mixer = 1 */
10138         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10139         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10140         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10141         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10142         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10143         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10144
10145
10146         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10147         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10148         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10149         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10150         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10151         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10152         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10153
10154         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10155         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10156
10157         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10158         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10159
10160         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10161         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10162         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10163         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10164         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10165         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10166
10167         /* FIXME: use matrix-type input source selection */
10168         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10169         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10170         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10171         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10172         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10173         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10174         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10175         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10176         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10177         /* Input mixer2 */
10178         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10179         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10180         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10181         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10182         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10183         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10184         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10185         /* Input mixer3 */
10186         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10187         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10188         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10189         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10190         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10191         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10192         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10193
10194         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10195
10196         { }
10197 };
10198
10199 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10200
10201         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10202         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10203         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10204
10205         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10206         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10207         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10208         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10209
10210         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10211         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10212         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10213         {}
10214 };
10215
10216
10217 #ifdef CONFIG_SND_HDA_POWER_SAVE
10218 #define alc262_loopbacks        alc880_loopbacks
10219 #endif
10220
10221 /* pcm configuration: identiacal with ALC880 */
10222 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10223 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10224 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10225 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10226
10227 /*
10228  * BIOS auto configuration
10229  */
10230 static int alc262_parse_auto_config(struct hda_codec *codec)
10231 {
10232         struct alc_spec *spec = codec->spec;
10233         int err;
10234         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10235
10236         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10237                                            alc262_ignore);
10238         if (err < 0)
10239                 return err;
10240         if (!spec->autocfg.line_outs)
10241                 return 0; /* can't find valid BIOS pin config */
10242         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10243         if (err < 0)
10244                 return err;
10245         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10246         if (err < 0)
10247                 return err;
10248
10249         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10250
10251         if (spec->autocfg.dig_out_pin)
10252                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10253         if (spec->autocfg.dig_in_pin)
10254                 spec->dig_in_nid = ALC262_DIGIN_NID;
10255
10256         if (spec->kctl_alloc)
10257                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10258
10259         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
10260         spec->num_mux_defs = 1;
10261         spec->input_mux = &spec->private_imux;
10262
10263         err = alc_auto_add_mic_boost(codec);
10264         if (err < 0)
10265                 return err;
10266
10267         return 1;
10268 }
10269
10270 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10271 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10272 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10273 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10274
10275
10276 /* init callback for auto-configuration model -- overriding the default init */
10277 static void alc262_auto_init(struct hda_codec *codec)
10278 {
10279         struct alc_spec *spec = codec->spec;
10280         alc262_auto_init_multi_out(codec);
10281         alc262_auto_init_hp_out(codec);
10282         alc262_auto_init_analog_input(codec);
10283         alc262_auto_init_input_src(codec);
10284         if (spec->unsol_event)
10285                 alc_sku_automute(codec);
10286 }
10287
10288 /*
10289  * configuration and preset
10290  */
10291 static const char *alc262_models[ALC262_MODEL_LAST] = {
10292         [ALC262_BASIC]          = "basic",
10293         [ALC262_HIPPO]          = "hippo",
10294         [ALC262_HIPPO_1]        = "hippo_1",
10295         [ALC262_FUJITSU]        = "fujitsu",
10296         [ALC262_HP_BPC]         = "hp-bpc",
10297         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10298         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10299         [ALC262_HP_RP5700]      = "hp-rp5700",
10300         [ALC262_BENQ_ED8]       = "benq",
10301         [ALC262_BENQ_T31]       = "benq-t31",
10302         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10303         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10304         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10305         [ALC262_ULTRA]          = "ultra",
10306         [ALC262_LENOVO_3000]    = "lenovo-3000",
10307         [ALC262_NEC]            = "nec",
10308         [ALC262_AUTO]           = "auto",
10309 };
10310
10311 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10312         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10313         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10314         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
10315         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
10316         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
10317         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
10318         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
10319         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
10320         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10321         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10322         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10323         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10324         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10325         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10326         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10327         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10328         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10329         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10330         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10331         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10332         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10333         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10334                       ALC262_HP_TC_T5735),
10335         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10336         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10337         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10338         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10339         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10340         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10341         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10342                       ALC262_TOSHIBA_RX1),
10343         SND_PCI_QUIRK(0x1179, 0x0268, "Toshiba S06", ALC262_TOSHIBA_S06),
10344         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10345         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10346         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
10347         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
10348         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10349         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10350         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10351         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10352         {}
10353 };
10354
10355 static struct alc_config_preset alc262_presets[] = {
10356         [ALC262_BASIC] = {
10357                 .mixers = { alc262_base_mixer },
10358                 .init_verbs = { alc262_init_verbs },
10359                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10360                 .dac_nids = alc262_dac_nids,
10361                 .hp_nid = 0x03,
10362                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10363                 .channel_mode = alc262_modes,
10364                 .input_mux = &alc262_capture_source,
10365         },
10366         [ALC262_HIPPO] = {
10367                 .mixers = { alc262_base_mixer },
10368                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10369                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10370                 .dac_nids = alc262_dac_nids,
10371                 .hp_nid = 0x03,
10372                 .dig_out_nid = ALC262_DIGOUT_NID,
10373                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10374                 .channel_mode = alc262_modes,
10375                 .input_mux = &alc262_capture_source,
10376                 .unsol_event = alc262_hippo_unsol_event,
10377                 .init_hook = alc262_hippo_automute,
10378         },
10379         [ALC262_HIPPO_1] = {
10380                 .mixers = { alc262_hippo1_mixer },
10381                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10382                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10383                 .dac_nids = alc262_dac_nids,
10384                 .hp_nid = 0x02,
10385                 .dig_out_nid = ALC262_DIGOUT_NID,
10386                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10387                 .channel_mode = alc262_modes,
10388                 .input_mux = &alc262_capture_source,
10389                 .unsol_event = alc262_hippo1_unsol_event,
10390                 .init_hook = alc262_hippo1_automute,
10391         },
10392         [ALC262_FUJITSU] = {
10393                 .mixers = { alc262_fujitsu_mixer },
10394                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10395                                 alc262_fujitsu_unsol_verbs },
10396                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10397                 .dac_nids = alc262_dac_nids,
10398                 .hp_nid = 0x03,
10399                 .dig_out_nid = ALC262_DIGOUT_NID,
10400                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10401                 .channel_mode = alc262_modes,
10402                 .input_mux = &alc262_fujitsu_capture_source,
10403                 .unsol_event = alc262_fujitsu_unsol_event,
10404                 .init_hook = alc262_fujitsu_init_hook,
10405         },
10406         [ALC262_HP_BPC] = {
10407                 .mixers = { alc262_HP_BPC_mixer },
10408                 .init_verbs = { alc262_HP_BPC_init_verbs },
10409                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10410                 .dac_nids = alc262_dac_nids,
10411                 .hp_nid = 0x03,
10412                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10413                 .channel_mode = alc262_modes,
10414                 .input_mux = &alc262_HP_capture_source,
10415                 .unsol_event = alc262_hp_bpc_unsol_event,
10416                 .init_hook = alc262_hp_bpc_automute,
10417         },
10418         [ALC262_HP_BPC_D7000_WF] = {
10419                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10420                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10421                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10422                 .dac_nids = alc262_dac_nids,
10423                 .hp_nid = 0x03,
10424                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10425                 .channel_mode = alc262_modes,
10426                 .input_mux = &alc262_HP_D7000_capture_source,
10427                 .unsol_event = alc262_hp_wildwest_unsol_event,
10428                 .init_hook = alc262_hp_wildwest_automute,
10429         },
10430         [ALC262_HP_BPC_D7000_WL] = {
10431                 .mixers = { alc262_HP_BPC_WildWest_mixer,
10432                             alc262_HP_BPC_WildWest_option_mixer },
10433                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10434                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10435                 .dac_nids = alc262_dac_nids,
10436                 .hp_nid = 0x03,
10437                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10438                 .channel_mode = alc262_modes,
10439                 .input_mux = &alc262_HP_D7000_capture_source,
10440                 .unsol_event = alc262_hp_wildwest_unsol_event,
10441                 .init_hook = alc262_hp_wildwest_automute,
10442         },
10443         [ALC262_HP_TC_T5735] = {
10444                 .mixers = { alc262_hp_t5735_mixer },
10445                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10446                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10447                 .dac_nids = alc262_dac_nids,
10448                 .hp_nid = 0x03,
10449                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10450                 .channel_mode = alc262_modes,
10451                 .input_mux = &alc262_capture_source,
10452                 .unsol_event = alc262_hp_t5735_unsol_event,
10453                 .init_hook = alc262_hp_t5735_init_hook,
10454         },
10455         [ALC262_HP_RP5700] = {
10456                 .mixers = { alc262_hp_rp5700_mixer },
10457                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10458                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10459                 .dac_nids = alc262_dac_nids,
10460                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10461                 .channel_mode = alc262_modes,
10462                 .input_mux = &alc262_hp_rp5700_capture_source,
10463         },
10464         [ALC262_BENQ_ED8] = {
10465                 .mixers = { alc262_base_mixer },
10466                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
10467                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10468                 .dac_nids = alc262_dac_nids,
10469                 .hp_nid = 0x03,
10470                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10471                 .channel_mode = alc262_modes,
10472                 .input_mux = &alc262_capture_source,
10473         },
10474         [ALC262_SONY_ASSAMD] = {
10475                 .mixers = { alc262_sony_mixer },
10476                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10477                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10478                 .dac_nids = alc262_dac_nids,
10479                 .hp_nid = 0x02,
10480                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10481                 .channel_mode = alc262_modes,
10482                 .input_mux = &alc262_capture_source,
10483                 .unsol_event = alc262_hippo_unsol_event,
10484                 .init_hook = alc262_hippo_automute,
10485         },
10486         [ALC262_BENQ_T31] = {
10487                 .mixers = { alc262_benq_t31_mixer },
10488                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10489                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10490                 .dac_nids = alc262_dac_nids,
10491                 .hp_nid = 0x03,
10492                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10493                 .channel_mode = alc262_modes,
10494                 .input_mux = &alc262_capture_source,
10495                 .unsol_event = alc262_hippo_unsol_event,
10496                 .init_hook = alc262_hippo_automute,
10497         },
10498         [ALC262_ULTRA] = {
10499                 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
10500                 .init_verbs = { alc262_ultra_verbs },
10501                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10502                 .dac_nids = alc262_dac_nids,
10503                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10504                 .channel_mode = alc262_modes,
10505                 .input_mux = &alc262_ultra_capture_source,
10506                 .adc_nids = alc262_adc_nids, /* ADC0 */
10507                 .capsrc_nids = alc262_capsrc_nids,
10508                 .num_adc_nids = 1, /* single ADC */
10509                 .unsol_event = alc262_ultra_unsol_event,
10510                 .init_hook = alc262_ultra_automute,
10511         },
10512         [ALC262_LENOVO_3000] = {
10513                 .mixers = { alc262_lenovo_3000_mixer },
10514                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10515                                 alc262_lenovo_3000_unsol_verbs },
10516                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10517                 .dac_nids = alc262_dac_nids,
10518                 .hp_nid = 0x03,
10519                 .dig_out_nid = ALC262_DIGOUT_NID,
10520                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10521                 .channel_mode = alc262_modes,
10522                 .input_mux = &alc262_fujitsu_capture_source,
10523                 .unsol_event = alc262_lenovo_3000_unsol_event,
10524         },
10525         [ALC262_NEC] = {
10526                 .mixers = { alc262_nec_mixer },
10527                 .init_verbs = { alc262_nec_verbs },
10528                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10529                 .dac_nids = alc262_dac_nids,
10530                 .hp_nid = 0x03,
10531                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10532                 .channel_mode = alc262_modes,
10533                 .input_mux = &alc262_capture_source,
10534         },
10535         [ALC262_TOSHIBA_S06] = {
10536                 .mixers = { alc262_toshiba_s06_mixer },
10537                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10538                                                         alc262_eapd_verbs },
10539                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10540                 .capsrc_nids = alc262_dmic_capsrc_nids,
10541                 .dac_nids = alc262_dac_nids,
10542                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10543                 .dig_out_nid = ALC262_DIGOUT_NID,
10544                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10545                 .channel_mode = alc262_modes,
10546                 .input_mux = &alc262_dmic_capture_source,
10547                 .unsol_event = alc262_toshiba_s06_unsol_event,
10548                 .init_hook = alc262_toshiba_s06_init_hook,
10549         },
10550         [ALC262_TOSHIBA_RX1] = {
10551                 .mixers = { alc262_toshiba_rx1_mixer },
10552                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
10553                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10554                 .dac_nids = alc262_dac_nids,
10555                 .hp_nid = 0x03,
10556                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10557                 .channel_mode = alc262_modes,
10558                 .input_mux = &alc262_capture_source,
10559                 .unsol_event = alc262_hippo_unsol_event,
10560                 .init_hook = alc262_hippo_automute,
10561         },
10562 };
10563
10564 static int patch_alc262(struct hda_codec *codec)
10565 {
10566         struct alc_spec *spec;
10567         int board_config;
10568         int err;
10569
10570         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10571         if (spec == NULL)
10572                 return -ENOMEM;
10573
10574         codec->spec = spec;
10575 #if 0
10576         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10577          * under-run
10578          */
10579         {
10580         int tmp;
10581         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10582         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10583         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10584         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10585         }
10586 #endif
10587
10588         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10589
10590         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10591                                                   alc262_models,
10592                                                   alc262_cfg_tbl);
10593
10594         if (board_config < 0) {
10595                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10596                        "trying auto-probe from BIOS...\n");
10597                 board_config = ALC262_AUTO;
10598         }
10599
10600         if (board_config == ALC262_AUTO) {
10601                 /* automatic parse from the BIOS config */
10602                 err = alc262_parse_auto_config(codec);
10603                 if (err < 0) {
10604                         alc_free(codec);
10605                         return err;
10606                 } else if (!err) {
10607                         printk(KERN_INFO
10608                                "hda_codec: Cannot set up configuration "
10609                                "from BIOS.  Using base mode...\n");
10610                         board_config = ALC262_BASIC;
10611                 }
10612         }
10613
10614         if (board_config != ALC262_AUTO)
10615                 setup_preset(spec, &alc262_presets[board_config]);
10616
10617         spec->stream_name_analog = "ALC262 Analog";
10618         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10619         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10620
10621         spec->stream_name_digital = "ALC262 Digital";
10622         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10623         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10624
10625         if (!spec->adc_nids && spec->input_mux) {
10626                 /* check whether NID 0x07 is valid */
10627                 unsigned int wcap = get_wcaps(codec, 0x07);
10628
10629                 /* get type */
10630                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10631                 if (wcap != AC_WID_AUD_IN) {
10632                         spec->adc_nids = alc262_adc_nids_alt;
10633                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10634                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10635                         spec->mixers[spec->num_mixers] =
10636                                 alc262_capture_alt_mixer;
10637                         spec->num_mixers++;
10638                 } else {
10639                         spec->adc_nids = alc262_adc_nids;
10640                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10641                         spec->capsrc_nids = alc262_capsrc_nids;
10642                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
10643                         spec->num_mixers++;
10644                 }
10645         }
10646
10647         spec->vmaster_nid = 0x0c;
10648
10649         codec->patch_ops = alc_patch_ops;
10650         if (board_config == ALC262_AUTO)
10651                 spec->init_hook = alc262_auto_init;
10652 #ifdef CONFIG_SND_HDA_POWER_SAVE
10653         if (!spec->loopback.amplist)
10654                 spec->loopback.amplist = alc262_loopbacks;
10655 #endif
10656
10657         return 0;
10658 }
10659
10660 /*
10661  *  ALC268 channel source setting (2 channel)
10662  */
10663 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10664 #define alc268_modes            alc260_modes
10665
10666 static hda_nid_t alc268_dac_nids[2] = {
10667         /* front, hp */
10668         0x02, 0x03
10669 };
10670
10671 static hda_nid_t alc268_adc_nids[2] = {
10672         /* ADC0-1 */
10673         0x08, 0x07
10674 };
10675
10676 static hda_nid_t alc268_adc_nids_alt[1] = {
10677         /* ADC0 */
10678         0x08
10679 };
10680
10681 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10682
10683 static struct snd_kcontrol_new alc268_base_mixer[] = {
10684         /* output mixer control */
10685         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10686         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10687         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10688         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10689         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10690         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10691         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10692         { }
10693 };
10694
10695 /* bind Beep switches of both NID 0x0f and 0x10 */
10696 static struct hda_bind_ctls alc268_bind_beep_sw = {
10697         .ops = &snd_hda_bind_sw,
10698         .values = {
10699                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10700                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10701                 0
10702         },
10703 };
10704
10705 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10706         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10707         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10708         { }
10709 };
10710
10711 static struct hda_verb alc268_eapd_verbs[] = {
10712         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10713         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10714         { }
10715 };
10716
10717 /* Toshiba specific */
10718 #define alc268_toshiba_automute alc262_hippo_automute
10719
10720 static struct hda_verb alc268_toshiba_verbs[] = {
10721         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10722         { } /* end */
10723 };
10724
10725 static struct hda_input_mux alc268_acer_lc_capture_source = {
10726         .num_items = 2,
10727         .items = {
10728                 { "i-Mic", 0x6 },
10729                 { "E-Mic", 0x0 },
10730         },
10731 };
10732
10733 /* Acer specific */
10734 /* bind volumes of both NID 0x02 and 0x03 */
10735 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10736         .ops = &snd_hda_bind_vol,
10737         .values = {
10738                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10739                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10740                 0
10741         },
10742 };
10743
10744 /* mute/unmute internal speaker according to the hp jack and mute state */
10745 static void alc268_acer_automute(struct hda_codec *codec, int force)
10746 {
10747         struct alc_spec *spec = codec->spec;
10748         unsigned int mute;
10749
10750         if (force || !spec->sense_updated) {
10751                 unsigned int present;
10752                 present = snd_hda_codec_read(codec, 0x14, 0,
10753                                          AC_VERB_GET_PIN_SENSE, 0);
10754                 spec->jack_present = (present & 0x80000000) != 0;
10755                 spec->sense_updated = 1;
10756         }
10757         if (spec->jack_present)
10758                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10759         else /* unmute internal speaker if necessary */
10760                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10761         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10762                                  HDA_AMP_MUTE, mute);
10763 }
10764
10765
10766 /* bind hp and internal speaker mute (with plug check) */
10767 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10768                                      struct snd_ctl_elem_value *ucontrol)
10769 {
10770         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10771         long *valp = ucontrol->value.integer.value;
10772         int change;
10773
10774         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10775                                           HDA_AMP_MUTE,
10776                                           valp[0] ? 0 : HDA_AMP_MUTE);
10777         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10778                                            HDA_AMP_MUTE,
10779                                            valp[1] ? 0 : HDA_AMP_MUTE);
10780         if (change)
10781                 alc268_acer_automute(codec, 0);
10782         return change;
10783 }
10784
10785 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
10786         /* output mixer control */
10787         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10788         {
10789                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10790                 .name = "Master Playback Switch",
10791                 .info = snd_hda_mixer_amp_switch_info,
10792                 .get = snd_hda_mixer_amp_switch_get,
10793                 .put = alc268_acer_master_sw_put,
10794                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10795         },
10796         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
10797         { }
10798 };
10799
10800 static struct snd_kcontrol_new alc268_acer_mixer[] = {
10801         /* output mixer control */
10802         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10803         {
10804                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10805                 .name = "Master Playback Switch",
10806                 .info = snd_hda_mixer_amp_switch_info,
10807                 .get = snd_hda_mixer_amp_switch_get,
10808                 .put = alc268_acer_master_sw_put,
10809                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10810         },
10811         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10812         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10813         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10814         { }
10815 };
10816
10817 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
10818         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10819         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10820         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10821         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10822         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
10823         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
10824         { }
10825 };
10826
10827 static struct hda_verb alc268_acer_verbs[] = {
10828         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
10829         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10830         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10831         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10832         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10833         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10834         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10835         { }
10836 };
10837
10838 /* unsolicited event for HP jack sensing */
10839 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
10840                                        unsigned int res)
10841 {
10842         if ((res >> 26) != ALC880_HP_EVENT)
10843                 return;
10844         alc268_toshiba_automute(codec);
10845 }
10846
10847 static void alc268_acer_unsol_event(struct hda_codec *codec,
10848                                        unsigned int res)
10849 {
10850         if ((res >> 26) != ALC880_HP_EVENT)
10851                 return;
10852         alc268_acer_automute(codec, 1);
10853 }
10854
10855 static void alc268_acer_init_hook(struct hda_codec *codec)
10856 {
10857         alc268_acer_automute(codec, 1);
10858 }
10859
10860 /* toggle speaker-output according to the hp-jack state */
10861 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
10862 {
10863         unsigned int present;
10864         unsigned char bits;
10865
10866         present = snd_hda_codec_read(codec, 0x15, 0,
10867                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10868         bits = present ? AMP_IN_MUTE(0) : 0;
10869         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
10870                                 AMP_IN_MUTE(0), bits);
10871         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
10872                                 AMP_IN_MUTE(0), bits);
10873 }
10874
10875
10876 static void alc268_acer_mic_automute(struct hda_codec *codec)
10877 {
10878         unsigned int present;
10879
10880         present = snd_hda_codec_read(codec, 0x18, 0,
10881                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10882         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
10883                             present ? 0x0 : 0x6);
10884 }
10885
10886 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
10887                                     unsigned int res)
10888 {
10889         if ((res >> 26) == ALC880_HP_EVENT)
10890                 alc268_aspire_one_speaker_automute(codec);
10891         if ((res >> 26) == ALC880_MIC_EVENT)
10892                 alc268_acer_mic_automute(codec);
10893 }
10894
10895 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
10896 {
10897         alc268_aspire_one_speaker_automute(codec);
10898         alc268_acer_mic_automute(codec);
10899 }
10900
10901 static struct snd_kcontrol_new alc268_dell_mixer[] = {
10902         /* output mixer control */
10903         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10904         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10905         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10906         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10907         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10908         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10909         { }
10910 };
10911
10912 static struct hda_verb alc268_dell_verbs[] = {
10913         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10914         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10915         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10916         { }
10917 };
10918
10919 /* mute/unmute internal speaker according to the hp jack and mute state */
10920 static void alc268_dell_automute(struct hda_codec *codec)
10921 {
10922         unsigned int present;
10923         unsigned int mute;
10924
10925         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
10926         if (present & 0x80000000)
10927                 mute = HDA_AMP_MUTE;
10928         else
10929                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
10930         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10931                                  HDA_AMP_MUTE, mute);
10932 }
10933
10934 static void alc268_dell_unsol_event(struct hda_codec *codec,
10935                                     unsigned int res)
10936 {
10937         if ((res >> 26) != ALC880_HP_EVENT)
10938                 return;
10939         alc268_dell_automute(codec);
10940 }
10941
10942 #define alc268_dell_init_hook   alc268_dell_automute
10943
10944 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
10945         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10946         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10947         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10948         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10949         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10950         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
10951         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
10952         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10953         { }
10954 };
10955
10956 static struct hda_verb alc267_quanta_il1_verbs[] = {
10957         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10958         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
10959         { }
10960 };
10961
10962 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
10963 {
10964         unsigned int present;
10965
10966         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
10967                 & AC_PINSENSE_PRESENCE;
10968         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
10969                             present ? 0 : PIN_OUT);
10970 }
10971
10972 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
10973 {
10974         unsigned int present;
10975
10976         present = snd_hda_codec_read(codec, 0x18, 0,
10977                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10978         snd_hda_codec_write(codec, 0x23, 0,
10979                             AC_VERB_SET_CONNECT_SEL,
10980                             present ? 0x00 : 0x01);
10981 }
10982
10983 static void alc267_quanta_il1_automute(struct hda_codec *codec)
10984 {
10985         alc267_quanta_il1_hp_automute(codec);
10986         alc267_quanta_il1_mic_automute(codec);
10987 }
10988
10989 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
10990                                            unsigned int res)
10991 {
10992         switch (res >> 26) {
10993         case ALC880_HP_EVENT:
10994                 alc267_quanta_il1_hp_automute(codec);
10995                 break;
10996         case ALC880_MIC_EVENT:
10997                 alc267_quanta_il1_mic_automute(codec);
10998                 break;
10999         }
11000 }
11001
11002 /*
11003  * generic initialization of ADC, input mixers and output mixers
11004  */
11005 static struct hda_verb alc268_base_init_verbs[] = {
11006         /* Unmute DAC0-1 and set vol = 0 */
11007         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11008         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11009         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11010         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11011         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11012         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11013
11014         /*
11015          * Set up output mixers (0x0c - 0x0e)
11016          */
11017         /* set vol=0 to output mixers */
11018         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11019         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11020         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11021         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11022
11023         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11024         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11025
11026         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11027         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11028         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11029         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11030         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11031         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11032         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11033         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11034
11035         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11036         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11037         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11038         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11039         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11040         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11041         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11042
11043         /* set PCBEEP vol = 0, mute connections */
11044         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11045         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11046         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11047
11048         /* Unmute Selector 23h,24h and set the default input to mic-in */
11049
11050         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11051         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11052         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11053         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11054
11055         { }
11056 };
11057
11058 /*
11059  * generic initialization of ADC, input mixers and output mixers
11060  */
11061 static struct hda_verb alc268_volume_init_verbs[] = {
11062         /* set output DAC */
11063         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11064         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11065         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11066         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11067
11068         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11069         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11070         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11071         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11072         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11073
11074         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11075         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11076         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11077         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11078         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11079
11080         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11081         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11082         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11083         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11084
11085         /* set PCBEEP vol = 0, mute connections */
11086         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11087         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11088         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11089
11090         { }
11091 };
11092
11093 #define alc268_mux_enum_info alc_mux_enum_info
11094 #define alc268_mux_enum_get alc_mux_enum_get
11095 #define alc268_mux_enum_put alc_mux_enum_put
11096
11097 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11098         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11099         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11100         {
11101                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11102                 /* The multiple "Capture Source" controls confuse alsamixer
11103                  * So call somewhat different..
11104                  */
11105                 /* .name = "Capture Source", */
11106                 .name = "Input Source",
11107                 .count = 1,
11108                 .info = alc268_mux_enum_info,
11109                 .get = alc268_mux_enum_get,
11110                 .put = alc268_mux_enum_put,
11111         },
11112         { } /* end */
11113 };
11114
11115 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11116         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11117         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11118         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11119         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11120         {
11121                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11122                 /* The multiple "Capture Source" controls confuse alsamixer
11123                  * So call somewhat different..
11124                  */
11125                 /* .name = "Capture Source", */
11126                 .name = "Input Source",
11127                 .count = 2,
11128                 .info = alc268_mux_enum_info,
11129                 .get = alc268_mux_enum_get,
11130                 .put = alc268_mux_enum_put,
11131         },
11132         { } /* end */
11133 };
11134
11135 static struct hda_input_mux alc268_capture_source = {
11136         .num_items = 4,
11137         .items = {
11138                 { "Mic", 0x0 },
11139                 { "Front Mic", 0x1 },
11140                 { "Line", 0x2 },
11141                 { "CD", 0x3 },
11142         },
11143 };
11144
11145 static struct hda_input_mux alc268_acer_capture_source = {
11146         .num_items = 3,
11147         .items = {
11148                 { "Mic", 0x0 },
11149                 { "Internal Mic", 0x6 },
11150                 { "Line", 0x2 },
11151         },
11152 };
11153
11154 #ifdef CONFIG_SND_DEBUG
11155 static struct snd_kcontrol_new alc268_test_mixer[] = {
11156         /* Volume widgets */
11157         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11158         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11159         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11160         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11161         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11162         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11163         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11164         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11165         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11166         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11167         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11168         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11169         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11170         /* The below appears problematic on some hardwares */
11171         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11172         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11173         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11174         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11175         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11176
11177         /* Modes for retasking pin widgets */
11178         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11179         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11180         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11181         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11182
11183         /* Controls for GPIO pins, assuming they are configured as outputs */
11184         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11185         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11186         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11187         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11188
11189         /* Switches to allow the digital SPDIF output pin to be enabled.
11190          * The ALC268 does not have an SPDIF input.
11191          */
11192         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11193
11194         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11195          * this output to turn on an external amplifier.
11196          */
11197         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11198         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11199
11200         { } /* end */
11201 };
11202 #endif
11203
11204 /* create input playback/capture controls for the given pin */
11205 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11206                                     const char *ctlname, int idx)
11207 {
11208         char name[32];
11209         int err;
11210
11211         sprintf(name, "%s Playback Volume", ctlname);
11212         if (nid == 0x14) {
11213                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11214                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11215                                                       HDA_OUTPUT));
11216                 if (err < 0)
11217                         return err;
11218         } else if (nid == 0x15) {
11219                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11220                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11221                                                       HDA_OUTPUT));
11222                 if (err < 0)
11223                         return err;
11224         } else
11225                 return -1;
11226         sprintf(name, "%s Playback Switch", ctlname);
11227         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11228                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11229         if (err < 0)
11230                 return err;
11231         return 0;
11232 }
11233
11234 /* add playback controls from the parsed DAC table */
11235 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11236                                              const struct auto_pin_cfg *cfg)
11237 {
11238         hda_nid_t nid;
11239         int err;
11240
11241         spec->multiout.num_dacs = 2;    /* only use one dac */
11242         spec->multiout.dac_nids = spec->private_dac_nids;
11243         spec->multiout.dac_nids[0] = 2;
11244         spec->multiout.dac_nids[1] = 3;
11245
11246         nid = cfg->line_out_pins[0];
11247         if (nid)
11248                 alc268_new_analog_output(spec, nid, "Front", 0);
11249
11250         nid = cfg->speaker_pins[0];
11251         if (nid == 0x1d) {
11252                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11253                                   "Speaker Playback Volume",
11254                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11255                 if (err < 0)
11256                         return err;
11257         }
11258         nid = cfg->hp_pins[0];
11259         if (nid)
11260                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11261
11262         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11263         if (nid == 0x16) {
11264                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11265                                   "Mono Playback Switch",
11266                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11267                 if (err < 0)
11268                         return err;
11269         }
11270         return 0;
11271 }
11272
11273 /* create playback/capture controls for input pins */
11274 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11275                                                 const struct auto_pin_cfg *cfg)
11276 {
11277         struct hda_input_mux *imux = &spec->private_imux;
11278         int i, idx1;
11279
11280         for (i = 0; i < AUTO_PIN_LAST; i++) {
11281                 switch(cfg->input_pins[i]) {
11282                 case 0x18:
11283                         idx1 = 0;       /* Mic 1 */
11284                         break;
11285                 case 0x19:
11286                         idx1 = 1;       /* Mic 2 */
11287                         break;
11288                 case 0x1a:
11289                         idx1 = 2;       /* Line In */
11290                         break;
11291                 case 0x1c:
11292                         idx1 = 3;       /* CD */
11293                         break;
11294                 case 0x12:
11295                 case 0x13:
11296                         idx1 = 6;       /* digital mics */
11297                         break;
11298                 default:
11299                         continue;
11300                 }
11301                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11302                 imux->items[imux->num_items].index = idx1;
11303                 imux->num_items++;
11304         }
11305         return 0;
11306 }
11307
11308 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11309 {
11310         struct alc_spec *spec = codec->spec;
11311         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11312         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11313         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11314         unsigned int    dac_vol1, dac_vol2;
11315
11316         if (speaker_nid) {
11317                 snd_hda_codec_write(codec, speaker_nid, 0,
11318                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11319                 snd_hda_codec_write(codec, 0x0f, 0,
11320                                     AC_VERB_SET_AMP_GAIN_MUTE,
11321                                     AMP_IN_UNMUTE(1));
11322                 snd_hda_codec_write(codec, 0x10, 0,
11323                                     AC_VERB_SET_AMP_GAIN_MUTE,
11324                                     AMP_IN_UNMUTE(1));
11325         } else {
11326                 snd_hda_codec_write(codec, 0x0f, 0,
11327                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11328                 snd_hda_codec_write(codec, 0x10, 0,
11329                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11330         }
11331
11332         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11333         if (line_nid == 0x14)
11334                 dac_vol2 = AMP_OUT_ZERO;
11335         else if (line_nid == 0x15)
11336                 dac_vol1 = AMP_OUT_ZERO;
11337         if (hp_nid == 0x14)
11338                 dac_vol2 = AMP_OUT_ZERO;
11339         else if (hp_nid == 0x15)
11340                 dac_vol1 = AMP_OUT_ZERO;
11341         if (line_nid != 0x16 || hp_nid != 0x16 ||
11342             spec->autocfg.line_out_pins[1] != 0x16 ||
11343             spec->autocfg.line_out_pins[2] != 0x16)
11344                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11345
11346         snd_hda_codec_write(codec, 0x02, 0,
11347                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11348         snd_hda_codec_write(codec, 0x03, 0,
11349                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11350 }
11351
11352 /* pcm configuration: identiacal with ALC880 */
11353 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11354 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11355 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11356 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11357
11358 /*
11359  * BIOS auto configuration
11360  */
11361 static int alc268_parse_auto_config(struct hda_codec *codec)
11362 {
11363         struct alc_spec *spec = codec->spec;
11364         int err;
11365         static hda_nid_t alc268_ignore[] = { 0 };
11366
11367         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11368                                            alc268_ignore);
11369         if (err < 0)
11370                 return err;
11371         if (!spec->autocfg.line_outs)
11372                 return 0; /* can't find valid BIOS pin config */
11373
11374         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11375         if (err < 0)
11376                 return err;
11377         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11378         if (err < 0)
11379                 return err;
11380
11381         spec->multiout.max_channels = 2;
11382
11383         /* digital only support output */
11384         if (spec->autocfg.dig_out_pin)
11385                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11386
11387         if (spec->kctl_alloc)
11388                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11389
11390         if (spec->autocfg.speaker_pins[0] != 0x1d)
11391                 spec->mixers[spec->num_mixers++] = alc268_beep_mixer;
11392
11393         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
11394         spec->num_mux_defs = 1;
11395         spec->input_mux = &spec->private_imux;
11396
11397         err = alc_auto_add_mic_boost(codec);
11398         if (err < 0)
11399                 return err;
11400
11401         return 1;
11402 }
11403
11404 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
11405 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
11406 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
11407
11408 /* init callback for auto-configuration model -- overriding the default init */
11409 static void alc268_auto_init(struct hda_codec *codec)
11410 {
11411         struct alc_spec *spec = codec->spec;
11412         alc268_auto_init_multi_out(codec);
11413         alc268_auto_init_hp_out(codec);
11414         alc268_auto_init_mono_speaker_out(codec);
11415         alc268_auto_init_analog_input(codec);
11416         if (spec->unsol_event)
11417                 alc_sku_automute(codec);
11418 }
11419
11420 /*
11421  * configuration and preset
11422  */
11423 static const char *alc268_models[ALC268_MODEL_LAST] = {
11424         [ALC267_QUANTA_IL1]     = "quanta-il1",
11425         [ALC268_3ST]            = "3stack",
11426         [ALC268_TOSHIBA]        = "toshiba",
11427         [ALC268_ACER]           = "acer",
11428         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
11429         [ALC268_DELL]           = "dell",
11430         [ALC268_ZEPTO]          = "zepto",
11431 #ifdef CONFIG_SND_DEBUG
11432         [ALC268_TEST]           = "test",
11433 #endif
11434         [ALC268_AUTO]           = "auto",
11435 };
11436
11437 static struct snd_pci_quirk alc268_cfg_tbl[] = {
11438         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
11439         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
11440         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
11441         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
11442         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11443         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11444                                                 ALC268_ACER_ASPIRE_ONE),
11445         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
11446         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
11447         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
11448         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
11449         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11450         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
11451         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
11452         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
11453         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
11454         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
11455         {}
11456 };
11457
11458 static struct alc_config_preset alc268_presets[] = {
11459         [ALC267_QUANTA_IL1] = {
11460                 .mixers = { alc267_quanta_il1_mixer },
11461                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11462                                 alc267_quanta_il1_verbs },
11463                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11464                 .dac_nids = alc268_dac_nids,
11465                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11466                 .adc_nids = alc268_adc_nids_alt,
11467                 .hp_nid = 0x03,
11468                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11469                 .channel_mode = alc268_modes,
11470                 .input_mux = &alc268_capture_source,
11471                 .unsol_event = alc267_quanta_il1_unsol_event,
11472                 .init_hook = alc267_quanta_il1_automute,
11473         },
11474         [ALC268_3ST] = {
11475                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11476                             alc268_beep_mixer },
11477                 .init_verbs = { alc268_base_init_verbs },
11478                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11479                 .dac_nids = alc268_dac_nids,
11480                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11481                 .adc_nids = alc268_adc_nids_alt,
11482                 .capsrc_nids = alc268_capsrc_nids,
11483                 .hp_nid = 0x03,
11484                 .dig_out_nid = ALC268_DIGOUT_NID,
11485                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11486                 .channel_mode = alc268_modes,
11487                 .input_mux = &alc268_capture_source,
11488         },
11489         [ALC268_TOSHIBA] = {
11490                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11491                             alc268_beep_mixer },
11492                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11493                                 alc268_toshiba_verbs },
11494                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11495                 .dac_nids = alc268_dac_nids,
11496                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11497                 .adc_nids = alc268_adc_nids_alt,
11498                 .capsrc_nids = alc268_capsrc_nids,
11499                 .hp_nid = 0x03,
11500                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11501                 .channel_mode = alc268_modes,
11502                 .input_mux = &alc268_capture_source,
11503                 .unsol_event = alc268_toshiba_unsol_event,
11504                 .init_hook = alc268_toshiba_automute,
11505         },
11506         [ALC268_ACER] = {
11507                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
11508                             alc268_beep_mixer },
11509                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11510                                 alc268_acer_verbs },
11511                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11512                 .dac_nids = alc268_dac_nids,
11513                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11514                 .adc_nids = alc268_adc_nids_alt,
11515                 .capsrc_nids = alc268_capsrc_nids,
11516                 .hp_nid = 0x02,
11517                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11518                 .channel_mode = alc268_modes,
11519                 .input_mux = &alc268_acer_capture_source,
11520                 .unsol_event = alc268_acer_unsol_event,
11521                 .init_hook = alc268_acer_init_hook,
11522         },
11523         [ALC268_ACER_ASPIRE_ONE] = {
11524                 .mixers = { alc268_acer_aspire_one_mixer,
11525                                 alc268_capture_alt_mixer },
11526                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11527                                 alc268_acer_aspire_one_verbs },
11528                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11529                 .dac_nids = alc268_dac_nids,
11530                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11531                 .adc_nids = alc268_adc_nids_alt,
11532                 .capsrc_nids = alc268_capsrc_nids,
11533                 .hp_nid = 0x03,
11534                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11535                 .channel_mode = alc268_modes,
11536                 .input_mux = &alc268_acer_lc_capture_source,
11537                 .unsol_event = alc268_acer_lc_unsol_event,
11538                 .init_hook = alc268_acer_lc_init_hook,
11539         },
11540         [ALC268_DELL] = {
11541                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
11542                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11543                                 alc268_dell_verbs },
11544                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11545                 .dac_nids = alc268_dac_nids,
11546                 .hp_nid = 0x02,
11547                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11548                 .channel_mode = alc268_modes,
11549                 .unsol_event = alc268_dell_unsol_event,
11550                 .init_hook = alc268_dell_init_hook,
11551                 .input_mux = &alc268_capture_source,
11552         },
11553         [ALC268_ZEPTO] = {
11554                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11555                             alc268_beep_mixer },
11556                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11557                                 alc268_toshiba_verbs },
11558                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11559                 .dac_nids = alc268_dac_nids,
11560                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11561                 .adc_nids = alc268_adc_nids_alt,
11562                 .capsrc_nids = alc268_capsrc_nids,
11563                 .hp_nid = 0x03,
11564                 .dig_out_nid = ALC268_DIGOUT_NID,
11565                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11566                 .channel_mode = alc268_modes,
11567                 .input_mux = &alc268_capture_source,
11568                 .unsol_event = alc268_toshiba_unsol_event,
11569                 .init_hook = alc268_toshiba_automute
11570         },
11571 #ifdef CONFIG_SND_DEBUG
11572         [ALC268_TEST] = {
11573                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11574                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11575                                 alc268_volume_init_verbs },
11576                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11577                 .dac_nids = alc268_dac_nids,
11578                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11579                 .adc_nids = alc268_adc_nids_alt,
11580                 .capsrc_nids = alc268_capsrc_nids,
11581                 .hp_nid = 0x03,
11582                 .dig_out_nid = ALC268_DIGOUT_NID,
11583                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11584                 .channel_mode = alc268_modes,
11585                 .input_mux = &alc268_capture_source,
11586         },
11587 #endif
11588 };
11589
11590 static int patch_alc268(struct hda_codec *codec)
11591 {
11592         struct alc_spec *spec;
11593         int board_config;
11594         int err;
11595
11596         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11597         if (spec == NULL)
11598                 return -ENOMEM;
11599
11600         codec->spec = spec;
11601
11602         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11603                                                   alc268_models,
11604                                                   alc268_cfg_tbl);
11605
11606         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11607                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11608                        "trying auto-probe from BIOS...\n");
11609                 board_config = ALC268_AUTO;
11610         }
11611
11612         if (board_config == ALC268_AUTO) {
11613                 /* automatic parse from the BIOS config */
11614                 err = alc268_parse_auto_config(codec);
11615                 if (err < 0) {
11616                         alc_free(codec);
11617                         return err;
11618                 } else if (!err) {
11619                         printk(KERN_INFO
11620                                "hda_codec: Cannot set up configuration "
11621                                "from BIOS.  Using base mode...\n");
11622                         board_config = ALC268_3ST;
11623                 }
11624         }
11625
11626         if (board_config != ALC268_AUTO)
11627                 setup_preset(spec, &alc268_presets[board_config]);
11628
11629         if (codec->vendor_id == 0x10ec0267) {
11630                 spec->stream_name_analog = "ALC267 Analog";
11631                 spec->stream_name_digital = "ALC267 Digital";
11632         } else {
11633                 spec->stream_name_analog = "ALC268 Analog";
11634                 spec->stream_name_digital = "ALC268 Digital";
11635         }
11636
11637         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11638         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11639         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11640
11641         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11642
11643         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11644                 /* override the amp caps for beep generator */
11645                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11646                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11647                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11648                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11649                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11650
11651         if (!spec->adc_nids && spec->input_mux) {
11652                 /* check whether NID 0x07 is valid */
11653                 unsigned int wcap = get_wcaps(codec, 0x07);
11654                 int i;
11655
11656                 /* get type */
11657                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11658                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11659                         spec->adc_nids = alc268_adc_nids_alt;
11660                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11661                         spec->mixers[spec->num_mixers] =
11662                                         alc268_capture_alt_mixer;
11663                         spec->num_mixers++;
11664                 } else {
11665                         spec->adc_nids = alc268_adc_nids;
11666                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11667                         spec->mixers[spec->num_mixers] =
11668                                 alc268_capture_mixer;
11669                         spec->num_mixers++;
11670                 }
11671                 spec->capsrc_nids = alc268_capsrc_nids;
11672                 /* set default input source */
11673                 for (i = 0; i < spec->num_adc_nids; i++)
11674                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11675                                 0, AC_VERB_SET_CONNECT_SEL,
11676                                 spec->input_mux->items[0].index);
11677         }
11678
11679         spec->vmaster_nid = 0x02;
11680
11681         codec->patch_ops = alc_patch_ops;
11682         if (board_config == ALC268_AUTO)
11683                 spec->init_hook = alc268_auto_init;
11684
11685         return 0;
11686 }
11687
11688 /*
11689  *  ALC269 channel source setting (2 channel)
11690  */
11691 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11692
11693 #define alc269_dac_nids         alc260_dac_nids
11694
11695 static hda_nid_t alc269_adc_nids[1] = {
11696         /* ADC1 */
11697         0x08,
11698 };
11699
11700 static hda_nid_t alc269_capsrc_nids[1] = {
11701         0x23,
11702 };
11703
11704 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11705  *       not a mux!
11706  */
11707
11708 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11709         .num_items = 2,
11710         .items = {
11711                 { "i-Mic", 0x5 },
11712                 { "e-Mic", 0x0 },
11713         },
11714 };
11715
11716 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11717         .num_items = 2,
11718         .items = {
11719                 { "i-Mic", 0x1 },
11720                 { "e-Mic", 0x0 },
11721         },
11722 };
11723
11724 #define alc269_modes            alc260_modes
11725 #define alc269_capture_source   alc880_lg_lw_capture_source
11726
11727 static struct snd_kcontrol_new alc269_base_mixer[] = {
11728         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11729         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11730         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11731         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11732         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11733         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11734         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11735         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11736         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11737         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11738         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11739         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11740         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11741         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
11742         { } /* end */
11743 };
11744
11745 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
11746         /* output mixer control */
11747         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11748         {
11749                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11750                 .name = "Master Playback Switch",
11751                 .info = snd_hda_mixer_amp_switch_info,
11752                 .get = snd_hda_mixer_amp_switch_get,
11753                 .put = alc268_acer_master_sw_put,
11754                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11755         },
11756         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11757         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11758         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11759         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11760         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11761         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11762         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
11763         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
11764         { }
11765 };
11766
11767 /* bind volumes of both NID 0x0c and 0x0d */
11768 static struct hda_bind_ctls alc269_epc_bind_vol = {
11769         .ops = &snd_hda_bind_vol,
11770         .values = {
11771                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11772                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11773                 0
11774         },
11775 };
11776
11777 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
11778         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11779         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
11780         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11781         { } /* end */
11782 };
11783
11784 /* capture mixer elements */
11785 static struct snd_kcontrol_new alc269_capture_mixer[] = {
11786         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11787         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11788         {
11789                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11790                 /* The multiple "Capture Source" controls confuse alsamixer
11791                  * So call somewhat different..
11792                  */
11793                 /* .name = "Capture Source", */
11794                 .name = "Input Source",
11795                 .count = 1,
11796                 .info = alc_mux_enum_info,
11797                 .get = alc_mux_enum_get,
11798                 .put = alc_mux_enum_put,
11799         },
11800         { } /* end */
11801 };
11802
11803 /* capture mixer elements */
11804 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
11805         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11806         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11807         { } /* end */
11808 };
11809
11810 /* beep control */
11811 static struct snd_kcontrol_new alc269_beep_mixer[] = {
11812         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11813         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11814         { } /* end */
11815 };
11816
11817 static struct hda_verb alc269_quanta_fl1_verbs[] = {
11818         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11819         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11820         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11821         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11822         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11823         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11824         { }
11825 };
11826
11827 /* toggle speaker-output according to the hp-jack state */
11828 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
11829 {
11830         unsigned int present;
11831         unsigned char bits;
11832
11833         present = snd_hda_codec_read(codec, 0x15, 0,
11834                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11835         bits = present ? AMP_IN_MUTE(0) : 0;
11836         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11837                         AMP_IN_MUTE(0), bits);
11838         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11839                         AMP_IN_MUTE(0), bits);
11840
11841         snd_hda_codec_write(codec, 0x20, 0,
11842                         AC_VERB_SET_COEF_INDEX, 0x0c);
11843         snd_hda_codec_write(codec, 0x20, 0,
11844                         AC_VERB_SET_PROC_COEF, 0x680);
11845
11846         snd_hda_codec_write(codec, 0x20, 0,
11847                         AC_VERB_SET_COEF_INDEX, 0x0c);
11848         snd_hda_codec_write(codec, 0x20, 0,
11849                         AC_VERB_SET_PROC_COEF, 0x480);
11850 }
11851
11852 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
11853 {
11854         unsigned int present;
11855
11856         present = snd_hda_codec_read(codec, 0x18, 0,
11857                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11858         snd_hda_codec_write(codec, 0x23, 0,
11859                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
11860 }
11861
11862 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
11863                                     unsigned int res)
11864 {
11865         if ((res >> 26) == ALC880_HP_EVENT)
11866                 alc269_quanta_fl1_speaker_automute(codec);
11867         if ((res >> 26) == ALC880_MIC_EVENT)
11868                 alc269_quanta_fl1_mic_automute(codec);
11869 }
11870
11871 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
11872 {
11873         alc269_quanta_fl1_speaker_automute(codec);
11874         alc269_quanta_fl1_mic_automute(codec);
11875 }
11876
11877 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
11878         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11879         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
11880         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11881         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
11882         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11883         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11884         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11885         {}
11886 };
11887
11888 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
11889         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11890         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
11891         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11892         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
11893         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11894         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11895         {}
11896 };
11897
11898 /* toggle speaker-output according to the hp-jack state */
11899 static void alc269_speaker_automute(struct hda_codec *codec)
11900 {
11901         unsigned int present;
11902         unsigned char bits;
11903
11904         present = snd_hda_codec_read(codec, 0x15, 0,
11905                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11906         bits = present ? AMP_IN_MUTE(0) : 0;
11907         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11908                                 AMP_IN_MUTE(0), bits);
11909         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11910                                 AMP_IN_MUTE(0), bits);
11911 }
11912
11913 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
11914 {
11915         unsigned int present;
11916
11917         present = snd_hda_codec_read(codec, 0x18, 0,
11918                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11919         snd_hda_codec_write(codec, 0x23, 0,
11920                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
11921 }
11922
11923 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
11924 {
11925         unsigned int present;
11926
11927         present = snd_hda_codec_read(codec, 0x18, 0,
11928                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11929         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11930                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
11931         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11932                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
11933 }
11934
11935 /* unsolicited event for HP jack sensing */
11936 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
11937                                      unsigned int res)
11938 {
11939         if ((res >> 26) == ALC880_HP_EVENT)
11940                 alc269_speaker_automute(codec);
11941
11942         if ((res >> 26) == ALC880_MIC_EVENT)
11943                 alc269_eeepc_dmic_automute(codec);
11944 }
11945
11946 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
11947 {
11948         alc269_speaker_automute(codec);
11949         alc269_eeepc_dmic_automute(codec);
11950 }
11951
11952 /* unsolicited event for HP jack sensing */
11953 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
11954                                      unsigned int res)
11955 {
11956         if ((res >> 26) == ALC880_HP_EVENT)
11957                 alc269_speaker_automute(codec);
11958
11959         if ((res >> 26) == ALC880_MIC_EVENT)
11960                 alc269_eeepc_amic_automute(codec);
11961 }
11962
11963 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
11964 {
11965         alc269_speaker_automute(codec);
11966         alc269_eeepc_amic_automute(codec);
11967 }
11968
11969 /*
11970  * generic initialization of ADC, input mixers and output mixers
11971  */
11972 static struct hda_verb alc269_init_verbs[] = {
11973         /*
11974          * Unmute ADC0 and set the default input to mic-in
11975          */
11976         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11977
11978         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
11979          * analog-loopback mixer widget
11980          * Note: PASD motherboards uses the Line In 2 as the input for
11981          * front panel mic (mic 2)
11982          */
11983         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11984         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11985         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11986         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11987         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11988         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11989
11990         /*
11991          * Set up output mixers (0x0c - 0x0e)
11992          */
11993         /* set vol=0 to output mixers */
11994         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11995         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11996
11997         /* set up input amps for analog loopback */
11998         /* Amp Indices: DAC = 0, mixer = 1 */
11999         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12000         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12001         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12002         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12003         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12004         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12005
12006         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12007         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12008         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12009         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12010         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12011         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12012         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12013
12014         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12015         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12016         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12017         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12018         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12019         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12020         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12021
12022         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12023         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12024
12025         /* FIXME: use matrix-type input source selection */
12026         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12027         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12028         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12029         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12030         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12031         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12032
12033         /* set EAPD */
12034         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12035         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12036         { }
12037 };
12038
12039 /* add playback controls from the parsed DAC table */
12040 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12041                                              const struct auto_pin_cfg *cfg)
12042 {
12043         hda_nid_t nid;
12044         int err;
12045
12046         spec->multiout.num_dacs = 1;    /* only use one dac */
12047         spec->multiout.dac_nids = spec->private_dac_nids;
12048         spec->multiout.dac_nids[0] = 2;
12049
12050         nid = cfg->line_out_pins[0];
12051         if (nid) {
12052                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12053                                   "Front Playback Volume",
12054                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12055                 if (err < 0)
12056                         return err;
12057                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12058                                   "Front Playback Switch",
12059                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12060                 if (err < 0)
12061                         return err;
12062         }
12063
12064         nid = cfg->speaker_pins[0];
12065         if (nid) {
12066                 if (!cfg->line_out_pins[0]) {
12067                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12068                                           "Speaker Playback Volume",
12069                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12070                                                               HDA_OUTPUT));
12071                         if (err < 0)
12072                                 return err;
12073                 }
12074                 if (nid == 0x16) {
12075                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12076                                           "Speaker Playback Switch",
12077                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12078                                                               HDA_OUTPUT));
12079                         if (err < 0)
12080                                 return err;
12081                 } else {
12082                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12083                                           "Speaker Playback Switch",
12084                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12085                                                               HDA_OUTPUT));
12086                         if (err < 0)
12087                                 return err;
12088                 }
12089         }
12090         nid = cfg->hp_pins[0];
12091         if (nid) {
12092                 /* spec->multiout.hp_nid = 2; */
12093                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12094                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12095                                           "Headphone Playback Volume",
12096                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12097                                                               HDA_OUTPUT));
12098                         if (err < 0)
12099                                 return err;
12100                 }
12101                 if (nid == 0x16) {
12102                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12103                                           "Headphone Playback Switch",
12104                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12105                                                               HDA_OUTPUT));
12106                         if (err < 0)
12107                                 return err;
12108                 } else {
12109                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12110                                           "Headphone Playback Switch",
12111                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12112                                                               HDA_OUTPUT));
12113                         if (err < 0)
12114                                 return err;
12115                 }
12116         }
12117         return 0;
12118 }
12119
12120 #define alc269_auto_create_analog_input_ctls \
12121         alc880_auto_create_analog_input_ctls
12122
12123 #ifdef CONFIG_SND_HDA_POWER_SAVE
12124 #define alc269_loopbacks        alc880_loopbacks
12125 #endif
12126
12127 /* pcm configuration: identiacal with ALC880 */
12128 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12129 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12130 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12131 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12132
12133 /*
12134  * BIOS auto configuration
12135  */
12136 static int alc269_parse_auto_config(struct hda_codec *codec)
12137 {
12138         struct alc_spec *spec = codec->spec;
12139         int i, err;
12140         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12141
12142         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12143                                            alc269_ignore);
12144         if (err < 0)
12145                 return err;
12146
12147         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12148         if (err < 0)
12149                 return err;
12150         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12151         if (err < 0)
12152                 return err;
12153
12154         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12155
12156         if (spec->autocfg.dig_out_pin)
12157                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12158
12159         if (spec->kctl_alloc)
12160                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
12161
12162         /* create a beep mixer control if the pin 0x1d isn't assigned */
12163         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12164                 if (spec->autocfg.input_pins[i] == 0x1d)
12165                         break;
12166         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12167                 spec->mixers[spec->num_mixers++] = alc269_beep_mixer;
12168
12169         spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
12170         spec->num_mux_defs = 1;
12171         spec->input_mux = &spec->private_imux;
12172         /* set default input source */
12173         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12174                                   0, AC_VERB_SET_CONNECT_SEL,
12175                                   spec->input_mux->items[0].index);
12176
12177         err = alc_auto_add_mic_boost(codec);
12178         if (err < 0)
12179                 return err;
12180
12181         spec->mixers[spec->num_mixers] = alc269_capture_mixer;
12182         spec->num_mixers++;
12183
12184         return 1;
12185 }
12186
12187 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12188 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12189 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12190
12191
12192 /* init callback for auto-configuration model -- overriding the default init */
12193 static void alc269_auto_init(struct hda_codec *codec)
12194 {
12195         struct alc_spec *spec = codec->spec;
12196         alc269_auto_init_multi_out(codec);
12197         alc269_auto_init_hp_out(codec);
12198         alc269_auto_init_analog_input(codec);
12199         if (spec->unsol_event)
12200                 alc_sku_automute(codec);
12201 }
12202
12203 /*
12204  * configuration and preset
12205  */
12206 static const char *alc269_models[ALC269_MODEL_LAST] = {
12207         [ALC269_BASIC]                  = "basic",
12208         [ALC269_QUANTA_FL1]             = "quanta",
12209         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12210         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901"
12211 };
12212
12213 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12214         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12215         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12216                       ALC269_ASUS_EEEPC_P703),
12217         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12218                       ALC269_ASUS_EEEPC_P901),
12219         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12220                       ALC269_ASUS_EEEPC_P901),
12221         {}
12222 };
12223
12224 static struct alc_config_preset alc269_presets[] = {
12225         [ALC269_BASIC] = {
12226                 .mixers = { alc269_base_mixer, alc269_capture_mixer },
12227                 .init_verbs = { alc269_init_verbs },
12228                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12229                 .dac_nids = alc269_dac_nids,
12230                 .hp_nid = 0x03,
12231                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12232                 .channel_mode = alc269_modes,
12233                 .input_mux = &alc269_capture_source,
12234         },
12235         [ALC269_QUANTA_FL1] = {
12236                 .mixers = { alc269_quanta_fl1_mixer },
12237                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
12238                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12239                 .dac_nids = alc269_dac_nids,
12240                 .hp_nid = 0x03,
12241                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12242                 .channel_mode = alc269_modes,
12243                 .input_mux = &alc269_capture_source,
12244                 .unsol_event = alc269_quanta_fl1_unsol_event,
12245                 .init_hook = alc269_quanta_fl1_init_hook,
12246         },
12247         [ALC269_ASUS_EEEPC_P703] = {
12248                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer },
12249                 .init_verbs = { alc269_init_verbs,
12250                                 alc269_eeepc_amic_init_verbs },
12251                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12252                 .dac_nids = alc269_dac_nids,
12253                 .hp_nid = 0x03,
12254                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12255                 .channel_mode = alc269_modes,
12256                 .input_mux = &alc269_eeepc_amic_capture_source,
12257                 .unsol_event = alc269_eeepc_amic_unsol_event,
12258                 .init_hook = alc269_eeepc_amic_inithook,
12259         },
12260         [ALC269_ASUS_EEEPC_P901] = {
12261                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer},
12262                 .init_verbs = { alc269_init_verbs,
12263                                 alc269_eeepc_dmic_init_verbs },
12264                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12265                 .dac_nids = alc269_dac_nids,
12266                 .hp_nid = 0x03,
12267                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12268                 .channel_mode = alc269_modes,
12269                 .input_mux = &alc269_eeepc_dmic_capture_source,
12270                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12271                 .init_hook = alc269_eeepc_dmic_inithook,
12272         },
12273 };
12274
12275 static int patch_alc269(struct hda_codec *codec)
12276 {
12277         struct alc_spec *spec;
12278         int board_config;
12279         int err;
12280
12281         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12282         if (spec == NULL)
12283                 return -ENOMEM;
12284
12285         codec->spec = spec;
12286
12287         alc_fix_pll_init(codec, 0x20, 0x04, 15);
12288
12289         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
12290                                                   alc269_models,
12291                                                   alc269_cfg_tbl);
12292
12293         if (board_config < 0) {
12294                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
12295                        "trying auto-probe from BIOS...\n");
12296                 board_config = ALC269_AUTO;
12297         }
12298
12299         if (board_config == ALC269_AUTO) {
12300                 /* automatic parse from the BIOS config */
12301                 err = alc269_parse_auto_config(codec);
12302                 if (err < 0) {
12303                         alc_free(codec);
12304                         return err;
12305                 } else if (!err) {
12306                         printk(KERN_INFO
12307                                "hda_codec: Cannot set up configuration "
12308                                "from BIOS.  Using base mode...\n");
12309                         board_config = ALC269_BASIC;
12310                 }
12311         }
12312
12313         if (board_config != ALC269_AUTO)
12314                 setup_preset(spec, &alc269_presets[board_config]);
12315
12316         spec->stream_name_analog = "ALC269 Analog";
12317         spec->stream_analog_playback = &alc269_pcm_analog_playback;
12318         spec->stream_analog_capture = &alc269_pcm_analog_capture;
12319
12320         spec->stream_name_digital = "ALC269 Digital";
12321         spec->stream_digital_playback = &alc269_pcm_digital_playback;
12322         spec->stream_digital_capture = &alc269_pcm_digital_capture;
12323
12324         spec->adc_nids = alc269_adc_nids;
12325         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12326         spec->capsrc_nids = alc269_capsrc_nids;
12327
12328         codec->patch_ops = alc_patch_ops;
12329         if (board_config == ALC269_AUTO)
12330                 spec->init_hook = alc269_auto_init;
12331 #ifdef CONFIG_SND_HDA_POWER_SAVE
12332         if (!spec->loopback.amplist)
12333                 spec->loopback.amplist = alc269_loopbacks;
12334 #endif
12335
12336         return 0;
12337 }
12338
12339 /*
12340  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
12341  */
12342
12343 /*
12344  * set the path ways for 2 channel output
12345  * need to set the codec line out and mic 1 pin widgets to inputs
12346  */
12347 static struct hda_verb alc861_threestack_ch2_init[] = {
12348         /* set pin widget 1Ah (line in) for input */
12349         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12350         /* set pin widget 18h (mic1/2) for input, for mic also enable
12351          * the vref
12352          */
12353         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12354
12355         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12356 #if 0
12357         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12358         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12359 #endif
12360         { } /* end */
12361 };
12362 /*
12363  * 6ch mode
12364  * need to set the codec line out and mic 1 pin widgets to outputs
12365  */
12366 static struct hda_verb alc861_threestack_ch6_init[] = {
12367         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12368         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12369         /* set pin widget 18h (mic1) for output (CLFE)*/
12370         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12371
12372         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12373         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12374
12375         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12376 #if 0
12377         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12378         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12379 #endif
12380         { } /* end */
12381 };
12382
12383 static struct hda_channel_mode alc861_threestack_modes[2] = {
12384         { 2, alc861_threestack_ch2_init },
12385         { 6, alc861_threestack_ch6_init },
12386 };
12387 /* Set mic1 as input and unmute the mixer */
12388 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
12389         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12390         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12391         { } /* end */
12392 };
12393 /* Set mic1 as output and mute mixer */
12394 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
12395         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12396         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12397         { } /* end */
12398 };
12399
12400 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
12401         { 2, alc861_uniwill_m31_ch2_init },
12402         { 4, alc861_uniwill_m31_ch4_init },
12403 };
12404
12405 /* Set mic1 and line-in as input and unmute the mixer */
12406 static struct hda_verb alc861_asus_ch2_init[] = {
12407         /* set pin widget 1Ah (line in) for input */
12408         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12409         /* set pin widget 18h (mic1/2) for input, for mic also enable
12410          * the vref
12411          */
12412         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12413
12414         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12415 #if 0
12416         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12417         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12418 #endif
12419         { } /* end */
12420 };
12421 /* Set mic1 nad line-in as output and mute mixer */
12422 static struct hda_verb alc861_asus_ch6_init[] = {
12423         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12424         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12425         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12426         /* set pin widget 18h (mic1) for output (CLFE)*/
12427         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12428         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12429         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12430         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12431
12432         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12433 #if 0
12434         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12435         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12436 #endif
12437         { } /* end */
12438 };
12439
12440 static struct hda_channel_mode alc861_asus_modes[2] = {
12441         { 2, alc861_asus_ch2_init },
12442         { 6, alc861_asus_ch6_init },
12443 };
12444
12445 /* patch-ALC861 */
12446
12447 static struct snd_kcontrol_new alc861_base_mixer[] = {
12448         /* output mixer control */
12449         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12450         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12451         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12452         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12453         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12454
12455         /*Input mixer control */
12456         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12457            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12458         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12459         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12460         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12461         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12462         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12463         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12464         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12465         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12466
12467         /* Capture mixer control */
12468         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12469         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12470         {
12471                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12472                 .name = "Capture Source",
12473                 .count = 1,
12474                 .info = alc_mux_enum_info,
12475                 .get = alc_mux_enum_get,
12476                 .put = alc_mux_enum_put,
12477         },
12478         { } /* end */
12479 };
12480
12481 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12482         /* output mixer control */
12483         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12484         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12485         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12486         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12487         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12488
12489         /* Input mixer control */
12490         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12491            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12492         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12493         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12494         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12495         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12496         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12497         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12498         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12499         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12500
12501         /* Capture mixer control */
12502         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12503         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12504         {
12505                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12506                 .name = "Capture Source",
12507                 .count = 1,
12508                 .info = alc_mux_enum_info,
12509                 .get = alc_mux_enum_get,
12510                 .put = alc_mux_enum_put,
12511         },
12512         {
12513                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12514                 .name = "Channel Mode",
12515                 .info = alc_ch_mode_info,
12516                 .get = alc_ch_mode_get,
12517                 .put = alc_ch_mode_put,
12518                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
12519         },
12520         { } /* end */
12521 };
12522
12523 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
12524         /* output mixer control */
12525         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12526         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12527         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12528
12529         /*Capture mixer control */
12530         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12531         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12532         {
12533                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12534                 .name = "Capture Source",
12535                 .count = 1,
12536                 .info = alc_mux_enum_info,
12537                 .get = alc_mux_enum_get,
12538                 .put = alc_mux_enum_put,
12539         },
12540
12541         { } /* end */
12542 };
12543
12544 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
12545         /* output mixer control */
12546         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12547         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12548         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12549         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12550         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12551
12552         /* Input mixer control */
12553         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12554            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12555         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12556         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12557         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12558         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12559         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12560         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12561         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12562         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12563
12564         /* Capture mixer control */
12565         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12566         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12567         {
12568                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12569                 .name = "Capture Source",
12570                 .count = 1,
12571                 .info = alc_mux_enum_info,
12572                 .get = alc_mux_enum_get,
12573                 .put = alc_mux_enum_put,
12574         },
12575         {
12576                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12577                 .name = "Channel Mode",
12578                 .info = alc_ch_mode_info,
12579                 .get = alc_ch_mode_get,
12580                 .put = alc_ch_mode_put,
12581                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
12582         },
12583         { } /* end */
12584 };
12585
12586 static struct snd_kcontrol_new alc861_asus_mixer[] = {
12587         /* output mixer control */
12588         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12589         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12590         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12591         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12592         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12593
12594         /* Input mixer control */
12595         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12596         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12597         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12598         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12599         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12600         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12601         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12602         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12603         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12604         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
12605
12606         /* Capture mixer control */
12607         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12608         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12609         {
12610                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12611                 .name = "Capture Source",
12612                 .count = 1,
12613                 .info = alc_mux_enum_info,
12614                 .get = alc_mux_enum_get,
12615                 .put = alc_mux_enum_put,
12616         },
12617         {
12618                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12619                 .name = "Channel Mode",
12620                 .info = alc_ch_mode_info,
12621                 .get = alc_ch_mode_get,
12622                 .put = alc_ch_mode_put,
12623                 .private_value = ARRAY_SIZE(alc861_asus_modes),
12624         },
12625         { }
12626 };
12627
12628 /* additional mixer */
12629 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
12630         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12631         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12632         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
12633         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
12634         { }
12635 };
12636
12637 /*
12638  * generic initialization of ADC, input mixers and output mixers
12639  */
12640 static struct hda_verb alc861_base_init_verbs[] = {
12641         /*
12642          * Unmute ADC0 and set the default input to mic-in
12643          */
12644         /* port-A for surround (rear panel) */
12645         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12646         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
12647         /* port-B for mic-in (rear panel) with vref */
12648         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12649         /* port-C for line-in (rear panel) */
12650         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12651         /* port-D for Front */
12652         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12653         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12654         /* port-E for HP out (front panel) */
12655         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
12656         /* route front PCM to HP */
12657         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12658         /* port-F for mic-in (front panel) with vref */
12659         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12660         /* port-G for CLFE (rear panel) */
12661         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12662         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12663         /* port-H for side (rear panel) */
12664         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12665         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
12666         /* CD-in */
12667         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12668         /* route front mic to ADC1*/
12669         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12670         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12671
12672         /* Unmute DAC0~3 & spdif out*/
12673         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12674         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12675         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12676         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12677         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12678
12679         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12680         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12681         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12682         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12683         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12684
12685         /* Unmute Stereo Mixer 15 */
12686         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12687         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12688         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12689         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12690
12691         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12692         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12693         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12694         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12695         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12696         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12697         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12698         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12699         /* hp used DAC 3 (Front) */
12700         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12701         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12702
12703         { }
12704 };
12705
12706 static struct hda_verb alc861_threestack_init_verbs[] = {
12707         /*
12708          * Unmute ADC0 and set the default input to mic-in
12709          */
12710         /* port-A for surround (rear panel) */
12711         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12712         /* port-B for mic-in (rear panel) with vref */
12713         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12714         /* port-C for line-in (rear panel) */
12715         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12716         /* port-D for Front */
12717         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12718         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12719         /* port-E for HP out (front panel) */
12720         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
12721         /* route front PCM to HP */
12722         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12723         /* port-F for mic-in (front panel) with vref */
12724         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12725         /* port-G for CLFE (rear panel) */
12726         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12727         /* port-H for side (rear panel) */
12728         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12729         /* CD-in */
12730         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12731         /* route front mic to ADC1*/
12732         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12733         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12734         /* Unmute DAC0~3 & spdif out*/
12735         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12736         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12737         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12738         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12739         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12740
12741         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12742         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12743         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12744         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12745         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12746
12747         /* Unmute Stereo Mixer 15 */
12748         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12749         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12750         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12751         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12752
12753         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12754         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12755         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12756         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12757         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12758         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12759         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12760         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12761         /* hp used DAC 3 (Front) */
12762         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12763         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12764         { }
12765 };
12766
12767 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
12768         /*
12769          * Unmute ADC0 and set the default input to mic-in
12770          */
12771         /* port-A for surround (rear panel) */
12772         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12773         /* port-B for mic-in (rear panel) with vref */
12774         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12775         /* port-C for line-in (rear panel) */
12776         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12777         /* port-D for Front */
12778         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12779         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12780         /* port-E for HP out (front panel) */
12781         /* this has to be set to VREF80 */
12782         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12783         /* route front PCM to HP */
12784         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12785         /* port-F for mic-in (front panel) with vref */
12786         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12787         /* port-G for CLFE (rear panel) */
12788         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12789         /* port-H for side (rear panel) */
12790         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12791         /* CD-in */
12792         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12793         /* route front mic to ADC1*/
12794         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12795         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12796         /* Unmute DAC0~3 & spdif out*/
12797         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12798         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12799         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12800         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12801         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12802
12803         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12804         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12805         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12806         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12807         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12808
12809         /* Unmute Stereo Mixer 15 */
12810         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12811         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12812         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12813         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12814
12815         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12816         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12817         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12818         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12819         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12820         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12821         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12822         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12823         /* hp used DAC 3 (Front) */
12824         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12825         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12826         { }
12827 };
12828
12829 static struct hda_verb alc861_asus_init_verbs[] = {
12830         /*
12831          * Unmute ADC0 and set the default input to mic-in
12832          */
12833         /* port-A for surround (rear panel)
12834          * according to codec#0 this is the HP jack
12835          */
12836         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
12837         /* route front PCM to HP */
12838         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
12839         /* port-B for mic-in (rear panel) with vref */
12840         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12841         /* port-C for line-in (rear panel) */
12842         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12843         /* port-D for Front */
12844         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12845         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12846         /* port-E for HP out (front panel) */
12847         /* this has to be set to VREF80 */
12848         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12849         /* route front PCM to HP */
12850         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12851         /* port-F for mic-in (front panel) with vref */
12852         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12853         /* port-G for CLFE (rear panel) */
12854         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12855         /* port-H for side (rear panel) */
12856         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12857         /* CD-in */
12858         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12859         /* route front mic to ADC1*/
12860         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12861         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12862         /* Unmute DAC0~3 & spdif out*/
12863         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12864         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12865         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12866         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12867         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12868         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12869         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12870         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12871         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12872         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12873
12874         /* Unmute Stereo Mixer 15 */
12875         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12876         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12877         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12878         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12879
12880         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12881         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12882         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12883         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12884         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12885         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12886         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12887         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12888         /* hp used DAC 3 (Front) */
12889         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12890         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12891         { }
12892 };
12893
12894 /* additional init verbs for ASUS laptops */
12895 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
12896         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
12897         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
12898         { }
12899 };
12900
12901 /*
12902  * generic initialization of ADC, input mixers and output mixers
12903  */
12904 static struct hda_verb alc861_auto_init_verbs[] = {
12905         /*
12906          * Unmute ADC0 and set the default input to mic-in
12907          */
12908         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
12909         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12910
12911         /* Unmute DAC0~3 & spdif out*/
12912         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12913         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12914         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12915         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12916         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12917
12918         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12919         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12920         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12921         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12922         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12923
12924         /* Unmute Stereo Mixer 15 */
12925         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12926         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12927         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12928         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
12929
12930         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12931         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12932         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12933         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12934         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12935         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12936         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12937         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12938
12939         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12940         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12941         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12942         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12943         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12944         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12945         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12946         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12947
12948         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
12949
12950         { }
12951 };
12952
12953 static struct hda_verb alc861_toshiba_init_verbs[] = {
12954         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12955
12956         { }
12957 };
12958
12959 /* toggle speaker-output according to the hp-jack state */
12960 static void alc861_toshiba_automute(struct hda_codec *codec)
12961 {
12962         unsigned int present;
12963
12964         present = snd_hda_codec_read(codec, 0x0f, 0,
12965                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12966         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
12967                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
12968         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
12969                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
12970 }
12971
12972 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
12973                                        unsigned int res)
12974 {
12975         if ((res >> 26) == ALC880_HP_EVENT)
12976                 alc861_toshiba_automute(codec);
12977 }
12978
12979 /* pcm configuration: identiacal with ALC880 */
12980 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
12981 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
12982 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
12983 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
12984
12985
12986 #define ALC861_DIGOUT_NID       0x07
12987
12988 static struct hda_channel_mode alc861_8ch_modes[1] = {
12989         { 8, NULL }
12990 };
12991
12992 static hda_nid_t alc861_dac_nids[4] = {
12993         /* front, surround, clfe, side */
12994         0x03, 0x06, 0x05, 0x04
12995 };
12996
12997 static hda_nid_t alc660_dac_nids[3] = {
12998         /* front, clfe, surround */
12999         0x03, 0x05, 0x06
13000 };
13001
13002 static hda_nid_t alc861_adc_nids[1] = {
13003         /* ADC0-2 */
13004         0x08,
13005 };
13006
13007 static struct hda_input_mux alc861_capture_source = {
13008         .num_items = 5,
13009         .items = {
13010                 { "Mic", 0x0 },
13011                 { "Front Mic", 0x3 },
13012                 { "Line", 0x1 },
13013                 { "CD", 0x4 },
13014                 { "Mixer", 0x5 },
13015         },
13016 };
13017
13018 /* fill in the dac_nids table from the parsed pin configuration */
13019 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13020                                      const struct auto_pin_cfg *cfg)
13021 {
13022         int i;
13023         hda_nid_t nid;
13024
13025         spec->multiout.dac_nids = spec->private_dac_nids;
13026         for (i = 0; i < cfg->line_outs; i++) {
13027                 nid = cfg->line_out_pins[i];
13028                 if (nid) {
13029                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13030                                 continue;
13031                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13032                 }
13033         }
13034         spec->multiout.num_dacs = cfg->line_outs;
13035         return 0;
13036 }
13037
13038 /* add playback controls from the parsed DAC table */
13039 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13040                                              const struct auto_pin_cfg *cfg)
13041 {
13042         char name[32];
13043         static const char *chname[4] = {
13044                 "Front", "Surround", NULL /*CLFE*/, "Side"
13045         };
13046         hda_nid_t nid;
13047         int i, idx, err;
13048
13049         for (i = 0; i < cfg->line_outs; i++) {
13050                 nid = spec->multiout.dac_nids[i];
13051                 if (!nid)
13052                         continue;
13053                 if (nid == 0x05) {
13054                         /* Center/LFE */
13055                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13056                                           "Center Playback Switch",
13057                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13058                                                               HDA_OUTPUT));
13059                         if (err < 0)
13060                                 return err;
13061                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13062                                           "LFE Playback Switch",
13063                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13064                                                               HDA_OUTPUT));
13065                         if (err < 0)
13066                                 return err;
13067                 } else {
13068                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13069                              idx++)
13070                                 if (nid == alc861_dac_nids[idx])
13071                                         break;
13072                         sprintf(name, "%s Playback Switch", chname[idx]);
13073                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13074                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13075                                                               HDA_OUTPUT));
13076                         if (err < 0)
13077                                 return err;
13078                 }
13079         }
13080         return 0;
13081 }
13082
13083 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13084 {
13085         int err;
13086         hda_nid_t nid;
13087
13088         if (!pin)
13089                 return 0;
13090
13091         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13092                 nid = 0x03;
13093                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13094                                   "Headphone Playback Switch",
13095                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13096                 if (err < 0)
13097                         return err;
13098                 spec->multiout.hp_nid = nid;
13099         }
13100         return 0;
13101 }
13102
13103 /* create playback/capture controls for input pins */
13104 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13105                                                 const struct auto_pin_cfg *cfg)
13106 {
13107         struct hda_input_mux *imux = &spec->private_imux;
13108         int i, err, idx, idx1;
13109
13110         for (i = 0; i < AUTO_PIN_LAST; i++) {
13111                 switch (cfg->input_pins[i]) {
13112                 case 0x0c:
13113                         idx1 = 1;
13114                         idx = 2;        /* Line In */
13115                         break;
13116                 case 0x0f:
13117                         idx1 = 2;
13118                         idx = 2;        /* Line In */
13119                         break;
13120                 case 0x0d:
13121                         idx1 = 0;
13122                         idx = 1;        /* Mic In */
13123                         break;
13124                 case 0x10:
13125                         idx1 = 3;
13126                         idx = 1;        /* Mic In */
13127                         break;
13128                 case 0x11:
13129                         idx1 = 4;
13130                         idx = 0;        /* CD */
13131                         break;
13132                 default:
13133                         continue;
13134                 }
13135
13136                 err = new_analog_input(spec, cfg->input_pins[i],
13137                                        auto_pin_cfg_labels[i], idx, 0x15);
13138                 if (err < 0)
13139                         return err;
13140
13141                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13142                 imux->items[imux->num_items].index = idx1;
13143                 imux->num_items++;
13144         }
13145         return 0;
13146 }
13147
13148 static struct snd_kcontrol_new alc861_capture_mixer[] = {
13149         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
13150         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
13151
13152         {
13153                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13154                 /* The multiple "Capture Source" controls confuse alsamixer
13155                  * So call somewhat different..
13156                  */
13157                 /* .name = "Capture Source", */
13158                 .name = "Input Source",
13159                 .count = 1,
13160                 .info = alc_mux_enum_info,
13161                 .get = alc_mux_enum_get,
13162                 .put = alc_mux_enum_put,
13163         },
13164         { } /* end */
13165 };
13166
13167 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13168                                               hda_nid_t nid,
13169                                               int pin_type, int dac_idx)
13170 {
13171         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13172                             pin_type);
13173         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13174                             AMP_OUT_UNMUTE);
13175 }
13176
13177 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13178 {
13179         struct alc_spec *spec = codec->spec;
13180         int i;
13181
13182         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13183         for (i = 0; i < spec->autocfg.line_outs; i++) {
13184                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13185                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13186                 if (nid)
13187                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13188                                                           spec->multiout.dac_nids[i]);
13189         }
13190 }
13191
13192 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13193 {
13194         struct alc_spec *spec = codec->spec;
13195         hda_nid_t pin;
13196
13197         pin = spec->autocfg.hp_pins[0];
13198         if (pin) /* connect to front */
13199                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13200                                                   spec->multiout.dac_nids[0]);
13201         pin = spec->autocfg.speaker_pins[0];
13202         if (pin)
13203                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13204 }
13205
13206 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13207 {
13208         struct alc_spec *spec = codec->spec;
13209         int i;
13210
13211         for (i = 0; i < AUTO_PIN_LAST; i++) {
13212                 hda_nid_t nid = spec->autocfg.input_pins[i];
13213                 if (nid >= 0x0c && nid <= 0x11) {
13214                         snd_hda_codec_write(codec, nid, 0,
13215                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13216                                             i <= AUTO_PIN_FRONT_MIC ?
13217                                             PIN_VREF80 : PIN_IN);
13218                 }
13219         }
13220 }
13221
13222 /* parse the BIOS configuration and set up the alc_spec */
13223 /* return 1 if successful, 0 if the proper config is not found,
13224  * or a negative error code
13225  */
13226 static int alc861_parse_auto_config(struct hda_codec *codec)
13227 {
13228         struct alc_spec *spec = codec->spec;
13229         int err;
13230         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13231
13232         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13233                                            alc861_ignore);
13234         if (err < 0)
13235                 return err;
13236         if (!spec->autocfg.line_outs)
13237                 return 0; /* can't find valid BIOS pin config */
13238
13239         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13240         if (err < 0)
13241                 return err;
13242         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13243         if (err < 0)
13244                 return err;
13245         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13246         if (err < 0)
13247                 return err;
13248         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13249         if (err < 0)
13250                 return err;
13251
13252         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13253
13254         if (spec->autocfg.dig_out_pin)
13255                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13256
13257         if (spec->kctl_alloc)
13258                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13259
13260         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
13261
13262         spec->num_mux_defs = 1;
13263         spec->input_mux = &spec->private_imux;
13264
13265         spec->adc_nids = alc861_adc_nids;
13266         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13267         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
13268         spec->num_mixers++;
13269
13270         return 1;
13271 }
13272
13273 /* additional initialization for auto-configuration model */
13274 static void alc861_auto_init(struct hda_codec *codec)
13275 {
13276         struct alc_spec *spec = codec->spec;
13277         alc861_auto_init_multi_out(codec);
13278         alc861_auto_init_hp_out(codec);
13279         alc861_auto_init_analog_input(codec);
13280         if (spec->unsol_event)
13281                 alc_sku_automute(codec);
13282 }
13283
13284 #ifdef CONFIG_SND_HDA_POWER_SAVE
13285 static struct hda_amp_list alc861_loopbacks[] = {
13286         { 0x15, HDA_INPUT, 0 },
13287         { 0x15, HDA_INPUT, 1 },
13288         { 0x15, HDA_INPUT, 2 },
13289         { 0x15, HDA_INPUT, 3 },
13290         { } /* end */
13291 };
13292 #endif
13293
13294
13295 /*
13296  * configuration and preset
13297  */
13298 static const char *alc861_models[ALC861_MODEL_LAST] = {
13299         [ALC861_3ST]            = "3stack",
13300         [ALC660_3ST]            = "3stack-660",
13301         [ALC861_3ST_DIG]        = "3stack-dig",
13302         [ALC861_6ST_DIG]        = "6stack-dig",
13303         [ALC861_UNIWILL_M31]    = "uniwill-m31",
13304         [ALC861_TOSHIBA]        = "toshiba",
13305         [ALC861_ASUS]           = "asus",
13306         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
13307         [ALC861_AUTO]           = "auto",
13308 };
13309
13310 static struct snd_pci_quirk alc861_cfg_tbl[] = {
13311         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
13312         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13313         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13314         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
13315         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
13316         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
13317         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
13318         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
13319          *        Any other models that need this preset?
13320          */
13321         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
13322         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
13323         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
13324         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
13325         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
13326         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
13327         /* FIXME: the below seems conflict */
13328         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
13329         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
13330         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
13331         {}
13332 };
13333
13334 static struct alc_config_preset alc861_presets[] = {
13335         [ALC861_3ST] = {
13336                 .mixers = { alc861_3ST_mixer },
13337                 .init_verbs = { alc861_threestack_init_verbs },
13338                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13339                 .dac_nids = alc861_dac_nids,
13340                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13341                 .channel_mode = alc861_threestack_modes,
13342                 .need_dac_fix = 1,
13343                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13344                 .adc_nids = alc861_adc_nids,
13345                 .input_mux = &alc861_capture_source,
13346         },
13347         [ALC861_3ST_DIG] = {
13348                 .mixers = { alc861_base_mixer },
13349                 .init_verbs = { alc861_threestack_init_verbs },
13350                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13351                 .dac_nids = alc861_dac_nids,
13352                 .dig_out_nid = ALC861_DIGOUT_NID,
13353                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13354                 .channel_mode = alc861_threestack_modes,
13355                 .need_dac_fix = 1,
13356                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13357                 .adc_nids = alc861_adc_nids,
13358                 .input_mux = &alc861_capture_source,
13359         },
13360         [ALC861_6ST_DIG] = {
13361                 .mixers = { alc861_base_mixer },
13362                 .init_verbs = { alc861_base_init_verbs },
13363                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13364                 .dac_nids = alc861_dac_nids,
13365                 .dig_out_nid = ALC861_DIGOUT_NID,
13366                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
13367                 .channel_mode = alc861_8ch_modes,
13368                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13369                 .adc_nids = alc861_adc_nids,
13370                 .input_mux = &alc861_capture_source,
13371         },
13372         [ALC660_3ST] = {
13373                 .mixers = { alc861_3ST_mixer },
13374                 .init_verbs = { alc861_threestack_init_verbs },
13375                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
13376                 .dac_nids = alc660_dac_nids,
13377                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13378                 .channel_mode = alc861_threestack_modes,
13379                 .need_dac_fix = 1,
13380                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13381                 .adc_nids = alc861_adc_nids,
13382                 .input_mux = &alc861_capture_source,
13383         },
13384         [ALC861_UNIWILL_M31] = {
13385                 .mixers = { alc861_uniwill_m31_mixer },
13386                 .init_verbs = { alc861_uniwill_m31_init_verbs },
13387                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13388                 .dac_nids = alc861_dac_nids,
13389                 .dig_out_nid = ALC861_DIGOUT_NID,
13390                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
13391                 .channel_mode = alc861_uniwill_m31_modes,
13392                 .need_dac_fix = 1,
13393                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13394                 .adc_nids = alc861_adc_nids,
13395                 .input_mux = &alc861_capture_source,
13396         },
13397         [ALC861_TOSHIBA] = {
13398                 .mixers = { alc861_toshiba_mixer },
13399                 .init_verbs = { alc861_base_init_verbs,
13400                                 alc861_toshiba_init_verbs },
13401                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13402                 .dac_nids = alc861_dac_nids,
13403                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13404                 .channel_mode = alc883_3ST_2ch_modes,
13405                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13406                 .adc_nids = alc861_adc_nids,
13407                 .input_mux = &alc861_capture_source,
13408                 .unsol_event = alc861_toshiba_unsol_event,
13409                 .init_hook = alc861_toshiba_automute,
13410         },
13411         [ALC861_ASUS] = {
13412                 .mixers = { alc861_asus_mixer },
13413                 .init_verbs = { alc861_asus_init_verbs },
13414                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13415                 .dac_nids = alc861_dac_nids,
13416                 .dig_out_nid = ALC861_DIGOUT_NID,
13417                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
13418                 .channel_mode = alc861_asus_modes,
13419                 .need_dac_fix = 1,
13420                 .hp_nid = 0x06,
13421                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13422                 .adc_nids = alc861_adc_nids,
13423                 .input_mux = &alc861_capture_source,
13424         },
13425         [ALC861_ASUS_LAPTOP] = {
13426                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
13427                 .init_verbs = { alc861_asus_init_verbs,
13428                                 alc861_asus_laptop_init_verbs },
13429                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13430                 .dac_nids = alc861_dac_nids,
13431                 .dig_out_nid = ALC861_DIGOUT_NID,
13432                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13433                 .channel_mode = alc883_3ST_2ch_modes,
13434                 .need_dac_fix = 1,
13435                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13436                 .adc_nids = alc861_adc_nids,
13437                 .input_mux = &alc861_capture_source,
13438         },
13439 };
13440
13441
13442 static int patch_alc861(struct hda_codec *codec)
13443 {
13444         struct alc_spec *spec;
13445         int board_config;
13446         int err;
13447
13448         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13449         if (spec == NULL)
13450                 return -ENOMEM;
13451
13452         codec->spec = spec;
13453
13454         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
13455                                                   alc861_models,
13456                                                   alc861_cfg_tbl);
13457
13458         if (board_config < 0) {
13459                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
13460                        "trying auto-probe from BIOS...\n");
13461                 board_config = ALC861_AUTO;
13462         }
13463
13464         if (board_config == ALC861_AUTO) {
13465                 /* automatic parse from the BIOS config */
13466                 err = alc861_parse_auto_config(codec);
13467                 if (err < 0) {
13468                         alc_free(codec);
13469                         return err;
13470                 } else if (!err) {
13471                         printk(KERN_INFO
13472                                "hda_codec: Cannot set up configuration "
13473                                "from BIOS.  Using base mode...\n");
13474                    board_config = ALC861_3ST_DIG;
13475                 }
13476         }
13477
13478         if (board_config != ALC861_AUTO)
13479                 setup_preset(spec, &alc861_presets[board_config]);
13480
13481         spec->stream_name_analog = "ALC861 Analog";
13482         spec->stream_analog_playback = &alc861_pcm_analog_playback;
13483         spec->stream_analog_capture = &alc861_pcm_analog_capture;
13484
13485         spec->stream_name_digital = "ALC861 Digital";
13486         spec->stream_digital_playback = &alc861_pcm_digital_playback;
13487         spec->stream_digital_capture = &alc861_pcm_digital_capture;
13488
13489         spec->vmaster_nid = 0x03;
13490
13491         codec->patch_ops = alc_patch_ops;
13492         if (board_config == ALC861_AUTO)
13493                 spec->init_hook = alc861_auto_init;
13494 #ifdef CONFIG_SND_HDA_POWER_SAVE
13495         if (!spec->loopback.amplist)
13496                 spec->loopback.amplist = alc861_loopbacks;
13497 #endif
13498
13499         return 0;
13500 }
13501
13502 /*
13503  * ALC861-VD support
13504  *
13505  * Based on ALC882
13506  *
13507  * In addition, an independent DAC
13508  */
13509 #define ALC861VD_DIGOUT_NID     0x06
13510
13511 static hda_nid_t alc861vd_dac_nids[4] = {
13512         /* front, surr, clfe, side surr */
13513         0x02, 0x03, 0x04, 0x05
13514 };
13515
13516 /* dac_nids for ALC660vd are in a different order - according to
13517  * Realtek's driver.
13518  * This should probably tesult in a different mixer for 6stack models
13519  * of ALC660vd codecs, but for now there is only 3stack mixer
13520  * - and it is the same as in 861vd.
13521  * adc_nids in ALC660vd are (is) the same as in 861vd
13522  */
13523 static hda_nid_t alc660vd_dac_nids[3] = {
13524         /* front, rear, clfe, rear_surr */
13525         0x02, 0x04, 0x03
13526 };
13527
13528 static hda_nid_t alc861vd_adc_nids[1] = {
13529         /* ADC0 */
13530         0x09,
13531 };
13532
13533 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
13534
13535 /* input MUX */
13536 /* FIXME: should be a matrix-type input source selection */
13537 static struct hda_input_mux alc861vd_capture_source = {
13538         .num_items = 4,
13539         .items = {
13540                 { "Mic", 0x0 },
13541                 { "Front Mic", 0x1 },
13542                 { "Line", 0x2 },
13543                 { "CD", 0x4 },
13544         },
13545 };
13546
13547 static struct hda_input_mux alc861vd_dallas_capture_source = {
13548         .num_items = 2,
13549         .items = {
13550                 { "Ext Mic", 0x0 },
13551                 { "Int Mic", 0x1 },
13552         },
13553 };
13554
13555 static struct hda_input_mux alc861vd_hp_capture_source = {
13556         .num_items = 2,
13557         .items = {
13558                 { "Front Mic", 0x0 },
13559                 { "ATAPI Mic", 0x1 },
13560         },
13561 };
13562
13563 #define alc861vd_mux_enum_info alc_mux_enum_info
13564 #define alc861vd_mux_enum_get alc_mux_enum_get
13565 /* ALC861VD has the ALC882-type input selection (but has only one ADC) */
13566 #define alc861vd_mux_enum_put alc882_mux_enum_put
13567
13568 /*
13569  * 2ch mode
13570  */
13571 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
13572         { 2, NULL }
13573 };
13574
13575 /*
13576  * 6ch mode
13577  */
13578 static struct hda_verb alc861vd_6stack_ch6_init[] = {
13579         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13580         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13581         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13582         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13583         { } /* end */
13584 };
13585
13586 /*
13587  * 8ch mode
13588  */
13589 static struct hda_verb alc861vd_6stack_ch8_init[] = {
13590         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13591         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13592         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13593         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13594         { } /* end */
13595 };
13596
13597 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
13598         { 6, alc861vd_6stack_ch6_init },
13599         { 8, alc861vd_6stack_ch8_init },
13600 };
13601
13602 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
13603         {
13604                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13605                 .name = "Channel Mode",
13606                 .info = alc_ch_mode_info,
13607                 .get = alc_ch_mode_get,
13608                 .put = alc_ch_mode_put,
13609         },
13610         { } /* end */
13611 };
13612
13613 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
13614         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
13615         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
13616
13617         {
13618                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13619                 /* The multiple "Capture Source" controls confuse alsamixer
13620                  * So call somewhat different..
13621                  */
13622                 /* .name = "Capture Source", */
13623                 .name = "Input Source",
13624                 .count = 1,
13625                 .info = alc861vd_mux_enum_info,
13626                 .get = alc861vd_mux_enum_get,
13627                 .put = alc861vd_mux_enum_put,
13628         },
13629         { } /* end */
13630 };
13631
13632 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13633  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13634  */
13635 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
13636         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13637         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13638
13639         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13640         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
13641
13642         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
13643                                 HDA_OUTPUT),
13644         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
13645                                 HDA_OUTPUT),
13646         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
13647         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
13648
13649         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
13650         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
13651
13652         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13653
13654         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13655         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13656         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13657
13658         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13659         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13660         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13661
13662         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13663         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13664
13665         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13666         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13667
13668         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13669         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13670
13671         { } /* end */
13672 };
13673
13674 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
13675         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13676         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13677
13678         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13679
13680         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13681         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13682         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13683
13684         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13685         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13686         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13687
13688         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13689         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13690
13691         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13692         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13693
13694         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13695         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13696
13697         { } /* end */
13698 };
13699
13700 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
13701         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13702         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
13703         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13704
13705         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13706
13707         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13708         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13709         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13710
13711         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13712         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13713         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13714
13715         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13716         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13717
13718         { } /* end */
13719 };
13720
13721 /* Pin assignment: Speaker=0x14, HP = 0x15,
13722  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
13723  */
13724 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
13725         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13726         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
13727         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13728         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
13729         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
13730         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13731         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13732         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
13733         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13734         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13735         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
13736         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
13737         { } /* end */
13738 };
13739
13740 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
13741  *                 Front Mic=0x18, ATAPI Mic = 0x19,
13742  */
13743 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
13744         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13745         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13746         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13747         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
13748         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13749         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13750         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13751         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13752
13753         { } /* end */
13754 };
13755
13756 /*
13757  * generic initialization of ADC, input mixers and output mixers
13758  */
13759 static struct hda_verb alc861vd_volume_init_verbs[] = {
13760         /*
13761          * Unmute ADC0 and set the default input to mic-in
13762          */
13763         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13764         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13765
13766         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
13767          * the analog-loopback mixer widget
13768          */
13769         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13770         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13771         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13772         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13773         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13774         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13775
13776         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
13777         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13778         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13779         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13780         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13781
13782         /*
13783          * Set up output mixers (0x02 - 0x05)
13784          */
13785         /* set vol=0 to output mixers */
13786         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13787         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13788         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13789         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13790
13791         /* set up input amps for analog loopback */
13792         /* Amp Indices: DAC = 0, mixer = 1 */
13793         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13794         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13795         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13796         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13797         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13798         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13799         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13800         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13801
13802         { }
13803 };
13804
13805 /*
13806  * 3-stack pin configuration:
13807  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
13808  */
13809 static struct hda_verb alc861vd_3stack_init_verbs[] = {
13810         /*
13811          * Set pin mode and muting
13812          */
13813         /* set front pin widgets 0x14 for output */
13814         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13815         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13816         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13817
13818         /* Mic (rear) pin: input vref at 80% */
13819         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13820         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13821         /* Front Mic pin: input vref at 80% */
13822         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13823         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13824         /* Line In pin: input */
13825         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13826         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13827         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13828         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13829         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13830         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13831         /* CD pin widget for input */
13832         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13833
13834         { }
13835 };
13836
13837 /*
13838  * 6-stack pin configuration:
13839  */
13840 static struct hda_verb alc861vd_6stack_init_verbs[] = {
13841         /*
13842          * Set pin mode and muting
13843          */
13844         /* set front pin widgets 0x14 for output */
13845         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13846         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13847         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13848
13849         /* Rear Pin: output 1 (0x0d) */
13850         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13851         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13852         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13853         /* CLFE Pin: output 2 (0x0e) */
13854         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13855         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13856         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
13857         /* Side Pin: output 3 (0x0f) */
13858         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13859         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13860         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
13861
13862         /* Mic (rear) pin: input vref at 80% */
13863         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13864         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13865         /* Front Mic pin: input vref at 80% */
13866         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13867         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13868         /* Line In pin: input */
13869         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13870         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13871         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13872         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13873         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13874         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13875         /* CD pin widget for input */
13876         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13877
13878         { }
13879 };
13880
13881 static struct hda_verb alc861vd_eapd_verbs[] = {
13882         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13883         { }
13884 };
13885
13886 static struct hda_verb alc660vd_eapd_verbs[] = {
13887         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13888         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13889         { }
13890 };
13891
13892 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
13893         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13894         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13895         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
13896         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13897         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13898         {}
13899 };
13900
13901 /* toggle speaker-output according to the hp-jack state */
13902 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
13903 {
13904         unsigned int present;
13905         unsigned char bits;
13906
13907         present = snd_hda_codec_read(codec, 0x1b, 0,
13908                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13909         bits = present ? HDA_AMP_MUTE : 0;
13910         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13911                                  HDA_AMP_MUTE, bits);
13912 }
13913
13914 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
13915 {
13916         unsigned int present;
13917         unsigned char bits;
13918
13919         present = snd_hda_codec_read(codec, 0x18, 0,
13920                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13921         bits = present ? HDA_AMP_MUTE : 0;
13922         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
13923                                  HDA_AMP_MUTE, bits);
13924 }
13925
13926 static void alc861vd_lenovo_automute(struct hda_codec *codec)
13927 {
13928         alc861vd_lenovo_hp_automute(codec);
13929         alc861vd_lenovo_mic_automute(codec);
13930 }
13931
13932 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
13933                                         unsigned int res)
13934 {
13935         switch (res >> 26) {
13936         case ALC880_HP_EVENT:
13937                 alc861vd_lenovo_hp_automute(codec);
13938                 break;
13939         case ALC880_MIC_EVENT:
13940                 alc861vd_lenovo_mic_automute(codec);
13941                 break;
13942         }
13943 }
13944
13945 static struct hda_verb alc861vd_dallas_verbs[] = {
13946         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13947         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13948         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13949         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13950
13951         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13952         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13953         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13954         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13955         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13956         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13957         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13958         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13959
13960         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13961         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13962         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13963         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13964         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13965         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13966         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13967         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13968
13969         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13970         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13971         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13972         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13973         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13974         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13975         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13976         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13977
13978         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13979         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13980         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13981         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13982
13983         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13984         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13985         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13986
13987         { } /* end */
13988 };
13989
13990 /* toggle speaker-output according to the hp-jack state */
13991 static void alc861vd_dallas_automute(struct hda_codec *codec)
13992 {
13993         unsigned int present;
13994
13995         present = snd_hda_codec_read(codec, 0x15, 0,
13996                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13997         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13998                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13999 }
14000
14001 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
14002 {
14003         if ((res >> 26) == ALC880_HP_EVENT)
14004                 alc861vd_dallas_automute(codec);
14005 }
14006
14007 #ifdef CONFIG_SND_HDA_POWER_SAVE
14008 #define alc861vd_loopbacks      alc880_loopbacks
14009 #endif
14010
14011 /* pcm configuration: identiacal with ALC880 */
14012 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14013 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14014 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14015 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14016
14017 /*
14018  * configuration and preset
14019  */
14020 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14021         [ALC660VD_3ST]          = "3stack-660",
14022         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14023         [ALC861VD_3ST]          = "3stack",
14024         [ALC861VD_3ST_DIG]      = "3stack-digout",
14025         [ALC861VD_6ST_DIG]      = "6stack-digout",
14026         [ALC861VD_LENOVO]       = "lenovo",
14027         [ALC861VD_DALLAS]       = "dallas",
14028         [ALC861VD_HP]           = "hp",
14029         [ALC861VD_AUTO]         = "auto",
14030 };
14031
14032 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14033         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14034         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14035         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14036         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14037         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC861VD_LENOVO),
14038         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14039         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14040         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14041         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14042         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14043         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14044         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14045         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14046         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
14047         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
14048         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
14049         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14050         {}
14051 };
14052
14053 static struct alc_config_preset alc861vd_presets[] = {
14054         [ALC660VD_3ST] = {
14055                 .mixers = { alc861vd_3st_mixer },
14056                 .init_verbs = { alc861vd_volume_init_verbs,
14057                                  alc861vd_3stack_init_verbs },
14058                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14059                 .dac_nids = alc660vd_dac_nids,
14060                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14061                 .channel_mode = alc861vd_3stack_2ch_modes,
14062                 .input_mux = &alc861vd_capture_source,
14063         },
14064         [ALC660VD_3ST_DIG] = {
14065                 .mixers = { alc861vd_3st_mixer },
14066                 .init_verbs = { alc861vd_volume_init_verbs,
14067                                  alc861vd_3stack_init_verbs },
14068                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14069                 .dac_nids = alc660vd_dac_nids,
14070                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14071                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14072                 .channel_mode = alc861vd_3stack_2ch_modes,
14073                 .input_mux = &alc861vd_capture_source,
14074         },
14075         [ALC861VD_3ST] = {
14076                 .mixers = { alc861vd_3st_mixer },
14077                 .init_verbs = { alc861vd_volume_init_verbs,
14078                                  alc861vd_3stack_init_verbs },
14079                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14080                 .dac_nids = alc861vd_dac_nids,
14081                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14082                 .channel_mode = alc861vd_3stack_2ch_modes,
14083                 .input_mux = &alc861vd_capture_source,
14084         },
14085         [ALC861VD_3ST_DIG] = {
14086                 .mixers = { alc861vd_3st_mixer },
14087                 .init_verbs = { alc861vd_volume_init_verbs,
14088                                  alc861vd_3stack_init_verbs },
14089                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14090                 .dac_nids = alc861vd_dac_nids,
14091                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14092                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14093                 .channel_mode = alc861vd_3stack_2ch_modes,
14094                 .input_mux = &alc861vd_capture_source,
14095         },
14096         [ALC861VD_6ST_DIG] = {
14097                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14098                 .init_verbs = { alc861vd_volume_init_verbs,
14099                                 alc861vd_6stack_init_verbs },
14100                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14101                 .dac_nids = alc861vd_dac_nids,
14102                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14103                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14104                 .channel_mode = alc861vd_6stack_modes,
14105                 .input_mux = &alc861vd_capture_source,
14106         },
14107         [ALC861VD_LENOVO] = {
14108                 .mixers = { alc861vd_lenovo_mixer },
14109                 .init_verbs = { alc861vd_volume_init_verbs,
14110                                 alc861vd_3stack_init_verbs,
14111                                 alc861vd_eapd_verbs,
14112                                 alc861vd_lenovo_unsol_verbs },
14113                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14114                 .dac_nids = alc660vd_dac_nids,
14115                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14116                 .channel_mode = alc861vd_3stack_2ch_modes,
14117                 .input_mux = &alc861vd_capture_source,
14118                 .unsol_event = alc861vd_lenovo_unsol_event,
14119                 .init_hook = alc861vd_lenovo_automute,
14120         },
14121         [ALC861VD_DALLAS] = {
14122                 .mixers = { alc861vd_dallas_mixer },
14123                 .init_verbs = { alc861vd_dallas_verbs },
14124                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14125                 .dac_nids = alc861vd_dac_nids,
14126                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14127                 .channel_mode = alc861vd_3stack_2ch_modes,
14128                 .input_mux = &alc861vd_dallas_capture_source,
14129                 .unsol_event = alc861vd_dallas_unsol_event,
14130                 .init_hook = alc861vd_dallas_automute,
14131         },
14132         [ALC861VD_HP] = {
14133                 .mixers = { alc861vd_hp_mixer },
14134                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14135                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14136                 .dac_nids = alc861vd_dac_nids,
14137                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14138                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14139                 .channel_mode = alc861vd_3stack_2ch_modes,
14140                 .input_mux = &alc861vd_hp_capture_source,
14141                 .unsol_event = alc861vd_dallas_unsol_event,
14142                 .init_hook = alc861vd_dallas_automute,
14143         },
14144 };
14145
14146 /*
14147  * BIOS auto configuration
14148  */
14149 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14150                                 hda_nid_t nid, int pin_type, int dac_idx)
14151 {
14152         alc_set_pin_output(codec, nid, pin_type);
14153 }
14154
14155 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14156 {
14157         struct alc_spec *spec = codec->spec;
14158         int i;
14159
14160         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14161         for (i = 0; i <= HDA_SIDE; i++) {
14162                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14163                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14164                 if (nid)
14165                         alc861vd_auto_set_output_and_unmute(codec, nid,
14166                                                             pin_type, i);
14167         }
14168 }
14169
14170
14171 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14172 {
14173         struct alc_spec *spec = codec->spec;
14174         hda_nid_t pin;
14175
14176         pin = spec->autocfg.hp_pins[0];
14177         if (pin) /* connect to front and  use dac 0 */
14178                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14179         pin = spec->autocfg.speaker_pins[0];
14180         if (pin)
14181                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14182 }
14183
14184 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14185 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14186
14187 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14188 {
14189         struct alc_spec *spec = codec->spec;
14190         int i;
14191
14192         for (i = 0; i < AUTO_PIN_LAST; i++) {
14193                 hda_nid_t nid = spec->autocfg.input_pins[i];
14194                 if (alc861vd_is_input_pin(nid)) {
14195                         snd_hda_codec_write(codec, nid, 0,
14196                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
14197                                         i <= AUTO_PIN_FRONT_MIC ?
14198                                                         PIN_VREF80 : PIN_IN);
14199                         if (nid != ALC861VD_PIN_CD_NID)
14200                                 snd_hda_codec_write(codec, nid, 0,
14201                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14202                                                 AMP_OUT_MUTE);
14203                 }
14204         }
14205 }
14206
14207 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14208
14209 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14210 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14211
14212 /* add playback controls from the parsed DAC table */
14213 /* Based on ALC880 version. But ALC861VD has separate,
14214  * different NIDs for mute/unmute switch and volume control */
14215 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14216                                              const struct auto_pin_cfg *cfg)
14217 {
14218         char name[32];
14219         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14220         hda_nid_t nid_v, nid_s;
14221         int i, err;
14222
14223         for (i = 0; i < cfg->line_outs; i++) {
14224                 if (!spec->multiout.dac_nids[i])
14225                         continue;
14226                 nid_v = alc861vd_idx_to_mixer_vol(
14227                                 alc880_dac_to_idx(
14228                                         spec->multiout.dac_nids[i]));
14229                 nid_s = alc861vd_idx_to_mixer_switch(
14230                                 alc880_dac_to_idx(
14231                                         spec->multiout.dac_nids[i]));
14232
14233                 if (i == 2) {
14234                         /* Center/LFE */
14235                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14236                                           "Center Playback Volume",
14237                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14238                                                               HDA_OUTPUT));
14239                         if (err < 0)
14240                                 return err;
14241                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14242                                           "LFE Playback Volume",
14243                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14244                                                               HDA_OUTPUT));
14245                         if (err < 0)
14246                                 return err;
14247                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14248                                           "Center Playback Switch",
14249                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14250                                                               HDA_INPUT));
14251                         if (err < 0)
14252                                 return err;
14253                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14254                                           "LFE Playback Switch",
14255                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14256                                                               HDA_INPUT));
14257                         if (err < 0)
14258                                 return err;
14259                 } else {
14260                         sprintf(name, "%s Playback Volume", chname[i]);
14261                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14262                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14263                                                               HDA_OUTPUT));
14264                         if (err < 0)
14265                                 return err;
14266                         sprintf(name, "%s Playback Switch", chname[i]);
14267                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14268                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14269                                                               HDA_INPUT));
14270                         if (err < 0)
14271                                 return err;
14272                 }
14273         }
14274         return 0;
14275 }
14276
14277 /* add playback controls for speaker and HP outputs */
14278 /* Based on ALC880 version. But ALC861VD has separate,
14279  * different NIDs for mute/unmute switch and volume control */
14280 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14281                                         hda_nid_t pin, const char *pfx)
14282 {
14283         hda_nid_t nid_v, nid_s;
14284         int err;
14285         char name[32];
14286
14287         if (!pin)
14288                 return 0;
14289
14290         if (alc880_is_fixed_pin(pin)) {
14291                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14292                 /* specify the DAC as the extra output */
14293                 if (!spec->multiout.hp_nid)
14294                         spec->multiout.hp_nid = nid_v;
14295                 else
14296                         spec->multiout.extra_out_nid[0] = nid_v;
14297                 /* control HP volume/switch on the output mixer amp */
14298                 nid_v = alc861vd_idx_to_mixer_vol(
14299                                 alc880_fixed_pin_idx(pin));
14300                 nid_s = alc861vd_idx_to_mixer_switch(
14301                                 alc880_fixed_pin_idx(pin));
14302
14303                 sprintf(name, "%s Playback Volume", pfx);
14304                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14305                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
14306                 if (err < 0)
14307                         return err;
14308                 sprintf(name, "%s Playback Switch", pfx);
14309                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14310                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
14311                 if (err < 0)
14312                         return err;
14313         } else if (alc880_is_multi_pin(pin)) {
14314                 /* set manual connection */
14315                 /* we have only a switch on HP-out PIN */
14316                 sprintf(name, "%s Playback Switch", pfx);
14317                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14318                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14319                 if (err < 0)
14320                         return err;
14321         }
14322         return 0;
14323 }
14324
14325 /* parse the BIOS configuration and set up the alc_spec
14326  * return 1 if successful, 0 if the proper config is not found,
14327  * or a negative error code
14328  * Based on ALC880 version - had to change it to override
14329  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
14330 static int alc861vd_parse_auto_config(struct hda_codec *codec)
14331 {
14332         struct alc_spec *spec = codec->spec;
14333         int err;
14334         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
14335
14336         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14337                                            alc861vd_ignore);
14338         if (err < 0)
14339                 return err;
14340         if (!spec->autocfg.line_outs)
14341                 return 0; /* can't find valid BIOS pin config */
14342
14343         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14344         if (err < 0)
14345                 return err;
14346         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
14347         if (err < 0)
14348                 return err;
14349         err = alc861vd_auto_create_extra_out(spec,
14350                                              spec->autocfg.speaker_pins[0],
14351                                              "Speaker");
14352         if (err < 0)
14353                 return err;
14354         err = alc861vd_auto_create_extra_out(spec,
14355                                              spec->autocfg.hp_pins[0],
14356                                              "Headphone");
14357         if (err < 0)
14358                 return err;
14359         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
14360         if (err < 0)
14361                 return err;
14362
14363         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14364
14365         if (spec->autocfg.dig_out_pin)
14366                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14367
14368         if (spec->kctl_alloc)
14369                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
14370
14371         spec->init_verbs[spec->num_init_verbs++]
14372                 = alc861vd_volume_init_verbs;
14373
14374         spec->num_mux_defs = 1;
14375         spec->input_mux = &spec->private_imux;
14376
14377         err = alc_auto_add_mic_boost(codec);
14378         if (err < 0)
14379                 return err;
14380
14381         return 1;
14382 }
14383
14384 /* additional initialization for auto-configuration model */
14385 static void alc861vd_auto_init(struct hda_codec *codec)
14386 {
14387         struct alc_spec *spec = codec->spec;
14388         alc861vd_auto_init_multi_out(codec);
14389         alc861vd_auto_init_hp_out(codec);
14390         alc861vd_auto_init_analog_input(codec);
14391         alc861vd_auto_init_input_src(codec);
14392         if (spec->unsol_event)
14393                 alc_sku_automute(codec);
14394 }
14395
14396 static int patch_alc861vd(struct hda_codec *codec)
14397 {
14398         struct alc_spec *spec;
14399         int err, board_config;
14400
14401         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14402         if (spec == NULL)
14403                 return -ENOMEM;
14404
14405         codec->spec = spec;
14406
14407         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
14408                                                   alc861vd_models,
14409                                                   alc861vd_cfg_tbl);
14410
14411         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
14412                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
14413                         "ALC861VD, trying auto-probe from BIOS...\n");
14414                 board_config = ALC861VD_AUTO;
14415         }
14416
14417         if (board_config == ALC861VD_AUTO) {
14418                 /* automatic parse from the BIOS config */
14419                 err = alc861vd_parse_auto_config(codec);
14420                 if (err < 0) {
14421                         alc_free(codec);
14422                         return err;
14423                 } else if (!err) {
14424                         printk(KERN_INFO
14425                                "hda_codec: Cannot set up configuration "
14426                                "from BIOS.  Using base mode...\n");
14427                         board_config = ALC861VD_3ST;
14428                 }
14429         }
14430
14431         if (board_config != ALC861VD_AUTO)
14432                 setup_preset(spec, &alc861vd_presets[board_config]);
14433
14434         if (codec->vendor_id == 0x10ec0660) {
14435                 spec->stream_name_analog = "ALC660-VD Analog";
14436                 spec->stream_name_digital = "ALC660-VD Digital";
14437                 /* always turn on EAPD */
14438                 spec->init_verbs[spec->num_init_verbs++] = alc660vd_eapd_verbs;
14439         } else {
14440                 spec->stream_name_analog = "ALC861VD Analog";
14441                 spec->stream_name_digital = "ALC861VD Digital";
14442         }
14443
14444         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
14445         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
14446
14447         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
14448         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
14449
14450         spec->adc_nids = alc861vd_adc_nids;
14451         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14452         spec->capsrc_nids = alc861vd_capsrc_nids;
14453
14454         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
14455         spec->num_mixers++;
14456
14457         spec->vmaster_nid = 0x02;
14458
14459         codec->patch_ops = alc_patch_ops;
14460
14461         if (board_config == ALC861VD_AUTO)
14462                 spec->init_hook = alc861vd_auto_init;
14463 #ifdef CONFIG_SND_HDA_POWER_SAVE
14464         if (!spec->loopback.amplist)
14465                 spec->loopback.amplist = alc861vd_loopbacks;
14466 #endif
14467
14468         return 0;
14469 }
14470
14471 /*
14472  * ALC662 support
14473  *
14474  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
14475  * configuration.  Each pin widget can choose any input DACs and a mixer.
14476  * Each ADC is connected from a mixer of all inputs.  This makes possible
14477  * 6-channel independent captures.
14478  *
14479  * In addition, an independent DAC for the multi-playback (not used in this
14480  * driver yet).
14481  */
14482 #define ALC662_DIGOUT_NID       0x06
14483 #define ALC662_DIGIN_NID        0x0a
14484
14485 static hda_nid_t alc662_dac_nids[4] = {
14486         /* front, rear, clfe, rear_surr */
14487         0x02, 0x03, 0x04
14488 };
14489
14490 static hda_nid_t alc662_adc_nids[1] = {
14491         /* ADC1-2 */
14492         0x09,
14493 };
14494
14495 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
14496
14497 /* input MUX */
14498 /* FIXME: should be a matrix-type input source selection */
14499 static struct hda_input_mux alc662_capture_source = {
14500         .num_items = 4,
14501         .items = {
14502                 { "Mic", 0x0 },
14503                 { "Front Mic", 0x1 },
14504                 { "Line", 0x2 },
14505                 { "CD", 0x4 },
14506         },
14507 };
14508
14509 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
14510         .num_items = 2,
14511         .items = {
14512                 { "Mic", 0x1 },
14513                 { "Line", 0x2 },
14514         },
14515 };
14516
14517 static struct hda_input_mux alc662_eeepc_capture_source = {
14518         .num_items = 2,
14519         .items = {
14520                 { "i-Mic", 0x1 },
14521                 { "e-Mic", 0x0 },
14522         },
14523 };
14524
14525 static struct hda_input_mux alc663_capture_source = {
14526         .num_items = 3,
14527         .items = {
14528                 { "Mic", 0x0 },
14529                 { "Front Mic", 0x1 },
14530                 { "Line", 0x2 },
14531         },
14532 };
14533
14534 static struct hda_input_mux alc663_m51va_capture_source = {
14535         .num_items = 2,
14536         .items = {
14537                 { "Ext-Mic", 0x0 },
14538                 { "D-Mic", 0x9 },
14539         },
14540 };
14541
14542 #define alc662_mux_enum_info alc_mux_enum_info
14543 #define alc662_mux_enum_get alc_mux_enum_get
14544 #define alc662_mux_enum_put alc882_mux_enum_put
14545
14546 /*
14547  * 2ch mode
14548  */
14549 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
14550         { 2, NULL }
14551 };
14552
14553 /*
14554  * 2ch mode
14555  */
14556 static struct hda_verb alc662_3ST_ch2_init[] = {
14557         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
14558         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14559         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
14560         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14561         { } /* end */
14562 };
14563
14564 /*
14565  * 6ch mode
14566  */
14567 static struct hda_verb alc662_3ST_ch6_init[] = {
14568         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14569         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14570         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
14571         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14572         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14573         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
14574         { } /* end */
14575 };
14576
14577 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
14578         { 2, alc662_3ST_ch2_init },
14579         { 6, alc662_3ST_ch6_init },
14580 };
14581
14582 /*
14583  * 2ch mode
14584  */
14585 static struct hda_verb alc662_sixstack_ch6_init[] = {
14586         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14587         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14588         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14589         { } /* end */
14590 };
14591
14592 /*
14593  * 6ch mode
14594  */
14595 static struct hda_verb alc662_sixstack_ch8_init[] = {
14596         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14597         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14598         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14599         { } /* end */
14600 };
14601
14602 static struct hda_channel_mode alc662_5stack_modes[2] = {
14603         { 2, alc662_sixstack_ch6_init },
14604         { 6, alc662_sixstack_ch8_init },
14605 };
14606
14607 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14608  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14609  */
14610
14611 static struct snd_kcontrol_new alc662_base_mixer[] = {
14612         /* output mixer control */
14613         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
14614         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14615         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
14616         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14617         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14618         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14619         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14620         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14621         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14622
14623         /*Input mixer control */
14624         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
14625         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
14626         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
14627         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
14628         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
14629         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
14630         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
14631         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
14632         { } /* end */
14633 };
14634
14635 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
14636         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14637         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14638         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14639         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14640         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14641         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14642         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14643         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14644         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14645         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14646         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14647         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14648         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14649         { } /* end */
14650 };
14651
14652 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
14653         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14654         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14655         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14656         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14657         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14658         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14659         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14660         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14661         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14662         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14663         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14664         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14665         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14666         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14667         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14668         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14669         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14670         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14671         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14672         { } /* end */
14673 };
14674
14675 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
14676         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14677         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
14678         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14679         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
14680         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14681         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14682         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14683         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14684         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14685         { } /* end */
14686 };
14687
14688 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
14689         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14690
14691         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14692         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14693
14694         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
14695         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14696         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14697
14698         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
14699         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14700         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14701         { } /* end */
14702 };
14703
14704 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
14705         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14706         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14707         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14708         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
14709         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14710         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14711         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
14712         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
14713         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14714         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
14715         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14716         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14717         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14718         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14719         { } /* end */
14720 };
14721
14722 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
14723         .ops = &snd_hda_bind_vol,
14724         .values = {
14725                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
14726                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
14727                 0
14728         },
14729 };
14730
14731 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
14732         .ops = &snd_hda_bind_sw,
14733         .values = {
14734                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14735                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
14736                 0
14737         },
14738 };
14739
14740 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
14741         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14742         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
14743         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14744         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14745         { } /* end */
14746 };
14747
14748 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
14749         .ops = &snd_hda_bind_sw,
14750         .values = {
14751                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14752                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
14753                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
14754                 0
14755         },
14756 };
14757
14758 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
14759         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14760         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
14761         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14762         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14763         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14764         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14765
14766         { } /* end */
14767 };
14768
14769 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
14770         .ops = &snd_hda_bind_sw,
14771         .values = {
14772                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14773                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
14774                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
14775                 0
14776         },
14777 };
14778
14779 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
14780         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14781         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
14782         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14783         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14784         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14785         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14786         { } /* end */
14787 };
14788
14789 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
14790         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14791         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14792         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14793         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14794         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14795         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14796         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14797         { } /* end */
14798 };
14799
14800 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
14801         .ops = &snd_hda_bind_vol,
14802         .values = {
14803                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
14804                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
14805                 0
14806         },
14807 };
14808
14809 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
14810         .ops = &snd_hda_bind_sw,
14811         .values = {
14812                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14813                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
14814                 0
14815         },
14816 };
14817
14818 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
14819         HDA_BIND_VOL("Master Playback Volume",
14820                                 &alc663_asus_two_bind_master_vol),
14821         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
14822         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14823         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14824         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14825         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14826         { } /* end */
14827 };
14828
14829 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
14830         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14831         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
14832         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14833         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14834         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14835         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14836         { } /* end */
14837 };
14838
14839 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
14840         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14841         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14842         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14843         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14844         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14845
14846         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14847         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14848         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14849         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14850         { } /* end */
14851 };
14852
14853 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
14854         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14855         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14856         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14857
14858         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14859         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14860         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14861         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14862         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14863         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14864         { } /* end */
14865 };
14866
14867 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
14868         {
14869                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14870                 .name = "Channel Mode",
14871                 .info = alc_ch_mode_info,
14872                 .get = alc_ch_mode_get,
14873                 .put = alc_ch_mode_put,
14874         },
14875         { } /* end */
14876 };
14877
14878 static struct hda_verb alc662_init_verbs[] = {
14879         /* ADC: mute amp left and right */
14880         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14881         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14882         /* Front mixer: unmute input/output amp left and right (volume = 0) */
14883
14884         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14885         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14886         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14887         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14888         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14889
14890         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14891         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14892         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14893         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14894         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14895         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14896
14897         /* Front Pin: output 0 (0x0c) */
14898         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14899         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14900
14901         /* Rear Pin: output 1 (0x0d) */
14902         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14903         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14904
14905         /* CLFE Pin: output 2 (0x0e) */
14906         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14907         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14908
14909         /* Mic (rear) pin: input vref at 80% */
14910         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14911         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14912         /* Front Mic pin: input vref at 80% */
14913         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14914         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14915         /* Line In pin: input */
14916         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14917         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14918         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14919         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14920         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14921         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14922         /* CD pin widget for input */
14923         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14924
14925         /* FIXME: use matrix-type input source selection */
14926         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
14927         /* Input mixer */
14928         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14929         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14930         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14931         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14932
14933         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14934         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14935         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14936         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14937
14938         /* always trun on EAPD */
14939         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14940         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14941
14942         { }
14943 };
14944
14945 static struct hda_verb alc662_sue_init_verbs[] = {
14946         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
14947         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
14948         {}
14949 };
14950
14951 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
14952         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14953         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14954         {}
14955 };
14956
14957 /* Set Unsolicited Event*/
14958 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
14959         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14960         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14961         {}
14962 };
14963
14964 /*
14965  * generic initialization of ADC, input mixers and output mixers
14966  */
14967 static struct hda_verb alc662_auto_init_verbs[] = {
14968         /*
14969          * Unmute ADC and set the default input to mic-in
14970          */
14971         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14972         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14973
14974         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
14975          * mixer widget
14976          * Note: PASD motherboards uses the Line In 2 as the input for front
14977          * panel mic (mic 2)
14978          */
14979         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14980         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14981         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14982         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14983         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14984         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14985
14986         /*
14987          * Set up output mixers (0x0c - 0x0f)
14988          */
14989         /* set vol=0 to output mixers */
14990         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14991         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14992         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14993
14994         /* set up input amps for analog loopback */
14995         /* Amp Indices: DAC = 0, mixer = 1 */
14996         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14997         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14998         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14999         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15000         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15001         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15002
15003
15004         /* FIXME: use matrix-type input source selection */
15005         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15006         /* Input mixer */
15007         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15008         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15009         { }
15010 };
15011
15012 /* additional verbs for ALC663 */
15013 static struct hda_verb alc663_auto_init_verbs[] = {
15014         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15015         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15016         { }
15017 };
15018
15019 static struct hda_verb alc663_m51va_init_verbs[] = {
15020         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15021         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15022         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15023         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15024         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15025         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15026         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15027         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15028         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15029         {}
15030 };
15031
15032 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15033         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15034         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15035         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15036         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15037         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15038         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15039         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15040         {}
15041 };
15042
15043 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15044         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15045         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15046         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15047         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15048         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15049         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15050         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15051         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15052         {}
15053 };
15054
15055 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15056         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15057         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15058         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15059         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15060         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15061         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15062         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15063         {}
15064 };
15065
15066 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15067         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15068         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15069         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15070         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15071         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15072         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15073         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15074         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15075         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15076         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15077         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15078         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15079         {}
15080 };
15081
15082 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15083         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15084         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15085         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15086         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15087         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15088         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15089         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15090         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15091         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15092         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15093         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15094         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15095         {}
15096 };
15097
15098 static struct hda_verb alc663_g71v_init_verbs[] = {
15099         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15100         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15101         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15102
15103         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15104         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15105         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15106
15107         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15108         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15109         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15110         {}
15111 };
15112
15113 static struct hda_verb alc663_g50v_init_verbs[] = {
15114         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15115         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15116         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15117
15118         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15119         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15120         {}
15121 };
15122
15123 static struct hda_verb alc662_ecs_init_verbs[] = {
15124         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15125         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15126         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15127         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15128         {}
15129 };
15130
15131 /* capture mixer elements */
15132 static struct snd_kcontrol_new alc662_capture_mixer[] = {
15133         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15134         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15135         {
15136                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15137                 /* The multiple "Capture Source" controls confuse alsamixer
15138                  * So call somewhat different..
15139                  */
15140                 /* .name = "Capture Source", */
15141                 .name = "Input Source",
15142                 .count = 1,
15143                 .info = alc662_mux_enum_info,
15144                 .get = alc662_mux_enum_get,
15145                 .put = alc662_mux_enum_put,
15146         },
15147         { } /* end */
15148 };
15149
15150 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15151         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15152         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15153         { } /* end */
15154 };
15155
15156 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15157 {
15158         unsigned int present;
15159         unsigned char bits;
15160
15161         present = snd_hda_codec_read(codec, 0x14, 0,
15162                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15163         bits = present ? HDA_AMP_MUTE : 0;
15164         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15165                                  HDA_AMP_MUTE, bits);
15166 }
15167
15168 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15169 {
15170         unsigned int present;
15171         unsigned char bits;
15172
15173         present = snd_hda_codec_read(codec, 0x1b, 0,
15174                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15175         bits = present ? HDA_AMP_MUTE : 0;
15176         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15177                                  HDA_AMP_MUTE, bits);
15178         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15179                                  HDA_AMP_MUTE, bits);
15180 }
15181
15182 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15183                                            unsigned int res)
15184 {
15185         if ((res >> 26) == ALC880_HP_EVENT)
15186                 alc662_lenovo_101e_all_automute(codec);
15187         if ((res >> 26) == ALC880_FRONT_EVENT)
15188                 alc662_lenovo_101e_ispeaker_automute(codec);
15189 }
15190
15191 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15192 {
15193         unsigned int present;
15194
15195         present = snd_hda_codec_read(codec, 0x18, 0,
15196                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15197         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15198                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15199         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15200                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15201         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15202                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15203         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15204                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15205 }
15206
15207 /* unsolicited event for HP jack sensing */
15208 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15209                                      unsigned int res)
15210 {
15211         if ((res >> 26) == ALC880_HP_EVENT)
15212                 alc262_hippo1_automute( codec );
15213
15214         if ((res >> 26) == ALC880_MIC_EVENT)
15215                 alc662_eeepc_mic_automute(codec);
15216 }
15217
15218 static void alc662_eeepc_inithook(struct hda_codec *codec)
15219 {
15220         alc262_hippo1_automute( codec );
15221         alc662_eeepc_mic_automute(codec);
15222 }
15223
15224 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15225 {
15226         unsigned int mute;
15227         unsigned int present;
15228
15229         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15230         present = snd_hda_codec_read(codec, 0x14, 0,
15231                                      AC_VERB_GET_PIN_SENSE, 0);
15232         present = (present & 0x80000000) != 0;
15233         if (present) {
15234                 /* mute internal speaker */
15235                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15236                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15237         } else {
15238                 /* unmute internal speaker if necessary */
15239                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15240                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15241                                         HDA_AMP_MUTE, mute);
15242         }
15243 }
15244
15245 /* unsolicited event for HP jack sensing */
15246 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15247                                           unsigned int res)
15248 {
15249         if ((res >> 26) == ALC880_HP_EVENT)
15250                 alc662_eeepc_ep20_automute(codec);
15251 }
15252
15253 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15254 {
15255         alc662_eeepc_ep20_automute(codec);
15256 }
15257
15258 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15259 {
15260         unsigned int present;
15261         unsigned char bits;
15262
15263         present = snd_hda_codec_read(codec, 0x21, 0,
15264                         AC_VERB_GET_PIN_SENSE, 0)
15265                         & AC_PINSENSE_PRESENCE;
15266         bits = present ? HDA_AMP_MUTE : 0;
15267         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15268                                 AMP_IN_MUTE(0), bits);
15269         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15270                                 AMP_IN_MUTE(0), bits);
15271 }
15272
15273 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15274 {
15275         unsigned int present;
15276         unsigned char bits;
15277
15278         present = snd_hda_codec_read(codec, 0x21, 0,
15279                         AC_VERB_GET_PIN_SENSE, 0)
15280                         & AC_PINSENSE_PRESENCE;
15281         bits = present ? HDA_AMP_MUTE : 0;
15282         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15283                                 AMP_IN_MUTE(0), bits);
15284         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15285                                 AMP_IN_MUTE(0), bits);
15286         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15287                                 AMP_IN_MUTE(0), bits);
15288         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15289                                 AMP_IN_MUTE(0), bits);
15290 }
15291
15292 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15293 {
15294         unsigned int present;
15295         unsigned char bits;
15296
15297         present = snd_hda_codec_read(codec, 0x15, 0,
15298                         AC_VERB_GET_PIN_SENSE, 0)
15299                         & AC_PINSENSE_PRESENCE;
15300         bits = present ? HDA_AMP_MUTE : 0;
15301         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15302                                 AMP_IN_MUTE(0), bits);
15303         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15304                                 AMP_IN_MUTE(0), bits);
15305         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15306                                 AMP_IN_MUTE(0), bits);
15307         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15308                                 AMP_IN_MUTE(0), bits);
15309 }
15310
15311 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15312 {
15313         unsigned int present;
15314         unsigned char bits;
15315
15316         present = snd_hda_codec_read(codec, 0x1b, 0,
15317                         AC_VERB_GET_PIN_SENSE, 0)
15318                         & AC_PINSENSE_PRESENCE;
15319         bits = present ? 0 : PIN_OUT;
15320         snd_hda_codec_write(codec, 0x14, 0,
15321                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15322 }
15323
15324 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15325 {
15326         unsigned int present1, present2;
15327
15328         present1 = snd_hda_codec_read(codec, 0x21, 0,
15329                         AC_VERB_GET_PIN_SENSE, 0)
15330                         & AC_PINSENSE_PRESENCE;
15331         present2 = snd_hda_codec_read(codec, 0x15, 0,
15332                         AC_VERB_GET_PIN_SENSE, 0)
15333                         & AC_PINSENSE_PRESENCE;
15334
15335         if (present1 || present2) {
15336                 snd_hda_codec_write_cache(codec, 0x14, 0,
15337                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15338         } else {
15339                 snd_hda_codec_write_cache(codec, 0x14, 0,
15340                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15341         }
15342 }
15343
15344 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15345 {
15346         unsigned int present1, present2;
15347
15348         present1 = snd_hda_codec_read(codec, 0x1b, 0,
15349                                 AC_VERB_GET_PIN_SENSE, 0)
15350                                 & AC_PINSENSE_PRESENCE;
15351         present2 = snd_hda_codec_read(codec, 0x15, 0,
15352                                 AC_VERB_GET_PIN_SENSE, 0)
15353                                 & AC_PINSENSE_PRESENCE;
15354
15355         if (present1 || present2) {
15356                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15357                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15358                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15359                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15360         } else {
15361                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15362                                 AMP_IN_MUTE(0), 0);
15363                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15364                                 AMP_IN_MUTE(0), 0);
15365         }
15366 }
15367
15368 static void alc663_m51va_mic_automute(struct hda_codec *codec)
15369 {
15370         unsigned int present;
15371
15372         present = snd_hda_codec_read(codec, 0x18, 0,
15373                         AC_VERB_GET_PIN_SENSE, 0)
15374                         & AC_PINSENSE_PRESENCE;
15375         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15376                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15377         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15378                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15379         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15380                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15381         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15382                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15383 }
15384
15385 static void alc663_m51va_unsol_event(struct hda_codec *codec,
15386                                            unsigned int res)
15387 {
15388         switch (res >> 26) {
15389         case ALC880_HP_EVENT:
15390                 alc663_m51va_speaker_automute(codec);
15391                 break;
15392         case ALC880_MIC_EVENT:
15393                 alc663_m51va_mic_automute(codec);
15394                 break;
15395         }
15396 }
15397
15398 static void alc663_m51va_inithook(struct hda_codec *codec)
15399 {
15400         alc663_m51va_speaker_automute(codec);
15401         alc663_m51va_mic_automute(codec);
15402 }
15403
15404 /* ***************** Mode1 ******************************/
15405 static void alc663_mode1_unsol_event(struct hda_codec *codec,
15406                                            unsigned int res)
15407 {
15408         switch (res >> 26) {
15409         case ALC880_HP_EVENT:
15410                 alc663_m51va_speaker_automute(codec);
15411                 break;
15412         case ALC880_MIC_EVENT:
15413                 alc662_eeepc_mic_automute(codec);
15414                 break;
15415         }
15416 }
15417
15418 static void alc663_mode1_inithook(struct hda_codec *codec)
15419 {
15420         alc663_m51va_speaker_automute(codec);
15421         alc662_eeepc_mic_automute(codec);
15422 }
15423 /* ***************** Mode2 ******************************/
15424 static void alc662_mode2_unsol_event(struct hda_codec *codec,
15425                                            unsigned int res)
15426 {
15427         switch (res >> 26) {
15428         case ALC880_HP_EVENT:
15429                 alc662_f5z_speaker_automute(codec);
15430                 break;
15431         case ALC880_MIC_EVENT:
15432                 alc662_eeepc_mic_automute(codec);
15433                 break;
15434         }
15435 }
15436
15437 static void alc662_mode2_inithook(struct hda_codec *codec)
15438 {
15439         alc662_f5z_speaker_automute(codec);
15440         alc662_eeepc_mic_automute(codec);
15441 }
15442 /* ***************** Mode3 ******************************/
15443 static void alc663_mode3_unsol_event(struct hda_codec *codec,
15444                                            unsigned int res)
15445 {
15446         switch (res >> 26) {
15447         case ALC880_HP_EVENT:
15448                 alc663_two_hp_m1_speaker_automute(codec);
15449                 break;
15450         case ALC880_MIC_EVENT:
15451                 alc662_eeepc_mic_automute(codec);
15452                 break;
15453         }
15454 }
15455
15456 static void alc663_mode3_inithook(struct hda_codec *codec)
15457 {
15458         alc663_two_hp_m1_speaker_automute(codec);
15459         alc662_eeepc_mic_automute(codec);
15460 }
15461 /* ***************** Mode4 ******************************/
15462 static void alc663_mode4_unsol_event(struct hda_codec *codec,
15463                                            unsigned int res)
15464 {
15465         switch (res >> 26) {
15466         case ALC880_HP_EVENT:
15467                 alc663_21jd_two_speaker_automute(codec);
15468                 break;
15469         case ALC880_MIC_EVENT:
15470                 alc662_eeepc_mic_automute(codec);
15471                 break;
15472         }
15473 }
15474
15475 static void alc663_mode4_inithook(struct hda_codec *codec)
15476 {
15477         alc663_21jd_two_speaker_automute(codec);
15478         alc662_eeepc_mic_automute(codec);
15479 }
15480 /* ***************** Mode5 ******************************/
15481 static void alc663_mode5_unsol_event(struct hda_codec *codec,
15482                                            unsigned int res)
15483 {
15484         switch (res >> 26) {
15485         case ALC880_HP_EVENT:
15486                 alc663_15jd_two_speaker_automute(codec);
15487                 break;
15488         case ALC880_MIC_EVENT:
15489                 alc662_eeepc_mic_automute(codec);
15490                 break;
15491         }
15492 }
15493
15494 static void alc663_mode5_inithook(struct hda_codec *codec)
15495 {
15496         alc663_15jd_two_speaker_automute(codec);
15497         alc662_eeepc_mic_automute(codec);
15498 }
15499 /* ***************** Mode6 ******************************/
15500 static void alc663_mode6_unsol_event(struct hda_codec *codec,
15501                                            unsigned int res)
15502 {
15503         switch (res >> 26) {
15504         case ALC880_HP_EVENT:
15505                 alc663_two_hp_m2_speaker_automute(codec);
15506                 break;
15507         case ALC880_MIC_EVENT:
15508                 alc662_eeepc_mic_automute(codec);
15509                 break;
15510         }
15511 }
15512
15513 static void alc663_mode6_inithook(struct hda_codec *codec)
15514 {
15515         alc663_two_hp_m2_speaker_automute(codec);
15516         alc662_eeepc_mic_automute(codec);
15517 }
15518
15519 static void alc663_g71v_hp_automute(struct hda_codec *codec)
15520 {
15521         unsigned int present;
15522         unsigned char bits;
15523
15524         present = snd_hda_codec_read(codec, 0x21, 0,
15525                                      AC_VERB_GET_PIN_SENSE, 0)
15526                 & AC_PINSENSE_PRESENCE;
15527         bits = present ? HDA_AMP_MUTE : 0;
15528         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15529                                  HDA_AMP_MUTE, bits);
15530         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15531                                  HDA_AMP_MUTE, bits);
15532 }
15533
15534 static void alc663_g71v_front_automute(struct hda_codec *codec)
15535 {
15536         unsigned int present;
15537         unsigned char bits;
15538
15539         present = snd_hda_codec_read(codec, 0x15, 0,
15540                                      AC_VERB_GET_PIN_SENSE, 0)
15541                 & AC_PINSENSE_PRESENCE;
15542         bits = present ? HDA_AMP_MUTE : 0;
15543         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15544                                  HDA_AMP_MUTE, bits);
15545 }
15546
15547 static void alc663_g71v_unsol_event(struct hda_codec *codec,
15548                                            unsigned int res)
15549 {
15550         switch (res >> 26) {
15551         case ALC880_HP_EVENT:
15552                 alc663_g71v_hp_automute(codec);
15553                 break;
15554         case ALC880_FRONT_EVENT:
15555                 alc663_g71v_front_automute(codec);
15556                 break;
15557         case ALC880_MIC_EVENT:
15558                 alc662_eeepc_mic_automute(codec);
15559                 break;
15560         }
15561 }
15562
15563 static void alc663_g71v_inithook(struct hda_codec *codec)
15564 {
15565         alc663_g71v_front_automute(codec);
15566         alc663_g71v_hp_automute(codec);
15567         alc662_eeepc_mic_automute(codec);
15568 }
15569
15570 static void alc663_g50v_unsol_event(struct hda_codec *codec,
15571                                            unsigned int res)
15572 {
15573         switch (res >> 26) {
15574         case ALC880_HP_EVENT:
15575                 alc663_m51va_speaker_automute(codec);
15576                 break;
15577         case ALC880_MIC_EVENT:
15578                 alc662_eeepc_mic_automute(codec);
15579                 break;
15580         }
15581 }
15582
15583 static void alc663_g50v_inithook(struct hda_codec *codec)
15584 {
15585         alc663_m51va_speaker_automute(codec);
15586         alc662_eeepc_mic_automute(codec);
15587 }
15588
15589 /* bind hp and internal speaker mute (with plug check) */
15590 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15591                                      struct snd_ctl_elem_value *ucontrol)
15592 {
15593         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15594         long *valp = ucontrol->value.integer.value;
15595         int change;
15596
15597         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15598                                           HDA_AMP_MUTE,
15599                                           valp[0] ? 0 : HDA_AMP_MUTE);
15600         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15601                                            HDA_AMP_MUTE,
15602                                            valp[1] ? 0 : HDA_AMP_MUTE);
15603         if (change)
15604                 alc262_hippo1_automute(codec);
15605         return change;
15606 }
15607
15608 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
15609         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15610         {
15611                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15612                 .name = "Master Playback Switch",
15613                 .info = snd_hda_mixer_amp_switch_info,
15614                 .get = snd_hda_mixer_amp_switch_get,
15615                 .put = alc662_ecs_master_sw_put,
15616                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15617         },
15618
15619         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
15620         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
15621         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
15622
15623         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15624         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15625         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15626         { } /* end */
15627 };
15628
15629 #ifdef CONFIG_SND_HDA_POWER_SAVE
15630 #define alc662_loopbacks        alc880_loopbacks
15631 #endif
15632
15633
15634 /* pcm configuration: identiacal with ALC880 */
15635 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
15636 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
15637 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
15638 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
15639
15640 /*
15641  * configuration and preset
15642  */
15643 static const char *alc662_models[ALC662_MODEL_LAST] = {
15644         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
15645         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
15646         [ALC662_3ST_6ch]        = "3stack-6ch",
15647         [ALC662_5ST_DIG]        = "6stack-dig",
15648         [ALC662_LENOVO_101E]    = "lenovo-101e",
15649         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
15650         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
15651         [ALC662_ECS] = "ecs",
15652         [ALC663_ASUS_M51VA] = "m51va",
15653         [ALC663_ASUS_G71V] = "g71v",
15654         [ALC663_ASUS_H13] = "h13",
15655         [ALC663_ASUS_G50V] = "g50v",
15656         [ALC663_ASUS_MODE1] = "asus-mode1",
15657         [ALC662_ASUS_MODE2] = "asus-mode2",
15658         [ALC663_ASUS_MODE3] = "asus-mode3",
15659         [ALC663_ASUS_MODE4] = "asus-mode4",
15660         [ALC663_ASUS_MODE5] = "asus-mode5",
15661         [ALC663_ASUS_MODE6] = "asus-mode6",
15662         [ALC662_AUTO]           = "auto",
15663 };
15664
15665 static struct snd_pci_quirk alc662_cfg_tbl[] = {
15666         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
15667         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS M51VA", ALC663_ASUS_G50V),
15668         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
15669         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
15670         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
15671         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
15672         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
15673         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
15674         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
15675         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
15676         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
15677         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
15678         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
15679         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
15680         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
15681         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
15682         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
15683         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
15684         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
15685         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
15686         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
15687         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
15688         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
15689         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
15690         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
15691         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
15692         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
15693         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
15694         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
15695         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
15696         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
15697         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
15698         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
15699         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
15700         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
15701         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
15702         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
15703         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
15704         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
15705         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
15706         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
15707         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
15708         {}
15709 };
15710
15711 static struct alc_config_preset alc662_presets[] = {
15712         [ALC662_3ST_2ch_DIG] = {
15713                 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer },
15714                 .init_verbs = { alc662_init_verbs },
15715                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15716                 .dac_nids = alc662_dac_nids,
15717                 .dig_out_nid = ALC662_DIGOUT_NID,
15718                 .dig_in_nid = ALC662_DIGIN_NID,
15719                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15720                 .channel_mode = alc662_3ST_2ch_modes,
15721                 .input_mux = &alc662_capture_source,
15722         },
15723         [ALC662_3ST_6ch_DIG] = {
15724                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
15725                             alc662_capture_mixer },
15726                 .init_verbs = { alc662_init_verbs },
15727                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15728                 .dac_nids = alc662_dac_nids,
15729                 .dig_out_nid = ALC662_DIGOUT_NID,
15730                 .dig_in_nid = ALC662_DIGIN_NID,
15731                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15732                 .channel_mode = alc662_3ST_6ch_modes,
15733                 .need_dac_fix = 1,
15734                 .input_mux = &alc662_capture_source,
15735         },
15736         [ALC662_3ST_6ch] = {
15737                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
15738                             alc662_capture_mixer },
15739                 .init_verbs = { alc662_init_verbs },
15740                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15741                 .dac_nids = alc662_dac_nids,
15742                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15743                 .channel_mode = alc662_3ST_6ch_modes,
15744                 .need_dac_fix = 1,
15745                 .input_mux = &alc662_capture_source,
15746         },
15747         [ALC662_5ST_DIG] = {
15748                 .mixers = { alc662_base_mixer, alc662_chmode_mixer,
15749                             alc662_capture_mixer },
15750                 .init_verbs = { alc662_init_verbs },
15751                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15752                 .dac_nids = alc662_dac_nids,
15753                 .dig_out_nid = ALC662_DIGOUT_NID,
15754                 .dig_in_nid = ALC662_DIGIN_NID,
15755                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
15756                 .channel_mode = alc662_5stack_modes,
15757                 .input_mux = &alc662_capture_source,
15758         },
15759         [ALC662_LENOVO_101E] = {
15760                 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer },
15761                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
15762                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15763                 .dac_nids = alc662_dac_nids,
15764                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15765                 .channel_mode = alc662_3ST_2ch_modes,
15766                 .input_mux = &alc662_lenovo_101e_capture_source,
15767                 .unsol_event = alc662_lenovo_101e_unsol_event,
15768                 .init_hook = alc662_lenovo_101e_all_automute,
15769         },
15770         [ALC662_ASUS_EEEPC_P701] = {
15771                 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer },
15772                 .init_verbs = { alc662_init_verbs,
15773                                 alc662_eeepc_sue_init_verbs },
15774                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15775                 .dac_nids = alc662_dac_nids,
15776                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15777                 .channel_mode = alc662_3ST_2ch_modes,
15778                 .input_mux = &alc662_eeepc_capture_source,
15779                 .unsol_event = alc662_eeepc_unsol_event,
15780                 .init_hook = alc662_eeepc_inithook,
15781         },
15782         [ALC662_ASUS_EEEPC_EP20] = {
15783                 .mixers = { alc662_eeepc_ep20_mixer, alc662_capture_mixer,
15784                             alc662_chmode_mixer },
15785                 .init_verbs = { alc662_init_verbs,
15786                                 alc662_eeepc_ep20_sue_init_verbs },
15787                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15788                 .dac_nids = alc662_dac_nids,
15789                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15790                 .channel_mode = alc662_3ST_6ch_modes,
15791                 .input_mux = &alc662_lenovo_101e_capture_source,
15792                 .unsol_event = alc662_eeepc_ep20_unsol_event,
15793                 .init_hook = alc662_eeepc_ep20_inithook,
15794         },
15795         [ALC662_ECS] = {
15796                 .mixers = { alc662_ecs_mixer, alc662_capture_mixer },
15797                 .init_verbs = { alc662_init_verbs,
15798                                 alc662_ecs_init_verbs },
15799                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15800                 .dac_nids = alc662_dac_nids,
15801                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15802                 .channel_mode = alc662_3ST_2ch_modes,
15803                 .input_mux = &alc662_eeepc_capture_source,
15804                 .unsol_event = alc662_eeepc_unsol_event,
15805                 .init_hook = alc662_eeepc_inithook,
15806         },
15807         [ALC663_ASUS_M51VA] = {
15808                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
15809                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
15810                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15811                 .dac_nids = alc662_dac_nids,
15812                 .dig_out_nid = ALC662_DIGOUT_NID,
15813                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15814                 .channel_mode = alc662_3ST_2ch_modes,
15815                 .input_mux = &alc663_m51va_capture_source,
15816                 .unsol_event = alc663_m51va_unsol_event,
15817                 .init_hook = alc663_m51va_inithook,
15818         },
15819         [ALC663_ASUS_G71V] = {
15820                 .mixers = { alc663_g71v_mixer, alc662_capture_mixer},
15821                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
15822                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15823                 .dac_nids = alc662_dac_nids,
15824                 .dig_out_nid = ALC662_DIGOUT_NID,
15825                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15826                 .channel_mode = alc662_3ST_2ch_modes,
15827                 .input_mux = &alc662_eeepc_capture_source,
15828                 .unsol_event = alc663_g71v_unsol_event,
15829                 .init_hook = alc663_g71v_inithook,
15830         },
15831         [ALC663_ASUS_H13] = {
15832                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
15833                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
15834                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15835                 .dac_nids = alc662_dac_nids,
15836                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15837                 .channel_mode = alc662_3ST_2ch_modes,
15838                 .input_mux = &alc663_m51va_capture_source,
15839                 .unsol_event = alc663_m51va_unsol_event,
15840                 .init_hook = alc663_m51va_inithook,
15841         },
15842         [ALC663_ASUS_G50V] = {
15843                 .mixers = { alc663_g50v_mixer, alc662_capture_mixer},
15844                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
15845                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15846                 .dac_nids = alc662_dac_nids,
15847                 .dig_out_nid = ALC662_DIGOUT_NID,
15848                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15849                 .channel_mode = alc662_3ST_6ch_modes,
15850                 .input_mux = &alc663_capture_source,
15851                 .unsol_event = alc663_g50v_unsol_event,
15852                 .init_hook = alc663_g50v_inithook,
15853         },
15854         [ALC663_ASUS_MODE1] = {
15855                 .mixers = { alc663_m51va_mixer, alc662_auto_capture_mixer },
15856                 .init_verbs = { alc662_init_verbs,
15857                                 alc663_21jd_amic_init_verbs },
15858                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15859                 .hp_nid = 0x03,
15860                 .dac_nids = alc662_dac_nids,
15861                 .dig_out_nid = ALC662_DIGOUT_NID,
15862                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15863                 .channel_mode = alc662_3ST_2ch_modes,
15864                 .input_mux = &alc662_eeepc_capture_source,
15865                 .unsol_event = alc663_mode1_unsol_event,
15866                 .init_hook = alc663_mode1_inithook,
15867         },
15868         [ALC662_ASUS_MODE2] = {
15869                 .mixers = { alc662_1bjd_mixer, alc662_auto_capture_mixer },
15870                 .init_verbs = { alc662_init_verbs,
15871                                 alc662_1bjd_amic_init_verbs },
15872                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15873                 .dac_nids = alc662_dac_nids,
15874                 .dig_out_nid = ALC662_DIGOUT_NID,
15875                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15876                 .channel_mode = alc662_3ST_2ch_modes,
15877                 .input_mux = &alc662_eeepc_capture_source,
15878                 .unsol_event = alc662_mode2_unsol_event,
15879                 .init_hook = alc662_mode2_inithook,
15880         },
15881         [ALC663_ASUS_MODE3] = {
15882                 .mixers = { alc663_two_hp_m1_mixer, alc662_auto_capture_mixer },
15883                 .init_verbs = { alc662_init_verbs,
15884                                 alc663_two_hp_amic_m1_init_verbs },
15885                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15886                 .hp_nid = 0x03,
15887                 .dac_nids = alc662_dac_nids,
15888                 .dig_out_nid = ALC662_DIGOUT_NID,
15889                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15890                 .channel_mode = alc662_3ST_2ch_modes,
15891                 .input_mux = &alc662_eeepc_capture_source,
15892                 .unsol_event = alc663_mode3_unsol_event,
15893                 .init_hook = alc663_mode3_inithook,
15894         },
15895         [ALC663_ASUS_MODE4] = {
15896                 .mixers = { alc663_asus_21jd_clfe_mixer,
15897                                 alc662_auto_capture_mixer},
15898                 .init_verbs = { alc662_init_verbs,
15899                                 alc663_21jd_amic_init_verbs},
15900                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15901                 .hp_nid = 0x03,
15902                 .dac_nids = alc662_dac_nids,
15903                 .dig_out_nid = ALC662_DIGOUT_NID,
15904                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15905                 .channel_mode = alc662_3ST_2ch_modes,
15906                 .input_mux = &alc662_eeepc_capture_source,
15907                 .unsol_event = alc663_mode4_unsol_event,
15908                 .init_hook = alc663_mode4_inithook,
15909         },
15910         [ALC663_ASUS_MODE5] = {
15911                 .mixers = { alc663_asus_15jd_clfe_mixer,
15912                                 alc662_auto_capture_mixer },
15913                 .init_verbs = { alc662_init_verbs,
15914                                 alc663_15jd_amic_init_verbs },
15915                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15916                 .hp_nid = 0x03,
15917                 .dac_nids = alc662_dac_nids,
15918                 .dig_out_nid = ALC662_DIGOUT_NID,
15919                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15920                 .channel_mode = alc662_3ST_2ch_modes,
15921                 .input_mux = &alc662_eeepc_capture_source,
15922                 .unsol_event = alc663_mode5_unsol_event,
15923                 .init_hook = alc663_mode5_inithook,
15924         },
15925         [ALC663_ASUS_MODE6] = {
15926                 .mixers = { alc663_two_hp_m2_mixer, alc662_auto_capture_mixer },
15927                 .init_verbs = { alc662_init_verbs,
15928                                 alc663_two_hp_amic_m2_init_verbs },
15929                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15930                 .hp_nid = 0x03,
15931                 .dac_nids = alc662_dac_nids,
15932                 .dig_out_nid = ALC662_DIGOUT_NID,
15933                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15934                 .channel_mode = alc662_3ST_2ch_modes,
15935                 .input_mux = &alc662_eeepc_capture_source,
15936                 .unsol_event = alc663_mode6_unsol_event,
15937                 .init_hook = alc663_mode6_inithook,
15938         },
15939 };
15940
15941
15942 /*
15943  * BIOS auto configuration
15944  */
15945
15946 /* add playback controls from the parsed DAC table */
15947 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
15948                                              const struct auto_pin_cfg *cfg)
15949 {
15950         char name[32];
15951         static const char *chname[4] = {
15952                 "Front", "Surround", NULL /*CLFE*/, "Side"
15953         };
15954         hda_nid_t nid;
15955         int i, err;
15956
15957         for (i = 0; i < cfg->line_outs; i++) {
15958                 if (!spec->multiout.dac_nids[i])
15959                         continue;
15960                 nid = alc880_idx_to_dac(i);
15961                 if (i == 2) {
15962                         /* Center/LFE */
15963                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
15964                                           "Center Playback Volume",
15965                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
15966                                                               HDA_OUTPUT));
15967                         if (err < 0)
15968                                 return err;
15969                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
15970                                           "LFE Playback Volume",
15971                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
15972                                                               HDA_OUTPUT));
15973                         if (err < 0)
15974                                 return err;
15975                         err = add_control(spec, ALC_CTL_BIND_MUTE,
15976                                           "Center Playback Switch",
15977                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
15978                                                               HDA_INPUT));
15979                         if (err < 0)
15980                                 return err;
15981                         err = add_control(spec, ALC_CTL_BIND_MUTE,
15982                                           "LFE Playback Switch",
15983                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
15984                                                               HDA_INPUT));
15985                         if (err < 0)
15986                                 return err;
15987                 } else {
15988                         sprintf(name, "%s Playback Volume", chname[i]);
15989                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15990                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
15991                                                               HDA_OUTPUT));
15992                         if (err < 0)
15993                                 return err;
15994                         sprintf(name, "%s Playback Switch", chname[i]);
15995                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15996                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
15997                                                               HDA_INPUT));
15998                         if (err < 0)
15999                                 return err;
16000                 }
16001         }
16002         return 0;
16003 }
16004
16005 /* add playback controls for speaker and HP outputs */
16006 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16007                                         const char *pfx)
16008 {
16009         hda_nid_t nid;
16010         int err;
16011         char name[32];
16012
16013         if (!pin)
16014                 return 0;
16015
16016         if (pin == 0x17) {
16017                 /* ALC663 has a mono output pin on 0x17 */
16018                 sprintf(name, "%s Playback Switch", pfx);
16019                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16020                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16021                 return err;
16022         }
16023
16024         if (alc880_is_fixed_pin(pin)) {
16025                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16026                 /* printk("DAC nid=%x\n",nid); */
16027                 /* specify the DAC as the extra output */
16028                 if (!spec->multiout.hp_nid)
16029                         spec->multiout.hp_nid = nid;
16030                 else
16031                         spec->multiout.extra_out_nid[0] = nid;
16032                 /* control HP volume/switch on the output mixer amp */
16033                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16034                 sprintf(name, "%s Playback Volume", pfx);
16035                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16036                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16037                 if (err < 0)
16038                         return err;
16039                 sprintf(name, "%s Playback Switch", pfx);
16040                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16041                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16042                 if (err < 0)
16043                         return err;
16044         } else if (alc880_is_multi_pin(pin)) {
16045                 /* set manual connection */
16046                 /* we have only a switch on HP-out PIN */
16047                 sprintf(name, "%s Playback Switch", pfx);
16048                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16049                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16050                 if (err < 0)
16051                         return err;
16052         }
16053         return 0;
16054 }
16055
16056 /* create playback/capture controls for input pins */
16057 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
16058                                                 const struct auto_pin_cfg *cfg)
16059 {
16060         struct hda_input_mux *imux = &spec->private_imux;
16061         int i, err, idx;
16062
16063         for (i = 0; i < AUTO_PIN_LAST; i++) {
16064                 if (alc880_is_input_pin(cfg->input_pins[i])) {
16065                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
16066                         err = new_analog_input(spec, cfg->input_pins[i],
16067                                                auto_pin_cfg_labels[i],
16068                                                idx, 0x0b);
16069                         if (err < 0)
16070                                 return err;
16071                         imux->items[imux->num_items].label =
16072                                 auto_pin_cfg_labels[i];
16073                         imux->items[imux->num_items].index =
16074                                 alc880_input_pin_idx(cfg->input_pins[i]);
16075                         imux->num_items++;
16076                 }
16077         }
16078         return 0;
16079 }
16080
16081 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16082                                               hda_nid_t nid, int pin_type,
16083                                               int dac_idx)
16084 {
16085         alc_set_pin_output(codec, nid, pin_type);
16086         /* need the manual connection? */
16087         if (alc880_is_multi_pin(nid)) {
16088                 struct alc_spec *spec = codec->spec;
16089                 int idx = alc880_multi_pin_idx(nid);
16090                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16091                                     AC_VERB_SET_CONNECT_SEL,
16092                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16093         }
16094 }
16095
16096 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16097 {
16098         struct alc_spec *spec = codec->spec;
16099         int i;
16100
16101         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16102         for (i = 0; i <= HDA_SIDE; i++) {
16103                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16104                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16105                 if (nid)
16106                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16107                                                           i);
16108         }
16109 }
16110
16111 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16112 {
16113         struct alc_spec *spec = codec->spec;
16114         hda_nid_t pin;
16115
16116         pin = spec->autocfg.hp_pins[0];
16117         if (pin) /* connect to front */
16118                 /* use dac 0 */
16119                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16120         pin = spec->autocfg.speaker_pins[0];
16121         if (pin)
16122                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16123 }
16124
16125 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
16126 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16127
16128 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16129 {
16130         struct alc_spec *spec = codec->spec;
16131         int i;
16132
16133         for (i = 0; i < AUTO_PIN_LAST; i++) {
16134                 hda_nid_t nid = spec->autocfg.input_pins[i];
16135                 if (alc662_is_input_pin(nid)) {
16136                         snd_hda_codec_write(codec, nid, 0,
16137                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
16138                                             (i <= AUTO_PIN_FRONT_MIC ?
16139                                              PIN_VREF80 : PIN_IN));
16140                         if (nid != ALC662_PIN_CD_NID)
16141                                 snd_hda_codec_write(codec, nid, 0,
16142                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16143                                                     AMP_OUT_MUTE);
16144                 }
16145         }
16146 }
16147
16148 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16149
16150 static int alc662_parse_auto_config(struct hda_codec *codec)
16151 {
16152         struct alc_spec *spec = codec->spec;
16153         int err;
16154         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16155
16156         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16157                                            alc662_ignore);
16158         if (err < 0)
16159                 return err;
16160         if (!spec->autocfg.line_outs)
16161                 return 0; /* can't find valid BIOS pin config */
16162
16163         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16164         if (err < 0)
16165                 return err;
16166         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16167         if (err < 0)
16168                 return err;
16169         err = alc662_auto_create_extra_out(spec,
16170                                            spec->autocfg.speaker_pins[0],
16171                                            "Speaker");
16172         if (err < 0)
16173                 return err;
16174         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
16175                                            "Headphone");
16176         if (err < 0)
16177                 return err;
16178         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
16179         if (err < 0)
16180                 return err;
16181
16182         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16183
16184         if (spec->autocfg.dig_out_pin)
16185                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16186
16187         if (spec->kctl_alloc)
16188                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
16189
16190         spec->num_mux_defs = 1;
16191         spec->input_mux = &spec->private_imux;
16192
16193         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
16194         if (codec->vendor_id == 0x10ec0663)
16195                 spec->init_verbs[spec->num_init_verbs++] =
16196                         alc663_auto_init_verbs;
16197
16198         err = alc_auto_add_mic_boost(codec);
16199         if (err < 0)
16200                 return err;
16201
16202         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
16203         spec->num_mixers++;
16204         return 1;
16205 }
16206
16207 /* additional initialization for auto-configuration model */
16208 static void alc662_auto_init(struct hda_codec *codec)
16209 {
16210         struct alc_spec *spec = codec->spec;
16211         alc662_auto_init_multi_out(codec);
16212         alc662_auto_init_hp_out(codec);
16213         alc662_auto_init_analog_input(codec);
16214         alc662_auto_init_input_src(codec);
16215         if (spec->unsol_event)
16216                 alc_sku_automute(codec);
16217 }
16218
16219 static int patch_alc662(struct hda_codec *codec)
16220 {
16221         struct alc_spec *spec;
16222         int err, board_config;
16223
16224         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16225         if (!spec)
16226                 return -ENOMEM;
16227
16228         codec->spec = spec;
16229
16230         alc_fix_pll_init(codec, 0x20, 0x04, 15);
16231
16232         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
16233                                                   alc662_models,
16234                                                   alc662_cfg_tbl);
16235         if (board_config < 0) {
16236                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
16237                        "trying auto-probe from BIOS...\n");
16238                 board_config = ALC662_AUTO;
16239         }
16240
16241         if (board_config == ALC662_AUTO) {
16242                 /* automatic parse from the BIOS config */
16243                 err = alc662_parse_auto_config(codec);
16244                 if (err < 0) {
16245                         alc_free(codec);
16246                         return err;
16247                 } else if (!err) {
16248                         printk(KERN_INFO
16249                                "hda_codec: Cannot set up configuration "
16250                                "from BIOS.  Using base mode...\n");
16251                         board_config = ALC662_3ST_2ch_DIG;
16252                 }
16253         }
16254
16255         if (board_config != ALC662_AUTO)
16256                 setup_preset(spec, &alc662_presets[board_config]);
16257
16258         if (codec->vendor_id == 0x10ec0663) {
16259                 spec->stream_name_analog = "ALC663 Analog";
16260                 spec->stream_name_digital = "ALC663 Digital";
16261         } else {
16262                 spec->stream_name_analog = "ALC662 Analog";
16263                 spec->stream_name_digital = "ALC662 Digital";
16264         }
16265
16266         spec->stream_analog_playback = &alc662_pcm_analog_playback;
16267         spec->stream_analog_capture = &alc662_pcm_analog_capture;
16268
16269         spec->stream_digital_playback = &alc662_pcm_digital_playback;
16270         spec->stream_digital_capture = &alc662_pcm_digital_capture;
16271
16272         spec->adc_nids = alc662_adc_nids;
16273         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16274         spec->capsrc_nids = alc662_capsrc_nids;
16275
16276         spec->vmaster_nid = 0x02;
16277
16278         codec->patch_ops = alc_patch_ops;
16279         if (board_config == ALC662_AUTO)
16280                 spec->init_hook = alc662_auto_init;
16281 #ifdef CONFIG_SND_HDA_POWER_SAVE
16282         if (!spec->loopback.amplist)
16283                 spec->loopback.amplist = alc662_loopbacks;
16284 #endif
16285
16286         return 0;
16287 }
16288
16289 /*
16290  * patch entries
16291  */
16292 struct hda_codec_preset snd_hda_preset_realtek[] = {
16293         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16294         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16295         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
16296         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
16297         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
16298         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
16299           .patch = patch_alc861 },
16300         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
16301         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
16302         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
16303         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
16304           .patch = patch_alc883 },
16305         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
16306           .patch = patch_alc662 },
16307         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
16308         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
16309         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
16310         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16311         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
16312           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16313         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
16314         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
16315         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16316         {} /* terminator */
16317 };