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