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