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