b0d30fced3f56d837e6f79bb9f41e191ae822a40
[pandora-kernel.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_beep.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_DC7600,
76         ALC260_HP_3013,
77         ALC260_FUJITSU_S702X,
78         ALC260_ACER,
79         ALC260_WILL,
80         ALC260_REPLACER_672V,
81         ALC260_FAVORIT100,
82 #ifdef CONFIG_SND_DEBUG
83         ALC260_TEST,
84 #endif
85         ALC260_AUTO,
86         ALC260_MODEL_LAST /* last tag */
87 };
88
89 /* ALC262 models */
90 enum {
91         ALC262_BASIC,
92         ALC262_HIPPO,
93         ALC262_HIPPO_1,
94         ALC262_FUJITSU,
95         ALC262_HP_BPC,
96         ALC262_HP_BPC_D7000_WL,
97         ALC262_HP_BPC_D7000_WF,
98         ALC262_HP_TC_T5735,
99         ALC262_HP_RP5700,
100         ALC262_BENQ_ED8,
101         ALC262_SONY_ASSAMD,
102         ALC262_BENQ_T31,
103         ALC262_ULTRA,
104         ALC262_LENOVO_3000,
105         ALC262_NEC,
106         ALC262_TOSHIBA_S06,
107         ALC262_TOSHIBA_RX1,
108         ALC262_TYAN,
109         ALC262_AUTO,
110         ALC262_MODEL_LAST /* last tag */
111 };
112
113 /* ALC268 models */
114 enum {
115         ALC267_QUANTA_IL1,
116         ALC268_3ST,
117         ALC268_TOSHIBA,
118         ALC268_ACER,
119         ALC268_ACER_DMIC,
120         ALC268_ACER_ASPIRE_ONE,
121         ALC268_DELL,
122         ALC268_ZEPTO,
123 #ifdef CONFIG_SND_DEBUG
124         ALC268_TEST,
125 #endif
126         ALC268_AUTO,
127         ALC268_MODEL_LAST /* last tag */
128 };
129
130 /* ALC269 models */
131 enum {
132         ALC269_BASIC,
133         ALC269_QUANTA_FL1,
134         ALC269_ASUS_EEEPC_P703,
135         ALC269_ASUS_EEEPC_P901,
136         ALC269_FUJITSU,
137         ALC269_LIFEBOOK,
138         ALC269_AUTO,
139         ALC269_MODEL_LAST /* last tag */
140 };
141
142 /* ALC861 models */
143 enum {
144         ALC861_3ST,
145         ALC660_3ST,
146         ALC861_3ST_DIG,
147         ALC861_6ST_DIG,
148         ALC861_UNIWILL_M31,
149         ALC861_TOSHIBA,
150         ALC861_ASUS,
151         ALC861_ASUS_LAPTOP,
152         ALC861_AUTO,
153         ALC861_MODEL_LAST,
154 };
155
156 /* ALC861-VD models */
157 enum {
158         ALC660VD_3ST,
159         ALC660VD_3ST_DIG,
160         ALC660VD_ASUS_V1S,
161         ALC861VD_3ST,
162         ALC861VD_3ST_DIG,
163         ALC861VD_6ST_DIG,
164         ALC861VD_LENOVO,
165         ALC861VD_DALLAS,
166         ALC861VD_HP,
167         ALC861VD_AUTO,
168         ALC861VD_MODEL_LAST,
169 };
170
171 /* ALC662 models */
172 enum {
173         ALC662_3ST_2ch_DIG,
174         ALC662_3ST_6ch_DIG,
175         ALC662_3ST_6ch,
176         ALC662_5ST_DIG,
177         ALC662_LENOVO_101E,
178         ALC662_ASUS_EEEPC_P701,
179         ALC662_ASUS_EEEPC_EP20,
180         ALC663_ASUS_M51VA,
181         ALC663_ASUS_G71V,
182         ALC663_ASUS_H13,
183         ALC663_ASUS_G50V,
184         ALC662_ECS,
185         ALC663_ASUS_MODE1,
186         ALC662_ASUS_MODE2,
187         ALC663_ASUS_MODE3,
188         ALC663_ASUS_MODE4,
189         ALC663_ASUS_MODE5,
190         ALC663_ASUS_MODE6,
191         ALC272_DELL,
192         ALC272_DELL_ZM1,
193         ALC272_SAMSUNG_NC10,
194         ALC662_AUTO,
195         ALC662_MODEL_LAST,
196 };
197
198 /* ALC882 models */
199 enum {
200         ALC882_3ST_DIG,
201         ALC882_6ST_DIG,
202         ALC882_ARIMA,
203         ALC882_W2JC,
204         ALC882_TARGA,
205         ALC882_ASUS_A7J,
206         ALC882_ASUS_A7M,
207         ALC885_MACPRO,
208         ALC885_MBP3,
209         ALC885_MB5,
210         ALC885_IMAC24,
211         ALC883_3ST_2ch_DIG,
212         ALC883_3ST_6ch_DIG,
213         ALC883_3ST_6ch,
214         ALC883_6ST_DIG,
215         ALC883_TARGA_DIG,
216         ALC883_TARGA_2ch_DIG,
217         ALC883_TARGA_8ch_DIG,
218         ALC883_ACER,
219         ALC883_ACER_ASPIRE,
220         ALC888_ACER_ASPIRE_4930G,
221         ALC888_ACER_ASPIRE_6530G,
222         ALC888_ACER_ASPIRE_8930G,
223         ALC883_MEDION,
224         ALC883_MEDION_MD2,
225         ALC883_LAPTOP_EAPD,
226         ALC883_LENOVO_101E_2ch,
227         ALC883_LENOVO_NB0763,
228         ALC888_LENOVO_MS7195_DIG,
229         ALC888_LENOVO_SKY,
230         ALC883_HAIER_W66,
231         ALC888_3ST_HP,
232         ALC888_6ST_DELL,
233         ALC883_MITAC,
234         ALC883_CLEVO_M720,
235         ALC883_FUJITSU_PI2515,
236         ALC888_FUJITSU_XA3530,
237         ALC883_3ST_6ch_INTEL,
238         ALC889A_INTEL,
239         ALC889_INTEL,
240         ALC888_ASUS_M90V,
241         ALC888_ASUS_EEE1601,
242         ALC889A_MB31,
243         ALC1200_ASUS_P5Q,
244         ALC883_SONY_VAIO_TT,
245         ALC882_AUTO,
246         ALC882_MODEL_LAST,
247 };
248
249 /* for GPIO Poll */
250 #define GPIO_MASK       0x03
251
252 /* extra amp-initialization sequence types */
253 enum {
254         ALC_INIT_NONE,
255         ALC_INIT_DEFAULT,
256         ALC_INIT_GPIO1,
257         ALC_INIT_GPIO2,
258         ALC_INIT_GPIO3,
259 };
260
261 struct alc_spec {
262         /* codec parameterization */
263         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
264         unsigned int num_mixers;
265         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
266         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
267
268         const struct hda_verb *init_verbs[5];   /* initialization verbs
269                                                  * don't forget NULL
270                                                  * termination!
271                                                  */
272         unsigned int num_init_verbs;
273
274         char stream_name_analog[32];    /* analog PCM stream */
275         struct hda_pcm_stream *stream_analog_playback;
276         struct hda_pcm_stream *stream_analog_capture;
277         struct hda_pcm_stream *stream_analog_alt_playback;
278         struct hda_pcm_stream *stream_analog_alt_capture;
279
280         char stream_name_digital[32];   /* digital PCM stream */
281         struct hda_pcm_stream *stream_digital_playback;
282         struct hda_pcm_stream *stream_digital_capture;
283
284         /* playback */
285         struct hda_multi_out multiout;  /* playback set-up
286                                          * max_channels, dacs must be set
287                                          * dig_out_nid and hp_nid are optional
288                                          */
289         hda_nid_t alt_dac_nid;
290         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
291         int dig_out_type;
292
293         /* capture */
294         unsigned int num_adc_nids;
295         hda_nid_t *adc_nids;
296         hda_nid_t *capsrc_nids;
297         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
298
299         /* capture source */
300         unsigned int num_mux_defs;
301         const struct hda_input_mux *input_mux;
302         unsigned int cur_mux[3];
303
304         /* channel model */
305         const struct hda_channel_mode *channel_mode;
306         int num_channel_mode;
307         int need_dac_fix;
308         int const_channel_count;
309         int ext_channel_count;
310
311         /* PCM information */
312         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
313
314         /* dynamic controls, init_verbs and input_mux */
315         struct auto_pin_cfg autocfg;
316         struct snd_array kctls;
317         struct hda_input_mux private_imux[3];
318         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
319         hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
320         hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
321
322         /* hooks */
323         void (*init_hook)(struct hda_codec *codec);
324         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
325
326         /* for pin sensing */
327         unsigned int sense_updated: 1;
328         unsigned int jack_present: 1;
329         unsigned int master_sw: 1;
330
331         /* other flags */
332         unsigned int no_analog :1; /* digital I/O only */
333         int init_amp;
334
335         /* for virtual master */
336         hda_nid_t vmaster_nid;
337 #ifdef CONFIG_SND_HDA_POWER_SAVE
338         struct hda_loopback_check loopback;
339 #endif
340
341         /* for PLL fix */
342         hda_nid_t pll_nid;
343         unsigned int pll_coef_idx, pll_coef_bit;
344 };
345
346 /*
347  * configuration template - to be copied to the spec instance
348  */
349 struct alc_config_preset {
350         struct snd_kcontrol_new *mixers[5]; /* should be identical size
351                                              * with spec
352                                              */
353         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
354         const struct hda_verb *init_verbs[5];
355         unsigned int num_dacs;
356         hda_nid_t *dac_nids;
357         hda_nid_t dig_out_nid;          /* optional */
358         hda_nid_t hp_nid;               /* optional */
359         hda_nid_t *slave_dig_outs;
360         unsigned int num_adc_nids;
361         hda_nid_t *adc_nids;
362         hda_nid_t *capsrc_nids;
363         hda_nid_t dig_in_nid;
364         unsigned int num_channel_mode;
365         const struct hda_channel_mode *channel_mode;
366         int need_dac_fix;
367         int const_channel_count;
368         unsigned int num_mux_defs;
369         const struct hda_input_mux *input_mux;
370         void (*unsol_event)(struct hda_codec *, unsigned int);
371         void (*init_hook)(struct hda_codec *);
372 #ifdef CONFIG_SND_HDA_POWER_SAVE
373         struct hda_amp_list *loopbacks;
374 #endif
375 };
376
377
378 /*
379  * input MUX handling
380  */
381 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
382                              struct snd_ctl_elem_info *uinfo)
383 {
384         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
385         struct alc_spec *spec = codec->spec;
386         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
387         if (mux_idx >= spec->num_mux_defs)
388                 mux_idx = 0;
389         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
390 }
391
392 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
393                             struct snd_ctl_elem_value *ucontrol)
394 {
395         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
396         struct alc_spec *spec = codec->spec;
397         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
398
399         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
400         return 0;
401 }
402
403 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
404                             struct snd_ctl_elem_value *ucontrol)
405 {
406         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
407         struct alc_spec *spec = codec->spec;
408         const struct hda_input_mux *imux;
409         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
410         unsigned int mux_idx;
411         hda_nid_t nid = spec->capsrc_nids ?
412                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
413         unsigned int type;
414
415         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
416         imux = &spec->input_mux[mux_idx];
417
418         type = get_wcaps_type(get_wcaps(codec, nid));
419         if (type == AC_WID_AUD_MIX) {
420                 /* Matrix-mixer style (e.g. ALC882) */
421                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
422                 unsigned int i, idx;
423
424                 idx = ucontrol->value.enumerated.item[0];
425                 if (idx >= imux->num_items)
426                         idx = imux->num_items - 1;
427                 if (*cur_val == idx)
428                         return 0;
429                 for (i = 0; i < imux->num_items; i++) {
430                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
431                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
432                                                  imux->items[i].index,
433                                                  HDA_AMP_MUTE, v);
434                 }
435                 *cur_val = idx;
436                 return 1;
437         } else {
438                 /* MUX style (e.g. ALC880) */
439                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
440                                              &spec->cur_mux[adc_idx]);
441         }
442 }
443
444 /*
445  * channel mode setting
446  */
447 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
448                             struct snd_ctl_elem_info *uinfo)
449 {
450         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
451         struct alc_spec *spec = codec->spec;
452         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
453                                     spec->num_channel_mode);
454 }
455
456 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
457                            struct snd_ctl_elem_value *ucontrol)
458 {
459         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
460         struct alc_spec *spec = codec->spec;
461         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
462                                    spec->num_channel_mode,
463                                    spec->ext_channel_count);
464 }
465
466 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
467                            struct snd_ctl_elem_value *ucontrol)
468 {
469         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
470         struct alc_spec *spec = codec->spec;
471         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
472                                       spec->num_channel_mode,
473                                       &spec->ext_channel_count);
474         if (err >= 0 && !spec->const_channel_count) {
475                 spec->multiout.max_channels = spec->ext_channel_count;
476                 if (spec->need_dac_fix)
477                         spec->multiout.num_dacs = spec->multiout.max_channels / 2;
478         }
479         return err;
480 }
481
482 /*
483  * Control the mode of pin widget settings via the mixer.  "pc" is used
484  * instead of "%" to avoid consequences of accidently treating the % as
485  * being part of a format specifier.  Maximum allowed length of a value is
486  * 63 characters plus NULL terminator.
487  *
488  * Note: some retasking pin complexes seem to ignore requests for input
489  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
490  * are requested.  Therefore order this list so that this behaviour will not
491  * cause problems when mixer clients move through the enum sequentially.
492  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
493  * March 2006.
494  */
495 static char *alc_pin_mode_names[] = {
496         "Mic 50pc bias", "Mic 80pc bias",
497         "Line in", "Line out", "Headphone out",
498 };
499 static unsigned char alc_pin_mode_values[] = {
500         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
501 };
502 /* The control can present all 5 options, or it can limit the options based
503  * in the pin being assumed to be exclusively an input or an output pin.  In
504  * addition, "input" pins may or may not process the mic bias option
505  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
506  * accept requests for bias as of chip versions up to March 2006) and/or
507  * wiring in the computer.
508  */
509 #define ALC_PIN_DIR_IN              0x00
510 #define ALC_PIN_DIR_OUT             0x01
511 #define ALC_PIN_DIR_INOUT           0x02
512 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
513 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
514
515 /* Info about the pin modes supported by the different pin direction modes.
516  * For each direction the minimum and maximum values are given.
517  */
518 static signed char alc_pin_mode_dir_info[5][2] = {
519         { 0, 2 },    /* ALC_PIN_DIR_IN */
520         { 3, 4 },    /* ALC_PIN_DIR_OUT */
521         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
522         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
523         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
524 };
525 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
526 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
527 #define alc_pin_mode_n_items(_dir) \
528         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
529
530 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
531                              struct snd_ctl_elem_info *uinfo)
532 {
533         unsigned int item_num = uinfo->value.enumerated.item;
534         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
535
536         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
537         uinfo->count = 1;
538         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
539
540         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
541                 item_num = alc_pin_mode_min(dir);
542         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
543         return 0;
544 }
545
546 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
547                             struct snd_ctl_elem_value *ucontrol)
548 {
549         unsigned int i;
550         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
551         hda_nid_t nid = kcontrol->private_value & 0xffff;
552         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
553         long *valp = ucontrol->value.integer.value;
554         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
555                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
556                                                  0x00);
557
558         /* Find enumerated value for current pinctl setting */
559         i = alc_pin_mode_min(dir);
560         while (i <= alc_pin_mode_max(dir) && alc_pin_mode_values[i] != pinctl)
561                 i++;
562         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
563         return 0;
564 }
565
566 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
567                             struct snd_ctl_elem_value *ucontrol)
568 {
569         signed int change;
570         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
571         hda_nid_t nid = kcontrol->private_value & 0xffff;
572         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
573         long val = *ucontrol->value.integer.value;
574         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
575                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
576                                                  0x00);
577
578         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
579                 val = alc_pin_mode_min(dir);
580
581         change = pinctl != alc_pin_mode_values[val];
582         if (change) {
583                 /* Set pin mode to that requested */
584                 snd_hda_codec_write_cache(codec, nid, 0,
585                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
586                                           alc_pin_mode_values[val]);
587
588                 /* Also enable the retasking pin's input/output as required
589                  * for the requested pin mode.  Enum values of 2 or less are
590                  * input modes.
591                  *
592                  * Dynamically switching the input/output buffers probably
593                  * reduces noise slightly (particularly on input) so we'll
594                  * do it.  However, having both input and output buffers
595                  * enabled simultaneously doesn't seem to be problematic if
596                  * this turns out to be necessary in the future.
597                  */
598                 if (val <= 2) {
599                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
600                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
601                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
602                                                  HDA_AMP_MUTE, 0);
603                 } else {
604                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
605                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
606                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
607                                                  HDA_AMP_MUTE, 0);
608                 }
609         }
610         return change;
611 }
612
613 #define ALC_PIN_MODE(xname, nid, dir) \
614         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
615           .info = alc_pin_mode_info, \
616           .get = alc_pin_mode_get, \
617           .put = alc_pin_mode_put, \
618           .private_value = nid | (dir<<16) }
619
620 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
621  * together using a mask with more than one bit set.  This control is
622  * currently used only by the ALC260 test model.  At this stage they are not
623  * needed for any "production" models.
624  */
625 #ifdef CONFIG_SND_DEBUG
626 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
627
628 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
629                              struct snd_ctl_elem_value *ucontrol)
630 {
631         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
632         hda_nid_t nid = kcontrol->private_value & 0xffff;
633         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
634         long *valp = ucontrol->value.integer.value;
635         unsigned int val = snd_hda_codec_read(codec, nid, 0,
636                                               AC_VERB_GET_GPIO_DATA, 0x00);
637
638         *valp = (val & mask) != 0;
639         return 0;
640 }
641 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
642                              struct snd_ctl_elem_value *ucontrol)
643 {
644         signed int change;
645         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646         hda_nid_t nid = kcontrol->private_value & 0xffff;
647         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
648         long val = *ucontrol->value.integer.value;
649         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
650                                                     AC_VERB_GET_GPIO_DATA,
651                                                     0x00);
652
653         /* Set/unset the masked GPIO bit(s) as needed */
654         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
655         if (val == 0)
656                 gpio_data &= ~mask;
657         else
658                 gpio_data |= mask;
659         snd_hda_codec_write_cache(codec, nid, 0,
660                                   AC_VERB_SET_GPIO_DATA, gpio_data);
661
662         return change;
663 }
664 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
665         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
666           .info = alc_gpio_data_info, \
667           .get = alc_gpio_data_get, \
668           .put = alc_gpio_data_put, \
669           .private_value = nid | (mask<<16) }
670 #endif   /* CONFIG_SND_DEBUG */
671
672 /* A switch control to allow the enabling of the digital IO pins on the
673  * ALC260.  This is incredibly simplistic; the intention of this control is
674  * to provide something in the test model allowing digital outputs to be
675  * identified if present.  If models are found which can utilise these
676  * outputs a more complete mixer control can be devised for those models if
677  * necessary.
678  */
679 #ifdef CONFIG_SND_DEBUG
680 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
681
682 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
683                               struct snd_ctl_elem_value *ucontrol)
684 {
685         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
686         hda_nid_t nid = kcontrol->private_value & 0xffff;
687         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
688         long *valp = ucontrol->value.integer.value;
689         unsigned int val = snd_hda_codec_read(codec, nid, 0,
690                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
691
692         *valp = (val & mask) != 0;
693         return 0;
694 }
695 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
696                               struct snd_ctl_elem_value *ucontrol)
697 {
698         signed int change;
699         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
700         hda_nid_t nid = kcontrol->private_value & 0xffff;
701         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
702         long val = *ucontrol->value.integer.value;
703         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
704                                                     AC_VERB_GET_DIGI_CONVERT_1,
705                                                     0x00);
706
707         /* Set/unset the masked control bit(s) as needed */
708         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
709         if (val==0)
710                 ctrl_data &= ~mask;
711         else
712                 ctrl_data |= mask;
713         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
714                                   ctrl_data);
715
716         return change;
717 }
718 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
719         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
720           .info = alc_spdif_ctrl_info, \
721           .get = alc_spdif_ctrl_get, \
722           .put = alc_spdif_ctrl_put, \
723           .private_value = nid | (mask<<16) }
724 #endif   /* CONFIG_SND_DEBUG */
725
726 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
727  * Again, this is only used in the ALC26x test models to help identify when
728  * the EAPD line must be asserted for features to work.
729  */
730 #ifdef CONFIG_SND_DEBUG
731 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
732
733 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
734                               struct snd_ctl_elem_value *ucontrol)
735 {
736         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
737         hda_nid_t nid = kcontrol->private_value & 0xffff;
738         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
739         long *valp = ucontrol->value.integer.value;
740         unsigned int val = snd_hda_codec_read(codec, nid, 0,
741                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
742
743         *valp = (val & mask) != 0;
744         return 0;
745 }
746
747 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
748                               struct snd_ctl_elem_value *ucontrol)
749 {
750         int change;
751         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
752         hda_nid_t nid = kcontrol->private_value & 0xffff;
753         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
754         long val = *ucontrol->value.integer.value;
755         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
756                                                     AC_VERB_GET_EAPD_BTLENABLE,
757                                                     0x00);
758
759         /* Set/unset the masked control bit(s) as needed */
760         change = (!val ? 0 : mask) != (ctrl_data & mask);
761         if (!val)
762                 ctrl_data &= ~mask;
763         else
764                 ctrl_data |= mask;
765         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
766                                   ctrl_data);
767
768         return change;
769 }
770
771 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
772         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
773           .info = alc_eapd_ctrl_info, \
774           .get = alc_eapd_ctrl_get, \
775           .put = alc_eapd_ctrl_put, \
776           .private_value = nid | (mask<<16) }
777 #endif   /* CONFIG_SND_DEBUG */
778
779 /*
780  * set up the input pin config (depending on the given auto-pin type)
781  */
782 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
783                               int auto_pin_type)
784 {
785         unsigned int val = PIN_IN;
786
787         if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
788                 unsigned int pincap;
789                 pincap = snd_hda_query_pin_caps(codec, nid);
790                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
791                 if (pincap & AC_PINCAP_VREF_80)
792                         val = PIN_VREF80;
793                 else if (pincap & AC_PINCAP_VREF_50)
794                         val = PIN_VREF50;
795                 else if (pincap & AC_PINCAP_VREF_100)
796                         val = PIN_VREF100;
797                 else if (pincap & AC_PINCAP_VREF_GRD)
798                         val = PIN_VREFGRD;
799         }
800         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
801 }
802
803 /*
804  */
805 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
806 {
807         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
808                 return;
809         spec->mixers[spec->num_mixers++] = mix;
810 }
811
812 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
813 {
814         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
815                 return;
816         spec->init_verbs[spec->num_init_verbs++] = verb;
817 }
818
819 #ifdef CONFIG_PROC_FS
820 /*
821  * hook for proc
822  */
823 static void print_realtek_coef(struct snd_info_buffer *buffer,
824                                struct hda_codec *codec, hda_nid_t nid)
825 {
826         int coeff;
827
828         if (nid != 0x20)
829                 return;
830         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
831         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
832         coeff = snd_hda_codec_read(codec, nid, 0,
833                                    AC_VERB_GET_COEF_INDEX, 0);
834         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
835 }
836 #else
837 #define print_realtek_coef      NULL
838 #endif
839
840 /*
841  * set up from the preset table
842  */
843 static void setup_preset(struct alc_spec *spec,
844                          const struct alc_config_preset *preset)
845 {
846         int i;
847
848         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
849                 add_mixer(spec, preset->mixers[i]);
850         spec->cap_mixer = preset->cap_mixer;
851         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
852              i++)
853                 add_verb(spec, preset->init_verbs[i]);
854
855         spec->channel_mode = preset->channel_mode;
856         spec->num_channel_mode = preset->num_channel_mode;
857         spec->need_dac_fix = preset->need_dac_fix;
858         spec->const_channel_count = preset->const_channel_count;
859
860         if (preset->const_channel_count)
861                 spec->multiout.max_channels = preset->const_channel_count;
862         else
863                 spec->multiout.max_channels = spec->channel_mode[0].channels;
864         spec->ext_channel_count = spec->channel_mode[0].channels;
865
866         spec->multiout.num_dacs = preset->num_dacs;
867         spec->multiout.dac_nids = preset->dac_nids;
868         spec->multiout.dig_out_nid = preset->dig_out_nid;
869         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
870         spec->multiout.hp_nid = preset->hp_nid;
871
872         spec->num_mux_defs = preset->num_mux_defs;
873         if (!spec->num_mux_defs)
874                 spec->num_mux_defs = 1;
875         spec->input_mux = preset->input_mux;
876
877         spec->num_adc_nids = preset->num_adc_nids;
878         spec->adc_nids = preset->adc_nids;
879         spec->capsrc_nids = preset->capsrc_nids;
880         spec->dig_in_nid = preset->dig_in_nid;
881
882         spec->unsol_event = preset->unsol_event;
883         spec->init_hook = preset->init_hook;
884 #ifdef CONFIG_SND_HDA_POWER_SAVE
885         spec->loopback.amplist = preset->loopbacks;
886 #endif
887 }
888
889 /* Enable GPIO mask and set output */
890 static struct hda_verb alc_gpio1_init_verbs[] = {
891         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
892         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
893         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
894         { }
895 };
896
897 static struct hda_verb alc_gpio2_init_verbs[] = {
898         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
899         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
900         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
901         { }
902 };
903
904 static struct hda_verb alc_gpio3_init_verbs[] = {
905         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
906         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
907         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
908         { }
909 };
910
911 /*
912  * Fix hardware PLL issue
913  * On some codecs, the analog PLL gating control must be off while
914  * the default value is 1.
915  */
916 static void alc_fix_pll(struct hda_codec *codec)
917 {
918         struct alc_spec *spec = codec->spec;
919         unsigned int val;
920
921         if (!spec->pll_nid)
922                 return;
923         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
924                             spec->pll_coef_idx);
925         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
926                                  AC_VERB_GET_PROC_COEF, 0);
927         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
928                             spec->pll_coef_idx);
929         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
930                             val & ~(1 << spec->pll_coef_bit));
931 }
932
933 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
934                              unsigned int coef_idx, unsigned int coef_bit)
935 {
936         struct alc_spec *spec = codec->spec;
937         spec->pll_nid = nid;
938         spec->pll_coef_idx = coef_idx;
939         spec->pll_coef_bit = coef_bit;
940         alc_fix_pll(codec);
941 }
942
943 static void alc_automute_pin(struct hda_codec *codec)
944 {
945         struct alc_spec *spec = codec->spec;
946         unsigned int present, pincap;
947         unsigned int nid = spec->autocfg.hp_pins[0];
948         int i;
949
950         pincap = snd_hda_query_pin_caps(codec, nid);
951         if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
952                 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
953         present = snd_hda_codec_read(codec, nid, 0,
954                                      AC_VERB_GET_PIN_SENSE, 0);
955         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
956         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
957                 nid = spec->autocfg.speaker_pins[i];
958                 if (!nid)
959                         break;
960                 snd_hda_codec_write(codec, nid, 0,
961                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
962                                     spec->jack_present ? 0 : PIN_OUT);
963         }
964 }
965
966 #if 0 /* it's broken in some cases -- temporarily disabled */
967 static void alc_mic_automute(struct hda_codec *codec)
968 {
969         struct alc_spec *spec = codec->spec;
970         unsigned int present;
971         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
972         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
973         unsigned int mix_nid = spec->capsrc_nids[0];
974         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
975
976         capsrc_idx_mic = mic_nid - 0x18;
977         capsrc_idx_fmic = fmic_nid - 0x18;
978         present = snd_hda_codec_read(codec, mic_nid, 0,
979                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
980         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
981                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
982         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
983                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
984         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
985                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
986 }
987 #else
988 #define alc_mic_automute(codec) do {} while(0) /* NOP */
989 #endif /* disabled */
990
991 /* unsolicited event for HP jack sensing */
992 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
993 {
994         if (codec->vendor_id == 0x10ec0880)
995                 res >>= 28;
996         else
997                 res >>= 26;
998         switch (res) {
999         case ALC880_HP_EVENT:
1000                 alc_automute_pin(codec);
1001                 break;
1002         case ALC880_MIC_EVENT:
1003                 alc_mic_automute(codec);
1004                 break;
1005         }
1006 }
1007
1008 static void alc_inithook(struct hda_codec *codec)
1009 {
1010         alc_automute_pin(codec);
1011         alc_mic_automute(codec);
1012 }
1013
1014 /* additional initialization for ALC888 variants */
1015 static void alc888_coef_init(struct hda_codec *codec)
1016 {
1017         unsigned int tmp;
1018
1019         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1020         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1021         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1022         if ((tmp & 0xf0) == 0x20)
1023                 /* alc888S-VC */
1024                 snd_hda_codec_read(codec, 0x20, 0,
1025                                    AC_VERB_SET_PROC_COEF, 0x830);
1026          else
1027                  /* alc888-VB */
1028                  snd_hda_codec_read(codec, 0x20, 0,
1029                                     AC_VERB_SET_PROC_COEF, 0x3030);
1030 }
1031
1032 static void alc889_coef_init(struct hda_codec *codec)
1033 {
1034         unsigned int tmp;
1035
1036         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1037         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1038         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1039         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1040 }
1041
1042 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1043 {
1044         unsigned int tmp;
1045
1046         switch (type) {
1047         case ALC_INIT_GPIO1:
1048                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1049                 break;
1050         case ALC_INIT_GPIO2:
1051                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1052                 break;
1053         case ALC_INIT_GPIO3:
1054                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1055                 break;
1056         case ALC_INIT_DEFAULT:
1057                 switch (codec->vendor_id) {
1058                 case 0x10ec0260:
1059                         snd_hda_codec_write(codec, 0x0f, 0,
1060                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1061                         snd_hda_codec_write(codec, 0x10, 0,
1062                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1063                         break;
1064                 case 0x10ec0262:
1065                 case 0x10ec0267:
1066                 case 0x10ec0268:
1067                 case 0x10ec0269:
1068                 case 0x10ec0272:
1069                 case 0x10ec0660:
1070                 case 0x10ec0662:
1071                 case 0x10ec0663:
1072                 case 0x10ec0862:
1073                 case 0x10ec0889:
1074                         snd_hda_codec_write(codec, 0x14, 0,
1075                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1076                         snd_hda_codec_write(codec, 0x15, 0,
1077                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1078                         break;
1079                 }
1080                 switch (codec->vendor_id) {
1081                 case 0x10ec0260:
1082                         snd_hda_codec_write(codec, 0x1a, 0,
1083                                             AC_VERB_SET_COEF_INDEX, 7);
1084                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1085                                                  AC_VERB_GET_PROC_COEF, 0);
1086                         snd_hda_codec_write(codec, 0x1a, 0,
1087                                             AC_VERB_SET_COEF_INDEX, 7);
1088                         snd_hda_codec_write(codec, 0x1a, 0,
1089                                             AC_VERB_SET_PROC_COEF,
1090                                             tmp | 0x2010);
1091                         break;
1092                 case 0x10ec0262:
1093                 case 0x10ec0880:
1094                 case 0x10ec0882:
1095                 case 0x10ec0883:
1096                 case 0x10ec0885:
1097                 case 0x10ec0887:
1098                 case 0x10ec0889:
1099                         alc889_coef_init(codec);
1100                         break;
1101                 case 0x10ec0888:
1102                         alc888_coef_init(codec);
1103                         break;
1104                 case 0x10ec0267:
1105                 case 0x10ec0268:
1106                         snd_hda_codec_write(codec, 0x20, 0,
1107                                             AC_VERB_SET_COEF_INDEX, 7);
1108                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1109                                                  AC_VERB_GET_PROC_COEF, 0);
1110                         snd_hda_codec_write(codec, 0x20, 0,
1111                                             AC_VERB_SET_COEF_INDEX, 7);
1112                         snd_hda_codec_write(codec, 0x20, 0,
1113                                             AC_VERB_SET_PROC_COEF,
1114                                             tmp | 0x3000);
1115                         break;
1116                 }
1117                 break;
1118         }
1119 }
1120
1121 static void alc_init_auto_hp(struct hda_codec *codec)
1122 {
1123         struct alc_spec *spec = codec->spec;
1124
1125         if (!spec->autocfg.hp_pins[0])
1126                 return;
1127
1128         if (!spec->autocfg.speaker_pins[0]) {
1129                 if (spec->autocfg.line_out_pins[0] &&
1130                     spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1131                         spec->autocfg.speaker_pins[0] =
1132                                 spec->autocfg.line_out_pins[0];
1133                 else
1134                         return;
1135         }
1136
1137         snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1138                     spec->autocfg.hp_pins[0]);
1139         snd_hda_codec_write_cache(codec, spec->autocfg.hp_pins[0], 0,
1140                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1141                                   AC_USRSP_EN | ALC880_HP_EVENT);
1142         spec->unsol_event = alc_sku_unsol_event;
1143 }
1144
1145 /* check subsystem ID and set up device-specific initialization;
1146  * return 1 if initialized, 0 if invalid SSID
1147  */
1148 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1149  *      31 ~ 16 :       Manufacture ID
1150  *      15 ~ 8  :       SKU ID
1151  *      7  ~ 0  :       Assembly ID
1152  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1153  */
1154 static int alc_subsystem_id(struct hda_codec *codec,
1155                             hda_nid_t porta, hda_nid_t porte,
1156                             hda_nid_t portd)
1157 {
1158         unsigned int ass, tmp, i;
1159         unsigned nid;
1160         struct alc_spec *spec = codec->spec;
1161
1162         ass = codec->subsystem_id & 0xffff;
1163         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1164                 goto do_sku;
1165
1166         /* invalid SSID, check the special NID pin defcfg instead */
1167         /*
1168          * 31~30        : port connectivity
1169          * 29~21        : reserve
1170          * 20           : PCBEEP input
1171          * 19~16        : Check sum (15:1)
1172          * 15~1         : Custom
1173          * 0            : override
1174         */
1175         nid = 0x1d;
1176         if (codec->vendor_id == 0x10ec0260)
1177                 nid = 0x17;
1178         ass = snd_hda_codec_get_pincfg(codec, nid);
1179         snd_printd("realtek: No valid SSID, "
1180                    "checking pincfg 0x%08x for NID 0x%x\n",
1181                    ass, nid);
1182         if (!(ass & 1) && !(ass & 0x100000))
1183                 return 0;
1184         if ((ass >> 30) != 1)   /* no physical connection */
1185                 return 0;
1186
1187         /* check sum */
1188         tmp = 0;
1189         for (i = 1; i < 16; i++) {
1190                 if ((ass >> i) & 1)
1191                         tmp++;
1192         }
1193         if (((ass >> 16) & 0xf) != tmp)
1194                 return 0;
1195 do_sku:
1196         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1197                    ass & 0xffff, codec->vendor_id);
1198         /*
1199          * 0 : override
1200          * 1 :  Swap Jack
1201          * 2 : 0 --> Desktop, 1 --> Laptop
1202          * 3~5 : External Amplifier control
1203          * 7~6 : Reserved
1204         */
1205         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1206         switch (tmp) {
1207         case 1:
1208                 spec->init_amp = ALC_INIT_GPIO1;
1209                 break;
1210         case 3:
1211                 spec->init_amp = ALC_INIT_GPIO2;
1212                 break;
1213         case 7:
1214                 spec->init_amp = ALC_INIT_GPIO3;
1215                 break;
1216         case 5:
1217                 spec->init_amp = ALC_INIT_DEFAULT;
1218                 break;
1219         }
1220
1221         /* is laptop or Desktop and enable the function "Mute internal speaker
1222          * when the external headphone out jack is plugged"
1223          */
1224         if (!(ass & 0x8000))
1225                 return 1;
1226         /*
1227          * 10~8 : Jack location
1228          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1229          * 14~13: Resvered
1230          * 15   : 1 --> enable the function "Mute internal speaker
1231          *              when the external headphone out jack is plugged"
1232          */
1233         if (!spec->autocfg.hp_pins[0]) {
1234                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1235                 if (tmp == 0)
1236                         spec->autocfg.hp_pins[0] = porta;
1237                 else if (tmp == 1)
1238                         spec->autocfg.hp_pins[0] = porte;
1239                 else if (tmp == 2)
1240                         spec->autocfg.hp_pins[0] = portd;
1241                 else
1242                         return 1;
1243         }
1244
1245         alc_init_auto_hp(codec);
1246         return 1;
1247 }
1248
1249 static void alc_ssid_check(struct hda_codec *codec,
1250                            hda_nid_t porta, hda_nid_t porte, hda_nid_t portd)
1251 {
1252         if (!alc_subsystem_id(codec, porta, porte, portd)) {
1253                 struct alc_spec *spec = codec->spec;
1254                 snd_printd("realtek: "
1255                            "Enable default setup for auto mode as fallback\n");
1256                 spec->init_amp = ALC_INIT_DEFAULT;
1257                 alc_init_auto_hp(codec);
1258         }
1259 }
1260
1261 /*
1262  * Fix-up pin default configurations
1263  */
1264
1265 struct alc_pincfg {
1266         hda_nid_t nid;
1267         u32 val;
1268 };
1269
1270 static void alc_fix_pincfg(struct hda_codec *codec,
1271                            const struct snd_pci_quirk *quirk,
1272                            const struct alc_pincfg **pinfix)
1273 {
1274         const struct alc_pincfg *cfg;
1275
1276         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1277         if (!quirk)
1278                 return;
1279
1280         cfg = pinfix[quirk->value];
1281         for (; cfg->nid; cfg++)
1282                 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1283 }
1284
1285 /*
1286  * ALC888
1287  */
1288
1289 /*
1290  * 2ch mode
1291  */
1292 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1293 /* Mic-in jack as mic in */
1294         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1295         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1296 /* Line-in jack as Line in */
1297         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1298         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1299 /* Line-Out as Front */
1300         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1301         { } /* end */
1302 };
1303
1304 /*
1305  * 4ch mode
1306  */
1307 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1308 /* Mic-in jack as mic in */
1309         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1310         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1311 /* Line-in jack as Surround */
1312         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1313         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1314 /* Line-Out as Front */
1315         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1316         { } /* end */
1317 };
1318
1319 /*
1320  * 6ch mode
1321  */
1322 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1323 /* Mic-in jack as CLFE */
1324         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1325         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1326 /* Line-in jack as Surround */
1327         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1328         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1329 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1330         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1331         { } /* end */
1332 };
1333
1334 /*
1335  * 8ch mode
1336  */
1337 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1338 /* Mic-in jack as CLFE */
1339         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1340         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1341 /* Line-in jack as Surround */
1342         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1343         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1344 /* Line-Out as Side */
1345         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1346         { } /* end */
1347 };
1348
1349 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1350         { 2, alc888_4ST_ch2_intel_init },
1351         { 4, alc888_4ST_ch4_intel_init },
1352         { 6, alc888_4ST_ch6_intel_init },
1353         { 8, alc888_4ST_ch8_intel_init },
1354 };
1355
1356 /*
1357  * ALC888 Fujitsu Siemens Amillo xa3530
1358  */
1359
1360 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1361 /* Front Mic: set to PIN_IN (empty by default) */
1362         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1363 /* Connect Internal HP to Front */
1364         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1365         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1366         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1367 /* Connect Bass HP to Front */
1368         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1369         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1370         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1371 /* Connect Line-Out side jack (SPDIF) to Side */
1372         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1373         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1374         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1375 /* Connect Mic jack to CLFE */
1376         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1377         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1378         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1379 /* Connect Line-in jack to Surround */
1380         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1381         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1382         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1383 /* Connect HP out jack to Front */
1384         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1385         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1386         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1387 /* Enable unsolicited event for HP jack and Line-out jack */
1388         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1389         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1390         {}
1391 };
1392
1393 static void alc_automute_amp(struct hda_codec *codec)
1394 {
1395         struct alc_spec *spec = codec->spec;
1396         unsigned int val, mute, pincap;
1397         hda_nid_t nid;
1398         int i;
1399
1400         spec->jack_present = 0;
1401         for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
1402                 nid = spec->autocfg.hp_pins[i];
1403                 if (!nid)
1404                         break;
1405                 pincap = snd_hda_query_pin_caps(codec, nid);
1406                 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1407                         snd_hda_codec_read(codec, nid, 0,
1408                                            AC_VERB_SET_PIN_SENSE, 0);
1409                 val = snd_hda_codec_read(codec, nid, 0,
1410                                          AC_VERB_GET_PIN_SENSE, 0);
1411                 if (val & AC_PINSENSE_PRESENCE) {
1412                         spec->jack_present = 1;
1413                         break;
1414                 }
1415         }
1416
1417         mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1418         /* Toggle internal speakers muting */
1419         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
1420                 nid = spec->autocfg.speaker_pins[i];
1421                 if (!nid)
1422                         break;
1423                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1424                                          HDA_AMP_MUTE, mute);
1425         }
1426 }
1427
1428 static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1429                                          unsigned int res)
1430 {
1431         if (codec->vendor_id == 0x10ec0880)
1432                 res >>= 28;
1433         else
1434                 res >>= 26;
1435         if (res == ALC880_HP_EVENT)
1436                 alc_automute_amp(codec);
1437 }
1438
1439 static void alc889_automute_init(struct hda_codec *codec)
1440 {
1441         struct alc_spec *spec = codec->spec;
1442
1443         spec->autocfg.hp_pins[0] = 0x15;
1444         spec->autocfg.speaker_pins[0] = 0x14;
1445         spec->autocfg.speaker_pins[1] = 0x16;
1446         spec->autocfg.speaker_pins[2] = 0x17;
1447         spec->autocfg.speaker_pins[3] = 0x19;
1448         spec->autocfg.speaker_pins[4] = 0x1a;
1449         alc_automute_amp(codec);
1450 }
1451
1452 static void alc889_intel_init_hook(struct hda_codec *codec)
1453 {
1454         alc889_coef_init(codec);
1455         alc889_automute_init(codec);
1456 }
1457
1458 static void alc888_fujitsu_xa3530_init_hook(struct hda_codec *codec)
1459 {
1460         struct alc_spec *spec = codec->spec;
1461
1462         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
1463         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1464         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1465         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1466         alc_automute_amp(codec);
1467 }
1468
1469 /*
1470  * ALC888 Acer Aspire 4930G model
1471  */
1472
1473 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1474 /* Front Mic: set to PIN_IN (empty by default) */
1475         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1476 /* Unselect Front Mic by default in input mixer 3 */
1477         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1478 /* Enable unsolicited event for HP jack */
1479         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1480 /* Connect Internal HP to front */
1481         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1482         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1483         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1484 /* Connect HP out to front */
1485         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1486         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1487         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1488         { }
1489 };
1490
1491 /*
1492  * ALC888 Acer Aspire 6530G model
1493  */
1494
1495 static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1496 /* Bias voltage on for external mic port */
1497         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1498 /* Front Mic: set to PIN_IN (empty by default) */
1499         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1500 /* Unselect Front Mic by default in input mixer 3 */
1501         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1502 /* Enable unsolicited event for HP jack */
1503         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1504 /* Enable speaker output */
1505         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1506         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1507 /* Enable headphone output */
1508         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1509         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1510         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1511         { }
1512 };
1513
1514 /*
1515  * ALC889 Acer Aspire 8930G model
1516  */
1517
1518 static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
1519 /* Front Mic: set to PIN_IN (empty by default) */
1520         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1521 /* Unselect Front Mic by default in input mixer 3 */
1522         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1523 /* Enable unsolicited event for HP jack */
1524         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1525 /* Connect Internal Front to Front */
1526         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1527         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1528         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1529 /* Connect Internal Rear to Rear */
1530         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1531         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1532         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
1533 /* Connect Internal CLFE to CLFE */
1534         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1535         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1536         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
1537 /* Connect HP out to Front */
1538         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1539         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1540         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1541 /* Enable all DACs */
1542 /*  DAC DISABLE/MUTE 1? */
1543 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
1544         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
1545         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1546 /*  DAC DISABLE/MUTE 2? */
1547 /*  some bit here disables the other DACs. Init=0x4900 */
1548         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
1549         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1550 /* Enable amplifiers */
1551         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1552         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1553 /* DMIC fix
1554  * This laptop has a stereo digital microphone. The mics are only 1cm apart
1555  * which makes the stereo useless. However, either the mic or the ALC889
1556  * makes the signal become a difference/sum signal instead of standard
1557  * stereo, which is annoying. So instead we flip this bit which makes the
1558  * codec replicate the sum signal to both channels, turning it into a
1559  * normal mono mic.
1560  */
1561 /*  DMIC_CONTROL? Init value = 0x0001 */
1562         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
1563         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
1564         { }
1565 };
1566
1567 static struct hda_input_mux alc888_2_capture_sources[2] = {
1568         /* Front mic only available on one ADC */
1569         {
1570                 .num_items = 4,
1571                 .items = {
1572                         { "Mic", 0x0 },
1573                         { "Line", 0x2 },
1574                         { "CD", 0x4 },
1575                         { "Front Mic", 0xb },
1576                 },
1577         },
1578         {
1579                 .num_items = 3,
1580                 .items = {
1581                         { "Mic", 0x0 },
1582                         { "Line", 0x2 },
1583                         { "CD", 0x4 },
1584                 },
1585         }
1586 };
1587
1588 static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
1589         /* Interal mic only available on one ADC */
1590         {
1591                 .num_items = 5,
1592                 .items = {
1593                         { "Ext Mic", 0x0 },
1594                         { "Line In", 0x2 },
1595                         { "CD", 0x4 },
1596                         { "Input Mix", 0xa },
1597                         { "Int Mic", 0xb },
1598                 },
1599         },
1600         {
1601                 .num_items = 4,
1602                 .items = {
1603                         { "Ext Mic", 0x0 },
1604                         { "Line In", 0x2 },
1605                         { "CD", 0x4 },
1606                         { "Input Mix", 0xa },
1607                 },
1608         }
1609 };
1610
1611 static struct hda_input_mux alc889_capture_sources[3] = {
1612         /* Digital mic only available on first "ADC" */
1613         {
1614                 .num_items = 5,
1615                 .items = {
1616                         { "Mic", 0x0 },
1617                         { "Line", 0x2 },
1618                         { "CD", 0x4 },
1619                         { "Front Mic", 0xb },
1620                         { "Input Mix", 0xa },
1621                 },
1622         },
1623         {
1624                 .num_items = 4,
1625                 .items = {
1626                         { "Mic", 0x0 },
1627                         { "Line", 0x2 },
1628                         { "CD", 0x4 },
1629                         { "Input Mix", 0xa },
1630                 },
1631         },
1632         {
1633                 .num_items = 4,
1634                 .items = {
1635                         { "Mic", 0x0 },
1636                         { "Line", 0x2 },
1637                         { "CD", 0x4 },
1638                         { "Input Mix", 0xa },
1639                 },
1640         }
1641 };
1642
1643 static struct snd_kcontrol_new alc888_base_mixer[] = {
1644         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1645         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1646         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1647         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1648         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1649                 HDA_OUTPUT),
1650         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1651         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1652         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1653         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1654         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1655         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1656         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1657         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1658         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1659         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1660         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1661         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1662         { } /* end */
1663 };
1664
1665 static void alc888_acer_aspire_4930g_init_hook(struct hda_codec *codec)
1666 {
1667         struct alc_spec *spec = codec->spec;
1668
1669         spec->autocfg.hp_pins[0] = 0x15;
1670         spec->autocfg.speaker_pins[0] = 0x14;
1671         alc_automute_amp(codec);
1672 }
1673
1674 static void alc888_acer_aspire_6530g_init_hook(struct hda_codec *codec)
1675 {
1676         struct alc_spec *spec = codec->spec;
1677
1678         spec->autocfg.hp_pins[0] = 0x15;
1679         spec->autocfg.speaker_pins[0] = 0x14;
1680         spec->autocfg.speaker_pins[1] = 0x16;
1681         spec->autocfg.speaker_pins[2] = 0x17;
1682         alc_automute_amp(codec);
1683 }
1684
1685 static void alc889_acer_aspire_8930g_init_hook(struct hda_codec *codec)
1686 {
1687         struct alc_spec *spec = codec->spec;
1688
1689         spec->autocfg.hp_pins[0] = 0x15;
1690         spec->autocfg.speaker_pins[0] = 0x14;
1691         spec->autocfg.speaker_pins[1] = 0x16;
1692         spec->autocfg.speaker_pins[2] = 0x1b;
1693         alc_automute_amp(codec);
1694 }
1695
1696 /*
1697  * ALC880 3-stack model
1698  *
1699  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1700  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1701  *                 F-Mic = 0x1b, HP = 0x19
1702  */
1703
1704 static hda_nid_t alc880_dac_nids[4] = {
1705         /* front, rear, clfe, rear_surr */
1706         0x02, 0x05, 0x04, 0x03
1707 };
1708
1709 static hda_nid_t alc880_adc_nids[3] = {
1710         /* ADC0-2 */
1711         0x07, 0x08, 0x09,
1712 };
1713
1714 /* The datasheet says the node 0x07 is connected from inputs,
1715  * but it shows zero connection in the real implementation on some devices.
1716  * Note: this is a 915GAV bug, fixed on 915GLV
1717  */
1718 static hda_nid_t alc880_adc_nids_alt[2] = {
1719         /* ADC1-2 */
1720         0x08, 0x09,
1721 };
1722
1723 #define ALC880_DIGOUT_NID       0x06
1724 #define ALC880_DIGIN_NID        0x0a
1725
1726 static struct hda_input_mux alc880_capture_source = {
1727         .num_items = 4,
1728         .items = {
1729                 { "Mic", 0x0 },
1730                 { "Front Mic", 0x3 },
1731                 { "Line", 0x2 },
1732                 { "CD", 0x4 },
1733         },
1734 };
1735
1736 /* channel source setting (2/6 channel selection for 3-stack) */
1737 /* 2ch mode */
1738 static struct hda_verb alc880_threestack_ch2_init[] = {
1739         /* set line-in to input, mute it */
1740         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1741         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1742         /* set mic-in to input vref 80%, mute it */
1743         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1744         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1745         { } /* end */
1746 };
1747
1748 /* 6ch mode */
1749 static struct hda_verb alc880_threestack_ch6_init[] = {
1750         /* set line-in to output, unmute it */
1751         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1752         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1753         /* set mic-in to output, unmute it */
1754         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1755         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1756         { } /* end */
1757 };
1758
1759 static struct hda_channel_mode alc880_threestack_modes[2] = {
1760         { 2, alc880_threestack_ch2_init },
1761         { 6, alc880_threestack_ch6_init },
1762 };
1763
1764 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1765         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1766         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1767         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1768         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1769         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1770         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1771         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1772         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 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_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1779         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1780         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1781         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1782         {
1783                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1784                 .name = "Channel Mode",
1785                 .info = alc_ch_mode_info,
1786                 .get = alc_ch_mode_get,
1787                 .put = alc_ch_mode_put,
1788         },
1789         { } /* end */
1790 };
1791
1792 /* capture mixer elements */
1793 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1794                             struct snd_ctl_elem_info *uinfo)
1795 {
1796         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1797         struct alc_spec *spec = codec->spec;
1798         int err;
1799
1800         mutex_lock(&codec->control_mutex);
1801         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1802                                                       HDA_INPUT);
1803         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1804         mutex_unlock(&codec->control_mutex);
1805         return err;
1806 }
1807
1808 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1809                            unsigned int size, unsigned int __user *tlv)
1810 {
1811         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1812         struct alc_spec *spec = codec->spec;
1813         int err;
1814
1815         mutex_lock(&codec->control_mutex);
1816         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1817                                                       HDA_INPUT);
1818         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1819         mutex_unlock(&codec->control_mutex);
1820         return err;
1821 }
1822
1823 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1824                              struct snd_ctl_elem_value *ucontrol);
1825
1826 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1827                                  struct snd_ctl_elem_value *ucontrol,
1828                                  getput_call_t func)
1829 {
1830         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1831         struct alc_spec *spec = codec->spec;
1832         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1833         int err;
1834
1835         mutex_lock(&codec->control_mutex);
1836         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1837                                                       3, 0, HDA_INPUT);
1838         err = func(kcontrol, ucontrol);
1839         mutex_unlock(&codec->control_mutex);
1840         return err;
1841 }
1842
1843 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1844                            struct snd_ctl_elem_value *ucontrol)
1845 {
1846         return alc_cap_getput_caller(kcontrol, ucontrol,
1847                                      snd_hda_mixer_amp_volume_get);
1848 }
1849
1850 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1851                            struct snd_ctl_elem_value *ucontrol)
1852 {
1853         return alc_cap_getput_caller(kcontrol, ucontrol,
1854                                      snd_hda_mixer_amp_volume_put);
1855 }
1856
1857 /* capture mixer elements */
1858 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1859
1860 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1861                           struct snd_ctl_elem_value *ucontrol)
1862 {
1863         return alc_cap_getput_caller(kcontrol, ucontrol,
1864                                      snd_hda_mixer_amp_switch_get);
1865 }
1866
1867 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1868                           struct snd_ctl_elem_value *ucontrol)
1869 {
1870         return alc_cap_getput_caller(kcontrol, ucontrol,
1871                                      snd_hda_mixer_amp_switch_put);
1872 }
1873
1874 #define _DEFINE_CAPMIX(num) \
1875         { \
1876                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1877                 .name = "Capture Switch", \
1878                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1879                 .count = num, \
1880                 .info = alc_cap_sw_info, \
1881                 .get = alc_cap_sw_get, \
1882                 .put = alc_cap_sw_put, \
1883         }, \
1884         { \
1885                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1886                 .name = "Capture Volume", \
1887                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1888                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1889                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1890                 .count = num, \
1891                 .info = alc_cap_vol_info, \
1892                 .get = alc_cap_vol_get, \
1893                 .put = alc_cap_vol_put, \
1894                 .tlv = { .c = alc_cap_vol_tlv }, \
1895         }
1896
1897 #define _DEFINE_CAPSRC(num) \
1898         { \
1899                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1900                 /* .name = "Capture Source", */ \
1901                 .name = "Input Source", \
1902                 .count = num, \
1903                 .info = alc_mux_enum_info, \
1904                 .get = alc_mux_enum_get, \
1905                 .put = alc_mux_enum_put, \
1906         }
1907
1908 #define DEFINE_CAPMIX(num) \
1909 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1910         _DEFINE_CAPMIX(num),                                  \
1911         _DEFINE_CAPSRC(num),                                  \
1912         { } /* end */                                         \
1913 }
1914
1915 #define DEFINE_CAPMIX_NOSRC(num) \
1916 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1917         _DEFINE_CAPMIX(num),                                        \
1918         { } /* end */                                               \
1919 }
1920
1921 /* up to three ADCs */
1922 DEFINE_CAPMIX(1);
1923 DEFINE_CAPMIX(2);
1924 DEFINE_CAPMIX(3);
1925 DEFINE_CAPMIX_NOSRC(1);
1926 DEFINE_CAPMIX_NOSRC(2);
1927 DEFINE_CAPMIX_NOSRC(3);
1928
1929 /*
1930  * ALC880 5-stack model
1931  *
1932  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1933  *      Side = 0x02 (0xd)
1934  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1935  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1936  */
1937
1938 /* additional mixers to alc880_three_stack_mixer */
1939 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1940         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1941         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1942         { } /* end */
1943 };
1944
1945 /* channel source setting (6/8 channel selection for 5-stack) */
1946 /* 6ch mode */
1947 static struct hda_verb alc880_fivestack_ch6_init[] = {
1948         /* set line-in to input, mute it */
1949         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1950         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1951         { } /* end */
1952 };
1953
1954 /* 8ch mode */
1955 static struct hda_verb alc880_fivestack_ch8_init[] = {
1956         /* set line-in to output, unmute it */
1957         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1958         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1959         { } /* end */
1960 };
1961
1962 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1963         { 6, alc880_fivestack_ch6_init },
1964         { 8, alc880_fivestack_ch8_init },
1965 };
1966
1967
1968 /*
1969  * ALC880 6-stack model
1970  *
1971  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1972  *      Side = 0x05 (0x0f)
1973  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1974  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1975  */
1976
1977 static hda_nid_t alc880_6st_dac_nids[4] = {
1978         /* front, rear, clfe, rear_surr */
1979         0x02, 0x03, 0x04, 0x05
1980 };
1981
1982 static struct hda_input_mux alc880_6stack_capture_source = {
1983         .num_items = 4,
1984         .items = {
1985                 { "Mic", 0x0 },
1986                 { "Front Mic", 0x1 },
1987                 { "Line", 0x2 },
1988                 { "CD", 0x4 },
1989         },
1990 };
1991
1992 /* fixed 8-channels */
1993 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1994         { 8, NULL },
1995 };
1996
1997 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1998         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1999         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2000         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2001         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2002         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2003         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2004         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2005         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2006         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2007         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2008         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2009         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2010         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2011         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2012         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2013         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2014         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2015         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2016         {
2017                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2018                 .name = "Channel Mode",
2019                 .info = alc_ch_mode_info,
2020                 .get = alc_ch_mode_get,
2021                 .put = alc_ch_mode_put,
2022         },
2023         { } /* end */
2024 };
2025
2026
2027 /*
2028  * ALC880 W810 model
2029  *
2030  * W810 has rear IO for:
2031  * Front (DAC 02)
2032  * Surround (DAC 03)
2033  * Center/LFE (DAC 04)
2034  * Digital out (06)
2035  *
2036  * The system also has a pair of internal speakers, and a headphone jack.
2037  * These are both connected to Line2 on the codec, hence to DAC 02.
2038  *
2039  * There is a variable resistor to control the speaker or headphone
2040  * volume. This is a hardware-only device without a software API.
2041  *
2042  * Plugging headphones in will disable the internal speakers. This is
2043  * implemented in hardware, not via the driver using jack sense. In
2044  * a similar fashion, plugging into the rear socket marked "front" will
2045  * disable both the speakers and headphones.
2046  *
2047  * For input, there's a microphone jack, and an "audio in" jack.
2048  * These may not do anything useful with this driver yet, because I
2049  * haven't setup any initialization verbs for these yet...
2050  */
2051
2052 static hda_nid_t alc880_w810_dac_nids[3] = {
2053         /* front, rear/surround, clfe */
2054         0x02, 0x03, 0x04
2055 };
2056
2057 /* fixed 6 channels */
2058 static struct hda_channel_mode alc880_w810_modes[1] = {
2059         { 6, NULL }
2060 };
2061
2062 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2063 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2064         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2065         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2066         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2067         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2068         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2069         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2070         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2071         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2072         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2073         { } /* end */
2074 };
2075
2076
2077 /*
2078  * Z710V model
2079  *
2080  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2081  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2082  *                 Line = 0x1a
2083  */
2084
2085 static hda_nid_t alc880_z71v_dac_nids[1] = {
2086         0x02
2087 };
2088 #define ALC880_Z71V_HP_DAC      0x03
2089
2090 /* fixed 2 channels */
2091 static struct hda_channel_mode alc880_2_jack_modes[1] = {
2092         { 2, NULL }
2093 };
2094
2095 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
2096         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2097         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2098         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2099         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2100         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2101         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2102         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2103         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2104         { } /* end */
2105 };
2106
2107
2108 /*
2109  * ALC880 F1734 model
2110  *
2111  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
2112  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
2113  */
2114
2115 static hda_nid_t alc880_f1734_dac_nids[1] = {
2116         0x03
2117 };
2118 #define ALC880_F1734_HP_DAC     0x02
2119
2120 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
2121         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2122         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2123         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2124         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 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("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2128         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2129         { } /* end */
2130 };
2131
2132 static struct hda_input_mux alc880_f1734_capture_source = {
2133         .num_items = 2,
2134         .items = {
2135                 { "Mic", 0x1 },
2136                 { "CD", 0x4 },
2137         },
2138 };
2139
2140
2141 /*
2142  * ALC880 ASUS model
2143  *
2144  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2145  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2146  *  Mic = 0x18, Line = 0x1a
2147  */
2148
2149 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
2150 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
2151
2152 static struct snd_kcontrol_new alc880_asus_mixer[] = {
2153         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2154         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2155         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2156         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2157         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2158         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2159         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2160         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2161         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2162         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2163         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2164         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2165         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2166         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2167         {
2168                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2169                 .name = "Channel Mode",
2170                 .info = alc_ch_mode_info,
2171                 .get = alc_ch_mode_get,
2172                 .put = alc_ch_mode_put,
2173         },
2174         { } /* end */
2175 };
2176
2177 /*
2178  * ALC880 ASUS W1V model
2179  *
2180  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2181  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2182  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
2183  */
2184
2185 /* additional mixers to alc880_asus_mixer */
2186 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
2187         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
2188         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
2189         { } /* end */
2190 };
2191
2192 /* TCL S700 */
2193 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
2194         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2195         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2196         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
2197         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
2198         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
2199         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
2200         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
2201         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
2202         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
2203         { } /* end */
2204 };
2205
2206 /* Uniwill */
2207 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
2208         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2209         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2210         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2211         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2212         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2213         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2214         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2215         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2216         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2217         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2218         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2219         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2220         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2221         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2222         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2223         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2224         {
2225                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2226                 .name = "Channel Mode",
2227                 .info = alc_ch_mode_info,
2228                 .get = alc_ch_mode_get,
2229                 .put = alc_ch_mode_put,
2230         },
2231         { } /* end */
2232 };
2233
2234 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
2235         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2236         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2237         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2238         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2239         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2240         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2241         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2242         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2243         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2244         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2245         { } /* end */
2246 };
2247
2248 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
2249         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2250         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2251         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2252         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2253         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2254         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2255         { } /* end */
2256 };
2257
2258 /*
2259  * virtual master controls
2260  */
2261
2262 /*
2263  * slave controls for virtual master
2264  */
2265 static const char *alc_slave_vols[] = {
2266         "Front Playback Volume",
2267         "Surround Playback Volume",
2268         "Center Playback Volume",
2269         "LFE Playback Volume",
2270         "Side Playback Volume",
2271         "Headphone Playback Volume",
2272         "Speaker Playback Volume",
2273         "Mono Playback Volume",
2274         "Line-Out Playback Volume",
2275         "PCM Playback Volume",
2276         NULL,
2277 };
2278
2279 static const char *alc_slave_sws[] = {
2280         "Front Playback Switch",
2281         "Surround Playback Switch",
2282         "Center Playback Switch",
2283         "LFE Playback Switch",
2284         "Side Playback Switch",
2285         "Headphone Playback Switch",
2286         "Speaker Playback Switch",
2287         "Mono Playback Switch",
2288         "IEC958 Playback Switch",
2289         NULL,
2290 };
2291
2292 /*
2293  * build control elements
2294  */
2295
2296 static void alc_free_kctls(struct hda_codec *codec);
2297
2298 /* additional beep mixers; the actual parameters are overwritten at build */
2299 static struct snd_kcontrol_new alc_beep_mixer[] = {
2300         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2301         HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT),
2302         { } /* end */
2303 };
2304
2305 static int alc_build_controls(struct hda_codec *codec)
2306 {
2307         struct alc_spec *spec = codec->spec;
2308         int err;
2309         int i;
2310
2311         for (i = 0; i < spec->num_mixers; i++) {
2312                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2313                 if (err < 0)
2314                         return err;
2315         }
2316         if (spec->cap_mixer) {
2317                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2318                 if (err < 0)
2319                         return err;
2320         }
2321         if (spec->multiout.dig_out_nid) {
2322                 err = snd_hda_create_spdif_out_ctls(codec,
2323                                                     spec->multiout.dig_out_nid);
2324                 if (err < 0)
2325                         return err;
2326                 if (!spec->no_analog) {
2327                         err = snd_hda_create_spdif_share_sw(codec,
2328                                                             &spec->multiout);
2329                         if (err < 0)
2330                                 return err;
2331                         spec->multiout.share_spdif = 1;
2332                 }
2333         }
2334         if (spec->dig_in_nid) {
2335                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2336                 if (err < 0)
2337                         return err;
2338         }
2339
2340         /* create beep controls if needed */
2341         if (spec->beep_amp) {
2342                 struct snd_kcontrol_new *knew;
2343                 for (knew = alc_beep_mixer; knew->name; knew++) {
2344                         struct snd_kcontrol *kctl;
2345                         kctl = snd_ctl_new1(knew, codec);
2346                         if (!kctl)
2347                                 return -ENOMEM;
2348                         kctl->private_value = spec->beep_amp;
2349                         err = snd_hda_ctl_add(codec, kctl);
2350                         if (err < 0)
2351                                 return err;
2352                 }
2353         }
2354
2355         /* if we have no master control, let's create it */
2356         if (!spec->no_analog &&
2357             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2358                 unsigned int vmaster_tlv[4];
2359                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2360                                         HDA_OUTPUT, vmaster_tlv);
2361                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2362                                           vmaster_tlv, alc_slave_vols);
2363                 if (err < 0)
2364                         return err;
2365         }
2366         if (!spec->no_analog &&
2367             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2368                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2369                                           NULL, alc_slave_sws);
2370                 if (err < 0)
2371                         return err;
2372         }
2373
2374         alc_free_kctls(codec); /* no longer needed */
2375         return 0;
2376 }
2377
2378
2379 /*
2380  * initialize the codec volumes, etc
2381  */
2382
2383 /*
2384  * generic initialization of ADC, input mixers and output mixers
2385  */
2386 static struct hda_verb alc880_volume_init_verbs[] = {
2387         /*
2388          * Unmute ADC0-2 and set the default input to mic-in
2389          */
2390         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2391         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2392         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2393         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2394         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2395         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2396
2397         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2398          * mixer widget
2399          * Note: PASD motherboards uses the Line In 2 as the input for front
2400          * panel mic (mic 2)
2401          */
2402         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2403         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2404         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2405         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2406         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2407         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2408         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2409         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2410
2411         /*
2412          * Set up output mixers (0x0c - 0x0f)
2413          */
2414         /* set vol=0 to output mixers */
2415         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2416         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2417         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2418         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2419         /* set up input amps for analog loopback */
2420         /* Amp Indices: DAC = 0, mixer = 1 */
2421         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2422         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2423         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2424         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2425         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2426         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2427         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2428         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2429
2430         { }
2431 };
2432
2433 /*
2434  * 3-stack pin configuration:
2435  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2436  */
2437 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2438         /*
2439          * preset connection lists of input pins
2440          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2441          */
2442         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2443         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2444         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2445
2446         /*
2447          * Set pin mode and muting
2448          */
2449         /* set front pin widgets 0x14 for output */
2450         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2451         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2452         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2453         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2454         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2455         /* Mic2 (as headphone out) for HP output */
2456         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2457         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2458         /* Line In pin widget for input */
2459         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2460         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2461         /* Line2 (as front mic) pin widget for input and vref at 80% */
2462         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2463         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2464         /* CD pin widget for input */
2465         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2466
2467         { }
2468 };
2469
2470 /*
2471  * 5-stack pin configuration:
2472  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2473  * line-in/side = 0x1a, f-mic = 0x1b
2474  */
2475 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2476         /*
2477          * preset connection lists of input pins
2478          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2479          */
2480         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2481         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2482
2483         /*
2484          * Set pin mode and muting
2485          */
2486         /* set pin widgets 0x14-0x17 for output */
2487         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2488         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2489         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2490         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2491         /* unmute pins for output (no gain on this amp) */
2492         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2493         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2494         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2495         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2496
2497         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2498         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2499         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2500         /* Mic2 (as headphone out) for HP output */
2501         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2502         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2503         /* Line In pin widget for input */
2504         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2505         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2506         /* Line2 (as front mic) pin widget for input and vref at 80% */
2507         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2508         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2509         /* CD pin widget for input */
2510         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2511
2512         { }
2513 };
2514
2515 /*
2516  * W810 pin configuration:
2517  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2518  */
2519 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2520         /* hphone/speaker input selector: front DAC */
2521         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2522
2523         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2524         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2525         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2526         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2527         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2528         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2529
2530         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2531         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2532
2533         { }
2534 };
2535
2536 /*
2537  * Z71V pin configuration:
2538  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2539  */
2540 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2541         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2542         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2543         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2544         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2545
2546         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2547         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2548         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2549         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2550
2551         { }
2552 };
2553
2554 /*
2555  * 6-stack pin configuration:
2556  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2557  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2558  */
2559 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2560         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2561
2562         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2563         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2564         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2565         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2566         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2567         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2568         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2569         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2570
2571         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2572         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2573         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2574         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2575         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2576         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2577         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2578         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2579         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2580
2581         { }
2582 };
2583
2584 /*
2585  * Uniwill pin configuration:
2586  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2587  * line = 0x1a
2588  */
2589 static struct hda_verb alc880_uniwill_init_verbs[] = {
2590         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2591
2592         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2593         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2594         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2595         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2596         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2597         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2598         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2599         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2600         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2601         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2602         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2603         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2604         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2605         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2606
2607         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2608         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2609         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2610         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2611         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2612         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2613         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2614         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2615         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2616
2617         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2618         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2619
2620         { }
2621 };
2622
2623 /*
2624 * Uniwill P53
2625 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2626  */
2627 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2628         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2629
2630         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2631         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2632         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2633         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2634         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2635         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2636         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2637         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2638         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2639         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2640         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2641         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2642
2643         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2644         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2645         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2646         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2647         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2648         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2649
2650         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2651         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2652
2653         { }
2654 };
2655
2656 static struct hda_verb alc880_beep_init_verbs[] = {
2657         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2658         { }
2659 };
2660
2661 /* auto-toggle front mic */
2662 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2663 {
2664         unsigned int present;
2665         unsigned char bits;
2666
2667         present = snd_hda_codec_read(codec, 0x18, 0,
2668                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2669         bits = present ? HDA_AMP_MUTE : 0;
2670         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2671 }
2672
2673 static void alc880_uniwill_init_hook(struct hda_codec *codec)
2674 {
2675         struct alc_spec *spec = codec->spec;
2676
2677         spec->autocfg.hp_pins[0] = 0x14;
2678         spec->autocfg.speaker_pins[0] = 0x15;
2679         spec->autocfg.speaker_pins[0] = 0x16;
2680         alc_automute_amp(codec);
2681         alc880_uniwill_mic_automute(codec);
2682 }
2683
2684 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2685                                        unsigned int res)
2686 {
2687         /* Looks like the unsol event is incompatible with the standard
2688          * definition.  4bit tag is placed at 28 bit!
2689          */
2690         switch (res >> 28) {
2691         case ALC880_MIC_EVENT:
2692                 alc880_uniwill_mic_automute(codec);
2693                 break;
2694         default:
2695                 alc_automute_amp_unsol_event(codec, res);
2696                 break;
2697         }
2698 }
2699
2700 static void alc880_uniwill_p53_init_hook(struct hda_codec *codec)
2701 {
2702         struct alc_spec *spec = codec->spec;
2703
2704         spec->autocfg.hp_pins[0] = 0x14;
2705         spec->autocfg.speaker_pins[0] = 0x15;
2706         alc_automute_amp(codec);
2707 }
2708
2709 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2710 {
2711         unsigned int present;
2712
2713         present = snd_hda_codec_read(codec, 0x21, 0,
2714                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2715         present &= HDA_AMP_VOLMASK;
2716         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2717                                  HDA_AMP_VOLMASK, present);
2718         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2719                                  HDA_AMP_VOLMASK, present);
2720 }
2721
2722 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2723                                            unsigned int res)
2724 {
2725         /* Looks like the unsol event is incompatible with the standard
2726          * definition.  4bit tag is placed at 28 bit!
2727          */
2728         if ((res >> 28) == ALC880_DCVOL_EVENT)
2729                 alc880_uniwill_p53_dcvol_automute(codec);
2730         else
2731                 alc_automute_amp_unsol_event(codec, res);
2732 }
2733
2734 /*
2735  * F1734 pin configuration:
2736  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2737  */
2738 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2739         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2740         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2741         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2742         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2743         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2744
2745         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2746         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2747         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2748         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2749
2750         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2751         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2752         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2753         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2754         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2755         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2756         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2757         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2758         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2759
2760         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2761         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2762
2763         { }
2764 };
2765
2766 /*
2767  * ASUS pin configuration:
2768  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2769  */
2770 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2771         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2772         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2773         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2774         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2775
2776         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2777         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2778         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2779         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2780         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2781         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2782         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2783         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2784
2785         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2786         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2787         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2788         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2789         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2790         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2791         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2792         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2793         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2794
2795         { }
2796 };
2797
2798 /* Enable GPIO mask and set output */
2799 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2800 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2801 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
2802
2803 /* Clevo m520g init */
2804 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2805         /* headphone output */
2806         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2807         /* line-out */
2808         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2809         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2810         /* Line-in */
2811         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2812         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2813         /* CD */
2814         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2815         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2816         /* Mic1 (rear panel) */
2817         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2818         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2819         /* Mic2 (front panel) */
2820         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2821         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2822         /* headphone */
2823         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2824         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2825         /* change to EAPD mode */
2826         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2827         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2828
2829         { }
2830 };
2831
2832 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2833         /* change to EAPD mode */
2834         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2835         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2836
2837         /* Headphone output */
2838         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2839         /* Front output*/
2840         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2841         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2842
2843         /* Line In pin widget for input */
2844         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2845         /* CD pin widget for input */
2846         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2847         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2848         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2849
2850         /* change to EAPD mode */
2851         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2852         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2853
2854         { }
2855 };
2856
2857 /*
2858  * LG m1 express dual
2859  *
2860  * Pin assignment:
2861  *   Rear Line-In/Out (blue): 0x14
2862  *   Build-in Mic-In: 0x15
2863  *   Speaker-out: 0x17
2864  *   HP-Out (green): 0x1b
2865  *   Mic-In/Out (red): 0x19
2866  *   SPDIF-Out: 0x1e
2867  */
2868
2869 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2870 static hda_nid_t alc880_lg_dac_nids[3] = {
2871         0x05, 0x02, 0x03
2872 };
2873
2874 /* seems analog CD is not working */
2875 static struct hda_input_mux alc880_lg_capture_source = {
2876         .num_items = 3,
2877         .items = {
2878                 { "Mic", 0x1 },
2879                 { "Line", 0x5 },
2880                 { "Internal Mic", 0x6 },
2881         },
2882 };
2883
2884 /* 2,4,6 channel modes */
2885 static struct hda_verb alc880_lg_ch2_init[] = {
2886         /* set line-in and mic-in to input */
2887         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2888         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2889         { }
2890 };
2891
2892 static struct hda_verb alc880_lg_ch4_init[] = {
2893         /* set line-in to out and mic-in to input */
2894         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2895         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2896         { }
2897 };
2898
2899 static struct hda_verb alc880_lg_ch6_init[] = {
2900         /* set line-in and mic-in to output */
2901         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2902         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2903         { }
2904 };
2905
2906 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2907         { 2, alc880_lg_ch2_init },
2908         { 4, alc880_lg_ch4_init },
2909         { 6, alc880_lg_ch6_init },
2910 };
2911
2912 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2913         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2914         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2915         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2916         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2917         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2918         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2919         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2920         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2921         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2922         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2923         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2924         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2925         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2926         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2927         {
2928                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2929                 .name = "Channel Mode",
2930                 .info = alc_ch_mode_info,
2931                 .get = alc_ch_mode_get,
2932                 .put = alc_ch_mode_put,
2933         },
2934         { } /* end */
2935 };
2936
2937 static struct hda_verb alc880_lg_init_verbs[] = {
2938         /* set capture source to mic-in */
2939         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2940         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2941         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2942         /* mute all amp mixer inputs */
2943         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2944         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2945         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2946         /* line-in to input */
2947         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2948         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2949         /* built-in mic */
2950         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2951         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2952         /* speaker-out */
2953         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2954         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2955         /* mic-in to input */
2956         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2957         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2958         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2959         /* HP-out */
2960         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2961         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2962         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2963         /* jack sense */
2964         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2965         { }
2966 };
2967
2968 /* toggle speaker-output according to the hp-jack state */
2969 static void alc880_lg_init_hook(struct hda_codec *codec)
2970 {
2971         struct alc_spec *spec = codec->spec;
2972
2973         spec->autocfg.hp_pins[0] = 0x1b;
2974         spec->autocfg.speaker_pins[0] = 0x17;
2975         alc_automute_amp(codec);
2976 }
2977
2978 /*
2979  * LG LW20
2980  *
2981  * Pin assignment:
2982  *   Speaker-out: 0x14
2983  *   Mic-In: 0x18
2984  *   Built-in Mic-In: 0x19
2985  *   Line-In: 0x1b
2986  *   HP-Out: 0x1a
2987  *   SPDIF-Out: 0x1e
2988  */
2989
2990 static struct hda_input_mux alc880_lg_lw_capture_source = {
2991         .num_items = 3,
2992         .items = {
2993                 { "Mic", 0x0 },
2994                 { "Internal Mic", 0x1 },
2995                 { "Line In", 0x2 },
2996         },
2997 };
2998
2999 #define alc880_lg_lw_modes alc880_threestack_modes
3000
3001 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3002         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3003         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3004         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3005         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
3006         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3007         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3008         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3009         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3010         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3011         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3012         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3013         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3014         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
3015         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
3016         {
3017                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3018                 .name = "Channel Mode",
3019                 .info = alc_ch_mode_info,
3020                 .get = alc_ch_mode_get,
3021                 .put = alc_ch_mode_put,
3022         },
3023         { } /* end */
3024 };
3025
3026 static struct hda_verb alc880_lg_lw_init_verbs[] = {
3027         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3028         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3029         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3030
3031         /* set capture source to mic-in */
3032         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3033         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3034         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3035         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3036         /* speaker-out */
3037         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3038         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3039         /* HP-out */
3040         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3041         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3042         /* mic-in to input */
3043         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3044         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3045         /* built-in mic */
3046         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3047         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3048         /* jack sense */
3049         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3050         { }
3051 };
3052
3053 /* toggle speaker-output according to the hp-jack state */
3054 static void alc880_lg_lw_init_hook(struct hda_codec *codec)
3055 {
3056         struct alc_spec *spec = codec->spec;
3057
3058         spec->autocfg.hp_pins[0] = 0x1b;
3059         spec->autocfg.speaker_pins[0] = 0x14;
3060         alc_automute_amp(codec);
3061 }
3062
3063 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
3064         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3065         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
3066         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3067         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3068         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3069         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
3070         { } /* end */
3071 };
3072
3073 static struct hda_input_mux alc880_medion_rim_capture_source = {
3074         .num_items = 2,
3075         .items = {
3076                 { "Mic", 0x0 },
3077                 { "Internal Mic", 0x1 },
3078         },
3079 };
3080
3081 static struct hda_verb alc880_medion_rim_init_verbs[] = {
3082         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3083
3084         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3085         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3086
3087         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3088         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3089         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3090         /* Mic2 (as headphone out) for HP output */
3091         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3092         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3093         /* Internal Speaker */
3094         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3095         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3096
3097         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3098         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3099
3100         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3101         { }
3102 };
3103
3104 /* toggle speaker-output according to the hp-jack state */
3105 static void alc880_medion_rim_automute(struct hda_codec *codec)
3106 {
3107         struct alc_spec *spec = codec->spec;
3108         alc_automute_amp(codec);
3109         /* toggle EAPD */
3110         if (spec->jack_present)
3111                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
3112         else
3113                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
3114 }
3115
3116 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3117                                           unsigned int res)
3118 {
3119         /* Looks like the unsol event is incompatible with the standard
3120          * definition.  4bit tag is placed at 28 bit!
3121          */
3122         if ((res >> 28) == ALC880_HP_EVENT)
3123                 alc880_medion_rim_automute(codec);
3124 }
3125
3126 static void alc880_medion_rim_init_hook(struct hda_codec *codec)
3127 {
3128         struct alc_spec *spec = codec->spec;
3129
3130         spec->autocfg.hp_pins[0] = 0x14;
3131         spec->autocfg.speaker_pins[0] = 0x1b;
3132         alc880_medion_rim_automute(codec);
3133 }
3134
3135 #ifdef CONFIG_SND_HDA_POWER_SAVE
3136 static struct hda_amp_list alc880_loopbacks[] = {
3137         { 0x0b, HDA_INPUT, 0 },
3138         { 0x0b, HDA_INPUT, 1 },
3139         { 0x0b, HDA_INPUT, 2 },
3140         { 0x0b, HDA_INPUT, 3 },
3141         { 0x0b, HDA_INPUT, 4 },
3142         { } /* end */
3143 };
3144
3145 static struct hda_amp_list alc880_lg_loopbacks[] = {
3146         { 0x0b, HDA_INPUT, 1 },
3147         { 0x0b, HDA_INPUT, 6 },
3148         { 0x0b, HDA_INPUT, 7 },
3149         { } /* end */
3150 };
3151 #endif
3152
3153 /*
3154  * Common callbacks
3155  */
3156
3157 static int alc_init(struct hda_codec *codec)
3158 {
3159         struct alc_spec *spec = codec->spec;
3160         unsigned int i;
3161
3162         alc_fix_pll(codec);
3163         alc_auto_init_amp(codec, spec->init_amp);
3164
3165         for (i = 0; i < spec->num_init_verbs; i++)
3166                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
3167
3168         if (spec->init_hook)
3169                 spec->init_hook(codec);
3170
3171         return 0;
3172 }
3173
3174 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
3175 {
3176         struct alc_spec *spec = codec->spec;
3177
3178         if (spec->unsol_event)
3179                 spec->unsol_event(codec, res);
3180 }
3181
3182 #ifdef CONFIG_SND_HDA_POWER_SAVE
3183 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
3184 {
3185         struct alc_spec *spec = codec->spec;
3186         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
3187 }
3188 #endif
3189
3190 /*
3191  * Analog playback callbacks
3192  */
3193 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
3194                                     struct hda_codec *codec,
3195                                     struct snd_pcm_substream *substream)
3196 {
3197         struct alc_spec *spec = codec->spec;
3198         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
3199                                              hinfo);
3200 }
3201
3202 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3203                                        struct hda_codec *codec,
3204                                        unsigned int stream_tag,
3205                                        unsigned int format,
3206                                        struct snd_pcm_substream *substream)
3207 {
3208         struct alc_spec *spec = codec->spec;
3209         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
3210                                                 stream_tag, format, substream);
3211 }
3212
3213 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3214                                        struct hda_codec *codec,
3215                                        struct snd_pcm_substream *substream)
3216 {
3217         struct alc_spec *spec = codec->spec;
3218         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
3219 }
3220
3221 /*
3222  * Digital out
3223  */
3224 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3225                                         struct hda_codec *codec,
3226                                         struct snd_pcm_substream *substream)
3227 {
3228         struct alc_spec *spec = codec->spec;
3229         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3230 }
3231
3232 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3233                                            struct hda_codec *codec,
3234                                            unsigned int stream_tag,
3235                                            unsigned int format,
3236                                            struct snd_pcm_substream *substream)
3237 {
3238         struct alc_spec *spec = codec->spec;
3239         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3240                                              stream_tag, format, substream);
3241 }
3242
3243 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3244                                            struct hda_codec *codec,
3245                                            struct snd_pcm_substream *substream)
3246 {
3247         struct alc_spec *spec = codec->spec;
3248         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3249 }
3250
3251 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3252                                          struct hda_codec *codec,
3253                                          struct snd_pcm_substream *substream)
3254 {
3255         struct alc_spec *spec = codec->spec;
3256         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3257 }
3258
3259 /*
3260  * Analog capture
3261  */
3262 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3263                                       struct hda_codec *codec,
3264                                       unsigned int stream_tag,
3265                                       unsigned int format,
3266                                       struct snd_pcm_substream *substream)
3267 {
3268         struct alc_spec *spec = codec->spec;
3269
3270         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3271                                    stream_tag, 0, format);
3272         return 0;
3273 }
3274
3275 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3276                                       struct hda_codec *codec,
3277                                       struct snd_pcm_substream *substream)
3278 {
3279         struct alc_spec *spec = codec->spec;
3280
3281         snd_hda_codec_cleanup_stream(codec,
3282                                      spec->adc_nids[substream->number + 1]);
3283         return 0;
3284 }
3285
3286
3287 /*
3288  */
3289 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3290         .substreams = 1,
3291         .channels_min = 2,
3292         .channels_max = 8,
3293         /* NID is set in alc_build_pcms */
3294         .ops = {
3295                 .open = alc880_playback_pcm_open,
3296                 .prepare = alc880_playback_pcm_prepare,
3297                 .cleanup = alc880_playback_pcm_cleanup
3298         },
3299 };
3300
3301 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3302         .substreams = 1,
3303         .channels_min = 2,
3304         .channels_max = 2,
3305         /* NID is set in alc_build_pcms */
3306 };
3307
3308 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3309         .substreams = 1,
3310         .channels_min = 2,
3311         .channels_max = 2,
3312         /* NID is set in alc_build_pcms */
3313 };
3314
3315 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3316         .substreams = 2, /* can be overridden */
3317         .channels_min = 2,
3318         .channels_max = 2,
3319         /* NID is set in alc_build_pcms */
3320         .ops = {
3321                 .prepare = alc880_alt_capture_pcm_prepare,
3322                 .cleanup = alc880_alt_capture_pcm_cleanup
3323         },
3324 };
3325
3326 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3327         .substreams = 1,
3328         .channels_min = 2,
3329         .channels_max = 2,
3330         /* NID is set in alc_build_pcms */
3331         .ops = {
3332                 .open = alc880_dig_playback_pcm_open,
3333                 .close = alc880_dig_playback_pcm_close,
3334                 .prepare = alc880_dig_playback_pcm_prepare,
3335                 .cleanup = alc880_dig_playback_pcm_cleanup
3336         },
3337 };
3338
3339 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3340         .substreams = 1,
3341         .channels_min = 2,
3342         .channels_max = 2,
3343         /* NID is set in alc_build_pcms */
3344 };
3345
3346 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3347 static struct hda_pcm_stream alc_pcm_null_stream = {
3348         .substreams = 0,
3349         .channels_min = 0,
3350         .channels_max = 0,
3351 };
3352
3353 static int alc_build_pcms(struct hda_codec *codec)
3354 {
3355         struct alc_spec *spec = codec->spec;
3356         struct hda_pcm *info = spec->pcm_rec;
3357         int i;
3358
3359         codec->num_pcms = 1;
3360         codec->pcm_info = info;
3361
3362         if (spec->no_analog)
3363                 goto skip_analog;
3364
3365         snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
3366                  "%s Analog", codec->chip_name);
3367         info->name = spec->stream_name_analog;
3368         
3369         if (spec->stream_analog_playback) {
3370                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3371                         return -EINVAL;
3372                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3373                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3374         }
3375         if (spec->stream_analog_capture) {
3376                 if (snd_BUG_ON(!spec->adc_nids))
3377                         return -EINVAL;
3378                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3379                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3380         }
3381
3382         if (spec->channel_mode) {
3383                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3384                 for (i = 0; i < spec->num_channel_mode; i++) {
3385                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3386                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3387                         }
3388                 }
3389         }
3390
3391  skip_analog:
3392         /* SPDIF for stream index #1 */
3393         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3394                 snprintf(spec->stream_name_digital,
3395                          sizeof(spec->stream_name_digital),
3396                          "%s Digital", codec->chip_name);
3397                 codec->num_pcms = 2;
3398                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3399                 info = spec->pcm_rec + 1;
3400                 info->name = spec->stream_name_digital;
3401                 if (spec->dig_out_type)
3402                         info->pcm_type = spec->dig_out_type;
3403                 else
3404                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3405                 if (spec->multiout.dig_out_nid &&
3406                     spec->stream_digital_playback) {
3407                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3408                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3409                 }
3410                 if (spec->dig_in_nid &&
3411                     spec->stream_digital_capture) {
3412                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3413                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3414                 }
3415                 /* FIXME: do we need this for all Realtek codec models? */
3416                 codec->spdif_status_reset = 1;
3417         }
3418
3419         if (spec->no_analog)
3420                 return 0;
3421
3422         /* If the use of more than one ADC is requested for the current
3423          * model, configure a second analog capture-only PCM.
3424          */
3425         /* Additional Analaog capture for index #2 */
3426         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3427             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3428                 codec->num_pcms = 3;
3429                 info = spec->pcm_rec + 2;
3430                 info->name = spec->stream_name_analog;
3431                 if (spec->alt_dac_nid) {
3432                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3433                                 *spec->stream_analog_alt_playback;
3434                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3435                                 spec->alt_dac_nid;
3436                 } else {
3437                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3438                                 alc_pcm_null_stream;
3439                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3440                 }
3441                 if (spec->num_adc_nids > 1) {
3442                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3443                                 *spec->stream_analog_alt_capture;
3444                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3445                                 spec->adc_nids[1];
3446                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3447                                 spec->num_adc_nids - 1;
3448                 } else {
3449                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3450                                 alc_pcm_null_stream;
3451                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3452                 }
3453         }
3454
3455         return 0;
3456 }
3457
3458 static void alc_free_kctls(struct hda_codec *codec)
3459 {
3460         struct alc_spec *spec = codec->spec;
3461
3462         if (spec->kctls.list) {
3463                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3464                 int i;
3465                 for (i = 0; i < spec->kctls.used; i++)
3466                         kfree(kctl[i].name);
3467         }
3468         snd_array_free(&spec->kctls);
3469 }
3470
3471 static void alc_free(struct hda_codec *codec)
3472 {
3473         struct alc_spec *spec = codec->spec;
3474
3475         if (!spec)
3476                 return;
3477
3478         alc_free_kctls(codec);
3479         kfree(spec);
3480         snd_hda_detach_beep_device(codec);
3481 }
3482
3483 #ifdef SND_HDA_NEEDS_RESUME
3484 static int alc_resume(struct hda_codec *codec)
3485 {
3486         codec->patch_ops.init(codec);
3487         snd_hda_codec_resume_amp(codec);
3488         snd_hda_codec_resume_cache(codec);
3489         return 0;
3490 }
3491 #endif
3492
3493 /*
3494  */
3495 static struct hda_codec_ops alc_patch_ops = {
3496         .build_controls = alc_build_controls,
3497         .build_pcms = alc_build_pcms,
3498         .init = alc_init,
3499         .free = alc_free,
3500         .unsol_event = alc_unsol_event,
3501 #ifdef SND_HDA_NEEDS_RESUME
3502         .resume = alc_resume,
3503 #endif
3504 #ifdef CONFIG_SND_HDA_POWER_SAVE
3505         .check_power_status = alc_check_power_status,
3506 #endif
3507 };
3508
3509
3510 /*
3511  * Test configuration for debugging
3512  *
3513  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3514  * enum controls.
3515  */
3516 #ifdef CONFIG_SND_DEBUG
3517 static hda_nid_t alc880_test_dac_nids[4] = {
3518         0x02, 0x03, 0x04, 0x05
3519 };
3520
3521 static struct hda_input_mux alc880_test_capture_source = {
3522         .num_items = 7,
3523         .items = {
3524                 { "In-1", 0x0 },
3525                 { "In-2", 0x1 },
3526                 { "In-3", 0x2 },
3527                 { "In-4", 0x3 },
3528                 { "CD", 0x4 },
3529                 { "Front", 0x5 },
3530                 { "Surround", 0x6 },
3531         },
3532 };
3533
3534 static struct hda_channel_mode alc880_test_modes[4] = {
3535         { 2, NULL },
3536         { 4, NULL },
3537         { 6, NULL },
3538         { 8, NULL },
3539 };
3540
3541 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3542                                  struct snd_ctl_elem_info *uinfo)
3543 {
3544         static char *texts[] = {
3545                 "N/A", "Line Out", "HP Out",
3546                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3547         };
3548         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3549         uinfo->count = 1;
3550         uinfo->value.enumerated.items = 8;
3551         if (uinfo->value.enumerated.item >= 8)
3552                 uinfo->value.enumerated.item = 7;
3553         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3554         return 0;
3555 }
3556
3557 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3558                                 struct snd_ctl_elem_value *ucontrol)
3559 {
3560         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3561         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3562         unsigned int pin_ctl, item = 0;
3563
3564         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3565                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3566         if (pin_ctl & AC_PINCTL_OUT_EN) {
3567                 if (pin_ctl & AC_PINCTL_HP_EN)
3568                         item = 2;
3569                 else
3570                         item = 1;
3571         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3572                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3573                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3574                 case AC_PINCTL_VREF_50:  item = 4; break;
3575                 case AC_PINCTL_VREF_GRD: item = 5; break;
3576                 case AC_PINCTL_VREF_80:  item = 6; break;
3577                 case AC_PINCTL_VREF_100: item = 7; break;
3578                 }
3579         }
3580         ucontrol->value.enumerated.item[0] = item;
3581         return 0;
3582 }
3583
3584 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3585                                 struct snd_ctl_elem_value *ucontrol)
3586 {
3587         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3588         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3589         static unsigned int ctls[] = {
3590                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3591                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3592                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3593                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3594                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3595                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3596         };
3597         unsigned int old_ctl, new_ctl;
3598
3599         old_ctl = snd_hda_codec_read(codec, nid, 0,
3600                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3601         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3602         if (old_ctl != new_ctl) {
3603                 int val;
3604                 snd_hda_codec_write_cache(codec, nid, 0,
3605                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3606                                           new_ctl);
3607                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3608                         HDA_AMP_MUTE : 0;
3609                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3610                                          HDA_AMP_MUTE, val);
3611                 return 1;
3612         }
3613         return 0;
3614 }
3615
3616 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3617                                  struct snd_ctl_elem_info *uinfo)
3618 {
3619         static char *texts[] = {
3620                 "Front", "Surround", "CLFE", "Side"
3621         };
3622         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3623         uinfo->count = 1;
3624         uinfo->value.enumerated.items = 4;
3625         if (uinfo->value.enumerated.item >= 4)
3626                 uinfo->value.enumerated.item = 3;
3627         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3628         return 0;