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