]> git.karo-electronics.de Git - karo-tx-linux.git/blob - sound/pci/hda/patch_realtek.c
2581b8caf0568651f045ba6813762e0423dcee88
[karo-tx-linux.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_patch.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_3013,
76         ALC260_FUJITSU_S702X,
77         ALC260_ACER,
78         ALC260_WILL,
79         ALC260_REPLACER_672V,
80 #ifdef CONFIG_SND_DEBUG
81         ALC260_TEST,
82 #endif
83         ALC260_AUTO,
84         ALC260_MODEL_LAST /* last tag */
85 };
86
87 /* ALC262 models */
88 enum {
89         ALC262_BASIC,
90         ALC262_HIPPO,
91         ALC262_HIPPO_1,
92         ALC262_FUJITSU,
93         ALC262_HP_BPC,
94         ALC262_HP_BPC_D7000_WL,
95         ALC262_HP_BPC_D7000_WF,
96         ALC262_HP_TC_T5735,
97         ALC262_HP_RP5700,
98         ALC262_BENQ_ED8,
99         ALC262_SONY_ASSAMD,
100         ALC262_BENQ_T31,
101         ALC262_ULTRA,
102         ALC262_LENOVO_3000,
103         ALC262_NEC,
104         ALC262_AUTO,
105         ALC262_MODEL_LAST /* last tag */
106 };
107
108 /* ALC268 models */
109 enum {
110         ALC267_QUANTA_IL1,
111         ALC268_3ST,
112         ALC268_TOSHIBA,
113         ALC268_ACER,
114         ALC268_DELL,
115         ALC268_ZEPTO,
116 #ifdef CONFIG_SND_DEBUG
117         ALC268_TEST,
118 #endif
119         ALC268_AUTO,
120         ALC268_MODEL_LAST /* last tag */
121 };
122
123 /* ALC269 models */
124 enum {
125         ALC269_BASIC,
126         ALC269_ASUS_EEEPC_P703,
127         ALC269_ASUS_EEEPC_P901,
128         ALC269_AUTO,
129         ALC269_MODEL_LAST /* last tag */
130 };
131
132 /* ALC861 models */
133 enum {
134         ALC861_3ST,
135         ALC660_3ST,
136         ALC861_3ST_DIG,
137         ALC861_6ST_DIG,
138         ALC861_UNIWILL_M31,
139         ALC861_TOSHIBA,
140         ALC861_ASUS,
141         ALC861_ASUS_LAPTOP,
142         ALC861_AUTO,
143         ALC861_MODEL_LAST,
144 };
145
146 /* ALC861-VD models */
147 enum {
148         ALC660VD_3ST,
149         ALC660VD_3ST_DIG,
150         ALC861VD_3ST,
151         ALC861VD_3ST_DIG,
152         ALC861VD_6ST_DIG,
153         ALC861VD_LENOVO,
154         ALC861VD_DALLAS,
155         ALC861VD_HP,
156         ALC861VD_AUTO,
157         ALC861VD_MODEL_LAST,
158 };
159
160 /* ALC662 models */
161 enum {
162         ALC662_3ST_2ch_DIG,
163         ALC662_3ST_6ch_DIG,
164         ALC662_3ST_6ch,
165         ALC662_5ST_DIG,
166         ALC662_LENOVO_101E,
167         ALC662_ASUS_EEEPC_P701,
168         ALC662_ASUS_EEEPC_EP20,
169         ALC663_ASUS_M51VA,
170         ALC663_ASUS_G71V,
171         ALC663_ASUS_H13,
172         ALC663_ASUS_G50V,
173         ALC662_AUTO,
174         ALC662_MODEL_LAST,
175 };
176
177 /* ALC882 models */
178 enum {
179         ALC882_3ST_DIG,
180         ALC882_6ST_DIG,
181         ALC882_ARIMA,
182         ALC882_W2JC,
183         ALC882_TARGA,
184         ALC882_ASUS_A7J,
185         ALC882_ASUS_A7M,
186         ALC885_MACPRO,
187         ALC885_MBP3,
188         ALC885_IMAC24,
189         ALC882_AUTO,
190         ALC882_MODEL_LAST,
191 };
192
193 /* ALC883 models */
194 enum {
195         ALC883_3ST_2ch_DIG,
196         ALC883_3ST_6ch_DIG,
197         ALC883_3ST_6ch,
198         ALC883_6ST_DIG,
199         ALC883_TARGA_DIG,
200         ALC883_TARGA_2ch_DIG,
201         ALC883_ACER,
202         ALC883_ACER_ASPIRE,
203         ALC883_MEDION,
204         ALC883_MEDION_MD2,      
205         ALC883_LAPTOP_EAPD,
206         ALC883_LENOVO_101E_2ch,
207         ALC883_LENOVO_NB0763,
208         ALC888_LENOVO_MS7195_DIG,
209         ALC883_HAIER_W66,               
210         ALC888_3ST_HP,
211         ALC888_6ST_DELL,
212         ALC883_MITAC,
213         ALC883_CLEVO_M720,
214         ALC883_FUJITSU_PI2515,
215         ALC883_3ST_6ch_INTEL,
216         ALC883_AUTO,
217         ALC883_MODEL_LAST,
218 };
219
220 /* for GPIO Poll */
221 #define GPIO_MASK       0x03
222
223 struct alc_spec {
224         /* codec parameterization */
225         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
226         unsigned int num_mixers;
227
228         const struct hda_verb *init_verbs[5];   /* initialization verbs
229                                                  * don't forget NULL
230                                                  * termination!
231                                                  */
232         unsigned int num_init_verbs;
233
234         char *stream_name_analog;       /* analog PCM stream */
235         struct hda_pcm_stream *stream_analog_playback;
236         struct hda_pcm_stream *stream_analog_capture;
237         struct hda_pcm_stream *stream_analog_alt_playback;
238         struct hda_pcm_stream *stream_analog_alt_capture;
239
240         char *stream_name_digital;      /* digital PCM stream */
241         struct hda_pcm_stream *stream_digital_playback;
242         struct hda_pcm_stream *stream_digital_capture;
243
244         /* playback */
245         struct hda_multi_out multiout;  /* playback set-up
246                                          * max_channels, dacs must be set
247                                          * dig_out_nid and hp_nid are optional
248                                          */
249         hda_nid_t alt_dac_nid;
250
251         /* capture */
252         unsigned int num_adc_nids;
253         hda_nid_t *adc_nids;
254         hda_nid_t *capsrc_nids;
255         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
256
257         /* capture source */
258         unsigned int num_mux_defs;
259         const struct hda_input_mux *input_mux;
260         unsigned int cur_mux[3];
261
262         /* channel model */
263         const struct hda_channel_mode *channel_mode;
264         int num_channel_mode;
265         int need_dac_fix;
266
267         /* PCM information */
268         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
269
270         /* dynamic controls, init_verbs and input_mux */
271         struct auto_pin_cfg autocfg;
272         unsigned int num_kctl_alloc, num_kctl_used;
273         struct snd_kcontrol_new *kctl_alloc;
274         struct hda_input_mux private_imux;
275         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
276
277         /* hooks */
278         void (*init_hook)(struct hda_codec *codec);
279         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
280
281         /* for pin sensing */
282         unsigned int sense_updated: 1;
283         unsigned int jack_present: 1;
284         unsigned int master_sw: 1;
285
286         /* for virtual master */
287         hda_nid_t vmaster_nid;
288 #ifdef CONFIG_SND_HDA_POWER_SAVE
289         struct hda_loopback_check loopback;
290 #endif
291
292         /* for PLL fix */
293         hda_nid_t pll_nid;
294         unsigned int pll_coef_idx, pll_coef_bit;
295
296 #ifdef SND_HDA_NEEDS_RESUME
297 #define ALC_MAX_PINS    16
298         unsigned int num_pins;
299         hda_nid_t pin_nids[ALC_MAX_PINS];
300         unsigned int pin_cfgs[ALC_MAX_PINS];
301 #endif
302 };
303
304 /*
305  * configuration template - to be copied to the spec instance
306  */
307 struct alc_config_preset {
308         struct snd_kcontrol_new *mixers[5]; /* should be identical size
309                                              * with spec
310                                              */
311         const struct hda_verb *init_verbs[5];
312         unsigned int num_dacs;
313         hda_nid_t *dac_nids;
314         hda_nid_t dig_out_nid;          /* optional */
315         hda_nid_t hp_nid;               /* optional */
316         unsigned int num_adc_nids;
317         hda_nid_t *adc_nids;
318         hda_nid_t *capsrc_nids;
319         hda_nid_t dig_in_nid;
320         unsigned int num_channel_mode;
321         const struct hda_channel_mode *channel_mode;
322         int need_dac_fix;
323         unsigned int num_mux_defs;
324         const struct hda_input_mux *input_mux;
325         void (*unsol_event)(struct hda_codec *, unsigned int);
326         void (*init_hook)(struct hda_codec *);
327 #ifdef CONFIG_SND_HDA_POWER_SAVE
328         struct hda_amp_list *loopbacks;
329 #endif
330 };
331
332
333 /*
334  * input MUX handling
335  */
336 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
337                              struct snd_ctl_elem_info *uinfo)
338 {
339         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
340         struct alc_spec *spec = codec->spec;
341         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
342         if (mux_idx >= spec->num_mux_defs)
343                 mux_idx = 0;
344         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
345 }
346
347 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
348                             struct snd_ctl_elem_value *ucontrol)
349 {
350         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
351         struct alc_spec *spec = codec->spec;
352         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
353
354         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
355         return 0;
356 }
357
358 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
359                             struct snd_ctl_elem_value *ucontrol)
360 {
361         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
362         struct alc_spec *spec = codec->spec;
363         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
364         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
365         hda_nid_t nid = spec->capsrc_nids ?
366                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
367         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
368                                      nid, &spec->cur_mux[adc_idx]);
369 }
370
371
372 /*
373  * channel mode setting
374  */
375 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
376                             struct snd_ctl_elem_info *uinfo)
377 {
378         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
379         struct alc_spec *spec = codec->spec;
380         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
381                                     spec->num_channel_mode);
382 }
383
384 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
385                            struct snd_ctl_elem_value *ucontrol)
386 {
387         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
388         struct alc_spec *spec = codec->spec;
389         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
390                                    spec->num_channel_mode,
391                                    spec->multiout.max_channels);
392 }
393
394 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
395                            struct snd_ctl_elem_value *ucontrol)
396 {
397         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
398         struct alc_spec *spec = codec->spec;
399         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
400                                       spec->num_channel_mode,
401                                       &spec->multiout.max_channels);
402         if (err >= 0 && spec->need_dac_fix)
403                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
404         return err;
405 }
406
407 /*
408  * Control the mode of pin widget settings via the mixer.  "pc" is used
409  * instead of "%" to avoid consequences of accidently treating the % as 
410  * being part of a format specifier.  Maximum allowed length of a value is
411  * 63 characters plus NULL terminator.
412  *
413  * Note: some retasking pin complexes seem to ignore requests for input
414  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
415  * are requested.  Therefore order this list so that this behaviour will not
416  * cause problems when mixer clients move through the enum sequentially.
417  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
418  * March 2006.
419  */
420 static char *alc_pin_mode_names[] = {
421         "Mic 50pc bias", "Mic 80pc bias",
422         "Line in", "Line out", "Headphone out",
423 };
424 static unsigned char alc_pin_mode_values[] = {
425         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
426 };
427 /* The control can present all 5 options, or it can limit the options based
428  * in the pin being assumed to be exclusively an input or an output pin.  In
429  * addition, "input" pins may or may not process the mic bias option
430  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
431  * accept requests for bias as of chip versions up to March 2006) and/or
432  * wiring in the computer.
433  */
434 #define ALC_PIN_DIR_IN              0x00
435 #define ALC_PIN_DIR_OUT             0x01
436 #define ALC_PIN_DIR_INOUT           0x02
437 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
438 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
439
440 /* Info about the pin modes supported by the different pin direction modes. 
441  * For each direction the minimum and maximum values are given.
442  */
443 static signed char alc_pin_mode_dir_info[5][2] = {
444         { 0, 2 },    /* ALC_PIN_DIR_IN */
445         { 3, 4 },    /* ALC_PIN_DIR_OUT */
446         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
447         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
448         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
449 };
450 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
451 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
452 #define alc_pin_mode_n_items(_dir) \
453         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
454
455 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
456                              struct snd_ctl_elem_info *uinfo)
457 {
458         unsigned int item_num = uinfo->value.enumerated.item;
459         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
460
461         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
462         uinfo->count = 1;
463         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
464
465         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
466                 item_num = alc_pin_mode_min(dir);
467         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
468         return 0;
469 }
470
471 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
472                             struct snd_ctl_elem_value *ucontrol)
473 {
474         unsigned int i;
475         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
476         hda_nid_t nid = kcontrol->private_value & 0xffff;
477         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
478         long *valp = ucontrol->value.integer.value;
479         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
480                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
481                                                  0x00);
482
483         /* Find enumerated value for current pinctl setting */
484         i = alc_pin_mode_min(dir);
485         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
486                 i++;
487         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
488         return 0;
489 }
490
491 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
492                             struct snd_ctl_elem_value *ucontrol)
493 {
494         signed int change;
495         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
496         hda_nid_t nid = kcontrol->private_value & 0xffff;
497         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
498         long val = *ucontrol->value.integer.value;
499         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
500                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
501                                                  0x00);
502
503         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
504                 val = alc_pin_mode_min(dir);
505
506         change = pinctl != alc_pin_mode_values[val];
507         if (change) {
508                 /* Set pin mode to that requested */
509                 snd_hda_codec_write_cache(codec, nid, 0,
510                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
511                                           alc_pin_mode_values[val]);
512
513                 /* Also enable the retasking pin's input/output as required 
514                  * for the requested pin mode.  Enum values of 2 or less are
515                  * input modes.
516                  *
517                  * Dynamically switching the input/output buffers probably
518                  * reduces noise slightly (particularly on input) so we'll
519                  * do it.  However, having both input and output buffers
520                  * enabled simultaneously doesn't seem to be problematic if
521                  * this turns out to be necessary in the future.
522                  */
523                 if (val <= 2) {
524                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
525                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
526                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
527                                                  HDA_AMP_MUTE, 0);
528                 } else {
529                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
530                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
531                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
532                                                  HDA_AMP_MUTE, 0);
533                 }
534         }
535         return change;
536 }
537
538 #define ALC_PIN_MODE(xname, nid, dir) \
539         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
540           .info = alc_pin_mode_info, \
541           .get = alc_pin_mode_get, \
542           .put = alc_pin_mode_put, \
543           .private_value = nid | (dir<<16) }
544
545 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
546  * together using a mask with more than one bit set.  This control is
547  * currently used only by the ALC260 test model.  At this stage they are not
548  * needed for any "production" models.
549  */
550 #ifdef CONFIG_SND_DEBUG
551 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
552
553 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
554                              struct snd_ctl_elem_value *ucontrol)
555 {
556         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
557         hda_nid_t nid = kcontrol->private_value & 0xffff;
558         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
559         long *valp = ucontrol->value.integer.value;
560         unsigned int val = snd_hda_codec_read(codec, nid, 0,
561                                               AC_VERB_GET_GPIO_DATA, 0x00);
562
563         *valp = (val & mask) != 0;
564         return 0;
565 }
566 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
567                              struct snd_ctl_elem_value *ucontrol)
568 {
569         signed int change;
570         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
571         hda_nid_t nid = kcontrol->private_value & 0xffff;
572         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
573         long val = *ucontrol->value.integer.value;
574         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
575                                                     AC_VERB_GET_GPIO_DATA,
576                                                     0x00);
577
578         /* Set/unset the masked GPIO bit(s) as needed */
579         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
580         if (val == 0)
581                 gpio_data &= ~mask;
582         else
583                 gpio_data |= mask;
584         snd_hda_codec_write_cache(codec, nid, 0,
585                                   AC_VERB_SET_GPIO_DATA, gpio_data);
586
587         return change;
588 }
589 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
590         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
591           .info = alc_gpio_data_info, \
592           .get = alc_gpio_data_get, \
593           .put = alc_gpio_data_put, \
594           .private_value = nid | (mask<<16) }
595 #endif   /* CONFIG_SND_DEBUG */
596
597 /* A switch control to allow the enabling of the digital IO pins on the
598  * ALC260.  This is incredibly simplistic; the intention of this control is
599  * to provide something in the test model allowing digital outputs to be
600  * identified if present.  If models are found which can utilise these
601  * outputs a more complete mixer control can be devised for those models if
602  * necessary.
603  */
604 #ifdef CONFIG_SND_DEBUG
605 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
606
607 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
608                               struct snd_ctl_elem_value *ucontrol)
609 {
610         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
611         hda_nid_t nid = kcontrol->private_value & 0xffff;
612         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
613         long *valp = ucontrol->value.integer.value;
614         unsigned int val = snd_hda_codec_read(codec, nid, 0,
615                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
616
617         *valp = (val & mask) != 0;
618         return 0;
619 }
620 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
621                               struct snd_ctl_elem_value *ucontrol)
622 {
623         signed int change;
624         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
625         hda_nid_t nid = kcontrol->private_value & 0xffff;
626         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
627         long val = *ucontrol->value.integer.value;
628         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
629                                                     AC_VERB_GET_DIGI_CONVERT_1,
630                                                     0x00);
631
632         /* Set/unset the masked control bit(s) as needed */
633         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
634         if (val==0)
635                 ctrl_data &= ~mask;
636         else
637                 ctrl_data |= mask;
638         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
639                                   ctrl_data);
640
641         return change;
642 }
643 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
644         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
645           .info = alc_spdif_ctrl_info, \
646           .get = alc_spdif_ctrl_get, \
647           .put = alc_spdif_ctrl_put, \
648           .private_value = nid | (mask<<16) }
649 #endif   /* CONFIG_SND_DEBUG */
650
651 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
652  * Again, this is only used in the ALC26x test models to help identify when
653  * the EAPD line must be asserted for features to work.
654  */
655 #ifdef CONFIG_SND_DEBUG
656 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
657
658 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
659                               struct snd_ctl_elem_value *ucontrol)
660 {
661         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
662         hda_nid_t nid = kcontrol->private_value & 0xffff;
663         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
664         long *valp = ucontrol->value.integer.value;
665         unsigned int val = snd_hda_codec_read(codec, nid, 0,
666                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
667
668         *valp = (val & mask) != 0;
669         return 0;
670 }
671
672 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
673                               struct snd_ctl_elem_value *ucontrol)
674 {
675         int change;
676         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
677         hda_nid_t nid = kcontrol->private_value & 0xffff;
678         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
679         long val = *ucontrol->value.integer.value;
680         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
681                                                     AC_VERB_GET_EAPD_BTLENABLE,
682                                                     0x00);
683
684         /* Set/unset the masked control bit(s) as needed */
685         change = (!val ? 0 : mask) != (ctrl_data & mask);
686         if (!val)
687                 ctrl_data &= ~mask;
688         else
689                 ctrl_data |= mask;
690         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
691                                   ctrl_data);
692
693         return change;
694 }
695
696 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
697         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
698           .info = alc_eapd_ctrl_info, \
699           .get = alc_eapd_ctrl_get, \
700           .put = alc_eapd_ctrl_put, \
701           .private_value = nid | (mask<<16) }
702 #endif   /* CONFIG_SND_DEBUG */
703
704 /*
705  * set up from the preset table
706  */
707 static void setup_preset(struct alc_spec *spec,
708                          const struct alc_config_preset *preset)
709 {
710         int i;
711
712         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
713                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
714         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
715              i++)
716                 spec->init_verbs[spec->num_init_verbs++] =
717                         preset->init_verbs[i];
718         
719         spec->channel_mode = preset->channel_mode;
720         spec->num_channel_mode = preset->num_channel_mode;
721         spec->need_dac_fix = preset->need_dac_fix;
722
723         spec->multiout.max_channels = spec->channel_mode[0].channels;
724
725         spec->multiout.num_dacs = preset->num_dacs;
726         spec->multiout.dac_nids = preset->dac_nids;
727         spec->multiout.dig_out_nid = preset->dig_out_nid;
728         spec->multiout.hp_nid = preset->hp_nid;
729         
730         spec->num_mux_defs = preset->num_mux_defs;
731         if (!spec->num_mux_defs)
732                 spec->num_mux_defs = 1;
733         spec->input_mux = preset->input_mux;
734
735         spec->num_adc_nids = preset->num_adc_nids;
736         spec->adc_nids = preset->adc_nids;
737         spec->capsrc_nids = preset->capsrc_nids;
738         spec->dig_in_nid = preset->dig_in_nid;
739
740         spec->unsol_event = preset->unsol_event;
741         spec->init_hook = preset->init_hook;
742 #ifdef CONFIG_SND_HDA_POWER_SAVE
743         spec->loopback.amplist = preset->loopbacks;
744 #endif
745 }
746
747 /* Enable GPIO mask and set output */
748 static struct hda_verb alc_gpio1_init_verbs[] = {
749         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
750         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
751         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
752         { }
753 };
754
755 static struct hda_verb alc_gpio2_init_verbs[] = {
756         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
757         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
758         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
759         { }
760 };
761
762 static struct hda_verb alc_gpio3_init_verbs[] = {
763         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
764         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
765         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
766         { }
767 };
768
769 /*
770  * Fix hardware PLL issue
771  * On some codecs, the analog PLL gating control must be off while
772  * the default value is 1.
773  */
774 static void alc_fix_pll(struct hda_codec *codec)
775 {
776         struct alc_spec *spec = codec->spec;
777         unsigned int val;
778
779         if (!spec->pll_nid)
780                 return;
781         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
782                             spec->pll_coef_idx);
783         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
784                                  AC_VERB_GET_PROC_COEF, 0);
785         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
786                             spec->pll_coef_idx);
787         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
788                             val & ~(1 << spec->pll_coef_bit));
789 }
790
791 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
792                              unsigned int coef_idx, unsigned int coef_bit)
793 {
794         struct alc_spec *spec = codec->spec;
795         spec->pll_nid = nid;
796         spec->pll_coef_idx = coef_idx;
797         spec->pll_coef_bit = coef_bit;
798         alc_fix_pll(codec);
799 }
800
801 static void alc_sku_automute(struct hda_codec *codec)
802 {
803         struct alc_spec *spec = codec->spec;
804         unsigned int present;
805         unsigned int hp_nid = spec->autocfg.hp_pins[0];
806         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
807
808         /* need to execute and sync at first */
809         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
810         present = snd_hda_codec_read(codec, hp_nid, 0,
811                                      AC_VERB_GET_PIN_SENSE, 0);
812         spec->jack_present = (present & 0x80000000) != 0;
813         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
814                             spec->jack_present ? 0 : PIN_OUT);
815 }
816
817 /* unsolicited event for HP jack sensing */
818 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
819 {
820         if (codec->vendor_id == 0x10ec0880)
821                 res >>= 28;
822         else
823                 res >>= 26;
824         if (res != ALC880_HP_EVENT)
825                 return;
826
827         alc_sku_automute(codec);
828 }
829
830 /* additional initialization for ALC888 variants */
831 static void alc888_coef_init(struct hda_codec *codec)
832 {
833         unsigned int tmp;
834
835         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
836         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
837         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
838         if ((tmp & 0xf0) == 2)
839                 /* alc888S-VC */
840                 snd_hda_codec_read(codec, 0x20, 0,
841                                    AC_VERB_SET_PROC_COEF, 0x830);
842          else
843                  /* alc888-VB */
844                  snd_hda_codec_read(codec, 0x20, 0,
845                                     AC_VERB_SET_PROC_COEF, 0x3030);
846 }
847
848 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
849  *      31 ~ 16 :       Manufacture ID
850  *      15 ~ 8  :       SKU ID
851  *      7  ~ 0  :       Assembly ID
852  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
853  */
854 static void alc_subsystem_id(struct hda_codec *codec,
855                              unsigned int porta, unsigned int porte,
856                              unsigned int portd)
857 {
858         unsigned int ass, tmp, i;
859         unsigned nid;
860         struct alc_spec *spec = codec->spec;
861
862         ass = codec->subsystem_id & 0xffff;
863         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
864                 goto do_sku;
865
866         /*      
867          * 31~30        : port conetcivity
868          * 29~21        : reserve
869          * 20           : PCBEEP input
870          * 19~16        : Check sum (15:1)
871          * 15~1         : Custom
872          * 0            : override
873         */
874         nid = 0x1d;
875         if (codec->vendor_id == 0x10ec0260)
876                 nid = 0x17;
877         ass = snd_hda_codec_read(codec, nid, 0,
878                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
879         if (!(ass & 1) && !(ass & 0x100000))
880                 return;
881         if ((ass >> 30) != 1)   /* no physical connection */
882                 return;
883
884         /* check sum */
885         tmp = 0;
886         for (i = 1; i < 16; i++) {
887                 if ((ass >> i) & 1)
888                         tmp++;
889         }
890         if (((ass >> 16) & 0xf) != tmp)
891                 return;
892 do_sku:
893         /*
894          * 0 : override
895          * 1 :  Swap Jack
896          * 2 : 0 --> Desktop, 1 --> Laptop
897          * 3~5 : External Amplifier control
898          * 7~6 : Reserved
899         */
900         tmp = (ass & 0x38) >> 3;        /* external Amp control */
901         switch (tmp) {
902         case 1:
903                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
904                 break;
905         case 3:
906                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
907                 break;
908         case 7:
909                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
910                 break;
911         case 5: /* set EAPD output high */
912                 switch (codec->vendor_id) {
913                 case 0x10ec0260:
914                         snd_hda_codec_write(codec, 0x0f, 0,
915                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
916                         snd_hda_codec_write(codec, 0x10, 0,
917                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
918                         break;
919                 case 0x10ec0262:
920                 case 0x10ec0267:
921                 case 0x10ec0268:
922                 case 0x10ec0269:
923                 case 0x10ec0272:
924                 case 0x10ec0660:
925                 case 0x10ec0662:
926                 case 0x10ec0663:
927                 case 0x10ec0862:
928                 case 0x10ec0889:
929                         snd_hda_codec_write(codec, 0x14, 0,
930                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
931                         snd_hda_codec_write(codec, 0x15, 0,
932                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
933                         break;
934                 }
935                 switch (codec->vendor_id) {
936                 case 0x10ec0260:
937                         snd_hda_codec_write(codec, 0x1a, 0,
938                                             AC_VERB_SET_COEF_INDEX, 7);
939                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
940                                                  AC_VERB_GET_PROC_COEF, 0);
941                         snd_hda_codec_write(codec, 0x1a, 0,
942                                             AC_VERB_SET_COEF_INDEX, 7);
943                         snd_hda_codec_write(codec, 0x1a, 0,
944                                             AC_VERB_SET_PROC_COEF,
945                                             tmp | 0x2010);
946                         break;
947                 case 0x10ec0262:
948                 case 0x10ec0880:
949                 case 0x10ec0882:
950                 case 0x10ec0883:
951                 case 0x10ec0885:
952                 case 0x10ec0887:
953                 case 0x10ec0889:
954                         snd_hda_codec_write(codec, 0x20, 0,
955                                             AC_VERB_SET_COEF_INDEX, 7);
956                         tmp = snd_hda_codec_read(codec, 0x20, 0,
957                                                  AC_VERB_GET_PROC_COEF, 0);
958                         snd_hda_codec_write(codec, 0x20, 0,
959                                             AC_VERB_SET_COEF_INDEX, 7); 
960                         snd_hda_codec_write(codec, 0x20, 0,
961                                             AC_VERB_SET_PROC_COEF,
962                                             tmp | 0x2010);
963                         break;
964                 case 0x10ec0888:
965                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
966                         break;
967                 case 0x10ec0267:
968                 case 0x10ec0268:
969                         snd_hda_codec_write(codec, 0x20, 0,
970                                             AC_VERB_SET_COEF_INDEX, 7);
971                         tmp = snd_hda_codec_read(codec, 0x20, 0,
972                                                  AC_VERB_GET_PROC_COEF, 0);
973                         snd_hda_codec_write(codec, 0x20, 0,
974                                             AC_VERB_SET_COEF_INDEX, 7); 
975                         snd_hda_codec_write(codec, 0x20, 0,
976                                             AC_VERB_SET_PROC_COEF,
977                                             tmp | 0x3000);
978                         break;
979                 }
980         default:
981                 break;
982         }
983         
984         /* is laptop or Desktop and enable the function "Mute internal speaker
985          * when the external headphone out jack is plugged"
986          */
987         if (!(ass & 0x8000))
988                 return;
989         /*
990          * 10~8 : Jack location
991          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
992          * 14~13: Resvered
993          * 15   : 1 --> enable the function "Mute internal speaker
994          *              when the external headphone out jack is plugged"
995          */
996         if (!spec->autocfg.speaker_pins[0]) {
997                 if (spec->autocfg.line_out_pins[0])
998                         spec->autocfg.speaker_pins[0] =
999                                 spec->autocfg.line_out_pins[0];
1000                 else
1001                         return;
1002         }
1003
1004         if (!spec->autocfg.hp_pins[0]) {
1005                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1006                 if (tmp == 0)
1007                         spec->autocfg.hp_pins[0] = porta;
1008                 else if (tmp == 1)
1009                         spec->autocfg.hp_pins[0] = porte;
1010                 else if (tmp == 2)
1011                         spec->autocfg.hp_pins[0] = portd;
1012                 else
1013                         return;
1014         }
1015
1016         snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1017                             AC_VERB_SET_UNSOLICITED_ENABLE,
1018                             AC_USRSP_EN | ALC880_HP_EVENT);
1019         spec->unsol_event = alc_sku_unsol_event;
1020 }
1021
1022 /*
1023  * Fix-up pin default configurations
1024  */
1025
1026 struct alc_pincfg {
1027         hda_nid_t nid;
1028         u32 val;
1029 };
1030
1031 static void alc_fix_pincfg(struct hda_codec *codec,
1032                            const struct snd_pci_quirk *quirk,
1033                            const struct alc_pincfg **pinfix)
1034 {
1035         const struct alc_pincfg *cfg;
1036
1037         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1038         if (!quirk)
1039                 return;
1040
1041         cfg = pinfix[quirk->value];
1042         for (; cfg->nid; cfg++) {
1043                 int i;
1044                 u32 val = cfg->val;
1045                 for (i = 0; i < 4; i++) {
1046                         snd_hda_codec_write(codec, cfg->nid, 0,
1047                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1048                                     val & 0xff);
1049                         val >>= 8;
1050                 }
1051         }
1052 }
1053
1054 /*
1055  * ALC880 3-stack model
1056  *
1057  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1058  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1059  *                 F-Mic = 0x1b, HP = 0x19
1060  */
1061
1062 static hda_nid_t alc880_dac_nids[4] = {
1063         /* front, rear, clfe, rear_surr */
1064         0x02, 0x05, 0x04, 0x03
1065 };
1066
1067 static hda_nid_t alc880_adc_nids[3] = {
1068         /* ADC0-2 */
1069         0x07, 0x08, 0x09,
1070 };
1071
1072 /* The datasheet says the node 0x07 is connected from inputs,
1073  * but it shows zero connection in the real implementation on some devices.
1074  * Note: this is a 915GAV bug, fixed on 915GLV
1075  */
1076 static hda_nid_t alc880_adc_nids_alt[2] = {
1077         /* ADC1-2 */
1078         0x08, 0x09,
1079 };
1080
1081 #define ALC880_DIGOUT_NID       0x06
1082 #define ALC880_DIGIN_NID        0x0a
1083
1084 static struct hda_input_mux alc880_capture_source = {
1085         .num_items = 4,
1086         .items = {
1087                 { "Mic", 0x0 },
1088                 { "Front Mic", 0x3 },
1089                 { "Line", 0x2 },
1090                 { "CD", 0x4 },
1091         },
1092 };
1093
1094 /* channel source setting (2/6 channel selection for 3-stack) */
1095 /* 2ch mode */
1096 static struct hda_verb alc880_threestack_ch2_init[] = {
1097         /* set line-in to input, mute it */
1098         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1099         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1100         /* set mic-in to input vref 80%, mute it */
1101         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1102         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1103         { } /* end */
1104 };
1105
1106 /* 6ch mode */
1107 static struct hda_verb alc880_threestack_ch6_init[] = {
1108         /* set line-in to output, unmute it */
1109         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1110         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1111         /* set mic-in to output, unmute it */
1112         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1113         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1114         { } /* end */
1115 };
1116
1117 static struct hda_channel_mode alc880_threestack_modes[2] = {
1118         { 2, alc880_threestack_ch2_init },
1119         { 6, alc880_threestack_ch6_init },
1120 };
1121
1122 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1123         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1124         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1125         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1126         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1127         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1128         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1129         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1130         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1131         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1132         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1133         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1134         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1135         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1136         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1137         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1138         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1139         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1140         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1141         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1142         {
1143                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1144                 .name = "Channel Mode",
1145                 .info = alc_ch_mode_info,
1146                 .get = alc_ch_mode_get,
1147                 .put = alc_ch_mode_put,
1148         },
1149         { } /* end */
1150 };
1151
1152 /* capture mixer elements */
1153 static struct snd_kcontrol_new alc880_capture_mixer[] = {
1154         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
1155         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
1156         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
1157         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
1158         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
1159         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1160         {
1161                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1162                 /* The multiple "Capture Source" controls confuse alsamixer
1163                  * So call somewhat different..
1164                  */
1165                 /* .name = "Capture Source", */
1166                 .name = "Input Source",
1167                 .count = 3,
1168                 .info = alc_mux_enum_info,
1169                 .get = alc_mux_enum_get,
1170                 .put = alc_mux_enum_put,
1171         },
1172         { } /* end */
1173 };
1174
1175 /* capture mixer elements (in case NID 0x07 not available) */
1176 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1177         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1178         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1179         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1180         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1181         {
1182                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1183                 /* The multiple "Capture Source" controls confuse alsamixer
1184                  * So call somewhat different..
1185                  */
1186                 /* .name = "Capture Source", */
1187                 .name = "Input Source",
1188                 .count = 2,
1189                 .info = alc_mux_enum_info,
1190                 .get = alc_mux_enum_get,
1191                 .put = alc_mux_enum_put,
1192         },
1193         { } /* end */
1194 };
1195
1196
1197
1198 /*
1199  * ALC880 5-stack model
1200  *
1201  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1202  *      Side = 0x02 (0xd)
1203  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1204  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1205  */
1206
1207 /* additional mixers to alc880_three_stack_mixer */
1208 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1209         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1210         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1211         { } /* end */
1212 };
1213
1214 /* channel source setting (6/8 channel selection for 5-stack) */
1215 /* 6ch mode */
1216 static struct hda_verb alc880_fivestack_ch6_init[] = {
1217         /* set line-in to input, mute it */
1218         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1219         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1220         { } /* end */
1221 };
1222
1223 /* 8ch mode */
1224 static struct hda_verb alc880_fivestack_ch8_init[] = {
1225         /* set line-in to output, unmute it */
1226         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1227         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1228         { } /* end */
1229 };
1230
1231 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1232         { 6, alc880_fivestack_ch6_init },
1233         { 8, alc880_fivestack_ch8_init },
1234 };
1235
1236
1237 /*
1238  * ALC880 6-stack model
1239  *
1240  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1241  *      Side = 0x05 (0x0f)
1242  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1243  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1244  */
1245
1246 static hda_nid_t alc880_6st_dac_nids[4] = {
1247         /* front, rear, clfe, rear_surr */
1248         0x02, 0x03, 0x04, 0x05
1249 };
1250
1251 static struct hda_input_mux alc880_6stack_capture_source = {
1252         .num_items = 4,
1253         .items = {
1254                 { "Mic", 0x0 },
1255                 { "Front Mic", 0x1 },
1256                 { "Line", 0x2 },
1257                 { "CD", 0x4 },
1258         },
1259 };
1260
1261 /* fixed 8-channels */
1262 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1263         { 8, NULL },
1264 };
1265
1266 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1267         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1268         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1269         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1270         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1271         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1272         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1273         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1274         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1275         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1276         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1277         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1278         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1279         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1280         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1281         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1282         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1283         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1284         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1285         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1286         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1287         {
1288                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1289                 .name = "Channel Mode",
1290                 .info = alc_ch_mode_info,
1291                 .get = alc_ch_mode_get,
1292                 .put = alc_ch_mode_put,
1293         },
1294         { } /* end */
1295 };
1296
1297
1298 /*
1299  * ALC880 W810 model
1300  *
1301  * W810 has rear IO for:
1302  * Front (DAC 02)
1303  * Surround (DAC 03)
1304  * Center/LFE (DAC 04)
1305  * Digital out (06)
1306  *
1307  * The system also has a pair of internal speakers, and a headphone jack.
1308  * These are both connected to Line2 on the codec, hence to DAC 02.
1309  * 
1310  * There is a variable resistor to control the speaker or headphone
1311  * volume. This is a hardware-only device without a software API.
1312  *
1313  * Plugging headphones in will disable the internal speakers. This is
1314  * implemented in hardware, not via the driver using jack sense. In
1315  * a similar fashion, plugging into the rear socket marked "front" will
1316  * disable both the speakers and headphones.
1317  *
1318  * For input, there's a microphone jack, and an "audio in" jack.
1319  * These may not do anything useful with this driver yet, because I
1320  * haven't setup any initialization verbs for these yet...
1321  */
1322
1323 static hda_nid_t alc880_w810_dac_nids[3] = {
1324         /* front, rear/surround, clfe */
1325         0x02, 0x03, 0x04
1326 };
1327
1328 /* fixed 6 channels */
1329 static struct hda_channel_mode alc880_w810_modes[1] = {
1330         { 6, NULL }
1331 };
1332
1333 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1334 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1335         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1336         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1337         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1338         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1339         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1340         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1341         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1342         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1343         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1344         { } /* end */
1345 };
1346
1347
1348 /*
1349  * Z710V model
1350  *
1351  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1352  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1353  *                 Line = 0x1a
1354  */
1355
1356 static hda_nid_t alc880_z71v_dac_nids[1] = {
1357         0x02
1358 };
1359 #define ALC880_Z71V_HP_DAC      0x03
1360
1361 /* fixed 2 channels */
1362 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1363         { 2, NULL }
1364 };
1365
1366 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1367         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1368         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1369         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1370         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1371         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1372         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1373         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1374         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1375         { } /* end */
1376 };
1377
1378
1379 /*
1380  * ALC880 F1734 model
1381  *
1382  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1383  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1384  */
1385
1386 static hda_nid_t alc880_f1734_dac_nids[1] = {
1387         0x03
1388 };
1389 #define ALC880_F1734_HP_DAC     0x02
1390
1391 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1392         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1393         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1394         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1395         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1396         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1397         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1398         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1399         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1400         { } /* end */
1401 };
1402
1403 static struct hda_input_mux alc880_f1734_capture_source = {
1404         .num_items = 2,
1405         .items = {
1406                 { "Mic", 0x1 },
1407                 { "CD", 0x4 },
1408         },
1409 };
1410
1411
1412 /*
1413  * ALC880 ASUS model
1414  *
1415  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1416  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1417  *  Mic = 0x18, Line = 0x1a
1418  */
1419
1420 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1421 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1422
1423 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1424         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1425         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1426         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1427         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1428         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1429         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1430         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1431         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1432         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1433         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1434         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1435         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1436         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1437         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1438         {
1439                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1440                 .name = "Channel Mode",
1441                 .info = alc_ch_mode_info,
1442                 .get = alc_ch_mode_get,
1443                 .put = alc_ch_mode_put,
1444         },
1445         { } /* end */
1446 };
1447
1448 /*
1449  * ALC880 ASUS W1V model
1450  *
1451  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1452  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1453  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1454  */
1455
1456 /* additional mixers to alc880_asus_mixer */
1457 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1458         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1459         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1460         { } /* end */
1461 };
1462
1463 /* additional mixers to alc880_asus_mixer */
1464 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1465         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1466         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1467         { } /* end */
1468 };
1469
1470 /* TCL S700 */
1471 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1472         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1473         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1474         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1475         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1476         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1477         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1478         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1479         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1480         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1481         {
1482                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1483                 /* The multiple "Capture Source" controls confuse alsamixer
1484                  * So call somewhat different..
1485                  */
1486                 /* .name = "Capture Source", */
1487                 .name = "Input Source",
1488                 .count = 1,
1489                 .info = alc_mux_enum_info,
1490                 .get = alc_mux_enum_get,
1491                 .put = alc_mux_enum_put,
1492         },
1493         { } /* end */
1494 };
1495
1496 /* Uniwill */
1497 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1498         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1499         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1500         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1501         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1502         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1503         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1504         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1505         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1506         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1507         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1508         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1509         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1510         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1511         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1512         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1513         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1514         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1515         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1516         {
1517                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1518                 .name = "Channel Mode",
1519                 .info = alc_ch_mode_info,
1520                 .get = alc_ch_mode_get,
1521                 .put = alc_ch_mode_put,
1522         },
1523         { } /* end */
1524 };
1525
1526 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1527         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1528         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1529         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1530         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1531         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1532         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1533         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1534         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1535         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1536         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1537         { } /* end */
1538 };
1539
1540 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1541         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1542         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1543         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1544         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1545         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1546         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1547         { } /* end */
1548 };
1549
1550 /*
1551  * virtual master controls
1552  */
1553
1554 /*
1555  * slave controls for virtual master
1556  */
1557 static const char *alc_slave_vols[] = {
1558         "Front Playback Volume",
1559         "Surround Playback Volume",
1560         "Center Playback Volume",
1561         "LFE Playback Volume",
1562         "Side Playback Volume",
1563         "Headphone Playback Volume",
1564         "Speaker Playback Volume",
1565         "Mono Playback Volume",
1566         "Line-Out Playback Volume",
1567         NULL,
1568 };
1569
1570 static const char *alc_slave_sws[] = {
1571         "Front Playback Switch",
1572         "Surround Playback Switch",
1573         "Center Playback Switch",
1574         "LFE Playback Switch",
1575         "Side Playback Switch",
1576         "Headphone Playback Switch",
1577         "Speaker Playback Switch",
1578         "Mono Playback Switch",
1579         "IEC958 Playback Switch",
1580         NULL,
1581 };
1582
1583 /*
1584  * build control elements
1585  */
1586 static int alc_build_controls(struct hda_codec *codec)
1587 {
1588         struct alc_spec *spec = codec->spec;
1589         int err;
1590         int i;
1591
1592         for (i = 0; i < spec->num_mixers; i++) {
1593                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1594                 if (err < 0)
1595                         return err;
1596         }
1597
1598         if (spec->multiout.dig_out_nid) {
1599                 err = snd_hda_create_spdif_out_ctls(codec,
1600                                                     spec->multiout.dig_out_nid);
1601                 if (err < 0)
1602                         return err;
1603                 err = snd_hda_create_spdif_share_sw(codec,
1604                                                     &spec->multiout);
1605                 if (err < 0)
1606                         return err;
1607                 spec->multiout.share_spdif = 1;
1608         }
1609         if (spec->dig_in_nid) {
1610                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1611                 if (err < 0)
1612                         return err;
1613         }
1614
1615         /* if we have no master control, let's create it */
1616         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1617                 unsigned int vmaster_tlv[4];
1618                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1619                                         HDA_OUTPUT, vmaster_tlv);
1620                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1621                                           vmaster_tlv, alc_slave_vols);
1622                 if (err < 0)
1623                         return err;
1624         }
1625         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1626                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1627                                           NULL, alc_slave_sws);
1628                 if (err < 0)
1629                         return err;
1630         }
1631
1632         return 0;
1633 }
1634
1635
1636 /*
1637  * initialize the codec volumes, etc
1638  */
1639
1640 /*
1641  * generic initialization of ADC, input mixers and output mixers
1642  */
1643 static struct hda_verb alc880_volume_init_verbs[] = {
1644         /*
1645          * Unmute ADC0-2 and set the default input to mic-in
1646          */
1647         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1648         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1649         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1650         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1651         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1652         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1653
1654         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1655          * mixer widget
1656          * Note: PASD motherboards uses the Line In 2 as the input for front
1657          * panel mic (mic 2)
1658          */
1659         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1660         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1661         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1662         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1663         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1664         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1665         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1666         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1667
1668         /*
1669          * Set up output mixers (0x0c - 0x0f)
1670          */
1671         /* set vol=0 to output mixers */
1672         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1673         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1674         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1675         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1676         /* set up input amps for analog loopback */
1677         /* Amp Indices: DAC = 0, mixer = 1 */
1678         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1679         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1680         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1681         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1682         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1683         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1684         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1685         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1686
1687         { }
1688 };
1689
1690 /*
1691  * 3-stack pin configuration:
1692  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1693  */
1694 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1695         /*
1696          * preset connection lists of input pins
1697          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1698          */
1699         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1700         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1701         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1702
1703         /*
1704          * Set pin mode and muting
1705          */
1706         /* set front pin widgets 0x14 for output */
1707         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1708         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1709         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1710         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1711         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1712         /* Mic2 (as headphone out) for HP output */
1713         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1714         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1715         /* Line In pin widget for input */
1716         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1717         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1718         /* Line2 (as front mic) pin widget for input and vref at 80% */
1719         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1720         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1721         /* CD pin widget for input */
1722         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1723
1724         { }
1725 };
1726
1727 /*
1728  * 5-stack pin configuration:
1729  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1730  * line-in/side = 0x1a, f-mic = 0x1b
1731  */
1732 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1733         /*
1734          * preset connection lists of input pins
1735          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1736          */
1737         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1738         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1739
1740         /*
1741          * Set pin mode and muting
1742          */
1743         /* set pin widgets 0x14-0x17 for output */
1744         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1745         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1746         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1747         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1748         /* unmute pins for output (no gain on this amp) */
1749         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1750         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1751         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1752         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1753
1754         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1755         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1756         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1757         /* Mic2 (as headphone out) for HP output */
1758         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1759         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1760         /* Line In pin widget for input */
1761         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1762         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1763         /* Line2 (as front mic) pin widget for input and vref at 80% */
1764         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1765         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1766         /* CD pin widget for input */
1767         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1768
1769         { }
1770 };
1771
1772 /*
1773  * W810 pin configuration:
1774  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1775  */
1776 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1777         /* hphone/speaker input selector: front DAC */
1778         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1779
1780         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1781         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1782         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1783         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1784         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1785         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1786
1787         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1788         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1789
1790         { }
1791 };
1792
1793 /*
1794  * Z71V pin configuration:
1795  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1796  */
1797 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1798         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1799         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1800         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1801         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1802
1803         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1804         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1805         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1806         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1807
1808         { }
1809 };
1810
1811 /*
1812  * 6-stack pin configuration:
1813  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1814  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1815  */
1816 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1817         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1818
1819         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1820         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1821         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1822         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1823         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1824         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1825         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1826         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1827
1828         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1829         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1830         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1831         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1832         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1833         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1834         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1835         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1836         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1837         
1838         { }
1839 };
1840
1841 /*
1842  * Uniwill pin configuration:
1843  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1844  * line = 0x1a
1845  */
1846 static struct hda_verb alc880_uniwill_init_verbs[] = {
1847         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1848
1849         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1850         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1851         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1852         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1853         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1854         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1855         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1856         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1857         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1858         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1859         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1860         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1861         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1862         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1863
1864         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1865         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1866         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1867         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1868         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1869         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1870         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1871         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1872         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1873
1874         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1875         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1876
1877         { }
1878 };
1879
1880 /*
1881 * Uniwill P53
1882 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 
1883  */
1884 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1885         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1886
1887         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1888         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1889         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1890         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1891         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1892         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1893         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1894         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1895         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1896         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1897         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1898         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1899
1900         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1901         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1902         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1903         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1904         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1905         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1906
1907         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1908         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1909
1910         { }
1911 };
1912
1913 static struct hda_verb alc880_beep_init_verbs[] = {
1914         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1915         { }
1916 };
1917
1918 /* toggle speaker-output according to the hp-jack state */
1919 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1920 {
1921         unsigned int present;
1922         unsigned char bits;
1923
1924         present = snd_hda_codec_read(codec, 0x14, 0,
1925                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1926         bits = present ? HDA_AMP_MUTE : 0;
1927         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1928                                  HDA_AMP_MUTE, bits);
1929         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1930                                  HDA_AMP_MUTE, bits);
1931 }
1932
1933 /* auto-toggle front mic */
1934 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1935 {
1936         unsigned int present;
1937         unsigned char bits;
1938
1939         present = snd_hda_codec_read(codec, 0x18, 0,
1940                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1941         bits = present ? HDA_AMP_MUTE : 0;
1942         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1943 }
1944
1945 static void alc880_uniwill_automute(struct hda_codec *codec)
1946 {
1947         alc880_uniwill_hp_automute(codec);
1948         alc880_uniwill_mic_automute(codec);
1949 }
1950
1951 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1952                                        unsigned int res)
1953 {
1954         /* Looks like the unsol event is incompatible with the standard
1955          * definition.  4bit tag is placed at 28 bit!
1956          */
1957         switch (res >> 28) {
1958         case ALC880_HP_EVENT:
1959                 alc880_uniwill_hp_automute(codec);
1960                 break;
1961         case ALC880_MIC_EVENT:
1962                 alc880_uniwill_mic_automute(codec);
1963                 break;
1964         }
1965 }
1966
1967 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1968 {
1969         unsigned int present;
1970         unsigned char bits;
1971
1972         present = snd_hda_codec_read(codec, 0x14, 0,
1973                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1974         bits = present ? HDA_AMP_MUTE : 0;
1975         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
1976 }
1977
1978 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1979 {
1980         unsigned int present;
1981         
1982         present = snd_hda_codec_read(codec, 0x21, 0,
1983                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1984         present &= HDA_AMP_VOLMASK;
1985         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
1986                                  HDA_AMP_VOLMASK, present);
1987         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
1988                                  HDA_AMP_VOLMASK, present);
1989 }
1990
1991 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1992                                            unsigned int res)
1993 {
1994         /* Looks like the unsol event is incompatible with the standard
1995          * definition.  4bit tag is placed at 28 bit!
1996          */
1997         if ((res >> 28) == ALC880_HP_EVENT)
1998                 alc880_uniwill_p53_hp_automute(codec);
1999         if ((res >> 28) == ALC880_DCVOL_EVENT)
2000                 alc880_uniwill_p53_dcvol_automute(codec);
2001 }
2002
2003 /*
2004  * F1734 pin configuration:
2005  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2006  */
2007 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2008         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2009         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2010         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2011         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2012         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2013
2014         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2015         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2016         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2017         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2018
2019         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2020         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2021         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2022         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2023         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2024         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2025         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2026         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2027         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2028
2029         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2030         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2031
2032         { }
2033 };
2034
2035 /*
2036  * ASUS pin configuration:
2037  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2038  */
2039 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2040         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2041         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2042         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2043         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2044
2045         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2046         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2047         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2048         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2049         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2050         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2051         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2052         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2053
2054         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2055         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2056         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2057         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2058         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2059         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2060         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2061         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2062         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2063         
2064         { }
2065 };
2066
2067 /* Enable GPIO mask and set output */
2068 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2069 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2070
2071 /* Clevo m520g init */
2072 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2073         /* headphone output */
2074         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2075         /* line-out */
2076         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2077         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2078         /* Line-in */
2079         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2080         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2081         /* CD */
2082         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2083         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2084         /* Mic1 (rear panel) */
2085         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2086         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2087         /* Mic2 (front panel) */
2088         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2089         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2090         /* headphone */
2091         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2092         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2093         /* change to EAPD mode */
2094         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2095         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2096
2097         { }
2098 };
2099
2100 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2101         /* change to EAPD mode */
2102         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2103         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2104
2105         /* Headphone output */
2106         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2107         /* Front output*/
2108         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2109         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2110
2111         /* Line In pin widget for input */
2112         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2113         /* CD pin widget for input */
2114         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2115         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2116         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2117
2118         /* change to EAPD mode */
2119         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2120         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2121
2122         { }
2123 };
2124
2125 /*
2126  * LG m1 express dual
2127  *
2128  * Pin assignment:
2129  *   Rear Line-In/Out (blue): 0x14
2130  *   Build-in Mic-In: 0x15
2131  *   Speaker-out: 0x17
2132  *   HP-Out (green): 0x1b
2133  *   Mic-In/Out (red): 0x19
2134  *   SPDIF-Out: 0x1e
2135  */
2136
2137 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2138 static hda_nid_t alc880_lg_dac_nids[3] = {
2139         0x05, 0x02, 0x03
2140 };
2141
2142 /* seems analog CD is not working */
2143 static struct hda_input_mux alc880_lg_capture_source = {
2144         .num_items = 3,
2145         .items = {
2146                 { "Mic", 0x1 },
2147                 { "Line", 0x5 },
2148                 { "Internal Mic", 0x6 },
2149         },
2150 };
2151
2152 /* 2,4,6 channel modes */
2153 static struct hda_verb alc880_lg_ch2_init[] = {
2154         /* set line-in and mic-in to input */
2155         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2156         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2157         { }
2158 };
2159
2160 static struct hda_verb alc880_lg_ch4_init[] = {
2161         /* set line-in to out and mic-in to input */
2162         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2163         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2164         { }
2165 };
2166
2167 static struct hda_verb alc880_lg_ch6_init[] = {
2168         /* set line-in and mic-in to output */
2169         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2170         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2171         { }
2172 };
2173
2174 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2175         { 2, alc880_lg_ch2_init },
2176         { 4, alc880_lg_ch4_init },
2177         { 6, alc880_lg_ch6_init },
2178 };
2179
2180 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2181         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2182         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2183         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2184         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2185         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2186         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2187         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2188         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2189         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2190         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2191         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2192         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2193         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2194         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2195         {
2196                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2197                 .name = "Channel Mode",
2198                 .info = alc_ch_mode_info,
2199                 .get = alc_ch_mode_get,
2200                 .put = alc_ch_mode_put,
2201         },
2202         { } /* end */
2203 };
2204
2205 static struct hda_verb alc880_lg_init_verbs[] = {
2206         /* set capture source to mic-in */
2207         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2208         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2209         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2210         /* mute all amp mixer inputs */
2211         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2212         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2213         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2214         /* line-in to input */
2215         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2216         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2217         /* built-in mic */
2218         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2219         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2220         /* speaker-out */
2221         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2222         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2223         /* mic-in to input */
2224         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2225         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2226         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2227         /* HP-out */
2228         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2229         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2230         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2231         /* jack sense */
2232         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2233         { }
2234 };
2235
2236 /* toggle speaker-output according to the hp-jack state */
2237 static void alc880_lg_automute(struct hda_codec *codec)
2238 {
2239         unsigned int present;
2240         unsigned char bits;
2241
2242         present = snd_hda_codec_read(codec, 0x1b, 0,
2243                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2244         bits = present ? HDA_AMP_MUTE : 0;
2245         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2246                                  HDA_AMP_MUTE, bits);
2247 }
2248
2249 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2250 {
2251         /* Looks like the unsol event is incompatible with the standard
2252          * definition.  4bit tag is placed at 28 bit!
2253          */
2254         if ((res >> 28) == 0x01)
2255                 alc880_lg_automute(codec);
2256 }
2257
2258 /*
2259  * LG LW20
2260  *
2261  * Pin assignment:
2262  *   Speaker-out: 0x14
2263  *   Mic-In: 0x18
2264  *   Built-in Mic-In: 0x19
2265  *   Line-In: 0x1b
2266  *   HP-Out: 0x1a
2267  *   SPDIF-Out: 0x1e
2268  */
2269
2270 static struct hda_input_mux alc880_lg_lw_capture_source = {
2271         .num_items = 3,
2272         .items = {
2273                 { "Mic", 0x0 },
2274                 { "Internal Mic", 0x1 },
2275                 { "Line In", 0x2 },
2276         },
2277 };
2278
2279 #define alc880_lg_lw_modes alc880_threestack_modes
2280
2281 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2282         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2283         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2284         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2285         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2286         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2287         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2288         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2289         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2290         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2291         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2292         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2293         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2294         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2295         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2296         {
2297                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2298                 .name = "Channel Mode",
2299                 .info = alc_ch_mode_info,
2300                 .get = alc_ch_mode_get,
2301                 .put = alc_ch_mode_put,
2302         },
2303         { } /* end */
2304 };
2305
2306 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2307         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2308         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2309         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2310
2311         /* set capture source to mic-in */
2312         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2313         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2314         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2315         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2316         /* speaker-out */
2317         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2318         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2319         /* HP-out */
2320         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2321         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2322         /* mic-in to input */
2323         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2324         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2325         /* built-in mic */
2326         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2327         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2328         /* jack sense */
2329         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2330         { }
2331 };
2332
2333 /* toggle speaker-output according to the hp-jack state */
2334 static void alc880_lg_lw_automute(struct hda_codec *codec)
2335 {
2336         unsigned int present;
2337         unsigned char bits;
2338
2339         present = snd_hda_codec_read(codec, 0x1b, 0,
2340                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2341         bits = present ? HDA_AMP_MUTE : 0;
2342         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2343                                  HDA_AMP_MUTE, bits);
2344 }
2345
2346 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2347 {
2348         /* Looks like the unsol event is incompatible with the standard
2349          * definition.  4bit tag is placed at 28 bit!
2350          */
2351         if ((res >> 28) == 0x01)
2352                 alc880_lg_lw_automute(codec);
2353 }
2354
2355 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2356         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2357         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2358         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2359         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2360         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2361         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2362         { } /* end */
2363 };
2364
2365 static struct hda_input_mux alc880_medion_rim_capture_source = {
2366         .num_items = 2,
2367         .items = {
2368                 { "Mic", 0x0 },
2369                 { "Internal Mic", 0x1 },
2370         },
2371 };
2372
2373 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2374         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2375
2376         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2377         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2378
2379         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2380         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2381         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2382         /* Mic2 (as headphone out) for HP output */
2383         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2384         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2385         /* Internal Speaker */
2386         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2387         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2388
2389         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2390         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2391
2392         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2393         { }
2394 };
2395
2396 /* toggle speaker-output according to the hp-jack state */
2397 static void alc880_medion_rim_automute(struct hda_codec *codec)
2398 {
2399         unsigned int present;
2400         unsigned char bits;
2401
2402         present = snd_hda_codec_read(codec, 0x14, 0,
2403                                      AC_VERB_GET_PIN_SENSE, 0)
2404                 & AC_PINSENSE_PRESENCE;
2405         bits = present ? HDA_AMP_MUTE : 0;
2406         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2407                                  HDA_AMP_MUTE, bits);
2408         if (present)
2409                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2410         else
2411                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2412 }
2413
2414 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2415                                           unsigned int res)
2416 {
2417         /* Looks like the unsol event is incompatible with the standard
2418          * definition.  4bit tag is placed at 28 bit!
2419          */
2420         if ((res >> 28) == ALC880_HP_EVENT)
2421                 alc880_medion_rim_automute(codec);
2422 }
2423
2424 #ifdef CONFIG_SND_HDA_POWER_SAVE
2425 static struct hda_amp_list alc880_loopbacks[] = {
2426         { 0x0b, HDA_INPUT, 0 },
2427         { 0x0b, HDA_INPUT, 1 },
2428         { 0x0b, HDA_INPUT, 2 },
2429         { 0x0b, HDA_INPUT, 3 },
2430         { 0x0b, HDA_INPUT, 4 },
2431         { } /* end */
2432 };
2433
2434 static struct hda_amp_list alc880_lg_loopbacks[] = {
2435         { 0x0b, HDA_INPUT, 1 },
2436         { 0x0b, HDA_INPUT, 6 },
2437         { 0x0b, HDA_INPUT, 7 },
2438         { } /* end */
2439 };
2440 #endif
2441
2442 /*
2443  * Common callbacks
2444  */
2445
2446 static int alc_init(struct hda_codec *codec)
2447 {
2448         struct alc_spec *spec = codec->spec;
2449         unsigned int i;
2450
2451         alc_fix_pll(codec);
2452         if (codec->vendor_id == 0x10ec0888)
2453                 alc888_coef_init(codec);
2454
2455         for (i = 0; i < spec->num_init_verbs; i++)
2456                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2457
2458         if (spec->init_hook)
2459                 spec->init_hook(codec);
2460
2461         return 0;
2462 }
2463
2464 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2465 {
2466         struct alc_spec *spec = codec->spec;
2467
2468         if (spec->unsol_event)
2469                 spec->unsol_event(codec, res);
2470 }
2471
2472 #ifdef CONFIG_SND_HDA_POWER_SAVE
2473 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2474 {
2475         struct alc_spec *spec = codec->spec;
2476         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2477 }
2478 #endif
2479
2480 /*
2481  * Analog playback callbacks
2482  */
2483 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2484                                     struct hda_codec *codec,
2485                                     struct snd_pcm_substream *substream)
2486 {
2487         struct alc_spec *spec = codec->spec;
2488         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2489                                              hinfo);
2490 }
2491
2492 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2493                                        struct hda_codec *codec,
2494                                        unsigned int stream_tag,
2495                                        unsigned int format,
2496                                        struct snd_pcm_substream *substream)
2497 {
2498         struct alc_spec *spec = codec->spec;
2499         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2500                                                 stream_tag, format, substream);
2501 }
2502
2503 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2504                                        struct hda_codec *codec,
2505                                        struct snd_pcm_substream *substream)
2506 {
2507         struct alc_spec *spec = codec->spec;
2508         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2509 }
2510
2511 /*
2512  * Digital out
2513  */
2514 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2515                                         struct hda_codec *codec,
2516                                         struct snd_pcm_substream *substream)
2517 {
2518         struct alc_spec *spec = codec->spec;
2519         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2520 }
2521
2522 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2523                                            struct hda_codec *codec,
2524                                            unsigned int stream_tag,
2525                                            unsigned int format,
2526                                            struct snd_pcm_substream *substream)
2527 {
2528         struct alc_spec *spec = codec->spec;
2529         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2530                                              stream_tag, format, substream);
2531 }
2532
2533 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2534                                          struct hda_codec *codec,
2535                                          struct snd_pcm_substream *substream)
2536 {
2537         struct alc_spec *spec = codec->spec;
2538         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2539 }
2540
2541 /*
2542  * Analog capture
2543  */
2544 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2545                                       struct hda_codec *codec,
2546                                       unsigned int stream_tag,
2547                                       unsigned int format,
2548                                       struct snd_pcm_substream *substream)
2549 {
2550         struct alc_spec *spec = codec->spec;
2551
2552         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2553                                    stream_tag, 0, format);
2554         return 0;
2555 }
2556
2557 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2558                                       struct hda_codec *codec,
2559                                       struct snd_pcm_substream *substream)
2560 {
2561         struct alc_spec *spec = codec->spec;
2562
2563         snd_hda_codec_cleanup_stream(codec,
2564                                      spec->adc_nids[substream->number + 1]);
2565         return 0;
2566 }
2567
2568
2569 /*
2570  */
2571 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2572         .substreams = 1,
2573         .channels_min = 2,
2574         .channels_max = 8,
2575         /* NID is set in alc_build_pcms */
2576         .ops = {
2577                 .open = alc880_playback_pcm_open,
2578                 .prepare = alc880_playback_pcm_prepare,
2579                 .cleanup = alc880_playback_pcm_cleanup
2580         },
2581 };
2582
2583 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2584         .substreams = 1,
2585         .channels_min = 2,
2586         .channels_max = 2,
2587         /* NID is set in alc_build_pcms */
2588 };
2589
2590 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
2591         .substreams = 1,
2592         .channels_min = 2,
2593         .channels_max = 2,
2594         /* NID is set in alc_build_pcms */
2595 };
2596
2597 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2598         .substreams = 2, /* can be overridden */
2599         .channels_min = 2,
2600         .channels_max = 2,
2601         /* NID is set in alc_build_pcms */
2602         .ops = {
2603                 .prepare = alc880_alt_capture_pcm_prepare,
2604                 .cleanup = alc880_alt_capture_pcm_cleanup
2605         },
2606 };
2607
2608 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2609         .substreams = 1,
2610         .channels_min = 2,
2611         .channels_max = 2,
2612         /* NID is set in alc_build_pcms */
2613         .ops = {
2614                 .open = alc880_dig_playback_pcm_open,
2615                 .close = alc880_dig_playback_pcm_close,
2616                 .prepare = alc880_dig_playback_pcm_prepare
2617         },
2618 };
2619
2620 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2621         .substreams = 1,
2622         .channels_min = 2,
2623         .channels_max = 2,
2624         /* NID is set in alc_build_pcms */
2625 };
2626
2627 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2628 static struct hda_pcm_stream alc_pcm_null_stream = {
2629         .substreams = 0,
2630         .channels_min = 0,
2631         .channels_max = 0,
2632 };
2633
2634 static int alc_build_pcms(struct hda_codec *codec)
2635 {
2636         struct alc_spec *spec = codec->spec;
2637         struct hda_pcm *info = spec->pcm_rec;
2638         int i;
2639
2640         codec->num_pcms = 1;
2641         codec->pcm_info = info;
2642
2643         info->name = spec->stream_name_analog;
2644         if (spec->stream_analog_playback) {
2645                 snd_assert(spec->multiout.dac_nids, return -EINVAL);
2646                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2647                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2648         }
2649         if (spec->stream_analog_capture) {
2650                 snd_assert(spec->adc_nids, return -EINVAL);
2651                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2652                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2653         }
2654
2655         if (spec->channel_mode) {
2656                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2657                 for (i = 0; i < spec->num_channel_mode; i++) {
2658                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2659                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2660                         }
2661                 }
2662         }
2663
2664         /* SPDIF for stream index #1 */
2665         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2666                 codec->num_pcms = 2;
2667                 info = spec->pcm_rec + 1;
2668                 info->name = spec->stream_name_digital;
2669                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2670                 if (spec->multiout.dig_out_nid &&
2671                     spec->stream_digital_playback) {
2672                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2673                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2674                 }
2675                 if (spec->dig_in_nid &&
2676                     spec->stream_digital_capture) {
2677                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2678                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2679                 }
2680         }
2681
2682         /* If the use of more than one ADC is requested for the current
2683          * model, configure a second analog capture-only PCM.
2684          */
2685         /* Additional Analaog capture for index #2 */
2686         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
2687             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
2688                 codec->num_pcms = 3;
2689                 info = spec->pcm_rec + 2;
2690                 info->name = spec->stream_name_analog;
2691                 if (spec->alt_dac_nid) {
2692                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2693                                 *spec->stream_analog_alt_playback;
2694                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2695                                 spec->alt_dac_nid;
2696                 } else {
2697                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2698                                 alc_pcm_null_stream;
2699                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2700                 }
2701                 if (spec->num_adc_nids > 1) {
2702                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2703                                 *spec->stream_analog_alt_capture;
2704                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2705                                 spec->adc_nids[1];
2706                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2707                                 spec->num_adc_nids - 1;
2708                 } else {
2709                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2710                                 alc_pcm_null_stream;
2711                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2712                 }
2713         }
2714
2715         return 0;
2716 }
2717
2718 static void alc_free(struct hda_codec *codec)
2719 {
2720         struct alc_spec *spec = codec->spec;
2721         unsigned int i;
2722
2723         if (!spec)
2724                 return;
2725
2726         if (spec->kctl_alloc) {
2727                 for (i = 0; i < spec->num_kctl_used; i++)
2728                         kfree(spec->kctl_alloc[i].name);
2729                 kfree(spec->kctl_alloc);
2730         }
2731         kfree(spec);
2732         codec->spec = NULL; /* to be sure */
2733 }
2734
2735 #ifdef SND_HDA_NEEDS_RESUME
2736 static void store_pin_configs(struct hda_codec *codec)
2737 {
2738         struct alc_spec *spec = codec->spec;
2739         hda_nid_t nid, end_nid;
2740
2741         end_nid = codec->start_nid + codec->num_nodes;
2742         for (nid = codec->start_nid; nid < end_nid; nid++) {
2743                 unsigned int wid_caps = get_wcaps(codec, nid);
2744                 unsigned int wid_type =
2745                         (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2746                 if (wid_type != AC_WID_PIN)
2747                         continue;
2748                 if (spec->num_pins >= ARRAY_SIZE(spec->pin_nids))
2749                         break;
2750                 spec->pin_nids[spec->num_pins] = nid;
2751                 spec->pin_cfgs[spec->num_pins] =
2752                         snd_hda_codec_read(codec, nid, 0,
2753                                            AC_VERB_GET_CONFIG_DEFAULT, 0);
2754                 spec->num_pins++;
2755         }
2756 }
2757
2758 static void resume_pin_configs(struct hda_codec *codec)
2759 {
2760         struct alc_spec *spec = codec->spec;
2761         int i;
2762
2763         for (i = 0; i < spec->num_pins; i++) {
2764                 hda_nid_t pin_nid = spec->pin_nids[i];
2765                 unsigned int pin_config = spec->pin_cfgs[i];
2766                 snd_hda_codec_write(codec, pin_nid, 0,
2767                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2768                                     pin_config & 0x000000ff);
2769                 snd_hda_codec_write(codec, pin_nid, 0,
2770                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2771                                     (pin_config & 0x0000ff00) >> 8);
2772                 snd_hda_codec_write(codec, pin_nid, 0,
2773                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2774                                     (pin_config & 0x00ff0000) >> 16);
2775                 snd_hda_codec_write(codec, pin_nid, 0,
2776                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2777                                     pin_config >> 24);
2778         }
2779 }
2780
2781 static int alc_resume(struct hda_codec *codec)
2782 {
2783         resume_pin_configs(codec);
2784         codec->patch_ops.init(codec);
2785         snd_hda_codec_resume_amp(codec);
2786         snd_hda_codec_resume_cache(codec);
2787         return 0;
2788 }
2789 #else
2790 #define store_pin_configs(codec)
2791 #endif
2792
2793 /*
2794  */
2795 static struct hda_codec_ops alc_patch_ops = {
2796         .build_controls = alc_build_controls,
2797         .build_pcms = alc_build_pcms,
2798         .init = alc_init,
2799         .free = alc_free,
2800         .unsol_event = alc_unsol_event,
2801 #ifdef SND_HDA_NEEDS_RESUME
2802         .resume = alc_resume,
2803 #endif
2804 #ifdef CONFIG_SND_HDA_POWER_SAVE
2805         .check_power_status = alc_check_power_status,
2806 #endif
2807 };
2808
2809
2810 /*
2811  * Test configuration for debugging
2812  *
2813  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2814  * enum controls.
2815  */
2816 #ifdef CONFIG_SND_DEBUG
2817 static hda_nid_t alc880_test_dac_nids[4] = {
2818         0x02, 0x03, 0x04, 0x05
2819 };
2820
2821 static struct hda_input_mux alc880_test_capture_source = {
2822         .num_items = 7,
2823         .items = {
2824                 { "In-1", 0x0 },
2825                 { "In-2", 0x1 },
2826                 { "In-3", 0x2 },
2827                 { "In-4", 0x3 },
2828                 { "CD", 0x4 },
2829                 { "Front", 0x5 },
2830                 { "Surround", 0x6 },
2831         },
2832 };
2833
2834 static struct hda_channel_mode alc880_test_modes[4] = {
2835         { 2, NULL },
2836         { 4, NULL },
2837         { 6, NULL },
2838         { 8, NULL },
2839 };
2840
2841 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2842                                  struct snd_ctl_elem_info *uinfo)
2843 {
2844         static char *texts[] = {
2845                 "N/A", "Line Out", "HP Out",
2846                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2847         };
2848         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2849         uinfo->count = 1;
2850         uinfo->value.enumerated.items = 8;
2851         if (uinfo->value.enumerated.item >= 8)
2852                 uinfo->value.enumerated.item = 7;
2853         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2854         return 0;
2855 }
2856
2857 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2858                                 struct snd_ctl_elem_value *ucontrol)
2859 {
2860         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2861         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2862         unsigned int pin_ctl, item = 0;
2863
2864         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2865                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2866         if (pin_ctl & AC_PINCTL_OUT_EN) {
2867                 if (pin_ctl & AC_PINCTL_HP_EN)
2868                         item = 2;
2869                 else
2870                         item = 1;
2871         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2872                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2873                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2874                 case AC_PINCTL_VREF_50:  item = 4; break;
2875                 case AC_PINCTL_VREF_GRD: item = 5; break;
2876                 case AC_PINCTL_VREF_80:  item = 6; break;
2877                 case AC_PINCTL_VREF_100: item = 7; break;
2878                 }
2879         }
2880         ucontrol->value.enumerated.item[0] = item;
2881         return 0;
2882 }
2883
2884 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2885                                 struct snd_ctl_elem_value *ucontrol)
2886 {
2887         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2888         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2889         static unsigned int ctls[] = {
2890                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2891                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2892                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2893                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2894                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2895                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2896         };
2897         unsigned int old_ctl, new_ctl;
2898
2899         old_ctl = snd_hda_codec_read(codec, nid, 0,
2900                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2901         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2902         if (old_ctl != new_ctl) {
2903                 int val;
2904                 snd_hda_codec_write_cache(codec, nid, 0,
2905                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2906                                           new_ctl);
2907                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2908                         HDA_AMP_MUTE : 0;
2909                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2910                                          HDA_AMP_MUTE, val);
2911                 return 1;
2912         }
2913         return 0;
2914 }
2915
2916 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2917                                  struct snd_ctl_elem_info *uinfo)
2918 {
2919         static char *texts[] = {
2920                 "Front", "Surround", "CLFE", "Side"
2921         };
2922         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2923         uinfo->count = 1;
2924         uinfo->value.enumerated.items = 4;
2925         if (uinfo->value.enumerated.item >= 4)
2926                 uinfo->value.enumerated.item = 3;
2927         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2928         return 0;
2929 }
2930
2931 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2932                                 struct snd_ctl_elem_value *ucontrol)
2933 {
2934         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2935         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2936         unsigned int sel;
2937
2938         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2939         ucontrol->value.enumerated.item[0] = sel & 3;
2940         return 0;
2941 }
2942
2943 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2944                                 struct snd_ctl_elem_value *ucontrol)
2945 {
2946         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2947         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2948         unsigned int sel;
2949
2950         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2951         if (ucontrol->value.enumerated.item[0] != sel) {
2952                 sel = ucontrol->value.enumerated.item[0] & 3;
2953                 snd_hda_codec_write_cache(codec, nid, 0,
2954                                           AC_VERB_SET_CONNECT_SEL, sel);
2955                 return 1;
2956         }
2957         return 0;
2958 }
2959
2960 #define PIN_CTL_TEST(xname,nid) {                       \
2961                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2962                         .name = xname,                 \
2963                         .info = alc_test_pin_ctl_info, \
2964                         .get = alc_test_pin_ctl_get,   \
2965                         .put = alc_test_pin_ctl_put,   \
2966                         .private_value = nid           \
2967                         }
2968
2969 #define PIN_SRC_TEST(xname,nid) {                       \
2970                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2971                         .name = xname,                 \
2972                         .info = alc_test_pin_src_info, \
2973                         .get = alc_test_pin_src_get,   \
2974                         .put = alc_test_pin_src_put,   \
2975                         .private_value = nid           \
2976                         }
2977
2978 static struct snd_kcontrol_new alc880_test_mixer[] = {
2979         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2980         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2981         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2982         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2983         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2984         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2985         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2986         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2987         PIN_CTL_TEST("Front Pin Mode", 0x14),
2988         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2989         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2990         PIN_CTL_TEST("Side Pin Mode", 0x17),
2991         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2992         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2993         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2994         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2995         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2996         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2997         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2998         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2999         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3000         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3001         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3002         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3003         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3004         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3005         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3006         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3007         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3008         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3009         {
3010                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3011                 .name = "Channel Mode",
3012                 .info = alc_ch_mode_info,
3013                 .get = alc_ch_mode_get,
3014                 .put = alc_ch_mode_put,
3015         },
3016         { } /* end */
3017 };
3018
3019 static struct hda_verb alc880_test_init_verbs[] = {
3020         /* Unmute inputs of 0x0c - 0x0f */
3021         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3022         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3023         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3024         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3025         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3026         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3027         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3028         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3029         /* Vol output for 0x0c-0x0f */
3030         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3031         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3032         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3033         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3034         /* Set output pins 0x14-0x17 */
3035         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3036         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3037         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3038         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3039         /* Unmute output pins 0x14-0x17 */
3040         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3041         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3042         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3043         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3044         /* Set input pins 0x18-0x1c */
3045         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3046         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3047         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3048         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3049         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3050         /* Mute input pins 0x18-0x1b */
3051         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3052         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3053         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3054         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3055         /* ADC set up */
3056         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3057         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3058         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3059         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3060         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3061         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3062         /* Analog input/passthru */
3063         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3064         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3065         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3066         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3067         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3068         { }
3069 };
3070 #endif
3071
3072 /*
3073  */
3074
3075 static const char *alc880_models[ALC880_MODEL_LAST] = {
3076         [ALC880_3ST]            = "3stack",
3077         [ALC880_TCL_S700]       = "tcl",
3078         [ALC880_3ST_DIG]        = "3stack-digout",
3079         [ALC880_CLEVO]          = "clevo",
3080         [ALC880_5ST]            = "5stack",
3081         [ALC880_5ST_DIG]        = "5stack-digout",
3082         [ALC880_W810]           = "w810",
3083         [ALC880_Z71V]           = "z71v",
3084         [ALC880_6ST]            = "6stack",
3085         [ALC880_6ST_DIG]        = "6stack-digout",
3086         [ALC880_ASUS]           = "asus",
3087         [ALC880_ASUS_W1V]       = "asus-w1v",
3088         [ALC880_ASUS_DIG]       = "asus-dig",
3089         [ALC880_ASUS_DIG2]      = "asus-dig2",
3090         [ALC880_UNIWILL_DIG]    = "uniwill",
3091         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3092         [ALC880_FUJITSU]        = "fujitsu",
3093         [ALC880_F1734]          = "F1734",
3094         [ALC880_LG]             = "lg",
3095         [ALC880_LG_LW]          = "lg-lw",
3096         [ALC880_MEDION_RIM]     = "medion",
3097 #ifdef CONFIG_SND_DEBUG
3098         [ALC880_TEST]           = "test",
3099 #endif
3100         [ALC880_AUTO]           = "auto",
3101 };
3102
3103 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3104         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3105         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3106         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3107         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3108         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3109         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3110         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3111         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3112         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3113         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3114         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3115         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3116         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3117         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3118         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3119         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3120         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3121         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3122         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3123         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3124         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3125         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3126         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3127         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3128         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3129         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3130         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3131         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3132         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3133         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3134         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3135         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3136         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3137         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3138         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3139         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3140         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3141         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3142         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3143         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3144         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3145         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3146         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3147         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3148         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3149         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3150         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3151         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3152         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3153         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3154         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3155         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3156         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3157         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3158         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3159         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3160         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3161         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3162         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3163         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3164         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3165         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3166         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3167         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3168         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3169         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3170         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3171         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3172         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3173         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3174         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3175         {}
3176 };
3177
3178 /*
3179  * ALC880 codec presets
3180  */
3181 static struct alc_config_preset alc880_presets[] = {
3182         [ALC880_3ST] = {
3183                 .mixers = { alc880_three_stack_mixer },
3184                 .init_verbs = { alc880_volume_init_verbs,
3185                                 alc880_pin_3stack_init_verbs },
3186                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3187                 .dac_nids = alc880_dac_nids,
3188                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3189                 .channel_mode = alc880_threestack_modes,
3190                 .need_dac_fix = 1,
3191                 .input_mux = &alc880_capture_source,
3192         },
3193         [ALC880_3ST_DIG] = {
3194                 .mixers = { alc880_three_stack_mixer },
3195                 .init_verbs = { alc880_volume_init_verbs,
3196                                 alc880_pin_3stack_init_verbs },
3197                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3198                 .dac_nids = alc880_dac_nids,
3199                 .dig_out_nid = ALC880_DIGOUT_NID,
3200                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3201                 .channel_mode = alc880_threestack_modes,
3202                 .need_dac_fix = 1,
3203                 .input_mux = &alc880_capture_source,
3204         },
3205         [ALC880_TCL_S700] = {
3206                 .mixers = { alc880_tcl_s700_mixer },
3207                 .init_verbs = { alc880_volume_init_verbs,
3208                                 alc880_pin_tcl_S700_init_verbs,
3209                                 alc880_gpio2_init_verbs },
3210                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3211                 .dac_nids = alc880_dac_nids,
3212                 .hp_nid = 0x03,
3213                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3214                 .channel_mode = alc880_2_jack_modes,
3215                 .input_mux = &alc880_capture_source,
3216         },
3217         [ALC880_5ST] = {
3218                 .mixers = { alc880_three_stack_mixer,
3219                             alc880_five_stack_mixer},
3220                 .init_verbs = { alc880_volume_init_verbs,
3221                                 alc880_pin_5stack_init_verbs },
3222                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3223                 .dac_nids = alc880_dac_nids,
3224                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3225                 .channel_mode = alc880_fivestack_modes,
3226                 .input_mux = &alc880_capture_source,
3227         },
3228         [ALC880_5ST_DIG] = {
3229                 .mixers = { alc880_three_stack_mixer,
3230                             alc880_five_stack_mixer },
3231                 .init_verbs = { alc880_volume_init_verbs,
3232                                 alc880_pin_5stack_init_verbs },
3233                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3234                 .dac_nids = alc880_dac_nids,
3235                 .dig_out_nid = ALC880_DIGOUT_NID,
3236                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3237                 .channel_mode = alc880_fivestack_modes,
3238                 .input_mux = &alc880_capture_source,
3239         },
3240         [ALC880_6ST] = {
3241                 .mixers = { alc880_six_stack_mixer },
3242                 .init_verbs = { alc880_volume_init_verbs,
3243                                 alc880_pin_6stack_init_verbs },
3244                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3245                 .dac_nids = alc880_6st_dac_nids,
3246                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3247                 .channel_mode = alc880_sixstack_modes,
3248                 .input_mux = &alc880_6stack_capture_source,
3249         },
3250         [ALC880_6ST_DIG] = {
3251                 .mixers = { alc880_six_stack_mixer },
3252                 .init_verbs = { alc880_volume_init_verbs,
3253                                 alc880_pin_6stack_init_verbs },
3254                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3255                 .dac_nids = alc880_6st_dac_nids,
3256                 .dig_out_nid = ALC880_DIGOUT_NID,
3257                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3258                 .channel_mode = alc880_sixstack_modes,
3259                 .input_mux = &alc880_6stack_capture_source,
3260         },
3261         [ALC880_W810] = {
3262                 .mixers = { alc880_w810_base_mixer },
3263                 .init_verbs = { alc880_volume_init_verbs,
3264                                 alc880_pin_w810_init_verbs,
3265                                 alc880_gpio2_init_verbs },
3266                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3267                 .dac_nids = alc880_w810_dac_nids,
3268                 .dig_out_nid = ALC880_DIGOUT_NID,
3269                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3270                 .channel_mode = alc880_w810_modes,
3271                 .input_mux = &alc880_capture_source,
3272         },
3273         [ALC880_Z71V] = {
3274                 .mixers = { alc880_z71v_mixer },
3275                 .init_verbs = { alc880_volume_init_verbs,
3276                                 alc880_pin_z71v_init_verbs },
3277                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3278                 .dac_nids = alc880_z71v_dac_nids,
3279                 .dig_out_nid = ALC880_DIGOUT_NID,
3280                 .hp_nid = 0x03,
3281                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3282                 .channel_mode = alc880_2_jack_modes,
3283                 .input_mux = &alc880_capture_source,
3284         },
3285         [ALC880_F1734] = {
3286                 .mixers = { alc880_f1734_mixer },
3287                 .init_verbs = { alc880_volume_init_verbs,
3288                                 alc880_pin_f1734_init_verbs },
3289                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3290                 .dac_nids = alc880_f1734_dac_nids,
3291                 .hp_nid = 0x02,
3292                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3293                 .channel_mode = alc880_2_jack_modes,
3294                 .input_mux = &alc880_f1734_capture_source,
3295                 .unsol_event = alc880_uniwill_p53_unsol_event,
3296                 .init_hook = alc880_uniwill_p53_hp_automute,
3297         },
3298         [ALC880_ASUS] = {
3299                 .mixers = { alc880_asus_mixer },
3300                 .init_verbs = { alc880_volume_init_verbs,
3301                                 alc880_pin_asus_init_verbs,
3302                                 alc880_gpio1_init_verbs },
3303                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3304                 .dac_nids = alc880_asus_dac_nids,
3305                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3306                 .channel_mode = alc880_asus_modes,
3307                 .need_dac_fix = 1,
3308                 .input_mux = &alc880_capture_source,
3309         },
3310         [ALC880_ASUS_DIG] = {
3311                 .mixers = { alc880_asus_mixer },
3312                 .init_verbs = { alc880_volume_init_verbs,
3313                                 alc880_pin_asus_init_verbs,
3314                                 alc880_gpio1_init_verbs },
3315                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3316                 .dac_nids = alc880_asus_dac_nids,
3317                 .dig_out_nid = ALC880_DIGOUT_NID,
3318                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3319                 .channel_mode = alc880_asus_modes,
3320                 .need_dac_fix = 1,
3321                 .input_mux = &alc880_capture_source,
3322         },
3323         [ALC880_ASUS_DIG2] = {
3324                 .mixers = { alc880_asus_mixer },
3325                 .init_verbs = { alc880_volume_init_verbs,
3326                                 alc880_pin_asus_init_verbs,
3327                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3328                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3329                 .dac_nids = alc880_asus_dac_nids,
3330                 .dig_out_nid = ALC880_DIGOUT_NID,
3331                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3332                 .channel_mode = alc880_asus_modes,
3333                 .need_dac_fix = 1,
3334                 .input_mux = &alc880_capture_source,
3335         },
3336         [ALC880_ASUS_W1V] = {
3337                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3338                 .init_verbs = { alc880_volume_init_verbs,
3339                                 alc880_pin_asus_init_verbs,
3340                                 alc880_gpio1_init_verbs },
3341                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3342                 .dac_nids = alc880_asus_dac_nids,
3343                 .dig_out_nid = ALC880_DIGOUT_NID,
3344                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3345                 .channel_mode = alc880_asus_modes,
3346                 .need_dac_fix = 1,
3347                 .input_mux = &alc880_capture_source,
3348         },
3349         [ALC880_UNIWILL_DIG] = {
3350                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3351                 .init_verbs = { alc880_volume_init_verbs,
3352                                 alc880_pin_asus_init_verbs },
3353                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3354                 .dac_nids = alc880_asus_dac_nids,
3355                 .dig_out_nid = ALC880_DIGOUT_NID,
3356                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3357                 .channel_mode = alc880_asus_modes,
3358                 .need_dac_fix = 1,
3359                 .input_mux = &alc880_capture_source,
3360         },
3361         [ALC880_UNIWILL] = {
3362                 .mixers = { alc880_uniwill_mixer },
3363                 .init_verbs = { alc880_volume_init_verbs,
3364                                 alc880_uniwill_init_verbs },
3365                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3366                 .dac_nids = alc880_asus_dac_nids,
3367                 .dig_out_nid = ALC880_DIGOUT_NID,
3368                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3369                 .channel_mode = alc880_threestack_modes,
3370                 .need_dac_fix = 1,
3371                 .input_mux = &alc880_capture_source,
3372                 .unsol_event = alc880_uniwill_unsol_event,
3373                 .init_hook = alc880_uniwill_automute,
3374         },
3375         [ALC880_UNIWILL_P53] = {
3376                 .mixers = { alc880_uniwill_p53_mixer },
3377                 .init_verbs = { alc880_volume_init_verbs,
3378                                 alc880_uniwill_p53_init_verbs },
3379                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3380                 .dac_nids = alc880_asus_dac_nids,
3381                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3382                 .channel_mode = alc880_threestack_modes,
3383                 .input_mux = &alc880_capture_source,
3384                 .unsol_event = alc880_uniwill_p53_unsol_event,
3385                 .init_hook = alc880_uniwill_p53_hp_automute,
3386         },
3387         [ALC880_FUJITSU] = {
3388                 .mixers = { alc880_fujitsu_mixer,
3389                             alc880_pcbeep_mixer, },
3390                 .init_verbs = { alc880_volume_init_verbs,
3391                                 alc880_uniwill_p53_init_verbs,
3392                                 alc880_beep_init_verbs },
3393                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3394                 .dac_nids = alc880_dac_nids,
3395                 .dig_out_nid = ALC880_DIGOUT_NID,
3396                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3397                 .channel_mode = alc880_2_jack_modes,
3398                 .input_mux = &alc880_capture_source,
3399                 .unsol_event = alc880_uniwill_p53_unsol_event,
3400                 .init_hook = alc880_uniwill_p53_hp_automute,
3401         },
3402         [ALC880_CLEVO] = {
3403                 .mixers = { alc880_three_stack_mixer },
3404                 .init_verbs = { alc880_volume_init_verbs,
3405                                 alc880_pin_clevo_init_verbs },
3406                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3407                 .dac_nids = alc880_dac_nids,
3408                 .hp_nid = 0x03,
3409                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3410                 .channel_mode = alc880_threestack_modes,
3411                 .need_dac_fix = 1,
3412                 .input_mux = &alc880_capture_source,
3413         },
3414         [ALC880_LG] = {
3415                 .mixers = { alc880_lg_mixer },
3416                 .init_verbs = { alc880_volume_init_verbs,
3417                                 alc880_lg_init_verbs },
3418                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3419                 .dac_nids = alc880_lg_dac_nids,
3420                 .dig_out_nid = ALC880_DIGOUT_NID,
3421                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3422                 .channel_mode = alc880_lg_ch_modes,
3423                 .need_dac_fix = 1,
3424                 .input_mux = &alc880_lg_capture_source,
3425                 .unsol_event = alc880_lg_unsol_event,
3426                 .init_hook = alc880_lg_automute,
3427 #ifdef CONFIG_SND_HDA_POWER_SAVE
3428                 .loopbacks = alc880_lg_loopbacks,
3429 #endif
3430         },
3431         [ALC880_LG_LW] = {
3432                 .mixers = { alc880_lg_lw_mixer },
3433                 .init_verbs = { alc880_volume_init_verbs,
3434                                 alc880_lg_lw_init_verbs },
3435                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3436                 .dac_nids = alc880_dac_nids,
3437                 .dig_out_nid = ALC880_DIGOUT_NID,
3438                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3439                 .channel_mode = alc880_lg_lw_modes,
3440                 .input_mux = &alc880_lg_lw_capture_source,
3441                 .unsol_event = alc880_lg_lw_unsol_event,
3442                 .init_hook = alc880_lg_lw_automute,
3443         },
3444         [ALC880_MEDION_RIM] = {
3445                 .mixers = { alc880_medion_rim_mixer },
3446                 .init_verbs = { alc880_volume_init_verbs,
3447                                 alc880_medion_rim_init_verbs,
3448                                 alc_gpio2_init_verbs },
3449                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3450                 .dac_nids = alc880_dac_nids,
3451                 .dig_out_nid = ALC880_DIGOUT_NID,
3452                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3453                 .channel_mode = alc880_2_jack_modes,
3454                 .input_mux = &alc880_medion_rim_capture_source,
3455                 .unsol_event = alc880_medion_rim_unsol_event,
3456                 .init_hook = alc880_medion_rim_automute,
3457         },
3458 #ifdef CONFIG_SND_DEBUG
3459         [ALC880_TEST] = {
3460                 .mixers = { alc880_test_mixer },
3461                 .init_verbs = { alc880_test_init_verbs },
3462                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3463                 .dac_nids = alc880_test_dac_nids,
3464                 .dig_out_nid = ALC880_DIGOUT_NID,
3465                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3466                 .channel_mode = alc880_test_modes,
3467                 .input_mux = &alc880_test_capture_source,
3468         },
3469 #endif
3470 };
3471
3472 /*
3473  * Automatic parse of I/O pins from the BIOS configuration
3474  */
3475
3476 #define NUM_CONTROL_ALLOC       32
3477 #define NUM_VERB_ALLOC          32
3478
3479 enum {
3480         ALC_CTL_WIDGET_VOL,
3481         ALC_CTL_WIDGET_MUTE,
3482         ALC_CTL_BIND_MUTE,
3483 };
3484 static struct snd_kcontrol_new alc880_control_templates[] = {
3485         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3486         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3487         HDA_BIND_MUTE(NULL, 0, 0, 0),
3488 };
3489
3490 /* add dynamic controls */
3491 static int add_control(struct alc_spec *spec, int type, const char *name,
3492                        unsigned long val)
3493 {
3494         struct snd_kcontrol_new *knew;
3495
3496         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
3497                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
3498
3499                 /* array + terminator */
3500                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3501                 if (!knew)
3502                         return -ENOMEM;
3503                 if (spec->kctl_alloc) {
3504                         memcpy(knew, spec->kctl_alloc,
3505                                sizeof(*knew) * spec->num_kctl_alloc);
3506                         kfree(spec->kctl_alloc);
3507                 }
3508                 spec->kctl_alloc = knew;
3509                 spec->num_kctl_alloc = num;
3510         }
3511
3512         knew = &spec->kctl_alloc[spec->num_kctl_used];
3513         *knew = alc880_control_templates[type];
3514         knew->name = kstrdup(name, GFP_KERNEL);
3515         if (!knew->name)
3516                 return -ENOMEM;
3517         knew->private_value = val;
3518         spec->num_kctl_used++;
3519         return 0;
3520 }
3521
3522 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3523 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3524 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3525 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3526 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3527 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3528 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3529 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3530 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3531 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3532 #define ALC880_PIN_CD_NID               0x1c
3533
3534 /* fill in the dac_nids table from the parsed pin configuration */
3535 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3536                                      const struct auto_pin_cfg *cfg)
3537 {
3538         hda_nid_t nid;
3539         int assigned[4];
3540         int i, j;
3541
3542         memset(assigned, 0, sizeof(assigned));
3543         spec->multiout.dac_nids = spec->private_dac_nids;
3544
3545         /* check the pins hardwired to audio widget */
3546         for (i = 0; i < cfg->line_outs; i++) {
3547                 nid = cfg->line_out_pins[i];
3548                 if (alc880_is_fixed_pin(nid)) {
3549                         int idx = alc880_fixed_pin_idx(nid);
3550                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3551                         assigned[idx] = 1;
3552                 }
3553         }
3554         /* left pins can be connect to any audio widget */
3555         for (i = 0; i < cfg->line_outs; i++) {
3556                 nid = cfg->line_out_pins[i];
3557                 if (alc880_is_fixed_pin(nid))
3558                         continue;
3559                 /* search for an empty channel */
3560                 for (j = 0; j < cfg->line_outs; j++) {
3561                         if (!assigned[j]) {
3562                                 spec->multiout.dac_nids[i] =
3563                                         alc880_idx_to_dac(j);
3564                                 assigned[j] = 1;
3565                                 break;
3566                         }
3567                 }
3568         }
3569         spec->multiout.num_dacs = cfg->line_outs;
3570         return 0;
3571 }
3572
3573 /* add playback controls from the parsed DAC table */
3574 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3575                                              const struct auto_pin_cfg *cfg)
3576 {
3577         char name[32];
3578         static const char *chname[4] = {
3579                 "Front", "Surround", NULL /*CLFE*/, "Side"
3580         };
3581         hda_nid_t nid;
3582         int i, err;
3583
3584         for (i = 0; i < cfg->line_outs; i++) {
3585                 if (!spec->multiout.dac_nids[i])
3586                         continue;
3587                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3588                 if (i == 2) {
3589                         /* Center/LFE */
3590                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3591                                           "Center Playback Volume",
3592                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3593                                                               HDA_OUTPUT));
3594                         if (err < 0)
3595                                 return err;
3596                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3597                                           "LFE Playback Volume",
3598                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3599                                                               HDA_OUTPUT));
3600                         if (err < 0)
3601                                 return err;
3602                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3603                                           "Center Playback Switch",
3604                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3605                                                               HDA_INPUT));
3606                         if (err < 0)
3607                                 return err;
3608                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3609                                           "LFE Playback Switch",
3610                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3611                                                               HDA_INPUT));
3612                         if (err < 0)
3613                                 return err;
3614                 } else {
3615                         sprintf(name, "%s Playback Volume", chname[i]);
3616                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3617                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3618                                                               HDA_OUTPUT));
3619                         if (err < 0)
3620                                 return err;
3621                         sprintf(name, "%s Playback Switch", chname[i]);
3622                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3623                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3624                                                               HDA_INPUT));
3625                         if (err < 0)
3626                                 return err;
3627                 }
3628         }
3629         return 0;
3630 }
3631
3632 /* add playback controls for speaker and HP outputs */
3633 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3634                                         const char *pfx)
3635 {
3636         hda_nid_t nid;
3637         int err;
3638         char name[32];
3639
3640         if (!pin)
3641                 return 0;
3642
3643         if (alc880_is_fixed_pin(pin)) {
3644                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3645                 /* specify the DAC as the extra output */
3646                 if (!spec->multiout.hp_nid)
3647                         spec->multiout.hp_nid = nid;
3648                 else
3649                         spec->multiout.extra_out_nid[0] = nid;
3650                 /* control HP volume/switch on the output mixer amp */
3651                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3652                 sprintf(name, "%s Playback Volume", pfx);
3653                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3654                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3655                 if (err < 0)
3656                         return err;
3657                 sprintf(name, "%s Playback Switch", pfx);
3658                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3659                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3660                 if (err < 0)
3661                         return err;
3662         } else if (alc880_is_multi_pin(pin)) {
3663                 /* set manual connection */
3664                 /* we have only a switch on HP-out PIN */
3665                 sprintf(name, "%s Playback Switch", pfx);
3666                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3667                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3668                 if (err < 0)
3669                         return err;
3670         }
3671         return 0;
3672 }
3673
3674 /* create input playback/capture controls for the given pin */
3675 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3676                             const char *ctlname,
3677                             int idx, hda_nid_t mix_nid)
3678 {
3679         char name[32];
3680         int err;
3681
3682         sprintf(name, "%s Playback Volume", ctlname);
3683         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3684                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3685         if (err < 0)
3686                 return err;
3687         sprintf(name, "%s Playback Switch", ctlname);
3688         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3689                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3690         if (err < 0)
3691                 return err;
3692         return 0;
3693 }
3694
3695 /* create playback/capture controls for input pins */
3696 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3697                                                 const struct auto_pin_cfg *cfg)
3698 {
3699         struct hda_input_mux *imux = &spec->private_imux;
3700         int i, err, idx;
3701
3702         for (i = 0; i < AUTO_PIN_LAST; i++) {
3703                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3704                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3705                         err = new_analog_input(spec, cfg->input_pins[i],
3706                                                auto_pin_cfg_labels[i],
3707                                                idx, 0x0b);
3708                         if (err < 0)
3709                                 return err;
3710                         imux->items[imux->num_items].label =
3711                                 auto_pin_cfg_labels[i];
3712                         imux->items[imux->num_items].index =
3713                                 alc880_input_pin_idx(cfg->input_pins[i]);
3714                         imux->num_items++;
3715                 }
3716         }
3717         return 0;
3718 }
3719
3720 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3721                                unsigned int pin_type)
3722 {
3723         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3724                             pin_type);
3725         /* unmute pin */
3726         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3727                             AMP_OUT_UNMUTE);
3728 }
3729
3730 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3731                                               hda_nid_t nid, int pin_type,
3732                                               int dac_idx)
3733 {
3734         alc_set_pin_output(codec, nid, pin_type);
3735         /* need the manual connection? */
3736         if (alc880_is_multi_pin(nid)) {
3737                 struct alc_spec *spec = codec->spec;
3738                 int idx = alc880_multi_pin_idx(nid);
3739                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3740                                     AC_VERB_SET_CONNECT_SEL,
3741                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3742         }
3743 }
3744
3745 static int get_pin_type(int line_out_type)
3746 {
3747         if (line_out_type == AUTO_PIN_HP_OUT)
3748                 return PIN_HP;
3749         else
3750                 return PIN_OUT;
3751 }
3752
3753 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3754 {
3755         struct alc_spec *spec = codec->spec;
3756         int i;
3757         
3758         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3759         for (i = 0; i < spec->autocfg.line_outs; i++) {
3760                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3761                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3762                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3763         }
3764 }
3765
3766 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3767 {
3768         struct alc_spec *spec = codec->spec;
3769         hda_nid_t pin;
3770
3771         pin = spec->autocfg.speaker_pins[0];
3772         if (pin) /* connect to front */
3773                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3774         pin = spec->autocfg.hp_pins[0];
3775         if (pin) /* connect to front */
3776                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3777 }
3778
3779 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3780 {
3781         struct alc_spec *spec = codec->spec;
3782         int i;
3783
3784         for (i = 0; i < AUTO_PIN_LAST; i++) {
3785                 hda_nid_t nid = spec->autocfg.input_pins[i];
3786                 if (alc880_is_input_pin(nid)) {
3787                         snd_hda_codec_write(codec, nid, 0,
3788                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3789                                             i <= AUTO_PIN_FRONT_MIC ?
3790                                             PIN_VREF80 : PIN_IN);
3791                         if (nid != ALC880_PIN_CD_NID)
3792                                 snd_hda_codec_write(codec, nid, 0,
3793                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3794                                                     AMP_OUT_MUTE);
3795                 }
3796         }
3797 }
3798
3799 /* parse the BIOS configuration and set up the alc_spec */
3800 /* return 1 if successful, 0 if the proper config is not found,
3801  * or a negative error code
3802  */
3803 static int alc880_parse_auto_config(struct hda_codec *codec)
3804 {
3805         struct alc_spec *spec = codec->spec;
3806         int err;
3807         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3808
3809         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3810                                            alc880_ignore);
3811         if (err < 0)
3812                 return err;
3813         if (!spec->autocfg.line_outs)
3814                 return 0; /* can't find valid BIOS pin config */
3815
3816         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3817         if (err < 0)
3818                 return err;
3819         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3820         if (err < 0)
3821                 return err;
3822         err = alc880_auto_create_extra_out(spec,
3823                                            spec->autocfg.speaker_pins[0],
3824                                            "Speaker");
3825         if (err < 0)
3826                 return err;
3827         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3828                                            "Headphone");
3829         if (err < 0)
3830                 return err;
3831         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3832         if (err < 0)
3833                 return err;
3834
3835         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3836
3837         if (spec->autocfg.dig_out_pin)
3838                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3839         if (spec->autocfg.dig_in_pin)
3840                 spec->dig_in_nid = ALC880_DIGIN_NID;
3841
3842         if (spec->kctl_alloc)
3843                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3844
3845         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3846
3847         spec->num_mux_defs = 1;
3848         spec->input_mux = &spec->private_imux;
3849
3850         store_pin_configs(codec);
3851         return 1;
3852 }
3853
3854 /* additional initialization for auto-configuration model */
3855 static void alc880_auto_init(struct hda_codec *codec)
3856 {
3857         struct alc_spec *spec = codec->spec;
3858         alc880_auto_init_multi_out(codec);
3859         alc880_auto_init_extra_out(codec);
3860         alc880_auto_init_analog_input(codec);
3861         if (spec->unsol_event)
3862                 alc_sku_automute(codec);
3863 }
3864
3865 /*
3866  * OK, here we have finally the patch for ALC880
3867  */
3868
3869 static int patch_alc880(struct hda_codec *codec)
3870 {
3871         struct alc_spec *spec;
3872         int board_config;
3873         int err;
3874
3875         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3876         if (spec == NULL)
3877                 return -ENOMEM;
3878
3879         codec->spec = spec;
3880
3881         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3882                                                   alc880_models,
3883                                                   alc880_cfg_tbl);
3884         if (board_config < 0) {
3885                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3886                        "trying auto-probe from BIOS...\n");
3887                 board_config = ALC880_AUTO;
3888         }
3889
3890         if (board_config == ALC880_AUTO) {
3891                 /* automatic parse from the BIOS config */
3892                 err = alc880_parse_auto_config(codec);
3893                 if (err < 0) {
3894                         alc_free(codec);
3895                         return err;
3896                 } else if (!err) {
3897                         printk(KERN_INFO
3898                                "hda_codec: Cannot set up configuration "
3899                                "from BIOS.  Using 3-stack mode...\n");
3900                         board_config = ALC880_3ST;
3901                 }
3902         }
3903
3904         if (board_config != ALC880_AUTO)
3905                 setup_preset(spec, &alc880_presets[board_config]);
3906
3907         spec->stream_name_analog = "ALC880 Analog";
3908         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3909         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3910         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
3911
3912         spec->stream_name_digital = "ALC880 Digital";
3913         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3914         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3915
3916         if (!spec->adc_nids && spec->input_mux) {
3917                 /* check whether NID 0x07 is valid */
3918                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3919                 /* get type */
3920                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3921                 if (wcap != AC_WID_AUD_IN) {
3922                         spec->adc_nids = alc880_adc_nids_alt;
3923                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3924                         spec->mixers[spec->num_mixers] =
3925                                 alc880_capture_alt_mixer;
3926                         spec->num_mixers++;
3927                 } else {
3928                         spec->adc_nids = alc880_adc_nids;
3929                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3930                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3931                         spec->num_mixers++;
3932                 }
3933         }
3934
3935         spec->vmaster_nid = 0x0c;
3936
3937         codec->patch_ops = alc_patch_ops;
3938         if (board_config == ALC880_AUTO)
3939                 spec->init_hook = alc880_auto_init;
3940 #ifdef CONFIG_SND_HDA_POWER_SAVE
3941         if (!spec->loopback.amplist)
3942                 spec->loopback.amplist = alc880_loopbacks;
3943 #endif
3944
3945         return 0;
3946 }
3947
3948
3949 /*
3950  * ALC260 support
3951  */
3952
3953 static hda_nid_t alc260_dac_nids[1] = {
3954         /* front */
3955         0x02,
3956 };
3957
3958 static hda_nid_t alc260_adc_nids[1] = {
3959         /* ADC0 */
3960         0x04,
3961 };
3962
3963 static hda_nid_t alc260_adc_nids_alt[1] = {
3964         /* ADC1 */
3965         0x05,
3966 };
3967
3968 static hda_nid_t alc260_hp_adc_nids[2] = {
3969         /* ADC1, 0 */
3970         0x05, 0x04
3971 };
3972
3973 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3974  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3975  */
3976 static hda_nid_t alc260_dual_adc_nids[2] = {
3977         /* ADC0, ADC1 */
3978         0x04, 0x05
3979 };
3980
3981 #define ALC260_DIGOUT_NID       0x03
3982 #define ALC260_DIGIN_NID        0x06
3983
3984 static struct hda_input_mux alc260_capture_source = {
3985         .num_items = 4,
3986         .items = {
3987                 { "Mic", 0x0 },
3988                 { "Front Mic", 0x1 },
3989                 { "Line", 0x2 },
3990                 { "CD", 0x4 },
3991         },
3992 };
3993
3994 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3995  * headphone jack and the internal CD lines since these are the only pins at
3996  * which audio can appear.  For flexibility, also allow the option of
3997  * recording the mixer output on the second ADC (ADC0 doesn't have a
3998  * connection to the mixer output).
3999  */
4000 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4001         {
4002                 .num_items = 3,
4003                 .items = {
4004                         { "Mic/Line", 0x0 },
4005                         { "CD", 0x4 },
4006                         { "Headphone", 0x2 },
4007                 },
4008         },
4009         {
4010                 .num_items = 4,
4011                 .items = {
4012                         { "Mic/Line", 0x0 },
4013                         { "CD", 0x4 },
4014                         { "Headphone", 0x2 },
4015                         { "Mixer", 0x5 },
4016                 },
4017         },
4018
4019 };
4020
4021 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4022  * the Fujitsu S702x, but jacks are marked differently.
4023  */
4024 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4025         {
4026                 .num_items = 4,
4027                 .items = {
4028                         { "Mic", 0x0 },
4029                         { "Line", 0x2 },
4030                         { "CD", 0x4 },
4031                         { "Headphone", 0x5 },
4032                 },
4033         },
4034         {
4035                 .num_items = 5,
4036                 .items = {
4037                         { "Mic", 0x0 },
4038                         { "Line", 0x2 },
4039                         { "CD", 0x4 },
4040                         { "Headphone", 0x6 },
4041                         { "Mixer", 0x5 },
4042                 },
4043         },
4044 };
4045 /*
4046  * This is just place-holder, so there's something for alc_build_pcms to look
4047  * at when it calculates the maximum number of channels. ALC260 has no mixer
4048  * element which allows changing the channel mode, so the verb list is
4049  * never used.
4050  */
4051 static struct hda_channel_mode alc260_modes[1] = {
4052         { 2, NULL },
4053 };
4054
4055
4056 /* Mixer combinations
4057  *
4058  * basic: base_output + input + pc_beep + capture
4059  * HP: base_output + input + capture_alt
4060  * HP_3013: hp_3013 + input + capture
4061  * fujitsu: fujitsu + capture
4062  * acer: acer + capture
4063  */
4064
4065 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4066         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4067         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4068         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4069         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4070         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4071         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4072         { } /* end */
4073 };
4074
4075 static struct snd_kcontrol_new alc260_input_mixer[] = {
4076         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4077         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4078         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4079         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4080         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4081         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4082         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4083         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4084         { } /* end */
4085 };
4086
4087 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4088         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4089         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4090         { } /* end */
4091 };
4092
4093 /* update HP, line and mono out pins according to the master switch */
4094 static void alc260_hp_master_update(struct hda_codec *codec,
4095                                     hda_nid_t hp, hda_nid_t line,
4096                                     hda_nid_t mono)
4097 {
4098         struct alc_spec *spec = codec->spec;
4099         unsigned int val = spec->master_sw ? PIN_HP : 0;
4100         /* change HP and line-out pins */
4101         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4102                             val);
4103         snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4104                             val);
4105         /* mono (speaker) depending on the HP jack sense */
4106         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4107         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4108                             val);
4109 }
4110
4111 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4112                                    struct snd_ctl_elem_value *ucontrol)
4113 {
4114         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4115         struct alc_spec *spec = codec->spec;
4116         *ucontrol->value.integer.value = spec->master_sw;
4117         return 0;
4118 }
4119
4120 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4121                                    struct snd_ctl_elem_value *ucontrol)
4122 {
4123         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4124         struct alc_spec *spec = codec->spec;
4125         int val = !!*ucontrol->value.integer.value;
4126         hda_nid_t hp, line, mono;
4127
4128         if (val == spec->master_sw)
4129                 return 0;
4130         spec->master_sw = val;
4131         hp = (kcontrol->private_value >> 16) & 0xff;
4132         line = (kcontrol->private_value >> 8) & 0xff;
4133         mono = kcontrol->private_value & 0xff;
4134         alc260_hp_master_update(codec, hp, line, mono);
4135         return 1;
4136 }
4137
4138 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4139         {
4140                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4141                 .name = "Master Playback Switch",
4142                 .info = snd_ctl_boolean_mono_info,
4143                 .get = alc260_hp_master_sw_get,
4144                 .put = alc260_hp_master_sw_put,
4145                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4146         },
4147         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4148         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4149         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4150         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4151         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4152                               HDA_OUTPUT),
4153         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4154         { } /* end */
4155 };
4156
4157 static struct hda_verb alc260_hp_unsol_verbs[] = {
4158         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4159         {},
4160 };
4161
4162 static void alc260_hp_automute(struct hda_codec *codec)
4163 {
4164         struct alc_spec *spec = codec->spec;
4165         unsigned int present;
4166
4167         present = snd_hda_codec_read(codec, 0x10, 0,
4168                                      AC_VERB_GET_PIN_SENSE, 0);
4169         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4170         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4171 }
4172
4173 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4174 {
4175         if ((res >> 26) == ALC880_HP_EVENT)
4176                 alc260_hp_automute(codec);
4177 }
4178
4179 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4180         {
4181                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4182                 .name = "Master Playback Switch",
4183                 .info = snd_ctl_boolean_mono_info,
4184                 .get = alc260_hp_master_sw_get,
4185                 .put = alc260_hp_master_sw_put,
4186                 .private_value = (0x10 << 16) | (0x15 << 8) | 0x11
4187         },
4188         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4189         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4190         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4191         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4192         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4193         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4194         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4195         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4196         { } /* end */
4197 };
4198
4199 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4200         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4201         {},
4202 };
4203
4204 static void alc260_hp_3013_automute(struct hda_codec *codec)
4205 {
4206         struct alc_spec *spec = codec->spec;
4207         unsigned int present;
4208
4209         present = snd_hda_codec_read(codec, 0x15, 0,
4210                                      AC_VERB_GET_PIN_SENSE, 0);
4211         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4212         alc260_hp_master_update(codec, 0x10, 0x15, 0x11);
4213 }
4214
4215 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4216                                        unsigned int res)
4217 {
4218         if ((res >> 26) == ALC880_HP_EVENT)
4219                 alc260_hp_3013_automute(codec);
4220 }
4221
4222 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
4223  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4224  */
4225 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4226         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4227         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4228         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4229         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4230         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4231         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4232         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4233         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4234         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4235         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4236         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4237         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4238         { } /* end */
4239 };
4240
4241 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4242  * versions of the ALC260 don't act on requests to enable mic bias from NID
4243  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4244  * datasheet doesn't mention this restriction.  At this stage it's not clear
4245  * whether this behaviour is intentional or is a hardware bug in chip
4246  * revisions available in early 2006.  Therefore for now allow the
4247  * "Headphone Jack Mode" control to span all choices, but if it turns out
4248  * that the lack of mic bias for this NID is intentional we could change the
4249  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4250  *
4251  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4252  * don't appear to make the mic bias available from the "line" jack, even
4253  * though the NID used for this jack (0x14) can supply it.  The theory is
4254  * that perhaps Acer have included blocking capacitors between the ALC260
4255  * and the output jack.  If this turns out to be the case for all such
4256  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4257  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4258  *
4259  * The C20x Tablet series have a mono internal speaker which is controlled
4260  * via the chip's Mono sum widget and pin complex, so include the necessary
4261  * controls for such models.  On models without a "mono speaker" the control
4262  * won't do anything.
4263  */
4264 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4265         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4266         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4267         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4268         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4269                               HDA_OUTPUT),
4270         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4271                            HDA_INPUT),
4272         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4273         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4274         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4275         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4276         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4277         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4278         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4279         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4280         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4281         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4282         { } /* end */
4283 };
4284
4285 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4286  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4287  */
4288 static struct snd_kcontrol_new alc260_will_mixer[] = {
4289         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4290         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4291         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4292         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4293         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4294         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4295         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4296         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4297         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4298         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4299         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4300         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4301         { } /* end */
4302 };
4303
4304 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4305  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4306  */
4307 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4308         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4309         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4310         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4311         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4312         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4313         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4314         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4315         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4316         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4317         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4318         { } /* end */
4319 };
4320
4321 /* capture mixer elements */
4322 static struct snd_kcontrol_new alc260_capture_mixer[] = {
4323         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
4324         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
4325         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
4326         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
4327         {
4328                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4329                 /* The multiple "Capture Source" controls confuse alsamixer
4330                  * So call somewhat different..
4331                  */
4332                 /* .name = "Capture Source", */
4333                 .name = "Input Source",
4334                 .count = 2,
4335                 .info = alc_mux_enum_info,
4336                 .get = alc_mux_enum_get,
4337                 .put = alc_mux_enum_put,
4338         },
4339         { } /* end */
4340 };
4341
4342 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
4343         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
4344         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
4345         {
4346                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4347                 /* The multiple "Capture Source" controls confuse alsamixer
4348                  * So call somewhat different..
4349                  */
4350                 /* .name = "Capture Source", */
4351                 .name = "Input Source",
4352                 .count = 1,
4353                 .info = alc_mux_enum_info,
4354                 .get = alc_mux_enum_get,
4355                 .put = alc_mux_enum_put,
4356         },
4357         { } /* end */
4358 };
4359
4360 /*
4361  * initialization verbs
4362  */
4363 static struct hda_verb alc260_init_verbs[] = {
4364         /* Line In pin widget for input */
4365         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4366         /* CD pin widget for input */
4367         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4368         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4369         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4370         /* Mic2 (front panel) pin widget for input and vref at 80% */
4371         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4372         /* LINE-2 is used for line-out in rear */
4373         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4374         /* select line-out */
4375         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4376         /* LINE-OUT pin */
4377         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4378         /* enable HP */
4379         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4380         /* enable Mono */
4381         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4382         /* mute capture amp left and right */
4383         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4384         /* set connection select to line in (default select for this ADC) */
4385         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4386         /* mute capture amp left and right */
4387         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4388         /* set connection select to line in (default select for this ADC) */
4389         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4390         /* set vol=0 Line-Out mixer amp left and right */
4391         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4392         /* unmute pin widget amp left and right (no gain on this amp) */
4393         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4394         /* set vol=0 HP mixer amp left and right */
4395         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4396         /* unmute pin widget amp left and right (no gain on this amp) */
4397         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4398         /* set vol=0 Mono mixer amp left and right */
4399         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4400         /* unmute pin widget amp left and right (no gain on this amp) */
4401         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4402         /* unmute LINE-2 out pin */
4403         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4404         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4405          * Line In 2 = 0x03
4406          */
4407         /* mute analog inputs */
4408         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4409         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4410         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4411         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4412         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4413         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4414         /* mute Front out path */
4415         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4416         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4417         /* mute Headphone out path */
4418         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4419         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4420         /* mute Mono out path */
4421         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4422         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4423         { }
4424 };
4425
4426 #if 0 /* should be identical with alc260_init_verbs? */
4427 static struct hda_verb alc260_hp_init_verbs[] = {
4428         /* Headphone and output */
4429         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4430         /* mono output */
4431         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4432         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4433         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4434         /* Mic2 (front panel) pin widget for input and vref at 80% */
4435         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4436         /* Line In pin widget for input */
4437         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4438         /* Line-2 pin widget for output */
4439         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4440         /* CD pin widget for input */
4441         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4442         /* unmute amp left and right */
4443         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4444         /* set connection select to line in (default select for this ADC) */
4445         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4446         /* unmute Line-Out mixer amp left and right (volume = 0) */
4447         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4448         /* mute pin widget amp left and right (no gain on this amp) */
4449         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4450         /* unmute HP mixer amp left and right (volume = 0) */
4451         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4452         /* mute pin widget amp left and right (no gain on this amp) */
4453         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4454         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4455          * Line In 2 = 0x03
4456          */
4457         /* mute analog inputs */
4458         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4459         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4460         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4461         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4462         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4463         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4464         /* Unmute Front out path */
4465         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4466         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4467         /* Unmute Headphone out path */
4468         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4469         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4470         /* Unmute Mono out path */
4471         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4472         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4473         { }
4474 };
4475 #endif
4476
4477 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4478         /* Line out and output */
4479         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4480         /* mono output */
4481         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4482         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4483         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4484         /* Mic2 (front panel) pin widget for input and vref at 80% */
4485         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4486         /* Line In pin widget for input */
4487         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4488         /* Headphone pin widget for output */
4489         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4490         /* CD pin widget for input */
4491         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4492         /* unmute amp left and right */
4493         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4494         /* set connection select to line in (default select for this ADC) */
4495         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4496         /* unmute Line-Out mixer amp left and right (volume = 0) */
4497         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4498         /* mute pin widget amp left and right (no gain on this amp) */
4499         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4500         /* unmute HP mixer amp left and right (volume = 0) */
4501         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4502         /* mute pin widget amp left and right (no gain on this amp) */
4503         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4504         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4505          * Line In 2 = 0x03
4506          */
4507         /* mute analog inputs */
4508         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4509         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4510         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4511         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4512         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4513         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4514         /* Unmute Front out path */
4515         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4516         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4517         /* Unmute Headphone out path */
4518         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4519         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4520         /* Unmute Mono out path */
4521         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4522         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4523         { }
4524 };
4525
4526 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4527  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4528  * audio = 0x16, internal speaker = 0x10.
4529  */
4530 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4531         /* Disable all GPIOs */
4532         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4533         /* Internal speaker is connected to headphone pin */
4534         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4535         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4536         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4537         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4538         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4539         /* Ensure all other unused pins are disabled and muted. */
4540         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4541         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4542         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4543         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4544         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4545         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4546         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4547         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4548
4549         /* Disable digital (SPDIF) pins */
4550         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4551         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4552
4553         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 
4554          * when acting as an output.
4555          */
4556         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4557
4558         /* Start with output sum widgets muted and their output gains at min */
4559         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4560         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4561         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4562         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4563         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4564         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4565         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4566         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4567         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4568
4569         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4570         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4571         /* Unmute Line1 pin widget output buffer since it starts as an output.
4572          * If the pin mode is changed by the user the pin mode control will
4573          * take care of enabling the pin's input/output buffers as needed.
4574          * Therefore there's no need to enable the input buffer at this
4575          * stage.
4576          */
4577         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4578         /* Unmute input buffer of pin widget used for Line-in (no equiv 
4579          * mixer ctrl)
4580          */
4581         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4582
4583         /* Mute capture amp left and right */
4584         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4585         /* Set ADC connection select to match default mixer setting - line 
4586          * in (on mic1 pin)
4587          */
4588         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4589
4590         /* Do the same for the second ADC: mute capture input amp and
4591          * set ADC connection to line in (on mic1 pin)
4592          */
4593         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4594         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4595
4596         /* Mute all inputs to mixer widget (even unconnected ones) */
4597         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4598         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4599         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4600         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4601         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4602         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4603         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4604         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4605
4606         { }
4607 };
4608
4609 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4610  * similar laptops (adapted from Fujitsu init verbs).
4611  */
4612 static struct hda_verb alc260_acer_init_verbs[] = {
4613         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4614          * the headphone jack.  Turn this on and rely on the standard mute
4615          * methods whenever the user wants to turn these outputs off.
4616          */
4617         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4618         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4619         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4620         /* Internal speaker/Headphone jack is connected to Line-out pin */
4621         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4622         /* Internal microphone/Mic jack is connected to Mic1 pin */
4623         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4624         /* Line In jack is connected to Line1 pin */
4625         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4626         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4627         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4628         /* Ensure all other unused pins are disabled and muted. */
4629         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4630         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4631         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4632         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4633         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4634         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4635         /* Disable digital (SPDIF) pins */
4636         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4637         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4638
4639         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 
4640          * bus when acting as outputs.
4641          */
4642         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4643         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4644
4645         /* Start with output sum widgets muted and their output gains at min */
4646         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4647         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4648         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4649         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4650         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4651         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4652         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4653         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4654         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4655
4656         /* Unmute Line-out pin widget amp left and right
4657          * (no equiv mixer ctrl)
4658          */
4659         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4660         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4661         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4662         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4663          * inputs. If the pin mode is changed by the user the pin mode control
4664          * will take care of enabling the pin's input/output buffers as needed.
4665          * Therefore there's no need to enable the input buffer at this
4666          * stage.
4667          */
4668         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4669         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4670
4671         /* Mute capture amp left and right */
4672         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4673         /* Set ADC connection select to match default mixer setting - mic
4674          * (on mic1 pin)
4675          */
4676         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4677
4678         /* Do similar with the second ADC: mute capture input amp and
4679          * set ADC connection to mic to match ALSA's default state.
4680          */
4681         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4682         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4683
4684         /* Mute all inputs to mixer widget (even unconnected ones) */
4685         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4686         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4687         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4688         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4689         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4690         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4691         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4692         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4693
4694         { }
4695 };
4696
4697 static struct hda_verb alc260_will_verbs[] = {
4698         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4699         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4700         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4701         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4702         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4703         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4704         {}
4705 };
4706
4707 static struct hda_verb alc260_replacer_672v_verbs[] = {
4708         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4709         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4710         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4711
4712         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4713         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4714         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4715
4716         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4717         {}
4718 };
4719
4720 /* toggle speaker-output according to the hp-jack state */
4721 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4722 {
4723         unsigned int present;
4724
4725         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4726         present = snd_hda_codec_read(codec, 0x0f, 0,
4727                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4728         if (present) {
4729                 snd_hda_codec_write_cache(codec, 0x01, 0,
4730                                           AC_VERB_SET_GPIO_DATA, 1);
4731                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4732                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4733                                           PIN_HP);
4734         } else {
4735                 snd_hda_codec_write_cache(codec, 0x01, 0,
4736                                           AC_VERB_SET_GPIO_DATA, 0);
4737                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4738                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4739                                           PIN_OUT);
4740         }
4741 }
4742
4743 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4744                                        unsigned int res)
4745 {
4746         if ((res >> 26) == ALC880_HP_EVENT)
4747                 alc260_replacer_672v_automute(codec);
4748 }
4749
4750 /* Test configuration for debugging, modelled after the ALC880 test
4751  * configuration.
4752  */
4753 #ifdef CONFIG_SND_DEBUG
4754 static hda_nid_t alc260_test_dac_nids[1] = {
4755         0x02,
4756 };
4757 static hda_nid_t alc260_test_adc_nids[2] = {
4758         0x04, 0x05,
4759 };
4760 /* For testing the ALC260, each input MUX needs its own definition since
4761  * the signal assignments are different.  This assumes that the first ADC 
4762  * is NID 0x04.
4763  */
4764 static struct hda_input_mux alc260_test_capture_sources[2] = {
4765         {
4766                 .num_items = 7,
4767                 .items = {
4768                         { "MIC1 pin", 0x0 },
4769                         { "MIC2 pin", 0x1 },
4770                         { "LINE1 pin", 0x2 },
4771                         { "LINE2 pin", 0x3 },
4772                         { "CD pin", 0x4 },
4773                         { "LINE-OUT pin", 0x5 },
4774                         { "HP-OUT pin", 0x6 },
4775                 },
4776         },
4777         {
4778                 .num_items = 8,
4779                 .items = {
4780                         { "MIC1 pin", 0x0 },
4781                         { "MIC2 pin", 0x1 },
4782                         { "LINE1 pin", 0x2 },
4783                         { "LINE2 pin", 0x3 },
4784                         { "CD pin", 0x4 },
4785                         { "Mixer", 0x5 },
4786                         { "LINE-OUT pin", 0x6 },
4787                         { "HP-OUT pin", 0x7 },
4788                 },
4789         },
4790 };
4791 static struct snd_kcontrol_new alc260_test_mixer[] = {
4792         /* Output driver widgets */
4793         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4794         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4795         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4796         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4797         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4798         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4799
4800         /* Modes for retasking pin widgets
4801          * Note: the ALC260 doesn't seem to act on requests to enable mic
4802          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4803          * mention this restriction.  At this stage it's not clear whether
4804          * this behaviour is intentional or is a hardware bug in chip
4805          * revisions available at least up until early 2006.  Therefore for
4806          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4807          * choices, but if it turns out that the lack of mic bias for these
4808          * NIDs is intentional we could change their modes from
4809          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4810          */
4811         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4812         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4813         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4814         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4815         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4816         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4817
4818         /* Loopback mixer controls */
4819         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4820         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4821         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4822         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4823         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4824         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4825         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4826         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4827         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4828         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4829         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4830         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4831         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4832         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4833         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4834         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4835
4836         /* Controls for GPIO pins, assuming they are configured as outputs */
4837         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4838         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4839         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4840         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4841
4842         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4843          * is ambigious as to which NID is which; testing on laptops which
4844          * make this output available should provide clarification. 
4845          */
4846         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4847         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4848
4849         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
4850          * this output to turn on an external amplifier.
4851          */
4852         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
4853         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
4854
4855         { } /* end */
4856 };
4857 static struct hda_verb alc260_test_init_verbs[] = {
4858         /* Enable all GPIOs as outputs with an initial value of 0 */
4859         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4860         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4861         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4862
4863         /* Enable retasking pins as output, initially without power amp */
4864         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4865         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4866         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4867         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4868         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4869         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4870
4871         /* Disable digital (SPDIF) pins initially, but users can enable
4872          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4873          * payload also sets the generation to 0, output to be in "consumer"
4874          * PCM format, copyright asserted, no pre-emphasis and no validity
4875          * control.
4876          */
4877         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4878         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4879
4880         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 
4881          * OUT1 sum bus when acting as an output.
4882          */
4883         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4884         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4885         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4886         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4887
4888         /* Start with output sum widgets muted and their output gains at min */
4889         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4890         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4891         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4892         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4893         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4894         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4895         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4896         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4897         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4898
4899         /* Unmute retasking pin widget output buffers since the default
4900          * state appears to be output.  As the pin mode is changed by the
4901          * user the pin mode control will take care of enabling the pin's
4902          * input/output buffers as needed.
4903          */
4904         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4905         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4906         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4907         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4908         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4909         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4910         /* Also unmute the mono-out pin widget */
4911         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4912
4913         /* Mute capture amp left and right */
4914         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4915         /* Set ADC connection select to match default mixer setting (mic1
4916          * pin)
4917          */
4918         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4919
4920         /* Do the same for the second ADC: mute capture input amp and
4921          * set ADC connection to mic1 pin
4922          */
4923         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4924         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4925
4926         /* Mute all inputs to mixer widget (even unconnected ones) */
4927         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4928         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4929         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4930         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4931         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4932         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4933         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4934         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4935
4936         { }
4937 };
4938 #endif
4939
4940 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
4941 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
4942
4943 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4944 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4945
4946 /*
4947  * for BIOS auto-configuration
4948  */
4949
4950 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4951                                         const char *pfx)
4952 {
4953         hda_nid_t nid_vol;
4954         unsigned long vol_val, sw_val;
4955         char name[32];
4956         int err;
4957
4958         if (nid >= 0x0f && nid < 0x11) {
4959                 nid_vol = nid - 0x7;
4960                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4961                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4962         } else if (nid == 0x11) {
4963                 nid_vol = nid - 0x7;
4964                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4965                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4966         } else if (nid >= 0x12 && nid <= 0x15) {
4967                 nid_vol = 0x08;
4968                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4969                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4970         } else
4971                 return 0; /* N/A */
4972         
4973         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4974         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4975         if (err < 0)
4976                 return err;
4977         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4978         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4979         if (err < 0)
4980                 return err;
4981         return 1;
4982 }
4983
4984 /* add playback controls from the parsed DAC table */
4985 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4986                                              const struct auto_pin_cfg *cfg)
4987 {
4988         hda_nid_t nid;
4989         int err;
4990
4991         spec->multiout.num_dacs = 1;
4992         spec->multiout.dac_nids = spec->private_dac_nids;
4993         spec->multiout.dac_nids[0] = 0x02;
4994
4995         nid = cfg->line_out_pins[0];
4996         if (nid) {
4997                 err = alc260_add_playback_controls(spec, nid, "Front");
4998                 if (err < 0)
4999                         return err;
5000         }
5001
5002         nid = cfg->speaker_pins[0];
5003         if (nid) {
5004                 err = alc260_add_playback_controls(spec, nid, "Speaker");
5005                 if (err < 0)
5006                         return err;
5007         }
5008
5009         nid = cfg->hp_pins[0];
5010         if (nid) {
5011                 err = alc260_add_playback_controls(spec, nid, "Headphone");
5012                 if (err < 0)
5013                         return err;
5014         }
5015         return 0;
5016 }
5017
5018 /* create playback/capture controls for input pins */
5019 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5020                                                 const struct auto_pin_cfg *cfg)
5021 {
5022         struct hda_input_mux *imux = &spec->private_imux;
5023         int i, err, idx;
5024
5025         for (i = 0; i < AUTO_PIN_LAST; i++) {
5026                 if (cfg->input_pins[i] >= 0x12) {
5027                         idx = cfg->input_pins[i] - 0x12;
5028                         err = new_analog_input(spec, cfg->input_pins[i],
5029                                                auto_pin_cfg_labels[i], idx,
5030                                                0x07);
5031                         if (err < 0)
5032                                 return err;
5033                         imux->items[imux->num_items].label =
5034                                 auto_pin_cfg_labels[i];
5035                         imux->items[imux->num_items].index = idx;
5036                         imux->num_items++;
5037                 }
5038                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5039                         idx = cfg->input_pins[i] - 0x09;
5040                         err = new_analog_input(spec, cfg->input_pins[i],
5041                                                auto_pin_cfg_labels[i], idx,
5042                                                0x07);
5043                         if (err < 0)
5044                                 return err;
5045                         imux->items[imux->num_items].label =
5046                                 auto_pin_cfg_labels[i];
5047                         imux->items[imux->num_items].index = idx;
5048                         imux->num_items++;
5049                 }
5050         }
5051         return 0;
5052 }
5053
5054 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5055                                               hda_nid_t nid, int pin_type,
5056                                               int sel_idx)
5057 {
5058         alc_set_pin_output(codec, nid, pin_type);
5059         /* need the manual connection? */
5060         if (nid >= 0x12) {
5061                 int idx = nid - 0x12;
5062                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5063                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5064         }
5065 }
5066
5067 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5068 {
5069         struct alc_spec *spec = codec->spec;
5070         hda_nid_t nid;
5071
5072         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5073         nid = spec->autocfg.line_out_pins[0];
5074         if (nid) {
5075                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5076                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5077         }
5078         
5079         nid = spec->autocfg.speaker_pins[0];
5080         if (nid)
5081                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5082
5083         nid = spec->autocfg.hp_pins[0];
5084         if (nid)
5085                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5086 }
5087
5088 #define ALC260_PIN_CD_NID               0x16
5089 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5090 {
5091         struct alc_spec *spec = codec->spec;
5092         int i;
5093
5094         for (i = 0; i < AUTO_PIN_LAST; i++) {
5095                 hda_nid_t nid = spec->autocfg.input_pins[i];
5096                 if (nid >= 0x12) {
5097                         snd_hda_codec_write(codec, nid, 0,
5098                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5099                                             i <= AUTO_PIN_FRONT_MIC ?
5100                                             PIN_VREF80 : PIN_IN);
5101                         if (nid != ALC260_PIN_CD_NID)
5102                                 snd_hda_codec_write(codec, nid, 0,
5103                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5104                                                     AMP_OUT_MUTE);
5105                 }
5106         }
5107 }
5108
5109 /*
5110  * generic initialization of ADC, input mixers and output mixers
5111  */
5112 static struct hda_verb alc260_volume_init_verbs[] = {
5113         /*
5114          * Unmute ADC0-1 and set the default input to mic-in
5115          */
5116         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5117         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5118         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5119         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5120         
5121         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5122          * mixer widget
5123          * Note: PASD motherboards uses the Line In 2 as the input for
5124          * front panel mic (mic 2)
5125          */
5126         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5127         /* mute analog inputs */
5128         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5129         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5130         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5131         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5132         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5133
5134         /*
5135          * Set up output mixers (0x08 - 0x0a)
5136          */
5137         /* set vol=0 to output mixers */
5138         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5139         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5140         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5141         /* set up input amps for analog loopback */
5142         /* Amp Indices: DAC = 0, mixer = 1 */
5143         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5144         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5145         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5146         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5147         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5148         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5149         
5150         { }
5151 };
5152
5153 static int alc260_parse_auto_config(struct hda_codec *codec)
5154 {
5155         struct alc_spec *spec = codec->spec;
5156         unsigned int wcap;
5157         int err;
5158         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5159
5160         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5161                                            alc260_ignore);
5162         if (err < 0)
5163                 return err;
5164         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5165         if (err < 0)
5166                 return err;
5167         if (!spec->kctl_alloc)
5168                 return 0; /* can't find valid BIOS pin config */
5169         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5170         if (err < 0)
5171                 return err;
5172
5173         spec->multiout.max_channels = 2;
5174
5175         if (spec->autocfg.dig_out_pin)
5176                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5177         if (spec->kctl_alloc)
5178                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
5179
5180         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
5181
5182         spec->num_mux_defs = 1;
5183         spec->input_mux = &spec->private_imux;
5184
5185         /* check whether NID 0x04 is valid */
5186         wcap = get_wcaps(codec, 0x04);
5187         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
5188         if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5189                 spec->adc_nids = alc260_adc_nids_alt;
5190                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5191                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
5192         } else {
5193                 spec->adc_nids = alc260_adc_nids;
5194                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5195                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
5196         }
5197         spec->num_mixers++;
5198
5199         store_pin_configs(codec);
5200         return 1;
5201 }
5202
5203 /* additional initialization for auto-configuration model */
5204 static void alc260_auto_init(struct hda_codec *codec)
5205 {
5206         struct alc_spec *spec = codec->spec;
5207         alc260_auto_init_multi_out(codec);
5208         alc260_auto_init_analog_input(codec);
5209         if (spec->unsol_event)
5210                 alc_sku_automute(codec);
5211 }
5212
5213 #ifdef CONFIG_SND_HDA_POWER_SAVE
5214 static struct hda_amp_list alc260_loopbacks[] = {
5215         { 0x07, HDA_INPUT, 0 },
5216         { 0x07, HDA_INPUT, 1 },
5217         { 0x07, HDA_INPUT, 2 },
5218         { 0x07, HDA_INPUT, 3 },
5219         { 0x07, HDA_INPUT, 4 },
5220         { } /* end */
5221 };
5222 #endif
5223
5224 /*
5225  * ALC260 configurations
5226  */
5227 static const char *alc260_models[ALC260_MODEL_LAST] = {
5228         [ALC260_BASIC]          = "basic",
5229         [ALC260_HP]             = "hp",
5230         [ALC260_HP_3013]        = "hp-3013",
5231         [ALC260_FUJITSU_S702X]  = "fujitsu",
5232         [ALC260_ACER]           = "acer",
5233         [ALC260_WILL]           = "will",
5234         [ALC260_REPLACER_672V]  = "replacer",
5235 #ifdef CONFIG_SND_DEBUG
5236         [ALC260_TEST]           = "test",
5237 #endif
5238         [ALC260_AUTO]           = "auto",
5239 };
5240
5241 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5242         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5243         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5244         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5245         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5246         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5247         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5248         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
5249         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5250         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5251         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5252         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5253         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5254         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5255         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5256         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5257         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5258         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5259         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5260         {}
5261 };
5262
5263 static struct alc_config_preset alc260_presets[] = {
5264         [ALC260_BASIC] = {
5265                 .mixers = { alc260_base_output_mixer,
5266                             alc260_input_mixer,
5267                             alc260_pc_beep_mixer,
5268                             alc260_capture_mixer },
5269                 .init_verbs = { alc260_init_verbs },
5270                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5271                 .dac_nids = alc260_dac_nids,
5272                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5273                 .adc_nids = alc260_adc_nids,
5274                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5275                 .channel_mode = alc260_modes,
5276                 .input_mux = &alc260_capture_source,
5277         },
5278         [ALC260_HP] = {
5279                 .mixers = { alc260_hp_output_mixer,
5280                             alc260_input_mixer,
5281                             alc260_capture_alt_mixer },
5282                 .init_verbs = { alc260_init_verbs,
5283                                 alc260_hp_unsol_verbs },
5284                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5285                 .dac_nids = alc260_dac_nids,
5286                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5287                 .adc_nids = alc260_hp_adc_nids,
5288                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5289                 .channel_mode = alc260_modes,
5290                 .input_mux = &alc260_capture_source,
5291                 .unsol_event = alc260_hp_unsol_event,
5292                 .init_hook = alc260_hp_automute,
5293         },
5294         [ALC260_HP_3013] = {
5295                 .mixers = { alc260_hp_3013_mixer,
5296                             alc260_input_mixer,
5297                             alc260_capture_alt_mixer },
5298                 .init_verbs = { alc260_hp_3013_init_verbs,
5299                                 alc260_hp_3013_unsol_verbs },
5300                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5301                 .dac_nids = alc260_dac_nids,
5302                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5303                 .adc_nids = alc260_hp_adc_nids,
5304                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5305                 .channel_mode = alc260_modes,
5306                 .input_mux = &alc260_capture_source,
5307                 .unsol_event = alc260_hp_3013_unsol_event,
5308                 .init_hook = alc260_hp_3013_automute,
5309         },
5310         [ALC260_FUJITSU_S702X] = {
5311                 .mixers = { alc260_fujitsu_mixer,
5312                             alc260_capture_mixer },
5313                 .init_verbs = { alc260_fujitsu_init_verbs },
5314                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5315                 .dac_nids = alc260_dac_nids,
5316                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5317                 .adc_nids = alc260_dual_adc_nids,
5318                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5319                 .channel_mode = alc260_modes,
5320                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5321                 .input_mux = alc260_fujitsu_capture_sources,
5322         },
5323         [ALC260_ACER] = {
5324                 .mixers = { alc260_acer_mixer,
5325                             alc260_capture_mixer },
5326                 .init_verbs = { alc260_acer_init_verbs },
5327                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5328                 .dac_nids = alc260_dac_nids,
5329                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5330                 .adc_nids = alc260_dual_adc_nids,
5331                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5332                 .channel_mode = alc260_modes,
5333                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5334                 .input_mux = alc260_acer_capture_sources,
5335         },
5336         [ALC260_WILL] = {
5337                 .mixers = { alc260_will_mixer,
5338                             alc260_capture_mixer },
5339                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5340                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5341                 .dac_nids = alc260_dac_nids,
5342                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5343                 .adc_nids = alc260_adc_nids,
5344                 .dig_out_nid = ALC260_DIGOUT_NID,
5345                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5346                 .channel_mode = alc260_modes,
5347                 .input_mux = &alc260_capture_source,
5348         },
5349         [ALC260_REPLACER_672V] = {
5350                 .mixers = { alc260_replacer_672v_mixer,
5351                             alc260_capture_mixer },
5352                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5353                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5354                 .dac_nids = alc260_dac_nids,
5355                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5356                 .adc_nids = alc260_adc_nids,
5357                 .dig_out_nid = ALC260_DIGOUT_NID,
5358                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5359                 .channel_mode = alc260_modes,
5360                 .input_mux = &alc260_capture_source,
5361                 .unsol_event = alc260_replacer_672v_unsol_event,
5362                 .init_hook = alc260_replacer_672v_automute,
5363         },
5364 #ifdef CONFIG_SND_DEBUG
5365         [ALC260_TEST] = {
5366                 .mixers = { alc260_test_mixer,
5367                             alc260_capture_mixer },
5368                 .init_verbs = { alc260_test_init_verbs },
5369                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5370                 .dac_nids = alc260_test_dac_nids,
5371                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5372                 .adc_nids = alc260_test_adc_nids,
5373                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5374                 .channel_mode = alc260_modes,
5375                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5376                 .input_mux = alc260_test_capture_sources,
5377         },
5378 #endif
5379 };
5380
5381 static int patch_alc260(struct hda_codec *codec)
5382 {
5383         struct alc_spec *spec;
5384         int err, board_config;
5385
5386         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5387         if (spec == NULL)
5388                 return -ENOMEM;
5389
5390         codec->spec = spec;
5391
5392         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5393                                                   alc260_models,
5394                                                   alc260_cfg_tbl);
5395         if (board_config < 0) {
5396                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5397                            "trying auto-probe from BIOS...\n");
5398                 board_config = ALC260_AUTO;
5399         }
5400
5401         if (board_config == ALC260_AUTO) {
5402                 /* automatic parse from the BIOS config */
5403                 err = alc260_parse_auto_config(codec);
5404                 if (err < 0) {
5405                         alc_free(codec);
5406                         return err;
5407                 } else if (!err) {
5408                         printk(KERN_INFO
5409                                "hda_codec: Cannot set up configuration "
5410                                "from BIOS.  Using base mode...\n");
5411                         board_config = ALC260_BASIC;
5412                 }
5413         }
5414
5415         if (board_config != ALC260_AUTO)
5416                 setup_preset(spec, &alc260_presets[board_config]);
5417
5418         spec->stream_name_analog = "ALC260 Analog";
5419         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5420         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5421
5422         spec->stream_name_digital = "ALC260 Digital";
5423         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5424         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5425
5426         spec->vmaster_nid = 0x08;
5427
5428         codec->patch_ops = alc_patch_ops;
5429         if (board_config == ALC260_AUTO)
5430                 spec->init_hook = alc260_auto_init;
5431 #ifdef CONFIG_SND_HDA_POWER_SAVE
5432         if (!spec->loopback.amplist)
5433                 spec->loopback.amplist = alc260_loopbacks;
5434 #endif
5435
5436         return 0;
5437 }
5438
5439
5440 /*
5441  * ALC882 support
5442  *
5443  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5444  * configuration.  Each pin widget can choose any input DACs and a mixer.
5445  * Each ADC is connected from a mixer of all inputs.  This makes possible
5446  * 6-channel independent captures.
5447  *
5448  * In addition, an independent DAC for the multi-playback (not used in this
5449  * driver yet).
5450  */
5451 #define ALC882_DIGOUT_NID       0x06
5452 #define ALC882_DIGIN_NID        0x0a
5453
5454 static struct hda_channel_mode alc882_ch_modes[1] = {
5455         { 8, NULL }
5456 };
5457
5458 static hda_nid_t alc882_dac_nids[4] = {
5459         /* front, rear, clfe, rear_surr */
5460         0x02, 0x03, 0x04, 0x05
5461 };
5462
5463 /* identical with ALC880 */
5464 #define alc882_adc_nids         alc880_adc_nids
5465 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5466
5467 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5468 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5469
5470 /* input MUX */
5471 /* FIXME: should be a matrix-type input source selection */
5472
5473 static struct hda_input_mux alc882_capture_source = {
5474         .num_items = 4,
5475         .items = {
5476                 { "Mic", 0x0 },
5477                 { "Front Mic", 0x1 },
5478                 { "Line", 0x2 },
5479                 { "CD", 0x4 },
5480         },
5481 };
5482 #define alc882_mux_enum_info alc_mux_enum_info
5483 #define alc882_mux_enum_get alc_mux_enum_get
5484
5485 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5486                                struct snd_ctl_elem_value *ucontrol)
5487 {
5488         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5489         struct alc_spec *spec = codec->spec;
5490         const struct hda_input_mux *imux = spec->input_mux;
5491         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5492         hda_nid_t nid = spec->capsrc_nids ?
5493                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
5494         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5495         unsigned int i, idx;
5496
5497         idx = ucontrol->value.enumerated.item[0];
5498         if (idx >= imux->num_items)
5499                 idx = imux->num_items - 1;
5500         if (*cur_val == idx)
5501                 return 0;
5502         for (i = 0; i < imux->num_items; i++) {
5503                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
5504                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
5505                                          imux->items[i].index,
5506                                          HDA_AMP_MUTE, v);
5507         }
5508         *cur_val = idx;
5509         return 1;
5510 }
5511
5512 /*
5513  * 2ch mode
5514  */
5515 static struct hda_verb alc882_3ST_ch2_init[] = {
5516         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5517         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5518         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5519         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5520         { } /* end */
5521 };
5522
5523 /*
5524  * 6ch mode
5525  */
5526 static struct hda_verb alc882_3ST_ch6_init[] = {
5527         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5528         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5529         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5530         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5531         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5532         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5533         { } /* end */
5534 };
5535
5536 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5537         { 2, alc882_3ST_ch2_init },
5538         { 6, alc882_3ST_ch6_init },
5539 };
5540
5541 /*
5542  * 6ch mode
5543  */
5544 static struct hda_verb alc882_sixstack_ch6_init[] = {
5545         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5546         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5547         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5548         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5549         { } /* end */
5550 };
5551
5552 /*
5553  * 8ch mode
5554  */
5555 static struct hda_verb alc882_sixstack_ch8_init[] = {
5556         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5557         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5558         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5559         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5560         { } /* end */
5561 };
5562
5563 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5564         { 6, alc882_sixstack_ch6_init },
5565         { 8, alc882_sixstack_ch8_init },
5566 };
5567
5568 /*
5569  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5570  */
5571
5572 /*
5573  * 2ch mode
5574  */
5575 static struct hda_verb alc885_mbp_ch2_init[] = {
5576         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5577         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5578         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5579         { } /* end */
5580 };
5581
5582 /*
5583  * 4ch mode
5584  */
5585 static struct hda_verb alc885_mbp_ch4_init[] = {
5586         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5587         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5588         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5589         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5590         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5591         { } /* end */
5592 };
5593
5594 static struct hda_channel_mode alc885_mbp_4ch_modes[2] = {
5595         { 2, alc885_mbp_ch2_init },
5596         { 4, alc885_mbp_ch4_init },
5597 };
5598
5599
5600 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5601  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5602  */
5603 static struct snd_kcontrol_new alc882_base_mixer[] = {
5604         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5605         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5606         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5607         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5608         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5609         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5610         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5611         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5612         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5613         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5614         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5615         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5616         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5617         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5618         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5619         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5620         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5621         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5622         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5623         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5624         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5625         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5626         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5627         { } /* end */
5628 };
5629
5630 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5631         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5632         HDA_BIND_MUTE   ("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
5633         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
5634         HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0e, 0x02, HDA_INPUT),
5635         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
5636         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5637         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5638         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5639         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5640         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
5641         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5642         { } /* end */
5643 };
5644 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5645         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5646         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5647         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5648         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5649         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5650         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5651         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5652         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5653         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5654         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5655         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5656         { } /* end */
5657 };
5658
5659 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5660         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5661         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5662         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5663         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5664         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5665         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5666         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5667         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5668         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5669         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5670         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5671         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5672         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5673         { } /* end */
5674 };
5675
5676 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5677  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5678  */
5679 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5680         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5681         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5682         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5683         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5684         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5685         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5686         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5687         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5688         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5689         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5690         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5691         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5692         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5693         { } /* end */
5694 };
5695
5696 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5697         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5698         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5699         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5700         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5701         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5702         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5703         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5704         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5705         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5706         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5707         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5708         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5709         { } /* end */
5710 };
5711
5712 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5713         {
5714                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5715                 .name = "Channel Mode",
5716                 .info = alc_ch_mode_info,
5717                 .get = alc_ch_mode_get,
5718                 .put = alc_ch_mode_put,
5719         },
5720         { } /* end */
5721 };
5722
5723 static struct hda_verb alc882_init_verbs[] = {
5724         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5725         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5726         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5727         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5728         /* Rear mixer */
5729         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5730         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5731         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5732         /* CLFE mixer */
5733         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5734         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5735         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5736         /* Side mixer */
5737         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5738         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5739         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5740
5741         /* Front Pin: output 0 (0x0c) */
5742         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5743         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5744         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5745         /* Rear Pin: output 1 (0x0d) */
5746         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5747         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5748         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5749         /* CLFE Pin: output 2 (0x0e) */
5750         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5751         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5752         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5753         /* Side Pin: output 3 (0x0f) */
5754         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5755         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5756         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5757         /* Mic (rear) pin: input vref at 80% */
5758         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5759         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5760         /* Front Mic pin: input vref at 80% */
5761         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5762         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5763         /* Line In pin: input */
5764         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5765         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5766         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5767         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5768         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5769         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5770         /* CD pin widget for input */
5771         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5772
5773         /* FIXME: use matrix-type input source selection */
5774         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5775         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5776         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5777         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5778         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5779         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5780         /* Input mixer2 */
5781         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5782         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5783         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5784         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5785         /* Input mixer3 */
5786         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5787         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5788         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5789         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5790         /* ADC1: mute amp left and right */
5791         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5792         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5793         /* ADC2: mute amp left and right */
5794         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5795         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5796         /* ADC3: mute amp left and right */
5797         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5798         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5799
5800         { }
5801 };
5802
5803 static struct hda_verb alc882_eapd_verbs[] = {
5804         /* change to EAPD mode */
5805         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5806         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5807         { }
5808 };
5809
5810 /* Mac Pro test */
5811 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5812         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5813         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5814         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5815         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5816         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5817         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5818         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5819         { } /* end */
5820 };
5821
5822 static struct hda_verb alc882_macpro_init_verbs[] = {
5823         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5824         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5825         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5826         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5827         /* Front Pin: output 0 (0x0c) */
5828         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5829         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5830         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5831         /* Front Mic pin: input vref at 80% */
5832         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5833         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5834         /* Speaker:  output */
5835         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5836         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5837         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5838         /* Headphone output (output 0 - 0x0c) */
5839         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5840         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5841         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5842
5843         /* FIXME: use matrix-type input source selection */
5844         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5845         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5846         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5847         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5848         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5849         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5850         /* Input mixer2 */
5851         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5852         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5853         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5854         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5855         /* Input mixer3 */
5856         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5857         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5858         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5859         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5860         /* ADC1: mute amp left and right */
5861         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5862         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5863         /* ADC2: mute amp left and right */
5864         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5865         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5866         /* ADC3: mute amp left and right */
5867         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5868         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5869
5870         { }
5871 };
5872
5873 /* Macbook Pro rev3 */
5874 static struct hda_verb alc885_mbp3_init_verbs[] = {
5875         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5876         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5877         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5878         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5879         /* Rear mixer */
5880         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5881         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5882         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5883         /* HP mixer */
5884         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5885         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5886         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5887         /* Front Pin: output 0 (0x0c) */
5888         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5889         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5890         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5891         /* HP Pin: output 0 (0x0e) */
5892         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5893         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5894         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},
5895         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5896         /* Mic (rear) pin: input vref at 80% */
5897         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5898         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5899         /* Front Mic pin: input vref at 80% */
5900         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5901         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5902         /* Line In pin: use output 1 when in LineOut mode */
5903         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5904         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5905         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5906
5907         /* FIXME: use matrix-type input source selection */
5908         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5909         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5910         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5911         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5912         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5913         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5914         /* Input mixer2 */
5915         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5916         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5917         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5918         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5919         /* Input mixer3 */
5920         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5921         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5922         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5923         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5924         /* ADC1: mute amp left and right */
5925         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5926         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5927         /* ADC2: mute amp left and right */
5928         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5929         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5930         /* ADC3: mute amp left and right */
5931         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5932         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5933
5934         { }
5935 };
5936
5937 /* iMac 24 mixer. */
5938 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
5939         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5940         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
5941         { } /* end */
5942 };
5943
5944 /* iMac 24 init verbs. */
5945 static struct hda_verb alc885_imac24_init_verbs[] = {
5946         /* Internal speakers: output 0 (0x0c) */
5947         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5948         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5949         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5950         /* Internal speakers: output 0 (0x0c) */
5951         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5952         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5953         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
5954         /* Headphone: output 0 (0x0c) */
5955         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5956         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5957         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5958         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5959         /* Front Mic: input vref at 80% */
5960         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5961         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5962         { }
5963 };
5964
5965 /* Toggle speaker-output according to the hp-jack state */
5966 static void alc885_imac24_automute(struct hda_codec *codec)
5967 {
5968         unsigned int present;
5969
5970         present = snd_hda_codec_read(codec, 0x14, 0,
5971                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5972         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
5973                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5974         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
5975                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5976 }
5977
5978 /* Processes unsolicited events. */
5979 static void alc885_imac24_unsol_event(struct hda_codec *codec,
5980                                       unsigned int res)
5981 {
5982         /* Headphone insertion or removal. */
5983         if ((res >> 26) == ALC880_HP_EVENT)
5984                 alc885_imac24_automute(codec);
5985 }
5986
5987 static void alc885_mbp3_automute(struct hda_codec *codec)
5988 {
5989         unsigned int present;
5990
5991         present = snd_hda_codec_read(codec, 0x15, 0,
5992                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5993         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
5994                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5995         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
5996                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
5997
5998 }
5999 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6000                                     unsigned int res)
6001 {
6002         /* Headphone insertion or removal. */
6003         if ((res >> 26) == ALC880_HP_EVENT)
6004                 alc885_mbp3_automute(codec);
6005 }
6006
6007
6008 static struct hda_verb alc882_targa_verbs[] = {
6009         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6010         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6011
6012         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6013         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6014         
6015         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6016         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6017         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6018
6019         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6020         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6021         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6022         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6023         { } /* end */
6024 };
6025
6026 /* toggle speaker-output according to the hp-jack state */
6027 static void alc882_targa_automute(struct hda_codec *codec)
6028 {
6029         unsigned int present;
6030  
6031         present = snd_hda_codec_read(codec, 0x14, 0,
6032                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6033         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6034                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6035         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6036                                   present ? 1 : 3);
6037 }
6038
6039 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6040 {
6041         /* Looks like the unsol event is incompatible with the standard
6042          * definition.  4bit tag is placed at 26 bit!
6043          */
6044         if (((res >> 26) == ALC880_HP_EVENT)) {
6045                 alc882_targa_automute(codec);
6046         }
6047 }
6048
6049 static struct hda_verb alc882_asus_a7j_verbs[] = {
6050         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6051         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6052
6053         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6054         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6055         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6056         
6057         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6058         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6059         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6060
6061         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6062         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6063         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6064         { } /* end */
6065 };
6066
6067 static struct hda_verb alc882_asus_a7m_verbs[] = {
6068         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6069         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6070
6071         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6072         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6073         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6074         
6075         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6076         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6077         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6078
6079         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6080         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6081         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6082         { } /* end */
6083 };
6084
6085 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6086 {
6087         unsigned int gpiostate, gpiomask, gpiodir;
6088
6089         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6090                                        AC_VERB_GET_GPIO_DATA, 0);
6091
6092         if (!muted)
6093                 gpiostate |= (1 << pin);
6094         else
6095                 gpiostate &= ~(1 << pin);
6096
6097         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6098                                       AC_VERB_GET_GPIO_MASK, 0);
6099         gpiomask |= (1 << pin);
6100
6101         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6102                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6103         gpiodir |= (1 << pin);
6104
6105
6106         snd_hda_codec_write(codec, codec->afg, 0,
6107                             AC_VERB_SET_GPIO_MASK, gpiomask);
6108         snd_hda_codec_write(codec, codec->afg, 0,
6109                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6110
6111         msleep(1);
6112
6113         snd_hda_codec_write(codec, codec->afg, 0,
6114                             AC_VERB_SET_GPIO_DATA, gpiostate);
6115 }
6116
6117 /* set up GPIO at initialization */
6118 static void alc885_macpro_init_hook(struct hda_codec *codec)
6119 {
6120         alc882_gpio_mute(codec, 0, 0);
6121         alc882_gpio_mute(codec, 1, 0);
6122 }
6123
6124 /* set up GPIO and update auto-muting at initialization */
6125 static void alc885_imac24_init_hook(struct hda_codec *codec)
6126 {
6127         alc885_macpro_init_hook(codec);
6128         alc885_imac24_automute(codec);
6129 }
6130
6131 /*
6132  * generic initialization of ADC, input mixers and output mixers
6133  */
6134 static struct hda_verb alc882_auto_init_verbs[] = {
6135         /*
6136          * Unmute ADC0-2 and set the default input to mic-in
6137          */
6138         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6139         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6140         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6141         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6142         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6143         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6144
6145         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6146          * mixer widget
6147          * Note: PASD motherboards uses the Line In 2 as the input for
6148          * front panel mic (mic 2)
6149          */
6150         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6151         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6152         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6153         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6154         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6155         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6156
6157         /*
6158          * Set up output mixers (0x0c - 0x0f)
6159          */
6160         /* set vol=0 to output mixers */
6161         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6162         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6163         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6164         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6165         /* set up input amps for analog loopback */
6166         /* Amp Indices: DAC = 0, mixer = 1 */
6167         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6168         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6169         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6170         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6171         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6172         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6173         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6174         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6175         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6176         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6177
6178         /* FIXME: use matrix-type input source selection */
6179         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6180         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6181         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6182         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6183         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6184         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6185         /* Input mixer2 */
6186         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6187         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6188         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6189         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6190         /* Input mixer3 */
6191         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6192         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6193         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6194         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6195
6196         { }
6197 };
6198
6199 /* capture mixer elements */
6200 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
6201         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6202         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6203         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6204         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6205         {
6206                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6207                 /* The multiple "Capture Source" controls confuse alsamixer
6208                  * So call somewhat different..
6209                  */
6210                 /* .name = "Capture Source", */
6211                 .name = "Input Source",
6212                 .count = 2,
6213                 .info = alc882_mux_enum_info,
6214                 .get = alc882_mux_enum_get,
6215                 .put = alc882_mux_enum_put,
6216         },
6217         { } /* end */
6218 };
6219
6220 static struct snd_kcontrol_new alc882_capture_mixer[] = {
6221         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
6222         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
6223         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
6224         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
6225         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
6226         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
6227         {
6228                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6229                 /* The multiple "Capture Source" controls confuse alsamixer
6230                  * So call somewhat different..
6231                  */
6232                 /* .name = "Capture Source", */
6233                 .name = "Input Source",
6234                 .count = 3,
6235                 .info = alc882_mux_enum_info,
6236                 .get = alc882_mux_enum_get,
6237                 .put = alc882_mux_enum_put,
6238         },
6239         { } /* end */
6240 };
6241
6242 #ifdef CONFIG_SND_HDA_POWER_SAVE
6243 #define alc882_loopbacks        alc880_loopbacks
6244 #endif
6245
6246 /* pcm configuration: identiacal with ALC880 */
6247 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6248 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6249 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6250 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6251
6252 /*
6253  * configuration and preset
6254  */
6255 static const char *alc882_models[ALC882_MODEL_LAST] = {
6256         [ALC882_3ST_DIG]        = "3stack-dig",
6257         [ALC882_6ST_DIG]        = "6stack-dig",
6258         [ALC882_ARIMA]          = "arima",
6259         [ALC882_W2JC]           = "w2jc",
6260         [ALC882_TARGA]          = "targa",
6261         [ALC882_ASUS_A7J]       = "asus-a7j",
6262         [ALC882_ASUS_A7M]       = "asus-a7m",
6263         [ALC885_MACPRO]         = "macpro",
6264         [ALC885_MBP3]           = "mbp3",
6265         [ALC885_IMAC24]         = "imac24",
6266         [ALC882_AUTO]           = "auto",
6267 };
6268
6269 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6270         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6271         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6272         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6273         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6274         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6275         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6276         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6277         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6278         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6279         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6280         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6281         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6282         {}
6283 };
6284
6285 static struct alc_config_preset alc882_presets[] = {
6286         [ALC882_3ST_DIG] = {
6287                 .mixers = { alc882_base_mixer },
6288                 .init_verbs = { alc882_init_verbs },
6289                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6290                 .dac_nids = alc882_dac_nids,
6291                 .dig_out_nid = ALC882_DIGOUT_NID,
6292                 .dig_in_nid = ALC882_DIGIN_NID,
6293                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6294                 .channel_mode = alc882_ch_modes,
6295                 .need_dac_fix = 1,
6296                 .input_mux = &alc882_capture_source,
6297         },
6298         [ALC882_6ST_DIG] = {
6299                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6300                 .init_verbs = { alc882_init_verbs },
6301                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6302                 .dac_nids = alc882_dac_nids,
6303                 .dig_out_nid = ALC882_DIGOUT_NID,
6304                 .dig_in_nid = ALC882_DIGIN_NID,
6305                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6306                 .channel_mode = alc882_sixstack_modes,
6307                 .input_mux = &alc882_capture_source,
6308         },
6309         [ALC882_ARIMA] = {
6310                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6311                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6312                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6313                 .dac_nids = alc882_dac_nids,
6314                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6315                 .channel_mode = alc882_sixstack_modes,
6316                 .input_mux = &alc882_capture_source,
6317         },
6318         [ALC882_W2JC] = {
6319                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6320                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6321                                 alc880_gpio1_init_verbs },
6322                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6323                 .dac_nids = alc882_dac_nids,
6324                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6325                 .channel_mode = alc880_threestack_modes,
6326                 .need_dac_fix = 1,
6327                 .input_mux = &alc882_capture_source,
6328                 .dig_out_nid = ALC882_DIGOUT_NID,
6329         },
6330         [ALC885_MBP3] = {
6331                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6332                 .init_verbs = { alc885_mbp3_init_verbs,
6333                                 alc880_gpio1_init_verbs },
6334                 .num_dacs = 2,
6335                 .dac_nids = alc882_dac_nids,
6336                 .hp_nid = 0x04,
6337                 .channel_mode = alc885_mbp_4ch_modes,
6338                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_4ch_modes),
6339                 .input_mux = &alc882_capture_source,
6340                 .dig_out_nid = ALC882_DIGOUT_NID,
6341                 .dig_in_nid = ALC882_DIGIN_NID,
6342                 .unsol_event = alc885_mbp3_unsol_event,
6343                 .init_hook = alc885_mbp3_automute,
6344         },
6345         [ALC885_MACPRO] = {
6346                 .mixers = { alc882_macpro_mixer },
6347                 .init_verbs = { alc882_macpro_init_verbs },
6348                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6349                 .dac_nids = alc882_dac_nids,
6350                 .dig_out_nid = ALC882_DIGOUT_NID,
6351                 .dig_in_nid = ALC882_DIGIN_NID,
6352                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6353                 .channel_mode = alc882_ch_modes,
6354                 .input_mux = &alc882_capture_source,
6355                 .init_hook = alc885_macpro_init_hook,
6356         },
6357         [ALC885_IMAC24] = {
6358                 .mixers = { alc885_imac24_mixer },
6359                 .init_verbs = { alc885_imac24_init_verbs },
6360                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6361                 .dac_nids = alc882_dac_nids,
6362                 .dig_out_nid = ALC882_DIGOUT_NID,
6363                 .dig_in_nid = ALC882_DIGIN_NID,
6364                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6365                 .channel_mode = alc882_ch_modes,
6366                 .input_mux = &alc882_capture_source,
6367                 .unsol_event = alc885_imac24_unsol_event,
6368                 .init_hook = alc885_imac24_init_hook,
6369         },
6370         [ALC882_TARGA] = {
6371                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
6372                             alc882_capture_mixer },
6373                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6374                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6375                 .dac_nids = alc882_dac_nids,
6376                 .dig_out_nid = ALC882_DIGOUT_NID,
6377                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6378                 .adc_nids = alc882_adc_nids,
6379                 .capsrc_nids = alc882_capsrc_nids,
6380                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6381                 .channel_mode = alc882_3ST_6ch_modes,
6382                 .need_dac_fix = 1,
6383                 .input_mux = &alc882_capture_source,
6384                 .unsol_event = alc882_targa_unsol_event,
6385                 .init_hook = alc882_targa_automute,
6386         },
6387         [ALC882_ASUS_A7J] = {
6388                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
6389                             alc882_capture_mixer },
6390                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6391                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6392                 .dac_nids = alc882_dac_nids,
6393                 .dig_out_nid = ALC882_DIGOUT_NID,
6394                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6395                 .adc_nids = alc882_adc_nids,
6396                 .capsrc_nids = alc882_capsrc_nids,
6397                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6398                 .channel_mode = alc882_3ST_6ch_modes,
6399                 .need_dac_fix = 1,
6400                 .input_mux = &alc882_capture_source,
6401         },      
6402         [ALC882_ASUS_A7M] = {
6403                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6404                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6405                                 alc880_gpio1_init_verbs,
6406                                 alc882_asus_a7m_verbs },
6407                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6408                 .dac_nids = alc882_dac_nids,
6409                 .dig_out_nid = ALC882_DIGOUT_NID,
6410                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6411                 .channel_mode = alc880_threestack_modes,
6412                 .need_dac_fix = 1,
6413                 .input_mux = &alc882_capture_source,
6414         },      
6415 };
6416
6417
6418 /*
6419  * Pin config fixes
6420  */
6421 enum { 
6422         PINFIX_ABIT_AW9D_MAX
6423 };
6424
6425 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6426         { 0x15, 0x01080104 }, /* side */
6427         { 0x16, 0x01011012 }, /* rear */
6428         { 0x17, 0x01016011 }, /* clfe */
6429         { }
6430 };
6431
6432 static const struct alc_pincfg *alc882_pin_fixes[] = {
6433         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6434 };
6435
6436 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6437         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6438         {}
6439 };
6440
6441 /*
6442  * BIOS auto configuration
6443  */
6444 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6445                                               hda_nid_t nid, int pin_type,
6446                                               int dac_idx)
6447 {
6448         /* set as output */
6449         struct alc_spec *spec = codec->spec;
6450         int idx;
6451
6452         alc_set_pin_output(codec, nid, pin_type);
6453         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6454                 idx = 4;
6455         else
6456                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6457         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6458
6459 }
6460
6461 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6462 {
6463         struct alc_spec *spec = codec->spec;
6464         int i;
6465
6466         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6467         for (i = 0; i <= HDA_SIDE; i++) {
6468                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6469                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6470                 if (nid)
6471                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6472                                                           i);
6473         }
6474 }
6475
6476 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6477 {
6478         struct alc_spec *spec = codec->spec;
6479         hda_nid_t pin;
6480
6481         pin = spec->autocfg.hp_pins[0];
6482         if (pin) /* connect to front */
6483                 /* use dac 0 */
6484                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6485         pin = spec->autocfg.speaker_pins[0];
6486         if (pin)
6487                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6488 }
6489
6490 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6491 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6492
6493 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6494 {
6495         struct alc_spec *spec = codec->spec;
6496         int i;
6497
6498         for (i = 0; i < AUTO_PIN_LAST; i++) {
6499                 hda_nid_t nid = spec->autocfg.input_pins[i];
6500                 unsigned int vref;
6501                 if (!nid)
6502                         continue;
6503                 vref = PIN_IN;
6504                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6505                         unsigned int pincap;
6506                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6507                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6508                             AC_PINCAP_VREF_80)
6509                                 vref = PIN_VREF80;
6510                 }
6511                 snd_hda_codec_write(codec, nid, 0,
6512                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6513                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6514                         snd_hda_codec_write(codec, nid, 0,
6515                                             AC_VERB_SET_AMP_GAIN_MUTE,
6516                                             AMP_OUT_MUTE);
6517         }
6518 }
6519
6520 static void alc882_auto_init_input_src(struct hda_codec *codec)
6521 {
6522         struct alc_spec *spec = codec->spec;
6523         const struct hda_input_mux *imux = spec->input_mux;
6524         int c;
6525
6526         for (c = 0; c < spec->num_adc_nids; c++) {
6527                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6528                 hda_nid_t nid = spec->capsrc_nids[c];
6529                 int conns, mute, idx, item;
6530
6531                 conns = snd_hda_get_connections(codec, nid, conn_list,
6532                                                 ARRAY_SIZE(conn_list));
6533                 if (conns < 0)
6534                         continue;
6535                 for (idx = 0; idx < conns; idx++) {
6536                         /* if the current connection is the selected one,
6537                          * unmute it as default - otherwise mute it
6538                          */
6539                         mute = AMP_IN_MUTE(idx);
6540                         for (item = 0; item < imux->num_items; item++) {
6541                                 if (imux->items[item].index == idx) {
6542                                         if (spec->cur_mux[c] == item)
6543                                                 mute = AMP_IN_UNMUTE(idx);
6544                                         break;
6545                                 }
6546                         }
6547                         snd_hda_codec_write(codec, nid, 0,
6548                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6549                 }
6550         }
6551 }
6552
6553 /* add mic boosts if needed */
6554 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6555 {
6556         struct alc_spec *spec = codec->spec;
6557         int err;
6558         hda_nid_t nid;
6559
6560         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6561         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6562                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6563                                   "Mic Boost",
6564                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6565                 if (err < 0)
6566                         return err;
6567         }
6568         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6569         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6570                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6571                                   "Front Mic Boost",
6572                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6573                 if (err < 0)
6574                         return err;
6575         }
6576         return 0;
6577 }
6578
6579 /* almost identical with ALC880 parser... */
6580 static int alc882_parse_auto_config(struct hda_codec *codec)
6581 {
6582         struct alc_spec *spec = codec->spec;
6583         int err = alc880_parse_auto_config(codec);
6584
6585         if (err < 0)
6586                 return err;
6587         else if (!err)
6588                 return 0; /* no config found */
6589
6590         err = alc_auto_add_mic_boost(codec);
6591         if (err < 0)
6592                 return err;
6593
6594         /* hack - override the init verbs */
6595         spec->init_verbs[0] = alc882_auto_init_verbs;
6596
6597         return 1; /* config found */
6598 }
6599
6600 /* additional initialization for auto-configuration model */
6601 static void alc882_auto_init(struct hda_codec *codec)
6602 {
6603         struct alc_spec *spec = codec->spec;
6604         alc882_auto_init_multi_out(codec);
6605         alc882_auto_init_hp_out(codec);
6606         alc882_auto_init_analog_input(codec);
6607         alc882_auto_init_input_src(codec);
6608         if (spec->unsol_event)
6609                 alc_sku_automute(codec);
6610 }
6611
6612 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6613
6614 static int patch_alc882(struct hda_codec *codec)
6615 {
6616         struct alc_spec *spec;
6617         int err, board_config;
6618
6619         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6620         if (spec == NULL)
6621                 return -ENOMEM;
6622
6623         codec->spec = spec;
6624
6625         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6626                                                   alc882_models,
6627                                                   alc882_cfg_tbl);
6628
6629         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6630                 /* Pick up systems that don't supply PCI SSID */
6631                 switch (codec->subsystem_id) {
6632                 case 0x106b0c00: /* Mac Pro */
6633                         board_config = ALC885_MACPRO;
6634                         break;
6635                 case 0x106b1000: /* iMac 24 */
6636                 case 0x106b2800: /* AppleTV */
6637                         board_config = ALC885_IMAC24;
6638                         break;
6639                 case 0x106b00a0: /* MacBookPro3,1 - Another revision */
6640                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
6641                 case 0x106b2c00: /* Macbook Pro rev3 */
6642                 case 0x106b3600: /* Macbook 3.1 */
6643                 case 0x106b3800: /* MacbookPro4,1 - latter revision */
6644                         board_config = ALC885_MBP3;
6645                         break;
6646                 default:
6647                         /* ALC889A is handled better as ALC888-compatible */
6648                         if (codec->revision_id == 0x100101 ||
6649                             codec->revision_id == 0x100103) {
6650                                 alc_free(codec);
6651                                 return patch_alc883(codec);
6652                         }
6653                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6654                                          "trying auto-probe from BIOS...\n");
6655                         board_config = ALC882_AUTO;
6656                 }
6657         }
6658
6659         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6660
6661         if (board_config == ALC882_AUTO) {
6662                 /* automatic parse from the BIOS config */
6663                 err = alc882_parse_auto_config(codec);
6664                 if (err < 0) {
6665                         alc_free(codec);
6666                         return err;
6667                 } else if (!err) {
6668                         printk(KERN_INFO
6669                                "hda_codec: Cannot set up configuration "
6670                                "from BIOS.  Using base mode...\n");
6671                         board_config = ALC882_3ST_DIG;
6672                 }
6673         }
6674
6675         if (board_config != ALC882_AUTO)
6676                 setup_preset(spec, &alc882_presets[board_config]);
6677
6678         if (codec->vendor_id == 0x10ec0885) {
6679                 spec->stream_name_analog = "ALC885 Analog";
6680                 spec->stream_name_digital = "ALC885 Digital";
6681         } else {
6682                 spec->stream_name_analog = "ALC882 Analog";
6683                 spec->stream_name_digital = "ALC882 Digital";
6684         }
6685
6686         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6687         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6688         /* FIXME: setup DAC5 */
6689         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
6690         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6691
6692         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6693         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6694
6695         if (!spec->adc_nids && spec->input_mux) {
6696                 /* check whether NID 0x07 is valid */
6697                 unsigned int wcap = get_wcaps(codec, 0x07);
6698                 /* get type */
6699                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6700                 if (wcap != AC_WID_AUD_IN) {
6701                         spec->adc_nids = alc882_adc_nids_alt;
6702                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6703                         spec->capsrc_nids = alc882_capsrc_nids_alt;
6704                         spec->mixers[spec->num_mixers] =
6705                                 alc882_capture_alt_mixer;
6706                         spec->num_mixers++;
6707                 } else {
6708                         spec->adc_nids = alc882_adc_nids;
6709                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6710                         spec->capsrc_nids = alc882_capsrc_nids;
6711                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6712                         spec->num_mixers++;
6713                 }
6714         }
6715
6716         spec->vmaster_nid = 0x0c;
6717
6718         codec->patch_ops = alc_patch_ops;
6719         if (board_config == ALC882_AUTO)
6720                 spec->init_hook = alc882_auto_init;
6721 #ifdef CONFIG_SND_HDA_POWER_SAVE
6722         if (!spec->loopback.amplist)
6723                 spec->loopback.amplist = alc882_loopbacks;
6724 #endif
6725
6726         return 0;
6727 }
6728
6729 /*
6730  * ALC883 support
6731  *
6732  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6733  * configuration.  Each pin widget can choose any input DACs and a mixer.
6734  * Each ADC is connected from a mixer of all inputs.  This makes possible
6735  * 6-channel independent captures.
6736  *
6737  * In addition, an independent DAC for the multi-playback (not used in this
6738  * driver yet).
6739  */
6740 #define ALC883_DIGOUT_NID       0x06
6741 #define ALC883_DIGIN_NID        0x0a
6742
6743 static hda_nid_t alc883_dac_nids[4] = {
6744         /* front, rear, clfe, rear_surr */
6745         0x02, 0x03, 0x04, 0x05
6746 };
6747
6748 static hda_nid_t alc883_adc_nids[2] = {
6749         /* ADC1-2 */
6750         0x08, 0x09,
6751 };
6752
6753 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6754
6755 /* input MUX */
6756 /* FIXME: should be a matrix-type input source selection */
6757
6758 static struct hda_input_mux alc883_capture_source = {
6759         .num_items = 4,
6760         .items = {
6761                 { "Mic", 0x0 },
6762                 { "Front Mic", 0x1 },
6763                 { "Line", 0x2 },
6764                 { "CD", 0x4 },
6765         },
6766 };
6767
6768 static struct hda_input_mux alc883_3stack_6ch_intel = {
6769         .num_items = 4,
6770         .items = {
6771                 { "Mic", 0x1 },
6772                 { "Front Mic", 0x0 },
6773                 { "Line", 0x2 },
6774                 { "CD", 0x4 },
6775         },
6776 };
6777
6778 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6779         .num_items = 2,
6780         .items = {
6781                 { "Mic", 0x1 },
6782                 { "Line", 0x2 },
6783         },
6784 };
6785
6786 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6787         .num_items = 4,
6788         .items = {
6789                 { "Mic", 0x0 },
6790                 { "iMic", 0x1 },
6791                 { "Line", 0x2 },
6792                 { "CD", 0x4 },
6793         },
6794 };
6795
6796 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6797         .num_items = 2,
6798         .items = {
6799                 { "Mic", 0x0 },
6800                 { "Int Mic", 0x1 },
6801         },
6802 };
6803
6804 #define alc883_mux_enum_info alc_mux_enum_info
6805 #define alc883_mux_enum_get alc_mux_enum_get
6806 /* ALC883 has the ALC882-type input selection */
6807 #define alc883_mux_enum_put alc882_mux_enum_put
6808
6809 /*
6810  * 2ch mode
6811  */
6812 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6813         { 2, NULL }
6814 };
6815
6816 /*
6817  * 2ch mode
6818  */
6819 static struct hda_verb alc883_3ST_ch2_init[] = {
6820         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6821         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6822         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6823         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6824         { } /* end */
6825 };
6826
6827 /*
6828  * 4ch mode
6829  */
6830 static struct hda_verb alc883_3ST_ch4_init[] = {
6831         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6832         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6833         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6834         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6835         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6836         { } /* end */
6837 };
6838
6839 /*
6840  * 6ch mode
6841  */
6842 static struct hda_verb alc883_3ST_ch6_init[] = {
6843         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6844         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6845         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6846         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6847         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6848         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6849         { } /* end */
6850 };
6851
6852 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6853         { 2, alc883_3ST_ch2_init },
6854         { 4, alc883_3ST_ch4_init },
6855         { 6, alc883_3ST_ch6_init },
6856 };
6857
6858 /*
6859  * 2ch mode
6860  */
6861 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6862         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6863         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6864         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6865         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6866         { } /* end */
6867 };
6868
6869 /*
6870  * 4ch mode
6871  */
6872 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
6873         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6874         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6875         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6876         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6877         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6878         { } /* end */
6879 };
6880
6881 /*
6882  * 6ch mode
6883  */
6884 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
6885         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6886         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6887         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
6888         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6889         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6890         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6891         { } /* end */
6892 };
6893
6894 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
6895         { 2, alc883_3ST_ch2_intel_init },
6896         { 4, alc883_3ST_ch4_intel_init },
6897         { 6, alc883_3ST_ch6_intel_init },
6898 };
6899
6900 /*
6901  * 6ch mode
6902  */
6903 static struct hda_verb alc883_sixstack_ch6_init[] = {
6904         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6905         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6906         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6907         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6908         { } /* end */
6909 };
6910
6911 /*
6912  * 8ch mode
6913  */
6914 static struct hda_verb alc883_sixstack_ch8_init[] = {
6915         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6916         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6917         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6918         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6919         { } /* end */
6920 };
6921
6922 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6923         { 6, alc883_sixstack_ch6_init },
6924         { 8, alc883_sixstack_ch8_init },
6925 };
6926
6927 static struct hda_verb alc883_medion_eapd_verbs[] = {
6928         /* eanable EAPD on medion laptop */
6929         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6930         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6931         { }
6932 };
6933
6934 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6935  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6936  */
6937
6938 static struct snd_kcontrol_new alc883_base_mixer[] = {
6939         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6940         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6941         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6942         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6943         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6944         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6945         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6946         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6947         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6948         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6949         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6950         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6951         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6952         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6953         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6954         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6955         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6956         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6957         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6958         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6959         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6960         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6961         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6962         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6963         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6964         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6965         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6966         {
6967                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6968                 /* .name = "Capture Source", */
6969                 .name = "Input Source",
6970                 .count = 2,
6971                 .info = alc883_mux_enum_info,
6972                 .get = alc883_mux_enum_get,
6973                 .put = alc883_mux_enum_put,
6974         },
6975         { } /* end */
6976 };
6977
6978 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
6979         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6980         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6981         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6982         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6983         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6984         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6985         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6986         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6987         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6988         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6989         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6990         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6991         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6992         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6993         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6994         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6995         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6996         {
6997                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6998                 /* .name = "Capture Source", */
6999                 .name = "Input Source",
7000                 .count = 2,
7001                 .info = alc883_mux_enum_info,
7002                 .get = alc883_mux_enum_get,
7003                 .put = alc883_mux_enum_put,
7004         },
7005         { } /* end */
7006 };
7007
7008 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7009         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7010         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7011         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7012         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7013         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7014         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7015         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7016         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7017         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7018         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7019         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7020         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7021         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7022         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7023         {
7024                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7025                 /* .name = "Capture Source", */
7026                 .name = "Input Source",
7027                 .count = 2,
7028                 .info = alc883_mux_enum_info,
7029                 .get = alc883_mux_enum_get,
7030                 .put = alc883_mux_enum_put,
7031         },
7032         { } /* end */
7033 };
7034
7035 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7036         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7037         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7038         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7039         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7040         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7041         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7042         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7043         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7044         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7045         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7046         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7047         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7048         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7049         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7050         {
7051                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7052                 /* .name = "Capture Source", */
7053                 .name = "Input Source",
7054                 .count = 2,
7055                 .info = alc883_mux_enum_info,
7056                 .get = alc883_mux_enum_get,
7057                 .put = alc883_mux_enum_put,
7058         },
7059         { } /* end */
7060 };
7061
7062 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7063         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7064         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7065         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7066         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7067         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7068         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7069         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7070         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7071         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7072         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7073         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7074         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7075         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7076         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7077         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7078         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7079         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7080         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7081         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7082         {
7083                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7084                 /* .name = "Capture Source", */
7085                 .name = "Input Source",
7086                 .count = 2,
7087                 .info = alc883_mux_enum_info,
7088                 .get = alc883_mux_enum_get,
7089                 .put = alc883_mux_enum_put,
7090         },
7091         { } /* end */
7092 };
7093
7094 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7095         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7096         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7097         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7098         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7099         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7100         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7101         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7102         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7103         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7104         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7105         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7106         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7107         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7108         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7109         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7110         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7111         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7112         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7113         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7114         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7115         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7116         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7117         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7118         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7119         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7120         {
7121                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7122                 /* .name = "Capture Source", */
7123                 .name = "Input Source",
7124                 .count = 2,
7125                 .info = alc883_mux_enum_info,
7126                 .get = alc883_mux_enum_get,
7127                 .put = alc883_mux_enum_put,
7128         },
7129         { } /* end */
7130 };
7131
7132 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7133         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7134         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7135         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7136         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7137         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7138                               HDA_OUTPUT),
7139         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7140         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7141         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7142         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7143         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7144         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7145         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7146         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7147         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7148         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7149         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7150         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7151         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7152         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7153         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7154         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7155         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7156         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7157         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7158         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7159         {
7160                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7161                 /* .name = "Capture Source", */
7162                 .name = "Input Source",
7163                 .count = 2,
7164                 .info = alc883_mux_enum_info,
7165                 .get = alc883_mux_enum_get,
7166                 .put = alc883_mux_enum_put,
7167         },
7168         { } /* end */
7169 };
7170
7171 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7172         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7173         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7174         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7175         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7176         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7177         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7178         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7179         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7180         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7181         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7182         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7183         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7184         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7185         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7186         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7187         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7188         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7189         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7190         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7191         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7192         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7193         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7194         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7195
7196         {
7197                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7198                 /* .name = "Capture Source", */
7199                 .name = "Input Source",
7200                 .count = 1,
7201                 .info = alc883_mux_enum_info,
7202                 .get = alc883_mux_enum_get,
7203                 .put = alc883_mux_enum_put,
7204         },
7205         { } /* end */
7206 };
7207
7208 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7209         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7210         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7211         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7212         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7213         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7214         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7215         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7216         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7217         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7218         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7219         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7220         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7221         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7222         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7223         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7224         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7225         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7226         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7227         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7228         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7229         {
7230                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7231                 /* .name = "Capture Source", */
7232                 .name = "Input Source",
7233                 .count = 2,
7234                 .info = alc883_mux_enum_info,
7235                 .get = alc883_mux_enum_get,
7236                 .put = alc883_mux_enum_put,
7237         },
7238         { } /* end */
7239 };
7240
7241 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7242         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7243         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7244         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7245         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7246         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7247         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7248         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7249         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7250         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7251         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7252         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7253         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7254         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7255         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7256         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7257         {
7258                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7259                 /* .name = "Capture Source", */
7260                 .name = "Input Source",
7261                 .count = 2,
7262                 .info = alc883_mux_enum_info,
7263                 .get = alc883_mux_enum_get,
7264                 .put = alc883_mux_enum_put,
7265         },
7266         { } /* end */
7267 };
7268
7269 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7270         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7271         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7272         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7273         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7274         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7275         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7276         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7277         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7278         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7279         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7280         {
7281                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7282                 /* .name = "Capture Source", */
7283                 .name = "Input Source",
7284                 .count = 1,
7285                 .info = alc883_mux_enum_info,
7286                 .get = alc883_mux_enum_get,
7287                 .put = alc883_mux_enum_put,
7288         },
7289         { } /* end */
7290 };
7291
7292 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7293         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7294         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7295         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7296         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7297         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7298         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7299         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7300         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7301         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7302         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7303         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7304         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7305         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7306         {
7307                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7308                 /* .name = "Capture Source", */
7309                 .name = "Input Source",
7310                 .count = 2,
7311                 .info = alc883_mux_enum_info,
7312                 .get = alc883_mux_enum_get,
7313                 .put = alc883_mux_enum_put,
7314         },
7315         { } /* end */
7316 };
7317
7318 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7319         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7320         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7321         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7322         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7323         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7324         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7325         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7326         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7327         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7328         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7329         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7330         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7331         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7332         {
7333                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7334                 /* .name = "Capture Source", */
7335                 .name = "Input Source",
7336                 .count = 2,
7337                 .info = alc883_mux_enum_info,
7338                 .get = alc883_mux_enum_get,
7339                 .put = alc883_mux_enum_put,
7340         },
7341         { } /* end */
7342 };      
7343
7344 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7345         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7346         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7347         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7348         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7349         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7350         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7351         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7352         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7353         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7354         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7355         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7356         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7357         {
7358                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7359                 /* .name = "Capture Source", */
7360                 .name = "Input Source",
7361                 .count = 2,
7362                 .info = alc883_mux_enum_info,
7363                 .get = alc883_mux_enum_get,
7364                 .put = alc883_mux_enum_put,
7365         },
7366         { } /* end */
7367 };
7368
7369 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7370         {
7371                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7372                 .name = "Channel Mode",
7373                 .info = alc_ch_mode_info,
7374                 .get = alc_ch_mode_get,
7375                 .put = alc_ch_mode_put,
7376         },
7377         { } /* end */
7378 };
7379
7380 static struct hda_verb alc883_init_verbs[] = {
7381         /* ADC1: mute amp left and right */
7382         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7383         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7384         /* ADC2: mute amp left and right */
7385         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7386         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7387         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7388         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7389         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7390         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7391         /* Rear mixer */
7392         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7393         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7394         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7395         /* CLFE mixer */
7396         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7397         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7398         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7399         /* Side mixer */
7400         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7401         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7402         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7403
7404         /* mute analog input loopbacks */
7405         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7406         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7407         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7408         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7409         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7410
7411         /* Front Pin: output 0 (0x0c) */
7412         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7413         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7414         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7415         /* Rear Pin: output 1 (0x0d) */
7416         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7417         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7418         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7419         /* CLFE Pin: output 2 (0x0e) */
7420         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7421         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7422         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7423         /* Side Pin: output 3 (0x0f) */
7424         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7425         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7426         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7427         /* Mic (rear) pin: input vref at 80% */
7428         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7429         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7430         /* Front Mic pin: input vref at 80% */
7431         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7432         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7433         /* Line In pin: input */
7434         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7435         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7436         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7437         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7438         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7439         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7440         /* CD pin widget for input */
7441         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7442
7443         /* FIXME: use matrix-type input source selection */
7444         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7445         /* Input mixer2 */
7446         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7447         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7448         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7449         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7450         /* Input mixer3 */
7451         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7452         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7453         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7454         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7455         { }
7456 };
7457
7458 /* toggle speaker-output according to the hp-jack state */
7459 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7460 {
7461         unsigned int present;
7462
7463         present = snd_hda_codec_read(codec, 0x15, 0,
7464                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7465         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7466                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7467         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7468                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7469 }
7470
7471 /* auto-toggle front mic */
7472 /*
7473 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7474 {
7475         unsigned int present;
7476         unsigned char bits;
7477
7478         present = snd_hda_codec_read(codec, 0x18, 0,
7479                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7480         bits = present ? HDA_AMP_MUTE : 0;
7481         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7482 }
7483 */
7484
7485 static void alc883_mitac_automute(struct hda_codec *codec)
7486 {
7487         alc883_mitac_hp_automute(codec);
7488         /* alc883_mitac_mic_automute(codec); */
7489 }
7490
7491 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7492                                            unsigned int res)
7493 {
7494         switch (res >> 26) {
7495         case ALC880_HP_EVENT:
7496                 alc883_mitac_hp_automute(codec);
7497                 break;
7498         case ALC880_MIC_EVENT:
7499                 /* alc883_mitac_mic_automute(codec); */
7500                 break;
7501         }
7502 }
7503
7504 static struct hda_verb alc883_mitac_verbs[] = {
7505         /* HP */
7506         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7507         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7508         /* Subwoofer */
7509         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7510         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7511
7512         /* enable unsolicited event */
7513         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7514         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7515
7516         { } /* end */
7517 };
7518
7519 static struct hda_verb alc883_clevo_m720_verbs[] = {
7520         /* HP */
7521         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7522         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7523         /* Int speaker */
7524         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7525         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7526
7527         /* enable unsolicited event */
7528         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7529         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7530
7531         { } /* end */
7532 };
7533
7534 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7535         /* HP */
7536         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7537         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7538         /* Subwoofer */
7539         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7540         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7541
7542         /* enable unsolicited event */
7543         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7544
7545         { } /* end */
7546 };
7547
7548 static struct hda_verb alc883_tagra_verbs[] = {
7549         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7550         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7551
7552         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7553         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7554         
7555         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7556         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7557         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7558
7559         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7560         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7561         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7562         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7563
7564         { } /* end */
7565 };
7566
7567 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7568         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7569         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7570         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7571         { } /* end */
7572 };
7573
7574 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7575         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7576         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7577         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7578         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7579         { } /* end */
7580 };
7581
7582 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7583         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7584         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7585         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7586         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7587         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7588         { } /* end */
7589 };
7590
7591 static struct hda_verb alc883_haier_w66_verbs[] = {
7592         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7593         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7594
7595         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7596
7597         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7598         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7599         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7600         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7601         { } /* end */
7602 };
7603
7604 static struct hda_verb alc888_3st_hp_verbs[] = {
7605         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7606         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7607         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7608         { }
7609 };
7610
7611 static struct hda_verb alc888_6st_dell_verbs[] = {
7612         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7613         { }
7614 };
7615
7616 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7617         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7618         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7619         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7620         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7621         { }
7622 };
7623
7624 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7625         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7626         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7627         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7628         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7629         { }
7630 };
7631
7632 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7633         { 2, alc888_3st_hp_2ch_init },
7634         { 6, alc888_3st_hp_6ch_init },
7635 };
7636
7637 /* toggle front-jack and RCA according to the hp-jack state */
7638 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7639 {
7640         unsigned int present;
7641  
7642         present = snd_hda_codec_read(codec, 0x1b, 0,
7643                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7644         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7645                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7646         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7647                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7648 }
7649
7650 /* toggle RCA according to the front-jack state */
7651 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7652 {
7653         unsigned int present;
7654  
7655         present = snd_hda_codec_read(codec, 0x14, 0,
7656                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7657         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7658                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7659 }
7660
7661 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7662                                              unsigned int res)
7663 {
7664         if ((res >> 26) == ALC880_HP_EVENT)
7665                 alc888_lenovo_ms7195_front_automute(codec);
7666         if ((res >> 26) == ALC880_FRONT_EVENT)
7667                 alc888_lenovo_ms7195_rca_automute(codec);
7668 }
7669
7670 static struct hda_verb alc883_medion_md2_verbs[] = {
7671         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7672         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7673
7674         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7675
7676         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7677         { } /* end */
7678 };
7679
7680 /* toggle speaker-output according to the hp-jack state */
7681 static void alc883_medion_md2_automute(struct hda_codec *codec)
7682 {
7683         unsigned int present;
7684  
7685         present = snd_hda_codec_read(codec, 0x14, 0,
7686                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7687         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7688                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7689 }
7690
7691 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7692                                           unsigned int res)
7693 {
7694         if ((res >> 26) == ALC880_HP_EVENT)
7695                 alc883_medion_md2_automute(codec);
7696 }
7697
7698 /* toggle speaker-output according to the hp-jack state */
7699 static void alc883_tagra_automute(struct hda_codec *codec)
7700 {
7701         unsigned int present;
7702         unsigned char bits;
7703
7704         present = snd_hda_codec_read(codec, 0x14, 0,
7705                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7706         bits = present ? HDA_AMP_MUTE : 0;
7707         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7708                                  HDA_AMP_MUTE, bits);
7709         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7710                                   present ? 1 : 3);
7711 }
7712
7713 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7714 {
7715         if ((res >> 26) == ALC880_HP_EVENT)
7716                 alc883_tagra_automute(codec);
7717 }
7718
7719 /* toggle speaker-output according to the hp-jack state */
7720 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7721 {
7722         unsigned int present;
7723         unsigned char bits;
7724
7725         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7726                 & AC_PINSENSE_PRESENCE;
7727         bits = present ? HDA_AMP_MUTE : 0;
7728         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7729                                  HDA_AMP_MUTE, bits);
7730 }
7731
7732 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7733 {
7734         unsigned int present;
7735
7736         present = snd_hda_codec_read(codec, 0x18, 0,
7737                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7738         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7739                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7740 }
7741
7742 static void alc883_clevo_m720_automute(struct hda_codec *codec)
7743 {
7744         alc883_clevo_m720_hp_automute(codec);
7745         alc883_clevo_m720_mic_automute(codec);
7746 }
7747
7748 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7749                                            unsigned int res)
7750 {
7751         switch (res >> 26) {
7752         case ALC880_HP_EVENT:
7753                 alc883_clevo_m720_hp_automute(codec);
7754                 break;
7755         case ALC880_MIC_EVENT:
7756                 alc883_clevo_m720_mic_automute(codec);
7757                 break;
7758         }
7759 }
7760
7761 /* toggle speaker-output according to the hp-jack state */
7762 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7763 {
7764         unsigned int present;
7765         unsigned char bits;
7766
7767         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7768                 & AC_PINSENSE_PRESENCE;
7769         bits = present ? HDA_AMP_MUTE : 0;
7770         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7771                                  HDA_AMP_MUTE, bits);
7772 }
7773
7774 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7775                                                   unsigned int res)
7776 {
7777         if ((res >> 26) == ALC880_HP_EVENT)
7778                 alc883_2ch_fujitsu_pi2515_automute(codec);
7779 }
7780
7781 static void alc883_haier_w66_automute(struct hda_codec *codec)
7782 {
7783         unsigned int present;
7784         unsigned char bits;
7785
7786         present = snd_hda_codec_read(codec, 0x1b, 0,
7787                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7788         bits = present ? 0x80 : 0;
7789         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7790                                  0x80, bits);
7791 }
7792
7793 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7794                                          unsigned int res)
7795 {
7796         if ((res >> 26) == ALC880_HP_EVENT)
7797                 alc883_haier_w66_automute(codec);
7798 }
7799
7800 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7801 {
7802         unsigned int present;
7803         unsigned char bits;
7804
7805         present = snd_hda_codec_read(codec, 0x14, 0,
7806                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7807         bits = present ? HDA_AMP_MUTE : 0;
7808         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7809                                  HDA_AMP_MUTE, bits);
7810 }
7811
7812 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7813 {
7814         unsigned int present;
7815         unsigned char bits;
7816
7817         present = snd_hda_codec_read(codec, 0x1b, 0,
7818                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7819         bits = present ? HDA_AMP_MUTE : 0;
7820         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7821                                  HDA_AMP_MUTE, bits);
7822         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7823                                  HDA_AMP_MUTE, bits);
7824 }
7825
7826 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7827                                            unsigned int res)
7828 {
7829         if ((res >> 26) == ALC880_HP_EVENT)
7830                 alc883_lenovo_101e_all_automute(codec);
7831         if ((res >> 26) == ALC880_FRONT_EVENT)
7832                 alc883_lenovo_101e_ispeaker_automute(codec);
7833 }
7834
7835 /* toggle speaker-output according to the hp-jack state */
7836 static void alc883_acer_aspire_automute(struct hda_codec *codec)
7837 {
7838         unsigned int present;
7839  
7840         present = snd_hda_codec_read(codec, 0x14, 0,
7841                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7842         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7843                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7844         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7845                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7846 }
7847
7848 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
7849                                            unsigned int res)
7850 {
7851         if ((res >> 26) == ALC880_HP_EVENT)
7852                 alc883_acer_aspire_automute(codec);
7853 }
7854
7855 static struct hda_verb alc883_acer_eapd_verbs[] = {
7856         /* HP Pin: output 0 (0x0c) */
7857         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7858         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7859         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7860         /* Front Pin: output 0 (0x0c) */
7861         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7862         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7863         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7864         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
7865         /* eanable EAPD on medion laptop */
7866         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7867         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
7868         /* enable unsolicited event */
7869         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7870         { }
7871 };
7872
7873 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
7874 {
7875         unsigned int present;
7876  
7877         present = snd_hda_codec_read(codec, 0x1b, 0,
7878                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7879         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7880                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7881         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7882                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7883         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7884                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7885         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7886                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7887 }
7888
7889 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
7890                                              unsigned int res)
7891 {
7892         switch (res >> 26) {
7893         case ALC880_HP_EVENT:
7894                 printk("hp_event\n");
7895                 alc888_6st_dell_front_automute(codec);
7896                 break;
7897         }
7898 }
7899
7900 /*
7901  * generic initialization of ADC, input mixers and output mixers
7902  */
7903 static struct hda_verb alc883_auto_init_verbs[] = {
7904         /*
7905          * Unmute ADC0-2 and set the default input to mic-in
7906          */
7907         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7908         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7909         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7910         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7911
7912         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7913          * mixer widget
7914          * Note: PASD motherboards uses the Line In 2 as the input for
7915          * front panel mic (mic 2)
7916          */
7917         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7918         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7919         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7920         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7921         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7922         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7923
7924         /*
7925          * Set up output mixers (0x0c - 0x0f)
7926          */
7927         /* set vol=0 to output mixers */
7928         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7929         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7930         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7931         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7932         /* set up input amps for analog loopback */
7933         /* Amp Indices: DAC = 0, mixer = 1 */
7934         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7935         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7936         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7937         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7938         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7939         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7940         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7941         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7942         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7943         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7944
7945         /* FIXME: use matrix-type input source selection */
7946         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7947         /* Input mixer1 */
7948         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7949         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7950         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7951         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7952         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7953         /* Input mixer2 */
7954         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7955         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7956         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7957         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7958         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7959
7960         { }
7961 };
7962
7963 /* capture mixer elements */
7964 static struct snd_kcontrol_new alc883_capture_mixer[] = {
7965         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7966         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7967         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7968         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7969         {
7970                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7971                 /* The multiple "Capture Source" controls confuse alsamixer
7972                  * So call somewhat different..
7973                  */
7974                 /* .name = "Capture Source", */
7975                 .name = "Input Source",
7976                 .count = 2,
7977                 .info = alc882_mux_enum_info,
7978                 .get = alc882_mux_enum_get,
7979                 .put = alc882_mux_enum_put,
7980         },
7981         { } /* end */
7982 };
7983
7984 #ifdef CONFIG_SND_HDA_POWER_SAVE
7985 #define alc883_loopbacks        alc880_loopbacks
7986 #endif
7987
7988 /* pcm configuration: identiacal with ALC880 */
7989 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
7990 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
7991 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
7992 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
7993 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
7994
7995 /*
7996  * configuration and preset
7997  */
7998 static const char *alc883_models[ALC883_MODEL_LAST] = {
7999         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8000         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8001         [ALC883_3ST_6ch]        = "3stack-6ch",
8002         [ALC883_6ST_DIG]        = "6stack-dig",
8003         [ALC883_TARGA_DIG]      = "targa-dig",
8004         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8005         [ALC883_ACER]           = "acer",
8006         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8007         [ALC883_MEDION]         = "medion",
8008         [ALC883_MEDION_MD2]     = "medion-md2",
8009         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8010         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8011         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8012         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8013         [ALC883_HAIER_W66]      = "haier-w66",
8014         [ALC888_3ST_HP]         = "3stack-hp",
8015         [ALC888_6ST_DELL]       = "6stack-dell",
8016         [ALC883_MITAC]          = "mitac",
8017         [ALC883_CLEVO_M720]     = "clevo-m720",
8018         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8019         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8020         [ALC883_AUTO]           = "auto",
8021 };
8022
8023 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8024         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8025         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8026         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8027         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8028         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8029         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE), 
8030         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8031         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8032         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8033         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8034         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8035         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8036         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8037         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8038         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8039         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8040         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8041         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8042         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8043         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8044         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8045         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8046         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8047         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8048         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8049         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8050         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8051         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8052         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8053         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8054         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8055         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8056         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8057         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8058         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8059         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8060         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8061         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8062         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8063         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8064         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8065         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8066         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8067         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8068         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8069         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8070         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8071         SND_PCI_QUIRK(0x1734, 0x1107, "FSC AMILO Xi2550",
8072                       ALC883_FUJITSU_PI2515),
8073         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8074         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8075         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8076         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8077         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8078         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8079         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8080         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8081         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8082         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8083         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8084         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8085         {}
8086 };
8087
8088 static struct alc_config_preset alc883_presets[] = {
8089         [ALC883_3ST_2ch_DIG] = {
8090                 .mixers = { alc883_3ST_2ch_mixer },
8091                 .init_verbs = { alc883_init_verbs },
8092                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8093                 .dac_nids = alc883_dac_nids,
8094                 .dig_out_nid = ALC883_DIGOUT_NID,
8095                 .dig_in_nid = ALC883_DIGIN_NID,
8096                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8097                 .channel_mode = alc883_3ST_2ch_modes,
8098                 .input_mux = &alc883_capture_source,
8099         },
8100         [ALC883_3ST_6ch_DIG] = {
8101                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8102                 .init_verbs = { alc883_init_verbs },
8103                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8104                 .dac_nids = alc883_dac_nids,
8105                 .dig_out_nid = ALC883_DIGOUT_NID,
8106                 .dig_in_nid = ALC883_DIGIN_NID,
8107                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8108                 .channel_mode = alc883_3ST_6ch_modes,
8109                 .need_dac_fix = 1,
8110                 .input_mux = &alc883_capture_source,
8111         },
8112         [ALC883_3ST_6ch] = {
8113                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8114                 .init_verbs = { alc883_init_verbs },
8115                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8116                 .dac_nids = alc883_dac_nids,
8117                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8118                 .channel_mode = alc883_3ST_6ch_modes,
8119                 .need_dac_fix = 1,
8120                 .input_mux = &alc883_capture_source,
8121         },
8122         [ALC883_3ST_6ch_INTEL] = {
8123                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8124                 .init_verbs = { alc883_init_verbs },
8125                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8126                 .dac_nids = alc883_dac_nids,
8127                 .dig_out_nid = ALC883_DIGOUT_NID,
8128                 .dig_in_nid = ALC883_DIGIN_NID,
8129                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8130                 .channel_mode = alc883_3ST_6ch_intel_modes,
8131                 .need_dac_fix = 1,
8132                 .input_mux = &alc883_3stack_6ch_intel,
8133         },
8134         [ALC883_6ST_DIG] = {
8135                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8136                 .init_verbs = { alc883_init_verbs },
8137                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8138                 .dac_nids = alc883_dac_nids,
8139                 .dig_out_nid = ALC883_DIGOUT_NID,
8140                 .dig_in_nid = ALC883_DIGIN_NID,
8141                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8142                 .channel_mode = alc883_sixstack_modes,
8143                 .input_mux = &alc883_capture_source,
8144         },
8145         [ALC883_TARGA_DIG] = {
8146                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8147                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8148                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8149                 .dac_nids = alc883_dac_nids,
8150                 .dig_out_nid = ALC883_DIGOUT_NID,
8151                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8152                 .channel_mode = alc883_3ST_6ch_modes,
8153                 .need_dac_fix = 1,
8154                 .input_mux = &alc883_capture_source,
8155                 .unsol_event = alc883_tagra_unsol_event,
8156                 .init_hook = alc883_tagra_automute,
8157         },
8158         [ALC883_TARGA_2ch_DIG] = {
8159                 .mixers = { alc883_tagra_2ch_mixer},
8160                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8161                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8162                 .dac_nids = alc883_dac_nids,
8163                 .dig_out_nid = ALC883_DIGOUT_NID,
8164                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8165                 .channel_mode = alc883_3ST_2ch_modes,
8166                 .input_mux = &alc883_capture_source,
8167                 .unsol_event = alc883_tagra_unsol_event,
8168                 .init_hook = alc883_tagra_automute,
8169         },
8170         [ALC883_ACER] = {
8171                 .mixers = { alc883_base_mixer },
8172                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8173                  * and the headphone jack.  Turn this on and rely on the
8174                  * standard mute methods whenever the user wants to turn
8175                  * these outputs off.
8176                  */
8177                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8178                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8179                 .dac_nids = alc883_dac_nids,
8180                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8181                 .channel_mode = alc883_3ST_2ch_modes,
8182                 .input_mux = &alc883_capture_source,
8183         },
8184         [ALC883_ACER_ASPIRE] = {
8185                 .mixers = { alc883_acer_aspire_mixer },
8186                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8187                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8188                 .dac_nids = alc883_dac_nids,
8189                 .dig_out_nid = ALC883_DIGOUT_NID,
8190                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8191                 .channel_mode = alc883_3ST_2ch_modes,
8192                 .input_mux = &alc883_capture_source,
8193                 .unsol_event = alc883_acer_aspire_unsol_event,
8194                 .init_hook = alc883_acer_aspire_automute,
8195         },
8196         [ALC883_MEDION] = {
8197                 .mixers = { alc883_fivestack_mixer,
8198                             alc883_chmode_mixer },
8199                 .init_verbs = { alc883_init_verbs,
8200                                 alc883_medion_eapd_verbs },
8201                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8202                 .dac_nids = alc883_dac_nids,
8203                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8204                 .channel_mode = alc883_sixstack_modes,
8205                 .input_mux = &alc883_capture_source,
8206         },
8207         [ALC883_MEDION_MD2] = {
8208                 .mixers = { alc883_medion_md2_mixer},
8209                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8210                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8211                 .dac_nids = alc883_dac_nids,
8212                 .dig_out_nid = ALC883_DIGOUT_NID,
8213                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8214                 .channel_mode = alc883_3ST_2ch_modes,
8215                 .input_mux = &alc883_capture_source,
8216                 .unsol_event = alc883_medion_md2_unsol_event,
8217                 .init_hook = alc883_medion_md2_automute,
8218         },      
8219         [ALC883_LAPTOP_EAPD] = {
8220                 .mixers = { alc883_base_mixer },
8221                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8222                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8223                 .dac_nids = alc883_dac_nids,
8224                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8225                 .channel_mode = alc883_3ST_2ch_modes,
8226                 .input_mux = &alc883_capture_source,
8227         },
8228         [ALC883_CLEVO_M720] = {
8229                 .mixers = { alc883_clevo_m720_mixer },
8230                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8231                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8232                 .dac_nids = alc883_dac_nids,
8233                 .dig_out_nid = ALC883_DIGOUT_NID,
8234                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8235                 .channel_mode = alc883_3ST_2ch_modes,
8236                 .input_mux = &alc883_capture_source,
8237                 .unsol_event = alc883_clevo_m720_unsol_event,
8238                 .init_hook = alc883_clevo_m720_automute,
8239         },
8240         [ALC883_LENOVO_101E_2ch] = {
8241                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8242                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8243                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8244                 .dac_nids = alc883_dac_nids,
8245                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8246                 .channel_mode = alc883_3ST_2ch_modes,
8247                 .input_mux = &alc883_lenovo_101e_capture_source,
8248                 .unsol_event = alc883_lenovo_101e_unsol_event,
8249                 .init_hook = alc883_lenovo_101e_all_automute,
8250         },
8251         [ALC883_LENOVO_NB0763] = {
8252                 .mixers = { alc883_lenovo_nb0763_mixer },
8253                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8254                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8255                 .dac_nids = alc883_dac_nids,
8256                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8257                 .channel_mode = alc883_3ST_2ch_modes,
8258                 .need_dac_fix = 1,
8259                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8260                 .unsol_event = alc883_medion_md2_unsol_event,
8261                 .init_hook = alc883_medion_md2_automute,
8262         },
8263         [ALC888_LENOVO_MS7195_DIG] = {
8264                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8265                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8266                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8267                 .dac_nids = alc883_dac_nids,
8268                 .dig_out_nid = ALC883_DIGOUT_NID,
8269                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8270                 .channel_mode = alc883_3ST_6ch_modes,
8271                 .need_dac_fix = 1,
8272                 .input_mux = &alc883_capture_source,
8273                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8274                 .init_hook = alc888_lenovo_ms7195_front_automute,
8275         },
8276         [ALC883_HAIER_W66] = {
8277                 .mixers = { alc883_tagra_2ch_mixer},
8278                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8279                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8280                 .dac_nids = alc883_dac_nids,
8281                 .dig_out_nid = ALC883_DIGOUT_NID,
8282                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8283                 .channel_mode = alc883_3ST_2ch_modes,
8284                 .input_mux = &alc883_capture_source,
8285                 .unsol_event = alc883_haier_w66_unsol_event,
8286                 .init_hook = alc883_haier_w66_automute,
8287         },
8288         [ALC888_3ST_HP] = {
8289                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8290                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8291                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8292                 .dac_nids = alc883_dac_nids,
8293                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8294                 .channel_mode = alc888_3st_hp_modes,
8295                 .need_dac_fix = 1,
8296                 .input_mux = &alc883_capture_source,
8297         },
8298         [ALC888_6ST_DELL] = {
8299                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8300                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8301                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8302                 .dac_nids = alc883_dac_nids,
8303                 .dig_out_nid = ALC883_DIGOUT_NID,
8304                 .dig_in_nid = ALC883_DIGIN_NID,
8305                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8306                 .channel_mode = alc883_sixstack_modes,
8307                 .input_mux = &alc883_capture_source,
8308                 .unsol_event = alc888_6st_dell_unsol_event,
8309                 .init_hook = alc888_6st_dell_front_automute,
8310         },
8311         [ALC883_MITAC] = {
8312                 .mixers = { alc883_mitac_mixer },
8313                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8314                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8315                 .dac_nids = alc883_dac_nids,
8316                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8317                 .channel_mode = alc883_3ST_2ch_modes,
8318                 .input_mux = &alc883_capture_source,
8319                 .unsol_event = alc883_mitac_unsol_event,
8320                 .init_hook = alc883_mitac_automute,
8321         },
8322         [ALC883_FUJITSU_PI2515] = {
8323                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8324                 .init_verbs = { alc883_init_verbs,
8325                                 alc883_2ch_fujitsu_pi2515_verbs},
8326                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8327                 .dac_nids = alc883_dac_nids,
8328                 .dig_out_nid = ALC883_DIGOUT_NID,
8329                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8330                 .channel_mode = alc883_3ST_2ch_modes,
8331                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8332                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8333                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8334         },
8335 };
8336
8337
8338 /*
8339  * BIOS auto configuration
8340  */
8341 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8342                                               hda_nid_t nid, int pin_type,
8343                                               int dac_idx)
8344 {
8345         /* set as output */
8346         struct alc_spec *spec = codec->spec;
8347         int idx;
8348
8349         alc_set_pin_output(codec, nid, pin_type);
8350         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8351                 idx = 4;
8352         else
8353                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8354         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8355
8356 }
8357
8358 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8359 {
8360         struct alc_spec *spec = codec->spec;
8361         int i;
8362
8363         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8364         for (i = 0; i <= HDA_SIDE; i++) {
8365                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8366                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8367                 if (nid)
8368                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8369                                                           i);
8370         }
8371 }
8372
8373 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8374 {
8375         struct alc_spec *spec = codec->spec;
8376         hda_nid_t pin;
8377
8378         pin = spec->autocfg.hp_pins[0];
8379         if (pin) /* connect to front */
8380                 /* use dac 0 */
8381                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8382         pin = spec->autocfg.speaker_pins[0];
8383         if (pin)
8384                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8385 }
8386
8387 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8388 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8389
8390 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8391 {
8392         struct alc_spec *spec = codec->spec;
8393         int i;
8394
8395         for (i = 0; i < AUTO_PIN_LAST; i++) {
8396                 hda_nid_t nid = spec->autocfg.input_pins[i];
8397                 if (alc883_is_input_pin(nid)) {
8398                         snd_hda_codec_write(codec, nid, 0,
8399                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8400                                             (i <= AUTO_PIN_FRONT_MIC ?
8401                                              PIN_VREF80 : PIN_IN));
8402                         if (nid != ALC883_PIN_CD_NID)
8403                                 snd_hda_codec_write(codec, nid, 0,
8404                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8405                                                     AMP_OUT_MUTE);
8406                 }
8407         }
8408 }
8409
8410 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8411
8412 /* almost identical with ALC880 parser... */
8413 static int alc883_parse_auto_config(struct hda_codec *codec)
8414 {
8415         struct alc_spec *spec = codec->spec;
8416         int err = alc880_parse_auto_config(codec);
8417
8418         if (err < 0)
8419                 return err;
8420         else if (!err)
8421                 return 0; /* no config found */
8422
8423         err = alc_auto_add_mic_boost(codec);
8424         if (err < 0)
8425                 return err;
8426
8427         /* hack - override the init verbs */
8428         spec->init_verbs[0] = alc883_auto_init_verbs;
8429         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
8430         spec->num_mixers++;
8431
8432         return 1; /* config found */
8433 }
8434
8435 /* additional initialization for auto-configuration model */
8436 static void alc883_auto_init(struct hda_codec *codec)
8437 {
8438         struct alc_spec *spec = codec->spec;
8439         alc883_auto_init_multi_out(codec);
8440         alc883_auto_init_hp_out(codec);
8441         alc883_auto_init_analog_input(codec);
8442         alc883_auto_init_input_src(codec);
8443         if (spec->unsol_event)
8444                 alc_sku_automute(codec);
8445 }
8446
8447 static int patch_alc883(struct hda_codec *codec)
8448 {
8449         struct alc_spec *spec;
8450         int err, board_config;
8451
8452         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8453         if (spec == NULL)
8454                 return -ENOMEM;
8455
8456         codec->spec = spec;
8457
8458         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
8459
8460         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8461                                                   alc883_models,
8462                                                   alc883_cfg_tbl);
8463         if (board_config < 0) {
8464                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8465                        "trying auto-probe from BIOS...\n");
8466                 board_config = ALC883_AUTO;
8467         }
8468
8469         if (board_config == ALC883_AUTO) {
8470                 /* automatic parse from the BIOS config */
8471                 err = alc883_parse_auto_config(codec);
8472                 if (err < 0) {
8473                         alc_free(codec);
8474                         return err;
8475                 } else if (!err) {
8476                         printk(KERN_INFO
8477                                "hda_codec: Cannot set up configuration "
8478                                "from BIOS.  Using base mode...\n");
8479                         board_config = ALC883_3ST_2ch_DIG;
8480                 }
8481         }
8482
8483         if (board_config != ALC883_AUTO)
8484                 setup_preset(spec, &alc883_presets[board_config]);
8485
8486         switch (codec->vendor_id) {
8487         case 0x10ec0888:
8488                 spec->stream_name_analog = "ALC888 Analog";
8489                 spec->stream_name_digital = "ALC888 Digital";
8490                 break;
8491         case 0x10ec0889:
8492                 spec->stream_name_analog = "ALC889 Analog";
8493                 spec->stream_name_digital = "ALC889 Digital";
8494                 break;
8495         default:
8496                 spec->stream_name_analog = "ALC883 Analog";
8497                 spec->stream_name_digital = "ALC883 Digital";
8498                 break;
8499         }
8500
8501         spec->stream_analog_playback = &alc883_pcm_analog_playback;
8502         spec->stream_analog_capture = &alc883_pcm_analog_capture;
8503         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
8504
8505         spec->stream_digital_playback = &alc883_pcm_digital_playback;
8506         spec->stream_digital_capture = &alc883_pcm_digital_capture;
8507
8508         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8509         spec->adc_nids = alc883_adc_nids;
8510         spec->capsrc_nids = alc883_capsrc_nids;
8511
8512         spec->vmaster_nid = 0x0c;
8513
8514         codec->patch_ops = alc_patch_ops;
8515         if (board_config == ALC883_AUTO)
8516                 spec->init_hook = alc883_auto_init;
8517
8518 #ifdef CONFIG_SND_HDA_POWER_SAVE
8519         if (!spec->loopback.amplist)
8520                 spec->loopback.amplist = alc883_loopbacks;
8521 #endif
8522
8523         return 0;
8524 }
8525
8526 /*
8527  * ALC262 support
8528  */
8529
8530 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
8531 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
8532
8533 #define alc262_dac_nids         alc260_dac_nids
8534 #define alc262_adc_nids         alc882_adc_nids
8535 #define alc262_adc_nids_alt     alc882_adc_nids_alt
8536 #define alc262_capsrc_nids      alc882_capsrc_nids
8537 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
8538
8539 #define alc262_modes            alc260_modes
8540 #define alc262_capture_source   alc882_capture_source
8541
8542 static struct snd_kcontrol_new alc262_base_mixer[] = {
8543         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8544         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8545         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8546         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8547         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8548         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8549         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8550         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8551         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8552         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8553         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8554         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8555         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8556            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8557         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
8558         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8559         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8560         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
8561         { } /* end */
8562 };
8563
8564 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
8565         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8566         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8567         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8568         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8569         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8570         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8571         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8572         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8573         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8574         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8575         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8576         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8577         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8578            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8579         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
8580         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8581         { } /* end */
8582 };
8583
8584 /* update HP, line and mono-out pins according to the master switch */
8585 static void alc262_hp_master_update(struct hda_codec *codec)
8586 {
8587         struct alc_spec *spec = codec->spec;
8588         int val = spec->master_sw;
8589
8590         /* HP & line-out */
8591         snd_hda_codec_write_cache(codec, 0x1b, 0,
8592                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8593                                   val ? PIN_HP : 0);
8594         snd_hda_codec_write_cache(codec, 0x15, 0,
8595                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8596                                   val ? PIN_HP : 0);
8597         /* mono (speaker) depending on the HP jack sense */
8598         val = val && !spec->jack_present;
8599         snd_hda_codec_write_cache(codec, 0x16, 0,
8600                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8601                                   val ? PIN_OUT : 0);
8602 }
8603
8604 static void alc262_hp_bpc_automute(struct hda_codec *codec)
8605 {
8606         struct alc_spec *spec = codec->spec;
8607         unsigned int presence;
8608         presence = snd_hda_codec_read(codec, 0x1b, 0,
8609                                       AC_VERB_GET_PIN_SENSE, 0);
8610         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8611         alc262_hp_master_update(codec);
8612 }
8613
8614 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
8615 {
8616         if ((res >> 26) != ALC880_HP_EVENT)
8617                 return;
8618         alc262_hp_bpc_automute(codec);
8619 }
8620
8621 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
8622 {
8623         struct alc_spec *spec = codec->spec;
8624         unsigned int presence;
8625         presence = snd_hda_codec_read(codec, 0x15, 0,
8626                                       AC_VERB_GET_PIN_SENSE, 0);
8627         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8628         alc262_hp_master_update(codec);
8629 }
8630
8631 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
8632                                            unsigned int res)
8633 {
8634         if ((res >> 26) != ALC880_HP_EVENT)
8635                 return;
8636         alc262_hp_wildwest_automute(codec);
8637 }
8638
8639 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
8640                                    struct snd_ctl_elem_value *ucontrol)
8641 {
8642         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8643         struct alc_spec *spec = codec->spec;
8644         *ucontrol->value.integer.value = spec->master_sw;
8645         return 0;
8646 }
8647
8648 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
8649                                    struct snd_ctl_elem_value *ucontrol)
8650 {
8651         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8652         struct alc_spec *spec = codec->spec;
8653         int val = !!*ucontrol->value.integer.value;
8654
8655         if (val == spec->master_sw)
8656                 return 0;
8657         spec->master_sw = val;
8658         alc262_hp_master_update(codec);
8659         return 1;
8660 }
8661
8662 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
8663         {
8664                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8665                 .name = "Master Playback Switch",
8666                 .info = snd_ctl_boolean_mono_info,
8667                 .get = alc262_hp_master_sw_get,
8668                 .put = alc262_hp_master_sw_put,
8669         },
8670         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8671         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8672         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8673         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8674                               HDA_OUTPUT),
8675         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8676                             HDA_OUTPUT),
8677         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8678         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8679         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8680         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8681         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8682         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8683         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8684         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8685         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8686         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8687         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8688         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8689         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
8690         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
8691         { } /* end */
8692 };
8693
8694 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
8695         {
8696                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8697                 .name = "Master Playback Switch",
8698                 .info = snd_ctl_boolean_mono_info,
8699                 .get = alc262_hp_master_sw_get,
8700                 .put = alc262_hp_master_sw_put,
8701         },
8702         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8703         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8704         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8705         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8706         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8707                               HDA_OUTPUT),
8708         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8709                             HDA_OUTPUT),
8710         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
8711         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
8712         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
8713         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8714         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8715         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8716         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8717         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8718         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8719         { } /* end */
8720 };
8721
8722 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
8723         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8724         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8725         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
8726         { } /* end */
8727 };
8728
8729 /* mute/unmute internal speaker according to the hp jack and mute state */
8730 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
8731 {
8732         struct alc_spec *spec = codec->spec;
8733
8734         if (force || !spec->sense_updated) {
8735                 unsigned int present;
8736                 present = snd_hda_codec_read(codec, 0x15, 0,
8737                                              AC_VERB_GET_PIN_SENSE, 0);
8738                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8739                 spec->sense_updated = 1;
8740         }
8741         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
8742                                  spec->jack_present ? HDA_AMP_MUTE : 0);
8743 }
8744
8745 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
8746                                         unsigned int res)
8747 {
8748         if ((res >> 26) != ALC880_HP_EVENT)
8749                 return;
8750         alc262_hp_t5735_automute(codec, 1);
8751 }
8752
8753 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
8754 {
8755         alc262_hp_t5735_automute(codec, 1);
8756 }
8757
8758 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
8759         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8760         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8761         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8762         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8763         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8764         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8765         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8766         { } /* end */
8767 };
8768
8769 static struct hda_verb alc262_hp_t5735_verbs[] = {
8770         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8771         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8772
8773         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8774         { }
8775 };
8776
8777 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
8778         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8779         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8780         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8781         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
8782         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8783         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8784         { } /* end */
8785 };
8786
8787 static struct hda_verb alc262_hp_rp5700_verbs[] = {
8788         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8789         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8790         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8791         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8792         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8793         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8794         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8795         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8796         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8797         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8798         {}
8799 };
8800
8801 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
8802         .num_items = 1,
8803         .items = {
8804                 { "Line", 0x1 },
8805         },
8806 };
8807
8808 /* bind hp and internal speaker mute (with plug check) */
8809 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
8810                                      struct snd_ctl_elem_value *ucontrol)
8811 {
8812         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8813         long *valp = ucontrol->value.integer.value;
8814         int change;
8815
8816         /* change hp mute */
8817         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
8818                                           HDA_AMP_MUTE,
8819                                           valp[0] ? 0 : HDA_AMP_MUTE);
8820         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
8821                                            HDA_AMP_MUTE,
8822                                            valp[1] ? 0 : HDA_AMP_MUTE);
8823         if (change) {
8824                 /* change speaker according to HP jack state */
8825                 struct alc_spec *spec = codec->spec;
8826                 unsigned int mute;
8827                 if (spec->jack_present)
8828                         mute = HDA_AMP_MUTE;
8829                 else
8830                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
8831                                                       HDA_OUTPUT, 0);
8832                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8833                                          HDA_AMP_MUTE, mute);
8834         }
8835         return change;
8836 }
8837
8838 static struct snd_kcontrol_new alc262_sony_mixer[] = {
8839         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8840         {
8841                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8842                 .name = "Master Playback Switch",
8843                 .info = snd_hda_mixer_amp_switch_info,
8844                 .get = snd_hda_mixer_amp_switch_get,
8845                 .put = alc262_sony_master_sw_put,
8846                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
8847         },
8848         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8849         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8850         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8851         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8852         { } /* end */
8853 };
8854
8855 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
8856         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8857         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8858         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8859         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8860         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8861         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8862         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8863         { } /* end */
8864 };
8865
8866 #define alc262_capture_mixer            alc882_capture_mixer
8867 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
8868
8869 /*
8870  * generic initialization of ADC, input mixers and output mixers
8871  */
8872 static struct hda_verb alc262_init_verbs[] = {
8873         /*
8874          * Unmute ADC0-2 and set the default input to mic-in
8875          */
8876         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8877         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8878         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8879         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8880         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8881         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8882
8883         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8884          * mixer widget
8885          * Note: PASD motherboards uses the Line In 2 as the input for
8886          * front panel mic (mic 2)
8887          */
8888         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8889         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8890         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8891         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8892         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8893         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8894
8895         /*
8896          * Set up output mixers (0x0c - 0x0e)
8897          */
8898         /* set vol=0 to output mixers */
8899         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8900         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8901         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8902         /* set up input amps for analog loopback */
8903         /* Amp Indices: DAC = 0, mixer = 1 */
8904         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8905         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8906         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8907         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8908         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8909         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8910
8911         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8912         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8913         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8914         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8915         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8916         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8917
8918         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8919         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8920         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8921         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8922         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8923         
8924         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8925         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8926         
8927         /* FIXME: use matrix-type input source selection */
8928         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8929         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8930         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8931         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8932         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8933         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8934         /* Input mixer2 */
8935         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8936         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8937         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8938         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8939         /* Input mixer3 */
8940         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8941         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8942         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8943         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8944
8945         { }
8946 };
8947
8948 static struct hda_verb alc262_hippo_unsol_verbs[] = {
8949         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8950         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8951         {}
8952 };
8953
8954 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
8955         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8956         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8957         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8958
8959         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8960         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8961         {}
8962 };
8963
8964 static struct hda_verb alc262_sony_unsol_verbs[] = {
8965         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8966         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8967         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
8968
8969         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8970         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8971         {}
8972 };
8973
8974 /* mute/unmute internal speaker according to the hp jack and mute state */
8975 static void alc262_hippo_automute(struct hda_codec *codec)
8976 {
8977         struct alc_spec *spec = codec->spec;
8978         unsigned int mute;
8979         unsigned int present;
8980
8981         /* need to execute and sync at first */
8982         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8983         present = snd_hda_codec_read(codec, 0x15, 0,
8984                                      AC_VERB_GET_PIN_SENSE, 0);
8985         spec->jack_present = (present & 0x80000000) != 0;
8986         if (spec->jack_present) {
8987                 /* mute internal speaker */
8988                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8989                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8990         } else {
8991                 /* unmute internal speaker if necessary */
8992                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8993                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8994                                          HDA_AMP_MUTE, mute);
8995         }
8996 }
8997
8998 /* unsolicited event for HP jack sensing */
8999 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9000                                        unsigned int res)
9001 {
9002         if ((res >> 26) != ALC880_HP_EVENT)
9003                 return;
9004         alc262_hippo_automute(codec);
9005 }
9006
9007 static void alc262_hippo1_automute(struct hda_codec *codec)
9008 {
9009         unsigned int mute;
9010         unsigned int present;
9011
9012         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9013         present = snd_hda_codec_read(codec, 0x1b, 0,
9014                                      AC_VERB_GET_PIN_SENSE, 0);
9015         present = (present & 0x80000000) != 0;
9016         if (present) {
9017                 /* mute internal speaker */
9018                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9019                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9020         } else {
9021                 /* unmute internal speaker if necessary */
9022                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9023                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9024                                          HDA_AMP_MUTE, mute);
9025         }
9026 }
9027
9028 /* unsolicited event for HP jack sensing */
9029 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9030                                        unsigned int res)
9031 {
9032         if ((res >> 26) != ALC880_HP_EVENT)
9033                 return;
9034         alc262_hippo1_automute(codec);
9035 }
9036
9037 /*
9038  * nec model
9039  *  0x15 = headphone
9040  *  0x16 = internal speaker
9041  *  0x18 = external mic
9042  */
9043
9044 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9045         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9046         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9047
9048         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9049         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9050         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9051
9052         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9053         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9054         { } /* end */
9055 };
9056
9057 static struct hda_verb alc262_nec_verbs[] = {
9058         /* Unmute Speaker */
9059         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9060
9061         /* Headphone */
9062         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9063         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9064
9065         /* External mic to headphone */
9066         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9067         /* External mic to speaker */
9068         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9069         {}
9070 };
9071
9072 /*
9073  * fujitsu model
9074  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9075  *  0x1b = port replicator headphone out
9076  */
9077
9078 #define ALC_HP_EVENT    0x37
9079
9080 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9081         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9082         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9083         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9084         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9085         {}
9086 };
9087
9088 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9089         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9090         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9091         {}
9092 };
9093
9094 static struct hda_input_mux alc262_fujitsu_capture_source = {
9095         .num_items = 3,
9096         .items = {
9097                 { "Mic", 0x0 },
9098                 { "Int Mic", 0x1 },
9099                 { "CD", 0x4 },
9100         },
9101 };
9102
9103 static struct hda_input_mux alc262_HP_capture_source = {
9104         .num_items = 5,
9105         .items = {
9106                 { "Mic", 0x0 },
9107                 { "Front Mic", 0x1 },
9108                 { "Line", 0x2 },
9109                 { "CD", 0x4 },
9110                 { "AUX IN", 0x6 },
9111         },
9112 };
9113
9114 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9115         .num_items = 4,
9116         .items = {
9117                 { "Mic", 0x0 },
9118                 { "Front Mic", 0x2 },
9119                 { "Line", 0x1 },
9120                 { "CD", 0x4 },
9121         },
9122 };
9123
9124 /* mute/unmute internal speaker according to the hp jacks and mute state */
9125 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9126 {
9127         struct alc_spec *spec = codec->spec;
9128         unsigned int mute;
9129
9130         if (force || !spec->sense_updated) {
9131                 unsigned int present;
9132                 /* need to execute and sync at first */
9133                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9134                 /* check laptop HP jack */
9135                 present = snd_hda_codec_read(codec, 0x14, 0,
9136                                              AC_VERB_GET_PIN_SENSE, 0);
9137                 /* need to execute and sync at first */
9138                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9139                 /* check docking HP jack */
9140                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9141                                               AC_VERB_GET_PIN_SENSE, 0);
9142                 if (present & AC_PINSENSE_PRESENCE)
9143                         spec->jack_present = 1;
9144                 else
9145                         spec->jack_present = 0;
9146                 spec->sense_updated = 1;
9147         }
9148         /* unmute internal speaker only if both HPs are unplugged and
9149          * master switch is on
9150          */
9151         if (spec->jack_present)
9152                 mute = HDA_AMP_MUTE;
9153         else
9154                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9155         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9156                                  HDA_AMP_MUTE, mute);
9157 }
9158
9159 /* unsolicited event for HP jack sensing */
9160 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9161                                        unsigned int res)
9162 {
9163         if ((res >> 26) != ALC_HP_EVENT)
9164                 return;
9165         alc262_fujitsu_automute(codec, 1);
9166 }
9167
9168 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9169 {
9170         alc262_fujitsu_automute(codec, 1);
9171 }
9172
9173 /* bind volumes of both NID 0x0c and 0x0d */
9174 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9175         .ops = &snd_hda_bind_vol,
9176         .values = {
9177                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9178                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9179                 0
9180         },
9181 };
9182
9183 /* mute/unmute internal speaker according to the hp jack and mute state */
9184 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9185 {
9186         struct alc_spec *spec = codec->spec;
9187         unsigned int mute;
9188
9189         if (force || !spec->sense_updated) {
9190                 unsigned int present_int_hp;
9191                 /* need to execute and sync at first */
9192                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9193                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9194                                         AC_VERB_GET_PIN_SENSE, 0);
9195                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9196                 spec->sense_updated = 1;
9197         }
9198         if (spec->jack_present) {
9199                 /* mute internal speaker */
9200                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9201                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9202                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9203                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9204         } else {
9205                 /* unmute internal speaker if necessary */
9206                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9207                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9208                                          HDA_AMP_MUTE, mute);
9209                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9210                                          HDA_AMP_MUTE, mute);
9211         }
9212 }
9213
9214 /* unsolicited event for HP jack sensing */
9215 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9216                                        unsigned int res)
9217 {
9218         if ((res >> 26) != ALC_HP_EVENT)
9219                 return;
9220         alc262_lenovo_3000_automute(codec, 1);
9221 }
9222
9223 static int amp_stereo_mute_update(struct hda_codec *codec, hda_nid_t nid,
9224                                   int dir, int idx, long *valp)
9225 {
9226         int i, change = 0;
9227
9228         for (i = 0; i < 2; i++, valp++)
9229                 change |= snd_hda_codec_amp_update(codec, nid, i, dir, idx,
9230                                                    HDA_AMP_MUTE,
9231                                                    *valp ? 0 : HDA_AMP_MUTE);
9232         return change;
9233 }
9234
9235 /* bind hp and internal speaker mute (with plug check) */
9236 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9237                                          struct snd_ctl_elem_value *ucontrol)
9238 {
9239         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9240         long *valp = ucontrol->value.integer.value;
9241         int change;
9242
9243         change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
9244         change |= amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
9245         if (change)
9246                 alc262_fujitsu_automute(codec, 0);
9247         return change;
9248 }
9249
9250 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9251         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9252         {
9253                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9254                 .name = "Master Playback Switch",
9255                 .info = snd_hda_mixer_amp_switch_info,
9256                 .get = snd_hda_mixer_amp_switch_get,
9257                 .put = alc262_fujitsu_master_sw_put,
9258                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9259         },
9260         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9261         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9262         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9263         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9264         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9265         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9266         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9267         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9268         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9269         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9270         { } /* end */
9271 };
9272
9273 /* bind hp and internal speaker mute (with plug check) */
9274 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9275                                          struct snd_ctl_elem_value *ucontrol)
9276 {
9277         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9278         long *valp = ucontrol->value.integer.value;
9279         int change;
9280
9281         change = amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
9282         if (change)
9283                 alc262_lenovo_3000_automute(codec, 0);
9284         return change;
9285 }
9286
9287 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9288         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9289         {
9290                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9291                 .name = "Master Playback Switch",
9292                 .info = snd_hda_mixer_amp_switch_info,
9293                 .get = snd_hda_mixer_amp_switch_get,
9294                 .put = alc262_lenovo_3000_master_sw_put,
9295                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9296         },
9297         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9298         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9299         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9300         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9301         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9302         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9303         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9304         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9305         { } /* end */
9306 };
9307
9308 /* additional init verbs for Benq laptops */
9309 static struct hda_verb alc262_EAPD_verbs[] = {
9310         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9311         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9312         {}
9313 };
9314
9315 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9316         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9317         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9318
9319         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9320         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9321         {}
9322 };
9323
9324 /* Samsung Q1 Ultra Vista model setup */
9325 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9326         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9327         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9328         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9329         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9330         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9331         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9332         { } /* end */
9333 };
9334
9335 static struct hda_verb alc262_ultra_verbs[] = {
9336         /* output mixer */
9337         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9338         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9339         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9340         /* speaker */
9341         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9342         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9343         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9344         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9345         /* HP */
9346         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9347         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9348         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9349         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9350         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9351         /* internal mic */
9352         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9353         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9354         /* ADC, choose mic */
9355         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9356         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9357         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9358         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9359         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9360         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9361         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9362         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9363         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9364         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
9365         {}
9366 };
9367
9368 /* mute/unmute internal speaker according to the hp jack and mute state */
9369 static void alc262_ultra_automute(struct hda_codec *codec)
9370 {
9371         struct alc_spec *spec = codec->spec;
9372         unsigned int mute;
9373
9374         mute = 0;
9375         /* auto-mute only when HP is used as HP */
9376         if (!spec->cur_mux[0]) {
9377                 unsigned int present;
9378                 /* need to execute and sync at first */
9379                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9380                 present = snd_hda_codec_read(codec, 0x15, 0,
9381                                              AC_VERB_GET_PIN_SENSE, 0);
9382                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9383                 if (spec->jack_present)
9384                         mute = HDA_AMP_MUTE;
9385         }
9386         /* mute/unmute internal speaker */
9387         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9388                                  HDA_AMP_MUTE, mute);
9389         /* mute/unmute HP */
9390         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9391                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
9392 }
9393
9394 /* unsolicited event for HP jack sensing */
9395 static void alc262_ultra_unsol_event(struct hda_codec *codec,
9396                                        unsigned int res)
9397 {
9398         if ((res >> 26) != ALC880_HP_EVENT)
9399                 return;
9400         alc262_ultra_automute(codec);
9401 }
9402
9403 static struct hda_input_mux alc262_ultra_capture_source = {
9404         .num_items = 2,
9405         .items = {
9406                 { "Mic", 0x1 },
9407                 { "Headphone", 0x7 },
9408         },
9409 };
9410
9411 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
9412                                      struct snd_ctl_elem_value *ucontrol)
9413 {
9414         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9415         struct alc_spec *spec = codec->spec;
9416         int ret;
9417
9418         ret = alc882_mux_enum_put(kcontrol, ucontrol);
9419         if (!ret)
9420                 return 0;
9421         /* reprogram the HP pin as mic or HP according to the input source */
9422         snd_hda_codec_write_cache(codec, 0x15, 0,
9423                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9424                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
9425         alc262_ultra_automute(codec); /* mute/unmute HP */
9426         return ret;
9427 }
9428
9429 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
9430         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
9431         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
9432         {
9433                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9434                 .name = "Capture Source",
9435                 .info = alc882_mux_enum_info,
9436                 .get = alc882_mux_enum_get,
9437                 .put = alc262_ultra_mux_enum_put,
9438         },
9439         { } /* end */
9440 };
9441
9442 /* add playback controls from the parsed DAC table */
9443 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
9444                                              const struct auto_pin_cfg *cfg)
9445 {
9446         hda_nid_t nid;
9447         int err;
9448
9449         spec->multiout.num_dacs = 1;    /* only use one dac */
9450         spec->multiout.dac_nids = spec->private_dac_nids;
9451         spec->multiout.dac_nids[0] = 2;
9452
9453         nid = cfg->line_out_pins[0];
9454         if (nid) {
9455                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9456                                   "Front Playback Volume",
9457                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
9458                 if (err < 0)
9459                         return err;
9460                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9461                                   "Front Playback Switch",
9462                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9463                 if (err < 0)
9464                         return err;
9465         }
9466
9467         nid = cfg->speaker_pins[0];
9468         if (nid) {
9469                 if (nid == 0x16) {
9470                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9471                                           "Speaker Playback Volume",
9472                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9473                                                               HDA_OUTPUT));
9474                         if (err < 0)
9475                                 return err;
9476                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9477                                           "Speaker Playback Switch",
9478                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9479                                                               HDA_OUTPUT));
9480                         if (err < 0)
9481                                 return err;
9482                 } else {
9483                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9484                                           "Speaker Playback Switch",
9485                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9486                                                               HDA_OUTPUT));
9487                         if (err < 0)
9488                                 return err;
9489                 }
9490         }
9491         nid = cfg->hp_pins[0];
9492         if (nid) {
9493                 /* spec->multiout.hp_nid = 2; */
9494                 if (nid == 0x16) {
9495                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9496                                           "Headphone Playback Volume",
9497                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9498                                                               HDA_OUTPUT));
9499                         if (err < 0)
9500                                 return err;
9501                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9502                                           "Headphone Playback Switch",
9503                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9504                                                               HDA_OUTPUT));
9505                         if (err < 0)
9506                                 return err;
9507                 } else {
9508                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9509                                           "Headphone Playback Switch",
9510                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9511                                                               HDA_OUTPUT));
9512                         if (err < 0)
9513                                 return err;
9514                 }
9515         }
9516         return 0;
9517 }
9518
9519 /* identical with ALC880 */
9520 #define alc262_auto_create_analog_input_ctls \
9521         alc880_auto_create_analog_input_ctls
9522
9523 /*
9524  * generic initialization of ADC, input mixers and output mixers
9525  */
9526 static struct hda_verb alc262_volume_init_verbs[] = {
9527         /*
9528          * Unmute ADC0-2 and set the default input to mic-in
9529          */
9530         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9531         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9532         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9533         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9534         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9535         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9536
9537         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9538          * mixer widget
9539          * Note: PASD motherboards uses the Line In 2 as the input for
9540          * front panel mic (mic 2)
9541          */
9542         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9543         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9544         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9545         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9546         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9547         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9548
9549         /*
9550          * Set up output mixers (0x0c - 0x0f)
9551          */
9552         /* set vol=0 to output mixers */
9553         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9554         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9555         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9556         
9557         /* set up input amps for analog loopback */
9558         /* Amp Indices: DAC = 0, mixer = 1 */
9559         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9560         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9561         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9562         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9563         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9564         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9565
9566         /* FIXME: use matrix-type input source selection */
9567         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9568         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9569         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9570         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9571         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9572         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9573         /* Input mixer2 */
9574         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9575         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9576         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9577         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9578         /* Input mixer3 */
9579         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9580         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9581         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9582         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9583
9584         { }
9585 };
9586
9587 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
9588         /*
9589          * Unmute ADC0-2 and set the default input to mic-in
9590          */
9591         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9592         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9593         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9594         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9595         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9596         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9597
9598         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9599          * mixer widget
9600          * Note: PASD motherboards uses the Line In 2 as the input for
9601          * front panel mic (mic 2)
9602          */
9603         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9604         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9605         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9606         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9607         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9608         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9609         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9610         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9611         
9612         /*
9613          * Set up output mixers (0x0c - 0x0e)
9614          */
9615         /* set vol=0 to output mixers */
9616         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9617         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9618         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9619
9620         /* set up input amps for analog loopback */
9621         /* Amp Indices: DAC = 0, mixer = 1 */
9622         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9623         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9624         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9625         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9626         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9627         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9628
9629         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9630         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9631         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9632
9633         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9634         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9635
9636         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9637         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9638
9639         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9640         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9641         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9642         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9643         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9644
9645         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9646         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9647         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9648         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9649         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9650         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9651
9652
9653         /* FIXME: use matrix-type input source selection */
9654         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9655         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9656         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9657         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9658         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9659         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9660         /* Input mixer2 */
9661         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9662         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9663         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9664         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9665         /* Input mixer3 */
9666         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9667         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9668         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9669         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9670
9671         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9672
9673         { }
9674 };
9675
9676 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
9677         /*
9678          * Unmute ADC0-2 and set the default input to mic-in
9679          */
9680         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9681         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9682         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9683         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9684         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9685         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9686
9687         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9688          * mixer widget
9689          * Note: PASD motherboards uses the Line In 2 as the input for front
9690          * panel mic (mic 2)
9691          */
9692         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9693         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9694         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9695         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9696         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9697         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9698         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9699         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9700         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9701         /*
9702          * Set up output mixers (0x0c - 0x0e)
9703          */
9704         /* set vol=0 to output mixers */
9705         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9706         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9707         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9708
9709         /* set up input amps for analog loopback */
9710         /* Amp Indices: DAC = 0, mixer = 1 */
9711         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9712         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9713         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9714         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9715         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9716         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9717
9718
9719         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
9720         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
9721         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
9722         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
9723         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
9724         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
9725         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
9726
9727         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9728         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9729
9730         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9731         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9732
9733         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
9734         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9735         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9736         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9737         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9738         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9739
9740         /* FIXME: use matrix-type input source selection */
9741         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9742         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9743         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
9744         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
9745         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
9746         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
9747         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
9748         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
9749         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
9750         /* Input mixer2 */
9751         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9752         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9753         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9754         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9755         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9756         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9757         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9758         /* Input mixer3 */
9759         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9760         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9761         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9762         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9763         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9764         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9765         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9766
9767         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9768
9769         { }
9770 };
9771
9772 #ifdef CONFIG_SND_HDA_POWER_SAVE
9773 #define alc262_loopbacks        alc880_loopbacks
9774 #endif
9775
9776 /* pcm configuration: identiacal with ALC880 */
9777 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
9778 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
9779 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
9780 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
9781
9782 /*
9783  * BIOS auto configuration
9784  */
9785 static int alc262_parse_auto_config(struct hda_codec *codec)
9786 {
9787         struct alc_spec *spec = codec->spec;
9788         int err;
9789         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
9790
9791         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9792                                            alc262_ignore);
9793         if (err < 0)
9794                 return err;
9795         if (!spec->autocfg.line_outs)
9796                 return 0; /* can't find valid BIOS pin config */
9797         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
9798         if (err < 0)
9799                 return err;
9800         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
9801         if (err < 0)
9802                 return err;
9803
9804         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9805
9806         if (spec->autocfg.dig_out_pin)
9807                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
9808         if (spec->autocfg.dig_in_pin)
9809                 spec->dig_in_nid = ALC262_DIGIN_NID;
9810
9811         if (spec->kctl_alloc)
9812                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9813
9814         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
9815         spec->num_mux_defs = 1;
9816         spec->input_mux = &spec->private_imux;
9817
9818         err = alc_auto_add_mic_boost(codec);
9819         if (err < 0)
9820                 return err;
9821
9822         store_pin_configs(codec);
9823         return 1;
9824 }
9825
9826 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
9827 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
9828 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
9829 #define alc262_auto_init_input_src      alc882_auto_init_input_src
9830
9831
9832 /* init callback for auto-configuration model -- overriding the default init */
9833 static void alc262_auto_init(struct hda_codec *codec)
9834 {
9835         struct alc_spec *spec = codec->spec;
9836         alc262_auto_init_multi_out(codec);
9837         alc262_auto_init_hp_out(codec);
9838         alc262_auto_init_analog_input(codec);
9839         alc262_auto_init_input_src(codec);
9840         if (spec->unsol_event)
9841                 alc_sku_automute(codec);
9842 }
9843
9844 /*
9845  * configuration and preset
9846  */
9847 static const char *alc262_models[ALC262_MODEL_LAST] = {
9848         [ALC262_BASIC]          = "basic",
9849         [ALC262_HIPPO]          = "hippo",
9850         [ALC262_HIPPO_1]        = "hippo_1",
9851         [ALC262_FUJITSU]        = "fujitsu",
9852         [ALC262_HP_BPC]         = "hp-bpc",
9853         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
9854         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
9855         [ALC262_HP_RP5700]      = "hp-rp5700",
9856         [ALC262_BENQ_ED8]       = "benq",
9857         [ALC262_BENQ_T31]       = "benq-t31",
9858         [ALC262_SONY_ASSAMD]    = "sony-assamd",
9859         [ALC262_ULTRA]          = "ultra",
9860         [ALC262_LENOVO_3000]    = "lenovo-3000",
9861         [ALC262_NEC]            = "nec",
9862         [ALC262_AUTO]           = "auto",
9863 };
9864
9865 static struct snd_pci_quirk alc262_cfg_tbl[] = {
9866         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
9867         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
9868         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
9869         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
9870         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
9871         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
9872         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
9873         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
9874         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
9875         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
9876         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
9877         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
9878         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
9879         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
9880         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
9881         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
9882         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
9883         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
9884         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
9885         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
9886         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
9887         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
9888                       ALC262_HP_TC_T5735),
9889         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
9890         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9891         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
9892         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9893         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9894         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
9895         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
9896                       ALC262_SONY_ASSAMD),
9897         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
9898         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
9899         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
9900         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
9901         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
9902         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
9903         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
9904         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
9905         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
9906         {}
9907 };
9908
9909 static struct alc_config_preset alc262_presets[] = {
9910         [ALC262_BASIC] = {
9911                 .mixers = { alc262_base_mixer },
9912                 .init_verbs = { alc262_init_verbs },
9913                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9914                 .dac_nids = alc262_dac_nids,
9915                 .hp_nid = 0x03,
9916                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9917                 .channel_mode = alc262_modes,
9918                 .input_mux = &alc262_capture_source,
9919         },
9920         [ALC262_HIPPO] = {
9921                 .mixers = { alc262_base_mixer },
9922                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
9923                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9924                 .dac_nids = alc262_dac_nids,
9925                 .hp_nid = 0x03,
9926                 .dig_out_nid = ALC262_DIGOUT_NID,
9927                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9928                 .channel_mode = alc262_modes,
9929                 .input_mux = &alc262_capture_source,
9930                 .unsol_event = alc262_hippo_unsol_event,
9931                 .init_hook = alc262_hippo_automute,
9932         },
9933         [ALC262_HIPPO_1] = {
9934                 .mixers = { alc262_hippo1_mixer },
9935                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
9936                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9937                 .dac_nids = alc262_dac_nids,
9938                 .hp_nid = 0x02,
9939                 .dig_out_nid = ALC262_DIGOUT_NID,
9940                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9941                 .channel_mode = alc262_modes,
9942                 .input_mux = &alc262_capture_source,
9943                 .unsol_event = alc262_hippo1_unsol_event,
9944                 .init_hook = alc262_hippo1_automute,
9945         },
9946         [ALC262_FUJITSU] = {
9947                 .mixers = { alc262_fujitsu_mixer },
9948                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9949                                 alc262_fujitsu_unsol_verbs },
9950                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9951                 .dac_nids = alc262_dac_nids,
9952                 .hp_nid = 0x03,
9953                 .dig_out_nid = ALC262_DIGOUT_NID,
9954                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9955                 .channel_mode = alc262_modes,
9956                 .input_mux = &alc262_fujitsu_capture_source,
9957                 .unsol_event = alc262_fujitsu_unsol_event,
9958                 .init_hook = alc262_fujitsu_init_hook,
9959         },
9960         [ALC262_HP_BPC] = {
9961                 .mixers = { alc262_HP_BPC_mixer },
9962                 .init_verbs = { alc262_HP_BPC_init_verbs },
9963                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9964                 .dac_nids = alc262_dac_nids,
9965                 .hp_nid = 0x03,
9966                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9967                 .channel_mode = alc262_modes,
9968                 .input_mux = &alc262_HP_capture_source,
9969                 .unsol_event = alc262_hp_bpc_unsol_event,
9970                 .init_hook = alc262_hp_bpc_automute,
9971         },
9972         [ALC262_HP_BPC_D7000_WF] = {
9973                 .mixers = { alc262_HP_BPC_WildWest_mixer },
9974                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9975                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9976                 .dac_nids = alc262_dac_nids,
9977                 .hp_nid = 0x03,
9978                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9979                 .channel_mode = alc262_modes,
9980                 .input_mux = &alc262_HP_D7000_capture_source,
9981                 .unsol_event = alc262_hp_wildwest_unsol_event,
9982                 .init_hook = alc262_hp_wildwest_automute,
9983         },
9984         [ALC262_HP_BPC_D7000_WL] = {
9985                 .mixers = { alc262_HP_BPC_WildWest_mixer,
9986                             alc262_HP_BPC_WildWest_option_mixer },
9987                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9988                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9989                 .dac_nids = alc262_dac_nids,
9990                 .hp_nid = 0x03,
9991                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9992                 .channel_mode = alc262_modes,
9993                 .input_mux = &alc262_HP_D7000_capture_source,
9994                 .unsol_event = alc262_hp_wildwest_unsol_event,
9995                 .init_hook = alc262_hp_wildwest_automute,
9996         },
9997         [ALC262_HP_TC_T5735] = {
9998                 .mixers = { alc262_hp_t5735_mixer },
9999                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10000                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10001                 .dac_nids = alc262_dac_nids,
10002                 .hp_nid = 0x03,
10003                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10004                 .channel_mode = alc262_modes,
10005                 .input_mux = &alc262_capture_source,
10006                 .unsol_event = alc262_hp_t5735_unsol_event,
10007                 .init_hook = alc262_hp_t5735_init_hook,
10008         },
10009         [ALC262_HP_RP5700] = {
10010                 .mixers = { alc262_hp_rp5700_mixer },
10011                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10012                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10013                 .dac_nids = alc262_dac_nids,
10014                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10015                 .channel_mode = alc262_modes,
10016                 .input_mux = &alc262_hp_rp5700_capture_source,
10017         },
10018         [ALC262_BENQ_ED8] = {
10019                 .mixers = { alc262_base_mixer },
10020                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
10021                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10022                 .dac_nids = alc262_dac_nids,
10023                 .hp_nid = 0x03,
10024                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10025                 .channel_mode = alc262_modes,
10026                 .input_mux = &alc262_capture_source,
10027         },
10028         [ALC262_SONY_ASSAMD] = {
10029                 .mixers = { alc262_sony_mixer },
10030                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10031                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10032                 .dac_nids = alc262_dac_nids,
10033                 .hp_nid = 0x02,
10034                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10035                 .channel_mode = alc262_modes,
10036                 .input_mux = &alc262_capture_source,
10037                 .unsol_event = alc262_hippo_unsol_event,
10038                 .init_hook = alc262_hippo_automute,
10039         },
10040         [ALC262_BENQ_T31] = {
10041                 .mixers = { alc262_benq_t31_mixer },
10042                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10043                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10044                 .dac_nids = alc262_dac_nids,
10045                 .hp_nid = 0x03,
10046                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10047                 .channel_mode = alc262_modes,
10048                 .input_mux = &alc262_capture_source,
10049                 .unsol_event = alc262_hippo_unsol_event,
10050                 .init_hook = alc262_hippo_automute,
10051         },      
10052         [ALC262_ULTRA] = {
10053                 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
10054                 .init_verbs = { alc262_ultra_verbs },
10055                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10056                 .dac_nids = alc262_dac_nids,
10057                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10058                 .channel_mode = alc262_modes,
10059                 .input_mux = &alc262_ultra_capture_source,
10060                 .adc_nids = alc262_adc_nids, /* ADC0 */
10061                 .capsrc_nids = alc262_capsrc_nids,
10062                 .num_adc_nids = 1, /* single ADC */
10063                 .unsol_event = alc262_ultra_unsol_event,
10064                 .init_hook = alc262_ultra_automute,
10065         },
10066         [ALC262_LENOVO_3000] = {
10067                 .mixers = { alc262_lenovo_3000_mixer },
10068                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10069                                 alc262_lenovo_3000_unsol_verbs },
10070                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10071                 .dac_nids = alc262_dac_nids,
10072                 .hp_nid = 0x03,
10073                 .dig_out_nid = ALC262_DIGOUT_NID,
10074                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10075                 .channel_mode = alc262_modes,
10076                 .input_mux = &alc262_fujitsu_capture_source,
10077                 .unsol_event = alc262_lenovo_3000_unsol_event,
10078         },
10079         [ALC262_NEC] = {
10080                 .mixers = { alc262_nec_mixer },
10081                 .init_verbs = { alc262_nec_verbs },
10082                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10083                 .dac_nids = alc262_dac_nids,
10084                 .hp_nid = 0x03,
10085                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10086                 .channel_mode = alc262_modes,
10087                 .input_mux = &alc262_capture_source,
10088         },
10089 };
10090
10091 static int patch_alc262(struct hda_codec *codec)
10092 {
10093         struct alc_spec *spec;
10094         int board_config;
10095         int err;
10096
10097         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10098         if (spec == NULL)
10099                 return -ENOMEM;
10100
10101         codec->spec = spec;
10102 #if 0
10103         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10104          * under-run
10105          */
10106         {
10107         int tmp;
10108         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10109         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10110         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10111         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10112         }
10113 #endif
10114
10115         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10116
10117         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10118                                                   alc262_models,
10119                                                   alc262_cfg_tbl);
10120
10121         if (board_config < 0) {
10122                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10123                        "trying auto-probe from BIOS...\n");
10124                 board_config = ALC262_AUTO;
10125         }
10126
10127         if (board_config == ALC262_AUTO) {
10128                 /* automatic parse from the BIOS config */
10129                 err = alc262_parse_auto_config(codec);
10130                 if (err < 0) {
10131                         alc_free(codec);
10132                         return err;
10133                 } else if (!err) {
10134                         printk(KERN_INFO
10135                                "hda_codec: Cannot set up configuration "
10136                                "from BIOS.  Using base mode...\n");
10137                         board_config = ALC262_BASIC;
10138                 }
10139         }
10140
10141         if (board_config != ALC262_AUTO)
10142                 setup_preset(spec, &alc262_presets[board_config]);
10143
10144         spec->stream_name_analog = "ALC262 Analog";
10145         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10146         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10147                 
10148         spec->stream_name_digital = "ALC262 Digital";
10149         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10150         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10151
10152         if (!spec->adc_nids && spec->input_mux) {
10153                 /* check whether NID 0x07 is valid */
10154                 unsigned int wcap = get_wcaps(codec, 0x07);
10155
10156                 /* get type */
10157                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10158                 if (wcap != AC_WID_AUD_IN) {
10159                         spec->adc_nids = alc262_adc_nids_alt;
10160                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10161                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10162                         spec->mixers[spec->num_mixers] =
10163                                 alc262_capture_alt_mixer;
10164                         spec->num_mixers++;
10165                 } else {
10166                         spec->adc_nids = alc262_adc_nids;
10167                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10168                         spec->capsrc_nids = alc262_capsrc_nids;
10169                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
10170                         spec->num_mixers++;
10171                 }
10172         }
10173
10174         spec->vmaster_nid = 0x0c;
10175
10176         codec->patch_ops = alc_patch_ops;
10177         if (board_config == ALC262_AUTO)
10178                 spec->init_hook = alc262_auto_init;
10179 #ifdef CONFIG_SND_HDA_POWER_SAVE
10180         if (!spec->loopback.amplist)
10181                 spec->loopback.amplist = alc262_loopbacks;
10182 #endif
10183                 
10184         return 0;
10185 }
10186
10187 /*
10188  *  ALC268 channel source setting (2 channel)
10189  */
10190 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10191 #define alc268_modes            alc260_modes
10192         
10193 static hda_nid_t alc268_dac_nids[2] = {
10194         /* front, hp */
10195         0x02, 0x03
10196 };
10197
10198 static hda_nid_t alc268_adc_nids[2] = {
10199         /* ADC0-1 */
10200         0x08, 0x07
10201 };
10202
10203 static hda_nid_t alc268_adc_nids_alt[1] = {
10204         /* ADC0 */
10205         0x08
10206 };
10207
10208 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10209
10210 static struct snd_kcontrol_new alc268_base_mixer[] = {
10211         /* output mixer control */
10212         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10213         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10214         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10215         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10216         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10217         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10218         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10219         { }
10220 };
10221
10222 /* bind Beep switches of both NID 0x0f and 0x10 */
10223 static struct hda_bind_ctls alc268_bind_beep_sw = {
10224         .ops = &snd_hda_bind_sw,
10225         .values = {
10226                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10227                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10228                 0
10229         },
10230 };
10231
10232 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10233         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10234         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10235         { }
10236 };
10237
10238 static struct hda_verb alc268_eapd_verbs[] = {
10239         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10240         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10241         { }
10242 };
10243
10244 /* Toshiba specific */
10245 #define alc268_toshiba_automute alc262_hippo_automute
10246
10247 static struct hda_verb alc268_toshiba_verbs[] = {
10248         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10249         { } /* end */
10250 };
10251
10252 /* Acer specific */
10253 /* bind volumes of both NID 0x02 and 0x03 */
10254 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10255         .ops = &snd_hda_bind_vol,
10256         .values = {
10257                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10258                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10259                 0
10260         },
10261 };
10262
10263 /* mute/unmute internal speaker according to the hp jack and mute state */
10264 static void alc268_acer_automute(struct hda_codec *codec, int force)
10265 {
10266         struct alc_spec *spec = codec->spec;
10267         unsigned int mute;
10268
10269         if (force || !spec->sense_updated) {
10270                 unsigned int present;
10271                 present = snd_hda_codec_read(codec, 0x14, 0,
10272                                          AC_VERB_GET_PIN_SENSE, 0);
10273                 spec->jack_present = (present & 0x80000000) != 0;
10274                 spec->sense_updated = 1;
10275         }
10276         if (spec->jack_present)
10277                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10278         else /* unmute internal speaker if necessary */
10279                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10280         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10281                                  HDA_AMP_MUTE, mute);
10282 }
10283
10284
10285 /* bind hp and internal speaker mute (with plug check) */
10286 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10287                                      struct snd_ctl_elem_value *ucontrol)
10288 {
10289         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10290         long *valp = ucontrol->value.integer.value;
10291         int change;
10292
10293         change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
10294         if (change)
10295                 alc268_acer_automute(codec, 0);
10296         return change;
10297 }
10298
10299 static struct snd_kcontrol_new alc268_acer_mixer[] = {
10300         /* output mixer control */
10301         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10302         {
10303                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10304                 .name = "Master Playback Switch",
10305                 .info = snd_hda_mixer_amp_switch_info,
10306                 .get = snd_hda_mixer_amp_switch_get,
10307                 .put = alc268_acer_master_sw_put,
10308                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10309         },
10310         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10311         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10312         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10313         { }
10314 };
10315
10316 static struct hda_verb alc268_acer_verbs[] = {
10317         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
10318         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10319         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10320         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10321         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10322         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10323
10324         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10325         { }
10326 };
10327
10328 /* unsolicited event for HP jack sensing */
10329 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
10330                                        unsigned int res)
10331 {
10332         if ((res >> 26) != ALC880_HP_EVENT)
10333                 return;
10334         alc268_toshiba_automute(codec);
10335 }
10336
10337 static void alc268_acer_unsol_event(struct hda_codec *codec,
10338                                        unsigned int res)
10339 {
10340         if ((res >> 26) != ALC880_HP_EVENT)
10341                 return;
10342         alc268_acer_automute(codec, 1);
10343 }
10344
10345 static void alc268_acer_init_hook(struct hda_codec *codec)
10346 {
10347         alc268_acer_automute(codec, 1);
10348 }
10349
10350 static struct snd_kcontrol_new alc268_dell_mixer[] = {
10351         /* output mixer control */
10352         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10353         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10354         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10355         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10356         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10357         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10358         { }
10359 };
10360
10361 static struct hda_verb alc268_dell_verbs[] = {
10362         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10363         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10364         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10365         { }
10366 };
10367
10368 /* mute/unmute internal speaker according to the hp jack and mute state */
10369 static void alc268_dell_automute(struct hda_codec *codec)
10370 {
10371         unsigned int present;
10372         unsigned int mute;
10373
10374         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
10375         if (present & 0x80000000)
10376                 mute = HDA_AMP_MUTE;
10377         else
10378                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
10379         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10380                                  HDA_AMP_MUTE, mute);
10381 }
10382
10383 static void alc268_dell_unsol_event(struct hda_codec *codec,
10384                                     unsigned int res)
10385 {
10386         if ((res >> 26) != ALC880_HP_EVENT)
10387                 return;
10388         alc268_dell_automute(codec);
10389 }
10390
10391 #define alc268_dell_init_hook   alc268_dell_automute
10392
10393 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
10394         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10395         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10396         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10397         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10398         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10399         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
10400         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
10401         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10402         { }
10403 };
10404
10405 static struct hda_verb alc267_quanta_il1_verbs[] = {
10406         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10407         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
10408         { }
10409 };
10410
10411 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
10412 {
10413         unsigned int present;
10414
10415         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
10416                 & AC_PINSENSE_PRESENCE;
10417         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
10418                             present ? 0 : PIN_OUT);
10419 }
10420
10421 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
10422 {
10423         unsigned int present;
10424
10425         present = snd_hda_codec_read(codec, 0x18, 0,
10426                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10427         snd_hda_codec_write(codec, 0x23, 0,
10428                             AC_VERB_SET_CONNECT_SEL,
10429                             present ? 0x00 : 0x01);
10430 }
10431
10432 static void alc267_quanta_il1_automute(struct hda_codec *codec)
10433 {
10434         alc267_quanta_il1_hp_automute(codec);
10435         alc267_quanta_il1_mic_automute(codec);
10436 }
10437
10438 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
10439                                            unsigned int res)
10440 {
10441         switch (res >> 26) {
10442         case ALC880_HP_EVENT:
10443                 alc267_quanta_il1_hp_automute(codec);
10444                 break;
10445         case ALC880_MIC_EVENT:
10446                 alc267_quanta_il1_mic_automute(codec);
10447                 break;
10448         }
10449 }
10450
10451 /*
10452  * generic initialization of ADC, input mixers and output mixers
10453  */
10454 static struct hda_verb alc268_base_init_verbs[] = {
10455         /* Unmute DAC0-1 and set vol = 0 */
10456         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10457         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10458         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10459         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10460         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10461         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10462
10463         /*
10464          * Set up output mixers (0x0c - 0x0e)
10465          */
10466         /* set vol=0 to output mixers */
10467         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10468         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10469         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10470         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
10471
10472         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10473         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10474
10475         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10476         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10477         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10478         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10479         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10480         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10481         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10482         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10483
10484         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10485         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10486         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10487         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10488         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10489         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10490         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10491
10492         /* set PCBEEP vol = 0, mute connections */
10493         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10494         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10495         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10496
10497         /* Unmute Selector 23h,24h and set the default input to mic-in */
10498         
10499         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
10500         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10501         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
10502         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10503
10504         { }
10505 };
10506
10507 /*
10508  * generic initialization of ADC, input mixers and output mixers
10509  */
10510 static struct hda_verb alc268_volume_init_verbs[] = {
10511         /* set output DAC */
10512         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10513         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10514         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10515         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10516
10517         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10518         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10519         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10520         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10521         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10522
10523         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10524         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10525         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10526         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10527         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10528
10529         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10530         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10531         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10532         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10533
10534         /* set PCBEEP vol = 0, mute connections */
10535         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10536         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10537         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10538
10539         { }
10540 };
10541
10542 #define alc268_mux_enum_info alc_mux_enum_info
10543 #define alc268_mux_enum_get alc_mux_enum_get
10544 #define alc268_mux_enum_put alc_mux_enum_put
10545
10546 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
10547         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10548         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10549         {
10550                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10551                 /* The multiple "Capture Source" controls confuse alsamixer
10552                  * So call somewhat different..
10553                  */
10554                 /* .name = "Capture Source", */
10555                 .name = "Input Source",
10556                 .count = 1,
10557                 .info = alc268_mux_enum_info,
10558                 .get = alc268_mux_enum_get,
10559                 .put = alc268_mux_enum_put,
10560         },
10561         { } /* end */
10562 };
10563
10564 static struct snd_kcontrol_new alc268_capture_mixer[] = {
10565         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10566         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10567         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
10568         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
10569         {
10570                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10571                 /* The multiple "Capture Source" controls confuse alsamixer
10572                  * So call somewhat different..
10573                  */
10574                 /* .name = "Capture Source", */
10575                 .name = "Input Source",
10576                 .count = 2,
10577                 .info = alc268_mux_enum_info,
10578                 .get = alc268_mux_enum_get,
10579                 .put = alc268_mux_enum_put,
10580         },
10581         { } /* end */
10582 };
10583
10584 static struct hda_input_mux alc268_capture_source = {
10585         .num_items = 4,
10586         .items = {
10587                 { "Mic", 0x0 },
10588                 { "Front Mic", 0x1 },
10589                 { "Line", 0x2 },
10590                 { "CD", 0x3 },
10591         },
10592 };
10593
10594 static struct hda_input_mux alc268_acer_capture_source = {
10595         .num_items = 3,
10596         .items = {
10597                 { "Mic", 0x0 },
10598                 { "Internal Mic", 0x6 },
10599                 { "Line", 0x2 },
10600         },
10601 };
10602
10603 #ifdef CONFIG_SND_DEBUG
10604 static struct snd_kcontrol_new alc268_test_mixer[] = {
10605         /* Volume widgets */
10606         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10607         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10608         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
10609         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
10610         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
10611         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
10612         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
10613         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
10614         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
10615         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
10616         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
10617         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
10618         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
10619         /* The below appears problematic on some hardwares */
10620         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
10621         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10622         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
10623         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
10624         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
10625
10626         /* Modes for retasking pin widgets */
10627         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
10628         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
10629         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
10630         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
10631
10632         /* Controls for GPIO pins, assuming they are configured as outputs */
10633         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
10634         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
10635         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
10636         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
10637
10638         /* Switches to allow the digital SPDIF output pin to be enabled.
10639          * The ALC268 does not have an SPDIF input.
10640          */
10641         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
10642
10643         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
10644          * this output to turn on an external amplifier.
10645          */
10646         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
10647         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
10648
10649         { } /* end */
10650 };
10651 #endif
10652
10653 /* create input playback/capture controls for the given pin */
10654 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
10655                                     const char *ctlname, int idx)
10656 {
10657         char name[32];
10658         int err;
10659
10660         sprintf(name, "%s Playback Volume", ctlname);
10661         if (nid == 0x14) {
10662                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10663                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
10664                                                       HDA_OUTPUT));
10665                 if (err < 0)
10666                         return err;
10667         } else if (nid == 0x15) {
10668                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10669                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
10670                                                       HDA_OUTPUT));
10671                 if (err < 0)
10672                         return err;
10673         } else
10674                 return -1;
10675         sprintf(name, "%s Playback Switch", ctlname);
10676         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
10677                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
10678         if (err < 0)
10679                 return err;
10680         return 0;
10681 }
10682
10683 /* add playback controls from the parsed DAC table */
10684 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
10685                                              const struct auto_pin_cfg *cfg)
10686 {
10687         hda_nid_t nid;
10688         int err;
10689
10690         spec->multiout.num_dacs = 2;    /* only use one dac */
10691         spec->multiout.dac_nids = spec->private_dac_nids;
10692         spec->multiout.dac_nids[0] = 2;
10693         spec->multiout.dac_nids[1] = 3;
10694
10695         nid = cfg->line_out_pins[0];
10696         if (nid)
10697                 alc268_new_analog_output(spec, nid, "Front", 0);        
10698
10699         nid = cfg->speaker_pins[0];
10700         if (nid == 0x1d) {
10701                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10702                                   "Speaker Playback Volume",
10703                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
10704                 if (err < 0)
10705                         return err;
10706         }
10707         nid = cfg->hp_pins[0];
10708         if (nid)
10709                 alc268_new_analog_output(spec, nid, "Headphone", 0);
10710
10711         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
10712         if (nid == 0x16) {
10713                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10714                                   "Mono Playback Switch",
10715                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
10716                 if (err < 0)
10717                         return err;
10718         }
10719         return 0;       
10720 }
10721
10722 /* create playback/capture controls for input pins */
10723 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
10724                                                 const struct auto_pin_cfg *cfg)
10725 {
10726         struct hda_input_mux *imux = &spec->private_imux;
10727         int i, idx1;
10728
10729         for (i = 0; i < AUTO_PIN_LAST; i++) {
10730                 switch(cfg->input_pins[i]) {
10731                 case 0x18:
10732                         idx1 = 0;       /* Mic 1 */
10733                         break;
10734                 case 0x19:
10735                         idx1 = 1;       /* Mic 2 */
10736                         break;
10737                 case 0x1a:
10738                         idx1 = 2;       /* Line In */
10739                         break;
10740                 case 0x1c:      
10741                         idx1 = 3;       /* CD */
10742                         break;
10743                 case 0x12:
10744                 case 0x13:
10745                         idx1 = 6;       /* digital mics */
10746                         break;
10747                 default:
10748                         continue;
10749                 }
10750                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
10751                 imux->items[imux->num_items].index = idx1;
10752                 imux->num_items++;      
10753         }
10754         return 0;
10755 }
10756
10757 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
10758 {
10759         struct alc_spec *spec = codec->spec;
10760         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10761         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10762         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10763         unsigned int    dac_vol1, dac_vol2;
10764
10765         if (speaker_nid) {
10766                 snd_hda_codec_write(codec, speaker_nid, 0,
10767                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
10768                 snd_hda_codec_write(codec, 0x0f, 0,
10769                                     AC_VERB_SET_AMP_GAIN_MUTE,
10770                                     AMP_IN_UNMUTE(1));
10771                 snd_hda_codec_write(codec, 0x10, 0,
10772                                     AC_VERB_SET_AMP_GAIN_MUTE,
10773                                     AMP_IN_UNMUTE(1));
10774         } else {
10775                 snd_hda_codec_write(codec, 0x0f, 0,
10776                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10777                 snd_hda_codec_write(codec, 0x10, 0,
10778                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10779         }
10780
10781         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
10782         if (line_nid == 0x14)   
10783                 dac_vol2 = AMP_OUT_ZERO;
10784         else if (line_nid == 0x15)
10785                 dac_vol1 = AMP_OUT_ZERO;
10786         if (hp_nid == 0x14)     
10787                 dac_vol2 = AMP_OUT_ZERO;
10788         else if (hp_nid == 0x15)
10789                 dac_vol1 = AMP_OUT_ZERO;
10790         if (line_nid != 0x16 || hp_nid != 0x16 ||
10791             spec->autocfg.line_out_pins[1] != 0x16 ||
10792             spec->autocfg.line_out_pins[2] != 0x16)
10793                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
10794
10795         snd_hda_codec_write(codec, 0x02, 0,
10796                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
10797         snd_hda_codec_write(codec, 0x03, 0,
10798                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
10799 }
10800
10801 /* pcm configuration: identiacal with ALC880 */
10802 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
10803 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
10804 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
10805 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
10806
10807 /*
10808  * BIOS auto configuration
10809  */
10810 static int alc268_parse_auto_config(struct hda_codec *codec)
10811 {
10812         struct alc_spec *spec = codec->spec;
10813         int err;
10814         static hda_nid_t alc268_ignore[] = { 0 };
10815
10816         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10817                                            alc268_ignore);
10818         if (err < 0)
10819                 return err;
10820         if (!spec->autocfg.line_outs)
10821                 return 0; /* can't find valid BIOS pin config */
10822
10823         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
10824         if (err < 0)
10825                 return err;
10826         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
10827         if (err < 0)
10828                 return err;
10829
10830         spec->multiout.max_channels = 2;
10831
10832         /* digital only support output */
10833         if (spec->autocfg.dig_out_pin)
10834                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
10835
10836         if (spec->kctl_alloc)
10837                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10838
10839         if (spec->autocfg.speaker_pins[0] != 0x1d)
10840                 spec->mixers[spec->num_mixers++] = alc268_beep_mixer;
10841
10842         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
10843         spec->num_mux_defs = 1;
10844         spec->input_mux = &spec->private_imux;
10845
10846         err = alc_auto_add_mic_boost(codec);
10847         if (err < 0)
10848                 return err;
10849
10850         store_pin_configs(codec);
10851         return 1;
10852 }
10853
10854 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
10855 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
10856 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
10857
10858 /* init callback for auto-configuration model -- overriding the default init */
10859 static void alc268_auto_init(struct hda_codec *codec)
10860 {
10861         struct alc_spec *spec = codec->spec;
10862         alc268_auto_init_multi_out(codec);
10863         alc268_auto_init_hp_out(codec);
10864         alc268_auto_init_mono_speaker_out(codec);
10865         alc268_auto_init_analog_input(codec);
10866         if (spec->unsol_event)
10867                 alc_sku_automute(codec);
10868 }
10869
10870 /*
10871  * configuration and preset
10872  */
10873 static const char *alc268_models[ALC268_MODEL_LAST] = {
10874         [ALC267_QUANTA_IL1]     = "quanta-il1",
10875         [ALC268_3ST]            = "3stack",
10876         [ALC268_TOSHIBA]        = "toshiba",
10877         [ALC268_ACER]           = "acer",
10878         [ALC268_DELL]           = "dell",
10879         [ALC268_ZEPTO]          = "zepto",
10880 #ifdef CONFIG_SND_DEBUG
10881         [ALC268_TEST]           = "test",
10882 #endif
10883         [ALC268_AUTO]           = "auto",
10884 };
10885
10886 static struct snd_pci_quirk alc268_cfg_tbl[] = {
10887         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
10888         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
10889         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
10890         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
10891         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
10892         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
10893         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
10894         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
10895         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
10896         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
10897         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
10898         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
10899         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
10900         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
10901         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
10902         {}
10903 };
10904
10905 static struct alc_config_preset alc268_presets[] = {
10906         [ALC267_QUANTA_IL1] = {
10907                 .mixers = { alc267_quanta_il1_mixer },
10908                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10909                                 alc267_quanta_il1_verbs },
10910                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10911                 .dac_nids = alc268_dac_nids,
10912                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10913                 .adc_nids = alc268_adc_nids_alt,
10914                 .hp_nid = 0x03,
10915                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10916                 .channel_mode = alc268_modes,
10917                 .input_mux = &alc268_capture_source,
10918                 .unsol_event = alc267_quanta_il1_unsol_event,
10919                 .init_hook = alc267_quanta_il1_automute,
10920         },
10921         [ALC268_3ST] = {
10922                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10923                             alc268_beep_mixer },
10924                 .init_verbs = { alc268_base_init_verbs },
10925                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10926                 .dac_nids = alc268_dac_nids,
10927                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10928                 .adc_nids = alc268_adc_nids_alt,
10929                 .capsrc_nids = alc268_capsrc_nids,
10930                 .hp_nid = 0x03,
10931                 .dig_out_nid = ALC268_DIGOUT_NID,
10932                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10933                 .channel_mode = alc268_modes,
10934                 .input_mux = &alc268_capture_source,
10935         },
10936         [ALC268_TOSHIBA] = {
10937                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10938                             alc268_beep_mixer },
10939                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10940                                 alc268_toshiba_verbs },
10941                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10942                 .dac_nids = alc268_dac_nids,
10943                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10944                 .adc_nids = alc268_adc_nids_alt,
10945                 .capsrc_nids = alc268_capsrc_nids,
10946                 .hp_nid = 0x03,
10947                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10948                 .channel_mode = alc268_modes,
10949                 .input_mux = &alc268_capture_source,
10950                 .unsol_event = alc268_toshiba_unsol_event,
10951                 .init_hook = alc268_toshiba_automute,
10952         },
10953         [ALC268_ACER] = {
10954                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
10955                             alc268_beep_mixer },
10956                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10957                                 alc268_acer_verbs },
10958                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10959                 .dac_nids = alc268_dac_nids,
10960                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10961                 .adc_nids = alc268_adc_nids_alt,
10962                 .capsrc_nids = alc268_capsrc_nids,
10963                 .hp_nid = 0x02,
10964                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10965                 .channel_mode = alc268_modes,
10966                 .input_mux = &alc268_acer_capture_source,
10967                 .unsol_event = alc268_acer_unsol_event,
10968                 .init_hook = alc268_acer_init_hook,
10969         },
10970         [ALC268_DELL] = {
10971                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
10972                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10973                                 alc268_dell_verbs },
10974                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10975                 .dac_nids = alc268_dac_nids,
10976                 .hp_nid = 0x02,
10977                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10978                 .channel_mode = alc268_modes,
10979                 .unsol_event = alc268_dell_unsol_event,
10980                 .init_hook = alc268_dell_init_hook,
10981                 .input_mux = &alc268_capture_source,
10982         },
10983         [ALC268_ZEPTO] = {
10984                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10985                             alc268_beep_mixer },
10986                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10987                                 alc268_toshiba_verbs },
10988                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10989                 .dac_nids = alc268_dac_nids,
10990                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10991                 .adc_nids = alc268_adc_nids_alt,
10992                 .capsrc_nids = alc268_capsrc_nids,
10993                 .hp_nid = 0x03,
10994                 .dig_out_nid = ALC268_DIGOUT_NID,
10995                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10996                 .channel_mode = alc268_modes,
10997                 .input_mux = &alc268_capture_source,
10998                 .unsol_event = alc268_toshiba_unsol_event,
10999                 .init_hook = alc268_toshiba_automute
11000         },
11001 #ifdef CONFIG_SND_DEBUG
11002         [ALC268_TEST] = {
11003                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11004                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11005                                 alc268_volume_init_verbs },
11006                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11007                 .dac_nids = alc268_dac_nids,
11008                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11009                 .adc_nids = alc268_adc_nids_alt,
11010                 .capsrc_nids = alc268_capsrc_nids,
11011                 .hp_nid = 0x03,
11012                 .dig_out_nid = ALC268_DIGOUT_NID,
11013                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11014                 .channel_mode = alc268_modes,
11015                 .input_mux = &alc268_capture_source,
11016         },
11017 #endif
11018 };
11019
11020 static int patch_alc268(struct hda_codec *codec)
11021 {
11022         struct alc_spec *spec;
11023         int board_config;
11024         int err;
11025
11026         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11027         if (spec == NULL)
11028                 return -ENOMEM;
11029
11030         codec->spec = spec;
11031
11032         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11033                                                   alc268_models,
11034                                                   alc268_cfg_tbl);
11035
11036         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11037                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11038                        "trying auto-probe from BIOS...\n");
11039                 board_config = ALC268_AUTO;
11040         }
11041
11042         if (board_config == ALC268_AUTO) {
11043                 /* automatic parse from the BIOS config */
11044                 err = alc268_parse_auto_config(codec);
11045                 if (err < 0) {
11046                         alc_free(codec);
11047                         return err;
11048                 } else if (!err) {
11049                         printk(KERN_INFO
11050                                "hda_codec: Cannot set up configuration "
11051                                "from BIOS.  Using base mode...\n");
11052                         board_config = ALC268_3ST;
11053                 }
11054         }
11055
11056         if (board_config != ALC268_AUTO)
11057                 setup_preset(spec, &alc268_presets[board_config]);
11058
11059         if (codec->vendor_id == 0x10ec0267) {
11060                 spec->stream_name_analog = "ALC267 Analog";
11061                 spec->stream_name_digital = "ALC267 Digital";
11062         } else {
11063                 spec->stream_name_analog = "ALC268 Analog";
11064                 spec->stream_name_digital = "ALC268 Digital";
11065         }
11066
11067         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11068         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11069         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11070
11071         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11072
11073         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11074                 /* override the amp caps for beep generator */
11075                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11076                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11077                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11078                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11079                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11080
11081         if (!spec->adc_nids && spec->input_mux) {
11082                 /* check whether NID 0x07 is valid */
11083                 unsigned int wcap = get_wcaps(codec, 0x07);
11084                 int i;
11085
11086                 /* get type */
11087                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11088                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11089                         spec->adc_nids = alc268_adc_nids_alt;
11090                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11091                         spec->mixers[spec->num_mixers] =
11092                                         alc268_capture_alt_mixer;
11093                         spec->num_mixers++;
11094                 } else {
11095                         spec->adc_nids = alc268_adc_nids;
11096                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11097                         spec->mixers[spec->num_mixers] =
11098                                 alc268_capture_mixer;
11099                         spec->num_mixers++;
11100                 }
11101                 spec->capsrc_nids = alc268_capsrc_nids;
11102                 /* set default input source */
11103                 for (i = 0; i < spec->num_adc_nids; i++)
11104                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11105                                 0, AC_VERB_SET_CONNECT_SEL,
11106                                 spec->input_mux->items[0].index);
11107         }
11108
11109         spec->vmaster_nid = 0x02;
11110
11111         codec->patch_ops = alc_patch_ops;
11112         if (board_config == ALC268_AUTO)
11113                 spec->init_hook = alc268_auto_init;
11114                 
11115         return 0;
11116 }
11117
11118 /*
11119  *  ALC269 channel source setting (2 channel)
11120  */
11121 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11122
11123 #define alc269_dac_nids         alc260_dac_nids
11124
11125 static hda_nid_t alc269_adc_nids[1] = {
11126         /* ADC1 */
11127         0x08,
11128 };
11129
11130 static hda_nid_t alc269_capsrc_nids[1] = {
11131         0x23,
11132 };
11133
11134 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11135  *       not a mux!
11136  */
11137
11138 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11139         .num_items = 2,
11140         .items = {
11141                 { "i-Mic", 0x5 },
11142                 { "e-Mic", 0x0 },
11143         },
11144 };
11145
11146 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11147         .num_items = 2,
11148         .items = {
11149                 { "i-Mic", 0x1 },
11150                 { "e-Mic", 0x0 },
11151         },
11152 };
11153
11154 #define alc269_modes            alc260_modes
11155 #define alc269_capture_source   alc880_lg_lw_capture_source
11156
11157 static struct snd_kcontrol_new alc269_base_mixer[] = {
11158         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11159         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11160         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11161         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11162         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11163         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11164         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11165         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11166         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11167         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11168         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11169         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
11170         { } /* end */
11171 };
11172
11173 /* bind volumes of both NID 0x0c and 0x0d */
11174 static struct hda_bind_ctls alc269_epc_bind_vol = {
11175         .ops = &snd_hda_bind_vol,
11176         .values = {
11177                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11178                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11179                 0
11180         },
11181 };
11182
11183 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
11184         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11185         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
11186         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11187         { } /* end */
11188 };
11189
11190 /* capture mixer elements */
11191 static struct snd_kcontrol_new alc269_capture_mixer[] = {
11192         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11193         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11194         {
11195                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11196                 /* The multiple "Capture Source" controls confuse alsamixer
11197                  * So call somewhat different..
11198                  */
11199                 /* .name = "Capture Source", */
11200                 .name = "Input Source",
11201                 .count = 1,
11202                 .info = alc_mux_enum_info,
11203                 .get = alc_mux_enum_get,
11204                 .put = alc_mux_enum_put,
11205         },
11206         { } /* end */
11207 };
11208
11209 /* capture mixer elements */
11210 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
11211         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11212         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11213         { } /* end */
11214 };
11215
11216 /*
11217  * generic initialization of ADC, input mixers and output mixers
11218  */
11219 static struct hda_verb alc269_init_verbs[] = {
11220         /*
11221          * Unmute ADC0 and set the default input to mic-in
11222          */
11223         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11224
11225         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
11226          * analog-loopback mixer widget
11227          * Note: PASD motherboards uses the Line In 2 as the input for
11228          * front panel mic (mic 2)
11229          */
11230         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11231         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11232         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11233         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11234         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11235         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11236
11237         /*
11238          * Set up output mixers (0x0c - 0x0e)
11239          */
11240         /* set vol=0 to output mixers */
11241         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11242         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11243
11244         /* set up input amps for analog loopback */
11245         /* Amp Indices: DAC = 0, mixer = 1 */
11246         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11247         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11248         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11249         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11250         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11251         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11252
11253         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11254         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11255         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11256         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11257         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11258         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11259         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11260
11261         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11262         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11263         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11264         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11265         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11266         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11267         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11268
11269         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
11270         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11271
11272         /* FIXME: use matrix-type input source selection */
11273         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
11274         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11275         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11276         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11277         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11278         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11279
11280         /* set EAPD */
11281         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11282         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11283         { }
11284 };
11285
11286 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
11287         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11288         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
11289         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11290         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
11291         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11292         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11293         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11294         {}
11295 };
11296
11297 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
11298         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11299         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
11300         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11301         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
11302         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11303         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11304         {}
11305 };
11306
11307 /* toggle speaker-output according to the hp-jack state */
11308 static void alc269_speaker_automute(struct hda_codec *codec)
11309 {
11310         unsigned int present;
11311         unsigned int bits;
11312
11313         present = snd_hda_codec_read(codec, 0x15, 0,
11314                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11315         bits = present ? AMP_IN_MUTE(0) : 0;
11316         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11317                                  AMP_IN_MUTE(0), bits);
11318         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11319                                  AMP_IN_MUTE(0), bits);
11320 }
11321
11322 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
11323 {
11324         unsigned int present;
11325
11326         present = snd_hda_codec_read(codec, 0x18, 0, AC_VERB_GET_PIN_SENSE, 0)
11327                 & AC_PINSENSE_PRESENCE;
11328         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11329                             present ? 0 : 5);
11330 }
11331
11332 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
11333 {
11334         unsigned int present;
11335
11336         present = snd_hda_codec_read(codec, 0x18, 0, AC_VERB_GET_PIN_SENSE, 0)
11337                 & AC_PINSENSE_PRESENCE;
11338         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11339                             present ? AMP_IN_UNMUTE(0) : AMP_IN_MUTE(0));
11340         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11341                             present ? AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1));
11342 }
11343
11344 /* unsolicited event for HP jack sensing */
11345 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
11346                                           unsigned int res)
11347 {
11348         if ((res >> 26) == ALC880_HP_EVENT)
11349                 alc269_speaker_automute(codec);
11350
11351         if ((res >> 26) == ALC880_MIC_EVENT)
11352                 alc269_eeepc_dmic_automute(codec);
11353 }
11354
11355 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
11356 {
11357         alc269_speaker_automute(codec);
11358         alc269_eeepc_dmic_automute(codec);
11359 }
11360
11361 /* unsolicited event for HP jack sensing */
11362 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
11363                                           unsigned int res)
11364 {
11365         if ((res >> 26) == ALC880_HP_EVENT)
11366                 alc269_speaker_automute(codec);
11367
11368         if ((res >> 26) == ALC880_MIC_EVENT)
11369                 alc269_eeepc_amic_automute(codec);
11370 }
11371
11372 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
11373 {
11374         alc269_speaker_automute(codec);
11375         alc269_eeepc_amic_automute(codec);
11376 }
11377
11378 /* add playback controls from the parsed DAC table */
11379 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
11380                                              const struct auto_pin_cfg *cfg)
11381 {
11382         hda_nid_t nid;
11383         int err;
11384
11385         spec->multiout.num_dacs = 1;    /* only use one dac */
11386         spec->multiout.dac_nids = spec->private_dac_nids;
11387         spec->multiout.dac_nids[0] = 2;
11388
11389         nid = cfg->line_out_pins[0];
11390         if (nid) {
11391                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11392                                   "Front Playback Volume",
11393                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
11394                 if (err < 0)
11395                         return err;
11396                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11397                                   "Front Playback Switch",
11398                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11399                 if (err < 0)
11400                         return err;
11401         }
11402
11403         nid = cfg->speaker_pins[0];
11404         if (nid) {
11405                 if (!cfg->line_out_pins[0]) {
11406                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11407                                           "Speaker Playback Volume",
11408                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
11409                                                               HDA_OUTPUT));
11410                         if (err < 0)
11411                                 return err;
11412                 }
11413                 if (nid == 0x16) {
11414                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11415                                           "Speaker Playback Switch",
11416                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11417                                                               HDA_OUTPUT));
11418                         if (err < 0)
11419                                 return err;
11420                 } else {
11421                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11422                                           "Speaker Playback Switch",
11423                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11424                                                               HDA_OUTPUT));
11425                         if (err < 0)
11426                                 return err;
11427                 }
11428         }
11429         nid = cfg->hp_pins[0];
11430         if (nid) {
11431                 /* spec->multiout.hp_nid = 2; */
11432                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
11433                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11434                                           "Headphone Playback Volume",
11435                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
11436                                                               HDA_OUTPUT));
11437                         if (err < 0)
11438                                 return err;
11439                 }
11440                 if (nid == 0x16) {
11441                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11442                                           "Headphone Playback Switch",
11443                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11444                                                               HDA_OUTPUT));
11445                         if (err < 0)
11446                                 return err;
11447                 } else {
11448                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11449                                           "Headphone Playback Switch",
11450                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11451                                                               HDA_OUTPUT));
11452                         if (err < 0)
11453                                 return err;
11454                 }
11455         }
11456         return 0;
11457 }
11458
11459 #define alc269_auto_create_analog_input_ctls \
11460         alc880_auto_create_analog_input_ctls
11461
11462 #ifdef CONFIG_SND_HDA_POWER_SAVE
11463 #define alc269_loopbacks        alc880_loopbacks
11464 #endif
11465
11466 /* pcm configuration: identiacal with ALC880 */
11467 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
11468 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
11469 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
11470 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
11471
11472 /*
11473  * BIOS auto configuration
11474  */
11475 static int alc269_parse_auto_config(struct hda_codec *codec)
11476 {
11477         struct alc_spec *spec = codec->spec;
11478         int err;
11479         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
11480
11481         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11482                                            alc269_ignore);
11483         if (err < 0)
11484                 return err;
11485
11486         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
11487         if (err < 0)
11488                 return err;
11489         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
11490         if (err < 0)
11491                 return err;
11492
11493         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11494
11495         if (spec->autocfg.dig_out_pin)
11496                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
11497
11498         if (spec->kctl_alloc)
11499                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11500
11501         spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
11502         spec->num_mux_defs = 1;
11503         spec->input_mux = &spec->private_imux;
11504         /* set default input source */
11505         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
11506                                   0, AC_VERB_SET_CONNECT_SEL,
11507                                   spec->input_mux->items[0].index);
11508
11509         err = alc_auto_add_mic_boost(codec);
11510         if (err < 0)
11511                 return err;
11512
11513         spec->mixers[spec->num_mixers] = alc269_capture_mixer;
11514         spec->num_mixers++;
11515
11516         store_pin_configs(codec);
11517         return 1;
11518 }
11519
11520 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
11521 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
11522 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
11523
11524
11525 /* init callback for auto-configuration model -- overriding the default init */
11526 static void alc269_auto_init(struct hda_codec *codec)
11527 {
11528         struct alc_spec *spec = codec->spec;
11529         alc269_auto_init_multi_out(codec);
11530         alc269_auto_init_hp_out(codec);
11531         alc269_auto_init_analog_input(codec);
11532         if (spec->unsol_event)
11533                 alc_sku_automute(codec);
11534 }
11535
11536 /*
11537  * configuration and preset
11538  */
11539 static const char *alc269_models[ALC269_MODEL_LAST] = {
11540         [ALC269_BASIC]          = "basic",
11541 };
11542
11543 static struct snd_pci_quirk alc269_cfg_tbl[] = {
11544         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
11545                       ALC269_ASUS_EEEPC_P703),
11546         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
11547                       ALC269_ASUS_EEEPC_P901),
11548         {}
11549 };
11550
11551 static struct alc_config_preset alc269_presets[] = {
11552         [ALC269_BASIC] = {
11553                 .mixers = { alc269_base_mixer, alc269_capture_mixer },
11554                 .init_verbs = { alc269_init_verbs },
11555                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11556                 .dac_nids = alc269_dac_nids,
11557                 .hp_nid = 0x03,
11558                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11559                 .channel_mode = alc269_modes,
11560                 .input_mux = &alc269_capture_source,
11561         },
11562         [ALC269_ASUS_EEEPC_P703] = {
11563                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer },
11564                 .init_verbs = { alc269_init_verbs,
11565                                 alc269_eeepc_amic_init_verbs },
11566                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11567                 .dac_nids = alc269_dac_nids,
11568                 .hp_nid = 0x03,
11569                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11570                 .channel_mode = alc269_modes,
11571                 .input_mux = &alc269_eeepc_amic_capture_source,
11572                 .unsol_event = alc269_eeepc_amic_unsol_event,
11573                 .init_hook = alc269_eeepc_amic_inithook,
11574         },
11575         [ALC269_ASUS_EEEPC_P901] = {
11576                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer},
11577                 .init_verbs = { alc269_init_verbs,
11578                                 alc269_eeepc_dmic_init_verbs },
11579                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11580                 .dac_nids = alc269_dac_nids,
11581                 .hp_nid = 0x03,
11582                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11583                 .channel_mode = alc269_modes,
11584                 .input_mux = &alc269_eeepc_dmic_capture_source,
11585                 .unsol_event = alc269_eeepc_dmic_unsol_event,
11586                 .init_hook = alc269_eeepc_dmic_inithook,
11587         },
11588 };
11589
11590 static int patch_alc269(struct hda_codec *codec)
11591 {
11592         struct alc_spec *spec;
11593         int board_config;
11594         int err;
11595
11596         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11597         if (spec == NULL)
11598                 return -ENOMEM;
11599
11600         codec->spec = spec;
11601
11602         alc_fix_pll_init(codec, 0x20, 0x04, 15);
11603
11604         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
11605                                                   alc269_models,
11606                                                   alc269_cfg_tbl);
11607
11608         if (board_config < 0) {
11609                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
11610                        "trying auto-probe from BIOS...\n");
11611                 board_config = ALC269_AUTO;
11612         }
11613
11614         if (board_config == ALC269_AUTO) {
11615                 /* automatic parse from the BIOS config */
11616                 err = alc269_parse_auto_config(codec);
11617                 if (err < 0) {
11618                         alc_free(codec);
11619                         return err;
11620                 } else if (!err) {
11621                         printk(KERN_INFO
11622                                "hda_codec: Cannot set up configuration "
11623                                "from BIOS.  Using base mode...\n");
11624                         board_config = ALC269_BASIC;
11625                 }
11626         }
11627
11628         if (board_config != ALC269_AUTO)
11629                 setup_preset(spec, &alc269_presets[board_config]);
11630
11631         spec->stream_name_analog = "ALC269 Analog";
11632         spec->stream_analog_playback = &alc269_pcm_analog_playback;
11633         spec->stream_analog_capture = &alc269_pcm_analog_capture;
11634
11635         spec->stream_name_digital = "ALC269 Digital";
11636         spec->stream_digital_playback = &alc269_pcm_digital_playback;
11637         spec->stream_digital_capture = &alc269_pcm_digital_capture;
11638
11639         spec->adc_nids = alc269_adc_nids;
11640         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
11641         spec->capsrc_nids = alc269_capsrc_nids;
11642
11643         spec->vmaster_nid = 0x02;
11644
11645         codec->patch_ops = alc_patch_ops;
11646         if (board_config == ALC269_AUTO)
11647                 spec->init_hook = alc269_auto_init;
11648 #ifdef CONFIG_SND_HDA_POWER_SAVE
11649         if (!spec->loopback.amplist)
11650                 spec->loopback.amplist = alc269_loopbacks;
11651 #endif
11652
11653         return 0;
11654 }
11655
11656 /*
11657  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
11658  */
11659
11660 /*
11661  * set the path ways for 2 channel output
11662  * need to set the codec line out and mic 1 pin widgets to inputs
11663  */
11664 static struct hda_verb alc861_threestack_ch2_init[] = {
11665         /* set pin widget 1Ah (line in) for input */
11666         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11667         /* set pin widget 18h (mic1/2) for input, for mic also enable
11668          * the vref
11669          */
11670         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11671
11672         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
11673 #if 0
11674         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11675         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
11676 #endif
11677         { } /* end */
11678 };
11679 /*
11680  * 6ch mode
11681  * need to set the codec line out and mic 1 pin widgets to outputs
11682  */
11683 static struct hda_verb alc861_threestack_ch6_init[] = {
11684         /* set pin widget 1Ah (line in) for output (Back Surround)*/
11685         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11686         /* set pin widget 18h (mic1) for output (CLFE)*/
11687         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11688
11689         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
11690         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
11691
11692         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11693 #if 0
11694         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11695         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11696 #endif
11697         { } /* end */
11698 };
11699
11700 static struct hda_channel_mode alc861_threestack_modes[2] = {
11701         { 2, alc861_threestack_ch2_init },
11702         { 6, alc861_threestack_ch6_init },
11703 };
11704 /* Set mic1 as input and unmute the mixer */
11705 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
11706         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11707         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11708         { } /* end */
11709 };
11710 /* Set mic1 as output and mute mixer */
11711 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
11712         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11713         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11714         { } /* end */
11715 };
11716
11717 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
11718         { 2, alc861_uniwill_m31_ch2_init },
11719         { 4, alc861_uniwill_m31_ch4_init },
11720 };
11721
11722 /* Set mic1 and line-in as input and unmute the mixer */
11723 static struct hda_verb alc861_asus_ch2_init[] = {
11724         /* set pin widget 1Ah (line in) for input */
11725         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11726         /* set pin widget 18h (mic1/2) for input, for mic also enable
11727          * the vref
11728          */
11729         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11730
11731         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
11732 #if 0
11733         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11734         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
11735 #endif
11736         { } /* end */
11737 };
11738 /* Set mic1 nad line-in as output and mute mixer */
11739 static struct hda_verb alc861_asus_ch6_init[] = {
11740         /* set pin widget 1Ah (line in) for output (Back Surround)*/
11741         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11742         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
11743         /* set pin widget 18h (mic1) for output (CLFE)*/
11744         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11745         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
11746         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
11747         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
11748
11749         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11750 #if 0
11751         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11752         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11753 #endif
11754         { } /* end */
11755 };
11756
11757 static struct hda_channel_mode alc861_asus_modes[2] = {
11758         { 2, alc861_asus_ch2_init },
11759         { 6, alc861_asus_ch6_init },
11760 };
11761
11762 /* patch-ALC861 */
11763
11764 static struct snd_kcontrol_new alc861_base_mixer[] = {
11765         /* output mixer control */
11766         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11767         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11768         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11769         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11770         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11771
11772         /*Input mixer control */
11773         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11774            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11775         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11776         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11777         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11778         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11779         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11780         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11781         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11782         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11783
11784         /* Capture mixer control */
11785         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11786         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11787         {
11788                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11789                 .name = "Capture Source",
11790                 .count = 1,
11791                 .info = alc_mux_enum_info,
11792                 .get = alc_mux_enum_get,
11793                 .put = alc_mux_enum_put,
11794         },
11795         { } /* end */
11796 };
11797
11798 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
11799         /* output mixer control */
11800         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11801         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11802         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11803         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11804         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11805
11806         /* Input mixer control */
11807         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11808            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11809         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11810         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11811         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11812         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11813         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11814         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11815         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11816         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11817
11818         /* Capture mixer control */
11819         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11820         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11821         {
11822                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11823                 .name = "Capture Source",
11824                 .count = 1,
11825                 .info = alc_mux_enum_info,
11826                 .get = alc_mux_enum_get,
11827                 .put = alc_mux_enum_put,
11828         },
11829         {
11830                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11831                 .name = "Channel Mode",
11832                 .info = alc_ch_mode_info,
11833                 .get = alc_ch_mode_get,
11834                 .put = alc_ch_mode_put,
11835                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
11836         },
11837         { } /* end */
11838 };
11839
11840 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
11841         /* output mixer control */
11842         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11843         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11844         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11845         
11846         /*Capture mixer control */
11847         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11848         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11849         {
11850                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11851                 .name = "Capture Source",
11852                 .count = 1,
11853                 .info = alc_mux_enum_info,
11854                 .get = alc_mux_enum_get,
11855                 .put = alc_mux_enum_put,
11856         },
11857
11858         { } /* end */
11859 };
11860
11861 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
11862         /* output mixer control */
11863         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11864         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11865         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11866         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11867         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11868
11869         /* Input mixer control */
11870         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11871            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11872         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11873         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11874         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11875         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11876         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11877         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11878         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11879         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11880
11881         /* Capture mixer control */
11882         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11883         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11884         {
11885                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11886                 .name = "Capture Source",
11887                 .count = 1,
11888                 .info = alc_mux_enum_info,
11889                 .get = alc_mux_enum_get,
11890                 .put = alc_mux_enum_put,
11891         },
11892         {
11893                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11894                 .name = "Channel Mode",
11895                 .info = alc_ch_mode_info,
11896                 .get = alc_ch_mode_get,
11897                 .put = alc_ch_mode_put,
11898                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
11899         },
11900         { } /* end */
11901 };
11902
11903 static struct snd_kcontrol_new alc861_asus_mixer[] = {
11904         /* output mixer control */
11905         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11906         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11907         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11908         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11909         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11910
11911         /* Input mixer control */
11912         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11913         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11914         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11915         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11916         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11917         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11918         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11919         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11920         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11921         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
11922
11923         /* Capture mixer control */
11924         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11925         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11926         {
11927                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11928                 .name = "Capture Source",
11929                 .count = 1,
11930                 .info = alc_mux_enum_info,
11931                 .get = alc_mux_enum_get,
11932                 .put = alc_mux_enum_put,
11933         },
11934         {
11935                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11936                 .name = "Channel Mode",
11937                 .info = alc_ch_mode_info,
11938                 .get = alc_ch_mode_get,
11939                 .put = alc_ch_mode_put,
11940                 .private_value = ARRAY_SIZE(alc861_asus_modes),
11941         },
11942         { }
11943 };
11944
11945 /* additional mixer */
11946 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
11947         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11948         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11949         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
11950         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
11951         { }
11952 };
11953
11954 /*
11955  * generic initialization of ADC, input mixers and output mixers
11956  */
11957 static struct hda_verb alc861_base_init_verbs[] = {
11958         /*
11959          * Unmute ADC0 and set the default input to mic-in
11960          */
11961         /* port-A for surround (rear panel) */
11962         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11963         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
11964         /* port-B for mic-in (rear panel) with vref */
11965         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11966         /* port-C for line-in (rear panel) */
11967         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11968         /* port-D for Front */
11969         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11970         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11971         /* port-E for HP out (front panel) */
11972         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11973         /* route front PCM to HP */
11974         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11975         /* port-F for mic-in (front panel) with vref */
11976         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11977         /* port-G for CLFE (rear panel) */
11978         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11979         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11980         /* port-H for side (rear panel) */
11981         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11982         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
11983         /* CD-in */
11984         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11985         /* route front mic to ADC1*/
11986         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11987         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11988         
11989         /* Unmute DAC0~3 & spdif out*/
11990         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11991         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11992         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11993         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11994         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11995         
11996         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11997         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11998         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11999         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12000         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12001         
12002         /* Unmute Stereo Mixer 15 */
12003         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12004         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12005         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12006         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12007
12008         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12009         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12010         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12011         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12012         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12013         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12014         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12015         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12016         /* hp used DAC 3 (Front) */
12017         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12018         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12019
12020         { }
12021 };
12022
12023 static struct hda_verb alc861_threestack_init_verbs[] = {
12024         /*
12025          * Unmute ADC0 and set the default input to mic-in
12026          */
12027         /* port-A for surround (rear panel) */
12028         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12029         /* port-B for mic-in (rear panel) with vref */
12030         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12031         /* port-C for line-in (rear panel) */
12032         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12033         /* port-D for Front */
12034         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12035         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12036         /* port-E for HP out (front panel) */
12037         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
12038         /* route front PCM to HP */
12039         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12040         /* port-F for mic-in (front panel) with vref */
12041         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12042         /* port-G for CLFE (rear panel) */
12043         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12044         /* port-H for side (rear panel) */
12045         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12046         /* CD-in */
12047         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12048         /* route front mic to ADC1*/
12049         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12050         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12051         /* Unmute DAC0~3 & spdif out*/
12052         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12053         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12054         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12055         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12056         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12057         
12058         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12059         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12060         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12061         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12062         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12063         
12064         /* Unmute Stereo Mixer 15 */
12065         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12066         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12067         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12068         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12069
12070         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12071         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12072         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12073         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12074         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12075         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12076         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12077         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12078         /* hp used DAC 3 (Front) */
12079         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12080         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12081         { }
12082 };
12083
12084 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
12085         /*
12086          * Unmute ADC0 and set the default input to mic-in
12087          */
12088         /* port-A for surround (rear panel) */
12089         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12090         /* port-B for mic-in (rear panel) with vref */
12091         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12092         /* port-C for line-in (rear panel) */
12093         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12094         /* port-D for Front */
12095         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12096         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12097         /* port-E for HP out (front panel) */
12098         /* this has to be set to VREF80 */
12099         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12100         /* route front PCM to HP */
12101         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12102         /* port-F for mic-in (front panel) with vref */
12103         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12104         /* port-G for CLFE (rear panel) */
12105         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12106         /* port-H for side (rear panel) */
12107         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12108         /* CD-in */
12109         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12110         /* route front mic to ADC1*/
12111         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12112         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12113         /* Unmute DAC0~3 & spdif out*/
12114         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12115         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12116         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12117         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12118         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12119         
12120         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12121         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12122         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12123         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12124         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12125         
12126         /* Unmute Stereo Mixer 15 */
12127         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12128         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12129         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12130         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12131
12132         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12133         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12134         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12135         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12136         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12137         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12138         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12139         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12140         /* hp used DAC 3 (Front) */
12141         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12142         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12143         { }
12144 };
12145
12146 static struct hda_verb alc861_asus_init_verbs[] = {
12147         /*
12148          * Unmute ADC0 and set the default input to mic-in
12149          */
12150         /* port-A for surround (rear panel)
12151          * according to codec#0 this is the HP jack
12152          */
12153         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
12154         /* route front PCM to HP */
12155         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
12156         /* port-B for mic-in (rear panel) with vref */
12157         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12158         /* port-C for line-in (rear panel) */
12159         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12160         /* port-D for Front */
12161         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12162         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12163         /* port-E for HP out (front panel) */
12164         /* this has to be set to VREF80 */
12165         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12166         /* route front PCM to HP */
12167         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12168         /* port-F for mic-in (front panel) with vref */
12169         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12170         /* port-G for CLFE (rear panel) */
12171         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12172         /* port-H for side (rear panel) */
12173         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12174         /* CD-in */
12175         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12176         /* route front mic to ADC1*/
12177         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12178         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12179         /* Unmute DAC0~3 & spdif out*/
12180         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12181         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12182         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12183         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12184         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12185         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12186         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12187         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12188         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12189         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12190         
12191         /* Unmute Stereo Mixer 15 */
12192         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12193         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12194         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12195         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12196
12197         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12198         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12199         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12200         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12201         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12202         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12203         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12204         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12205         /* hp used DAC 3 (Front) */
12206         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12207         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12208         { }
12209 };
12210
12211 /* additional init verbs for ASUS laptops */
12212 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
12213         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
12214         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
12215         { }
12216 };
12217
12218 /*
12219  * generic initialization of ADC, input mixers and output mixers
12220  */
12221 static struct hda_verb alc861_auto_init_verbs[] = {
12222         /*
12223          * Unmute ADC0 and set the default input to mic-in
12224          */
12225         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
12226         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12227         
12228         /* Unmute DAC0~3 & spdif out*/
12229         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12230         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12231         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12232         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12233         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12234         
12235         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12236         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12237         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12238         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12239         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12240         
12241         /* Unmute Stereo Mixer 15 */
12242         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12243         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12244         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12245         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
12246
12247         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12248         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12249         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12250         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12251         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12252         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12253         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12254         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12255
12256         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12257         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12258         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12259         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12260         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12261         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12262         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12263         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12264
12265         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
12266
12267         { }
12268 };
12269
12270 static struct hda_verb alc861_toshiba_init_verbs[] = {
12271         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12272
12273         { }
12274 };
12275
12276 /* toggle speaker-output according to the hp-jack state */
12277 static void alc861_toshiba_automute(struct hda_codec *codec)
12278 {
12279         unsigned int present;
12280
12281         present = snd_hda_codec_read(codec, 0x0f, 0,
12282                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12283         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
12284                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
12285         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
12286                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
12287 }
12288
12289 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
12290                                        unsigned int res)
12291 {
12292         if ((res >> 26) == ALC880_HP_EVENT)
12293                 alc861_toshiba_automute(codec);
12294 }
12295
12296 /* pcm configuration: identiacal with ALC880 */
12297 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
12298 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
12299 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
12300 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
12301
12302
12303 #define ALC861_DIGOUT_NID       0x07
12304
12305 static struct hda_channel_mode alc861_8ch_modes[1] = {
12306         { 8, NULL }
12307 };
12308
12309 static hda_nid_t alc861_dac_nids[4] = {
12310         /* front, surround, clfe, side */
12311         0x03, 0x06, 0x05, 0x04
12312 };
12313
12314 static hda_nid_t alc660_dac_nids[3] = {
12315         /* front, clfe, surround */
12316         0x03, 0x05, 0x06
12317 };
12318
12319 static hda_nid_t alc861_adc_nids[1] = {
12320         /* ADC0-2 */
12321         0x08,
12322 };
12323
12324 static struct hda_input_mux alc861_capture_source = {
12325         .num_items = 5,
12326         .items = {
12327                 { "Mic", 0x0 },
12328                 { "Front Mic", 0x3 },
12329                 { "Line", 0x1 },
12330                 { "CD", 0x4 },
12331                 { "Mixer", 0x5 },
12332         },
12333 };
12334
12335 /* fill in the dac_nids table from the parsed pin configuration */
12336 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
12337                                      const struct auto_pin_cfg *cfg)
12338 {
12339         int i;
12340         hda_nid_t nid;
12341
12342         spec->multiout.dac_nids = spec->private_dac_nids;
12343         for (i = 0; i < cfg->line_outs; i++) {
12344                 nid = cfg->line_out_pins[i];
12345                 if (nid) {
12346                         if (i >= ARRAY_SIZE(alc861_dac_nids))
12347                                 continue;
12348                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
12349                 }
12350         }
12351         spec->multiout.num_dacs = cfg->line_outs;
12352         return 0;
12353 }
12354
12355 /* add playback controls from the parsed DAC table */
12356 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
12357                                              const struct auto_pin_cfg *cfg)
12358 {
12359         char name[32];
12360         static const char *chname[4] = {
12361                 "Front", "Surround", NULL /*CLFE*/, "Side"
12362         };
12363         hda_nid_t nid;
12364         int i, idx, err;
12365
12366         for (i = 0; i < cfg->line_outs; i++) {
12367                 nid = spec->multiout.dac_nids[i];
12368                 if (!nid)
12369                         continue;
12370                 if (nid == 0x05) {
12371                         /* Center/LFE */
12372                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12373                                           "Center Playback Switch",
12374                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
12375                                                               HDA_OUTPUT));
12376                         if (err < 0)
12377                                 return err;
12378                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12379                                           "LFE Playback Switch",
12380                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12381                                                               HDA_OUTPUT));
12382                         if (err < 0)
12383                                 return err;
12384                 } else {
12385                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
12386                              idx++)
12387                                 if (nid == alc861_dac_nids[idx])
12388                                         break;
12389                         sprintf(name, "%s Playback Switch", chname[idx]);
12390                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12391                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12392                                                               HDA_OUTPUT));
12393                         if (err < 0)
12394                                 return err;
12395                 }
12396         }
12397         return 0;
12398 }
12399
12400 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
12401 {
12402         int err;
12403         hda_nid_t nid;
12404
12405         if (!pin)
12406                 return 0;
12407
12408         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
12409                 nid = 0x03;
12410                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12411                                   "Headphone Playback Switch",
12412                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12413                 if (err < 0)
12414                         return err;
12415                 spec->multiout.hp_nid = nid;
12416         }
12417         return 0;
12418 }
12419
12420 /* create playback/capture controls for input pins */
12421 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
12422                                                 const struct auto_pin_cfg *cfg)
12423 {
12424         struct hda_input_mux *imux = &spec->private_imux;
12425         int i, err, idx, idx1;
12426
12427         for (i = 0; i < AUTO_PIN_LAST; i++) {
12428                 switch (cfg->input_pins[i]) {
12429                 case 0x0c:
12430                         idx1 = 1;
12431                         idx = 2;        /* Line In */
12432                         break;
12433                 case 0x0f:
12434                         idx1 = 2;
12435                         idx = 2;        /* Line In */
12436                         break;
12437                 case 0x0d:
12438                         idx1 = 0;
12439                         idx = 1;        /* Mic In */
12440                         break;
12441                 case 0x10:
12442                         idx1 = 3;
12443                         idx = 1;        /* Mic In */
12444                         break;
12445                 case 0x11:
12446                         idx1 = 4;
12447                         idx = 0;        /* CD */
12448                         break;
12449                 default:
12450                         continue;
12451                 }
12452
12453                 err = new_analog_input(spec, cfg->input_pins[i],
12454                                        auto_pin_cfg_labels[i], idx, 0x15);
12455                 if (err < 0)
12456                         return err;
12457
12458                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
12459                 imux->items[imux->num_items].index = idx1;
12460                 imux->num_items++;
12461         }
12462         return 0;
12463 }
12464
12465 static struct snd_kcontrol_new alc861_capture_mixer[] = {
12466         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12467         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12468
12469         {
12470                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12471                 /* The multiple "Capture Source" controls confuse alsamixer
12472                  * So call somewhat different..
12473                  */
12474                 /* .name = "Capture Source", */
12475                 .name = "Input Source",
12476                 .count = 1,
12477                 .info = alc_mux_enum_info,
12478                 .get = alc_mux_enum_get,
12479                 .put = alc_mux_enum_put,
12480         },
12481         { } /* end */
12482 };
12483
12484 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
12485                                               hda_nid_t nid,
12486                                               int pin_type, int dac_idx)
12487 {
12488         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
12489                             pin_type);
12490         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12491                             AMP_OUT_UNMUTE);
12492 }
12493
12494 static void alc861_auto_init_multi_out(struct hda_codec *codec)
12495 {
12496         struct alc_spec *spec = codec->spec;
12497         int i;
12498
12499         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
12500         for (i = 0; i < spec->autocfg.line_outs; i++) {
12501                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
12502                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12503                 if (nid)
12504                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
12505                                                           spec->multiout.dac_nids[i]);
12506         }
12507 }
12508
12509 static void alc861_auto_init_hp_out(struct hda_codec *codec)
12510 {
12511         struct alc_spec *spec = codec->spec;
12512         hda_nid_t pin;
12513
12514         pin = spec->autocfg.hp_pins[0];
12515         if (pin) /* connect to front */
12516                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
12517                                                   spec->multiout.dac_nids[0]);
12518         pin = spec->autocfg.speaker_pins[0];
12519         if (pin)
12520                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
12521 }
12522
12523 static void alc861_auto_init_analog_input(struct hda_codec *codec)
12524 {
12525         struct alc_spec *spec = codec->spec;
12526         int i;
12527
12528         for (i = 0; i < AUTO_PIN_LAST; i++) {
12529                 hda_nid_t nid = spec->autocfg.input_pins[i];
12530                 if (nid >= 0x0c && nid <= 0x11) {
12531                         snd_hda_codec_write(codec, nid, 0,
12532                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
12533                                             i <= AUTO_PIN_FRONT_MIC ?
12534                                             PIN_VREF80 : PIN_IN);
12535                 }
12536         }
12537 }
12538
12539 /* parse the BIOS configuration and set up the alc_spec */
12540 /* return 1 if successful, 0 if the proper config is not found,
12541  * or a negative error code
12542  */
12543 static int alc861_parse_auto_config(struct hda_codec *codec)
12544 {
12545         struct alc_spec *spec = codec->spec;
12546         int err;
12547         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
12548
12549         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12550                                            alc861_ignore);
12551         if (err < 0)
12552                 return err;
12553         if (!spec->autocfg.line_outs)
12554                 return 0; /* can't find valid BIOS pin config */
12555
12556         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
12557         if (err < 0)
12558                 return err;
12559         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
12560         if (err < 0)
12561                 return err;
12562         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
12563         if (err < 0)
12564                 return err;
12565         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
12566         if (err < 0)
12567                 return err;
12568
12569         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12570
12571         if (spec->autocfg.dig_out_pin)
12572                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
12573
12574         if (spec->kctl_alloc)
12575                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
12576
12577         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
12578
12579         spec->num_mux_defs = 1;
12580         spec->input_mux = &spec->private_imux;
12581
12582         spec->adc_nids = alc861_adc_nids;
12583         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
12584         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
12585         spec->num_mixers++;
12586
12587         store_pin_configs(codec);
12588         return 1;
12589 }
12590
12591 /* additional initialization for auto-configuration model */
12592 static void alc861_auto_init(struct hda_codec *codec)
12593 {
12594         struct alc_spec *spec = codec->spec;
12595         alc861_auto_init_multi_out(codec);
12596         alc861_auto_init_hp_out(codec);
12597         alc861_auto_init_analog_input(codec);
12598         if (spec->unsol_event)
12599                 alc_sku_automute(codec);
12600 }
12601
12602 #ifdef CONFIG_SND_HDA_POWER_SAVE
12603 static struct hda_amp_list alc861_loopbacks[] = {
12604         { 0x15, HDA_INPUT, 0 },
12605         { 0x15, HDA_INPUT, 1 },
12606         { 0x15, HDA_INPUT, 2 },
12607         { 0x15, HDA_INPUT, 3 },
12608         { } /* end */
12609 };
12610 #endif
12611
12612
12613 /*
12614  * configuration and preset
12615  */
12616 static const char *alc861_models[ALC861_MODEL_LAST] = {
12617         [ALC861_3ST]            = "3stack",
12618         [ALC660_3ST]            = "3stack-660",
12619         [ALC861_3ST_DIG]        = "3stack-dig",
12620         [ALC861_6ST_DIG]        = "6stack-dig",
12621         [ALC861_UNIWILL_M31]    = "uniwill-m31",
12622         [ALC861_TOSHIBA]        = "toshiba",
12623         [ALC861_ASUS]           = "asus",
12624         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
12625         [ALC861_AUTO]           = "auto",
12626 };
12627
12628 static struct snd_pci_quirk alc861_cfg_tbl[] = {
12629         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
12630         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
12631         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
12632         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
12633         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
12634         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
12635         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
12636         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
12637          *        Any other models that need this preset?
12638          */
12639         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
12640         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
12641         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
12642         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
12643         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
12644         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
12645         /* FIXME: the below seems conflict */
12646         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
12647         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
12648         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
12649         {}
12650 };
12651
12652 static struct alc_config_preset alc861_presets[] = {
12653         [ALC861_3ST] = {
12654                 .mixers = { alc861_3ST_mixer },
12655                 .init_verbs = { alc861_threestack_init_verbs },
12656                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12657                 .dac_nids = alc861_dac_nids,
12658                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12659                 .channel_mode = alc861_threestack_modes,
12660                 .need_dac_fix = 1,
12661                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12662                 .adc_nids = alc861_adc_nids,
12663                 .input_mux = &alc861_capture_source,
12664         },
12665         [ALC861_3ST_DIG] = {
12666                 .mixers = { alc861_base_mixer },
12667                 .init_verbs = { alc861_threestack_init_verbs },
12668                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12669                 .dac_nids = alc861_dac_nids,
12670                 .dig_out_nid = ALC861_DIGOUT_NID,
12671                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12672                 .channel_mode = alc861_threestack_modes,
12673                 .need_dac_fix = 1,
12674                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12675                 .adc_nids = alc861_adc_nids,
12676                 .input_mux = &alc861_capture_source,
12677         },
12678         [ALC861_6ST_DIG] = {
12679                 .mixers = { alc861_base_mixer },
12680                 .init_verbs = { alc861_base_init_verbs },
12681                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12682                 .dac_nids = alc861_dac_nids,
12683                 .dig_out_nid = ALC861_DIGOUT_NID,
12684                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
12685                 .channel_mode = alc861_8ch_modes,
12686                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12687                 .adc_nids = alc861_adc_nids,
12688                 .input_mux = &alc861_capture_source,
12689         },
12690         [ALC660_3ST] = {
12691                 .mixers = { alc861_3ST_mixer },
12692                 .init_verbs = { alc861_threestack_init_verbs },
12693                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
12694                 .dac_nids = alc660_dac_nids,
12695                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12696                 .channel_mode = alc861_threestack_modes,
12697                 .need_dac_fix = 1,
12698                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12699                 .adc_nids = alc861_adc_nids,
12700                 .input_mux = &alc861_capture_source,
12701         },
12702         [ALC861_UNIWILL_M31] = {
12703                 .mixers = { alc861_uniwill_m31_mixer },
12704                 .init_verbs = { alc861_uniwill_m31_init_verbs },
12705                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12706                 .dac_nids = alc861_dac_nids,
12707                 .dig_out_nid = ALC861_DIGOUT_NID,
12708                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
12709                 .channel_mode = alc861_uniwill_m31_modes,
12710                 .need_dac_fix = 1,
12711                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12712                 .adc_nids = alc861_adc_nids,
12713                 .input_mux = &alc861_capture_source,
12714         },
12715         [ALC861_TOSHIBA] = {
12716                 .mixers = { alc861_toshiba_mixer },
12717                 .init_verbs = { alc861_base_init_verbs,
12718                                 alc861_toshiba_init_verbs },
12719                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12720                 .dac_nids = alc861_dac_nids,
12721                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
12722                 .channel_mode = alc883_3ST_2ch_modes,
12723                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12724                 .adc_nids = alc861_adc_nids,
12725                 .input_mux = &alc861_capture_source,
12726                 .unsol_event = alc861_toshiba_unsol_event,
12727                 .init_hook = alc861_toshiba_automute,
12728         },
12729         [ALC861_ASUS] = {
12730                 .mixers = { alc861_asus_mixer },
12731                 .init_verbs = { alc861_asus_init_verbs },
12732                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12733                 .dac_nids = alc861_dac_nids,
12734                 .dig_out_nid = ALC861_DIGOUT_NID,
12735                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
12736                 .channel_mode = alc861_asus_modes,
12737                 .need_dac_fix = 1,
12738                 .hp_nid = 0x06,
12739                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12740                 .adc_nids = alc861_adc_nids,
12741                 .input_mux = &alc861_capture_source,
12742         },
12743         [ALC861_ASUS_LAPTOP] = {
12744                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
12745                 .init_verbs = { alc861_asus_init_verbs,
12746                                 alc861_asus_laptop_init_verbs },
12747                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12748                 .dac_nids = alc861_dac_nids,
12749                 .dig_out_nid = ALC861_DIGOUT_NID,
12750                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
12751                 .channel_mode = alc883_3ST_2ch_modes,
12752                 .need_dac_fix = 1,
12753                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12754                 .adc_nids = alc861_adc_nids,
12755                 .input_mux = &alc861_capture_source,
12756         },
12757 };
12758
12759
12760 static int patch_alc861(struct hda_codec *codec)
12761 {
12762         struct alc_spec *spec;
12763         int board_config;
12764         int err;
12765
12766         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12767         if (spec == NULL)
12768                 return -ENOMEM;
12769
12770         codec->spec = spec;
12771
12772         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
12773                                                   alc861_models,
12774                                                   alc861_cfg_tbl);
12775
12776         if (board_config < 0) {
12777                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
12778                        "trying auto-probe from BIOS...\n");
12779                 board_config = ALC861_AUTO;
12780         }
12781
12782         if (board_config == ALC861_AUTO) {
12783                 /* automatic parse from the BIOS config */
12784                 err = alc861_parse_auto_config(codec);
12785                 if (err < 0) {
12786                         alc_free(codec);
12787                         return err;
12788                 } else if (!err) {
12789                         printk(KERN_INFO
12790                                "hda_codec: Cannot set up configuration "
12791                                "from BIOS.  Using base mode...\n");
12792                    board_config = ALC861_3ST_DIG;
12793                 }
12794         }
12795
12796         if (board_config != ALC861_AUTO)
12797                 setup_preset(spec, &alc861_presets[board_config]);
12798
12799         spec->stream_name_analog = "ALC861 Analog";
12800         spec->stream_analog_playback = &alc861_pcm_analog_playback;
12801         spec->stream_analog_capture = &alc861_pcm_analog_capture;
12802
12803         spec->stream_name_digital = "ALC861 Digital";
12804         spec->stream_digital_playback = &alc861_pcm_digital_playback;
12805         spec->stream_digital_capture = &alc861_pcm_digital_capture;
12806
12807         spec->vmaster_nid = 0x03;
12808
12809         codec->patch_ops = alc_patch_ops;
12810         if (board_config == ALC861_AUTO)
12811                 spec->init_hook = alc861_auto_init;
12812 #ifdef CONFIG_SND_HDA_POWER_SAVE
12813         if (!spec->loopback.amplist)
12814                 spec->loopback.amplist = alc861_loopbacks;
12815 #endif
12816                 
12817         return 0;
12818 }
12819
12820 /*
12821  * ALC861-VD support
12822  *
12823  * Based on ALC882
12824  *
12825  * In addition, an independent DAC
12826  */
12827 #define ALC861VD_DIGOUT_NID     0x06
12828
12829 static hda_nid_t alc861vd_dac_nids[4] = {
12830         /* front, surr, clfe, side surr */
12831         0x02, 0x03, 0x04, 0x05
12832 };
12833
12834 /* dac_nids for ALC660vd are in a different order - according to
12835  * Realtek's driver.
12836  * This should probably tesult in a different mixer for 6stack models
12837  * of ALC660vd codecs, but for now there is only 3stack mixer
12838  * - and it is the same as in 861vd.
12839  * adc_nids in ALC660vd are (is) the same as in 861vd
12840  */
12841 static hda_nid_t alc660vd_dac_nids[3] = {
12842         /* front, rear, clfe, rear_surr */
12843         0x02, 0x04, 0x03
12844 };
12845
12846 static hda_nid_t alc861vd_adc_nids[1] = {
12847         /* ADC0 */
12848         0x09,
12849 };
12850
12851 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
12852
12853 /* input MUX */
12854 /* FIXME: should be a matrix-type input source selection */
12855 static struct hda_input_mux alc861vd_capture_source = {
12856         .num_items = 4,
12857         .items = {
12858                 { "Mic", 0x0 },
12859                 { "Front Mic", 0x1 },
12860                 { "Line", 0x2 },
12861                 { "CD", 0x4 },
12862         },
12863 };
12864
12865 static struct hda_input_mux alc861vd_dallas_capture_source = {
12866         .num_items = 2,
12867         .items = {
12868                 { "Ext Mic", 0x0 },
12869                 { "Int Mic", 0x1 },
12870         },
12871 };
12872
12873 static struct hda_input_mux alc861vd_hp_capture_source = {
12874         .num_items = 2,
12875         .items = {
12876                 { "Front Mic", 0x0 },
12877                 { "ATAPI Mic", 0x1 },
12878         },
12879 };
12880
12881 #define alc861vd_mux_enum_info alc_mux_enum_info
12882 #define alc861vd_mux_enum_get alc_mux_enum_get
12883 /* ALC861VD has the ALC882-type input selection (but has only one ADC) */
12884 #define alc861vd_mux_enum_put alc882_mux_enum_put
12885
12886 /*
12887  * 2ch mode
12888  */
12889 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
12890         { 2, NULL }
12891 };
12892
12893 /*
12894  * 6ch mode
12895  */
12896 static struct hda_verb alc861vd_6stack_ch6_init[] = {
12897         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12898         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12899         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12900         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12901         { } /* end */
12902 };
12903
12904 /*
12905  * 8ch mode
12906  */
12907 static struct hda_verb alc861vd_6stack_ch8_init[] = {
12908         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12909         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12910         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12911         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12912         { } /* end */
12913 };
12914
12915 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
12916         { 6, alc861vd_6stack_ch6_init },
12917         { 8, alc861vd_6stack_ch8_init },
12918 };
12919
12920 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
12921         {
12922                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12923                 .name = "Channel Mode",
12924                 .info = alc_ch_mode_info,
12925                 .get = alc_ch_mode_get,
12926                 .put = alc_ch_mode_put,
12927         },
12928         { } /* end */
12929 };
12930
12931 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
12932         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12933         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12934
12935         {
12936                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12937                 /* The multiple "Capture Source" controls confuse alsamixer
12938                  * So call somewhat different..
12939                  */
12940                 /* .name = "Capture Source", */
12941                 .name = "Input Source",
12942                 .count = 1,
12943                 .info = alc861vd_mux_enum_info,
12944                 .get = alc861vd_mux_enum_get,
12945                 .put = alc861vd_mux_enum_put,
12946         },
12947         { } /* end */
12948 };
12949
12950 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
12951  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
12952  */
12953 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
12954         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12955         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12956
12957         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12958         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
12959
12960         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
12961                                 HDA_OUTPUT),
12962         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
12963                                 HDA_OUTPUT),
12964         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12965         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
12966
12967         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
12968         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
12969
12970         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12971
12972         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12973         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12974         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12975
12976         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12977         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12978         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12979
12980         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12981         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12982
12983         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12984         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12985
12986         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12987         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12988
12989         { } /* end */
12990 };
12991
12992 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
12993         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12994         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12995
12996         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12997
12998         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12999         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13000         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13001
13002         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13003         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13004         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13005
13006         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13007         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13008
13009         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13010         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13011
13012         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13013         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13014
13015         { } /* end */
13016 };
13017
13018 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
13019         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13020         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
13021         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13022
13023         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13024
13025         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13026         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13027         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13028
13029         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13030         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13031         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13032
13033         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13034         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13035
13036         { } /* end */
13037 };
13038
13039 /* Pin assignment: Speaker=0x14, HP = 0x15,
13040  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
13041  */
13042 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
13043         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13044         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
13045         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13046         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
13047         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
13048         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13049         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13050         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
13051         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13052         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13053         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
13054         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
13055         { } /* end */
13056 };
13057
13058 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
13059  *                 Front Mic=0x18, ATAPI Mic = 0x19,
13060  */
13061 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
13062         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13063         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13064         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13065         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
13066         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13067         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13068         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13069         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13070         
13071         { } /* end */
13072 };
13073
13074 /*
13075  * generic initialization of ADC, input mixers and output mixers
13076  */
13077 static struct hda_verb alc861vd_volume_init_verbs[] = {
13078         /*
13079          * Unmute ADC0 and set the default input to mic-in
13080          */
13081         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13082         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13083
13084         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
13085          * the analog-loopback mixer widget
13086          */
13087         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13088         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13089         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13090         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13091         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13092         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13093
13094         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
13095         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13096         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13097         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13098         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13099
13100         /*
13101          * Set up output mixers (0x02 - 0x05)
13102          */
13103         /* set vol=0 to output mixers */
13104         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13105         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13106         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13107         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13108
13109         /* set up input amps for analog loopback */
13110         /* Amp Indices: DAC = 0, mixer = 1 */
13111         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13112         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13113         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13114         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13115         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13116         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13117         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13118         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13119
13120         { }
13121 };
13122
13123 /*
13124  * 3-stack pin configuration:
13125  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
13126  */
13127 static struct hda_verb alc861vd_3stack_init_verbs[] = {
13128         /*
13129          * Set pin mode and muting
13130          */
13131         /* set front pin widgets 0x14 for output */
13132         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13133         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13134         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13135
13136         /* Mic (rear) pin: input vref at 80% */
13137         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13138         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13139         /* Front Mic pin: input vref at 80% */
13140         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13141         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13142         /* Line In pin: input */
13143         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13144         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13145         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13146         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13147         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13148         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13149         /* CD pin widget for input */
13150         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13151
13152         { }
13153 };
13154
13155 /*
13156  * 6-stack pin configuration:
13157  */
13158 static struct hda_verb alc861vd_6stack_init_verbs[] = {
13159         /*
13160          * Set pin mode and muting
13161          */
13162         /* set front pin widgets 0x14 for output */
13163         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13164         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13165         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13166
13167         /* Rear Pin: output 1 (0x0d) */
13168         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13169         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13170         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13171         /* CLFE Pin: output 2 (0x0e) */
13172         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13173         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13174         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
13175         /* Side Pin: output 3 (0x0f) */
13176         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13177         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13178         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
13179
13180         /* Mic (rear) pin: input vref at 80% */
13181         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13182         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13183         /* Front Mic pin: input vref at 80% */
13184         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13185         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13186         /* Line In pin: input */
13187         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13188         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13189         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13190         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13191         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13192         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13193         /* CD pin widget for input */
13194         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13195
13196         { }
13197 };
13198
13199 static struct hda_verb alc861vd_eapd_verbs[] = {
13200         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13201         { }
13202 };
13203
13204 static struct hda_verb alc660vd_eapd_verbs[] = {
13205         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13206         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13207         { }
13208 };
13209
13210 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
13211         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13212         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13213         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
13214         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13215         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 
13216         {}
13217 };
13218
13219 /* toggle speaker-output according to the hp-jack state */
13220 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
13221 {
13222         unsigned int present;
13223         unsigned char bits;
13224
13225         present = snd_hda_codec_read(codec, 0x1b, 0,
13226                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13227         bits = present ? HDA_AMP_MUTE : 0;
13228         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13229                                  HDA_AMP_MUTE, bits);
13230 }
13231
13232 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
13233 {
13234         unsigned int present;
13235         unsigned char bits;
13236
13237         present = snd_hda_codec_read(codec, 0x18, 0,
13238                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13239         bits = present ? HDA_AMP_MUTE : 0;
13240         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
13241                                  HDA_AMP_MUTE, bits);
13242 }
13243
13244 static void alc861vd_lenovo_automute(struct hda_codec *codec)
13245 {
13246         alc861vd_lenovo_hp_automute(codec);
13247         alc861vd_lenovo_mic_automute(codec);
13248 }
13249
13250 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
13251                                         unsigned int res)
13252 {
13253         switch (res >> 26) {
13254         case ALC880_HP_EVENT:
13255                 alc861vd_lenovo_hp_automute(codec);
13256                 break;
13257         case ALC880_MIC_EVENT:
13258                 alc861vd_lenovo_mic_automute(codec);
13259                 break;
13260         }
13261 }
13262
13263 static struct hda_verb alc861vd_dallas_verbs[] = {
13264         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13265         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13266         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13267         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13268
13269         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13270         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13271         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13272         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13273         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13274         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13275         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13276         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13277         
13278         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13279         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13280         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13281         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13282         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13283         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13284         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13285         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13286
13287         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13288         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13289         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13290         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13291         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13292         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13293         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13294         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13295
13296         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13297         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13298         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13299         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13300
13301         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13302         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},  
13303         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13304
13305         { } /* end */
13306 };
13307
13308 /* toggle speaker-output according to the hp-jack state */
13309 static void alc861vd_dallas_automute(struct hda_codec *codec)
13310 {
13311         unsigned int present;
13312
13313         present = snd_hda_codec_read(codec, 0x15, 0,
13314                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13315         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13316                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13317 }
13318
13319 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
13320 {
13321         if ((res >> 26) == ALC880_HP_EVENT)
13322                 alc861vd_dallas_automute(codec);
13323 }
13324
13325 #ifdef CONFIG_SND_HDA_POWER_SAVE
13326 #define alc861vd_loopbacks      alc880_loopbacks
13327 #endif
13328
13329 /* pcm configuration: identiacal with ALC880 */
13330 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
13331 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
13332 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
13333 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
13334
13335 /*
13336  * configuration and preset
13337  */
13338 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
13339         [ALC660VD_3ST]          = "3stack-660",
13340         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
13341         [ALC861VD_3ST]          = "3stack",
13342         [ALC861VD_3ST_DIG]      = "3stack-digout",
13343         [ALC861VD_6ST_DIG]      = "6stack-digout",
13344         [ALC861VD_LENOVO]       = "lenovo",
13345         [ALC861VD_DALLAS]       = "dallas",
13346         [ALC861VD_HP]           = "hp",
13347         [ALC861VD_AUTO]         = "auto",
13348 };
13349
13350 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
13351         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
13352         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
13353         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
13354         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
13355         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC861VD_LENOVO),
13356         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
13357         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
13358         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
13359         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
13360         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
13361         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
13362         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
13363         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
13364         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
13365         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
13366         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
13367         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
13368         {}
13369 };
13370
13371 static struct alc_config_preset alc861vd_presets[] = {
13372         [ALC660VD_3ST] = {
13373                 .mixers = { alc861vd_3st_mixer },
13374                 .init_verbs = { alc861vd_volume_init_verbs,
13375                                  alc861vd_3stack_init_verbs },
13376                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13377                 .dac_nids = alc660vd_dac_nids,
13378                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13379                 .channel_mode = alc861vd_3stack_2ch_modes,
13380                 .input_mux = &alc861vd_capture_source,
13381         },
13382         [ALC660VD_3ST_DIG] = {
13383                 .mixers = { alc861vd_3st_mixer },
13384                 .init_verbs = { alc861vd_volume_init_verbs,
13385                                  alc861vd_3stack_init_verbs },
13386                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13387                 .dac_nids = alc660vd_dac_nids,
13388                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13389                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13390                 .channel_mode = alc861vd_3stack_2ch_modes,
13391                 .input_mux = &alc861vd_capture_source,
13392         },
13393         [ALC861VD_3ST] = {
13394                 .mixers = { alc861vd_3st_mixer },
13395                 .init_verbs = { alc861vd_volume_init_verbs,
13396                                  alc861vd_3stack_init_verbs },
13397                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13398                 .dac_nids = alc861vd_dac_nids,
13399                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13400                 .channel_mode = alc861vd_3stack_2ch_modes,
13401                 .input_mux = &alc861vd_capture_source,
13402         },
13403         [ALC861VD_3ST_DIG] = {
13404                 .mixers = { alc861vd_3st_mixer },
13405                 .init_verbs = { alc861vd_volume_init_verbs,
13406                                  alc861vd_3stack_init_verbs },
13407                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13408                 .dac_nids = alc861vd_dac_nids,
13409                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13410                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13411                 .channel_mode = alc861vd_3stack_2ch_modes,
13412                 .input_mux = &alc861vd_capture_source,
13413         },
13414         [ALC861VD_6ST_DIG] = {
13415                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
13416                 .init_verbs = { alc861vd_volume_init_verbs,
13417                                 alc861vd_6stack_init_verbs },
13418                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13419                 .dac_nids = alc861vd_dac_nids,
13420                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13421                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
13422                 .channel_mode = alc861vd_6stack_modes,
13423                 .input_mux = &alc861vd_capture_source,
13424         },
13425         [ALC861VD_LENOVO] = {
13426                 .mixers = { alc861vd_lenovo_mixer },
13427                 .init_verbs = { alc861vd_volume_init_verbs,
13428                                 alc861vd_3stack_init_verbs,
13429                                 alc861vd_eapd_verbs,
13430                                 alc861vd_lenovo_unsol_verbs },
13431                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13432                 .dac_nids = alc660vd_dac_nids,
13433                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13434                 .channel_mode = alc861vd_3stack_2ch_modes,
13435                 .input_mux = &alc861vd_capture_source,
13436                 .unsol_event = alc861vd_lenovo_unsol_event,
13437                 .init_hook = alc861vd_lenovo_automute,
13438         },
13439         [ALC861VD_DALLAS] = {
13440                 .mixers = { alc861vd_dallas_mixer },
13441                 .init_verbs = { alc861vd_dallas_verbs },
13442                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13443                 .dac_nids = alc861vd_dac_nids,
13444                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13445                 .channel_mode = alc861vd_3stack_2ch_modes,
13446                 .input_mux = &alc861vd_dallas_capture_source,
13447                 .unsol_event = alc861vd_dallas_unsol_event,
13448                 .init_hook = alc861vd_dallas_automute,
13449         },
13450         [ALC861VD_HP] = {
13451                 .mixers = { alc861vd_hp_mixer },
13452                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
13453                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13454                 .dac_nids = alc861vd_dac_nids,
13455                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13456                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13457                 .channel_mode = alc861vd_3stack_2ch_modes,
13458                 .input_mux = &alc861vd_hp_capture_source,
13459                 .unsol_event = alc861vd_dallas_unsol_event,
13460                 .init_hook = alc861vd_dallas_automute,
13461         },              
13462 };
13463
13464 /*
13465  * BIOS auto configuration
13466  */
13467 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
13468                                 hda_nid_t nid, int pin_type, int dac_idx)
13469 {
13470         alc_set_pin_output(codec, nid, pin_type);
13471 }
13472
13473 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
13474 {
13475         struct alc_spec *spec = codec->spec;
13476         int i;
13477
13478         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
13479         for (i = 0; i <= HDA_SIDE; i++) {
13480                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13481                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13482                 if (nid)
13483                         alc861vd_auto_set_output_and_unmute(codec, nid,
13484                                                             pin_type, i);
13485         }
13486 }
13487
13488
13489 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
13490 {
13491         struct alc_spec *spec = codec->spec;
13492         hda_nid_t pin;
13493
13494         pin = spec->autocfg.hp_pins[0];
13495         if (pin) /* connect to front and  use dac 0 */
13496                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
13497         pin = spec->autocfg.speaker_pins[0];
13498         if (pin)
13499                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13500 }
13501
13502 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
13503 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
13504
13505 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
13506 {
13507         struct alc_spec *spec = codec->spec;
13508         int i;
13509
13510         for (i = 0; i < AUTO_PIN_LAST; i++) {
13511                 hda_nid_t nid = spec->autocfg.input_pins[i];
13512                 if (alc861vd_is_input_pin(nid)) {
13513                         snd_hda_codec_write(codec, nid, 0,
13514                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
13515                                         i <= AUTO_PIN_FRONT_MIC ?
13516                                                         PIN_VREF80 : PIN_IN);
13517                         if (nid != ALC861VD_PIN_CD_NID)
13518                                 snd_hda_codec_write(codec, nid, 0,
13519                                                 AC_VERB_SET_AMP_GAIN_MUTE,
13520                                                 AMP_OUT_MUTE);
13521                 }
13522         }
13523 }
13524
13525 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
13526
13527 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
13528 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
13529
13530 /* add playback controls from the parsed DAC table */
13531 /* Based on ALC880 version. But ALC861VD has separate,
13532  * different NIDs for mute/unmute switch and volume control */
13533 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
13534                                              const struct auto_pin_cfg *cfg)
13535 {
13536         char name[32];
13537         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
13538         hda_nid_t nid_v, nid_s;
13539         int i, err;
13540
13541         for (i = 0; i < cfg->line_outs; i++) {
13542                 if (!spec->multiout.dac_nids[i])
13543                         continue;
13544                 nid_v = alc861vd_idx_to_mixer_vol(
13545                                 alc880_dac_to_idx(
13546                                         spec->multiout.dac_nids[i]));
13547                 nid_s = alc861vd_idx_to_mixer_switch(
13548                                 alc880_dac_to_idx(
13549                                         spec->multiout.dac_nids[i]));
13550
13551                 if (i == 2) {
13552                         /* Center/LFE */
13553                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13554                                           "Center Playback Volume",
13555                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
13556                                                               HDA_OUTPUT));
13557                         if (err < 0)
13558                                 return err;
13559                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13560                                           "LFE Playback Volume",
13561                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
13562                                                               HDA_OUTPUT));
13563                         if (err < 0)
13564                                 return err;
13565                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13566                                           "Center Playback Switch",
13567                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
13568                                                               HDA_INPUT));
13569                         if (err < 0)
13570                                 return err;
13571                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13572                                           "LFE Playback Switch",
13573                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
13574                                                               HDA_INPUT));
13575                         if (err < 0)
13576                                 return err;
13577                 } else {
13578                         sprintf(name, "%s Playback Volume", chname[i]);
13579                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13580                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
13581                                                               HDA_OUTPUT));
13582                         if (err < 0)
13583                                 return err;
13584                         sprintf(name, "%s Playback Switch", chname[i]);
13585                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13586                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
13587                                                               HDA_INPUT));
13588                         if (err < 0)
13589                                 return err;
13590                 }
13591         }
13592         return 0;
13593 }
13594
13595 /* add playback controls for speaker and HP outputs */
13596 /* Based on ALC880 version. But ALC861VD has separate,
13597  * different NIDs for mute/unmute switch and volume control */
13598 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
13599                                         hda_nid_t pin, const char *pfx)
13600 {
13601         hda_nid_t nid_v, nid_s;
13602         int err;
13603         char name[32];
13604
13605         if (!pin)
13606                 return 0;
13607
13608         if (alc880_is_fixed_pin(pin)) {
13609                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
13610                 /* specify the DAC as the extra output */
13611                 if (!spec->multiout.hp_nid)
13612                         spec->multiout.hp_nid = nid_v;
13613                 else
13614                         spec->multiout.extra_out_nid[0] = nid_v;
13615                 /* control HP volume/switch on the output mixer amp */
13616                 nid_v = alc861vd_idx_to_mixer_vol(
13617                                 alc880_fixed_pin_idx(pin));
13618                 nid_s = alc861vd_idx_to_mixer_switch(
13619                                 alc880_fixed_pin_idx(pin));
13620
13621                 sprintf(name, "%s Playback Volume", pfx);
13622                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13623                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
13624                 if (err < 0)
13625                         return err;
13626                 sprintf(name, "%s Playback Switch", pfx);
13627                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13628                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
13629                 if (err < 0)
13630                         return err;
13631         } else if (alc880_is_multi_pin(pin)) {
13632                 /* set manual connection */
13633                 /* we have only a switch on HP-out PIN */
13634                 sprintf(name, "%s Playback Switch", pfx);
13635                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
13636                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
13637                 if (err < 0)
13638                         return err;
13639         }
13640         return 0;
13641 }
13642
13643 /* parse the BIOS configuration and set up the alc_spec
13644  * return 1 if successful, 0 if the proper config is not found,
13645  * or a negative error code
13646  * Based on ALC880 version - had to change it to override
13647  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
13648 static int alc861vd_parse_auto_config(struct hda_codec *codec)
13649 {
13650         struct alc_spec *spec = codec->spec;
13651         int err;
13652         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
13653
13654         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13655                                            alc861vd_ignore);
13656         if (err < 0)
13657                 return err;
13658         if (!spec->autocfg.line_outs)
13659                 return 0; /* can't find valid BIOS pin config */
13660
13661         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
13662         if (err < 0)
13663                 return err;
13664         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
13665         if (err < 0)
13666                 return err;
13667         err = alc861vd_auto_create_extra_out(spec,
13668                                              spec->autocfg.speaker_pins[0],
13669                                              "Speaker");
13670         if (err < 0)
13671                 return err;
13672         err = alc861vd_auto_create_extra_out(spec,
13673                                              spec->autocfg.hp_pins[0],
13674                                              "Headphone");
13675         if (err < 0)
13676                 return err;
13677         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
13678         if (err < 0)
13679                 return err;
13680
13681         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13682
13683         if (spec->autocfg.dig_out_pin)
13684                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
13685
13686         if (spec->kctl_alloc)
13687                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13688
13689         spec->init_verbs[spec->num_init_verbs++]
13690                 = alc861vd_volume_init_verbs;
13691
13692         spec->num_mux_defs = 1;
13693         spec->input_mux = &spec->private_imux;
13694
13695         err = alc_auto_add_mic_boost(codec);
13696         if (err < 0)
13697                 return err;
13698
13699         store_pin_configs(codec);
13700         return 1;
13701 }
13702
13703 /* additional initialization for auto-configuration model */
13704 static void alc861vd_auto_init(struct hda_codec *codec)
13705 {
13706         struct alc_spec *spec = codec->spec;
13707         alc861vd_auto_init_multi_out(codec);
13708         alc861vd_auto_init_hp_out(codec);
13709         alc861vd_auto_init_analog_input(codec);
13710         alc861vd_auto_init_input_src(codec);
13711         if (spec->unsol_event)
13712                 alc_sku_automute(codec);
13713 }
13714
13715 static int patch_alc861vd(struct hda_codec *codec)
13716 {
13717         struct alc_spec *spec;
13718         int err, board_config;
13719
13720         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13721         if (spec == NULL)
13722                 return -ENOMEM;
13723
13724         codec->spec = spec;
13725
13726         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
13727                                                   alc861vd_models,
13728                                                   alc861vd_cfg_tbl);
13729
13730         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
13731                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
13732                         "ALC861VD, trying auto-probe from BIOS...\n");
13733                 board_config = ALC861VD_AUTO;
13734         }
13735
13736         if (board_config == ALC861VD_AUTO) {
13737                 /* automatic parse from the BIOS config */
13738                 err = alc861vd_parse_auto_config(codec);
13739                 if (err < 0) {
13740                         alc_free(codec);
13741                         return err;
13742                 } else if (!err) {
13743                         printk(KERN_INFO
13744                                "hda_codec: Cannot set up configuration "
13745                                "from BIOS.  Using base mode...\n");
13746                         board_config = ALC861VD_3ST;
13747                 }
13748         }
13749
13750         if (board_config != ALC861VD_AUTO)
13751                 setup_preset(spec, &alc861vd_presets[board_config]);
13752
13753         if (codec->vendor_id == 0x10ec0660) {
13754                 spec->stream_name_analog = "ALC660-VD Analog";
13755                 spec->stream_name_digital = "ALC660-VD Digital";
13756                 /* always turn on EAPD */
13757                 spec->init_verbs[spec->num_init_verbs++] = alc660vd_eapd_verbs;
13758         } else {
13759                 spec->stream_name_analog = "ALC861VD Analog";
13760                 spec->stream_name_digital = "ALC861VD Digital";
13761         }
13762
13763         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
13764         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
13765
13766         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
13767         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
13768
13769         spec->adc_nids = alc861vd_adc_nids;
13770         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
13771         spec->capsrc_nids = alc861vd_capsrc_nids;
13772
13773         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
13774         spec->num_mixers++;
13775
13776         spec->vmaster_nid = 0x02;
13777
13778         codec->patch_ops = alc_patch_ops;
13779
13780         if (board_config == ALC861VD_AUTO)
13781                 spec->init_hook = alc861vd_auto_init;
13782 #ifdef CONFIG_SND_HDA_POWER_SAVE
13783         if (!spec->loopback.amplist)
13784                 spec->loopback.amplist = alc861vd_loopbacks;
13785 #endif
13786
13787         return 0;
13788 }
13789
13790 /*
13791  * ALC662 support
13792  *
13793  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
13794  * configuration.  Each pin widget can choose any input DACs and a mixer.
13795  * Each ADC is connected from a mixer of all inputs.  This makes possible
13796  * 6-channel independent captures.
13797  *
13798  * In addition, an independent DAC for the multi-playback (not used in this
13799  * driver yet).
13800  */
13801 #define ALC662_DIGOUT_NID       0x06
13802 #define ALC662_DIGIN_NID        0x0a
13803
13804 static hda_nid_t alc662_dac_nids[4] = {
13805         /* front, rear, clfe, rear_surr */
13806         0x02, 0x03, 0x04
13807 };
13808
13809 static hda_nid_t alc662_adc_nids[1] = {
13810         /* ADC1-2 */
13811         0x09,
13812 };
13813
13814 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
13815
13816 /* input MUX */
13817 /* FIXME: should be a matrix-type input source selection */
13818 static struct hda_input_mux alc662_capture_source = {
13819         .num_items = 4,
13820         .items = {
13821                 { "Mic", 0x0 },
13822                 { "Front Mic", 0x1 },
13823                 { "Line", 0x2 },
13824                 { "CD", 0x4 },
13825         },
13826 };
13827
13828 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
13829         .num_items = 2,
13830         .items = {
13831                 { "Mic", 0x1 },
13832                 { "Line", 0x2 },
13833         },
13834 };
13835
13836 static struct hda_input_mux alc662_eeepc_capture_source = {
13837         .num_items = 2,
13838         .items = {
13839                 { "i-Mic", 0x1 },
13840                 { "e-Mic", 0x0 },
13841         },
13842 };
13843
13844 static struct hda_input_mux alc663_capture_source = {
13845         .num_items = 3,
13846         .items = {
13847                 { "Mic", 0x0 },
13848                 { "Front Mic", 0x1 },
13849                 { "Line", 0x2 },
13850         },
13851 };
13852
13853 static struct hda_input_mux alc663_m51va_capture_source = {
13854         .num_items = 2,
13855         .items = {
13856                 { "Ext-Mic", 0x0 },
13857                 { "D-Mic", 0x9 },
13858         },
13859 };
13860
13861 #define alc662_mux_enum_info alc_mux_enum_info
13862 #define alc662_mux_enum_get alc_mux_enum_get
13863 #define alc662_mux_enum_put alc882_mux_enum_put
13864
13865 /*
13866  * 2ch mode
13867  */
13868 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
13869         { 2, NULL }
13870 };
13871
13872 /*
13873  * 2ch mode
13874  */
13875 static struct hda_verb alc662_3ST_ch2_init[] = {
13876         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
13877         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13878         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
13879         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13880         { } /* end */
13881 };
13882
13883 /*
13884  * 6ch mode
13885  */
13886 static struct hda_verb alc662_3ST_ch6_init[] = {
13887         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13888         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13889         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
13890         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13891         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13892         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
13893         { } /* end */
13894 };
13895
13896 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
13897         { 2, alc662_3ST_ch2_init },
13898         { 6, alc662_3ST_ch6_init },
13899 };
13900
13901 /*
13902  * 2ch mode
13903  */
13904 static struct hda_verb alc662_sixstack_ch6_init[] = {
13905         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13906         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13907         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13908         { } /* end */
13909 };
13910
13911 /*
13912  * 6ch mode
13913  */
13914 static struct hda_verb alc662_sixstack_ch8_init[] = {
13915         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13916         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13917         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13918         { } /* end */
13919 };
13920
13921 static struct hda_channel_mode alc662_5stack_modes[2] = {
13922         { 2, alc662_sixstack_ch6_init },
13923         { 6, alc662_sixstack_ch8_init },
13924 };
13925
13926 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13927  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13928  */
13929
13930 static struct snd_kcontrol_new alc662_base_mixer[] = {
13931         /* output mixer control */
13932         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13933         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13934         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13935         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
13936         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13937         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13938         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
13939         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
13940         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13941
13942         /*Input mixer control */
13943         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
13944         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
13945         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
13946         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
13947         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
13948         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
13949         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
13950         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
13951         { } /* end */
13952 };
13953
13954 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
13955         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13956         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13957         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13958         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13959         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13960         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13961         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13962         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13963         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13964         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13965         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13966         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13967         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13968         { } /* end */
13969 };
13970
13971 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
13972         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13973         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13974         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13975         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
13976         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13977         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13978         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
13979         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
13980         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13981         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13982         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13983         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13984         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13985         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13986         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13987         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13988         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13989         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13990         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13991         { } /* end */
13992 };
13993
13994 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
13995         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13996         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
13997         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13998         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
13999         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14000         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14001         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14002         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14003         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14004         { } /* end */
14005 };
14006
14007 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
14008         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14009
14010         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14011         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14012
14013         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
14014         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14015         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14016
14017         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
14018         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14019         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14020         { } /* end */
14021 };
14022
14023 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
14024         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14025         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14026         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14027         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
14028         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14029         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14030         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
14031         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
14032         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14033         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
14034         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14035         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14036         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14037         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14038         { } /* end */
14039 };
14040
14041 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
14042         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14043         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14044         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14045         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14046         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14047         HDA_CODEC_MUTE("DMic Playback Switch", 0x23, 0x9, HDA_INPUT),
14048         { } /* end */
14049 };
14050
14051 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
14052         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14053         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14054         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14055         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14056         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14057
14058         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14059         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14060         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14061         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14062         { } /* end */
14063 };
14064
14065 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
14066         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14067         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14068         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14069
14070         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14071         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14072         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14073         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14074         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14075         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14076         { } /* end */
14077 };
14078
14079 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
14080         {
14081                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14082                 .name = "Channel Mode",
14083                 .info = alc_ch_mode_info,
14084                 .get = alc_ch_mode_get,
14085                 .put = alc_ch_mode_put,
14086         },
14087         { } /* end */
14088 };
14089
14090 static struct hda_verb alc662_init_verbs[] = {
14091         /* ADC: mute amp left and right */
14092         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14093         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14094         /* Front mixer: unmute input/output amp left and right (volume = 0) */
14095
14096         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14097         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14098         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14099         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14100         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14101
14102         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14103         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14104         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14105         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14106         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14107         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14108
14109         /* Front Pin: output 0 (0x0c) */
14110         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14111         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14112
14113         /* Rear Pin: output 1 (0x0d) */
14114         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14115         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14116
14117         /* CLFE Pin: output 2 (0x0e) */
14118         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14119         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14120
14121         /* Mic (rear) pin: input vref at 80% */
14122         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14123         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14124         /* Front Mic pin: input vref at 80% */
14125         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14126         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14127         /* Line In pin: input */
14128         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14129         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14130         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14131         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14132         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14133         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14134         /* CD pin widget for input */
14135         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14136
14137         /* FIXME: use matrix-type input source selection */
14138         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
14139         /* Input mixer */
14140         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14141         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14142         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14143         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14144
14145         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14146         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14147         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14148         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14149
14150         /* always trun on EAPD */
14151         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14152         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14153
14154         { }
14155 };
14156
14157 static struct hda_verb alc662_sue_init_verbs[] = {
14158         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
14159         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
14160         {}
14161 };
14162
14163 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
14164         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14165         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14166         {}
14167 };
14168
14169 /* Set Unsolicited Event*/
14170 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
14171         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14172         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14173         {}
14174 };
14175
14176 /*
14177  * generic initialization of ADC, input mixers and output mixers
14178  */
14179 static struct hda_verb alc662_auto_init_verbs[] = {
14180         /*
14181          * Unmute ADC and set the default input to mic-in
14182          */
14183         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14184         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14185
14186         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
14187          * mixer widget
14188          * Note: PASD motherboards uses the Line In 2 as the input for front
14189          * panel mic (mic 2)
14190          */
14191         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14192         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14193         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14194         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14195         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14196         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14197
14198         /*
14199          * Set up output mixers (0x0c - 0x0f)
14200          */
14201         /* set vol=0 to output mixers */
14202         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14203         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14204         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14205
14206         /* set up input amps for analog loopback */
14207         /* Amp Indices: DAC = 0, mixer = 1 */
14208         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14209         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14210         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14211         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14212         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14213         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14214
14215
14216         /* FIXME: use matrix-type input source selection */
14217         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
14218         /* Input mixer */
14219         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14220         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14221         { }
14222 };
14223
14224 /* additional verbs for ALC663 */
14225 static struct hda_verb alc663_auto_init_verbs[] = {
14226         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14227         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14228         { }
14229 };
14230
14231 static struct hda_verb alc663_m51va_init_verbs[] = {
14232         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14233         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14234         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14235
14236         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
14237
14238         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14239         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14240         {}
14241 };
14242
14243 static struct hda_verb alc663_g71v_init_verbs[] = {
14244         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14245         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
14246         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
14247
14248         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14249         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14250         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14251
14252         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
14253         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
14254         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
14255         {}
14256 };
14257
14258 static struct hda_verb alc663_g50v_init_verbs[] = {
14259         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14260         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14261         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14262
14263         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14264         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14265         {}
14266 };
14267
14268 /* capture mixer elements */
14269 static struct snd_kcontrol_new alc662_capture_mixer[] = {
14270         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
14271         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
14272         {
14273                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14274                 /* The multiple "Capture Source" controls confuse alsamixer
14275                  * So call somewhat different..
14276                  */
14277                 /* .name = "Capture Source", */
14278                 .name = "Input Source",
14279                 .count = 1,
14280                 .info = alc662_mux_enum_info,
14281                 .get = alc662_mux_enum_get,
14282                 .put = alc662_mux_enum_put,
14283         },
14284         { } /* end */
14285 };
14286
14287 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
14288 {
14289         unsigned int present;
14290         unsigned char bits;
14291
14292         present = snd_hda_codec_read(codec, 0x14, 0,
14293                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14294         bits = present ? HDA_AMP_MUTE : 0;
14295         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14296                                  HDA_AMP_MUTE, bits);
14297 }
14298
14299 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
14300 {
14301         unsigned int present;
14302         unsigned char bits;
14303
14304         present = snd_hda_codec_read(codec, 0x1b, 0,
14305                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14306         bits = present ? HDA_AMP_MUTE : 0;
14307         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14308                                  HDA_AMP_MUTE, bits);
14309         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14310                                  HDA_AMP_MUTE, bits);
14311 }
14312
14313 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
14314                                            unsigned int res)
14315 {
14316         if ((res >> 26) == ALC880_HP_EVENT)
14317                 alc662_lenovo_101e_all_automute(codec);
14318         if ((res >> 26) == ALC880_FRONT_EVENT)
14319                 alc662_lenovo_101e_ispeaker_automute(codec);
14320 }
14321
14322 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
14323 {
14324         unsigned int present;
14325
14326         present = snd_hda_codec_read(codec, 0x18, 0,
14327                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14328         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14329                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14330         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14331                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14332         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14333                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
14334         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14335                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
14336 }
14337
14338 /* unsolicited event for HP jack sensing */
14339 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
14340                                      unsigned int res)
14341 {
14342         if ((res >> 26) == ALC880_HP_EVENT)
14343                 alc262_hippo1_automute( codec );
14344
14345         if ((res >> 26) == ALC880_MIC_EVENT)
14346                 alc662_eeepc_mic_automute(codec);
14347 }
14348
14349 static void alc662_eeepc_inithook(struct hda_codec *codec)
14350 {
14351         alc262_hippo1_automute( codec );
14352         alc662_eeepc_mic_automute(codec);
14353 }
14354
14355 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
14356 {
14357         unsigned int mute;
14358         unsigned int present;
14359
14360         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
14361         present = snd_hda_codec_read(codec, 0x14, 0,
14362                                      AC_VERB_GET_PIN_SENSE, 0);
14363         present = (present & 0x80000000) != 0;
14364         if (present) {
14365                 /* mute internal speaker */
14366                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
14367                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
14368         } else {
14369                 /* unmute internal speaker if necessary */
14370                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
14371                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
14372                                          HDA_AMP_MUTE, mute);
14373         }
14374 }
14375
14376 /* unsolicited event for HP jack sensing */
14377 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
14378                                           unsigned int res)
14379 {
14380         if ((res >> 26) == ALC880_HP_EVENT)
14381                 alc662_eeepc_ep20_automute(codec);
14382 }
14383
14384 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
14385 {
14386         alc662_eeepc_ep20_automute(codec);
14387 }
14388
14389 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
14390 {
14391         unsigned int present;
14392         unsigned char bits;
14393
14394         present = snd_hda_codec_read(codec, 0x21, 0,
14395                                      AC_VERB_GET_PIN_SENSE, 0)
14396                 & AC_PINSENSE_PRESENCE;
14397         bits = present ? HDA_AMP_MUTE : 0;
14398         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14399                                  HDA_AMP_MUTE, bits);
14400 }
14401
14402 static void alc663_m51va_mic_automute(struct hda_codec *codec)
14403 {
14404         unsigned int present;
14405
14406         present = snd_hda_codec_read(codec, 0x18, 0,
14407                                      AC_VERB_GET_PIN_SENSE, 0)
14408                 & AC_PINSENSE_PRESENCE;
14409         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14410                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14411         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14412                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14413         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14414                             0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
14415         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14416                             0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
14417 }
14418
14419 static void alc663_m51va_unsol_event(struct hda_codec *codec,
14420                                            unsigned int res)
14421 {
14422         switch (res >> 26) {
14423         case ALC880_HP_EVENT:
14424                 alc663_m51va_speaker_automute(codec);
14425                 break;
14426         case ALC880_MIC_EVENT:
14427                 alc663_m51va_mic_automute(codec);
14428                 break;
14429         }
14430 }
14431
14432 static void alc663_m51va_inithook(struct hda_codec *codec)
14433 {
14434         alc663_m51va_speaker_automute(codec);
14435         alc663_m51va_mic_automute(codec);
14436 }
14437
14438 static void alc663_g71v_hp_automute(struct hda_codec *codec)
14439 {
14440         unsigned int present;
14441         unsigned char bits;
14442
14443         present = snd_hda_codec_read(codec, 0x21, 0,
14444                                      AC_VERB_GET_PIN_SENSE, 0)
14445                 & AC_PINSENSE_PRESENCE;
14446         bits = present ? HDA_AMP_MUTE : 0;
14447         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14448                                  HDA_AMP_MUTE, bits);
14449         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14450                                  HDA_AMP_MUTE, bits);
14451 }
14452
14453 static void alc663_g71v_front_automute(struct hda_codec *codec)
14454 {
14455         unsigned int present;
14456         unsigned char bits;
14457
14458         present = snd_hda_codec_read(codec, 0x15, 0,
14459                                      AC_VERB_GET_PIN_SENSE, 0)
14460                 & AC_PINSENSE_PRESENCE;
14461         bits = present ? HDA_AMP_MUTE : 0;
14462         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14463                                  HDA_AMP_MUTE, bits);
14464 }
14465
14466 static void alc663_g71v_unsol_event(struct hda_codec *codec,
14467                                            unsigned int res)
14468 {
14469         switch (res >> 26) {
14470         case ALC880_HP_EVENT:
14471                 alc663_g71v_hp_automute(codec);
14472                 break;
14473         case ALC880_FRONT_EVENT:
14474                 alc663_g71v_front_automute(codec);
14475                 break;
14476         case ALC880_MIC_EVENT:
14477                 alc662_eeepc_mic_automute(codec);
14478                 break;
14479         }
14480 }
14481
14482 static void alc663_g71v_inithook(struct hda_codec *codec)
14483 {
14484         alc663_g71v_front_automute(codec);
14485         alc663_g71v_hp_automute(codec);
14486         alc662_eeepc_mic_automute(codec);
14487 }
14488
14489 static void alc663_g50v_unsol_event(struct hda_codec *codec,
14490                                            unsigned int res)
14491 {
14492         switch (res >> 26) {
14493         case ALC880_HP_EVENT:
14494                 alc663_m51va_speaker_automute(codec);
14495                 break;
14496         case ALC880_MIC_EVENT:
14497                 alc662_eeepc_mic_automute(codec);
14498                 break;
14499         }
14500 }
14501
14502 static void alc663_g50v_inithook(struct hda_codec *codec)
14503 {
14504         alc663_m51va_speaker_automute(codec);
14505         alc662_eeepc_mic_automute(codec);
14506 }
14507
14508 #ifdef CONFIG_SND_HDA_POWER_SAVE
14509 #define alc662_loopbacks        alc880_loopbacks
14510 #endif
14511
14512
14513 /* pcm configuration: identiacal with ALC880 */
14514 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
14515 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
14516 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
14517 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
14518
14519 /*
14520  * configuration and preset
14521  */
14522 static const char *alc662_models[ALC662_MODEL_LAST] = {
14523         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
14524         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
14525         [ALC662_3ST_6ch]        = "3stack-6ch",
14526         [ALC662_5ST_DIG]        = "6stack-dig",
14527         [ALC662_LENOVO_101E]    = "lenovo-101e",
14528         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
14529         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
14530         [ALC663_ASUS_M51VA] = "m51va",
14531         [ALC663_ASUS_G71V] = "g71v",
14532         [ALC663_ASUS_H13] = "h13",
14533         [ALC663_ASUS_G50V] = "g50v",
14534         [ALC662_AUTO]           = "auto",
14535 };
14536
14537 static struct snd_pci_quirk alc662_cfg_tbl[] = {
14538         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS G71V", ALC663_ASUS_G71V),
14539         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
14540         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS M51VA", ALC663_ASUS_G50V),
14541         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
14542         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
14543         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
14544         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
14545         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
14546         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
14547         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
14548         {}
14549 };
14550
14551 static struct alc_config_preset alc662_presets[] = {
14552         [ALC662_3ST_2ch_DIG] = {
14553                 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer },
14554                 .init_verbs = { alc662_init_verbs },
14555                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14556                 .dac_nids = alc662_dac_nids,
14557                 .dig_out_nid = ALC662_DIGOUT_NID,
14558                 .dig_in_nid = ALC662_DIGIN_NID,
14559                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14560                 .channel_mode = alc662_3ST_2ch_modes,
14561                 .input_mux = &alc662_capture_source,
14562         },
14563         [ALC662_3ST_6ch_DIG] = {
14564                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
14565                             alc662_capture_mixer },
14566                 .init_verbs = { alc662_init_verbs },
14567                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14568                 .dac_nids = alc662_dac_nids,
14569                 .dig_out_nid = ALC662_DIGOUT_NID,
14570                 .dig_in_nid = ALC662_DIGIN_NID,
14571                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14572                 .channel_mode = alc662_3ST_6ch_modes,
14573                 .need_dac_fix = 1,
14574                 .input_mux = &alc662_capture_source,
14575         },
14576         [ALC662_3ST_6ch] = {
14577                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
14578                             alc662_capture_mixer },
14579                 .init_verbs = { alc662_init_verbs },
14580                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14581                 .dac_nids = alc662_dac_nids,
14582                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14583                 .channel_mode = alc662_3ST_6ch_modes,
14584                 .need_dac_fix = 1,
14585                 .input_mux = &alc662_capture_source,
14586         },
14587         [ALC662_5ST_DIG] = {
14588                 .mixers = { alc662_base_mixer, alc662_chmode_mixer,
14589                             alc662_capture_mixer },
14590                 .init_verbs = { alc662_init_verbs },
14591                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14592                 .dac_nids = alc662_dac_nids,
14593                 .dig_out_nid = ALC662_DIGOUT_NID,
14594                 .dig_in_nid = ALC662_DIGIN_NID,
14595                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
14596                 .channel_mode = alc662_5stack_modes,
14597                 .input_mux = &alc662_capture_source,
14598         },
14599         [ALC662_LENOVO_101E] = {
14600                 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer },
14601                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
14602                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14603                 .dac_nids = alc662_dac_nids,
14604                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14605                 .channel_mode = alc662_3ST_2ch_modes,
14606                 .input_mux = &alc662_lenovo_101e_capture_source,
14607                 .unsol_event = alc662_lenovo_101e_unsol_event,
14608                 .init_hook = alc662_lenovo_101e_all_automute,
14609         },
14610         [ALC662_ASUS_EEEPC_P701] = {
14611                 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer },
14612                 .init_verbs = { alc662_init_verbs,
14613                                 alc662_eeepc_sue_init_verbs },
14614                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14615                 .dac_nids = alc662_dac_nids,
14616                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14617                 .channel_mode = alc662_3ST_2ch_modes,
14618                 .input_mux = &alc662_eeepc_capture_source,
14619                 .unsol_event = alc662_eeepc_unsol_event,
14620                 .init_hook = alc662_eeepc_inithook,
14621         },
14622         [ALC662_ASUS_EEEPC_EP20] = {
14623                 .mixers = { alc662_eeepc_ep20_mixer, alc662_capture_mixer,
14624                             alc662_chmode_mixer },
14625                 .init_verbs = { alc662_init_verbs,
14626                                 alc662_eeepc_ep20_sue_init_verbs },
14627                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14628                 .dac_nids = alc662_dac_nids,
14629                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14630                 .channel_mode = alc662_3ST_6ch_modes,
14631                 .input_mux = &alc662_lenovo_101e_capture_source,
14632                 .unsol_event = alc662_eeepc_ep20_unsol_event,
14633                 .init_hook = alc662_eeepc_ep20_inithook,
14634         },
14635         [ALC663_ASUS_M51VA] = {
14636                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
14637                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
14638                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14639                 .dac_nids = alc662_dac_nids,
14640                 .dig_out_nid = ALC662_DIGOUT_NID,
14641                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14642                 .channel_mode = alc662_3ST_2ch_modes,
14643                 .input_mux = &alc663_m51va_capture_source,
14644                 .unsol_event = alc663_m51va_unsol_event,
14645                 .init_hook = alc663_m51va_inithook,
14646         },
14647         [ALC663_ASUS_G71V] = {
14648                 .mixers = { alc663_g71v_mixer, alc662_capture_mixer},
14649                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
14650                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14651                 .dac_nids = alc662_dac_nids,
14652                 .dig_out_nid = ALC662_DIGOUT_NID,
14653                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14654                 .channel_mode = alc662_3ST_2ch_modes,
14655                 .input_mux = &alc662_eeepc_capture_source,
14656                 .unsol_event = alc663_g71v_unsol_event,
14657                 .init_hook = alc663_g71v_inithook,
14658         },
14659         [ALC663_ASUS_H13] = {
14660                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
14661                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
14662                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14663                 .dac_nids = alc662_dac_nids,
14664                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14665                 .channel_mode = alc662_3ST_2ch_modes,
14666                 .input_mux = &alc663_m51va_capture_source,
14667                 .unsol_event = alc663_m51va_unsol_event,
14668                 .init_hook = alc663_m51va_inithook,
14669         },
14670         [ALC663_ASUS_G50V] = {
14671                 .mixers = { alc663_g50v_mixer, alc662_capture_mixer},
14672                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
14673                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14674                 .dac_nids = alc662_dac_nids,
14675                 .dig_out_nid = ALC662_DIGOUT_NID,
14676                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14677                 .channel_mode = alc662_3ST_6ch_modes,
14678                 .input_mux = &alc663_capture_source,
14679                 .unsol_event = alc663_g50v_unsol_event,
14680                 .init_hook = alc663_g50v_inithook,
14681         },
14682 };
14683
14684
14685 /*
14686  * BIOS auto configuration
14687  */
14688
14689 /* add playback controls from the parsed DAC table */
14690 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
14691                                              const struct auto_pin_cfg *cfg)
14692 {
14693         char name[32];
14694         static const char *chname[4] = {
14695                 "Front", "Surround", NULL /*CLFE*/, "Side"
14696         };
14697         hda_nid_t nid;
14698         int i, err;
14699
14700         for (i = 0; i < cfg->line_outs; i++) {
14701                 if (!spec->multiout.dac_nids[i])
14702                         continue;
14703                 nid = alc880_idx_to_dac(i);
14704                 if (i == 2) {
14705                         /* Center/LFE */
14706                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14707                                           "Center Playback Volume",
14708                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
14709                                                               HDA_OUTPUT));
14710                         if (err < 0)
14711                                 return err;
14712                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14713                                           "LFE Playback Volume",
14714                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
14715                                                               HDA_OUTPUT));
14716                         if (err < 0)
14717                                 return err;
14718                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14719                                           "Center Playback Switch",
14720                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
14721                                                               HDA_INPUT));
14722                         if (err < 0)
14723                                 return err;
14724                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14725                                           "LFE Playback Switch",
14726                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
14727                                                               HDA_INPUT));
14728                         if (err < 0)
14729                                 return err;
14730                 } else {
14731                         sprintf(name, "%s Playback Volume", chname[i]);
14732                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14733                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
14734                                                               HDA_OUTPUT));
14735                         if (err < 0)
14736                                 return err;
14737                         sprintf(name, "%s Playback Switch", chname[i]);
14738                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14739                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
14740                                                               HDA_INPUT));
14741                         if (err < 0)
14742                                 return err;
14743                 }
14744         }
14745         return 0;
14746 }
14747
14748 /* add playback controls for speaker and HP outputs */
14749 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
14750                                         const char *pfx)
14751 {
14752         hda_nid_t nid;
14753         int err;
14754         char name[32];
14755
14756         if (!pin)
14757                 return 0;
14758
14759         if (pin == 0x17) {
14760                 /* ALC663 has a mono output pin on 0x17 */
14761                 sprintf(name, "%s Playback Switch", pfx);
14762                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14763                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
14764                 return err;
14765         }
14766
14767         if (alc880_is_fixed_pin(pin)) {
14768                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14769                 /* printk("DAC nid=%x\n",nid); */
14770                 /* specify the DAC as the extra output */
14771                 if (!spec->multiout.hp_nid)
14772                         spec->multiout.hp_nid = nid;
14773                 else
14774                         spec->multiout.extra_out_nid[0] = nid;
14775                 /* control HP volume/switch on the output mixer amp */
14776                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14777                 sprintf(name, "%s Playback Volume", pfx);
14778                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14779                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
14780                 if (err < 0)
14781                         return err;
14782                 sprintf(name, "%s Playback Switch", pfx);
14783                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14784                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
14785                 if (err < 0)
14786                         return err;
14787         } else if (alc880_is_multi_pin(pin)) {
14788                 /* set manual connection */
14789                 /* we have only a switch on HP-out PIN */
14790                 sprintf(name, "%s Playback Switch", pfx);
14791                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14792                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14793                 if (err < 0)
14794                         return err;
14795         }
14796         return 0;
14797 }
14798
14799 /* create playback/capture controls for input pins */
14800 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
14801                                                 const struct auto_pin_cfg *cfg)
14802 {
14803         struct hda_input_mux *imux = &spec->private_imux;
14804         int i, err, idx;
14805
14806         for (i = 0; i < AUTO_PIN_LAST; i++) {
14807                 if (alc880_is_input_pin(cfg->input_pins[i])) {
14808                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
14809                         err = new_analog_input(spec, cfg->input_pins[i],
14810                                                auto_pin_cfg_labels[i],
14811                                                idx, 0x0b);
14812                         if (err < 0)
14813                                 return err;
14814                         imux->items[imux->num_items].label =
14815                                 auto_pin_cfg_labels[i];
14816                         imux->items[imux->num_items].index =
14817                                 alc880_input_pin_idx(cfg->input_pins[i]);
14818                         imux->num_items++;
14819                 }
14820         }
14821         return 0;
14822 }
14823
14824 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
14825                                               hda_nid_t nid, int pin_type,
14826                                               int dac_idx)
14827 {
14828         alc_set_pin_output(codec, nid, pin_type);
14829         /* need the manual connection? */
14830         if (alc880_is_multi_pin(nid)) {
14831                 struct alc_spec *spec = codec->spec;
14832                 int idx = alc880_multi_pin_idx(nid);
14833                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
14834                                     AC_VERB_SET_CONNECT_SEL,
14835                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
14836         }
14837 }
14838
14839 static void alc662_auto_init_multi_out(struct hda_codec *codec)
14840 {
14841         struct alc_spec *spec = codec->spec;
14842         int i;
14843
14844         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14845         for (i = 0; i <= HDA_SIDE; i++) {
14846                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14847                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14848                 if (nid)
14849                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
14850                                                           i);
14851         }
14852 }
14853
14854 static void alc662_auto_init_hp_out(struct hda_codec *codec)
14855 {
14856         struct alc_spec *spec = codec->spec;
14857         hda_nid_t pin;
14858
14859         pin = spec->autocfg.hp_pins[0];
14860         if (pin) /* connect to front */
14861                 /* use dac 0 */
14862                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14863         pin = spec->autocfg.speaker_pins[0];
14864         if (pin)
14865                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14866 }
14867
14868 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
14869 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
14870
14871 static void alc662_auto_init_analog_input(struct hda_codec *codec)
14872 {
14873         struct alc_spec *spec = codec->spec;
14874         int i;
14875
14876         for (i = 0; i < AUTO_PIN_LAST; i++) {
14877                 hda_nid_t nid = spec->autocfg.input_pins[i];
14878                 if (alc662_is_input_pin(nid)) {
14879                         snd_hda_codec_write(codec, nid, 0,
14880                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
14881                                             (i <= AUTO_PIN_FRONT_MIC ?
14882                                              PIN_VREF80 : PIN_IN));
14883                         if (nid != ALC662_PIN_CD_NID)
14884                                 snd_hda_codec_write(codec, nid, 0,
14885                                                     AC_VERB_SET_AMP_GAIN_MUTE,
14886                                                     AMP_OUT_MUTE);
14887                 }
14888         }
14889 }
14890
14891 #define alc662_auto_init_input_src      alc882_auto_init_input_src
14892
14893 static int alc662_parse_auto_config(struct hda_codec *codec)
14894 {
14895         struct alc_spec *spec = codec->spec;
14896         int err;
14897         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
14898
14899         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14900                                            alc662_ignore);
14901         if (err < 0)
14902                 return err;
14903         if (!spec->autocfg.line_outs)
14904                 return 0; /* can't find valid BIOS pin config */
14905
14906         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14907         if (err < 0)
14908                 return err;
14909         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
14910         if (err < 0)
14911                 return err;
14912         err = alc662_auto_create_extra_out(spec,
14913                                            spec->autocfg.speaker_pins[0],
14914                                            "Speaker");
14915         if (err < 0)
14916                 return err;
14917         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
14918                                            "Headphone");
14919         if (err < 0)
14920                 return err;
14921         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
14922         if (err < 0)
14923                 return err;
14924
14925         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14926
14927         if (spec->autocfg.dig_out_pin)
14928                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
14929
14930         if (spec->kctl_alloc)
14931                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
14932
14933         spec->num_mux_defs = 1;
14934         spec->input_mux = &spec->private_imux;
14935         
14936         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
14937         if (codec->vendor_id == 0x10ec0663)
14938                 spec->init_verbs[spec->num_init_verbs++] =
14939                         alc663_auto_init_verbs;
14940
14941         err = alc_auto_add_mic_boost(codec);
14942         if (err < 0)
14943                 return err;
14944
14945         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
14946         spec->num_mixers++;
14947
14948         store_pin_configs(codec);
14949         return 1;
14950 }
14951
14952 /* additional initialization for auto-configuration model */
14953 static void alc662_auto_init(struct hda_codec *codec)
14954 {
14955         struct alc_spec *spec = codec->spec;
14956         alc662_auto_init_multi_out(codec);
14957         alc662_auto_init_hp_out(codec);
14958         alc662_auto_init_analog_input(codec);
14959         alc662_auto_init_input_src(codec);
14960         if (spec->unsol_event)
14961                 alc_sku_automute(codec);
14962 }
14963
14964 static int patch_alc662(struct hda_codec *codec)
14965 {
14966         struct alc_spec *spec;
14967         int err, board_config;
14968
14969         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14970         if (!spec)
14971                 return -ENOMEM;
14972
14973         codec->spec = spec;
14974
14975         alc_fix_pll_init(codec, 0x20, 0x04, 15);
14976
14977         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
14978                                                   alc662_models,
14979                                                   alc662_cfg_tbl);
14980         if (board_config < 0) {
14981                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
14982                        "trying auto-probe from BIOS...\n");
14983                 board_config = ALC662_AUTO;
14984         }
14985
14986         if (board_config == ALC662_AUTO) {
14987                 /* automatic parse from the BIOS config */
14988                 err = alc662_parse_auto_config(codec);
14989                 if (err < 0) {
14990                         alc_free(codec);
14991                         return err;
14992                 } else if (!err) {
14993                         printk(KERN_INFO
14994                                "hda_codec: Cannot set up configuration "
14995                                "from BIOS.  Using base mode...\n");
14996                         board_config = ALC662_3ST_2ch_DIG;
14997                 }
14998         }
14999
15000         if (board_config != ALC662_AUTO)
15001                 setup_preset(spec, &alc662_presets[board_config]);
15002
15003         if (codec->vendor_id == 0x10ec0663) {
15004                 spec->stream_name_analog = "ALC663 Analog";
15005                 spec->stream_name_digital = "ALC663 Digital";
15006         } else if (codec->vendor_id == 0x10ec0272) {
15007                 spec->stream_name_analog = "ALC272 Analog";
15008                 spec->stream_name_digital = "ALC272 Digital";
15009         } else {
15010                 spec->stream_name_analog = "ALC662 Analog";
15011                 spec->stream_name_digital = "ALC662 Digital";
15012         }
15013
15014         spec->stream_analog_playback = &alc662_pcm_analog_playback;
15015         spec->stream_analog_capture = &alc662_pcm_analog_capture;
15016
15017         spec->stream_digital_playback = &alc662_pcm_digital_playback;
15018         spec->stream_digital_capture = &alc662_pcm_digital_capture;
15019
15020         spec->adc_nids = alc662_adc_nids;
15021         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
15022         spec->capsrc_nids = alc662_capsrc_nids;
15023
15024         spec->vmaster_nid = 0x02;
15025
15026         codec->patch_ops = alc_patch_ops;
15027         if (board_config == ALC662_AUTO)
15028                 spec->init_hook = alc662_auto_init;
15029 #ifdef CONFIG_SND_HDA_POWER_SAVE
15030         if (!spec->loopback.amplist)
15031                 spec->loopback.amplist = alc662_loopbacks;
15032 #endif
15033
15034         return 0;
15035 }
15036
15037 /*
15038  * patch entries
15039  */
15040 struct hda_codec_preset snd_hda_preset_realtek[] = {
15041         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
15042         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
15043         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
15044         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
15045         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
15046         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
15047         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
15048           .patch = patch_alc861 },
15049         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
15050         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
15051         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
15052         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
15053           .patch = patch_alc883 },
15054         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
15055           .patch = patch_alc662 },
15056         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
15057         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
15058         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
15059         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
15060         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
15061           .patch = patch_alc882 }, /* should be patch_alc883() in future */
15062         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
15063           .patch = patch_alc882 }, /* should be patch_alc883() in future */
15064         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
15065         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
15066         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
15067         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
15068         {} /* terminator */
15069 };