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