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