1a7703a496556b14f41324d49dbb68bebf59d2ef
[linux-2.6.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include <sound/jack.h>
32 #include "hda_codec.h"
33 #include "hda_local.h"
34 #include "hda_beep.h"
35
36 #define ALC880_FRONT_EVENT              0x01
37 #define ALC880_DCVOL_EVENT              0x02
38 #define ALC880_HP_EVENT                 0x04
39 #define ALC880_MIC_EVENT                0x08
40
41 /* ALC880 board config type */
42 enum {
43         ALC880_3ST,
44         ALC880_3ST_DIG,
45         ALC880_5ST,
46         ALC880_5ST_DIG,
47         ALC880_W810,
48         ALC880_Z71V,
49         ALC880_6ST,
50         ALC880_6ST_DIG,
51         ALC880_F1734,
52         ALC880_ASUS,
53         ALC880_ASUS_DIG,
54         ALC880_ASUS_W1V,
55         ALC880_ASUS_DIG2,
56         ALC880_FUJITSU,
57         ALC880_UNIWILL_DIG,
58         ALC880_UNIWILL,
59         ALC880_UNIWILL_P53,
60         ALC880_CLEVO,
61         ALC880_TCL_S700,
62         ALC880_LG,
63         ALC880_LG_LW,
64         ALC880_MEDION_RIM,
65 #ifdef CONFIG_SND_DEBUG
66         ALC880_TEST,
67 #endif
68         ALC880_AUTO,
69         ALC880_MODEL_LAST /* last tag */
70 };
71
72 /* ALC260 models */
73 enum {
74         ALC260_BASIC,
75         ALC260_HP,
76         ALC260_HP_DC7600,
77         ALC260_HP_3013,
78         ALC260_FUJITSU_S702X,
79         ALC260_ACER,
80         ALC260_WILL,
81         ALC260_REPLACER_672V,
82         ALC260_FAVORIT100,
83 #ifdef CONFIG_SND_DEBUG
84         ALC260_TEST,
85 #endif
86         ALC260_AUTO,
87         ALC260_MODEL_LAST /* last tag */
88 };
89
90 /* ALC262 models */
91 enum {
92         ALC262_BASIC,
93         ALC262_HIPPO,
94         ALC262_HIPPO_1,
95         ALC262_FUJITSU,
96         ALC262_HP_BPC,
97         ALC262_HP_BPC_D7000_WL,
98         ALC262_HP_BPC_D7000_WF,
99         ALC262_HP_TC_T5735,
100         ALC262_HP_RP5700,
101         ALC262_BENQ_ED8,
102         ALC262_SONY_ASSAMD,
103         ALC262_BENQ_T31,
104         ALC262_ULTRA,
105         ALC262_LENOVO_3000,
106         ALC262_NEC,
107         ALC262_TOSHIBA_S06,
108         ALC262_TOSHIBA_RX1,
109         ALC262_TYAN,
110         ALC262_AUTO,
111         ALC262_MODEL_LAST /* last tag */
112 };
113
114 /* ALC268 models */
115 enum {
116         ALC267_QUANTA_IL1,
117         ALC268_3ST,
118         ALC268_TOSHIBA,
119         ALC268_ACER,
120         ALC268_ACER_DMIC,
121         ALC268_ACER_ASPIRE_ONE,
122         ALC268_DELL,
123         ALC268_ZEPTO,
124 #ifdef CONFIG_SND_DEBUG
125         ALC268_TEST,
126 #endif
127         ALC268_AUTO,
128         ALC268_MODEL_LAST /* last tag */
129 };
130
131 /* ALC269 models */
132 enum {
133         ALC269_BASIC,
134         ALC269_QUANTA_FL1,
135         ALC269_AMIC,
136         ALC269_DMIC,
137         ALC269VB_AMIC,
138         ALC269VB_DMIC,
139         ALC269_FUJITSU,
140         ALC269_LIFEBOOK,
141         ALC271_ACER,
142         ALC269_AUTO,
143         ALC269_MODEL_LAST /* last tag */
144 };
145
146 /* ALC861 models */
147 enum {
148         ALC861_3ST,
149         ALC660_3ST,
150         ALC861_3ST_DIG,
151         ALC861_6ST_DIG,
152         ALC861_UNIWILL_M31,
153         ALC861_TOSHIBA,
154         ALC861_ASUS,
155         ALC861_ASUS_LAPTOP,
156         ALC861_AUTO,
157         ALC861_MODEL_LAST,
158 };
159
160 /* ALC861-VD models */
161 enum {
162         ALC660VD_3ST,
163         ALC660VD_3ST_DIG,
164         ALC660VD_ASUS_V1S,
165         ALC861VD_3ST,
166         ALC861VD_3ST_DIG,
167         ALC861VD_6ST_DIG,
168         ALC861VD_LENOVO,
169         ALC861VD_DALLAS,
170         ALC861VD_HP,
171         ALC861VD_AUTO,
172         ALC861VD_MODEL_LAST,
173 };
174
175 /* ALC662 models */
176 enum {
177         ALC662_3ST_2ch_DIG,
178         ALC662_3ST_6ch_DIG,
179         ALC662_3ST_6ch,
180         ALC662_5ST_DIG,
181         ALC662_LENOVO_101E,
182         ALC662_ASUS_EEEPC_P701,
183         ALC662_ASUS_EEEPC_EP20,
184         ALC663_ASUS_M51VA,
185         ALC663_ASUS_G71V,
186         ALC663_ASUS_H13,
187         ALC663_ASUS_G50V,
188         ALC662_ECS,
189         ALC663_ASUS_MODE1,
190         ALC662_ASUS_MODE2,
191         ALC663_ASUS_MODE3,
192         ALC663_ASUS_MODE4,
193         ALC663_ASUS_MODE5,
194         ALC663_ASUS_MODE6,
195         ALC663_ASUS_MODE7,
196         ALC663_ASUS_MODE8,
197         ALC272_DELL,
198         ALC272_DELL_ZM1,
199         ALC272_SAMSUNG_NC10,
200         ALC662_AUTO,
201         ALC662_MODEL_LAST,
202 };
203
204 /* ALC882 models */
205 enum {
206         ALC882_3ST_DIG,
207         ALC882_6ST_DIG,
208         ALC882_ARIMA,
209         ALC882_W2JC,
210         ALC882_TARGA,
211         ALC882_ASUS_A7J,
212         ALC882_ASUS_A7M,
213         ALC885_MACPRO,
214         ALC885_MBA21,
215         ALC885_MBP3,
216         ALC885_MB5,
217         ALC885_MACMINI3,
218         ALC885_IMAC24,
219         ALC885_IMAC91,
220         ALC883_3ST_2ch_DIG,
221         ALC883_3ST_6ch_DIG,
222         ALC883_3ST_6ch,
223         ALC883_6ST_DIG,
224         ALC883_TARGA_DIG,
225         ALC883_TARGA_2ch_DIG,
226         ALC883_TARGA_8ch_DIG,
227         ALC883_ACER,
228         ALC883_ACER_ASPIRE,
229         ALC888_ACER_ASPIRE_4930G,
230         ALC888_ACER_ASPIRE_6530G,
231         ALC888_ACER_ASPIRE_8930G,
232         ALC888_ACER_ASPIRE_7730G,
233         ALC883_MEDION,
234         ALC883_MEDION_MD2,
235         ALC883_MEDION_WIM2160,
236         ALC883_LAPTOP_EAPD,
237         ALC883_LENOVO_101E_2ch,
238         ALC883_LENOVO_NB0763,
239         ALC888_LENOVO_MS7195_DIG,
240         ALC888_LENOVO_SKY,
241         ALC883_HAIER_W66,
242         ALC888_3ST_HP,
243         ALC888_6ST_DELL,
244         ALC883_MITAC,
245         ALC883_CLEVO_M540R,
246         ALC883_CLEVO_M720,
247         ALC883_FUJITSU_PI2515,
248         ALC888_FUJITSU_XA3530,
249         ALC883_3ST_6ch_INTEL,
250         ALC889A_INTEL,
251         ALC889_INTEL,
252         ALC888_ASUS_M90V,
253         ALC888_ASUS_EEE1601,
254         ALC889A_MB31,
255         ALC1200_ASUS_P5Q,
256         ALC883_SONY_VAIO_TT,
257         ALC882_AUTO,
258         ALC882_MODEL_LAST,
259 };
260
261 /* ALC680 models */
262 enum {
263         ALC680_BASE,
264         ALC680_AUTO,
265         ALC680_MODEL_LAST,
266 };
267
268 /* for GPIO Poll */
269 #define GPIO_MASK       0x03
270
271 /* extra amp-initialization sequence types */
272 enum {
273         ALC_INIT_NONE,
274         ALC_INIT_DEFAULT,
275         ALC_INIT_GPIO1,
276         ALC_INIT_GPIO2,
277         ALC_INIT_GPIO3,
278 };
279
280 struct alc_mic_route {
281         hda_nid_t pin;
282         unsigned char mux_idx;
283         unsigned char amix_idx;
284 };
285
286 struct alc_jack {
287         hda_nid_t nid;
288         int type;
289         struct snd_jack *jack;
290 };
291
292 #define MUX_IDX_UNDEF   ((unsigned char)-1)
293
294 struct alc_customize_define {
295         unsigned int  sku_cfg;
296         unsigned char port_connectivity;
297         unsigned char check_sum;
298         unsigned char customization;
299         unsigned char external_amp;
300         unsigned int  enable_pcbeep:1;
301         unsigned int  platform_type:1;
302         unsigned int  swap:1;
303         unsigned int  override:1;
304         unsigned int  fixup:1; /* Means that this sku is set by driver, not read from hw */
305 };
306
307 struct alc_spec {
308         /* codec parameterization */
309         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
310         unsigned int num_mixers;
311         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
312         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
313
314         const struct hda_verb *init_verbs[10];  /* initialization verbs
315                                                  * don't forget NULL
316                                                  * termination!
317                                                  */
318         unsigned int num_init_verbs;
319
320         char stream_name_analog[32];    /* analog PCM stream */
321         struct hda_pcm_stream *stream_analog_playback;
322         struct hda_pcm_stream *stream_analog_capture;
323         struct hda_pcm_stream *stream_analog_alt_playback;
324         struct hda_pcm_stream *stream_analog_alt_capture;
325
326         char stream_name_digital[32];   /* digital PCM stream */
327         struct hda_pcm_stream *stream_digital_playback;
328         struct hda_pcm_stream *stream_digital_capture;
329
330         /* playback */
331         struct hda_multi_out multiout;  /* playback set-up
332                                          * max_channels, dacs must be set
333                                          * dig_out_nid and hp_nid are optional
334                                          */
335         hda_nid_t alt_dac_nid;
336         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
337         int dig_out_type;
338
339         /* capture */
340         unsigned int num_adc_nids;
341         hda_nid_t *adc_nids;
342         hda_nid_t *capsrc_nids;
343         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
344
345         /* capture setup for dynamic dual-adc switch */
346         unsigned int cur_adc_idx;
347         hda_nid_t cur_adc;
348         unsigned int cur_adc_stream_tag;
349         unsigned int cur_adc_format;
350
351         /* capture source */
352         unsigned int num_mux_defs;
353         const struct hda_input_mux *input_mux;
354         unsigned int cur_mux[3];
355         struct alc_mic_route ext_mic;
356         struct alc_mic_route int_mic;
357
358         /* channel model */
359         const struct hda_channel_mode *channel_mode;
360         int num_channel_mode;
361         int need_dac_fix;
362         int const_channel_count;
363         int ext_channel_count;
364
365         /* PCM information */
366         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
367
368         /* jack detection */
369         struct snd_array jacks;
370
371         /* dynamic controls, init_verbs and input_mux */
372         struct auto_pin_cfg autocfg;
373         struct alc_customize_define cdefine;
374         struct snd_array kctls;
375         struct hda_input_mux private_imux[3];
376         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
377         hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
378         hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
379
380         /* hooks */
381         void (*init_hook)(struct hda_codec *codec);
382         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
383 #ifdef CONFIG_SND_HDA_POWER_SAVE
384         void (*power_hook)(struct hda_codec *codec);
385 #endif
386
387         /* for pin sensing */
388         unsigned int sense_updated: 1;
389         unsigned int jack_present: 1;
390         unsigned int master_sw: 1;
391         unsigned int auto_mic:1;
392
393         /* other flags */
394         unsigned int no_analog :1; /* digital I/O only */
395         unsigned int dual_adc_switch:1; /* switch ADCs (for ALC275) */
396         int init_amp;
397         int codec_variant;      /* flag for other variants */
398
399         /* for virtual master */
400         hda_nid_t vmaster_nid;
401 #ifdef CONFIG_SND_HDA_POWER_SAVE
402         struct hda_loopback_check loopback;
403 #endif
404
405         /* for PLL fix */
406         hda_nid_t pll_nid;
407         unsigned int pll_coef_idx, pll_coef_bit;
408 };
409
410 /*
411  * configuration template - to be copied to the spec instance
412  */
413 struct alc_config_preset {
414         struct snd_kcontrol_new *mixers[5]; /* should be identical size
415                                              * with spec
416                                              */
417         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
418         const struct hda_verb *init_verbs[5];
419         unsigned int num_dacs;
420         hda_nid_t *dac_nids;
421         hda_nid_t dig_out_nid;          /* optional */
422         hda_nid_t hp_nid;               /* optional */
423         hda_nid_t *slave_dig_outs;
424         unsigned int num_adc_nids;
425         hda_nid_t *adc_nids;
426         hda_nid_t *capsrc_nids;
427         hda_nid_t dig_in_nid;
428         unsigned int num_channel_mode;
429         const struct hda_channel_mode *channel_mode;
430         int need_dac_fix;
431         int const_channel_count;
432         unsigned int num_mux_defs;
433         const struct hda_input_mux *input_mux;
434         void (*unsol_event)(struct hda_codec *, unsigned int);
435         void (*setup)(struct hda_codec *);
436         void (*init_hook)(struct hda_codec *);
437 #ifdef CONFIG_SND_HDA_POWER_SAVE
438         struct hda_amp_list *loopbacks;
439         void (*power_hook)(struct hda_codec *codec);
440 #endif
441 };
442
443
444 /*
445  * input MUX handling
446  */
447 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
448                              struct snd_ctl_elem_info *uinfo)
449 {
450         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
451         struct alc_spec *spec = codec->spec;
452         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
453         if (mux_idx >= spec->num_mux_defs)
454                 mux_idx = 0;
455         if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
456                 mux_idx = 0;
457         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
458 }
459
460 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
461                             struct snd_ctl_elem_value *ucontrol)
462 {
463         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
464         struct alc_spec *spec = codec->spec;
465         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
466
467         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
468         return 0;
469 }
470
471 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
472                             struct snd_ctl_elem_value *ucontrol)
473 {
474         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
475         struct alc_spec *spec = codec->spec;
476         const struct hda_input_mux *imux;
477         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
478         unsigned int mux_idx;
479         hda_nid_t nid = spec->capsrc_nids ?
480                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
481         unsigned int type;
482
483         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
484         imux = &spec->input_mux[mux_idx];
485         if (!imux->num_items && mux_idx > 0)
486                 imux = &spec->input_mux[0];
487
488         type = get_wcaps_type(get_wcaps(codec, nid));
489         if (type == AC_WID_AUD_MIX) {
490                 /* Matrix-mixer style (e.g. ALC882) */
491                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
492                 unsigned int i, idx;
493
494                 idx = ucontrol->value.enumerated.item[0];
495                 if (idx >= imux->num_items)
496                         idx = imux->num_items - 1;
497                 if (*cur_val == idx)
498                         return 0;
499                 for (i = 0; i < imux->num_items; i++) {
500                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
501                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
502                                                  imux->items[i].index,
503                                                  HDA_AMP_MUTE, v);
504                 }
505                 *cur_val = idx;
506                 return 1;
507         } else {
508                 /* MUX style (e.g. ALC880) */
509                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
510                                              &spec->cur_mux[adc_idx]);
511         }
512 }
513
514 /*
515  * channel mode setting
516  */
517 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
518                             struct snd_ctl_elem_info *uinfo)
519 {
520         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
521         struct alc_spec *spec = codec->spec;
522         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
523                                     spec->num_channel_mode);
524 }
525
526 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
527                            struct snd_ctl_elem_value *ucontrol)
528 {
529         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
530         struct alc_spec *spec = codec->spec;
531         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
532                                    spec->num_channel_mode,
533                                    spec->ext_channel_count);
534 }
535
536 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
537                            struct snd_ctl_elem_value *ucontrol)
538 {
539         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
540         struct alc_spec *spec = codec->spec;
541         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
542                                       spec->num_channel_mode,
543                                       &spec->ext_channel_count);
544         if (err >= 0 && !spec->const_channel_count) {
545                 spec->multiout.max_channels = spec->ext_channel_count;
546                 if (spec->need_dac_fix)
547                         spec->multiout.num_dacs = spec->multiout.max_channels / 2;
548         }
549         return err;
550 }
551
552 /*
553  * Control the mode of pin widget settings via the mixer.  "pc" is used
554  * instead of "%" to avoid consequences of accidently treating the % as
555  * being part of a format specifier.  Maximum allowed length of a value is
556  * 63 characters plus NULL terminator.
557  *
558  * Note: some retasking pin complexes seem to ignore requests for input
559  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
560  * are requested.  Therefore order this list so that this behaviour will not
561  * cause problems when mixer clients move through the enum sequentially.
562  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
563  * March 2006.
564  */
565 static char *alc_pin_mode_names[] = {
566         "Mic 50pc bias", "Mic 80pc bias",
567         "Line in", "Line out", "Headphone out",
568 };
569 static unsigned char alc_pin_mode_values[] = {
570         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
571 };
572 /* The control can present all 5 options, or it can limit the options based
573  * in the pin being assumed to be exclusively an input or an output pin.  In
574  * addition, "input" pins may or may not process the mic bias option
575  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
576  * accept requests for bias as of chip versions up to March 2006) and/or
577  * wiring in the computer.
578  */
579 #define ALC_PIN_DIR_IN              0x00
580 #define ALC_PIN_DIR_OUT             0x01
581 #define ALC_PIN_DIR_INOUT           0x02
582 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
583 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
584
585 /* Info about the pin modes supported by the different pin direction modes.
586  * For each direction the minimum and maximum values are given.
587  */
588 static signed char alc_pin_mode_dir_info[5][2] = {
589         { 0, 2 },    /* ALC_PIN_DIR_IN */
590         { 3, 4 },    /* ALC_PIN_DIR_OUT */
591         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
592         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
593         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
594 };
595 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
596 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
597 #define alc_pin_mode_n_items(_dir) \
598         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
599
600 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
601                              struct snd_ctl_elem_info *uinfo)
602 {
603         unsigned int item_num = uinfo->value.enumerated.item;
604         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
605
606         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
607         uinfo->count = 1;
608         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
609
610         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
611                 item_num = alc_pin_mode_min(dir);
612         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
613         return 0;
614 }
615
616 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
617                             struct snd_ctl_elem_value *ucontrol)
618 {
619         unsigned int i;
620         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
621         hda_nid_t nid = kcontrol->private_value & 0xffff;
622         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
623         long *valp = ucontrol->value.integer.value;
624         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
625                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
626                                                  0x00);
627
628         /* Find enumerated value for current pinctl setting */
629         i = alc_pin_mode_min(dir);
630         while (i <= alc_pin_mode_max(dir) && alc_pin_mode_values[i] != pinctl)
631                 i++;
632         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
633         return 0;
634 }
635
636 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
637                             struct snd_ctl_elem_value *ucontrol)
638 {
639         signed int change;
640         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
641         hda_nid_t nid = kcontrol->private_value & 0xffff;
642         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
643         long val = *ucontrol->value.integer.value;
644         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
645                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
646                                                  0x00);
647
648         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
649                 val = alc_pin_mode_min(dir);
650
651         change = pinctl != alc_pin_mode_values[val];
652         if (change) {
653                 /* Set pin mode to that requested */
654                 snd_hda_codec_write_cache(codec, nid, 0,
655                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
656                                           alc_pin_mode_values[val]);
657
658                 /* Also enable the retasking pin's input/output as required
659                  * for the requested pin mode.  Enum values of 2 or less are
660                  * input modes.
661                  *
662                  * Dynamically switching the input/output buffers probably
663                  * reduces noise slightly (particularly on input) so we'll
664                  * do it.  However, having both input and output buffers
665                  * enabled simultaneously doesn't seem to be problematic if
666                  * this turns out to be necessary in the future.
667                  */
668                 if (val <= 2) {
669                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
670                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
671                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
672                                                  HDA_AMP_MUTE, 0);
673                 } else {
674                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
675                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
676                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
677                                                  HDA_AMP_MUTE, 0);
678                 }
679         }
680         return change;
681 }
682
683 #define ALC_PIN_MODE(xname, nid, dir) \
684         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
685           .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
686           .info = alc_pin_mode_info, \
687           .get = alc_pin_mode_get, \
688           .put = alc_pin_mode_put, \
689           .private_value = nid | (dir<<16) }
690
691 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
692  * together using a mask with more than one bit set.  This control is
693  * currently used only by the ALC260 test model.  At this stage they are not
694  * needed for any "production" models.
695  */
696 #ifdef CONFIG_SND_DEBUG
697 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
698
699 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
700                              struct snd_ctl_elem_value *ucontrol)
701 {
702         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
703         hda_nid_t nid = kcontrol->private_value & 0xffff;
704         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
705         long *valp = ucontrol->value.integer.value;
706         unsigned int val = snd_hda_codec_read(codec, nid, 0,
707                                               AC_VERB_GET_GPIO_DATA, 0x00);
708
709         *valp = (val & mask) != 0;
710         return 0;
711 }
712 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
713                              struct snd_ctl_elem_value *ucontrol)
714 {
715         signed int change;
716         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
717         hda_nid_t nid = kcontrol->private_value & 0xffff;
718         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
719         long val = *ucontrol->value.integer.value;
720         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
721                                                     AC_VERB_GET_GPIO_DATA,
722                                                     0x00);
723
724         /* Set/unset the masked GPIO bit(s) as needed */
725         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
726         if (val == 0)
727                 gpio_data &= ~mask;
728         else
729                 gpio_data |= mask;
730         snd_hda_codec_write_cache(codec, nid, 0,
731                                   AC_VERB_SET_GPIO_DATA, gpio_data);
732
733         return change;
734 }
735 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
736         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
737           .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
738           .info = alc_gpio_data_info, \
739           .get = alc_gpio_data_get, \
740           .put = alc_gpio_data_put, \
741           .private_value = nid | (mask<<16) }
742 #endif   /* CONFIG_SND_DEBUG */
743
744 /* A switch control to allow the enabling of the digital IO pins on the
745  * ALC260.  This is incredibly simplistic; the intention of this control is
746  * to provide something in the test model allowing digital outputs to be
747  * identified if present.  If models are found which can utilise these
748  * outputs a more complete mixer control can be devised for those models if
749  * necessary.
750  */
751 #ifdef CONFIG_SND_DEBUG
752 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
753
754 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
755                               struct snd_ctl_elem_value *ucontrol)
756 {
757         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
758         hda_nid_t nid = kcontrol->private_value & 0xffff;
759         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
760         long *valp = ucontrol->value.integer.value;
761         unsigned int val = snd_hda_codec_read(codec, nid, 0,
762                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
763
764         *valp = (val & mask) != 0;
765         return 0;
766 }
767 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
768                               struct snd_ctl_elem_value *ucontrol)
769 {
770         signed int change;
771         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
772         hda_nid_t nid = kcontrol->private_value & 0xffff;
773         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
774         long val = *ucontrol->value.integer.value;
775         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
776                                                     AC_VERB_GET_DIGI_CONVERT_1,
777                                                     0x00);
778
779         /* Set/unset the masked control bit(s) as needed */
780         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
781         if (val==0)
782                 ctrl_data &= ~mask;
783         else
784                 ctrl_data |= mask;
785         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
786                                   ctrl_data);
787
788         return change;
789 }
790 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
791         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
792           .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
793           .info = alc_spdif_ctrl_info, \
794           .get = alc_spdif_ctrl_get, \
795           .put = alc_spdif_ctrl_put, \
796           .private_value = nid | (mask<<16) }
797 #endif   /* CONFIG_SND_DEBUG */
798
799 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
800  * Again, this is only used in the ALC26x test models to help identify when
801  * the EAPD line must be asserted for features to work.
802  */
803 #ifdef CONFIG_SND_DEBUG
804 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
805
806 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
807                               struct snd_ctl_elem_value *ucontrol)
808 {
809         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
810         hda_nid_t nid = kcontrol->private_value & 0xffff;
811         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
812         long *valp = ucontrol->value.integer.value;
813         unsigned int val = snd_hda_codec_read(codec, nid, 0,
814                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
815
816         *valp = (val & mask) != 0;
817         return 0;
818 }
819
820 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
821                               struct snd_ctl_elem_value *ucontrol)
822 {
823         int change;
824         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
825         hda_nid_t nid = kcontrol->private_value & 0xffff;
826         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
827         long val = *ucontrol->value.integer.value;
828         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
829                                                     AC_VERB_GET_EAPD_BTLENABLE,
830                                                     0x00);
831
832         /* Set/unset the masked control bit(s) as needed */
833         change = (!val ? 0 : mask) != (ctrl_data & mask);
834         if (!val)
835                 ctrl_data &= ~mask;
836         else
837                 ctrl_data |= mask;
838         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
839                                   ctrl_data);
840
841         return change;
842 }
843
844 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
845         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
846           .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
847           .info = alc_eapd_ctrl_info, \
848           .get = alc_eapd_ctrl_get, \
849           .put = alc_eapd_ctrl_put, \
850           .private_value = nid | (mask<<16) }
851 #endif   /* CONFIG_SND_DEBUG */
852
853 /*
854  * set up the input pin config (depending on the given auto-pin type)
855  */
856 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
857                               int auto_pin_type)
858 {
859         unsigned int val = PIN_IN;
860
861         if (auto_pin_type == AUTO_PIN_MIC) {
862                 unsigned int pincap;
863                 unsigned int oldval;
864                 oldval = snd_hda_codec_read(codec, nid, 0,
865                                             AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
866                 pincap = snd_hda_query_pin_caps(codec, nid);
867                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
868                 /* if the default pin setup is vref50, we give it priority */
869                 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
870                         val = PIN_VREF80;
871                 else if (pincap & AC_PINCAP_VREF_50)
872                         val = PIN_VREF50;
873                 else if (pincap & AC_PINCAP_VREF_100)
874                         val = PIN_VREF100;
875                 else if (pincap & AC_PINCAP_VREF_GRD)
876                         val = PIN_VREFGRD;
877         }
878         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
879 }
880
881 static void alc_fixup_autocfg_pin_nums(struct hda_codec *codec)
882 {
883         struct alc_spec *spec = codec->spec;
884         struct auto_pin_cfg *cfg = &spec->autocfg;
885
886         if (!cfg->line_outs) {
887                 while (cfg->line_outs < AUTO_CFG_MAX_OUTS &&
888                        cfg->line_out_pins[cfg->line_outs])
889                         cfg->line_outs++;
890         }
891         if (!cfg->speaker_outs) {
892                 while (cfg->speaker_outs < AUTO_CFG_MAX_OUTS &&
893                        cfg->speaker_pins[cfg->speaker_outs])
894                         cfg->speaker_outs++;
895         }
896         if (!cfg->hp_outs) {
897                 while (cfg->hp_outs < AUTO_CFG_MAX_OUTS &&
898                        cfg->hp_pins[cfg->hp_outs])
899                         cfg->hp_outs++;
900         }
901 }
902
903 /*
904  */
905 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
906 {
907         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
908                 return;
909         spec->mixers[spec->num_mixers++] = mix;
910 }
911
912 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
913 {
914         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
915                 return;
916         spec->init_verbs[spec->num_init_verbs++] = verb;
917 }
918
919 /*
920  * set up from the preset table
921  */
922 static void setup_preset(struct hda_codec *codec,
923                          const struct alc_config_preset *preset)
924 {
925         struct alc_spec *spec = codec->spec;
926         int i;
927
928         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
929                 add_mixer(spec, preset->mixers[i]);
930         spec->cap_mixer = preset->cap_mixer;
931         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
932              i++)
933                 add_verb(spec, preset->init_verbs[i]);
934
935         spec->channel_mode = preset->channel_mode;
936         spec->num_channel_mode = preset->num_channel_mode;
937         spec->need_dac_fix = preset->need_dac_fix;
938         spec->const_channel_count = preset->const_channel_count;
939
940         if (preset->const_channel_count)
941                 spec->multiout.max_channels = preset->const_channel_count;
942         else
943                 spec->multiout.max_channels = spec->channel_mode[0].channels;
944         spec->ext_channel_count = spec->channel_mode[0].channels;
945
946         spec->multiout.num_dacs = preset->num_dacs;
947         spec->multiout.dac_nids = preset->dac_nids;
948         spec->multiout.dig_out_nid = preset->dig_out_nid;
949         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
950         spec->multiout.hp_nid = preset->hp_nid;
951
952         spec->num_mux_defs = preset->num_mux_defs;
953         if (!spec->num_mux_defs)
954                 spec->num_mux_defs = 1;
955         spec->input_mux = preset->input_mux;
956
957         spec->num_adc_nids = preset->num_adc_nids;
958         spec->adc_nids = preset->adc_nids;
959         spec->capsrc_nids = preset->capsrc_nids;
960         spec->dig_in_nid = preset->dig_in_nid;
961
962         spec->unsol_event = preset->unsol_event;
963         spec->init_hook = preset->init_hook;
964 #ifdef CONFIG_SND_HDA_POWER_SAVE
965         spec->power_hook = preset->power_hook;
966         spec->loopback.amplist = preset->loopbacks;
967 #endif
968
969         if (preset->setup)
970                 preset->setup(codec);
971
972         alc_fixup_autocfg_pin_nums(codec);
973 }
974
975 /* Enable GPIO mask and set output */
976 static struct hda_verb alc_gpio1_init_verbs[] = {
977         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
978         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
979         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
980         { }
981 };
982
983 static struct hda_verb alc_gpio2_init_verbs[] = {
984         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
985         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
986         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
987         { }
988 };
989
990 static struct hda_verb alc_gpio3_init_verbs[] = {
991         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
992         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
993         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
994         { }
995 };
996
997 /*
998  * Fix hardware PLL issue
999  * On some codecs, the analog PLL gating control must be off while
1000  * the default value is 1.
1001  */
1002 static void alc_fix_pll(struct hda_codec *codec)
1003 {
1004         struct alc_spec *spec = codec->spec;
1005         unsigned int val;
1006
1007         if (!spec->pll_nid)
1008                 return;
1009         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
1010                             spec->pll_coef_idx);
1011         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
1012                                  AC_VERB_GET_PROC_COEF, 0);
1013         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
1014                             spec->pll_coef_idx);
1015         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
1016                             val & ~(1 << spec->pll_coef_bit));
1017 }
1018
1019 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
1020                              unsigned int coef_idx, unsigned int coef_bit)
1021 {
1022         struct alc_spec *spec = codec->spec;
1023         spec->pll_nid = nid;
1024         spec->pll_coef_idx = coef_idx;
1025         spec->pll_coef_bit = coef_bit;
1026         alc_fix_pll(codec);
1027 }
1028
1029 #ifdef CONFIG_SND_HDA_INPUT_JACK
1030 static void alc_free_jack_priv(struct snd_jack *jack)
1031 {
1032         struct alc_jack *jacks = jack->private_data;
1033         jacks->nid = 0;
1034         jacks->jack = NULL;
1035 }
1036
1037 static int alc_add_jack(struct hda_codec *codec,
1038                 hda_nid_t nid, int type)
1039 {
1040         struct alc_spec *spec;
1041         struct alc_jack *jack;
1042         const char *name;
1043         int err;
1044
1045         spec = codec->spec;
1046         snd_array_init(&spec->jacks, sizeof(*jack), 32);
1047         jack = snd_array_new(&spec->jacks);
1048         if (!jack)
1049                 return -ENOMEM;
1050
1051         jack->nid = nid;
1052         jack->type = type;
1053         name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
1054
1055         err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
1056         if (err < 0)
1057                 return err;
1058         jack->jack->private_data = jack;
1059         jack->jack->private_free = alc_free_jack_priv;
1060         return 0;
1061 }
1062
1063 static void alc_report_jack(struct hda_codec *codec, hda_nid_t nid)
1064 {
1065         struct alc_spec *spec = codec->spec;
1066         struct alc_jack *jacks = spec->jacks.list;
1067
1068         if (jacks) {
1069                 int i;
1070                 for (i = 0; i < spec->jacks.used; i++) {
1071                         if (jacks->nid == nid) {
1072                                 unsigned int present;
1073                                 present = snd_hda_jack_detect(codec, nid);
1074
1075                                 present = (present) ? jacks->type : 0;
1076
1077                                 snd_jack_report(jacks->jack, present);
1078                         }
1079                         jacks++;
1080                 }
1081         }
1082 }
1083
1084 static int alc_init_jacks(struct hda_codec *codec)
1085 {
1086         struct alc_spec *spec = codec->spec;
1087         int err;
1088         unsigned int hp_nid = spec->autocfg.hp_pins[0];
1089         unsigned int mic_nid = spec->ext_mic.pin;
1090
1091         if (hp_nid) {
1092                 err = alc_add_jack(codec, hp_nid, SND_JACK_HEADPHONE);
1093                 if (err < 0)
1094                         return err;
1095                 alc_report_jack(codec, hp_nid);
1096         }
1097
1098         if (mic_nid) {
1099                 err = alc_add_jack(codec, mic_nid, SND_JACK_MICROPHONE);
1100                 if (err < 0)
1101                         return err;
1102                 alc_report_jack(codec, mic_nid);
1103         }
1104
1105         return 0;
1106 }
1107 #else
1108 static inline void alc_report_jack(struct hda_codec *codec, hda_nid_t nid)
1109 {
1110 }
1111
1112 static inline int alc_init_jacks(struct hda_codec *codec)
1113 {
1114         return 0;
1115 }
1116 #endif
1117
1118 static void alc_automute_speaker(struct hda_codec *codec, int pinctl)
1119 {
1120         struct alc_spec *spec = codec->spec;
1121         unsigned int mute;
1122         hda_nid_t nid;
1123         int i;
1124
1125         spec->jack_present = 0;
1126         for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
1127                 nid = spec->autocfg.hp_pins[i];
1128                 if (!nid)
1129                         break;
1130                 if (snd_hda_jack_detect(codec, nid)) {
1131                         spec->jack_present = 1;
1132                         break;
1133                 }
1134                 alc_report_jack(codec, spec->autocfg.hp_pins[i]);
1135         }
1136
1137         mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1138         /* Toggle internal speakers muting */
1139         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
1140                 nid = spec->autocfg.speaker_pins[i];
1141                 if (!nid)
1142                         break;
1143                 if (pinctl) {
1144                         snd_hda_codec_write(codec, nid, 0,
1145                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
1146                                     spec->jack_present ? 0 : PIN_OUT);
1147                 } else {
1148                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1149                                          HDA_AMP_MUTE, mute);
1150                 }
1151         }
1152 }
1153
1154 static void alc_automute_pin(struct hda_codec *codec)
1155 {
1156         alc_automute_speaker(codec, 1);
1157 }
1158
1159 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
1160                                 hda_nid_t nid)
1161 {
1162         hda_nid_t conn[HDA_MAX_NUM_INPUTS];
1163         int i, nums;
1164
1165         nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
1166         for (i = 0; i < nums; i++)
1167                 if (conn[i] == nid)
1168                         return i;
1169         return -1;
1170 }
1171
1172 /* switch the current ADC according to the jack state */
1173 static void alc_dual_mic_adc_auto_switch(struct hda_codec *codec)
1174 {
1175         struct alc_spec *spec = codec->spec;
1176         unsigned int present;
1177         hda_nid_t new_adc;
1178
1179         present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1180         if (present)
1181                 spec->cur_adc_idx = 1;
1182         else
1183                 spec->cur_adc_idx = 0;
1184         new_adc = spec->adc_nids[spec->cur_adc_idx];
1185         if (spec->cur_adc && spec->cur_adc != new_adc) {
1186                 /* stream is running, let's swap the current ADC */
1187                 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1188                 spec->cur_adc = new_adc;
1189                 snd_hda_codec_setup_stream(codec, new_adc,
1190                                            spec->cur_adc_stream_tag, 0,
1191                                            spec->cur_adc_format);
1192         }
1193 }
1194
1195 static void alc_mic_automute(struct hda_codec *codec)
1196 {
1197         struct alc_spec *spec = codec->spec;
1198         struct alc_mic_route *dead, *alive;
1199         unsigned int present, type;
1200         hda_nid_t cap_nid;
1201
1202         if (!spec->auto_mic)
1203                 return;
1204         if (!spec->int_mic.pin || !spec->ext_mic.pin)
1205                 return;
1206         if (snd_BUG_ON(!spec->adc_nids))
1207                 return;
1208
1209         if (spec->dual_adc_switch) {
1210                 alc_dual_mic_adc_auto_switch(codec);
1211                 return;
1212         }
1213
1214         cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1215
1216         present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1217         if (present) {
1218                 alive = &spec->ext_mic;
1219                 dead = &spec->int_mic;
1220         } else {
1221                 alive = &spec->int_mic;
1222                 dead = &spec->ext_mic;
1223         }
1224
1225         type = get_wcaps_type(get_wcaps(codec, cap_nid));
1226         if (type == AC_WID_AUD_MIX) {
1227                 /* Matrix-mixer style (e.g. ALC882) */
1228                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1229                                          alive->mux_idx,
1230                                          HDA_AMP_MUTE, 0);
1231                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1232                                          dead->mux_idx,
1233                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
1234         } else {
1235                 /* MUX style (e.g. ALC880) */
1236                 snd_hda_codec_write_cache(codec, cap_nid, 0,
1237                                           AC_VERB_SET_CONNECT_SEL,
1238                                           alive->mux_idx);
1239         }
1240         alc_report_jack(codec, spec->ext_mic.pin);
1241
1242         /* FIXME: analog mixer */
1243 }
1244
1245 /* unsolicited event for HP jack sensing */
1246 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
1247 {
1248         if (codec->vendor_id == 0x10ec0880)
1249                 res >>= 28;
1250         else
1251                 res >>= 26;
1252         switch (res) {
1253         case ALC880_HP_EVENT:
1254                 alc_automute_pin(codec);
1255                 break;
1256         case ALC880_MIC_EVENT:
1257                 alc_mic_automute(codec);
1258                 break;
1259         }
1260 }
1261
1262 static void alc_inithook(struct hda_codec *codec)
1263 {
1264         alc_automute_pin(codec);
1265         alc_mic_automute(codec);
1266 }
1267
1268 /* additional initialization for ALC888 variants */
1269 static void alc888_coef_init(struct hda_codec *codec)
1270 {
1271         unsigned int tmp;
1272
1273         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1274         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1275         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1276         if ((tmp & 0xf0) == 0x20)
1277                 /* alc888S-VC */
1278                 snd_hda_codec_read(codec, 0x20, 0,
1279                                    AC_VERB_SET_PROC_COEF, 0x830);
1280          else
1281                  /* alc888-VB */
1282                  snd_hda_codec_read(codec, 0x20, 0,
1283                                     AC_VERB_SET_PROC_COEF, 0x3030);
1284 }
1285
1286 static void alc889_coef_init(struct hda_codec *codec)
1287 {
1288         unsigned int tmp;
1289
1290         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1291         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1292         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1293         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1294 }
1295
1296 /* turn on/off EAPD control (only if available) */
1297 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
1298 {
1299         if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
1300                 return;
1301         if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
1302                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1303                                     on ? 2 : 0);
1304 }
1305
1306 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1307 {
1308         unsigned int tmp;
1309
1310         switch (type) {
1311         case ALC_INIT_GPIO1:
1312                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1313                 break;
1314         case ALC_INIT_GPIO2:
1315                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1316                 break;
1317         case ALC_INIT_GPIO3:
1318                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1319                 break;
1320         case ALC_INIT_DEFAULT:
1321                 switch (codec->vendor_id) {
1322                 case 0x10ec0260:
1323                         set_eapd(codec, 0x0f, 1);
1324                         set_eapd(codec, 0x10, 1);
1325                         break;
1326                 case 0x10ec0262:
1327                 case 0x10ec0267:
1328                 case 0x10ec0268:
1329                 case 0x10ec0269:
1330                 case 0x10ec0270:
1331                 case 0x10ec0272:
1332                 case 0x10ec0660:
1333                 case 0x10ec0662:
1334                 case 0x10ec0663:
1335                 case 0x10ec0862:
1336                 case 0x10ec0889:
1337                         set_eapd(codec, 0x14, 1);
1338                         set_eapd(codec, 0x15, 1);
1339                         break;
1340                 }
1341                 switch (codec->vendor_id) {
1342                 case 0x10ec0260:
1343                         snd_hda_codec_write(codec, 0x1a, 0,
1344                                             AC_VERB_SET_COEF_INDEX, 7);
1345                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1346                                                  AC_VERB_GET_PROC_COEF, 0);
1347                         snd_hda_codec_write(codec, 0x1a, 0,
1348                                             AC_VERB_SET_COEF_INDEX, 7);
1349                         snd_hda_codec_write(codec, 0x1a, 0,
1350                                             AC_VERB_SET_PROC_COEF,
1351                                             tmp | 0x2010);
1352                         break;
1353                 case 0x10ec0262:
1354                 case 0x10ec0880:
1355                 case 0x10ec0882:
1356                 case 0x10ec0883:
1357                 case 0x10ec0885:
1358                 case 0x10ec0887:
1359                 case 0x10ec0889:
1360                         alc889_coef_init(codec);
1361                         break;
1362                 case 0x10ec0888:
1363                         alc888_coef_init(codec);
1364                         break;
1365 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
1366                 case 0x10ec0267:
1367                 case 0x10ec0268:
1368                         snd_hda_codec_write(codec, 0x20, 0,
1369                                             AC_VERB_SET_COEF_INDEX, 7);
1370                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1371                                                  AC_VERB_GET_PROC_COEF, 0);
1372                         snd_hda_codec_write(codec, 0x20, 0,
1373                                             AC_VERB_SET_COEF_INDEX, 7);
1374                         snd_hda_codec_write(codec, 0x20, 0,
1375                                             AC_VERB_SET_PROC_COEF,
1376                                             tmp | 0x3000);
1377                         break;
1378 #endif /* XXX */
1379                 }
1380                 break;
1381         }
1382 }
1383
1384 static void alc_init_auto_hp(struct hda_codec *codec)
1385 {
1386         struct alc_spec *spec = codec->spec;
1387         struct auto_pin_cfg *cfg = &spec->autocfg;
1388         int i;
1389
1390         if (!cfg->hp_pins[0]) {
1391                 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1392                         return;
1393         }
1394
1395         if (!cfg->speaker_pins[0]) {
1396                 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1397                         return;
1398                 memcpy(cfg->speaker_pins, cfg->line_out_pins,
1399                        sizeof(cfg->speaker_pins));
1400                 cfg->speaker_outs = cfg->line_outs;
1401         }
1402
1403         if (!cfg->hp_pins[0]) {
1404                 memcpy(cfg->hp_pins, cfg->line_out_pins,
1405                        sizeof(cfg->hp_pins));
1406                 cfg->hp_outs = cfg->line_outs;
1407         }
1408
1409         for (i = 0; i < cfg->hp_outs; i++) {
1410                 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1411                             cfg->hp_pins[i]);
1412                 snd_hda_codec_write_cache(codec, cfg->hp_pins[i], 0,
1413                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1414                                   AC_USRSP_EN | ALC880_HP_EVENT);
1415         }
1416         spec->unsol_event = alc_sku_unsol_event;
1417 }
1418
1419 static void alc_init_auto_mic(struct hda_codec *codec)
1420 {
1421         struct alc_spec *spec = codec->spec;
1422         struct auto_pin_cfg *cfg = &spec->autocfg;
1423         hda_nid_t fixed, ext;
1424         int i;
1425
1426         /* there must be only two mic inputs exclusively */
1427         for (i = 0; i < cfg->num_inputs; i++)
1428                 if (cfg->inputs[i].type >= AUTO_PIN_LINE_IN)
1429                         return;
1430
1431         fixed = ext = 0;
1432         for (i = 0; i < cfg->num_inputs; i++) {
1433                 hda_nid_t nid = cfg->inputs[i].pin;
1434                 unsigned int defcfg;
1435                 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1436                 switch (snd_hda_get_input_pin_attr(defcfg)) {
1437                 case INPUT_PIN_ATTR_INT:
1438                         if (fixed)
1439                                 return; /* already occupied */
1440                         fixed = nid;
1441                         break;
1442                 case INPUT_PIN_ATTR_UNUSED:
1443                         return; /* invalid entry */
1444                 default:
1445                         if (ext)
1446                                 return; /* already occupied */
1447                         ext = nid;
1448                         break;
1449                 }
1450         }
1451         if (!ext || !fixed)
1452                 return;
1453         if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
1454                 return; /* no unsol support */
1455         snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x\n",
1456                     ext, fixed);
1457         spec->ext_mic.pin = ext;
1458         spec->int_mic.pin = fixed;
1459         spec->ext_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1460         spec->int_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1461         spec->auto_mic = 1;
1462         snd_hda_codec_write_cache(codec, spec->ext_mic.pin, 0,
1463                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1464                                   AC_USRSP_EN | ALC880_MIC_EVENT);
1465         spec->unsol_event = alc_sku_unsol_event;
1466 }
1467
1468 /* Could be any non-zero and even value. When used as fixup, tells
1469  * the driver to ignore any present sku defines.
1470  */
1471 #define ALC_FIXUP_SKU_IGNORE (2)
1472
1473 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1474 {
1475         unsigned int ass, tmp, i;
1476         unsigned nid = 0;
1477         struct alc_spec *spec = codec->spec;
1478
1479         spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1480
1481         if (spec->cdefine.fixup) {
1482                 ass = spec->cdefine.sku_cfg;
1483                 if (ass == ALC_FIXUP_SKU_IGNORE)
1484                         return -1;
1485                 goto do_sku;
1486         }
1487
1488         ass = codec->subsystem_id & 0xffff;
1489         if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1490                 goto do_sku;
1491
1492         nid = 0x1d;
1493         if (codec->vendor_id == 0x10ec0260)
1494                 nid = 0x17;
1495         ass = snd_hda_codec_get_pincfg(codec, nid);
1496
1497         if (!(ass & 1)) {
1498                 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1499                        codec->chip_name, ass);
1500                 return -1;
1501         }
1502
1503         /* check sum */
1504         tmp = 0;
1505         for (i = 1; i < 16; i++) {
1506                 if ((ass >> i) & 1)
1507                         tmp++;
1508         }
1509         if (((ass >> 16) & 0xf) != tmp)
1510                 return -1;
1511
1512         spec->cdefine.port_connectivity = ass >> 30;
1513         spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1514         spec->cdefine.check_sum = (ass >> 16) & 0xf;
1515         spec->cdefine.customization = ass >> 8;
1516 do_sku:
1517         spec->cdefine.sku_cfg = ass;
1518         spec->cdefine.external_amp = (ass & 0x38) >> 3;
1519         spec->cdefine.platform_type = (ass & 0x4) >> 2;
1520         spec->cdefine.swap = (ass & 0x2) >> 1;
1521         spec->cdefine.override = ass & 0x1;
1522
1523         snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1524                    nid, spec->cdefine.sku_cfg);
1525         snd_printd("SKU: port_connectivity=0x%x\n",
1526                    spec->cdefine.port_connectivity);
1527         snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1528         snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1529         snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1530         snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1531         snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1532         snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1533         snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1534
1535         return 0;
1536 }
1537
1538 /* check subsystem ID and set up device-specific initialization;
1539  * return 1 if initialized, 0 if invalid SSID
1540  */
1541 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1542  *      31 ~ 16 :       Manufacture ID
1543  *      15 ~ 8  :       SKU ID
1544  *      7  ~ 0  :       Assembly ID
1545  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1546  */
1547 static int alc_subsystem_id(struct hda_codec *codec,
1548                             hda_nid_t porta, hda_nid_t porte,
1549                             hda_nid_t portd, hda_nid_t porti)
1550 {
1551         unsigned int ass, tmp, i;
1552         unsigned nid;
1553         struct alc_spec *spec = codec->spec;
1554
1555         if (spec->cdefine.fixup) {
1556                 ass = spec->cdefine.sku_cfg;
1557                 if (ass == ALC_FIXUP_SKU_IGNORE)
1558                         return 0;
1559                 goto do_sku;
1560         }
1561
1562         ass = codec->subsystem_id & 0xffff;
1563         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1564                 goto do_sku;
1565
1566         /* invalid SSID, check the special NID pin defcfg instead */
1567         /*
1568          * 31~30        : port connectivity
1569          * 29~21        : reserve
1570          * 20           : PCBEEP input
1571          * 19~16        : Check sum (15:1)
1572          * 15~1         : Custom
1573          * 0            : override
1574         */
1575         nid = 0x1d;
1576         if (codec->vendor_id == 0x10ec0260)
1577                 nid = 0x17;
1578         ass = snd_hda_codec_get_pincfg(codec, nid);
1579         snd_printd("realtek: No valid SSID, "
1580                    "checking pincfg 0x%08x for NID 0x%x\n",
1581                    ass, nid);
1582         if (!(ass & 1))
1583                 return 0;
1584         if ((ass >> 30) != 1)   /* no physical connection */
1585                 return 0;
1586
1587         /* check sum */
1588         tmp = 0;
1589         for (i = 1; i < 16; i++) {
1590                 if ((ass >> i) & 1)
1591                         tmp++;
1592         }
1593         if (((ass >> 16) & 0xf) != tmp)
1594                 return 0;
1595 do_sku:
1596         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1597                    ass & 0xffff, codec->vendor_id);
1598         /*
1599          * 0 : override
1600          * 1 :  Swap Jack
1601          * 2 : 0 --> Desktop, 1 --> Laptop
1602          * 3~5 : External Amplifier control
1603          * 7~6 : Reserved
1604         */
1605         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1606         switch (tmp) {
1607         case 1:
1608                 spec->init_amp = ALC_INIT_GPIO1;
1609                 break;
1610         case 3:
1611                 spec->init_amp = ALC_INIT_GPIO2;
1612                 break;
1613         case 7:
1614                 spec->init_amp = ALC_INIT_GPIO3;
1615                 break;
1616         case 5:
1617                 spec->init_amp = ALC_INIT_DEFAULT;
1618                 break;
1619         }
1620
1621         /* is laptop or Desktop and enable the function "Mute internal speaker
1622          * when the external headphone out jack is plugged"
1623          */
1624         if (!(ass & 0x8000))
1625                 return 1;
1626         /*
1627          * 10~8 : Jack location
1628          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1629          * 14~13: Resvered
1630          * 15   : 1 --> enable the function "Mute internal speaker
1631          *              when the external headphone out jack is plugged"
1632          */
1633         if (!spec->autocfg.hp_pins[0]) {
1634                 hda_nid_t nid;
1635                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1636                 if (tmp == 0)
1637                         nid = porta;
1638                 else if (tmp == 1)
1639                         nid = porte;
1640                 else if (tmp == 2)
1641                         nid = portd;
1642                 else if (tmp == 3)
1643                         nid = porti;
1644                 else
1645                         return 1;
1646                 for (i = 0; i < spec->autocfg.line_outs; i++)
1647                         if (spec->autocfg.line_out_pins[i] == nid)
1648                                 return 1;
1649                 spec->autocfg.hp_pins[0] = nid;
1650         }
1651
1652         alc_init_auto_hp(codec);
1653         alc_init_auto_mic(codec);
1654         return 1;
1655 }
1656
1657 static void alc_ssid_check(struct hda_codec *codec,
1658                            hda_nid_t porta, hda_nid_t porte,
1659                            hda_nid_t portd, hda_nid_t porti)
1660 {
1661         if (!alc_subsystem_id(codec, porta, porte, portd, porti)) {
1662                 struct alc_spec *spec = codec->spec;
1663                 snd_printd("realtek: "
1664                            "Enable default setup for auto mode as fallback\n");
1665                 spec->init_amp = ALC_INIT_DEFAULT;
1666                 alc_init_auto_hp(codec);
1667                 alc_init_auto_mic(codec);
1668         }
1669 }
1670
1671 /*
1672  * Fix-up pin default configurations and add default verbs
1673  */
1674
1675 struct alc_pincfg {
1676         hda_nid_t nid;
1677         u32 val;
1678 };
1679
1680 struct alc_fixup {
1681         unsigned int sku;
1682         const struct alc_pincfg *pins;
1683         const struct hda_verb *verbs;
1684 };
1685
1686 static void alc_pick_fixup(struct hda_codec *codec,
1687                            const struct snd_pci_quirk *quirk,
1688                            const struct alc_fixup *fix,
1689                            int pre_init)
1690 {
1691         const struct alc_pincfg *cfg;
1692         struct alc_spec *spec;
1693
1694         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1695         if (!quirk)
1696                 return;
1697         fix += quirk->value;
1698         cfg = fix->pins;
1699         if (pre_init && fix->sku) {
1700 #ifdef CONFIG_SND_DEBUG_VERBOSE
1701                 snd_printdd(KERN_INFO "hda_codec: %s: Apply sku override for %s\n",
1702                             codec->chip_name, quirk->name);
1703 #endif
1704                 spec = codec->spec;
1705                 spec->cdefine.sku_cfg = fix->sku;
1706                 spec->cdefine.fixup = 1;
1707         }
1708         if (pre_init && cfg) {
1709 #ifdef CONFIG_SND_DEBUG_VERBOSE
1710                 snd_printdd(KERN_INFO "hda_codec: %s: Apply pincfg for %s\n",
1711                             codec->chip_name, quirk->name);
1712 #endif
1713                 for (; cfg->nid; cfg++)
1714                         snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1715         }
1716         if (!pre_init && fix->verbs) {
1717 #ifdef CONFIG_SND_DEBUG_VERBOSE
1718                 snd_printdd(KERN_INFO "hda_codec: %s: Apply fix-verbs for %s\n",
1719                             codec->chip_name, quirk->name);
1720 #endif
1721                 add_verb(codec->spec, fix->verbs);
1722         }
1723 }
1724
1725 static int alc_read_coef_idx(struct hda_codec *codec,
1726                         unsigned int coef_idx)
1727 {
1728         unsigned int val;
1729         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1730                                 coef_idx);
1731         val = snd_hda_codec_read(codec, 0x20, 0,
1732                                 AC_VERB_GET_PROC_COEF, 0);
1733         return val;
1734 }
1735
1736 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1737                                                         unsigned int coef_val)
1738 {
1739         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1740                             coef_idx);
1741         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1742                             coef_val);
1743 }
1744
1745 /* set right pin controls for digital I/O */
1746 static void alc_auto_init_digital(struct hda_codec *codec)
1747 {
1748         struct alc_spec *spec = codec->spec;
1749         int i;
1750         hda_nid_t pin;
1751
1752         for (i = 0; i < spec->autocfg.dig_outs; i++) {
1753                 pin = spec->autocfg.dig_out_pins[i];
1754                 if (pin) {
1755                         snd_hda_codec_write(codec, pin, 0,
1756                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
1757                                             PIN_OUT);
1758                 }
1759         }
1760         pin = spec->autocfg.dig_in_pin;
1761         if (pin)
1762                 snd_hda_codec_write(codec, pin, 0,
1763                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
1764                                     PIN_IN);
1765 }
1766
1767 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1768 static void alc_auto_parse_digital(struct hda_codec *codec)
1769 {
1770         struct alc_spec *spec = codec->spec;
1771         int i, err;
1772         hda_nid_t dig_nid;
1773
1774         /* support multiple SPDIFs; the secondary is set up as a slave */
1775         for (i = 0; i < spec->autocfg.dig_outs; i++) {
1776                 err = snd_hda_get_connections(codec,
1777                                               spec->autocfg.dig_out_pins[i],
1778                                               &dig_nid, 1);
1779                 if (err < 0)
1780                         continue;
1781                 if (!i) {
1782                         spec->multiout.dig_out_nid = dig_nid;
1783                         spec->dig_out_type = spec->autocfg.dig_out_type[0];
1784                 } else {
1785                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1786                         if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1787                                 break;
1788                         spec->slave_dig_outs[i - 1] = dig_nid;
1789                 }
1790         }
1791
1792         if (spec->autocfg.dig_in_pin) {
1793                 dig_nid = codec->start_nid;
1794                 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1795                         unsigned int wcaps = get_wcaps(codec, dig_nid);
1796                         if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1797                                 continue;
1798                         if (!(wcaps & AC_WCAP_DIGITAL))
1799                                 continue;
1800                         if (!(wcaps & AC_WCAP_CONN_LIST))
1801                                 continue;
1802                         err = get_connection_index(codec, dig_nid,
1803                                                    spec->autocfg.dig_in_pin);
1804                         if (err >= 0) {
1805                                 spec->dig_in_nid = dig_nid;
1806                                 break;
1807                         }
1808                 }
1809         }
1810 }
1811
1812 /*
1813  * ALC888
1814  */
1815
1816 /*
1817  * 2ch mode
1818  */
1819 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1820 /* Mic-in jack as mic in */
1821         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1822         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1823 /* Line-in jack as Line in */
1824         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1825         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1826 /* Line-Out as Front */
1827         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1828         { } /* end */
1829 };
1830
1831 /*
1832  * 4ch mode
1833  */
1834 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1835 /* Mic-in jack as mic in */
1836         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1837         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1838 /* Line-in jack as Surround */
1839         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1840         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1841 /* Line-Out as Front */
1842         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1843         { } /* end */
1844 };
1845
1846 /*
1847  * 6ch mode
1848  */
1849 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1850 /* Mic-in jack as CLFE */
1851         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1852         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1853 /* Line-in jack as Surround */
1854         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1855         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1856 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1857         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1858         { } /* end */
1859 };
1860
1861 /*
1862  * 8ch mode
1863  */
1864 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1865 /* Mic-in jack as CLFE */
1866         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1867         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1868 /* Line-in jack as Surround */
1869         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1870         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1871 /* Line-Out as Side */
1872         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1873         { } /* end */
1874 };
1875
1876 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1877         { 2, alc888_4ST_ch2_intel_init },
1878         { 4, alc888_4ST_ch4_intel_init },
1879         { 6, alc888_4ST_ch6_intel_init },
1880         { 8, alc888_4ST_ch8_intel_init },
1881 };
1882
1883 /*
1884  * ALC888 Fujitsu Siemens Amillo xa3530
1885  */
1886
1887 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1888 /* Front Mic: set to PIN_IN (empty by default) */
1889         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1890 /* Connect Internal HP to Front */
1891         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1892         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1893         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1894 /* Connect Bass HP to Front */
1895         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1896         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1897         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1898 /* Connect Line-Out side jack (SPDIF) to Side */
1899         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1900         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1901         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1902 /* Connect Mic jack to CLFE */
1903         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1904         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1905         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1906 /* Connect Line-in jack to Surround */
1907         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1908         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1909         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1910 /* Connect HP out jack to Front */
1911         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1912         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1913         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1914 /* Enable unsolicited event for HP jack and Line-out jack */
1915         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1916         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1917         {}
1918 };
1919
1920 static void alc_automute_amp(struct hda_codec *codec)
1921 {
1922         alc_automute_speaker(codec, 0);
1923 }
1924
1925 static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1926                                          unsigned int res)
1927 {
1928         if (codec->vendor_id == 0x10ec0880)
1929                 res >>= 28;
1930         else
1931                 res >>= 26;
1932         if (res == ALC880_HP_EVENT)
1933                 alc_automute_amp(codec);
1934 }
1935
1936 static void alc889_automute_setup(struct hda_codec *codec)
1937 {
1938         struct alc_spec *spec = codec->spec;
1939
1940         spec->autocfg.hp_pins[0] = 0x15;
1941         spec->autocfg.speaker_pins[0] = 0x14;
1942         spec->autocfg.speaker_pins[1] = 0x16;
1943         spec->autocfg.speaker_pins[2] = 0x17;
1944         spec->autocfg.speaker_pins[3] = 0x19;
1945         spec->autocfg.speaker_pins[4] = 0x1a;
1946 }
1947
1948 static void alc889_intel_init_hook(struct hda_codec *codec)
1949 {
1950         alc889_coef_init(codec);
1951         alc_automute_amp(codec);
1952 }
1953
1954 static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
1955 {
1956         struct alc_spec *spec = codec->spec;
1957
1958         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
1959         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1960         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1961         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1962 }
1963
1964 /*
1965  * ALC888 Acer Aspire 4930G model
1966  */
1967
1968 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1969 /* Front Mic: set to PIN_IN (empty by default) */
1970         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1971 /* Unselect Front Mic by default in input mixer 3 */
1972         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1973 /* Enable unsolicited event for HP jack */
1974         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1975 /* Connect Internal HP to front */
1976         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1977         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1978         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1979 /* Connect HP out to front */
1980         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1981         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1982         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1983         { }
1984 };
1985
1986 /*
1987  * ALC888 Acer Aspire 6530G model
1988  */
1989
1990 static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1991 /* Route to built-in subwoofer as well as speakers */
1992         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1993         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1994         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1995         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1996 /* Bias voltage on for external mic port */
1997         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1998 /* Front Mic: set to PIN_IN (empty by default) */
1999         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2000 /* Unselect Front Mic by default in input mixer 3 */
2001         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2002 /* Enable unsolicited event for HP jack */
2003         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2004 /* Enable speaker output */
2005         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2006         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2007         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
2008 /* Enable headphone output */
2009         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2010         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2011         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2012         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
2013         { }
2014 };
2015
2016 /*
2017  * ALC889 Acer Aspire 8930G model
2018  */
2019
2020 static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
2021 /* Front Mic: set to PIN_IN (empty by default) */
2022         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2023 /* Unselect Front Mic by default in input mixer 3 */
2024         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2025 /* Enable unsolicited event for HP jack */
2026         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2027 /* Connect Internal Front to Front */
2028         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2029         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2030         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
2031 /* Connect Internal Rear to Rear */
2032         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2033         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2034         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
2035 /* Connect Internal CLFE to CLFE */
2036         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2037         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2038         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
2039 /* Connect HP out to Front */
2040         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2041         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2042         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2043 /* Enable all DACs */
2044 /*  DAC DISABLE/MUTE 1? */
2045 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
2046         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
2047         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
2048 /*  DAC DISABLE/MUTE 2? */
2049 /*  some bit here disables the other DACs. Init=0x4900 */
2050         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
2051         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
2052 /* DMIC fix
2053  * This laptop has a stereo digital microphone. The mics are only 1cm apart
2054  * which makes the stereo useless. However, either the mic or the ALC889
2055  * makes the signal become a difference/sum signal instead of standard
2056  * stereo, which is annoying. So instead we flip this bit which makes the
2057  * codec replicate the sum signal to both channels, turning it into a
2058  * normal mono mic.
2059  */
2060 /*  DMIC_CONTROL? Init value = 0x0001 */
2061         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
2062         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
2063         { }
2064 };
2065
2066 static struct hda_input_mux alc888_2_capture_sources[2] = {
2067         /* Front mic only available on one ADC */
2068         {
2069                 .num_items = 4,
2070                 .items = {
2071                         { "Mic", 0x0 },
2072                         { "Line", 0x2 },
2073                         { "CD", 0x4 },
2074                         { "Front Mic", 0xb },
2075                 },
2076         },
2077         {
2078                 .num_items = 3,
2079                 .items = {
2080                         { "Mic", 0x0 },
2081                         { "Line", 0x2 },
2082                         { "CD", 0x4 },
2083                 },
2084         }
2085 };
2086
2087 static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
2088         /* Interal mic only available on one ADC */
2089         {
2090                 .num_items = 5,
2091                 .items = {
2092                         { "Ext Mic", 0x0 },
2093                         { "Line In", 0x2 },
2094                         { "CD", 0x4 },
2095                         { "Input Mix", 0xa },
2096                         { "Int Mic", 0xb },
2097                 },
2098         },
2099         {
2100                 .num_items = 4,
2101                 .items = {
2102                         { "Ext Mic", 0x0 },
2103                         { "Line In", 0x2 },
2104                         { "CD", 0x4 },
2105                         { "Input Mix", 0xa },
2106                 },
2107         }
2108 };
2109
2110 static struct hda_input_mux alc889_capture_sources[3] = {
2111         /* Digital mic only available on first "ADC" */
2112         {
2113                 .num_items = 5,
2114                 .items = {
2115                         { "Mic", 0x0 },
2116                         { "Line", 0x2 },
2117                         { "CD", 0x4 },
2118                         { "Front Mic", 0xb },
2119                         { "Input Mix", 0xa },
2120                 },
2121         },
2122         {
2123                 .num_items = 4,
2124                 .items = {
2125                         { "Mic", 0x0 },
2126                         { "Line", 0x2 },
2127                         { "CD", 0x4 },
2128                         { "Input Mix", 0xa },
2129                 },
2130         },
2131         {
2132                 .num_items = 4,
2133                 .items = {
2134                         { "Mic", 0x0 },
2135                         { "Line", 0x2 },
2136                         { "CD", 0x4 },
2137                         { "Input Mix", 0xa },
2138                 },
2139         }
2140 };
2141
2142 static struct snd_kcontrol_new alc888_base_mixer[] = {
2143         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2144         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2145         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2146         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2147         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
2148                 HDA_OUTPUT),
2149         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2150         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2151         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2152         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2153         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2154         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2155         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2156         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2157         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2158         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2159         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
2160         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2161         { } /* end */
2162 };
2163
2164 static struct snd_kcontrol_new alc889_acer_aspire_8930g_mixer[] = {
2165         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2166         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2167         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2168         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2169         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
2170                 HDA_OUTPUT),
2171         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2172         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2173         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2174         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2175         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2176         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2177         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
2178         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2179         { } /* end */
2180 };
2181
2182
2183 static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
2184 {
2185         struct alc_spec *spec = codec->spec;
2186
2187         spec->autocfg.hp_pins[0] = 0x15;
2188         spec->autocfg.speaker_pins[0] = 0x14;
2189         spec->autocfg.speaker_pins[1] = 0x16;
2190         spec->autocfg.speaker_pins[2] = 0x17;
2191 }
2192
2193 static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
2194 {
2195         struct alc_spec *spec = codec->spec;
2196
2197         spec->autocfg.hp_pins[0] = 0x15;
2198         spec->autocfg.speaker_pins[0] = 0x14;
2199         spec->autocfg.speaker_pins[1] = 0x16;
2200         spec->autocfg.speaker_pins[2] = 0x17;
2201 }
2202
2203 static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
2204 {
2205         struct alc_spec *spec = codec->spec;
2206
2207         spec->autocfg.hp_pins[0] = 0x15;
2208         spec->autocfg.speaker_pins[0] = 0x14;
2209         spec->autocfg.speaker_pins[1] = 0x16;
2210         spec->autocfg.speaker_pins[2] = 0x1b;
2211 }
2212
2213 /*
2214  * ALC880 3-stack model
2215  *
2216  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
2217  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
2218  *                 F-Mic = 0x1b, HP = 0x19
2219  */
2220
2221 static hda_nid_t alc880_dac_nids[4] = {
2222         /* front, rear, clfe, rear_surr */
2223         0x02, 0x05, 0x04, 0x03
2224 };
2225
2226 static hda_nid_t alc880_adc_nids[3] = {
2227         /* ADC0-2 */
2228         0x07, 0x08, 0x09,
2229 };
2230
2231 /* The datasheet says the node 0x07 is connected from inputs,
2232  * but it shows zero connection in the real implementation on some devices.
2233  * Note: this is a 915GAV bug, fixed on 915GLV
2234  */
2235 static hda_nid_t alc880_adc_nids_alt[2] = {
2236         /* ADC1-2 */
2237         0x08, 0x09,
2238 };
2239
2240 #define ALC880_DIGOUT_NID       0x06
2241 #define ALC880_DIGIN_NID        0x0a
2242
2243 static struct hda_input_mux alc880_capture_source = {
2244         .num_items = 4,
2245         .items = {
2246                 { "Mic", 0x0 },
2247                 { "Front Mic", 0x3 },
2248                 { "Line", 0x2 },
2249                 { "CD", 0x4 },
2250         },
2251 };
2252
2253 /* channel source setting (2/6 channel selection for 3-stack) */
2254 /* 2ch mode */
2255 static struct hda_verb alc880_threestack_ch2_init[] = {
2256         /* set line-in to input, mute it */
2257         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2258         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2259         /* set mic-in to input vref 80%, mute it */
2260         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2261         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2262         { } /* end */
2263 };
2264
2265 /* 6ch mode */
2266 static struct hda_verb alc880_threestack_ch6_init[] = {
2267         /* set line-in to output, unmute it */
2268         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2269         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2270         /* set mic-in to output, unmute it */
2271         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2272         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2273         { } /* end */
2274 };
2275
2276 static struct hda_channel_mode alc880_threestack_modes[2] = {
2277         { 2, alc880_threestack_ch2_init },
2278         { 6, alc880_threestack_ch6_init },
2279 };
2280
2281 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
2282         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2283         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2284         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2285         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2286         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2287         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2288         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2289         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2290         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2291         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2292         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2293         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2294         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2295         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2296         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
2297         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
2298         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
2299         {
2300                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2301                 .name = "Channel Mode",
2302                 .info = alc_ch_mode_info,
2303                 .get = alc_ch_mode_get,
2304                 .put = alc_ch_mode_put,
2305         },
2306         { } /* end */
2307 };
2308
2309 /* capture mixer elements */
2310 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
2311                             struct snd_ctl_elem_info *uinfo)
2312 {
2313         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2314         struct alc_spec *spec = codec->spec;
2315         int err;
2316
2317         mutex_lock(&codec->control_mutex);
2318         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
2319                                                       HDA_INPUT);
2320         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
2321         mutex_unlock(&codec->control_mutex);
2322         return err;
2323 }
2324
2325 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
2326                            unsigned int size, unsigned int __user *tlv)
2327 {
2328         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2329         struct alc_spec *spec = codec->spec;
2330         int err;
2331
2332         mutex_lock(&codec->control_mutex);
2333         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
2334                                                       HDA_INPUT);
2335         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
2336         mutex_unlock(&codec->control_mutex);
2337         return err;
2338 }
2339
2340 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
2341                              struct snd_ctl_elem_value *ucontrol);
2342
2343 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
2344                                  struct snd_ctl_elem_value *ucontrol,
2345                                  getput_call_t func)
2346 {
2347         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2348         struct alc_spec *spec = codec->spec;
2349         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2350         int err;
2351
2352         mutex_lock(&codec->control_mutex);
2353         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
2354                                                       3, 0, HDA_INPUT);
2355         err = func(kcontrol, ucontrol);
2356         mutex_unlock(&codec->control_mutex);
2357         return err;
2358 }
2359
2360 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
2361                            struct snd_ctl_elem_value *ucontrol)
2362 {
2363         return alc_cap_getput_caller(kcontrol, ucontrol,
2364                                      snd_hda_mixer_amp_volume_get);
2365 }
2366
2367 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
2368                            struct snd_ctl_elem_value *ucontrol)
2369 {
2370         return alc_cap_getput_caller(kcontrol, ucontrol,
2371                                      snd_hda_mixer_amp_volume_put);
2372 }
2373
2374 /* capture mixer elements */
2375 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
2376
2377 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
2378                           struct snd_ctl_elem_value *ucontrol)
2379 {
2380         return alc_cap_getput_caller(kcontrol, ucontrol,
2381                                      snd_hda_mixer_amp_switch_get);
2382 }
2383
2384 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
2385                           struct snd_ctl_elem_value *ucontrol)
2386 {
2387         return alc_cap_getput_caller(kcontrol, ucontrol,
2388                                      snd_hda_mixer_amp_switch_put);
2389 }
2390
2391 #define _DEFINE_CAPMIX(num) \
2392         { \
2393                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2394                 .name = "Capture Switch", \
2395                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
2396                 .count = num, \
2397                 .info = alc_cap_sw_info, \
2398                 .get = alc_cap_sw_get, \
2399                 .put = alc_cap_sw_put, \
2400         }, \
2401         { \
2402                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2403                 .name = "Capture Volume", \
2404                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2405                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2406                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
2407                 .count = num, \
2408                 .info = alc_cap_vol_info, \
2409                 .get = alc_cap_vol_get, \
2410                 .put = alc_cap_vol_put, \
2411                 .tlv = { .c = alc_cap_vol_tlv }, \
2412         }
2413
2414 #define _DEFINE_CAPSRC(num) \
2415         { \
2416                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2417                 /* .name = "Capture Source", */ \
2418                 .name = "Input Source", \
2419                 .count = num, \
2420                 .info = alc_mux_enum_info, \
2421                 .get = alc_mux_enum_get, \
2422                 .put = alc_mux_enum_put, \
2423         }
2424
2425 #define DEFINE_CAPMIX(num) \
2426 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
2427         _DEFINE_CAPMIX(num),                                  \
2428         _DEFINE_CAPSRC(num),                                  \
2429         { } /* end */                                         \
2430 }
2431
2432 #define DEFINE_CAPMIX_NOSRC(num) \
2433 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
2434         _DEFINE_CAPMIX(num),                                        \
2435         { } /* end */                                               \
2436 }
2437
2438 /* up to three ADCs */
2439 DEFINE_CAPMIX(1);
2440 DEFINE_CAPMIX(2);
2441 DEFINE_CAPMIX(3);
2442 DEFINE_CAPMIX_NOSRC(1);
2443 DEFINE_CAPMIX_NOSRC(2);
2444 DEFINE_CAPMIX_NOSRC(3);
2445
2446 /*
2447  * ALC880 5-stack model
2448  *
2449  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
2450  *      Side = 0x02 (0xd)
2451  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
2452  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
2453  */
2454
2455 /* additional mixers to alc880_three_stack_mixer */
2456 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
2457         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2458         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
2459         { } /* end */
2460 };
2461
2462 /* channel source setting (6/8 channel selection for 5-stack) */
2463 /* 6ch mode */
2464 static struct hda_verb alc880_fivestack_ch6_init[] = {
2465         /* set line-in to input, mute it */
2466         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2467         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2468         { } /* end */
2469 };
2470
2471 /* 8ch mode */
2472 static struct hda_verb alc880_fivestack_ch8_init[] = {
2473         /* set line-in to output, unmute it */
2474         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2475         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2476         { } /* end */
2477 };
2478
2479 static struct hda_channel_mode alc880_fivestack_modes[2] = {
2480         { 6, alc880_fivestack_ch6_init },
2481         { 8, alc880_fivestack_ch8_init },
2482 };
2483
2484
2485 /*
2486  * ALC880 6-stack model
2487  *
2488  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
2489  *      Side = 0x05 (0x0f)
2490  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
2491  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
2492  */
2493
2494 static hda_nid_t alc880_6st_dac_nids[4] = {
2495         /* front, rear, clfe, rear_surr */
2496         0x02, 0x03, 0x04, 0x05
2497 };
2498
2499 static struct hda_input_mux alc880_6stack_capture_source = {
2500         .num_items = 4,
2501         .items = {
2502                 { "Mic", 0x0 },
2503                 { "Front Mic", 0x1 },
2504                 { "Line", 0x2 },
2505                 { "CD", 0x4 },
2506         },
2507 };
2508
2509 /* fixed 8-channels */
2510 static struct hda_channel_mode alc880_sixstack_modes[1] = {
2511         { 8, NULL },
2512 };
2513
2514 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
2515         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2516         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2517         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2518         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2519         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2520         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2521         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2522         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2523         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2524         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2525         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2526         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2527         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2528         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2529         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2530         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2531         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2532         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2533         {
2534                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2535                 .name = "Channel Mode",
2536                 .info = alc_ch_mode_info,
2537                 .get = alc_ch_mode_get,
2538                 .put = alc_ch_mode_put,
2539         },
2540         { } /* end */
2541 };
2542
2543
2544 /*
2545  * ALC880 W810 model
2546  *
2547  * W810 has rear IO for:
2548  * Front (DAC 02)
2549  * Surround (DAC 03)
2550  * Center/LFE (DAC 04)
2551  * Digital out (06)
2552  *
2553  * The system also has a pair of internal speakers, and a headphone jack.
2554  * These are both connected to Line2 on the codec, hence to DAC 02.
2555  *
2556  * There is a variable resistor to control the speaker or headphone
2557  * volume. This is a hardware-only device without a software API.
2558  *
2559  * Plugging headphones in will disable the internal speakers. This is
2560  * implemented in hardware, not via the driver using jack sense. In
2561  * a similar fashion, plugging into the rear socket marked "front" will
2562  * disable both the speakers and headphones.
2563  *
2564  * For input, there's a microphone jack, and an "audio in" jack.
2565  * These may not do anything useful with this driver yet, because I
2566  * haven't setup any initialization verbs for these yet...
2567  */
2568
2569 static hda_nid_t alc880_w810_dac_nids[3] = {
2570         /* front, rear/surround, clfe */
2571         0x02, 0x03, 0x04
2572 };
2573
2574 /* fixed 6 channels */
2575 static struct hda_channel_mode alc880_w810_modes[1] = {
2576         { 6, NULL }
2577 };
2578
2579 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2580 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2581         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2582         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2583         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2584         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2585         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2586         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2587         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2588         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2589         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2590         { } /* end */
2591 };
2592
2593
2594 /*
2595  * Z710V model
2596  *
2597  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2598  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2599  *                 Line = 0x1a
2600  */
2601
2602 static hda_nid_t alc880_z71v_dac_nids[1] = {
2603         0x02
2604 };
2605 #define ALC880_Z71V_HP_DAC      0x03
2606
2607 /* fixed 2 channels */
2608 static struct hda_channel_mode alc880_2_jack_modes[1] = {
2609         { 2, NULL }
2610 };
2611
2612 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
2613         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2614         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2615         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2616         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2617         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2618         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2619         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2620         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2621         { } /* end */
2622 };
2623
2624
2625 /*
2626  * ALC880 F1734 model
2627  *
2628  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
2629  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
2630  */
2631
2632 static hda_nid_t alc880_f1734_dac_nids[1] = {
2633         0x03
2634 };
2635 #define ALC880_F1734_HP_DAC     0x02
2636
2637 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
2638         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2639         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2640         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2641         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2642         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2643         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2644         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2645         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2646         { } /* end */
2647 };
2648
2649 static struct hda_input_mux alc880_f1734_capture_source = {
2650         .num_items = 2,
2651         .items = {
2652                 { "Mic", 0x1 },
2653                 { "CD", 0x4 },
2654         },
2655 };
2656
2657
2658 /*
2659  * ALC880 ASUS model
2660  *
2661  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2662  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2663  *  Mic = 0x18, Line = 0x1a
2664  */
2665
2666 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
2667 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
2668
2669 static struct snd_kcontrol_new alc880_asus_mixer[] = {
2670         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2671         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2672         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2673         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2674         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2675         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2676         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2677         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2678         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2679         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2680         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2681         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2682         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2683         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2684         {
2685                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2686                 .name = "Channel Mode",
2687                 .info = alc_ch_mode_info,
2688                 .get = alc_ch_mode_get,
2689                 .put = alc_ch_mode_put,
2690         },
2691         { } /* end */
2692 };
2693
2694 /*
2695  * ALC880 ASUS W1V model
2696  *
2697  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2698  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2699  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
2700  */
2701
2702 /* additional mixers to alc880_asus_mixer */
2703 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
2704         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
2705         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
2706         { } /* end */
2707 };
2708
2709 /* TCL S700 */
2710 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
2711         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2712         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2713         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
2714         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
2715         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
2716         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
2717         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
2718         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
2719         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
2720         { } /* end */
2721 };
2722
2723 /* Uniwill */
2724 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
2725         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2726         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2727         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2728         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2729         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2730         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2731         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2732         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2733         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2734         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2735         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2736         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2737         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2738         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2739         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2740         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2741         {
2742                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2743                 .name = "Channel Mode",
2744                 .info = alc_ch_mode_info,
2745                 .get = alc_ch_mode_get,
2746                 .put = alc_ch_mode_put,
2747         },
2748         { } /* end */
2749 };
2750
2751 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
2752         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2753         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2754         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2755         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2756         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2757         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2758         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2759         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2760         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2761         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2762         { } /* end */
2763 };
2764
2765 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
2766         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2767         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2768         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2769         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2770         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2771         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2772         { } /* end */
2773 };
2774
2775 /*
2776  * virtual master controls
2777  */
2778
2779 /*
2780  * slave controls for virtual master
2781  */
2782 static const char *alc_slave_vols[] = {
2783         "Front Playback Volume",
2784         "Surround Playback Volume",
2785         "Center Playback Volume",
2786         "LFE Playback Volume",
2787         "Side Playback Volume",
2788         "Headphone Playback Volume",
2789         "Speaker Playback Volume",
2790         "Mono Playback Volume",
2791         "Line-Out Playback Volume",
2792         "PCM Playback Volume",
2793         NULL,
2794 };
2795
2796 static const char *alc_slave_sws[] = {
2797         "Front Playback Switch",
2798         "Surround Playback Switch",
2799         "Center Playback Switch",
2800         "LFE Playback Switch",
2801         "Side Playback Switch",
2802         "Headphone Playback Switch",
2803         "Speaker Playback Switch",
2804         "Mono Playback Switch",
2805         "IEC958 Playback Switch",
2806         "Line-Out Playback Switch",
2807         "PCM Playback Switch",
2808         NULL,
2809 };
2810
2811 /*
2812  * build control elements
2813  */
2814
2815 #define NID_MAPPING             (-1)
2816
2817 #define SUBDEV_SPEAKER_         (0 << 6)
2818 #define SUBDEV_HP_              (1 << 6)
2819 #define SUBDEV_LINE_            (2 << 6)
2820 #define SUBDEV_SPEAKER(x)       (SUBDEV_SPEAKER_ | ((x) & 0x3f))
2821 #define SUBDEV_HP(x)            (SUBDEV_HP_ | ((x) & 0x3f))
2822 #define SUBDEV_LINE(x)          (SUBDEV_LINE_ | ((x) & 0x3f))
2823
2824 static void alc_free_kctls(struct hda_codec *codec);
2825
2826 #ifdef CONFIG_SND_HDA_INPUT_BEEP
2827 /* additional beep mixers; the actual parameters are overwritten at build */
2828 static struct snd_kcontrol_new alc_beep_mixer[] = {
2829         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2830         HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
2831         { } /* end */
2832 };
2833 #endif
2834
2835 static int alc_build_controls(struct hda_codec *codec)
2836 {
2837         struct alc_spec *spec = codec->spec;
2838         struct snd_kcontrol *kctl = NULL;
2839         struct snd_kcontrol_new *knew;
2840         int i, j, err;
2841         unsigned int u;
2842         hda_nid_t nid;
2843
2844         for (i = 0; i < spec->num_mixers; i++) {
2845                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2846                 if (err < 0)
2847                         return err;
2848         }
2849         if (spec->cap_mixer) {
2850                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2851                 if (err < 0)
2852                         return err;
2853         }
2854         if (spec->multiout.dig_out_nid) {
2855                 err = snd_hda_create_spdif_out_ctls(codec,
2856                                                     spec->multiout.dig_out_nid);
2857                 if (err < 0)
2858                         return err;
2859                 if (!spec->no_analog) {
2860                         err = snd_hda_create_spdif_share_sw(codec,
2861                                                             &spec->multiout);
2862                         if (err < 0)
2863                                 return err;
2864                         spec->multiout.share_spdif = 1;
2865                 }
2866         }
2867         if (spec->dig_in_nid) {
2868                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2869                 if (err < 0)
2870                         return err;
2871         }
2872
2873 #ifdef CONFIG_SND_HDA_INPUT_BEEP
2874         /* create beep controls if needed */
2875         if (spec->beep_amp) {
2876                 struct snd_kcontrol_new *knew;
2877                 for (knew = alc_beep_mixer; knew->name; knew++) {
2878                         struct snd_kcontrol *kctl;
2879                         kctl = snd_ctl_new1(knew, codec);
2880                         if (!kctl)
2881                                 return -ENOMEM;
2882                         kctl->private_value = spec->beep_amp;
2883                         err = snd_hda_ctl_add(codec, 0, kctl);
2884                         if (err < 0)
2885                                 return err;
2886                 }
2887         }
2888 #endif
2889
2890         /* if we have no master control, let's create it */
2891         if (!spec->no_analog &&
2892             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2893                 unsigned int vmaster_tlv[4];
2894                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2895                                         HDA_OUTPUT, vmaster_tlv);
2896                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2897                                           vmaster_tlv, alc_slave_vols);
2898                 if (err < 0)
2899                         return err;
2900         }
2901         if (!spec->no_analog &&
2902             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2903                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2904                                           NULL, alc_slave_sws);
2905                 if (err < 0)
2906                         return err;
2907         }
2908
2909         /* assign Capture Source enums to NID */
2910         if (spec->capsrc_nids || spec->adc_nids) {
2911                 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
2912                 if (!kctl)
2913                         kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
2914                 for (i = 0; kctl && i < kctl->count; i++) {
2915                         hda_nid_t *nids = spec->capsrc_nids;
2916                         if (!nids)
2917                                 nids = spec->adc_nids;
2918                         err = snd_hda_add_nid(codec, kctl, i, nids[i]);
2919                         if (err < 0)
2920                                 return err;
2921                 }
2922         }
2923         if (spec->cap_mixer) {
2924                 const char *kname = kctl ? kctl->id.name : NULL;
2925                 for (knew = spec->cap_mixer; knew->name; knew++) {
2926                         if (kname && strcmp(knew->name, kname) == 0)
2927                                 continue;
2928                         kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2929                         for (i = 0; kctl && i < kctl->count; i++) {
2930                                 err = snd_hda_add_nid(codec, kctl, i,
2931                                                       spec->adc_nids[i]);
2932                                 if (err < 0)
2933                                         return err;
2934                         }
2935                 }
2936         }
2937
2938         /* other nid->control mapping */
2939         for (i = 0; i < spec->num_mixers; i++) {
2940                 for (knew = spec->mixers[i]; knew->name; knew++) {
2941                         if (knew->iface != NID_MAPPING)
2942                                 continue;
2943                         kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2944                         if (kctl == NULL)
2945                                 continue;
2946                         u = knew->subdevice;
2947                         for (j = 0; j < 4; j++, u >>= 8) {
2948                                 nid = u & 0x3f;
2949                                 if (nid == 0)
2950                                         continue;
2951                                 switch (u & 0xc0) {
2952                                 case SUBDEV_SPEAKER_:
2953                                         nid = spec->autocfg.speaker_pins[nid];
2954                                         break;
2955                                 case SUBDEV_LINE_:
2956                                         nid = spec->autocfg.line_out_pins[nid];
2957                                         break;
2958                                 case SUBDEV_HP_:
2959                                         nid = spec->autocfg.hp_pins[nid];
2960                                         break;
2961                                 default:
2962                                         continue;
2963                                 }
2964                                 err = snd_hda_add_nid(codec, kctl, 0, nid);
2965                                 if (err < 0)
2966                                         return err;
2967                         }
2968                         u = knew->private_value;
2969                         for (j = 0; j < 4; j++, u >>= 8) {
2970                                 nid = u & 0xff;
2971                                 if (nid == 0)
2972                                         continue;
2973                                 err = snd_hda_add_nid(codec, kctl, 0, nid);
2974                                 if (err < 0)
2975                                         return err;
2976                         }
2977                 }
2978         }
2979
2980         alc_free_kctls(codec); /* no longer needed */
2981
2982         return 0;
2983 }
2984
2985
2986 /*
2987  * initialize the codec volumes, etc
2988  */
2989
2990 /*
2991  * generic initialization of ADC, input mixers and output mixers
2992  */
2993 static struct hda_verb alc880_volume_init_verbs[] = {
2994         /*
2995          * Unmute ADC0-2 and set the default input to mic-in
2996          */
2997         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2998         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2999         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3000         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3001         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3002         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3003
3004         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3005          * mixer widget
3006          * Note: PASD motherboards uses the Line In 2 as the input for front
3007          * panel mic (mic 2)
3008          */
3009         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
3010         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3011         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3012         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3013         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3014         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3015         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3016         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3017
3018         /*
3019          * Set up output mixers (0x0c - 0x0f)
3020          */
3021         /* set vol=0 to output mixers */
3022         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3023         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3024         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3025         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3026         /* set up input amps for analog loopback */
3027         /* Amp Indices: DAC = 0, mixer = 1 */
3028         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3029         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3030         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3031         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3032         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3033         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3034         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3035         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3036
3037         { }
3038 };
3039
3040 /*
3041  * 3-stack pin configuration:
3042  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
3043  */
3044 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
3045         /*
3046          * preset connection lists of input pins
3047          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
3048          */
3049         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3050         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3051         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3052
3053         /*
3054          * Set pin mode and muting
3055          */
3056         /* set front pin widgets 0x14 for output */
3057         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3058         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3059         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3060         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3061         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3062         /* Mic2 (as headphone out) for HP output */
3063         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3064         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3065         /* Line In pin widget for input */
3066         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3067         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3068         /* Line2 (as front mic) pin widget for input and vref at 80% */
3069         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3070         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3071         /* CD pin widget for input */
3072         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3073
3074         { }
3075 };
3076
3077 /*
3078  * 5-stack pin configuration:
3079  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
3080  * line-in/side = 0x1a, f-mic = 0x1b
3081  */
3082 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
3083         /*
3084          * preset connection lists of input pins
3085          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
3086          */
3087         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3088         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
3089
3090         /*
3091          * Set pin mode and muting
3092          */
3093         /* set pin widgets 0x14-0x17 for output */
3094         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3095         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3096         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3097         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3098         /* unmute pins for output (no gain on this amp) */
3099         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3100         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3101         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3102         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3103
3104         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3105         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3106         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3107         /* Mic2 (as headphone out) for HP output */
3108         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3109         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3110         /* Line In pin widget for input */
3111         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3112         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3113         /* Line2 (as front mic) pin widget for input and vref at 80% */
3114         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3115         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3116         /* CD pin widget for input */
3117         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3118
3119         { }
3120 };
3121
3122 /*
3123  * W810 pin configuration:
3124  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
3125  */
3126 static struct hda_verb alc880_pin_w810_init_verbs[] = {
3127         /* hphone/speaker input selector: front DAC */
3128         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
3129
3130         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3131         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3132         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3133         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3134         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3135         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3136
3137         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3138         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3139
3140         { }
3141 };
3142
3143 /*
3144  * Z71V pin configuration:
3145  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
3146  */
3147 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
3148         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3149         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3150         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3151         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3152
3153         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3154         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3155         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3156         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3157
3158         { }
3159 };
3160
3161 /*
3162  * 6-stack pin configuration:
3163  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
3164  * f-mic = 0x19, line = 0x1a, HP = 0x1b
3165  */
3166 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
3167         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3168
3169         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3170         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3171         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3172         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3173         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3174         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3175         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3176         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3177
3178         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3179         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3180         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3181         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3182         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3183         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3184         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3185         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3186         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3187
3188         { }
3189 };
3190
3191 /*
3192  * Uniwill pin configuration:
3193  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
3194  * line = 0x1a
3195  */
3196 static struct hda_verb alc880_uniwill_init_verbs[] = {
3197         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3198
3199         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3200         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3201         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3202         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3203         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3204         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3205         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3206         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3207         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3208         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3209         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3210         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3211         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3212         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3213
3214         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3215         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3216         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3217         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3218         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3219         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3220         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
3221         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
3222         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3223
3224         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3225         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
3226
3227         { }
3228 };
3229
3230 /*
3231 * Uniwill P53
3232 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
3233  */
3234 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
3235         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3236
3237         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3238         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3239         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3240         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3241         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3242         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3243         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3244         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3245         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3246         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3247         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3248         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3249
3250         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3251         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3252         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3253         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3254         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3255         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3256
3257         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3258         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
3259
3260         { }
3261 };
3262
3263 static struct hda_verb alc880_beep_init_verbs[] = {
3264         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
3265         { }
3266 };
3267
3268 /* auto-toggle front mic */
3269 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
3270 {
3271         unsigned int present;
3272         unsigned char bits;
3273
3274         present = snd_hda_jack_detect(codec, 0x18);
3275         bits = present ? HDA_AMP_MUTE : 0;
3276         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
3277 }
3278
3279 static void alc880_uniwill_setup(struct hda_codec *codec)
3280 {
3281         struct alc_spec *spec = codec->spec;
3282
3283         spec->autocfg.hp_pins[0] = 0x14;
3284         spec->autocfg.speaker_pins[0] = 0x15;
3285         spec->autocfg.speaker_pins[0] = 0x16;
3286 }
3287
3288 static void alc880_uniwill_init_hook(struct hda_codec *codec)
3289 {
3290         alc_automute_amp(codec);
3291         alc880_uniwill_mic_automute(codec);
3292 }
3293
3294 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
3295                                        unsigned int res)
3296 {
3297         /* Looks like the unsol event is incompatible with the standard
3298          * definition.  4bit tag is placed at 28 bit!
3299          */
3300         switch (res >> 28) {
3301         case ALC880_MIC_EVENT:
3302                 alc880_uniwill_mic_automute(codec);
3303                 break;
3304         default:
3305                 alc_automute_amp_unsol_event(codec, res);
3306                 break;
3307         }
3308 }
3309
3310 static void alc880_uniwill_p53_setup(struct hda_codec *codec)
3311 {
3312         struct alc_spec *spec = codec->spec;
3313
3314         spec->autocfg.hp_pins[0] = 0x14;
3315         spec->autocfg.speaker_pins[0] = 0x15;
3316 }
3317
3318 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
3319 {
3320         unsigned int present;
3321
3322         present = snd_hda_codec_read(codec, 0x21, 0,
3323                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
3324         present &= HDA_AMP_VOLMASK;
3325         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
3326                                  HDA_AMP_VOLMASK, present);
3327         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
3328                                  HDA_AMP_VOLMASK, present);
3329 }
3330
3331 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
3332                                            unsigned int res)
3333 {
3334         /* Looks like the unsol event is incompatible with the standard
3335          * definition.  4bit tag is placed at 28 bit!
3336          */
3337         if ((res >> 28) == ALC880_DCVOL_EVENT)
3338                 alc880_uniwill_p53_dcvol_automute(codec);
3339         else
3340                 alc_automute_amp_unsol_event(codec, res);
3341 }
3342
3343 /*
3344  * F1734 pin configuration:
3345  * HP = 0x14, speaker-out = 0x15, mic = 0x18
3346  */
3347 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
3348         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
3349         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
3350         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
3351         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
3352         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
3353
3354         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3355         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3356         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3357         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3358
3359         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3360         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3361         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
3362         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3363         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3364         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3365         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3366         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3367         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3368
3369         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
3370         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
3371
3372         { }
3373 };
3374
3375 /*
3376  * ASUS pin configuration:
3377  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
3378  */
3379 static struct hda_verb alc880_pin_asus_init_verbs[] = {
3380         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
3381         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
3382         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
3383         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
3384
3385         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3386         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3387         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3388         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3389         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3390         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3391         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3392         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3393
3394         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3395         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3396         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3397         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3398         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3399         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3400         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3401         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3402         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3403
3404         { }
3405 };
3406
3407 /* Enable GPIO mask and set output */
3408 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
3409 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
3410 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
3411
3412 /* Clevo m520g init */
3413 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
3414         /* headphone output */
3415         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3416         /* line-out */
3417         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3418         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3419         /* Line-in */
3420         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3421         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3422         /* CD */
3423         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3424         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3425         /* Mic1 (rear panel) */
3426         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3427         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3428         /* Mic2 (front panel) */
3429         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3430         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3431         /* headphone */
3432         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3433         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3434         /* change to EAPD mode */
3435         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3436         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3437
3438         { }
3439 };
3440
3441 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
3442         /* change to EAPD mode */
3443         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3444         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3445
3446         /* Headphone output */
3447         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3448         /* Front output*/
3449         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3450         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
3451
3452         /* Line In pin widget for input */
3453         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3454         /* CD pin widget for input */
3455         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3456         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3457         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3458
3459         /* change to EAPD mode */
3460         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3461         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
3462
3463         { }
3464 };
3465
3466 /*
3467  * LG m1 express dual
3468  *
3469  * Pin assignment:
3470  *   Rear Line-In/Out (blue): 0x14
3471  *   Build-in Mic-In: 0x15
3472  *   Speaker-out: 0x17
3473  *   HP-Out (green): 0x1b
3474  *   Mic-In/Out (red): 0x19
3475  *   SPDIF-Out: 0x1e
3476  */
3477
3478 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
3479 static hda_nid_t alc880_lg_dac_nids[3] = {
3480         0x05, 0x02, 0x03
3481 };
3482
3483 /* seems analog CD is not working */
3484 static struct hda_input_mux alc880_lg_capture_source = {
3485         .num_items = 3,
3486         .items = {
3487                 { "Mic", 0x1 },
3488                 { "Line", 0x5 },
3489                 { "Internal Mic", 0x6 },
3490         },
3491 };
3492
3493 /* 2,4,6 channel modes */
3494 static struct hda_verb alc880_lg_ch2_init[] = {
3495         /* set line-in and mic-in to input */
3496         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
3497         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3498         { }
3499 };
3500
3501 static struct hda_verb alc880_lg_ch4_init[] = {
3502         /* set line-in to out and mic-in to input */
3503         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3504         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3505         { }
3506 };
3507
3508 static struct hda_verb alc880_lg_ch6_init[] = {
3509         /* set line-in and mic-in to output */
3510         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3511         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3512         { }
3513 };
3514
3515 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
3516         { 2, alc880_lg_ch2_init },
3517         { 4, alc880_lg_ch4_init },
3518         { 6, alc880_lg_ch6_init },
3519 };
3520
3521 static struct snd_kcontrol_new alc880_lg_mixer[] = {
3522         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3523         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3524         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3525         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
3526         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
3527         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
3528         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
3529         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
3530         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3531         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3532         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
3533         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
3534         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
3535         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
3536         {
3537                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3538                 .name = "Channel Mode",
3539                 .info = alc_ch_mode_info,
3540                 .get = alc_ch_mode_get,
3541                 .put = alc_ch_mode_put,
3542         },
3543         { } /* end */
3544 };
3545
3546 static struct hda_verb alc880_lg_init_verbs[] = {
3547         /* set capture source to mic-in */
3548         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3549         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3550         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3551         /* mute all amp mixer inputs */
3552         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3553         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3554         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3555         /* line-in to input */
3556         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3557         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3558         /* built-in mic */
3559         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3560         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3561         /* speaker-out */
3562         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3563         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3564         /* mic-in to input */
3565         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3566         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3567         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3568         /* HP-out */
3569         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
3570         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3571         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3572         /* jack sense */
3573         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3574         { }
3575 };
3576
3577 /* toggle speaker-output according to the hp-jack state */
3578 static void alc880_lg_setup(struct hda_codec *codec)
3579 {
3580         struct alc_spec *spec = codec->spec;
3581
3582         spec->autocfg.hp_pins[0] = 0x1b;
3583         spec->autocfg.speaker_pins[0] = 0x17;
3584 }
3585
3586 /*
3587  * LG LW20
3588  *
3589  * Pin assignment:
3590  *   Speaker-out: 0x14
3591  *   Mic-In: 0x18
3592  *   Built-in Mic-In: 0x19
3593  *   Line-In: 0x1b
3594  *   HP-Out: 0x1a
3595  *   SPDIF-Out: 0x1e
3596  */
3597
3598 static struct hda_input_mux alc880_lg_lw_capture_source = {
3599         .num_items = 3,
3600         .items = {
3601                 { "Mic", 0x0 },
3602                 { "Internal Mic", 0x1 },
3603                 { "Line In", 0x2 },
3604         },
3605 };
3606
3607 #define alc880_lg_lw_modes alc880_threestack_modes
3608
3609 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3610         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3611         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3612         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3613         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
3614         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3615         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3616         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3617         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3618         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3619         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3620         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3621         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3622         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
3623         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
3624         {
3625                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3626                 .name = "Channel Mode",
3627                 .info = alc_ch_mode_info,
3628                 .get = alc_ch_mode_get,
3629                 .put = alc_ch_mode_put,
3630         },
3631         { } /* end */
3632 };
3633
3634 static struct hda_verb alc880_lg_lw_init_verbs[] = {
3635         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3636         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3637         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3638
3639         /* set capture source to mic-in */
3640         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3641         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3642         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3643         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3644         /* speaker-out */
3645         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3646         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3647         /* HP-out */
3648         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3649         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3650         /* mic-in to input */
3651         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3652         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3653         /* built-in mic */
3654         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3655         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3656         /* jack sense */
3657         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3658         { }
3659 };
3660
3661 /* toggle speaker-output according to the hp-jack state */
3662 static void alc880_lg_lw_setup(struct hda_codec *codec)
3663 {
3664         struct alc_spec *spec = codec->spec;
3665
3666         spec->autocfg.hp_pins[0] = 0x1b;
3667         spec->autocfg.speaker_pins[0] = 0x14;
3668 }
3669
3670 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
3671         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3672         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
3673         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3674         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3675         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3676         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
3677         { } /* end */
3678 };
3679
3680 static struct hda_input_mux alc880_medion_rim_capture_source = {
3681         .num_items = 2,
3682         .items = {
3683                 { "Mic", 0x0 },
3684                 { "Internal Mic", 0x1 },
3685         },
3686 };
3687
3688 static struct hda_verb alc880_medion_rim_init_verbs[] = {
3689         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3690
3691         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3692         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3693
3694         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3695         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3696         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3697         /* Mic2 (as headphone out) for HP output */
3698         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3699         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3700         /* Internal Speaker */
3701         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3702         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3703
3704         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3705         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3706
3707         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3708         { }
3709 };
3710
3711 /* toggle speaker-output according to the hp-jack state */
3712 static void alc880_medion_rim_automute(struct hda_codec *codec)
3713 {
3714         struct alc_spec *spec = codec->spec;
3715         alc_automute_amp(codec);
3716         /* toggle EAPD */
3717         if (spec->jack_present)
3718                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
3719         else
3720                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
3721 }
3722
3723 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3724                                           unsigned int res)
3725 {
3726         /* Looks like the unsol event is incompatible with the standard
3727          * definition.  4bit tag is placed at 28 bit!
3728          */
3729         if ((res >> 28) == ALC880_HP_EVENT)
3730                 alc880_medion_rim_automute(codec);
3731 }
3732
3733 static void alc880_medion_rim_setup(struct hda_codec *codec)
3734 {
3735         struct alc_spec *spec = codec->spec;
3736
3737         spec->autocfg.hp_pins[0] = 0x14;
3738         spec->autocfg.speaker_pins[0] = 0x1b;
3739 }
3740
3741 #ifdef CONFIG_SND_HDA_POWER_SAVE
3742 static struct hda_amp_list alc880_loopbacks[] = {
3743         { 0x0b, HDA_INPUT, 0 },
3744         { 0x0b, HDA_INPUT, 1 },
3745         { 0x0b, HDA_INPUT, 2 },
3746         { 0x0b, HDA_INPUT, 3 },
3747         { 0x0b, HDA_INPUT, 4 },
3748         { } /* end */
3749 };
3750
3751 static struct hda_amp_list alc880_lg_loopbacks[] = {
3752         { 0x0b, HDA_INPUT, 1 },
3753         { 0x0b, HDA_INPUT, 6 },
3754         { 0x0b, HDA_INPUT, 7 },
3755         { } /* end */
3756 };
3757 #endif
3758
3759 /*
3760  * Common callbacks
3761  */
3762
3763 static int alc_init(struct hda_codec *codec)
3764 {
3765         struct alc_spec *spec = codec->spec;
3766         unsigned int i;
3767
3768         alc_fix_pll(codec);
3769         alc_auto_init_amp(codec, spec->init_amp);
3770
3771         for (i = 0; i < spec->num_init_verbs; i++)
3772                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
3773
3774         if (spec->init_hook)
3775                 spec->init_hook(codec);
3776
3777         hda_call_check_power_status(codec, 0x01);
3778         return 0;
3779 }
3780
3781 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
3782 {
3783         struct alc_spec *spec = codec->spec;
3784
3785         if (spec->unsol_event)
3786                 spec->unsol_event(codec, res);
3787 }
3788
3789 #ifdef CONFIG_SND_HDA_POWER_SAVE
3790 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
3791 {
3792         struct alc_spec *spec = codec->spec;
3793         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
3794 }
3795 #endif
3796
3797 /*
3798  * Analog playback callbacks
3799  */
3800 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
3801                                     struct hda_codec *codec,
3802                                     struct snd_pcm_substream *substream)
3803 {
3804         struct alc_spec *spec = codec->spec;
3805         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
3806                                              hinfo);
3807 }
3808
3809 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3810                                        struct hda_codec *codec,
3811                                        unsigned int stream_tag,
3812                                        unsigned int format,
3813                                        struct snd_pcm_substream *substream)
3814 {
3815         struct alc_spec *spec = codec->spec;
3816         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
3817                                                 stream_tag, format, substream);
3818 }
3819
3820 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3821                                        struct hda_codec *codec,
3822                                        struct snd_pcm_substream *substream)
3823 {
3824         struct alc_spec *spec = codec->spec;
3825         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
3826 }
3827
3828 /*
3829  * Digital out
3830  */
3831 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3832                                         struct hda_codec *codec,
3833                                         struct snd_pcm_substream *substream)
3834 {
3835         struct alc_spec *spec = codec->spec;
3836         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3837 }
3838
3839 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3840                                            struct hda_codec *codec,
3841                                            unsigned int stream_tag,
3842                                            unsigned int format,
3843                                            struct snd_pcm_substream *substream)
3844 {
3845         struct alc_spec *spec = codec->spec;
3846         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3847                                              stream_tag, format, substream);
3848 }
3849
3850 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3851                                            struct hda_codec *codec,
3852                                            struct snd_pcm_substream *substream)
3853 {
3854         struct alc_spec *spec = codec->spec;
3855         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3856 }
3857
3858 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3859                                          struct hda_codec *codec,
3860                                          struct snd_pcm_substream *substream)
3861 {
3862         struct alc_spec *spec = codec->spec;
3863         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3864 }
3865
3866 /*
3867  * Analog capture
3868  */
3869 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3870                                       struct hda_codec *codec,
3871                                       unsigned int stream_tag,
3872                                       unsigned int format,
3873                                       struct snd_pcm_substream *substream)
3874 {
3875         struct alc_spec *spec = codec->spec;
3876
3877         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3878                                    stream_tag, 0, format);
3879         return 0;
3880 }
3881
3882 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3883                                       struct hda_codec *codec,
3884                                       struct snd_pcm_substream *substream)
3885 {
3886         struct alc_spec *spec = codec->spec;
3887
3888         snd_hda_codec_cleanup_stream(codec,
3889                                      spec->adc_nids[substream->number + 1]);
3890         return 0;
3891 }
3892
3893 /* analog capture with dynamic dual-adc changes */
3894 static int dualmic_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3895                                        struct hda_codec *codec,
3896                                        unsigned int stream_tag,
3897                                        unsigned int format,
3898                                        struct snd_pcm_substream *substream)
3899 {
3900         struct alc_spec *spec = codec->spec;
3901         spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
3902         spec->cur_adc_stream_tag = stream_tag;
3903         spec->cur_adc_format = format;
3904         snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
3905         return 0;
3906 }
3907
3908 static int dualmic_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3909                                        struct hda_codec *codec,
3910                                        struct snd_pcm_substream *substream)
3911 {
3912         struct alc_spec *spec = codec->spec;
3913         snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3914         spec->cur_adc = 0;
3915         return 0;
3916 }
3917
3918 static struct hda_pcm_stream dualmic_pcm_analog_capture = {
3919         .substreams = 1,
3920         .channels_min = 2,
3921         .channels_max = 2,
3922         .nid = 0, /* fill later */
3923         .ops = {
3924                 .prepare = dualmic_capture_pcm_prepare,
3925                 .cleanup = dualmic_capture_pcm_cleanup
3926         },
3927 };
3928
3929 /*
3930  */
3931 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3932         .substreams = 1,
3933         .channels_min = 2,
3934         .channels_max = 8,
3935         /* NID is set in alc_build_pcms */
3936         .ops = {
3937                 .open = alc880_playback_pcm_open,
3938                 .prepare = alc880_playback_pcm_prepare,
3939                 .cleanup = alc880_playback_pcm_cleanup
3940         },
3941 };
3942
3943 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3944         .substreams = 1,
3945         .channels_min = 2,
3946         .channels_max = 2,
3947         /* NID is set in alc_build_pcms */
3948 };
3949
3950 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3951         .substreams = 1,
3952         .channels_min = 2,
3953         .channels_max = 2,
3954         /* NID is set in alc_build_pcms */
3955 };
3956
3957 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3958         .substreams = 2, /* can be overridden */
3959         .channels_min = 2,
3960         .channels_max = 2,
3961         /* NID is set in alc_build_pcms */
3962         .ops = {
3963                 .prepare = alc880_alt_capture_pcm_prepare,
3964                 .cleanup = alc880_alt_capture_pcm_cleanup
3965         },
3966 };
3967
3968 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3969         .substreams = 1,
3970         .channels_min = 2,
3971         .channels_max = 2,
3972         /* NID is set in alc_build_pcms */
3973         .ops = {
3974                 .open = alc880_dig_playback_pcm_open,
3975                 .close = alc880_dig_playback_pcm_close,
3976                 .prepare = alc880_dig_playback_pcm_prepare,
3977                 .cleanup = alc880_dig_playback_pcm_cleanup
3978         },
3979 };
3980
3981 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3982         .substreams = 1,
3983         .channels_min = 2,
3984         .channels_max = 2,
3985         /* NID is set in alc_build_pcms */
3986 };
3987
3988 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3989 static struct hda_pcm_stream alc_pcm_null_stream = {
3990         .substreams = 0,
3991         .channels_min = 0,
3992         .channels_max = 0,
3993 };
3994
3995 static int alc_build_pcms(struct hda_codec *codec)
3996 {
3997         struct alc_spec *spec = codec->spec;
3998         struct hda_pcm *info = spec->pcm_rec;
3999         int i;
4000
4001         codec->num_pcms = 1;
4002         codec->pcm_info = info;
4003
4004         if (spec->no_analog)
4005                 goto skip_analog;
4006
4007         snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
4008                  "%s Analog", codec->chip_name);
4009         info->name = spec->stream_name_analog;
4010
4011         if (spec->stream_analog_playback) {
4012                 if (snd_BUG_ON(!spec->multiout.dac_nids))
4013                         return -EINVAL;
4014                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
4015                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
4016         }
4017         if (spec->stream_analog_capture) {
4018                 if (snd_BUG_ON(!spec->adc_nids))
4019                         return -EINVAL;
4020                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
4021                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
4022         }
4023
4024         if (spec->channel_mode) {
4025                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
4026                 for (i = 0; i < spec->num_channel_mode; i++) {
4027                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
4028                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
4029                         }
4030                 }
4031         }
4032
4033  skip_analog:
4034         /* SPDIF for stream index #1 */
4035         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
4036                 snprintf(spec->stream_name_digital,
4037                          sizeof(spec->stream_name_digital),
4038                          "%s Digital", codec->chip_name);
4039                 codec->num_pcms = 2;
4040                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
4041                 info = spec->pcm_rec + 1;
4042                 info->name = spec->stream_name_digital;
4043                 if (spec->dig_out_type)
4044                         info->pcm_type = spec->dig_out_type;
4045                 else
4046                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
4047                 if (spec->multiout.dig_out_nid &&
4048                     spec->stream_digital_playback) {
4049                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
4050                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
4051                 }
4052                 if (spec->dig_in_nid &&
4053                     spec->stream_digital_capture) {
4054                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
4055                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
4056                 }
4057                 /* FIXME: do we need this for all Realtek codec models? */
4058                 codec->spdif_status_reset = 1;
4059         }
4060
4061         if (spec->no_analog)
4062                 return 0;
4063
4064         /* If the use of more than one ADC is requested for the current
4065          * model, configure a second analog capture-only PCM.
4066          */
4067         /* Additional Analaog capture for index #2 */
4068         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
4069             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
4070                 codec->num_pcms = 3;
4071                 info = spec->pcm_rec + 2;
4072                 info->name = spec->stream_name_analog;
4073                 if (spec->alt_dac_nid) {
4074                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
4075                                 *spec->stream_analog_alt_playback;
4076                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
4077                                 spec->alt_dac_nid;
4078                 } else {
4079                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
4080                                 alc_pcm_null_stream;
4081                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
4082                 }
4083                 if (spec->num_adc_nids > 1) {
4084                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
4085                                 *spec->stream_analog_alt_capture;
4086                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
4087                                 spec->adc_nids[1];
4088                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
4089                                 spec->num_adc_nids - 1;
4090                 } else {
4091                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
4092                                 alc_pcm_null_stream;
4093                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
4094                 }
4095         }
4096
4097         return 0;
4098 }
4099
4100 static inline void alc_shutup(struct hda_codec *codec)
4101 {
4102         snd_hda_shutup_pins(codec);
4103 }
4104
4105 static void alc_free_kctls(struct hda_codec *codec)
4106 {
4107         struct alc_spec *spec = codec->spec;
4108
4109         if (spec->kctls.list) {
4110                 struct snd_kcontrol_new *kctl = spec->kctls.list;
4111                 int i;
4112                 for (i = 0; i < spec->kctls.used; i++)
4113                         kfree(kctl[i].name);
4114         }
4115         snd_array_free(&spec->kctls);
4116 }
4117
4118 static void alc_free(struct hda_codec *codec)
4119 {
4120         struct alc_spec *spec = codec->spec;
4121
4122         if (!spec)
4123                 return;
4124
4125         alc_shutup(codec);
4126         alc_free_kctls(codec);
4127         kfree(spec);
4128         snd_hda_detach_beep_device(codec);
4129 }
4130
4131 #ifdef CONFIG_SND_HDA_POWER_SAVE
4132 static void alc_power_eapd(struct hda_codec *codec)
4133 {
4134         /* We currently only handle front, HP */
4135         switch (codec->vendor_id) {
4136         case 0x10ec0260:
4137                 set_eapd(codec, 0x0f, 0);
4138                 set_eapd(codec, 0x10, 0);
4139                 break;
4140         case 0x10ec0262:
4141         case 0x10ec0267:
4142         case 0x10ec0268:
4143         case 0x10ec0269:
4144         case 0x10ec0270:
4145         case 0x10ec0272:
4146         case 0x10ec0660:
4147         case 0x10ec0662:
4148         case 0x10ec0663:
4149         case 0x10ec0862:
4150         case 0x10ec0889:
4151                 set_eapd(codec, 0x14, 0);
4152                 set_eapd(codec, 0x15, 0);
4153                 break;
4154         }
4155 }
4156
4157 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
4158 {
4159         struct alc_spec *spec = codec->spec;
4160         alc_shutup(codec);
4161         if (spec && spec->power_hook)
4162                 spec->power_hook(codec);
4163         return 0;
4164 }
4165 #endif
4166
4167 #ifdef SND_HDA_NEEDS_RESUME
4168 static int alc_resume(struct hda_codec *codec)
4169 {
4170         codec->patch_ops.init(codec);
4171         snd_hda_codec_resume_amp(codec);
4172         snd_hda_codec_resume_cache(codec);
4173         hda_call_check_power_status(codec, 0x01);
4174         return 0;
4175 }
4176 #endif
4177
4178 /*
4179  */
4180 static struct hda_codec_ops alc_patch_ops = {
4181         .build_controls = alc_build_controls,
4182         .build_pcms = alc_build_pcms,
4183         .init = alc_init,
4184         .free = alc_free,
4185         .unsol_event = alc_unsol_event,
4186 #ifdef SND_HDA_NEEDS_RESUME
4187         .resume = alc_resume,
4188 #endif
4189 #ifdef CONFIG_SND_HDA_POWER_SAVE
4190         .suspend = alc_suspend,
4191         .check_power_status = alc_check_power_status,
4192 #endif
4193         .reboot_notify = alc_shutup,
4194 };
4195
4196 /* replace the codec chip_name with the given string */
4197 static int alc_codec_rename(struct hda_codec *codec, const char *name)
4198 {
4199         kfree(codec->chip_name);
4200         codec->chip_name = kstrdup(name, GFP_KERNEL);
4201         if (!codec->chip_name) {
4202                 alc_free(codec);
4203                 return -ENOMEM;
4204         }
4205         return 0;
4206 }
4207
4208 /*
4209  * Test configuration for debugging
4210  *
4211  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
4212  * enum controls.
4213  */
4214 #ifdef CONFIG_SND_DEBUG
4215 static hda_nid_t alc880_test_dac_nids[4] = {
4216         0x02, 0x03, 0x04, 0x05
4217 };
4218
4219 static struct hda_input_mux alc880_test_capture_source = {
4220         .num_items = 7,
4221         .items = {
4222                 { "In-1", 0x0 },
4223                 { "In-2", 0x1 },
4224                 { "In-3", 0x2 },
4225                 { "In-4", 0x3 },
4226                 { "CD", 0x4 },
4227                 { "Front", 0x5 },
4228                 { "Surround", 0x6 },
4229         },
4230 };
4231
4232 static struct hda_channel_mode alc880_test_modes[4] = {
4233         { 2, NULL },
4234         { 4, NULL },
4235         { 6, NULL },
4236         { 8, NULL },
4237 };
4238
4239 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
4240                                  struct snd_ctl_elem_info *uinfo)
4241 {
4242         static char *texts[] = {
4243                 "N/A", "Line Out", "HP Out",
4244                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
4245         };
4246         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4247         uinfo->count = 1;
4248         uinfo->value.enumerated.items = 8;
4249         if (uinfo->value.enumerated.item >= 8)
4250                 uinfo->value.enumerated.item = 7;
4251         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
4252         return 0;
4253 }
4254
4255 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
4256                                 struct snd_ctl_elem_value *ucontrol)
4257 {
4258         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4259         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4260         unsigned int pin_ctl, item = 0;
4261
4262         pin_ctl = snd_hda_codec_read(codec, nid, 0,
4263                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4264         if (pin_ctl & AC_PINCTL_OUT_EN) {
4265                 if (pin_ctl & AC_PINCTL_HP_EN)
4266                         item = 2;
4267                 else
4268                         item = 1;
4269         } else if (pin_ctl & AC_PINCTL_IN_EN) {
4270                 switch (pin_ctl & AC_PINCTL_VREFEN) {
4271                 case AC_PINCTL_VREF_HIZ: item = 3; break;
4272                 case AC_PINCTL_VREF_50:  item = 4; break;
4273                 case AC_PINCTL_VREF_GRD: item = 5; break;
4274                 case AC_PINCTL_VREF_80:  item = 6; break;
4275                 case AC_PINCTL_VREF_100: item = 7; break;
4276                 }
4277         }
4278         ucontrol->value.enumerated.item[0] = item;
4279         return 0;
4280 }
4281
4282 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
4283                                 struct snd_ctl_elem_value *ucontrol)
4284 {
4285         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4286         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4287         static unsigned int ctls[] = {
4288                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
4289                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
4290                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
4291                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
4292                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
4293                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
4294         };
4295         unsigned int old_ctl, new_ctl;
4296
4297         old_ctl = snd_hda_codec_read(codec, nid, 0,
4298                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4299         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
4300         if (old_ctl != new_ctl) {
4301                 int val;
4302                 snd_hda_codec_write_cache(codec, nid, 0,
4303                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4304                                           new_ctl);
4305                 val = ucontrol->value.enumerated.item[0] >= 3 ?
4306                         HDA_AMP_MUTE : 0;
4307                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4308                                          HDA_AMP_MUTE, val);
4309                 return 1;
4310         }
4311         return 0;
4312 }
4313
4314 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
4315                                  struct snd_ctl_elem_info *uinfo)
4316 {
4317         static char *texts[] = {
4318                 "Front", "Surround", "CLFE", "Side"
4319         };
4320         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4321         uinfo->count = 1;
4322         uinfo->value.enumerated.items = 4;
4323         if (uinfo->value.enumerated.item >= 4)
4324                 uinfo->value.enumerated.item = 3;
4325         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
4326         return 0;
4327 }
4328
4329 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
4330                                 struct snd_ctl_elem_value *ucontrol)
4331 {
4332         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4333         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4334         unsigned int sel;
4335
4336         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
4337         ucontrol->value.enumerated.item[0] = sel & 3;
4338         return 0;
4339 }
4340
4341 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
4342                                 struct snd_ctl_elem_value *ucontrol)
4343 {
4344         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4345         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4346         unsigned int sel;
4347
4348         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
4349         if (ucontrol->value.enumerated.item[0] != sel) {
4350                 sel = ucontrol->value.enumerated.item[0] & 3;
4351                 snd_hda_codec_write_cache(codec, nid, 0,
4352                                           AC_VERB_SET_CONNECT_SEL, sel);
4353                 return 1;
4354         }
4355         return 0;
4356 }
4357
4358 #define PIN_CTL_TEST(xname,nid) {                       \
4359                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
4360                         .name = xname,                 \
4361                         .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
4362                         .info = alc_test_pin_ctl_info, \
4363                         .get = alc_test_pin_ctl_get,   \
4364                         .put = alc_test_pin_ctl_put,   \
4365                         .private_value = nid           \
4366                         }
4367
4368 #define PIN_SRC_TEST(xname,nid) {                       \
4369                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
4370                         .name = xname,                 \
4371                         .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
4372                         .info = alc_test_pin_src_info, \
4373                         .get = alc_test_pin_src_get,   \
4374                         .put = alc_test_pin_src_put,   \
4375                         .private_value = nid           \
4376                         }
4377
4378 static struct snd_kcontrol_new alc880_test_mixer[] = {
4379         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4380         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
4381         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
4382         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
4383         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4384         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
4385         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
4386         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
4387         PIN_CTL_TEST("Front Pin Mode", 0x14),
4388         PIN_CTL_TEST("Surround Pin Mode", 0x15),
4389         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
4390         PIN_CTL_TEST("Side Pin Mode", 0x17),
4391         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
4392         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
4393         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
4394         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
4395         PIN_SRC_TEST("In-1 Pin Source", 0x18),
4396         PIN_SRC_TEST("In-2 Pin Source", 0x19),
4397         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
4398         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
4399         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
4400         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
4401         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
4402         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
4403         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
4404         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
4405         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
4406         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
4407         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
4408         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
4409         {
4410                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4411                 .name = "Channel Mode",
4412                 .info = alc_ch_mode_info,
4413                 .get = alc_ch_mode_get,
4414                 .put = alc_ch_mode_put,
4415         },
4416         { } /* end */
4417 };
4418
4419 static struct hda_verb alc880_test_init_verbs[] = {
4420         /* Unmute inputs of 0x0c - 0x0f */
4421         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4422         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4423         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4424         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4425         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4426         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4427         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4428         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4429         /* Vol output for 0x0c-0x0f */
4430         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4431         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4432         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4433         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4434         /* Set output pins 0x14-0x17 */
4435         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4436         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4437         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4438         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4439         /* Unmute output pins 0x14-0x17 */
4440         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4441         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4442         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4443         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4444         /* Set input pins 0x18-0x1c */
4445         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4446         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4447         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4448         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4449         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4450         /* Mute input pins 0x18-0x1b */
4451         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4452         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4453         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4454         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4455         /* ADC set up */
4456         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4457         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
4458         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4459         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
4460         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4461         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
4462         /* Analog input/passthru */
4463         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4464         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4465         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4466         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4467         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4468         { }
4469 };
4470 #endif
4471
4472 /*
4473  */
4474
4475 static const char *alc880_models[ALC880_MODEL_LAST] = {
4476         [ALC880_3ST]            = "3stack",
4477         [ALC880_TCL_S700]       = "tcl",
4478         [ALC880_3ST_DIG]        = "3stack-digout",
4479         [ALC880_CLEVO]          = "clevo",
4480         [ALC880_5ST]            = "5stack",
4481         [ALC880_5ST_DIG]        = "5stack-digout",
4482         [ALC880_W810]           = "w810",
4483         [ALC880_Z71V]           = "z71v",
4484         [ALC880_6ST]            = "6stack",
4485         [ALC880_6ST_DIG]        = "6stack-digout",
4486         [ALC880_ASUS]           = "asus",
4487         [ALC880_ASUS_W1V]       = "asus-w1v",
4488         [ALC880_ASUS_DIG]       = "asus-dig",
4489         [ALC880_ASUS_DIG2]      = "asus-dig2",
4490         [ALC880_UNIWILL_DIG]    = "uniwill",
4491         [ALC880_UNIWILL_P53]    = "uniwill-p53",
4492         [ALC880_FUJITSU]        = "fujitsu",
4493         [ALC880_F1734]          = "F1734",
4494         [ALC880_LG]             = "lg",
4495         [ALC880_LG_LW]          = "lg-lw",
4496         [ALC880_MEDION_RIM]     = "medion",
4497 #ifdef CONFIG_SND_DEBUG
4498         [ALC880_TEST]           = "test",
4499 #endif
4500         [ALC880_AUTO]           = "auto",
4501 };
4502
4503 static struct snd_pci_quirk alc880_cfg_tbl[] = {
4504         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
4505         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
4506         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
4507         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
4508         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
4509         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
4510         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
4511         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
4512         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
4513         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
4514         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
4515         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
4516         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
4517         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
4518         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
4519         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
4520         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
4521         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
4522         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
4523         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
4524         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
4525         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
4526         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
4527         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
4528         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
4529         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
4530         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
4531         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
4532         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
4533         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
4534         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
4535         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
4536         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
4537         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
4538         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
4539         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
4540         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
4541         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
4542         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
4543         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
4544         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
4545         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
4546         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
4547         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
4548         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
4549         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
4550         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
4551         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
4552         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
4553         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_F1734),
4554         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
4555         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
4556         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
4557         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
4558         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
4559         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
4560         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
4561         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
4562         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
4563         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
4564         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
4565         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
4566         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
4567         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
4568         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
4569         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
4570         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
4571         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
4572         /* default Intel */
4573         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
4574         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
4575         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
4576         {}
4577 };
4578
4579 /*
4580  * ALC880 codec presets
4581  */
4582 static struct alc_config_preset alc880_presets[] = {
4583         [ALC880_3ST] = {
4584                 .mixers = { alc880_three_stack_mixer },
4585                 .init_verbs = { alc880_volume_init_verbs,
4586                                 alc880_pin_3stack_init_verbs },
4587                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4588                 .dac_nids = alc880_dac_nids,
4589                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4590                 .channel_mode = alc880_threestack_modes,
4591                 .need_dac_fix = 1,
4592                 .input_mux = &alc880_capture_source,
4593         },
4594         [ALC880_3ST_DIG] = {
4595                 .mixers = { alc880_three_stack_mixer },
4596                 .init_verbs = { alc880_volume_init_verbs,
4597                                 alc880_pin_3stack_init_verbs },
4598                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4599                 .dac_nids = alc880_dac_nids,
4600                 .dig_out_nid = ALC880_DIGOUT_NID,
4601                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4602                 .channel_mode = alc880_threestack_modes,
4603                 .need_dac_fix = 1,
4604                 .input_mux = &alc880_capture_source,
4605         },
4606         [ALC880_TCL_S700] = {
4607                 .mixers = { alc880_tcl_s700_mixer },
4608                 .init_verbs = { alc880_volume_init_verbs,
4609                                 alc880_pin_tcl_S700_init_verbs,
4610                                 alc880_gpio2_init_verbs },
4611                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4612                 .dac_nids = alc880_dac_nids,
4613                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
4614                 .num_adc_nids = 1, /* single ADC */
4615                 .hp_nid = 0x03,
4616                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4617                 .channel_mode = alc880_2_jack_modes,
4618                 .input_mux = &alc880_capture_source,
4619         },
4620         [ALC880_5ST] = {
4621                 .mixers = { alc880_three_stack_mixer,
4622                             alc880_five_stack_mixer},
4623                 .init_verbs = { alc880_volume_init_verbs,
4624                                 alc880_pin_5stack_init_verbs },
4625                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4626                 .dac_nids = alc880_dac_nids,
4627                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4628                 .channel_mode = alc880_fivestack_modes,
4629                 .input_mux = &alc880_capture_source,
4630         },
4631         [ALC880_5ST_DIG] = {
4632                 .mixers = { alc880_three_stack_mixer,
4633                             alc880_five_stack_mixer },
4634                 .init_verbs = { alc880_volume_init_verbs,
4635                                 alc880_pin_5stack_init_verbs },
4636                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4637                 .dac_nids = alc880_dac_nids,
4638                 .dig_out_nid = ALC880_DIGOUT_NID,
4639                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4640                 .channel_mode = alc880_fivestack_modes,
4641                 .input_mux = &alc880_capture_source,
4642         },
4643         [ALC880_6ST] = {
4644                 .mixers = { alc880_six_stack_mixer },
4645                 .init_verbs = { alc880_volume_init_verbs,
4646                                 alc880_pin_6stack_init_verbs },
4647                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4648                 .dac_nids = alc880_6st_dac_nids,
4649                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4650                 .channel_mode = alc880_sixstack_modes,
4651                 .input_mux = &alc880_6stack_capture_source,
4652         },
4653         [ALC880_6ST_DIG] = {
4654                 .mixers = { alc880_six_stack_mixer },
4655                 .init_verbs = { alc880_volume_init_verbs,
4656                                 alc880_pin_6stack_init_verbs },
4657                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4658                 .dac_nids = alc880_6st_dac_nids,
4659                 .dig_out_nid = ALC880_DIGOUT_NID,
4660                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4661                 .channel_mode = alc880_sixstack_modes,
4662                 .input_mux = &alc880_6stack_capture_source,
4663         },
4664         [ALC880_W810] = {
4665                 .mixers = { alc880_w810_base_mixer },
4666                 .init_verbs = { alc880_volume_init_verbs,
4667                                 alc880_pin_w810_init_verbs,
4668                                 alc880_gpio2_init_verbs },
4669                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
4670                 .dac_nids = alc880_w810_dac_nids,
4671                 .dig_out_nid = ALC880_DIGOUT_NID,
4672                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4673                 .channel_mode = alc880_w810_modes,
4674                 .input_mux = &alc880_capture_source,
4675         },
4676         [ALC880_Z71V] = {
4677                 .mixers = { alc880_z71v_mixer },
4678                 .init_verbs = { alc880_volume_init_verbs,
4679                                 alc880_pin_z71v_init_verbs },
4680                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
4681                 .dac_nids = alc880_z71v_dac_nids,
4682                 .dig_out_nid = ALC880_DIGOUT_NID,
4683                 .hp_nid = 0x03,
4684                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4685                 .channel_mode = alc880_2_jack_modes,
4686                 .input_mux = &alc880_capture_source,
4687         },
4688         [ALC880_F1734] = {
4689                 .mixers = { alc880_f1734_mixer },
4690                 .init_verbs = { alc880_volume_init_verbs,
4691                                 alc880_pin_f1734_init_verbs },
4692                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
4693                 .dac_nids = alc880_f1734_dac_nids,
4694                 .hp_nid = 0x02,
4695                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4696                 .channel_mode = alc880_2_jack_modes,
4697                 .input_mux = &alc880_f1734_capture_source,
4698                 .unsol_event = alc880_uniwill_p53_unsol_event,
4699                 .setup = alc880_uniwill_p53_setup,
4700                 .init_hook = alc_automute_amp,
4701         },
4702         [ALC880_ASUS] = {
4703                 .mixers = { alc880_asus_mixer },
4704                 .init_verbs = { alc880_volume_init_verbs,
4705                                 alc880_pin_asus_init_verbs,
4706                                 alc880_gpio1_init_verbs },
4707                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4708                 .dac_nids = alc880_asus_dac_nids,
4709                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4710                 .channel_mode = alc880_asus_modes,
4711                 .need_dac_fix = 1,
4712                 .input_mux = &alc880_capture_source,
4713         },
4714         [ALC880_ASUS_DIG] = {
4715                 .mixers = { alc880_asus_mixer },
4716                 .init_verbs = { alc880_volume_init_verbs,
4717                                 alc880_pin_asus_init_verbs,
4718                                 alc880_gpio1_init_verbs },
4719                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4720                 .dac_nids = alc880_asus_dac_nids,
4721                 .dig_out_nid = ALC880_DIGOUT_NID,
4722                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4723                 .channel_mode = alc880_asus_modes,
4724                 .need_dac_fix = 1,
4725                 .input_mux = &alc880_capture_source,
4726         },
4727         [ALC880_ASUS_DIG2] = {
4728                 .mixers = { alc880_asus_mixer },
4729                 .init_verbs = { alc880_volume_init_verbs,
4730                                 alc880_pin_asus_init_verbs,
4731                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
4732                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4733                 .dac_nids = alc880_asus_dac_nids,
4734                 .dig_out_nid = ALC880_DIGOUT_NID,
4735                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4736                 .channel_mode = alc880_asus_modes,
4737                 .need_dac_fix = 1,
4738                 .input_mux = &alc880_capture_source,
4739         },
4740         [ALC880_ASUS_W1V] = {
4741                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
4742                 .init_verbs = { alc880_volume_init_verbs,
4743                                 alc880_pin_asus_init_verbs,
4744                                 alc880_gpio1_init_verbs },
4745                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4746                 .dac_nids = alc880_asus_dac_nids,
4747                 .dig_out_nid = ALC880_DIGOUT_NID,
4748                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4749                 .channel_mode = alc880_asus_modes,
4750                 .need_dac_fix = 1,
4751                 .input_mux = &alc880_capture_source,
4752         },
4753         [ALC880_UNIWILL_DIG] = {
4754                 .mixers = { alc880_asus_mixer },
4755                 .init_verbs = { alc880_volume_init_verbs,
4756                                 alc880_pin_asus_init_verbs },
4757                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4758                 .dac_nids = alc880_asus_dac_nids,
4759                 .dig_out_nid = ALC880_DIGOUT_NID,
4760                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4761                 .channel_mode = alc880_asus_modes,
4762                 .need_dac_fix = 1,
4763                 .input_mux = &alc880_capture_source,
4764         },
4765         [ALC880_UNIWILL] = {
4766                 .mixers = { alc880_uniwill_mixer },
4767                 .init_verbs = { alc880_volume_init_verbs,
4768                                 alc880_uniwill_init_verbs },
4769                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4770                 .dac_nids = alc880_asus_dac_nids,
4771                 .dig_out_nid = ALC880_DIGOUT_NID,
4772                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4773                 .channel_mode = alc880_threestack_modes,
4774                 .need_dac_fix = 1,
4775                 .input_mux = &alc880_capture_source,
4776                 .unsol_event = alc880_uniwill_unsol_event,
4777                 .setup = alc880_uniwill_setup,
4778                 .init_hook = alc880_uniwill_init_hook,
4779         },
4780         [ALC880_UNIWILL_P53] = {
4781                 .mixers = { alc880_uniwill_p53_mixer },
4782                 .init_verbs = { alc880_volume_init_verbs,
4783                                 alc880_uniwill_p53_init_verbs },
4784                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4785                 .dac_nids = alc880_asus_dac_nids,
4786                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4787                 .channel_mode = alc880_threestack_modes,
4788                 .input_mux = &alc880_capture_source,
4789                 .unsol_event = alc880_uniwill_p53_unsol_event,
4790                 .setup = alc880_uniwill_p53_setup,
4791                 .init_hook = alc_automute_amp,
4792         },
4793         [ALC880_FUJITSU] = {
4794                 .mixers = { alc880_fujitsu_mixer },
4795                 .init_verbs = { alc880_volume_init_verbs,
4796                                 alc880_uniwill_p53_init_verbs,
4797                                 alc880_beep_init_verbs },
4798                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4799                 .dac_nids = alc880_dac_nids,
4800                 .dig_out_nid = ALC880_DIGOUT_NID,
4801                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4802                 .channel_mode = alc880_2_jack_modes,
4803                 .input_mux = &alc880_capture_source,
4804                 .unsol_event = alc880_uniwill_p53_unsol_event,
4805                 .setup = alc880_uniwill_p53_setup,
4806                 .init_hook = alc_automute_amp,
4807         },
4808         [ALC880_CLEVO] = {
4809                 .mixers = { alc880_three_stack_mixer },
4810                 .init_verbs = { alc880_volume_init_verbs,
4811                                 alc880_pin_clevo_init_verbs },
4812                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4813                 .dac_nids = alc880_dac_nids,
4814                 .hp_nid = 0x03,
4815                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4816                 .channel_mode = alc880_threestack_modes,
4817                 .need_dac_fix = 1,
4818                 .input_mux = &alc880_capture_source,
4819         },
4820         [ALC880_LG] = {
4821                 .mixers = { alc880_lg_mixer },
4822                 .init_verbs = { alc880_volume_init_verbs,
4823                                 alc880_lg_init_verbs },
4824                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
4825                 .dac_nids = alc880_lg_dac_nids,
4826                 .dig_out_nid = ALC880_DIGOUT_NID,
4827                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
4828                 .channel_mode = alc880_lg_ch_modes,
4829                 .need_dac_fix = 1,
4830                 .input_mux = &alc880_lg_capture_source,
4831                 .unsol_event = alc_automute_amp_unsol_event,
4832                 .setup = alc880_lg_setup,
4833                 .init_hook = alc_automute_amp,
4834 #ifdef CONFIG_SND_HDA_POWER_SAVE
4835                 .loopbacks = alc880_lg_loopbacks,
4836 #endif
4837         },
4838         [ALC880_LG_LW] = {
4839                 .mixers = { alc880_lg_lw_mixer },
4840                 .init_verbs = { alc880_volume_init_verbs,
4841                                 alc880_lg_lw_init_verbs },
4842                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4843                 .dac_nids = alc880_dac_nids,
4844                 .dig_out_nid = ALC880_DIGOUT_NID,
4845                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
4846                 .channel_mode = alc880_lg_lw_modes,
4847                 .input_mux = &alc880_lg_lw_capture_source,
4848                 .unsol_event = alc_automute_amp_unsol_event,
4849                 .setup = alc880_lg_lw_setup,
4850                 .init_hook = alc_automute_amp,
4851         },
4852         [ALC880_MEDION_RIM] = {
4853                 .mixers = { alc880_medion_rim_mixer },
4854                 .init_verbs = { alc880_volume_init_verbs,
4855                                 alc880_medion_rim_init_verbs,
4856                                 alc_gpio2_init_verbs },
4857                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4858                 .dac_nids = alc880_dac_nids,
4859                 .dig_out_nid = ALC880_DIGOUT_NID,
4860                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4861                 .channel_mode = alc880_2_jack_modes,
4862                 .input_mux = &alc880_medion_rim_capture_source,
4863                 .unsol_event = alc880_medion_rim_unsol_event,
4864                 .setup = alc880_medion_rim_setup,
4865                 .init_hook = alc880_medion_rim_automute,
4866         },
4867 #ifdef CONFIG_SND_DEBUG
4868         [ALC880_TEST] = {
4869                 .mixers = { alc880_test_mixer },
4870                 .init_verbs = { alc880_test_init_verbs },
4871                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
4872                 .dac_nids = alc880_test_dac_nids,
4873                 .dig_out_nid = ALC880_DIGOUT_NID,
4874                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
4875                 .channel_mode = alc880_test_modes,
4876                 .input_mux = &alc880_test_capture_source,
4877         },
4878 #endif
4879 };
4880
4881 /*
4882  * Automatic parse of I/O pins from the BIOS configuration
4883  */
4884
4885 enum {
4886         ALC_CTL_WIDGET_VOL,
4887         ALC_CTL_WIDGET_MUTE,
4888         ALC_CTL_BIND_MUTE,
4889 };
4890 static struct snd_kcontrol_new alc880_control_templates[] = {
4891         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
4892         HDA_CODEC_MUTE(NULL, 0, 0, 0),
4893         HDA_BIND_MUTE(NULL, 0, 0, 0),
4894 };
4895
4896 /* add dynamic controls */
4897 static int add_control(struct alc_spec *spec, int type, const char *name,
4898                        int cidx, unsigned long val)
4899 {
4900         struct snd_kcontrol_new *knew;
4901
4902         snd_array_init(&spec->kctls, sizeof(*knew), 32);
4903         knew = snd_array_new(&spec->kctls);
4904         if (!knew)
4905                 return -ENOMEM;
4906         *knew = alc880_control_templates[type];
4907         knew->name = kstrdup(name, GFP_KERNEL);
4908         if (!knew->name)
4909                 return -ENOMEM;
4910         knew->index = cidx;
4911         if (get_amp_nid_(val))
4912                 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
4913         knew->private_value = val;
4914         return 0;
4915 }
4916
4917 static int add_control_with_pfx(struct alc_spec *spec, int type,
4918                                 const char *pfx, const char *dir,
4919                                 const char *sfx, int cidx, unsigned long val)
4920 {
4921         char name[32];
4922         snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
4923         return add_control(spec, type, name, cidx, val);
4924 }
4925
4926 #define add_pb_vol_ctrl(spec, type, pfx, val)                   \
4927         add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
4928 #define add_pb_sw_ctrl(spec, type, pfx, val)                    \
4929         add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
4930 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val)                   \
4931         add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
4932 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val)                    \
4933         add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
4934
4935 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
4936 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
4937 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
4938 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
4939 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
4940 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
4941 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
4942 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
4943 #define ALC880_PIN_CD_NID               0x1c
4944
4945 /* fill in the dac_nids table from the parsed pin configuration */
4946 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
4947                                      const struct auto_pin_cfg *cfg)
4948 {
4949         hda_nid_t nid;
4950         int assigned[4];
4951         int i, j;
4952
4953         memset(assigned, 0, sizeof(assigned));
4954         spec->multiout.dac_nids = spec->private_dac_nids;
4955
4956         /* check the pins hardwired to audio widget */
4957         for (i = 0; i < cfg->line_outs; i++) {
4958                 nid = cfg->line_out_pins[i];
4959                 if (alc880_is_fixed_pin(nid)) {
4960                         int idx = alc880_fixed_pin_idx(nid);
4961                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
4962                         assigned[idx] = 1;
4963                 }
4964         }
4965         /* left pins can be connect to any audio widget */
4966         for (i = 0; i < cfg->line_outs; i++) {
4967                 nid = cfg->line_out_pins[i];
4968                 if (alc880_is_fixed_pin(nid))
4969                         continue;
4970                 /* search for an empty channel */
4971                 for (j = 0; j < cfg->line_outs; j++) {
4972                         if (!assigned[j]) {
4973                                 spec->multiout.dac_nids[i] =
4974                                         alc880_idx_to_dac(j);
4975                                 assigned[j] = 1;
4976                                 break;
4977                         }
4978                 }
4979         }
4980         spec->multiout.num_dacs = cfg->line_outs;
4981         return 0;
4982 }
4983
4984 /* add playback controls from the parsed DAC table */
4985 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4986                                              const struct auto_pin_cfg *cfg)
4987 {
4988         static const char *chname[4] = {
4989                 "Front", "Surround", NULL /*CLFE*/, "Side"
4990         };
4991         hda_nid_t nid;
4992         int i, err;
4993
4994         for (i = 0; i < cfg->line_outs; i++) {
4995                 if (!spec->multiout.dac_nids[i])
4996                         continue;
4997                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4998                 if (i == 2) {
4999                         /* Center/LFE */
5000                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
5001                                               "Center",
5002                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
5003                                                               HDA_OUTPUT));
5004                         if (err < 0)
5005                                 return err;
5006                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
5007                                               "LFE",
5008                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
5009                                                               HDA_OUTPUT));
5010                         if (err < 0)
5011                                 return err;
5012                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
5013                                              "Center",
5014                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
5015                                                               HDA_INPUT));
5016                         if (err < 0)
5017                                 return err;
5018                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
5019                                              "LFE",
5020                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
5021                                                               HDA_INPUT));
5022                         if (err < 0)
5023                                 return err;
5024                 } else {
5025                         const char *pfx;
5026                         if (cfg->line_outs == 1 &&
5027                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
5028                                 pfx = "Speaker";
5029                         else
5030                                 pfx = chname[i];
5031                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
5032                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
5033                                                               HDA_OUTPUT));
5034                         if (err < 0)
5035                                 return err;
5036                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
5037                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
5038                                                               HDA_INPUT));
5039                         if (err < 0)
5040                                 return err;
5041                 }
5042         }
5043         return 0;
5044 }
5045
5046 /* add playback controls for speaker and HP outputs */
5047 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
5048                                         const char *pfx)
5049 {
5050         hda_nid_t nid;
5051         int err;
5052
5053         if (!pin)
5054                 return 0;
5055
5056         if (alc880_is_fixed_pin(pin)) {
5057                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
5058                 /* specify the DAC as the extra output */
5059                 if (!spec->multiout.hp_nid)
5060                         spec->multiout.hp_nid = nid;
5061                 else
5062                         spec->multiout.extra_out_nid[0] = nid;
5063                 /* control HP volume/switch on the output mixer amp */
5064                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
5065                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
5066                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
5067                 if (err < 0)
5068                         return err;
5069                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
5070                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
5071                 if (err < 0)
5072                         return err;
5073         } else if (alc880_is_multi_pin(pin)) {
5074                 /* set manual connection */
5075                 /* we have only a switch on HP-out PIN */
5076                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
5077                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5078                 if (err < 0)
5079                         return err;
5080         }
5081         return 0;
5082 }
5083
5084 /* create input playback/capture controls for the given pin */
5085 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
5086                             const char *ctlname, int ctlidx,
5087                             int idx, hda_nid_t mix_nid)
5088 {
5089         int err;
5090
5091         err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
5092                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
5093         if (err < 0)
5094                 return err;
5095         err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
5096                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
5097         if (err < 0)
5098                 return err;
5099         return 0;
5100 }
5101
5102 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
5103 {
5104         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
5105         return (pincap & AC_PINCAP_IN) != 0;
5106 }
5107
5108 /* create playback/capture controls for input pins */
5109 static int alc_auto_create_input_ctls(struct hda_codec *codec,
5110                                       const struct auto_pin_cfg *cfg,
5111                                       hda_nid_t mixer,
5112                                       hda_nid_t cap1, hda_nid_t cap2)
5113 {
5114         struct alc_spec *spec = codec->spec;
5115         struct hda_input_mux *imux = &spec->private_imux[0];
5116         int i, err, idx, type, type_idx = 0;
5117
5118         for (i = 0; i < cfg->num_inputs; i++) {
5119                 hda_nid_t pin;
5120                 const char *label;
5121
5122                 pin = cfg->inputs[i].pin;
5123                 if (!alc_is_input_pin(codec, pin))
5124                         continue;
5125
5126                 type = cfg->inputs[i].type;
5127                 if (i > 0 && type == cfg->inputs[i - 1].type)
5128                         type_idx++;
5129                 else
5130                         type_idx = 0;
5131                 label = hda_get_autocfg_input_label(codec, cfg, i);
5132                 if (mixer) {
5133                         idx = get_connection_index(codec, mixer, pin);
5134                         if (idx >= 0) {
5135                                 err = new_analog_input(spec, pin,
5136                                                        label, type_idx,
5137                                                        idx, mixer);
5138                                 if (err < 0)
5139                                         return err;
5140                         }
5141                 }
5142
5143                 if (!cap1)
5144                         continue;
5145                 idx = get_connection_index(codec, cap1, pin);
5146                 if (idx < 0 && cap2)
5147                         idx = get_connection_index(codec, cap2, pin);
5148                 if (idx >= 0)
5149                         snd_hda_add_imux_item(imux, label, idx, NULL);
5150         }
5151         return 0;
5152 }
5153
5154 static int alc880_auto_create_input_ctls(struct hda_codec *codec,
5155                                                 const struct auto_pin_cfg *cfg)
5156 {
5157         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x08, 0x09);
5158 }
5159
5160 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
5161                                unsigned int pin_type)
5162 {
5163         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5164                             pin_type);
5165         /* unmute pin */
5166         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5167                             AMP_OUT_UNMUTE);
5168 }
5169
5170 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
5171                                               hda_nid_t nid, int pin_type,
5172                                               int dac_idx)
5173 {
5174         alc_set_pin_output(codec, nid, pin_type);
5175         /* need the manual connection? */
5176         if (alc880_is_multi_pin(nid)) {
5177                 struct alc_spec *spec = codec->spec;
5178                 int idx = alc880_multi_pin_idx(nid);
5179                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
5180                                     AC_VERB_SET_CONNECT_SEL,
5181                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
5182         }
5183 }
5184
5185 static int get_pin_type(int line_out_type)
5186 {
5187         if (line_out_type == AUTO_PIN_HP_OUT)
5188                 return PIN_HP;
5189         else
5190                 return PIN_OUT;
5191 }
5192
5193 static void alc880_auto_init_multi_out(struct hda_codec *codec)
5194 {
5195         struct alc_spec *spec = codec->spec;
5196         int i;
5197
5198         for (i = 0; i < spec->autocfg.line_outs; i++) {
5199                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
5200                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5201                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
5202         }
5203 }
5204
5205 static void alc880_auto_init_extra_out(struct hda_codec *codec)
5206 {
5207         struct alc_spec *spec = codec->spec;
5208         hda_nid_t pin;
5209
5210         pin = spec->autocfg.speaker_pins[0];
5211         if (pin) /* connect to front */
5212                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
5213         pin = spec->autocfg.hp_pins[0];
5214         if (pin) /* connect to front */
5215                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
5216 }
5217
5218 static void alc880_auto_init_analog_input(struct hda_codec *codec)
5219 {
5220         struct alc_spec *spec = codec->spec;
5221         struct auto_pin_cfg *cfg = &spec->autocfg;
5222         int i;
5223
5224         for (i = 0; i < cfg->num_inputs; i++) {
5225                 hda_nid_t nid = cfg->inputs[i].pin;
5226                 if (alc_is_input_pin(codec, nid)) {
5227                         alc_set_input_pin(codec, nid, cfg->inputs[i].type);
5228                         if (nid != ALC880_PIN_CD_NID &&
5229                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
5230                                 snd_hda_codec_write(codec, nid, 0,
5231                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5232                                                     AMP_OUT_MUTE);
5233                 }
5234         }
5235 }
5236
5237 static void alc880_auto_init_input_src(struct hda_codec *codec)
5238 {
5239         struct alc_spec *spec = codec->spec;
5240         int c;
5241
5242         for (c = 0; c < spec->num_adc_nids; c++) {
5243                 unsigned int mux_idx;
5244                 const struct hda_input_mux *imux;
5245                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
5246                 imux = &spec->input_mux[mux_idx];
5247                 if (!imux->num_items && mux_idx > 0)
5248                         imux = &spec->input_mux[0];
5249                 if (imux)
5250                         snd_hda_codec_write(codec, spec->adc_nids[c], 0,
5251                                             AC_VERB_SET_CONNECT_SEL,
5252                                             imux->items[0].index);
5253         }
5254 }
5255
5256 /* parse the BIOS configuration and set up the alc_spec */
5257 /* return 1 if successful, 0 if the proper config is not found,
5258  * or a negative error code
5259  */
5260 static int alc880_parse_auto_config(struct hda_codec *codec)
5261 {
5262         struct alc_spec *spec = codec->spec;
5263         int err;
5264         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
5265
5266         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5267                                            alc880_ignore);
5268         if (err < 0)
5269                 return err;
5270         if (!spec->autocfg.line_outs)
5271                 return 0; /* can't find valid BIOS pin config */
5272
5273         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
5274         if (err < 0)
5275                 return err;
5276         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
5277         if (err < 0)
5278                 return err;
5279         err = alc880_auto_create_extra_out(spec,
5280                                            spec->autocfg.speaker_pins[0],
5281                                            "Speaker");
5282         if (err < 0)
5283                 return err;
5284         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
5285                                            "Headphone");
5286         if (err < 0)
5287                 return err;
5288         err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
5289         if (err < 0)
5290                 return err;
5291
5292         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5293
5294         alc_auto_parse_digital(codec);
5295
5296         if (spec->kctls.list)
5297                 add_mixer(spec, spec->kctls.list);
5298
5299         add_verb(spec, alc880_volume_init_verbs);
5300
5301         spec->num_mux_defs = 1;
5302         spec->input_mux = &spec->private_imux[0];
5303
5304         alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
5305
5306         return 1;
5307 }
5308
5309 /* additional initialization for auto-configuration model */
5310 static void alc880_auto_init(struct hda_codec *codec)
5311 {
5312         struct alc_spec *spec = codec->spec;
5313         alc880_auto_init_multi_out(codec);
5314         alc880_auto_init_extra_out(codec);
5315         alc880_auto_init_analog_input(codec);
5316         alc880_auto_init_input_src(codec);
5317         alc_auto_init_digital(codec);
5318         if (spec->unsol_event)
5319                 alc_inithook(codec);
5320 }
5321
5322 /* check the ADC/MUX contains all input pins; some ADC/MUX contains only
5323  * one of two digital mic pins, e.g. on ALC272
5324  */
5325 static void fixup_automic_adc(struct hda_codec *codec)
5326 {
5327         struct alc_spec *spec = codec->spec;
5328         int i;
5329
5330         for (i = 0; i < spec->num_adc_nids; i++) {
5331                 hda_nid_t cap = spec->capsrc_nids ?
5332                         spec->capsrc_nids[i] : spec->adc_nids[i];
5333                 int iidx, eidx;
5334
5335                 iidx = get_connection_index(codec, cap, spec->int_mic.pin);
5336                 if (iidx < 0)
5337                         continue;
5338                 eidx = get_connection_index(codec, cap, spec->ext_mic.pin);
5339                 if (eidx < 0)
5340                         continue;
5341                 spec->int_mic.mux_idx = iidx;
5342                 spec->ext_mic.mux_idx = eidx;
5343                 if (spec->capsrc_nids)
5344                         spec->capsrc_nids += i;
5345                 spec->adc_nids += i;
5346                 spec->num_adc_nids = 1;
5347                 return;
5348         }
5349         snd_printd(KERN_INFO "hda_codec: %s: "
5350                    "No ADC/MUX containing both 0x%x and 0x%x pins\n",
5351                    codec->chip_name, spec->int_mic.pin, spec->ext_mic.pin);
5352         spec->auto_mic = 0; /* disable auto-mic to be sure */
5353 }
5354
5355 /* select or unmute the given capsrc route */
5356 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
5357                                     int idx)
5358 {
5359         if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
5360                 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
5361                                          HDA_AMP_MUTE, 0);
5362         } else {
5363                 snd_hda_codec_write_cache(codec, cap, 0,
5364                                           AC_VERB_SET_CONNECT_SEL, idx);
5365         }
5366 }
5367
5368 /* set the default connection to that pin */
5369 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
5370 {
5371         struct alc_spec *spec = codec->spec;
5372         int i;
5373
5374         for (i = 0; i < spec->num_adc_nids; i++) {
5375                 hda_nid_t cap = spec->capsrc_nids ?
5376                         spec->capsrc_nids[i] : spec->adc_nids[i];
5377                 int idx;
5378
5379                 idx = get_connection_index(codec, cap, pin);
5380                 if (idx < 0)
5381                         continue;
5382                 select_or_unmute_capsrc(codec, cap, idx);
5383                 return i; /* return the found index */
5384         }
5385         return -1; /* not found */
5386 }
5387
5388 /* choose the ADC/MUX containing the input pin and initialize the setup */
5389 static void fixup_single_adc(struct hda_codec *codec)
5390 {
5391         struct alc_spec *spec = codec->spec;
5392         struct auto_pin_cfg *cfg = &spec->autocfg;
5393         int i;
5394
5395         /* search for the input pin; there must be only one */
5396         if (cfg->num_inputs != 1)
5397                 return;
5398         i = init_capsrc_for_pin(codec, cfg->inputs[0].pin);
5399         if (i >= 0) {
5400                 /* use only this ADC */
5401                 if (spec->capsrc_nids)
5402                         spec->capsrc_nids += i;
5403                 spec->adc_nids += i;
5404                 spec->num_adc_nids = 1;
5405         }
5406 }
5407
5408 /* initialize dual adcs */
5409 static void fixup_dual_adc_switch(struct hda_codec *codec)
5410 {
5411         struct alc_spec *spec = codec->spec;
5412         init_capsrc_for_pin(codec, spec->ext_mic.pin);
5413         init_capsrc_for_pin(codec, spec->int_mic.pin);
5414 }
5415
5416 static void set_capture_mixer(struct hda_codec *codec)
5417 {
5418         struct alc_spec *spec = codec->spec;
5419         static struct snd_kcontrol_new *caps[2][3] = {
5420                 { alc_capture_mixer_nosrc1,
5421                   alc_capture_mixer_nosrc2,
5422                   alc_capture_mixer_nosrc3 },
5423                 { alc_capture_mixer1,
5424                   alc_capture_mixer2,
5425                   alc_capture_mixer3 },
5426         };
5427         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
5428                 int mux = 0;
5429                 int num_adcs = spec->num_adc_nids;
5430                 if (spec->dual_adc_switch)
5431                         fixup_dual_adc_switch(codec);
5432                 else if (spec->auto_mic)
5433                         fixup_automic_adc(codec);
5434                 else if (spec->input_mux) {
5435                         if (spec->input_mux->num_items > 1)
5436                                 mux = 1;
5437                         else if (spec->input_mux->num_items == 1)
5438                                 fixup_single_adc(codec);
5439                 }
5440                 if (spec->dual_adc_switch)
5441                         num_adcs = 1;
5442                 spec->cap_mixer = caps[mux][num_adcs - 1];
5443         }
5444 }
5445
5446 /* fill adc_nids (and capsrc_nids) containing all active input pins */
5447 static void fillup_priv_adc_nids(struct hda_codec *codec, hda_nid_t *nids,
5448                                  int num_nids)
5449 {
5450         struct alc_spec *spec = codec->spec;
5451         struct auto_pin_cfg *cfg = &spec->autocfg;
5452         int n;
5453         hda_nid_t fallback_adc = 0, fallback_cap = 0;
5454
5455         for (n = 0; n < num_nids; n++) {
5456                 hda_nid_t adc, cap;
5457                 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
5458                 int nconns, i, j;
5459
5460                 adc = nids[n];
5461                 if (get_wcaps_type(get_wcaps(codec, adc)) != AC_WID_AUD_IN)
5462                         continue;
5463                 cap = adc;
5464                 nconns = snd_hda_get_connections(codec, cap, conn,
5465                                                  ARRAY_SIZE(conn));
5466                 if (nconns == 1) {
5467                         cap = conn[0];
5468                         nconns = snd_hda_get_connections(codec, cap, conn,
5469                                                          ARRAY_SIZE(conn));
5470                 }
5471                 if (nconns <= 0)
5472                         continue;
5473                 if (!fallback_adc) {
5474                         fallback_adc = adc;
5475                         fallback_cap = cap;
5476                 }
5477                 for (i = 0; i < cfg->num_inputs; i++) {
5478                         hda_nid_t nid = cfg->inputs[i].pin;
5479                         for (j = 0; j < nconns; j++) {
5480                                 if (conn[j] == nid)
5481                                         break;
5482                         }
5483                         if (j >= nconns)
5484                                 break;
5485                 }
5486                 if (i >= cfg->num_inputs) {
5487                         int num_adcs = spec->num_adc_nids;
5488                         spec->private_adc_nids[num_adcs] = adc;
5489                         spec->private_capsrc_nids[num_adcs] = cap;
5490                         spec->num_adc_nids++;
5491                         spec->adc_nids = spec->private_adc_nids;
5492                         if (adc != cap)
5493                                 spec->capsrc_nids = spec->private_capsrc_nids;
5494                 }
5495         }
5496         if (!spec->num_adc_nids) {
5497                 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
5498                        " using fallback 0x%x\n",
5499                        codec->chip_name, fallback_adc);
5500                 spec->private_adc_nids[0] = fallback_adc;
5501                 spec->adc_nids = spec->private_adc_nids;
5502                 if (fallback_adc != fallback_cap) {
5503                         spec->private_capsrc_nids[0] = fallback_cap;
5504                         spec->capsrc_nids = spec->private_adc_nids;
5505                 }
5506         }
5507 }
5508
5509 #ifdef CONFIG_SND_HDA_INPUT_BEEP
5510 #define set_beep_amp(spec, nid, idx, dir) \
5511         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
5512
5513 static struct snd_pci_quirk beep_white_list[] = {
5514         SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
5515         SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
5516         SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
5517         {}
5518 };
5519
5520 static inline int has_cdefine_beep(struct hda_codec *codec)
5521 {
5522         struct alc_spec *spec = codec->spec;
5523         const struct snd_pci_quirk *q;
5524         q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
5525         if (q)
5526                 return q->value;
5527         return spec->cdefine.enable_pcbeep;
5528 }
5529 #else
5530 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
5531 #define has_cdefine_beep(codec)         0
5532 #endif
5533
5534 /*
5535  * OK, here we have finally the patch for ALC880
5536  */
5537
5538 static int patch_alc880(struct hda_codec *codec)
5539 {
5540         struct alc_spec *spec;
5541         int board_config;
5542         int err;
5543
5544         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5545         if (spec == NULL)
5546                 return -ENOMEM;
5547
5548         codec->spec = spec;
5549
5550         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
5551                                                   alc880_models,
5552                                                   alc880_cfg_tbl);
5553         if (board_config < 0) {
5554                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5555                        codec->chip_name);
5556                 board_config = ALC880_AUTO;
5557         }
5558
5559         if (board_config == ALC880_AUTO) {
5560                 /* automatic parse from the BIOS config */
5561                 err = alc880_parse_auto_config(codec);
5562                 if (err < 0) {
5563                         alc_free(codec);
5564                         return err;
5565                 } else if (!err) {
5566                         printk(KERN_INFO
5567                                "hda_codec: Cannot set up configuration "
5568                                "from BIOS.  Using 3-stack mode...\n");
5569                         board_config = ALC880_3ST;
5570                 }
5571         }
5572
5573         err = snd_hda_attach_beep_device(codec, 0x1);
5574         if (err < 0) {
5575                 alc_free(codec);
5576                 return err;
5577         }
5578
5579         if (board_config != ALC880_AUTO)
5580                 setup_preset(codec, &alc880_presets[board_config]);
5581
5582         spec->stream_analog_playback = &alc880_pcm_analog_playback;
5583         spec->stream_analog_capture = &alc880_pcm_analog_capture;
5584         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
5585
5586         spec->stream_digital_playback = &alc880_pcm_digital_playback;
5587         spec->stream_digital_capture = &alc880_pcm_digital_capture;
5588
5589         if (!spec->adc_nids && spec->input_mux) {
5590                 /* check whether NID 0x07 is valid */
5591                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
5592                 /* get type */
5593                 wcap = get_wcaps_type(wcap);
5594                 if (wcap != AC_WID_AUD_IN) {
5595                         spec->adc_nids = alc880_adc_nids_alt;
5596                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
5597                 } else {
5598                         spec->adc_nids = alc880_adc_nids;
5599                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
5600                 }
5601         }
5602         set_capture_mixer(codec);
5603         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5604
5605         spec->vmaster_nid = 0x0c;
5606
5607         codec->patch_ops = alc_patch_ops;
5608         if (board_config == ALC880_AUTO)
5609                 spec->init_hook = alc880_auto_init;
5610 #ifdef CONFIG_SND_HDA_POWER_SAVE
5611         if (!spec->loopback.amplist)
5612                 spec->loopback.amplist = alc880_loopbacks;
5613 #endif
5614
5615         return 0;
5616 }
5617
5618
5619 /*
5620  * ALC260 support
5621  */
5622
5623 static hda_nid_t alc260_dac_nids[1] = {
5624         /* front */
5625         0x02,
5626 };
5627
5628 static hda_nid_t alc260_adc_nids[1] = {
5629         /* ADC0 */
5630         0x04,
5631 };
5632
5633 static hda_nid_t alc260_adc_nids_alt[1] = {
5634         /* ADC1 */
5635         0x05,
5636 };
5637
5638 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
5639  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
5640  */
5641 static hda_nid_t alc260_dual_adc_nids[2] = {
5642         /* ADC0, ADC1 */
5643         0x04, 0x05
5644 };
5645
5646 #define ALC260_DIGOUT_NID       0x03
5647 #define ALC260_DIGIN_NID        0x06
5648
5649 static struct hda_input_mux alc260_capture_source = {
5650         .num_items = 4,
5651         .items = {
5652                 { "Mic", 0x0 },
5653                 { "Front Mic", 0x1 },
5654                 { "Line", 0x2 },
5655                 { "CD", 0x4 },
5656         },
5657 };
5658
5659 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
5660  * headphone jack and the internal CD lines since these are the only pins at
5661  * which audio can appear.  For flexibility, also allow the option of
5662  * recording the mixer output on the second ADC (ADC0 doesn't have a
5663  * connection to the mixer output).
5664  */
5665 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
5666         {
5667                 .num_items = 3,
5668                 .items = {
5669                         { "Mic/Line", 0x0 },
5670                         { "CD", 0x4 },
5671                         { "Headphone", 0x2 },
5672                 },
5673         },
5674         {
5675                 .num_items = 4,
5676                 .items = {
5677                         { "Mic/Line", 0x0 },
5678                         { "CD", 0x4 },
5679                         { "Headphone", 0x2 },
5680                         { "Mixer", 0x5 },
5681                 },
5682         },
5683
5684 };
5685
5686 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
5687  * the Fujitsu S702x, but jacks are marked differently.
5688  */
5689 static struct hda_input_mux alc260_acer_capture_sources[2] = {
5690         {
5691                 .num_items = 4,
5692                 .items = {
5693                         { "Mic", 0x0 },
5694                         { "Line", 0x2 },
5695                         { "CD", 0x4 },
5696                         { "Headphone", 0x5 },
5697                 },
5698         },
5699         {
5700                 .num_items = 5,
5701                 .items = {
5702                         { "Mic", 0x0 },
5703                         { "Line", 0x2 },
5704                         { "CD", 0x4 },
5705                         { "Headphone", 0x6 },
5706                         { "Mixer", 0x5 },
5707                 },
5708         },
5709 };
5710
5711 /* Maxdata Favorit 100XS */
5712 static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
5713         {
5714                 .num_items = 2,
5715                 .items = {
5716                         { "Line/Mic", 0x0 },
5717                         { "CD", 0x4 },
5718                 },
5719         },
5720         {
5721                 .num_items = 3,
5722                 .items = {
5723                         { "Line/Mic", 0x0 },
5724                         { "CD", 0x4 },
5725                         { "Mixer", 0x5 },
5726                 },
5727         },
5728 };
5729
5730 /*
5731  * This is just place-holder, so there's something for alc_build_pcms to look
5732  * at when it calculates the maximum number of channels. ALC260 has no mixer
5733  * element which allows changing the channel mode, so the verb list is
5734  * never used.
5735  */
5736 static struct hda_channel_mode alc260_modes[1] = {
5737         { 2, NULL },
5738 };
5739
5740
5741 /* Mixer combinations
5742  *
5743  * basic: base_output + input + pc_beep + capture
5744  * HP: base_output + input + capture_alt
5745  * HP_3013: hp_3013 + input + capture
5746  * fujitsu: fujitsu + capture
5747  * acer: acer + capture
5748  */
5749
5750 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
5751         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5752         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5753         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5754         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5755         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5756         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5757         { } /* end */
5758 };
5759
5760 static struct snd_kcontrol_new alc260_input_mixer[] = {
5761         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5762         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5763         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5764         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5765         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5766         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5767         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
5768         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
5769         { } /* end */
5770 };
5771
5772 /* update HP, line and mono out pins according to the master switch */
5773 static void alc260_hp_master_update(struct hda_codec *codec,
5774                                     hda_nid_t hp, hda_nid_t line,
5775                                     hda_nid_t mono)
5776 {
5777         struct alc_spec *spec = codec->spec;
5778         unsigned int val = spec->master_sw ? PIN_HP : 0;
5779         /* change HP and line-out pins */
5780         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5781                             val);
5782         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5783                             val);
5784         /* mono (speaker) depending on the HP jack sense */
5785         val = (val && !spec->jack_present) ? PIN_OUT : 0;
5786         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5787                             val);
5788 }
5789
5790 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
5791                                    struct snd_ctl_elem_value *ucontrol)
5792 {
5793         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5794         struct alc_spec *spec = codec->spec;
5795         *ucontrol->value.integer.value = spec->master_sw;
5796         return 0;
5797 }
5798
5799 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
5800                                    struct snd_ctl_elem_value *ucontrol)
5801 {
5802         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5803         struct alc_spec *spec = codec->spec;
5804         int val = !!*ucontrol->value.integer.value;
5805         hda_nid_t hp, line, mono;
5806
5807         if (val == spec->master_sw)
5808                 return 0;
5809         spec->master_sw = val;
5810         hp = (kcontrol->private_value >> 16) & 0xff;
5811         line = (kcontrol->private_value >> 8) & 0xff;
5812         mono = kcontrol->private_value & 0xff;
5813         alc260_hp_master_update(codec, hp, line, mono);
5814         return 1;
5815 }
5816
5817 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
5818         {
5819                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5820                 .name = "Master Playback Switch",
5821                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
5822                 .info = snd_ctl_boolean_mono_info,
5823                 .get = alc260_hp_master_sw_get,
5824                 .put = alc260_hp_master_sw_put,
5825                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
5826         },
5827         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5828         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5829         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5830         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5831         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5832                               HDA_OUTPUT),
5833         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5834         { } /* end */
5835 };
5836
5837 static struct hda_verb alc260_hp_unsol_verbs[] = {
5838         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5839         {},
5840 };
5841
5842 static void alc260_hp_automute(struct hda_codec *codec)
5843 {
5844         struct alc_spec *spec = codec->spec;
5845
5846         spec->jack_present = snd_hda_jack_detect(codec, 0x10);
5847         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
5848 }
5849
5850 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
5851 {
5852         if ((res >> 26) == ALC880_HP_EVENT)
5853                 alc260_hp_automute(codec);
5854 }
5855
5856 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
5857         {
5858                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5859                 .name = "Master Playback Switch",
5860                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
5861                 .info = snd_ctl_boolean_mono_info,
5862                 .get = alc260_hp_master_sw_get,
5863                 .put = alc260_hp_master_sw_put,
5864                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
5865         },
5866         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5867         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5868         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
5869         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
5870         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5871         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5872         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5873         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
5874         { } /* end */
5875 };
5876
5877 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
5878         .ops = &snd_hda_bind_vol,
5879         .values = {
5880                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
5881                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
5882                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
5883                 0
5884         },
5885 };
5886
5887 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
5888         .ops = &snd_hda_bind_sw,
5889         .values = {
5890                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
5891                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
5892                 0
5893         },
5894 };
5895
5896 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
5897         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
5898         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
5899         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
5900         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5901         { } /* end */
5902 };
5903
5904 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
5905         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5906         {},
5907 };
5908
5909 static void alc260_hp_3013_automute(struct hda_codec *codec)
5910 {
5911         struct alc_spec *spec = codec->spec;
5912
5913         spec->jack_present = snd_hda_jack_detect(codec, 0x15);
5914         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
5915 }
5916
5917 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
5918                                        unsigned int res)
5919 {
5920         if ((res >> 26) == ALC880_HP_EVENT)
5921                 alc260_hp_3013_automute(codec);
5922 }
5923
5924 static void alc260_hp_3012_automute(struct hda_codec *codec)
5925 {
5926         unsigned int bits = snd_hda_jack_detect(codec, 0x10) ? 0 : PIN_OUT;
5927
5928         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5929                             bits);
5930         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5931                             bits);
5932         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5933                             bits);
5934 }
5935
5936 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
5937                                        unsigned int res)
5938 {
5939         if ((res >> 26) == ALC880_HP_EVENT)
5940                 alc260_hp_3012_automute(codec);
5941 }
5942
5943 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
5944  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
5945  */
5946 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
5947         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5948         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
5949         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5950         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5951         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5952         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
5953         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
5954         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
5955         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5956         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
5957         { } /* end */
5958 };
5959
5960 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
5961  * versions of the ALC260 don't act on requests to enable mic bias from NID
5962  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
5963  * datasheet doesn't mention this restriction.  At this stage it's not clear
5964  * whether this behaviour is intentional or is a hardware bug in chip
5965  * revisions available in early 2006.  Therefore for now allow the
5966  * "Headphone Jack Mode" control to span all choices, but if it turns out
5967  * that the lack of mic bias for this NID is intentional we could change the
5968  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5969  *
5970  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
5971  * don't appear to make the mic bias available from the "line" jack, even
5972  * though the NID used for this jack (0x14) can supply it.  The theory is
5973  * that perhaps Acer have included blocking capacitors between the ALC260
5974  * and the output jack.  If this turns out to be the case for all such
5975  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
5976  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
5977  *
5978  * The C20x Tablet series have a mono internal speaker which is controlled
5979  * via the chip's Mono sum widget and pin complex, so include the necessary
5980  * controls for such models.  On models without a "mono speaker" the control
5981  * won't do anything.
5982  */
5983 static struct snd_kcontrol_new alc260_acer_mixer[] = {
5984         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5985         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5986         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5987         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5988                               HDA_OUTPUT),
5989         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
5990                            HDA_INPUT),
5991         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5992         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5993         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),