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