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