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