]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - sound/pci/hda/patch_realtek.c
78bea2c6ab6da9e93ab36366b87ca236b2f09b5f
[linux-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_EEEPC_P703,
135         ALC269_ASUS_EEEPC_P901,
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         ALC662_AUTO,
192         ALC662_MODEL_LAST,
193 };
194
195 /* ALC882 models */
196 enum {
197         ALC882_3ST_DIG,
198         ALC882_6ST_DIG,
199         ALC882_ARIMA,
200         ALC882_W2JC,
201         ALC882_TARGA,
202         ALC882_ASUS_A7J,
203         ALC882_ASUS_A7M,
204         ALC885_MACPRO,
205         ALC885_MBP3,
206         ALC885_IMAC24,
207         ALC882_AUTO,
208         ALC882_MODEL_LAST,
209 };
210
211 /* ALC883 models */
212 enum {
213         ALC883_3ST_2ch_DIG,
214         ALC883_3ST_6ch_DIG,
215         ALC883_3ST_6ch,
216         ALC883_6ST_DIG,
217         ALC883_TARGA_DIG,
218         ALC883_TARGA_2ch_DIG,
219         ALC883_ACER,
220         ALC883_ACER_ASPIRE,
221         ALC888_ACER_ASPIRE_4930G,
222         ALC883_MEDION,
223         ALC883_MEDION_MD2,
224         ALC883_LAPTOP_EAPD,
225         ALC883_LENOVO_101E_2ch,
226         ALC883_LENOVO_NB0763,
227         ALC888_LENOVO_MS7195_DIG,
228         ALC888_LENOVO_SKY,
229         ALC883_HAIER_W66,
230         ALC888_3ST_HP,
231         ALC888_6ST_DELL,
232         ALC883_MITAC,
233         ALC883_CLEVO_M720,
234         ALC883_FUJITSU_PI2515,
235         ALC888_FUJITSU_XA3530,
236         ALC883_3ST_6ch_INTEL,
237         ALC888_ASUS_M90V,
238         ALC888_ASUS_EEE1601,
239         ALC1200_ASUS_P5Q,
240         ALC883_AUTO,
241         ALC883_MODEL_LAST,
242 };
243
244 /* styles of capture selection */
245 enum {
246         CAPT_MUX = 0,   /* only mux based */
247         CAPT_MIX,       /* only mixer based */
248         CAPT_1MUX_MIX,  /* first mux and other mixers */
249 };
250
251 /* for GPIO Poll */
252 #define GPIO_MASK       0x03
253
254 struct alc_spec {
255         /* codec parameterization */
256         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
257         unsigned int num_mixers;
258         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
259         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
260
261         const struct hda_verb *init_verbs[5];   /* initialization verbs
262                                                  * don't forget NULL
263                                                  * termination!
264                                                  */
265         unsigned int num_init_verbs;
266
267         char *stream_name_analog;       /* analog PCM stream */
268         struct hda_pcm_stream *stream_analog_playback;
269         struct hda_pcm_stream *stream_analog_capture;
270         struct hda_pcm_stream *stream_analog_alt_playback;
271         struct hda_pcm_stream *stream_analog_alt_capture;
272
273         char *stream_name_digital;      /* digital PCM stream */
274         struct hda_pcm_stream *stream_digital_playback;
275         struct hda_pcm_stream *stream_digital_capture;
276
277         /* playback */
278         struct hda_multi_out multiout;  /* playback set-up
279                                          * max_channels, dacs must be set
280                                          * dig_out_nid and hp_nid are optional
281                                          */
282         hda_nid_t alt_dac_nid;
283         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
284         int dig_out_type;
285
286         /* capture */
287         unsigned int num_adc_nids;
288         hda_nid_t *adc_nids;
289         hda_nid_t *capsrc_nids;
290         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
291         int capture_style;              /* capture style (CAPT_*) */
292
293         /* capture source */
294         unsigned int num_mux_defs;
295         const struct hda_input_mux *input_mux;
296         unsigned int cur_mux[3];
297
298         /* channel model */
299         const struct hda_channel_mode *channel_mode;
300         int num_channel_mode;
301         int need_dac_fix;
302
303         /* PCM information */
304         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
305
306         /* dynamic controls, init_verbs and input_mux */
307         struct auto_pin_cfg autocfg;
308         struct snd_array kctls;
309         struct hda_input_mux private_imux[3];
310         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
311
312         /* hooks */
313         void (*init_hook)(struct hda_codec *codec);
314         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
315
316         /* for pin sensing */
317         unsigned int sense_updated: 1;
318         unsigned int jack_present: 1;
319         unsigned int master_sw: 1;
320
321         /* other flags */
322         unsigned int no_analog :1; /* digital I/O only */
323
324         /* for virtual master */
325         hda_nid_t vmaster_nid;
326 #ifdef CONFIG_SND_HDA_POWER_SAVE
327         struct hda_loopback_check loopback;
328 #endif
329
330         /* for PLL fix */
331         hda_nid_t pll_nid;
332         unsigned int pll_coef_idx, pll_coef_bit;
333 };
334
335 /*
336  * configuration template - to be copied to the spec instance
337  */
338 struct alc_config_preset {
339         struct snd_kcontrol_new *mixers[5]; /* should be identical size
340                                              * with spec
341                                              */
342         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
343         const struct hda_verb *init_verbs[5];
344         unsigned int num_dacs;
345         hda_nid_t *dac_nids;
346         hda_nid_t dig_out_nid;          /* optional */
347         hda_nid_t hp_nid;               /* optional */
348         hda_nid_t *slave_dig_outs;
349         unsigned int num_adc_nids;
350         hda_nid_t *adc_nids;
351         hda_nid_t *capsrc_nids;
352         hda_nid_t dig_in_nid;
353         unsigned int num_channel_mode;
354         const struct hda_channel_mode *channel_mode;
355         int need_dac_fix;
356         unsigned int num_mux_defs;
357         const struct hda_input_mux *input_mux;
358         void (*unsol_event)(struct hda_codec *, unsigned int);
359         void (*init_hook)(struct hda_codec *);
360 #ifdef CONFIG_SND_HDA_POWER_SAVE
361         struct hda_amp_list *loopbacks;
362 #endif
363 };
364
365
366 /*
367  * input MUX handling
368  */
369 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
370                              struct snd_ctl_elem_info *uinfo)
371 {
372         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
373         struct alc_spec *spec = codec->spec;
374         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
375         if (mux_idx >= spec->num_mux_defs)
376                 mux_idx = 0;
377         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
378 }
379
380 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
381                             struct snd_ctl_elem_value *ucontrol)
382 {
383         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
384         struct alc_spec *spec = codec->spec;
385         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
386
387         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
388         return 0;
389 }
390
391 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
392                             struct snd_ctl_elem_value *ucontrol)
393 {
394         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
395         struct alc_spec *spec = codec->spec;
396         const struct hda_input_mux *imux;
397         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
398         unsigned int mux_idx;
399         hda_nid_t nid = spec->capsrc_nids ?
400                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
401
402         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
403         imux = &spec->input_mux[mux_idx];
404
405         if (spec->capture_style &&
406             !(spec->capture_style == CAPT_1MUX_MIX && !adc_idx)) {
407                 /* Matrix-mixer style (e.g. ALC882) */
408                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
409                 unsigned int i, idx;
410
411                 idx = ucontrol->value.enumerated.item[0];
412                 if (idx >= imux->num_items)
413                         idx = imux->num_items - 1;
414                 if (*cur_val == idx)
415                         return 0;
416                 for (i = 0; i < imux->num_items; i++) {
417                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
418                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
419                                                  imux->items[i].index,
420                                                  HDA_AMP_MUTE, v);
421                 }
422                 *cur_val = idx;
423                 return 1;
424         } else {
425                 /* MUX style (e.g. ALC880) */
426                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
427                                              &spec->cur_mux[adc_idx]);
428         }
429 }
430
431 /*
432  * channel mode setting
433  */
434 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
435                             struct snd_ctl_elem_info *uinfo)
436 {
437         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
438         struct alc_spec *spec = codec->spec;
439         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
440                                     spec->num_channel_mode);
441 }
442
443 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
444                            struct snd_ctl_elem_value *ucontrol)
445 {
446         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
447         struct alc_spec *spec = codec->spec;
448         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
449                                    spec->num_channel_mode,
450                                    spec->multiout.max_channels);
451 }
452
453 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
454                            struct snd_ctl_elem_value *ucontrol)
455 {
456         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
457         struct alc_spec *spec = codec->spec;
458         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
459                                       spec->num_channel_mode,
460                                       &spec->multiout.max_channels);
461         if (err >= 0 && spec->need_dac_fix)
462                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
463         return err;
464 }
465
466 /*
467  * Control the mode of pin widget settings via the mixer.  "pc" is used
468  * instead of "%" to avoid consequences of accidently treating the % as
469  * being part of a format specifier.  Maximum allowed length of a value is
470  * 63 characters plus NULL terminator.
471  *
472  * Note: some retasking pin complexes seem to ignore requests for input
473  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
474  * are requested.  Therefore order this list so that this behaviour will not
475  * cause problems when mixer clients move through the enum sequentially.
476  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
477  * March 2006.
478  */
479 static char *alc_pin_mode_names[] = {
480         "Mic 50pc bias", "Mic 80pc bias",
481         "Line in", "Line out", "Headphone out",
482 };
483 static unsigned char alc_pin_mode_values[] = {
484         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
485 };
486 /* The control can present all 5 options, or it can limit the options based
487  * in the pin being assumed to be exclusively an input or an output pin.  In
488  * addition, "input" pins may or may not process the mic bias option
489  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
490  * accept requests for bias as of chip versions up to March 2006) and/or
491  * wiring in the computer.
492  */
493 #define ALC_PIN_DIR_IN              0x00
494 #define ALC_PIN_DIR_OUT             0x01
495 #define ALC_PIN_DIR_INOUT           0x02
496 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
497 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
498
499 /* Info about the pin modes supported by the different pin direction modes.
500  * For each direction the minimum and maximum values are given.
501  */
502 static signed char alc_pin_mode_dir_info[5][2] = {
503         { 0, 2 },    /* ALC_PIN_DIR_IN */
504         { 3, 4 },    /* ALC_PIN_DIR_OUT */
505         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
506         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
507         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
508 };
509 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
510 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
511 #define alc_pin_mode_n_items(_dir) \
512         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
513
514 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
515                              struct snd_ctl_elem_info *uinfo)
516 {
517         unsigned int item_num = uinfo->value.enumerated.item;
518         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
519
520         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
521         uinfo->count = 1;
522         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
523
524         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
525                 item_num = alc_pin_mode_min(dir);
526         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
527         return 0;
528 }
529
530 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
531                             struct snd_ctl_elem_value *ucontrol)
532 {
533         unsigned int i;
534         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
535         hda_nid_t nid = kcontrol->private_value & 0xffff;
536         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
537         long *valp = ucontrol->value.integer.value;
538         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
539                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
540                                                  0x00);
541
542         /* Find enumerated value for current pinctl setting */
543         i = alc_pin_mode_min(dir);
544         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
545                 i++;
546         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
547         return 0;
548 }
549
550 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
551                             struct snd_ctl_elem_value *ucontrol)
552 {
553         signed int change;
554         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
555         hda_nid_t nid = kcontrol->private_value & 0xffff;
556         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
557         long val = *ucontrol->value.integer.value;
558         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
559                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
560                                                  0x00);
561
562         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
563                 val = alc_pin_mode_min(dir);
564
565         change = pinctl != alc_pin_mode_values[val];
566         if (change) {
567                 /* Set pin mode to that requested */
568                 snd_hda_codec_write_cache(codec, nid, 0,
569                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
570                                           alc_pin_mode_values[val]);
571
572                 /* Also enable the retasking pin's input/output as required
573                  * for the requested pin mode.  Enum values of 2 or less are
574                  * input modes.
575                  *
576                  * Dynamically switching the input/output buffers probably
577                  * reduces noise slightly (particularly on input) so we'll
578                  * do it.  However, having both input and output buffers
579                  * enabled simultaneously doesn't seem to be problematic if
580                  * this turns out to be necessary in the future.
581                  */
582                 if (val <= 2) {
583                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
584                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
585                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
586                                                  HDA_AMP_MUTE, 0);
587                 } else {
588                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
589                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
590                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
591                                                  HDA_AMP_MUTE, 0);
592                 }
593         }
594         return change;
595 }
596
597 #define ALC_PIN_MODE(xname, nid, dir) \
598         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
599           .info = alc_pin_mode_info, \
600           .get = alc_pin_mode_get, \
601           .put = alc_pin_mode_put, \
602           .private_value = nid | (dir<<16) }
603
604 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
605  * together using a mask with more than one bit set.  This control is
606  * currently used only by the ALC260 test model.  At this stage they are not
607  * needed for any "production" models.
608  */
609 #ifdef CONFIG_SND_DEBUG
610 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
611
612 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
613                              struct snd_ctl_elem_value *ucontrol)
614 {
615         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
616         hda_nid_t nid = kcontrol->private_value & 0xffff;
617         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
618         long *valp = ucontrol->value.integer.value;
619         unsigned int val = snd_hda_codec_read(codec, nid, 0,
620                                               AC_VERB_GET_GPIO_DATA, 0x00);
621
622         *valp = (val & mask) != 0;
623         return 0;
624 }
625 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
626                              struct snd_ctl_elem_value *ucontrol)
627 {
628         signed int change;
629         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
630         hda_nid_t nid = kcontrol->private_value & 0xffff;
631         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
632         long val = *ucontrol->value.integer.value;
633         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
634                                                     AC_VERB_GET_GPIO_DATA,
635                                                     0x00);
636
637         /* Set/unset the masked GPIO bit(s) as needed */
638         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
639         if (val == 0)
640                 gpio_data &= ~mask;
641         else
642                 gpio_data |= mask;
643         snd_hda_codec_write_cache(codec, nid, 0,
644                                   AC_VERB_SET_GPIO_DATA, gpio_data);
645
646         return change;
647 }
648 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
649         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
650           .info = alc_gpio_data_info, \
651           .get = alc_gpio_data_get, \
652           .put = alc_gpio_data_put, \
653           .private_value = nid | (mask<<16) }
654 #endif   /* CONFIG_SND_DEBUG */
655
656 /* A switch control to allow the enabling of the digital IO pins on the
657  * ALC260.  This is incredibly simplistic; the intention of this control is
658  * to provide something in the test model allowing digital outputs to be
659  * identified if present.  If models are found which can utilise these
660  * outputs a more complete mixer control can be devised for those models if
661  * necessary.
662  */
663 #ifdef CONFIG_SND_DEBUG
664 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
665
666 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
667                               struct snd_ctl_elem_value *ucontrol)
668 {
669         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670         hda_nid_t nid = kcontrol->private_value & 0xffff;
671         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
672         long *valp = ucontrol->value.integer.value;
673         unsigned int val = snd_hda_codec_read(codec, nid, 0,
674                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
675
676         *valp = (val & mask) != 0;
677         return 0;
678 }
679 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
680                               struct snd_ctl_elem_value *ucontrol)
681 {
682         signed int change;
683         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
684         hda_nid_t nid = kcontrol->private_value & 0xffff;
685         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
686         long val = *ucontrol->value.integer.value;
687         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
688                                                     AC_VERB_GET_DIGI_CONVERT_1,
689                                                     0x00);
690
691         /* Set/unset the masked control bit(s) as needed */
692         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
693         if (val==0)
694                 ctrl_data &= ~mask;
695         else
696                 ctrl_data |= mask;
697         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
698                                   ctrl_data);
699
700         return change;
701 }
702 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
703         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
704           .info = alc_spdif_ctrl_info, \
705           .get = alc_spdif_ctrl_get, \
706           .put = alc_spdif_ctrl_put, \
707           .private_value = nid | (mask<<16) }
708 #endif   /* CONFIG_SND_DEBUG */
709
710 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
711  * Again, this is only used in the ALC26x test models to help identify when
712  * the EAPD line must be asserted for features to work.
713  */
714 #ifdef CONFIG_SND_DEBUG
715 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
716
717 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
718                               struct snd_ctl_elem_value *ucontrol)
719 {
720         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
721         hda_nid_t nid = kcontrol->private_value & 0xffff;
722         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
723         long *valp = ucontrol->value.integer.value;
724         unsigned int val = snd_hda_codec_read(codec, nid, 0,
725                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
726
727         *valp = (val & mask) != 0;
728         return 0;
729 }
730
731 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
732                               struct snd_ctl_elem_value *ucontrol)
733 {
734         int change;
735         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
736         hda_nid_t nid = kcontrol->private_value & 0xffff;
737         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
738         long val = *ucontrol->value.integer.value;
739         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
740                                                     AC_VERB_GET_EAPD_BTLENABLE,
741                                                     0x00);
742
743         /* Set/unset the masked control bit(s) as needed */
744         change = (!val ? 0 : mask) != (ctrl_data & mask);
745         if (!val)
746                 ctrl_data &= ~mask;
747         else
748                 ctrl_data |= mask;
749         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
750                                   ctrl_data);
751
752         return change;
753 }
754
755 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
756         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
757           .info = alc_eapd_ctrl_info, \
758           .get = alc_eapd_ctrl_get, \
759           .put = alc_eapd_ctrl_put, \
760           .private_value = nid | (mask<<16) }
761 #endif   /* CONFIG_SND_DEBUG */
762
763 /*
764  * set up the input pin config (depending on the given auto-pin type)
765  */
766 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
767                               int auto_pin_type)
768 {
769         unsigned int val = PIN_IN;
770
771         if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
772                 unsigned int pincap;
773                 pincap = snd_hda_query_pin_caps(codec, nid);
774                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
775                 if (pincap & AC_PINCAP_VREF_80)
776                         val = PIN_VREF80;
777         }
778         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
779 }
780
781 /*
782  */
783 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
784 {
785         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
786                 return;
787         spec->mixers[spec->num_mixers++] = mix;
788 }
789
790 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
791 {
792         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
793                 return;
794         spec->init_verbs[spec->num_init_verbs++] = verb;
795 }
796
797 #ifdef CONFIG_PROC_FS
798 /*
799  * hook for proc
800  */
801 static void print_realtek_coef(struct snd_info_buffer *buffer,
802                                struct hda_codec *codec, hda_nid_t nid)
803 {
804         int coeff;
805
806         if (nid != 0x20)
807                 return;
808         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
809         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
810         coeff = snd_hda_codec_read(codec, nid, 0,
811                                    AC_VERB_GET_COEF_INDEX, 0);
812         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
813 }
814 #else
815 #define print_realtek_coef      NULL
816 #endif
817
818 /*
819  * set up from the preset table
820  */
821 static void setup_preset(struct alc_spec *spec,
822                          const struct alc_config_preset *preset)
823 {
824         int i;
825
826         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
827                 add_mixer(spec, preset->mixers[i]);
828         spec->cap_mixer = preset->cap_mixer;
829         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
830              i++)
831                 add_verb(spec, preset->init_verbs[i]);
832
833         spec->channel_mode = preset->channel_mode;
834         spec->num_channel_mode = preset->num_channel_mode;
835         spec->need_dac_fix = preset->need_dac_fix;
836
837         spec->multiout.max_channels = spec->channel_mode[0].channels;
838
839         spec->multiout.num_dacs = preset->num_dacs;
840         spec->multiout.dac_nids = preset->dac_nids;
841         spec->multiout.dig_out_nid = preset->dig_out_nid;
842         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
843         spec->multiout.hp_nid = preset->hp_nid;
844
845         spec->num_mux_defs = preset->num_mux_defs;
846         if (!spec->num_mux_defs)
847                 spec->num_mux_defs = 1;
848         spec->input_mux = preset->input_mux;
849
850         spec->num_adc_nids = preset->num_adc_nids;
851         spec->adc_nids = preset->adc_nids;
852         spec->capsrc_nids = preset->capsrc_nids;
853         spec->dig_in_nid = preset->dig_in_nid;
854
855         spec->unsol_event = preset->unsol_event;
856         spec->init_hook = preset->init_hook;
857 #ifdef CONFIG_SND_HDA_POWER_SAVE
858         spec->loopback.amplist = preset->loopbacks;
859 #endif
860 }
861
862 /* Enable GPIO mask and set output */
863 static struct hda_verb alc_gpio1_init_verbs[] = {
864         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
865         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
866         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
867         { }
868 };
869
870 static struct hda_verb alc_gpio2_init_verbs[] = {
871         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
872         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
873         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
874         { }
875 };
876
877 static struct hda_verb alc_gpio3_init_verbs[] = {
878         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
879         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
880         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
881         { }
882 };
883
884 /*
885  * Fix hardware PLL issue
886  * On some codecs, the analog PLL gating control must be off while
887  * the default value is 1.
888  */
889 static void alc_fix_pll(struct hda_codec *codec)
890 {
891         struct alc_spec *spec = codec->spec;
892         unsigned int val;
893
894         if (!spec->pll_nid)
895                 return;
896         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
897                             spec->pll_coef_idx);
898         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
899                                  AC_VERB_GET_PROC_COEF, 0);
900         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
901                             spec->pll_coef_idx);
902         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
903                             val & ~(1 << spec->pll_coef_bit));
904 }
905
906 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
907                              unsigned int coef_idx, unsigned int coef_bit)
908 {
909         struct alc_spec *spec = codec->spec;
910         spec->pll_nid = nid;
911         spec->pll_coef_idx = coef_idx;
912         spec->pll_coef_bit = coef_bit;
913         alc_fix_pll(codec);
914 }
915
916 static void alc_sku_automute(struct hda_codec *codec)
917 {
918         struct alc_spec *spec = codec->spec;
919         unsigned int present;
920         unsigned int hp_nid = spec->autocfg.hp_pins[0];
921         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
922
923         /* need to execute and sync at first */
924         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
925         present = snd_hda_codec_read(codec, hp_nid, 0,
926                                      AC_VERB_GET_PIN_SENSE, 0);
927         spec->jack_present = (present & 0x80000000) != 0;
928         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
929                             spec->jack_present ? 0 : PIN_OUT);
930 }
931
932 #if 0 /* it's broken in some acses -- temporarily disabled */
933 static void alc_mic_automute(struct hda_codec *codec)
934 {
935         struct alc_spec *spec = codec->spec;
936         unsigned int present;
937         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
938         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
939         unsigned int mix_nid = spec->capsrc_nids[0];
940         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
941
942         capsrc_idx_mic = mic_nid - 0x18;
943         capsrc_idx_fmic = fmic_nid - 0x18;
944         present = snd_hda_codec_read(codec, mic_nid, 0,
945                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
946         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
947                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
948         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
949                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
950         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
951                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
952 }
953 #else
954 #define alc_mic_automute(codec) do {} while(0) /* NOP */
955 #endif /* disabled */
956
957 /* unsolicited event for HP jack sensing */
958 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
959 {
960         if (codec->vendor_id == 0x10ec0880)
961                 res >>= 28;
962         else
963                 res >>= 26;
964         if (res == ALC880_HP_EVENT)
965                 alc_sku_automute(codec);
966
967         if (res == ALC880_MIC_EVENT)
968                 alc_mic_automute(codec);
969 }
970
971 static void alc_inithook(struct hda_codec *codec)
972 {
973         alc_sku_automute(codec);
974         alc_mic_automute(codec);
975 }
976
977 /* additional initialization for ALC888 variants */
978 static void alc888_coef_init(struct hda_codec *codec)
979 {
980         unsigned int tmp;
981
982         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
983         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
984         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
985         if ((tmp & 0xf0) == 0x20)
986                 /* alc888S-VC */
987                 snd_hda_codec_read(codec, 0x20, 0,
988                                    AC_VERB_SET_PROC_COEF, 0x830);
989          else
990                  /* alc888-VB */
991                  snd_hda_codec_read(codec, 0x20, 0,
992                                     AC_VERB_SET_PROC_COEF, 0x3030);
993 }
994
995 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
996  *      31 ~ 16 :       Manufacture ID
997  *      15 ~ 8  :       SKU ID
998  *      7  ~ 0  :       Assembly ID
999  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1000  */
1001 static void alc_subsystem_id(struct hda_codec *codec,
1002                              unsigned int porta, unsigned int porte,
1003                              unsigned int portd)
1004 {
1005         unsigned int ass, tmp, i;
1006         unsigned nid;
1007         struct alc_spec *spec = codec->spec;
1008
1009         ass = codec->subsystem_id & 0xffff;
1010         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1011                 goto do_sku;
1012
1013         /*
1014          * 31~30        : port conetcivity
1015          * 29~21        : reserve
1016          * 20           : PCBEEP input
1017          * 19~16        : Check sum (15:1)
1018          * 15~1         : Custom
1019          * 0            : override
1020         */
1021         nid = 0x1d;
1022         if (codec->vendor_id == 0x10ec0260)
1023                 nid = 0x17;
1024         ass = snd_hda_codec_get_pincfg(codec, nid);
1025         if (!(ass & 1) && !(ass & 0x100000))
1026                 return;
1027         if ((ass >> 30) != 1)   /* no physical connection */
1028                 return;
1029
1030         /* check sum */
1031         tmp = 0;
1032         for (i = 1; i < 16; i++) {
1033                 if ((ass >> i) & 1)
1034                         tmp++;
1035         }
1036         if (((ass >> 16) & 0xf) != tmp)
1037                 return;
1038 do_sku:
1039         /*
1040          * 0 : override
1041          * 1 :  Swap Jack
1042          * 2 : 0 --> Desktop, 1 --> Laptop
1043          * 3~5 : External Amplifier control
1044          * 7~6 : Reserved
1045         */
1046         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1047         switch (tmp) {
1048         case 1:
1049                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1050                 break;
1051         case 3:
1052                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1053                 break;
1054         case 7:
1055                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1056                 break;
1057         case 5: /* set EAPD output high */
1058                 switch (codec->vendor_id) {
1059                 case 0x10ec0260:
1060                         snd_hda_codec_write(codec, 0x0f, 0,
1061                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1062                         snd_hda_codec_write(codec, 0x10, 0,
1063                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1064                         break;
1065                 case 0x10ec0262:
1066                 case 0x10ec0267:
1067                 case 0x10ec0268:
1068                 case 0x10ec0269:
1069                 case 0x10ec0272:
1070                 case 0x10ec0660:
1071                 case 0x10ec0662:
1072                 case 0x10ec0663:
1073                 case 0x10ec0862:
1074                 case 0x10ec0889:
1075                         snd_hda_codec_write(codec, 0x14, 0,
1076                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1077                         snd_hda_codec_write(codec, 0x15, 0,
1078                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1079                         break;
1080                 }
1081                 switch (codec->vendor_id) {
1082                 case 0x10ec0260:
1083                         snd_hda_codec_write(codec, 0x1a, 0,
1084                                             AC_VERB_SET_COEF_INDEX, 7);
1085                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1086                                                  AC_VERB_GET_PROC_COEF, 0);
1087                         snd_hda_codec_write(codec, 0x1a, 0,
1088                                             AC_VERB_SET_COEF_INDEX, 7);
1089                         snd_hda_codec_write(codec, 0x1a, 0,
1090                                             AC_VERB_SET_PROC_COEF,
1091                                             tmp | 0x2010);
1092                         break;
1093                 case 0x10ec0262:
1094                 case 0x10ec0880:
1095                 case 0x10ec0882:
1096                 case 0x10ec0883:
1097                 case 0x10ec0885:
1098                 case 0x10ec0887:
1099                 case 0x10ec0889:
1100                         snd_hda_codec_write(codec, 0x20, 0,
1101                                             AC_VERB_SET_COEF_INDEX, 7);
1102                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1103                                                  AC_VERB_GET_PROC_COEF, 0);
1104                         snd_hda_codec_write(codec, 0x20, 0,
1105                                             AC_VERB_SET_COEF_INDEX, 7);
1106                         snd_hda_codec_write(codec, 0x20, 0,
1107                                             AC_VERB_SET_PROC_COEF,
1108                                             tmp | 0x2010);
1109                         break;
1110                 case 0x10ec0888:
1111                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1112                         break;
1113                 case 0x10ec0267:
1114                 case 0x10ec0268:
1115                         snd_hda_codec_write(codec, 0x20, 0,
1116                                             AC_VERB_SET_COEF_INDEX, 7);
1117                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1118                                                  AC_VERB_GET_PROC_COEF, 0);
1119                         snd_hda_codec_write(codec, 0x20, 0,
1120                                             AC_VERB_SET_COEF_INDEX, 7);
1121                         snd_hda_codec_write(codec, 0x20, 0,
1122                                             AC_VERB_SET_PROC_COEF,
1123                                             tmp | 0x3000);
1124                         break;
1125                 }
1126         default:
1127                 break;
1128         }
1129
1130         /* is laptop or Desktop and enable the function "Mute internal speaker
1131          * when the external headphone out jack is plugged"
1132          */
1133         if (!(ass & 0x8000))
1134                 return;
1135         /*
1136          * 10~8 : Jack location
1137          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1138          * 14~13: Resvered
1139          * 15   : 1 --> enable the function "Mute internal speaker
1140          *              when the external headphone out jack is plugged"
1141          */
1142         if (!spec->autocfg.speaker_pins[0]) {
1143                 if (spec->autocfg.line_out_pins[0])
1144                         spec->autocfg.speaker_pins[0] =
1145                                 spec->autocfg.line_out_pins[0];
1146                 else
1147                         return;
1148         }
1149
1150         if (!spec->autocfg.hp_pins[0]) {
1151                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1152                 if (tmp == 0)
1153                         spec->autocfg.hp_pins[0] = porta;
1154                 else if (tmp == 1)
1155                         spec->autocfg.hp_pins[0] = porte;
1156                 else if (tmp == 2)
1157                         spec->autocfg.hp_pins[0] = portd;
1158                 else
1159                         return;
1160         }
1161         if (spec->autocfg.hp_pins[0])
1162                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1163                         AC_VERB_SET_UNSOLICITED_ENABLE,
1164                         AC_USRSP_EN | ALC880_HP_EVENT);
1165
1166 #if 0 /* it's broken in some acses -- temporarily disabled */
1167         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1168                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1169                 snd_hda_codec_write(codec,
1170                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1171                         AC_VERB_SET_UNSOLICITED_ENABLE,
1172                         AC_USRSP_EN | ALC880_MIC_EVENT);
1173 #endif /* disabled */
1174
1175         spec->unsol_event = alc_sku_unsol_event;
1176 }
1177
1178 /*
1179  * Fix-up pin default configurations
1180  */
1181
1182 struct alc_pincfg {
1183         hda_nid_t nid;
1184         u32 val;
1185 };
1186
1187 static void alc_fix_pincfg(struct hda_codec *codec,
1188                            const struct snd_pci_quirk *quirk,
1189                            const struct alc_pincfg **pinfix)
1190 {
1191         const struct alc_pincfg *cfg;
1192
1193         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1194         if (!quirk)
1195                 return;
1196
1197         cfg = pinfix[quirk->value];
1198         for (; cfg->nid; cfg++)
1199                 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1200 }
1201
1202 /*
1203  * ALC888
1204  */
1205
1206 /*
1207  * 2ch mode
1208  */
1209 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1210 /* Mic-in jack as mic in */
1211         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1212         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1213 /* Line-in jack as Line in */
1214         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1215         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1216 /* Line-Out as Front */
1217         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1218         { } /* end */
1219 };
1220
1221 /*
1222  * 4ch mode
1223  */
1224 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1225 /* Mic-in jack as mic in */
1226         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1227         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1228 /* Line-in jack as Surround */
1229         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1230         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1231 /* Line-Out as Front */
1232         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1233         { } /* end */
1234 };
1235
1236 /*
1237  * 6ch mode
1238  */
1239 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1240 /* Mic-in jack as CLFE */
1241         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1242         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1243 /* Line-in jack as Surround */
1244         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1245         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1246 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1247         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1248         { } /* end */
1249 };
1250
1251 /*
1252  * 8ch mode
1253  */
1254 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1255 /* Mic-in jack as CLFE */
1256         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1257         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1258 /* Line-in jack as Surround */
1259         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1260         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1261 /* Line-Out as Side */
1262         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1263         { } /* end */
1264 };
1265
1266 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1267         { 2, alc888_4ST_ch2_intel_init },
1268         { 4, alc888_4ST_ch4_intel_init },
1269         { 6, alc888_4ST_ch6_intel_init },
1270         { 8, alc888_4ST_ch8_intel_init },
1271 };
1272
1273 /*
1274  * ALC888 Fujitsu Siemens Amillo xa3530
1275  */
1276
1277 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1278 /* Front Mic: set to PIN_IN (empty by default) */
1279         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1280 /* Connect Internal HP to Front */
1281         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1282         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1283         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1284 /* Connect Bass HP to Front */
1285         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1286         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1287         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1288 /* Connect Line-Out side jack (SPDIF) to Side */
1289         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1290         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1291         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1292 /* Connect Mic jack to CLFE */
1293         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1294         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1295         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1296 /* Connect Line-in jack to Surround */
1297         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1298         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1299         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1300 /* Connect HP out jack to Front */
1301         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1302         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1303         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1304 /* Enable unsolicited event for HP jack and Line-out jack */
1305         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1306         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1307         {}
1308 };
1309
1310 static void alc888_fujitsu_xa3530_automute(struct hda_codec *codec)
1311 {
1312         unsigned int present;
1313         unsigned int bits;
1314         /* Line out presence */
1315         present = snd_hda_codec_read(codec, 0x17, 0,
1316                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1317         /* HP out presence */
1318         present = present || snd_hda_codec_read(codec, 0x1b, 0,
1319                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1320         bits = present ? HDA_AMP_MUTE : 0;
1321         /* Toggle internal speakers muting */
1322         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1323                                  HDA_AMP_MUTE, bits);
1324         /* Toggle internal bass muting */
1325         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1326                                  HDA_AMP_MUTE, bits);
1327 }
1328
1329 static void alc888_fujitsu_xa3530_unsol_event(struct hda_codec *codec,
1330                 unsigned int res)
1331 {
1332         if (res >> 26 == ALC880_HP_EVENT)
1333                 alc888_fujitsu_xa3530_automute(codec);
1334 }
1335
1336
1337 /*
1338  * ALC888 Acer Aspire 4930G model
1339  */
1340
1341 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1342 /* Front Mic: set to PIN_IN (empty by default) */
1343         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1344 /* Unselect Front Mic by default in input mixer 3 */
1345         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1346 /* Enable unsolicited event for HP jack */
1347         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1348 /* Connect Internal HP to front */
1349         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1350         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1351         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1352 /* Connect HP out to front */
1353         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1354         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1355         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1356         { }
1357 };
1358
1359 static struct hda_input_mux alc888_2_capture_sources[2] = {
1360         /* Front mic only available on one ADC */
1361         {
1362                 .num_items = 4,
1363                 .items = {
1364                         { "Mic", 0x0 },
1365                         { "Line", 0x2 },
1366                         { "CD", 0x4 },
1367                         { "Front Mic", 0xb },
1368                 },
1369         },
1370         {
1371                 .num_items = 3,
1372                 .items = {
1373                         { "Mic", 0x0 },
1374                         { "Line", 0x2 },
1375                         { "CD", 0x4 },
1376                 },
1377         }
1378 };
1379
1380 static struct snd_kcontrol_new alc888_base_mixer[] = {
1381         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1382         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1383         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1384         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1385         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1386                 HDA_OUTPUT),
1387         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1388         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1389         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1390         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1391         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1392         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1393         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1394         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1395         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1396         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1397         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1398         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1399         { } /* end */
1400 };
1401
1402 static void alc888_acer_aspire_4930g_automute(struct hda_codec *codec)
1403 {
1404         unsigned int present;
1405         unsigned int bits;
1406         present = snd_hda_codec_read(codec, 0x15, 0,
1407                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1408         bits = present ? HDA_AMP_MUTE : 0;
1409         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1410                                  HDA_AMP_MUTE, bits);
1411 }
1412
1413 static void alc888_acer_aspire_4930g_unsol_event(struct hda_codec *codec,
1414                 unsigned int res)
1415 {
1416         if (res >> 26 == ALC880_HP_EVENT)
1417                 alc888_acer_aspire_4930g_automute(codec);
1418 }
1419
1420 /*
1421  * ALC880 3-stack model
1422  *
1423  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1424  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1425  *                 F-Mic = 0x1b, HP = 0x19
1426  */
1427
1428 static hda_nid_t alc880_dac_nids[4] = {
1429         /* front, rear, clfe, rear_surr */
1430         0x02, 0x05, 0x04, 0x03
1431 };
1432
1433 static hda_nid_t alc880_adc_nids[3] = {
1434         /* ADC0-2 */
1435         0x07, 0x08, 0x09,
1436 };
1437
1438 /* The datasheet says the node 0x07 is connected from inputs,
1439  * but it shows zero connection in the real implementation on some devices.
1440  * Note: this is a 915GAV bug, fixed on 915GLV
1441  */
1442 static hda_nid_t alc880_adc_nids_alt[2] = {
1443         /* ADC1-2 */
1444         0x08, 0x09,
1445 };
1446
1447 #define ALC880_DIGOUT_NID       0x06
1448 #define ALC880_DIGIN_NID        0x0a
1449
1450 static struct hda_input_mux alc880_capture_source = {
1451         .num_items = 4,
1452         .items = {
1453                 { "Mic", 0x0 },
1454                 { "Front Mic", 0x3 },
1455                 { "Line", 0x2 },
1456                 { "CD", 0x4 },
1457         },
1458 };
1459
1460 /* channel source setting (2/6 channel selection for 3-stack) */
1461 /* 2ch mode */
1462 static struct hda_verb alc880_threestack_ch2_init[] = {
1463         /* set line-in to input, mute it */
1464         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1465         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1466         /* set mic-in to input vref 80%, mute it */
1467         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1468         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1469         { } /* end */
1470 };
1471
1472 /* 6ch mode */
1473 static struct hda_verb alc880_threestack_ch6_init[] = {
1474         /* set line-in to output, unmute it */
1475         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1476         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1477         /* set mic-in to output, unmute it */
1478         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1479         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1480         { } /* end */
1481 };
1482
1483 static struct hda_channel_mode alc880_threestack_modes[2] = {
1484         { 2, alc880_threestack_ch2_init },
1485         { 6, alc880_threestack_ch6_init },
1486 };
1487
1488 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1489         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1490         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1491         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1492         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1493         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1494         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1495         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1496         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1497         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1498         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1499         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1500         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1501         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1502         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1503         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1504         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1505         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1506         {
1507                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1508                 .name = "Channel Mode",
1509                 .info = alc_ch_mode_info,
1510                 .get = alc_ch_mode_get,
1511                 .put = alc_ch_mode_put,
1512         },
1513         { } /* end */
1514 };
1515
1516 /* capture mixer elements */
1517 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1518                             struct snd_ctl_elem_info *uinfo)
1519 {
1520         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1521         struct alc_spec *spec = codec->spec;
1522         int err;
1523
1524         mutex_lock(&codec->control_mutex);
1525         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1526                                                       HDA_INPUT);
1527         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1528         mutex_unlock(&codec->control_mutex);
1529         return err;
1530 }
1531
1532 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1533                            unsigned int size, unsigned int __user *tlv)
1534 {
1535         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1536         struct alc_spec *spec = codec->spec;
1537         int err;
1538
1539         mutex_lock(&codec->control_mutex);
1540         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1541                                                       HDA_INPUT);
1542         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1543         mutex_unlock(&codec->control_mutex);
1544         return err;
1545 }
1546
1547 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1548                              struct snd_ctl_elem_value *ucontrol);
1549
1550 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1551                                  struct snd_ctl_elem_value *ucontrol,
1552                                  getput_call_t func)
1553 {
1554         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1555         struct alc_spec *spec = codec->spec;
1556         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1557         int err;
1558
1559         mutex_lock(&codec->control_mutex);
1560         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1561                                                       3, 0, HDA_INPUT);
1562         err = func(kcontrol, ucontrol);
1563         mutex_unlock(&codec->control_mutex);
1564         return err;
1565 }
1566
1567 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1568                            struct snd_ctl_elem_value *ucontrol)
1569 {
1570         return alc_cap_getput_caller(kcontrol, ucontrol,
1571                                      snd_hda_mixer_amp_volume_get);
1572 }
1573
1574 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1575                            struct snd_ctl_elem_value *ucontrol)
1576 {
1577         return alc_cap_getput_caller(kcontrol, ucontrol,
1578                                      snd_hda_mixer_amp_volume_put);
1579 }
1580
1581 /* capture mixer elements */
1582 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1583
1584 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1585                           struct snd_ctl_elem_value *ucontrol)
1586 {
1587         return alc_cap_getput_caller(kcontrol, ucontrol,
1588                                      snd_hda_mixer_amp_switch_get);
1589 }
1590
1591 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1592                           struct snd_ctl_elem_value *ucontrol)
1593 {
1594         return alc_cap_getput_caller(kcontrol, ucontrol,
1595                                      snd_hda_mixer_amp_switch_put);
1596 }
1597
1598 #define _DEFINE_CAPMIX(num) \
1599         { \
1600                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1601                 .name = "Capture Switch", \
1602                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1603                 .count = num, \
1604                 .info = alc_cap_sw_info, \
1605                 .get = alc_cap_sw_get, \
1606                 .put = alc_cap_sw_put, \
1607         }, \
1608         { \
1609                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1610                 .name = "Capture Volume", \
1611                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1612                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1613                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1614                 .count = num, \
1615                 .info = alc_cap_vol_info, \
1616                 .get = alc_cap_vol_get, \
1617                 .put = alc_cap_vol_put, \
1618                 .tlv = { .c = alc_cap_vol_tlv }, \
1619         }
1620
1621 #define _DEFINE_CAPSRC(num) \
1622         { \
1623                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1624                 /* .name = "Capture Source", */ \
1625                 .name = "Input Source", \
1626                 .count = num, \
1627                 .info = alc_mux_enum_info, \
1628                 .get = alc_mux_enum_get, \
1629                 .put = alc_mux_enum_put, \
1630         }
1631
1632 #define DEFINE_CAPMIX(num) \
1633 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1634         _DEFINE_CAPMIX(num),                                  \
1635         _DEFINE_CAPSRC(num),                                  \
1636         { } /* end */                                         \
1637 }
1638
1639 #define DEFINE_CAPMIX_NOSRC(num) \
1640 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1641         _DEFINE_CAPMIX(num),                                        \
1642         { } /* end */                                               \
1643 }
1644
1645 /* up to three ADCs */
1646 DEFINE_CAPMIX(1);
1647 DEFINE_CAPMIX(2);
1648 DEFINE_CAPMIX(3);
1649 DEFINE_CAPMIX_NOSRC(1);
1650 DEFINE_CAPMIX_NOSRC(2);
1651 DEFINE_CAPMIX_NOSRC(3);
1652
1653 /*
1654  * ALC880 5-stack model
1655  *
1656  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1657  *      Side = 0x02 (0xd)
1658  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1659  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1660  */
1661
1662 /* additional mixers to alc880_three_stack_mixer */
1663 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1664         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1665         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1666         { } /* end */
1667 };
1668
1669 /* channel source setting (6/8 channel selection for 5-stack) */
1670 /* 6ch mode */
1671 static struct hda_verb alc880_fivestack_ch6_init[] = {
1672         /* set line-in to input, mute it */
1673         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1674         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1675         { } /* end */
1676 };
1677
1678 /* 8ch mode */
1679 static struct hda_verb alc880_fivestack_ch8_init[] = {
1680         /* set line-in to output, unmute it */
1681         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1682         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1683         { } /* end */
1684 };
1685
1686 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1687         { 6, alc880_fivestack_ch6_init },
1688         { 8, alc880_fivestack_ch8_init },
1689 };
1690
1691
1692 /*
1693  * ALC880 6-stack model
1694  *
1695  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1696  *      Side = 0x05 (0x0f)
1697  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1698  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1699  */
1700
1701 static hda_nid_t alc880_6st_dac_nids[4] = {
1702         /* front, rear, clfe, rear_surr */
1703         0x02, 0x03, 0x04, 0x05
1704 };
1705
1706 static struct hda_input_mux alc880_6stack_capture_source = {
1707         .num_items = 4,
1708         .items = {
1709                 { "Mic", 0x0 },
1710                 { "Front Mic", 0x1 },
1711                 { "Line", 0x2 },
1712                 { "CD", 0x4 },
1713         },
1714 };
1715
1716 /* fixed 8-channels */
1717 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1718         { 8, NULL },
1719 };
1720
1721 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1722         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1723         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1724         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1725         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1726         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1727         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1728         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1729         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1730         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1731         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1732         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1733         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1734         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1735         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1736         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1737         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1738         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1739         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1740         {
1741                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1742                 .name = "Channel Mode",
1743                 .info = alc_ch_mode_info,
1744                 .get = alc_ch_mode_get,
1745                 .put = alc_ch_mode_put,
1746         },
1747         { } /* end */
1748 };
1749
1750
1751 /*
1752  * ALC880 W810 model
1753  *
1754  * W810 has rear IO for:
1755  * Front (DAC 02)
1756  * Surround (DAC 03)
1757  * Center/LFE (DAC 04)
1758  * Digital out (06)
1759  *
1760  * The system also has a pair of internal speakers, and a headphone jack.
1761  * These are both connected to Line2 on the codec, hence to DAC 02.
1762  *
1763  * There is a variable resistor to control the speaker or headphone
1764  * volume. This is a hardware-only device without a software API.
1765  *
1766  * Plugging headphones in will disable the internal speakers. This is
1767  * implemented in hardware, not via the driver using jack sense. In
1768  * a similar fashion, plugging into the rear socket marked "front" will
1769  * disable both the speakers and headphones.
1770  *
1771  * For input, there's a microphone jack, and an "audio in" jack.
1772  * These may not do anything useful with this driver yet, because I
1773  * haven't setup any initialization verbs for these yet...
1774  */
1775
1776 static hda_nid_t alc880_w810_dac_nids[3] = {
1777         /* front, rear/surround, clfe */
1778         0x02, 0x03, 0x04
1779 };
1780
1781 /* fixed 6 channels */
1782 static struct hda_channel_mode alc880_w810_modes[1] = {
1783         { 6, NULL }
1784 };
1785
1786 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1787 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1788         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1789         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1790         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1791         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1792         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1793         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1794         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1795         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1796         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1797         { } /* end */
1798 };
1799
1800
1801 /*
1802  * Z710V model
1803  *
1804  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1805  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1806  *                 Line = 0x1a
1807  */
1808
1809 static hda_nid_t alc880_z71v_dac_nids[1] = {
1810         0x02
1811 };
1812 #define ALC880_Z71V_HP_DAC      0x03
1813
1814 /* fixed 2 channels */
1815 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1816         { 2, NULL }
1817 };
1818
1819 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1820         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1821         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1822         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1823         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1824         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1825         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1826         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1827         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1828         { } /* end */
1829 };
1830
1831
1832 /*
1833  * ALC880 F1734 model
1834  *
1835  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1836  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1837  */
1838
1839 static hda_nid_t alc880_f1734_dac_nids[1] = {
1840         0x03
1841 };
1842 #define ALC880_F1734_HP_DAC     0x02
1843
1844 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1845         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1846         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1847         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1848         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1849         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1850         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1851         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1852         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1853         { } /* end */
1854 };
1855
1856 static struct hda_input_mux alc880_f1734_capture_source = {
1857         .num_items = 2,
1858         .items = {
1859                 { "Mic", 0x1 },
1860                 { "CD", 0x4 },
1861         },
1862 };
1863
1864
1865 /*
1866  * ALC880 ASUS model
1867  *
1868  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1869  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1870  *  Mic = 0x18, Line = 0x1a
1871  */
1872
1873 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1874 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1875
1876 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1877         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1878         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1879         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1880         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1881         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1882         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1883         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1884         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1885         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1886         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1887         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1888         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1889         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1890         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1891         {
1892                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1893                 .name = "Channel Mode",
1894                 .info = alc_ch_mode_info,
1895                 .get = alc_ch_mode_get,
1896                 .put = alc_ch_mode_put,
1897         },
1898         { } /* end */
1899 };
1900
1901 /*
1902  * ALC880 ASUS W1V model
1903  *
1904  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1905  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1906  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1907  */
1908
1909 /* additional mixers to alc880_asus_mixer */
1910 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1911         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1912         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1913         { } /* end */
1914 };
1915
1916 /* TCL S700 */
1917 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1918         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1919         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1920         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1921         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1922         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1923         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1924         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1925         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1926         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1927         { } /* end */
1928 };
1929
1930 /* Uniwill */
1931 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1932         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1933         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1934         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1935         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1936         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1937         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1938         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1939         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1940         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1941         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1942         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1943         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1944         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1945         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1946         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1947         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1948         {
1949                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1950                 .name = "Channel Mode",
1951                 .info = alc_ch_mode_info,
1952                 .get = alc_ch_mode_get,
1953                 .put = alc_ch_mode_put,
1954         },
1955         { } /* end */
1956 };
1957
1958 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1959         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1960         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1961         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1962         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1963         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1964         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1965         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1966         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1967         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1968         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1969         { } /* end */
1970 };
1971
1972 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1973         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1974         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1975         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1976         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1977         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1978         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1979         { } /* end */
1980 };
1981
1982 /*
1983  * virtual master controls
1984  */
1985
1986 /*
1987  * slave controls for virtual master
1988  */
1989 static const char *alc_slave_vols[] = {
1990         "Front Playback Volume",
1991         "Surround Playback Volume",
1992         "Center Playback Volume",
1993         "LFE Playback Volume",
1994         "Side Playback Volume",
1995         "Headphone Playback Volume",
1996         "Speaker Playback Volume",
1997         "Mono Playback Volume",
1998         "Line-Out Playback Volume",
1999         "PCM Playback Volume",
2000         NULL,
2001 };
2002
2003 static const char *alc_slave_sws[] = {
2004         "Front Playback Switch",
2005         "Surround Playback Switch",
2006         "Center Playback Switch",
2007         "LFE Playback Switch",
2008         "Side Playback Switch",
2009         "Headphone Playback Switch",
2010         "Speaker Playback Switch",
2011         "Mono Playback Switch",
2012         "IEC958 Playback Switch",
2013         NULL,
2014 };
2015
2016 /*
2017  * build control elements
2018  */
2019
2020 static void alc_free_kctls(struct hda_codec *codec);
2021
2022 /* additional beep mixers; the actual parameters are overwritten at build */
2023 static struct snd_kcontrol_new alc_beep_mixer[] = {
2024         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2025         HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT),
2026         { } /* end */
2027 };
2028
2029 static int alc_build_controls(struct hda_codec *codec)
2030 {
2031         struct alc_spec *spec = codec->spec;
2032         int err;
2033         int i;
2034
2035         for (i = 0; i < spec->num_mixers; i++) {
2036                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2037                 if (err < 0)
2038                         return err;
2039         }
2040         if (spec->cap_mixer) {
2041                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2042                 if (err < 0)
2043                         return err;
2044         }
2045         if (spec->multiout.dig_out_nid) {
2046                 err = snd_hda_create_spdif_out_ctls(codec,
2047                                                     spec->multiout.dig_out_nid);
2048                 if (err < 0)
2049                         return err;
2050                 if (!spec->no_analog) {
2051                         err = snd_hda_create_spdif_share_sw(codec,
2052                                                             &spec->multiout);
2053                         if (err < 0)
2054                                 return err;
2055                         spec->multiout.share_spdif = 1;
2056                 }
2057         }
2058         if (spec->dig_in_nid) {
2059                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2060                 if (err < 0)
2061                         return err;
2062         }
2063
2064         /* create beep controls if needed */
2065         if (spec->beep_amp) {
2066                 struct snd_kcontrol_new *knew;
2067                 for (knew = alc_beep_mixer; knew->name; knew++) {
2068                         struct snd_kcontrol *kctl;
2069                         kctl = snd_ctl_new1(knew, codec);
2070                         if (!kctl)
2071                                 return -ENOMEM;
2072                         kctl->private_value = spec->beep_amp;
2073                         err = snd_hda_ctl_add(codec, kctl);
2074                         if (err < 0)
2075                                 return err;
2076                 }
2077         }
2078
2079         /* if we have no master control, let's create it */
2080         if (!spec->no_analog &&
2081             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2082                 unsigned int vmaster_tlv[4];
2083                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2084                                         HDA_OUTPUT, vmaster_tlv);
2085                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2086                                           vmaster_tlv, alc_slave_vols);
2087                 if (err < 0)
2088                         return err;
2089         }
2090         if (!spec->no_analog &&
2091             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2092                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2093                                           NULL, alc_slave_sws);
2094                 if (err < 0)
2095                         return err;
2096         }
2097
2098         alc_free_kctls(codec); /* no longer needed */
2099         return 0;
2100 }
2101
2102
2103 /*
2104  * initialize the codec volumes, etc
2105  */
2106
2107 /*
2108  * generic initialization of ADC, input mixers and output mixers
2109  */
2110 static struct hda_verb alc880_volume_init_verbs[] = {
2111         /*
2112          * Unmute ADC0-2 and set the default input to mic-in
2113          */
2114         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2115         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2116         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2117         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2118         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2119         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2120
2121         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2122          * mixer widget
2123          * Note: PASD motherboards uses the Line In 2 as the input for front
2124          * panel mic (mic 2)
2125          */
2126         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2127         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2128         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2129         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2130         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2131         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2132         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2133         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2134
2135         /*
2136          * Set up output mixers (0x0c - 0x0f)
2137          */
2138         /* set vol=0 to output mixers */
2139         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2140         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2141         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2142         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2143         /* set up input amps for analog loopback */
2144         /* Amp Indices: DAC = 0, mixer = 1 */
2145         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2146         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2147         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2148         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2149         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2150         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2151         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2152         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2153
2154         { }
2155 };
2156
2157 /*
2158  * 3-stack pin configuration:
2159  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2160  */
2161 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2162         /*
2163          * preset connection lists of input pins
2164          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2165          */
2166         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2167         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2168         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2169
2170         /*
2171          * Set pin mode and muting
2172          */
2173         /* set front pin widgets 0x14 for output */
2174         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2175         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2176         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2177         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2178         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2179         /* Mic2 (as headphone out) for HP output */
2180         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2181         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2182         /* Line In pin widget for input */
2183         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2184         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2185         /* Line2 (as front mic) pin widget for input and vref at 80% */
2186         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2187         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2188         /* CD pin widget for input */
2189         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2190
2191         { }
2192 };
2193
2194 /*
2195  * 5-stack pin configuration:
2196  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2197  * line-in/side = 0x1a, f-mic = 0x1b
2198  */
2199 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2200         /*
2201          * preset connection lists of input pins
2202          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2203          */
2204         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2205         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2206
2207         /*
2208          * Set pin mode and muting
2209          */
2210         /* set pin widgets 0x14-0x17 for output */
2211         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2212         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2213         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2214         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2215         /* unmute pins for output (no gain on this amp) */
2216         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2217         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2218         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2219         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2220
2221         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2222         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2223         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2224         /* Mic2 (as headphone out) for HP output */
2225         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2226         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2227         /* Line In pin widget for input */
2228         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2229         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2230         /* Line2 (as front mic) pin widget for input and vref at 80% */
2231         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2232         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2233         /* CD pin widget for input */
2234         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2235
2236         { }
2237 };
2238
2239 /*
2240  * W810 pin configuration:
2241  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2242  */
2243 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2244         /* hphone/speaker input selector: front DAC */
2245         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2246
2247         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2248         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2249         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2250         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2251         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2252         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2253
2254         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2255         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2256
2257         { }
2258 };
2259
2260 /*
2261  * Z71V pin configuration:
2262  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2263  */
2264 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2265         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2266         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2267         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2268         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2269
2270         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2271         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2272         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2273         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2274
2275         { }
2276 };
2277
2278 /*
2279  * 6-stack pin configuration:
2280  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2281  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2282  */
2283 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2284         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2285
2286         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2287         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2288         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2289         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2290         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2291         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2292         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2293         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2294
2295         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2296         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2297         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2298         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2299         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2300         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2301         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2302         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2303         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2304
2305         { }
2306 };
2307
2308 /*
2309  * Uniwill pin configuration:
2310  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2311  * line = 0x1a
2312  */
2313 static struct hda_verb alc880_uniwill_init_verbs[] = {
2314         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2315
2316         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2317         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2318         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2319         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2320         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2321         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2322         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2323         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2324         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2325         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2326         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2327         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2328         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2329         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2330
2331         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2332         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2333         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2334         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2335         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2336         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2337         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2338         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2339         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2340
2341         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2342         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2343
2344         { }
2345 };
2346
2347 /*
2348 * Uniwill P53
2349 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2350  */
2351 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2352         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2353
2354         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2355         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2356         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2357         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2358         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2359         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2360         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2361         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2362         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2363         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2364         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2365         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2366
2367         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2368         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2369         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2370         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2371         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2372         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2373
2374         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2375         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2376
2377         { }
2378 };
2379
2380 static struct hda_verb alc880_beep_init_verbs[] = {
2381         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2382         { }
2383 };
2384
2385 /* toggle speaker-output according to the hp-jack state */
2386 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
2387 {
2388         unsigned int present;
2389         unsigned char bits;
2390
2391         present = snd_hda_codec_read(codec, 0x14, 0,
2392                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2393         bits = present ? HDA_AMP_MUTE : 0;
2394         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
2395                                  HDA_AMP_MUTE, bits);
2396         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
2397                                  HDA_AMP_MUTE, bits);
2398 }
2399
2400 /* auto-toggle front mic */
2401 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2402 {
2403         unsigned int present;
2404         unsigned char bits;
2405
2406         present = snd_hda_codec_read(codec, 0x18, 0,
2407                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2408         bits = present ? HDA_AMP_MUTE : 0;
2409         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2410 }
2411
2412 static void alc880_uniwill_automute(struct hda_codec *codec)
2413 {
2414         alc880_uniwill_hp_automute(codec);
2415         alc880_uniwill_mic_automute(codec);
2416 }
2417
2418 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2419                                        unsigned int res)
2420 {
2421         /* Looks like the unsol event is incompatible with the standard
2422          * definition.  4bit tag is placed at 28 bit!
2423          */
2424         switch (res >> 28) {
2425         case ALC880_HP_EVENT:
2426                 alc880_uniwill_hp_automute(codec);
2427                 break;
2428         case ALC880_MIC_EVENT:
2429                 alc880_uniwill_mic_automute(codec);
2430                 break;
2431         }
2432 }
2433
2434 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2435 {
2436         unsigned int present;
2437         unsigned char bits;
2438
2439         present = snd_hda_codec_read(codec, 0x14, 0,
2440                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2441         bits = present ? HDA_AMP_MUTE : 0;
2442         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2443 }
2444
2445 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2446 {
2447         unsigned int present;
2448
2449         present = snd_hda_codec_read(codec, 0x21, 0,
2450                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2451         present &= HDA_AMP_VOLMASK;
2452         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2453                                  HDA_AMP_VOLMASK, present);
2454         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2455                                  HDA_AMP_VOLMASK, present);
2456 }
2457
2458 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2459                                            unsigned int res)
2460 {
2461         /* Looks like the unsol event is incompatible with the standard
2462          * definition.  4bit tag is placed at 28 bit!
2463          */
2464         if ((res >> 28) == ALC880_HP_EVENT)
2465                 alc880_uniwill_p53_hp_automute(codec);
2466         if ((res >> 28) == ALC880_DCVOL_EVENT)
2467                 alc880_uniwill_p53_dcvol_automute(codec);
2468 }
2469
2470 /*
2471  * F1734 pin configuration:
2472  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2473  */
2474 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2475         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2476         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2477         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2478         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2479         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2480
2481         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2482         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2483         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2484         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2485
2486         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2487         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2488         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2489         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2490         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2491         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2492         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2493         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2494         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2495
2496         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2497         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2498
2499         { }
2500 };
2501
2502 /*
2503  * ASUS pin configuration:
2504  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2505  */
2506 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2507         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2508         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2509         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2510         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2511
2512         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2513         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2514         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2515         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2516         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2517         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2518         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2519         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2520
2521         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2522         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2523         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2524         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2525         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2526         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2527         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2528         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2529         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2530
2531         { }
2532 };
2533
2534 /* Enable GPIO mask and set output */
2535 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2536 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2537
2538 /* Clevo m520g init */
2539 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2540         /* headphone output */
2541         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2542         /* line-out */
2543         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2544         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2545         /* Line-in */
2546         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2547         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2548         /* CD */
2549         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2550         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2551         /* Mic1 (rear panel) */
2552         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2553         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2554         /* Mic2 (front panel) */
2555         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2556         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2557         /* headphone */
2558         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2559         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2560         /* change to EAPD mode */
2561         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2562         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2563
2564         { }
2565 };
2566
2567 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2568         /* change to EAPD mode */
2569         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2570         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2571
2572         /* Headphone output */
2573         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2574         /* Front output*/
2575         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2576         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2577
2578         /* Line In pin widget for input */
2579         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2580         /* CD pin widget for input */
2581         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2582         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2583         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2584
2585         /* change to EAPD mode */
2586         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2587         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2588
2589         { }
2590 };
2591
2592 /*
2593  * LG m1 express dual
2594  *
2595  * Pin assignment:
2596  *   Rear Line-In/Out (blue): 0x14
2597  *   Build-in Mic-In: 0x15
2598  *   Speaker-out: 0x17
2599  *   HP-Out (green): 0x1b
2600  *   Mic-In/Out (red): 0x19
2601  *   SPDIF-Out: 0x1e
2602  */
2603
2604 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2605 static hda_nid_t alc880_lg_dac_nids[3] = {
2606         0x05, 0x02, 0x03
2607 };
2608
2609 /* seems analog CD is not working */
2610 static struct hda_input_mux alc880_lg_capture_source = {
2611         .num_items = 3,
2612         .items = {
2613                 { "Mic", 0x1 },
2614                 { "Line", 0x5 },
2615                 { "Internal Mic", 0x6 },
2616         },
2617 };
2618
2619 /* 2,4,6 channel modes */
2620 static struct hda_verb alc880_lg_ch2_init[] = {
2621         /* set line-in and mic-in to input */
2622         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2623         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2624         { }
2625 };
2626
2627 static struct hda_verb alc880_lg_ch4_init[] = {
2628         /* set line-in to out and mic-in to input */
2629         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2630         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2631         { }
2632 };
2633
2634 static struct hda_verb alc880_lg_ch6_init[] = {
2635         /* set line-in and mic-in to output */
2636         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2637         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2638         { }
2639 };
2640
2641 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2642         { 2, alc880_lg_ch2_init },
2643         { 4, alc880_lg_ch4_init },
2644         { 6, alc880_lg_ch6_init },
2645 };
2646
2647 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2648         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2649         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2650         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2651         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2652         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2653         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2654         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2655         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2656         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2657         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2658         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2659         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2660         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2661         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2662         {
2663                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2664                 .name = "Channel Mode",
2665                 .info = alc_ch_mode_info,
2666                 .get = alc_ch_mode_get,
2667                 .put = alc_ch_mode_put,
2668         },
2669         { } /* end */
2670 };
2671
2672 static struct hda_verb alc880_lg_init_verbs[] = {
2673         /* set capture source to mic-in */
2674         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2675         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2676         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2677         /* mute all amp mixer inputs */
2678         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2679         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2680         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2681         /* line-in to input */
2682         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2683         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2684         /* built-in mic */
2685         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2686         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2687         /* speaker-out */
2688         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2689         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2690         /* mic-in to input */
2691         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2692         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2693         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2694         /* HP-out */
2695         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2696         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2697         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2698         /* jack sense */
2699         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2700         { }
2701 };
2702
2703 /* toggle speaker-output according to the hp-jack state */
2704 static void alc880_lg_automute(struct hda_codec *codec)
2705 {
2706         unsigned int present;
2707         unsigned char bits;
2708
2709         present = snd_hda_codec_read(codec, 0x1b, 0,
2710                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2711         bits = present ? HDA_AMP_MUTE : 0;
2712         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2713                                  HDA_AMP_MUTE, bits);
2714 }
2715
2716 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2717 {
2718         /* Looks like the unsol event is incompatible with the standard
2719          * definition.  4bit tag is placed at 28 bit!
2720          */
2721         if ((res >> 28) == 0x01)
2722                 alc880_lg_automute(codec);
2723 }
2724
2725 /*
2726  * LG LW20
2727  *
2728  * Pin assignment:
2729  *   Speaker-out: 0x14
2730  *   Mic-In: 0x18
2731  *   Built-in Mic-In: 0x19
2732  *   Line-In: 0x1b
2733  *   HP-Out: 0x1a
2734  *   SPDIF-Out: 0x1e
2735  */
2736
2737 static struct hda_input_mux alc880_lg_lw_capture_source = {
2738         .num_items = 3,
2739         .items = {
2740                 { "Mic", 0x0 },
2741                 { "Internal Mic", 0x1 },
2742                 { "Line In", 0x2 },
2743         },
2744 };
2745
2746 #define alc880_lg_lw_modes alc880_threestack_modes
2747
2748 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2749         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2750         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2751         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2752         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2753         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2754         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2755         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2756         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2757         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2758         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2759         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2760         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2761         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2762         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2763         {
2764                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2765                 .name = "Channel Mode",
2766                 .info = alc_ch_mode_info,
2767                 .get = alc_ch_mode_get,
2768                 .put = alc_ch_mode_put,
2769         },
2770         { } /* end */
2771 };
2772
2773 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2774         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2775         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2776         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2777
2778         /* set capture source to mic-in */
2779         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2780         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2781         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2782         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2783         /* speaker-out */
2784         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2785         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2786         /* HP-out */
2787         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2788         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2789         /* mic-in to input */
2790         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2791         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2792         /* built-in mic */
2793         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2794         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2795         /* jack sense */
2796         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2797         { }
2798 };
2799
2800 /* toggle speaker-output according to the hp-jack state */
2801 static void alc880_lg_lw_automute(struct hda_codec *codec)
2802 {
2803         unsigned int present;
2804         unsigned char bits;
2805
2806         present = snd_hda_codec_read(codec, 0x1b, 0,
2807                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2808         bits = present ? HDA_AMP_MUTE : 0;
2809         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2810                                  HDA_AMP_MUTE, bits);
2811 }
2812
2813 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2814 {
2815         /* Looks like the unsol event is incompatible with the standard
2816          * definition.  4bit tag is placed at 28 bit!
2817          */
2818         if ((res >> 28) == 0x01)
2819                 alc880_lg_lw_automute(codec);
2820 }
2821
2822 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2823         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2824         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2825         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2826         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2827         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2828         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2829         { } /* end */
2830 };
2831
2832 static struct hda_input_mux alc880_medion_rim_capture_source = {
2833         .num_items = 2,
2834         .items = {
2835                 { "Mic", 0x0 },
2836                 { "Internal Mic", 0x1 },
2837         },
2838 };
2839
2840 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2841         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2842
2843         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2844         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2845
2846         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2847         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2848         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2849         /* Mic2 (as headphone out) for HP output */
2850         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2851         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2852         /* Internal Speaker */
2853         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2854         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2855
2856         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2857         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2858
2859         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2860         { }
2861 };
2862
2863 /* toggle speaker-output according to the hp-jack state */
2864 static void alc880_medion_rim_automute(struct hda_codec *codec)
2865 {
2866         unsigned int present;
2867         unsigned char bits;
2868
2869         present = snd_hda_codec_read(codec, 0x14, 0,
2870                                      AC_VERB_GET_PIN_SENSE, 0)
2871                 & AC_PINSENSE_PRESENCE;
2872         bits = present ? HDA_AMP_MUTE : 0;
2873         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2874                                  HDA_AMP_MUTE, bits);
2875         if (present)
2876                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2877         else
2878                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2879 }
2880
2881 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2882                                           unsigned int res)
2883 {
2884         /* Looks like the unsol event is incompatible with the standard
2885          * definition.  4bit tag is placed at 28 bit!
2886          */
2887         if ((res >> 28) == ALC880_HP_EVENT)
2888                 alc880_medion_rim_automute(codec);
2889 }
2890
2891 #ifdef CONFIG_SND_HDA_POWER_SAVE
2892 static struct hda_amp_list alc880_loopbacks[] = {
2893         { 0x0b, HDA_INPUT, 0 },
2894         { 0x0b, HDA_INPUT, 1 },
2895         { 0x0b, HDA_INPUT, 2 },
2896         { 0x0b, HDA_INPUT, 3 },
2897         { 0x0b, HDA_INPUT, 4 },
2898         { } /* end */
2899 };
2900
2901 static struct hda_amp_list alc880_lg_loopbacks[] = {
2902         { 0x0b, HDA_INPUT, 1 },
2903         { 0x0b, HDA_INPUT, 6 },
2904         { 0x0b, HDA_INPUT, 7 },
2905         { } /* end */
2906 };
2907 #endif
2908
2909 /*
2910  * Common callbacks
2911  */
2912
2913 static int alc_init(struct hda_codec *codec)
2914 {
2915         struct alc_spec *spec = codec->spec;
2916         unsigned int i;
2917
2918         alc_fix_pll(codec);
2919         if (codec->vendor_id == 0x10ec0888)
2920                 alc888_coef_init(codec);
2921
2922         for (i = 0; i < spec->num_init_verbs; i++)
2923                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2924
2925         if (spec->init_hook)
2926                 spec->init_hook(codec);
2927
2928         return 0;
2929 }
2930
2931 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2932 {
2933         struct alc_spec *spec = codec->spec;
2934
2935         if (spec->unsol_event)
2936                 spec->unsol_event(codec, res);
2937 }
2938
2939 #ifdef CONFIG_SND_HDA_POWER_SAVE
2940 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2941 {
2942         struct alc_spec *spec = codec->spec;
2943         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2944 }
2945 #endif
2946
2947 /*
2948  * Analog playback callbacks
2949  */
2950 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2951                                     struct hda_codec *codec,
2952                                     struct snd_pcm_substream *substream)
2953 {
2954         struct alc_spec *spec = codec->spec;
2955         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2956                                              hinfo);
2957 }
2958
2959 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2960                                        struct hda_codec *codec,
2961                                        unsigned int stream_tag,
2962                                        unsigned int format,
2963                                        struct snd_pcm_substream *substream)
2964 {
2965         struct alc_spec *spec = codec->spec;
2966         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2967                                                 stream_tag, format, substream);
2968 }
2969
2970 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2971                                        struct hda_codec *codec,
2972                                        struct snd_pcm_substream *substream)
2973 {
2974         struct alc_spec *spec = codec->spec;
2975         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2976 }
2977
2978 /*
2979  * Digital out
2980  */
2981 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2982                                         struct hda_codec *codec,
2983                                         struct snd_pcm_substream *substream)
2984 {
2985         struct alc_spec *spec = codec->spec;
2986         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2987 }
2988
2989 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2990                                            struct hda_codec *codec,
2991                                            unsigned int stream_tag,
2992                                            unsigned int format,
2993                                            struct snd_pcm_substream *substream)
2994 {
2995         struct alc_spec *spec = codec->spec;
2996         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2997                                              stream_tag, format, substream);
2998 }
2999
3000 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3001                                            struct hda_codec *codec,
3002                                            struct snd_pcm_substream *substream)
3003 {
3004         struct alc_spec *spec = codec->spec;
3005         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3006 }
3007
3008 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3009                                          struct hda_codec *codec,
3010                                          struct snd_pcm_substream *substream)
3011 {
3012         struct alc_spec *spec = codec->spec;
3013         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3014 }
3015
3016 /*
3017  * Analog capture
3018  */
3019 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3020                                       struct hda_codec *codec,
3021                                       unsigned int stream_tag,
3022                                       unsigned int format,
3023                                       struct snd_pcm_substream *substream)
3024 {
3025         struct alc_spec *spec = codec->spec;
3026
3027         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3028                                    stream_tag, 0, format);
3029         return 0;
3030 }
3031
3032 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3033                                       struct hda_codec *codec,
3034                                       struct snd_pcm_substream *substream)
3035 {
3036         struct alc_spec *spec = codec->spec;
3037
3038         snd_hda_codec_cleanup_stream(codec,
3039                                      spec->adc_nids[substream->number + 1]);
3040         return 0;
3041 }
3042
3043
3044 /*
3045  */
3046 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3047         .substreams = 1,
3048         .channels_min = 2,
3049         .channels_max = 8,
3050         /* NID is set in alc_build_pcms */
3051         .ops = {
3052                 .open = alc880_playback_pcm_open,
3053                 .prepare = alc880_playback_pcm_prepare,
3054                 .cleanup = alc880_playback_pcm_cleanup
3055         },
3056 };
3057
3058 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3059         .substreams = 1,
3060         .channels_min = 2,
3061         .channels_max = 2,
3062         /* NID is set in alc_build_pcms */
3063 };
3064
3065 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3066         .substreams = 1,
3067         .channels_min = 2,
3068         .channels_max = 2,
3069         /* NID is set in alc_build_pcms */
3070 };
3071
3072 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3073         .substreams = 2, /* can be overridden */
3074         .channels_min = 2,
3075         .channels_max = 2,
3076         /* NID is set in alc_build_pcms */
3077         .ops = {
3078                 .prepare = alc880_alt_capture_pcm_prepare,
3079                 .cleanup = alc880_alt_capture_pcm_cleanup
3080         },
3081 };
3082
3083 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3084         .substreams = 1,
3085         .channels_min = 2,
3086         .channels_max = 2,
3087         /* NID is set in alc_build_pcms */
3088         .ops = {
3089                 .open = alc880_dig_playback_pcm_open,
3090                 .close = alc880_dig_playback_pcm_close,
3091                 .prepare = alc880_dig_playback_pcm_prepare,
3092                 .cleanup = alc880_dig_playback_pcm_cleanup
3093         },
3094 };
3095
3096 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3097         .substreams = 1,
3098         .channels_min = 2,
3099         .channels_max = 2,
3100         /* NID is set in alc_build_pcms */
3101 };
3102
3103 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3104 static struct hda_pcm_stream alc_pcm_null_stream = {
3105         .substreams = 0,
3106         .channels_min = 0,
3107         .channels_max = 0,
3108 };
3109
3110 static int alc_build_pcms(struct hda_codec *codec)
3111 {
3112         struct alc_spec *spec = codec->spec;
3113         struct hda_pcm *info = spec->pcm_rec;
3114         int i;
3115
3116         codec->num_pcms = 1;
3117         codec->pcm_info = info;
3118
3119         if (spec->no_analog)
3120                 goto skip_analog;
3121
3122         info->name = spec->stream_name_analog;
3123         if (spec->stream_analog_playback) {
3124                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3125                         return -EINVAL;
3126                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3127                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3128         }
3129         if (spec->stream_analog_capture) {
3130                 if (snd_BUG_ON(!spec->adc_nids))
3131                         return -EINVAL;
3132                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3133                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3134         }
3135
3136         if (spec->channel_mode) {
3137                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3138                 for (i = 0; i < spec->num_channel_mode; i++) {
3139                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3140                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3141                         }
3142                 }
3143         }
3144
3145  skip_analog:
3146         /* SPDIF for stream index #1 */
3147         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3148                 codec->num_pcms = 2;
3149                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3150                 info = spec->pcm_rec + 1;
3151                 info->name = spec->stream_name_digital;
3152                 if (spec->dig_out_type)
3153                         info->pcm_type = spec->dig_out_type;
3154                 else
3155                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3156                 if (spec->multiout.dig_out_nid &&
3157                     spec->stream_digital_playback) {
3158                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3159                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3160                 }
3161                 if (spec->dig_in_nid &&
3162                     spec->stream_digital_capture) {
3163                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3164                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3165                 }
3166                 /* FIXME: do we need this for all Realtek codec models? */
3167                 codec->spdif_status_reset = 1;
3168         }
3169
3170         if (spec->no_analog)
3171                 return 0;
3172
3173         /* If the use of more than one ADC is requested for the current
3174          * model, configure a second analog capture-only PCM.
3175          */
3176         /* Additional Analaog capture for index #2 */
3177         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3178             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3179                 codec->num_pcms = 3;
3180                 info = spec->pcm_rec + 2;
3181                 info->name = spec->stream_name_analog;
3182                 if (spec->alt_dac_nid) {
3183                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3184                                 *spec->stream_analog_alt_playback;
3185                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3186                                 spec->alt_dac_nid;
3187                 } else {
3188                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3189                                 alc_pcm_null_stream;
3190                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3191                 }
3192                 if (spec->num_adc_nids > 1) {
3193                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3194                                 *spec->stream_analog_alt_capture;
3195                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3196                                 spec->adc_nids[1];
3197                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3198                                 spec->num_adc_nids - 1;
3199                 } else {
3200                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3201                                 alc_pcm_null_stream;
3202                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3203                 }
3204         }
3205
3206         return 0;
3207 }
3208
3209 static void alc_free_kctls(struct hda_codec *codec)
3210 {
3211         struct alc_spec *spec = codec->spec;
3212
3213         if (spec->kctls.list) {
3214                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3215                 int i;
3216                 for (i = 0; i < spec->kctls.used; i++)
3217                         kfree(kctl[i].name);
3218         }
3219         snd_array_free(&spec->kctls);
3220 }
3221
3222 static void alc_free(struct hda_codec *codec)
3223 {
3224         struct alc_spec *spec = codec->spec;
3225
3226         if (!spec)
3227                 return;
3228
3229         alc_free_kctls(codec);
3230         kfree(spec);
3231         snd_hda_detach_beep_device(codec);
3232 }
3233
3234 #ifdef SND_HDA_NEEDS_RESUME
3235 static int alc_resume(struct hda_codec *codec)
3236 {
3237         codec->patch_ops.init(codec);
3238         snd_hda_codec_resume_amp(codec);
3239         snd_hda_codec_resume_cache(codec);
3240         return 0;
3241 }
3242 #endif
3243
3244 /*
3245  */
3246 static struct hda_codec_ops alc_patch_ops = {
3247         .build_controls = alc_build_controls,
3248         .build_pcms = alc_build_pcms,
3249         .init = alc_init,
3250         .free = alc_free,
3251         .unsol_event = alc_unsol_event,
3252 #ifdef SND_HDA_NEEDS_RESUME
3253         .resume = alc_resume,
3254 #endif
3255 #ifdef CONFIG_SND_HDA_POWER_SAVE
3256         .check_power_status = alc_check_power_status,
3257 #endif
3258 };
3259
3260
3261 /*
3262  * Test configuration for debugging
3263  *
3264  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3265  * enum controls.
3266  */
3267 #ifdef CONFIG_SND_DEBUG
3268 static hda_nid_t alc880_test_dac_nids[4] = {
3269         0x02, 0x03, 0x04, 0x05
3270 };
3271
3272 static struct hda_input_mux alc880_test_capture_source = {
3273         .num_items = 7,
3274         .items = {
3275                 { "In-1", 0x0 },
3276                 { "In-2", 0x1 },
3277                 { "In-3", 0x2 },
3278                 { "In-4", 0x3 },
3279                 { "CD", 0x4 },
3280                 { "Front", 0x5 },
3281                 { "Surround", 0x6 },
3282         },
3283 };
3284
3285 static struct hda_channel_mode alc880_test_modes[4] = {
3286         { 2, NULL },
3287         { 4, NULL },
3288         { 6, NULL },
3289         { 8, NULL },
3290 };
3291
3292 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3293                                  struct snd_ctl_elem_info *uinfo)
3294 {
3295         static char *texts[] = {
3296                 "N/A", "Line Out", "HP Out",
3297                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3298         };
3299         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3300         uinfo->count = 1;
3301         uinfo->value.enumerated.items = 8;
3302         if (uinfo->value.enumerated.item >= 8)
3303                 uinfo->value.enumerated.item = 7;
3304         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3305         return 0;
3306 }
3307
3308 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3309                                 struct snd_ctl_elem_value *ucontrol)
3310 {
3311         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3312         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3313         unsigned int pin_ctl, item = 0;
3314
3315         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3316                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3317         if (pin_ctl & AC_PINCTL_OUT_EN) {
3318                 if (pin_ctl & AC_PINCTL_HP_EN)
3319                         item = 2;
3320                 else
3321                         item = 1;
3322         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3323                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3324                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3325                 case AC_PINCTL_VREF_50:  item = 4; break;
3326                 case AC_PINCTL_VREF_GRD: item = 5; break;
3327                 case AC_PINCTL_VREF_80:  item = 6; break;
3328                 case AC_PINCTL_VREF_100: item = 7; break;
3329                 }
3330         }
3331         ucontrol->value.enumerated.item[0] = item;
3332         return 0;
3333 }
3334
3335 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3336                                 struct snd_ctl_elem_value *ucontrol)
3337 {
3338         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3339         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3340         static unsigned int ctls[] = {
3341                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3342                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3343                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3344                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3345                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3346                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3347         };
3348         unsigned int old_ctl, new_ctl;
3349
3350         old_ctl = snd_hda_codec_read(codec, nid, 0,
3351                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3352         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3353         if (old_ctl != new_ctl) {
3354                 int val;
3355                 snd_hda_codec_write_cache(codec, nid, 0,
3356                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3357                                           new_ctl);
3358                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3359                         HDA_AMP_MUTE : 0;
3360                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3361                                          HDA_AMP_MUTE, val);
3362                 return 1;
3363         }
3364         return 0;
3365 }
3366
3367 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3368                                  struct snd_ctl_elem_info *uinfo)
3369 {
3370         static char *texts[] = {
3371                 "Front", "Surround", "CLFE", "Side"
3372         };
3373         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3374         uinfo->count = 1;
3375         uinfo->value.enumerated.items = 4;
3376         if (uinfo->value.enumerated.item >= 4)
3377                 uinfo->value.enumerated.item = 3;
3378         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3379         return 0;
3380 }
3381
3382 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3383                                 struct snd_ctl_elem_value *ucontrol)
3384 {
3385         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3386         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3387         unsigned int sel;
3388
3389         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3390         ucontrol->value.enumerated.item[0] = sel & 3;
3391         return 0;
3392 }
3393
3394 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3395                                 struct snd_ctl_elem_value *ucontrol)
3396 {
3397         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3398         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3399         unsigned int sel;
3400
3401         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3402         if (ucontrol->value.enumerated.item[0] != sel) {
3403                 sel = ucontrol->value.enumerated.item[0] & 3;
3404                 snd_hda_codec_write_cache(codec, nid, 0,
3405                                           AC_VERB_SET_CONNECT_SEL, sel);
3406                 return 1;
3407         }
3408         return 0;
3409 }
3410
3411 #define PIN_CTL_TEST(xname,nid) {                       \
3412                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3413                         .name = xname,                 \
3414                         .info = alc_test_pin_ctl_info, \
3415                         .get = alc_test_pin_ctl_get,   \
3416                         .put = alc_test_pin_ctl_put,   \
3417                         .private_value = nid           \
3418                         }
3419
3420 #define PIN_SRC_TEST(xname,nid) {                       \
3421                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3422                         .name = xname,                 \
3423                         .info = alc_test_pin_src_info, \
3424                         .get = alc_test_pin_src_get,   \
3425                         .put = alc_test_pin_src_put,   \
3426                         .private_value = nid           \
3427                         }
3428
3429 static struct snd_kcontrol_new alc880_test_mixer[] = {
3430         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3431         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3432         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3433         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3434         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3435         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3436         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3437         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3438         PIN_CTL_TEST("Front Pin Mode", 0x14),
3439         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3440         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3441         PIN_CTL_TEST("Side Pin Mode", 0x17),
3442         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3443         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3444         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3445         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3446         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3447         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3448         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3449         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3450         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3451         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3452         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3453         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3454         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3455         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3456         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3457         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3458         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3459         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3460         {
3461                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3462                 .name = "Channel Mode",
3463                 .info = alc_ch_mode_info,
3464                 .get = alc_ch_mode_get,
3465                 .put = alc_ch_mode_put,
3466         },
3467         { } /* end */
3468 };
3469
3470 static struct hda_verb alc880_test_init_verbs[] = {
3471         /* Unmute inputs of 0x0c - 0x0f */
3472         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3473         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3474         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3475         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3476         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3477         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3478         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3479         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3480         /* Vol output for 0x0c-0x0f */
3481         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3482         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3483         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3484         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3485         /* Set output pins 0x14-0x17 */
3486         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3487         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3488         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3489         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3490         /* Unmute output pins 0x14-0x17 */
3491         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3492         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3493         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3494         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3495         /* Set input pins 0x18-0x1c */
3496         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3497         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3498         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3499         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3500         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3501         /* Mute input pins 0x18-0x1b */
3502         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3503         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3504         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3505         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3506         /* ADC set up */
3507         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3508         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3509         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3510         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3511         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3512         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3513         /* Analog input/passthru */
3514         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3515         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3516         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3517         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3518         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3519         { }
3520 };
3521 #endif
3522
3523 /*
3524  */
3525
3526 static const char *alc880_models[ALC880_MODEL_LAST] = {
3527         [ALC880_3ST]            = "3stack",
3528         [ALC880_TCL_S700]       = "tcl",
3529         [ALC880_3ST_DIG]        = "3stack-digout",
3530         [ALC880_CLEVO]          = "clevo",
3531         [ALC880_5ST]            = "5stack",
3532         [ALC880_5ST_DIG]        = "5stack-digout",
3533         [ALC880_W810]           = "w810",
3534         [ALC880_Z71V]           = "z71v",
3535         [ALC880_6ST]            = "6stack",
3536         [ALC880_6ST_DIG]        = "6stack-digout",
3537         [ALC880_ASUS]           = "asus",
3538         [ALC880_ASUS_W1V]       = "asus-w1v",
3539         [ALC880_ASUS_DIG]       = "asus-dig",
3540         [ALC880_ASUS_DIG2]      = "asus-dig2",
3541         [ALC880_UNIWILL_DIG]    = "uniwill",
3542         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3543         [ALC880_FUJITSU]        = "fujitsu",
3544         [ALC880_F1734]          = "F1734",
3545         [ALC880_LG]             = "lg",
3546         [ALC880_LG_LW]          = "lg-lw",
3547         [ALC880_MEDION_RIM]     = "medion",
3548 #ifdef CONFIG_SND_DEBUG
3549         [ALC880_TEST]           = "test",
3550 #endif
3551         [ALC880_AUTO]           = "auto",
3552 };
3553
3554 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3555         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3556         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3557         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3558         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3559         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3560         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3561         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3562         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3563         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3564         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3565         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3566         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3567         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3568         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3569         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3570         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3571         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3572         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3573         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3574         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3575         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3576         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3577         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3578         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3579         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3580         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
3581         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3582         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3583         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3584         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3585         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3586         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3587         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3588         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3589         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3590         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3591         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3592         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3593         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3594         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3595         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3596         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3597         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3598         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3599         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3600         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3601         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3602         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3603         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3604         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3605         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3606         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3607         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3608         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3609         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3610         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3611         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3612         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3613         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3614         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3615         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3616         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3617         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3618         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3619         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3620         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3621         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3622         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3623         /* default Intel */
3624         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
3625         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3626         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3627         {}
3628 };
3629
3630 /*
3631  * ALC880 codec presets
3632  */
3633 static struct alc_config_preset alc880_presets[] = {
3634         [ALC880_3ST] = {
3635                 .mixers = { alc880_three_stack_mixer },
3636                 .init_verbs = { alc880_volume_init_verbs,
3637                                 alc880_pin_3stack_init_verbs },
3638                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3639                 .dac_nids = alc880_dac_nids,
3640                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3641                 .channel_mode = alc880_threestack_modes,
3642                 .need_dac_fix = 1,
3643                 .input_mux = &alc880_capture_source,
3644         },
3645         [ALC880_3ST_DIG] = {
3646                 .mixers = { alc880_three_stack_mixer },
3647                 .init_verbs = { alc880_volume_init_verbs,
3648                                 alc880_pin_3stack_init_verbs },
3649                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3650                 .dac_nids = alc880_dac_nids,
3651                 .dig_out_nid = ALC880_DIGOUT_NID,
3652                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3653                 .channel_mode = alc880_threestack_modes,
3654                 .need_dac_fix = 1,
3655                 .input_mux = &alc880_capture_source,
3656         },
3657         [ALC880_TCL_S700] = {
3658                 .mixers = { alc880_tcl_s700_mixer },
3659                 .init_verbs = { alc880_volume_init_verbs,
3660                                 alc880_pin_tcl_S700_init_verbs,
3661                                 alc880_gpio2_init_verbs },
3662                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3663                 .dac_nids = alc880_dac_nids,
3664                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3665                 .num_adc_nids = 1, /* single ADC */
3666                 .hp_nid = 0x03,
3667                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3668                 .channel_mode = alc880_2_jack_modes,
3669                 .input_mux = &alc880_capture_source,
3670         },
3671         [ALC880_5ST] = {
3672                 .mixers = { alc880_three_stack_mixer,
3673                             alc880_five_stack_mixer},
3674                 .init_verbs = { alc880_volume_init_verbs,
3675                                 alc880_pin_5stack_init_verbs },
3676                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3677                 .dac_nids = alc880_dac_nids,
3678                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3679                 .channel_mode = alc880_fivestack_modes,
3680                 .input_mux = &alc880_capture_source,
3681         },
3682         [ALC880_5ST_DIG] = {
3683                 .mixers = { alc880_three_stack_mixer,
3684                             alc880_five_stack_mixer },
3685                 .init_verbs = { alc880_volume_init_verbs,
3686                                 alc880_pin_5stack_init_verbs },
3687                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3688                 .dac_nids = alc880_dac_nids,
3689                 .dig_out_nid = ALC880_DIGOUT_NID,
3690                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3691                 .channel_mode = alc880_fivestack_modes,
3692                 .input_mux = &alc880_capture_source,
3693         },
3694         [ALC880_6ST] = {
3695                 .mixers = { alc880_six_stack_mixer },
3696                 .init_verbs = { alc880_volume_init_verbs,
3697                                 alc880_pin_6stack_init_verbs },
3698                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3699                 .dac_nids = alc880_6st_dac_nids,
3700                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3701                 .channel_mode = alc880_sixstack_modes,
3702                 .input_mux = &alc880_6stack_capture_source,
3703         },
3704         [ALC880_6ST_DIG] = {
3705                 .mixers = { alc880_six_stack_mixer },
3706                 .init_verbs = { alc880_volume_init_verbs,
3707                                 alc880_pin_6stack_init_verbs },
3708                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3709                 .dac_nids = alc880_6st_dac_nids,
3710                 .dig_out_nid = ALC880_DIGOUT_NID,
3711                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3712                 .channel_mode = alc880_sixstack_modes,
3713                 .input_mux = &alc880_6stack_capture_source,
3714         },
3715         [ALC880_W810] = {
3716                 .mixers = { alc880_w810_base_mixer },
3717                 .init_verbs = { alc880_volume_init_verbs,
3718                                 alc880_pin_w810_init_verbs,
3719                                 alc880_gpio2_init_verbs },
3720                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3721                 .dac_nids = alc880_w810_dac_nids,
3722                 .dig_out_nid = ALC880_DIGOUT_NID,
3723                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3724                 .channel_mode = alc880_w810_modes,
3725                 .input_mux = &alc880_capture_source,
3726         },
3727         [ALC880_Z71V] = {
3728                 .mixers = { alc880_z71v_mixer },
3729                 .init_verbs = { alc880_volume_init_verbs,
3730                                 alc880_pin_z71v_init_verbs },
3731                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3732                 .dac_nids = alc880_z71v_dac_nids,
3733                 .dig_out_nid = ALC880_DIGOUT_NID,
3734                 .hp_nid = 0x03,
3735                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3736                 .channel_mode = alc880_2_jack_modes,
3737                 .input_mux = &alc880_capture_source,
3738         },
3739         [ALC880_F1734] = {
3740                 .mixers = { alc880_f1734_mixer },
3741                 .init_verbs = { alc880_volume_init_verbs,
3742                                 alc880_pin_f1734_init_verbs },
3743                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3744                 .dac_nids = alc880_f1734_dac_nids,
3745                 .hp_nid = 0x02,
3746                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3747                 .channel_mode = alc880_2_jack_modes,
3748                 .input_mux = &alc880_f1734_capture_source,
3749                 .unsol_event = alc880_uniwill_p53_unsol_event,
3750                 .init_hook = alc880_uniwill_p53_hp_automute,
3751         },
3752         [ALC880_ASUS] = {
3753                 .mixers = { alc880_asus_mixer },
3754                 .init_verbs = { alc880_volume_init_verbs,
3755                                 alc880_pin_asus_init_verbs,
3756                                 alc880_gpio1_init_verbs },
3757                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3758                 .dac_nids = alc880_asus_dac_nids,
3759                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3760                 .channel_mode = alc880_asus_modes,
3761                 .need_dac_fix = 1,
3762                 .input_mux = &alc880_capture_source,
3763         },
3764         [ALC880_ASUS_DIG] = {
3765                 .mixers = { alc880_asus_mixer },
3766                 .init_verbs = { alc880_volume_init_verbs,
3767                                 alc880_pin_asus_init_verbs,
3768                                 alc880_gpio1_init_verbs },
3769                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3770                 .dac_nids = alc880_asus_dac_nids,