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