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