]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - sound/pci/hda/patch_realtek.c
[ALSA] hda-intel - Fix pci_disable_msi() call
[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,
ae6b813a 54 ALC880_LG,
d681518a 55 ALC880_LG_LW,
e9edcee0
TI
56#ifdef CONFIG_SND_DEBUG
57 ALC880_TEST,
58#endif
df694daa 59 ALC880_AUTO,
16ded525
TI
60 ALC880_MODEL_LAST /* last tag */
61};
62
63/* ALC260 models */
64enum {
65 ALC260_BASIC,
66 ALC260_HP,
df694daa
KY
67 ALC260_HP_3013,
68 ALC260_FUJITSU_S702X,
0bfc90e9 69 ALC260_ACER,
7cf51e48
JW
70#ifdef CONFIG_SND_DEBUG
71 ALC260_TEST,
72#endif
df694daa 73 ALC260_AUTO,
16ded525 74 ALC260_MODEL_LAST /* last tag */
1da177e4
LT
75};
76
df694daa
KY
77/* ALC262 models */
78enum {
79 ALC262_BASIC,
834be88d 80 ALC262_FUJITSU,
9c7f852e 81 ALC262_HP_BPC,
304dcaac 82 ALC262_BENQ_ED8,
df694daa
KY
83 ALC262_AUTO,
84 ALC262_MODEL_LAST /* last tag */
85};
86
87/* ALC861 models */
88enum {
89 ALC861_3ST,
9c7f852e 90 ALC660_3ST,
df694daa
KY
91 ALC861_3ST_DIG,
92 ALC861_6ST_DIG,
22309c3e 93 ALC861_UNIWILL_M31,
df694daa
KY
94 ALC861_AUTO,
95 ALC861_MODEL_LAST,
96};
97
98/* ALC882 models */
99enum {
100 ALC882_3ST_DIG,
101 ALC882_6ST_DIG,
4b146cb0 102 ALC882_ARIMA,
df694daa
KY
103 ALC882_AUTO,
104 ALC882_MODEL_LAST,
105};
106
9c7f852e
TI
107/* ALC883 models */
108enum {
109 ALC883_3ST_2ch_DIG,
110 ALC883_3ST_6ch_DIG,
111 ALC883_3ST_6ch,
112 ALC883_6ST_DIG,
113 ALC888_DEMO_BOARD,
bab282b9 114 ALC883_ACER,
9c7f852e
TI
115 ALC883_AUTO,
116 ALC883_MODEL_LAST,
117};
118
df694daa
KY
119/* for GPIO Poll */
120#define GPIO_MASK 0x03
121
1da177e4
LT
122struct alc_spec {
123 /* codec parameterization */
df694daa 124 struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
1da177e4
LT
125 unsigned int num_mixers;
126
df694daa 127 const struct hda_verb *init_verbs[5]; /* initialization verbs
9c7f852e
TI
128 * don't forget NULL
129 * termination!
e9edcee0
TI
130 */
131 unsigned int num_init_verbs;
1da177e4 132
16ded525 133 char *stream_name_analog; /* analog PCM stream */
1da177e4
LT
134 struct hda_pcm_stream *stream_analog_playback;
135 struct hda_pcm_stream *stream_analog_capture;
136
16ded525 137 char *stream_name_digital; /* digital PCM stream */
1da177e4
LT
138 struct hda_pcm_stream *stream_digital_playback;
139 struct hda_pcm_stream *stream_digital_capture;
140
141 /* playback */
16ded525
TI
142 struct hda_multi_out multiout; /* playback set-up
143 * max_channels, dacs must be set
144 * dig_out_nid and hp_nid are optional
145 */
1da177e4
LT
146
147 /* capture */
148 unsigned int num_adc_nids;
149 hda_nid_t *adc_nids;
16ded525 150 hda_nid_t dig_in_nid; /* digital-in NID; optional */
1da177e4
LT
151
152 /* capture source */
a1e8d2da 153 unsigned int num_mux_defs;
1da177e4
LT
154 const struct hda_input_mux *input_mux;
155 unsigned int cur_mux[3];
156
157 /* channel model */
d2a6d7dc 158 const struct hda_channel_mode *channel_mode;
1da177e4 159 int num_channel_mode;
4e195a7b 160 int need_dac_fix;
1da177e4
LT
161
162 /* PCM information */
4c5186ed 163 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
41e41f1f 164
e9edcee0
TI
165 /* dynamic controls, init_verbs and input_mux */
166 struct auto_pin_cfg autocfg;
167 unsigned int num_kctl_alloc, num_kctl_used;
c8b6bf9b 168 struct snd_kcontrol_new *kctl_alloc;
e9edcee0 169 struct hda_input_mux private_imux;
df694daa 170 hda_nid_t private_dac_nids[5];
834be88d 171
ae6b813a
TI
172 /* hooks */
173 void (*init_hook)(struct hda_codec *codec);
174 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
175
834be88d
TI
176 /* for pin sensing */
177 unsigned int sense_updated: 1;
178 unsigned int jack_present: 1;
df694daa
KY
179};
180
181/*
182 * configuration template - to be copied to the spec instance
183 */
184struct alc_config_preset {
9c7f852e
TI
185 struct snd_kcontrol_new *mixers[5]; /* should be identical size
186 * with spec
187 */
df694daa
KY
188 const struct hda_verb *init_verbs[5];
189 unsigned int num_dacs;
190 hda_nid_t *dac_nids;
191 hda_nid_t dig_out_nid; /* optional */
192 hda_nid_t hp_nid; /* optional */
193 unsigned int num_adc_nids;
194 hda_nid_t *adc_nids;
195 hda_nid_t dig_in_nid;
196 unsigned int num_channel_mode;
197 const struct hda_channel_mode *channel_mode;
4e195a7b 198 int need_dac_fix;
a1e8d2da 199 unsigned int num_mux_defs;
df694daa 200 const struct hda_input_mux *input_mux;
ae6b813a
TI
201 void (*unsol_event)(struct hda_codec *, unsigned int);
202 void (*init_hook)(struct hda_codec *);
1da177e4
LT
203};
204
1da177e4
LT
205
206/*
207 * input MUX handling
208 */
9c7f852e
TI
209static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
210 struct snd_ctl_elem_info *uinfo)
1da177e4
LT
211{
212 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
213 struct alc_spec *spec = codec->spec;
a1e8d2da
JW
214 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
215 if (mux_idx >= spec->num_mux_defs)
216 mux_idx = 0;
217 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
1da177e4
LT
218}
219
9c7f852e
TI
220static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
221 struct snd_ctl_elem_value *ucontrol)
1da177e4
LT
222{
223 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
224 struct alc_spec *spec = codec->spec;
225 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
226
227 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
228 return 0;
229}
230
9c7f852e
TI
231static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
232 struct snd_ctl_elem_value *ucontrol)
1da177e4
LT
233{
234 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
235 struct alc_spec *spec = codec->spec;
236 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
a1e8d2da
JW
237 unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
238 return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
9c7f852e
TI
239 spec->adc_nids[adc_idx],
240 &spec->cur_mux[adc_idx]);
1da177e4
LT
241}
242
e9edcee0 243
1da177e4
LT
244/*
245 * channel mode setting
246 */
9c7f852e
TI
247static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
248 struct snd_ctl_elem_info *uinfo)
1da177e4
LT
249{
250 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
251 struct alc_spec *spec = codec->spec;
d2a6d7dc
TI
252 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
253 spec->num_channel_mode);
1da177e4
LT
254}
255
9c7f852e
TI
256static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_value *ucontrol)
1da177e4
LT
258{
259 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
260 struct alc_spec *spec = codec->spec;
d2a6d7dc 261 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
9c7f852e
TI
262 spec->num_channel_mode,
263 spec->multiout.max_channels);
1da177e4
LT
264}
265
9c7f852e
TI
266static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
267 struct snd_ctl_elem_value *ucontrol)
1da177e4
LT
268{
269 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
270 struct alc_spec *spec = codec->spec;
4e195a7b
TI
271 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
272 spec->num_channel_mode,
273 &spec->multiout.max_channels);
274 if (! err && spec->need_dac_fix)
275 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
276 return err;
1da177e4
LT
277}
278
a9430dd8 279/*
4c5186ed
JW
280 * Control the mode of pin widget settings via the mixer. "pc" is used
281 * instead of "%" to avoid consequences of accidently treating the % as
282 * being part of a format specifier. Maximum allowed length of a value is
283 * 63 characters plus NULL terminator.
7cf51e48
JW
284 *
285 * Note: some retasking pin complexes seem to ignore requests for input
286 * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
287 * are requested. Therefore order this list so that this behaviour will not
288 * cause problems when mixer clients move through the enum sequentially.
a1e8d2da
JW
289 * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
290 * March 2006.
4c5186ed
JW
291 */
292static char *alc_pin_mode_names[] = {
7cf51e48
JW
293 "Mic 50pc bias", "Mic 80pc bias",
294 "Line in", "Line out", "Headphone out",
4c5186ed
JW
295};
296static unsigned char alc_pin_mode_values[] = {
7cf51e48 297 PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
4c5186ed
JW
298};
299/* The control can present all 5 options, or it can limit the options based
a1e8d2da
JW
300 * in the pin being assumed to be exclusively an input or an output pin. In
301 * addition, "input" pins may or may not process the mic bias option
302 * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
303 * accept requests for bias as of chip versions up to March 2006) and/or
304 * wiring in the computer.
a9430dd8 305 */
a1e8d2da
JW
306#define ALC_PIN_DIR_IN 0x00
307#define ALC_PIN_DIR_OUT 0x01
308#define ALC_PIN_DIR_INOUT 0x02
309#define ALC_PIN_DIR_IN_NOMICBIAS 0x03
310#define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
4c5186ed 311
a1e8d2da 312/* Info about the pin modes supported by the different pin direction modes.
4c5186ed
JW
313 * For each direction the minimum and maximum values are given.
314 */
a1e8d2da 315static signed char alc_pin_mode_dir_info[5][2] = {
4c5186ed
JW
316 { 0, 2 }, /* ALC_PIN_DIR_IN */
317 { 3, 4 }, /* ALC_PIN_DIR_OUT */
318 { 0, 4 }, /* ALC_PIN_DIR_INOUT */
a1e8d2da
JW
319 { 2, 2 }, /* ALC_PIN_DIR_IN_NOMICBIAS */
320 { 2, 4 }, /* ALC_PIN_DIR_INOUT_NOMICBIAS */
4c5186ed
JW
321};
322#define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
323#define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
324#define alc_pin_mode_n_items(_dir) \
325 (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
326
9c7f852e
TI
327static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
328 struct snd_ctl_elem_info *uinfo)
a9430dd8 329{
4c5186ed
JW
330 unsigned int item_num = uinfo->value.enumerated.item;
331 unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
332
333 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
a9430dd8 334 uinfo->count = 1;
4c5186ed
JW
335 uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
336
337 if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
338 item_num = alc_pin_mode_min(dir);
339 strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
a9430dd8
JW
340 return 0;
341}
342
9c7f852e
TI
343static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
344 struct snd_ctl_elem_value *ucontrol)
a9430dd8 345{
4c5186ed 346 unsigned int i;
a9430dd8
JW
347 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
348 hda_nid_t nid = kcontrol->private_value & 0xffff;
4c5186ed 349 unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
a9430dd8 350 long *valp = ucontrol->value.integer.value;
9c7f852e
TI
351 unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
352 AC_VERB_GET_PIN_WIDGET_CONTROL,
353 0x00);
a9430dd8 354
4c5186ed
JW
355 /* Find enumerated value for current pinctl setting */
356 i = alc_pin_mode_min(dir);
9c7f852e 357 while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
4c5186ed 358 i++;
9c7f852e 359 *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
a9430dd8
JW
360 return 0;
361}
362
9c7f852e
TI
363static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
364 struct snd_ctl_elem_value *ucontrol)
a9430dd8 365{
4c5186ed 366 signed int change;
a9430dd8
JW
367 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
368 hda_nid_t nid = kcontrol->private_value & 0xffff;
4c5186ed
JW
369 unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
370 long val = *ucontrol->value.integer.value;
9c7f852e
TI
371 unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
372 AC_VERB_GET_PIN_WIDGET_CONTROL,
373 0x00);
a9430dd8 374
9c7f852e 375 if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
4c5186ed
JW
376 val = alc_pin_mode_min(dir);
377
378 change = pinctl != alc_pin_mode_values[val];
cdcd9268
JW
379 if (change) {
380 /* Set pin mode to that requested */
a9430dd8 381 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL,
9c7f852e 382 alc_pin_mode_values[val]);
cdcd9268
JW
383
384 /* Also enable the retasking pin's input/output as required
385 * for the requested pin mode. Enum values of 2 or less are
386 * input modes.
387 *
388 * Dynamically switching the input/output buffers probably
a1e8d2da
JW
389 * reduces noise slightly (particularly on input) so we'll
390 * do it. However, having both input and output buffers
391 * enabled simultaneously doesn't seem to be problematic if
392 * this turns out to be necessary in the future.
cdcd9268
JW
393 */
394 if (val <= 2) {
9c7f852e
TI
395 snd_hda_codec_write(codec, nid, 0,
396 AC_VERB_SET_AMP_GAIN_MUTE,
397 AMP_OUT_MUTE);
398 snd_hda_codec_write(codec, nid, 0,
399 AC_VERB_SET_AMP_GAIN_MUTE,
400 AMP_IN_UNMUTE(0));
cdcd9268 401 } else {
9c7f852e
TI
402 snd_hda_codec_write(codec, nid, 0,
403 AC_VERB_SET_AMP_GAIN_MUTE,
404 AMP_IN_MUTE(0));
405 snd_hda_codec_write(codec, nid, 0,
406 AC_VERB_SET_AMP_GAIN_MUTE,
407 AMP_OUT_UNMUTE);
cdcd9268
JW
408 }
409 }
a9430dd8
JW
410 return change;
411}
412
4c5186ed 413#define ALC_PIN_MODE(xname, nid, dir) \
a9430dd8 414 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
4c5186ed
JW
415 .info = alc_pin_mode_info, \
416 .get = alc_pin_mode_get, \
417 .put = alc_pin_mode_put, \
418 .private_value = nid | (dir<<16) }
df694daa 419
5c8f858d
JW
420/* A switch control for ALC260 GPIO pins. Multiple GPIOs can be ganged
421 * together using a mask with more than one bit set. This control is
422 * currently used only by the ALC260 test model. At this stage they are not
423 * needed for any "production" models.
424 */
425#ifdef CONFIG_SND_DEBUG
9c7f852e
TI
426static int alc_gpio_data_info(struct snd_kcontrol *kcontrol,
427 struct snd_ctl_elem_info *uinfo)
5c8f858d
JW
428{
429 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
430 uinfo->count = 1;
431 uinfo->value.integer.min = 0;
432 uinfo->value.integer.max = 1;
433 return 0;
434}
9c7f852e
TI
435static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
436 struct snd_ctl_elem_value *ucontrol)
5c8f858d
JW
437{
438 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
439 hda_nid_t nid = kcontrol->private_value & 0xffff;
440 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
441 long *valp = ucontrol->value.integer.value;
9c7f852e
TI
442 unsigned int val = snd_hda_codec_read(codec, nid, 0,
443 AC_VERB_GET_GPIO_DATA, 0x00);
5c8f858d
JW
444
445 *valp = (val & mask) != 0;
446 return 0;
447}
9c7f852e
TI
448static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
449 struct snd_ctl_elem_value *ucontrol)
5c8f858d
JW
450{
451 signed int change;
452 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
453 hda_nid_t nid = kcontrol->private_value & 0xffff;
454 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
455 long val = *ucontrol->value.integer.value;
9c7f852e
TI
456 unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
457 AC_VERB_GET_GPIO_DATA,
458 0x00);
5c8f858d
JW
459
460 /* Set/unset the masked GPIO bit(s) as needed */
9c7f852e
TI
461 change = (val == 0 ? 0 : mask) != (gpio_data & mask);
462 if (val == 0)
5c8f858d
JW
463 gpio_data &= ~mask;
464 else
465 gpio_data |= mask;
9c7f852e 466 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_GPIO_DATA, gpio_data);
5c8f858d
JW
467
468 return change;
469}
470#define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
471 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
472 .info = alc_gpio_data_info, \
473 .get = alc_gpio_data_get, \
474 .put = alc_gpio_data_put, \
475 .private_value = nid | (mask<<16) }
476#endif /* CONFIG_SND_DEBUG */
477
92621f13
JW
478/* A switch control to allow the enabling of the digital IO pins on the
479 * ALC260. This is incredibly simplistic; the intention of this control is
480 * to provide something in the test model allowing digital outputs to be
481 * identified if present. If models are found which can utilise these
482 * outputs a more complete mixer control can be devised for those models if
483 * necessary.
484 */
485#ifdef CONFIG_SND_DEBUG
9c7f852e
TI
486static int alc_spdif_ctrl_info(struct snd_kcontrol *kcontrol,
487 struct snd_ctl_elem_info *uinfo)
92621f13
JW
488{
489 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
490 uinfo->count = 1;
491 uinfo->value.integer.min = 0;
492 uinfo->value.integer.max = 1;
493 return 0;
494}
9c7f852e
TI
495static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
496 struct snd_ctl_elem_value *ucontrol)
92621f13
JW
497{
498 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
499 hda_nid_t nid = kcontrol->private_value & 0xffff;
500 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
501 long *valp = ucontrol->value.integer.value;
9c7f852e
TI
502 unsigned int val = snd_hda_codec_read(codec, nid, 0,
503 AC_VERB_GET_DIGI_CONVERT, 0x00);
92621f13
JW
504
505 *valp = (val & mask) != 0;
506 return 0;
507}
9c7f852e
TI
508static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
509 struct snd_ctl_elem_value *ucontrol)
92621f13
JW
510{
511 signed int change;
512 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
513 hda_nid_t nid = kcontrol->private_value & 0xffff;
514 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
515 long val = *ucontrol->value.integer.value;
9c7f852e
TI
516 unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
517 AC_VERB_GET_DIGI_CONVERT,
518 0x00);
92621f13
JW
519
520 /* Set/unset the masked control bit(s) as needed */
9c7f852e 521 change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
92621f13
JW
522 if (val==0)
523 ctrl_data &= ~mask;
524 else
525 ctrl_data |= mask;
9c7f852e
TI
526 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
527 ctrl_data);
92621f13
JW
528
529 return change;
530}
531#define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
532 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
533 .info = alc_spdif_ctrl_info, \
534 .get = alc_spdif_ctrl_get, \
535 .put = alc_spdif_ctrl_put, \
536 .private_value = nid | (mask<<16) }
537#endif /* CONFIG_SND_DEBUG */
538
df694daa
KY
539/*
540 * set up from the preset table
541 */
9c7f852e
TI
542static void setup_preset(struct alc_spec *spec,
543 const struct alc_config_preset *preset)
df694daa
KY
544{
545 int i;
546
547 for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
548 spec->mixers[spec->num_mixers++] = preset->mixers[i];
9c7f852e
TI
549 for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
550 i++)
551 spec->init_verbs[spec->num_init_verbs++] =
552 preset->init_verbs[i];
df694daa
KY
553
554 spec->channel_mode = preset->channel_mode;
555 spec->num_channel_mode = preset->num_channel_mode;
4e195a7b 556 spec->need_dac_fix = preset->need_dac_fix;
df694daa
KY
557
558 spec->multiout.max_channels = spec->channel_mode[0].channels;
559
560 spec->multiout.num_dacs = preset->num_dacs;
561 spec->multiout.dac_nids = preset->dac_nids;
562 spec->multiout.dig_out_nid = preset->dig_out_nid;
563 spec->multiout.hp_nid = preset->hp_nid;
564
a1e8d2da
JW
565 spec->num_mux_defs = preset->num_mux_defs;
566 if (! spec->num_mux_defs)
567 spec->num_mux_defs = 1;
df694daa
KY
568 spec->input_mux = preset->input_mux;
569
570 spec->num_adc_nids = preset->num_adc_nids;
571 spec->adc_nids = preset->adc_nids;
572 spec->dig_in_nid = preset->dig_in_nid;
ae6b813a
TI
573
574 spec->unsol_event = preset->unsol_event;
575 spec->init_hook = preset->init_hook;
df694daa
KY
576}
577
1da177e4 578/*
e9edcee0
TI
579 * ALC880 3-stack model
580 *
581 * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
9c7f852e
TI
582 * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
583 * F-Mic = 0x1b, HP = 0x19
1da177e4
LT
584 */
585
e9edcee0
TI
586static hda_nid_t alc880_dac_nids[4] = {
587 /* front, rear, clfe, rear_surr */
588 0x02, 0x05, 0x04, 0x03
589};
590
591static hda_nid_t alc880_adc_nids[3] = {
592 /* ADC0-2 */
593 0x07, 0x08, 0x09,
594};
595
596/* The datasheet says the node 0x07 is connected from inputs,
597 * but it shows zero connection in the real implementation on some devices.
df694daa 598 * Note: this is a 915GAV bug, fixed on 915GLV
1da177e4 599 */
e9edcee0
TI
600static hda_nid_t alc880_adc_nids_alt[2] = {
601 /* ADC1-2 */
602 0x08, 0x09,
603};
604
605#define ALC880_DIGOUT_NID 0x06
606#define ALC880_DIGIN_NID 0x0a
607
608static struct hda_input_mux alc880_capture_source = {
609 .num_items = 4,
610 .items = {
611 { "Mic", 0x0 },
612 { "Front Mic", 0x3 },
613 { "Line", 0x2 },
614 { "CD", 0x4 },
615 },
616};
617
618/* channel source setting (2/6 channel selection for 3-stack) */
619/* 2ch mode */
620static struct hda_verb alc880_threestack_ch2_init[] = {
621 /* set line-in to input, mute it */
622 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
623 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
624 /* set mic-in to input vref 80%, mute it */
625 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
626 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
627 { } /* end */
628};
629
630/* 6ch mode */
631static struct hda_verb alc880_threestack_ch6_init[] = {
632 /* set line-in to output, unmute it */
633 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
634 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
635 /* set mic-in to output, unmute it */
636 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
637 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
638 { } /* end */
639};
640
d2a6d7dc 641static struct hda_channel_mode alc880_threestack_modes[2] = {
e9edcee0
TI
642 { 2, alc880_threestack_ch2_init },
643 { 6, alc880_threestack_ch6_init },
644};
645
c8b6bf9b 646static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
05acb863 647 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
985be54b 648 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
05acb863 649 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
985be54b 650 HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
05acb863
TI
651 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
652 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
985be54b
TI
653 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
654 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1da177e4
LT
655 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
656 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
657 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
658 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
659 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
660 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
661 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
662 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
663 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
664 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
e9edcee0
TI
665 HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
666 {
667 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
668 .name = "Channel Mode",
df694daa
KY
669 .info = alc_ch_mode_info,
670 .get = alc_ch_mode_get,
671 .put = alc_ch_mode_put,
e9edcee0
TI
672 },
673 { } /* end */
674};
675
676/* capture mixer elements */
c8b6bf9b 677static struct snd_kcontrol_new alc880_capture_mixer[] = {
e9edcee0
TI
678 HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
679 HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
680 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
681 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
682 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
683 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1da177e4
LT
684 {
685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
686 /* The multiple "Capture Source" controls confuse alsamixer
687 * So call somewhat different..
688 * FIXME: the controls appear in the "playback" view!
689 */
690 /* .name = "Capture Source", */
691 .name = "Input Source",
e9edcee0 692 .count = 3,
1da177e4
LT
693 .info = alc_mux_enum_info,
694 .get = alc_mux_enum_get,
695 .put = alc_mux_enum_put,
696 },
1da177e4
LT
697 { } /* end */
698};
699
e9edcee0 700/* capture mixer elements (in case NID 0x07 not available) */
c8b6bf9b 701static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
71fe7b82
TI
702 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
703 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
704 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
705 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1da177e4
LT
706 {
707 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
708 /* The multiple "Capture Source" controls confuse alsamixer
709 * So call somewhat different..
710 * FIXME: the controls appear in the "playback" view!
711 */
712 /* .name = "Capture Source", */
713 .name = "Input Source",
714 .count = 2,
715 .info = alc_mux_enum_info,
716 .get = alc_mux_enum_get,
717 .put = alc_mux_enum_put,
718 },
1da177e4
LT
719 { } /* end */
720};
721
e9edcee0
TI
722
723
724/*
725 * ALC880 5-stack model
726 *
9c7f852e
TI
727 * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
728 * Side = 0x02 (0xd)
e9edcee0
TI
729 * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
730 * Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
731 */
732
733/* additional mixers to alc880_three_stack_mixer */
c8b6bf9b 734static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
e9edcee0 735 HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
985be54b 736 HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1da177e4
LT
737 { } /* end */
738};
739
e9edcee0
TI
740/* channel source setting (6/8 channel selection for 5-stack) */
741/* 6ch mode */
742static struct hda_verb alc880_fivestack_ch6_init[] = {
743 /* set line-in to input, mute it */
744 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
745 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
dfc0ff62
TI
746 { } /* end */
747};
748
e9edcee0
TI
749/* 8ch mode */
750static struct hda_verb alc880_fivestack_ch8_init[] = {
751 /* set line-in to output, unmute it */
752 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
753 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
754 { } /* end */
755};
756
d2a6d7dc 757static struct hda_channel_mode alc880_fivestack_modes[2] = {
e9edcee0
TI
758 { 6, alc880_fivestack_ch6_init },
759 { 8, alc880_fivestack_ch8_init },
760};
761
762
763/*
764 * ALC880 6-stack model
765 *
9c7f852e
TI
766 * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
767 * Side = 0x05 (0x0f)
e9edcee0
TI
768 * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
769 * Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
770 */
771
772static hda_nid_t alc880_6st_dac_nids[4] = {
773 /* front, rear, clfe, rear_surr */
774 0x02, 0x03, 0x04, 0x05
775};
776
777static struct hda_input_mux alc880_6stack_capture_source = {
778 .num_items = 4,
779 .items = {
780 { "Mic", 0x0 },
781 { "Front Mic", 0x1 },
782 { "Line", 0x2 },
783 { "CD", 0x4 },
784 },
785};
786
787/* fixed 8-channels */
d2a6d7dc 788static struct hda_channel_mode alc880_sixstack_modes[1] = {
e9edcee0
TI
789 { 8, NULL },
790};
791
c8b6bf9b 792static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
16ded525 793 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
985be54b 794 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
16ded525 795 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
985be54b 796 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
16ded525
TI
797 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
798 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
985be54b
TI
799 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
800 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
16ded525 801 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
985be54b 802 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
16ded525
TI
803 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
804 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
805 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
806 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
807 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
808 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
809 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
810 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
811 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
812 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
16ded525
TI
813 {
814 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
815 .name = "Channel Mode",
df694daa
KY
816 .info = alc_ch_mode_info,
817 .get = alc_ch_mode_get,
818 .put = alc_ch_mode_put,
16ded525
TI
819 },
820 { } /* end */
821};
822
e9edcee0
TI
823
824/*
825 * ALC880 W810 model
826 *
827 * W810 has rear IO for:
828 * Front (DAC 02)
829 * Surround (DAC 03)
830 * Center/LFE (DAC 04)
831 * Digital out (06)
832 *
833 * The system also has a pair of internal speakers, and a headphone jack.
834 * These are both connected to Line2 on the codec, hence to DAC 02.
835 *
836 * There is a variable resistor to control the speaker or headphone
837 * volume. This is a hardware-only device without a software API.
838 *
839 * Plugging headphones in will disable the internal speakers. This is
840 * implemented in hardware, not via the driver using jack sense. In
841 * a similar fashion, plugging into the rear socket marked "front" will
842 * disable both the speakers and headphones.
843 *
844 * For input, there's a microphone jack, and an "audio in" jack.
845 * These may not do anything useful with this driver yet, because I
846 * haven't setup any initialization verbs for these yet...
847 */
848
849static hda_nid_t alc880_w810_dac_nids[3] = {
850 /* front, rear/surround, clfe */
851 0x02, 0x03, 0x04
16ded525
TI
852};
853
e9edcee0 854/* fixed 6 channels */
d2a6d7dc 855static struct hda_channel_mode alc880_w810_modes[1] = {
e9edcee0
TI
856 { 6, NULL }
857};
858
859/* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
c8b6bf9b 860static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
16ded525 861 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
985be54b 862 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
16ded525 863 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
985be54b 864 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
16ded525
TI
865 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
866 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
985be54b
TI
867 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
868 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
e9edcee0
TI
869 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
870 { } /* end */
871};
872
873
874/*
875 * Z710V model
876 *
877 * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
9c7f852e
TI
878 * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
879 * Line = 0x1a
e9edcee0
TI
880 */
881
882static hda_nid_t alc880_z71v_dac_nids[1] = {
883 0x02
884};
885#define ALC880_Z71V_HP_DAC 0x03
886
887/* fixed 2 channels */
d2a6d7dc 888static struct hda_channel_mode alc880_2_jack_modes[1] = {
e9edcee0
TI
889 { 2, NULL }
890};
891
c8b6bf9b 892static struct snd_kcontrol_new alc880_z71v_mixer[] = {
e9edcee0 893 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
985be54b 894 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
e9edcee0 895 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
985be54b 896 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
16ded525
TI
897 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
898 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
16ded525
TI
899 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
900 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16ded525
TI
901 { } /* end */
902};
903
e9edcee0
TI
904
905/* FIXME! */
906/*
907 * ALC880 F1734 model
908 *
909 * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
910 * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
911 */
912
913static hda_nid_t alc880_f1734_dac_nids[1] = {
914 0x03
915};
916#define ALC880_F1734_HP_DAC 0x02
917
c8b6bf9b 918static struct snd_kcontrol_new alc880_f1734_mixer[] = {
e9edcee0 919 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
985be54b 920 HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
e9edcee0 921 HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
985be54b 922 HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
e9edcee0
TI
923 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
924 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
925 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
926 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
927 { } /* end */
928};
929
930
931/* FIXME! */
932/*
933 * ALC880 ASUS model
934 *
935 * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
936 * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
937 * Mic = 0x18, Line = 0x1a
938 */
939
940#define alc880_asus_dac_nids alc880_w810_dac_nids /* identical with w810 */
941#define alc880_asus_modes alc880_threestack_modes /* 2/6 channel mode */
942
c8b6bf9b 943static struct snd_kcontrol_new alc880_asus_mixer[] = {
16ded525 944 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
985be54b 945 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
16ded525 946 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
985be54b 947 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
16ded525
TI
948 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
949 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
985be54b
TI
950 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
951 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
16ded525
TI
952 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
953 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
954 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
955 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
16ded525
TI
956 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
957 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16ded525
TI
958 {
959 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
960 .name = "Channel Mode",
df694daa
KY
961 .info = alc_ch_mode_info,
962 .get = alc_ch_mode_get,
963 .put = alc_ch_mode_put,
16ded525
TI
964 },
965 { } /* end */
966};
e9edcee0
TI
967
968/* FIXME! */
969/*
970 * ALC880 ASUS W1V model
971 *
972 * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
973 * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
974 * Mic = 0x18, Line = 0x1a, Line2 = 0x1b
975 */
976
977/* additional mixers to alc880_asus_mixer */
c8b6bf9b 978static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
e9edcee0
TI
979 HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
980 HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
981 { } /* end */
982};
983
3c10a9d9 984/* additional mixers to alc880_asus_mixer */
c8b6bf9b 985static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
3c10a9d9
TI
986 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
987 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
988 { } /* end */
989};
e9edcee0 990
df694daa
KY
991/* TCL S700 */
992static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
993 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
994 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
995 HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
996 HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
997 HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
998 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
999 HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1000 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1001 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1002 {
1003 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1004 /* The multiple "Capture Source" controls confuse alsamixer
1005 * So call somewhat different..
1006 * FIXME: the controls appear in the "playback" view!
1007 */
1008 /* .name = "Capture Source", */
1009 .name = "Input Source",
1010 .count = 1,
1011 .info = alc_mux_enum_info,
1012 .get = alc_mux_enum_get,
1013 .put = alc_mux_enum_put,
1014 },
1015 { } /* end */
1016};
1017
1da177e4 1018/*
e9edcee0 1019 * build control elements
1da177e4
LT
1020 */
1021static int alc_build_controls(struct hda_codec *codec)
1022{
1023 struct alc_spec *spec = codec->spec;
1024 int err;
1025 int i;
1026
1027 for (i = 0; i < spec->num_mixers; i++) {
1028 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1029 if (err < 0)
1030 return err;
1031 }
1032
1033 if (spec->multiout.dig_out_nid) {
9c7f852e
TI
1034 err = snd_hda_create_spdif_out_ctls(codec,
1035 spec->multiout.dig_out_nid);
1da177e4
LT
1036 if (err < 0)
1037 return err;
1038 }
1039 if (spec->dig_in_nid) {
1040 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1041 if (err < 0)
1042 return err;
1043 }
1044 return 0;
1045}
1046
e9edcee0 1047
1da177e4
LT
1048/*
1049 * initialize the codec volumes, etc
1050 */
1051
e9edcee0
TI
1052/*
1053 * generic initialization of ADC, input mixers and output mixers
1054 */
1055static struct hda_verb alc880_volume_init_verbs[] = {
1056 /*
1057 * Unmute ADC0-2 and set the default input to mic-in
1058 */
71fe7b82 1059 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
e9edcee0 1060 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
71fe7b82 1061 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
e9edcee0 1062 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
71fe7b82 1063 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
e9edcee0 1064 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1da177e4 1065
e9edcee0
TI
1066 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1067 * mixer widget
9c7f852e
TI
1068 * Note: PASD motherboards uses the Line In 2 as the input for front
1069 * panel mic (mic 2)
1da177e4 1070 */
e9edcee0 1071 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
16ded525 1072 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
e9edcee0
TI
1073 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1074 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1075 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1076 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1da177e4 1077
e9edcee0
TI
1078 /*
1079 * Set up output mixers (0x0c - 0x0f)
1da177e4 1080 */
e9edcee0
TI
1081 /* set vol=0 to output mixers */
1082 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1083 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1084 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1085 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1086 /* set up input amps for analog loopback */
1087 /* Amp Indices: DAC = 0, mixer = 1 */
05acb863
TI
1088 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1089 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
05acb863
TI
1090 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1091 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
05acb863
TI
1092 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1093 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
05acb863
TI
1094 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1095 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1da177e4
LT
1096
1097 { }
1098};
1099
e9edcee0
TI
1100/*
1101 * 3-stack pin configuration:
1102 * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1103 */
1104static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1105 /*
1106 * preset connection lists of input pins
1107 * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1108 */
1109 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1110 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1111 {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1112
1113 /*
1114 * Set pin mode and muting
1115 */
1116 /* set front pin widgets 0x14 for output */
05acb863 1117 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0
TI
1118 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1119 /* Mic1 (rear panel) pin widget for input and vref at 80% */
1120 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1121 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1122 /* Mic2 (as headphone out) for HP output */
1123 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1124 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1da177e4 1125 /* Line In pin widget for input */
05acb863 1126 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
e9edcee0
TI
1127 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1128 /* Line2 (as front mic) pin widget for input and vref at 80% */
1129 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1130 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1da177e4 1131 /* CD pin widget for input */
05acb863 1132 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1da177e4 1133
e9edcee0
TI
1134 { }
1135};
1da177e4 1136
e9edcee0
TI
1137/*
1138 * 5-stack pin configuration:
1139 * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1140 * line-in/side = 0x1a, f-mic = 0x1b
1141 */
1142static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1143 /*
1144 * preset connection lists of input pins
1145 * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1da177e4 1146 */
e9edcee0
TI
1147 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1148 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1da177e4 1149
e9edcee0
TI
1150 /*
1151 * Set pin mode and muting
1da177e4 1152 */
e9edcee0
TI
1153 /* set pin widgets 0x14-0x17 for output */
1154 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1155 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1156 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1157 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1158 /* unmute pins for output (no gain on this amp) */
1159 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1160 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1161 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1162 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1163
1164 /* Mic1 (rear panel) pin widget for input and vref at 80% */
1165 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1166 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1167 /* Mic2 (as headphone out) for HP output */
1168 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1169 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1170 /* Line In pin widget for input */
1171 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1172 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1173 /* Line2 (as front mic) pin widget for input and vref at 80% */
1174 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1175 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1176 /* CD pin widget for input */
1177 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1da177e4
LT
1178
1179 { }
1180};
1181
e9edcee0
TI
1182/*
1183 * W810 pin configuration:
1184 * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1185 */
1186static struct hda_verb alc880_pin_w810_init_verbs[] = {
1187 /* hphone/speaker input selector: front DAC */
1188 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1da177e4 1189
05acb863 1190 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 1191 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
05acb863 1192 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 1193 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
05acb863 1194 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 1195 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1da177e4 1196
e9edcee0 1197 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
05acb863 1198 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1da177e4 1199
1da177e4
LT
1200 { }
1201};
1202
e9edcee0
TI
1203/*
1204 * Z71V pin configuration:
1205 * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1206 */
1207static struct hda_verb alc880_pin_z71v_init_verbs[] = {
05acb863 1208 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 1209 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
05acb863 1210 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
e9edcee0 1211 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
dfc0ff62 1212
16ded525 1213 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
e9edcee0 1214 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16ded525 1215 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
e9edcee0 1216 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16ded525
TI
1217
1218 { }
1219};
1220
e9edcee0
TI
1221/*
1222 * 6-stack pin configuration:
9c7f852e
TI
1223 * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1224 * f-mic = 0x19, line = 0x1a, HP = 0x1b
e9edcee0
TI
1225 */
1226static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1227 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1228
16ded525 1229 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 1230 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 1231 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 1232 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 1233 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 1234 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 1235 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0
TI
1236 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1237
16ded525 1238 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
e9edcee0 1239 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16ded525 1240 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
e9edcee0 1241 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16ded525 1242 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
e9edcee0 1243 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16ded525 1244 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
e9edcee0 1245 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525
TI
1246 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1247
e9edcee0
TI
1248 { }
1249};
1250
1251/* FIXME! */
1252/*
1253 * F1734 pin configuration:
1254 * HP = 0x14, speaker-out = 0x15, mic = 0x18
1255 */
1256static struct hda_verb alc880_pin_f1734_init_verbs[] = {
16ded525
TI
1257 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1258 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1259 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1260 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1261
e9edcee0 1262 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16ded525 1263 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
e9edcee0 1264 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16ded525 1265 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 1266
e9edcee0
TI
1267 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1268 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16ded525 1269 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
e9edcee0 1270 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16ded525 1271 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 1272 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 1273 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 1274 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 1275 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
dfc0ff62
TI
1276
1277 { }
1278};
1279
e9edcee0
TI
1280/* FIXME! */
1281/*
1282 * ASUS pin configuration:
1283 * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
1284 */
1285static struct hda_verb alc880_pin_asus_init_verbs[] = {
16ded525
TI
1286 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1287 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1288 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1289 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1290
1291 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
e9edcee0 1292 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 1293 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 1294 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 1295 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 1296 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525 1297 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0
TI
1298 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1299
1300 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1301 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1302 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1303 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1304 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1305 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16ded525 1306 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
e9edcee0 1307 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16ded525
TI
1308 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1309
e9edcee0
TI
1310 { }
1311};
16ded525 1312
e9edcee0
TI
1313/* Enable GPIO mask and set output */
1314static struct hda_verb alc880_gpio1_init_verbs[] = {
1315 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
1316 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
1317 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
df694daa
KY
1318
1319 { }
e9edcee0 1320};
16ded525 1321
e9edcee0
TI
1322/* Enable GPIO mask and set output */
1323static struct hda_verb alc880_gpio2_init_verbs[] = {
1324 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
1325 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
1326 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
df694daa
KY
1327
1328 { }
1329};
1330
1331/* Clevo m520g init */
1332static struct hda_verb alc880_pin_clevo_init_verbs[] = {
1333 /* headphone output */
1334 {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1335 /* line-out */
1336 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1337 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1338 /* Line-in */
1339 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1340 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1341 /* CD */
1342 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1343 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1344 /* Mic1 (rear panel) */
1345 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1346 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1347 /* Mic2 (front panel) */
1348 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1349 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1350 /* headphone */
1351 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1352 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1353 /* change to EAPD mode */
1354 {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1355 {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
1356
1357 { }
16ded525
TI
1358};
1359
df694daa 1360static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
4b146cb0
TI
1361 /* change to EAPD mode */
1362 {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1363 {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
1364
df694daa
KY
1365 /* Headphone output */
1366 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1367 /* Front output*/
1368 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1369 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1370
1371 /* Line In pin widget for input */
1372 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1373 /* CD pin widget for input */
1374 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1375 /* Mic1 (rear panel) pin widget for input and vref at 80% */
1376 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1377
1378 /* change to EAPD mode */
1379 {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1380 {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
1381
1382 { }
1383};
16ded525 1384
e9edcee0 1385/*
ae6b813a
TI
1386 * LG m1 express dual
1387 *
1388 * Pin assignment:
1389 * Rear Line-In/Out (blue): 0x14
1390 * Build-in Mic-In: 0x15
1391 * Speaker-out: 0x17
1392 * HP-Out (green): 0x1b
1393 * Mic-In/Out (red): 0x19
1394 * SPDIF-Out: 0x1e
1395 */
1396
1397/* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
1398static hda_nid_t alc880_lg_dac_nids[3] = {
1399 0x05, 0x02, 0x03
1400};
1401
1402/* seems analog CD is not working */
1403static struct hda_input_mux alc880_lg_capture_source = {
1404 .num_items = 3,
1405 .items = {
1406 { "Mic", 0x1 },
1407 { "Line", 0x5 },
1408 { "Internal Mic", 0x6 },
1409 },
1410};
1411
1412/* 2,4,6 channel modes */
1413static struct hda_verb alc880_lg_ch2_init[] = {
1414 /* set line-in and mic-in to input */
1415 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1416 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1417 { }
1418};
1419
1420static struct hda_verb alc880_lg_ch4_init[] = {
1421 /* set line-in to out and mic-in to input */
1422 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1423 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1424 { }
1425};
1426
1427static struct hda_verb alc880_lg_ch6_init[] = {
1428 /* set line-in and mic-in to output */
1429 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1430 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1431 { }
1432};
1433
1434static struct hda_channel_mode alc880_lg_ch_modes[3] = {
1435 { 2, alc880_lg_ch2_init },
1436 { 4, alc880_lg_ch4_init },
1437 { 6, alc880_lg_ch6_init },
1438};
1439
1440static struct snd_kcontrol_new alc880_lg_mixer[] = {
1441 /* FIXME: it's not really "master" but front channels */
1442 HDA_CODEC_VOLUME("Master Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1443 HDA_BIND_MUTE("Master Playback Switch", 0x0f, 2, HDA_INPUT),
1444 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1445 HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
1446 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1447 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
1448 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
1449 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
1450 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1451 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1452 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
1453 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
1454 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
1455 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
1456 {
1457 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1458 .name = "Channel Mode",
1459 .info = alc_ch_mode_info,
1460 .get = alc_ch_mode_get,
1461 .put = alc_ch_mode_put,
1462 },
1463 { } /* end */
1464};
1465
1466static struct hda_verb alc880_lg_init_verbs[] = {
1467 /* set capture source to mic-in */
1468 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1469 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1470 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1471 /* mute all amp mixer inputs */
1472 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
1473 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(6)},
1474 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
1475 /* line-in to input */
1476 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1477 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1478 /* built-in mic */
1479 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1480 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1481 /* speaker-out */
1482 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1483 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1484 /* mic-in to input */
1485 {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1486 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1487 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1488 /* HP-out */
1489 {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
1490 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1491 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1492 /* jack sense */
1493 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
1494 { }
1495};
1496
1497/* toggle speaker-output according to the hp-jack state */
1498static void alc880_lg_automute(struct hda_codec *codec)
1499{
1500 unsigned int present;
1501
1502 present = snd_hda_codec_read(codec, 0x1b, 0,
1503 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1504 snd_hda_codec_amp_update(codec, 0x17, 0, HDA_OUTPUT, 0,
1505 0x80, present ? 0x80 : 0);
1506 snd_hda_codec_amp_update(codec, 0x17, 1, HDA_OUTPUT, 0,
1507 0x80, present ? 0x80 : 0);
1508}
1509
1510static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
1511{
1512 /* Looks like the unsol event is incompatible with the standard
1513 * definition. 4bit tag is placed at 28 bit!
1514 */
1515 if ((res >> 28) == 0x01)
1516 alc880_lg_automute(codec);
1517}
1518
d681518a
TI
1519/*
1520 * LG LW20
1521 *
1522 * Pin assignment:
1523 * Speaker-out: 0x14
1524 * Mic-In: 0x18
1525 * Built-in Mic-In: 0x19 (?)
1526 * HP-Out: 0x1b
1527 * SPDIF-Out: 0x1e
1528 */
1529
1530/* seems analog CD is not working */
1531static struct hda_input_mux alc880_lg_lw_capture_source = {
1532 .num_items = 2,
1533 .items = {
1534 { "Mic", 0x0 },
1535 { "Internal Mic", 0x1 },
1536 },
1537};
1538
1539static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
1540 HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1541 HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
1542 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1543 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1544 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
1545 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
1546 { } /* end */
1547};
1548
1549static struct hda_verb alc880_lg_lw_init_verbs[] = {
1550 /* set capture source to mic-in */
1551 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1552 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1553 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1554 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
1555 /* speaker-out */
1556 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1557 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1558 /* HP-out */
1559 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1560 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1561 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1562 /* mic-in to input */
1563 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1564 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1565 /* built-in mic */
1566 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1567 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1568 /* jack sense */
1569 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
1570 { }
1571};
1572
1573/* toggle speaker-output according to the hp-jack state */
1574static void alc880_lg_lw_automute(struct hda_codec *codec)
1575{
1576 unsigned int present;
1577
1578 present = snd_hda_codec_read(codec, 0x1b, 0,
1579 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1580 snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
1581 0x80, present ? 0x80 : 0);
1582 snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
1583 0x80, present ? 0x80 : 0);
1584}
1585
1586static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
1587{
1588 /* Looks like the unsol event is incompatible with the standard
1589 * definition. 4bit tag is placed at 28 bit!
1590 */
1591 if ((res >> 28) == 0x01)
1592 alc880_lg_lw_automute(codec);
1593}
1594
ae6b813a
TI
1595/*
1596 * Common callbacks
e9edcee0
TI
1597 */
1598
1da177e4
LT
1599static int alc_init(struct hda_codec *codec)
1600{
1601 struct alc_spec *spec = codec->spec;
e9edcee0
TI
1602 unsigned int i;
1603
1604 for (i = 0; i < spec->num_init_verbs; i++)
1605 snd_hda_sequence_write(codec, spec->init_verbs[i]);
ae6b813a
TI
1606
1607 if (spec->init_hook)
1608 spec->init_hook(codec);
1609
1da177e4
LT
1610 return 0;
1611}
1612
ae6b813a
TI
1613static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
1614{
1615 struct alc_spec *spec = codec->spec;
1616
1617 if (spec->unsol_event)
1618 spec->unsol_event(codec, res);
1619}
1620
1da177e4
LT
1621#ifdef CONFIG_PM
1622/*
1623 * resume
1624 */
1625static int alc_resume(struct hda_codec *codec)
1626{
1627 struct alc_spec *spec = codec->spec;
1628 int i;
1629
1630 alc_init(codec);
e9edcee0 1631 for (i = 0; i < spec->num_mixers; i++)
1da177e4 1632 snd_hda_resume_ctls(codec, spec->mixers[i]);
1da177e4
LT
1633 if (spec->multiout.dig_out_nid)
1634 snd_hda_resume_spdif_out(codec);
1635 if (spec->dig_in_nid)
1636 snd_hda_resume_spdif_in(codec);
1637
1638 return 0;
1639}
1640#endif
1641
1642/*
1643 * Analog playback callbacks
1644 */
1645static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
1646 struct hda_codec *codec,
c8b6bf9b 1647 struct snd_pcm_substream *substream)
1da177e4
LT
1648{
1649 struct alc_spec *spec = codec->spec;
1650 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1651}
1652
1653static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1654 struct hda_codec *codec,
1655 unsigned int stream_tag,
1656 unsigned int format,
c8b6bf9b 1657 struct snd_pcm_substream *substream)
1da177e4
LT
1658{
1659 struct alc_spec *spec = codec->spec;
9c7f852e
TI
1660 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
1661 stream_tag, format, substream);
1da177e4
LT
1662}
1663
1664static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1665 struct hda_codec *codec,
c8b6bf9b 1666 struct snd_pcm_substream *substream)
1da177e4
LT
1667{
1668 struct alc_spec *spec = codec->spec;
1669 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1670}
1671
1672/*
1673 * Digital out
1674 */
1675static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1676 struct hda_codec *codec,
c8b6bf9b 1677 struct snd_pcm_substream *substream)
1da177e4
LT
1678{
1679 struct alc_spec *spec = codec->spec;
1680 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1681}
1682
1683static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1684 struct hda_codec *codec,
c8b6bf9b 1685 struct snd_pcm_substream *substream)
1da177e4
LT
1686{
1687 struct alc_spec *spec = codec->spec;
1688 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1689}
1690
1691/*
1692 * Analog capture
1693 */
1694static int alc880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1695 struct hda_codec *codec,
1696 unsigned int stream_tag,
1697 unsigned int format,
c8b6bf9b 1698 struct snd_pcm_substream *substream)
1da177e4
LT
1699{
1700 struct alc_spec *spec = codec->spec;
1701
1702 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1703 stream_tag, 0, format);
1704 return 0;
1705}
1706
1707static int alc880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1708 struct hda_codec *codec,
c8b6bf9b 1709 struct snd_pcm_substream *substream)
1da177e4
LT
1710{
1711 struct alc_spec *spec = codec->spec;
1712
9c7f852e
TI
1713 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1714 0, 0, 0);
1da177e4
LT
1715 return 0;
1716}
1717
1718
1719/*
1720 */
1721static struct hda_pcm_stream alc880_pcm_analog_playback = {
1722 .substreams = 1,
1723 .channels_min = 2,
1724 .channels_max = 8,
e9edcee0 1725 /* NID is set in alc_build_pcms */
1da177e4
LT
1726 .ops = {
1727 .open = alc880_playback_pcm_open,
1728 .prepare = alc880_playback_pcm_prepare,
1729 .cleanup = alc880_playback_pcm_cleanup
1730 },
1731};
1732
1733static struct hda_pcm_stream alc880_pcm_analog_capture = {
1734 .substreams = 2,
1735 .channels_min = 2,
1736 .channels_max = 2,
e9edcee0 1737 /* NID is set in alc_build_pcms */
1da177e4
LT
1738 .ops = {
1739 .prepare = alc880_capture_pcm_prepare,
1740 .cleanup = alc880_capture_pcm_cleanup
1741 },
1742};
1743
1744static struct hda_pcm_stream alc880_pcm_digital_playback = {
1745 .substreams = 1,
1746 .channels_min = 2,
1747 .channels_max = 2,
1748 /* NID is set in alc_build_pcms */
1749 .ops = {
1750 .open = alc880_dig_playback_pcm_open,
1751 .close = alc880_dig_playback_pcm_close
1752 },
1753};
1754
1755static struct hda_pcm_stream alc880_pcm_digital_capture = {
1756 .substreams = 1,
1757 .channels_min = 2,
1758 .channels_max = 2,
1759 /* NID is set in alc_build_pcms */
1760};
1761
4c5186ed
JW
1762/* Used by alc_build_pcms to flag that a PCM has no playback stream */
1763static struct hda_pcm_stream alc_pcm_null_playback = {
1764 .substreams = 0,
1765 .channels_min = 0,
1766 .channels_max = 0,
1767};
1768
1da177e4
LT
1769static int alc_build_pcms(struct hda_codec *codec)
1770{
1771 struct alc_spec *spec = codec->spec;
1772 struct hda_pcm *info = spec->pcm_rec;
1773 int i;
1774
1775 codec->num_pcms = 1;
1776 codec->pcm_info = info;
1777
1778 info->name = spec->stream_name_analog;
4a471b7d
TI
1779 if (spec->stream_analog_playback) {
1780 snd_assert(spec->multiout.dac_nids, return -EINVAL);
1781 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
1782 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
1783 }
1784 if (spec->stream_analog_capture) {
1785 snd_assert(spec->adc_nids, return -EINVAL);
1786 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1787 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1788 }
1789
1790 if (spec->channel_mode) {
1791 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
1792 for (i = 0; i < spec->num_channel_mode; i++) {
1793 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
1794 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
1795 }
1da177e4
LT
1796 }
1797 }
1798
4c5186ed
JW
1799 /* If the use of more than one ADC is requested for the current
1800 * model, configure a second analog capture-only PCM.
1801 */
1802 if (spec->num_adc_nids > 1) {
1803 codec->num_pcms++;
1804 info++;
1805 info->name = spec->stream_name_analog;
1806 /* No playback stream for second PCM */
1807 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = alc_pcm_null_playback;
1808 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
1809 if (spec->stream_analog_capture) {
1810 snd_assert(spec->adc_nids, return -EINVAL);
1811 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1812 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[1];
1813 }
1814 }
1815
1da177e4
LT
1816 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1817 codec->num_pcms++;
1818 info++;
1819 info->name = spec->stream_name_digital;
4a471b7d
TI
1820 if (spec->multiout.dig_out_nid &&
1821 spec->stream_digital_playback) {
1da177e4
LT
1822 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
1823 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1824 }
4a471b7d
TI
1825 if (spec->dig_in_nid &&
1826 spec->stream_digital_capture) {
1da177e4
LT
1827 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
1828 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1829 }
1830 }
1831
1832 return 0;
1833}
1834
1835static void alc_free(struct hda_codec *codec)
1836{
e9edcee0
TI
1837 struct alc_spec *spec = codec->spec;
1838 unsigned int i;
1839
1840 if (! spec)
1841 return;
1842
1843 if (spec->kctl_alloc) {
1844 for (i = 0; i < spec->num_kctl_used; i++)
1845 kfree(spec->kctl_alloc[i].name);
1846 kfree(spec->kctl_alloc);
1847 }
1848 kfree(spec);
1da177e4
LT
1849}
1850
1851/*
1852 */
1853static struct hda_codec_ops alc_patch_ops = {
1854 .build_controls = alc_build_controls,
1855 .build_pcms = alc_build_pcms,
1856 .init = alc_init,
1857 .free = alc_free,
ae6b813a 1858 .unsol_event = alc_unsol_event,
1da177e4
LT
1859#ifdef CONFIG_PM
1860 .resume = alc_resume,
1861#endif
1862};
1863
2fa522be
TI
1864
1865/*
1866 * Test configuration for debugging
1867 *
1868 * Almost all inputs/outputs are enabled. I/O pins can be configured via
1869 * enum controls.
1870 */
1871#ifdef CONFIG_SND_DEBUG
1872static hda_nid_t alc880_test_dac_nids[4] = {
1873 0x02, 0x03, 0x04, 0x05
1874};
1875
1876static struct hda_input_mux alc880_test_capture_source = {
ae6b813a 1877 .num_items = 7,
2fa522be
TI
1878 .items = {
1879 { "In-1", 0x0 },
1880 { "In-2", 0x1 },
1881 { "In-3", 0x2 },
1882 { "In-4", 0x3 },
1883 { "CD", 0x4 },
ae6b813a
TI
1884 { "Front", 0x5 },
1885 { "Surround", 0x6 },
2fa522be
TI
1886 },
1887};
1888
d2a6d7dc 1889static struct hda_channel_mode alc880_test_modes[4] = {
2fa522be 1890 { 2, NULL },
fd2c326d 1891 { 4, NULL },
2fa522be 1892 { 6, NULL },
fd2c326d 1893 { 8, NULL },
2fa522be
TI
1894};
1895
9c7f852e
TI
1896static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
1897 struct snd_ctl_elem_info *uinfo)
2fa522be
TI
1898{
1899 static char *texts[] = {
1900 "N/A", "Line Out", "HP Out",
1901 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
1902 };
1903 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1904 uinfo->count = 1;
1905 uinfo->value.enumerated.items = 8;
1906 if (uinfo->value.enumerated.item >= 8)
1907 uinfo->value.enumerated.item = 7;
1908 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1909 return 0;
1910}
1911
9c7f852e
TI
1912static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
1913 struct snd_ctl_elem_value *ucontrol)
2fa522be
TI
1914{
1915 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1916 hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
1917 unsigned int pin_ctl, item = 0;
1918
1919 pin_ctl = snd_hda_codec_read(codec, nid, 0,
1920 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1921 if (pin_ctl & AC_PINCTL_OUT_EN) {
1922 if (pin_ctl & AC_PINCTL_HP_EN)
1923 item = 2;
1924 else
1925 item = 1;
1926 } else if (pin_ctl & AC_PINCTL_IN_EN) {
1927 switch (pin_ctl & AC_PINCTL_VREFEN) {
1928 case AC_PINCTL_VREF_HIZ: item = 3; break;
1929 case AC_PINCTL_VREF_50: item = 4; break;
1930 case AC_PINCTL_VREF_GRD: item = 5; break;
1931 case AC_PINCTL_VREF_80: item = 6; break;
1932 case AC_PINCTL_VREF_100: item = 7; break;
1933 }
1934 }
1935 ucontrol->value.enumerated.item[0] = item;
1936 return 0;
1937}
1938
9c7f852e
TI
1939static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
1940 struct snd_ctl_elem_value *ucontrol)
2fa522be
TI
1941{
1942 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1943 hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
1944 static unsigned int ctls[] = {
1945 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
1946 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
1947 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
1948 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
1949 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
1950 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
1951 };
1952 unsigned int old_ctl, new_ctl;
1953
1954 old_ctl = snd_hda_codec_read(codec, nid, 0,
1955 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1956 new_ctl = ctls[ucontrol->value.enumerated.item[0]];
1957 if (old_ctl != new_ctl) {
9c7f852e
TI
1958 snd_hda_codec_write(codec, nid, 0,
1959 AC_VERB_SET_PIN_WIDGET_CONTROL, new_ctl);
2fa522be 1960 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
9c7f852e
TI
1961 (ucontrol->value.enumerated.item[0] >= 3 ?
1962 0xb080 : 0xb000));
2fa522be
TI
1963 return 1;
1964 }
1965 return 0;
1966}
1967
9c7f852e
TI
1968static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
1969 struct snd_ctl_elem_info *uinfo)
2fa522be
TI
1970{
1971 static char *texts[] = {
1972 "Front", "Surround", "CLFE", "Side"
1973 };
1974 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1975 uinfo->count = 1;
1976 uinfo->value.enumerated.items = 4;
1977 if (uinfo->value.enumerated.item >= 4)
1978 uinfo->value.enumerated.item = 3;
1979 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1980 return 0;
1981}
1982
9c7f852e
TI
1983static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
1984 struct snd_ctl_elem_value *ucontrol)
2fa522be
TI
1985{
1986 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1987 hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
1988 unsigned int sel;
1989
1990 sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
1991 ucontrol->value.enumerated.item[0] = sel & 3;
1992 return 0;
1993}
1994
9c7f852e
TI
1995static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
1996 struct snd_ctl_elem_value *ucontrol)
2fa522be
TI
1997{
1998 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1999 hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2000 unsigned int sel;
2001
2002 sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2003 if (ucontrol->value.enumerated.item[0] != sel) {
2004 sel = ucontrol->value.enumerated.item[0] & 3;
2005 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, sel);
2006 return 1;
2007 }
2008 return 0;
2009}
2010
2011#define PIN_CTL_TEST(xname,nid) { \
2012 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2013 .name = xname, \
2014 .info = alc_test_pin_ctl_info, \
2015 .get = alc_test_pin_ctl_get, \
2016 .put = alc_test_pin_ctl_put, \
2017 .private_value = nid \
2018 }
2019
2020#define PIN_SRC_TEST(xname,nid) { \
2021 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2022 .name = xname, \
2023 .info = alc_test_pin_src_info, \
2024 .get = alc_test_pin_src_get, \
2025 .put = alc_test_pin_src_put, \
2026 .private_value = nid \
2027 }
2028
c8b6bf9b 2029static struct snd_kcontrol_new alc880_test_mixer[] = {
05acb863
TI
2030 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2031 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2032 HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2033 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
985be54b
TI
2034 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2035 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2036 HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2037 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2fa522be
TI
2038 PIN_CTL_TEST("Front Pin Mode", 0x14),
2039 PIN_CTL_TEST("Surround Pin Mode", 0x15),
2040 PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2041 PIN_CTL_TEST("Side Pin Mode", 0x17),
2042 PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2043 PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2044 PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2045 PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2046 PIN_SRC_TEST("In-1 Pin Source", 0x18),
2047 PIN_SRC_TEST("In-2 Pin Source", 0x19),
2048 PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2049 PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2050 HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2051 HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2052 HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2053 HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2054 HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2055 HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2056 HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2057 HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2058 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2059 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2fa522be
TI
2060 {
2061 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2062 .name = "Channel Mode",
df694daa
KY
2063 .info = alc_ch_mode_info,
2064 .get = alc_ch_mode_get,
2065 .put = alc_ch_mode_put,
2fa522be
TI
2066 },
2067 { } /* end */
2068};
2069
2070static struct hda_verb alc880_test_init_verbs[] = {
2071 /* Unmute inputs of 0x0c - 0x0f */
05acb863
TI
2072 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2073 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2074 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2075 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2076 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2077 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2078 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2079 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2fa522be 2080 /* Vol output for 0x0c-0x0f */
05acb863
TI
2081 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2082 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2083 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2084 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2fa522be 2085 /* Set output pins 0x14-0x17 */
05acb863
TI
2086 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2087 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2088 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2089 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2fa522be 2090 /* Unmute output pins 0x14-0x17 */
05acb863
TI
2091 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2092 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2093 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2094 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2fa522be 2095 /* Set input pins 0x18-0x1c */
16ded525
TI
2096 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2097 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
05acb863
TI
2098 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2099 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2100 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2fa522be 2101 /* Mute input pins 0x18-0x1b */
05acb863
TI
2102 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2103 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2104 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2105 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
71fe7b82 2106 /* ADC set up */
05acb863 2107 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
71fe7b82 2108 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
05acb863 2109 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
71fe7b82 2110 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
05acb863 2111 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
71fe7b82 2112 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
05acb863
TI
2113 /* Analog input/passthru */
2114 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2115 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2116 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2117 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2118 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2fa522be
TI
2119 { }
2120};
2121#endif
2122
1da177e4
LT
2123/*
2124 */
2125
2126static struct hda_board_config alc880_cfg_tbl[] = {
2127 /* Back 3 jack, front 2 jack */
2128 { .modelname = "3stack", .config = ALC880_3ST },
7291548d
TI
2129 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe200, .config = ALC880_3ST },
2130 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe201, .config = ALC880_3ST },
2131 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe202, .config = ALC880_3ST },
2132 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe203, .config = ALC880_3ST },
2133 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe204, .config = ALC880_3ST },
2134 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe205, .config = ALC880_3ST },
2135 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe206, .config = ALC880_3ST },
2136 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe207, .config = ALC880_3ST },
2137 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe208, .config = ALC880_3ST },
2138 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe209, .config = ALC880_3ST },
2139 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20a, .config = ALC880_3ST },
2140 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20b, .config = ALC880_3ST },
2141 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20c, .config = ALC880_3ST },
2142 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20d, .config = ALC880_3ST },
2143 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20e, .config = ALC880_3ST },
2144 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20f, .config = ALC880_3ST },
2145 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe210, .config = ALC880_3ST },
2146 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe211, .config = ALC880_3ST },
2aaeee8b
TD
2147 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe212, .config = ALC880_3ST },
2148 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe213, .config = ALC880_3ST },
7291548d 2149 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe214, .config = ALC880_3ST },
2aaeee8b 2150 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe234, .config = ALC880_3ST },
7291548d
TI
2151 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe302, .config = ALC880_3ST },
2152 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe303, .config = ALC880_3ST },
2153 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe304, .config = ALC880_3ST },
2154 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe306, .config = ALC880_3ST },
2155 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe307, .config = ALC880_3ST },
2156 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe404, .config = ALC880_3ST },
2157 { .pci_subvendor = 0x8086, .pci_subdevice = 0xa101, .config = ALC880_3ST },
2158 { .pci_subvendor = 0x107b, .pci_subdevice = 0x3031, .config = ALC880_3ST },
2159 { .pci_subvendor = 0x107b, .pci_subdevice = 0x4036, .config = ALC880_3ST },
2160 { .pci_subvendor = 0x107b, .pci_subdevice = 0x4037, .config = ALC880_3ST },
2161 { .pci_subvendor = 0x107b, .pci_subdevice = 0x4038, .config = ALC880_3ST },
2162 { .pci_subvendor = 0x107b, .pci_subdevice = 0x4040, .config = ALC880_3ST },
2163 { .pci_subvendor = 0x107b, .pci_subdevice = 0x4041, .config = ALC880_3ST },
df694daa 2164 /* TCL S700 */
4b146cb0 2165 { .modelname = "tcl", .config = ALC880_TCL_S700 },
df694daa 2166 { .pci_subvendor = 0x19db, .pci_subdevice = 0x4188, .config = ALC880_TCL_S700 },
1da177e4
LT
2167
2168 /* Back 3 jack, front 2 jack (Internal add Aux-In) */
7291548d 2169 { .pci_subvendor = 0x1025, .pci_subdevice = 0xe310, .config = ALC880_3ST },
16ded525 2170 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81d6, .config = ALC880_3ST },
0ca21611 2171 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81a0, .config = ALC880_3ST },
1da177e4
LT
2172
2173 /* Back 3 jack plus 1 SPDIF out jack, front 2 jack */
2174 { .modelname = "3stack-digout", .config = ALC880_3ST_DIG },
7291548d 2175 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe308, .config = ALC880_3ST_DIG },
5a47fe3c 2176 { .pci_subvendor = 0x1025, .pci_subdevice = 0x0070, .config = ALC880_3ST_DIG },
5a053d01
TI
2177
2178 /* Clevo laptops */
2179 { .modelname = "clevo", .config = ALC880_CLEVO },
2180 { .pci_subvendor = 0x1558, .pci_subdevice = 0x0520,
2181 .config = ALC880_CLEVO }, /* Clevo m520G NB */
2182 { .pci_subvendor = 0x1558, .pci_subdevice = 0x0660,
2183 .config = ALC880_CLEVO }, /* Clevo m665n */
1da177e4
LT
2184
2185 /* Back 3 jack plus 1 SPDIF out jack, front 2 jack (Internal add Aux-In)*/
7291548d
TI
2186 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe305, .config = ALC880_3ST_DIG },
2187 { .pci_subvendor = 0x8086, .pci_subdevice = 0xd402, .config = ALC880_3ST_DIG },
2188 { .pci_subvendor = 0x1025, .pci_subdevice = 0xe309, .config = ALC880_3ST_DIG },
1da177e4
LT
2189
2190 /* Back 5 jack, front 2 jack */
2191 { .modelname = "5stack", .config = ALC880_5ST },
7291548d
TI
2192 { .pci_subvendor = 0x107b, .pci_subdevice = 0x3033, .config = ALC880_5ST },
2193 { .pci_subvendor = 0x107b, .pci_subdevice = 0x4039, .config = ALC880_5ST },
2194 { .pci_subvendor = 0x107b, .pci_subdevice = 0x3032, .config = ALC880_5ST },
2195 { .pci_subvendor = 0x103c, .pci_subdevice = 0x2a09, .config = ALC880_5ST },
16ded525 2196 { .pci_subvendor = 0x1043, .pci_subdevice = 0x814e, .config = ALC880_5ST },
1da177e4
LT
2197
2198 /* Back 5 jack plus 1 SPDIF out jack, front 2 jack */
2199 { .modelname = "5stack-digout", .config = ALC880_5ST_DIG },
7291548d
TI
2200 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe224, .config = ALC880_5ST_DIG },
2201 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe400, .config = ALC880_5ST_DIG },
2202 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe401, .config = ALC880_5ST_DIG },
2203 { .pci_subvendor = 0x8086, .pci_subdevice = 0xe402, .config = ALC880_5ST_DIG },
2204 { .pci_subvendor = 0x8086, .pci_subdevice = 0xd400, .config = ALC880_5ST_DIG },
2205 { .pci_subvendor = 0x8086, .pci_subdevice = 0xd401, .config = ALC880_5ST_DIG },
2206 { .pci_subvendor = 0x8086, .pci_subdevice = 0xa100, .config = ALC880_5ST_DIG },
2207 { .pci_subvendor = 0x1565, .pci_subdevice = 0x8202, .config = ALC880_5ST_DIG },
16ded525 2208 { .pci_subvendor = 0x1019, .pci_subdevice = 0xa880, .config = ALC880_5ST_DIG },
ede3531e
TI
2209 { .pci_subvendor = 0xa0a0, .pci_subdevice = 0x0560,
2210 .config = ALC880_5ST_DIG }, /* Aopen i915GMm-HFS */
7a318a70 2211 /* { .pci_subvendor = 0x1019, .pci_subdevice = 0xa884, .config = ALC880_5ST_DIG }, */ /* conflict with 6stack */
16ded525 2212 { .pci_subvendor = 0x1695, .pci_subdevice = 0x400d, .config = ALC880_5ST_DIG },
b0af0de5
TI
2213 /* note subvendor = 0 below */
2214 /* { .pci_subvendor = 0x0000, .pci_subdevice = 0x8086, .config = ALC880_5ST_DIG }, */
1da177e4
LT
2215
2216 { .modelname = "w810", .config = ALC880_W810 },
7291548d 2217 { .pci_subvendor = 0x161f, .pci_subdevice = 0x203d, .config = ALC880_W810 },
1da177e4 2218
dfc0ff62 2219 { .modelname = "z71v", .config = ALC880_Z71V },
7291548d 2220 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1964, .config = ALC880_Z71V },
dfc0ff62 2221
b6482d48 2222 { .modelname = "6stack", .config = ALC880_6ST },
7632c7b4 2223 { .pci_subvendor = 0x1043, .pci_subdevice = 0x8196, .config = ALC880_6ST }, /* ASUS P5GD1-HVM */
df694daa 2224 { .pci_subvendor = 0x1043, .pci_subdevice = 0x81b4, .config = ALC880_6ST },
7a318a70 2225 { .pci_subvendor = 0x1019, .pci_subdevice = 0xa884, .config = ALC880_6ST }, /* Acer APFV */
bae2bdb3 2226 { .pci_subvendor = 0x1458, .pci_subdevice = 0xa102, .config = ALC880_6ST }, /* Gigabyte K8N51 */
b6482d48
TI
2227
2228 { .modelname = "6stack-digout", .config = ALC880_6ST_DIG },
16ded525
TI
2229 { .pci_subvendor = 0x2668, .pci_subdevice = 0x8086, .config = ALC880_6ST_DIG },
2230 { .pci_subvendor = 0x8086, .pci_subdevice = 0x2668, .config = ALC880_6ST_DIG },
2231 { .pci_subvendor = 0x1462, .pci_subdevice = 0x1150, .config = ALC880_6ST_DIG },
2232 { .pci_subvendor = 0xe803, .pci_subdevice = 0x1019, .config = ALC880_6ST_DIG },
df694daa
KY
2233 { .pci_subvendor = 0x1039, .pci_subdevice = 0x1234, .config = ALC880_6ST_DIG },
2234 { .pci_subvendor = 0x1025, .pci_subdevice = 0x0077, .config = ALC880_6ST_DIG },
2235 { .pci_subvendor = 0x1025, .pci_subdevice = 0x0078, .config = ALC880_6ST_DIG },
2236 { .pci_subvendor = 0x1025, .pci_subdevice = 0x0087, .config = ALC880_6ST_DIG },
041dec01 2237 { .pci_subvendor = 0x1297, .pci_subdevice = 0xc790, .config = ALC880_6ST_DIG }, /* Shuttle ST20G5 */
a12606cf 2238 { .pci_subvendor = 0x1509, .pci_subdevice = 0x925d, .config = ALC880_6ST_DIG }, /* FIC P4M-915GD1 */
531213a9 2239 { .pci_subvendor = 0x1695, .pci_subdevice = 0x4012, .config = ALC880_5ST_DIG }, /* Epox EP-5LDA+ GLi */
16ded525 2240
e9edcee0 2241 { .modelname = "asus", .config = ALC880_ASUS },
16ded525
TI
2242 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1964, .config = ALC880_ASUS_DIG },
2243 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1973, .config = ALC880_ASUS_DIG },
2244 { .pci_subvendor = 0x1043, .pci_subdevice = 0x19b3, .config = ALC880_ASUS_DIG },
2245 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1113, .config = ALC880_ASUS_DIG },
8648811f 2246 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1173, .config = ALC880_ASUS_DIG },
16ded525 2247 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1993, .config = ALC880_ASUS },
f5a5ffad 2248 { .pci_subvendor = 0x1043, .pci_subdevice = 0x10c2, .config = ALC880_ASUS_DIG }, /* Asus W6A */
16ded525
TI
2249 { .pci_subvendor = 0x1043, .pci_subdevice = 0x10c3, .config = ALC880_ASUS_DIG },
2250 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1133, .config = ALC880_ASUS },
2251 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1123, .config = ALC880_ASUS_DIG },
2252 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1143, .config = ALC880_ASUS },
4b146cb0 2253 { .modelname = "asus-w1v", .config = ALC880_ASUS_W1V },
16ded525 2254 { .pci_subvendor = 0x1043, .pci_subdevice = 0x10b3, .config = ALC880_ASUS_W1V },
4b146cb0 2255 { .modelname = "asus-dig", .config = ALC880_ASUS_DIG },
84f3430c 2256 { .pci_subvendor = 0x1043, .pci_subdevice = 0x8181, .config = ALC880_ASUS_DIG }, /* ASUS P4GPL-X */
4b146cb0 2257 { .modelname = "asus-dig2", .config = ALC880_ASUS_DIG2 },
df694daa 2258 { .pci_subvendor = 0x1558, .pci_subdevice = 0x5401, .config = ALC880_ASUS_DIG2 },
16ded525
TI
2259
2260 { .modelname = "uniwill", .config = ALC880_UNIWILL_DIG },
2261 { .pci_subvendor = 0x1584, .pci_subdevice = 0x9050, .config = ALC880_UNIWILL_DIG },
2262
2263 { .modelname = "F1734", .config = ALC880_F1734 },
2264 { .pci_subvendor = 0x1734, .pci_subdevice = 0x107c, .config = ALC880_F1734 },
df694daa 2265 { .pci_subvendor = 0x1584, .pci_subdevice = 0x9054, .config = ALC880_F1734 },
16ded525 2266
ae6b813a
TI
2267 { .modelname = "lg", .config = ALC880_LG },
2268 { .pci_subvendor = 0x1854, .pci_subdevice = 0x003b, .config = ALC880_LG },
886da867 2269 { .pci_subvendor = 0x1854, .pci_subdevice = 0x0068, .config = ALC880_LG },
ae6b813a 2270
d681518a
TI
2271 { .modelname = "lg-lw", .config = ALC880_LG_LW },
2272 { .pci_subvendor = 0x1854, .pci_subdevice = 0x0018, .config = ALC880_LG_LW },
cd417d4f 2273 { .pci_subvendor = 0x1854, .pci_subdevice = 0x0077, .config = ALC880_LG_LW },
d681518a 2274
2fa522be
TI
2275#ifdef CONFIG_SND_DEBUG
2276 { .modelname = "test", .config = ALC880_TEST },
2277#endif
df694daa 2278 { .modelname = "auto", .config = ALC880_AUTO },
2fa522be 2279
1da177e4
LT
2280 {}
2281};
2282
16ded525 2283/*
df694daa 2284 * ALC880 codec presets
16ded525 2285 */
16ded525
TI
2286static struct alc_config_preset alc880_presets[] = {
2287 [ALC880_3ST] = {
e9edcee0
TI
2288 .mixers = { alc880_three_stack_mixer },
2289 .init_verbs = { alc880_volume_init_verbs, alc880_pin_3stack_init_verbs },
16ded525 2290 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
16ded525 2291 .dac_nids = alc880_dac_nids,
16ded525
TI
2292 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2293 .channel_mode = alc880_threestack_modes,
4e195a7b 2294 .need_dac_fix = 1,
16ded525
TI
2295 .input_mux = &alc880_capture_source,
2296 },
2297 [ALC880_3ST_DIG] = {
e9edcee0
TI
2298 .mixers = { alc880_three_stack_mixer },
2299 .init_verbs = { alc880_volume_init_verbs, alc880_pin_3stack_init_verbs },
16ded525 2300 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
16ded525
TI
2301 .dac_nids = alc880_dac_nids,
2302 .dig_out_nid = ALC880_DIGOUT_NID,
16ded525
TI
2303 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2304 .channel_mode = alc880_threestack_modes,
4e195a7b 2305 .need_dac_fix = 1,
16ded525
TI
2306 .input_mux = &alc880_capture_source,
2307 },
df694daa
KY
2308 [ALC880_TCL_S700] = {
2309 .mixers = { alc880_tcl_s700_mixer },
2310 .init_verbs = { alc880_volume_init_verbs,
2311 alc880_pin_tcl_S700_init_verbs,
2312 alc880_gpio2_init_verbs },
2313 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2314 .dac_nids = alc880_dac_nids,
2315 .hp_nid = 0x03,
2316 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2317 .channel_mode = alc880_2_jack_modes,
2318 .input_mux = &alc880_capture_source,
2319 },
16ded525 2320 [ALC880_5ST] = {
e9edcee0
TI
2321 .mixers = { alc880_three_stack_mixer, alc880_five_stack_mixer},
2322 .init_verbs = { alc880_volume_init_verbs, alc880_pin_5stack_init_verbs },
16ded525
TI
2323 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2324 .dac_nids = alc880_dac_nids,
16ded525
TI
2325 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2326 .channel_mode = alc880_fivestack_modes,
2327 .input_mux = &alc880_capture_source,
2328 },
2329 [ALC880_5ST_DIG] = {
e9edcee0
TI
2330 .mixers = { alc880_three_stack_mixer, alc880_five_stack_mixer },
2331 .init_verbs = { alc880_volume_init_verbs, alc880_pin_5stack_init_verbs },
16ded525
TI
2332 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2333 .dac_nids = alc880_dac_nids,
2334 .dig_out_nid = ALC880_DIGOUT_NID,
16ded525
TI
2335 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2336 .channel_mode = alc880_fivestack_modes,
2337 .input_mux = &alc880_capture_source,
2338 },
b6482d48
TI
2339 [ALC880_6ST] = {
2340 .mixers = { alc880_six_stack_mixer },
2341 .init_verbs = { alc880_volume_init_verbs, alc880_pin_6stack_init_verbs },
2342 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2343 .dac_nids = alc880_6st_dac_nids,
2344 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2345 .channel_mode = alc880_sixstack_modes,
2346 .input_mux = &alc880_6stack_capture_source,
2347 },
16ded525 2348 [ALC880_6ST_DIG] = {
e9edcee0
TI
2349 .mixers = { alc880_six_stack_mixer },
2350 .init_verbs = { alc880_volume_init_verbs, alc880_pin_6stack_init_verbs },
16ded525
TI
2351 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2352 .dac_nids = alc880_6st_dac_nids,
2353 .dig_out_nid = ALC880_DIGOUT_NID,
16ded525
TI
2354 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2355 .channel_mode = alc880_sixstack_modes,
2356 .input_mux = &alc880_6stack_capture_source,
2357 },
2358 [ALC880_W810] = {
e9edcee0 2359 .mixers = { alc880_w810_base_mixer },
b0af0de5
TI
2360 .init_verbs = { alc880_volume_init_verbs, alc880_pin_w810_init_verbs,
2361 alc880_gpio2_init_verbs },
16ded525
TI
2362 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
2363 .dac_nids = alc880_w810_dac_nids,
2364 .dig_out_nid = ALC880_DIGOUT_NID,
16ded525
TI
2365 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
2366 .channel_mode = alc880_w810_modes,
2367 .input_mux = &alc880_capture_source,
2368 },
2369 [ALC880_Z71V] = {
e9edcee0 2370 .mixers = { alc880_z71v_mixer },
b0af0de5 2371 .init_verbs = { alc880_volume_init_verbs, alc880_pin_z71v_init_verbs },
16ded525
TI
2372 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
2373 .dac_nids = alc880_z71v_dac_nids,
2374 .dig_out_nid = ALC880_DIGOUT_NID,
2375 .hp_nid = 0x03,
e9edcee0
TI
2376 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2377 .channel_mode = alc880_2_jack_modes,
16ded525
TI
2378 .input_mux = &alc880_capture_source,
2379 },
2380 [ALC880_F1734] = {
e9edcee0
TI
2381 .mixers = { alc880_f1734_mixer },
2382 .init_verbs = { alc880_volume_init_verbs, alc880_pin_f1734_init_verbs },
2383 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
2384 .dac_nids = alc880_f1734_dac_nids,
2385 .hp_nid = 0x02,
2386 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2387 .channel_mode = alc880_2_jack_modes,
16ded525
TI
2388 .input_mux = &alc880_capture_source,
2389 },
2390 [ALC880_ASUS] = {
e9edcee0
TI
2391 .mixers = { alc880_asus_mixer },
2392 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
2393 alc880_gpio1_init_verbs },
2394 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2395 .dac_nids = alc880_asus_dac_nids,
2396 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2397 .channel_mode = alc880_asus_modes,
4e195a7b 2398 .need_dac_fix = 1,
16ded525
TI
2399 .input_mux = &alc880_capture_source,
2400 },
2401 [ALC880_ASUS_DIG] = {
e9edcee0
TI
2402 .mixers = { alc880_asus_mixer },
2403 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
2404 alc880_gpio1_init_verbs },
2405 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2406 .dac_nids = alc880_asus_dac_nids,
16ded525 2407 .dig_out_nid = ALC880_DIGOUT_NID,
e9edcee0
TI
2408 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2409 .channel_mode = alc880_asus_modes,
4e195a7b 2410 .need_dac_fix = 1,
16ded525
TI
2411 .input_mux = &alc880_capture_source,
2412 },
df694daa
KY
2413 [ALC880_ASUS_DIG2] = {
2414 .mixers = { alc880_asus_mixer },
2415 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
2416 alc880_gpio2_init_verbs }, /* use GPIO2 */
2417 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2418 .dac_nids = alc880_asus_dac_nids,
2419 .dig_out_nid = ALC880_DIGOUT_NID,
2420 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2421 .channel_mode = alc880_asus_modes,
4e195a7b 2422 .need_dac_fix = 1,
df694daa
KY
2423 .input_mux = &alc880_capture_source,
2424 },
16ded525 2425 [ALC880_ASUS_W1V] = {
e9edcee0
TI
2426 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
2427 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
2428 alc880_gpio1_init_verbs },
2429 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2430 .dac_nids = alc880_asus_dac_nids,
16ded525 2431 .dig_out_nid = ALC880_DIGOUT_NID,
e9edcee0
TI
2432 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2433 .channel_mode = alc880_asus_modes,
4e195a7b 2434 .need_dac_fix = 1,
16ded525
TI
2435 .input_mux = &alc880_capture_source,
2436 },
2437 [ALC880_UNIWILL_DIG] = {
3c10a9d9 2438 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
e9edcee0
TI
2439 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs },
2440 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2441 .dac_nids = alc880_asus_dac_nids,
16ded525 2442 .dig_out_nid = ALC880_DIGOUT_NID,
e9edcee0
TI
2443 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2444 .channel_mode = alc880_asus_modes,
4e195a7b 2445 .need_dac_fix = 1,
16ded525
TI
2446 .input_mux = &alc880_capture_source,
2447 },
df694daa
KY
2448 [ALC880_CLEVO] = {
2449 .mixers = { alc880_three_stack_mixer },
2450 .init_verbs = { alc880_volume_init_verbs,
2451 alc880_pin_clevo_init_verbs },
2452 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2453 .dac_nids = alc880_dac_nids,
2454 .hp_nid = 0x03,
2455 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2456 .channel_mode = alc880_threestack_modes,
4e195a7b 2457 .need_dac_fix = 1,
df694daa
KY
2458 .input_mux = &alc880_capture_source,
2459 },
ae6b813a
TI
2460 [ALC880_LG] = {
2461 .mixers = { alc880_lg_mixer },
2462 .init_verbs = { alc880_volume_init_verbs,
2463 alc880_lg_init_verbs },
2464 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
2465 .dac_nids = alc880_lg_dac_nids,
2466 .dig_out_nid = ALC880_DIGOUT_NID,
2467 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
2468 .channel_mode = alc880_lg_ch_modes,
4e195a7b 2469 .need_dac_fix = 1,
ae6b813a
TI
2470 .input_mux = &alc880_lg_capture_source,
2471 .unsol_event = alc880_lg_unsol_event,
2472 .init_hook = alc880_lg_automute,
2473 },
d681518a
TI
2474 [ALC880_LG_LW] = {
2475 .mixers = { alc880_lg_lw_mixer },
2476 .init_verbs = { alc880_volume_init_verbs,
2477 alc880_lg_lw_init_verbs },
2478 .num_dacs = 1,
2479 .dac_nids = alc880_dac_nids,
2480 .dig_out_nid = ALC880_DIGOUT_NID,
2481 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2482 .channel_mode = alc880_2_jack_modes,
2483 .input_mux = &alc880_lg_lw_capture_source,
2484 .unsol_event = alc880_lg_lw_unsol_event,
2485 .init_hook = alc880_lg_lw_automute,
2486 },
16ded525
TI
2487#ifdef CONFIG_SND_DEBUG
2488 [ALC880_TEST] = {
e9edcee0
TI
2489 .mixers = { alc880_test_mixer },
2490 .init_verbs = { alc880_test_init_verbs },
16ded525
TI
2491 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
2492 .dac_nids = alc880_test_dac_nids,
2493 .dig_out_nid = ALC880_DIGOUT_NID,
16ded525
TI
2494 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
2495 .channel_mode = alc880_test_modes,
2496 .input_mux = &alc880_test_capture_source,
2497 },
2498#endif
2499};
2500
e9edcee0
TI
2501/*
2502 * Automatic parse of I/O pins from the BIOS configuration
2503 */
2504
2505#define NUM_CONTROL_ALLOC 32
2506#define NUM_VERB_ALLOC 32
2507
2508enum {
2509 ALC_CTL_WIDGET_VOL,
2510 ALC_CTL_WIDGET_MUTE,
2511 ALC_CTL_BIND_MUTE,
2512};
c8b6bf9b 2513static struct snd_kcontrol_new alc880_control_templates[] = {
e9edcee0
TI
2514 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2515 HDA_CODEC_MUTE(NULL, 0, 0, 0),
985be54b 2516 HDA_BIND_MUTE(NULL, 0, 0, 0),
e9edcee0
TI
2517};
2518
2519/* add dynamic controls */
2520static int add_control(struct alc_spec *spec, int type, const char *name, unsigned long val)
2521{
c8b6bf9b 2522 struct snd_kcontrol_new *knew;
e9edcee0
TI
2523
2524 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2525 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2526
2527 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2528 if (! knew)
2529 return -ENOMEM;
2530 if (spec->kctl_alloc) {
2531 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2532 kfree(spec->kctl_alloc);
2533 }
2534 spec->kctl_alloc = knew;
2535 spec->num_kctl_alloc = num;
2536 }
2537
2538 knew = &spec->kctl_alloc[spec->num_kctl_used];
2539 *knew = alc880_control_templates[type];
543537bd 2540 knew->name = kstrdup(name, GFP_KERNEL);
e9edcee0
TI
2541 if (! knew->name)
2542 return -ENOMEM;
2543 knew->private_value = val;
2544 spec->num_kctl_used++;
2545 return 0;
2546}
2547
2548#define alc880_is_fixed_pin(nid) ((nid) >= 0x14 && (nid) <= 0x17)
2549#define alc880_fixed_pin_idx(nid) ((nid) - 0x14)
2550#define alc880_is_multi_pin(nid) ((nid) >= 0x18)
2551#define alc880_multi_pin_idx(nid) ((nid) - 0x18)
2552#define alc880_is_input_pin(nid) ((nid) >= 0x18)
2553#define alc880_input_pin_idx(nid) ((nid) - 0x18)
2554#define alc880_idx_to_dac(nid) ((nid) + 0x02)
2555#define alc880_dac_to_idx(nid) ((nid) - 0x02)
2556#define alc880_idx_to_mixer(nid) ((nid) + 0x0c)
2557#define alc880_idx_to_selector(nid) ((nid) + 0x10)
2558#define ALC880_PIN_CD_NID 0x1c
2559
2560/* fill in the dac_nids table from the parsed pin configuration */
2561static int alc880_auto_fill_dac_nids(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
2562{
2563 hda_nid_t nid;
2564 int assigned[4];
2565 int i, j;
2566
2567 memset(assigned, 0, sizeof(assigned));
b0af0de5 2568 spec->multiout.dac_nids = spec->private_dac_nids;
e9edcee0
TI
2569
2570 /* check the pins hardwired to audio widget */
2571 for (i = 0; i < cfg->line_outs; i++) {
2572 nid = cfg->line_out_pins[i];
2573 if (alc880_is_fixed_pin(nid)) {
2574 int idx = alc880_fixed_pin_idx(nid);
5014f193 2575 spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
e9edcee0
TI
2576 assigned[idx] = 1;
2577 }
2578 }
2579 /* left pins can be connect to any audio widget */
2580 for (i = 0; i < cfg->line_outs; i++) {
2581 nid = cfg->line_out_pins[i];
2582 if (alc880_is_fixed_pin(nid))
2583 continue;
2584 /* search for an empty channel */
2585 for (j = 0; j < cfg->line_outs; j++) {
2586 if (! assigned[j]) {
2587 spec->multiout.dac_nids[i] = alc880_idx_to_dac(j);
2588 assigned[j] = 1;
2589 break;
2590 }
2591 }
2592 }
2593 spec->multiout.num_dacs = cfg->line_outs;
2594 return 0;
2595}
2596
2597/* add playback controls from the parsed DAC table */
df694daa
KY
2598static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
2599 const struct auto_pin_cfg *cfg)
e9edcee0
TI
2600{
2601 char name[32];
2602 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2603 hda_nid_t nid;
2604 int i, err;
2605
2606 for (i = 0; i < cfg->line_outs; i++) {
2607 if (! spec->multiout.dac_nids[i])
2608 continue;
2609 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
2610 if (i == 2) {
2611 /* Center/LFE */
2612 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Center Playback Volume",
2613 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
2614 return err;
2615 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "LFE Playback Volume",
2616 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
2617 return err;
2618 if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "Center Playback Switch",
2619 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT))) < 0)
2620 return err;
2621 if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "LFE Playback Switch",
2622 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT))) < 0)
2623 return err;
2624 } else {
2625 sprintf(name, "%s Playback Volume", chname[i]);
2626 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
2627 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2628 return err;
2629 sprintf(name, "%s Playback Switch", chname[i]);
2630 if ((err = add_control(spec, ALC_CTL_BIND_MUTE, name,
2631 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2632 return err;
2633 }
2634 }
e9edcee0
TI
2635 return 0;
2636}
2637
8d88bc3d
TI
2638/* add playback controls for speaker and HP outputs */
2639static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
2640 const char *pfx)
e9edcee0
TI
2641{
2642 hda_nid_t nid;
2643 int err;
8d88bc3d 2644 char name[32];
e9edcee0
TI
2645
2646 if (! pin)
2647 return 0;
2648
2649 if (alc880_is_fixed_pin(pin)) {
2650 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
82bc955f
TI
2651 /* specify the DAC as the extra output */
2652 if (! spec->multiout.hp_nid)
e9edcee0 2653 spec->multiout.hp_nid = nid;
82bc955f
TI
2654 else
2655 spec->multiout.extra_out_nid[0] = nid;
e9edcee0
TI
2656 /* control HP volume/switch on the output mixer amp */
2657 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
8d88bc3d
TI
2658 sprintf(name, "%s Playback Volume", pfx);
2659 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
e9edcee0
TI
2660 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2661 return err;
8d88bc3d
TI
2662 sprintf(name, "%s Playback Switch", pfx);
2663 if ((err = add_control(spec, ALC_CTL_BIND_MUTE, name,
e9edcee0
TI
2664 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2665 return err;
2666 } else if (alc880_is_multi_pin(pin)) {
2667 /* set manual connection */
e9edcee0 2668 /* we have only a switch on HP-out PIN */
8d88bc3d
TI
2669 sprintf(name, "%s Playback Switch", pfx);
2670 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
e9edcee0
TI
2671 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT))) < 0)
2672 return err;
2673 }
2674 return 0;
2675}
2676
2677/* create input playback/capture controls for the given pin */
df694daa
KY
2678static int new_analog_input(struct alc_spec *spec, hda_nid_t pin, const char *ctlname,
2679 int idx, hda_nid_t mix_nid)
e9edcee0
TI
2680{
2681 char name[32];
df694daa 2682 int err;
e9edcee0
TI
2683
2684 sprintf(name, "%s Playback Volume", ctlname);
e9edcee0 2685 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
df694daa 2686 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT))) < 0)
e9edcee0
TI
2687 return err;
2688 sprintf(name, "%s Playback Switch", ctlname);
2689 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
df694daa 2690 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT))) < 0)
e9edcee0
TI
2691 return err;
2692 return 0;
2693}
2694
2695/* create playback/capture controls for input pins */
df694daa
KY
2696static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
2697 const struct auto_pin_cfg *cfg)
e9edcee0 2698{
e9edcee0 2699 struct hda_input_mux *imux = &spec->private_imux;
df694daa 2700 int i, err, idx;
e9edcee0
TI
2701
2702 for (i = 0; i < AUTO_PIN_LAST; i++) {
2703 if (alc880_is_input_pin(cfg->input_pins[i])) {
df694daa 2704 idx = alc880_input_pin_idx(cfg->input_pins[i]);
4a471b7d
TI
2705 err = new_analog_input(spec, cfg->input_pins[i],
2706 auto_pin_cfg_labels[i],
df694daa 2707 idx, 0x0b);
e9edcee0
TI
2708 if (err < 0)
2709 return err;
4a471b7d 2710 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
e9edcee0
TI
2711 imux->items[imux->num_items].index = alc880_input_pin_idx(cfg->input_pins[i]);
2712 imux->num_items++;
2713 }
2714 }
2715 return 0;
2716}
2717
df694daa
KY
2718static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
2719 hda_nid_t nid, int pin_type,
e9edcee0
TI
2720 int dac_idx)
2721{
2722 /* set as output */
2723 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2724 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2725 /* need the manual connection? */
2726 if (alc880_is_multi_pin(nid)) {
2727 struct alc_spec *spec = codec->spec;
2728 int idx = alc880_multi_pin_idx(nid);
2729 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
2730 AC_VERB_SET_CONNECT_SEL,
2731 alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
2732 }
2733}
2734
2735static void alc880_auto_init_multi_out(struct hda_codec *codec)
2736{
2737 struct alc_spec *spec = codec->spec;
2738 int i;
2739
2740 for (i = 0; i < spec->autocfg.line_outs; i++) {
2741 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2742 alc880_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2743 }
2744}
2745
8d88bc3d 2746static void alc880_auto_init_extra_out(struct hda_codec *codec)
e9edcee0
TI
2747{
2748 struct alc_spec *spec = codec->spec;
2749 hda_nid_t pin;
2750
82bc955f 2751 pin = spec->autocfg.speaker_pins[0];
8d88bc3d
TI
2752 if (pin) /* connect to front */
2753 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
e9edcee0
TI
2754 pin = spec->autocfg.hp_pin;
2755 if (pin) /* connect to front */
2756 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2757}
2758
2759static void alc880_auto_init_analog_input(struct hda_codec *codec)
2760{
2761 struct alc_spec *spec = codec->spec;
2762 int i;
2763
2764 for (i = 0; i < AUTO_PIN_LAST; i++) {
2765 hda_nid_t nid = spec->autocfg.input_pins[i];
2766 if (alc880_is_input_pin(nid)) {
2767 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2768 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2769 if (nid != ALC880_PIN_CD_NID)
2770 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2771 AMP_OUT_MUTE);
2772 }
2773 }
2774}
2775
2776/* parse the BIOS configuration and set up the alc_spec */
2777/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2778static int alc880_parse_auto_config(struct hda_codec *codec)
2779{
2780 struct alc_spec *spec = codec->spec;
2781 int err;
df694daa 2782 static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
e9edcee0 2783
df694daa
KY
2784 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
2785 alc880_ignore)) < 0)
e9edcee0 2786 return err;
82bc955f 2787 if (! spec->autocfg.line_outs)
e9edcee0 2788 return 0; /* can't find valid BIOS pin config */
df694daa
KY
2789
2790 if ((err = alc880_auto_fill_dac_nids(spec, &spec->autocfg)) < 0 ||
2791 (err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
82bc955f
TI
2792 (err = alc880_auto_create_extra_out(spec,
2793 spec->autocfg.speaker_pins[0],
8d88bc3d 2794 "Speaker")) < 0 ||
82bc955f 2795 (err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pin,
8d88bc3d 2796 "Headphone")) < 0 ||
e9edcee0
TI
2797 (err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2798 return err;
2799
2800 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2801
2802 if (spec->autocfg.dig_out_pin)
2803 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
2804 if (spec->autocfg.dig_in_pin)
2805 spec->dig_in_nid = ALC880_DIGIN_NID;
2806
2807 if (spec->kctl_alloc)
2808 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2809
2810 spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
2811
a1e8d2da 2812 spec->num_mux_defs = 1;
e9edcee0
TI
2813 spec->input_mux = &spec->private_imux;
2814
2815 return 1;
2816}
2817
ae6b813a
TI
2818/* additional initialization for auto-configuration model */
2819static void alc880_auto_init(struct hda_codec *codec)
e9edcee0 2820{
e9edcee0 2821 alc880_auto_init_multi_out(codec);
8d88bc3d 2822 alc880_auto_init_extra_out(codec);
e9edcee0 2823 alc880_auto_init_analog_input(codec);
e9edcee0
TI
2824}
2825
2826/*
2827 * OK, here we have finally the patch for ALC880
2828 */
2829
1da177e4
LT
2830static int patch_alc880(struct hda_codec *codec)
2831{
2832 struct alc_spec *spec;
2833 int board_config;
df694daa 2834 int err;
1da177e4 2835
e560d8d8 2836 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1da177e4
LT
2837 if (spec == NULL)
2838 return -ENOMEM;
2839
2840 codec->spec = spec;
2841
2842 board_config = snd_hda_check_board_config(codec, alc880_cfg_tbl);
16ded525 2843 if (board_config < 0 || board_config >= ALC880_MODEL_LAST) {
9c7f852e
TI
2844 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
2845 "trying auto-probe from BIOS...\n");
e9edcee0 2846 board_config = ALC880_AUTO;
1da177e4 2847 }
1da177e4 2848
e9edcee0
TI
2849 if (board_config == ALC880_AUTO) {
2850 /* automatic parse from the BIOS config */
2851 err = alc880_parse_auto_config(codec);
2852 if (err < 0) {
2853 alc_free(codec);
2854 return err;
2855 } else if (! err) {
9c7f852e
TI
2856 printk(KERN_INFO
2857 "hda_codec: Cannot set up configuration "
2858 "from BIOS. Using 3-stack mode...\n");
e9edcee0
TI
2859 board_config = ALC880_3ST;
2860 }
1da177e4
LT
2861 }
2862
df694daa
KY
2863 if (board_config != ALC880_AUTO)
2864 setup_preset(spec, &alc880_presets[board_config]);
1da177e4
LT
2865
2866 spec->stream_name_analog = "ALC880 Analog";
2867 spec->stream_analog_playback = &alc880_pcm_analog_playback;
2868 spec->stream_analog_capture = &alc880_pcm_analog_capture;
2869
2870 spec->stream_name_digital = "ALC880 Digital";
2871 spec->stream_digital_playback = &alc880_pcm_digital_playback;
2872 spec->stream_digital_capture = &alc880_pcm_digital_capture;
2873
e9edcee0
TI
2874 if (! spec->adc_nids && spec->input_mux) {
2875 /* check whether NID 0x07 is valid */
54d17403 2876 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
e9edcee0
TI
2877 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
2878 if (wcap != AC_WID_AUD_IN) {
2879 spec->adc_nids = alc880_adc_nids_alt;
2880 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
2881 spec->mixers[spec->num_mixers] = alc880_capture_alt_mixer;
2882 spec->num_mixers++;
2883 } else {
2884 spec->adc_nids = alc880_adc_nids;
2885 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
2886 spec->mixers[spec->num_mixers] = alc880_capture_mixer;
2887 spec->num_mixers++;
2888 }
2889 }
1da177e4
LT
2890
2891 codec->patch_ops = alc_patch_ops;
e9edcee0 2892 if (board_config == ALC880_AUTO)
ae6b813a 2893 spec->init_hook = alc880_auto_init;
1da177e4
LT
2894
2895 return 0;
2896}
2897
e9edcee0 2898
1da177e4
LT
2899/*
2900 * ALC260 support
2901 */
2902
e9edcee0
TI
2903static hda_nid_t alc260_dac_nids[1] = {
2904 /* front */
2905 0x02,
2906};
2907
2908static hda_nid_t alc260_adc_nids[1] = {
2909 /* ADC0 */
2910 0x04,
2911};
2912
df694daa 2913static hda_nid_t alc260_adc_nids_alt[1] = {
e9edcee0
TI
2914 /* ADC1 */
2915 0x05,
2916};
2917
df694daa
KY
2918static hda_nid_t alc260_hp_adc_nids[2] = {
2919 /* ADC1, 0 */
2920 0x05, 0x04
2921};
2922
d57fdac0
JW
2923/* NIDs used when simultaneous access to both ADCs makes sense. Note that
2924 * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
2925 */
2926static hda_nid_t alc260_dual_adc_nids[2] = {
4c5186ed
JW
2927 /* ADC0, ADC1 */
2928 0x04, 0x05
2929};
2930
e9edcee0
TI
2931#define ALC260_DIGOUT_NID 0x03
2932#define ALC260_DIGIN_NID 0x06
2933
2934static struct hda_input_mux alc260_capture_source = {
2935 .num_items = 4,
2936 .items = {
2937 { "Mic", 0x0 },
2938 { "Front Mic", 0x1 },
2939 { "Line", 0x2 },
2940 { "CD", 0x4 },
2941 },
2942};
2943
17e7aec6 2944/* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
a1e8d2da
JW
2945 * headphone jack and the internal CD lines since these are the only pins at
2946 * which audio can appear. For flexibility, also allow the option of
2947 * recording the mixer output on the second ADC (ADC0 doesn't have a
2948 * connection to the mixer output).
a9430dd8 2949 */
a1e8d2da
JW
2950static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
2951 {
2952 .num_items = 3,
2953 .items = {
2954 { "Mic/Line", 0x0 },
2955 { "CD", 0x4 },
2956 { "Headphone", 0x2 },
2957 },
a9430dd8 2958 },
a1e8d2da
JW
2959 {
2960 .num_items = 4,
2961 .items = {
2962 { "Mic/Line", 0x0 },
2963 { "CD", 0x4 },
2964 { "Headphone", 0x2 },
2965 { "Mixer", 0x5 },
2966 },
2967 },
2968
a9430dd8
JW
2969};
2970
a1e8d2da
JW
2971/* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
2972 * the Fujitsu S702x, but jacks are marked differently.
0bfc90e9 2973 */
a1e8d2da
JW
2974static struct hda_input_mux alc260_acer_capture_sources[2] = {
2975 {
2976 .num_items = 4,
2977 .items = {
2978 { "Mic", 0x0 },
2979 { "Line", 0x2 },
2980 { "CD", 0x4 },
2981 { "Headphone", 0x5 },
2982 },
2983 },
2984 {
2985 .num_items = 5,
2986 .items = {
2987 { "Mic", 0x0 },
2988 { "Line", 0x2 },
2989 { "CD", 0x4 },
2990 { "Headphone", 0x6 },
2991 { "Mixer", 0x5 },
2992 },
0bfc90e9
JW
2993 },
2994};
1da177e4
LT
2995/*
2996 * This is just place-holder, so there's something for alc_build_pcms to look
2997 * at when it calculates the maximum number of channels. ALC260 has no mixer
2998 * element which allows changing the channel mode, so the verb list is
2999 * never used.
3000 */
d2a6d7dc 3001static struct hda_channel_mode alc260_modes[1] = {
1da177e4
LT
3002 { 2, NULL },
3003};
3004
df694daa
KY
3005
3006/* Mixer combinations
3007 *
3008 * basic: base_output + input + pc_beep + capture
3009 * HP: base_output + input + capture_alt
3010 * HP_3013: hp_3013 + input + capture
3011 * fujitsu: fujitsu + capture
0bfc90e9 3012 * acer: acer + capture
df694daa
KY
3013 */
3014
3015static struct snd_kcontrol_new alc260_base_output_mixer[] = {
05acb863 3016 HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
985be54b 3017 HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
05acb863 3018 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
985be54b 3019 HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
05acb863 3020 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
985be54b 3021 HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
1da177e4 3022 { } /* end */
df694daa 3023};
1da177e4 3024
df694daa 3025static struct snd_kcontrol_new alc260_input_mixer[] = {
16ded525
TI
3026 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3027 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3028 HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3029 HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3030 HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3031 HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3032 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
3033 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
df694daa
KY
3034 { } /* end */
3035};
3036
3037static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
3038 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
3039 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
3040 { } /* end */
3041};
3042
3043static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
3044 HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3045 HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3046 HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
3047 HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
3048 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3049 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3050 HDA_CODEC_VOLUME_MONO("iSpeaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3051 HDA_CODEC_MUTE_MONO("iSpeaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
16ded525
TI
3052 { } /* end */
3053};
3054
a1e8d2da
JW
3055/* Fujitsu S702x series laptops. ALC260 pin usage: Mic/Line jack = 0x12,
3056 * HP jack = 0x14, CD audio = 0x16, internal speaker = 0x10.
3057 */
c8b6bf9b 3058static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
a9430dd8 3059 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
985be54b 3060 HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4c5186ed 3061 ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
a9430dd8
JW
3062 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3063 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3064 HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
3065 HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4c5186ed 3066 ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
a9430dd8
JW
3067 HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3068 HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3069 HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
985be54b 3070 HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
df694daa
KY
3071 { } /* end */
3072};
3073
a1e8d2da
JW
3074/* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks. Note that current
3075 * versions of the ALC260 don't act on requests to enable mic bias from NID
3076 * 0x0f (used to drive the headphone jack in these laptops). The ALC260
3077 * datasheet doesn't mention this restriction. At this stage it's not clear
3078 * whether this behaviour is intentional or is a hardware bug in chip
3079 * revisions available in early 2006. Therefore for now allow the
3080 * "Headphone Jack Mode" control to span all choices, but if it turns out
3081 * that the lack of mic bias for this NID is intentional we could change the
3082 * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
3083 *
3084 * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
3085 * don't appear to make the mic bias available from the "line" jack, even
3086 * though the NID used for this jack (0x14) can supply it. The theory is
3087 * that perhaps Acer have included blocking capacitors between the ALC260
3088 * and the output jack. If this turns out to be the case for all such
3089 * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
3090 * to ALC_PIN_DIR_INOUT_NOMICBIAS.
3091 */
0bfc90e9
JW
3092static struct snd_kcontrol_new alc260_acer_mixer[] = {
3093 HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3094 HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
a1e8d2da 3095 ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
0bfc90e9
JW
3096 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3097 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3098 HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3099 HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3100 ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3101 HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3102 HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3103 ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3104 HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3105 HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3106 { } /* end */
3107};
3108
df694daa
KY
3109/* capture mixer elements */
3110static struct snd_kcontrol_new alc260_capture_mixer[] = {
a9430dd8
JW
3111 HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
3112 HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
df694daa
KY
3113 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
3114 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
a9430dd8
JW
3115 {
3116 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
df694daa
KY
3117 /* The multiple "Capture Source" controls confuse alsamixer
3118 * So call somewhat different..
3119 * FIXME: the controls appear in the "playback" view!
3120 */
3121 /* .name = "Capture Source", */
3122 .name = "Input Source",
3123 .count = 2,
3124 .info = alc_mux_enum_info,
3125 .get = alc_mux_enum_get,
3126 .put = alc_mux_enum_put,
3127 },
3128 { } /* end */
3129};
3130
3131static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
3132 HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
3133 HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
3134 {
3135 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3136 /* The multiple "Capture Source" controls confuse alsamixer
3137 * So call somewhat different..
3138 * FIXME: the controls appear in the "playback" view!
3139 */
3140 /* .name = "Capture Source", */
3141 .name = "Input Source",
3142 .count = 1,
a9430dd8
JW
3143 .info = alc_mux_enum_info,
3144 .get = alc_mux_enum_get,
3145 .put = alc_mux_enum_put,
3146 },
3147 { } /* end */
3148};
3149
df694daa
KY
3150/*
3151 * initialization verbs
3152 */
1da177e4
LT
3153static struct hda_verb alc260_init_verbs[] = {
3154 /* Line In pin widget for input */
05acb863 3155 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1da177e4 3156 /* CD pin widget for input */
05acb863 3157 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1da177e4 3158 /* Mic1 (rear panel) pin widget for input and vref at 80% */
16ded525 3159 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1da177e4 3160 /* Mic2 (front panel) pin widget for input and vref at 80% */
16ded525 3161 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1da177e4 3162 /* LINE-2 is used for line-out in rear */
05acb863 3163 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1da177e4 3164 /* select line-out */
fd56f2db 3165 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
1da177e4 3166 /* LINE-OUT pin */
05acb863 3167 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1da177e4 3168 /* enable HP */
05acb863 3169 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1da177e4 3170 /* enable Mono */
05acb863
TI
3171 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3172 /* mute capture amp left and right */
16ded525 3173 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1da177e4
LT
3174 /* set connection select to line in (default select for this ADC) */
3175 {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
16ded525
TI
3176 /* mute capture amp left and right */
3177 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3178 /* set connection select to line in (default select for this ADC) */
3179 {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
05acb863
TI
3180 /* set vol=0 Line-Out mixer amp left and right */
3181 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3182 /* unmute pin widget amp left and right (no gain on this amp) */
3183 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3184 /* set vol=0 HP mixer amp left and right */
3185 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3186 /* unmute pin widget amp left and right (no gain on this amp) */
3187 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3188 /* set vol=0 Mono mixer amp left and right */
3189 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3190 /* unmute pin widget amp left and right (no gain on this amp) */
3191 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3192 /* unmute LINE-2 out pin */
3193 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1da177e4 3194 /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 & Line In 2 = 0x03 */
05acb863 3195 /* mute CD */
16ded525 3196 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
05acb863 3197 /* mute Line In */
16ded525 3198 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
05acb863 3199 /* mute Mic */
16ded525 3200 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1da177e4 3201 /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
05acb863
TI
3202 /* mute Front out path */
3203 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3204 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3205 /* mute Headphone out path */
3206 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3207 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3208 /* mute Mono out path */
3209 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3210 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1da177e4
LT
3211 { }
3212};
3213
474167d6 3214#if 0 /* should be identical with alc260_init_verbs? */
df694daa
KY
3215static struct hda_verb alc260_hp_init_verbs[] = {
3216 /* Headphone and output */
3217 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3218 /* mono output */
3219 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3220 /* Mic1 (rear panel) pin widget for input and vref at 80% */
3221 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3222 /* Mic2 (front panel) pin widget for input and vref at 80% */
3223 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3224 /* Line In pin widget for input */
3225 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3226 /* Line-2 pin widget for output */
3227 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3228 /* CD pin widget for input */
3229 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3230 /* unmute amp left and right */
3231 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3232 /* set connection select to line in (default select for this ADC) */
3233 {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3234 /* unmute Line-Out mixer amp left and right (volume = 0) */
3235 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3236 /* mute pin widget amp left and right (no gain on this amp) */
3237 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3238 /* unmute HP mixer amp left and right (volume = 0) */
3239 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3240 /* mute pin widget amp left and right (no gain on this amp) */
3241 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3242 /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 & Line In 2 = 0x03 */
3243 /* unmute CD */
3244 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
3245 /* unmute Line In */
3246 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
3247 /* unmute Mic */
3248 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3249 /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3250 /* Unmute Front out path */
3251 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3252 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3253 /* Unmute Headphone out path */
3254 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3255 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3256 /* Unmute Mono out path */
3257 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3258 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3259 { }
3260};
474167d6 3261#endif
df694daa
KY
3262
3263static struct hda_verb alc260_hp_3013_init_verbs[] = {
3264 /* Line out and output */
3265 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3266 /* mono output */
3267 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3268 /* Mic1 (rear panel) pin widget for input and vref at 80% */
3269 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3270 /* Mic2 (front panel) pin widget for input and vref at 80% */
3271 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3272 /* Line In pin widget for input */
3273 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3274 /* Headphone pin widget for output */
3275 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3276 /* CD pin widget for input */
3277 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3278 /* unmute amp left and right */
3279 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3280 /* set connection select to line in (default select for this ADC) */
3281 {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3282 /* unmute Line-Out mixer amp left and right (volume = 0) */
3283 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3284 /* mute pin widget amp left and right (no gain on this amp) */
3285 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3286 /* unmute HP mixer amp left and right (volume = 0) */
3287 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3288 /* mute pin widget amp left and right (no gain on this amp) */
3289 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3290 /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 & Line In 2 = 0x03 */
3291 /* unmute CD */
3292 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
3293 /* unmute Line In */
3294 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
3295 /* unmute Mic */
3296 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3297 /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3298 /* Unmute Front out path */
3299 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3300 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3301 /* Unmute Headphone out path */
3302 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3303 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3304 /* Unmute Mono out path */
3305 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3306 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3307 { }
3308};
3309
a9430dd8 3310/* Initialisation sequence for ALC260 as configured in Fujitsu S702x
a1e8d2da
JW
3311 * laptops. ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
3312 * audio = 0x16, internal speaker = 0x10.
a9430dd8
JW
3313 */
3314static struct hda_verb alc260_fujitsu_init_verbs[] = {
3315 /* Disable all GPIOs */
3316 {0x01, AC_VERB_SET_GPIO_MASK, 0},
3317 /* Internal speaker is connected to headphone pin */
3318 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3319 /* Headphone/Line-out jack connects to Line1 pin; make it an output */
3320 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
f7ace40d
JW
3321 /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
3322 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3323 /* Ensure all other unused pins are disabled and muted. */
3324 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3325 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
a9430dd8 3326 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
f7ace40d 3327 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
a9430dd8 3328 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
f7ace40d
JW
3329 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3330 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3331 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3332
3333 /* Disable digital (SPDIF) pins */
3334 {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3335 {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
a9430dd8 3336
f7ace40d
JW
3337 /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
3338 * when acting as an output.
3339 */
3340 {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4c5186ed 3341
f7ace40d 3342 /* Start with output sum widgets muted and their output gains at min */
8b33a5aa
TI
3343 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3344 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3345 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3346 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3347 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3348 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3349 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3350 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3351 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
a9430dd8 3352
f7ace40d
JW
3353 /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
3354 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3355 /* Unmute Line1 pin widget output buffer since it starts as an output.
3356 * If the pin mode is changed by the user the pin mode control will
3357 * take care of enabling the pin's input/output buffers as needed.
3358 * Therefore there's no need to enable the input buffer at this
3359 * stage.
cdcd9268 3360 */
f7ace40d 3361 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
cdcd9268
JW
3362 /* Unmute input buffer of pin widget used for Line-in (no equiv
3363 * mixer ctrl)
3364 */
f7ace40d
JW
3365 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3366
3367 /* Mute capture amp left and right */
3368 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3369 /* Set ADC connection select to match default mixer setting - line
3370 * in (on mic1 pin)
3371 */
3372 {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
3373
3374 /* Do the same for the second ADC: mute capture input amp and
3375 * set ADC connection to line in (on mic1 pin)
3376 */
3377 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3378 {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
3379
3380 /* Mute all inputs to mixer widget (even unconnected ones) */
3381 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
3382 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
3383 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
3384 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
3385 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
3386 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
3387 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
3388 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4a471b7d
TI
3389
3390 { }
a9430dd8
JW
3391};
3392
0bfc90e9
JW
3393/* Initialisation sequence for ALC260 as configured in Acer TravelMate and
3394 * similar laptops (adapted from Fujitsu init verbs).
3395 */
3396static struct hda_verb alc260_acer_init_verbs[] = {
3397 /* On TravelMate laptops, GPIO 0 enables the internal speaker and
3398 * the headphone jack. Turn this on and rely on the standard mute
3399 * methods whenever the user wants to turn these outputs off.
3400 */
3401 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
3402 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
3403 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
3404 /* Internal speaker/Headphone jack is connected to Line-out pin */
3405 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3406 /* Internal microphone/Mic jack is connected to Mic1 pin */
3407 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
3408 /* Line In jack is connected to Line1 pin */
3409 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3410 /* Ensure all other unused pins are disabled and muted. */
3411 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3412 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3413 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3414 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3415 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3416 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3417 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3418 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3419 /* Disable digital (SPDIF) pins */
3420 {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3421 {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3422
3423 /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
3424 * bus when acting as outputs.
3425 */
3426 {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
3427 {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3428
3429 /* Start with output sum widgets muted and their output gains at min */
3430 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3431 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3432 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3433 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3434 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3435 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3436 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3437 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3438 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3439
3440 /* Unmute Line-out pin widget amp left and right (no equiv mixer ctrl) */
3441 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3442 /* Unmute Mic1 and Line1 pin widget input buffers since they start as
3443 * inputs. If the pin mode is changed by the user the pin mode control
3444 * will take care of enabling the pin's input/output buffers as needed.
3445 * Therefore there's no need to enable the input buffer at this
3446 * stage.
3447 */
3448 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3449 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3450
3451 /* Mute capture amp left and right */
3452 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3453 /* Set ADC connection select to match default mixer setting - mic
3454 * (on mic1 pin)
3455 */
3456 {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
3457
3458 /* Do similar with the second ADC: mute capture input amp and
a1e8d2da 3459 * set ADC connection to mic to match ALSA's default state.
0bfc90e9
JW
3460 */
3461 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
a1e8d2da 3462 {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
0bfc90e9
JW
3463
3464 /* Mute all inputs to mixer widget (even unconnected ones) */
3465 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
3466 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
3467 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
3468 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
3469 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
3470 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
3471 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
3472 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
3473
3474 { }
3475};
3476
7cf51e48
JW
3477/* Test configuration for debugging, modelled after the ALC880 test
3478 * configuration.
3479 */
3480#ifdef CONFIG_SND_DEBUG
3481static hda_nid_t alc260_test_dac_nids[1] = {
3482 0x02,
3483};
3484static hda_nid_t alc260_test_adc_nids[2] = {
3485 0x04, 0x05,
3486};
a1e8d2da
JW
3487/* For testing the ALC260, each input MUX needs its own definition since
3488 * the signal assignments are different. This assumes that the first ADC
3489 * is NID 0x04.
17e7aec6 3490 */
a1e8d2da
JW
3491static struct hda_input_mux alc260_test_capture_sources[2] = {
3492 {
3493 .num_items = 7,
3494 .items = {
3495 { "MIC1 pin", 0x0 },
3496 { "MIC2 pin", 0x1 },
3497 { "LINE1 pin", 0x2 },
3498 { "LINE2 pin", 0x3 },
3499 { "CD pin", 0x4 },
3500 { "LINE-OUT pin", 0x5 },
3501 { "HP-OUT pin", 0x6 },
3502 },
3503 },
3504 {
3505 .num_items = 8,
3506 .items = {
3507 { "MIC1 pin", 0x0 },
3508 { "MIC2 pin", 0x1 },
3509 { "LINE1 pin", 0x2 },
3510 { "LINE2 pin", 0x3 },
3511 { "CD pin", 0x4 },
3512 { "Mixer", 0x5 },
3513 { "LINE-OUT pin", 0x6 },
3514 { "HP-OUT pin", 0x7 },
3515 },
7cf51e48
JW
3516 },
3517};
3518static struct snd_kcontrol_new alc260_test_mixer[] = {
3519 /* Output driver widgets */
3520 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3521 HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3522 HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3523 HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
3524 HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3525 HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
3526
a1e8d2da
JW
3527 /* Modes for retasking pin widgets
3528 * Note: the ALC260 doesn't seem to act on requests to enable mic
3529 * bias from NIDs 0x0f and 0x10. The ALC260 datasheet doesn't
3530 * mention this restriction. At this stage it's not clear whether
3531 * this behaviour is intentional or is a hardware bug in chip
3532 * revisions available at least up until early 2006. Therefore for
3533 * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
3534 * choices, but if it turns out that the lack of mic bias for these
3535 * NIDs is intentional we could change their modes from
3536 * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
3537 */
7cf51e48
JW
3538 ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
3539 ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
3540 ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
3541 ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
3542 ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
3543 ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
3544
3545 /* Loopback mixer controls */
3546 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
3547 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
3548 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
3549 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
3550 HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
3551 HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
3552 HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
3553 HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
3554 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3555 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3556 HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3557 HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3558 HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
3559 HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
3560 HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
3561 HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5c8f858d
JW
3562
3563 /* Controls for GPIO pins, assuming they are configured as outputs */
3564 ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
3565 ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
3566 ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
3567 ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
3568
92621f13
JW
3569 /* Switches to allow the digital IO pins to be enabled. The datasheet
3570 * is ambigious as to which NID is which; testing on laptops which
3571 * make this output available should provide clarification.
3572 */
3573 ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
3574 ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
3575
7cf51e48
JW
3576 { } /* end */
3577};
3578static struct hda_verb alc260_test_init_verbs[] = {
5c8f858d
JW
3579 /* Enable all GPIOs as outputs with an initial value of 0 */
3580 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
3581 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
3582 {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
3583
7cf51e48
JW
3584 /* Enable retasking pins as output, initially without power amp */
3585 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3586 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3587 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3588 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3589 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3590 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3591
92621f13
JW
3592 /* Disable digital (SPDIF) pins initially, but users can enable
3593 * them via a mixer switch. In the case of SPDIF-out, this initverb
3594 * payload also sets the generation to 0, output to be in "consumer"
3595 * PCM format, copyright asserted, no pre-emphasis and no validity
3596 * control.
3597 */
7cf51e48
JW
3598 {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3599 {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3600
f7ace40d 3601 /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
7cf51e48
JW
3602 * OUT1 sum bus when acting as an output.
3603 */
3604 {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
3605 {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
3606 {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3607 {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
3608
3609 /* Start with output sum widgets muted and their output gains at min */
3610 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3611 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3612 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3613 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3614 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3615 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3616 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3617 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3618 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3619
cdcd9268
JW
3620 /* Unmute retasking pin widget output buffers since the default
3621 * state appears to be output. As the pin mode is changed by the
3622 * user the pin mode control will take care of enabling the pin's
3623 * input/output buffers as needed.
3624 */
7cf51e48
JW
3625 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3626 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3627 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3628 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3629 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3630 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3631 /* Also unmute the mono-out pin widget */
3632 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3633
7cf51e48
JW
3634 /* Mute capture amp left and right */
3635 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
f7ace40d
JW
3636 /* Set ADC connection select to match default mixer setting (mic1
3637 * pin)
7cf51e48
JW
3638 */
3639 {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
3640
3641 /* Do the same for the second ADC: mute capture input amp and
f7ace40d 3642 * set ADC connection to mic1 pin
7cf51e48
JW
3643 */
3644 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3645 {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
3646
3647 /* Mute all inputs to mixer widget (even unconnected ones) */
3648 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
3649 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
3650 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
3651 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
3652 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
3653 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
3654 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
3655 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
3656
3657 { }
3658};
3659#endif
3660
1da177e4
LT
3661static struct hda_pcm_stream alc260_pcm_analog_playback = {
3662 .substreams = 1,
3663 .channels_min = 2,
3664 .channels_max = 2,
1da177e4
LT
3665};
3666
3667static struct hda_pcm_stream alc260_pcm_analog_capture = {
3668 .substreams = 1,
3669 .channels_min = 2,
3670 .channels_max = 2,
1da177e4
LT
3671};
3672
a3bcba38
TI
3673#define alc260_pcm_digital_playback alc880_pcm_digital_playback
3674#define alc260_pcm_digital_capture alc880_pcm_digital_capture
3675
df694daa
KY
3676/*
3677 * for BIOS auto-configuration
3678 */
16ded525 3679
df694daa
KY
3680static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
3681 const char *pfx)
3682{
3683 hda_nid_t nid_vol;
3684 unsigned long vol_val, sw_val;
3685 char name[32];
3686 int err;
3687
3688 if (nid >= 0x0f && nid < 0x11) {
3689 nid_vol = nid - 0x7;
3690 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
3691 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3692 } else if (nid == 0x11) {
3693 nid_vol = nid - 0x7;
3694 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
3695 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
3696 } else if (nid >= 0x12 && nid <= 0x15) {
3697 nid_vol = 0x08;
3698 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
3699 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3700 } else
3701 return 0; /* N/A */
3702
3703 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3704 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val)) < 0)
3705 return err;
3706 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3707 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val)) < 0)
3708 return err;
3709 return 1;
3710}
3711
3712/* add playback controls from the parsed DAC table */
3713static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
3714 const struct auto_pin_cfg *cfg)
3715{
3716 hda_nid_t nid;
3717 int err;
3718
3719 spec->multiout.num_dacs = 1;
3720 spec->multiout.dac_nids = spec->private_dac_nids;
3721 spec->multiout.dac_nids[0] = 0x02;
3722
3723 nid = cfg->line_out_pins[0];
3724 if (nid) {
3725 err = alc260_add_playback_controls(spec, nid, "Front");
3726 if (err < 0)
3727 return err;
3728 }
3729
82bc955f 3730 nid = cfg->speaker_pins[0];
df694daa
KY
3731 if (nid) {
3732 err = alc260_add_playback_controls(spec, nid, "Speaker");
3733 if (err < 0)
3734 return err;
3735 }
3736
3737 nid = cfg->hp_pin;
3738 if (nid) {
3739 err = alc260_add_playback_controls(spec, nid, "Headphone");
3740 if (err < 0)
3741 return err;
3742 }
3743 return 0;
3744}
3745
3746/* create playback/capture controls for input pins */
3747static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
3748 const struct auto_pin_cfg *cfg)
3749{
df694daa
KY
3750 struct hda_input_mux *imux = &spec->private_imux;
3751 int i, err, idx;
3752
3753 for (i = 0; i < AUTO_PIN_LAST; i++) {
3754 if (cfg->input_pins[i] >= 0x12) {
3755 idx = cfg->input_pins[i] - 0x12;
4a471b7d
TI
3756 err = new_analog_input(spec, cfg->input_pins[i],
3757 auto_pin_cfg_labels[i], idx, 0x07);
df694daa
KY
3758 if (err < 0)
3759 return err;
4a471b7d 3760 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
df694daa
KY
3761 imux->items[imux->num_items].index = idx;
3762 imux->num_items++;
3763 }
3764 if ((cfg->input_pins[i] >= 0x0f) && (cfg->input_pins[i] <= 0x10)){
3765 idx = cfg->input_pins[i] - 0x09;
4a471b7d
TI
3766 err = new_analog_input(spec, cfg->input_pins[i],
3767 auto_pin_cfg_labels[i], idx, 0x07);
df694daa
KY
3768 if (err < 0)
3769 return err;
4a471b7d 3770 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
df694daa
KY
3771 imux->items[imux->num_items].index = idx;
3772 imux->num_items++;
3773 }
3774 }
3775 return 0;
3776}
3777
3778static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
3779 hda_nid_t nid, int pin_type,
3780 int sel_idx)
3781{
3782 /* set as output */
3783 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
3784 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
3785 /* need the manual connection? */
3786 if (nid >= 0x12) {
3787 int idx = nid - 0x12;
3788 snd_hda_codec_write(codec, idx + 0x0b, 0,
3789 AC_VERB_SET_CONNECT_SEL, sel_idx);
3790
3791 }
3792}
3793
3794static void alc260_auto_init_multi_out(struct hda_codec *codec)
3795{
3796 struct alc_spec *spec = codec->spec;
3797 hda_nid_t nid;
3798
3799 nid = spec->autocfg.line_out_pins[0];
3800 if (nid)
3801 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
3802
82bc955f 3803 nid = spec->autocfg.speaker_pins[0];
df694daa
KY
3804 if (nid)
3805 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
3806
3807 nid = spec->autocfg.hp_pin;
3808 if (nid)
3809 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
3810}
3811
3812#define ALC260_PIN_CD_NID 0x16
3813static void alc260_auto_init_analog_input(struct hda_codec *codec)
3814{
3815 struct alc_spec *spec = codec->spec;
3816 int i;
3817
3818 for (i = 0; i < AUTO_PIN_LAST; i++) {
3819 hda_nid_t nid = spec->autocfg.input_pins[i];
3820 if (nid >= 0x12) {
3821 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3822 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
3823 if (nid != ALC260_PIN_CD_NID)
3824 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3825 AMP_OUT_MUTE);
3826 }
3827 }
3828}
3829
3830/*
3831 * generic initialization of ADC, input mixers and output mixers
3832 */
3833static struct hda_verb alc260_volume_init_verbs[] = {
3834 /*
3835 * Unmute ADC0-1 and set the default input to mic-in
3836 */
3837 {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
3838 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3839 {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
3840 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3841
3842 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3843 * mixer widget
3844 * Note: PASD motherboards uses the Line In 2 as the input for front panel
3845 * mic (mic 2)
3846 */
3847 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
3848 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3849 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3850 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3851 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3852 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3853
3854 /*
3855 * Set up output mixers (0x08 - 0x0a)
3856 */
3857 /* set vol=0 to output mixers */
3858 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3859 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3860 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3861 /* set up input amps for analog loopback */
3862 /* Amp Indices: DAC = 0, mixer = 1 */
3863 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3864 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3865 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3866 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3867 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3868 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3869
3870 { }
3871};
3872
3873static int alc260_parse_auto_config(struct hda_codec *codec)
3874{
3875 struct alc_spec *spec = codec->spec;
3876 unsigned int wcap;
3877 int err;
3878 static hda_nid_t alc260_ignore[] = { 0x17, 0 };
3879
3880 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3881 alc260_ignore)) < 0)
3882 return err;
4a471b7d
TI
3883 if ((err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0)
3884 return err;
3885 if (! spec->kctl_alloc)
df694daa 3886 return 0; /* can't find valid BIOS pin config */
4a471b7d 3887 if ((err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
df694daa
KY
3888 return err;
3889
3890 spec->multiout.max_channels = 2;
3891
3892 if (spec->autocfg.dig_out_pin)
3893 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
3894 if (spec->kctl_alloc)
3895 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3896
3897 spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
3898
a1e8d2da 3899 spec->num_mux_defs = 1;
df694daa
KY
3900 spec->input_mux = &spec->private_imux;
3901
3902 /* check whether NID 0x04 is valid */
4a471b7d 3903 wcap = get_wcaps(codec, 0x04);
df694daa
KY
3904 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
3905 if (wcap != AC_WID_AUD_IN) {
3906 spec->adc_nids = alc260_adc_nids_alt;
3907 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
3908 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
df694daa
KY
3909 } else {
3910 spec->adc_nids = alc260_adc_nids;
3911 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
3912 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
df694daa 3913 }
4a471b7d 3914 spec->num_mixers++;
df694daa
KY
3915
3916 return 1;
3917}
3918
ae6b813a
TI
3919/* additional initialization for auto-configuration model */
3920static void alc260_auto_init(struct hda_codec *codec)
df694daa 3921{
df694daa
KY
3922 alc260_auto_init_multi_out(codec);
3923 alc260_auto_init_analog_input(codec);
df694daa
KY
3924}
3925
3926/*
3927 * ALC260 configurations
3928 */
3929static struct hda_board_config alc260_cfg_tbl[] = {
3930 { .modelname = "basic", .config = ALC260_BASIC },
b14e77e6
TI
3931 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81bb,
3932 .config = ALC260_BASIC }, /* Sony VAIO */
3206b9ca
TI
3933 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81cc,
3934 .config = ALC260_BASIC }, /* Sony VAIO VGN-S3HP */
5e1b1518
KC
3935 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81cd,
3936 .config = ALC260_BASIC }, /* Sony VAIO */
c1fc8047
TI
3937 { .pci_subvendor = 0x152d, .pci_subdevice = 0x0729,
3938 .config = ALC260_BASIC }, /* CTL Travel Master U553W */
df694daa 3939 { .modelname = "hp", .config = ALC260_HP },
4b146cb0 3940 { .modelname = "hp-3013", .config = ALC260_HP_3013 },
25b6c43b 3941 { .pci_subvendor = 0x103c, .pci_subdevice = 0x3010, .config = ALC260_HP_3013 },
df694daa 3942 { .pci_subvendor = 0x103c, .pci_subdevice = 0x3011, .config = ALC260_HP },
766a6c36 3943 { .pci_subvendor = 0x103c, .pci_subdevice = 0x3012, .config = ALC260_HP_3013 },
df694daa
KY
3944 { .pci_subvendor = 0x103c, .pci_subdevice = 0x3013, .config = ALC260_HP_3013 },
3945 { .pci_subvendor = 0x103c, .pci_subdevice = 0x3014, .config = ALC260_HP },
3946 { .pci_subvendor = 0x103c, .pci_subdevice = 0x3015, .config = ALC260_HP },
3947 { .pci_subvendor = 0x103c, .pci_subdevice = 0x3016, .config = ALC260_HP },
3948 { .modelname = "fujitsu", .config = ALC260_FUJITSU_S702X },
3949 { .pci_subvendor = 0x10cf, .pci_subdevice = 0x1326, .config = ALC260_FUJITSU_S702X },
0bfc90e9
JW
3950 { .modelname = "acer", .config = ALC260_ACER },
3951 { .pci_subvendor = 0x1025, .pci_subdevice = 0x008f, .config = ALC260_ACER },
7cf51e48
JW
3952#ifdef CONFIG_SND_DEBUG
3953 { .modelname = "test", .config = ALC260_TEST },
3954#endif
df694daa
KY
3955 { .modelname = "auto", .config = ALC260_AUTO },
3956 {}
3957};
3958
3959static struct alc_config_preset alc260_presets[] = {
3960 [ALC260_BASIC] = {
3961 .mixers = { alc260_base_output_mixer,
3962 alc260_input_mixer,
3963 alc260_pc_beep_mixer,
3964 alc260_capture_mixer },
3965 .init_verbs = { alc260_init_verbs },
3966 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
3967 .dac_nids = alc260_dac_nids,
3968 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
3969 .adc_nids = alc260_adc_nids,
3970 .num_channel_mode = ARRAY_SIZE(alc260_modes),
3971 .channel_mode = alc260_modes,
3972 .input_mux = &alc260_capture_source,
3973 },
3974 [ALC260_HP] = {
3975 .mixers = { alc260_base_output_mixer,
3976 alc260_input_mixer,
3977 alc260_capture_alt_mixer },
474167d6 3978 .init_verbs = { alc260_init_verbs },
df694daa
KY
3979 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
3980 .dac_nids = alc260_dac_nids,
3981 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
3982 .adc_nids = alc260_hp_adc_nids,
3983 .num_channel_mode = ARRAY_SIZE(alc260_modes),
3984 .channel_mode = alc260_modes,
3985 .input_mux = &alc260_capture_source,
3986 },
3987 [ALC260_HP_3013] = {
3988 .mixers = { alc260_hp_3013_mixer,
3989 alc260_input_mixer,
3990 alc260_capture_alt_mixer },
3991 .init_verbs = { alc260_hp_3013_init_verbs },
3992 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
3993 .dac_nids = alc260_dac_nids,
3994 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
3995 .adc_nids = alc260_hp_adc_nids,
3996 .num_channel_mode = ARRAY_SIZE(alc260_modes),
3997 .channel_mode = alc260_modes,
3998 .input_mux = &alc260_capture_source,
3999 },
4000 [ALC260_FUJITSU_S702X] = {
4001 .mixers = { alc260_fujitsu_mixer,
4002 alc260_capture_mixer },
4003 .init_verbs = { alc260_fujitsu_init_verbs },
4004 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4005 .dac_nids = alc260_dac_nids,
d57fdac0
JW
4006 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4007 .adc_nids = alc260_dual_adc_nids,
df694daa
KY
4008 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4009 .channel_mode = alc260_modes,
a1e8d2da
JW
4010 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
4011 .input_mux = alc260_fujitsu_capture_sources,
df694daa 4012 },
0bfc90e9
JW
4013 [ALC260_ACER] = {
4014 .mixers = { alc260_acer_mixer,
4015 alc260_capture_mixer },
4016 .init_verbs = { alc260_acer_init_verbs },
4017 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4018 .dac_nids = alc260_dac_nids,
4019 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4020 .adc_nids = alc260_dual_adc_nids,
4021 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4022 .channel_mode = alc260_modes,
a1e8d2da
JW
4023 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
4024 .input_mux = alc260_acer_capture_sources,
0bfc90e9 4025 },
7cf51e48
JW
4026#ifdef CONFIG_SND_DEBUG
4027 [ALC260_TEST] = {
4028 .mixers = { alc260_test_mixer,
4029 alc260_capture_mixer },
4030 .init_verbs = { alc260_test_init_verbs },
4031 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
4032 .dac_nids = alc260_test_dac_nids,
4033 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
4034 .adc_nids = alc260_test_adc_nids,
4035 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4036 .channel_mode = alc260_modes,
a1e8d2da
JW
4037 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
4038 .input_mux = alc260_test_capture_sources,
7cf51e48
JW
4039 },
4040#endif
df694daa
KY
4041};
4042
4043static int patch_alc260(struct hda_codec *codec)
1da177e4
LT
4044{
4045 struct alc_spec *spec;
df694daa 4046 int err, board_config;
1da177e4 4047
e560d8d8 4048 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1da177e4
LT
4049 if (spec == NULL)
4050 return -ENOMEM;
4051
4052 codec->spec = spec;
4053
16ded525
TI
4054 board_config = snd_hda_check_board_config(codec, alc260_cfg_tbl);
4055 if (board_config < 0 || board_config >= ALC260_MODEL_LAST) {
9c7f852e
TI
4056 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
4057 "trying auto-probe from BIOS...\n");
df694daa 4058 board_config = ALC260_AUTO;
16ded525 4059 }
1da177e4 4060
df694daa
KY
4061 if (board_config == ALC260_AUTO) {
4062 /* automatic parse from the BIOS config */
4063 err = alc260_parse_auto_config(codec);
4064 if (err < 0) {
4065 alc_free(codec);
4066 return err;
4067 } else if (! err) {
9c7f852e
TI
4068 printk(KERN_INFO
4069 "hda_codec: Cannot set up configuration "
4070 "from BIOS. Using base mode...\n");
df694daa
KY
4071 board_config = ALC260_BASIC;
4072 }
a9430dd8 4073 }
e9edcee0 4074
df694daa
KY
4075 if (board_config != ALC260_AUTO)
4076 setup_preset(spec, &alc260_presets[board_config]);
1da177e4
LT
4077
4078 spec->stream_name_analog = "ALC260 Analog";
4079 spec->stream_analog_playback = &alc260_pcm_analog_playback;
4080 spec->stream_analog_capture = &alc260_pcm_analog_capture;
4081
a3bcba38
TI
4082 spec->stream_name_digital = "ALC260 Digital";
4083 spec->stream_digital_playback = &alc260_pcm_digital_playback;
4084 spec->stream_digital_capture = &alc260_pcm_digital_capture;
4085
1da177e4 4086 codec->patch_ops = alc_patch_ops;
df694daa 4087 if (board_config == ALC260_AUTO)
ae6b813a 4088 spec->init_hook = alc260_auto_init;
1da177e4
LT
4089
4090 return 0;
4091}
4092
e9edcee0 4093
1da177e4
LT
4094/*
4095 * ALC882 support
4096 *
4097 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4098 * configuration. Each pin widget can choose any input DACs and a mixer.
4099 * Each ADC is connected from a mixer of all inputs. This makes possible
4100 * 6-channel independent captures.
4101 *
4102 * In addition, an independent DAC for the multi-playback (not used in this
4103 * driver yet).
4104 */
df694daa
KY
4105#define ALC882_DIGOUT_NID 0x06
4106#define ALC882_DIGIN_NID 0x0a
1da177e4 4107
d2a6d7dc 4108static struct hda_channel_mode alc882_ch_modes[1] = {
1da177e4
LT
4109 { 8, NULL }
4110};
4111
4112static hda_nid_t alc882_dac_nids[4] = {
4113 /* front, rear, clfe, rear_surr */
4114 0x02, 0x03, 0x04, 0x05
4115};
4116
df694daa
KY
4117/* identical with ALC880 */
4118#define alc882_adc_nids alc880_adc_nids
4119#define alc882_adc_nids_alt alc880_adc_nids_alt
1da177e4
LT
4120
4121/* input MUX */
4122/* FIXME: should be a matrix-type input source selection */
4123
4124static struct hda_input_mux alc882_capture_source = {
4125 .num_items = 4,
4126 .items = {
4127 { "Mic", 0x0 },
4128 { "Front Mic", 0x1 },
4129 { "Line", 0x2 },
4130 { "CD", 0x4 },
4131 },
4132};
1da177e4
LT
4133#define alc882_mux_enum_info alc_mux_enum_info
4134#define alc882_mux_enum_get alc_mux_enum_get
4135
c8b6bf9b 4136static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1da177e4
LT
4137{
4138 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4139 struct alc_spec *spec = codec->spec;
4140 const struct hda_input_mux *imux = spec->input_mux;
4141 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
4142 static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
4143 hda_nid_t nid = capture_mixers[adc_idx];
4144 unsigned int *cur_val = &spec->cur_mux[adc_idx];
4145 unsigned int i, idx;
4146
4147 idx = ucontrol->value.enumerated.item[0];
4148 if (idx >= imux->num_items)
4149 idx = imux->num_items - 1;
4150 if (*cur_val == idx && ! codec->in_resume)
4151 return 0;
4152 for (i = 0; i < imux->num_items; i++) {
4153 unsigned int v = (i == idx) ? 0x7000 : 0x7080;
4154 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4155 v | (imux->items[i].index << 8));
4156 }
4157 *cur_val = idx;
4158 return 1;
4159}
4160
df694daa
KY
4161/*
4162 * 6ch mode
4163 */
4164static struct hda_verb alc882_sixstack_ch6_init[] = {
4165 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
4166 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4167 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4168 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4169 { } /* end */
4170};
4171
4172/*
4173 * 8ch mode
4174 */
4175static struct hda_verb alc882_sixstack_ch8_init[] = {
4176 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4177 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4178 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4179 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4180 { } /* end */
4181};
4182
4183static struct hda_channel_mode alc882_sixstack_modes[2] = {
4184 { 6, alc882_sixstack_ch6_init },
4185 { 8, alc882_sixstack_ch8_init },
4186};
4187
1da177e4
LT
4188/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
4189 * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
4190 */
c8b6bf9b 4191static struct snd_kcontrol_new alc882_base_mixer[] = {
05acb863 4192 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
985be54b 4193 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
05acb863 4194 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
985be54b 4195 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
05acb863
TI
4196 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
4197 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
985be54b
TI
4198 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
4199 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
05acb863 4200 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
985be54b 4201 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1da177e4
LT
4202 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
4203 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4204 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4205 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4206 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4207 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4208 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4209 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
4210 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
4211 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4212 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1da177e4
LT
4213 { } /* end */
4214};
4215
df694daa
KY
4216static struct snd_kcontrol_new alc882_chmode_mixer[] = {
4217 {
4218 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4219 .name = "Channel Mode",
4220 .info = alc_ch_mode_info,
4221 .get = alc_ch_mode_get,
4222 .put = alc_ch_mode_put,
4223 },
4224 { } /* end */
4225};
4226
1da177e4
LT
4227static struct hda_verb alc882_init_verbs[] = {
4228 /* Front mixer: unmute input/output amp left and right (volume = 0) */
05acb863
TI
4229 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4230 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4231 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1da177e4 4232 /* Rear mixer */
05acb863
TI
4233 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4234 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4235 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1da177e4 4236 /* CLFE mixer */
05acb863
TI
4237 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4238 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4239 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1da177e4 4240 /* Side mixer */
05acb863
TI
4241 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4242 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4243 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1da177e4 4244
e9edcee0 4245 /* Front Pin: output 0 (0x0c) */
05acb863 4246 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
05acb863 4247 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1da177e4 4248 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
e9edcee0 4249 /* Rear Pin: output 1 (0x0d) */
05acb863 4250 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
05acb863 4251 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1da177e4 4252 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
e9edcee0 4253 /* CLFE Pin: output 2 (0x0e) */
05acb863 4254 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
05acb863 4255 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1da177e4 4256 {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
e9edcee0 4257 /* Side Pin: output 3 (0x0f) */
05acb863 4258 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
05acb863 4259 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1da177e4 4260 {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
e9edcee0 4261 /* Mic (rear) pin: input vref at 80% */
16ded525 4262 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
e9edcee0
TI
4263 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4264 /* Front Mic pin: input vref at 80% */
16ded525 4265 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
e9edcee0
TI
4266 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4267 /* Line In pin: input */
05acb863 4268 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
e9edcee0
TI
4269 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4270 /* Line-2 In: Headphone output (output 0 - 0x0c) */
4271 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4272 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4273 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1da177e4 4274 /* CD pin widget for input */
05acb863 4275 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1da177e4
LT
4276
4277 /* FIXME: use matrix-type input source selection */
4278 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
4279 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
05acb863
TI
4280 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4281 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4282 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4283 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1da177e4 4284 /* Input mixer2 */
05acb863
TI
4285 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4286 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4287 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4288 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1da177e4 4289 /* Input mixer3 */
05acb863
TI
4290 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4291 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4292 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4293 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4294 /* ADC1: mute amp left and right */
4295 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
71fe7b82 4296 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
05acb863
TI
4297 /* ADC2: mute amp left and right */
4298 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
71fe7b82 4299 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
05acb863
TI
4300 /* ADC3: mute amp left and right */
4301 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
71fe7b82 4302 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1da177e4
LT
4303
4304 { }
4305};
4306
4b146cb0
TI
4307static struct hda_verb alc882_eapd_verbs[] = {
4308 /* change to EAPD mode */
4309 {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
4310 {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
4311 { }
4312};
4313
df694daa
KY
4314/*
4315 * generic initialization of ADC, input mixers and output mixers
4316 */
4317static struct hda_verb alc882_auto_init_verbs[] = {
4318 /*
4319 * Unmute ADC0-2 and set the default input to mic-in
4320 */
4321 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
4322 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4323 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
4324 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4325 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
4326 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1da177e4 4327
df694daa
KY
4328 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4329 * mixer widget
4330 * Note: PASD motherboards uses the Line In 2 as the input for front panel
4331 * mic (mic 2)
4332 */
4333 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4334 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4335 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4336 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4337 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4338 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
e9edcee0 4339
df694daa
KY
4340 /*
4341 * Set up output mixers (0x0c - 0x0f)
4342 */
4343 /* set vol=0 to output mixers */
4344 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4345 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4346 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4347 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4348 /* set up input amps for analog loopback */
4349 /* Amp Indices: DAC = 0, mixer = 1 */
4350 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4351 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4352 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4353 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4354 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4355 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4356 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4357 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4358 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4359 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4360
4361 /* FIXME: use matrix-type input source selection */
4362 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
4363 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
4364 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4365 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
4366 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
4367 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
4368 /* Input mixer2 */
4369 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4370 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
4371 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
4372 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
4373 /* Input mixer3 */
4374 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4375 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
4376 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
4377 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
4378
4379 { }
4380};
4381
4382/* capture mixer elements */
4383static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
4384 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
4385 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
4386 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
4387 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
4388 {
4389 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4390 /* The multiple "Capture Source" controls confuse alsamixer
4391 * So call somewhat different..
4392 * FIXME: the controls appear in the "playback" view!
4393 */
4394 /* .name = "Capture Source", */
4395 .name = "Input Source",
4396 .count = 2,
4397 .info = alc882_mux_enum_info,
4398 .get = alc882_mux_enum_get,
4399 .put = alc882_mux_enum_put,
4400 },
4401 { } /* end */
4402};
4403
4404static struct snd_kcontrol_new alc882_capture_mixer[] = {
4405 HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
4406 HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
4407 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
4408 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
4409 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
4410 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
4411 {
4412 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4413 /* The multiple "Capture Source" controls confuse alsamixer
4414 * So call somewhat different..
4415 * FIXME: the controls appear in the "playback" view!
4416 */
4417 /* .name = "Capture Source", */
4418 .name = "Input Source",
4419 .count = 3,
4420 .info = alc882_mux_enum_info,
4421 .get = alc882_mux_enum_get,
4422 .put = alc882_mux_enum_put,
4423 },
4424 { } /* end */
4425};
4426
4427/* pcm configuration: identiacal with ALC880 */
4428#define alc882_pcm_analog_playback alc880_pcm_analog_playback
4429#define alc882_pcm_analog_capture alc880_pcm_analog_capture
4430#define alc882_pcm_digital_playback alc880_pcm_digital_playback
4431#define alc882_pcm_digital_capture alc880_pcm_digital_capture
4432
4433/*
4434 * configuration and preset
4435 */
4436static struct hda_board_config alc882_cfg_tbl[] = {
1494a92f
TI
4437 { .modelname = "3stack-dig", .config = ALC882_3ST_DIG },
4438 { .modelname = "6stack-dig", .config = ALC882_6ST_DIG },
9c7f852e
TI
4439 { .pci_subvendor = 0x1462, .pci_subdevice = 0x6668,
4440 .config = ALC882_6ST_DIG }, /* MSI */
4441 { .pci_subvendor = 0x105b, .pci_subdevice = 0x6668,
4442 .config = ALC882_6ST_DIG }, /* Foxconn */
4443 { .pci_subvendor = 0x1019, .pci_subdevice = 0x6668,
4444 .config = ALC882_6ST_DIG }, /* ECS to Intel*/
4b146cb0
TI
4445 { .modelname = "arima", .config = ALC882_ARIMA },
4446 { .pci_subvendor = 0x161f, .pci_subdevice = 0x2054,
4447 .config = ALC882_ARIMA }, /* Arima W820Di1 */
1494a92f 4448 { .modelname = "auto", .config = ALC882_AUTO },
df694daa
KY
4449 {}
4450};
4451
4452static struct alc_config_preset alc882_presets[] = {
4453 [ALC882_3ST_DIG] = {
4454 .mixers = { alc882_base_mixer },
4455 .init_verbs = { alc882_init_verbs },
4456 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
4457 .dac_nids = alc882_dac_nids,
4458 .dig_out_nid = ALC882_DIGOUT_NID,
df694daa
KY
4459 .dig_in_nid = ALC882_DIGIN_NID,
4460 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
4461 .channel_mode = alc882_ch_modes,
4e195a7b 4462 .need_dac_fix = 1,
df694daa
KY
4463 .input_mux = &alc882_capture_source,
4464 },
4465 [ALC882_6ST_DIG] = {
4466 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
4467 .init_verbs = { alc882_init_verbs },
4468 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
4469 .dac_nids = alc882_dac_nids,
4470 .dig_out_nid = ALC882_DIGOUT_NID,
df694daa
KY
4471 .dig_in_nid = ALC882_DIGIN_NID,
4472 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
4473 .channel_mode = alc882_sixstack_modes,
4474 .input_mux = &alc882_capture_source,
4475 },
4b146cb0
TI
4476 [ALC882_ARIMA] = {
4477 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
4478 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
4479 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
4480 .dac_nids = alc882_dac_nids,
4481 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
4482 .channel_mode = alc882_sixstack_modes,
4483 .input_mux = &alc882_capture_source,
4484 },
df694daa
KY
4485};
4486
4487
4488/*
4489 * BIOS auto configuration
4490 */
4491static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
4492 hda_nid_t nid, int pin_type,
4493 int dac_idx)
4494{
4495 /* set as output */
4496 struct alc_spec *spec = codec->spec;
4497 int idx;
4498
4499 if (spec->multiout.dac_nids[dac_idx] == 0x25)
4500 idx = 4;
4501 else
4502 idx = spec->multiout.dac_nids[dac_idx] - 2;
4503
4504 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
4505 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
4506 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
4507
4508}
4509
4510static void alc882_auto_init_multi_out(struct hda_codec *codec)
4511{
4512 struct alc_spec *spec = codec->spec;
4513 int i;
4514
4515 for (i = 0; i <= HDA_SIDE; i++) {
4516 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4517 if (nid)
4518 alc882_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
4519 }
4520}
4521
4522static void alc882_auto_init_hp_out(struct hda_codec *codec)
4523{
4524 struct alc_spec *spec = codec->spec;
4525 hda_nid_t pin;
4526
4527 pin = spec->autocfg.hp_pin;
4528 if (pin) /* connect to front */
4529 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); /* use dac 0 */
4530}
4531
4532#define alc882_is_input_pin(nid) alc880_is_input_pin(nid)
4533#define ALC882_PIN_CD_NID ALC880_PIN_CD_NID
4534
4535static void alc882_auto_init_analog_input(struct hda_codec *codec)
4536{
4537 struct alc_spec *spec = codec->spec;
4538 int i;
4539
4540 for (i = 0; i < AUTO_PIN_LAST; i++) {
4541 hda_nid_t nid = spec->autocfg.input_pins[i];
4542 if (alc882_is_input_pin(nid)) {
4543 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4544 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
4545 if (nid != ALC882_PIN_CD_NID)
4546 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4547 AMP_OUT_MUTE);
4548 }
4549 }
4550}
4551
4552/* almost identical with ALC880 parser... */
4553static int alc882_parse_auto_config(struct hda_codec *codec)
4554{
4555 struct alc_spec *spec = codec->spec;
4556 int err = alc880_parse_auto_config(codec);
4557
4558 if (err < 0)
4559 return err;
c5f2ea08
TI
4560 else if (err > 0)
4561 /* hack - override the init verbs */
4562 spec->init_verbs[0] = alc882_auto_init_verbs;
4563 return err;
df694daa
KY
4564}
4565
ae6b813a
TI
4566/* additional initialization for auto-configuration model */
4567static void alc882_auto_init(struct hda_codec *codec)
df694daa 4568{
df694daa
KY
4569 alc882_auto_init_multi_out(codec);
4570 alc882_auto_init_hp_out(codec);
4571 alc882_auto_init_analog_input(codec);
df694daa
KY
4572}
4573
df694daa
KY
4574static int patch_alc882(struct hda_codec *codec)
4575{
4576 struct alc_spec *spec;
4577 int err, board_config;
4578
4579 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4580 if (spec == NULL)
4581 return -ENOMEM;
4582
4583 codec->spec = spec;
4584
4585 board_config = snd_hda_check_board_config(codec, alc882_cfg_tbl);
4586
4587 if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
9c7f852e
TI
4588 printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
4589 "trying auto-probe from BIOS...\n");
df694daa
KY
4590 board_config = ALC882_AUTO;
4591 }
4592
4593 if (board_config == ALC882_AUTO) {
4594 /* automatic parse from the BIOS config */
4595 err = alc882_parse_auto_config(codec);
4596 if (err < 0) {
4597 alc_free(codec);
4598 return err;
4599 } else if (! err) {
9c7f852e
TI
4600 printk(KERN_INFO
4601 "hda_codec: Cannot set up configuration "
4602 "from BIOS. Using base mode...\n");
df694daa
KY
4603 board_config = ALC882_3ST_DIG;
4604 }
4605 }
4606
4607 if (board_config != ALC882_AUTO)
4608 setup_preset(spec, &alc882_presets[board_config]);
1da177e4
LT
4609
4610 spec->stream_name_analog = "ALC882 Analog";
df694daa
KY
4611 spec->stream_analog_playback = &alc882_pcm_analog_playback;
4612 spec->stream_analog_capture = &alc882_pcm_analog_capture;
1da177e4
LT
4613
4614 spec->stream_name_digital = "ALC882 Digital";
df694daa
KY
4615 spec->stream_digital_playback = &alc882_pcm_digital_playback;
4616 spec->stream_digital_capture = &alc882_pcm_digital_capture;
1da177e4 4617
df694daa
KY
4618 if (! spec->adc_nids && spec->input_mux) {
4619 /* check whether NID 0x07 is valid */
4a471b7d 4620 unsigned int wcap = get_wcaps(codec, 0x07);
df694daa
KY
4621 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4622 if (wcap != AC_WID_AUD_IN) {
4623 spec->adc_nids = alc882_adc_nids_alt;
4624 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
4625 spec->mixers[spec->num_mixers] = alc882_capture_alt_mixer;
4626 spec->num_mixers++;
4627 } else {
4628 spec->adc_nids = alc882_adc_nids;
4629 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
4630 spec->mixers[spec->num_mixers] = alc882_capture_mixer;
4631 spec->num_mixers++;
4632 }
4633 }
1da177e4
LT
4634
4635 codec->patch_ops = alc_patch_ops;
df694daa 4636 if (board_config == ALC882_AUTO)
ae6b813a 4637 spec->init_hook = alc882_auto_init;
df694daa
KY
4638
4639 return 0;
4640}
4641
4642/*
9c7f852e
TI
4643 * ALC883 support
4644 *
4645 * ALC883 is almost identical with ALC880 but has cleaner and more flexible
4646 * configuration. Each pin widget can choose any input DACs and a mixer.
4647 * Each ADC is connected from a mixer of all inputs. This makes possible
4648 * 6-channel independent captures.
4649 *
4650 * In addition, an independent DAC for the multi-playback (not used in this
4651 * driver yet).
df694daa 4652 */
9c7f852e
TI
4653#define ALC883_DIGOUT_NID 0x06
4654#define ALC883_DIGIN_NID 0x0a
df694daa 4655
9c7f852e
TI
4656static hda_nid_t alc883_dac_nids[4] = {
4657 /* front, rear, clfe, rear_surr */
4658 0x02, 0x04, 0x03, 0x05
4659};
df694daa 4660
9c7f852e
TI
4661static hda_nid_t alc883_adc_nids[2] = {
4662 /* ADC1-2 */
4663 0x08, 0x09,
4664};
4665/* input MUX */
4666/* FIXME: should be a matrix-type input source selection */
df694daa 4667
9c7f852e
TI
4668static struct hda_input_mux alc883_capture_source = {
4669 .num_items = 4,
4670 .items = {
4671 { "Mic", 0x0 },
4672 { "Front Mic", 0x1 },
4673 { "Line", 0x2 },
4674 { "CD", 0x4 },
4675 },
4676};
4677#define alc883_mux_enum_info alc_mux_enum_info
4678#define alc883_mux_enum_get alc_mux_enum_get
df694daa 4679
9c7f852e
TI
4680static int alc883_mux_enum_put(struct snd_kcontrol *kcontrol,
4681 struct snd_ctl_elem_value *ucontrol)
4682{
4683 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4684 struct alc_spec *spec = codec->spec;
4685 const struct hda_input_mux *imux = spec->input_mux;
4686 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
4687 static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
4688 hda_nid_t nid = capture_mixers[adc_idx];
4689 unsigned int *cur_val = &spec->cur_mux[adc_idx];
4690 unsigned int i, idx;
4691
4692 idx = ucontrol->value.enumerated.item[0];
4693 if (idx >= imux->num_items)
4694 idx = imux->num_items - 1;
4695 if (*cur_val == idx && ! codec->in_resume)
4696 return 0;
4697 for (i = 0; i < imux->num_items; i++) {
4698 unsigned int v = (i == idx) ? 0x7000 : 0x7080;
4699 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4700 v | (imux->items[i].index << 8));
4701 }
4702 *cur_val = idx;
4703 return 1;
4704}
4705/*
4706 * 2ch mode
4707 */
4708static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
4709 { 2, NULL }
4710};
4711
4712/*
4713 * 2ch mode
4714 */
4715static struct hda_verb alc883_3ST_ch2_init[] = {
4716 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
4717 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
4718 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
4719 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
4720 { } /* end */
4721};
4722
4723/*
4724 * 6ch mode
4725 */
4726static struct hda_verb alc883_3ST_ch6_init[] = {
4727 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4728 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
4729 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
4730 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4731 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
4732 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
4733 { } /* end */
4734};
4735
4736static struct hda_channel_mode alc883_3ST_6ch_modes[2] = {
4737 { 2, alc883_3ST_ch2_init },
4738 { 6, alc883_3ST_ch6_init },
4739};
4740
4741/*
4742 * 6ch mode
4743 */
4744static struct hda_verb alc883_sixstack_ch6_init[] = {
4745 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
4746 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4747 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4748 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4749 { } /* end */
4750};
4751
4752/*
4753 * 8ch mode
4754 */
4755static struct hda_verb alc883_sixstack_ch8_init[] = {
4756 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4757 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4758 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4759 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4760 { } /* end */
4761};
4762
4763static struct hda_channel_mode alc883_sixstack_modes[2] = {
4764 { 6, alc883_sixstack_ch6_init },
4765 { 8, alc883_sixstack_ch8_init },
4766};
4767
4768/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
4769 * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
4770 */
4771
4772static struct snd_kcontrol_new alc883_base_mixer[] = {
df694daa 4773 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9c7f852e
TI
4774 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4775 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
4776 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
4777 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
4778 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
4779 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
4780 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
4781 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
4782 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
4783 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
df694daa
KY
4784 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4785 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4786 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4787 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4788 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4789 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9c7f852e
TI
4790 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
4791 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
4792 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4793 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
4794 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
4795 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
4796 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
4797 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
4798 {
4799 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4800 /* .name = "Capture Source", */
4801 .name = "Input Source",
4802 .count = 2,
4803 .info = alc883_mux_enum_info,
4804 .get = alc883_mux_enum_get,
4805 .put = alc883_mux_enum_put,
4806 },
df694daa 4807 { } /* end */
834be88d
TI
4808};
4809
9c7f852e
TI
4810static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
4811 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4812 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4813 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
4814 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4815 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4816 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4817 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4818 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4819 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4820 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
4821 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
4822 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4823 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
4824 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
4825 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
4826 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
4827 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
4828 {
4829 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4830 /* .name = "Capture Source", */
4831 .name = "Input Source",
4832 .count = 2,
4833 .info = alc883_mux_enum_info,
4834 .get = alc883_mux_enum_get,
4835 .put = alc883_mux_enum_put,
4836 },
4837 { } /* end */
4838};
df694daa 4839
9c7f852e
TI
4840static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
4841 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4842 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4843 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
4844 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
4845 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
4846 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
4847 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
4848 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
4849 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
4850 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4851 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4852 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4853 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4854 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4855 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4856 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
4857 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
4858 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4859 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
4860 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
4861 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
4862 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
4863 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
4864 {
4865 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4866 /* .name = "Capture Source", */
4867 .name = "Input Source",
4868 .count = 2,
4869 .info = alc883_mux_enum_info,
4870 .get = alc883_mux_enum_get,
4871 .put = alc883_mux_enum_put,
4872 },
4873 { } /* end */
4874};
4875
4876static struct snd_kcontrol_new alc883_chmode_mixer[] = {
4877 {
4878 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4879 .name = "Channel Mode",
4880 .info = alc_ch_mode_info,
4881 .get = alc_ch_mode_get,
4882 .put = alc_ch_mode_put,
4883 },
4884 { } /* end */
4885};
4886
4887static struct hda_verb alc883_init_verbs[] = {
4888 /* ADC1: mute amp left and right */
4889 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
df694daa 4890 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9c7f852e
TI
4891 /* ADC2: mute amp left and right */
4892 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
df694daa 4893 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9c7f852e
TI
4894 /* Front mixer: unmute input/output amp left and right (volume = 0) */
4895 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4896 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4897 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4898 /* Rear mixer */
4899 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4900 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4901 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4902 /* CLFE mixer */
4903 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4904 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4905 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4906 /* Side mixer */
4907 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4908 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4909 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
df694daa 4910
df694daa
KY
4911 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4912 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4913 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4914 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4915 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
4916
9c7f852e
TI
4917 /* Front Pin: output 0 (0x0c) */
4918 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4919 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4920 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
4921 /* Rear Pin: output 1 (0x0d) */
4922 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4923 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4924 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
4925 /* CLFE Pin: output 2 (0x0e) */
4926 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4927 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4928 {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
4929 /* Side Pin: output 3 (0x0f) */
4930 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4931 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4932 {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
4933 /* Mic (rear) pin: input vref at 80% */
4934 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4935 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4936 /* Front Mic pin: input vref at 80% */
4937 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4938 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4939 /* Line In pin: input */
4940 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4941 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4942 /* Line-2 In: Headphone output (output 0 - 0x0c) */
4943 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4944 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4945 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
4946 /* CD pin widget for input */
4947 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4948
4949 /* FIXME: use matrix-type input source selection */
4950 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
4951 /* Input mixer2 */
4952 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4953 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4954 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4955 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
4956 /* Input mixer3 */
4957 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4958 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4959 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4960 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
4961 { }
4962};
4963
4964/*
4965 * generic initialization of ADC, input mixers and output mixers
4966 */
4967static struct hda_verb alc883_auto_init_verbs[] = {
4968 /*
4969 * Unmute ADC0-2 and set the default input to mic-in
4970 */
4971 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
4972 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4973 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
4974 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4975
4976 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4977 * mixer widget
4978 * Note: PASD motherboards uses the Line In 2 as the input for front panel
4979 * mic (mic 2)
4980 */
4981 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4982 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4983 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4984 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4985 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4986 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
4987
4988 /*
4989 * Set up output mixers (0x0c - 0x0f)
4990 */
4991 /* set vol=0 to output mixers */
4992 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4993 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4994 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4995 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4996 /* set up input amps for analog loopback */
4997 /* Amp Indices: DAC = 0, mixer = 1 */
4998 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4999 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5000 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5001 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5002 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5003 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5004 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5005 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5006 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5007 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5008
5009 /* FIXME: use matrix-type input source selection */
5010 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5011 /* Input mixer1 */
5012 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5013 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5014 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
5015 //{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
5016 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
5017 /* Input mixer2 */
5018 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5019 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5020 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
5021 //{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
5022 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
5023
5024 { }
5025};
5026
5027/* capture mixer elements */
5028static struct snd_kcontrol_new alc883_capture_mixer[] = {
5029 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5030 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5031 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5032 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5033 {
5034 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5035 /* The multiple "Capture Source" controls confuse alsamixer
5036 * So call somewhat different..
5037 * FIXME: the controls appear in the "playback" view!
5038 */
5039 /* .name = "Capture Source", */
5040 .name = "Input Source",
5041 .count = 2,
5042 .info = alc882_mux_enum_info,
5043 .get = alc882_mux_enum_get,
5044 .put = alc882_mux_enum_put,
5045 },
5046 { } /* end */
5047};
5048
5049/* pcm configuration: identiacal with ALC880 */
5050#define alc883_pcm_analog_playback alc880_pcm_analog_playback
5051#define alc883_pcm_analog_capture alc880_pcm_analog_capture
5052#define alc883_pcm_digital_playback alc880_pcm_digital_playback
5053#define alc883_pcm_digital_capture alc880_pcm_digital_capture
5054
5055/*
5056 * configuration and preset
5057 */
5058static struct hda_board_config alc883_cfg_tbl[] = {
5059 { .modelname = "3stack-dig", .config = ALC883_3ST_2ch_DIG },
4b146cb0
TI
5060 { .modelname = "3stack-6ch-dig", .config = ALC883_3ST_6ch_DIG },
5061 { .pci_subvendor = 0x1019, .pci_subdevice = 0x6668,
5062 .config = ALC883_3ST_6ch_DIG }, /* ECS to Intel*/
5063 { .modelname = "3stack-6ch", .config = ALC883_3ST_6ch },
5064 { .pci_subvendor = 0x108e, .pci_subdevice = 0x534d,
5065 .config = ALC883_3ST_6ch },
2aaeee8b
TD
5066 { .pci_subvendor = 0x8086, .pci_subdevice = 0xd601,
5067 .config = ALC883_3ST_6ch }, /* D102GGC */
9c7f852e 5068 { .modelname = "6stack-dig", .config = ALC883_6ST_DIG },
9c7f852e
TI
5069 { .pci_subvendor = 0x1462, .pci_subdevice = 0x6668,
5070 .config = ALC883_6ST_DIG }, /* MSI */
5071 { .pci_subvendor = 0x105b, .pci_subdevice = 0x6668,
5072 .config = ALC883_6ST_DIG }, /* Foxconn */
4b146cb0 5073 { .modelname = "6stack-dig-demo", .config = ALC888_DEMO_BOARD },
bab282b9
VA
5074 { .modelname = "acer", .config = ALC883_ACER },
5075 { .pci_subvendor = 0x1025, .pci_subdevice = 0/*0x0102*/,
5076 .config = ALC883_ACER },
9c7f852e
TI
5077 { .modelname = "auto", .config = ALC883_AUTO },
5078 {}
5079};
5080
5081static struct alc_config_preset alc883_presets[] = {
5082 [ALC883_3ST_2ch_DIG] = {
5083 .mixers = { alc883_3ST_2ch_mixer },
5084 .init_verbs = { alc883_init_verbs },
5085 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5086 .dac_nids = alc883_dac_nids,
5087 .dig_out_nid = ALC883_DIGOUT_NID,
5088 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5089 .adc_nids = alc883_adc_nids,
5090 .dig_in_nid = ALC883_DIGIN_NID,
5091 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
5092 .channel_mode = alc883_3ST_2ch_modes,
5093 .input_mux = &alc883_capture_source,
5094 },
5095 [ALC883_3ST_6ch_DIG] = {
5096 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
5097 .init_verbs = { alc883_init_verbs },
5098 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5099 .dac_nids = alc883_dac_nids,
5100 .dig_out_nid = ALC883_DIGOUT_NID,
5101 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5102 .adc_nids = alc883_adc_nids,
5103 .dig_in_nid = ALC883_DIGIN_NID,
5104 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
5105 .channel_mode = alc883_3ST_6ch_modes,
4e195a7b 5106 .need_dac_fix = 1,
9c7f852e
TI
5107 .input_mux = &alc883_capture_source,
5108 },
5109 [ALC883_3ST_6ch] = {
5110 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
5111 .init_verbs = { alc883_init_verbs },
5112 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5113 .dac_nids = alc883_dac_nids,
5114 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5115 .adc_nids = alc883_adc_nids,
5116 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
5117 .channel_mode = alc883_3ST_6ch_modes,
4e195a7b 5118 .need_dac_fix = 1,
9c7f852e
TI
5119 .input_mux = &alc883_capture_source,
5120 },
5121 [ALC883_6ST_DIG] = {
5122 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
5123 .init_verbs = { alc883_init_verbs },
5124 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5125 .dac_nids = alc883_dac_nids,
5126 .dig_out_nid = ALC883_DIGOUT_NID,
5127 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5128 .adc_nids = alc883_adc_nids,
5129 .dig_in_nid = ALC883_DIGIN_NID,
5130 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
5131 .channel_mode = alc883_sixstack_modes,
5132 .input_mux = &alc883_capture_source,
5133 },
5134 [ALC888_DEMO_BOARD] = {
5135 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
5136 .init_verbs = { alc883_init_verbs },
5137 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5138 .dac_nids = alc883_dac_nids,
5139 .dig_out_nid = ALC883_DIGOUT_NID,
5140 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5141 .adc_nids = alc883_adc_nids,
5142 .dig_in_nid = ALC883_DIGIN_NID,
5143 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
5144 .channel_mode = alc883_sixstack_modes,
5145 .input_mux = &alc883_capture_source,
5146 },
bab282b9
VA
5147 [ALC883_ACER] = {
5148 .mixers = { alc883_base_mixer,
5149 alc883_chmode_mixer },
5150 /* On TravelMate laptops, GPIO 0 enables the internal speaker
5151 * and the headphone jack. Turn this on and rely on the
5152 * standard mute methods whenever the user wants to turn
5153 * these outputs off.
5154 */
5155 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
5156 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5157 .dac_nids = alc883_dac_nids,
5158 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5159 .adc_nids = alc883_adc_nids,
5160 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
5161 .channel_mode = alc883_3ST_2ch_modes,
5162 .input_mux = &alc883_capture_source,
5163 },
9c7f852e
TI
5164};
5165
5166
5167/*
5168 * BIOS auto configuration
5169 */
5170static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
5171 hda_nid_t nid, int pin_type,
5172 int dac_idx)
5173{
5174 /* set as output */
5175 struct alc_spec *spec = codec->spec;
5176 int idx;
5177
5178 if (spec->multiout.dac_nids[dac_idx] == 0x25)
5179 idx = 4;
5180 else
5181 idx = spec->multiout.dac_nids[dac_idx] - 2;
5182
5183 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5184 pin_type);
5185 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5186 AMP_OUT_UNMUTE);
5187 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
5188
5189}
5190
5191static void alc883_auto_init_multi_out(struct hda_codec *codec)
5192{
5193 struct alc_spec *spec = codec->spec;
5194 int i;
5195
5196 for (i = 0; i <= HDA_SIDE; i++) {
5197 hda_nid_t nid = spec->autocfg.line_out_pins[i];
5198 if (nid)
5199 alc883_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
5200 }
5201}
5202
5203static void alc883_auto_init_hp_out(struct hda_codec *codec)
5204{
5205 struct alc_spec *spec = codec->spec;
5206 hda_nid_t pin;
5207
5208 pin = spec->autocfg.hp_pin;
5209 if (pin) /* connect to front */
5210 /* use dac 0 */
5211 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
5212}
5213
5214#define alc883_is_input_pin(nid) alc880_is_input_pin(nid)
5215#define ALC883_PIN_CD_NID ALC880_PIN_CD_NID
5216
5217static void alc883_auto_init_analog_input(struct hda_codec *codec)
5218{
5219 struct alc_spec *spec = codec->spec;
5220 int i;
5221
5222 for (i = 0; i < AUTO_PIN_LAST; i++) {
5223 hda_nid_t nid = spec->autocfg.input_pins[i];
5224 if (alc883_is_input_pin(nid)) {
5225 snd_hda_codec_write(codec, nid, 0,
5226 AC_VERB_SET_PIN_WIDGET_CONTROL,
5227 (i <= AUTO_PIN_FRONT_MIC ?
5228 PIN_VREF80 : PIN_IN));
5229 if (nid != ALC883_PIN_CD_NID)
5230 snd_hda_codec_write(codec, nid, 0,
5231 AC_VERB_SET_AMP_GAIN_MUTE,
5232 AMP_OUT_MUTE);
5233 }
5234 }
5235}
5236
5237/* almost identical with ALC880 parser... */
5238static int alc883_parse_auto_config(struct hda_codec *codec)
5239{
5240 struct alc_spec *spec = codec->spec;
5241 int err = alc880_parse_auto_config(codec);
5242
5243 if (err < 0)
5244 return err;
5245 else if (err > 0)
5246 /* hack - override the init verbs */
5247 spec->init_verbs[0] = alc883_auto_init_verbs;
5248 spec->mixers[spec->num_mixers] = alc883_capture_mixer;
5249 spec->num_mixers++;
5250 return err;
5251}
5252
5253/* additional initialization for auto-configuration model */
5254static void alc883_auto_init(struct hda_codec *codec)
5255{
5256 alc883_auto_init_multi_out(codec);
5257 alc883_auto_init_hp_out(codec);
5258 alc883_auto_init_analog_input(codec);
5259}
5260
5261static int patch_alc883(struct hda_codec *codec)
5262{
5263 struct alc_spec *spec;
5264 int err, board_config;
5265
5266 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5267 if (spec == NULL)
5268 return -ENOMEM;
5269
5270 codec->spec = spec;
5271
5272 board_config = snd_hda_check_board_config(codec, alc883_cfg_tbl);
5273 if (board_config < 0 || board_config >= ALC883_MODEL_LAST) {
5274 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
5275 "trying auto-probe from BIOS...\n");
5276 board_config = ALC883_AUTO;
5277 }
5278
5279 if (board_config == ALC883_AUTO) {
5280 /* automatic parse from the BIOS config */
5281 err = alc883_parse_auto_config(codec);
5282 if (err < 0) {
5283 alc_free(codec);
5284 return err;
5285 } else if (! err) {
5286 printk(KERN_INFO
5287 "hda_codec: Cannot set up configuration "
5288 "from BIOS. Using base mode...\n");
5289 board_config = ALC883_3ST_2ch_DIG;
5290 }
5291 }
5292
5293 if (board_config != ALC883_AUTO)
5294 setup_preset(spec, &alc883_presets[board_config]);
5295
5296 spec->stream_name_analog = "ALC883 Analog";
5297 spec->stream_analog_playback = &alc883_pcm_analog_playback;
5298 spec->stream_analog_capture = &alc883_pcm_analog_capture;
5299
5300 spec->stream_name_digital = "ALC883 Digital";
5301 spec->stream_digital_playback = &alc883_pcm_digital_playback;
5302 spec->stream_digital_capture = &alc883_pcm_digital_capture;
5303
4b146cb0
TI
5304 if (! spec->adc_nids && spec->input_mux) {
5305 spec->adc_nids = alc883_adc_nids;
5306 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
5307 }
9c7f852e
TI
5308
5309 codec->patch_ops = alc_patch_ops;
5310 if (board_config == ALC883_AUTO)
5311 spec->init_hook = alc883_auto_init;
5312
5313 return 0;
5314}
5315
5316/*
5317 * ALC262 support
5318 */
5319
5320#define ALC262_DIGOUT_NID ALC880_DIGOUT_NID
5321#define ALC262_DIGIN_NID ALC880_DIGIN_NID
5322
5323#define alc262_dac_nids alc260_dac_nids
5324#define alc262_adc_nids alc882_adc_nids
5325#define alc262_adc_nids_alt alc882_adc_nids_alt
5326
5327#define alc262_modes alc260_modes
5328#define alc262_capture_source alc882_capture_source
5329
5330static struct snd_kcontrol_new alc262_base_mixer[] = {
5331 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5332 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5333 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5334 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5335 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5336 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5337 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5338 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5339 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
5340 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
5341 /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
5342 HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
5343 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
5344 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5345 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5346 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
5347 { } /* end */
5348};
5349
5350static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
5351 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5352 HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5353 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5354 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5355 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
5356
5357 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5358 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5359 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
5360 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
5361 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5362 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5363 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5364 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5365 HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
5366 HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
5367 HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
5368 HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
5369 { } /* end */
5370};
5371
5372#define alc262_capture_mixer alc882_capture_mixer
5373#define alc262_capture_alt_mixer alc882_capture_alt_mixer
5374
5375/*
5376 * generic initialization of ADC, input mixers and output mixers
5377 */
5378static struct hda_verb alc262_init_verbs[] = {
5379 /*
5380 * Unmute ADC0-2 and set the default input to mic-in
5381 */
5382 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5383 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5384 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5385 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5386 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5387 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5388
5389 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5390 * mixer widget
5391 * Note: PASD motherboards uses the Line In 2 as the input for front panel
5392 * mic (mic 2)
5393 */
5394 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5395 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5396 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5397 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
5398 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
5399 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
5400
5401 /*
df694daa
KY
5402 * Set up output mixers (0x0c - 0x0e)
5403 */
5404 /* set vol=0 to output mixers */
5405 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5406 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5407 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5408 /* set up input amps for analog loopback */
5409 /* Amp Indices: DAC = 0, mixer = 1 */
5410 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5411 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5412 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5413 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5414 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5415 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5416
5417 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5418 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5419 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5420 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5421 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5422 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5423
5424 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5425 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5426 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5427 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5428 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5429
5430 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5431 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5432
5433 /* FIXME: use matrix-type input source selection */
5434 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5435 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5436 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5437 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5438 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5439 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5440 /* Input mixer2 */
5441 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5442 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5443 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5444 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5445 /* Input mixer3 */
5446 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5447 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5448 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5449 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5450
5451 { }
5452};
1da177e4 5453
834be88d
TI
5454/*
5455 * fujitsu model
5456 * 0x14 = headphone/spdif-out, 0x15 = internal speaker
5457 */
5458
5459#define ALC_HP_EVENT 0x37
5460
5461static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
5462 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
5463 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5464 {}
5465};
5466
5467static struct hda_input_mux alc262_fujitsu_capture_source = {
5468 .num_items = 2,
5469 .items = {
5470 { "Mic", 0x0 },
5471 { "CD", 0x4 },
5472 },
5473};
5474
9c7f852e
TI
5475static struct hda_input_mux alc262_HP_capture_source = {
5476 .num_items = 5,
5477 .items = {
5478 { "Mic", 0x0 },
5479 { "Front Mic", 0x3 },
5480 { "Line", 0x2 },
5481 { "CD", 0x4 },
5482 { "AUX IN", 0x6 },
5483 },
5484};
5485
834be88d
TI
5486/* mute/unmute internal speaker according to the hp jack and mute state */
5487static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
5488{
5489 struct alc_spec *spec = codec->spec;
5490 unsigned int mute;
5491
5492 if (force || ! spec->sense_updated) {
5493 unsigned int present;
5494 /* need to execute and sync at first */
5495 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
5496 present = snd_hda_codec_read(codec, 0x14, 0,
5497 AC_VERB_GET_PIN_SENSE, 0);
5498 spec->jack_present = (present & 0x80000000) != 0;
5499 spec->sense_updated = 1;
5500 }
5501 if (spec->jack_present) {
5502 /* mute internal speaker */
5503 snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
5504 0x80, 0x80);
5505 snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
5506 0x80, 0x80);
5507 } else {
5508 /* unmute internal speaker if necessary */
5509 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
5510 snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
5511 0x80, mute & 0x80);
5512 mute = snd_hda_codec_amp_read(codec, 0x14, 1, HDA_OUTPUT, 0);
5513 snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
5514 0x80, mute & 0x80);
5515 }
5516}
5517
5518/* unsolicited event for HP jack sensing */
5519static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
5520 unsigned int res)
5521{
5522 if ((res >> 26) != ALC_HP_EVENT)
5523 return;
5524 alc262_fujitsu_automute(codec, 1);
5525}
5526
5527/* bind volumes of both NID 0x0c and 0x0d */
5528static int alc262_fujitsu_master_vol_put(struct snd_kcontrol *kcontrol,
5529 struct snd_ctl_elem_value *ucontrol)
5530{
5531 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5532 long *valp = ucontrol->value.integer.value;
5533 int change;
5534
5535 change = snd_hda_codec_amp_update(codec, 0x0c, 0, HDA_OUTPUT, 0,
5536 0x7f, valp[0] & 0x7f);
5537 change |= snd_hda_codec_amp_update(codec, 0x0c, 1, HDA_OUTPUT, 0,
5538 0x7f, valp[1] & 0x7f);
5539 snd_hda_codec_amp_update(codec, 0x0d, 0, HDA_OUTPUT, 0,
5540 0x7f, valp[0] & 0x7f);
5541 snd_hda_codec_amp_update(codec, 0x0d, 1, HDA_OUTPUT, 0,
5542 0x7f, valp[1] & 0x7f);
5543 return change;
5544}
5545
5546/* bind hp and internal speaker mute (with plug check) */
5547static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
5548 struct snd_ctl_elem_value *ucontrol)
5549{
5550 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5551 long *valp = ucontrol->value.integer.value;
5552 int change;
5553
5554 change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
5555 0x80, valp[0] ? 0 : 0x80);
5556 change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
5557 0x80, valp[1] ? 0 : 0x80);
5558 if (change || codec->in_resume)
5559 alc262_fujitsu_automute(codec, codec->in_resume);
5560 return change;
5561}
5562
5563static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
5564 {
5565 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5566 .name = "Master Playback Volume",
5567 .info = snd_hda_mixer_amp_volume_info,
5568 .get = snd_hda_mixer_amp_volume_get,
5569 .put = alc262_fujitsu_master_vol_put,
c2566524 5570 .tlv = { .c = snd_hda_mixer_amp_tlv },
834be88d
TI
5571 .private_value = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
5572 },
5573 {
5574 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5575 .name = "Master Playback Switch",
5576 .info = snd_hda_mixer_amp_switch_info,
5577 .get = snd_hda_mixer_amp_switch_get,
5578 .put = alc262_fujitsu_master_sw_put,
5579 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
5580 },
5581 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5582 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5583 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5584 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5585 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5586 { } /* end */
5587};
5588
304dcaac
TI
5589/* additional init verbs for Benq laptops */
5590static struct hda_verb alc262_EAPD_verbs[] = {
5591 {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5592 {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
5593 {}
5594};
5595
df694daa
KY
5596/* add playback controls from the parsed DAC table */
5597static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
5598{
5599 hda_nid_t nid;
5600 int err;
5601
5602 spec->multiout.num_dacs = 1; /* only use one dac */
5603 spec->multiout.dac_nids = spec->private_dac_nids;
5604 spec->multiout.dac_nids[0] = 2;
5605
5606 nid = cfg->line_out_pins[0];
5607 if (nid) {
5608 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Front Playback Volume",
5609 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT))) < 0)
5610 return err;
5611 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Front Playback Switch",
5612 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
5613 return err;
5614 }
5615
82bc955f 5616 nid = cfg->speaker_pins[0];
df694daa
KY
5617 if (nid) {
5618 if (nid == 0x16) {
5619 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Speaker Playback Volume",
5620 HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT))) < 0)
5621 return err;
5622 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Speaker Playback Switch",
5623 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
5624 return err;
5625 } else {
df694daa
KY
5626 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Speaker Playback Switch",
5627 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
5628 return err;
5629 }
5630 }
5631 nid = cfg->hp_pin;
5632 if (nid) {
5633 /* spec->multiout.hp_nid = 2; */
5634 if (nid == 0x16) {
5635 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Headphone Playback Volume",
5636 HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT))) < 0)
5637 return err;
5638 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
5639 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
5640 return err;
5641 } else {
df694daa
KY
5642 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
5643 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
5644 return err;
5645 }
5646 }
5647 return 0;
5648}
5649
5650/* identical with ALC880 */
5651#define alc262_auto_create_analog_input_ctls alc880_auto_create_analog_input_ctls
5652
5653/*
5654 * generic initialization of ADC, input mixers and output mixers
5655 */
5656static struct hda_verb alc262_volume_init_verbs[] = {
5657 /*
5658 * Unmute ADC0-2 and set the default input to mic-in
5659 */
5660 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5661 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5662 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5663 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5664 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5665 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5666
5667 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5668 * mixer widget
5669 * Note: PASD motherboards uses the Line In 2 as the input for front panel
5670 * mic (mic 2)
5671 */
5672 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5673 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5674 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5675 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
5676 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
5677 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
5678
5679 /*
5680 * Set up output mixers (0x0c - 0x0f)
5681 */
5682 /* set vol=0 to output mixers */
5683 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5684 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5685 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5686
5687 /* set up input amps for analog loopback */
5688 /* Amp Indices: DAC = 0, mixer = 1 */
5689 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5690 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5691 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5692 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5693 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5694 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5695
5696 /* FIXME: use matrix-type input source selection */
5697 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5698 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5699 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5700 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5701 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5702 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5703 /* Input mixer2 */
5704 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5705 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5706 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5707 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5708 /* Input mixer3 */
5709 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5710 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5711 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5712 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5713
5714 { }
5715};
5716
9c7f852e
TI
5717static struct hda_verb alc262_HP_BPC_init_verbs[] = {
5718 /*
5719 * Unmute ADC0-2 and set the default input to mic-in
5720 */
5721 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5722 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5723 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5724 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5725 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5726 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5727
5728 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5729 * mixer widget
5730 * Note: PASD motherboards uses the Line In 2 as the input for front panel
5731 * mic (mic 2)
5732 */
5733 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5734 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5735 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5736 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
5737 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
5738 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
5739 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
5740 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(6)},
5741
5742 /*
5743 * Set up output mixers (0x0c - 0x0e)
5744 */
5745 /* set vol=0 to output mixers */
5746 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5747 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5748 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5749
5750 /* set up input amps for analog loopback */
5751 /* Amp Indices: DAC = 0, mixer = 1 */
5752 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5753 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5754 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5755 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5756 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5757 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5758
5759 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5760 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5761 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5762
5763 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5764 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5765
5766 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5767 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5768
5769 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5770 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5771 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5772 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5773 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5774
5775 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
5776 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
5777 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
5778 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
5779 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
5780 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
5781
5782
5783 /* FIXME: use matrix-type input source selection */
5784 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5785 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5786 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5787 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
5788 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
5789 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
5790 /* Input mixer2 */
5791 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5792 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
5793 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
5794 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
5795 /* Input mixer3 */
5796 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5797 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
5798 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
5799 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
5800
5801 { }
5802};
5803
df694daa
KY
5804/* pcm configuration: identiacal with ALC880 */
5805#define alc262_pcm_analog_playback alc880_pcm_analog_playback
5806#define alc262_pcm_analog_capture alc880_pcm_analog_capture
5807#define alc262_pcm_digital_playback alc880_pcm_digital_playback
5808#define alc262_pcm_digital_capture alc880_pcm_digital_capture
5809
5810/*
5811 * BIOS auto configuration
5812 */
5813static int alc262_parse_auto_config(struct hda_codec *codec)
5814{
5815 struct alc_spec *spec = codec->spec;
5816 int err;
5817 static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
5818
5819 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5820 alc262_ignore)) < 0)
5821 return err;
82bc955f 5822 if (! spec->autocfg.line_outs)
df694daa
KY
5823 return 0; /* can't find valid BIOS pin config */
5824 if ((err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
5825 (err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
5826 return err;
5827
5828 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5829
5830 if (spec->autocfg.dig_out_pin)
5831 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
5832 if (spec->autocfg.dig_in_pin)
5833 spec->dig_in_nid = ALC262_DIGIN_NID;
5834
5835 if (spec->kctl_alloc)
5836 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
5837
5838 spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
a1e8d2da 5839 spec->num_mux_defs = 1;
df694daa
KY
5840 spec->input_mux = &spec->private_imux;
5841
5842 return 1;
5843}
5844
5845#define alc262_auto_init_multi_out alc882_auto_init_multi_out
5846#define alc262_auto_init_hp_out alc882_auto_init_hp_out
5847#define alc262_auto_init_analog_input alc882_auto_init_analog_input
5848
5849
5850/* init callback for auto-configuration model -- overriding the default init */
ae6b813a 5851static void alc262_auto_init(struct hda_codec *codec)
df694daa 5852{
df694daa
KY
5853 alc262_auto_init_multi_out(codec);
5854 alc262_auto_init_hp_out(codec);
5855 alc262_auto_init_analog_input(codec);
df694daa
KY
5856}
5857
5858/*
5859 * configuration and preset
5860 */
5861static struct hda_board_config alc262_cfg_tbl[] = {
5862 { .modelname = "basic", .config = ALC262_BASIC },
834be88d 5863 { .modelname = "fujitsu", .config = ALC262_FUJITSU },
9c7f852e
TI
5864 { .pci_subvendor = 0x10cf, .pci_subdevice = 0x1397,
5865 .config = ALC262_FUJITSU },
6d177ba7 5866 { .modelname = "hp-bpc", .config = ALC262_HP_BPC },
9c7f852e
TI
5867 { .pci_subvendor = 0x103c, .pci_subdevice = 0x208c,
5868 .config = ALC262_HP_BPC }, /* xw4400 */
5869 { .pci_subvendor = 0x103c, .pci_subdevice = 0x3014,
5870 .config = ALC262_HP_BPC }, /* xw6400 */
5871 { .pci_subvendor = 0x103c, .pci_subdevice = 0x3015,
5872 .config = ALC262_HP_BPC }, /* xw8400 */
5873 { .pci_subvendor = 0x103c, .pci_subdevice = 0x12fe,
5874 .config = ALC262_HP_BPC }, /* xw9400 */
304dcaac
TI
5875 { .modelname = "benq", .config = ALC262_BENQ_ED8 },
5876 { .pci_subvendor = 0x17ff, .pci_subdevice = 0x0560,
5877 .config = ALC262_BENQ_ED8 },
df694daa
KY
5878 { .modelname = "auto", .config = ALC262_AUTO },
5879 {}
5880};
5881
5882static struct alc_config_preset alc262_presets[] = {
5883 [ALC262_BASIC] = {
5884 .mixers = { alc262_base_mixer },
5885 .init_verbs = { alc262_init_verbs },
5886 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
5887 .dac_nids = alc262_dac_nids,
5888 .hp_nid = 0x03,
5889 .num_channel_mode = ARRAY_SIZE(alc262_modes),
5890 .channel_mode = alc262_modes,
a3bcba38 5891 .input_mux = &alc262_capture_source,
df694daa 5892 },
834be88d
TI
5893 [ALC262_FUJITSU] = {
5894 .mixers = { alc262_fujitsu_mixer },
5895 .init_verbs = { alc262_init_verbs, alc262_fujitsu_unsol_verbs },
5896 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
5897 .dac_nids = alc262_dac_nids,
5898 .hp_nid = 0x03,
5899 .dig_out_nid = ALC262_DIGOUT_NID,
5900 .num_channel_mode = ARRAY_SIZE(alc262_modes),
5901 .channel_mode = alc262_modes,
5902 .input_mux = &alc262_fujitsu_capture_source,
ae6b813a 5903 .unsol_event = alc262_fujitsu_unsol_event,
834be88d 5904 },
9c7f852e
TI
5905 [ALC262_HP_BPC] = {
5906 .mixers = { alc262_HP_BPC_mixer },
5907 .init_verbs = { alc262_HP_BPC_init_verbs },
5908 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
5909 .dac_nids = alc262_dac_nids,
5910 .hp_nid = 0x03,
5911 .num_channel_mode = ARRAY_SIZE(alc262_modes),
5912 .channel_mode = alc262_modes,
5913 .input_mux = &alc262_HP_capture_source,
5914 },
304dcaac
TI
5915 [ALC262_BENQ_ED8] = {
5916 .mixers = { alc262_base_mixer },
5917 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
5918 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
5919 .dac_nids = alc262_dac_nids,
5920 .hp_nid = 0x03,
5921 .num_channel_mode = ARRAY_SIZE(alc262_modes),
5922 .channel_mode = alc262_modes,
5923 .input_mux = &alc262_capture_source,
5924 },
df694daa
KY
5925};
5926
5927static int patch_alc262(struct hda_codec *codec)
5928{
5929 struct alc_spec *spec;
5930 int board_config;
5931 int err;
5932
5933 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
5934 if (spec == NULL)
5935 return -ENOMEM;
5936
5937 codec->spec = spec;
5938#if 0
5939 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is under-run */
5940 {
5941 int tmp;
5942 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5943 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5944 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5945 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5946 }
5947#endif
5948
5949 board_config = snd_hda_check_board_config(codec, alc262_cfg_tbl);
9c7f852e 5950
df694daa 5951 if (board_config < 0 || board_config >= ALC262_MODEL_LAST) {
9c7f852e
TI
5952 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
5953 "trying auto-probe from BIOS...\n");
df694daa
KY
5954 board_config = ALC262_AUTO;
5955 }
5956
5957 if (board_config == ALC262_AUTO) {
5958 /* automatic parse from the BIOS config */
5959 err = alc262_parse_auto_config(codec);
5960 if (err < 0) {
5961 alc_free(codec);
5962 return err;
5963 } else if (! err) {
9c7f852e
TI
5964 printk(KERN_INFO
5965 "hda_codec: Cannot set up configuration "
5966 "from BIOS. Using base mode...\n");
df694daa
KY
5967 board_config = ALC262_BASIC;
5968 }
5969 }
5970
5971 if (board_config != ALC262_AUTO)
5972 setup_preset(spec, &alc262_presets[board_config]);
5973
5974 spec->stream_name_analog = "ALC262 Analog";
5975 spec->stream_analog_playback = &alc262_pcm_analog_playback;
5976 spec->stream_analog_capture = &alc262_pcm_analog_capture;
5977
5978 spec->stream_name_digital = "ALC262 Digital";
5979 spec->stream_digital_playback = &alc262_pcm_digital_playback;
5980 spec->stream_digital_capture = &alc262_pcm_digital_capture;
5981
5982 if (! spec->adc_nids && spec->input_mux) {
5983 /* check whether NID 0x07 is valid */
4a471b7d
TI
5984 unsigned int wcap = get_wcaps(codec, 0x07);
5985
df694daa
KY
5986 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
5987 if (wcap != AC_WID_AUD_IN) {
5988 spec->adc_nids = alc262_adc_nids_alt;
5989 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
5990 spec->mixers[spec->num_mixers] = alc262_capture_alt_mixer;
5991 spec->num_mixers++;
5992 } else {
5993 spec->adc_nids = alc262_adc_nids;
5994 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
5995 spec->mixers[spec->num_mixers] = alc262_capture_mixer;
5996 spec->num_mixers++;
5997 }
5998 }
5999
6000 codec->patch_ops = alc_patch_ops;
6001 if (board_config == ALC262_AUTO)
ae6b813a 6002 spec->init_hook = alc262_auto_init;
834be88d 6003
df694daa
KY
6004 return 0;
6005}
6006
df694daa
KY
6007/*
6008 * ALC861 channel source setting (2/6 channel selection for 3-stack)
6009 */
6010
6011/*
6012 * set the path ways for 2 channel output
6013 * need to set the codec line out and mic 1 pin widgets to inputs
6014 */
6015static struct hda_verb alc861_threestack_ch2_init[] = {
6016 /* set pin widget 1Ah (line in) for input */
6017 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
6018 /* set pin widget 18h (mic1/2) for input, for mic also enable the vref */
6019 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
6020
9c7f852e
TI
6021 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
6022#if 0
6023 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
6024 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
6025#endif
df694daa
KY
6026 { } /* end */
6027};
6028/*
6029 * 6ch mode
6030 * need to set the codec line out and mic 1 pin widgets to outputs
6031 */
6032static struct hda_verb alc861_threestack_ch6_init[] = {
6033 /* set pin widget 1Ah (line in) for output (Back Surround)*/
6034 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
6035 /* set pin widget 18h (mic1) for output (CLFE)*/
6036 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
6037
6038 { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
9c7f852e 6039 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
df694daa 6040
9c7f852e
TI
6041 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
6042#if 0
6043 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
6044 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
6045#endif
df694daa
KY
6046 { } /* end */
6047};
6048
6049static struct hda_channel_mode alc861_threestack_modes[2] = {
6050 { 2, alc861_threestack_ch2_init },
6051 { 6, alc861_threestack_ch6_init },
6052};
22309c3e
TI
6053/* Set mic1 as input and unmute the mixer */
6054static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
6055 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
6056 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
6057 { } /* end */
6058};
6059/* Set mic1 as output and mute mixer */
6060static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
6061 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
6062 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
6063 { } /* end */
6064};
6065
6066static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
6067 { 2, alc861_uniwill_m31_ch2_init },
6068 { 4, alc861_uniwill_m31_ch4_init },
6069};
df694daa
KY
6070
6071/* patch-ALC861 */
6072
6073static struct snd_kcontrol_new alc861_base_mixer[] = {
6074 /* output mixer control */
6075 HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
6076 HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
6077 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
6078 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
6079 HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
6080
6081 /*Input mixer control */
6082 /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
6083 HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
6084 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
6085 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
6086 HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
6087 HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
6088 HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
6089 HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
6090 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
6091 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
6092
6093 /* Capture mixer control */
6094 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6095 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6096 {
6097 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6098 .name = "Capture Source",
6099 .count = 1,
6100 .info = alc_mux_enum_info,
6101 .get = alc_mux_enum_get,
6102 .put = alc_mux_enum_put,
6103 },
6104 { } /* end */
6105};
6106
6107static struct snd_kcontrol_new alc861_3ST_mixer[] = {
6108 /* output mixer control */
6109 HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
6110 HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
6111 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
6112 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
6113 /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
6114
6115 /* Input mixer control */
6116 /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
6117 HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
6118 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
6119 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
6120 HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
6121 HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
6122 HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
6123 HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
6124 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
6125 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
6126
6127 /* Capture mixer control */
6128 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6129 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6130 {
6131 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6132 .name = "Capture Source",
6133 .count = 1,
6134 .info = alc_mux_enum_info,
6135 .get = alc_mux_enum_get,
6136 .put = alc_mux_enum_put,
6137 },
6138 {
6139 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6140 .name = "Channel Mode",
6141 .info = alc_ch_mode_info,
6142 .get = alc_ch_mode_get,
6143 .put = alc_ch_mode_put,
6144 .private_value = ARRAY_SIZE(alc861_threestack_modes),
6145 },
6146 { } /* end */
6147};
22309c3e
TI
6148static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
6149 /* output mixer control */
6150 HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
6151 HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
6152 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
6153 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
6154 /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
6155
6156 /* Input mixer control */
6157 /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
6158 HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
6159 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
6160 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
6161 HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
6162 HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
6163 HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
6164 HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
6165 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
6166 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
6167
6168 /* Capture mixer control */
6169 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6170 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6171 {
6172 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6173 .name = "Capture Source",
6174 .count = 1,
6175 .info = alc_mux_enum_info,
6176 .get = alc_mux_enum_get,
6177 .put = alc_mux_enum_put,
6178 },
6179 {
6180 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6181 .name = "Channel Mode",
6182 .info = alc_ch_mode_info,
6183 .get = alc_ch_mode_get,
6184 .put = alc_ch_mode_put,
6185 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
6186 },
6187 { } /* end */
6188};
df694daa
KY
6189
6190/*
6191 * generic initialization of ADC, input mixers and output mixers
6192 */
6193static struct hda_verb alc861_base_init_verbs[] = {
6194 /*
6195 * Unmute ADC0 and set the default input to mic-in
6196 */
6197 /* port-A for surround (rear panel) */
6198 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
6199 { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
6200 /* port-B for mic-in (rear panel) with vref */
6201 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
6202 /* port-C for line-in (rear panel) */
6203 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
6204 /* port-D for Front */
6205 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
6206 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
6207 /* port-E for HP out (front panel) */
6208 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
6209 /* route front PCM to HP */
6210 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01 },
6211 /* port-F for mic-in (front panel) with vref */
6212 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
6213 /* port-G for CLFE (rear panel) */
6214 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
6215 { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
6216 /* port-H for side (rear panel) */
6217 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
6218 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
6219 /* CD-in */
6220 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
6221 /* route front mic to ADC1*/
6222 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6223 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6224
6225 /* Unmute DAC0~3 & spdif out*/
6226 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6227 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6228 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6229 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6230 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6231
6232 /* Unmute Mixer 14 (mic) 1c (Line in)*/
6233 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6234 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6235 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6236 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6237
6238 /* Unmute Stereo Mixer 15 */
6239 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6240 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6241 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6242 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c }, //Output 0~12 step
6243
6244 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6245 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6246 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6247 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6248 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6249 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6250 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6251 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6252 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, // hp used DAC 3 (Front)
6253 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6254
6255 { }
6256};
6257
6258static struct hda_verb alc861_threestack_init_verbs[] = {
6259 /*
6260 * Unmute ADC0 and set the default input to mic-in
6261 */
6262 /* port-A for surround (rear panel) */
6263 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6264 /* port-B for mic-in (rear panel) with vref */
6265 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
6266 /* port-C for line-in (rear panel) */
6267 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
6268 /* port-D for Front */
6269 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
6270 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
6271 /* port-E for HP out (front panel) */
6272 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
6273 /* route front PCM to HP */
6274 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01 },
6275 /* port-F for mic-in (front panel) with vref */
6276 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
6277 /* port-G for CLFE (rear panel) */
6278 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6279 /* port-H for side (rear panel) */
6280 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6281 /* CD-in */
6282 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
6283 /* route front mic to ADC1*/
6284 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6285 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6286 /* Unmute DAC0~3 & spdif out*/
6287 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6288 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6289 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6290 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6291 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6292
6293 /* Unmute Mixer 14 (mic) 1c (Line in)*/
6294 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6295 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6296 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6297 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6298
6299 /* Unmute Stereo Mixer 15 */
6300 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6301 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6302 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6303 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c }, //Output 0~12 step
6304
6305 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6306 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6307 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6308 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6309 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6310 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6311 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6312 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6313 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, // hp used DAC 3 (Front)
6314 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6315 { }
6316};
22309c3e
TI
6317
6318static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
6319 /*
6320 * Unmute ADC0 and set the default input to mic-in
6321 */
6322 /* port-A for surround (rear panel) */
6323 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6324 /* port-B for mic-in (rear panel) with vref */
6325 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
6326 /* port-C for line-in (rear panel) */
6327 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
6328 /* port-D for Front */
6329 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
6330 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
6331 /* port-E for HP out (front panel) */
6332 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 }, // this has to be set to VREF80
6333 /* route front PCM to HP */
6334 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01 },
6335 /* port-F for mic-in (front panel) with vref */
6336 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
6337 /* port-G for CLFE (rear panel) */
6338 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6339 /* port-H for side (rear panel) */
6340 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6341 /* CD-in */
6342 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
6343 /* route front mic to ADC1*/
6344 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6345 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6346 /* Unmute DAC0~3 & spdif out*/
6347 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6348 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6349 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6350 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6351 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6352
6353 /* Unmute Mixer 14 (mic) 1c (Line in)*/
6354 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6355 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6356 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6357 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6358
6359 /* Unmute Stereo Mixer 15 */
6360 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6361 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6362 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6363 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c }, //Output 0~12 step
6364
6365 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6366 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6367 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6368 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6369 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6370 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6371 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6372 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6373 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, // hp used DAC 3 (Front)
6374 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6375 { }
6376};
6377
df694daa
KY
6378/*
6379 * generic initialization of ADC, input mixers and output mixers
6380 */
6381static struct hda_verb alc861_auto_init_verbs[] = {
6382 /*
6383 * Unmute ADC0 and set the default input to mic-in
6384 */
6385// {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6386 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6387
6388 /* Unmute DAC0~3 & spdif out*/
6389 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6390 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6391 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6392 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6393 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6394
6395 /* Unmute Mixer 14 (mic) 1c (Line in)*/
6396 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6397 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6398 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6399 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6400
6401 /* Unmute Stereo Mixer 15 */
6402 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6403 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6404 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6405 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
6406
6407 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6408 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6409 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6410 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6411 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6412 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6413 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6414 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6415
6416 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6417 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6418 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6419 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
6420 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6421 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6422 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6423 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
6424
6425 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, // set Mic 1
6426
6427 { }
6428};
6429
6430/* pcm configuration: identiacal with ALC880 */
6431#define alc861_pcm_analog_playback alc880_pcm_analog_playback
6432#define alc861_pcm_analog_capture alc880_pcm_analog_capture
6433#define alc861_pcm_digital_playback alc880_pcm_digital_playback
6434#define alc861_pcm_digital_capture alc880_pcm_digital_capture
6435
6436
6437#define ALC861_DIGOUT_NID 0x07
6438
6439static struct hda_channel_mode alc861_8ch_modes[1] = {
6440 { 8, NULL }
6441};
6442
6443static hda_nid_t alc861_dac_nids[4] = {
6444 /* front, surround, clfe, side */
6445 0x03, 0x06, 0x05, 0x04
6446};
6447
9c7f852e
TI
6448static hda_nid_t alc660_dac_nids[3] = {
6449 /* front, clfe, surround */
6450 0x03, 0x05, 0x06
6451};
6452
df694daa
KY
6453static hda_nid_t alc861_adc_nids[1] = {
6454 /* ADC0-2 */
6455 0x08,
6456};
6457
6458static struct hda_input_mux alc861_capture_source = {
6459 .num_items = 5,
6460 .items = {
6461 { "Mic", 0x0 },
6462 { "Front Mic", 0x3 },
6463 { "Line", 0x1 },
6464 { "CD", 0x4 },
6465 { "Mixer", 0x5 },
6466 },
6467};
6468
6469/* fill in the dac_nids table from the parsed pin configuration */
6470static int alc861_auto_fill_dac_nids(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
6471{
6472 int i;
6473 hda_nid_t nid;
6474
6475 spec->multiout.dac_nids = spec->private_dac_nids;
6476 for (i = 0; i < cfg->line_outs; i++) {
6477 nid = cfg->line_out_pins[i];
6478 if (nid) {
6479 if (i >= ARRAY_SIZE(alc861_dac_nids))
6480 continue;
6481 spec->multiout.dac_nids[i] = alc861_dac_nids[i];
6482 }
6483 }
6484 spec->multiout.num_dacs = cfg->line_outs;
6485 return 0;
6486}
6487
6488/* add playback controls from the parsed DAC table */
6489static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
6490 const struct auto_pin_cfg *cfg)
6491{
6492 char name[32];
6493 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
6494 hda_nid_t nid;
6495 int i, idx, err;
6496
6497 for (i = 0; i < cfg->line_outs; i++) {
6498 nid = spec->multiout.dac_nids[i];
6499 if (! nid)
6500 continue;
6501 if (nid == 0x05) {
6502 /* Center/LFE */
6503 if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "Center Playback Switch",
6504 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
6505 return err;
6506 if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "LFE Playback Switch",
6507 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
6508 return err;
6509 } else {
6510 for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1; idx++)
6511 if (nid == alc861_dac_nids[idx])
6512 break;
6513 sprintf(name, "%s Playback Switch", chname[idx]);
6514 if ((err = add_control(spec, ALC_CTL_BIND_MUTE, name,
6515 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
6516 return err;
6517 }
6518 }
6519 return 0;
6520}
6521
6522static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
6523{
6524 int err;
6525 hda_nid_t nid;
6526
6527 if (! pin)
6528 return 0;
6529
6530 if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
6531 nid = 0x03;
6532 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
6533 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
6534 return err;
6535 spec->multiout.hp_nid = nid;
6536 }
6537 return 0;
6538}
6539
6540/* create playback/capture controls for input pins */
6541static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
6542{
df694daa
KY
6543 struct hda_input_mux *imux = &spec->private_imux;
6544 int i, err, idx, idx1;
6545
6546 for (i = 0; i < AUTO_PIN_LAST; i++) {
6547 switch(cfg->input_pins[i]) {
6548 case 0x0c:
6549 idx1 = 1;
6550 idx = 2; // Line In
6551 break;
6552 case 0x0f:
6553 idx1 = 2;
6554 idx = 2; // Line In
6555 break;
6556 case 0x0d:
6557 idx1 = 0;
6558 idx = 1; // Mic In
6559 break;
6560 case 0x10:
6561 idx1 = 3;
6562 idx = 1; // Mic In
6563 break;
6564 case 0x11:
6565 idx1 = 4;
6566 idx = 0; // CD
6567 break;
6568 default:
6569 continue;
6570 }
6571
4a471b7d
TI
6572 err = new_analog_input(spec, cfg->input_pins[i],
6573 auto_pin_cfg_labels[i], idx, 0x15);
df694daa
KY
6574 if (err < 0)
6575 return err;
6576
4a471b7d 6577 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
df694daa
KY
6578 imux->items[imux->num_items].index = idx1;
6579 imux->num_items++;
6580 }
6581 return 0;
6582}
6583
6584static struct snd_kcontrol_new alc861_capture_mixer[] = {
6585 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6586 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6587
6588 {
6589 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6590 /* The multiple "Capture Source" controls confuse alsamixer
6591 * So call somewhat different..
6592 *FIXME: the controls appear in the "playback" view!
6593 */
6594 /* .name = "Capture Source", */
6595 .name = "Input Source",
6596 .count = 1,
6597 .info = alc_mux_enum_info,
6598 .get = alc_mux_enum_get,
6599 .put = alc_mux_enum_put,
6600 },
6601 { } /* end */
6602};
6603
6604static void alc861_auto_set_output_and_unmute(struct hda_codec *codec, hda_nid_t nid,
6605 int pin_type, int dac_idx)
6606{
6607 /* set as output */
6608
6609 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
6610 snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
6611
6612}
6613
6614static void alc861_auto_init_multi_out(struct hda_codec *codec)
6615{
6616 struct alc_spec *spec = codec->spec;
6617 int i;
6618
6619 for (i = 0; i < spec->autocfg.line_outs; i++) {
6620 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6621 if (nid)
6622 alc861_auto_set_output_and_unmute(codec, nid, PIN_OUT, spec->multiout.dac_nids[i]);
6623 }
6624}
6625
6626static void alc861_auto_init_hp_out(struct hda_codec *codec)
6627{
6628 struct alc_spec *spec = codec->spec;
6629 hda_nid_t pin;
6630
6631 pin = spec->autocfg.hp_pin;
6632 if (pin) /* connect to front */
6633 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP, spec->multiout.dac_nids[0]);
6634}
6635
6636static void alc861_auto_init_analog_input(struct hda_codec *codec)
6637{
6638 struct alc_spec *spec = codec->spec;
6639 int i;
6640
6641 for (i = 0; i < AUTO_PIN_LAST; i++) {
6642 hda_nid_t nid = spec->autocfg.input_pins[i];
6643 if ((nid>=0x0c) && (nid <=0x11)) {
6644 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
6645 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
6646 }
6647 }
6648}
6649
6650/* parse the BIOS configuration and set up the alc_spec */
6651/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
6652static int alc861_parse_auto_config(struct hda_codec *codec)
6653{
6654 struct alc_spec *spec = codec->spec;
6655 int err;
6656 static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
6657
6658 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
6659 alc861_ignore)) < 0)
6660 return err;
82bc955f 6661 if (! spec->autocfg.line_outs)
df694daa
KY
6662 return 0; /* can't find valid BIOS pin config */
6663
6664 if ((err = alc861_auto_fill_dac_nids(spec, &spec->autocfg)) < 0 ||
6665 (err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
6666 (err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pin)) < 0 ||
6667 (err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
6668 return err;
6669
6670 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6671
6672 if (spec->autocfg.dig_out_pin)
6673 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
6674
6675 if (spec->kctl_alloc)
6676 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
6677
6678 spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
6679
a1e8d2da 6680 spec->num_mux_defs = 1;
df694daa
KY
6681 spec->input_mux = &spec->private_imux;
6682
6683 spec->adc_nids = alc861_adc_nids;
6684 spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
6685 spec->mixers[spec->num_mixers] = alc861_capture_mixer;
6686 spec->num_mixers++;
6687
6688 return 1;
6689}
6690
ae6b813a
TI
6691/* additional initialization for auto-configuration model */
6692static void alc861_auto_init(struct hda_codec *codec)
df694daa 6693{
df694daa
KY
6694 alc861_auto_init_multi_out(codec);
6695 alc861_auto_init_hp_out(codec);
6696 alc861_auto_init_analog_input(codec);
df694daa
KY
6697}
6698
6699
6700/*
6701 * configuration and preset
6702 */
6703static struct hda_board_config alc861_cfg_tbl[] = {
6704 { .modelname = "3stack", .config = ALC861_3ST },
9c7f852e
TI
6705 { .pci_subvendor = 0x8086, .pci_subdevice = 0xd600,
6706 .config = ALC861_3ST },
4b146cb0 6707 { .modelname = "3stack-660", .config = ALC660_3ST },
9c7f852e
TI
6708 { .pci_subvendor = 0x1043, .pci_subdevice = 0x81e7,
6709 .config = ALC660_3ST },
df694daa
KY
6710 { .modelname = "3stack-dig", .config = ALC861_3ST_DIG },
6711 { .modelname = "6stack-dig", .config = ALC861_6ST_DIG },
22309c3e
TI
6712 { .modelname = "uniwill-m31", .config = ALC861_UNIWILL_M31},
6713 { .pci_subvendor = 0x1584, .pci_subdevice = 0x9072,
6714 .config = ALC861_UNIWILL_M31 },
df694daa
KY
6715 { .modelname = "auto", .config = ALC861_AUTO },
6716 {}
6717};
6718
6719static struct alc_config_preset alc861_presets[] = {
6720 [ALC861_3ST] = {
6721 .mixers = { alc861_3ST_mixer },
6722 .init_verbs = { alc861_threestack_init_verbs },
6723 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
6724 .dac_nids = alc861_dac_nids,
6725 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
6726 .channel_mode = alc861_threestack_modes,
4e195a7b 6727 .need_dac_fix = 1,
df694daa
KY
6728 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
6729 .adc_nids = alc861_adc_nids,
6730 .input_mux = &alc861_capture_source,
6731 },
6732 [ALC861_3ST_DIG] = {
6733 .mixers = { alc861_base_mixer },
6734 .init_verbs = { alc861_threestack_init_verbs },
6735 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
6736 .dac_nids = alc861_dac_nids,
6737 .dig_out_nid = ALC861_DIGOUT_NID,
6738 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
6739 .channel_mode = alc861_threestack_modes,
4e195a7b 6740 .need_dac_fix = 1,
df694daa
KY
6741 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
6742 .adc_nids = alc861_adc_nids,
6743 .input_mux = &alc861_capture_source,
6744 },
6745 [ALC861_6ST_DIG] = {
6746 .mixers = { alc861_base_mixer },
6747 .init_verbs = { alc861_base_init_verbs },
6748 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
6749 .dac_nids = alc861_dac_nids,
6750 .dig_out_nid = ALC861_DIGOUT_NID,
6751 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
6752 .channel_mode = alc861_8ch_modes,
6753 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
6754 .adc_nids = alc861_adc_nids,
6755 .input_mux = &alc861_capture_source,
6756 },
9c7f852e
TI
6757 [ALC660_3ST] = {
6758 .mixers = { alc861_3ST_mixer },
6759 .init_verbs = { alc861_threestack_init_verbs },
6760 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
6761 .dac_nids = alc660_dac_nids,
6762 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
6763 .channel_mode = alc861_threestack_modes,
4e195a7b 6764 .need_dac_fix = 1,
9c7f852e
TI
6765 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
6766 .adc_nids = alc861_adc_nids,
6767 .input_mux = &alc861_capture_source,
6768 },
22309c3e
TI
6769 [ALC861_UNIWILL_M31] = {
6770 .mixers = { alc861_uniwill_m31_mixer },
6771 .init_verbs = { alc861_uniwill_m31_init_verbs },
6772 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
6773 .dac_nids = alc861_dac_nids,
6774 .dig_out_nid = ALC861_DIGOUT_NID,
6775 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
6776 .channel_mode = alc861_uniwill_m31_modes,
6777 .need_dac_fix = 1,
6778 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
6779 .adc_nids = alc861_adc_nids,
6780 .input_mux = &alc861_capture_source,
6781 },
6782
df694daa
KY
6783};
6784
6785
6786static int patch_alc861(struct hda_codec *codec)
6787{
6788 struct alc_spec *spec;
6789 int board_config;
6790 int err;
6791
6792 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
6793 if (spec == NULL)
6794 return -ENOMEM;
6795
6796 codec->spec = spec;
6797
6798 board_config = snd_hda_check_board_config(codec, alc861_cfg_tbl);
9c7f852e 6799
df694daa 6800 if (board_config < 0 || board_config >= ALC861_MODEL_LAST) {
9c7f852e
TI
6801 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
6802 "trying auto-probe from BIOS...\n");
df694daa
KY
6803 board_config = ALC861_AUTO;
6804 }
6805
6806 if (board_config == ALC861_AUTO) {
6807 /* automatic parse from the BIOS config */
6808 err = alc861_parse_auto_config(codec);
6809 if (err < 0) {
6810 alc_free(codec);
6811 return err;
6812 } else if (! err) {
9c7f852e
TI
6813 printk(KERN_INFO
6814 "hda_codec: Cannot set up configuration "
6815 "from BIOS. Using base mode...\n");
df694daa
KY
6816 board_config = ALC861_3ST_DIG;
6817 }
6818 }
6819
6820 if (board_config != ALC861_AUTO)
6821 setup_preset(spec, &alc861_presets[board_config]);
6822
6823 spec->stream_name_analog = "ALC861 Analog";
6824 spec->stream_analog_playback = &alc861_pcm_analog_playback;
6825 spec->stream_analog_capture = &alc861_pcm_analog_capture;
6826
6827 spec->stream_name_digital = "ALC861 Digital";
6828 spec->stream_digital_playback = &alc861_pcm_digital_playback;
6829 spec->stream_digital_capture = &alc861_pcm_digital_capture;
6830
6831 codec->patch_ops = alc_patch_ops;
6832 if (board_config == ALC861_AUTO)
ae6b813a 6833 spec->init_hook = alc861_auto_init;
df694daa 6834
1da177e4
LT
6835 return 0;
6836}
6837
6838/*
6839 * patch entries
6840 */
6841struct hda_codec_preset snd_hda_preset_realtek[] = {
6842 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
df694daa 6843 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
1da177e4
LT
6844 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
6845 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
9c7f852e 6846 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
df694daa 6847 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
9c7f852e
TI
6848 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
6849 { .id = 0x10ec0861, .rev = 0x100300, .name = "ALC861",
6850 .patch = patch_alc861 },
6851 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
6852 .patch = patch_alc861 },
1da177e4
LT
6853 {} /* terminator */
6854};