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