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