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