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