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