Merge branch 'master'
[cascardo/linux.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 PeiSen Hou <pshou@realtek.com.tw>
7  *                    Takashi Iwai <tiwai@suse.de>
8  *
9  *  This driver is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This driver is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22  */
23
24 #include <sound/driver.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/slab.h>
28 #include <linux/pci.h>
29 #include <sound/core.h>
30 #include "hda_codec.h"
31 #include "hda_local.h"
32
33
34 /* ALC880 board config type */
35 enum {
36         ALC880_3ST,
37         ALC880_3ST_DIG,
38         ALC880_5ST,
39         ALC880_5ST_DIG,
40         ALC880_W810,
41         ALC880_Z71V,
42         ALC880_AUTO,
43         ALC880_6ST,
44         ALC880_6ST_DIG,
45         ALC880_F1734,
46         ALC880_ASUS,
47         ALC880_ASUS_DIG,
48         ALC880_ASUS_W1V,
49         ALC880_UNIWILL_DIG,
50 #ifdef CONFIG_SND_DEBUG
51         ALC880_TEST,
52 #endif
53         ALC880_MODEL_LAST /* last tag */
54 };
55
56 /* ALC260 models */
57 enum {
58         ALC260_BASIC,
59         ALC260_HP,
60         ALC260_FUJITSU_S702x,
61         ALC260_MODEL_LAST /* last tag */
62 };
63
64 /* amp values */
65 #define AMP_IN_MUTE(idx)        (0x7080 | ((idx)<<8))
66 #define AMP_IN_UNMUTE(idx)      (0x7000 | ((idx)<<8))
67 #define AMP_OUT_MUTE    0xb080
68 #define AMP_OUT_UNMUTE  0xb000
69 #define AMP_OUT_ZERO    0xb000
70 /* pinctl values */
71 #define PIN_IN          0x20
72 #define PIN_VREF80      0x24
73 #define PIN_VREF50      0x21
74 #define PIN_OUT         0x40
75 #define PIN_HP          0xc0
76 #define PIN_HP_AMP      0x80
77
78 struct alc_spec {
79         /* codec parameterization */
80         snd_kcontrol_new_t *mixers[3];  /* mixer arrays */
81         unsigned int num_mixers;
82
83         const struct hda_verb *init_verbs[3];   /* initialization verbs
84                                                  * don't forget NULL termination!
85                                                  */
86         unsigned int num_init_verbs;
87
88         char *stream_name_analog;       /* analog PCM stream */
89         struct hda_pcm_stream *stream_analog_playback;
90         struct hda_pcm_stream *stream_analog_capture;
91
92         char *stream_name_digital;      /* digital PCM stream */ 
93         struct hda_pcm_stream *stream_digital_playback;
94         struct hda_pcm_stream *stream_digital_capture;
95
96         /* playback */
97         struct hda_multi_out multiout;  /* playback set-up
98                                          * max_channels, dacs must be set
99                                          * dig_out_nid and hp_nid are optional
100                                          */
101
102         /* capture */
103         unsigned int num_adc_nids;
104         hda_nid_t *adc_nids;
105         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
106
107         /* capture source */
108         const struct hda_input_mux *input_mux;
109         unsigned int cur_mux[3];
110
111         /* channel model */
112         const struct alc_channel_mode *channel_mode;
113         int num_channel_mode;
114
115         /* PCM information */
116         struct hda_pcm pcm_rec[2];      /* used in alc_build_pcms() */
117
118         /* dynamic controls, init_verbs and input_mux */
119         struct auto_pin_cfg autocfg;
120         unsigned int num_kctl_alloc, num_kctl_used;
121         snd_kcontrol_new_t *kctl_alloc;
122         struct hda_input_mux private_imux;
123         hda_nid_t private_dac_nids[4];
124 };
125
126
127 /*
128  * input MUX handling
129  */
130 static int alc_mux_enum_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
131 {
132         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
133         struct alc_spec *spec = codec->spec;
134         return snd_hda_input_mux_info(spec->input_mux, uinfo);
135 }
136
137 static int alc_mux_enum_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
138 {
139         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
140         struct alc_spec *spec = codec->spec;
141         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
142
143         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
144         return 0;
145 }
146
147 static int alc_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
148 {
149         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
150         struct alc_spec *spec = codec->spec;
151         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
152         return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
153                                      spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]);
154 }
155
156
157 /*
158  * channel mode setting
159  */
160 struct alc_channel_mode {
161         int channels;
162         const struct hda_verb *sequence;
163 };
164
165 static int alc880_ch_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
166 {
167         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
168         struct alc_spec *spec = codec->spec;
169         int items = kcontrol->private_value ? (int)kcontrol->private_value : 2;
170
171         snd_assert(spec->channel_mode, return -ENXIO);
172         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
173         uinfo->count = 1;
174         uinfo->value.enumerated.items = items;
175         if (uinfo->value.enumerated.item >= items)
176                 uinfo->value.enumerated.item = items - 1;
177         sprintf(uinfo->value.enumerated.name, "%dch",
178                 spec->channel_mode[uinfo->value.enumerated.item].channels);
179         return 0;
180 }
181
182 static int alc880_ch_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
183 {
184         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
185         struct alc_spec *spec = codec->spec;
186         int items = kcontrol->private_value ? (int)kcontrol->private_value : 2;
187         int i;
188
189         snd_assert(spec->channel_mode, return -ENXIO);
190         for (i = 0; i < items; i++) {
191                 if (spec->multiout.max_channels == spec->channel_mode[i].channels) {
192                         ucontrol->value.enumerated.item[0] = i;
193                         break;
194                 }
195         }
196         return 0;
197 }
198
199 static int alc880_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
200 {
201         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
202         struct alc_spec *spec = codec->spec;
203         int mode;
204
205         snd_assert(spec->channel_mode, return -ENXIO);
206         mode = ucontrol->value.enumerated.item[0] ? 1 : 0;
207         if (spec->multiout.max_channels == spec->channel_mode[mode].channels &&
208             ! codec->in_resume)
209                 return 0;
210
211         /* change the current channel setting */
212         spec->multiout.max_channels = spec->channel_mode[mode].channels;
213         if (spec->channel_mode[mode].sequence)
214                 snd_hda_sequence_write(codec, spec->channel_mode[mode].sequence);
215
216         return 1;
217 }
218
219
220 /*
221  * Control of pin widget settings via the mixer.  Only boolean settings are
222  * supported, so VrefEn can't be controlled using these functions as they
223  * stand.
224  */
225 static int alc_pinctl_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
226 {
227         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
228         uinfo->count = 1;
229         uinfo->value.integer.min = 0;
230         uinfo->value.integer.max = 1;
231         return 0;
232 }
233
234 static int alc_pinctl_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
235 {
236         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
237         hda_nid_t nid = kcontrol->private_value & 0xffff;
238         long mask = (kcontrol->private_value >> 16) & 0xff;
239         long *valp = ucontrol->value.integer.value;
240
241         *valp = 0;
242         if (snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00) & mask)
243                 *valp = 1;
244         return 0;
245 }
246
247 static int alc_pinctl_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
248 {
249         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
250         hda_nid_t nid = kcontrol->private_value & 0xffff;
251         long mask = (kcontrol->private_value >> 16) & 0xff;
252         long *valp = ucontrol->value.integer.value;
253         unsigned int pinctl = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00);
254         int change = ((pinctl & mask)!=0) != *valp;
255
256         if (change)
257                 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL,
258                         *valp?(pinctl|mask):(pinctl&~mask));
259         return change;
260 }
261
262 #define ALC_PINCTL_SWITCH(xname, nid, mask) \
263         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
264           .info = alc_pinctl_switch_info, \
265           .get = alc_pinctl_switch_get, \
266           .put = alc_pinctl_switch_put, \
267           .private_value = (nid) | (mask<<16) }
268
269 /*
270  * ALC880 3-stack model
271  *
272  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
273  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18, F-Mic = 0x1b
274  *                 HP = 0x19
275  */
276
277 static hda_nid_t alc880_dac_nids[4] = {
278         /* front, rear, clfe, rear_surr */
279         0x02, 0x05, 0x04, 0x03
280 };
281
282 static hda_nid_t alc880_adc_nids[3] = {
283         /* ADC0-2 */
284         0x07, 0x08, 0x09,
285 };
286
287 /* The datasheet says the node 0x07 is connected from inputs,
288  * but it shows zero connection in the real implementation on some devices.
289  */
290 static hda_nid_t alc880_adc_nids_alt[2] = {
291         /* ADC1-2 */
292         0x08, 0x09,
293 };
294
295 #define ALC880_DIGOUT_NID       0x06
296 #define ALC880_DIGIN_NID        0x0a
297
298 static struct hda_input_mux alc880_capture_source = {
299         .num_items = 4,
300         .items = {
301                 { "Mic", 0x0 },
302                 { "Front Mic", 0x3 },
303                 { "Line", 0x2 },
304                 { "CD", 0x4 },
305         },
306 };
307
308 /* channel source setting (2/6 channel selection for 3-stack) */
309 /* 2ch mode */
310 static struct hda_verb alc880_threestack_ch2_init[] = {
311         /* set line-in to input, mute it */
312         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
313         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
314         /* set mic-in to input vref 80%, mute it */
315         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
316         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
317         { } /* end */
318 };
319
320 /* 6ch mode */
321 static struct hda_verb alc880_threestack_ch6_init[] = {
322         /* set line-in to output, unmute it */
323         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
324         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
325         /* set mic-in to output, unmute it */
326         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
327         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
328         { } /* end */
329 };
330
331 static struct alc_channel_mode alc880_threestack_modes[2] = {
332         { 2, alc880_threestack_ch2_init },
333         { 6, alc880_threestack_ch6_init },
334 };
335
336 static snd_kcontrol_new_t alc880_three_stack_mixer[] = {
337         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
338         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
339         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
340         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
341         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
342         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
343         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
344         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
345         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
346         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
347         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
348         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
349         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
350         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
351         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
352         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
353         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
354         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
355         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
356         {
357                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
358                 .name = "Channel Mode",
359                 .info = alc880_ch_mode_info,
360                 .get = alc880_ch_mode_get,
361                 .put = alc880_ch_mode_put,
362         },
363         { } /* end */
364 };
365
366 /* capture mixer elements */
367 static snd_kcontrol_new_t alc880_capture_mixer[] = {
368         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
369         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
370         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
371         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
372         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
373         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
374         {
375                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
376                 /* The multiple "Capture Source" controls confuse alsamixer
377                  * So call somewhat different..
378                  * FIXME: the controls appear in the "playback" view!
379                  */
380                 /* .name = "Capture Source", */
381                 .name = "Input Source",
382                 .count = 3,
383                 .info = alc_mux_enum_info,
384                 .get = alc_mux_enum_get,
385                 .put = alc_mux_enum_put,
386         },
387         { } /* end */
388 };
389
390 /* capture mixer elements (in case NID 0x07 not available) */
391 static snd_kcontrol_new_t alc880_capture_alt_mixer[] = {
392         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
393         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
394         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
395         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
396         {
397                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
398                 /* The multiple "Capture Source" controls confuse alsamixer
399                  * So call somewhat different..
400                  * FIXME: the controls appear in the "playback" view!
401                  */
402                 /* .name = "Capture Source", */
403                 .name = "Input Source",
404                 .count = 2,
405                 .info = alc_mux_enum_info,
406                 .get = alc_mux_enum_get,
407                 .put = alc_mux_enum_put,
408         },
409         { } /* end */
410 };
411
412
413
414 /*
415  * ALC880 5-stack model
416  *
417  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d), Side = 0x02 (0xd)
418  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
419  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
420  */
421
422 /* additional mixers to alc880_three_stack_mixer */
423 static snd_kcontrol_new_t alc880_five_stack_mixer[] = {
424         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
425         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
426         { } /* end */
427 };
428
429 /* channel source setting (6/8 channel selection for 5-stack) */
430 /* 6ch mode */
431 static struct hda_verb alc880_fivestack_ch6_init[] = {
432         /* set line-in to input, mute it */
433         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
434         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
435         { } /* end */
436 };
437
438 /* 8ch mode */
439 static struct hda_verb alc880_fivestack_ch8_init[] = {
440         /* set line-in to output, unmute it */
441         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
442         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
443         { } /* end */
444 };
445
446 static struct alc_channel_mode alc880_fivestack_modes[2] = {
447         { 6, alc880_fivestack_ch6_init },
448         { 8, alc880_fivestack_ch8_init },
449 };
450
451
452 /*
453  * ALC880 6-stack model
454  *
455  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e), Side = 0x05 (0x0f)
456  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
457  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
458  */
459
460 static hda_nid_t alc880_6st_dac_nids[4] = {
461         /* front, rear, clfe, rear_surr */
462         0x02, 0x03, 0x04, 0x05
463 };      
464
465 static struct hda_input_mux alc880_6stack_capture_source = {
466         .num_items = 4,
467         .items = {
468                 { "Mic", 0x0 },
469                 { "Front Mic", 0x1 },
470                 { "Line", 0x2 },
471                 { "CD", 0x4 },
472         },
473 };
474
475 /* fixed 8-channels */
476 static struct alc_channel_mode alc880_sixstack_modes[1] = {
477         { 8, NULL },
478 };
479
480 static snd_kcontrol_new_t alc880_six_stack_mixer[] = {
481         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
482         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
483         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
484         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
485         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
486         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
487         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
488         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
489         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
490         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
491         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
492         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
493         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
494         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
495         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
496         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
497         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
498         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
499         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
500         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
501         {
502                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
503                 .name = "Channel Mode",
504                 .info = alc880_ch_mode_info,
505                 .get = alc880_ch_mode_get,
506                 .put = alc880_ch_mode_put,
507         },
508         { } /* end */
509 };
510
511
512 /*
513  * ALC880 W810 model
514  *
515  * W810 has rear IO for:
516  * Front (DAC 02)
517  * Surround (DAC 03)
518  * Center/LFE (DAC 04)
519  * Digital out (06)
520  *
521  * The system also has a pair of internal speakers, and a headphone jack.
522  * These are both connected to Line2 on the codec, hence to DAC 02.
523  * 
524  * There is a variable resistor to control the speaker or headphone
525  * volume. This is a hardware-only device without a software API.
526  *
527  * Plugging headphones in will disable the internal speakers. This is
528  * implemented in hardware, not via the driver using jack sense. In
529  * a similar fashion, plugging into the rear socket marked "front" will
530  * disable both the speakers and headphones.
531  *
532  * For input, there's a microphone jack, and an "audio in" jack.
533  * These may not do anything useful with this driver yet, because I
534  * haven't setup any initialization verbs for these yet...
535  */
536
537 static hda_nid_t alc880_w810_dac_nids[3] = {
538         /* front, rear/surround, clfe */
539         0x02, 0x03, 0x04
540 };
541
542 /* fixed 6 channels */
543 static struct alc_channel_mode alc880_w810_modes[1] = {
544         { 6, NULL }
545 };
546
547 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
548 static snd_kcontrol_new_t alc880_w810_base_mixer[] = {
549         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
550         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
551         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
552         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
553         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
554         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
555         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
556         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
557         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
558         { } /* end */
559 };
560
561
562 /*
563  * Z710V model
564  *
565  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
566  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?), Line = 0x1a
567  */
568
569 static hda_nid_t alc880_z71v_dac_nids[1] = {
570         0x02
571 };
572 #define ALC880_Z71V_HP_DAC      0x03
573
574 /* fixed 2 channels */
575 static struct alc_channel_mode alc880_2_jack_modes[1] = {
576         { 2, NULL }
577 };
578
579 static snd_kcontrol_new_t alc880_z71v_mixer[] = {
580         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
581         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
582         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
583         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
584         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
585         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
586         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
587         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
588         { } /* end */
589 };
590
591
592 /* FIXME! */
593 /*
594  * ALC880 F1734 model
595  *
596  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
597  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
598  */
599
600 static hda_nid_t alc880_f1734_dac_nids[1] = {
601         0x03
602 };
603 #define ALC880_F1734_HP_DAC     0x02
604
605 static snd_kcontrol_new_t alc880_f1734_mixer[] = {
606         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
607         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
608         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
609         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
610         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
611         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
612         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
613         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
614         { } /* end */
615 };
616
617
618 /* FIXME! */
619 /*
620  * ALC880 ASUS model
621  *
622  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
623  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
624  *  Mic = 0x18, Line = 0x1a
625  */
626
627 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
628 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
629
630 static snd_kcontrol_new_t alc880_asus_mixer[] = {
631         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
632         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
633         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
634         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
635         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
636         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
637         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
638         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
639         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
640         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
641         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
642         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
643         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
644         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
645         {
646                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
647                 .name = "Channel Mode",
648                 .info = alc880_ch_mode_info,
649                 .get = alc880_ch_mode_get,
650                 .put = alc880_ch_mode_put,
651         },
652         { } /* end */
653 };
654
655 /* FIXME! */
656 /*
657  * ALC880 ASUS W1V model
658  *
659  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
660  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
661  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
662  */
663
664 /* additional mixers to alc880_asus_mixer */
665 static snd_kcontrol_new_t alc880_asus_w1v_mixer[] = {
666         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
667         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
668         { } /* end */
669 };
670
671 /* additional mixers to alc880_asus_mixer */
672 static snd_kcontrol_new_t alc880_pcbeep_mixer[] = {
673         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
674         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
675         { } /* end */
676 };
677
678 /*
679  * build control elements
680  */
681 static int alc_build_controls(struct hda_codec *codec)
682 {
683         struct alc_spec *spec = codec->spec;
684         int err;
685         int i;
686
687         for (i = 0; i < spec->num_mixers; i++) {
688                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
689                 if (err < 0)
690                         return err;
691         }
692
693         if (spec->multiout.dig_out_nid) {
694                 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
695                 if (err < 0)
696                         return err;
697         }
698         if (spec->dig_in_nid) {
699                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
700                 if (err < 0)
701                         return err;
702         }
703         return 0;
704 }
705
706
707 /*
708  * initialize the codec volumes, etc
709  */
710
711 /*
712  * generic initialization of ADC, input mixers and output mixers
713  */
714 static struct hda_verb alc880_volume_init_verbs[] = {
715         /*
716          * Unmute ADC0-2 and set the default input to mic-in
717          */
718         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
719         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
720         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
721         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
722         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
723         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
724
725         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
726          * mixer widget
727          * Note: PASD motherboards uses the Line In 2 as the input for front panel
728          * mic (mic 2)
729          */
730         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
731         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
732         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
733         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
734         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
735         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
736
737         /*
738          * Set up output mixers (0x0c - 0x0f)
739          */
740         /* set vol=0 to output mixers */
741         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
742         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
743         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
744         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
745         /* set up input amps for analog loopback */
746         /* Amp Indices: DAC = 0, mixer = 1 */
747         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
748         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
749         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
750         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
751         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
752         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
753         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
754         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
755
756         { }
757 };
758
759 /*
760  * 3-stack pin configuration:
761  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
762  */
763 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
764         /*
765          * preset connection lists of input pins
766          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
767          */
768         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
769         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
770         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
771
772         /*
773          * Set pin mode and muting
774          */
775         /* set front pin widgets 0x14 for output */
776         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
777         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
778         /* Mic1 (rear panel) pin widget for input and vref at 80% */
779         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
780         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
781         /* Mic2 (as headphone out) for HP output */
782         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
783         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
784         /* Line In pin widget for input */
785         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
786         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
787         /* Line2 (as front mic) pin widget for input and vref at 80% */
788         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
789         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
790         /* CD pin widget for input */
791         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
792
793         { }
794 };
795
796 /*
797  * 5-stack pin configuration:
798  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
799  * line-in/side = 0x1a, f-mic = 0x1b
800  */
801 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
802         /*
803          * preset connection lists of input pins
804          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
805          */
806         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
807         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
808
809         /*
810          * Set pin mode and muting
811          */
812         /* set pin widgets 0x14-0x17 for output */
813         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
814         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
815         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
816         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
817         /* unmute pins for output (no gain on this amp) */
818         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
819         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
820         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
821         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
822
823         /* Mic1 (rear panel) pin widget for input and vref at 80% */
824         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
825         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
826         /* Mic2 (as headphone out) for HP output */
827         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
828         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
829         /* Line In pin widget for input */
830         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
831         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
832         /* Line2 (as front mic) pin widget for input and vref at 80% */
833         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
834         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
835         /* CD pin widget for input */
836         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
837
838         { }
839 };
840
841 /*
842  * W810 pin configuration:
843  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
844  */
845 static struct hda_verb alc880_pin_w810_init_verbs[] = {
846         /* hphone/speaker input selector: front DAC */
847         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
848
849         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
850         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
851         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
852         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
853         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
854         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
855
856         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
857         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
858
859         { }
860 };
861
862 /*
863  * Z71V pin configuration:
864  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
865  */
866 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
867         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
868         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
869         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
870         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
871
872         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
873         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
874         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
875         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
876
877         { }
878 };
879
880 /*
881  * 6-stack pin configuration:
882  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18, f-mic = 0x19,
883  * line = 0x1a, HP = 0x1b
884  */
885 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
886         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
887
888         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
889         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
890         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
891         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
892         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
893         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
894         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
895         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
896
897         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
898         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
899         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
900         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
901         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
902         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
903         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
904         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
905         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
906         
907         { }
908 };
909
910 /* FIXME! */
911 /*
912  * F1734 pin configuration:
913  * HP = 0x14, speaker-out = 0x15, mic = 0x18
914  */
915 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
916         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
917         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
918         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
919         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
920
921         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
922         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
923         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
924         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
925
926         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
927         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
928         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
929         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
930         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
931         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
932         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
933         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
934         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
935
936         { }
937 };
938
939 /* FIXME! */
940 /*
941  * ASUS pin configuration:
942  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
943  */
944 static struct hda_verb alc880_pin_asus_init_verbs[] = {
945         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
946         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
947         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
948         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
949
950         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
951         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
952         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
953         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
954         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
955         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
956         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
957         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
958
959         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
960         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
961         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
962         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
963         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
964         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
965         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
966         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
967         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
968         
969         { }
970 };
971
972 /* Enable GPIO mask and set output */
973 static struct hda_verb alc880_gpio1_init_verbs[] = {
974         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
975         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
976         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
977 };
978
979 /* Enable GPIO mask and set output */
980 static struct hda_verb alc880_gpio2_init_verbs[] = {
981         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
982         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
983         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
984 };
985
986
987 /*
988  */
989
990 static int alc_init(struct hda_codec *codec)
991 {
992         struct alc_spec *spec = codec->spec;
993         unsigned int i;
994
995         for (i = 0; i < spec->num_init_verbs; i++)
996                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
997         return 0;
998 }
999
1000 #ifdef CONFIG_PM
1001 /*
1002  * resume
1003  */
1004 static int alc_resume(struct hda_codec *codec)
1005 {
1006         struct alc_spec *spec = codec->spec;
1007         int i;
1008
1009         alc_init(codec);
1010         for (i = 0; i < spec->num_mixers; i++)
1011                 snd_hda_resume_ctls(codec, spec->mixers[i]);
1012         if (spec->multiout.dig_out_nid)
1013                 snd_hda_resume_spdif_out(codec);
1014         if (spec->dig_in_nid)
1015                 snd_hda_resume_spdif_in(codec);
1016
1017         return 0;
1018 }
1019 #endif
1020
1021 /*
1022  * Analog playback callbacks
1023  */
1024 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
1025                                     struct hda_codec *codec,
1026                                     snd_pcm_substream_t *substream)
1027 {
1028         struct alc_spec *spec = codec->spec;
1029         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1030 }
1031
1032 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1033                                        struct hda_codec *codec,
1034                                        unsigned int stream_tag,
1035                                        unsigned int format,
1036                                        snd_pcm_substream_t *substream)
1037 {
1038         struct alc_spec *spec = codec->spec;
1039         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1040                                                 format, substream);
1041 }
1042
1043 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1044                                        struct hda_codec *codec,
1045                                        snd_pcm_substream_t *substream)
1046 {
1047         struct alc_spec *spec = codec->spec;
1048         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1049 }
1050
1051 /*
1052  * Digital out
1053  */
1054 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1055                                         struct hda_codec *codec,
1056                                         snd_pcm_substream_t *substream)
1057 {
1058         struct alc_spec *spec = codec->spec;
1059         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1060 }
1061
1062 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1063                                          struct hda_codec *codec,
1064                                          snd_pcm_substream_t *substream)
1065 {
1066         struct alc_spec *spec = codec->spec;
1067         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1068 }
1069
1070 /*
1071  * Analog capture
1072  */
1073 static int alc880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1074                                       struct hda_codec *codec,
1075                                       unsigned int stream_tag,
1076                                       unsigned int format,
1077                                       snd_pcm_substream_t *substream)
1078 {
1079         struct alc_spec *spec = codec->spec;
1080
1081         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1082                                    stream_tag, 0, format);
1083         return 0;
1084 }
1085
1086 static int alc880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1087                                       struct hda_codec *codec,
1088                                       snd_pcm_substream_t *substream)
1089 {
1090         struct alc_spec *spec = codec->spec;
1091
1092         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
1093         return 0;
1094 }
1095
1096
1097 /*
1098  */
1099 static struct hda_pcm_stream alc880_pcm_analog_playback = {
1100         .substreams = 1,
1101         .channels_min = 2,
1102         .channels_max = 8,
1103         /* NID is set in alc_build_pcms */
1104         .ops = {
1105                 .open = alc880_playback_pcm_open,
1106                 .prepare = alc880_playback_pcm_prepare,
1107                 .cleanup = alc880_playback_pcm_cleanup
1108         },
1109 };
1110
1111 static struct hda_pcm_stream alc880_pcm_analog_capture = {
1112         .substreams = 2,
1113         .channels_min = 2,
1114         .channels_max = 2,
1115         /* NID is set in alc_build_pcms */
1116         .ops = {
1117                 .prepare = alc880_capture_pcm_prepare,
1118                 .cleanup = alc880_capture_pcm_cleanup
1119         },
1120 };
1121
1122 static struct hda_pcm_stream alc880_pcm_digital_playback = {
1123         .substreams = 1,
1124         .channels_min = 2,
1125         .channels_max = 2,
1126         /* NID is set in alc_build_pcms */
1127         .ops = {
1128                 .open = alc880_dig_playback_pcm_open,
1129                 .close = alc880_dig_playback_pcm_close
1130         },
1131 };
1132
1133 static struct hda_pcm_stream alc880_pcm_digital_capture = {
1134         .substreams = 1,
1135         .channels_min = 2,
1136         .channels_max = 2,
1137         /* NID is set in alc_build_pcms */
1138 };
1139
1140 static int alc_build_pcms(struct hda_codec *codec)
1141 {
1142         struct alc_spec *spec = codec->spec;
1143         struct hda_pcm *info = spec->pcm_rec;
1144         int i;
1145
1146         codec->num_pcms = 1;
1147         codec->pcm_info = info;
1148
1149         info->name = spec->stream_name_analog;
1150         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
1151         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
1152         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1153         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1154
1155         info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
1156         for (i = 0; i < spec->num_channel_mode; i++) {
1157                 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
1158                     info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
1159                 }
1160         }
1161
1162         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1163                 codec->num_pcms++;
1164                 info++;
1165                 info->name = spec->stream_name_digital;
1166                 if (spec->multiout.dig_out_nid) {
1167                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
1168                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1169                 }
1170                 if (spec->dig_in_nid) {
1171                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
1172                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1173                 }
1174         }
1175
1176         return 0;
1177 }
1178
1179 static void alc_free(struct hda_codec *codec)
1180 {
1181         struct alc_spec *spec = codec->spec;
1182         unsigned int i;
1183
1184         if (! spec)
1185                 return;
1186
1187         if (spec->kctl_alloc) {
1188                 for (i = 0; i < spec->num_kctl_used; i++)
1189                         kfree(spec->kctl_alloc[i].name);
1190                 kfree(spec->kctl_alloc);
1191         }
1192         kfree(spec);
1193 }
1194
1195 /*
1196  */
1197 static struct hda_codec_ops alc_patch_ops = {
1198         .build_controls = alc_build_controls,
1199         .build_pcms = alc_build_pcms,
1200         .init = alc_init,
1201         .free = alc_free,
1202 #ifdef CONFIG_PM
1203         .resume = alc_resume,
1204 #endif
1205 };
1206
1207
1208 /*
1209  * Test configuration for debugging
1210  *
1211  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
1212  * enum controls.
1213  */
1214 #ifdef CONFIG_SND_DEBUG
1215 static hda_nid_t alc880_test_dac_nids[4] = {
1216         0x02, 0x03, 0x04, 0x05
1217 };
1218
1219 static struct hda_input_mux alc880_test_capture_source = {
1220         .num_items = 5,
1221         .items = {
1222                 { "In-1", 0x0 },
1223                 { "In-2", 0x1 },
1224                 { "In-3", 0x2 },
1225                 { "In-4", 0x3 },
1226                 { "CD", 0x4 },
1227         },
1228 };
1229
1230 static struct alc_channel_mode alc880_test_modes[4] = {
1231         { 2, NULL },
1232         { 4, NULL },
1233         { 6, NULL },
1234         { 8, NULL },
1235 };
1236
1237 static int alc_test_pin_ctl_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1238 {
1239         static char *texts[] = {
1240                 "N/A", "Line Out", "HP Out",
1241                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
1242         };
1243         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1244         uinfo->count = 1;
1245         uinfo->value.enumerated.items = 8;
1246         if (uinfo->value.enumerated.item >= 8)
1247                 uinfo->value.enumerated.item = 7;
1248         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1249         return 0;
1250 }
1251
1252 static int alc_test_pin_ctl_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1253 {
1254         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1255         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
1256         unsigned int pin_ctl, item = 0;
1257
1258         pin_ctl = snd_hda_codec_read(codec, nid, 0,
1259                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1260         if (pin_ctl & AC_PINCTL_OUT_EN) {
1261                 if (pin_ctl & AC_PINCTL_HP_EN)
1262                         item = 2;
1263                 else
1264                         item = 1;
1265         } else if (pin_ctl & AC_PINCTL_IN_EN) {
1266                 switch (pin_ctl & AC_PINCTL_VREFEN) {
1267                 case AC_PINCTL_VREF_HIZ: item = 3; break;
1268                 case AC_PINCTL_VREF_50:  item = 4; break;
1269                 case AC_PINCTL_VREF_GRD: item = 5; break;
1270                 case AC_PINCTL_VREF_80:  item = 6; break;
1271                 case AC_PINCTL_VREF_100: item = 7; break;
1272                 }
1273         }
1274         ucontrol->value.enumerated.item[0] = item;
1275         return 0;
1276 }
1277
1278 static int alc_test_pin_ctl_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1279 {
1280         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1281         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
1282         static unsigned int ctls[] = {
1283                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
1284                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
1285                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
1286                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
1287                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
1288                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
1289         };
1290         unsigned int old_ctl, new_ctl;
1291
1292         old_ctl = snd_hda_codec_read(codec, nid, 0,
1293                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1294         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
1295         if (old_ctl != new_ctl) {
1296                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, new_ctl);
1297                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1298                                     ucontrol->value.enumerated.item[0] >= 3 ? 0xb080 : 0xb000);
1299                 return 1;
1300         }
1301         return 0;
1302 }
1303
1304 static int alc_test_pin_src_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1305 {
1306         static char *texts[] = {
1307                 "Front", "Surround", "CLFE", "Side"
1308         };
1309         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1310         uinfo->count = 1;
1311         uinfo->value.enumerated.items = 4;
1312         if (uinfo->value.enumerated.item >= 4)
1313                 uinfo->value.enumerated.item = 3;
1314         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1315         return 0;
1316 }
1317
1318 static int alc_test_pin_src_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1319 {
1320         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1321         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
1322         unsigned int sel;
1323
1324         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
1325         ucontrol->value.enumerated.item[0] = sel & 3;
1326         return 0;
1327 }
1328
1329 static int alc_test_pin_src_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1330 {
1331         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1332         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
1333         unsigned int sel;
1334
1335         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
1336         if (ucontrol->value.enumerated.item[0] != sel) {
1337                 sel = ucontrol->value.enumerated.item[0] & 3;
1338                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, sel);
1339                 return 1;
1340         }
1341         return 0;
1342 }
1343
1344 #define PIN_CTL_TEST(xname,nid) {                       \
1345                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
1346                         .name = xname,                 \
1347                         .info = alc_test_pin_ctl_info, \
1348                         .get = alc_test_pin_ctl_get,   \
1349                         .put = alc_test_pin_ctl_put,   \
1350                         .private_value = nid           \
1351                         }
1352
1353 #define PIN_SRC_TEST(xname,nid) {                       \
1354                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
1355                         .name = xname,                 \
1356                         .info = alc_test_pin_src_info, \
1357                         .get = alc_test_pin_src_get,   \
1358                         .put = alc_test_pin_src_put,   \
1359                         .private_value = nid           \
1360                         }
1361
1362 static snd_kcontrol_new_t alc880_test_mixer[] = {
1363         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1364         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1365         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
1366         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1367         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1368         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1369         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
1370         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1371         PIN_CTL_TEST("Front Pin Mode", 0x14),
1372         PIN_CTL_TEST("Surround Pin Mode", 0x15),
1373         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
1374         PIN_CTL_TEST("Side Pin Mode", 0x17),
1375         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
1376         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
1377         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
1378         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
1379         PIN_SRC_TEST("In-1 Pin Source", 0x18),
1380         PIN_SRC_TEST("In-2 Pin Source", 0x19),
1381         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
1382         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
1383         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
1384         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
1385         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
1386         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
1387         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
1388         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
1389         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
1390         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
1391         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
1392         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
1393         {
1394                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1395                 .name = "Channel Mode",
1396                 .info = alc880_ch_mode_info,
1397                 .get = alc880_ch_mode_get,
1398                 .put = alc880_ch_mode_put,
1399         },
1400         { } /* end */
1401 };
1402
1403 static struct hda_verb alc880_test_init_verbs[] = {
1404         /* Unmute inputs of 0x0c - 0x0f */
1405         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1406         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1407         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1408         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1409         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1410         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1411         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1412         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1413         /* Vol output for 0x0c-0x0f */
1414         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1415         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1416         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1417         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1418         /* Set output pins 0x14-0x17 */
1419         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1420         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1421         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1422         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1423         /* Unmute output pins 0x14-0x17 */
1424         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1425         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1426         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1427         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1428         /* Set input pins 0x18-0x1c */
1429         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1430         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1431         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1432         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1433         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1434         /* Mute input pins 0x18-0x1b */
1435         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1436         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1437         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1438         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1439         /* ADC set up */
1440         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1441         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1442         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1443         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1444         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1445         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1446         /* Analog input/passthru */
1447         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1448         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1449         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1450         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1451         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1452         { }
1453 };
1454 #endif
1455
1456 /*
1457  */
1458
1459 static struct hda_board_config alc880_cfg_tbl[] = {
1460         /* Back 3 jack, front 2 jack */
1461         { .modelname = "3stack", .config = ALC880_3ST },
1462         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe200, .config = ALC880_3ST },
1463         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe201, .config = ALC880_3ST },
1464         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe202, .config = ALC880_3ST },
1465         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe203, .config = ALC880_3ST },
1466         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe204, .config = ALC880_3ST },
1467         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe205, .config = ALC880_3ST },
1468         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe206, .config = ALC880_3ST },
1469         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe207, .config = ALC880_3ST },
1470         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe208, .config = ALC880_3ST },
1471         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe209, .config = ALC880_3ST },
1472         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20a, .config = ALC880_3ST },
1473         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20b, .config = ALC880_3ST },
1474         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20c, .config = ALC880_3ST },
1475         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20d, .config = ALC880_3ST },
1476         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20e, .config = ALC880_3ST },
1477         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20f, .config = ALC880_3ST },
1478         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe210, .config = ALC880_3ST },
1479         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe211, .config = ALC880_3ST },
1480         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe214, .config = ALC880_3ST },
1481         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe302, .config = ALC880_3ST },
1482         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe303, .config = ALC880_3ST },
1483         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe304, .config = ALC880_3ST },
1484         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe306, .config = ALC880_3ST },
1485         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe307, .config = ALC880_3ST },
1486         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe404, .config = ALC880_3ST },
1487         { .pci_subvendor = 0x8086, .pci_subdevice = 0xa101, .config = ALC880_3ST },
1488         { .pci_subvendor = 0x107b, .pci_subdevice = 0x3031, .config = ALC880_3ST },
1489         { .pci_subvendor = 0x107b, .pci_subdevice = 0x4036, .config = ALC880_3ST },
1490         { .pci_subvendor = 0x107b, .pci_subdevice = 0x4037, .config = ALC880_3ST },
1491         { .pci_subvendor = 0x107b, .pci_subdevice = 0x4038, .config = ALC880_3ST },
1492         { .pci_subvendor = 0x107b, .pci_subdevice = 0x4040, .config = ALC880_3ST },
1493         { .pci_subvendor = 0x107b, .pci_subdevice = 0x4041, .config = ALC880_3ST },
1494
1495         /* Back 3 jack, front 2 jack (Internal add Aux-In) */
1496         { .pci_subvendor = 0x1025, .pci_subdevice = 0xe310, .config = ALC880_3ST },
1497         { .pci_subvendor = 0x104d, .pci_subdevice = 0x81d6, .config = ALC880_3ST }, 
1498         { .pci_subvendor = 0x104d, .pci_subdevice = 0x81a0, .config = ALC880_3ST },
1499
1500         /* Back 3 jack plus 1 SPDIF out jack, front 2 jack */
1501         { .modelname = "3stack-digout", .config = ALC880_3ST_DIG },
1502         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe308, .config = ALC880_3ST_DIG },
1503         { .pci_subvendor = 0x1025, .pci_subdevice = 0x0070, .config = ALC880_3ST_DIG },
1504
1505         /* Back 3 jack plus 1 SPDIF out jack, front 2 jack (Internal add Aux-In)*/
1506         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe305, .config = ALC880_3ST_DIG },
1507         { .pci_subvendor = 0x8086, .pci_subdevice = 0xd402, .config = ALC880_3ST_DIG },
1508         { .pci_subvendor = 0x1025, .pci_subdevice = 0xe309, .config = ALC880_3ST_DIG },
1509
1510         /* Back 5 jack, front 2 jack */
1511         { .modelname = "5stack", .config = ALC880_5ST },
1512         { .pci_subvendor = 0x107b, .pci_subdevice = 0x3033, .config = ALC880_5ST },
1513         { .pci_subvendor = 0x107b, .pci_subdevice = 0x4039, .config = ALC880_5ST },
1514         { .pci_subvendor = 0x107b, .pci_subdevice = 0x3032, .config = ALC880_5ST },
1515         { .pci_subvendor = 0x103c, .pci_subdevice = 0x2a09, .config = ALC880_5ST },
1516         { .pci_subvendor = 0x1043, .pci_subdevice = 0x814e, .config = ALC880_5ST },
1517
1518         /* Back 5 jack plus 1 SPDIF out jack, front 2 jack */
1519         { .modelname = "5stack-digout", .config = ALC880_5ST_DIG },
1520         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe224, .config = ALC880_5ST_DIG },
1521         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe400, .config = ALC880_5ST_DIG },
1522         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe401, .config = ALC880_5ST_DIG },
1523         { .pci_subvendor = 0x8086, .pci_subdevice = 0xe402, .config = ALC880_5ST_DIG },
1524         { .pci_subvendor = 0x8086, .pci_subdevice = 0xd400, .config = ALC880_5ST_DIG },
1525         { .pci_subvendor = 0x8086, .pci_subdevice = 0xd401, .config = ALC880_5ST_DIG },
1526         { .pci_subvendor = 0x8086, .pci_subdevice = 0xa100, .config = ALC880_5ST_DIG },
1527         { .pci_subvendor = 0x1565, .pci_subdevice = 0x8202, .config = ALC880_5ST_DIG },
1528         { .pci_subvendor = 0x1019, .pci_subdevice = 0xa880, .config = ALC880_5ST_DIG },
1529         /* { .pci_subvendor = 0x1019, .pci_subdevice = 0xa884, .config = ALC880_5ST_DIG }, */ /* conflict with 6stack */
1530         { .pci_subvendor = 0x1695, .pci_subdevice = 0x400d, .config = ALC880_5ST_DIG },
1531         /* note subvendor = 0 below */
1532         /* { .pci_subvendor = 0x0000, .pci_subdevice = 0x8086, .config = ALC880_5ST_DIG }, */
1533
1534         { .modelname = "w810", .config = ALC880_W810 },
1535         { .pci_subvendor = 0x161f, .pci_subdevice = 0x203d, .config = ALC880_W810 },
1536
1537         { .modelname = "z71v", .config = ALC880_Z71V },
1538         { .pci_subvendor = 0x1043, .pci_subdevice = 0x1964, .config = ALC880_Z71V },
1539
1540         { .modelname = "6stack", .config = ALC880_6ST },
1541         { .pci_subvendor = 0x1019, .pci_subdevice = 0xa884, .config = ALC880_6ST }, /* Acer APFV */
1542
1543         { .modelname = "6stack-digout", .config = ALC880_6ST_DIG },
1544         { .pci_subvendor = 0x2668, .pci_subdevice = 0x8086, .config = ALC880_6ST_DIG },
1545         { .pci_subvendor = 0x8086, .pci_subdevice = 0x2668, .config = ALC880_6ST_DIG },
1546         { .pci_subvendor = 0x1462, .pci_subdevice = 0x1150, .config = ALC880_6ST_DIG },
1547         { .pci_subvendor = 0xe803, .pci_subdevice = 0x1019, .config = ALC880_6ST_DIG },
1548
1549         { .modelname = "asus", .config = ALC880_ASUS },
1550         { .pci_subvendor = 0x1043, .pci_subdevice = 0x1964, .config = ALC880_ASUS_DIG },
1551         { .pci_subvendor = 0x1043, .pci_subdevice = 0x1973, .config = ALC880_ASUS_DIG },
1552         { .pci_subvendor = 0x1043, .pci_subdevice = 0x19b3, .config = ALC880_ASUS_DIG },
1553         { .pci_subvendor = 0x1043, .pci_subdevice = 0x1113, .config = ALC880_ASUS_DIG },
1554         { .pci_subvendor = 0x1043, .pci_subdevice = 0x1173, .config = ALC880_ASUS_DIG },
1555         { .pci_subvendor = 0x1043, .pci_subdevice = 0x1993, .config = ALC880_ASUS },
1556         { .pci_subvendor = 0x1043, .pci_subdevice = 0x10c3, .config = ALC880_ASUS_DIG },
1557         { .pci_subvendor = 0x1043, .pci_subdevice = 0x1133, .config = ALC880_ASUS },
1558         { .pci_subvendor = 0x1043, .pci_subdevice = 0x1123, .config = ALC880_ASUS_DIG },
1559         { .pci_subvendor = 0x1043, .pci_subdevice = 0x1143, .config = ALC880_ASUS },
1560         { .pci_subvendor = 0x1043, .pci_subdevice = 0x10b3, .config = ALC880_ASUS_W1V },
1561
1562         { .modelname = "uniwill", .config = ALC880_UNIWILL_DIG },
1563         { .pci_subvendor = 0x1584, .pci_subdevice = 0x9050, .config = ALC880_UNIWILL_DIG },     
1564
1565         { .modelname = "F1734", .config = ALC880_F1734 },
1566         { .pci_subvendor = 0x1734, .pci_subdevice = 0x107c, .config = ALC880_F1734 },
1567
1568 #ifdef CONFIG_SND_DEBUG
1569         { .modelname = "test", .config = ALC880_TEST },
1570 #endif
1571
1572         {}
1573 };
1574
1575 /*
1576  * configuration template - to be copied to the spec instance
1577  */
1578 struct alc_config_preset {
1579         snd_kcontrol_new_t *mixers[4];
1580         const struct hda_verb *init_verbs[4];
1581         unsigned int num_dacs;
1582         hda_nid_t *dac_nids;
1583         hda_nid_t dig_out_nid;          /* optional */
1584         hda_nid_t hp_nid;               /* optional */
1585         unsigned int num_adc_nids;
1586         hda_nid_t *adc_nids;
1587         unsigned int num_channel_mode;
1588         const struct alc_channel_mode *channel_mode;
1589         const struct hda_input_mux *input_mux;
1590 };
1591
1592 static struct alc_config_preset alc880_presets[] = {
1593         [ALC880_3ST] = {
1594                 .mixers = { alc880_three_stack_mixer },
1595                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_3stack_init_verbs },
1596                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
1597                 .dac_nids = alc880_dac_nids,
1598                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
1599                 .channel_mode = alc880_threestack_modes,
1600                 .input_mux = &alc880_capture_source,
1601         },
1602         [ALC880_3ST_DIG] = {
1603                 .mixers = { alc880_three_stack_mixer },
1604                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_3stack_init_verbs },
1605                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
1606                 .dac_nids = alc880_dac_nids,
1607                 .dig_out_nid = ALC880_DIGOUT_NID,
1608                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
1609                 .channel_mode = alc880_threestack_modes,
1610                 .input_mux = &alc880_capture_source,
1611         },
1612         [ALC880_5ST] = {
1613                 .mixers = { alc880_three_stack_mixer, alc880_five_stack_mixer},
1614                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_5stack_init_verbs },
1615                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
1616                 .dac_nids = alc880_dac_nids,
1617                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
1618                 .channel_mode = alc880_fivestack_modes,
1619                 .input_mux = &alc880_capture_source,
1620         },
1621         [ALC880_5ST_DIG] = {
1622                 .mixers = { alc880_three_stack_mixer, alc880_five_stack_mixer },
1623                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_5stack_init_verbs },
1624                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
1625                 .dac_nids = alc880_dac_nids,
1626                 .dig_out_nid = ALC880_DIGOUT_NID,
1627                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
1628                 .channel_mode = alc880_fivestack_modes,
1629                 .input_mux = &alc880_capture_source,
1630         },
1631         [ALC880_6ST] = {
1632                 .mixers = { alc880_six_stack_mixer },
1633                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_6stack_init_verbs },
1634                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
1635                 .dac_nids = alc880_6st_dac_nids,
1636                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
1637                 .channel_mode = alc880_sixstack_modes,
1638                 .input_mux = &alc880_6stack_capture_source,
1639         },
1640         [ALC880_6ST_DIG] = {
1641                 .mixers = { alc880_six_stack_mixer },
1642                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_6stack_init_verbs },
1643                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
1644                 .dac_nids = alc880_6st_dac_nids,
1645                 .dig_out_nid = ALC880_DIGOUT_NID,
1646                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
1647                 .channel_mode = alc880_sixstack_modes,
1648                 .input_mux = &alc880_6stack_capture_source,
1649         },
1650         [ALC880_W810] = {
1651                 .mixers = { alc880_w810_base_mixer },
1652                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_w810_init_verbs,
1653                                 alc880_gpio2_init_verbs },
1654                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
1655                 .dac_nids = alc880_w810_dac_nids,
1656                 .dig_out_nid = ALC880_DIGOUT_NID,
1657                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
1658                 .channel_mode = alc880_w810_modes,
1659                 .input_mux = &alc880_capture_source,
1660         },
1661         [ALC880_Z71V] = {
1662                 .mixers = { alc880_z71v_mixer },
1663                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_z71v_init_verbs },
1664                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
1665                 .dac_nids = alc880_z71v_dac_nids,
1666                 .dig_out_nid = ALC880_DIGOUT_NID,
1667                 .hp_nid = 0x03,
1668                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
1669                 .channel_mode = alc880_2_jack_modes,
1670                 .input_mux = &alc880_capture_source,
1671         },
1672         [ALC880_F1734] = {
1673                 .mixers = { alc880_f1734_mixer },
1674                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_f1734_init_verbs },
1675                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
1676                 .dac_nids = alc880_f1734_dac_nids,
1677                 .hp_nid = 0x02,
1678                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
1679                 .channel_mode = alc880_2_jack_modes,
1680                 .input_mux = &alc880_capture_source,
1681         },
1682         [ALC880_ASUS] = {
1683                 .mixers = { alc880_asus_mixer },
1684                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
1685                                 alc880_gpio1_init_verbs },
1686                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
1687                 .dac_nids = alc880_asus_dac_nids,
1688                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
1689                 .channel_mode = alc880_asus_modes,
1690                 .input_mux = &alc880_capture_source,
1691         },
1692         [ALC880_ASUS_DIG] = {
1693                 .mixers = { alc880_asus_mixer },
1694                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
1695                                 alc880_gpio1_init_verbs },
1696                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
1697                 .dac_nids = alc880_asus_dac_nids,
1698                 .dig_out_nid = ALC880_DIGOUT_NID,
1699                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
1700                 .channel_mode = alc880_asus_modes,
1701                 .input_mux = &alc880_capture_source,
1702         },
1703         [ALC880_ASUS_W1V] = {
1704                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
1705                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
1706                                 alc880_gpio1_init_verbs },
1707                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
1708                 .dac_nids = alc880_asus_dac_nids,
1709                 .dig_out_nid = ALC880_DIGOUT_NID,
1710                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
1711                 .channel_mode = alc880_asus_modes,
1712                 .input_mux = &alc880_capture_source,
1713         },
1714         [ALC880_UNIWILL_DIG] = {
1715                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
1716                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs },
1717                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
1718                 .dac_nids = alc880_asus_dac_nids,
1719                 .dig_out_nid = ALC880_DIGOUT_NID,
1720                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
1721                 .channel_mode = alc880_asus_modes,
1722                 .input_mux = &alc880_capture_source,
1723         },
1724 #ifdef CONFIG_SND_DEBUG
1725         [ALC880_TEST] = {
1726                 .mixers = { alc880_test_mixer },
1727                 .init_verbs = { alc880_test_init_verbs },
1728                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
1729                 .dac_nids = alc880_test_dac_nids,
1730                 .dig_out_nid = ALC880_DIGOUT_NID,
1731                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
1732                 .channel_mode = alc880_test_modes,
1733                 .input_mux = &alc880_test_capture_source,
1734         },
1735 #endif
1736 };
1737
1738 /*
1739  * Automatic parse of I/O pins from the BIOS configuration
1740  */
1741
1742 #define NUM_CONTROL_ALLOC       32
1743 #define NUM_VERB_ALLOC          32
1744
1745 enum {
1746         ALC_CTL_WIDGET_VOL,
1747         ALC_CTL_WIDGET_MUTE,
1748         ALC_CTL_BIND_MUTE,
1749 };
1750 static snd_kcontrol_new_t alc880_control_templates[] = {
1751         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1752         HDA_CODEC_MUTE(NULL, 0, 0, 0),
1753         HDA_BIND_MUTE(NULL, 0, 0, 0),
1754 };
1755
1756 /* add dynamic controls */
1757 static int add_control(struct alc_spec *spec, int type, const char *name, unsigned long val)
1758 {
1759         snd_kcontrol_new_t *knew;
1760
1761         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1762                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1763
1764                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1765                 if (! knew)
1766                         return -ENOMEM;
1767                 if (spec->kctl_alloc) {
1768                         memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1769                         kfree(spec->kctl_alloc);
1770                 }
1771                 spec->kctl_alloc = knew;
1772                 spec->num_kctl_alloc = num;
1773         }
1774
1775         knew = &spec->kctl_alloc[spec->num_kctl_used];
1776         *knew = alc880_control_templates[type];
1777         knew->name = kstrdup(name, GFP_KERNEL);
1778         if (! knew->name)
1779                 return -ENOMEM;
1780         knew->private_value = val;
1781         spec->num_kctl_used++;
1782         return 0;
1783 }
1784
1785 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
1786 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
1787 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
1788 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
1789 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
1790 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
1791 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
1792 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
1793 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
1794 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
1795 #define ALC880_PIN_CD_NID               0x1c
1796
1797 /* fill in the dac_nids table from the parsed pin configuration */
1798 static int alc880_auto_fill_dac_nids(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
1799 {
1800         hda_nid_t nid;
1801         int assigned[4];
1802         int i, j;
1803
1804         memset(assigned, 0, sizeof(assigned));
1805         spec->multiout.dac_nids = spec->private_dac_nids;
1806
1807         /* check the pins hardwired to audio widget */
1808         for (i = 0; i < cfg->line_outs; i++) {
1809                 nid = cfg->line_out_pins[i];
1810                 if (alc880_is_fixed_pin(nid)) {
1811                         int idx = alc880_fixed_pin_idx(nid);
1812                         spec->multiout.dac_nids[i] = alc880_dac_to_idx(idx);
1813                         assigned[idx] = 1;
1814                 }
1815         }
1816         /* left pins can be connect to any audio widget */
1817         for (i = 0; i < cfg->line_outs; i++) {
1818                 nid = cfg->line_out_pins[i];
1819                 if (alc880_is_fixed_pin(nid))
1820                         continue;
1821                 /* search for an empty channel */
1822                 for (j = 0; j < cfg->line_outs; j++) {
1823                         if (! assigned[j]) {
1824                                 spec->multiout.dac_nids[i] = alc880_idx_to_dac(j);
1825                                 assigned[j] = 1;
1826                                 break;
1827                         }
1828                 }
1829         }
1830         spec->multiout.num_dacs = cfg->line_outs;
1831         return 0;
1832 }
1833
1834 /* add playback controls from the parsed DAC table */
1835 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
1836 {
1837         char name[32];
1838         static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
1839         hda_nid_t nid;
1840         int i, err;
1841
1842         for (i = 0; i < cfg->line_outs; i++) {
1843                 if (! spec->multiout.dac_nids[i])
1844                         continue;
1845                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
1846                 if (i == 2) {
1847                         /* Center/LFE */
1848                         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Center Playback Volume",
1849                                                HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
1850                                 return err;
1851                         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "LFE Playback Volume",
1852                                                HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
1853                                 return err;
1854                         if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "Center Playback Switch",
1855                                                HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT))) < 0)
1856                                 return err;
1857                         if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "LFE Playback Switch",
1858                                                HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT))) < 0)
1859                                 return err;
1860                 } else {
1861                         sprintf(name, "%s Playback Volume", chname[i]);
1862                         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
1863                                                HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1864                                 return err;
1865                         sprintf(name, "%s Playback Switch", chname[i]);
1866                         if ((err = add_control(spec, ALC_CTL_BIND_MUTE, name,
1867                                                HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
1868                                 return err;
1869                 }
1870         }
1871
1872         return 0;
1873 }
1874
1875 /* add playback controls for HP output */
1876 static int alc880_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
1877 {
1878         hda_nid_t nid;
1879         int err;
1880
1881         if (! pin)
1882                 return 0;
1883
1884         if (alc880_is_fixed_pin(pin)) {
1885                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
1886                 if (! spec->multiout.dac_nids[0]) {
1887                         /* use this as the primary output */
1888                         spec->multiout.dac_nids[0] = nid;
1889                         if (! spec->multiout.num_dacs)
1890                                 spec->multiout.num_dacs = 1;
1891                 } else 
1892                         /* specify the DAC as the extra HP output */
1893                         spec->multiout.hp_nid = nid;
1894                 /* control HP volume/switch on the output mixer amp */
1895                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
1896                 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Headphone Playback Volume",
1897                                        HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1898                         return err;
1899                 if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "Headphone Playback Switch",
1900                                        HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
1901                         return err;
1902         } else if (alc880_is_multi_pin(pin)) {
1903                 /* set manual connection */
1904                 if (! spec->multiout.dac_nids[0]) {
1905                         /* use this as the primary output */
1906                         spec->multiout.dac_nids[0] = alc880_idx_to_dac(alc880_multi_pin_idx(pin));
1907                         if (! spec->multiout.num_dacs)
1908                                 spec->multiout.num_dacs = 1;
1909                 }
1910                 /* we have only a switch on HP-out PIN */
1911                 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
1912                                        HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT))) < 0)
1913                         return err;
1914         }
1915         return 0;
1916 }
1917
1918 /* create input playback/capture controls for the given pin */
1919 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin, const char *ctlname)
1920 {
1921         char name[32];
1922         int err, idx;
1923
1924         sprintf(name, "%s Playback Volume", ctlname);
1925         idx = alc880_input_pin_idx(pin);
1926         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
1927                                HDA_COMPOSE_AMP_VAL(0x0b, 3, idx, HDA_INPUT))) < 0)
1928                 return err;
1929         sprintf(name, "%s Playback Switch", ctlname);
1930         if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
1931                                HDA_COMPOSE_AMP_VAL(0x0b, 3, idx, HDA_INPUT))) < 0)
1932                 return err;
1933         return 0;
1934 }
1935
1936 /* create playback/capture controls for input pins */
1937 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
1938 {
1939         static char *labels[AUTO_PIN_LAST] = {
1940                 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux"
1941         };
1942         struct hda_input_mux *imux = &spec->private_imux;
1943         int i, err;
1944
1945         for (i = 0; i < AUTO_PIN_LAST; i++) {
1946                 if (alc880_is_input_pin(cfg->input_pins[i])) {
1947                         err = new_analog_input(spec, cfg->input_pins[i], labels[i]);
1948                         if (err < 0)
1949                                 return err;
1950                         imux->items[imux->num_items].label = labels[i];
1951                         imux->items[imux->num_items].index = alc880_input_pin_idx(cfg->input_pins[i]);
1952                         imux->num_items++;
1953                 }
1954         }
1955         return 0;
1956 }
1957
1958 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec, hda_nid_t nid, int pin_type,
1959                                               int dac_idx)
1960 {
1961         /* set as output */
1962         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
1963         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
1964         /* need the manual connection? */
1965         if (alc880_is_multi_pin(nid)) {
1966                 struct alc_spec *spec = codec->spec;
1967                 int idx = alc880_multi_pin_idx(nid);
1968                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
1969                                     AC_VERB_SET_CONNECT_SEL,
1970                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
1971         }
1972 }
1973
1974 static void alc880_auto_init_multi_out(struct hda_codec *codec)
1975 {
1976         struct alc_spec *spec = codec->spec;
1977         int i;
1978
1979         for (i = 0; i < spec->autocfg.line_outs; i++) {
1980                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1981                 alc880_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
1982         }
1983 }
1984
1985 static void alc880_auto_init_hp_out(struct hda_codec *codec)
1986 {
1987         struct alc_spec *spec = codec->spec;
1988         hda_nid_t pin;
1989
1990         pin = spec->autocfg.hp_pin;
1991         if (pin) /* connect to front */
1992                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
1993 }
1994
1995 static void alc880_auto_init_analog_input(struct hda_codec *codec)
1996 {
1997         struct alc_spec *spec = codec->spec;
1998         int i;
1999
2000         for (i = 0; i < AUTO_PIN_LAST; i++) {
2001                 hda_nid_t nid = spec->autocfg.input_pins[i];
2002                 if (alc880_is_input_pin(nid)) {
2003                         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2004                                             i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2005                         if (nid != ALC880_PIN_CD_NID)
2006                                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2007                                                     AMP_OUT_MUTE);
2008                 }
2009         }
2010 }
2011
2012 /* parse the BIOS configuration and set up the alc_spec */
2013 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2014 static int alc880_parse_auto_config(struct hda_codec *codec)
2015 {
2016         struct alc_spec *spec = codec->spec;
2017         int err;
2018
2019         if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg)) < 0)
2020                 return err;
2021         if ((err = alc880_auto_fill_dac_nids(spec, &spec->autocfg)) < 0)
2022                 return err;
2023         if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
2024                 return 0; /* can't find valid BIOS pin config */
2025         if ((err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2026             (err = alc880_auto_create_hp_ctls(spec, spec->autocfg.hp_pin)) < 0 ||
2027             (err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2028                 return err;
2029
2030         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2031
2032         if (spec->autocfg.dig_out_pin)
2033                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
2034         if (spec->autocfg.dig_in_pin)
2035                 spec->dig_in_nid = ALC880_DIGIN_NID;
2036
2037         if (spec->kctl_alloc)
2038                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2039
2040         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
2041
2042         spec->input_mux = &spec->private_imux;
2043
2044         return 1;
2045 }
2046
2047 /* init callback for auto-configuration model -- overriding the default init */
2048 static int alc880_auto_init(struct hda_codec *codec)
2049 {
2050         alc_init(codec);
2051         alc880_auto_init_multi_out(codec);
2052         alc880_auto_init_hp_out(codec);
2053         alc880_auto_init_analog_input(codec);
2054         return 0;
2055 }
2056
2057 /*
2058  * OK, here we have finally the patch for ALC880
2059  */
2060
2061 static int patch_alc880(struct hda_codec *codec)
2062 {
2063         struct alc_spec *spec;
2064         int board_config;
2065         int i, err;
2066
2067         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2068         if (spec == NULL)
2069                 return -ENOMEM;
2070
2071         codec->spec = spec;
2072
2073         board_config = snd_hda_check_board_config(codec, alc880_cfg_tbl);
2074         if (board_config < 0 || board_config >= ALC880_MODEL_LAST) {
2075                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, trying auto-probe from BIOS...\n");
2076                 board_config = ALC880_AUTO;
2077         }
2078
2079         if (board_config == ALC880_AUTO) {
2080                 /* automatic parse from the BIOS config */
2081                 err = alc880_parse_auto_config(codec);
2082                 if (err < 0) {
2083                         alc_free(codec);
2084                         return err;
2085                 } else if (! err) {
2086                         printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS.  Using 3-stack mode...\n");
2087                         board_config = ALC880_3ST;
2088                 }
2089         }
2090
2091         if (board_config != ALC880_AUTO) {
2092                 /* set up from the preset table */
2093                 const struct alc_config_preset *preset;
2094
2095                 preset = &alc880_presets[board_config];
2096
2097                 for (i = 0; preset->mixers[i]; i++) {
2098                         snd_assert(spec->num_mixers < ARRAY_SIZE(spec->mixers), break);
2099                         spec->mixers[spec->num_mixers++] = preset->mixers[i];
2100                 }
2101                 for (i = 0; preset->init_verbs[i]; i++) {
2102                         snd_assert(spec->num_init_verbs < ARRAY_SIZE(spec->init_verbs), break);
2103                         spec->init_verbs[spec->num_init_verbs++] = preset->init_verbs[i];
2104                 }
2105
2106                 spec->channel_mode = preset->channel_mode;
2107                 spec->num_channel_mode = preset->num_channel_mode;
2108
2109                 spec->multiout.max_channels = spec->channel_mode[0].channels;
2110
2111                 spec->multiout.num_dacs = preset->num_dacs;
2112                 spec->multiout.dac_nids = preset->dac_nids;
2113                 spec->multiout.dig_out_nid = preset->dig_out_nid;
2114                 spec->multiout.hp_nid = preset->hp_nid;
2115
2116                 spec->input_mux = preset->input_mux;
2117
2118                 spec->num_adc_nids = preset->num_adc_nids;
2119                 spec->adc_nids = preset->adc_nids;
2120         }
2121
2122         spec->stream_name_analog = "ALC880 Analog";
2123         spec->stream_analog_playback = &alc880_pcm_analog_playback;
2124         spec->stream_analog_capture = &alc880_pcm_analog_capture;
2125
2126         spec->stream_name_digital = "ALC880 Digital";
2127         spec->stream_digital_playback = &alc880_pcm_digital_playback;
2128         spec->stream_digital_capture = &alc880_pcm_digital_capture;
2129
2130         if (! spec->adc_nids && spec->input_mux) {
2131                 /* check whether NID 0x07 is valid */
2132                 unsigned int wcap = snd_hda_param_read(codec, alc880_adc_nids[0],
2133                                                        AC_PAR_AUDIO_WIDGET_CAP);
2134                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
2135                 if (wcap != AC_WID_AUD_IN) {
2136                         spec->adc_nids = alc880_adc_nids_alt;
2137                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
2138                         spec->mixers[spec->num_mixers] = alc880_capture_alt_mixer;
2139                         spec->num_mixers++;
2140                 } else {
2141                         spec->adc_nids = alc880_adc_nids;
2142                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
2143                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
2144                         spec->num_mixers++;
2145                 }
2146         }
2147
2148         codec->patch_ops = alc_patch_ops;
2149         if (board_config == ALC880_AUTO)
2150                 codec->patch_ops.init = alc880_auto_init;
2151
2152         return 0;
2153 }
2154
2155
2156 /*
2157  * ALC260 support
2158  */
2159
2160 static hda_nid_t alc260_dac_nids[1] = {
2161         /* front */
2162         0x02,
2163 };
2164
2165 static hda_nid_t alc260_adc_nids[1] = {
2166         /* ADC0 */
2167         0x04,
2168 };
2169
2170 static hda_nid_t alc260_hp_adc_nids[1] = {
2171         /* ADC1 */
2172         0x05,
2173 };
2174
2175 #define ALC260_DIGOUT_NID       0x03
2176 #define ALC260_DIGIN_NID        0x06
2177
2178 static struct hda_input_mux alc260_capture_source = {
2179         .num_items = 4,
2180         .items = {
2181                 { "Mic", 0x0 },
2182                 { "Front Mic", 0x1 },
2183                 { "Line", 0x2 },
2184                 { "CD", 0x4 },
2185         },
2186 };
2187
2188 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack
2189  * and the internal CD lines.
2190  */
2191 static struct hda_input_mux alc260_fujitsu_capture_source = {
2192         .num_items = 2,
2193         .items = {
2194                 { "Mic/Line", 0x0 },
2195                 { "CD", 0x4 },
2196         },
2197 };
2198
2199 /*
2200  * This is just place-holder, so there's something for alc_build_pcms to look
2201  * at when it calculates the maximum number of channels. ALC260 has no mixer
2202  * element which allows changing the channel mode, so the verb list is
2203  * never used.
2204  */
2205 static struct alc_channel_mode alc260_modes[1] = {
2206         { 2, NULL },
2207 };
2208
2209 static snd_kcontrol_new_t alc260_base_mixer[] = {
2210         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
2211         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
2212         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
2213         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
2214         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
2215         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
2216         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
2217         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
2218         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
2219         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
2220         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
2221         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
2222         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
2223         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
2224         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2225         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
2226         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
2227         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
2228         {
2229                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2230                 .name = "Capture Source",
2231                 .info = alc_mux_enum_info,
2232                 .get = alc_mux_enum_get,
2233                 .put = alc_mux_enum_put,
2234         },
2235         { } /* end */
2236 };
2237
2238 static snd_kcontrol_new_t alc260_hp_mixer[] = {
2239         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
2240         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
2241         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
2242         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
2243         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
2244         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
2245         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
2246         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
2247         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
2248         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
2249         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
2250         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
2251         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2252         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
2253         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
2254         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
2255         {
2256                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2257                 .name = "Capture Source",
2258                 .info = alc_mux_enum_info,
2259                 .get = alc_mux_enum_get,
2260                 .put = alc_mux_enum_put,
2261         },
2262         { } /* end */
2263 };
2264
2265 static snd_kcontrol_new_t alc260_fujitsu_mixer[] = {
2266         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
2267         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
2268         ALC_PINCTL_SWITCH("Headphone Amp Switch", 0x14, PIN_HP_AMP),
2269         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
2270         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
2271         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
2272         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
2273         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
2274         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
2275         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
2276         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
2277         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
2278         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
2279         {
2280                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2281                 .name = "Capture Source",
2282                 .info = alc_mux_enum_info,
2283                 .get = alc_mux_enum_get,
2284                 .put = alc_mux_enum_put,
2285         },
2286         { } /* end */
2287 };
2288
2289 static struct hda_verb alc260_init_verbs[] = {
2290         /* Line In pin widget for input */
2291         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2292         /* CD pin widget for input */
2293         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2294         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2295         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2296         /* Mic2 (front panel) pin widget for input and vref at 80% */
2297         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2298         /* LINE-2 is used for line-out in rear */
2299         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2300         /* select line-out */
2301         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2302         /* LINE-OUT pin */
2303         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2304         /* enable HP */
2305         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2306         /* enable Mono */
2307         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2308         /* mute capture amp left and right */
2309         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2310         /* set connection select to line in (default select for this ADC) */
2311         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
2312         /* mute capture amp left and right */
2313         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2314         /* set connection select to line in (default select for this ADC) */
2315         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
2316         /* set vol=0 Line-Out mixer amp left and right */
2317         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2318         /* unmute pin widget amp left and right (no gain on this amp) */
2319         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2320         /* set vol=0 HP mixer amp left and right */
2321         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2322         /* unmute pin widget amp left and right (no gain on this amp) */
2323         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2324         /* set vol=0 Mono mixer amp left and right */
2325         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2326         /* unmute pin widget amp left and right (no gain on this amp) */
2327         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2328         /* unmute LINE-2 out pin */
2329         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2330         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 & Line In 2 = 0x03 */
2331         /* mute CD */
2332         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2333         /* mute Line In */
2334         {0x07,  AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2335         /* mute Mic */
2336         {0x07,  AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2337         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
2338         /* mute Front out path */
2339         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2340         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2341         /* mute Headphone out path */
2342         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2343         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2344         /* mute Mono out path */
2345         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2346         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2347         { }
2348 };
2349
2350 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
2351  * laptops.
2352  */
2353 static struct hda_verb alc260_fujitsu_init_verbs[] = {
2354         /* Disable all GPIOs */
2355         {0x01, AC_VERB_SET_GPIO_MASK, 0},
2356         /* Internal speaker is connected to headphone pin */
2357         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2358         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
2359         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2360         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
2361         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2362         /* Ensure all other unused pins are disabled and muted.
2363          * Note: trying to set widget 0x15 to anything blocks all audio
2364          * output for some reason, so just leave that at the default.
2365          */
2366         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2367         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2368         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2369         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2370         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2371         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2372         /* Disable digital (SPDIF) pins */
2373         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
2374         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
2375
2376         /* Start with mixer outputs muted */
2377         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2378         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2379         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2380
2381         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
2382         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2383         /* Unmute Line1 pin widget amp left and right (no equiv mixer ctrl) */
2384         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2385         /* Unmute pin widget used for Line-in (no equiv mixer ctrl) */
2386         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2387
2388         /* Mute capture amp left and right */
2389         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2390         /* Set ADC connection select to line in (on mic1 pin) */
2391         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
2392
2393         /* Mute all inputs to mixer widget (even unconnected ones) */
2394         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
2395         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
2396         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
2397         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
2398         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
2399         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
2400         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
2401         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
2402 };
2403
2404 static struct hda_pcm_stream alc260_pcm_analog_playback = {
2405         .substreams = 1,
2406         .channels_min = 2,
2407         .channels_max = 2,
2408 };
2409
2410 static struct hda_pcm_stream alc260_pcm_analog_capture = {
2411         .substreams = 1,
2412         .channels_min = 2,
2413         .channels_max = 2,
2414 };
2415
2416 static struct hda_board_config alc260_cfg_tbl[] = {
2417         { .modelname = "hp", .config = ALC260_HP },
2418         { .pci_subvendor = 0x103c, .config = ALC260_HP },
2419         { .modelname = "fujitsu", .config = ALC260_FUJITSU_S702x },
2420         { .pci_subvendor = 0x10cf, .pci_subdevice = 0x1326, .config = ALC260_FUJITSU_S702x },
2421         {}
2422 };
2423
2424 static int patch_alc260(struct hda_codec *codec)
2425 {
2426         struct alc_spec *spec;
2427         int board_config;
2428
2429         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2430         if (spec == NULL)
2431                 return -ENOMEM;
2432
2433         codec->spec = spec;
2434
2435         board_config = snd_hda_check_board_config(codec, alc260_cfg_tbl);
2436         if (board_config < 0 || board_config >= ALC260_MODEL_LAST) {
2437                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260\n");
2438                 board_config = ALC260_BASIC;
2439         }
2440
2441         switch (board_config) {
2442         case ALC260_HP:
2443                 spec->mixers[spec->num_mixers] = alc260_hp_mixer;
2444                 spec->num_mixers++;
2445                 break;
2446         case ALC260_FUJITSU_S702x:
2447                 spec->mixers[spec->num_mixers] = alc260_fujitsu_mixer;
2448                 spec->num_mixers++;
2449                 break;
2450         default:
2451                 spec->mixers[spec->num_mixers] = alc260_base_mixer;
2452                 spec->num_mixers++;
2453                 break;
2454         }
2455
2456         if (board_config != ALC260_FUJITSU_S702x) {
2457                 spec->init_verbs[0] = alc260_init_verbs;
2458                 spec->num_init_verbs = 1;
2459         } else {
2460                 spec->init_verbs[0] = alc260_fujitsu_init_verbs;
2461                 spec->num_init_verbs = 1;
2462         }
2463
2464         spec->channel_mode = alc260_modes;
2465         spec->num_channel_mode = ARRAY_SIZE(alc260_modes);
2466
2467         spec->stream_name_analog = "ALC260 Analog";
2468         spec->stream_analog_playback = &alc260_pcm_analog_playback;
2469         spec->stream_analog_capture = &alc260_pcm_analog_capture;
2470
2471         spec->multiout.max_channels = spec->channel_mode[0].channels;
2472         spec->multiout.num_dacs = ARRAY_SIZE(alc260_dac_nids);
2473         spec->multiout.dac_nids = alc260_dac_nids;
2474
2475         if (board_config != ALC260_FUJITSU_S702x) {
2476                 spec->input_mux = &alc260_capture_source;
2477         } else {
2478                 spec->input_mux = &alc260_fujitsu_capture_source;
2479         }
2480         switch (board_config) {
2481         case ALC260_HP:
2482                 spec->num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids);
2483                 spec->adc_nids = alc260_hp_adc_nids;
2484                 break;
2485         default:
2486                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
2487                 spec->adc_nids = alc260_adc_nids;
2488                 break;
2489         }
2490
2491         codec->patch_ops = alc_patch_ops;
2492
2493         return 0;
2494 }
2495
2496
2497 /*
2498  * ALC882 support
2499  *
2500  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
2501  * configuration.  Each pin widget can choose any input DACs and a mixer.
2502  * Each ADC is connected from a mixer of all inputs.  This makes possible
2503  * 6-channel independent captures.
2504  *
2505  * In addition, an independent DAC for the multi-playback (not used in this
2506  * driver yet).
2507  */
2508
2509 static struct alc_channel_mode alc882_ch_modes[1] = {
2510         { 8, NULL }
2511 };
2512
2513 static hda_nid_t alc882_dac_nids[4] = {
2514         /* front, rear, clfe, rear_surr */
2515         0x02, 0x03, 0x04, 0x05
2516 };
2517
2518 static hda_nid_t alc882_adc_nids[3] = {
2519         /* ADC0-2 */
2520         0x07, 0x08, 0x09,
2521 };
2522
2523 /* input MUX */
2524 /* FIXME: should be a matrix-type input source selection */
2525
2526 static struct hda_input_mux alc882_capture_source = {
2527         .num_items = 4,
2528         .items = {
2529                 { "Mic", 0x0 },
2530                 { "Front Mic", 0x1 },
2531                 { "Line", 0x2 },
2532                 { "CD", 0x4 },
2533         },
2534 };
2535
2536 #define alc882_mux_enum_info alc_mux_enum_info
2537 #define alc882_mux_enum_get alc_mux_enum_get
2538
2539 static int alc882_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
2540 {
2541         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2542         struct alc_spec *spec = codec->spec;
2543         const struct hda_input_mux *imux = spec->input_mux;
2544         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2545         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
2546         hda_nid_t nid = capture_mixers[adc_idx];
2547         unsigned int *cur_val = &spec->cur_mux[adc_idx];
2548         unsigned int i, idx;
2549
2550         idx = ucontrol->value.enumerated.item[0];
2551         if (idx >= imux->num_items)
2552                 idx = imux->num_items - 1;
2553         if (*cur_val == idx && ! codec->in_resume)
2554                 return 0;
2555         for (i = 0; i < imux->num_items; i++) {
2556                 unsigned int v = (i == idx) ? 0x7000 : 0x7080;
2557                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2558                                     v | (imux->items[i].index << 8));
2559         }
2560         *cur_val = idx;
2561         return 1;
2562 }
2563
2564 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
2565  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
2566  */
2567 static snd_kcontrol_new_t alc882_base_mixer[] = {
2568         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2569         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2570         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2571         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2572         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2573         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2574         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2575         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2576         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2577         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2578         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2579         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2580         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2581         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2582         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2583         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2584         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2585         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2586         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2587         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
2588         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
2589         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
2590         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
2591         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
2592         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
2593         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
2594         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
2595         {
2596                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2597                 /* .name = "Capture Source", */
2598                 .name = "Input Source",
2599                 .count = 3,
2600                 .info = alc882_mux_enum_info,
2601                 .get = alc882_mux_enum_get,
2602                 .put = alc882_mux_enum_put,
2603         },
2604         { } /* end */
2605 };
2606
2607 static struct hda_verb alc882_init_verbs[] = {
2608         /* Front mixer: unmute input/output amp left and right (volume = 0) */
2609         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2610         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2611         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2612         /* Rear mixer */
2613         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2614         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2615         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2616         /* CLFE mixer */
2617         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2618         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2619         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2620         /* Side mixer */
2621         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2622         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2623         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2624
2625         /* Front Pin: output 0 (0x0c) */
2626         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2627         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2628         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
2629         /* Rear Pin: output 1 (0x0d) */
2630         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2631         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2632         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
2633         /* CLFE Pin: output 2 (0x0e) */
2634         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2635         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2636         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
2637         /* Side Pin: output 3 (0x0f) */
2638         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2639         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2640         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
2641         /* Mic (rear) pin: input vref at 80% */
2642         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2643         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2644         /* Front Mic pin: input vref at 80% */
2645         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2646         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2647         /* Line In pin: input */
2648         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2649         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2650         /* Line-2 In: Headphone output (output 0 - 0x0c) */
2651         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2652         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2653         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2654         /* CD pin widget for input */
2655         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2656
2657         /* FIXME: use matrix-type input source selection */
2658         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
2659         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
2660         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2661         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2662         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2663         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2664         /* Input mixer2 */
2665         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2666         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2667         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2668         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2669         /* Input mixer3 */
2670         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2671         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2672         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2673         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2674         /* ADC1: mute amp left and right */
2675         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2676         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2677         /* ADC2: mute amp left and right */
2678         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2679         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2680         /* ADC3: mute amp left and right */
2681         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2682         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2683
2684         { }
2685 };
2686
2687 static int patch_alc882(struct hda_codec *codec)
2688 {
2689         struct alc_spec *spec;
2690
2691         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2692         if (spec == NULL)
2693                 return -ENOMEM;
2694
2695         codec->spec = spec;
2696
2697         spec->mixers[spec->num_mixers] = alc882_base_mixer;
2698         spec->num_mixers++;
2699
2700         spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
2701         spec->dig_in_nid = ALC880_DIGIN_NID;
2702         spec->init_verbs[0] = alc882_init_verbs;
2703         spec->num_init_verbs = 1;
2704
2705         spec->channel_mode = alc882_ch_modes;
2706         spec->num_channel_mode = ARRAY_SIZE(alc882_ch_modes);
2707
2708         spec->stream_name_analog = "ALC882 Analog";
2709         spec->stream_analog_playback = &alc880_pcm_analog_playback;
2710         spec->stream_analog_capture = &alc880_pcm_analog_capture;
2711
2712         spec->stream_name_digital = "ALC882 Digital";
2713         spec->stream_digital_playback = &alc880_pcm_digital_playback;
2714         spec->stream_digital_capture = &alc880_pcm_digital_capture;
2715
2716         spec->multiout.max_channels = spec->channel_mode[0].channels;
2717         spec->multiout.num_dacs = ARRAY_SIZE(alc882_dac_nids);
2718         spec->multiout.dac_nids = alc882_dac_nids;
2719
2720         spec->input_mux = &alc882_capture_source;
2721         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
2722         spec->adc_nids = alc882_adc_nids;
2723
2724         codec->patch_ops = alc_patch_ops;
2725
2726         return 0;
2727 }
2728
2729 /*
2730  * patch entries
2731  */
2732 struct hda_codec_preset snd_hda_preset_realtek[] = {
2733         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
2734         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
2735         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
2736         {} /* terminator */
2737 };