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