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