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