]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - sound/pci/hda/patch_realtek.c
[ALSA] opti93x: optimize a register access
[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
3c10a9d9
TI
690/* additional mixers to alc880_asus_mixer */
691static snd_kcontrol_new_t alc880_pcbeep_mixer[] = {
692 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
693 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
694 { } /* end */
695};
e9edcee0 696
1da177e4 697/*
e9edcee0 698 * build control elements
1da177e4
LT
699 */
700static int alc_build_controls(struct hda_codec *codec)
701{
702 struct alc_spec *spec = codec->spec;
703 int err;
704 int i;
705
706 for (i = 0; i < spec->num_mixers; i++) {
707 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
708 if (err < 0)
709 return err;
710 }
711
712 if (spec->multiout.dig_out_nid) {
713 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
714 if (err < 0)
715 return err;
716 }
717 if (spec->dig_in_nid) {
718 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
719 if (err < 0)
720 return err;
721 }
722 return 0;
723}
724
e9edcee0 725
1da177e4
LT
726/*
727 * initialize the codec volumes, etc
728 */
729
e9edcee0
TI
730/*
731 * generic initialization of ADC, input mixers and output mixers
732 */
733static struct hda_verb alc880_volume_init_verbs[] = {
734 /*
735 * Unmute ADC0-2 and set the default input to mic-in
736 */
71fe7b82 737 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
e9edcee0 738 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
71fe7b82 739 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
e9edcee0 740 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
71fe7b82 741 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
e9edcee0 742 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1da177e4 743
e9edcee0
TI
744 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
745 * mixer widget
1da177e4
LT
746 * Note: PASD motherboards uses the Line In 2 as the input for front panel
747 * mic (mic 2)
748 */
e9edcee0 749 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
16ded525 750 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
e9edcee0
TI
751 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
752 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
753 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
754 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1da177e4 755
e9edcee0
TI
756 /*
757 * Set up output mixers (0x0c - 0x0f)
1da177e4 758 */
e9edcee0
TI
759 /* set vol=0 to output mixers */
760 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
761 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
762 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
763 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
764 /* set up input amps for analog loopback */
765 /* Amp Indices: DAC = 0, mixer = 1 */
05acb863
TI
766 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
767 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
05acb863
TI
768 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
769 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
05acb863
TI
770 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
771 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
05acb863
TI
772 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
773 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1da177e4
LT
774
775 { }
776};
777
e9edcee0
TI
778/*
779 * 3-stack pin configuration:
780 * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
781 */
782static struct hda_verb alc880_pin_3stack_init_verbs[] = {
783 /*
784 * preset connection lists of input pins
785 * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
786 */
787 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
788 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
789 {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
790
791 /*
792 * Set pin mode and muting
793 */
794 /* set front pin widgets 0x14 for output */
05acb863 795 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0
TI
796 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
797 /* Mic1 (rear panel) pin widget for input and vref at 80% */
798 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
799 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
800 /* Mic2 (as headphone out) for HP output */
801 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
802 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1da177e4 803 /* Line In pin widget for input */
05acb863 804 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
e9edcee0
TI
805 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
806 /* Line2 (as front mic) pin widget for input and vref at 80% */
807 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
808 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1da177e4 809 /* CD pin widget for input */
05acb863 810 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1da177e4 811
e9edcee0
TI
812 { }
813};
1da177e4 814
e9edcee0
TI
815/*
816 * 5-stack pin configuration:
817 * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
818 * line-in/side = 0x1a, f-mic = 0x1b
819 */
820static struct hda_verb alc880_pin_5stack_init_verbs[] = {
821 /*
822 * preset connection lists of input pins
823 * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1da177e4 824 */
e9edcee0
TI
825 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
826 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1da177e4 827
e9edcee0
TI
828 /*
829 * Set pin mode and muting
1da177e4 830 */
e9edcee0
TI
831 /* set pin widgets 0x14-0x17 for output */
832 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
833 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
834 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
835 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
836 /* unmute pins for output (no gain on this amp) */
837 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
838 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
839 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
840 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
841
842 /* Mic1 (rear panel) pin widget for input and vref at 80% */
843 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
844 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
845 /* Mic2 (as headphone out) for HP output */
846 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
847 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
848 /* Line In pin widget for input */
849 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
850 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
851 /* Line2 (as front mic) pin widget for input and vref at 80% */
852 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
853 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
854 /* CD pin widget for input */
855 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1da177e4
LT
856
857 { }
858};
859
e9edcee0
TI
860/*
861 * W810 pin configuration:
862 * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
863 */
864static struct hda_verb alc880_pin_w810_init_verbs[] = {
865 /* hphone/speaker input selector: front DAC */
866 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1da177e4 867
05acb863 868 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 869 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
05acb863 870 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 871 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
05acb863 872 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 873 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1da177e4 874
e9edcee0 875 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
05acb863 876 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1da177e4 877
1da177e4
LT
878 { }
879};
880
e9edcee0
TI
881/*
882 * Z71V pin configuration:
883 * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
884 */
885static struct hda_verb alc880_pin_z71v_init_verbs[] = {
05acb863 886 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 887 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
05acb863 888 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
e9edcee0 889 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
dfc0ff62 890
16ded525 891 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
e9edcee0 892 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16ded525 893 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
e9edcee0 894 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16ded525
TI
895
896 { }
897};
898
e9edcee0
TI
899/*
900 * 6-stack pin configuration:
901 * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18, f-mic = 0x19,
902 * line = 0x1a, HP = 0x1b
903 */
904static struct hda_verb alc880_pin_6stack_init_verbs[] = {
905 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
906
16ded525 907 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 908 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 909 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 910 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 911 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 912 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 913 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0
TI
914 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
915
16ded525 916 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
e9edcee0 917 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16ded525 918 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
e9edcee0 919 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16ded525 920 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
e9edcee0 921 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16ded525 922 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
e9edcee0 923 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525
TI
924 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
925
e9edcee0
TI
926 { }
927};
928
929/* FIXME! */
930/*
931 * F1734 pin configuration:
932 * HP = 0x14, speaker-out = 0x15, mic = 0x18
933 */
934static struct hda_verb alc880_pin_f1734_init_verbs[] = {
16ded525
TI
935 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
936 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
937 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
938 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
939
e9edcee0 940 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16ded525 941 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
e9edcee0 942 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16ded525 943 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 944
e9edcee0
TI
945 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
946 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16ded525 947 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
e9edcee0 948 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16ded525 949 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 950 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 951 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 952 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 953 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
dfc0ff62
TI
954
955 { }
956};
957
e9edcee0
TI
958/* FIXME! */
959/*
960 * ASUS pin configuration:
961 * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
962 */
963static struct hda_verb alc880_pin_asus_init_verbs[] = {
16ded525
TI
964 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
965 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
966 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
967 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
968
969 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
e9edcee0 970 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 971 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 972 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 973 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 974 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 975 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0
TI
976 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
977
978 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
979 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
980 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
981 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
982 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
983 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16ded525 984 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 985 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525
TI
986 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
987
e9edcee0
TI
988 { }
989};
16ded525 990
e9edcee0
TI
991/* Enable GPIO mask and set output */
992static struct hda_verb alc880_gpio1_init_verbs[] = {
993 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
994 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
995 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
996};
16ded525 997
e9edcee0
TI
998/* Enable GPIO mask and set output */
999static struct hda_verb alc880_gpio2_init_verbs[] = {
1000 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
1001 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
1002 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
16ded525
TI
1003};
1004
1005
e9edcee0
TI
1006/*
1007 */
1008
1da177e4
LT
1009static int alc_init(struct hda_codec *codec)
1010{
1011 struct alc_spec *spec = codec->spec;
e9edcee0
TI
1012 unsigned int i;
1013
1014 for (i = 0; i < spec->num_init_verbs; i++)
1015 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1da177e4
LT
1016 return 0;
1017}
1018
1019#ifdef CONFIG_PM
1020/*
1021 * resume
1022 */
1023static int alc_resume(struct hda_codec *codec)
1024{
1025 struct alc_spec *spec = codec->spec;
1026 int i;
1027
1028 alc_init(codec);
e9edcee0 1029 for (i = 0; i < spec->num_mixers; i++)
1da177e4 1030 snd_hda_resume_ctls(codec, spec->mixers[i]);
1da177e4
LT
1031 if (spec->multiout.dig_out_nid)
1032 snd_hda_resume_spdif_out(codec);
1033 if (spec->dig_in_nid)
1034 snd_hda_resume_spdif_in(codec);
1035
1036 return 0;
1037}
1038#endif
1039
1040/*
1041 * Analog playback callbacks
1042 */
1043static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
1044 struct hda_codec *codec,
1045 snd_pcm_substream_t *substream)
1046{
1047 struct alc_spec *spec = codec->spec;
1048 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1049}
1050
1051static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1052 struct hda_codec *codec,
1053 unsigned int stream_tag,
1054 unsigned int format,
1055 snd_pcm_substream_t *substream)
1056{
1057 struct alc_spec *spec = codec->spec;
1058 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1059 format, substream);
1060}
1061
1062static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1063 struct hda_codec *codec,
1064 snd_pcm_substream_t *substream)
1065{
1066 struct alc_spec *spec = codec->spec;
1067 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1068}
1069
1070/*
1071 * Digital out
1072 */
1073static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1074 struct hda_codec *codec,
1075 snd_pcm_substream_t *substream)
1076{
1077 struct alc_spec *spec = codec->spec;
1078 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1079}
1080
1081static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1082 struct hda_codec *codec,
1083 snd_pcm_substream_t *substream)
1084{
1085 struct alc_spec *spec = codec->spec;
1086 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1087}
1088
1089/*
1090 * Analog capture
1091 */
1092static int alc880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1093 struct hda_codec *codec,
1094 unsigned int stream_tag,
1095 unsigned int format,
1096 snd_pcm_substream_t *substream)
1097{
1098 struct alc_spec *spec = codec->spec;
1099
1100 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1101 stream_tag, 0, format);
1102 return 0;
1103}
1104
1105static int alc880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1106 struct hda_codec *codec,
1107 snd_pcm_substream_t *substream)
1108{
1109 struct alc_spec *spec = codec->spec;
1110
1111 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
1112 return 0;
1113}
1114
1115
1116/*
1117 */
1118static struct hda_pcm_stream alc880_pcm_analog_playback = {
1119 .substreams = 1,
1120 .channels_min = 2,
1121 .channels_max = 8,
e9edcee0 1122 /* NID is set in alc_build_pcms */
1da177e4
LT
1123 .ops = {
1124 .open = alc880_playback_pcm_open,
1125 .prepare = alc880_playback_pcm_prepare,
1126 .cleanup = alc880_playback_pcm_cleanup
1127 },
1128};
1129
1130static struct hda_pcm_stream alc880_pcm_analog_capture = {
1131 .substreams = 2,
1132 .channels_min = 2,
1133 .channels_max = 2,
e9edcee0 1134 /* NID is set in alc_build_pcms */
1da177e4
LT
1135 .ops = {
1136 .prepare = alc880_capture_pcm_prepare,
1137 .cleanup = alc880_capture_pcm_cleanup
1138 },
1139};
1140
1141static struct hda_pcm_stream alc880_pcm_digital_playback = {
1142 .substreams = 1,
1143 .channels_min = 2,
1144 .channels_max = 2,
1145 /* NID is set in alc_build_pcms */
1146 .ops = {
1147 .open = alc880_dig_playback_pcm_open,
1148 .close = alc880_dig_playback_pcm_close
1149 },
1150};
1151
1152static struct hda_pcm_stream alc880_pcm_digital_capture = {
1153 .substreams = 1,
1154 .channels_min = 2,
1155 .channels_max = 2,
1156 /* NID is set in alc_build_pcms */
1157};
1158
1159static int alc_build_pcms(struct hda_codec *codec)
1160{
1161 struct alc_spec *spec = codec->spec;
1162 struct hda_pcm *info = spec->pcm_rec;
1163 int i;
1164
1165 codec->num_pcms = 1;
1166 codec->pcm_info = info;
1167
1168 info->name = spec->stream_name_analog;
1169 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
e9edcee0 1170 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
1da177e4 1171 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
e9edcee0 1172 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1da177e4
LT
1173
1174 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
1175 for (i = 0; i < spec->num_channel_mode; i++) {
1176 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
1177 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
1178 }
1179 }
1180
1181 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1182 codec->num_pcms++;
1183 info++;
1184 info->name = spec->stream_name_digital;
1185 if (spec->multiout.dig_out_nid) {
1186 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
1187 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1188 }
1189 if (spec->dig_in_nid) {
1190 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
1191 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1192 }
1193 }
1194
1195 return 0;
1196}
1197
1198static void alc_free(struct hda_codec *codec)
1199{
e9edcee0
TI
1200 struct alc_spec *spec = codec->spec;
1201 unsigned int i;
1202
1203 if (! spec)
1204 return;
1205
1206 if (spec->kctl_alloc) {
1207 for (i = 0; i < spec->num_kctl_used; i++)
1208 kfree(spec->kctl_alloc[i].name);
1209 kfree(spec->kctl_alloc);
1210 }
1211 kfree(spec);
1da177e4
LT
1212}
1213
1214/*
1215 */
1216static struct hda_codec_ops alc_patch_ops = {
1217 .build_controls = alc_build_controls,
1218 .build_pcms = alc_build_pcms,
1219 .init = alc_init,
1220 .free = alc_free,
1221#ifdef CONFIG_PM
1222 .resume = alc_resume,
1223#endif
1224};
1225
2fa522be
TI
1226
1227/*
1228 * Test configuration for debugging
1229 *
1230 * Almost all inputs/outputs are enabled. I/O pins can be configured via
1231 * enum controls.
1232 */
1233#ifdef CONFIG_SND_DEBUG
1234static hda_nid_t alc880_test_dac_nids[4] = {
1235 0x02, 0x03, 0x04, 0x05
1236};
1237
1238static struct hda_input_mux alc880_test_capture_source = {
1239 .num_items = 5,
1240 .items = {
1241 { "In-1", 0x0 },
1242 { "In-2", 0x1 },
1243 { "In-3", 0x2 },
1244 { "In-4", 0x3 },
1245 { "CD", 0x4 },
1246 },
1247};
1248
fd2c326d 1249static struct alc_channel_mode alc880_test_modes[4] = {
2fa522be 1250 { 2, NULL },
fd2c326d 1251 { 4, NULL },
2fa522be 1252 { 6, NULL },
fd2c326d 1253 { 8, NULL },
2fa522be
TI
1254};
1255
1256static int alc_test_pin_ctl_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1257{
1258 static char *texts[] = {
1259 "N/A", "Line Out", "HP Out",
1260 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
1261 };
1262 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1263 uinfo->count = 1;
1264 uinfo->value.enumerated.items = 8;
1265 if (uinfo->value.enumerated.item >= 8)
1266 uinfo->value.enumerated.item = 7;
1267 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1268 return 0;
1269}
1270
1271static int alc_test_pin_ctl_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1272{
1273 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1274 hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
1275 unsigned int pin_ctl, item = 0;
1276
1277 pin_ctl = snd_hda_codec_read(codec, nid, 0,
1278 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1279 if (pin_ctl & AC_PINCTL_OUT_EN) {
1280 if (pin_ctl & AC_PINCTL_HP_EN)
1281 item = 2;
1282 else
1283 item = 1;
1284 } else if (pin_ctl & AC_PINCTL_IN_EN) {
1285 switch (pin_ctl & AC_PINCTL_VREFEN) {
1286 case AC_PINCTL_VREF_HIZ: item = 3; break;
1287 case AC_PINCTL_VREF_50: item = 4; break;
1288 case AC_PINCTL_VREF_GRD: item = 5; break;
1289 case AC_PINCTL_VREF_80: item = 6; break;
1290 case AC_PINCTL_VREF_100: item = 7; break;
1291 }
1292 }
1293 ucontrol->value.enumerated.item[0] = item;
1294 return 0;
1295}
1296
1297static int alc_test_pin_ctl_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1298{
1299 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1300 hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
1301 static unsigned int ctls[] = {
1302 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
1303 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
1304 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
1305 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
1306 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
1307 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
1308 };
1309 unsigned int old_ctl, new_ctl;
1310
1311 old_ctl = snd_hda_codec_read(codec, nid, 0,
1312 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1313 new_ctl = ctls[ucontrol->value.enumerated.item[0]];
1314 if (old_ctl != new_ctl) {
1315 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, new_ctl);
1316 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1317 ucontrol->value.enumerated.item[0] >= 3 ? 0xb080 : 0xb000);
1318 return 1;
1319 }
1320 return 0;
1321}
1322
1323static int alc_test_pin_src_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1324{
1325 static char *texts[] = {
1326 "Front", "Surround", "CLFE", "Side"
1327 };
1328 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1329 uinfo->count = 1;
1330 uinfo->value.enumerated.items = 4;
1331 if (uinfo->value.enumerated.item >= 4)
1332 uinfo->value.enumerated.item = 3;
1333 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1334 return 0;
1335}
1336
1337static int alc_test_pin_src_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1338{
1339 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1340 hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
1341 unsigned int sel;
1342
1343 sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
1344 ucontrol->value.enumerated.item[0] = sel & 3;
1345 return 0;
1346}
1347
1348static int alc_test_pin_src_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1349{
1350 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1351 hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
1352 unsigned int sel;
1353
1354 sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
1355 if (ucontrol->value.enumerated.item[0] != sel) {
1356 sel = ucontrol->value.enumerated.item[0] & 3;
1357 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, sel);
1358 return 1;
1359 }
1360 return 0;
1361}
1362
1363#define PIN_CTL_TEST(xname,nid) { \
1364 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1365 .name = xname, \
1366 .info = alc_test_pin_ctl_info, \
1367 .get = alc_test_pin_ctl_get, \
1368 .put = alc_test_pin_ctl_put, \
1369 .private_value = nid \
1370 }
1371
1372#define PIN_SRC_TEST(xname,nid) { \
1373 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1374 .name = xname, \
1375 .info = alc_test_pin_src_info, \
1376 .get = alc_test_pin_src_get, \
1377 .put = alc_test_pin_src_put, \
1378 .private_value = nid \
1379 }
1380
1381static snd_kcontrol_new_t alc880_test_mixer[] = {
05acb863
TI
1382 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1383 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1384 HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
1385 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1386 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1387 ALC_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1388 ALC_BIND_MUTE("CLFE Playback Volume", 0x0e, 2, HDA_INPUT),
1389 ALC_BIND_MUTE("Side Playback Volume", 0x0f, 2, HDA_INPUT),
2fa522be
TI
1390 PIN_CTL_TEST("Front Pin Mode", 0x14),
1391 PIN_CTL_TEST("Surround Pin Mode", 0x15),
1392 PIN_CTL_TEST("CLFE Pin Mode", 0x16),
1393 PIN_CTL_TEST("Side Pin Mode", 0x17),
1394 PIN_CTL_TEST("In-1 Pin Mode", 0x18),
1395 PIN_CTL_TEST("In-2 Pin Mode", 0x19),
1396 PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
1397 PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
1398 PIN_SRC_TEST("In-1 Pin Source", 0x18),
1399 PIN_SRC_TEST("In-2 Pin Source", 0x19),
1400 PIN_SRC_TEST("In-3 Pin Source", 0x1a),
1401 PIN_SRC_TEST("In-4 Pin Source", 0x1b),
1402 HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
1403 HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
1404 HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
1405 HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
1406 HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
1407 HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
1408 HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
1409 HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
1410 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
1411 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
05acb863
TI
1412 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1413 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1414 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1415 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
2fa522be
TI
1416 {
1417 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1418 .name = "Input Source",
1419 .count = 2,
1420 .info = alc_mux_enum_info,
1421 .get = alc_mux_enum_get,
1422 .put = alc_mux_enum_put,
1423 },
1424 {
1425 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1426 .name = "Channel Mode",
1427 .info = alc880_ch_mode_info,
1428 .get = alc880_ch_mode_get,
1429 .put = alc880_ch_mode_put,
1430 },
1431 { } /* end */
1432};
1433
1434static struct hda_verb alc880_test_init_verbs[] = {
1435 /* Unmute inputs of 0x0c - 0x0f */
05acb863
TI
1436 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1437 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1438 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1439 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1440 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1441 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1442 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1443 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2fa522be 1444 /* Vol output for 0x0c-0x0f */
05acb863
TI
1445 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1446 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1447 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1448 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2fa522be 1449 /* Set output pins 0x14-0x17 */
05acb863
TI
1450 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1451 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1452 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1453 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2fa522be 1454 /* Unmute output pins 0x14-0x17 */
05acb863
TI
1455 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1456 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1457 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1458 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2fa522be 1459 /* Set input pins 0x18-0x1c */
16ded525
TI
1460 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1461 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
05acb863
TI
1462 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1463 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1464 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2fa522be 1465 /* Mute input pins 0x18-0x1b */
05acb863
TI
1466 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1467 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1468 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1469 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
71fe7b82 1470 /* ADC set up */
05acb863 1471 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
71fe7b82 1472 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
05acb863 1473 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
71fe7b82 1474 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
05acb863 1475 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
71fe7b82 1476 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
05acb863
TI
1477 /* Analog input/passthru */
1478 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1479 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1480 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1481 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1482 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2fa522be
TI
1483 { }
1484};
1485#endif
1486
1da177e4
LT
1487/*
1488 */
1489
1490static struct hda_board_config alc880_cfg_tbl[] = {
1491 /* Back 3 jack, front 2 jack */
1492 { .modelname = "3stack", .config = ALC880_3ST },
7291548d
TI
1493 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe200, .config = ALC880_3ST },
1494 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe201, .config = ALC880_3ST },
1495 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe202, .config = ALC880_3ST },
1496 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe203, .config = ALC880_3ST },
1497 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe204, .config = ALC880_3ST },
1498 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe205, .config = ALC880_3ST },
1499 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe206, .config = ALC880_3ST },
1500 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe207, .config = ALC880_3ST },
1501 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe208, .config = ALC880_3ST },
1502 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe209, .config = ALC880_3ST },
1503 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20a, .config = ALC880_3ST },
1504 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20b, .config = ALC880_3ST },
1505 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20c, .config = ALC880_3ST },
1506 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20d, .config = ALC880_3ST },
1507 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20e, .config = ALC880_3ST },
1508 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20f, .config = ALC880_3ST },
1509 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe210, .config = ALC880_3ST },
1510 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe211, .config = ALC880_3ST },
1511 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe214, .config = ALC880_3ST },
1512 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe302, .config = ALC880_3ST },
1513 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe303, .config = ALC880_3ST },
1514 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe304, .config = ALC880_3ST },
1515 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe306, .config = ALC880_3ST },
1516 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe307, .config = ALC880_3ST },
1517 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe404, .config = ALC880_3ST },
1518 { .pci_subvendor = 0x8086, .pci_subdevice = 0xa101, .config = ALC880_3ST },
1519 { .pci_subvendor = 0x107b, .pci_subdevice = 0x3031, .config = ALC880_3ST },
1520 { .pci_subvendor = 0x107b, .pci_subdevice = 0x4036, .config = ALC880_3ST },
1521 { .pci_subvendor = 0x107b, .pci_subdevice = 0x4037, .config = ALC880_3ST },
1522 { .pci_subvendor = 0x107b, .pci_subdevice = 0x4038, .config = ALC880_3ST },
1523 { .pci_subvendor = 0x107b, .pci_subdevice = 0x4040, .config = ALC880_3ST },
1524 { .pci_subvendor = 0x107b, .pci_subdevice = 0x4041, .config = ALC880_3ST },
1da177e4
LT
1525
1526 /* Back 3 jack, front 2 jack (Internal add Aux-In) */
7291548d 1527 { .pci_subvendor = 0x1025, .pci_subdevice = 0xe310, .config = ALC880_3ST },
16ded525 1528 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81d6, .config = ALC880_3ST },
1da177e4
LT
1529
1530 /* Back 3 jack plus 1 SPDIF out jack, front 2 jack */
1531 { .modelname = "3stack-digout", .config = ALC880_3ST_DIG },
7291548d 1532 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe308, .config = ALC880_3ST_DIG },
5a47fe3c 1533 { .pci_subvendor = 0x1025, .pci_subdevice = 0x0070, .config = ALC880_3ST_DIG },
1da177e4
LT
1534
1535 /* Back 3 jack plus 1 SPDIF out jack, front 2 jack (Internal add Aux-In)*/
7291548d
TI
1536 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe305, .config = ALC880_3ST_DIG },
1537 { .pci_subvendor = 0x8086, .pci_subdevice = 0xd402, .config = ALC880_3ST_DIG },
1538 { .pci_subvendor = 0x1025, .pci_subdevice = 0xe309, .config = ALC880_3ST_DIG },
1da177e4
LT
1539
1540 /* Back 5 jack, front 2 jack */
1541 { .modelname = "5stack", .config = ALC880_5ST },
7291548d
TI
1542 { .pci_subvendor = 0x107b, .pci_subdevice = 0x3033, .config = ALC880_5ST },
1543 { .pci_subvendor = 0x107b, .pci_subdevice = 0x4039, .config = ALC880_5ST },
1544 { .pci_subvendor = 0x107b, .pci_subdevice = 0x3032, .config = ALC880_5ST },
1545 { .pci_subvendor = 0x103c, .pci_subdevice = 0x2a09, .config = ALC880_5ST },
16ded525 1546 { .pci_subvendor = 0x1043, .pci_subdevice = 0x814e, .config = ALC880_5ST },
1da177e4
LT
1547
1548 /* Back 5 jack plus 1 SPDIF out jack, front 2 jack */
1549 { .modelname = "5stack-digout", .config = ALC880_5ST_DIG },
7291548d
TI
1550 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe224, .config = ALC880_5ST_DIG },
1551 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe400, .config = ALC880_5ST_DIG },
1552 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe401, .config = ALC880_5ST_DIG },
1553 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe402, .config = ALC880_5ST_DIG },
1554 { .pci_subvendor = 0x8086, .pci_subdevice = 0xd400, .config = ALC880_5ST_DIG },
1555 { .pci_subvendor = 0x8086, .pci_subdevice = 0xd401, .config = ALC880_5ST_DIG },
1556 { .pci_subvendor = 0x8086, .pci_subdevice = 0xa100, .config = ALC880_5ST_DIG },
1557 { .pci_subvendor = 0x1565, .pci_subdevice = 0x8202, .config = ALC880_5ST_DIG },
16ded525 1558 { .pci_subvendor = 0x1019, .pci_subdevice = 0xa880, .config = ALC880_5ST_DIG },
7a318a70 1559 /* { .pci_subvendor = 0x1019, .pci_subdevice = 0xa884, .config = ALC880_5ST_DIG }, */ /* conflict with 6stack */
16ded525 1560 { .pci_subvendor = 0x1695, .pci_subdevice = 0x400d, .config = ALC880_5ST_DIG },
b0af0de5
TI
1561 /* note subvendor = 0 below */
1562 /* { .pci_subvendor = 0x0000, .pci_subdevice = 0x8086, .config = ALC880_5ST_DIG }, */
1da177e4
LT
1563
1564 { .modelname = "w810", .config = ALC880_W810 },
7291548d 1565 { .pci_subvendor = 0x161f, .pci_subdevice = 0x203d, .config = ALC880_W810 },
1da177e4 1566
dfc0ff62 1567 { .modelname = "z71v", .config = ALC880_Z71V },
7291548d 1568 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1964, .config = ALC880_Z71V },
dfc0ff62 1569
b6482d48 1570 { .modelname = "6stack", .config = ALC880_6ST },
7a318a70 1571 { .pci_subvendor = 0x1019, .pci_subdevice = 0xa884, .config = ALC880_6ST }, /* Acer APFV */
b6482d48
TI
1572
1573 { .modelname = "6stack-digout", .config = ALC880_6ST_DIG },
16ded525
TI
1574 { .pci_subvendor = 0x2668, .pci_subdevice = 0x8086, .config = ALC880_6ST_DIG },
1575 { .pci_subvendor = 0x8086, .pci_subdevice = 0x2668, .config = ALC880_6ST_DIG },
1576 { .pci_subvendor = 0x1462, .pci_subdevice = 0x1150, .config = ALC880_6ST_DIG },
1577 { .pci_subvendor = 0xe803, .pci_subdevice = 0x1019, .config = ALC880_6ST_DIG },
1578
e9edcee0 1579 { .modelname = "asus", .config = ALC880_ASUS },
16ded525
TI
1580 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1964, .config = ALC880_ASUS_DIG },
1581 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1973, .config = ALC880_ASUS_DIG },
1582 { .pci_subvendor = 0x1043, .pci_subdevice = 0x19b3, .config = ALC880_ASUS_DIG },
1583 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1113, .config = ALC880_ASUS_DIG },
1584 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1993, .config = ALC880_ASUS },
1585 { .pci_subvendor = 0x1043, .pci_subdevice = 0x10c3, .config = ALC880_ASUS_DIG },
1586 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1133, .config = ALC880_ASUS },
1587 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1123, .config = ALC880_ASUS_DIG },
1588 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1143, .config = ALC880_ASUS },
1589 { .pci_subvendor = 0x1043, .pci_subdevice = 0x10b3, .config = ALC880_ASUS_W1V },
1590
1591 { .modelname = "uniwill", .config = ALC880_UNIWILL_DIG },
1592 { .pci_subvendor = 0x1584, .pci_subdevice = 0x9050, .config = ALC880_UNIWILL_DIG },
1593
1594 { .modelname = "F1734", .config = ALC880_F1734 },
1595 { .pci_subvendor = 0x1734, .pci_subdevice = 0x107c, .config = ALC880_F1734 },
1596
2fa522be
TI
1597#ifdef CONFIG_SND_DEBUG
1598 { .modelname = "test", .config = ALC880_TEST },
1599#endif
1600
1da177e4
LT
1601 {}
1602};
1603
16ded525
TI
1604/*
1605 * configuration template - to be copied to the spec instance
1606 */
1607struct alc_config_preset {
e9edcee0
TI
1608 snd_kcontrol_new_t *mixers[4];
1609 const struct hda_verb *init_verbs[4];
16ded525
TI
1610 unsigned int num_dacs;
1611 hda_nid_t *dac_nids;
1612 hda_nid_t dig_out_nid; /* optional */
1613 hda_nid_t hp_nid; /* optional */
1614 unsigned int num_adc_nids;
1615 hda_nid_t *adc_nids;
1616 unsigned int num_channel_mode;
1617 const struct alc_channel_mode *channel_mode;
1618 const struct hda_input_mux *input_mux;
1619};
1620
1621static struct alc_config_preset alc880_presets[] = {
1622 [ALC880_3ST] = {
e9edcee0
TI
1623 .mixers = { alc880_three_stack_mixer },
1624 .init_verbs = { alc880_volume_init_verbs, alc880_pin_3stack_init_verbs },
16ded525 1625 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
16ded525 1626 .dac_nids = alc880_dac_nids,
16ded525
TI
1627 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
1628 .channel_mode = alc880_threestack_modes,
1629 .input_mux = &alc880_capture_source,
1630 },
1631 [ALC880_3ST_DIG] = {
e9edcee0
TI
1632 .mixers = { alc880_three_stack_mixer },
1633 .init_verbs = { alc880_volume_init_verbs, alc880_pin_3stack_init_verbs },
16ded525 1634 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
16ded525
TI
1635 .dac_nids = alc880_dac_nids,
1636 .dig_out_nid = ALC880_DIGOUT_NID,
16ded525
TI
1637 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
1638 .channel_mode = alc880_threestack_modes,
1639 .input_mux = &alc880_capture_source,
1640 },
1641 [ALC880_5ST] = {
e9edcee0
TI
1642 .mixers = { alc880_three_stack_mixer, alc880_five_stack_mixer},
1643 .init_verbs = { alc880_volume_init_verbs, alc880_pin_5stack_init_verbs },
16ded525
TI
1644 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
1645 .dac_nids = alc880_dac_nids,
16ded525
TI
1646 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
1647 .channel_mode = alc880_fivestack_modes,
1648 .input_mux = &alc880_capture_source,
1649 },
1650 [ALC880_5ST_DIG] = {
e9edcee0
TI
1651 .mixers = { alc880_three_stack_mixer, alc880_five_stack_mixer },
1652 .init_verbs = { alc880_volume_init_verbs, alc880_pin_5stack_init_verbs },
16ded525
TI
1653 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
1654 .dac_nids = alc880_dac_nids,
1655 .dig_out_nid = ALC880_DIGOUT_NID,
16ded525
TI
1656 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
1657 .channel_mode = alc880_fivestack_modes,
1658 .input_mux = &alc880_capture_source,
1659 },
b6482d48
TI
1660 [ALC880_6ST] = {
1661 .mixers = { alc880_six_stack_mixer },
1662 .init_verbs = { alc880_volume_init_verbs, alc880_pin_6stack_init_verbs },
1663 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
1664 .dac_nids = alc880_6st_dac_nids,
1665 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
1666 .channel_mode = alc880_sixstack_modes,
1667 .input_mux = &alc880_6stack_capture_source,
1668 },
16ded525 1669 [ALC880_6ST_DIG] = {
e9edcee0
TI
1670 .mixers = { alc880_six_stack_mixer },
1671 .init_verbs = { alc880_volume_init_verbs, alc880_pin_6stack_init_verbs },
16ded525
TI
1672 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
1673 .dac_nids = alc880_6st_dac_nids,
1674 .dig_out_nid = ALC880_DIGOUT_NID,
16ded525
TI
1675 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
1676 .channel_mode = alc880_sixstack_modes,
1677 .input_mux = &alc880_6stack_capture_source,
1678 },
1679 [ALC880_W810] = {
e9edcee0 1680 .mixers = { alc880_w810_base_mixer },
b0af0de5
TI
1681 .init_verbs = { alc880_volume_init_verbs, alc880_pin_w810_init_verbs,
1682 alc880_gpio2_init_verbs },
16ded525
TI
1683 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
1684 .dac_nids = alc880_w810_dac_nids,
1685 .dig_out_nid = ALC880_DIGOUT_NID,
16ded525
TI
1686 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
1687 .channel_mode = alc880_w810_modes,
1688 .input_mux = &alc880_capture_source,
1689 },
1690 [ALC880_Z71V] = {
e9edcee0 1691 .mixers = { alc880_z71v_mixer },
b0af0de5 1692 .init_verbs = { alc880_volume_init_verbs, alc880_pin_z71v_init_verbs },
16ded525
TI
1693 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
1694 .dac_nids = alc880_z71v_dac_nids,
1695 .dig_out_nid = ALC880_DIGOUT_NID,
1696 .hp_nid = 0x03,
e9edcee0
TI
1697 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
1698 .channel_mode = alc880_2_jack_modes,
16ded525
TI
1699 .input_mux = &alc880_capture_source,
1700 },
1701 [ALC880_F1734] = {
e9edcee0
TI
1702 .mixers = { alc880_f1734_mixer },
1703 .init_verbs = { alc880_volume_init_verbs, alc880_pin_f1734_init_verbs },
1704 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
1705 .dac_nids = alc880_f1734_dac_nids,
1706 .hp_nid = 0x02,
1707 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
1708 .channel_mode = alc880_2_jack_modes,
16ded525
TI
1709 .input_mux = &alc880_capture_source,
1710 },
1711 [ALC880_ASUS] = {
e9edcee0
TI
1712 .mixers = { alc880_asus_mixer },
1713 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
1714 alc880_gpio1_init_verbs },
1715 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
1716 .dac_nids = alc880_asus_dac_nids,
1717 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
1718 .channel_mode = alc880_asus_modes,
16ded525
TI
1719 .input_mux = &alc880_capture_source,
1720 },
1721 [ALC880_ASUS_DIG] = {
e9edcee0
TI
1722 .mixers = { alc880_asus_mixer },
1723 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
1724 alc880_gpio1_init_verbs },
1725 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
1726 .dac_nids = alc880_asus_dac_nids,
16ded525 1727 .dig_out_nid = ALC880_DIGOUT_NID,
e9edcee0
TI
1728 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
1729 .channel_mode = alc880_asus_modes,
16ded525
TI
1730 .input_mux = &alc880_capture_source,
1731 },
1732 [ALC880_ASUS_W1V] = {
e9edcee0
TI
1733 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
1734 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
1735 alc880_gpio1_init_verbs },
1736 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
1737 .dac_nids = alc880_asus_dac_nids,
16ded525 1738 .dig_out_nid = ALC880_DIGOUT_NID,
e9edcee0
TI
1739 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
1740 .channel_mode = alc880_asus_modes,
16ded525
TI
1741 .input_mux = &alc880_capture_source,
1742 },
1743 [ALC880_UNIWILL_DIG] = {
3c10a9d9 1744 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
e9edcee0
TI
1745 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs },
1746 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
1747 .dac_nids = alc880_asus_dac_nids,
16ded525 1748 .dig_out_nid = ALC880_DIGOUT_NID,
e9edcee0
TI
1749 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
1750 .channel_mode = alc880_asus_modes,
16ded525
TI
1751 .input_mux = &alc880_capture_source,
1752 },
1753#ifdef CONFIG_SND_DEBUG
1754 [ALC880_TEST] = {
e9edcee0
TI
1755 .mixers = { alc880_test_mixer },
1756 .init_verbs = { alc880_test_init_verbs },
16ded525
TI
1757 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
1758 .dac_nids = alc880_test_dac_nids,
1759 .dig_out_nid = ALC880_DIGOUT_NID,
16ded525
TI
1760 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
1761 .channel_mode = alc880_test_modes,
1762 .input_mux = &alc880_test_capture_source,
1763 },
1764#endif
1765};
1766
e9edcee0
TI
1767/*
1768 * Automatic parse of I/O pins from the BIOS configuration
1769 */
1770
1771#define NUM_CONTROL_ALLOC 32
1772#define NUM_VERB_ALLOC 32
1773
1774enum {
1775 ALC_CTL_WIDGET_VOL,
1776 ALC_CTL_WIDGET_MUTE,
1777 ALC_CTL_BIND_MUTE,
1778};
1779static snd_kcontrol_new_t alc880_control_templates[] = {
1780 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1781 HDA_CODEC_MUTE(NULL, 0, 0, 0),
1782 ALC_BIND_MUTE(NULL, 0, 0, 0),
1783};
1784
1785/* add dynamic controls */
1786static int add_control(struct alc_spec *spec, int type, const char *name, unsigned long val)
1787{
1788 snd_kcontrol_new_t *knew;
1789
1790 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1791 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1792
1793 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1794 if (! knew)
1795 return -ENOMEM;
1796 if (spec->kctl_alloc) {
1797 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1798 kfree(spec->kctl_alloc);
1799 }
1800 spec->kctl_alloc = knew;
1801 spec->num_kctl_alloc = num;
1802 }
1803
1804 knew = &spec->kctl_alloc[spec->num_kctl_used];
1805 *knew = alc880_control_templates[type];
543537bd 1806 knew->name = kstrdup(name, GFP_KERNEL);
e9edcee0
TI
1807 if (! knew->name)
1808 return -ENOMEM;
1809 knew->private_value = val;
1810 spec->num_kctl_used++;
1811 return 0;
1812}
1813
1814#define alc880_is_fixed_pin(nid) ((nid) >= 0x14 && (nid) <= 0x17)
1815#define alc880_fixed_pin_idx(nid) ((nid) - 0x14)
1816#define alc880_is_multi_pin(nid) ((nid) >= 0x18)
1817#define alc880_multi_pin_idx(nid) ((nid) - 0x18)
1818#define alc880_is_input_pin(nid) ((nid) >= 0x18)
1819#define alc880_input_pin_idx(nid) ((nid) - 0x18)
1820#define alc880_idx_to_dac(nid) ((nid) + 0x02)
1821#define alc880_dac_to_idx(nid) ((nid) - 0x02)
1822#define alc880_idx_to_mixer(nid) ((nid) + 0x0c)
1823#define alc880_idx_to_selector(nid) ((nid) + 0x10)
1824#define ALC880_PIN_CD_NID 0x1c
1825
1826/* fill in the dac_nids table from the parsed pin configuration */
1827static int alc880_auto_fill_dac_nids(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
1828{
1829 hda_nid_t nid;
1830 int assigned[4];
1831 int i, j;
1832
1833 memset(assigned, 0, sizeof(assigned));
b0af0de5 1834 spec->multiout.dac_nids = spec->private_dac_nids;
e9edcee0
TI
1835
1836 /* check the pins hardwired to audio widget */
1837 for (i = 0; i < cfg->line_outs; i++) {
1838 nid = cfg->line_out_pins[i];
1839 if (alc880_is_fixed_pin(nid)) {
1840 int idx = alc880_fixed_pin_idx(nid);
1841 spec->multiout.dac_nids[i] = alc880_dac_to_idx(idx);
1842 assigned[idx] = 1;
1843 }
1844 }
1845 /* left pins can be connect to any audio widget */
1846 for (i = 0; i < cfg->line_outs; i++) {
1847 nid = cfg->line_out_pins[i];
1848 if (alc880_is_fixed_pin(nid))
1849 continue;
1850 /* search for an empty channel */
1851 for (j = 0; j < cfg->line_outs; j++) {
1852 if (! assigned[j]) {
1853 spec->multiout.dac_nids[i] = alc880_idx_to_dac(j);
1854 assigned[j] = 1;
1855 break;
1856 }
1857 }
1858 }
1859 spec->multiout.num_dacs = cfg->line_outs;
1860 return 0;
1861}
1862
1863/* add playback controls from the parsed DAC table */
1864static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
1865{
1866 char name[32];
1867 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
1868 hda_nid_t nid;
1869 int i, err;
1870
1871 for (i = 0; i < cfg->line_outs; i++) {
1872 if (! spec->multiout.dac_nids[i])
1873 continue;
1874 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
1875 if (i == 2) {
1876 /* Center/LFE */
1877 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Center Playback Volume",
1878 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
1879 return err;
1880 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "LFE Playback Volume",
1881 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
1882 return err;
1883 if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "Center Playback Switch",
1884 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT))) < 0)
1885 return err;
1886 if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "LFE Playback Switch",
1887 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT))) < 0)
1888 return err;
1889 } else {
1890 sprintf(name, "%s Playback Volume", chname[i]);
1891 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
1892 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1893 return err;
1894 sprintf(name, "%s Playback Switch", chname[i]);
1895 if ((err = add_control(spec, ALC_CTL_BIND_MUTE, name,
1896 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
1897 return err;
1898 }
1899 }
1900
1901 return 0;
1902}
1903
1904/* add playback controls for HP output */
1905static int alc880_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
1906{
1907 hda_nid_t nid;
1908 int err;
1909
1910 if (! pin)
1911 return 0;
1912
1913 if (alc880_is_fixed_pin(pin)) {
1914 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
1915 if (! spec->multiout.dac_nids[0]) {
1916 /* use this as the primary output */
1917 spec->multiout.dac_nids[0] = nid;
1918 if (! spec->multiout.num_dacs)
1919 spec->multiout.num_dacs = 1;
1920 } else
1921 /* specify the DAC as the extra HP output */
1922 spec->multiout.hp_nid = nid;
1923 /* control HP volume/switch on the output mixer amp */
1924 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
1925 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Headphone Playback Volume",
1926 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1927 return err;
1928 if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "Headphone Playback Switch",
1929 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
1930 return err;
1931 } else if (alc880_is_multi_pin(pin)) {
1932 /* set manual connection */
1933 if (! spec->multiout.dac_nids[0]) {
1934 /* use this as the primary output */
1935 spec->multiout.dac_nids[0] = alc880_idx_to_dac(alc880_multi_pin_idx(pin));
1936 if (! spec->multiout.num_dacs)
1937 spec->multiout.num_dacs = 1;
1938 }
1939 /* we have only a switch on HP-out PIN */
1940 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
1941 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT))) < 0)
1942 return err;
1943 }
1944 return 0;
1945}
1946
1947/* create input playback/capture controls for the given pin */
1948static int new_analog_input(struct alc_spec *spec, hda_nid_t pin, const char *ctlname)
1949{
1950 char name[32];
1951 int err, idx;
1952
1953 sprintf(name, "%s Playback Volume", ctlname);
1954 idx = alc880_input_pin_idx(pin);
1955 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
1956 HDA_COMPOSE_AMP_VAL(0x0b, 3, idx, HDA_INPUT))) < 0)
1957 return err;
1958 sprintf(name, "%s Playback Switch", ctlname);
1959 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
1960 HDA_COMPOSE_AMP_VAL(0x0b, 3, idx, HDA_INPUT))) < 0)
1961 return err;
1962 return 0;
1963}
1964
1965/* create playback/capture controls for input pins */
1966static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
1967{
1968 static char *labels[AUTO_PIN_LAST] = {
1969 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux"
1970 };
1971 struct hda_input_mux *imux = &spec->private_imux;
1972 int i, err;
1973
1974 for (i = 0; i < AUTO_PIN_LAST; i++) {
1975 if (alc880_is_input_pin(cfg->input_pins[i])) {
1976 err = new_analog_input(spec, cfg->input_pins[i], labels[i]);
1977 if (err < 0)
1978 return err;
1979 imux->items[imux->num_items].label = labels[i];
1980 imux->items[imux->num_items].index = alc880_input_pin_idx(cfg->input_pins[i]);
1981 imux->num_items++;
1982 }
1983 }
1984 return 0;
1985}
1986
1987static void alc880_auto_set_output_and_unmute(struct hda_codec *codec, hda_nid_t nid, int pin_type,
1988 int dac_idx)
1989{
1990 /* set as output */
1991 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
1992 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
1993 /* need the manual connection? */
1994 if (alc880_is_multi_pin(nid)) {
1995 struct alc_spec *spec = codec->spec;
1996 int idx = alc880_multi_pin_idx(nid);
1997 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
1998 AC_VERB_SET_CONNECT_SEL,
1999 alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
2000 }
2001}
2002
2003static void alc880_auto_init_multi_out(struct hda_codec *codec)
2004{
2005 struct alc_spec *spec = codec->spec;
2006 int i;
2007
2008 for (i = 0; i < spec->autocfg.line_outs; i++) {
2009 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2010 alc880_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2011 }
2012}
2013
2014static void alc880_auto_init_hp_out(struct hda_codec *codec)
2015{
2016 struct alc_spec *spec = codec->spec;
2017 hda_nid_t pin;
2018
2019 pin = spec->autocfg.hp_pin;
2020 if (pin) /* connect to front */
2021 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2022}
2023
2024static void alc880_auto_init_analog_input(struct hda_codec *codec)
2025{
2026 struct alc_spec *spec = codec->spec;
2027 int i;
2028
2029 for (i = 0; i < AUTO_PIN_LAST; i++) {
2030 hda_nid_t nid = spec->autocfg.input_pins[i];
2031 if (alc880_is_input_pin(nid)) {
2032 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2033 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2034 if (nid != ALC880_PIN_CD_NID)
2035 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2036 AMP_OUT_MUTE);
2037 }
2038 }
2039}
2040
2041/* parse the BIOS configuration and set up the alc_spec */
2042/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2043static int alc880_parse_auto_config(struct hda_codec *codec)
2044{
2045 struct alc_spec *spec = codec->spec;
2046 int err;
2047
2048 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg)) < 0)
2049 return err;
2050 if ((err = alc880_auto_fill_dac_nids(spec, &spec->autocfg)) < 0)
2051 return err;
2052 if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
2053 return 0; /* can't find valid BIOS pin config */
2054 if ((err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2055 (err = alc880_auto_create_hp_ctls(spec, spec->autocfg.hp_pin)) < 0 ||
2056 (err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2057 return err;
2058
2059 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2060
2061 if (spec->autocfg.dig_out_pin)
2062 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
2063 if (spec->autocfg.dig_in_pin)
2064 spec->dig_in_nid = ALC880_DIGIN_NID;
2065
2066 if (spec->kctl_alloc)
2067 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2068
2069 spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
2070
2071 spec->input_mux = &spec->private_imux;
2072
2073 return 1;
2074}
2075
2076/* init callback for auto-configuration model -- overriding the default init */
2077static int alc880_auto_init(struct hda_codec *codec)
2078{
2079 alc_init(codec);
2080 alc880_auto_init_multi_out(codec);
2081 alc880_auto_init_hp_out(codec);
2082 alc880_auto_init_analog_input(codec);
2083 return 0;
2084}
2085
2086/*
2087 * OK, here we have finally the patch for ALC880
2088 */
2089
1da177e4
LT
2090static int patch_alc880(struct hda_codec *codec)
2091{
2092 struct alc_spec *spec;
2093 int board_config;
e9edcee0 2094 int i, err;
1da177e4
LT
2095
2096 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
2097 if (spec == NULL)
2098 return -ENOMEM;
2099
41e41f1f 2100 init_MUTEX(&spec->bind_mutex);
1da177e4
LT
2101 codec->spec = spec;
2102
2103 board_config = snd_hda_check_board_config(codec, alc880_cfg_tbl);
16ded525 2104 if (board_config < 0 || board_config >= ALC880_MODEL_LAST) {
e9edcee0
TI
2105 printk(KERN_INFO "hda_codec: Unknown model for ALC880, trying auto-probe from BIOS...\n");
2106 board_config = ALC880_AUTO;
1da177e4 2107 }
1da177e4 2108
e9edcee0
TI
2109 if (board_config == ALC880_AUTO) {
2110 /* automatic parse from the BIOS config */
2111 err = alc880_parse_auto_config(codec);
2112 if (err < 0) {
2113 alc_free(codec);
2114 return err;
2115 } else if (! err) {
2116 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 3-stack mode...\n");
2117 board_config = ALC880_3ST;
2118 }
1da177e4
LT
2119 }
2120
e9edcee0
TI
2121 if (board_config != ALC880_AUTO) {
2122 /* set up from the preset table */
2123 const struct alc_config_preset *preset;
2124
2125 preset = &alc880_presets[board_config];
2126
2127 for (i = 0; preset->mixers[i]; i++) {
2128 snd_assert(spec->num_mixers < ARRAY_SIZE(spec->mixers), break);
2129 spec->mixers[spec->num_mixers++] = preset->mixers[i];
2130 }
2131 for (i = 0; preset->init_verbs[i]; i++) {
2132 snd_assert(spec->num_init_verbs < ARRAY_SIZE(spec->init_verbs), break);
2133 spec->init_verbs[spec->num_init_verbs++] = preset->init_verbs[i];
2134 }
2135
2136 spec->channel_mode = preset->channel_mode;
2137 spec->num_channel_mode = preset->num_channel_mode;
2138
2139 spec->multiout.max_channels = spec->channel_mode[0].channels;
2140
2141 spec->multiout.num_dacs = preset->num_dacs;
2142 spec->multiout.dac_nids = preset->dac_nids;
2143 spec->multiout.dig_out_nid = preset->dig_out_nid;
2144 spec->multiout.hp_nid = preset->hp_nid;
2145
2146 spec->input_mux = preset->input_mux;
2147
2148 spec->num_adc_nids = preset->num_adc_nids;
2149 spec->adc_nids = preset->adc_nids;
2150 }
1da177e4
LT
2151
2152 spec->stream_name_analog = "ALC880 Analog";
2153 spec->stream_analog_playback = &alc880_pcm_analog_playback;
2154 spec->stream_analog_capture = &alc880_pcm_analog_capture;
2155
2156 spec->stream_name_digital = "ALC880 Digital";
2157 spec->stream_digital_playback = &alc880_pcm_digital_playback;
2158 spec->stream_digital_capture = &alc880_pcm_digital_capture;
2159
e9edcee0
TI
2160 if (! spec->adc_nids && spec->input_mux) {
2161 /* check whether NID 0x07 is valid */
2162 unsigned int wcap = snd_hda_param_read(codec, alc880_adc_nids[0],
2163 AC_PAR_AUDIO_WIDGET_CAP);
2164 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
2165 if (wcap != AC_WID_AUD_IN) {
2166 spec->adc_nids = alc880_adc_nids_alt;
2167 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
2168 spec->mixers[spec->num_mixers] = alc880_capture_alt_mixer;
2169 spec->num_mixers++;
2170 } else {
2171 spec->adc_nids = alc880_adc_nids;
2172 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
2173 spec->mixers[spec->num_mixers] = alc880_capture_mixer;
2174 spec->num_mixers++;
2175 }
2176 }
1da177e4
LT
2177
2178 codec->patch_ops = alc_patch_ops;
e9edcee0
TI
2179 if (board_config == ALC880_AUTO)
2180 codec->patch_ops.init = alc880_auto_init;
1da177e4
LT
2181
2182 return 0;
2183}
2184
e9edcee0 2185
1da177e4
LT
2186/*
2187 * ALC260 support
2188 */
2189
e9edcee0
TI
2190static hda_nid_t alc260_dac_nids[1] = {
2191 /* front */
2192 0x02,
2193};
2194
2195static hda_nid_t alc260_adc_nids[1] = {
2196 /* ADC0 */
2197 0x04,
2198};
2199
2200static hda_nid_t alc260_hp_adc_nids[1] = {
2201 /* ADC1 */
2202 0x05,
2203};
2204
2205#define ALC260_DIGOUT_NID 0x03
2206#define ALC260_DIGIN_NID 0x06
2207
2208static struct hda_input_mux alc260_capture_source = {
2209 .num_items = 4,
2210 .items = {
2211 { "Mic", 0x0 },
2212 { "Front Mic", 0x1 },
2213 { "Line", 0x2 },
2214 { "CD", 0x4 },
2215 },
2216};
2217
1da177e4
LT
2218/*
2219 * This is just place-holder, so there's something for alc_build_pcms to look
2220 * at when it calculates the maximum number of channels. ALC260 has no mixer
2221 * element which allows changing the channel mode, so the verb list is
2222 * never used.
2223 */
2224static struct alc_channel_mode alc260_modes[1] = {
2225 { 2, NULL },
2226};
2227
e9edcee0 2228static snd_kcontrol_new_t alc260_base_mixer[] = {
05acb863
TI
2229 HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
2230 ALC_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
1da177e4
LT
2231 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
2232 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
2233 HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
2234 HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
2235 HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
2236 HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
2237 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
2238 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
2239 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
2240 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
05acb863
TI
2241 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
2242 ALC_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
2243 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2244 ALC_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_OUTPUT),
1da177e4
LT
2245 HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
2246 HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
2247 {
2248 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2249 .name = "Capture Source",
2250 .info = alc_mux_enum_info,
2251 .get = alc_mux_enum_get,
2252 .put = alc_mux_enum_put,
2253 },
2254 { } /* end */
2255};
2256
e9edcee0 2257static snd_kcontrol_new_t alc260_hp_mixer[] = {
16ded525
TI
2258 HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
2259 ALC_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
2260 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
2261 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
2262 HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
2263 HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
2264 HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
2265 HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
2266 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
2267 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
2268 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
2269 ALC_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
2270 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2271 ALC_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_OUTPUT),
2272 HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
2273 HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
2274 {
2275 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2276 .name = "Capture Source",
2277 .info = alc_mux_enum_info,
2278 .get = alc_mux_enum_get,
2279 .put = alc_mux_enum_put,
2280 },
2281 { } /* end */
2282};
2283
1da177e4
LT
2284static struct hda_verb alc260_init_verbs[] = {
2285 /* Line In pin widget for input */
05acb863 2286 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1da177e4 2287 /* CD pin widget for input */
05acb863 2288 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1da177e4 2289 /* Mic1 (rear panel) pin widget for input and vref at 80% */
16ded525 2290 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1da177e4 2291 /* Mic2 (front panel) pin widget for input and vref at 80% */
16ded525 2292 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1da177e4 2293 /* LINE-2 is used for line-out in rear */
05acb863 2294 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1da177e4
LT
2295 /* select line-out */
2296 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2297 /* LINE-OUT pin */
05acb863 2298 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1da177e4 2299 /* enable HP */
05acb863 2300 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1da177e4 2301 /* enable Mono */
05acb863
TI
2302 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2303 /* mute capture amp left and right */
16ded525 2304 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1da177e4
LT
2305 /* set connection select to line in (default select for this ADC) */
2306 {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
16ded525
TI
2307 /* mute capture amp left and right */
2308 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2309 /* set connection select to line in (default select for this ADC) */
2310 {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
05acb863
TI
2311 /* set vol=0 Line-Out mixer amp left and right */
2312 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2313 /* unmute pin widget amp left and right (no gain on this amp) */
2314 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2315 /* set vol=0 HP mixer amp left and right */
2316 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2317 /* unmute pin widget amp left and right (no gain on this amp) */
2318 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2319 /* set vol=0 Mono mixer amp left and right */
2320 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2321 /* unmute pin widget amp left and right (no gain on this amp) */
2322 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2323 /* unmute LINE-2 out pin */
2324 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1da177e4 2325 /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 & Line In 2 = 0x03 */
05acb863 2326 /* mute CD */
16ded525 2327 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
05acb863 2328 /* mute Line In */
16ded525 2329 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
05acb863 2330 /* mute Mic */
16ded525 2331 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1da177e4 2332 /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
05acb863
TI
2333 /* mute Front out path */
2334 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2335 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2336 /* mute Headphone out path */
2337 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2338 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2339 /* mute Mono out path */
2340 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2341 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1da177e4
LT
2342 { }
2343};
2344
2345static struct hda_pcm_stream alc260_pcm_analog_playback = {
2346 .substreams = 1,
2347 .channels_min = 2,
2348 .channels_max = 2,
1da177e4
LT
2349};
2350
2351static struct hda_pcm_stream alc260_pcm_analog_capture = {
2352 .substreams = 1,
2353 .channels_min = 2,
2354 .channels_max = 2,
1da177e4
LT
2355};
2356
16ded525
TI
2357static struct hda_board_config alc260_cfg_tbl[] = {
2358 { .modelname = "hp", .config = ALC260_HP },
2359 { .pci_subvendor = 0x103c, .config = ALC260_HP },
2360 {}
2361};
2362
1da177e4
LT
2363static int patch_alc260(struct hda_codec *codec)
2364{
2365 struct alc_spec *spec;
16ded525 2366 int board_config;
1da177e4
LT
2367
2368 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
2369 if (spec == NULL)
2370 return -ENOMEM;
2371
41e41f1f 2372 init_MUTEX(&spec->bind_mutex);
1da177e4
LT
2373 codec->spec = spec;
2374
16ded525
TI
2375 board_config = snd_hda_check_board_config(codec, alc260_cfg_tbl);
2376 if (board_config < 0 || board_config >= ALC260_MODEL_LAST) {
2377 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260\n");
2378 board_config = ALC260_BASIC;
2379 }
2380
2381 switch (board_config) {
2382 case ALC260_HP:
e9edcee0 2383 spec->mixers[spec->num_mixers] = alc260_hp_mixer;
16ded525
TI
2384 spec->num_mixers++;
2385 break;
2386 default:
2387 spec->mixers[spec->num_mixers] = alc260_base_mixer;
2388 spec->num_mixers++;
2389 break;
2390 }
1da177e4 2391
e9edcee0
TI
2392 spec->init_verbs[0] = alc260_init_verbs;
2393 spec->num_init_verbs = 1;
2394
1da177e4
LT
2395 spec->channel_mode = alc260_modes;
2396 spec->num_channel_mode = ARRAY_SIZE(alc260_modes);
2397
2398 spec->stream_name_analog = "ALC260 Analog";
2399 spec->stream_analog_playback = &alc260_pcm_analog_playback;
2400 spec->stream_analog_capture = &alc260_pcm_analog_capture;
2401
2402 spec->multiout.max_channels = spec->channel_mode[0].channels;
2403 spec->multiout.num_dacs = ARRAY_SIZE(alc260_dac_nids);
2404 spec->multiout.dac_nids = alc260_dac_nids;
2405
2406 spec->input_mux = &alc260_capture_source;
16ded525
TI
2407 switch (board_config) {
2408 case ALC260_HP:
16ded525
TI
2409 spec->num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids);
2410 spec->adc_nids = alc260_hp_adc_nids;
2411 break;
2412 default:
2413 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
2414 spec->adc_nids = alc260_adc_nids;
2415 break;
2416 }
1da177e4
LT
2417
2418 codec->patch_ops = alc_patch_ops;
2419
2420 return 0;
2421}
2422
e9edcee0 2423
1da177e4
LT
2424/*
2425 * ALC882 support
2426 *
2427 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
2428 * configuration. Each pin widget can choose any input DACs and a mixer.
2429 * Each ADC is connected from a mixer of all inputs. This makes possible
2430 * 6-channel independent captures.
2431 *
2432 * In addition, an independent DAC for the multi-playback (not used in this
2433 * driver yet).
2434 */
2435
2436static struct alc_channel_mode alc882_ch_modes[1] = {
2437 { 8, NULL }
2438};
2439
2440static hda_nid_t alc882_dac_nids[4] = {
2441 /* front, rear, clfe, rear_surr */
2442 0x02, 0x03, 0x04, 0x05
2443};
2444
2445static hda_nid_t alc882_adc_nids[3] = {
2446 /* ADC0-2 */
2447 0x07, 0x08, 0x09,
2448};
2449
2450/* input MUX */
2451/* FIXME: should be a matrix-type input source selection */
2452
2453static struct hda_input_mux alc882_capture_source = {
2454 .num_items = 4,
2455 .items = {
2456 { "Mic", 0x0 },
2457 { "Front Mic", 0x1 },
2458 { "Line", 0x2 },
2459 { "CD", 0x4 },
2460 },
2461};
2462
2463#define alc882_mux_enum_info alc_mux_enum_info
2464#define alc882_mux_enum_get alc_mux_enum_get
2465
2466static int alc882_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
2467{
2468 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2469 struct alc_spec *spec = codec->spec;
2470 const struct hda_input_mux *imux = spec->input_mux;
2471 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2472 static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
2473 hda_nid_t nid = capture_mixers[adc_idx];
2474 unsigned int *cur_val = &spec->cur_mux[adc_idx];
2475 unsigned int i, idx;
2476
2477 idx = ucontrol->value.enumerated.item[0];
2478 if (idx >= imux->num_items)
2479 idx = imux->num_items - 1;
2480 if (*cur_val == idx && ! codec->in_resume)
2481 return 0;
2482 for (i = 0; i < imux->num_items; i++) {
2483 unsigned int v = (i == idx) ? 0x7000 : 0x7080;
2484 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2485 v | (imux->items[i].index << 8));
2486 }
2487 *cur_val = idx;
2488 return 1;
2489}
2490
2491/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
2492 * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
2493 */
2494static snd_kcontrol_new_t alc882_base_mixer[] = {
05acb863
TI
2495 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2496 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2497 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2498 ALC_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2499 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2500 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2501 ALC_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2502 ALC_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_OUTPUT),
2503 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2504 ALC_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1da177e4
LT
2505 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2506 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2507 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2508 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2509 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2510 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2511 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2512 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2513 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2514 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
2515 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
2516 HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
2517 HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
2518 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
2519 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
2520 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
2521 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
2522 {
2523 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2524 /* .name = "Capture Source", */
2525 .name = "Input Source",
2526 .count = 3,
2527 .info = alc882_mux_enum_info,
2528 .get = alc882_mux_enum_get,
2529 .put = alc882_mux_enum_put,
2530 },
2531 { } /* end */
2532};
2533
2534static struct hda_verb alc882_init_verbs[] = {
2535 /* Front mixer: unmute input/output amp left and right (volume = 0) */
05acb863
TI
2536 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2537 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2538 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1da177e4 2539 /* Rear mixer */
05acb863
TI
2540 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2541 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2542 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1da177e4 2543 /* CLFE mixer */
05acb863
TI
2544 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2545 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2546 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1da177e4 2547 /* Side mixer */
05acb863
TI
2548 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2549 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2550 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1da177e4 2551
e9edcee0 2552 /* Front Pin: output 0 (0x0c) */
05acb863 2553 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
05acb863 2554 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1da177e4 2555 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
e9edcee0 2556 /* Rear Pin: output 1 (0x0d) */
05acb863 2557 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
05acb863 2558 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1da177e4 2559 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
e9edcee0 2560 /* CLFE Pin: output 2 (0x0e) */
05acb863 2561 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
05acb863 2562 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1da177e4 2563 {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
e9edcee0 2564 /* Side Pin: output 3 (0x0f) */
05acb863 2565 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
05acb863 2566 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1da177e4 2567 {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
e9edcee0 2568 /* Mic (rear) pin: input vref at 80% */
16ded525 2569 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
e9edcee0
TI
2570 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2571 /* Front Mic pin: input vref at 80% */
16ded525 2572 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
e9edcee0
TI
2573 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2574 /* Line In pin: input */
05acb863 2575 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
e9edcee0
TI
2576 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2577 /* Line-2 In: Headphone output (output 0 - 0x0c) */
2578 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2579 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2580 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1da177e4 2581 /* CD pin widget for input */
05acb863 2582 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1da177e4
LT
2583
2584 /* FIXME: use matrix-type input source selection */
2585 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
2586 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
05acb863
TI
2587 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2588 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2589 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2590 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1da177e4 2591 /* Input mixer2 */
05acb863
TI
2592 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2593 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2594 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2595 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1da177e4 2596 /* Input mixer3 */
05acb863
TI
2597 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2598 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2599 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2600 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2601 /* ADC1: mute amp left and right */
2602 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
71fe7b82 2603 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
05acb863
TI
2604 /* ADC2: mute amp left and right */
2605 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
71fe7b82 2606 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
05acb863
TI
2607 /* ADC3: mute amp left and right */
2608 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
71fe7b82 2609 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1da177e4
LT
2610
2611 { }
2612};
2613
2614static int patch_alc882(struct hda_codec *codec)
2615{
2616 struct alc_spec *spec;
2617
2618 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
2619 if (spec == NULL)
2620 return -ENOMEM;
2621
41e41f1f 2622 init_MUTEX(&spec->bind_mutex);
1da177e4
LT
2623 codec->spec = spec;
2624
2625 spec->mixers[spec->num_mixers] = alc882_base_mixer;
2626 spec->num_mixers++;
2627
2628 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
2629 spec->dig_in_nid = ALC880_DIGIN_NID;
e9edcee0
TI
2630 spec->init_verbs[0] = alc882_init_verbs;
2631 spec->num_init_verbs = 1;
2632
1da177e4
LT
2633 spec->channel_mode = alc882_ch_modes;
2634 spec->num_channel_mode = ARRAY_SIZE(alc882_ch_modes);
2635
2636 spec->stream_name_analog = "ALC882 Analog";
2637 spec->stream_analog_playback = &alc880_pcm_analog_playback;
2638 spec->stream_analog_capture = &alc880_pcm_analog_capture;
2639
2640 spec->stream_name_digital = "ALC882 Digital";
2641 spec->stream_digital_playback = &alc880_pcm_digital_playback;
2642 spec->stream_digital_capture = &alc880_pcm_digital_capture;
2643
2644 spec->multiout.max_channels = spec->channel_mode[0].channels;
2645 spec->multiout.num_dacs = ARRAY_SIZE(alc882_dac_nids);
2646 spec->multiout.dac_nids = alc882_dac_nids;
2647
2648 spec->input_mux = &alc882_capture_source;
2649 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
2650 spec->adc_nids = alc882_adc_nids;
2651
2652 codec->patch_ops = alc_patch_ops;
2653
2654 return 0;
2655}
2656
2657/*
2658 * patch entries
2659 */
2660struct hda_codec_preset snd_hda_preset_realtek[] = {
2661 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
2662 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
2663 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
2664 {} /* terminator */
2665};