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