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