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