ALSA: hda/realtek: Remove extra .capsrc_nids initialization for ALC889_INTEL
[sfrench/cifs-2.6.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_beep.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         ALC260_FAVORIT100,
82 #ifdef CONFIG_SND_DEBUG
83         ALC260_TEST,
84 #endif
85         ALC260_AUTO,
86         ALC260_MODEL_LAST /* last tag */
87 };
88
89 /* ALC262 models */
90 enum {
91         ALC262_BASIC,
92         ALC262_HIPPO,
93         ALC262_HIPPO_1,
94         ALC262_FUJITSU,
95         ALC262_HP_BPC,
96         ALC262_HP_BPC_D7000_WL,
97         ALC262_HP_BPC_D7000_WF,
98         ALC262_HP_TC_T5735,
99         ALC262_HP_RP5700,
100         ALC262_BENQ_ED8,
101         ALC262_SONY_ASSAMD,
102         ALC262_BENQ_T31,
103         ALC262_ULTRA,
104         ALC262_LENOVO_3000,
105         ALC262_NEC,
106         ALC262_TOSHIBA_S06,
107         ALC262_TOSHIBA_RX1,
108         ALC262_TYAN,
109         ALC262_AUTO,
110         ALC262_MODEL_LAST /* last tag */
111 };
112
113 /* ALC268 models */
114 enum {
115         ALC267_QUANTA_IL1,
116         ALC268_3ST,
117         ALC268_TOSHIBA,
118         ALC268_ACER,
119         ALC268_ACER_DMIC,
120         ALC268_ACER_ASPIRE_ONE,
121         ALC268_DELL,
122         ALC268_ZEPTO,
123 #ifdef CONFIG_SND_DEBUG
124         ALC268_TEST,
125 #endif
126         ALC268_AUTO,
127         ALC268_MODEL_LAST /* last tag */
128 };
129
130 /* ALC269 models */
131 enum {
132         ALC269_BASIC,
133         ALC269_QUANTA_FL1,
134         ALC269_ASUS_AMIC,
135         ALC269_ASUS_DMIC,
136         ALC269_FUJITSU,
137         ALC269_LIFEBOOK,
138         ALC269_AUTO,
139         ALC269_MODEL_LAST /* last tag */
140 };
141
142 /* ALC861 models */
143 enum {
144         ALC861_3ST,
145         ALC660_3ST,
146         ALC861_3ST_DIG,
147         ALC861_6ST_DIG,
148         ALC861_UNIWILL_M31,
149         ALC861_TOSHIBA,
150         ALC861_ASUS,
151         ALC861_ASUS_LAPTOP,
152         ALC861_AUTO,
153         ALC861_MODEL_LAST,
154 };
155
156 /* ALC861-VD models */
157 enum {
158         ALC660VD_3ST,
159         ALC660VD_3ST_DIG,
160         ALC660VD_ASUS_V1S,
161         ALC861VD_3ST,
162         ALC861VD_3ST_DIG,
163         ALC861VD_6ST_DIG,
164         ALC861VD_LENOVO,
165         ALC861VD_DALLAS,
166         ALC861VD_HP,
167         ALC861VD_AUTO,
168         ALC861VD_MODEL_LAST,
169 };
170
171 /* ALC662 models */
172 enum {
173         ALC662_3ST_2ch_DIG,
174         ALC662_3ST_6ch_DIG,
175         ALC662_3ST_6ch,
176         ALC662_5ST_DIG,
177         ALC662_LENOVO_101E,
178         ALC662_ASUS_EEEPC_P701,
179         ALC662_ASUS_EEEPC_EP20,
180         ALC663_ASUS_M51VA,
181         ALC663_ASUS_G71V,
182         ALC663_ASUS_H13,
183         ALC663_ASUS_G50V,
184         ALC662_ECS,
185         ALC663_ASUS_MODE1,
186         ALC662_ASUS_MODE2,
187         ALC663_ASUS_MODE3,
188         ALC663_ASUS_MODE4,
189         ALC663_ASUS_MODE5,
190         ALC663_ASUS_MODE6,
191         ALC663_ASUS_MODE7,
192         ALC663_ASUS_MODE8,
193         ALC272_DELL,
194         ALC272_DELL_ZM1,
195         ALC272_SAMSUNG_NC10,
196         ALC662_AUTO,
197         ALC662_MODEL_LAST,
198 };
199
200 /* ALC882 models */
201 enum {
202         ALC882_3ST_DIG,
203         ALC882_6ST_DIG,
204         ALC882_ARIMA,
205         ALC882_W2JC,
206         ALC882_TARGA,
207         ALC882_ASUS_A7J,
208         ALC882_ASUS_A7M,
209         ALC885_MACPRO,
210         ALC885_MBP3,
211         ALC885_MB5,
212         ALC885_IMAC24,
213         ALC885_IMAC91,
214         ALC883_3ST_2ch_DIG,
215         ALC883_3ST_6ch_DIG,
216         ALC883_3ST_6ch,
217         ALC883_6ST_DIG,
218         ALC883_TARGA_DIG,
219         ALC883_TARGA_2ch_DIG,
220         ALC883_TARGA_8ch_DIG,
221         ALC883_ACER,
222         ALC883_ACER_ASPIRE,
223         ALC888_ACER_ASPIRE_4930G,
224         ALC888_ACER_ASPIRE_6530G,
225         ALC888_ACER_ASPIRE_8930G,
226         ALC888_ACER_ASPIRE_7730G,
227         ALC883_MEDION,
228         ALC883_MEDION_MD2,
229         ALC883_LAPTOP_EAPD,
230         ALC883_LENOVO_101E_2ch,
231         ALC883_LENOVO_NB0763,
232         ALC888_LENOVO_MS7195_DIG,
233         ALC888_LENOVO_SKY,
234         ALC883_HAIER_W66,
235         ALC888_3ST_HP,
236         ALC888_6ST_DELL,
237         ALC883_MITAC,
238         ALC883_CLEVO_M540R,
239         ALC883_CLEVO_M720,
240         ALC883_FUJITSU_PI2515,
241         ALC888_FUJITSU_XA3530,
242         ALC883_3ST_6ch_INTEL,
243         ALC889A_INTEL,
244         ALC889_INTEL,
245         ALC888_ASUS_M90V,
246         ALC888_ASUS_EEE1601,
247         ALC889A_MB31,
248         ALC1200_ASUS_P5Q,
249         ALC883_SONY_VAIO_TT,
250         ALC882_AUTO,
251         ALC882_MODEL_LAST,
252 };
253
254 /* for GPIO Poll */
255 #define GPIO_MASK       0x03
256
257 /* extra amp-initialization sequence types */
258 enum {
259         ALC_INIT_NONE,
260         ALC_INIT_DEFAULT,
261         ALC_INIT_GPIO1,
262         ALC_INIT_GPIO2,
263         ALC_INIT_GPIO3,
264 };
265
266 struct alc_mic_route {
267         hda_nid_t pin;
268         unsigned char mux_idx;
269         unsigned char amix_idx;
270 };
271
272 #define MUX_IDX_UNDEF   ((unsigned char)-1)
273
274 struct alc_spec {
275         /* codec parameterization */
276         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
277         unsigned int num_mixers;
278         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
279         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
280
281         const struct hda_verb *init_verbs[10];  /* initialization verbs
282                                                  * don't forget NULL
283                                                  * termination!
284                                                  */
285         unsigned int num_init_verbs;
286
287         char stream_name_analog[32];    /* analog PCM stream */
288         struct hda_pcm_stream *stream_analog_playback;
289         struct hda_pcm_stream *stream_analog_capture;
290         struct hda_pcm_stream *stream_analog_alt_playback;
291         struct hda_pcm_stream *stream_analog_alt_capture;
292
293         char stream_name_digital[32];   /* digital PCM stream */
294         struct hda_pcm_stream *stream_digital_playback;
295         struct hda_pcm_stream *stream_digital_capture;
296
297         /* playback */
298         struct hda_multi_out multiout;  /* playback set-up
299                                          * max_channels, dacs must be set
300                                          * dig_out_nid and hp_nid are optional
301                                          */
302         hda_nid_t alt_dac_nid;
303         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
304         int dig_out_type;
305
306         /* capture */
307         unsigned int num_adc_nids;
308         hda_nid_t *adc_nids;
309         hda_nid_t *capsrc_nids;
310         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
311
312         /* capture source */
313         unsigned int num_mux_defs;
314         const struct hda_input_mux *input_mux;
315         unsigned int cur_mux[3];
316         struct alc_mic_route ext_mic;
317         struct alc_mic_route int_mic;
318
319         /* channel model */
320         const struct hda_channel_mode *channel_mode;
321         int num_channel_mode;
322         int need_dac_fix;
323         int const_channel_count;
324         int ext_channel_count;
325
326         /* PCM information */
327         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
328
329         /* dynamic controls, init_verbs and input_mux */
330         struct auto_pin_cfg autocfg;
331         struct snd_array kctls;
332         struct hda_input_mux private_imux[3];
333         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
334         hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
335         hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
336
337         /* hooks */
338         void (*init_hook)(struct hda_codec *codec);
339         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
340
341         /* for pin sensing */
342         unsigned int sense_updated: 1;
343         unsigned int jack_present: 1;
344         unsigned int master_sw: 1;
345         unsigned int auto_mic:1;
346
347         /* other flags */
348         unsigned int no_analog :1; /* digital I/O only */
349         int init_amp;
350
351         /* for virtual master */
352         hda_nid_t vmaster_nid;
353 #ifdef CONFIG_SND_HDA_POWER_SAVE
354         struct hda_loopback_check loopback;
355 #endif
356
357         /* for PLL fix */
358         hda_nid_t pll_nid;
359         unsigned int pll_coef_idx, pll_coef_bit;
360 };
361
362 /*
363  * configuration template - to be copied to the spec instance
364  */
365 struct alc_config_preset {
366         struct snd_kcontrol_new *mixers[5]; /* should be identical size
367                                              * with spec
368                                              */
369         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
370         const struct hda_verb *init_verbs[5];
371         unsigned int num_dacs;
372         hda_nid_t *dac_nids;
373         hda_nid_t dig_out_nid;          /* optional */
374         hda_nid_t hp_nid;               /* optional */
375         hda_nid_t *slave_dig_outs;
376         unsigned int num_adc_nids;
377         hda_nid_t *adc_nids;
378         hda_nid_t *capsrc_nids;
379         hda_nid_t dig_in_nid;
380         unsigned int num_channel_mode;
381         const struct hda_channel_mode *channel_mode;
382         int need_dac_fix;
383         int const_channel_count;
384         unsigned int num_mux_defs;
385         const struct hda_input_mux *input_mux;
386         void (*unsol_event)(struct hda_codec *, unsigned int);
387         void (*setup)(struct hda_codec *);
388         void (*init_hook)(struct hda_codec *);
389 #ifdef CONFIG_SND_HDA_POWER_SAVE
390         struct hda_amp_list *loopbacks;
391 #endif
392 };
393
394
395 /*
396  * input MUX handling
397  */
398 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
399                              struct snd_ctl_elem_info *uinfo)
400 {
401         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
402         struct alc_spec *spec = codec->spec;
403         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
404         if (mux_idx >= spec->num_mux_defs)
405                 mux_idx = 0;
406         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
407 }
408
409 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
410                             struct snd_ctl_elem_value *ucontrol)
411 {
412         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
413         struct alc_spec *spec = codec->spec;
414         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
415
416         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
417         return 0;
418 }
419
420 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
421                             struct snd_ctl_elem_value *ucontrol)
422 {
423         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
424         struct alc_spec *spec = codec->spec;
425         const struct hda_input_mux *imux;
426         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
427         unsigned int mux_idx;
428         hda_nid_t nid = spec->capsrc_nids ?
429                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
430         unsigned int type;
431
432         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
433         imux = &spec->input_mux[mux_idx];
434
435         type = get_wcaps_type(get_wcaps(codec, nid));
436         if (type == AC_WID_AUD_MIX) {
437                 /* Matrix-mixer style (e.g. ALC882) */
438                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
439                 unsigned int i, idx;
440
441                 idx = ucontrol->value.enumerated.item[0];
442                 if (idx >= imux->num_items)
443                         idx = imux->num_items - 1;
444                 if (*cur_val == idx)
445                         return 0;
446                 for (i = 0; i < imux->num_items; i++) {
447                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
448                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
449                                                  imux->items[i].index,
450                                                  HDA_AMP_MUTE, v);
451                 }
452                 *cur_val = idx;
453                 return 1;
454         } else {
455                 /* MUX style (e.g. ALC880) */
456                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
457                                              &spec->cur_mux[adc_idx]);
458         }
459 }
460
461 /*
462  * channel mode setting
463  */
464 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
465                             struct snd_ctl_elem_info *uinfo)
466 {
467         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
468         struct alc_spec *spec = codec->spec;
469         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
470                                     spec->num_channel_mode);
471 }
472
473 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
474                            struct snd_ctl_elem_value *ucontrol)
475 {
476         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
477         struct alc_spec *spec = codec->spec;
478         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
479                                    spec->num_channel_mode,
480                                    spec->ext_channel_count);
481 }
482
483 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
484                            struct snd_ctl_elem_value *ucontrol)
485 {
486         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
487         struct alc_spec *spec = codec->spec;
488         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
489                                       spec->num_channel_mode,
490                                       &spec->ext_channel_count);
491         if (err >= 0 && !spec->const_channel_count) {
492                 spec->multiout.max_channels = spec->ext_channel_count;
493                 if (spec->need_dac_fix)
494                         spec->multiout.num_dacs = spec->multiout.max_channels / 2;
495         }
496         return err;
497 }
498
499 /*
500  * Control the mode of pin widget settings via the mixer.  "pc" is used
501  * instead of "%" to avoid consequences of accidently treating the % as
502  * being part of a format specifier.  Maximum allowed length of a value is
503  * 63 characters plus NULL terminator.
504  *
505  * Note: some retasking pin complexes seem to ignore requests for input
506  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
507  * are requested.  Therefore order this list so that this behaviour will not
508  * cause problems when mixer clients move through the enum sequentially.
509  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
510  * March 2006.
511  */
512 static char *alc_pin_mode_names[] = {
513         "Mic 50pc bias", "Mic 80pc bias",
514         "Line in", "Line out", "Headphone out",
515 };
516 static unsigned char alc_pin_mode_values[] = {
517         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
518 };
519 /* The control can present all 5 options, or it can limit the options based
520  * in the pin being assumed to be exclusively an input or an output pin.  In
521  * addition, "input" pins may or may not process the mic bias option
522  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
523  * accept requests for bias as of chip versions up to March 2006) and/or
524  * wiring in the computer.
525  */
526 #define ALC_PIN_DIR_IN              0x00
527 #define ALC_PIN_DIR_OUT             0x01
528 #define ALC_PIN_DIR_INOUT           0x02
529 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
530 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
531
532 /* Info about the pin modes supported by the different pin direction modes.
533  * For each direction the minimum and maximum values are given.
534  */
535 static signed char alc_pin_mode_dir_info[5][2] = {
536         { 0, 2 },    /* ALC_PIN_DIR_IN */
537         { 3, 4 },    /* ALC_PIN_DIR_OUT */
538         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
539         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
540         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
541 };
542 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
543 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
544 #define alc_pin_mode_n_items(_dir) \
545         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
546
547 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
548                              struct snd_ctl_elem_info *uinfo)
549 {
550         unsigned int item_num = uinfo->value.enumerated.item;
551         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
552
553         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
554         uinfo->count = 1;
555         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
556
557         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
558                 item_num = alc_pin_mode_min(dir);
559         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
560         return 0;
561 }
562
563 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
564                             struct snd_ctl_elem_value *ucontrol)
565 {
566         unsigned int i;
567         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
568         hda_nid_t nid = kcontrol->private_value & 0xffff;
569         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
570         long *valp = ucontrol->value.integer.value;
571         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
572                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
573                                                  0x00);
574
575         /* Find enumerated value for current pinctl setting */
576         i = alc_pin_mode_min(dir);
577         while (i <= alc_pin_mode_max(dir) && alc_pin_mode_values[i] != pinctl)
578                 i++;
579         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
580         return 0;
581 }
582
583 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
584                             struct snd_ctl_elem_value *ucontrol)
585 {
586         signed int change;
587         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
588         hda_nid_t nid = kcontrol->private_value & 0xffff;
589         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
590         long val = *ucontrol->value.integer.value;
591         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
592                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
593                                                  0x00);
594
595         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
596                 val = alc_pin_mode_min(dir);
597
598         change = pinctl != alc_pin_mode_values[val];
599         if (change) {
600                 /* Set pin mode to that requested */
601                 snd_hda_codec_write_cache(codec, nid, 0,
602                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
603                                           alc_pin_mode_values[val]);
604
605                 /* Also enable the retasking pin's input/output as required
606                  * for the requested pin mode.  Enum values of 2 or less are
607                  * input modes.
608                  *
609                  * Dynamically switching the input/output buffers probably
610                  * reduces noise slightly (particularly on input) so we'll
611                  * do it.  However, having both input and output buffers
612                  * enabled simultaneously doesn't seem to be problematic if
613                  * this turns out to be necessary in the future.
614                  */
615                 if (val <= 2) {
616                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
617                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
618                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
619                                                  HDA_AMP_MUTE, 0);
620                 } else {
621                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
622                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
623                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
624                                                  HDA_AMP_MUTE, 0);
625                 }
626         }
627         return change;
628 }
629
630 #define ALC_PIN_MODE(xname, nid, dir) \
631         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
632           .info = alc_pin_mode_info, \
633           .get = alc_pin_mode_get, \
634           .put = alc_pin_mode_put, \
635           .private_value = nid | (dir<<16) }
636
637 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
638  * together using a mask with more than one bit set.  This control is
639  * currently used only by the ALC260 test model.  At this stage they are not
640  * needed for any "production" models.
641  */
642 #ifdef CONFIG_SND_DEBUG
643 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
644
645 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
646                              struct snd_ctl_elem_value *ucontrol)
647 {
648         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
649         hda_nid_t nid = kcontrol->private_value & 0xffff;
650         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
651         long *valp = ucontrol->value.integer.value;
652         unsigned int val = snd_hda_codec_read(codec, nid, 0,
653                                               AC_VERB_GET_GPIO_DATA, 0x00);
654
655         *valp = (val & mask) != 0;
656         return 0;
657 }
658 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
659                              struct snd_ctl_elem_value *ucontrol)
660 {
661         signed int change;
662         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
663         hda_nid_t nid = kcontrol->private_value & 0xffff;
664         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
665         long val = *ucontrol->value.integer.value;
666         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
667                                                     AC_VERB_GET_GPIO_DATA,
668                                                     0x00);
669
670         /* Set/unset the masked GPIO bit(s) as needed */
671         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
672         if (val == 0)
673                 gpio_data &= ~mask;
674         else
675                 gpio_data |= mask;
676         snd_hda_codec_write_cache(codec, nid, 0,
677                                   AC_VERB_SET_GPIO_DATA, gpio_data);
678
679         return change;
680 }
681 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
682         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
683           .info = alc_gpio_data_info, \
684           .get = alc_gpio_data_get, \
685           .put = alc_gpio_data_put, \
686           .private_value = nid | (mask<<16) }
687 #endif   /* CONFIG_SND_DEBUG */
688
689 /* A switch control to allow the enabling of the digital IO pins on the
690  * ALC260.  This is incredibly simplistic; the intention of this control is
691  * to provide something in the test model allowing digital outputs to be
692  * identified if present.  If models are found which can utilise these
693  * outputs a more complete mixer control can be devised for those models if
694  * necessary.
695  */
696 #ifdef CONFIG_SND_DEBUG
697 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
698
699 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
700                               struct snd_ctl_elem_value *ucontrol)
701 {
702         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
703         hda_nid_t nid = kcontrol->private_value & 0xffff;
704         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
705         long *valp = ucontrol->value.integer.value;
706         unsigned int val = snd_hda_codec_read(codec, nid, 0,
707                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
708
709         *valp = (val & mask) != 0;
710         return 0;
711 }
712 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
713                               struct snd_ctl_elem_value *ucontrol)
714 {
715         signed int change;
716         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
717         hda_nid_t nid = kcontrol->private_value & 0xffff;
718         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
719         long val = *ucontrol->value.integer.value;
720         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
721                                                     AC_VERB_GET_DIGI_CONVERT_1,
722                                                     0x00);
723
724         /* Set/unset the masked control bit(s) as needed */
725         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
726         if (val==0)
727                 ctrl_data &= ~mask;
728         else
729                 ctrl_data |= mask;
730         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
731                                   ctrl_data);
732
733         return change;
734 }
735 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
736         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
737           .info = alc_spdif_ctrl_info, \
738           .get = alc_spdif_ctrl_get, \
739           .put = alc_spdif_ctrl_put, \
740           .private_value = nid | (mask<<16) }
741 #endif   /* CONFIG_SND_DEBUG */
742
743 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
744  * Again, this is only used in the ALC26x test models to help identify when
745  * the EAPD line must be asserted for features to work.
746  */
747 #ifdef CONFIG_SND_DEBUG
748 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
749
750 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
751                               struct snd_ctl_elem_value *ucontrol)
752 {
753         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
754         hda_nid_t nid = kcontrol->private_value & 0xffff;
755         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
756         long *valp = ucontrol->value.integer.value;
757         unsigned int val = snd_hda_codec_read(codec, nid, 0,
758                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
759
760         *valp = (val & mask) != 0;
761         return 0;
762 }
763
764 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
765                               struct snd_ctl_elem_value *ucontrol)
766 {
767         int change;
768         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
769         hda_nid_t nid = kcontrol->private_value & 0xffff;
770         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
771         long val = *ucontrol->value.integer.value;
772         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
773                                                     AC_VERB_GET_EAPD_BTLENABLE,
774                                                     0x00);
775
776         /* Set/unset the masked control bit(s) as needed */
777         change = (!val ? 0 : mask) != (ctrl_data & mask);
778         if (!val)
779                 ctrl_data &= ~mask;
780         else
781                 ctrl_data |= mask;
782         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
783                                   ctrl_data);
784
785         return change;
786 }
787
788 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
789         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
790           .info = alc_eapd_ctrl_info, \
791           .get = alc_eapd_ctrl_get, \
792           .put = alc_eapd_ctrl_put, \
793           .private_value = nid | (mask<<16) }
794 #endif   /* CONFIG_SND_DEBUG */
795
796 /*
797  * set up the input pin config (depending on the given auto-pin type)
798  */
799 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
800                               int auto_pin_type)
801 {
802         unsigned int val = PIN_IN;
803
804         if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
805                 unsigned int pincap;
806                 pincap = snd_hda_query_pin_caps(codec, nid);
807                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
808                 if (pincap & AC_PINCAP_VREF_80)
809                         val = PIN_VREF80;
810                 else if (pincap & AC_PINCAP_VREF_50)
811                         val = PIN_VREF50;
812                 else if (pincap & AC_PINCAP_VREF_100)
813                         val = PIN_VREF100;
814                 else if (pincap & AC_PINCAP_VREF_GRD)
815                         val = PIN_VREFGRD;
816         }
817         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
818 }
819
820 /*
821  */
822 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
823 {
824         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
825                 return;
826         spec->mixers[spec->num_mixers++] = mix;
827 }
828
829 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
830 {
831         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
832                 return;
833         spec->init_verbs[spec->num_init_verbs++] = verb;
834 }
835
836 #ifdef CONFIG_PROC_FS
837 /*
838  * hook for proc
839  */
840 static void print_realtek_coef(struct snd_info_buffer *buffer,
841                                struct hda_codec *codec, hda_nid_t nid)
842 {
843         int coeff;
844
845         if (nid != 0x20)
846                 return;
847         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
848         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
849         coeff = snd_hda_codec_read(codec, nid, 0,
850                                    AC_VERB_GET_COEF_INDEX, 0);
851         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
852 }
853 #else
854 #define print_realtek_coef      NULL
855 #endif
856
857 /*
858  * set up from the preset table
859  */
860 static void setup_preset(struct hda_codec *codec,
861                          const struct alc_config_preset *preset)
862 {
863         struct alc_spec *spec = codec->spec;
864         int i;
865
866         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
867                 add_mixer(spec, preset->mixers[i]);
868         spec->cap_mixer = preset->cap_mixer;
869         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
870              i++)
871                 add_verb(spec, preset->init_verbs[i]);
872
873         spec->channel_mode = preset->channel_mode;
874         spec->num_channel_mode = preset->num_channel_mode;
875         spec->need_dac_fix = preset->need_dac_fix;
876         spec->const_channel_count = preset->const_channel_count;
877
878         if (preset->const_channel_count)
879                 spec->multiout.max_channels = preset->const_channel_count;
880         else
881                 spec->multiout.max_channels = spec->channel_mode[0].channels;
882         spec->ext_channel_count = spec->channel_mode[0].channels;
883
884         spec->multiout.num_dacs = preset->num_dacs;
885         spec->multiout.dac_nids = preset->dac_nids;
886         spec->multiout.dig_out_nid = preset->dig_out_nid;
887         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
888         spec->multiout.hp_nid = preset->hp_nid;
889
890         spec->num_mux_defs = preset->num_mux_defs;
891         if (!spec->num_mux_defs)
892                 spec->num_mux_defs = 1;
893         spec->input_mux = preset->input_mux;
894
895         spec->num_adc_nids = preset->num_adc_nids;
896         spec->adc_nids = preset->adc_nids;
897         spec->capsrc_nids = preset->capsrc_nids;
898         spec->dig_in_nid = preset->dig_in_nid;
899
900         spec->unsol_event = preset->unsol_event;
901         spec->init_hook = preset->init_hook;
902 #ifdef CONFIG_SND_HDA_POWER_SAVE
903         spec->loopback.amplist = preset->loopbacks;
904 #endif
905
906         if (preset->setup)
907                 preset->setup(codec);
908 }
909
910 /* Enable GPIO mask and set output */
911 static struct hda_verb alc_gpio1_init_verbs[] = {
912         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
913         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
914         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
915         { }
916 };
917
918 static struct hda_verb alc_gpio2_init_verbs[] = {
919         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
920         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
921         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
922         { }
923 };
924
925 static struct hda_verb alc_gpio3_init_verbs[] = {
926         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
927         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
928         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
929         { }
930 };
931
932 /*
933  * Fix hardware PLL issue
934  * On some codecs, the analog PLL gating control must be off while
935  * the default value is 1.
936  */
937 static void alc_fix_pll(struct hda_codec *codec)
938 {
939         struct alc_spec *spec = codec->spec;
940         unsigned int val;
941
942         if (!spec->pll_nid)
943                 return;
944         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
945                             spec->pll_coef_idx);
946         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
947                                  AC_VERB_GET_PROC_COEF, 0);
948         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
949                             spec->pll_coef_idx);
950         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
951                             val & ~(1 << spec->pll_coef_bit));
952 }
953
954 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
955                              unsigned int coef_idx, unsigned int coef_bit)
956 {
957         struct alc_spec *spec = codec->spec;
958         spec->pll_nid = nid;
959         spec->pll_coef_idx = coef_idx;
960         spec->pll_coef_bit = coef_bit;
961         alc_fix_pll(codec);
962 }
963
964 static void alc_automute_pin(struct hda_codec *codec)
965 {
966         struct alc_spec *spec = codec->spec;
967         unsigned int nid = spec->autocfg.hp_pins[0];
968         int i;
969
970         if (!nid)
971                 return;
972         spec->jack_present = snd_hda_jack_detect(codec, nid);
973         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
974                 nid = spec->autocfg.speaker_pins[i];
975                 if (!nid)
976                         break;
977                 snd_hda_codec_write(codec, nid, 0,
978                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
979                                     spec->jack_present ? 0 : PIN_OUT);
980         }
981 }
982
983 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
984                                 hda_nid_t nid)
985 {
986         hda_nid_t conn[HDA_MAX_NUM_INPUTS];
987         int i, nums;
988
989         nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
990         for (i = 0; i < nums; i++)
991                 if (conn[i] == nid)
992                         return i;
993         return -1;
994 }
995
996 static void alc_mic_automute(struct hda_codec *codec)
997 {
998         struct alc_spec *spec = codec->spec;
999         struct alc_mic_route *dead, *alive;
1000         unsigned int present, type;
1001         hda_nid_t cap_nid;
1002
1003         if (!spec->auto_mic)
1004                 return;
1005         if (!spec->int_mic.pin || !spec->ext_mic.pin)
1006                 return;
1007         if (snd_BUG_ON(!spec->adc_nids))
1008                 return;
1009
1010         cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1011
1012         present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1013         if (present) {
1014                 alive = &spec->ext_mic;
1015                 dead = &spec->int_mic;
1016         } else {
1017                 alive = &spec->int_mic;
1018                 dead = &spec->ext_mic;
1019         }
1020
1021         type = get_wcaps_type(get_wcaps(codec, cap_nid));
1022         if (type == AC_WID_AUD_MIX) {
1023                 /* Matrix-mixer style (e.g. ALC882) */
1024                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1025                                          alive->mux_idx,
1026                                          HDA_AMP_MUTE, 0);
1027                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1028                                          dead->mux_idx,
1029                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
1030         } else {
1031                 /* MUX style (e.g. ALC880) */
1032                 snd_hda_codec_write_cache(codec, cap_nid, 0,
1033                                           AC_VERB_SET_CONNECT_SEL,
1034                                           alive->mux_idx);
1035         }
1036
1037         /* FIXME: analog mixer */
1038 }
1039
1040 /* unsolicited event for HP jack sensing */
1041 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
1042 {
1043         if (codec->vendor_id == 0x10ec0880)
1044                 res >>= 28;
1045         else
1046                 res >>= 26;
1047         switch (res) {
1048         case ALC880_HP_EVENT:
1049                 alc_automute_pin(codec);
1050                 break;
1051         case ALC880_MIC_EVENT:
1052                 alc_mic_automute(codec);
1053                 break;
1054         }
1055 }
1056
1057 static void alc_inithook(struct hda_codec *codec)
1058 {
1059         alc_automute_pin(codec);
1060         alc_mic_automute(codec);
1061 }
1062
1063 /* additional initialization for ALC888 variants */
1064 static void alc888_coef_init(struct hda_codec *codec)
1065 {
1066         unsigned int tmp;
1067
1068         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1069         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1070         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1071         if ((tmp & 0xf0) == 0x20)
1072                 /* alc888S-VC */
1073                 snd_hda_codec_read(codec, 0x20, 0,
1074                                    AC_VERB_SET_PROC_COEF, 0x830);
1075          else
1076                  /* alc888-VB */
1077                  snd_hda_codec_read(codec, 0x20, 0,
1078                                     AC_VERB_SET_PROC_COEF, 0x3030);
1079 }
1080
1081 static void alc889_coef_init(struct hda_codec *codec)
1082 {
1083         unsigned int tmp;
1084
1085         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1086         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1087         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1088         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1089 }
1090
1091 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1092 {
1093         unsigned int tmp;
1094
1095         switch (type) {
1096         case ALC_INIT_GPIO1:
1097                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1098                 break;
1099         case ALC_INIT_GPIO2:
1100                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1101                 break;
1102         case ALC_INIT_GPIO3:
1103                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1104                 break;
1105         case ALC_INIT_DEFAULT:
1106                 switch (codec->vendor_id) {
1107                 case 0x10ec0260:
1108                         snd_hda_codec_write(codec, 0x0f, 0,
1109                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1110                         snd_hda_codec_write(codec, 0x10, 0,
1111                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1112                         break;
1113                 case 0x10ec0262:
1114                 case 0x10ec0267:
1115                 case 0x10ec0268:
1116                 case 0x10ec0269:
1117                 case 0x10ec0272:
1118                 case 0x10ec0660:
1119                 case 0x10ec0662:
1120                 case 0x10ec0663:
1121                 case 0x10ec0862:
1122                 case 0x10ec0889:
1123                         snd_hda_codec_write(codec, 0x14, 0,
1124                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1125                         snd_hda_codec_write(codec, 0x15, 0,
1126                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1127                         break;
1128                 }
1129                 switch (codec->vendor_id) {
1130                 case 0x10ec0260:
1131                         snd_hda_codec_write(codec, 0x1a, 0,
1132                                             AC_VERB_SET_COEF_INDEX, 7);
1133                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1134                                                  AC_VERB_GET_PROC_COEF, 0);
1135                         snd_hda_codec_write(codec, 0x1a, 0,
1136                                             AC_VERB_SET_COEF_INDEX, 7);
1137                         snd_hda_codec_write(codec, 0x1a, 0,
1138                                             AC_VERB_SET_PROC_COEF,
1139                                             tmp | 0x2010);
1140                         break;
1141                 case 0x10ec0262:
1142                 case 0x10ec0880:
1143                 case 0x10ec0882:
1144                 case 0x10ec0883:
1145                 case 0x10ec0885:
1146                 case 0x10ec0887:
1147                 case 0x10ec0889:
1148                         alc889_coef_init(codec);
1149                         break;
1150                 case 0x10ec0888:
1151                         alc888_coef_init(codec);
1152                         break;
1153                 case 0x10ec0267:
1154                 case 0x10ec0268:
1155                         snd_hda_codec_write(codec, 0x20, 0,
1156                                             AC_VERB_SET_COEF_INDEX, 7);
1157                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1158                                                  AC_VERB_GET_PROC_COEF, 0);
1159                         snd_hda_codec_write(codec, 0x20, 0,
1160                                             AC_VERB_SET_COEF_INDEX, 7);
1161                         snd_hda_codec_write(codec, 0x20, 0,
1162                                             AC_VERB_SET_PROC_COEF,
1163                                             tmp | 0x3000);
1164                         break;
1165                 }
1166                 break;
1167         }
1168 }
1169
1170 static void alc_init_auto_hp(struct hda_codec *codec)
1171 {
1172         struct alc_spec *spec = codec->spec;
1173
1174         if (!spec->autocfg.hp_pins[0])
1175                 return;
1176
1177         if (!spec->autocfg.speaker_pins[0]) {
1178                 if (spec->autocfg.line_out_pins[0] &&
1179                     spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1180                         spec->autocfg.speaker_pins[0] =
1181                                 spec->autocfg.line_out_pins[0];
1182                 else
1183                         return;
1184         }
1185
1186         snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1187                     spec->autocfg.hp_pins[0]);
1188         snd_hda_codec_write_cache(codec, spec->autocfg.hp_pins[0], 0,
1189                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1190                                   AC_USRSP_EN | ALC880_HP_EVENT);
1191         spec->unsol_event = alc_sku_unsol_event;
1192 }
1193
1194 static void alc_init_auto_mic(struct hda_codec *codec)
1195 {
1196         struct alc_spec *spec = codec->spec;
1197         struct auto_pin_cfg *cfg = &spec->autocfg;
1198         hda_nid_t fixed, ext;
1199         int i;
1200
1201         /* there must be only two mic inputs exclusively */
1202         for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++)
1203                 if (cfg->input_pins[i])
1204                         return;
1205
1206         fixed = ext = 0;
1207         for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++) {
1208                 hda_nid_t nid = cfg->input_pins[i];
1209                 unsigned int defcfg;
1210                 if (!nid)
1211                         return;
1212                 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1213                 switch (get_defcfg_connect(defcfg)) {
1214                 case AC_JACK_PORT_FIXED:
1215                         if (fixed)
1216                                 return; /* already occupied */
1217                         fixed = nid;
1218                         break;
1219                 case AC_JACK_PORT_COMPLEX:
1220                         if (ext)
1221                                 return; /* already occupied */
1222                         ext = nid;
1223                         break;
1224                 default:
1225                         return; /* invalid entry */
1226                 }
1227         }
1228         if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
1229                 return; /* no unsol support */
1230         snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x\n",
1231                     ext, fixed);
1232         spec->ext_mic.pin = ext;
1233         spec->int_mic.pin = fixed;
1234         spec->ext_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1235         spec->int_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1236         spec->auto_mic = 1;
1237         snd_hda_codec_write_cache(codec, spec->ext_mic.pin, 0,
1238                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1239                                   AC_USRSP_EN | ALC880_MIC_EVENT);
1240         spec->unsol_event = alc_sku_unsol_event;
1241 }
1242
1243 /* check subsystem ID and set up device-specific initialization;
1244  * return 1 if initialized, 0 if invalid SSID
1245  */
1246 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1247  *      31 ~ 16 :       Manufacture ID
1248  *      15 ~ 8  :       SKU ID
1249  *      7  ~ 0  :       Assembly ID
1250  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1251  */
1252 static int alc_subsystem_id(struct hda_codec *codec,
1253                             hda_nid_t porta, hda_nid_t porte,
1254                             hda_nid_t portd)
1255 {
1256         unsigned int ass, tmp, i;
1257         unsigned nid;
1258         struct alc_spec *spec = codec->spec;
1259
1260         ass = codec->subsystem_id & 0xffff;
1261         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1262                 goto do_sku;
1263
1264         /* invalid SSID, check the special NID pin defcfg instead */
1265         /*
1266          * 31~30        : port connectivity
1267          * 29~21        : reserve
1268          * 20           : PCBEEP input
1269          * 19~16        : Check sum (15:1)
1270          * 15~1         : Custom
1271          * 0            : override
1272         */
1273         nid = 0x1d;
1274         if (codec->vendor_id == 0x10ec0260)
1275                 nid = 0x17;
1276         ass = snd_hda_codec_get_pincfg(codec, nid);
1277         snd_printd("realtek: No valid SSID, "
1278                    "checking pincfg 0x%08x for NID 0x%x\n",
1279                    ass, nid);
1280         if (!(ass & 1) && !(ass & 0x100000))
1281                 return 0;
1282         if ((ass >> 30) != 1)   /* no physical connection */
1283                 return 0;
1284
1285         /* check sum */
1286         tmp = 0;
1287         for (i = 1; i < 16; i++) {
1288                 if ((ass >> i) & 1)
1289                         tmp++;
1290         }
1291         if (((ass >> 16) & 0xf) != tmp)
1292                 return 0;
1293 do_sku:
1294         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1295                    ass & 0xffff, codec->vendor_id);
1296         /*
1297          * 0 : override
1298          * 1 :  Swap Jack
1299          * 2 : 0 --> Desktop, 1 --> Laptop
1300          * 3~5 : External Amplifier control
1301          * 7~6 : Reserved
1302         */
1303         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1304         switch (tmp) {
1305         case 1:
1306                 spec->init_amp = ALC_INIT_GPIO1;
1307                 break;
1308         case 3:
1309                 spec->init_amp = ALC_INIT_GPIO2;
1310                 break;
1311         case 7:
1312                 spec->init_amp = ALC_INIT_GPIO3;
1313                 break;
1314         case 5:
1315                 spec->init_amp = ALC_INIT_DEFAULT;
1316                 break;
1317         }
1318
1319         /* is laptop or Desktop and enable the function "Mute internal speaker
1320          * when the external headphone out jack is plugged"
1321          */
1322         if (!(ass & 0x8000))
1323                 return 1;
1324         /*
1325          * 10~8 : Jack location
1326          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1327          * 14~13: Resvered
1328          * 15   : 1 --> enable the function "Mute internal speaker
1329          *              when the external headphone out jack is plugged"
1330          */
1331         if (!spec->autocfg.hp_pins[0]) {
1332                 hda_nid_t nid;
1333                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1334                 if (tmp == 0)
1335                         nid = porta;
1336                 else if (tmp == 1)
1337                         nid = porte;
1338                 else if (tmp == 2)
1339                         nid = portd;
1340                 else
1341                         return 1;
1342                 for (i = 0; i < spec->autocfg.line_outs; i++)
1343                         if (spec->autocfg.line_out_pins[i] == nid)
1344                                 return 1;
1345                 spec->autocfg.hp_pins[0] = nid;
1346         }
1347
1348         alc_init_auto_hp(codec);
1349         alc_init_auto_mic(codec);
1350         return 1;
1351 }
1352
1353 static void alc_ssid_check(struct hda_codec *codec,
1354                            hda_nid_t porta, hda_nid_t porte, hda_nid_t portd)
1355 {
1356         if (!alc_subsystem_id(codec, porta, porte, portd)) {
1357                 struct alc_spec *spec = codec->spec;
1358                 snd_printd("realtek: "
1359                            "Enable default setup for auto mode as fallback\n");
1360                 spec->init_amp = ALC_INIT_DEFAULT;
1361                 alc_init_auto_hp(codec);
1362                 alc_init_auto_mic(codec);
1363         }
1364 }
1365
1366 /*
1367  * Fix-up pin default configurations and add default verbs
1368  */
1369
1370 struct alc_pincfg {
1371         hda_nid_t nid;
1372         u32 val;
1373 };
1374
1375 struct alc_fixup {
1376         const struct alc_pincfg *pins;
1377         const struct hda_verb *verbs;
1378 };
1379
1380 static void alc_pick_fixup(struct hda_codec *codec,
1381                            const struct snd_pci_quirk *quirk,
1382                            const struct alc_fixup *fix)
1383 {
1384         const struct alc_pincfg *cfg;
1385
1386         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1387         if (!quirk)
1388                 return;
1389
1390         fix += quirk->value;
1391         cfg = fix->pins;
1392         if (cfg) {
1393                 for (; cfg->nid; cfg++)
1394                         snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1395         }
1396         if (fix->verbs)
1397                 add_verb(codec->spec, fix->verbs);
1398 }
1399
1400 static int alc_read_coef_idx(struct hda_codec *codec,
1401                         unsigned int coef_idx)
1402 {
1403         unsigned int val;
1404         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1405                                 coef_idx);
1406         val = snd_hda_codec_read(codec, 0x20, 0,
1407                                 AC_VERB_GET_PROC_COEF, 0);
1408         return val;
1409 }
1410
1411 /*
1412  * ALC888
1413  */
1414
1415 /*
1416  * 2ch mode
1417  */
1418 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1419 /* Mic-in jack as mic in */
1420         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1421         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1422 /* Line-in jack as Line in */
1423         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1424         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1425 /* Line-Out as Front */
1426         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1427         { } /* end */
1428 };
1429
1430 /*
1431  * 4ch mode
1432  */
1433 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1434 /* Mic-in jack as mic in */
1435         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1436         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1437 /* Line-in jack as Surround */
1438         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1439         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1440 /* Line-Out as Front */
1441         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1442         { } /* end */
1443 };
1444
1445 /*
1446  * 6ch mode
1447  */
1448 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1449 /* Mic-in jack as CLFE */
1450         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1451         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1452 /* Line-in jack as Surround */
1453         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1454         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1455 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1456         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1457         { } /* end */
1458 };
1459
1460 /*
1461  * 8ch mode
1462  */
1463 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1464 /* Mic-in jack as CLFE */
1465         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1466         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1467 /* Line-in jack as Surround */
1468         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1469         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1470 /* Line-Out as Side */
1471         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1472         { } /* end */
1473 };
1474
1475 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1476         { 2, alc888_4ST_ch2_intel_init },
1477         { 4, alc888_4ST_ch4_intel_init },
1478         { 6, alc888_4ST_ch6_intel_init },
1479         { 8, alc888_4ST_ch8_intel_init },
1480 };
1481
1482 /*
1483  * ALC888 Fujitsu Siemens Amillo xa3530
1484  */
1485
1486 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1487 /* Front Mic: set to PIN_IN (empty by default) */
1488         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1489 /* Connect Internal HP to Front */
1490         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1491         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1492         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1493 /* Connect Bass HP to Front */
1494         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1495         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1496         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1497 /* Connect Line-Out side jack (SPDIF) to Side */
1498         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1499         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1500         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1501 /* Connect Mic jack to CLFE */
1502         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1503         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1504         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1505 /* Connect Line-in jack to Surround */
1506         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1507         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1508         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1509 /* Connect HP out jack to Front */
1510         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1511         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1512         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1513 /* Enable unsolicited event for HP jack and Line-out jack */
1514         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1515         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1516         {}
1517 };
1518
1519 static void alc_automute_amp(struct hda_codec *codec)
1520 {
1521         struct alc_spec *spec = codec->spec;
1522         unsigned int mute;
1523         hda_nid_t nid;
1524         int i;
1525
1526         spec->jack_present = 0;
1527         for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
1528                 nid = spec->autocfg.hp_pins[i];
1529                 if (!nid)
1530                         break;
1531                 if (snd_hda_jack_detect(codec, nid)) {
1532                         spec->jack_present = 1;
1533                         break;
1534                 }
1535         }
1536
1537         mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1538         /* Toggle internal speakers muting */
1539         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
1540                 nid = spec->autocfg.speaker_pins[i];
1541                 if (!nid)
1542                         break;
1543                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1544                                          HDA_AMP_MUTE, mute);
1545         }
1546 }
1547
1548 static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1549                                          unsigned int res)
1550 {
1551         if (codec->vendor_id == 0x10ec0880)
1552                 res >>= 28;
1553         else
1554                 res >>= 26;
1555         if (res == ALC880_HP_EVENT)
1556                 alc_automute_amp(codec);
1557 }
1558
1559 static void alc889_automute_setup(struct hda_codec *codec)
1560 {
1561         struct alc_spec *spec = codec->spec;
1562
1563         spec->autocfg.hp_pins[0] = 0x15;
1564         spec->autocfg.speaker_pins[0] = 0x14;
1565         spec->autocfg.speaker_pins[1] = 0x16;
1566         spec->autocfg.speaker_pins[2] = 0x17;
1567         spec->autocfg.speaker_pins[3] = 0x19;
1568         spec->autocfg.speaker_pins[4] = 0x1a;
1569 }
1570
1571 static void alc889_intel_init_hook(struct hda_codec *codec)
1572 {
1573         alc889_coef_init(codec);
1574         alc_automute_amp(codec);
1575 }
1576
1577 static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
1578 {
1579         struct alc_spec *spec = codec->spec;
1580
1581         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
1582         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1583         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1584         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1585 }
1586
1587 /*
1588  * ALC888 Acer Aspire 4930G model
1589  */
1590
1591 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1592 /* Front Mic: set to PIN_IN (empty by default) */
1593         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1594 /* Unselect Front Mic by default in input mixer 3 */
1595         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1596 /* Enable unsolicited event for HP jack */
1597         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1598 /* Connect Internal HP to front */
1599         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1600         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1601         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1602 /* Connect HP out to front */
1603         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1604         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1605         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1606         { }
1607 };
1608
1609 /*
1610  * ALC888 Acer Aspire 6530G model
1611  */
1612
1613 static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1614 /* Bias voltage on for external mic port */
1615         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1616 /* Front Mic: set to PIN_IN (empty by default) */
1617         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1618 /* Unselect Front Mic by default in input mixer 3 */
1619         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1620 /* Enable unsolicited event for HP jack */
1621         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1622 /* Enable speaker output */
1623         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1624         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1625 /* Enable headphone output */
1626         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1627         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1628         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1629         { }
1630 };
1631
1632 /*
1633  * ALC889 Acer Aspire 8930G model
1634  */
1635
1636 static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
1637 /* Front Mic: set to PIN_IN (empty by default) */
1638         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1639 /* Unselect Front Mic by default in input mixer 3 */
1640         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1641 /* Enable unsolicited event for HP jack */
1642         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1643 /* Connect Internal Front to Front */
1644         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1645         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1646         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1647 /* Connect Internal Rear to Rear */
1648         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1649         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1650         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
1651 /* Connect Internal CLFE to CLFE */
1652         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1653         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1654         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
1655 /* Connect HP out to Front */
1656         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1657         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1658         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1659 /* Enable all DACs */
1660 /*  DAC DISABLE/MUTE 1? */
1661 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
1662         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
1663         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1664 /*  DAC DISABLE/MUTE 2? */
1665 /*  some bit here disables the other DACs. Init=0x4900 */
1666         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
1667         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1668 /* Enable amplifiers */
1669         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1670         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1671 /* DMIC fix
1672  * This laptop has a stereo digital microphone. The mics are only 1cm apart
1673  * which makes the stereo useless. However, either the mic or the ALC889
1674  * makes the signal become a difference/sum signal instead of standard
1675  * stereo, which is annoying. So instead we flip this bit which makes the
1676  * codec replicate the sum signal to both channels, turning it into a
1677  * normal mono mic.
1678  */
1679 /*  DMIC_CONTROL? Init value = 0x0001 */
1680         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
1681         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
1682         { }
1683 };
1684
1685 static struct hda_input_mux alc888_2_capture_sources[2] = {
1686         /* Front mic only available on one ADC */
1687         {
1688                 .num_items = 4,
1689                 .items = {
1690                         { "Mic", 0x0 },
1691                         { "Line", 0x2 },
1692                         { "CD", 0x4 },
1693                         { "Front Mic", 0xb },
1694                 },
1695         },
1696         {
1697                 .num_items = 3,
1698                 .items = {
1699                         { "Mic", 0x0 },
1700                         { "Line", 0x2 },
1701                         { "CD", 0x4 },
1702                 },
1703         }
1704 };
1705
1706 static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
1707         /* Interal mic only available on one ADC */
1708         {
1709                 .num_items = 5,
1710                 .items = {
1711                         { "Ext Mic", 0x0 },
1712                         { "Line In", 0x2 },
1713                         { "CD", 0x4 },
1714                         { "Input Mix", 0xa },
1715                         { "Int Mic", 0xb },
1716                 },
1717         },
1718         {
1719                 .num_items = 4,
1720                 .items = {
1721                         { "Ext Mic", 0x0 },
1722                         { "Line In", 0x2 },
1723                         { "CD", 0x4 },
1724                         { "Input Mix", 0xa },
1725                 },
1726         }
1727 };
1728
1729 static struct hda_input_mux alc889_capture_sources[3] = {
1730         /* Digital mic only available on first "ADC" */
1731         {
1732                 .num_items = 5,
1733                 .items = {
1734                         { "Mic", 0x0 },
1735                         { "Line", 0x2 },
1736                         { "CD", 0x4 },
1737                         { "Front Mic", 0xb },
1738                         { "Input Mix", 0xa },
1739                 },
1740         },
1741         {
1742                 .num_items = 4,
1743                 .items = {
1744                         { "Mic", 0x0 },
1745                         { "Line", 0x2 },
1746                         { "CD", 0x4 },
1747                         { "Input Mix", 0xa },
1748                 },
1749         },
1750         {
1751                 .num_items = 4,
1752                 .items = {
1753                         { "Mic", 0x0 },
1754                         { "Line", 0x2 },
1755                         { "CD", 0x4 },
1756                         { "Input Mix", 0xa },
1757                 },
1758         }
1759 };
1760
1761 static struct snd_kcontrol_new alc888_base_mixer[] = {
1762         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1763         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1764         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1765         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1766         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1767                 HDA_OUTPUT),
1768         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1769         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1770         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1771         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1772         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1773         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1774         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1775         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1776         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1777         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1778         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1779         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1780         { } /* end */
1781 };
1782
1783 static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
1784 {
1785         struct alc_spec *spec = codec->spec;
1786
1787         spec->autocfg.hp_pins[0] = 0x15;
1788         spec->autocfg.speaker_pins[0] = 0x14;
1789         spec->autocfg.speaker_pins[1] = 0x16;
1790         spec->autocfg.speaker_pins[2] = 0x17;
1791 }
1792
1793 static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
1794 {
1795         struct alc_spec *spec = codec->spec;
1796
1797         spec->autocfg.hp_pins[0] = 0x15;
1798         spec->autocfg.speaker_pins[0] = 0x14;
1799         spec->autocfg.speaker_pins[1] = 0x16;
1800         spec->autocfg.speaker_pins[2] = 0x17;
1801 }
1802
1803 static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
1804 {
1805         struct alc_spec *spec = codec->spec;
1806
1807         spec->autocfg.hp_pins[0] = 0x15;
1808         spec->autocfg.speaker_pins[0] = 0x14;
1809         spec->autocfg.speaker_pins[1] = 0x16;
1810         spec->autocfg.speaker_pins[2] = 0x1b;
1811 }
1812
1813 /*
1814  * ALC880 3-stack model
1815  *
1816  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1817  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1818  *                 F-Mic = 0x1b, HP = 0x19
1819  */
1820
1821 static hda_nid_t alc880_dac_nids[4] = {
1822         /* front, rear, clfe, rear_surr */
1823         0x02, 0x05, 0x04, 0x03
1824 };
1825
1826 static hda_nid_t alc880_adc_nids[3] = {
1827         /* ADC0-2 */
1828         0x07, 0x08, 0x09,
1829 };
1830
1831 /* The datasheet says the node 0x07 is connected from inputs,
1832  * but it shows zero connection in the real implementation on some devices.
1833  * Note: this is a 915GAV bug, fixed on 915GLV
1834  */
1835 static hda_nid_t alc880_adc_nids_alt[2] = {
1836         /* ADC1-2 */
1837         0x08, 0x09,
1838 };
1839
1840 #define ALC880_DIGOUT_NID       0x06
1841 #define ALC880_DIGIN_NID        0x0a
1842
1843 static struct hda_input_mux alc880_capture_source = {
1844         .num_items = 4,
1845         .items = {
1846                 { "Mic", 0x0 },
1847                 { "Front Mic", 0x3 },
1848                 { "Line", 0x2 },
1849                 { "CD", 0x4 },
1850         },
1851 };
1852
1853 /* channel source setting (2/6 channel selection for 3-stack) */
1854 /* 2ch mode */
1855 static struct hda_verb alc880_threestack_ch2_init[] = {
1856         /* set line-in to input, mute it */
1857         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1858         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1859         /* set mic-in to input vref 80%, mute it */
1860         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1861         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1862         { } /* end */
1863 };
1864
1865 /* 6ch mode */
1866 static struct hda_verb alc880_threestack_ch6_init[] = {
1867         /* set line-in to output, unmute it */
1868         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1869         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1870         /* set mic-in to output, unmute it */
1871         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1872         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1873         { } /* end */
1874 };
1875
1876 static struct hda_channel_mode alc880_threestack_modes[2] = {
1877         { 2, alc880_threestack_ch2_init },
1878         { 6, alc880_threestack_ch6_init },
1879 };
1880
1881 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1882         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1883         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1884         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1885         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1886         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1887         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1888         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1889         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1890         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1891         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1892         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1893         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1894         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1895         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1896         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1897         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1898         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1899         {
1900                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1901                 .name = "Channel Mode",
1902                 .info = alc_ch_mode_info,
1903                 .get = alc_ch_mode_get,
1904                 .put = alc_ch_mode_put,
1905         },
1906         { } /* end */
1907 };
1908
1909 /* capture mixer elements */
1910 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1911                             struct snd_ctl_elem_info *uinfo)
1912 {
1913         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1914         struct alc_spec *spec = codec->spec;
1915         int err;
1916
1917         mutex_lock(&codec->control_mutex);
1918         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1919                                                       HDA_INPUT);
1920         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1921         mutex_unlock(&codec->control_mutex);
1922         return err;
1923 }
1924
1925 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1926                            unsigned int size, unsigned int __user *tlv)
1927 {
1928         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1929         struct alc_spec *spec = codec->spec;
1930         int err;
1931
1932         mutex_lock(&codec->control_mutex);
1933         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1934                                                       HDA_INPUT);
1935         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1936         mutex_unlock(&codec->control_mutex);
1937         return err;
1938 }
1939
1940 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1941                              struct snd_ctl_elem_value *ucontrol);
1942
1943 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1944                                  struct snd_ctl_elem_value *ucontrol,
1945                                  getput_call_t func)
1946 {
1947         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1948         struct alc_spec *spec = codec->spec;
1949         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1950         int err;
1951
1952         mutex_lock(&codec->control_mutex);
1953         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1954                                                       3, 0, HDA_INPUT);
1955         err = func(kcontrol, ucontrol);
1956         mutex_unlock(&codec->control_mutex);
1957         return err;
1958 }
1959
1960 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1961                            struct snd_ctl_elem_value *ucontrol)
1962 {
1963         return alc_cap_getput_caller(kcontrol, ucontrol,
1964                                      snd_hda_mixer_amp_volume_get);
1965 }
1966
1967 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1968                            struct snd_ctl_elem_value *ucontrol)
1969 {
1970         return alc_cap_getput_caller(kcontrol, ucontrol,
1971                                      snd_hda_mixer_amp_volume_put);
1972 }
1973
1974 /* capture mixer elements */
1975 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1976
1977 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1978                           struct snd_ctl_elem_value *ucontrol)
1979 {
1980         return alc_cap_getput_caller(kcontrol, ucontrol,
1981                                      snd_hda_mixer_amp_switch_get);
1982 }
1983
1984 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1985                           struct snd_ctl_elem_value *ucontrol)
1986 {
1987         return alc_cap_getput_caller(kcontrol, ucontrol,
1988                                      snd_hda_mixer_amp_switch_put);
1989 }
1990
1991 #define _DEFINE_CAPMIX(num) \
1992         { \
1993                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1994                 .name = "Capture Switch", \
1995                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1996                 .count = num, \
1997                 .info = alc_cap_sw_info, \
1998                 .get = alc_cap_sw_get, \
1999                 .put = alc_cap_sw_put, \
2000         }, \
2001         { \
2002                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2003                 .name = "Capture Volume", \
2004                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2005                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2006                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
2007                 .count = num, \
2008                 .info = alc_cap_vol_info, \
2009                 .get = alc_cap_vol_get, \
2010                 .put = alc_cap_vol_put, \
2011                 .tlv = { .c = alc_cap_vol_tlv }, \
2012         }
2013
2014 #define _DEFINE_CAPSRC(num) \
2015         { \
2016                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2017                 /* .name = "Capture Source", */ \
2018                 .name = "Input Source", \
2019                 .count = num, \
2020                 .info = alc_mux_enum_info, \
2021                 .get = alc_mux_enum_get, \
2022                 .put = alc_mux_enum_put, \
2023         }
2024
2025 #define DEFINE_CAPMIX(num) \
2026 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
2027         _DEFINE_CAPMIX(num),                                  \
2028         _DEFINE_CAPSRC(num),                                  \
2029         { } /* end */                                         \
2030 }
2031
2032 #define DEFINE_CAPMIX_NOSRC(num) \
2033 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
2034         _DEFINE_CAPMIX(num),                                        \
2035         { } /* end */                                               \
2036 }
2037
2038 /* up to three ADCs */
2039 DEFINE_CAPMIX(1);
2040 DEFINE_CAPMIX(2);
2041 DEFINE_CAPMIX(3);
2042 DEFINE_CAPMIX_NOSRC(1);
2043 DEFINE_CAPMIX_NOSRC(2);
2044 DEFINE_CAPMIX_NOSRC(3);
2045
2046 /*
2047  * ALC880 5-stack model
2048  *
2049  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
2050  *      Side = 0x02 (0xd)
2051  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
2052  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
2053  */
2054
2055 /* additional mixers to alc880_three_stack_mixer */
2056 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
2057         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2058         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
2059         { } /* end */
2060 };
2061
2062 /* channel source setting (6/8 channel selection for 5-stack) */
2063 /* 6ch mode */
2064 static struct hda_verb alc880_fivestack_ch6_init[] = {
2065         /* set line-in to input, mute it */
2066         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2067         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2068         { } /* end */
2069 };
2070
2071 /* 8ch mode */
2072 static struct hda_verb alc880_fivestack_ch8_init[] = {
2073         /* set line-in to output, unmute it */
2074         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2075         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2076         { } /* end */
2077 };
2078
2079 static struct hda_channel_mode alc880_fivestack_modes[2] = {
2080         { 6, alc880_fivestack_ch6_init },
2081         { 8, alc880_fivestack_ch8_init },
2082 };
2083
2084
2085 /*
2086  * ALC880 6-stack model
2087  *
2088  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
2089  *      Side = 0x05 (0x0f)
2090  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
2091  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
2092  */
2093
2094 static hda_nid_t alc880_6st_dac_nids[4] = {
2095         /* front, rear, clfe, rear_surr */
2096         0x02, 0x03, 0x04, 0x05
2097 };
2098
2099 static struct hda_input_mux alc880_6stack_capture_source = {
2100         .num_items = 4,
2101         .items = {
2102                 { "Mic", 0x0 },
2103                 { "Front Mic", 0x1 },
2104                 { "Line", 0x2 },
2105                 { "CD", 0x4 },
2106         },
2107 };
2108
2109 /* fixed 8-channels */
2110 static struct hda_channel_mode alc880_sixstack_modes[1] = {
2111         { 8, NULL },
2112 };
2113
2114 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
2115         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2116         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2117         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2118         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2119         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2120         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2121         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2122         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2123         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2124         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2125         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2126         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2127         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2128         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2129         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2130         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2131         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2132         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2133         {
2134                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2135                 .name = "Channel Mode",
2136                 .info = alc_ch_mode_info,
2137                 .get = alc_ch_mode_get,
2138                 .put = alc_ch_mode_put,
2139         },
2140         { } /* end */
2141 };
2142
2143
2144 /*
2145  * ALC880 W810 model
2146  *
2147  * W810 has rear IO for:
2148  * Front (DAC 02)
2149  * Surround (DAC 03)
2150  * Center/LFE (DAC 04)
2151  * Digital out (06)
2152  *
2153  * The system also has a pair of internal speakers, and a headphone jack.
2154  * These are both connected to Line2 on the codec, hence to DAC 02.
2155  *
2156  * There is a variable resistor to control the speaker or headphone
2157  * volume. This is a hardware-only device without a software API.
2158  *
2159  * Plugging headphones in will disable the internal speakers. This is
2160  * implemented in hardware, not via the driver using jack sense. In
2161  * a similar fashion, plugging into the rear socket marked "front" will
2162  * disable both the speakers and headphones.
2163  *
2164  * For input, there's a microphone jack, and an "audio in" jack.
2165  * These may not do anything useful with this driver yet, because I
2166  * haven't setup any initialization verbs for these yet...
2167  */
2168
2169 static hda_nid_t alc880_w810_dac_nids[3] = {
2170         /* front, rear/surround, clfe */
2171         0x02, 0x03, 0x04
2172 };
2173
2174 /* fixed 6 channels */
2175 static struct hda_channel_mode alc880_w810_modes[1] = {
2176         { 6, NULL }
2177 };
2178
2179 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2180 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2181         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2182         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2183         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2184         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2185         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2186         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2187         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2188         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2189         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2190         { } /* end */
2191 };
2192
2193
2194 /*
2195  * Z710V model
2196  *
2197  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2198  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2199  *                 Line = 0x1a
2200  */
2201
2202 static hda_nid_t alc880_z71v_dac_nids[1] = {
2203         0x02
2204 };
2205 #define ALC880_Z71V_HP_DAC      0x03
2206
2207 /* fixed 2 channels */
2208 static struct hda_channel_mode alc880_2_jack_modes[1] = {
2209         { 2, NULL }
2210 };
2211
2212 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
2213         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2214         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2215         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2216         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2217         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2218         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2219         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2220         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2221         { } /* end */
2222 };
2223
2224
2225 /*
2226  * ALC880 F1734 model
2227  *
2228  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
2229  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
2230  */
2231
2232 static hda_nid_t alc880_f1734_dac_nids[1] = {
2233         0x03
2234 };
2235 #define ALC880_F1734_HP_DAC     0x02
2236
2237 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
2238         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2239         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2240         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2241         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2242         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2243         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2244         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2245         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2246         { } /* end */
2247 };
2248
2249 static struct hda_input_mux alc880_f1734_capture_source = {
2250         .num_items = 2,
2251         .items = {
2252                 { "Mic", 0x1 },
2253                 { "CD", 0x4 },
2254         },
2255 };
2256
2257
2258 /*
2259  * ALC880 ASUS model
2260  *
2261  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2262  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2263  *  Mic = 0x18, Line = 0x1a
2264  */
2265
2266 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
2267 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
2268
2269 static struct snd_kcontrol_new alc880_asus_mixer[] = {
2270         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2271         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2272         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2273         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2274         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2275         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2276         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2277         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2278         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2279         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2280         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2281         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2282         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2283         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2284         {
2285                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2286                 .name = "Channel Mode",
2287                 .info = alc_ch_mode_info,
2288                 .get = alc_ch_mode_get,
2289                 .put = alc_ch_mode_put,
2290         },
2291         { } /* end */
2292 };
2293
2294 /*
2295  * ALC880 ASUS W1V model
2296  *
2297  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2298  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2299  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
2300  */
2301
2302 /* additional mixers to alc880_asus_mixer */
2303 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
2304         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
2305         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
2306         { } /* end */
2307 };
2308
2309 /* TCL S700 */
2310 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
2311         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2312         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2313         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
2314         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
2315         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
2316         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
2317         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
2318         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
2319         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
2320         { } /* end */
2321 };
2322
2323 /* Uniwill */
2324 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
2325         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2326         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2327         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2328         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2329         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2330         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2331         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2332         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2333         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2334         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2335         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2336         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2337         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2338         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2339         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2340         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2341         {
2342                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2343                 .name = "Channel Mode",
2344                 .info = alc_ch_mode_info,
2345                 .get = alc_ch_mode_get,
2346                 .put = alc_ch_mode_put,
2347         },
2348         { } /* end */
2349 };
2350
2351 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
2352         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2353         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2354         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2355         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2356         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2357         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2358         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2359         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2360         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2361         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2362         { } /* end */
2363 };
2364
2365 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
2366         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2367         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2368         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2369         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2370         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2371         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2372         { } /* end */
2373 };
2374
2375 /*
2376  * virtual master controls
2377  */
2378
2379 /*
2380  * slave controls for virtual master
2381  */
2382 static const char *alc_slave_vols[] = {
2383         "Front Playback Volume",
2384         "Surround Playback Volume",
2385         "Center Playback Volume",
2386         "LFE Playback Volume",
2387         "Side Playback Volume",
2388         "Headphone Playback Volume",
2389         "Speaker Playback Volume",
2390         "Mono Playback Volume",
2391         "Line-Out Playback Volume",
2392         "PCM Playback Volume",
2393         NULL,
2394 };
2395
2396 static const char *alc_slave_sws[] = {
2397         "Front Playback Switch",
2398         "Surround Playback Switch",
2399         "Center Playback Switch",
2400         "LFE Playback Switch",
2401         "Side Playback Switch",
2402         "Headphone Playback Switch",
2403         "Speaker Playback Switch",
2404         "Mono Playback Switch",
2405         "IEC958 Playback Switch",
2406         "Line-Out Playback Switch",
2407         "PCM Playback Switch",
2408         NULL,
2409 };
2410
2411 /*
2412  * build control elements
2413  */
2414
2415 static void alc_free_kctls(struct hda_codec *codec);
2416
2417 #ifdef CONFIG_SND_HDA_INPUT_BEEP
2418 /* additional beep mixers; the actual parameters are overwritten at build */
2419 static struct snd_kcontrol_new alc_beep_mixer[] = {
2420         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2421         HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
2422         { } /* end */
2423 };
2424 #endif
2425
2426 static int alc_build_controls(struct hda_codec *codec)
2427 {
2428         struct alc_spec *spec = codec->spec;
2429         int err;
2430         int i;
2431
2432         for (i = 0; i < spec->num_mixers; i++) {
2433                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2434                 if (err < 0)
2435                         return err;
2436         }
2437         if (spec->cap_mixer) {
2438                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2439                 if (err < 0)
2440                         return err;
2441         }
2442         if (spec->multiout.dig_out_nid) {
2443                 err = snd_hda_create_spdif_out_ctls(codec,
2444                                                     spec->multiout.dig_out_nid);
2445                 if (err < 0)
2446                         return err;
2447                 if (!spec->no_analog) {
2448                         err = snd_hda_create_spdif_share_sw(codec,
2449                                                             &spec->multiout);
2450                         if (err < 0)
2451                                 return err;
2452                         spec->multiout.share_spdif = 1;
2453                 }
2454         }
2455         if (spec->dig_in_nid) {
2456                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2457                 if (err < 0)
2458                         return err;
2459         }
2460
2461 #ifdef CONFIG_SND_HDA_INPUT_BEEP
2462         /* create beep controls if needed */
2463         if (spec->beep_amp) {
2464                 struct snd_kcontrol_new *knew;
2465                 for (knew = alc_beep_mixer; knew->name; knew++) {
2466                         struct snd_kcontrol *kctl;
2467                         kctl = snd_ctl_new1(knew, codec);
2468                         if (!kctl)
2469                                 return -ENOMEM;
2470                         kctl->private_value = spec->beep_amp;
2471                         err = snd_hda_ctl_add(codec,
2472                                         get_amp_nid_(spec->beep_amp), kctl);
2473                         if (err < 0)
2474                                 return err;
2475                 }
2476         }
2477 #endif
2478
2479         /* if we have no master control, let's create it */
2480         if (!spec->no_analog &&
2481             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2482                 unsigned int vmaster_tlv[4];
2483                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2484                                         HDA_OUTPUT, vmaster_tlv);
2485                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2486                                           vmaster_tlv, alc_slave_vols);
2487                 if (err < 0)
2488                         return err;
2489         }
2490         if (!spec->no_analog &&
2491             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2492                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2493                                           NULL, alc_slave_sws);
2494                 if (err < 0)
2495                         return err;
2496         }
2497
2498         alc_free_kctls(codec); /* no longer needed */
2499         return 0;
2500 }
2501
2502
2503 /*
2504  * initialize the codec volumes, etc
2505  */
2506
2507 /*
2508  * generic initialization of ADC, input mixers and output mixers
2509  */
2510 static struct hda_verb alc880_volume_init_verbs[] = {
2511         /*
2512          * Unmute ADC0-2 and set the default input to mic-in
2513          */
2514         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2515         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2516         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2517         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2518         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2519         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2520
2521         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2522          * mixer widget
2523          * Note: PASD motherboards uses the Line In 2 as the input for front
2524          * panel mic (mic 2)
2525          */
2526         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2527         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2528         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2529         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2530         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2531         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2532         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2533         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2534
2535         /*
2536          * Set up output mixers (0x0c - 0x0f)
2537          */
2538         /* set vol=0 to output mixers */
2539         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2540         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2541         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2542         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2543         /* set up input amps for analog loopback */
2544         /* Amp Indices: DAC = 0, mixer = 1 */
2545         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2546         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2547         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2548         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2549         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2550         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2551         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2552         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2553
2554         { }
2555 };
2556
2557 /*
2558  * 3-stack pin configuration:
2559  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2560  */
2561 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2562         /*
2563          * preset connection lists of input pins
2564          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2565          */
2566         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2567         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2568         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2569
2570         /*
2571          * Set pin mode and muting
2572          */
2573         /* set front pin widgets 0x14 for output */
2574         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2575         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2576         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2577         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2578         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2579         /* Mic2 (as headphone out) for HP output */
2580         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2581         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2582         /* Line In pin widget for input */
2583         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2584         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2585         /* Line2 (as front mic) pin widget for input and vref at 80% */
2586         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2587         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2588         /* CD pin widget for input */
2589         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2590
2591         { }
2592 };
2593
2594 /*
2595  * 5-stack pin configuration:
2596  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2597  * line-in/side = 0x1a, f-mic = 0x1b
2598  */
2599 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2600         /*
2601          * preset connection lists of input pins
2602          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2603          */
2604         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2605         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2606
2607         /*
2608          * Set pin mode and muting
2609          */
2610         /* set pin widgets 0x14-0x17 for output */
2611         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2612         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2613         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2614         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2615         /* unmute pins for output (no gain on this amp) */
2616         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2617         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2618         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2619         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2620
2621         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2622         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2623         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2624         /* Mic2 (as headphone out) for HP output */
2625         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2626         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2627         /* Line In pin widget for input */
2628         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2629         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2630         /* Line2 (as front mic) pin widget for input and vref at 80% */
2631         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2632         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2633         /* CD pin widget for input */
2634         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2635
2636         { }
2637 };
2638
2639 /*
2640  * W810 pin configuration:
2641  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2642  */
2643 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2644         /* hphone/speaker input selector: front DAC */
2645         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2646
2647         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2648         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2649         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2650         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2651         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2652         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2653
2654         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2655         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2656
2657         { }
2658 };
2659
2660 /*
2661  * Z71V pin configuration:
2662  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2663  */
2664 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2665         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2666         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2667         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2668         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2669
2670         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2671         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2672         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2673         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2674
2675         { }
2676 };
2677
2678 /*
2679  * 6-stack pin configuration:
2680  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2681  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2682  */
2683 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2684         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2685
2686         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2687         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2688         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2689         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2690         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2691         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2692         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2693         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2694
2695         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2696         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2697         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2698         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2699         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2700         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2701         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2702         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2703         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2704
2705         { }
2706 };
2707
2708 /*
2709  * Uniwill pin configuration:
2710  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2711  * line = 0x1a
2712  */
2713 static struct hda_verb alc880_uniwill_init_verbs[] = {
2714         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2715
2716         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2717         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2718         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2719         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2720         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2721         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2722         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2723         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2724         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2725         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2726         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2727         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2728         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2729         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2730
2731         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2732         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2733         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2734         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2735         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2736         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2737         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2738         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2739         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2740
2741         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2742         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2743
2744         { }
2745 };
2746
2747 /*
2748 * Uniwill P53
2749 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2750  */
2751 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2752         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2753
2754         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2755         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2756         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2757         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2758         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2759         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2760         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2761         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2762         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2763         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2764         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2765         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2766
2767         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2768         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2769         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2770         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2771         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2772         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2773
2774         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2775         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2776
2777         { }
2778 };
2779
2780 static struct hda_verb alc880_beep_init_verbs[] = {
2781         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2782         { }
2783 };
2784
2785 /* auto-toggle front mic */
2786 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2787 {
2788         unsigned int present;
2789         unsigned char bits;
2790
2791         present = snd_hda_jack_detect(codec, 0x18);
2792         bits = present ? HDA_AMP_MUTE : 0;
2793         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2794 }
2795
2796 static void alc880_uniwill_setup(struct hda_codec *codec)
2797 {
2798         struct alc_spec *spec = codec->spec;
2799
2800         spec->autocfg.hp_pins[0] = 0x14;
2801         spec->autocfg.speaker_pins[0] = 0x15;
2802         spec->autocfg.speaker_pins[0] = 0x16;
2803 }
2804
2805 static void alc880_uniwill_init_hook(struct hda_codec *codec)
2806 {
2807         alc_automute_amp(codec);
2808         alc880_uniwill_mic_automute(codec);
2809 }
2810
2811 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2812                                        unsigned int res)
2813 {
2814         /* Looks like the unsol event is incompatible with the standard
2815          * definition.  4bit tag is placed at 28 bit!
2816          */
2817         switch (res >> 28) {
2818         case ALC880_MIC_EVENT:
2819                 alc880_uniwill_mic_automute(codec);
2820                 break;
2821         default:
2822                 alc_automute_amp_unsol_event(codec, res);
2823                 break;
2824         }
2825 }
2826
2827 static void alc880_uniwill_p53_setup(struct hda_codec *codec)
2828 {
2829         struct alc_spec *spec = codec->spec;
2830
2831         spec->autocfg.hp_pins[0] = 0x14;
2832         spec->autocfg.speaker_pins[0] = 0x15;
2833 }
2834
2835 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2836 {
2837         unsigned int present;
2838
2839         present = snd_hda_codec_read(codec, 0x21, 0,
2840                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2841         present &= HDA_AMP_VOLMASK;
2842         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2843                                  HDA_AMP_VOLMASK, present);
2844         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2845                                  HDA_AMP_VOLMASK, present);
2846 }
2847
2848 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2849                                            unsigned int res)
2850 {
2851         /* Looks like the unsol event is incompatible with the standard
2852          * definition.  4bit tag is placed at 28 bit!
2853          */
2854         if ((res >> 28) == ALC880_DCVOL_EVENT)
2855                 alc880_uniwill_p53_dcvol_automute(codec);
2856         else
2857                 alc_automute_amp_unsol_event(codec, res);
2858 }
2859
2860 /*
2861  * F1734 pin configuration:
2862  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2863  */
2864 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2865         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2866         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2867         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2868         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2869         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2870
2871         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2872         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2873         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2874         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2875
2876         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2877         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2878         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2879         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2880         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2881         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2882         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2883         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2884         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2885
2886         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2887         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2888
2889         { }
2890 };
2891
2892 /*
2893  * ASUS pin configuration:
2894  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2895  */
2896 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2897         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2898         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2899         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2900         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2901
2902         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2903         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2904         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2905         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2906         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2907         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2908         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2909         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2910
2911         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2912         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2913         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2914         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2915         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2916         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2917         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2918         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2919         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2920
2921         { }
2922 };
2923
2924 /* Enable GPIO mask and set output */
2925 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2926 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2927 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
2928
2929 /* Clevo m520g init */
2930 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2931         /* headphone output */
2932         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2933         /* line-out */
2934         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2935         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2936         /* Line-in */
2937         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2938         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2939         /* CD */
2940         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2941         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2942         /* Mic1 (rear panel) */
2943         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2944         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2945         /* Mic2 (front panel) */
2946         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2947         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2948         /* headphone */
2949         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2950         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2951         /* change to EAPD mode */
2952         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2953         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2954
2955         { }
2956 };
2957
2958 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2959         /* change to EAPD mode */
2960         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2961         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2962
2963         /* Headphone output */
2964         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2965         /* Front output*/
2966         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2967         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2968
2969         /* Line In pin widget for input */
2970         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2971         /* CD pin widget for input */
2972         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2973         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2974         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2975
2976         /* change to EAPD mode */
2977         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2978         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2979
2980         { }
2981 };
2982
2983 /*
2984  * LG m1 express dual
2985  *
2986  * Pin assignment:
2987  *   Rear Line-In/Out (blue): 0x14
2988  *   Build-in Mic-In: 0x15
2989  *   Speaker-out: 0x17
2990  *   HP-Out (green): 0x1b
2991  *   Mic-In/Out (red): 0x19
2992  *   SPDIF-Out: 0x1e
2993  */
2994
2995 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2996 static hda_nid_t alc880_lg_dac_nids[3] = {
2997         0x05, 0x02, 0x03
2998 };
2999
3000 /* seems analog CD is not working */
3001 static struct hda_input_mux alc880_lg_capture_source = {
3002         .num_items = 3,
3003         .items = {
3004                 { "Mic", 0x1 },
3005                 { "Line", 0x5 },
3006                 { "Internal Mic", 0x6 },
3007         },
3008 };
3009
3010 /* 2,4,6 channel modes */
3011 static struct hda_verb alc880_lg_ch2_init[] = {
3012         /* set line-in and mic-in to input */
3013         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
3014         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3015         { }
3016 };
3017
3018 static struct hda_verb alc880_lg_ch4_init[] = {
3019         /* set line-in to out and mic-in to input */
3020         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3021         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3022         { }
3023 };
3024
3025 static struct hda_verb alc880_lg_ch6_init[] = {
3026         /* set line-in and mic-in to output */
3027         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3028         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3029         { }
3030 };
3031
3032 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
3033         { 2, alc880_lg_ch2_init },
3034         { 4, alc880_lg_ch4_init },
3035         { 6, alc880_lg_ch6_init },
3036 };
3037
3038 static struct snd_kcontrol_new alc880_lg_mixer[] = {
3039         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3040         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3041         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3042         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
3043         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
3044         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
3045         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
3046         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
3047         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3048         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3049         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
3050         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
3051         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
3052         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
3053         {
3054                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3055                 .name = "Channel Mode",
3056                 .info = alc_ch_mode_info,
3057                 .get = alc_ch_mode_get,
3058                 .put = alc_ch_mode_put,
3059         },
3060         { } /* end */
3061 };
3062
3063 static struct hda_verb alc880_lg_init_verbs[] = {
3064         /* set capture source to mic-in */
3065         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3066         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3067         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3068         /* mute all amp mixer inputs */
3069         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3070         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3071         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3072         /* line-in to input */
3073         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3074         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3075         /* built-in mic */
3076         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3077         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3078         /* speaker-out */
3079         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3080         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3081         /* mic-in to input */
3082         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3083         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3084         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3085         /* HP-out */
3086         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
3087         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3088         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3089         /* jack sense */
3090         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3091         { }
3092 };
3093
3094 /* toggle speaker-output according to the hp-jack state */
3095 static void alc880_lg_setup(struct hda_codec *codec)
3096 {
3097         struct alc_spec *spec = codec->spec;
3098
3099         spec->autocfg.hp_pins[0] = 0x1b;
3100         spec->autocfg.speaker_pins[0] = 0x17;
3101 }
3102
3103 /*
3104  * LG LW20
3105  *
3106  * Pin assignment:
3107  *   Speaker-out: 0x14
3108  *   Mic-In: 0x18
3109  *   Built-in Mic-In: 0x19
3110  *   Line-In: 0x1b
3111  *   HP-Out: 0x1a
3112  *   SPDIF-Out: 0x1e
3113  */
3114
3115 static struct hda_input_mux alc880_lg_lw_capture_source = {
3116         .num_items = 3,
3117         .items = {
3118                 { "Mic", 0x0 },
3119                 { "Internal Mic", 0x1 },
3120                 { "Line In", 0x2 },
3121         },
3122 };
3123
3124 #define alc880_lg_lw_modes alc880_threestack_modes
3125
3126 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3127         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3128         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3129         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3130         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
3131         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3132         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3133         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3134         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3135         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3136         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3137         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3138         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3139         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
3140         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
3141         {
3142                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3143                 .name = "Channel Mode",
3144                 .info = alc_ch_mode_info,
3145                 .get = alc_ch_mode_get,
3146                 .put = alc_ch_mode_put,
3147         },
3148         { } /* end */
3149 };
3150
3151 static struct hda_verb alc880_lg_lw_init_verbs[] = {
3152         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3153         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3154         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3155
3156         /* set capture source to mic-in */
3157         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3158         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3159         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3160         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3161         /* speaker-out */
3162         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3163         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3164         /* HP-out */
3165         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3166         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3167         /* mic-in to input */
3168         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3169         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3170         /* built-in mic */
3171         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3172         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3173         /* jack sense */
3174         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3175         { }
3176 };
3177
3178 /* toggle speaker-output according to the hp-jack state */
3179 static void alc880_lg_lw_setup(struct hda_codec *codec)
3180 {
3181         struct alc_spec *spec = codec->spec;
3182
3183         spec->autocfg.hp_pins[0] = 0x1b;
3184         spec->autocfg.speaker_pins[0] = 0x14;
3185 }
3186
3187 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
3188         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3189         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
3190         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3191         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3192         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3193         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
3194         { } /* end */
3195 };
3196
3197 static struct hda_input_mux alc880_medion_rim_capture_source = {
3198         .num_items = 2,
3199         .items = {
3200                 { "Mic", 0x0 },
3201                 { "Internal Mic", 0x1 },
3202         },
3203 };
3204
3205 static struct hda_verb alc880_medion_rim_init_verbs[] = {
3206         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3207
3208         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},