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