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