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