patch_realtek.c 600.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5
/*
 * Universal Interface for Intel High Definition Audio Codec
 *
 * HD audio interface patch for ALC 260/880/882 codecs
 *
6 7
 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
 *                    PeiSen Hou <pshou@realtek.com.tw>
L
Linus Torvalds 已提交
8
 *                    Takashi Iwai <tiwai@suse.de>
9
 *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
L
Linus Torvalds 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 *
 *  This driver is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This driver is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 */

#include <linux/init.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/pci.h>
#include <sound/core.h>
#include "hda_codec.h"
#include "hda_local.h"
33
#include "hda_beep.h"
L
Linus Torvalds 已提交
34

35 36 37 38
#define ALC880_FRONT_EVENT		0x01
#define ALC880_DCVOL_EVENT		0x02
#define ALC880_HP_EVENT			0x04
#define ALC880_MIC_EVENT		0x08
L
Linus Torvalds 已提交
39 40 41 42 43 44 45 46

/* ALC880 board config type */
enum {
	ALC880_3ST,
	ALC880_3ST_DIG,
	ALC880_5ST,
	ALC880_5ST_DIG,
	ALC880_W810,
T
Takashi Iwai 已提交
47
	ALC880_Z71V,
48
	ALC880_6ST,
49 50 51 52 53
	ALC880_6ST_DIG,
	ALC880_F1734,
	ALC880_ASUS,
	ALC880_ASUS_DIG,
	ALC880_ASUS_W1V,
54
	ALC880_ASUS_DIG2,
55
	ALC880_FUJITSU,
56
	ALC880_UNIWILL_DIG,
57 58
	ALC880_UNIWILL,
	ALC880_UNIWILL_P53,
59 60
	ALC880_CLEVO,
	ALC880_TCL_S700,
61
	ALC880_LG,
62
	ALC880_LG_LW,
63
	ALC880_MEDION_RIM,
64 65 66
#ifdef CONFIG_SND_DEBUG
	ALC880_TEST,
#endif
67
	ALC880_AUTO,
68 69 70 71 72 73 74
	ALC880_MODEL_LAST /* last tag */
};

/* ALC260 models */
enum {
	ALC260_BASIC,
	ALC260_HP,
75
	ALC260_HP_DC7600,
76 77
	ALC260_HP_3013,
	ALC260_FUJITSU_S702X,
78
	ALC260_ACER,
79 80
	ALC260_WILL,
	ALC260_REPLACER_672V,
81
	ALC260_FAVORIT100,
82 83 84
#ifdef CONFIG_SND_DEBUG
	ALC260_TEST,
#endif
85
	ALC260_AUTO,
86
	ALC260_MODEL_LAST /* last tag */
L
Linus Torvalds 已提交
87 88
};

89 90 91
/* ALC262 models */
enum {
	ALC262_BASIC,
92 93
	ALC262_HIPPO,
	ALC262_HIPPO_1,
94
	ALC262_FUJITSU,
95
	ALC262_HP_BPC,
96 97
	ALC262_HP_BPC_D7000_WL,
	ALC262_HP_BPC_D7000_WF,
98
	ALC262_HP_TC_T5735,
99
	ALC262_HP_RP5700,
100
	ALC262_BENQ_ED8,
101
	ALC262_SONY_ASSAMD,
102
	ALC262_BENQ_T31,
103
	ALC262_ULTRA,
104
	ALC262_LENOVO_3000,
105
	ALC262_NEC,
106
	ALC262_TOSHIBA_S06,
107
	ALC262_TOSHIBA_RX1,
108
	ALC262_TYAN,
109 110 111 112
	ALC262_AUTO,
	ALC262_MODEL_LAST /* last tag */
};

113 114
/* ALC268 models */
enum {
115
	ALC267_QUANTA_IL1,
116
	ALC268_3ST,
117
	ALC268_TOSHIBA,
118
	ALC268_ACER,
T
Takashi Iwai 已提交
119
	ALC268_ACER_DMIC,
120
	ALC268_ACER_ASPIRE_ONE,
121
	ALC268_DELL,
122
	ALC268_ZEPTO,
123 124 125
#ifdef CONFIG_SND_DEBUG
	ALC268_TEST,
#endif
126 127 128 129
	ALC268_AUTO,
	ALC268_MODEL_LAST /* last tag */
};

130 131 132
/* ALC269 models */
enum {
	ALC269_BASIC,
133
	ALC269_QUANTA_FL1,
K
Kailang Yang 已提交
134 135 136 137
	ALC269_AMIC,
	ALC269_DMIC,
	ALC269VB_AMIC,
	ALC269VB_DMIC,
138
	ALC269_FUJITSU,
139
	ALC269_LIFEBOOK,
140 141 142 143
	ALC269_AUTO,
	ALC269_MODEL_LAST /* last tag */
};

144 145 146
/* ALC861 models */
enum {
	ALC861_3ST,
147
	ALC660_3ST,
148 149
	ALC861_3ST_DIG,
	ALC861_6ST_DIG,
150
	ALC861_UNIWILL_M31,
151
	ALC861_TOSHIBA,
152
	ALC861_ASUS,
153
	ALC861_ASUS_LAPTOP,
154 155 156 157
	ALC861_AUTO,
	ALC861_MODEL_LAST,
};

158 159 160
/* ALC861-VD models */
enum {
	ALC660VD_3ST,
161
	ALC660VD_3ST_DIG,
T
Takashi Iwai 已提交
162
	ALC660VD_ASUS_V1S,
163 164 165
	ALC861VD_3ST,
	ALC861VD_3ST_DIG,
	ALC861VD_6ST_DIG,
166
	ALC861VD_LENOVO,
167
	ALC861VD_DALLAS,
168
	ALC861VD_HP,
169 170 171 172
	ALC861VD_AUTO,
	ALC861VD_MODEL_LAST,
};

173 174 175 176 177 178 179
/* ALC662 models */
enum {
	ALC662_3ST_2ch_DIG,
	ALC662_3ST_6ch_DIG,
	ALC662_3ST_6ch,
	ALC662_5ST_DIG,
	ALC662_LENOVO_101E,
180
	ALC662_ASUS_EEEPC_P701,
181
	ALC662_ASUS_EEEPC_EP20,
K
Kailang Yang 已提交
182 183 184 185
	ALC663_ASUS_M51VA,
	ALC663_ASUS_G71V,
	ALC663_ASUS_H13,
	ALC663_ASUS_G50V,
186 187 188 189 190 191 192
	ALC662_ECS,
	ALC663_ASUS_MODE1,
	ALC662_ASUS_MODE2,
	ALC663_ASUS_MODE3,
	ALC663_ASUS_MODE4,
	ALC663_ASUS_MODE5,
	ALC663_ASUS_MODE6,
193 194
	ALC663_ASUS_MODE7,
	ALC663_ASUS_MODE8,
195 196
	ALC272_DELL,
	ALC272_DELL_ZM1,
197
	ALC272_SAMSUNG_NC10,
198 199 200 201
	ALC662_AUTO,
	ALC662_MODEL_LAST,
};

202 203 204 205
/* ALC882 models */
enum {
	ALC882_3ST_DIG,
	ALC882_6ST_DIG,
206
	ALC882_ARIMA,
207
	ALC882_W2JC,
208 209
	ALC882_TARGA,
	ALC882_ASUS_A7J,
210
	ALC882_ASUS_A7M,
211
	ALC885_MACPRO,
212
	ALC885_MBA21,
213
	ALC885_MBP3,
214
	ALC885_MB5,
215
	ALC885_MACMINI3,
216
	ALC885_IMAC24,
217
	ALC885_IMAC91,
218 219 220 221
	ALC883_3ST_2ch_DIG,
	ALC883_3ST_6ch_DIG,
	ALC883_3ST_6ch,
	ALC883_6ST_DIG,
222 223
	ALC883_TARGA_DIG,
	ALC883_TARGA_2ch_DIG,
224
	ALC883_TARGA_8ch_DIG,
225
	ALC883_ACER,
226
	ALC883_ACER_ASPIRE,
227
	ALC888_ACER_ASPIRE_4930G,
228
	ALC888_ACER_ASPIRE_6530G,
229
	ALC888_ACER_ASPIRE_8930G,
230
	ALC888_ACER_ASPIRE_7730G,
231
	ALC883_MEDION,
232
	ALC883_MEDION_MD2,
233
	ALC883_LAPTOP_EAPD,
234
	ALC883_LENOVO_101E_2ch,
235
	ALC883_LENOVO_NB0763,
236
	ALC888_LENOVO_MS7195_DIG,
237
	ALC888_LENOVO_SKY,
238
	ALC883_HAIER_W66,
239
	ALC888_3ST_HP,
240
	ALC888_6ST_DELL,
241
	ALC883_MITAC,
242
	ALC883_CLEVO_M540R,
243
	ALC883_CLEVO_M720,
244
	ALC883_FUJITSU_PI2515,
245
	ALC888_FUJITSU_XA3530,
246
	ALC883_3ST_6ch_INTEL,
247 248
	ALC889A_INTEL,
	ALC889_INTEL,
249 250
	ALC888_ASUS_M90V,
	ALC888_ASUS_EEE1601,
251
	ALC889A_MB31,
252
	ALC1200_ASUS_P5Q,
G
Guido Günther 已提交
253
	ALC883_SONY_VAIO_TT,
254 255
	ALC882_AUTO,
	ALC882_MODEL_LAST,
256 257
};

258 259 260
/* for GPIO Poll */
#define GPIO_MASK	0x03

261 262 263 264 265 266 267 268 269
/* extra amp-initialization sequence types */
enum {
	ALC_INIT_NONE,
	ALC_INIT_DEFAULT,
	ALC_INIT_GPIO1,
	ALC_INIT_GPIO2,
	ALC_INIT_GPIO3,
};

270 271 272 273 274 275 276 277
struct alc_mic_route {
	hda_nid_t pin;
	unsigned char mux_idx;
	unsigned char amix_idx;
};

#define MUX_IDX_UNDEF	((unsigned char)-1)

L
Linus Torvalds 已提交
278 279
struct alc_spec {
	/* codec parameterization */
280
	struct snd_kcontrol_new *mixers[5];	/* mixer arrays */
L
Linus Torvalds 已提交
281
	unsigned int num_mixers;
282
	struct snd_kcontrol_new *cap_mixer;	/* capture mixer */
283
	unsigned int beep_amp;	/* beep amp value, set via set_beep_amp() */
L
Linus Torvalds 已提交
284

285
	const struct hda_verb *init_verbs[10];	/* initialization verbs
286 287
						 * don't forget NULL
						 * termination!
288 289
						 */
	unsigned int num_init_verbs;
L
Linus Torvalds 已提交
290

291
	char stream_name_analog[32];	/* analog PCM stream */
L
Linus Torvalds 已提交
292 293
	struct hda_pcm_stream *stream_analog_playback;
	struct hda_pcm_stream *stream_analog_capture;
294 295
	struct hda_pcm_stream *stream_analog_alt_playback;
	struct hda_pcm_stream *stream_analog_alt_capture;
L
Linus Torvalds 已提交
296

297
	char stream_name_digital[32];	/* digital PCM stream */
L
Linus Torvalds 已提交
298 299 300 301
	struct hda_pcm_stream *stream_digital_playback;
	struct hda_pcm_stream *stream_digital_capture;

	/* playback */
302 303 304 305
	struct hda_multi_out multiout;	/* playback set-up
					 * max_channels, dacs must be set
					 * dig_out_nid and hp_nid are optional
					 */
306
	hda_nid_t alt_dac_nid;
307
	hda_nid_t slave_dig_outs[3];	/* optional - for auto-parsing */
308
	int dig_out_type;
L
Linus Torvalds 已提交
309 310 311 312

	/* capture */
	unsigned int num_adc_nids;
	hda_nid_t *adc_nids;
313
	hda_nid_t *capsrc_nids;
314
	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
L
Linus Torvalds 已提交
315 316

	/* capture source */
317
	unsigned int num_mux_defs;
L
Linus Torvalds 已提交
318 319
	const struct hda_input_mux *input_mux;
	unsigned int cur_mux[3];
320 321
	struct alc_mic_route ext_mic;
	struct alc_mic_route int_mic;
L
Linus Torvalds 已提交
322 323

	/* channel model */
324
	const struct hda_channel_mode *channel_mode;
L
Linus Torvalds 已提交
325
	int num_channel_mode;
326
	int need_dac_fix;
327 328
	int const_channel_count;
	int ext_channel_count;
L
Linus Torvalds 已提交
329 330

	/* PCM information */
331
	struct hda_pcm pcm_rec[3];	/* used in alc_build_pcms() */
332

333 334
	/* dynamic controls, init_verbs and input_mux */
	struct auto_pin_cfg autocfg;
335
	struct snd_array kctls;
336
	struct hda_input_mux private_imux[3];
337
	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
338 339
	hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
	hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
340

341 342 343
	/* hooks */
	void (*init_hook)(struct hda_codec *codec);
	void (*unsol_event)(struct hda_codec *codec, unsigned int res);
344
#ifdef CONFIG_SND_HDA_POWER_SAVE
345
	void (*power_hook)(struct hda_codec *codec);
346
#endif
347

348 349 350
	/* for pin sensing */
	unsigned int sense_updated: 1;
	unsigned int jack_present: 1;
351
	unsigned int master_sw: 1;
352
	unsigned int auto_mic:1;
353

354 355
	/* other flags */
	unsigned int no_analog :1; /* digital I/O only */
356
	int init_amp;
357

358 359
	/* for virtual master */
	hda_nid_t vmaster_nid;
360 361 362
#ifdef CONFIG_SND_HDA_POWER_SAVE
	struct hda_loopback_check loopback;
#endif
363 364 365 366

	/* for PLL fix */
	hda_nid_t pll_nid;
	unsigned int pll_coef_idx, pll_coef_bit;
367 368 369 370 371 372
};

/*
 * configuration template - to be copied to the spec instance
 */
struct alc_config_preset {
373 374 375
	struct snd_kcontrol_new *mixers[5]; /* should be identical size
					     * with spec
					     */
376
	struct snd_kcontrol_new *cap_mixer; /* capture mixer */
377 378 379 380 381
	const struct hda_verb *init_verbs[5];
	unsigned int num_dacs;
	hda_nid_t *dac_nids;
	hda_nid_t dig_out_nid;		/* optional */
	hda_nid_t hp_nid;		/* optional */
382
	hda_nid_t *slave_dig_outs;
383 384
	unsigned int num_adc_nids;
	hda_nid_t *adc_nids;
385
	hda_nid_t *capsrc_nids;
386 387 388
	hda_nid_t dig_in_nid;
	unsigned int num_channel_mode;
	const struct hda_channel_mode *channel_mode;
389
	int need_dac_fix;
390
	int const_channel_count;
391
	unsigned int num_mux_defs;
392
	const struct hda_input_mux *input_mux;
393
	void (*unsol_event)(struct hda_codec *, unsigned int);
394
	void (*setup)(struct hda_codec *);
395
	void (*init_hook)(struct hda_codec *);
396 397
#ifdef CONFIG_SND_HDA_POWER_SAVE
	struct hda_amp_list *loopbacks;
398
	void (*power_hook)(struct hda_codec *codec);
399
#endif
L
Linus Torvalds 已提交
400 401 402 403 404 405
};


/*
 * input MUX handling
 */
406 407
static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
			     struct snd_ctl_elem_info *uinfo)
L
Linus Torvalds 已提交
408 409 410
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct alc_spec *spec = codec->spec;
411 412 413
	unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
	if (mux_idx >= spec->num_mux_defs)
		mux_idx = 0;
414 415
	if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
		mux_idx = 0;
416
	return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
L
Linus Torvalds 已提交
417 418
}

419 420
static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
			    struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
421 422 423 424 425 426 427 428 429
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct alc_spec *spec = codec->spec;
	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);

	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
	return 0;
}

430 431
static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
			    struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
432 433 434
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct alc_spec *spec = codec->spec;
435
	const struct hda_input_mux *imux;
L
Linus Torvalds 已提交
436
	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
437
	unsigned int mux_idx;
438 439
	hda_nid_t nid = spec->capsrc_nids ?
		spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
440
	unsigned int type;
L
Linus Torvalds 已提交
441

442 443
	mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
	imux = &spec->input_mux[mux_idx];
444 445
	if (!imux->num_items && mux_idx > 0)
		imux = &spec->input_mux[0];
446

447
	type = get_wcaps_type(get_wcaps(codec, nid));
448
	if (type == AC_WID_AUD_MIX) {
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
		/* Matrix-mixer style (e.g. ALC882) */
		unsigned int *cur_val = &spec->cur_mux[adc_idx];
		unsigned int i, idx;

		idx = ucontrol->value.enumerated.item[0];
		if (idx >= imux->num_items)
			idx = imux->num_items - 1;
		if (*cur_val == idx)
			return 0;
		for (i = 0; i < imux->num_items; i++) {
			unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
			snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
						 imux->items[i].index,
						 HDA_AMP_MUTE, v);
		}
		*cur_val = idx;
		return 1;
	} else {
		/* MUX style (e.g. ALC880) */
468
		return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
469 470 471
					     &spec->cur_mux[adc_idx]);
	}
}
472

L
Linus Torvalds 已提交
473 474 475
/*
 * channel mode setting
 */
476 477
static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
			    struct snd_ctl_elem_info *uinfo)
L
Linus Torvalds 已提交
478 479 480
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct alc_spec *spec = codec->spec;
481 482
	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
				    spec->num_channel_mode);
L
Linus Torvalds 已提交
483 484
}

485 486
static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
			   struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
487 488 489
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct alc_spec *spec = codec->spec;
490
	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
491
				   spec->num_channel_mode,
492
				   spec->ext_channel_count);
L
Linus Torvalds 已提交
493 494
}

495 496
static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
			   struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
497 498 499
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct alc_spec *spec = codec->spec;
500 501
	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
				      spec->num_channel_mode,
502 503 504 505 506 507
				      &spec->ext_channel_count);
	if (err >= 0 && !spec->const_channel_count) {
		spec->multiout.max_channels = spec->ext_channel_count;
		if (spec->need_dac_fix)
			spec->multiout.num_dacs = spec->multiout.max_channels / 2;
	}
508
	return err;
L
Linus Torvalds 已提交
509 510
}

511
/*
512
 * Control the mode of pin widget settings via the mixer.  "pc" is used
513
 * instead of "%" to avoid consequences of accidently treating the % as
514 515
 * being part of a format specifier.  Maximum allowed length of a value is
 * 63 characters plus NULL terminator.
516 517 518 519 520
 *
 * Note: some retasking pin complexes seem to ignore requests for input
 * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
 * are requested.  Therefore order this list so that this behaviour will not
 * cause problems when mixer clients move through the enum sequentially.
521 522
 * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
 * March 2006.
523 524
 */
static char *alc_pin_mode_names[] = {
525 526
	"Mic 50pc bias", "Mic 80pc bias",
	"Line in", "Line out", "Headphone out",
527 528
};
static unsigned char alc_pin_mode_values[] = {
529
	PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
530 531
};
/* The control can present all 5 options, or it can limit the options based
532 533 534 535 536
 * in the pin being assumed to be exclusively an input or an output pin.  In
 * addition, "input" pins may or may not process the mic bias option
 * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
 * accept requests for bias as of chip versions up to March 2006) and/or
 * wiring in the computer.
537
 */
538 539 540 541 542
#define ALC_PIN_DIR_IN              0x00
#define ALC_PIN_DIR_OUT             0x01
#define ALC_PIN_DIR_INOUT           0x02
#define ALC_PIN_DIR_IN_NOMICBIAS    0x03
#define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
543

544
/* Info about the pin modes supported by the different pin direction modes.
545 546
 * For each direction the minimum and maximum values are given.
 */
547
static signed char alc_pin_mode_dir_info[5][2] = {
548 549 550
	{ 0, 2 },    /* ALC_PIN_DIR_IN */
	{ 3, 4 },    /* ALC_PIN_DIR_OUT */
	{ 0, 4 },    /* ALC_PIN_DIR_INOUT */
551 552
	{ 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
	{ 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
553 554 555 556 557 558
};
#define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
#define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
#define alc_pin_mode_n_items(_dir) \
	(alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)

559 560
static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
			     struct snd_ctl_elem_info *uinfo)
561
{
562 563 564 565
	unsigned int item_num = uinfo->value.enumerated.item;
	unsigned char dir = (kcontrol->private_value >> 16) & 0xff;

	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
566
	uinfo->count = 1;
567 568 569 570 571
	uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);

	if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
		item_num = alc_pin_mode_min(dir);
	strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
572 573 574
	return 0;
}

575 576
static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
			    struct snd_ctl_elem_value *ucontrol)
577
{
578
	unsigned int i;
579 580
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	hda_nid_t nid = kcontrol->private_value & 0xffff;
581
	unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
582
	long *valp = ucontrol->value.integer.value;
583 584 585
	unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
						 AC_VERB_GET_PIN_WIDGET_CONTROL,
						 0x00);
586

587 588
	/* Find enumerated value for current pinctl setting */
	i = alc_pin_mode_min(dir);
R
Roel Kluin 已提交
589
	while (i <= alc_pin_mode_max(dir) && alc_pin_mode_values[i] != pinctl)
590
		i++;
591
	*valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
592 593 594
	return 0;
}

595 596
static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
			    struct snd_ctl_elem_value *ucontrol)
597
{
598
	signed int change;
599 600
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	hda_nid_t nid = kcontrol->private_value & 0xffff;
601 602
	unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
	long val = *ucontrol->value.integer.value;
603 604 605
	unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
						 AC_VERB_GET_PIN_WIDGET_CONTROL,
						 0x00);
606

607
	if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
608 609 610
		val = alc_pin_mode_min(dir);

	change = pinctl != alc_pin_mode_values[val];
611 612
	if (change) {
		/* Set pin mode to that requested */
613 614 615
		snd_hda_codec_write_cache(codec, nid, 0,
					  AC_VERB_SET_PIN_WIDGET_CONTROL,
					  alc_pin_mode_values[val]);
616

617
		/* Also enable the retasking pin's input/output as required
618 619 620 621
		 * for the requested pin mode.  Enum values of 2 or less are
		 * input modes.
		 *
		 * Dynamically switching the input/output buffers probably
622 623 624 625
		 * reduces noise slightly (particularly on input) so we'll
		 * do it.  However, having both input and output buffers
		 * enabled simultaneously doesn't seem to be problematic if
		 * this turns out to be necessary in the future.
626 627
		 */
		if (val <= 2) {
628 629 630 631
			snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
						 HDA_AMP_MUTE, HDA_AMP_MUTE);
			snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
						 HDA_AMP_MUTE, 0);
632
		} else {
633 634 635 636
			snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
						 HDA_AMP_MUTE, HDA_AMP_MUTE);
			snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
						 HDA_AMP_MUTE, 0);
637 638
		}
	}
639 640 641
	return change;
}

642
#define ALC_PIN_MODE(xname, nid, dir) \
643
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
644
	  .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
645 646 647 648
	  .info = alc_pin_mode_info, \
	  .get = alc_pin_mode_get, \
	  .put = alc_pin_mode_put, \
	  .private_value = nid | (dir<<16) }
649

650 651 652 653 654 655
/* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
 * together using a mask with more than one bit set.  This control is
 * currently used only by the ALC260 test model.  At this stage they are not
 * needed for any "production" models.
 */
#ifdef CONFIG_SND_DEBUG
656
#define alc_gpio_data_info	snd_ctl_boolean_mono_info
657

658 659
static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
			     struct snd_ctl_elem_value *ucontrol)
660 661 662 663 664
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	hda_nid_t nid = kcontrol->private_value & 0xffff;
	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
	long *valp = ucontrol->value.integer.value;
665 666
	unsigned int val = snd_hda_codec_read(codec, nid, 0,
					      AC_VERB_GET_GPIO_DATA, 0x00);
667 668 669 670

	*valp = (val & mask) != 0;
	return 0;
}
671 672
static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
			     struct snd_ctl_elem_value *ucontrol)
673 674 675 676 677 678
{
	signed int change;
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	hda_nid_t nid = kcontrol->private_value & 0xffff;
	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
	long val = *ucontrol->value.integer.value;
679 680 681
	unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
						    AC_VERB_GET_GPIO_DATA,
						    0x00);
682 683

	/* Set/unset the masked GPIO bit(s) as needed */
684 685
	change = (val == 0 ? 0 : mask) != (gpio_data & mask);
	if (val == 0)
686 687 688
		gpio_data &= ~mask;
	else
		gpio_data |= mask;
689 690
	snd_hda_codec_write_cache(codec, nid, 0,
				  AC_VERB_SET_GPIO_DATA, gpio_data);
691 692 693 694 695

	return change;
}
#define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
696
	  .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
697 698 699 700 701 702
	  .info = alc_gpio_data_info, \
	  .get = alc_gpio_data_get, \
	  .put = alc_gpio_data_put, \
	  .private_value = nid | (mask<<16) }
#endif   /* CONFIG_SND_DEBUG */

703 704 705 706 707 708 709 710
/* A switch control to allow the enabling of the digital IO pins on the
 * ALC260.  This is incredibly simplistic; the intention of this control is
 * to provide something in the test model allowing digital outputs to be
 * identified if present.  If models are found which can utilise these
 * outputs a more complete mixer control can be devised for those models if
 * necessary.
 */
#ifdef CONFIG_SND_DEBUG
711
#define alc_spdif_ctrl_info	snd_ctl_boolean_mono_info
712

713 714
static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
			      struct snd_ctl_elem_value *ucontrol)
715 716 717 718 719
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	hda_nid_t nid = kcontrol->private_value & 0xffff;
	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
	long *valp = ucontrol->value.integer.value;
720
	unsigned int val = snd_hda_codec_read(codec, nid, 0,
721
					      AC_VERB_GET_DIGI_CONVERT_1, 0x00);
722 723 724 725

	*valp = (val & mask) != 0;
	return 0;
}
726 727
static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
			      struct snd_ctl_elem_value *ucontrol)
728 729 730 731 732 733
{
	signed int change;
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	hda_nid_t nid = kcontrol->private_value & 0xffff;
	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
	long val = *ucontrol->value.integer.value;
734
	unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
735
						    AC_VERB_GET_DIGI_CONVERT_1,
736
						    0x00);
737 738

	/* Set/unset the masked control bit(s) as needed */
739
	change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
740 741 742 743
	if (val==0)
		ctrl_data &= ~mask;
	else
		ctrl_data |= mask;
744 745
	snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
				  ctrl_data);
746 747 748 749 750

	return change;
}
#define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
751
	  .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
752 753 754 755 756 757
	  .info = alc_spdif_ctrl_info, \
	  .get = alc_spdif_ctrl_get, \
	  .put = alc_spdif_ctrl_put, \
	  .private_value = nid | (mask<<16) }
#endif   /* CONFIG_SND_DEBUG */

758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
/* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
 * Again, this is only used in the ALC26x test models to help identify when
 * the EAPD line must be asserted for features to work.
 */
#ifdef CONFIG_SND_DEBUG
#define alc_eapd_ctrl_info	snd_ctl_boolean_mono_info

static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
			      struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	hda_nid_t nid = kcontrol->private_value & 0xffff;
	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
	long *valp = ucontrol->value.integer.value;
	unsigned int val = snd_hda_codec_read(codec, nid, 0,
					      AC_VERB_GET_EAPD_BTLENABLE, 0x00);

	*valp = (val & mask) != 0;
	return 0;
}

static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
			      struct snd_ctl_elem_value *ucontrol)
{
	int change;
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	hda_nid_t nid = kcontrol->private_value & 0xffff;
	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
	long val = *ucontrol->value.integer.value;
	unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
						    AC_VERB_GET_EAPD_BTLENABLE,
						    0x00);

	/* Set/unset the masked control bit(s) as needed */
	change = (!val ? 0 : mask) != (ctrl_data & mask);
	if (!val)
		ctrl_data &= ~mask;
	else
		ctrl_data |= mask;
	snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
				  ctrl_data);

	return change;
}

#define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
805
	  .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
806 807 808 809 810 811
	  .info = alc_eapd_ctrl_info, \
	  .get = alc_eapd_ctrl_get, \
	  .put = alc_eapd_ctrl_put, \
	  .private_value = nid | (mask<<16) }
#endif   /* CONFIG_SND_DEBUG */

812 813 814 815 816 817 818 819 820 821
/*
 * set up the input pin config (depending on the given auto-pin type)
 */
static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
			      int auto_pin_type)
{
	unsigned int val = PIN_IN;

	if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
		unsigned int pincap;
T
Takashi Iwai 已提交
822
		pincap = snd_hda_query_pin_caps(codec, nid);
823 824 825
		pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
		if (pincap & AC_PINCAP_VREF_80)
			val = PIN_VREF80;
826 827 828 829 830 831
		else if (pincap & AC_PINCAP_VREF_50)
			val = PIN_VREF50;
		else if (pincap & AC_PINCAP_VREF_100)
			val = PIN_VREF100;
		else if (pincap & AC_PINCAP_VREF_GRD)
			val = PIN_VREFGRD;
832 833 834 835
	}
	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
}

836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851
/*
 */
static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
{
	if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
		return;
	spec->mixers[spec->num_mixers++] = mix;
}

static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
{
	if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
		return;
	spec->init_verbs[spec->num_init_verbs++] = verb;
}

852 853 854
/*
 * set up from the preset table
 */
855
static void setup_preset(struct hda_codec *codec,
856
			 const struct alc_config_preset *preset)
857
{
858
	struct alc_spec *spec = codec->spec;
859 860 861
	int i;

	for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
862
		add_mixer(spec, preset->mixers[i]);
863
	spec->cap_mixer = preset->cap_mixer;
864 865
	for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
	     i++)
866
		add_verb(spec, preset->init_verbs[i]);
867

868 869
	spec->channel_mode = preset->channel_mode;
	spec->num_channel_mode = preset->num_channel_mode;
870
	spec->need_dac_fix = preset->need_dac_fix;
871
	spec->const_channel_count = preset->const_channel_count;
872

873 874 875 876 877
	if (preset->const_channel_count)
		spec->multiout.max_channels = preset->const_channel_count;
	else
		spec->multiout.max_channels = spec->channel_mode[0].channels;
	spec->ext_channel_count = spec->channel_mode[0].channels;
878 879 880 881

	spec->multiout.num_dacs = preset->num_dacs;
	spec->multiout.dac_nids = preset->dac_nids;
	spec->multiout.dig_out_nid = preset->dig_out_nid;
882
	spec->multiout.slave_dig_outs = preset->slave_dig_outs;
883
	spec->multiout.hp_nid = preset->hp_nid;
884

885
	spec->num_mux_defs = preset->num_mux_defs;
886
	if (!spec->num_mux_defs)
887
		spec->num_mux_defs = 1;
888 889 890 891
	spec->input_mux = preset->input_mux;

	spec->num_adc_nids = preset->num_adc_nids;
	spec->adc_nids = preset->adc_nids;
892
	spec->capsrc_nids = preset->capsrc_nids;
893
	spec->dig_in_nid = preset->dig_in_nid;
894 895 896

	spec->unsol_event = preset->unsol_event;
	spec->init_hook = preset->init_hook;
897
#ifdef CONFIG_SND_HDA_POWER_SAVE
898
	spec->power_hook = preset->power_hook;
899 900
	spec->loopback.amplist = preset->loopbacks;
#endif
901 902 903

	if (preset->setup)
		preset->setup(codec);
904 905
}

906 907 908 909 910 911 912 913 914 915 916 917 918 919 920
/* Enable GPIO mask and set output */
static struct hda_verb alc_gpio1_init_verbs[] = {
	{0x01, AC_VERB_SET_GPIO_MASK, 0x01},
	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
	{0x01, AC_VERB_SET_GPIO_DATA, 0x01},
	{ }
};

static struct hda_verb alc_gpio2_init_verbs[] = {
	{0x01, AC_VERB_SET_GPIO_MASK, 0x02},
	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
	{0x01, AC_VERB_SET_GPIO_DATA, 0x02},
	{ }
};

921 922 923 924 925 926 927
static struct hda_verb alc_gpio3_init_verbs[] = {
	{0x01, AC_VERB_SET_GPIO_MASK, 0x03},
	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
	{0x01, AC_VERB_SET_GPIO_DATA, 0x03},
	{ }
};

928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
/*
 * Fix hardware PLL issue
 * On some codecs, the analog PLL gating control must be off while
 * the default value is 1.
 */
static void alc_fix_pll(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	unsigned int val;

	if (!spec->pll_nid)
		return;
	snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
			    spec->pll_coef_idx);
	val = snd_hda_codec_read(codec, spec->pll_nid, 0,
				 AC_VERB_GET_PROC_COEF, 0);
	snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
			    spec->pll_coef_idx);
	snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
			    val & ~(1 << spec->pll_coef_bit));
}

static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
			     unsigned int coef_idx, unsigned int coef_bit)
{
	struct alc_spec *spec = codec->spec;
	spec->pll_nid = nid;
	spec->pll_coef_idx = coef_idx;
	spec->pll_coef_bit = coef_bit;
	alc_fix_pll(codec);
}

960
static void alc_automute_pin(struct hda_codec *codec)
961 962
{
	struct alc_spec *spec = codec->spec;
963 964
	unsigned int nid = spec->autocfg.hp_pins[0];
	int i;
965

966 967
	if (!nid)
		return;
968
	spec->jack_present = snd_hda_jack_detect(codec, nid);
969 970 971 972 973 974 975 976
	for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
		nid = spec->autocfg.speaker_pins[i];
		if (!nid)
			break;
		snd_hda_codec_write(codec, nid, 0,
				    AC_VERB_SET_PIN_WIDGET_CONTROL,
				    spec->jack_present ? 0 : PIN_OUT);
	}
977 978
}

979 980 981 982 983 984 985 986 987 988 989 990 991
static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
				hda_nid_t nid)
{
	hda_nid_t conn[HDA_MAX_NUM_INPUTS];
	int i, nums;

	nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
	for (i = 0; i < nums; i++)
		if (conn[i] == nid)
			return i;
	return -1;
}

992 993 994
static void alc_mic_automute(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
995 996 997 998
	struct alc_mic_route *dead, *alive;
	unsigned int present, type;
	hda_nid_t cap_nid;

999 1000
	if (!spec->auto_mic)
		return;
1001 1002 1003 1004 1005 1006 1007
	if (!spec->int_mic.pin || !spec->ext_mic.pin)
		return;
	if (snd_BUG_ON(!spec->adc_nids))
		return;

	cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];

1008
	present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
	if (present) {
		alive = &spec->ext_mic;
		dead = &spec->int_mic;
	} else {
		alive = &spec->int_mic;
		dead = &spec->ext_mic;
	}

	type = get_wcaps_type(get_wcaps(codec, cap_nid));
	if (type == AC_WID_AUD_MIX) {
		/* Matrix-mixer style (e.g. ALC882) */
		snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
					 alive->mux_idx,
					 HDA_AMP_MUTE, 0);
		snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
					 dead->mux_idx,
					 HDA_AMP_MUTE, HDA_AMP_MUTE);
	} else {
		/* MUX style (e.g. ALC880) */
		snd_hda_codec_write_cache(codec, cap_nid, 0,
					  AC_VERB_SET_CONNECT_SEL,
					  alive->mux_idx);
	}

	/* FIXME: analog mixer */
1034 1035
}

1036 1037 1038 1039 1040 1041 1042
/* unsolicited event for HP jack sensing */
static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
{
	if (codec->vendor_id == 0x10ec0880)
		res >>= 28;
	else
		res >>= 26;
1043 1044 1045 1046 1047
	switch (res) {
	case ALC880_HP_EVENT:
		alc_automute_pin(codec);
		break;
	case ALC880_MIC_EVENT:
1048
		alc_mic_automute(codec);
1049 1050
		break;
	}
1051 1052 1053 1054
}

static void alc_inithook(struct hda_codec *codec)
{
1055
	alc_automute_pin(codec);
1056
	alc_mic_automute(codec);
1057 1058
}

1059 1060 1061 1062 1063 1064 1065 1066
/* additional initialization for ALC888 variants */
static void alc888_coef_init(struct hda_codec *codec)
{
	unsigned int tmp;

	snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
	tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
	snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1067
	if ((tmp & 0xf0) == 0x20)
1068 1069 1070 1071 1072 1073 1074 1075 1076
		/* alc888S-VC */
		snd_hda_codec_read(codec, 0x20, 0,
				   AC_VERB_SET_PROC_COEF, 0x830);
	 else
		 /* alc888-VB */
		 snd_hda_codec_read(codec, 0x20, 0,
				    AC_VERB_SET_PROC_COEF, 0x3030);
}

1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
static void alc889_coef_init(struct hda_codec *codec)
{
	unsigned int tmp;

	snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
	tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
	snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
	snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
}

1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
/* turn on/off EAPD control (only if available) */
static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
{
	if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
		return;
	if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
				    on ? 2 : 0);
}

1097
static void alc_auto_init_amp(struct hda_codec *codec, int type)
1098
{
1099
	unsigned int tmp;
1100

1101 1102
	switch (type) {
	case ALC_INIT_GPIO1:
1103 1104
		snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
		break;
1105
	case ALC_INIT_GPIO2:
1106 1107
		snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
		break;
1108
	case ALC_INIT_GPIO3:
1109 1110
		snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
		break;
1111
	case ALC_INIT_DEFAULT:
1112
		switch (codec->vendor_id) {
1113
		case 0x10ec0260:
1114 1115
			set_eapd(codec, 0x0f, 1);
			set_eapd(codec, 0x10, 1);
1116 1117
			break;
		case 0x10ec0262:
1118 1119
		case 0x10ec0267:
		case 0x10ec0268:
1120
		case 0x10ec0269:
1121
		case 0x10ec0270:
1122
		case 0x10ec0272:
1123 1124 1125
		case 0x10ec0660:
		case 0x10ec0662:
		case 0x10ec0663:
1126
		case 0x10ec0862:
1127
		case 0x10ec0889:
1128 1129
			set_eapd(codec, 0x14, 1);
			set_eapd(codec, 0x15, 1);
1130
			break;
1131
		}
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
		switch (codec->vendor_id) {
		case 0x10ec0260:
			snd_hda_codec_write(codec, 0x1a, 0,
					    AC_VERB_SET_COEF_INDEX, 7);
			tmp = snd_hda_codec_read(codec, 0x1a, 0,
						 AC_VERB_GET_PROC_COEF, 0);
			snd_hda_codec_write(codec, 0x1a, 0,
					    AC_VERB_SET_COEF_INDEX, 7);
			snd_hda_codec_write(codec, 0x1a, 0,
					    AC_VERB_SET_PROC_COEF,
					    tmp | 0x2010);
			break;
		case 0x10ec0262:
		case 0x10ec0880:
		case 0x10ec0882:
		case 0x10ec0883:
		case 0x10ec0885:
1149
		case 0x10ec0887:
1150
		case 0x10ec0889:
1151
			alc889_coef_init(codec);
1152
			break;
1153
		case 0x10ec0888:
1154
			alc888_coef_init(codec);
1155
			break;
1156
#if 0 /* XXX: This may cause the silent output on speaker on some machines */
1157 1158 1159 1160 1161 1162 1163
		case 0x10ec0267:
		case 0x10ec0268:
			snd_hda_codec_write(codec, 0x20, 0,
					    AC_VERB_SET_COEF_INDEX, 7);
			tmp = snd_hda_codec_read(codec, 0x20, 0,
						 AC_VERB_GET_PROC_COEF, 0);
			snd_hda_codec_write(codec, 0x20, 0,
1164
					    AC_VERB_SET_COEF_INDEX, 7);
1165 1166 1167 1168
			snd_hda_codec_write(codec, 0x20, 0,
					    AC_VERB_SET_PROC_COEF,
					    tmp | 0x3000);
			break;
1169
#endif /* XXX */
1170
		}
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
		break;
	}
}

static void alc_init_auto_hp(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;

	if (!spec->autocfg.hp_pins[0])
		return;

	if (!spec->autocfg.speaker_pins[0]) {
1183 1184
		if (spec->autocfg.line_out_pins[0] &&
		    spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1185 1186 1187 1188 1189 1190
			spec->autocfg.speaker_pins[0] =
				spec->autocfg.line_out_pins[0];
		else
			return;
	}

1191 1192
	snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
		    spec->autocfg.hp_pins[0]);
1193 1194 1195 1196 1197 1198
	snd_hda_codec_write_cache(codec, spec->autocfg.hp_pins[0], 0,
				  AC_VERB_SET_UNSOLICITED_ENABLE,
				  AC_USRSP_EN | ALC880_HP_EVENT);
	spec->unsol_event = alc_sku_unsol_event;
}

1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
static void alc_init_auto_mic(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	struct auto_pin_cfg *cfg = &spec->autocfg;
	hda_nid_t fixed, ext;
	int i;

	/* there must be only two mic inputs exclusively */
	for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++)
		if (cfg->input_pins[i])
			return;

	fixed = ext = 0;
	for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++) {
		hda_nid_t nid = cfg->input_pins[i];
		unsigned int defcfg;
		if (!nid)
			return;
		defcfg = snd_hda_codec_get_pincfg(codec, nid);
		switch (get_defcfg_connect(defcfg)) {
		case AC_JACK_PORT_FIXED:
			if (fixed)
				return; /* already occupied */
			fixed = nid;
			break;
		case AC_JACK_PORT_COMPLEX:
			if (ext)
				return; /* already occupied */
			ext = nid;
			break;
		default:
			return; /* invalid entry */
		}
	}
1233 1234
	if (!ext || !fixed)
		return;
1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
	if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
		return; /* no unsol support */
	snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x\n",
		    ext, fixed);
	spec->ext_mic.pin = ext;
	spec->int_mic.pin = fixed;
	spec->ext_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
	spec->int_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
	spec->auto_mic = 1;
	snd_hda_codec_write_cache(codec, spec->ext_mic.pin, 0,
				  AC_VERB_SET_UNSOLICITED_ENABLE,
				  AC_USRSP_EN | ALC880_MIC_EVENT);
	spec->unsol_event = alc_sku_unsol_event;
}

1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
/* check subsystem ID and set up device-specific initialization;
 * return 1 if initialized, 0 if invalid SSID
 */
/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
 *	31 ~ 16 :	Manufacture ID
 *	15 ~ 8	:	SKU ID
 *	7  ~ 0	:	Assembly ID
 *	port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
 */
static int alc_subsystem_id(struct hda_codec *codec,
			    hda_nid_t porta, hda_nid_t porte,
1261
			    hda_nid_t portd, hda_nid_t porti)
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
{
	unsigned int ass, tmp, i;
	unsigned nid;
	struct alc_spec *spec = codec->spec;

	ass = codec->subsystem_id & 0xffff;
	if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
		goto do_sku;

	/* invalid SSID, check the special NID pin defcfg instead */
	/*
1273
	 * 31~30	: port connectivity
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
	 * 29~21	: reserve
	 * 20		: PCBEEP input
	 * 19~16	: Check sum (15:1)
	 * 15~1		: Custom
	 * 0		: override
	*/
	nid = 0x1d;
	if (codec->vendor_id == 0x10ec0260)
		nid = 0x17;
	ass = snd_hda_codec_get_pincfg(codec, nid);
	snd_printd("realtek: No valid SSID, "
		   "checking pincfg 0x%08x for NID 0x%x\n",
1286
		   ass, nid);
1287
	if (!(ass & 1))
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322
		return 0;
	if ((ass >> 30) != 1)	/* no physical connection */
		return 0;

	/* check sum */
	tmp = 0;
	for (i = 1; i < 16; i++) {
		if ((ass >> i) & 1)
			tmp++;
	}
	if (((ass >> 16) & 0xf) != tmp)
		return 0;
do_sku:
	snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
		   ass & 0xffff, codec->vendor_id);
	/*
	 * 0 : override
	 * 1 :	Swap Jack
	 * 2 : 0 --> Desktop, 1 --> Laptop
	 * 3~5 : External Amplifier control
	 * 7~6 : Reserved
	*/
	tmp = (ass & 0x38) >> 3;	/* external Amp control */
	switch (tmp) {
	case 1:
		spec->init_amp = ALC_INIT_GPIO1;
		break;
	case 3:
		spec->init_amp = ALC_INIT_GPIO2;
		break;
	case 7:
		spec->init_amp = ALC_INIT_GPIO3;
		break;
	case 5:
		spec->init_amp = ALC_INIT_DEFAULT;
1323 1324
		break;
	}
1325

1326
	/* is laptop or Desktop and enable the function "Mute internal speaker
1327 1328
	 * when the external headphone out jack is plugged"
	 */
1329
	if (!(ass & 0x8000))
1330
		return 1;
1331 1332 1333 1334 1335 1336 1337 1338
	/*
	 * 10~8 : Jack location
	 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
	 * 14~13: Resvered
	 * 15   : 1 --> enable the function "Mute internal speaker
	 *	        when the external headphone out jack is plugged"
	 */
	if (!spec->autocfg.hp_pins[0]) {
1339
		hda_nid_t nid;
1340 1341
		tmp = (ass >> 11) & 0x3;	/* HP to chassis */
		if (tmp == 0)
1342
			nid = porta;
1343
		else if (tmp == 1)
1344
			nid = porte;
1345
		else if (tmp == 2)
1346
			nid = portd;
1347 1348
		else if (tmp == 3)
			nid = porti;
1349
		else
1350
			return 1;
1351 1352 1353 1354
		for (i = 0; i < spec->autocfg.line_outs; i++)
			if (spec->autocfg.line_out_pins[i] == nid)
				return 1;
		spec->autocfg.hp_pins[0] = nid;
1355 1356
	}

1357
	alc_init_auto_hp(codec);
1358
	alc_init_auto_mic(codec);
1359 1360
	return 1;
}
1361

1362
static void alc_ssid_check(struct hda_codec *codec,
1363 1364
			   hda_nid_t porta, hda_nid_t porte,
			   hda_nid_t portd, hda_nid_t porti)
1365
{
1366
	if (!alc_subsystem_id(codec, porta, porte, portd, porti)) {
1367 1368 1369 1370 1371
		struct alc_spec *spec = codec->spec;
		snd_printd("realtek: "
			   "Enable default setup for auto mode as fallback\n");
		spec->init_amp = ALC_INIT_DEFAULT;
		alc_init_auto_hp(codec);
1372
		alc_init_auto_mic(codec);
1373
	}
1374 1375
}

1376
/*
1377
 * Fix-up pin default configurations and add default verbs
1378 1379 1380 1381 1382 1383 1384
 */

struct alc_pincfg {
	hda_nid_t nid;
	u32 val;
};

1385 1386 1387 1388 1389 1390
struct alc_fixup {
	const struct alc_pincfg *pins;
	const struct hda_verb *verbs;
};

static void alc_pick_fixup(struct hda_codec *codec,
1391
			   const struct snd_pci_quirk *quirk,
1392
			   const struct alc_fixup *fix)
1393 1394 1395 1396 1397 1398 1399
{
	const struct alc_pincfg *cfg;

	quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
	if (!quirk)
		return;

1400 1401 1402 1403 1404 1405 1406 1407
	fix += quirk->value;
	cfg = fix->pins;
	if (cfg) {
		for (; cfg->nid; cfg++)
			snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
	}
	if (fix->verbs)
		add_verb(codec->spec, fix->verbs);
1408 1409
}

1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420
static int alc_read_coef_idx(struct hda_codec *codec,
			unsigned int coef_idx)
{
	unsigned int val;
	snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
		    		coef_idx);
	val = snd_hda_codec_read(codec, 0x20, 0,
			 	AC_VERB_GET_PROC_COEF, 0);
	return val;
}

1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528
/*
 * ALC888
 */

/*
 * 2ch mode
 */
static struct hda_verb alc888_4ST_ch2_intel_init[] = {
/* Mic-in jack as mic in */
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
/* Line-in jack as Line in */
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
/* Line-Out as Front */
	{ 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
	{ } /* end */
};

/*
 * 4ch mode
 */
static struct hda_verb alc888_4ST_ch4_intel_init[] = {
/* Mic-in jack as mic in */
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
/* Line-in jack as Surround */
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
/* Line-Out as Front */
	{ 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
	{ } /* end */
};

/*
 * 6ch mode
 */
static struct hda_verb alc888_4ST_ch6_intel_init[] = {
/* Mic-in jack as CLFE */
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
/* Line-in jack as Surround */
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
/* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
	{ 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
	{ } /* end */
};

/*
 * 8ch mode
 */
static struct hda_verb alc888_4ST_ch8_intel_init[] = {
/* Mic-in jack as CLFE */
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
/* Line-in jack as Surround */
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
/* Line-Out as Side */
	{ 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
	{ } /* end */
};

static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
	{ 2, alc888_4ST_ch2_intel_init },
	{ 4, alc888_4ST_ch4_intel_init },
	{ 6, alc888_4ST_ch6_intel_init },
	{ 8, alc888_4ST_ch8_intel_init },
};

/*
 * ALC888 Fujitsu Siemens Amillo xa3530
 */

static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
/* Front Mic: set to PIN_IN (empty by default) */
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
/* Connect Internal HP to Front */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
/* Connect Bass HP to Front */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
/* Connect Line-Out side jack (SPDIF) to Side */
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
/* Connect Mic jack to CLFE */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
/* Connect Line-in jack to Surround */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
/* Connect HP out jack to Front */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
/* Enable unsolicited event for HP jack and Line-out jack */
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{}
};

1529
static void alc_automute_amp(struct hda_codec *codec)
1530
{
1531
	struct alc_spec *spec = codec->spec;
1532
	unsigned int mute;
1533 1534 1535 1536 1537 1538 1539 1540
	hda_nid_t nid;
	int i;

	spec->jack_present = 0;
	for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
		nid = spec->autocfg.hp_pins[i];
		if (!nid)
			break;
1541
		if (snd_hda_jack_detect(codec, nid)) {
1542 1543 1544 1545 1546 1547
			spec->jack_present = 1;
			break;
		}
	}

	mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1548
	/* Toggle internal speakers muting */
1549 1550 1551 1552 1553 1554 1555
	for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
		nid = spec->autocfg.speaker_pins[i];
		if (!nid)
			break;
		snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
					 HDA_AMP_MUTE, mute);
	}
1556 1557
}

1558 1559
static void alc_automute_amp_unsol_event(struct hda_codec *codec,
					 unsigned int res)
1560
{
1561 1562 1563 1564 1565 1566
	if (codec->vendor_id == 0x10ec0880)
		res >>= 28;
	else
		res >>= 26;
	if (res == ALC880_HP_EVENT)
		alc_automute_amp(codec);
1567 1568
}

1569
static void alc889_automute_setup(struct hda_codec *codec)
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583
{
	struct alc_spec *spec = codec->spec;

	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
	spec->autocfg.speaker_pins[1] = 0x16;
	spec->autocfg.speaker_pins[2] = 0x17;
	spec->autocfg.speaker_pins[3] = 0x19;
	spec->autocfg.speaker_pins[4] = 0x1a;
}

static void alc889_intel_init_hook(struct hda_codec *codec)
{
	alc889_coef_init(codec);
1584
	alc_automute_amp(codec);
1585 1586
}

1587
static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
1588 1589 1590 1591 1592 1593 1594 1595
{
	struct alc_spec *spec = codec->spec;

	spec->autocfg.hp_pins[0] = 0x17; /* line-out */
	spec->autocfg.hp_pins[1] = 0x1b; /* hp */
	spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
	spec->autocfg.speaker_pins[1] = 0x15; /* bass */
}
1596

1597 1598 1599 1600 1601 1602 1603 1604 1605
/*
 * ALC888 Acer Aspire 4930G model
 */

static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
/* Front Mic: set to PIN_IN (empty by default) */
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
/* Unselect Front Mic by default in input mixer 3 */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1606
/* Enable unsolicited event for HP jack */
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
/* Connect Internal HP to front */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
/* Connect HP out to front */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{ }
};

1619 1620 1621 1622 1623 1624 1625
/*
 * ALC888 Acer Aspire 6530G model
 */

static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
/* Bias voltage on for external mic port */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1626 1627 1628 1629
/* Front Mic: set to PIN_IN (empty by default) */
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
/* Unselect Front Mic by default in input mixer 3 */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
/* Enable unsolicited event for HP jack */
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
/* Enable speaker output */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
/* Enable headphone output */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{ }
};

1642
/*
1643
 * ALC889 Acer Aspire 8930G model
1644 1645
 */

1646
static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665
/* Front Mic: set to PIN_IN (empty by default) */
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
/* Unselect Front Mic by default in input mixer 3 */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
/* Enable unsolicited event for HP jack */
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
/* Connect Internal Front to Front */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
/* Connect Internal Rear to Rear */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
/* Connect Internal CLFE to CLFE */
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
/* Connect HP out to Front */
1666
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
/* Enable all DACs */
/*  DAC DISABLE/MUTE 1? */
/*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
	{0x20, AC_VERB_SET_COEF_INDEX, 0x03},
	{0x20, AC_VERB_SET_PROC_COEF, 0x0000},
/*  DAC DISABLE/MUTE 2? */
/*  some bit here disables the other DACs. Init=0x4900 */
	{0x20, AC_VERB_SET_COEF_INDEX, 0x08},
	{0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688
/* DMIC fix
 * This laptop has a stereo digital microphone. The mics are only 1cm apart
 * which makes the stereo useless. However, either the mic or the ALC889
 * makes the signal become a difference/sum signal instead of standard
 * stereo, which is annoying. So instead we flip this bit which makes the
 * codec replicate the sum signal to both channels, turning it into a
 * normal mono mic.
 */
/*  DMIC_CONTROL? Init value = 0x0001 */
	{0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
	{0x20, AC_VERB_SET_PROC_COEF, 0x0003},
1689 1690 1691
	{ }
};

1692
static struct hda_input_mux alc888_2_capture_sources[2] = {
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712
	/* Front mic only available on one ADC */
	{
		.num_items = 4,
		.items = {
			{ "Mic", 0x0 },
			{ "Line", 0x2 },
			{ "CD", 0x4 },
			{ "Front Mic", 0xb },
		},
	},
	{
		.num_items = 3,
		.items = {
			{ "Mic", 0x0 },
			{ "Line", 0x2 },
			{ "CD", 0x4 },
		},
	}
};

1713 1714 1715
static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
	/* Interal mic only available on one ADC */
	{
1716
		.num_items = 5,
1717 1718
		.items = {
			{ "Ext Mic", 0x0 },
1719
			{ "Line In", 0x2 },
1720
			{ "CD", 0x4 },
1721
			{ "Input Mix", 0xa },
1722 1723 1724 1725
			{ "Int Mic", 0xb },
		},
	},
	{
1726
		.num_items = 4,
1727 1728
		.items = {
			{ "Ext Mic", 0x0 },
1729
			{ "Line In", 0x2 },
1730
			{ "CD", 0x4 },
1731
			{ "Input Mix", 0xa },
1732 1733 1734 1735
		},
	}
};

1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767
static struct hda_input_mux alc889_capture_sources[3] = {
	/* Digital mic only available on first "ADC" */
	{
		.num_items = 5,
		.items = {
			{ "Mic", 0x0 },
			{ "Line", 0x2 },
			{ "CD", 0x4 },
			{ "Front Mic", 0xb },
			{ "Input Mix", 0xa },
		},
	},
	{
		.num_items = 4,
		.items = {
			{ "Mic", 0x0 },
			{ "Line", 0x2 },
			{ "CD", 0x4 },
			{ "Input Mix", 0xa },
		},
	},
	{
		.num_items = 4,
		.items = {
			{ "Mic", 0x0 },
			{ "Line", 0x2 },
			{ "CD", 0x4 },
			{ "Input Mix", 0xa },
		},
	}
};

1768
static struct snd_kcontrol_new alc888_base_mixer[] = {
1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
		HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
};

1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808
static struct snd_kcontrol_new alc889_acer_aspire_8930g_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
		HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
};


1809
static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
1810
{
1811
	struct alc_spec *spec = codec->spec;
1812

1813 1814
	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
1815 1816
	spec->autocfg.speaker_pins[1] = 0x16;
	spec->autocfg.speaker_pins[2] = 0x17;
1817 1818
}

1819
static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
1820 1821 1822 1823 1824 1825 1826 1827 1828
{
	struct alc_spec *spec = codec->spec;

	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
	spec->autocfg.speaker_pins[1] = 0x16;
	spec->autocfg.speaker_pins[2] = 0x17;
}

1829
static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
1830 1831 1832 1833 1834 1835 1836 1837 1838
{
	struct alc_spec *spec = codec->spec;

	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
	spec->autocfg.speaker_pins[1] = 0x16;
	spec->autocfg.speaker_pins[2] = 0x1b;
}

L
Linus Torvalds 已提交
1839
/*
1840 1841 1842
 * ALC880 3-stack model
 *
 * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1843 1844
 * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
 *                 F-Mic = 0x1b, HP = 0x19
L
Linus Torvalds 已提交
1845 1846
 */

1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858
static hda_nid_t alc880_dac_nids[4] = {
	/* front, rear, clfe, rear_surr */
	0x02, 0x05, 0x04, 0x03
};

static hda_nid_t alc880_adc_nids[3] = {
	/* ADC0-2 */
	0x07, 0x08, 0x09,
};

/* The datasheet says the node 0x07 is connected from inputs,
 * but it shows zero connection in the real implementation on some devices.
1859
 * Note: this is a 915GAV bug, fixed on 915GLV
L
Linus Torvalds 已提交
1860
 */
1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901
static hda_nid_t alc880_adc_nids_alt[2] = {
	/* ADC1-2 */
	0x08, 0x09,
};

#define ALC880_DIGOUT_NID	0x06
#define ALC880_DIGIN_NID	0x0a

static struct hda_input_mux alc880_capture_source = {
	.num_items = 4,
	.items = {
		{ "Mic", 0x0 },
		{ "Front Mic", 0x3 },
		{ "Line", 0x2 },
		{ "CD", 0x4 },
	},
};

/* channel source setting (2/6 channel selection for 3-stack) */
/* 2ch mode */
static struct hda_verb alc880_threestack_ch2_init[] = {
	/* set line-in to input, mute it */
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	/* set mic-in to input vref 80%, mute it */
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ } /* end */
};

/* 6ch mode */
static struct hda_verb alc880_threestack_ch6_init[] = {
	/* set line-in to output, unmute it */
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	/* set mic-in to output, unmute it */
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ } /* end */
};

1902
static struct hda_channel_mode alc880_threestack_modes[2] = {
1903 1904 1905 1906
	{ 2, alc880_threestack_ch2_init },
	{ 6, alc880_threestack_ch6_init },
};

1907
static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1908
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
1909
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1910
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
1911
	HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1912 1913
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
1914 1915
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
L
Linus Torvalds 已提交
1916 1917 1918 1919 1920 1921 1922 1923
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1924 1925 1926 1927
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Channel Mode",
1928 1929 1930
		.info = alc_ch_mode_info,
		.get = alc_ch_mode_get,
		.put = alc_ch_mode_put,
1931 1932 1933 1934 1935
	},
	{ } /* end */
};

/* capture mixer elements */
1936 1937 1938 1939 1940 1941
static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
			    struct snd_ctl_elem_info *uinfo)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct alc_spec *spec = codec->spec;
	int err;
L
Linus Torvalds 已提交
1942

1943
	mutex_lock(&codec->control_mutex);
1944 1945 1946
	kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
						      HDA_INPUT);
	err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1947
	mutex_unlock(&codec->control_mutex);
1948 1949 1950 1951 1952 1953 1954 1955 1956
	return err;
}

static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
			   unsigned int size, unsigned int __user *tlv)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct alc_spec *spec = codec->spec;
	int err;
L
Linus Torvalds 已提交
1957

1958
	mutex_lock(&codec->control_mutex);
1959 1960 1961
	kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
						      HDA_INPUT);
	err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1962
	mutex_unlock(&codec->control_mutex);
1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977
	return err;
}

typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
			     struct snd_ctl_elem_value *ucontrol);

static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
				 struct snd_ctl_elem_value *ucontrol,
				 getput_call_t func)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct alc_spec *spec = codec->spec;
	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
	int err;

1978
	mutex_lock(&codec->control_mutex);
1979 1980 1981
	kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
						      3, 0, HDA_INPUT);
	err = func(kcontrol, ucontrol);
1982
	mutex_unlock(&codec->control_mutex);
1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016
	return err;
}

static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
			   struct snd_ctl_elem_value *ucontrol)
{
	return alc_cap_getput_caller(kcontrol, ucontrol,
				     snd_hda_mixer_amp_volume_get);
}

static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
			   struct snd_ctl_elem_value *ucontrol)
{
	return alc_cap_getput_caller(kcontrol, ucontrol,
				     snd_hda_mixer_amp_volume_put);
}

/* capture mixer elements */
#define alc_cap_sw_info		snd_ctl_boolean_stereo_info

static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
			  struct snd_ctl_elem_value *ucontrol)
{
	return alc_cap_getput_caller(kcontrol, ucontrol,
				     snd_hda_mixer_amp_switch_get);
}

static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
			  struct snd_ctl_elem_value *ucontrol)
{
	return alc_cap_getput_caller(kcontrol, ucontrol,
				     snd_hda_mixer_amp_switch_put);
}

2017
#define _DEFINE_CAPMIX(num) \
2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037
	{ \
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
		.name = "Capture Switch", \
		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
		.count = num, \
		.info = alc_cap_sw_info, \
		.get = alc_cap_sw_get, \
		.put = alc_cap_sw_put, \
	}, \
	{ \
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
		.name = "Capture Volume", \
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
			   SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
			   SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
		.count = num, \
		.info = alc_cap_vol_info, \
		.get = alc_cap_vol_get, \
		.put = alc_cap_vol_put, \
		.tlv = { .c = alc_cap_vol_tlv }, \
2038 2039 2040
	}

#define _DEFINE_CAPSRC(num) \
2041 2042 2043 2044 2045 2046 2047 2048
	{ \
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
		/* .name = "Capture Source", */ \
		.name = "Input Source", \
		.count = num, \
		.info = alc_mux_enum_info, \
		.get = alc_mux_enum_get, \
		.put = alc_mux_enum_put, \
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061
	}

#define DEFINE_CAPMIX(num) \
static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
	_DEFINE_CAPMIX(num),				      \
	_DEFINE_CAPSRC(num),				      \
	{ } /* end */					      \
}

#define DEFINE_CAPMIX_NOSRC(num) \
static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
	_DEFINE_CAPMIX(num),					    \
	{ } /* end */						    \
2062 2063 2064 2065 2066 2067
}

/* up to three ADCs */
DEFINE_CAPMIX(1);
DEFINE_CAPMIX(2);
DEFINE_CAPMIX(3);
2068 2069 2070
DEFINE_CAPMIX_NOSRC(1);
DEFINE_CAPMIX_NOSRC(2);
DEFINE_CAPMIX_NOSRC(3);
2071 2072 2073 2074

/*
 * ALC880 5-stack model
 *
2075 2076
 * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
 *      Side = 0x02 (0xd)
2077 2078 2079 2080 2081
 * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
 *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
 */

/* additional mixers to alc880_three_stack_mixer */
2082
static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
2083
	HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
2084
	HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
L
Linus Torvalds 已提交
2085 2086 2087
	{ } /* end */
};

2088 2089 2090 2091 2092 2093
/* channel source setting (6/8 channel selection for 5-stack) */
/* 6ch mode */
static struct hda_verb alc880_fivestack_ch6_init[] = {
	/* set line-in to input, mute it */
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
T
Takashi Iwai 已提交
2094 2095 2096
	{ } /* end */
};

2097 2098 2099 2100 2101 2102 2103 2104
/* 8ch mode */
static struct hda_verb alc880_fivestack_ch8_init[] = {
	/* set line-in to output, unmute it */
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ } /* end */
};

2105
static struct hda_channel_mode alc880_fivestack_modes[2] = {
2106 2107 2108 2109 2110 2111 2112 2113
	{ 6, alc880_fivestack_ch6_init },
	{ 8, alc880_fivestack_ch8_init },
};


/*
 * ALC880 6-stack model
 *
2114 2115
 * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
 *      Side = 0x05 (0x0f)
2116 2117 2118 2119 2120 2121 2122
 * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
 *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
 */

static hda_nid_t alc880_6st_dac_nids[4] = {
	/* front, rear, clfe, rear_surr */
	0x02, 0x03, 0x04, 0x05
2123
};
2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135

static struct hda_input_mux alc880_6stack_capture_source = {
	.num_items = 4,
	.items = {
		{ "Mic", 0x0 },
		{ "Front Mic", 0x1 },
		{ "Line", 0x2 },
		{ "CD", 0x4 },
	},
};

/* fixed 8-channels */
2136
static struct hda_channel_mode alc880_sixstack_modes[1] = {
2137 2138 2139
	{ 8, NULL },
};

2140
static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
2141
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
2142
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2143
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
2144
	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2145 2146
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
2147 2148
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2149
	HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
2150
	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Channel Mode",
2162 2163 2164
		.info = alc_ch_mode_info,
		.get = alc_ch_mode_get,
		.put = alc_ch_mode_put,
2165 2166 2167 2168
	},
	{ } /* end */
};

2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180

/*
 * ALC880 W810 model
 *
 * W810 has rear IO for:
 * Front (DAC 02)
 * Surround (DAC 03)
 * Center/LFE (DAC 04)
 * Digital out (06)
 *
 * The system also has a pair of internal speakers, and a headphone jack.
 * These are both connected to Line2 on the codec, hence to DAC 02.
2181
 *
2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197
 * There is a variable resistor to control the speaker or headphone
 * volume. This is a hardware-only device without a software API.
 *
 * Plugging headphones in will disable the internal speakers. This is
 * implemented in hardware, not via the driver using jack sense. In
 * a similar fashion, plugging into the rear socket marked "front" will
 * disable both the speakers and headphones.
 *
 * For input, there's a microphone jack, and an "audio in" jack.
 * These may not do anything useful with this driver yet, because I
 * haven't setup any initialization verbs for these yet...
 */

static hda_nid_t alc880_w810_dac_nids[3] = {
	/* front, rear/surround, clfe */
	0x02, 0x03, 0x04
2198 2199
};

2200
/* fixed 6 channels */
2201
static struct hda_channel_mode alc880_w810_modes[1] = {
2202 2203 2204 2205
	{ 6, NULL }
};

/* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2206
static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2207
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
2208
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2209
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
2210
	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2211 2212
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
2213 2214
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2215 2216 2217 2218 2219 2220 2221 2222 2223
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
	{ } /* end */
};


/*
 * Z710V model
 *
 * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2224 2225
 * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
 *                 Line = 0x1a
2226 2227 2228 2229 2230 2231 2232 2233
 */

static hda_nid_t alc880_z71v_dac_nids[1] = {
	0x02
};
#define ALC880_Z71V_HP_DAC	0x03

/* fixed 2 channels */
2234
static struct hda_channel_mode alc880_2_jack_modes[1] = {
2235 2236 2237
	{ 2, NULL }
};

2238
static struct snd_kcontrol_new alc880_z71v_mixer[] = {
2239
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
2240
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2241
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
2242
	HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2243 2244 2245 2246 2247 2248 2249
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
};

2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262

/*
 * ALC880 F1734 model
 *
 * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
 * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
 */

static hda_nid_t alc880_f1734_dac_nids[1] = {
	0x03
};
#define ALC880_F1734_HP_DAC	0x02

2263
static struct snd_kcontrol_new alc880_f1734_mixer[] = {
2264
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
2265
	HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2266 2267
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2268 2269
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2270 2271
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2272 2273 2274
	{ } /* end */
};

2275 2276 2277 2278 2279 2280 2281 2282
static struct hda_input_mux alc880_f1734_capture_source = {
	.num_items = 2,
	.items = {
		{ "Mic", 0x1 },
		{ "CD", 0x4 },
	},
};

2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294

/*
 * ALC880 ASUS model
 *
 * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
 * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
 *  Mic = 0x18, Line = 0x1a
 */

#define alc880_asus_dac_nids	alc880_w810_dac_nids	/* identical with w810 */
#define alc880_asus_modes	alc880_threestack_modes	/* 2/6 channel mode */

2295
static struct snd_kcontrol_new alc880_asus_mixer[] = {
2296
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
2297
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2298
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
2299
	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2300 2301
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
2302 2303
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2304 2305 2306 2307 2308 2309 2310 2311 2312
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Channel Mode",
2313 2314 2315
		.info = alc_ch_mode_info,
		.get = alc_ch_mode_get,
		.put = alc_ch_mode_put,
2316 2317 2318
	},
	{ } /* end */
};
2319 2320 2321 2322 2323 2324 2325 2326 2327 2328

/*
 * ALC880 ASUS W1V model
 *
 * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
 * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
 *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
 */

/* additional mixers to alc880_asus_mixer */
2329
static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
2330 2331 2332 2333 2334
	HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
	HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
	{ } /* end */
};

2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348
/* TCL S700 */
static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
	{ } /* end */
};

2349 2350
/* Uniwill */
static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
2351 2352 2353 2354
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Channel Mode",
		.info = alc_ch_mode_info,
		.get = alc_ch_mode_get,
		.put = alc_ch_mode_put,
	},
	{ } /* end */
};

2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390
static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

2391
static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
2392 2393 2394 2395
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2396 2397 2398 2399 2400
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
};

2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417
/*
 * virtual master controls
 */

/*
 * slave controls for virtual master
 */
static const char *alc_slave_vols[] = {
	"Front Playback Volume",
	"Surround Playback Volume",
	"Center Playback Volume",
	"LFE Playback Volume",
	"Side Playback Volume",
	"Headphone Playback Volume",
	"Speaker Playback Volume",
	"Mono Playback Volume",
	"Line-Out Playback Volume",
2418
	"PCM Playback Volume",
2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430
	NULL,
};

static const char *alc_slave_sws[] = {
	"Front Playback Switch",
	"Surround Playback Switch",
	"Center Playback Switch",
	"LFE Playback Switch",
	"Side Playback Switch",
	"Headphone Playback Switch",
	"Speaker Playback Switch",
	"Mono Playback Switch",
2431
	"IEC958 Playback Switch",
2432 2433
	"Line-Out Playback Switch",
	"PCM Playback Switch",
2434 2435 2436
	NULL,
};

L
Linus Torvalds 已提交
2437
/*
2438
 * build control elements
L
Linus Torvalds 已提交
2439
 */
2440

2441 2442 2443 2444 2445 2446 2447 2448 2449
#define NID_MAPPING		(-1)

#define SUBDEV_SPEAKER_		(0 << 6)
#define SUBDEV_HP_		(1 << 6)
#define SUBDEV_LINE_		(2 << 6)
#define SUBDEV_SPEAKER(x)	(SUBDEV_SPEAKER_ | ((x) & 0x3f))
#define SUBDEV_HP(x)		(SUBDEV_HP_ | ((x) & 0x3f))
#define SUBDEV_LINE(x)		(SUBDEV_LINE_ | ((x) & 0x3f))

2450 2451
static void alc_free_kctls(struct hda_codec *codec);

2452
#ifdef CONFIG_SND_HDA_INPUT_BEEP
2453 2454 2455
/* additional beep mixers; the actual parameters are overwritten at build */
static struct snd_kcontrol_new alc_beep_mixer[] = {
	HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2456
	HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
2457 2458
	{ } /* end */
};
2459
#endif
2460

L
Linus Torvalds 已提交
2461 2462 2463
static int alc_build_controls(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
2464 2465 2466 2467 2468
	struct snd_kcontrol *kctl;
	struct snd_kcontrol_new *knew;
	int i, j, err;
	unsigned int u;
	hda_nid_t nid;
L
Linus Torvalds 已提交
2469 2470 2471 2472 2473 2474

	for (i = 0; i < spec->num_mixers; i++) {
		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
		if (err < 0)
			return err;
	}
2475 2476 2477 2478 2479
	if (spec->cap_mixer) {
		err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
		if (err < 0)
			return err;
	}
L
Linus Torvalds 已提交
2480
	if (spec->multiout.dig_out_nid) {
2481 2482
		err = snd_hda_create_spdif_out_ctls(codec,
						    spec->multiout.dig_out_nid);
L
Linus Torvalds 已提交
2483 2484
		if (err < 0)
			return err;
2485 2486 2487 2488 2489 2490 2491
		if (!spec->no_analog) {
			err = snd_hda_create_spdif_share_sw(codec,
							    &spec->multiout);
			if (err < 0)
				return err;
			spec->multiout.share_spdif = 1;
		}
L
Linus Torvalds 已提交
2492 2493 2494 2495 2496 2497
	}
	if (spec->dig_in_nid) {
		err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
		if (err < 0)
			return err;
	}
2498

2499
#ifdef CONFIG_SND_HDA_INPUT_BEEP
2500 2501 2502 2503 2504 2505 2506 2507 2508
	/* create beep controls if needed */
	if (spec->beep_amp) {
		struct snd_kcontrol_new *knew;
		for (knew = alc_beep_mixer; knew->name; knew++) {
			struct snd_kcontrol *kctl;
			kctl = snd_ctl_new1(knew, codec);
			if (!kctl)
				return -ENOMEM;
			kctl->private_value = spec->beep_amp;
2509
			err = snd_hda_ctl_add(codec, 0, kctl);
2510 2511 2512 2513
			if (err < 0)
				return err;
		}
	}
2514
#endif
2515

2516
	/* if we have no master control, let's create it */
2517 2518
	if (!spec->no_analog &&
	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2519
		unsigned int vmaster_tlv[4];
2520
		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2521
					HDA_OUTPUT, vmaster_tlv);
2522
		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2523
					  vmaster_tlv, alc_slave_vols);
2524 2525 2526
		if (err < 0)
			return err;
	}
2527 2528
	if (!spec->no_analog &&
	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2529 2530 2531 2532 2533 2534
		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
					  NULL, alc_slave_sws);
		if (err < 0)
			return err;
	}

2535 2536 2537 2538 2539
	/* assign Capture Source enums to NID */
	kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
	if (!kctl)
		kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
	for (i = 0; kctl && i < kctl->count; i++) {
2540 2541 2542
		hda_nid_t *nids = spec->capsrc_nids;
		if (!nids)
			nids = spec->adc_nids;
2543
		err = snd_hda_add_nid(codec, kctl, i, nids[i]);
2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602
		if (err < 0)
			return err;
	}
	if (spec->cap_mixer) {
		const char *kname = kctl ? kctl->id.name : NULL;
		for (knew = spec->cap_mixer; knew->name; knew++) {
			if (kname && strcmp(knew->name, kname) == 0)
				continue;
			kctl = snd_hda_find_mixer_ctl(codec, knew->name);
			for (i = 0; kctl && i < kctl->count; i++) {
				err = snd_hda_add_nid(codec, kctl, i,
						      spec->adc_nids[i]);
				if (err < 0)
					return err;
			}
		}
	}

	/* other nid->control mapping */
	for (i = 0; i < spec->num_mixers; i++) {
		for (knew = spec->mixers[i]; knew->name; knew++) {
			if (knew->iface != NID_MAPPING)
				continue;
			kctl = snd_hda_find_mixer_ctl(codec, knew->name);
			if (kctl == NULL)
				continue;
			u = knew->subdevice;
			for (j = 0; j < 4; j++, u >>= 8) {
				nid = u & 0x3f;
				if (nid == 0)
					continue;
				switch (u & 0xc0) {
				case SUBDEV_SPEAKER_:
					nid = spec->autocfg.speaker_pins[nid];
					break;
				case SUBDEV_LINE_:
					nid = spec->autocfg.line_out_pins[nid];
					break;
				case SUBDEV_HP_:
					nid = spec->autocfg.hp_pins[nid];
					break;
				default:
					continue;
				}
				err = snd_hda_add_nid(codec, kctl, 0, nid);
				if (err < 0)
					return err;
			}
			u = knew->private_value;
			for (j = 0; j < 4; j++, u >>= 8) {
				nid = u & 0xff;
				if (nid == 0)
					continue;
				err = snd_hda_add_nid(codec, kctl, 0, nid);
				if (err < 0)
					return err;
			}
		}
	}
2603 2604 2605

	alc_free_kctls(codec); /* no longer needed */

L
Linus Torvalds 已提交
2606 2607 2608
	return 0;
}

2609

L
Linus Torvalds 已提交
2610 2611 2612 2613
/*
 * initialize the codec volumes, etc
 */

2614 2615 2616 2617 2618 2619 2620
/*
 * generic initialization of ADC, input mixers and output mixers
 */
static struct hda_verb alc880_volume_init_verbs[] = {
	/*
	 * Unmute ADC0-2 and set the default input to mic-in
	 */
2621
	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2622
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2623
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2624
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2625
	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2626
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
L
Linus Torvalds 已提交
2627

2628 2629
	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
	 * mixer widget
2630 2631
	 * Note: PASD motherboards uses the Line In 2 as the input for front
	 * panel mic (mic 2)
L
Linus Torvalds 已提交
2632
	 */
2633
	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2634 2635 2636 2637 2638 2639 2640
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
L
Linus Torvalds 已提交
2641

2642 2643
	/*
	 * Set up output mixers (0x0c - 0x0f)
L
Linus Torvalds 已提交
2644
	 */
2645 2646 2647 2648 2649 2650 2651
	/* set vol=0 to output mixers */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	/* set up input amps for analog loopback */
	/* Amp Indices: DAC = 0, mixer = 1 */
2652 2653 2654 2655 2656 2657 2658 2659
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
L
Linus Torvalds 已提交
2660 2661 2662 2663

	{ }
};

2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680
/*
 * 3-stack pin configuration:
 * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
 */
static struct hda_verb alc880_pin_3stack_init_verbs[] = {
	/*
	 * preset connection lists of input pins
	 * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
	 */
	{0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
	{0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
	{0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */

	/*
	 * Set pin mode and muting
	 */
	/* set front pin widgets 0x14 for output */
2681
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2682 2683 2684 2685 2686 2687 2688
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* Mic1 (rear panel) pin widget for input and vref at 80% */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Mic2 (as headphone out) for HP output */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
L
Linus Torvalds 已提交
2689
	/* Line In pin widget for input */
2690
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2691 2692 2693 2694
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Line2 (as front mic) pin widget for input and vref at 80% */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
L
Linus Torvalds 已提交
2695
	/* CD pin widget for input */
2696
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
L
Linus Torvalds 已提交
2697

2698 2699
	{ }
};
L
Linus Torvalds 已提交
2700

2701 2702 2703 2704 2705 2706 2707 2708 2709
/*
 * 5-stack pin configuration:
 * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
 * line-in/side = 0x1a, f-mic = 0x1b
 */
static struct hda_verb alc880_pin_5stack_init_verbs[] = {
	/*
	 * preset connection lists of input pins
	 * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
L
Linus Torvalds 已提交
2710
	 */
2711 2712
	{0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
	{0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
L
Linus Torvalds 已提交
2713

2714 2715
	/*
	 * Set pin mode and muting
L
Linus Torvalds 已提交
2716
	 */
2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741
	/* set pin widgets 0x14-0x17 for output */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	/* unmute pins for output (no gain on this amp) */
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},

	/* Mic1 (rear panel) pin widget for input and vref at 80% */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Mic2 (as headphone out) for HP output */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* Line In pin widget for input */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Line2 (as front mic) pin widget for input and vref at 80% */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* CD pin widget for input */
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
L
Linus Torvalds 已提交
2742 2743 2744 2745

	{ }
};

2746 2747 2748 2749 2750 2751 2752
/*
 * W810 pin configuration:
 * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
 */
static struct hda_verb alc880_pin_w810_init_verbs[] = {
	/* hphone/speaker input selector: front DAC */
	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
L
Linus Torvalds 已提交
2753

2754
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2755
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2756
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2757
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2758
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2759
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
L
Linus Torvalds 已提交
2760

2761
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2762
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
L
Linus Torvalds 已提交
2763 2764 2765 2766

	{ }
};

2767 2768 2769 2770 2771
/*
 * Z71V pin configuration:
 * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
 */
static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2772
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2773
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2774
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2775
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
T
Takashi Iwai 已提交
2776

2777
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2778
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2779
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2780
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2781 2782 2783 2784

	{ }
};

2785 2786
/*
 * 6-stack pin configuration:
2787 2788
 * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
 * f-mic = 0x19, line = 0x1a, HP = 0x1b
2789 2790 2791 2792
 */
static struct hda_verb alc880_pin_6stack_init_verbs[] = {
	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */

2793
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2794
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2795
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2796
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2797
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2798
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2799
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2800 2801
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},

2802
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2803
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2804
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2805
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2806
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2807
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2808
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2809
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2810
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2811

2812 2813 2814
	{ }
};

2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855
/*
 * Uniwill pin configuration:
 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
 * line = 0x1a
 */
static struct hda_verb alc880_uniwill_init_verbs[] = {
	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */

	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},

	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
	/* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},

	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},

	{ }
};

/*
* Uniwill P53
2856
* HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886
 */
static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */

	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},

	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},

	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},

	{ }
};

2887 2888 2889 2890 2891
static struct hda_verb alc880_beep_init_verbs[] = {
	{ 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
	{ }
};

2892 2893 2894 2895 2896
/* auto-toggle front mic */
static void alc880_uniwill_mic_automute(struct hda_codec *codec)
{
 	unsigned int present;
	unsigned char bits;
2897

2898
	present = snd_hda_jack_detect(codec, 0x18);
2899 2900
	bits = present ? HDA_AMP_MUTE : 0;
	snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2901 2902
}

2903
static void alc880_uniwill_setup(struct hda_codec *codec)
2904
{
2905 2906 2907 2908 2909
	struct alc_spec *spec = codec->spec;

	spec->autocfg.hp_pins[0] = 0x14;
	spec->autocfg.speaker_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x16;
2910 2911 2912 2913
}

static void alc880_uniwill_init_hook(struct hda_codec *codec)
{
2914
	alc_automute_amp(codec);
2915
	alc880_uniwill_mic_automute(codec);
2916 2917 2918 2919 2920 2921 2922 2923
}

static void alc880_uniwill_unsol_event(struct hda_codec *codec,
				       unsigned int res)
{
	/* Looks like the unsol event is incompatible with the standard
	 * definition.  4bit tag is placed at 28 bit!
	 */
2924 2925 2926 2927
	switch (res >> 28) {
	case ALC880_MIC_EVENT:
		alc880_uniwill_mic_automute(codec);
		break;
2928 2929 2930
	default:
		alc_automute_amp_unsol_event(codec, res);
		break;
2931
	}
2932 2933
}

2934
static void alc880_uniwill_p53_setup(struct hda_codec *codec)
2935
{
2936
	struct alc_spec *spec = codec->spec;
2937

2938 2939
	spec->autocfg.hp_pins[0] = 0x14;
	spec->autocfg.speaker_pins[0] = 0x15;
2940 2941 2942 2943 2944
}

static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
{
	unsigned int present;
2945

2946
	present = snd_hda_codec_read(codec, 0x21, 0,
2947 2948 2949 2950 2951 2952
				     AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
	present &= HDA_AMP_VOLMASK;
	snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
				 HDA_AMP_VOLMASK, present);
	snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
				 HDA_AMP_VOLMASK, present);
2953
}
2954

2955 2956 2957 2958 2959 2960
static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
					   unsigned int res)
{
	/* Looks like the unsol event is incompatible with the standard
	 * definition.  4bit tag is placed at 28 bit!
	 */
2961
	if ((res >> 28) == ALC880_DCVOL_EVENT)
2962
		alc880_uniwill_p53_dcvol_automute(codec);
2963 2964
	else
		alc_automute_amp_unsol_event(codec, res);
2965 2966
}

2967 2968 2969 2970 2971
/*
 * F1734 pin configuration:
 * HP = 0x14, speaker-out = 0x15, mic = 0x18
 */
static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2972
	{0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2973 2974 2975 2976 2977
	{0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
	{0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00},

2978
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2979
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2980
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2981 2982
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},

2983 2984
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2985
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2986
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2987
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2988
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2989
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2990
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2991
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
T
Takashi Iwai 已提交
2992

2993 2994 2995
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},

T
Takashi Iwai 已提交
2996 2997 2998
	{ }
};

2999 3000 3001 3002 3003
/*
 * ASUS pin configuration:
 * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
 */
static struct hda_verb alc880_pin_asus_init_verbs[] = {
3004 3005 3006 3007 3008 3009
	{0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
	{0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00},

	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3010
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3011
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3012
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3013
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3014
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3015
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3016 3017 3018 3019 3020 3021 3022 3023
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},

	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3024
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3025
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3026
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3027

3028 3029
	{ }
};
3030

3031
/* Enable GPIO mask and set output */
3032 3033
#define alc880_gpio1_init_verbs	alc_gpio1_init_verbs
#define alc880_gpio2_init_verbs	alc_gpio2_init_verbs
3034
#define alc880_gpio3_init_verbs	alc_gpio3_init_verbs
3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062

/* Clevo m520g init */
static struct hda_verb alc880_pin_clevo_init_verbs[] = {
	/* headphone output */
	{0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
	/* line-out */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* Line-in */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* CD */
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* Mic1 (rear panel) */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* Mic2 (front panel) */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* headphone */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
        /* change to EAPD mode */
	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
	{0x20, AC_VERB_SET_PROC_COEF,  0x3060},

	{ }
3063 3064
};

3065
static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
3066 3067 3068 3069
	/* change to EAPD mode */
	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
	{0x20, AC_VERB_SET_PROC_COEF,  0x3060},

3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088
	/* Headphone output */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	/* Front output*/
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},

	/* Line In pin widget for input */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	/* CD pin widget for input */
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	/* Mic1 (rear panel) pin widget for input and vref at 80% */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},

	/* change to EAPD mode */
	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
	{0x20, AC_VERB_SET_PROC_COEF,  0x3070},

	{ }
};
3089

3090
/*
3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145
 * LG m1 express dual
 *
 * Pin assignment:
 *   Rear Line-In/Out (blue): 0x14
 *   Build-in Mic-In: 0x15
 *   Speaker-out: 0x17
 *   HP-Out (green): 0x1b
 *   Mic-In/Out (red): 0x19
 *   SPDIF-Out: 0x1e
 */

/* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
static hda_nid_t alc880_lg_dac_nids[3] = {
	0x05, 0x02, 0x03
};

/* seems analog CD is not working */
static struct hda_input_mux alc880_lg_capture_source = {
	.num_items = 3,
	.items = {
		{ "Mic", 0x1 },
		{ "Line", 0x5 },
		{ "Internal Mic", 0x6 },
	},
};

/* 2,4,6 channel modes */
static struct hda_verb alc880_lg_ch2_init[] = {
	/* set line-in and mic-in to input */
	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
	{ 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ }
};

static struct hda_verb alc880_lg_ch4_init[] = {
	/* set line-in to out and mic-in to input */
	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
	{ 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ }
};

static struct hda_verb alc880_lg_ch6_init[] = {
	/* set line-in and mic-in to output */
	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
	{ 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
	{ }
};

static struct hda_channel_mode alc880_lg_ch_modes[3] = {
	{ 2, alc880_lg_ch2_init },
	{ 4, alc880_lg_ch4_init },
	{ 6, alc880_lg_ch6_init },
};

static struct snd_kcontrol_new alc880_lg_mixer[] = {
3146 3147
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Channel Mode",
		.info = alc_ch_mode_info,
		.get = alc_ch_mode_get,
		.put = alc_ch_mode_put,
	},
	{ } /* end */
};

static struct hda_verb alc880_lg_init_verbs[] = {
	/* set capture source to mic-in */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	/* mute all amp mixer inputs */
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3177 3178
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196
	/* line-in to input */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* built-in mic */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* speaker-out */
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* mic-in to input */
	{0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* HP-out */
	{0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* jack sense */
3197
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3198 3199 3200 3201
	{ }
};

/* toggle speaker-output according to the hp-jack state */
3202
static void alc880_lg_setup(struct hda_codec *codec)
3203
{
3204
	struct alc_spec *spec = codec->spec;
3205

3206 3207
	spec->autocfg.hp_pins[0] = 0x1b;
	spec->autocfg.speaker_pins[0] = 0x17;
3208 3209
}

3210 3211 3212 3213 3214 3215
/*
 * LG LW20
 *
 * Pin assignment:
 *   Speaker-out: 0x14
 *   Mic-In: 0x18
3216 3217 3218
 *   Built-in Mic-In: 0x19
 *   Line-In: 0x1b
 *   HP-Out: 0x1a
3219 3220 3221 3222
 *   SPDIF-Out: 0x1e
 */

static struct hda_input_mux alc880_lg_lw_capture_source = {
3223
	.num_items = 3,
3224 3225 3226
	.items = {
		{ "Mic", 0x0 },
		{ "Internal Mic", 0x1 },
3227
		{ "Line In", 0x2 },
3228 3229 3230
	},
};

3231 3232
#define alc880_lg_lw_modes alc880_threestack_modes

3233
static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3234 3235 3236 3237 3238 3239 3240 3241 3242 3243
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3244 3245 3246 3247
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
3248 3249 3250 3251 3252 3253 3254
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Channel Mode",
		.info = alc_ch_mode_info,
		.get = alc_ch_mode_get,
		.put = alc_ch_mode_put,
	},
3255 3256 3257 3258
	{ } /* end */
};

static struct hda_verb alc880_lg_lw_init_verbs[] = {
3259 3260 3261 3262
	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
	{0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
	{0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */

3263 3264 3265 3266
	/* set capture source to mic-in */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3267
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280
	/* speaker-out */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* HP-out */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* mic-in to input */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* built-in mic */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* jack sense */
3281
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3282 3283 3284 3285
	{ }
};

/* toggle speaker-output according to the hp-jack state */
3286
static void alc880_lg_lw_setup(struct hda_codec *codec)
3287
{
3288
	struct alc_spec *spec = codec->spec;
3289

3290 3291
	spec->autocfg.hp_pins[0] = 0x1b;
	spec->autocfg.speaker_pins[0] = 0x14;
3292 3293
}

3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337
static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
	HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

static struct hda_input_mux alc880_medion_rim_capture_source = {
	.num_items = 2,
	.items = {
		{ "Mic", 0x0 },
		{ "Internal Mic", 0x1 },
	},
};

static struct hda_verb alc880_medion_rim_init_verbs[] = {
	{0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */

	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},

	/* Mic1 (rear panel) pin widget for input and vref at 80% */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Mic2 (as headphone out) for HP output */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Internal Speaker */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},

	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
	{0x20, AC_VERB_SET_PROC_COEF,  0x3060},

	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{ }
};

/* toggle speaker-output according to the hp-jack state */
static void alc880_medion_rim_automute(struct hda_codec *codec)
{
3338 3339 3340 3341
	struct alc_spec *spec = codec->spec;
	alc_automute_amp(codec);
	/* toggle EAPD */
	if (spec->jack_present)
3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356
		snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
	else
		snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
}

static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
					  unsigned int res)
{
	/* Looks like the unsol event is incompatible with the standard
	 * definition.  4bit tag is placed at 28 bit!
	 */
	if ((res >> 28) == ALC880_HP_EVENT)
		alc880_medion_rim_automute(codec);
}

3357
static void alc880_medion_rim_setup(struct hda_codec *codec)
3358 3359 3360 3361 3362 3363 3364
{
	struct alc_spec *spec = codec->spec;

	spec->autocfg.hp_pins[0] = 0x14;
	spec->autocfg.speaker_pins[0] = 0x1b;
}

3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382
#ifdef CONFIG_SND_HDA_POWER_SAVE
static struct hda_amp_list alc880_loopbacks[] = {
	{ 0x0b, HDA_INPUT, 0 },
	{ 0x0b, HDA_INPUT, 1 },
	{ 0x0b, HDA_INPUT, 2 },
	{ 0x0b, HDA_INPUT, 3 },
	{ 0x0b, HDA_INPUT, 4 },
	{ } /* end */
};

static struct hda_amp_list alc880_lg_loopbacks[] = {
	{ 0x0b, HDA_INPUT, 1 },
	{ 0x0b, HDA_INPUT, 6 },
	{ 0x0b, HDA_INPUT, 7 },
	{ } /* end */
};
#endif

3383 3384
/*
 * Common callbacks
3385 3386
 */

L
Linus Torvalds 已提交
3387 3388 3389
static int alc_init(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
3390 3391
	unsigned int i;

3392
	alc_fix_pll(codec);
3393
	alc_auto_init_amp(codec, spec->init_amp);
3394

3395 3396
	for (i = 0; i < spec->num_init_verbs; i++)
		snd_hda_sequence_write(codec, spec->init_verbs[i]);
3397 3398 3399 3400

	if (spec->init_hook)
		spec->init_hook(codec);

L
Linus Torvalds 已提交
3401 3402 3403
	return 0;
}

3404 3405 3406 3407 3408 3409 3410 3411
static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
{
	struct alc_spec *spec = codec->spec;

	if (spec->unsol_event)
		spec->unsol_event(codec, res);
}

3412 3413 3414 3415 3416 3417 3418 3419
#ifdef CONFIG_SND_HDA_POWER_SAVE
static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
{
	struct alc_spec *spec = codec->spec;
	return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
}
#endif

L
Linus Torvalds 已提交
3420 3421 3422 3423 3424
/*
 * Analog playback callbacks
 */
static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
				    struct hda_codec *codec,
3425
				    struct snd_pcm_substream *substream)
L
Linus Torvalds 已提交
3426 3427
{
	struct alc_spec *spec = codec->spec;
3428 3429
	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
					     hinfo);
L
Linus Torvalds 已提交
3430 3431 3432 3433 3434 3435
}

static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
				       struct hda_codec *codec,
				       unsigned int stream_tag,
				       unsigned int format,
3436
				       struct snd_pcm_substream *substream)
L
Linus Torvalds 已提交
3437 3438
{
	struct alc_spec *spec = codec->spec;
3439 3440
	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
						stream_tag, format, substream);
L
Linus Torvalds 已提交
3441 3442 3443 3444
}

static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
				       struct hda_codec *codec,
3445
				       struct snd_pcm_substream *substream)
L
Linus Torvalds 已提交
3446 3447 3448 3449 3450 3451 3452 3453 3454 3455
{
	struct alc_spec *spec = codec->spec;
	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
}

/*
 * Digital out
 */
static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
					struct hda_codec *codec,
3456
					struct snd_pcm_substream *substream)
L
Linus Torvalds 已提交
3457 3458 3459 3460 3461
{
	struct alc_spec *spec = codec->spec;
	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
}

3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472
static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
					   struct hda_codec *codec,
					   unsigned int stream_tag,
					   unsigned int format,
					   struct snd_pcm_substream *substream)
{
	struct alc_spec *spec = codec->spec;
	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
					     stream_tag, format, substream);
}

3473 3474 3475 3476 3477 3478 3479 3480
static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
					   struct hda_codec *codec,
					   struct snd_pcm_substream *substream)
{
	struct alc_spec *spec = codec->spec;
	return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
}

L
Linus Torvalds 已提交
3481 3482
static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
					 struct hda_codec *codec,
3483
					 struct snd_pcm_substream *substream)
L
Linus Torvalds 已提交
3484 3485 3486 3487 3488 3489 3490 3491
{
	struct alc_spec *spec = codec->spec;
	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
}

/*
 * Analog capture
 */
3492
static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
L
Linus Torvalds 已提交
3493 3494 3495
				      struct hda_codec *codec,
				      unsigned int stream_tag,
				      unsigned int format,
3496
				      struct snd_pcm_substream *substream)
L
Linus Torvalds 已提交
3497 3498 3499
{
	struct alc_spec *spec = codec->spec;

3500
	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
L
Linus Torvalds 已提交
3501 3502 3503 3504
				   stream_tag, 0, format);
	return 0;
}

3505
static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
L
Linus Torvalds 已提交
3506
				      struct hda_codec *codec,
3507
				      struct snd_pcm_substream *substream)
L
Linus Torvalds 已提交
3508 3509 3510
{
	struct alc_spec *spec = codec->spec;

3511 3512
	snd_hda_codec_cleanup_stream(codec,
				     spec->adc_nids[substream->number + 1]);
L
Linus Torvalds 已提交
3513 3514 3515 3516 3517 3518 3519 3520 3521 3522
	return 0;
}


/*
 */
static struct hda_pcm_stream alc880_pcm_analog_playback = {
	.substreams = 1,
	.channels_min = 2,
	.channels_max = 8,
3523
	/* NID is set in alc_build_pcms */
L
Linus Torvalds 已提交
3524 3525 3526 3527 3528 3529 3530 3531
	.ops = {
		.open = alc880_playback_pcm_open,
		.prepare = alc880_playback_pcm_prepare,
		.cleanup = alc880_playback_pcm_cleanup
	},
};

static struct hda_pcm_stream alc880_pcm_analog_capture = {
3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546
	.substreams = 1,
	.channels_min = 2,
	.channels_max = 2,
	/* NID is set in alc_build_pcms */
};

static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
	.substreams = 1,
	.channels_min = 2,
	.channels_max = 2,
	/* NID is set in alc_build_pcms */
};

static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
	.substreams = 2, /* can be overridden */
L
Linus Torvalds 已提交
3547 3548
	.channels_min = 2,
	.channels_max = 2,
3549
	/* NID is set in alc_build_pcms */
L
Linus Torvalds 已提交
3550
	.ops = {
3551 3552
		.prepare = alc880_alt_capture_pcm_prepare,
		.cleanup = alc880_alt_capture_pcm_cleanup
L
Linus Torvalds 已提交
3553 3554 3555 3556 3557 3558 3559 3560 3561 3562
	},
};

static struct hda_pcm_stream alc880_pcm_digital_playback = {
	.substreams = 1,
	.channels_min = 2,
	.channels_max = 2,
	/* NID is set in alc_build_pcms */
	.ops = {
		.open = alc880_dig_playback_pcm_open,
3563
		.close = alc880_dig_playback_pcm_close,
3564 3565
		.prepare = alc880_dig_playback_pcm_prepare,
		.cleanup = alc880_dig_playback_pcm_cleanup
L
Linus Torvalds 已提交
3566 3567 3568 3569 3570 3571 3572 3573 3574 3575
	},
};

static struct hda_pcm_stream alc880_pcm_digital_capture = {
	.substreams = 1,
	.channels_min = 2,
	.channels_max = 2,
	/* NID is set in alc_build_pcms */
};

3576
/* Used by alc_build_pcms to flag that a PCM has no playback stream */
3577
static struct hda_pcm_stream alc_pcm_null_stream = {
3578 3579 3580 3581 3582
	.substreams = 0,
	.channels_min = 0,
	.channels_max = 0,
};

L
Linus Torvalds 已提交
3583 3584 3585 3586 3587 3588 3589 3590 3591
static int alc_build_pcms(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	struct hda_pcm *info = spec->pcm_rec;
	int i;

	codec->num_pcms = 1;
	codec->pcm_info = info;

3592 3593 3594
	if (spec->no_analog)
		goto skip_analog;

3595 3596
	snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
		 "%s Analog", codec->chip_name);
L
Linus Torvalds 已提交
3597
	info->name = spec->stream_name_analog;
3598

3599
	if (spec->stream_analog_playback) {
3600 3601
		if (snd_BUG_ON(!spec->multiout.dac_nids))
			return -EINVAL;
3602 3603 3604 3605
		info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
	}
	if (spec->stream_analog_capture) {
3606 3607
		if (snd_BUG_ON(!spec->adc_nids))
			return -EINVAL;
3608 3609 3610 3611 3612 3613 3614 3615 3616 3617
		info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
		info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
	}

	if (spec->channel_mode) {
		info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
		for (i = 0; i < spec->num_channel_mode; i++) {
			if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
				info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
			}
L
Linus Torvalds 已提交
3618 3619 3620
		}
	}

3621
 skip_analog:
3622
	/* SPDIF for stream index #1 */
L
Linus Torvalds 已提交
3623
	if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3624 3625 3626
		snprintf(spec->stream_name_digital,
			 sizeof(spec->stream_name_digital),
			 "%s Digital", codec->chip_name);
3627
		codec->num_pcms = 2;
3628
	        codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3629
		info = spec->pcm_rec + 1;
L
Linus Torvalds 已提交
3630
		info->name = spec->stream_name_digital;
3631 3632 3633 3634
		if (spec->dig_out_type)
			info->pcm_type = spec->dig_out_type;
		else
			info->pcm_type = HDA_PCM_TYPE_SPDIF;
3635 3636
		if (spec->multiout.dig_out_nid &&
		    spec->stream_digital_playback) {
L
Linus Torvalds 已提交
3637 3638 3639
			info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
			info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
		}
3640 3641
		if (spec->dig_in_nid &&
		    spec->stream_digital_capture) {
L
Linus Torvalds 已提交
3642 3643 3644
			info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
		}
3645 3646
		/* FIXME: do we need this for all Realtek codec models? */
		codec->spdif_status_reset = 1;
L
Linus Torvalds 已提交
3647 3648
	}

3649 3650 3651
	if (spec->no_analog)
		return 0;

3652 3653 3654 3655
	/* If the use of more than one ADC is requested for the current
	 * model, configure a second analog capture-only PCM.
	 */
	/* Additional Analaog capture for index #2 */
3656 3657
	if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
	    (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3658
		codec->num_pcms = 3;
3659
		info = spec->pcm_rec + 2;
3660
		info->name = spec->stream_name_analog;
3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681
		if (spec->alt_dac_nid) {
			info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
				*spec->stream_analog_alt_playback;
			info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
				spec->alt_dac_nid;
		} else {
			info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
				alc_pcm_null_stream;
			info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
		}
		if (spec->num_adc_nids > 1) {
			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
				*spec->stream_analog_alt_capture;
			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
				spec->adc_nids[1];
			info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
				spec->num_adc_nids - 1;
		} else {
			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
				alc_pcm_null_stream;
			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3682 3683 3684
		}
	}

L
Linus Torvalds 已提交
3685 3686 3687
	return 0;
}

3688 3689 3690 3691 3692
static inline void alc_shutup(struct hda_codec *codec)
{
	snd_hda_shutup_pins(codec);
}

3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705
static void alc_free_kctls(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;

	if (spec->kctls.list) {
		struct snd_kcontrol_new *kctl = spec->kctls.list;
		int i;
		for (i = 0; i < spec->kctls.used; i++)
			kfree(kctl[i].name);
	}
	snd_array_free(&spec->kctls);
}

L
Linus Torvalds 已提交
3706 3707
static void alc_free(struct hda_codec *codec)
{
3708 3709
	struct alc_spec *spec = codec->spec;

3710
	if (!spec)
3711 3712
		return;

3713
	alc_shutup(codec);
3714
	alc_free_kctls(codec);
3715
	kfree(spec);
3716
	snd_hda_detach_beep_device(codec);
L
Linus Torvalds 已提交
3717 3718
}

3719
#ifdef CONFIG_SND_HDA_POWER_SAVE
3720 3721 3722 3723 3724
static void alc_power_eapd(struct hda_codec *codec)
{
	/* We currently only handle front, HP */
	switch (codec->vendor_id) {
	case 0x10ec0260:
3725 3726
		set_eapd(codec, 0x0f, 0);
		set_eapd(codec, 0x10, 0);
3727 3728 3729 3730 3731
		break;
	case 0x10ec0262:
	case 0x10ec0267:
	case 0x10ec0268:
	case 0x10ec0269:
3732
	case 0x10ec0270:
3733 3734 3735 3736 3737 3738
	case 0x10ec0272:
	case 0x10ec0660:
	case 0x10ec0662:
	case 0x10ec0663:
	case 0x10ec0862:
	case 0x10ec0889:
3739 3740
		set_eapd(codec, 0x14, 0);
		set_eapd(codec, 0x15, 0);
3741 3742 3743 3744
		break;
	}
}

3745 3746 3747
static int alc_suspend(struct hda_codec *codec, pm_message_t state)
{
	struct alc_spec *spec = codec->spec;
3748
	alc_shutup(codec);
3749
	if (spec && spec->power_hook)
3750
		spec->power_hook(codec);
3751 3752 3753 3754
	return 0;
}
#endif

3755 3756 3757 3758 3759 3760 3761 3762 3763 3764
#ifdef SND_HDA_NEEDS_RESUME
static int alc_resume(struct hda_codec *codec)
{
	codec->patch_ops.init(codec);
	snd_hda_codec_resume_amp(codec);
	snd_hda_codec_resume_cache(codec);
	return 0;
}
#endif

L
Linus Torvalds 已提交
3765 3766 3767 3768 3769 3770 3771
/*
 */
static struct hda_codec_ops alc_patch_ops = {
	.build_controls = alc_build_controls,
	.build_pcms = alc_build_pcms,
	.init = alc_init,
	.free = alc_free,
3772
	.unsol_event = alc_unsol_event,
3773 3774 3775
#ifdef SND_HDA_NEEDS_RESUME
	.resume = alc_resume,
#endif
3776
#ifdef CONFIG_SND_HDA_POWER_SAVE
3777
	.suspend = alc_suspend,
3778 3779
	.check_power_status = alc_check_power_status,
#endif
3780
	.reboot_notify = alc_shutup,
L
Linus Torvalds 已提交
3781 3782
};

3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795

/*
 * Test configuration for debugging
 *
 * Almost all inputs/outputs are enabled.  I/O pins can be configured via
 * enum controls.
 */
#ifdef CONFIG_SND_DEBUG
static hda_nid_t alc880_test_dac_nids[4] = {
	0x02, 0x03, 0x04, 0x05
};

static struct hda_input_mux alc880_test_capture_source = {
3796
	.num_items = 7,
3797 3798 3799 3800 3801 3802
	.items = {
		{ "In-1", 0x0 },
		{ "In-2", 0x1 },
		{ "In-3", 0x2 },
		{ "In-4", 0x3 },
		{ "CD", 0x4 },
3803 3804
		{ "Front", 0x5 },
		{ "Surround", 0x6 },
3805 3806 3807
	},
};

3808
static struct hda_channel_mode alc880_test_modes[4] = {
3809
	{ 2, NULL },
3810
	{ 4, NULL },
3811
	{ 6, NULL },
3812
	{ 8, NULL },
3813 3814
};

3815 3816
static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
				 struct snd_ctl_elem_info *uinfo)
3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830
{
	static char *texts[] = {
		"N/A", "Line Out", "HP Out",
		"In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
	};
	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
	uinfo->count = 1;
	uinfo->value.enumerated.items = 8;
	if (uinfo->value.enumerated.item >= 8)
		uinfo->value.enumerated.item = 7;
	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
	return 0;
}

3831 3832
static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
	unsigned int pin_ctl, item = 0;

	pin_ctl = snd_hda_codec_read(codec, nid, 0,
				     AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
	if (pin_ctl & AC_PINCTL_OUT_EN) {
		if (pin_ctl & AC_PINCTL_HP_EN)
			item = 2;
		else
			item = 1;
	} else if (pin_ctl & AC_PINCTL_IN_EN) {
		switch (pin_ctl & AC_PINCTL_VREFEN) {
		case AC_PINCTL_VREF_HIZ: item = 3; break;
		case AC_PINCTL_VREF_50:  item = 4; break;
		case AC_PINCTL_VREF_GRD: item = 5; break;
		case AC_PINCTL_VREF_80:  item = 6; break;
		case AC_PINCTL_VREF_100: item = 7; break;
		}
	}
	ucontrol->value.enumerated.item[0] = item;
	return 0;
}

3858 3859
static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
	static unsigned int ctls[] = {
		0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
		AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
		AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
		AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
		AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
		AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
	};
	unsigned int old_ctl, new_ctl;

	old_ctl = snd_hda_codec_read(codec, nid, 0,
				     AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
	new_ctl = ctls[ucontrol->value.enumerated.item[0]];
	if (old_ctl != new_ctl) {
3877 3878 3879 3880
		int val;
		snd_hda_codec_write_cache(codec, nid, 0,
					  AC_VERB_SET_PIN_WIDGET_CONTROL,
					  new_ctl);
3881 3882 3883 3884
		val = ucontrol->value.enumerated.item[0] >= 3 ?
			HDA_AMP_MUTE : 0;
		snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
					 HDA_AMP_MUTE, val);
3885 3886 3887 3888 3889
		return 1;
	}
	return 0;
}

3890 3891
static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
				 struct snd_ctl_elem_info *uinfo)
3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904
{
	static char *texts[] = {
		"Front", "Surround", "CLFE", "Side"
	};
	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
	uinfo->count = 1;
	uinfo->value.enumerated.items = 4;
	if (uinfo->value.enumerated.item >= 4)
		uinfo->value.enumerated.item = 3;
	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
	return 0;
}

3905 3906
static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
3907 3908 3909 3910 3911 3912 3913 3914 3915 3916
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
	unsigned int sel;

	sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
	ucontrol->value.enumerated.item[0] = sel & 3;
	return 0;
}

3917 3918
static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
3919 3920 3921 3922 3923 3924 3925 3926
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
	unsigned int sel;

	sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
	if (ucontrol->value.enumerated.item[0] != sel) {
		sel = ucontrol->value.enumerated.item[0] & 3;
3927 3928
		snd_hda_codec_write_cache(codec, nid, 0,
					  AC_VERB_SET_CONNECT_SEL, sel);
3929 3930 3931 3932 3933 3934 3935 3936
		return 1;
	}
	return 0;
}

#define PIN_CTL_TEST(xname,nid) {			\
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,	\
			.name = xname,		       \
3937
			.subdevice = HDA_SUBDEV_NID_FLAG | nid, \
3938 3939 3940 3941 3942 3943 3944 3945 3946
			.info = alc_test_pin_ctl_info, \
			.get = alc_test_pin_ctl_get,   \
			.put = alc_test_pin_ctl_put,   \
			.private_value = nid	       \
			}

#define PIN_SRC_TEST(xname,nid) {			\
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,	\
			.name = xname,		       \
3947
			.subdevice = HDA_SUBDEV_NID_FLAG | nid, \
3948 3949 3950 3951 3952 3953
			.info = alc_test_pin_src_info, \
			.get = alc_test_pin_src_get,   \
			.put = alc_test_pin_src_put,   \
			.private_value = nid	       \
			}

3954
static struct snd_kcontrol_new alc880_test_mixer[] = {
3955 3956 3957 3958
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
3959 3960 3961 3962
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
	HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987
	PIN_CTL_TEST("Front Pin Mode", 0x14),
	PIN_CTL_TEST("Surround Pin Mode", 0x15),
	PIN_CTL_TEST("CLFE Pin Mode", 0x16),
	PIN_CTL_TEST("Side Pin Mode", 0x17),
	PIN_CTL_TEST("In-1 Pin Mode", 0x18),
	PIN_CTL_TEST("In-2 Pin Mode", 0x19),
	PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
	PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
	PIN_SRC_TEST("In-1 Pin Source", 0x18),
	PIN_SRC_TEST("In-2 Pin Source", 0x19),
	PIN_SRC_TEST("In-3 Pin Source", 0x1a),
	PIN_SRC_TEST("In-4 Pin Source", 0x1b),
	HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
	HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
	HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
	HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Channel Mode",
3988 3989 3990
		.info = alc_ch_mode_info,
		.get = alc_ch_mode_get,
		.put = alc_ch_mode_put,
3991 3992 3993 3994 3995 3996
	},
	{ } /* end */
};

static struct hda_verb alc880_test_init_verbs[] = {
	/* Unmute inputs of 0x0c - 0x0f */
3997 3998 3999 4000 4001 4002 4003 4004
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4005
	/* Vol output for 0x0c-0x0f */
4006 4007 4008 4009
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4010
	/* Set output pins 0x14-0x17 */
4011 4012 4013 4014
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4015
	/* Unmute output pins 0x14-0x17 */
4016 4017 4018 4019
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4020
	/* Set input pins 0x18-0x1c */
4021 4022
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4023 4024 4025
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4026
	/* Mute input pins 0x18-0x1b */
4027 4028 4029 4030
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4031
	/* ADC set up */
4032
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4033
	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
4034
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4035
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
4036
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4037
	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
4038 4039 4040 4041 4042 4043
	/* Analog input/passthru */
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4044 4045 4046 4047
	{ }
};
#endif

L
Linus Torvalds 已提交
4048 4049 4050
/*
 */

4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066
static const char *alc880_models[ALC880_MODEL_LAST] = {
	[ALC880_3ST]		= "3stack",
	[ALC880_TCL_S700]	= "tcl",
	[ALC880_3ST_DIG]	= "3stack-digout",
	[ALC880_CLEVO]		= "clevo",
	[ALC880_5ST]		= "5stack",
	[ALC880_5ST_DIG]	= "5stack-digout",
	[ALC880_W810]		= "w810",
	[ALC880_Z71V]		= "z71v",
	[ALC880_6ST]		= "6stack",
	[ALC880_6ST_DIG]	= "6stack-digout",
	[ALC880_ASUS]		= "asus",
	[ALC880_ASUS_W1V]	= "asus-w1v",
	[ALC880_ASUS_DIG]	= "asus-dig",
	[ALC880_ASUS_DIG2]	= "asus-dig2",
	[ALC880_UNIWILL_DIG]	= "uniwill",
4067 4068
	[ALC880_UNIWILL_P53]	= "uniwill-p53",
	[ALC880_FUJITSU]	= "fujitsu",
4069 4070 4071
	[ALC880_F1734]		= "F1734",
	[ALC880_LG]		= "lg",
	[ALC880_LG_LW]		= "lg-lw",
4072
	[ALC880_MEDION_RIM]	= "medion",
4073
#ifdef CONFIG_SND_DEBUG
4074
	[ALC880_TEST]		= "test",
4075
#endif
4076 4077 4078 4079
	[ALC880_AUTO]		= "auto",
};

static struct snd_pci_quirk alc880_cfg_tbl[] = {
4080
	SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100
	SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
	SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
	SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
	SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
	SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
	SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
	SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
	SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
	SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
	SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
	SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
	SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
	SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
	SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
	SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
	SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
	SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
	/* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
	SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
	SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
T
Travis Place 已提交
4101
	SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
4102 4103 4104
	SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
	SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
	SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
T
Takashi Iwai 已提交
4105
	SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
4106
	SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
4107 4108
	SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
	SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
4109 4110 4111 4112 4113 4114
	SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
	SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
	SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
	SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
	SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
	SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
4115 4116
	SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
	SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
4117
	SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
4118
	SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
4119
	SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
4120
	SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
4121 4122
	SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
	SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
4123
	SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
4124
	SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
4125
	SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
4126 4127
	SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
	SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
4128
	SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
4129
	SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
4130
	SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
4131
	SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
4132 4133 4134
	SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
	SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
	SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
4135 4136 4137 4138
	SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
	SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
	SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
	SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
4139 4140
	SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
	SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
4141
	SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
4142
	SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
4143 4144
	SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
	SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
4145 4146 4147
	SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
	SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
	SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
T
Takashi Iwai 已提交
4148 4149
	/* default Intel */
	SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
4150 4151
	SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
	SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
L
Linus Torvalds 已提交
4152 4153 4154
	{}
};

4155
/*
4156
 * ALC880 codec presets
4157 4158 4159
 */
static struct alc_config_preset alc880_presets[] = {
	[ALC880_3ST] = {
4160
		.mixers = { alc880_three_stack_mixer },
4161 4162
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_3stack_init_verbs },
4163 4164 4165 4166
		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
		.dac_nids = alc880_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
		.channel_mode = alc880_threestack_modes,
4167
		.need_dac_fix = 1,
4168 4169 4170
		.input_mux = &alc880_capture_source,
	},
	[ALC880_3ST_DIG] = {
4171
		.mixers = { alc880_three_stack_mixer },
4172 4173
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_3stack_init_verbs },
4174 4175 4176 4177 4178
		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
		.dac_nids = alc880_dac_nids,
		.dig_out_nid = ALC880_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
		.channel_mode = alc880_threestack_modes,
4179
		.need_dac_fix = 1,
4180 4181
		.input_mux = &alc880_capture_source,
	},
4182 4183 4184 4185 4186 4187 4188
	[ALC880_TCL_S700] = {
		.mixers = { alc880_tcl_s700_mixer },
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_tcl_S700_init_verbs,
				alc880_gpio2_init_verbs },
		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
		.dac_nids = alc880_dac_nids,
4189 4190
		.adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
		.num_adc_nids = 1, /* single ADC */
4191 4192 4193 4194 4195
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
		.channel_mode = alc880_2_jack_modes,
		.input_mux = &alc880_capture_source,
	},
4196
	[ALC880_5ST] = {
4197 4198 4199 4200
		.mixers = { alc880_three_stack_mixer,
			    alc880_five_stack_mixer},
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_5stack_init_verbs },
4201 4202 4203 4204 4205 4206 4207
		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
		.dac_nids = alc880_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
		.channel_mode = alc880_fivestack_modes,
		.input_mux = &alc880_capture_source,
	},
	[ALC880_5ST_DIG] = {
4208 4209 4210 4211
		.mixers = { alc880_three_stack_mixer,
			    alc880_five_stack_mixer },
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_5stack_init_verbs },
4212 4213 4214 4215 4216 4217 4218
		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
		.dac_nids = alc880_dac_nids,
		.dig_out_nid = ALC880_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
		.channel_mode = alc880_fivestack_modes,
		.input_mux = &alc880_capture_source,
	},
4219 4220
	[ALC880_6ST] = {
		.mixers = { alc880_six_stack_mixer },
4221 4222
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_6stack_init_verbs },
4223 4224 4225 4226 4227 4228
		.num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
		.dac_nids = alc880_6st_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
		.channel_mode = alc880_sixstack_modes,
		.input_mux = &alc880_6stack_capture_source,
	},
4229
	[ALC880_6ST_DIG] = {
4230
		.mixers = { alc880_six_stack_mixer },
4231 4232
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_6stack_init_verbs },
4233 4234 4235 4236 4237 4238 4239 4240
		.num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
		.dac_nids = alc880_6st_dac_nids,
		.dig_out_nid = ALC880_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
		.channel_mode = alc880_sixstack_modes,
		.input_mux = &alc880_6stack_capture_source,
	},
	[ALC880_W810] = {
4241
		.mixers = { alc880_w810_base_mixer },
4242 4243
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_w810_init_verbs,
4244
				alc880_gpio2_init_verbs },
4245 4246 4247 4248 4249 4250 4251 4252
		.num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
		.dac_nids = alc880_w810_dac_nids,
		.dig_out_nid = ALC880_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
		.channel_mode = alc880_w810_modes,
		.input_mux = &alc880_capture_source,
	},
	[ALC880_Z71V] = {
4253
		.mixers = { alc880_z71v_mixer },
4254 4255
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_z71v_init_verbs },
4256 4257 4258 4259
		.num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
		.dac_nids = alc880_z71v_dac_nids,
		.dig_out_nid = ALC880_DIGOUT_NID,
		.hp_nid = 0x03,
4260 4261
		.num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
		.channel_mode = alc880_2_jack_modes,
4262 4263 4264
		.input_mux = &alc880_capture_source,
	},
	[ALC880_F1734] = {
4265
		.mixers = { alc880_f1734_mixer },
4266 4267
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_f1734_init_verbs },
4268 4269 4270 4271 4272
		.num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
		.dac_nids = alc880_f1734_dac_nids,
		.hp_nid = 0x02,
		.num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
		.channel_mode = alc880_2_jack_modes,
4273 4274
		.input_mux = &alc880_f1734_capture_source,
		.unsol_event = alc880_uniwill_p53_unsol_event,
4275 4276
		.setup = alc880_uniwill_p53_setup,
		.init_hook = alc_automute_amp,
4277 4278
	},
	[ALC880_ASUS] = {
4279
		.mixers = { alc880_asus_mixer },
4280 4281
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_asus_init_verbs,
4282 4283 4284 4285 4286
				alc880_gpio1_init_verbs },
		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
		.dac_nids = alc880_asus_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
		.channel_mode = alc880_asus_modes,
4287
		.need_dac_fix = 1,
4288 4289 4290
		.input_mux = &alc880_capture_source,
	},
	[ALC880_ASUS_DIG] = {
4291
		.mixers = { alc880_asus_mixer },
4292 4293
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_asus_init_verbs,
4294 4295 4296
				alc880_gpio1_init_verbs },
		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
		.dac_nids = alc880_asus_dac_nids,
4297
		.dig_out_nid = ALC880_DIGOUT_NID,
4298 4299
		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
		.channel_mode = alc880_asus_modes,
4300
		.need_dac_fix = 1,
4301 4302
		.input_mux = &alc880_capture_source,
	},
4303 4304
	[ALC880_ASUS_DIG2] = {
		.mixers = { alc880_asus_mixer },
4305 4306
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_asus_init_verbs,
4307 4308 4309 4310 4311 4312
				alc880_gpio2_init_verbs }, /* use GPIO2 */
		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
		.dac_nids = alc880_asus_dac_nids,
		.dig_out_nid = ALC880_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
		.channel_mode = alc880_asus_modes,
4313
		.need_dac_fix = 1,
4314 4315
		.input_mux = &alc880_capture_source,
	},
4316
	[ALC880_ASUS_W1V] = {
4317
		.mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
4318 4319
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_asus_init_verbs,
4320 4321 4322
				alc880_gpio1_init_verbs },
		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
		.dac_nids = alc880_asus_dac_nids,
4323
		.dig_out_nid = ALC880_DIGOUT_NID,
4324 4325
		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
		.channel_mode = alc880_asus_modes,
4326
		.need_dac_fix = 1,
4327 4328 4329
		.input_mux = &alc880_capture_source,
	},
	[ALC880_UNIWILL_DIG] = {
4330
		.mixers = { alc880_asus_mixer },
4331 4332
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_asus_init_verbs },
4333 4334
		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
		.dac_nids = alc880_asus_dac_nids,
4335
		.dig_out_nid = ALC880_DIGOUT_NID,
4336 4337
		.num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
		.channel_mode = alc880_asus_modes,
4338
		.need_dac_fix = 1,
4339 4340
		.input_mux = &alc880_capture_source,
	},
4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352
	[ALC880_UNIWILL] = {
		.mixers = { alc880_uniwill_mixer },
		.init_verbs = { alc880_volume_init_verbs,
				alc880_uniwill_init_verbs },
		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
		.dac_nids = alc880_asus_dac_nids,
		.dig_out_nid = ALC880_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
		.channel_mode = alc880_threestack_modes,
		.need_dac_fix = 1,
		.input_mux = &alc880_capture_source,
		.unsol_event = alc880_uniwill_unsol_event,
4353
		.setup = alc880_uniwill_setup,
4354
		.init_hook = alc880_uniwill_init_hook,
4355 4356 4357 4358 4359 4360 4361 4362
	},
	[ALC880_UNIWILL_P53] = {
		.mixers = { alc880_uniwill_p53_mixer },
		.init_verbs = { alc880_volume_init_verbs,
				alc880_uniwill_p53_init_verbs },
		.num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
		.dac_nids = alc880_asus_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4363 4364 4365
		.channel_mode = alc880_threestack_modes,
		.input_mux = &alc880_capture_source,
		.unsol_event = alc880_uniwill_p53_unsol_event,
4366 4367
		.setup = alc880_uniwill_p53_setup,
		.init_hook = alc_automute_amp,
4368 4369
	},
	[ALC880_FUJITSU] = {
4370
		.mixers = { alc880_fujitsu_mixer },
4371 4372 4373 4374 4375
		.init_verbs = { alc880_volume_init_verbs,
				alc880_uniwill_p53_init_verbs,
	       			alc880_beep_init_verbs },
		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
		.dac_nids = alc880_dac_nids,
4376
		.dig_out_nid = ALC880_DIGOUT_NID,
4377 4378
		.num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
		.channel_mode = alc880_2_jack_modes,
4379 4380
		.input_mux = &alc880_capture_source,
		.unsol_event = alc880_uniwill_p53_unsol_event,
4381 4382
		.setup = alc880_uniwill_p53_setup,
		.init_hook = alc_automute_amp,
4383
	},
4384 4385 4386 4387 4388 4389 4390 4391 4392
	[ALC880_CLEVO] = {
		.mixers = { alc880_three_stack_mixer },
		.init_verbs = { alc880_volume_init_verbs,
				alc880_pin_clevo_init_verbs },
		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
		.dac_nids = alc880_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
		.channel_mode = alc880_threestack_modes,
4393
		.need_dac_fix = 1,
4394 4395
		.input_mux = &alc880_capture_source,
	},
4396 4397 4398 4399 4400 4401 4402 4403 4404
	[ALC880_LG] = {
		.mixers = { alc880_lg_mixer },
		.init_verbs = { alc880_volume_init_verbs,
				alc880_lg_init_verbs },
		.num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
		.dac_nids = alc880_lg_dac_nids,
		.dig_out_nid = ALC880_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
		.channel_mode = alc880_lg_ch_modes,
4405
		.need_dac_fix = 1,
4406
		.input_mux = &alc880_lg_capture_source,
4407
		.unsol_event = alc_automute_amp_unsol_event,
4408 4409
		.setup = alc880_lg_setup,
		.init_hook = alc_automute_amp,
4410 4411 4412
#ifdef CONFIG_SND_HDA_POWER_SAVE
		.loopbacks = alc880_lg_loopbacks,
#endif
4413
	},
4414 4415 4416 4417
	[ALC880_LG_LW] = {
		.mixers = { alc880_lg_lw_mixer },
		.init_verbs = { alc880_volume_init_verbs,
				alc880_lg_lw_init_verbs },
4418
		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
4419 4420
		.dac_nids = alc880_dac_nids,
		.dig_out_nid = ALC880_DIGOUT_NID,
4421 4422
		.num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
		.channel_mode = alc880_lg_lw_modes,
4423
		.input_mux = &alc880_lg_lw_capture_source,
4424
		.unsol_event = alc_automute_amp_unsol_event,
4425 4426
		.setup = alc880_lg_lw_setup,
		.init_hook = alc_automute_amp,
4427
	},
4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439
	[ALC880_MEDION_RIM] = {
		.mixers = { alc880_medion_rim_mixer },
		.init_verbs = { alc880_volume_init_verbs,
				alc880_medion_rim_init_verbs,
				alc_gpio2_init_verbs },
		.num_dacs = ARRAY_SIZE(alc880_dac_nids),
		.dac_nids = alc880_dac_nids,
		.dig_out_nid = ALC880_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
		.channel_mode = alc880_2_jack_modes,
		.input_mux = &alc880_medion_rim_capture_source,
		.unsol_event = alc880_medion_rim_unsol_event,
4440 4441
		.setup = alc880_medion_rim_setup,
		.init_hook = alc880_medion_rim_automute,
4442
	},
4443 4444
#ifdef CONFIG_SND_DEBUG
	[ALC880_TEST] = {
4445 4446
		.mixers = { alc880_test_mixer },
		.init_verbs = { alc880_test_init_verbs },
4447 4448 4449 4450 4451 4452 4453 4454 4455 4456
		.num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
		.dac_nids = alc880_test_dac_nids,
		.dig_out_nid = ALC880_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc880_test_modes),
		.channel_mode = alc880_test_modes,
		.input_mux = &alc880_test_capture_source,
	},
#endif
};

4457 4458 4459 4460 4461 4462 4463 4464 4465
/*
 * Automatic parse of I/O pins from the BIOS configuration
 */

enum {
	ALC_CTL_WIDGET_VOL,
	ALC_CTL_WIDGET_MUTE,
	ALC_CTL_BIND_MUTE,
};
4466
static struct snd_kcontrol_new alc880_control_templates[] = {
4467 4468
	HDA_CODEC_VOLUME(NULL, 0, 0, 0),
	HDA_CODEC_MUTE(NULL, 0, 0, 0),
T
Takashi Iwai 已提交
4469
	HDA_BIND_MUTE(NULL, 0, 0, 0),
4470 4471 4472
};

/* add dynamic controls */
4473 4474
static int add_control(struct alc_spec *spec, int type, const char *name,
		       unsigned long val)
4475
{
4476
	struct snd_kcontrol_new *knew;
4477

4478 4479 4480 4481
	snd_array_init(&spec->kctls, sizeof(*knew), 32);
	knew = snd_array_new(&spec->kctls);
	if (!knew)
		return -ENOMEM;
4482
	*knew = alc880_control_templates[type];
4483
	knew->name = kstrdup(name, GFP_KERNEL);
4484
	if (!knew->name)
4485
		return -ENOMEM;
4486
	if (get_amp_nid_(val))
4487
		knew->subdevice = HDA_SUBDEV_AMP_FLAG;
4488 4489 4490 4491
	knew->private_value = val;
	return 0;
}

4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505
static int add_control_with_pfx(struct alc_spec *spec, int type,
				const char *pfx, const char *dir,
				const char *sfx, unsigned long val)
{
	char name[32];
	snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
	return add_control(spec, type, name, val);
}

#define add_pb_vol_ctrl(spec, type, pfx, val) \
	add_control_with_pfx(spec, type, pfx, "Playback", "Volume", val)
#define add_pb_sw_ctrl(spec, type, pfx, val) \
	add_control_with_pfx(spec, type, pfx, "Playback", "Switch", val)

4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516
#define alc880_is_fixed_pin(nid)	((nid) >= 0x14 && (nid) <= 0x17)
#define alc880_fixed_pin_idx(nid)	((nid) - 0x14)
#define alc880_is_multi_pin(nid)	((nid) >= 0x18)
#define alc880_multi_pin_idx(nid)	((nid) - 0x18)
#define alc880_idx_to_dac(nid)		((nid) + 0x02)
#define alc880_dac_to_idx(nid)		((nid) - 0x02)
#define alc880_idx_to_mixer(nid)	((nid) + 0x0c)
#define alc880_idx_to_selector(nid)	((nid) + 0x10)
#define ALC880_PIN_CD_NID		0x1c

/* fill in the dac_nids table from the parsed pin configuration */
4517 4518
static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
				     const struct auto_pin_cfg *cfg)
4519 4520 4521 4522 4523 4524
{
	hda_nid_t nid;
	int assigned[4];
	int i, j;

	memset(assigned, 0, sizeof(assigned));
4525
	spec->multiout.dac_nids = spec->private_dac_nids;
4526 4527 4528 4529 4530 4531

	/* check the pins hardwired to audio widget */
	for (i = 0; i < cfg->line_outs; i++) {
		nid = cfg->line_out_pins[i];
		if (alc880_is_fixed_pin(nid)) {
			int idx = alc880_fixed_pin_idx(nid);
4532
			spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
4533 4534 4535 4536 4537 4538 4539 4540 4541 4542
			assigned[idx] = 1;
		}
	}
	/* left pins can be connect to any audio widget */
	for (i = 0; i < cfg->line_outs; i++) {
		nid = cfg->line_out_pins[i];
		if (alc880_is_fixed_pin(nid))
			continue;
		/* search for an empty channel */
		for (j = 0; j < cfg->line_outs; j++) {
4543 4544 4545
			if (!assigned[j]) {
				spec->multiout.dac_nids[i] =
					alc880_idx_to_dac(j);
4546 4547 4548 4549 4550 4551 4552 4553 4554 4555
				assigned[j] = 1;
				break;
			}
		}
	}
	spec->multiout.num_dacs = cfg->line_outs;
	return 0;
}

/* add playback controls from the parsed DAC table */
4556 4557
static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
					     const struct auto_pin_cfg *cfg)
4558
{
4559 4560 4561
	static const char *chname[4] = {
		"Front", "Surround", NULL /*CLFE*/, "Side"
	};
4562 4563 4564 4565
	hda_nid_t nid;
	int i, err;

	for (i = 0; i < cfg->line_outs; i++) {
4566
		if (!spec->multiout.dac_nids[i])
4567 4568 4569 4570
			continue;
		nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
		if (i == 2) {
			/* Center/LFE */
4571 4572
			err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
					      "Center",
4573 4574 4575
					  HDA_COMPOSE_AMP_VAL(nid, 1, 0,
							      HDA_OUTPUT));
			if (err < 0)
4576
				return err;
4577 4578
			err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
					      "LFE",
4579 4580 4581
					  HDA_COMPOSE_AMP_VAL(nid, 2, 0,
							      HDA_OUTPUT));
			if (err < 0)
4582
				return err;
4583 4584
			err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
					     "Center",
4585 4586 4587
					  HDA_COMPOSE_AMP_VAL(nid, 1, 2,
							      HDA_INPUT));
			if (err < 0)
4588
				return err;
4589 4590
			err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
					     "LFE",
4591 4592 4593
					  HDA_COMPOSE_AMP_VAL(nid, 2, 2,
							      HDA_INPUT));
			if (err < 0)
4594 4595
				return err;
		} else {
4596 4597 4598 4599 4600 4601
			const char *pfx;
			if (cfg->line_outs == 1 &&
			    cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
				pfx = "Speaker";
			else
				pfx = chname[i];
4602
			err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4603 4604 4605
					  HDA_COMPOSE_AMP_VAL(nid, 3, 0,
							      HDA_OUTPUT));
			if (err < 0)
4606
				return err;
4607
			err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4608 4609 4610
					  HDA_COMPOSE_AMP_VAL(nid, 3, 2,
							      HDA_INPUT));
			if (err < 0)
4611 4612 4613 4614 4615 4616
				return err;
		}
	}
	return 0;
}

4617 4618 4619
/* add playback controls for speaker and HP outputs */
static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
					const char *pfx)
4620 4621 4622 4623
{
	hda_nid_t nid;
	int err;

4624
	if (!pin)
4625 4626 4627 4628
		return 0;

	if (alc880_is_fixed_pin(pin)) {
		nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4629
		/* specify the DAC as the extra output */
4630
		if (!spec->multiout.hp_nid)
4631
			spec->multiout.hp_nid = nid;
4632 4633
		else
			spec->multiout.extra_out_nid[0] = nid;
4634 4635
		/* control HP volume/switch on the output mixer amp */
		nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4636
		err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4637 4638
				  HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
		if (err < 0)
4639
			return err;
4640
		err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4641 4642
				  HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
		if (err < 0)
4643 4644 4645 4646
			return err;
	} else if (alc880_is_multi_pin(pin)) {
		/* set manual connection */
		/* we have only a switch on HP-out PIN */
4647
		err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
4648 4649
				  HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
		if (err < 0)
4650 4651 4652 4653 4654 4655
			return err;
	}
	return 0;
}

/* create input playback/capture controls for the given pin */
4656 4657
static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
			    const char *ctlname,
4658
			    int idx, hda_nid_t mix_nid)
4659
{
4660
	int err;
4661

4662
	err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
4663 4664
			  HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
	if (err < 0)
4665
		return err;
4666
	err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
4667 4668
			  HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
	if (err < 0)
4669 4670 4671 4672
		return err;
	return 0;
}

4673 4674 4675 4676 4677 4678
static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
{
	unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
	return (pincap & AC_PINCAP_IN) != 0;
}

4679
/* create playback/capture controls for input pins */
4680 4681 4682 4683
static int alc_auto_create_input_ctls(struct hda_codec *codec,
				      const struct auto_pin_cfg *cfg,
				      hda_nid_t mixer,
				      hda_nid_t cap1, hda_nid_t cap2)
4684
{
4685
	struct alc_spec *spec = codec->spec;
4686
	struct hda_input_mux *imux = &spec->private_imux[0];
4687
	int i, err, idx;
4688 4689

	for (i = 0; i < AUTO_PIN_LAST; i++) {
4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712
		hda_nid_t pin;

		pin = cfg->input_pins[i];
		if (!alc_is_input_pin(codec, pin))
			continue;

		if (mixer) {
			idx = get_connection_index(codec, mixer, pin);
			if (idx >= 0) {
				err = new_analog_input(spec, pin,
						       auto_pin_cfg_labels[i],
						       idx, mixer);
				if (err < 0)
					return err;
			}
		}

		if (!cap1)
			continue;
		idx = get_connection_index(codec, cap1, pin);
		if (idx < 0 && cap2)
			idx = get_connection_index(codec, cap2, pin);
		if (idx >= 0) {
4713 4714
			imux->items[imux->num_items].label =
				auto_pin_cfg_labels[i];
4715
			imux->items[imux->num_items].index = idx;
4716 4717 4718 4719 4720 4721
			imux->num_items++;
		}
	}
	return 0;
}

4722 4723 4724 4725 4726 4727
static int alc880_auto_create_input_ctls(struct hda_codec *codec,
						const struct auto_pin_cfg *cfg)
{
	return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x08, 0x09);
}

4728 4729 4730 4731 4732 4733
static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
			       unsigned int pin_type)
{
	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
			    pin_type);
	/* unmute pin */
4734 4735
	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
			    AMP_OUT_UNMUTE);
4736 4737
}

4738 4739
static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
					      hda_nid_t nid, int pin_type,
4740 4741
					      int dac_idx)
{
4742
	alc_set_pin_output(codec, nid, pin_type);
4743 4744 4745 4746 4747 4748 4749 4750 4751 4752
	/* need the manual connection? */
	if (alc880_is_multi_pin(nid)) {
		struct alc_spec *spec = codec->spec;
		int idx = alc880_multi_pin_idx(nid);
		snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
				    AC_VERB_SET_CONNECT_SEL,
				    alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
	}
}

4753 4754 4755 4756 4757 4758 4759 4760
static int get_pin_type(int line_out_type)
{
	if (line_out_type == AUTO_PIN_HP_OUT)
		return PIN_HP;
	else
		return PIN_OUT;
}

4761 4762 4763 4764
static void alc880_auto_init_multi_out(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int i;
4765

4766 4767
	for (i = 0; i < spec->autocfg.line_outs; i++) {
		hda_nid_t nid = spec->autocfg.line_out_pins[i];
4768 4769
		int pin_type = get_pin_type(spec->autocfg.line_out_type);
		alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4770 4771 4772
	}
}

4773
static void alc880_auto_init_extra_out(struct hda_codec *codec)
4774 4775 4776 4777
{
	struct alc_spec *spec = codec->spec;
	hda_nid_t pin;

4778
	pin = spec->autocfg.speaker_pins[0];
4779 4780
	if (pin) /* connect to front */
		alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4781
	pin = spec->autocfg.hp_pins[0];
4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792
	if (pin) /* connect to front */
		alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
}

static void alc880_auto_init_analog_input(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int i;

	for (i = 0; i < AUTO_PIN_LAST; i++) {
		hda_nid_t nid = spec->autocfg.input_pins[i];
4793
		if (alc_is_input_pin(codec, nid)) {
4794
			alc_set_input_pin(codec, nid, i);
4795 4796
			if (nid != ALC880_PIN_CD_NID &&
			    (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
4797 4798
				snd_hda_codec_write(codec, nid, 0,
						    AC_VERB_SET_AMP_GAIN_MUTE,
4799 4800 4801 4802 4803 4804
						    AMP_OUT_MUTE);
		}
	}
}

/* parse the BIOS configuration and set up the alc_spec */
4805 4806 4807
/* return 1 if successful, 0 if the proper config is not found,
 * or a negative error code
 */
4808 4809 4810
static int alc880_parse_auto_config(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
4811
	int i, err;
4812
	static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4813

4814 4815 4816
	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
					   alc880_ignore);
	if (err < 0)
4817
		return err;
4818
	if (!spec->autocfg.line_outs)
4819
		return 0; /* can't find valid BIOS pin config */
4820

4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835
	err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
	if (err < 0)
		return err;
	err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
	if (err < 0)
		return err;
	err = alc880_auto_create_extra_out(spec,
					   spec->autocfg.speaker_pins[0],
					   "Speaker");
	if (err < 0)
		return err;
	err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
					   "Headphone");
	if (err < 0)
		return err;
4836
	err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
4837
	if (err < 0)
4838 4839 4840 4841
		return err;

	spec->multiout.max_channels = spec->multiout.num_dacs * 2;

4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853
	/* check multiple SPDIF-out (for recent codecs) */
	for (i = 0; i < spec->autocfg.dig_outs; i++) {
		hda_nid_t dig_nid;
		err = snd_hda_get_connections(codec,
					      spec->autocfg.dig_out_pins[i],
					      &dig_nid, 1);
		if (err < 0)
			continue;
		if (!i)
			spec->multiout.dig_out_nid = dig_nid;
		else {
			spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4854
			if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
4855
				break;
4856
			spec->slave_dig_outs[i - 1] = dig_nid;
4857 4858
		}
	}
4859 4860 4861
	if (spec->autocfg.dig_in_pin)
		spec->dig_in_nid = ALC880_DIGIN_NID;

4862
	if (spec->kctls.list)
4863
		add_mixer(spec, spec->kctls.list);
4864

4865
	add_verb(spec, alc880_volume_init_verbs);
4866

4867
	spec->num_mux_defs = 1;
4868
	spec->input_mux = &spec->private_imux[0];
4869

4870
	alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
4871

4872 4873 4874
	return 1;
}

4875 4876
/* additional initialization for auto-configuration model */
static void alc880_auto_init(struct hda_codec *codec)
4877
{
4878
	struct alc_spec *spec = codec->spec;
4879
	alc880_auto_init_multi_out(codec);
4880
	alc880_auto_init_extra_out(codec);
4881
	alc880_auto_init_analog_input(codec);
4882
	if (spec->unsol_event)
4883
		alc_inithook(codec);
4884 4885
}

4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918
/* check the ADC/MUX contains all input pins; some ADC/MUX contains only
 * one of two digital mic pins, e.g. on ALC272
 */
static void fixup_automic_adc(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int i;

	for (i = 0; i < spec->num_adc_nids; i++) {
		hda_nid_t cap = spec->capsrc_nids ?
			spec->capsrc_nids[i] : spec->adc_nids[i];
		int iidx, eidx;

		iidx = get_connection_index(codec, cap, spec->int_mic.pin);
		if (iidx < 0)
			continue;
		eidx = get_connection_index(codec, cap, spec->ext_mic.pin);
		if (eidx < 0)
			continue;
		spec->int_mic.mux_idx = iidx;
		spec->ext_mic.mux_idx = eidx;
		if (spec->capsrc_nids)
			spec->capsrc_nids += i;
		spec->adc_nids += i;
		spec->num_adc_nids = 1;
		return;
	}
	snd_printd(KERN_INFO "hda_codec: %s: "
		   "No ADC/MUX containing both 0x%x and 0x%x pins\n",
		   codec->chip_name, spec->int_mic.pin, spec->ext_mic.pin);
	spec->auto_mic = 0; /* disable auto-mic to be sure */
}

4919 4920 4921 4922
/* choose the ADC/MUX containing the input pin and initialize the setup */
static void fixup_single_adc(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
4923
	hda_nid_t pin = 0;
4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961
	int i;

	/* search for the input pin; there must be only one */
	for (i = 0; i < AUTO_PIN_LAST; i++) {
		if (spec->autocfg.input_pins[i]) {
			pin = spec->autocfg.input_pins[i];
			break;
		}
	}
	if (!pin)
		return;

	/* set the default connection to that pin */
	for (i = 0; i < spec->num_adc_nids; i++) {
		hda_nid_t cap = spec->capsrc_nids ?
			spec->capsrc_nids[i] : spec->adc_nids[i];
		int idx;

		idx = get_connection_index(codec, cap, pin);
		if (idx < 0)
			continue;
		/* use only this ADC */
		if (spec->capsrc_nids)
			spec->capsrc_nids += i;
		spec->adc_nids += i;
		spec->num_adc_nids = 1;
		/* select or unmute this route */
		if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
			snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
						 HDA_AMP_MUTE, 0);
		} else {
			snd_hda_codec_write_cache(codec, cap, 0,
					  AC_VERB_SET_CONNECT_SEL, idx);
		}
		return;
	}
}

4962
static void set_capture_mixer(struct hda_codec *codec)
4963
{
4964
	struct alc_spec *spec = codec->spec;
4965 4966 4967 4968 4969 4970 4971
	static struct snd_kcontrol_new *caps[2][3] = {
		{ alc_capture_mixer_nosrc1,
		  alc_capture_mixer_nosrc2,
		  alc_capture_mixer_nosrc3 },
		{ alc_capture_mixer1,
		  alc_capture_mixer2,
		  alc_capture_mixer3 },
4972
	};
4973
	if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4974 4975
		int mux = 0;
		if (spec->auto_mic)
4976
			fixup_automic_adc(codec);
4977 4978 4979 4980 4981 4982
		else if (spec->input_mux) {
			if (spec->input_mux->num_items > 1)
				mux = 1;
			else if (spec->input_mux->num_items == 1)
				fixup_single_adc(codec);
		}
4983 4984
		spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
	}
4985 4986
}

4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049
/* fill adc_nids (and capsrc_nids) containing all active input pins */
static void fillup_priv_adc_nids(struct hda_codec *codec, hda_nid_t *nids,
				 int num_nids)
{
	struct alc_spec *spec = codec->spec;
	int n;
	hda_nid_t fallback_adc = 0, fallback_cap = 0;

	for (n = 0; n < num_nids; n++) {
		hda_nid_t adc, cap;
		hda_nid_t conn[HDA_MAX_NUM_INPUTS];
		int nconns, i, j;

		adc = nids[n];
		if (get_wcaps_type(get_wcaps(codec, adc)) != AC_WID_AUD_IN)
			continue;
		cap = adc;
		nconns = snd_hda_get_connections(codec, cap, conn,
						 ARRAY_SIZE(conn));
		if (nconns == 1) {
			cap = conn[0];
			nconns = snd_hda_get_connections(codec, cap, conn,
							 ARRAY_SIZE(conn));
		}
		if (nconns <= 0)
			continue;
		if (!fallback_adc) {
			fallback_adc = adc;
			fallback_cap = cap;
		}
		for (i = 0; i < AUTO_PIN_LAST; i++) {
			hda_nid_t nid = spec->autocfg.input_pins[i];
			if (!nid)
				continue;
			for (j = 0; j < nconns; j++) {
				if (conn[j] == nid)
					break;
			}
			if (j >= nconns)
				break;
		}
		if (i >= AUTO_PIN_LAST) {
			int num_adcs = spec->num_adc_nids;
			spec->private_adc_nids[num_adcs] = adc;
			spec->private_capsrc_nids[num_adcs] = cap;
			spec->num_adc_nids++;
			spec->adc_nids = spec->private_adc_nids;
			if (adc != cap)
				spec->capsrc_nids = spec->private_capsrc_nids;
		}
	}
	if (!spec->num_adc_nids) {
		printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
		       " using fallback 0x%x\n", fallback_adc);
		spec->private_adc_nids[0] = fallback_adc;
		spec->adc_nids = spec->private_adc_nids;
		if (fallback_adc != fallback_cap) {
			spec->private_capsrc_nids[0] = fallback_cap;
			spec->capsrc_nids = spec->private_adc_nids;
		}
	}
}

5050
#ifdef CONFIG_SND_HDA_INPUT_BEEP
5051 5052
#define set_beep_amp(spec, nid, idx, dir) \
	((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
5053 5054 5055
#else
#define set_beep_amp(spec, nid, idx, dir) /* NOP */
#endif
5056 5057 5058 5059 5060

/*
 * OK, here we have finally the patch for ALC880
 */

L
Linus Torvalds 已提交
5061 5062 5063 5064
static int patch_alc880(struct hda_codec *codec)
{
	struct alc_spec *spec;
	int board_config;
5065
	int err;
L
Linus Torvalds 已提交
5066

5067
	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
L
Linus Torvalds 已提交
5068 5069 5070 5071 5072
	if (spec == NULL)
		return -ENOMEM;

	codec->spec = spec;

5073 5074 5075 5076
	board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
						  alc880_models,
						  alc880_cfg_tbl);
	if (board_config < 0) {
5077 5078
		printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
		       codec->chip_name);
5079
		board_config = ALC880_AUTO;
L
Linus Torvalds 已提交
5080 5081
	}

5082 5083 5084 5085 5086 5087
	if (board_config == ALC880_AUTO) {
		/* automatic parse from the BIOS config */
		err = alc880_parse_auto_config(codec);
		if (err < 0) {
			alc_free(codec);
			return err;
5088
		} else if (!err) {
5089 5090 5091
			printk(KERN_INFO
			       "hda_codec: Cannot set up configuration "
			       "from BIOS.  Using 3-stack mode...\n");
5092 5093
			board_config = ALC880_3ST;
		}
L
Linus Torvalds 已提交
5094 5095
	}

5096 5097 5098 5099 5100 5101
	err = snd_hda_attach_beep_device(codec, 0x1);
	if (err < 0) {
		alc_free(codec);
		return err;
	}

5102
	if (board_config != ALC880_AUTO)
5103
		setup_preset(codec, &alc880_presets[board_config]);
L
Linus Torvalds 已提交
5104 5105 5106

	spec->stream_analog_playback = &alc880_pcm_analog_playback;
	spec->stream_analog_capture = &alc880_pcm_analog_capture;
5107
	spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
L
Linus Torvalds 已提交
5108 5109 5110 5111

	spec->stream_digital_playback = &alc880_pcm_digital_playback;
	spec->stream_digital_capture = &alc880_pcm_digital_capture;

5112
	if (!spec->adc_nids && spec->input_mux) {
5113
		/* check whether NID 0x07 is valid */
5114
		unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
5115
		/* get type */
5116
		wcap = get_wcaps_type(wcap);
5117 5118 5119 5120 5121 5122 5123 5124
		if (wcap != AC_WID_AUD_IN) {
			spec->adc_nids = alc880_adc_nids_alt;
			spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
		} else {
			spec->adc_nids = alc880_adc_nids;
			spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
		}
	}
5125
	set_capture_mixer(codec);
5126
	set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
L
Linus Torvalds 已提交
5127

5128 5129
	spec->vmaster_nid = 0x0c;

L
Linus Torvalds 已提交
5130
	codec->patch_ops = alc_patch_ops;
5131
	if (board_config == ALC880_AUTO)
5132
		spec->init_hook = alc880_auto_init;
5133 5134 5135 5136
#ifdef CONFIG_SND_HDA_POWER_SAVE
	if (!spec->loopback.amplist)
		spec->loopback.amplist = alc880_loopbacks;
#endif
L
Linus Torvalds 已提交
5137 5138 5139 5140

	return 0;
}

5141

L
Linus Torvalds 已提交
5142 5143 5144 5145
/*
 * ALC260 support
 */

5146 5147 5148 5149 5150 5151 5152 5153 5154 5155
static hda_nid_t alc260_dac_nids[1] = {
	/* front */
	0x02,
};

static hda_nid_t alc260_adc_nids[1] = {
	/* ADC0 */
	0x04,
};

5156
static hda_nid_t alc260_adc_nids_alt[1] = {
5157 5158 5159 5160
	/* ADC1 */
	0x05,
};

5161 5162 5163 5164
/* NIDs used when simultaneous access to both ADCs makes sense.  Note that
 * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
 */
static hda_nid_t alc260_dual_adc_nids[2] = {
5165 5166 5167 5168
	/* ADC0, ADC1 */
	0x04, 0x05
};

5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181
#define ALC260_DIGOUT_NID	0x03
#define ALC260_DIGIN_NID	0x06

static struct hda_input_mux alc260_capture_source = {
	.num_items = 4,
	.items = {
		{ "Mic", 0x0 },
		{ "Front Mic", 0x1 },
		{ "Line", 0x2 },
		{ "CD", 0x4 },
	},
};

5182
/* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
5183 5184 5185 5186
 * headphone jack and the internal CD lines since these are the only pins at
 * which audio can appear.  For flexibility, also allow the option of
 * recording the mixer output on the second ADC (ADC0 doesn't have a
 * connection to the mixer output).
5187
 */
5188 5189 5190 5191 5192 5193 5194 5195
static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
	{
		.num_items = 3,
		.items = {
			{ "Mic/Line", 0x0 },
			{ "CD", 0x4 },
			{ "Headphone", 0x2 },
		},
5196
	},
5197 5198 5199 5200 5201 5202 5203 5204 5205 5206
	{
		.num_items = 4,
		.items = {
			{ "Mic/Line", 0x0 },
			{ "CD", 0x4 },
			{ "Headphone", 0x2 },
			{ "Mixer", 0x5 },
		},
	},

5207 5208
};

5209 5210
/* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
 * the Fujitsu S702x, but jacks are marked differently.
5211
 */
5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230
static struct hda_input_mux alc260_acer_capture_sources[2] = {
	{
		.num_items = 4,
		.items = {
			{ "Mic", 0x0 },
			{ "Line", 0x2 },
			{ "CD", 0x4 },
			{ "Headphone", 0x5 },
		},
	},
	{
		.num_items = 5,
		.items = {
			{ "Mic", 0x0 },
			{ "Line", 0x2 },
			{ "CD", 0x4 },
			{ "Headphone", 0x6 },
			{ "Mixer", 0x5 },
		},
5231 5232
	},
};
5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252

/* Maxdata Favorit 100XS */
static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
	{
		.num_items = 2,
		.items = {
			{ "Line/Mic", 0x0 },
			{ "CD", 0x4 },
		},
	},
	{
		.num_items = 3,
		.items = {
			{ "Line/Mic", 0x0 },
			{ "CD", 0x4 },
			{ "Mixer", 0x5 },
		},
	},
};

L
Linus Torvalds 已提交
5253 5254 5255 5256 5257 5258
/*
 * This is just place-holder, so there's something for alc_build_pcms to look
 * at when it calculates the maximum number of channels. ALC260 has no mixer
 * element which allows changing the channel mode, so the verb list is
 * never used.
 */
5259
static struct hda_channel_mode alc260_modes[1] = {
L
Linus Torvalds 已提交
5260 5261 5262
	{ 2, NULL },
};

5263 5264 5265 5266 5267 5268 5269

/* Mixer combinations
 *
 * basic: base_output + input + pc_beep + capture
 * HP: base_output + input + capture_alt
 * HP_3013: hp_3013 + input + capture
 * fujitsu: fujitsu + capture
5270
 * acer: acer + capture
5271 5272 5273
 */

static struct snd_kcontrol_new alc260_base_output_mixer[] = {
5274
	HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
5275
	HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5276
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
5277
	HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5278
	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
5279
	HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
L
Linus Torvalds 已提交
5280
	{ } /* end */
5281
};
L
Linus Torvalds 已提交
5282

5283
static struct snd_kcontrol_new alc260_input_mixer[] = {
5284 5285 5286 5287 5288 5289 5290 5291
	HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
5292 5293 5294
	{ } /* end */
};

5295 5296 5297 5298 5299 5300 5301 5302
/* update HP, line and mono out pins according to the master switch */
static void alc260_hp_master_update(struct hda_codec *codec,
				    hda_nid_t hp, hda_nid_t line,
				    hda_nid_t mono)
{
	struct alc_spec *spec = codec->spec;
	unsigned int val = spec->master_sw ? PIN_HP : 0;
	/* change HP and line-out pins */
5303
	snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5304
			    val);
5305
	snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5306 5307 5308
			    val);
	/* mono (speaker) depending on the HP jack sense */
	val = (val && !spec->jack_present) ? PIN_OUT : 0;
5309
	snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343
			    val);
}

static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
				   struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct alc_spec *spec = codec->spec;
	*ucontrol->value.integer.value = spec->master_sw;
	return 0;
}

static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
				   struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct alc_spec *spec = codec->spec;
	int val = !!*ucontrol->value.integer.value;
	hda_nid_t hp, line, mono;

	if (val == spec->master_sw)
		return 0;
	spec->master_sw = val;
	hp = (kcontrol->private_value >> 16) & 0xff;
	line = (kcontrol->private_value >> 8) & 0xff;
	mono = kcontrol->private_value & 0xff;
	alc260_hp_master_update(codec, hp, line, mono);
	return 1;
}

static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Master Playback Switch",
5344
		.subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368
		.info = snd_ctl_boolean_mono_info,
		.get = alc260_hp_master_sw_get,
		.put = alc260_hp_master_sw_put,
		.private_value = (0x0f << 16) | (0x10 << 8) | 0x11
	},
	HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
	HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
			      HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
	{ } /* end */
};

static struct hda_verb alc260_hp_unsol_verbs[] = {
	{0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{},
};

static void alc260_hp_automute(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;

5369
	spec->jack_present = snd_hda_jack_detect(codec, 0x10);
5370 5371 5372 5373 5374 5375 5376 5377 5378
	alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
}

static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
{
	if ((res >> 26) == ALC880_HP_EVENT)
		alc260_hp_automute(codec);
}

5379
static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
5380 5381 5382
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Master Playback Switch",
5383
		.subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
5384 5385 5386
		.info = snd_ctl_boolean_mono_info,
		.get = alc260_hp_master_sw_get,
		.put = alc260_hp_master_sw_put,
5387
		.private_value = (0x15 << 16) | (0x10 << 8) | 0x11
5388
	},
5389 5390 5391 5392 5393 5394
	HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
	HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5395 5396
	HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
5397 5398 5399
	{ } /* end */
};

5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426
static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
	.ops = &snd_hda_bind_vol,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
		0
	},
};

static struct hda_bind_ctls alc260_dc7600_bind_switch = {
	.ops = &snd_hda_bind_sw,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
		0
	},
};

static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
	HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
	HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
	HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
	{ } /* end */
};

5427 5428 5429 5430 5431 5432 5433 5434 5435
static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{},
};

static void alc260_hp_3013_automute(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;

5436
	spec->jack_present = snd_hda_jack_detect(codec, 0x15);
5437
	alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
5438 5439 5440 5441 5442 5443 5444 5445 5446
}

static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
				       unsigned int res)
{
	if ((res >> 26) == ALC880_HP_EVENT)
		alc260_hp_3013_automute(codec);
}

5447 5448
static void alc260_hp_3012_automute(struct hda_codec *codec)
{
5449
	unsigned int bits = snd_hda_jack_detect(codec, 0x10) ? 0 : PIN_OUT;
5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466

	snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
			    bits);
	snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
			    bits);
	snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
			    bits);
}

static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
				       unsigned int res)
{
	if ((res >> 26) == ALC880_HP_EVENT)
		alc260_hp_3012_automute(codec);
}

/* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
5467 5468
 * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
 */
5469
static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
5470
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
5471
	HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
5472
	ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5473 5474 5475 5476
	HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
5477
	ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
5478 5479
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
5480 5481 5482
	{ } /* end */
};

5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499
/* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
 * versions of the ALC260 don't act on requests to enable mic bias from NID
 * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
 * datasheet doesn't mention this restriction.  At this stage it's not clear
 * whether this behaviour is intentional or is a hardware bug in chip
 * revisions available in early 2006.  Therefore for now allow the
 * "Headphone Jack Mode" control to span all choices, but if it turns out
 * that the lack of mic bias for this NID is intentional we could change the
 * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
 *
 * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
 * don't appear to make the mic bias available from the "line" jack, even
 * though the NID used for this jack (0x14) can supply it.  The theory is
 * that perhaps Acer have included blocking capacitors between the ALC260
 * and the output jack.  If this turns out to be the case for all such
 * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
 * to ALC_PIN_DIR_INOUT_NOMICBIAS.
5500 5501 5502 5503 5504
 *
 * The C20x Tablet series have a mono internal speaker which is controlled
 * via the chip's Mono sum widget and pin complex, so include the necessary
 * controls for such models.  On models without a "mono speaker" the control
 * won't do anything.
5505
 */
5506 5507 5508
static struct snd_kcontrol_new alc260_acer_mixer[] = {
	HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5509
	ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5510
	HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5511
			      HDA_OUTPUT),
5512
	HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
5513
			   HDA_INPUT),
5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524
	HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
	ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
	ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
	{ } /* end */
};

5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536
/* Maxdata Favorit 100XS: one output and one input (0x12) jack
 */
static struct snd_kcontrol_new alc260_favorit100_mixer[] = {
	HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
	ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
	HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
	ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
	{ } /* end */
};

5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570
/* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
 * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
 */
static struct snd_kcontrol_new alc260_will_mixer[] = {
	HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
	ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
	ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
	{ } /* end */
};

/* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
 * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
 */
static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
	HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
	ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
	HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
	ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
	{ } /* end */
};

5571 5572 5573
/*
 * initialization verbs
 */
L
Linus Torvalds 已提交
5574 5575
static struct hda_verb alc260_init_verbs[] = {
	/* Line In pin widget for input */
5576
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
L
Linus Torvalds 已提交
5577
	/* CD pin widget for input */
5578
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
L
Linus Torvalds 已提交
5579
	/* Mic1 (rear panel) pin widget for input and vref at 80% */
5580
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
L
Linus Torvalds 已提交
5581
	/* Mic2 (front panel) pin widget for input and vref at 80% */
5582
	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
L
Linus Torvalds 已提交
5583
	/* LINE-2 is used for line-out in rear */
5584
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
L
Linus Torvalds 已提交
5585
	/* select line-out */
5586
	{0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
L
Linus Torvalds 已提交
5587
	/* LINE-OUT pin */
5588
	{0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
L
Linus Torvalds 已提交
5589
	/* enable HP */
5590
	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
L
Linus Torvalds 已提交
5591
	/* enable Mono */
5592 5593
	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	/* mute capture amp left and right */
5594
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
L
Linus Torvalds 已提交
5595 5596
	/* set connection select to line in (default select for this ADC) */
	{0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5597 5598 5599 5600
	/* mute capture amp left and right */
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	/* set connection select to line in (default select for this ADC) */
	{0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614
	/* set vol=0 Line-Out mixer amp left and right */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	/* unmute pin widget amp left and right (no gain on this amp) */
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* set vol=0 HP mixer amp left and right */
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	/* unmute pin widget amp left and right (no gain on this amp) */
	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* set vol=0 Mono mixer amp left and right */
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	/* unmute pin widget amp left and right (no gain on this amp) */
	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* unmute LINE-2 out pin */
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5615 5616 5617
	/* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
	 * Line In 2 = 0x03
	 */
5618 5619 5620 5621 5622 5623
	/* mute analog inputs */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
L
Linus Torvalds 已提交
5624
	/* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5625 5626 5627 5628 5629 5630 5631 5632 5633
	/* mute Front out path */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	/* mute Headphone out path */
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	/* mute Mono out path */
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
L
Linus Torvalds 已提交
5634 5635 5636
	{ }
};

5637
#if 0 /* should be identical with alc260_init_verbs? */
5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664
static struct hda_verb alc260_hp_init_verbs[] = {
	/* Headphone and output */
	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
	/* mono output */
	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
	/* Mic1 (rear panel) pin widget for input and vref at 80% */
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
	/* Mic2 (front panel) pin widget for input and vref at 80% */
	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
	/* Line In pin widget for input */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
	/* Line-2 pin widget for output */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
	/* CD pin widget for input */
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
	/* unmute amp left and right */
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
	/* set connection select to line in (default select for this ADC) */
	{0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
	/* unmute Line-Out mixer amp left and right (volume = 0) */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
	/* mute pin widget amp left and right (no gain on this amp) */
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
	/* unmute HP mixer amp left and right (volume = 0) */
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
	/* mute pin widget amp left and right (no gain on this amp) */
	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5665 5666 5667
	/* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
	 * Line In 2 = 0x03
	 */
5668 5669 5670 5671 5672 5673
	/* mute analog inputs */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685
	/* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
	/* Unmute Front out path */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
	/* Unmute Headphone out path */
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
	/* Unmute Mono out path */
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
	{ }
};
5686
#endif
5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714

static struct hda_verb alc260_hp_3013_init_verbs[] = {
	/* Line out and output */
	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
	/* mono output */
	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
	/* Mic1 (rear panel) pin widget for input and vref at 80% */
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
	/* Mic2 (front panel) pin widget for input and vref at 80% */
	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
	/* Line In pin widget for input */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
	/* Headphone pin widget for output */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
	/* CD pin widget for input */
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
	/* unmute amp left and right */
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
	/* set connection select to line in (default select for this ADC) */
	{0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
	/* unmute Line-Out mixer amp left and right (volume = 0) */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
	/* mute pin widget amp left and right (no gain on this amp) */
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
	/* unmute HP mixer amp left and right (volume = 0) */
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
	/* mute pin widget amp left and right (no gain on this amp) */
	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5715 5716 5717
	/* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
	 * Line In 2 = 0x03
	 */
5718 5719 5720 5721 5722 5723
	/* mute analog inputs */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736
	/* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
	/* Unmute Front out path */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
	/* Unmute Headphone out path */
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
	/* Unmute Mono out path */
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
	{ }
};

5737
/* Initialisation sequence for ALC260 as configured in Fujitsu S702x
5738 5739
 * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
 * audio = 0x16, internal speaker = 0x10.
5740 5741 5742 5743 5744 5745 5746 5747
 */
static struct hda_verb alc260_fujitsu_init_verbs[] = {
	/* Disable all GPIOs */
	{0x01, AC_VERB_SET_GPIO_MASK, 0},
	/* Internal speaker is connected to headphone pin */
	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	/* Headphone/Line-out jack connects to Line1 pin; make it an output */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5748 5749 5750 5751 5752
	/* Mic/Line-in jack is connected to mic1 pin, so make it an input */
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	/* Ensure all other unused pins are disabled and muted. */
	{0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5753
	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5754
	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5755
	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5756 5757 5758 5759 5760 5761 5762
	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},

	/* Disable digital (SPDIF) pins */
	{0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
	{0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5763

5764
	/* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5765 5766 5767
	 * when acting as an output.
	 */
	{0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5768

5769
	/* Start with output sum widgets muted and their output gains at min */
5770 5771 5772 5773 5774 5775 5776 5777 5778
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5779

5780 5781 5782 5783 5784 5785 5786
	/* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* Unmute Line1 pin widget output buffer since it starts as an output.
	 * If the pin mode is changed by the user the pin mode control will
	 * take care of enabling the pin's input/output buffers as needed.
	 * Therefore there's no need to enable the input buffer at this
	 * stage.
5787
	 */
5788
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5789
	/* Unmute input buffer of pin widget used for Line-in (no equiv
5790 5791
	 * mixer ctrl)
	 */
5792 5793 5794 5795
	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},

	/* Mute capture amp left and right */
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5796
	/* Set ADC connection select to match default mixer setting - line
5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815
	 * in (on mic1 pin)
	 */
	{0x04, AC_VERB_SET_CONNECT_SEL, 0x00},

	/* Do the same for the second ADC: mute capture input amp and
	 * set ADC connection to line in (on mic1 pin)
	 */
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x05, AC_VERB_SET_CONNECT_SEL, 0x00},

	/* Mute all inputs to mixer widget (even unconnected ones) */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5816 5817

	{ }
5818 5819
};

5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836
/* Initialisation sequence for ALC260 as configured in Acer TravelMate and
 * similar laptops (adapted from Fujitsu init verbs).
 */
static struct hda_verb alc260_acer_init_verbs[] = {
	/* On TravelMate laptops, GPIO 0 enables the internal speaker and
	 * the headphone jack.  Turn this on and rely on the standard mute
	 * methods whenever the user wants to turn these outputs off.
	 */
	{0x01, AC_VERB_SET_GPIO_MASK, 0x01},
	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
	{0x01, AC_VERB_SET_GPIO_DATA, 0x01},
	/* Internal speaker/Headphone jack is connected to Line-out pin */
	{0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	/* Internal microphone/Mic jack is connected to Mic1 pin */
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
	/* Line In jack is connected to Line1 pin */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5837 5838
	/* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849
	/* Ensure all other unused pins are disabled and muted. */
	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	/* Disable digital (SPDIF) pins */
	{0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
	{0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},

5850
	/* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866
	 * bus when acting as outputs.
	 */
	{0x0b, AC_VERB_SET_CONNECT_SEL, 0},
	{0x0d, AC_VERB_SET_CONNECT_SEL, 0},

	/* Start with output sum widgets muted and their output gains at min */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},

5867 5868 5869
	/* Unmute Line-out pin widget amp left and right
	 * (no equiv mixer ctrl)
	 */
5870
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5871 5872
	/* Unmute mono pin widget amp output (no equiv mixer ctrl) */
	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889
	/* Unmute Mic1 and Line1 pin widget input buffers since they start as
	 * inputs. If the pin mode is changed by the user the pin mode control
	 * will take care of enabling the pin's input/output buffers as needed.
	 * Therefore there's no need to enable the input buffer at this
	 * stage.
	 */
	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},

	/* Mute capture amp left and right */
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	/* Set ADC connection select to match default mixer setting - mic
	 * (on mic1 pin)
	 */
	{0x04, AC_VERB_SET_CONNECT_SEL, 0x00},

	/* Do similar with the second ADC: mute capture input amp and
5890
	 * set ADC connection to mic to match ALSA's default state.
5891 5892
	 */
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5893
	{0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907

	/* Mute all inputs to mixer widget (even unconnected ones) */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */

	{ }
};

5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990
/* Initialisation sequence for Maxdata Favorit 100XS
 * (adapted from Acer init verbs).
 */
static struct hda_verb alc260_favorit100_init_verbs[] = {
	/* GPIO 0 enables the output jack.
	 * Turn this on and rely on the standard mute
	 * methods whenever the user wants to turn these outputs off.
	 */
	{0x01, AC_VERB_SET_GPIO_MASK, 0x01},
	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
	{0x01, AC_VERB_SET_GPIO_DATA, 0x01},
	/* Line/Mic input jack is connected to Mic1 pin */
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
	/* Ensure all other unused pins are disabled and muted. */
	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	/* Disable digital (SPDIF) pins */
	{0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
	{0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},

	/* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
	 * bus when acting as outputs.
	 */
	{0x0b, AC_VERB_SET_CONNECT_SEL, 0},
	{0x0d, AC_VERB_SET_CONNECT_SEL, 0},

	/* Start with output sum widgets muted and their output gains at min */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},

	/* Unmute Line-out pin widget amp left and right
	 * (no equiv mixer ctrl)
	 */
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* Unmute Mic1 and Line1 pin widget input buffers since they start as
	 * inputs. If the pin mode is changed by the user the pin mode control
	 * will take care of enabling the pin's input/output buffers as needed.
	 * Therefore there's no need to enable the input buffer at this
	 * stage.
	 */
	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},

	/* Mute capture amp left and right */
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	/* Set ADC connection select to match default mixer setting - mic
	 * (on mic1 pin)
	 */
	{0x04, AC_VERB_SET_CONNECT_SEL, 0x00},

	/* Do similar with the second ADC: mute capture input amp and
	 * set ADC connection to mic to match ALSA's default state.
	 */
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x05, AC_VERB_SET_CONNECT_SEL, 0x00},

	/* Mute all inputs to mixer widget (even unconnected ones) */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */

	{ }
};

5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019
static struct hda_verb alc260_will_verbs[] = {
	{0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
	{0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
	{0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
	{}
};

static struct hda_verb alc260_replacer_672v_verbs[] = {
	{0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
	{0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
	{0x1a, AC_VERB_SET_PROC_COEF, 0x3050},

	{0x01, AC_VERB_SET_GPIO_MASK, 0x01},
	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
	{0x01, AC_VERB_SET_GPIO_DATA, 0x00},

	{0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

/* toggle speaker-output according to the hp-jack state */
static void alc260_replacer_672v_automute(struct hda_codec *codec)
{
        unsigned int present;

	/* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
6020
	present = snd_hda_jack_detect(codec, 0x0f);
6021
	if (present) {
6022 6023 6024 6025 6026
		snd_hda_codec_write_cache(codec, 0x01, 0,
					  AC_VERB_SET_GPIO_DATA, 1);
		snd_hda_codec_write_cache(codec, 0x0f, 0,
					  AC_VERB_SET_PIN_WIDGET_CONTROL,
					  PIN_HP);
6027
	} else {
6028 6029 6030 6031 6032
		snd_hda_codec_write_cache(codec, 0x01, 0,
					  AC_VERB_SET_GPIO_DATA, 0);
		snd_hda_codec_write_cache(codec, 0x0f, 0,
					  AC_VERB_SET_PIN_WIDGET_CONTROL,
					  PIN_OUT);
6033 6034 6035 6036 6037 6038 6039 6040 6041 6042
	}
}

static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
                                       unsigned int res)
{
        if ((res >> 26) == ALC880_HP_EVENT)
                alc260_replacer_672v_automute(codec);
}

6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056
static struct hda_verb alc260_hp_dc7600_verbs[] = {
	{0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

6057 6058 6059 6060 6061 6062 6063 6064 6065 6066
/* Test configuration for debugging, modelled after the ALC880 test
 * configuration.
 */
#ifdef CONFIG_SND_DEBUG
static hda_nid_t alc260_test_dac_nids[1] = {
	0x02,
};
static hda_nid_t alc260_test_adc_nids[2] = {
	0x04, 0x05,
};
6067
/* For testing the ALC260, each input MUX needs its own definition since
6068
 * the signal assignments are different.  This assumes that the first ADC
6069
 * is NID 0x04.
6070
 */
6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095
static struct hda_input_mux alc260_test_capture_sources[2] = {
	{
		.num_items = 7,
		.items = {
			{ "MIC1 pin", 0x0 },
			{ "MIC2 pin", 0x1 },
			{ "LINE1 pin", 0x2 },
			{ "LINE2 pin", 0x3 },
			{ "CD pin", 0x4 },
			{ "LINE-OUT pin", 0x5 },
			{ "HP-OUT pin", 0x6 },
		},
        },
	{
		.num_items = 8,
		.items = {
			{ "MIC1 pin", 0x0 },
			{ "MIC2 pin", 0x1 },
			{ "LINE1 pin", 0x2 },
			{ "LINE2 pin", 0x3 },
			{ "CD pin", 0x4 },
			{ "Mixer", 0x5 },
			{ "LINE-OUT pin", 0x6 },
			{ "HP-OUT pin", 0x7 },
		},
6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106
        },
};
static struct snd_kcontrol_new alc260_test_mixer[] = {
	/* Output driver widgets */
	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),

6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117
	/* Modes for retasking pin widgets
	 * Note: the ALC260 doesn't seem to act on requests to enable mic
         * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
         * mention this restriction.  At this stage it's not clear whether
         * this behaviour is intentional or is a hardware bug in chip
         * revisions available at least up until early 2006.  Therefore for
         * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
         * choices, but if it turns out that the lack of mic bias for these
         * NIDs is intentional we could change their modes from
         * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
	 */
6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139
	ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
	ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
	ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
	ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
	ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
	ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),

	/* Loopback mixer controls */
	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
	HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
	HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
	HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
	HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
	HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
6140 6141 6142 6143 6144 6145 6146

	/* Controls for GPIO pins, assuming they are configured as outputs */
	ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
	ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
	ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
	ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),

6147 6148
	/* Switches to allow the digital IO pins to be enabled.  The datasheet
	 * is ambigious as to which NID is which; testing on laptops which
6149
	 * make this output available should provide clarification.
6150 6151 6152 6153
	 */
	ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
	ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),

6154 6155 6156 6157 6158 6159
	/* A switch allowing EAPD to be enabled.  Some laptops seem to use
	 * this output to turn on an external amplifier.
	 */
	ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
	ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),

6160 6161 6162
	{ } /* end */
};
static struct hda_verb alc260_test_init_verbs[] = {
6163 6164 6165 6166 6167
	/* Enable all GPIOs as outputs with an initial value of 0 */
	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
	{0x01, AC_VERB_SET_GPIO_DATA, 0x00},
	{0x01, AC_VERB_SET_GPIO_MASK, 0x0f},

6168 6169 6170 6171 6172 6173 6174 6175
	/* Enable retasking pins as output, initially without power amp */
	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},

6176 6177 6178 6179 6180 6181
	/* Disable digital (SPDIF) pins initially, but users can enable
	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
	 * payload also sets the generation to 0, output to be in "consumer"
	 * PCM format, copyright asserted, no pre-emphasis and no validity
	 * control.
	 */
6182 6183 6184
	{0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
	{0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},

6185
	/* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203
	 * OUT1 sum bus when acting as an output.
	 */
	{0x0b, AC_VERB_SET_CONNECT_SEL, 0},
	{0x0c, AC_VERB_SET_CONNECT_SEL, 0},
	{0x0d, AC_VERB_SET_CONNECT_SEL, 0},
	{0x0e, AC_VERB_SET_CONNECT_SEL, 0},

	/* Start with output sum widgets muted and their output gains at min */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},

6204 6205 6206 6207 6208
	/* Unmute retasking pin widget output buffers since the default
	 * state appears to be output.  As the pin mode is changed by the
	 * user the pin mode control will take care of enabling the pin's
	 * input/output buffers as needed.
	 */
6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219
	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* Also unmute the mono-out pin widget */
	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},

	/* Mute capture amp left and right */
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6220 6221
	/* Set ADC connection select to match default mixer setting (mic1
	 * pin)
6222 6223 6224 6225
	 */
	{0x04, AC_VERB_SET_CONNECT_SEL, 0x00},

	/* Do the same for the second ADC: mute capture input amp and
6226
	 * set ADC connection to mic1 pin
6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244
	 */
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x05, AC_VERB_SET_CONNECT_SEL, 0x00},

	/* Mute all inputs to mixer widget (even unconnected ones) */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */

	{ }
};
#endif

6245 6246
#define alc260_pcm_analog_playback	alc880_pcm_analog_alt_playback
#define alc260_pcm_analog_capture	alc880_pcm_analog_capture
L
Linus Torvalds 已提交
6247

6248 6249 6250
#define alc260_pcm_digital_playback	alc880_pcm_digital_playback
#define alc260_pcm_digital_capture	alc880_pcm_digital_capture

6251 6252 6253
/*
 * for BIOS auto-configuration
 */
6254

6255
static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
6256
					const char *pfx, int *vol_bits)
6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275
{
	hda_nid_t nid_vol;
	unsigned long vol_val, sw_val;
	int err;

	if (nid >= 0x0f && nid < 0x11) {
		nid_vol = nid - 0x7;
		vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
		sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
	} else if (nid == 0x11) {
		nid_vol = nid - 0x7;
		vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
		sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
	} else if (nid >= 0x12 && nid <= 0x15) {
		nid_vol = 0x08;
		vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
		sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
	} else
		return 0; /* N/A */
6276

6277 6278
	if (!(*vol_bits & (1 << nid_vol))) {
		/* first control for the volume widget */
6279
		err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, vol_val);
6280 6281 6282 6283
		if (err < 0)
			return err;
		*vol_bits |= (1 << nid_vol);
	}
6284
	err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, sw_val);
6285
	if (err < 0)
6286 6287 6288 6289 6290 6291 6292 6293 6294 6295
		return err;
	return 1;
}

/* add playback controls from the parsed DAC table */
static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
					     const struct auto_pin_cfg *cfg)
{
	hda_nid_t nid;
	int err;
6296
	int vols = 0;
6297 6298 6299 6300 6301 6302 6303

	spec->multiout.num_dacs = 1;
	spec->multiout.dac_nids = spec->private_dac_nids;
	spec->multiout.dac_nids[0] = 0x02;

	nid = cfg->line_out_pins[0];
	if (nid) {
6304 6305 6306 6307 6308 6309 6310 6311
		const char *pfx;
		if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
			pfx = "Master";
		else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
			pfx = "Speaker";
		else
			pfx = "Front";
		err = alc260_add_playback_controls(spec, nid, pfx, &vols);
6312 6313 6314 6315
		if (err < 0)
			return err;
	}

6316
	nid = cfg->speaker_pins[0];
6317
	if (nid) {
6318
		err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
6319 6320 6321 6322
		if (err < 0)
			return err;
	}

6323
	nid = cfg->hp_pins[0];
6324
	if (nid) {
6325 6326
		err = alc260_add_playback_controls(spec, nid, "Headphone",
						   &vols);
6327 6328 6329
		if (err < 0)
			return err;
	}
6330
	return 0;
6331 6332 6333
}

/* create playback/capture controls for input pins */
6334
static int alc260_auto_create_input_ctls(struct hda_codec *codec,
6335 6336
						const struct auto_pin_cfg *cfg)
{
6337
	return alc_auto_create_input_ctls(codec, cfg, 0x07, 0x04, 0x05);
6338 6339 6340 6341 6342 6343
}

static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
					      hda_nid_t nid, int pin_type,
					      int sel_idx)
{
6344
	alc_set_pin_output(codec, nid, pin_type);
6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357
	/* need the manual connection? */
	if (nid >= 0x12) {
		int idx = nid - 0x12;
		snd_hda_codec_write(codec, idx + 0x0b, 0,
				    AC_VERB_SET_CONNECT_SEL, sel_idx);
	}
}

static void alc260_auto_init_multi_out(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	hda_nid_t nid;

6358
	nid = spec->autocfg.line_out_pins[0];
6359 6360 6361 6362
	if (nid) {
		int pin_type = get_pin_type(spec->autocfg.line_out_type);
		alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
	}
6363

6364
	nid = spec->autocfg.speaker_pins[0];
6365 6366 6367
	if (nid)
		alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);

6368
	nid = spec->autocfg.hp_pins[0];
6369
	if (nid)
6370
		alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
6371
}
6372 6373 6374 6375 6376 6377 6378 6379 6380 6381

#define ALC260_PIN_CD_NID		0x16
static void alc260_auto_init_analog_input(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int i;

	for (i = 0; i < AUTO_PIN_LAST; i++) {
		hda_nid_t nid = spec->autocfg.input_pins[i];
		if (nid >= 0x12) {
6382
			alc_set_input_pin(codec, nid, i);
6383 6384
			if (nid != ALC260_PIN_CD_NID &&
			    (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
6385 6386
				snd_hda_codec_write(codec, nid, 0,
						    AC_VERB_SET_AMP_GAIN_MUTE,
6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402
						    AMP_OUT_MUTE);
		}
	}
}

/*
 * generic initialization of ADC, input mixers and output mixers
 */
static struct hda_verb alc260_volume_init_verbs[] = {
	/*
	 * Unmute ADC0-1 and set the default input to mic-in
	 */
	{0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6403

6404 6405
	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
	 * mixer widget
6406 6407
	 * Note: PASD motherboards uses the Line In 2 as the input for
	 * front panel mic (mic 2)
6408 6409
	 */
	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6410 6411 6412 6413 6414 6415
	/* mute analog inputs */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431

	/*
	 * Set up output mixers (0x08 - 0x0a)
	 */
	/* set vol=0 to output mixers */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	/* set up input amps for analog loopback */
	/* Amp Indices: DAC = 0, mixer = 1 */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6432

6433 6434 6435 6436 6437 6438 6439 6440 6441
	{ }
};

static int alc260_parse_auto_config(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int err;
	static hda_nid_t alc260_ignore[] = { 0x17, 0 };

6442 6443 6444
	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
					   alc260_ignore);
	if (err < 0)
6445
		return err;
6446 6447
	err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
	if (err < 0)
6448
		return err;
6449
	if (!spec->kctls.list)
6450
		return 0; /* can't find valid BIOS pin config */
6451
	err = alc260_auto_create_input_ctls(codec, &spec->autocfg);
6452
	if (err < 0)
6453 6454 6455 6456
		return err;

	spec->multiout.max_channels = 2;

6457
	if (spec->autocfg.dig_outs)
6458
		spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
6459
	if (spec->kctls.list)
6460
		add_mixer(spec, spec->kctls.list);
6461

6462
	add_verb(spec, alc260_volume_init_verbs);
6463

6464
	spec->num_mux_defs = 1;
6465
	spec->input_mux = &spec->private_imux[0];
6466

6467
	alc_ssid_check(codec, 0x10, 0x15, 0x0f, 0);
6468

6469 6470 6471
	return 1;
}

6472 6473
/* additional initialization for auto-configuration model */
static void alc260_auto_init(struct hda_codec *codec)
6474
{
6475
	struct alc_spec *spec = codec->spec;
6476 6477
	alc260_auto_init_multi_out(codec);
	alc260_auto_init_analog_input(codec);
6478
	if (spec->unsol_event)
6479
		alc_inithook(codec);
6480 6481
}

6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492
#ifdef CONFIG_SND_HDA_POWER_SAVE
static struct hda_amp_list alc260_loopbacks[] = {
	{ 0x07, HDA_INPUT, 0 },
	{ 0x07, HDA_INPUT, 1 },
	{ 0x07, HDA_INPUT, 2 },
	{ 0x07, HDA_INPUT, 3 },
	{ 0x07, HDA_INPUT, 4 },
	{ } /* end */
};
#endif

6493 6494 6495
/*
 * ALC260 configurations
 */
6496 6497 6498 6499
static const char *alc260_models[ALC260_MODEL_LAST] = {
	[ALC260_BASIC]		= "basic",
	[ALC260_HP]		= "hp",
	[ALC260_HP_3013]	= "hp-3013",
6500
	[ALC260_HP_DC7600]	= "hp-dc7600",
6501 6502
	[ALC260_FUJITSU_S702X]	= "fujitsu",
	[ALC260_ACER]		= "acer",
6503 6504
	[ALC260_WILL]		= "will",
	[ALC260_REPLACER_672V]	= "replacer",
6505
	[ALC260_FAVORIT100]	= "favorit100",
6506
#ifdef CONFIG_SND_DEBUG
6507
	[ALC260_TEST]		= "test",
6508
#endif
6509 6510 6511 6512
	[ALC260_AUTO]		= "auto",
};

static struct snd_pci_quirk alc260_cfg_tbl[] = {
6513
	SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
6514
	SND_PCI_QUIRK(0x1025, 0x007f, "Acer", ALC260_WILL),
6515
	SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
6516
	SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
6517
	SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
6518
	SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_AUTO), /* no quirk */
6519
	SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
6520
	SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
6521
	SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
6522 6523 6524 6525 6526 6527 6528 6529 6530
	SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
	SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
	SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
	SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
	SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
	SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
	SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
	SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
	SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
6531
	SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
6532
	SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
6533 6534 6535 6536 6537 6538
	{}
};

static struct alc_config_preset alc260_presets[] = {
	[ALC260_BASIC] = {
		.mixers = { alc260_base_output_mixer,
6539
			    alc260_input_mixer },
6540 6541 6542
		.init_verbs = { alc260_init_verbs },
		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
		.dac_nids = alc260_dac_nids,
6543
		.num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6544
		.adc_nids = alc260_dual_adc_nids,
6545 6546 6547 6548 6549
		.num_channel_mode = ARRAY_SIZE(alc260_modes),
		.channel_mode = alc260_modes,
		.input_mux = &alc260_capture_source,
	},
	[ALC260_HP] = {
6550
		.mixers = { alc260_hp_output_mixer,
6551
			    alc260_input_mixer },
6552 6553
		.init_verbs = { alc260_init_verbs,
				alc260_hp_unsol_verbs },
6554 6555
		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
		.dac_nids = alc260_dac_nids,
6556 6557
		.num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
		.adc_nids = alc260_adc_nids_alt,
6558 6559 6560
		.num_channel_mode = ARRAY_SIZE(alc260_modes),
		.channel_mode = alc260_modes,
		.input_mux = &alc260_capture_source,
6561 6562
		.unsol_event = alc260_hp_unsol_event,
		.init_hook = alc260_hp_automute,
6563
	},
6564 6565
	[ALC260_HP_DC7600] = {
		.mixers = { alc260_hp_dc7600_mixer,
6566
			    alc260_input_mixer },
6567 6568 6569 6570
		.init_verbs = { alc260_init_verbs,
				alc260_hp_dc7600_verbs },
		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
		.dac_nids = alc260_dac_nids,
6571 6572
		.num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
		.adc_nids = alc260_adc_nids_alt,
6573 6574 6575 6576 6577 6578
		.num_channel_mode = ARRAY_SIZE(alc260_modes),
		.channel_mode = alc260_modes,
		.input_mux = &alc260_capture_source,
		.unsol_event = alc260_hp_3012_unsol_event,
		.init_hook = alc260_hp_3012_automute,
	},
6579 6580
	[ALC260_HP_3013] = {
		.mixers = { alc260_hp_3013_mixer,
6581
			    alc260_input_mixer },
6582 6583
		.init_verbs = { alc260_hp_3013_init_verbs,
				alc260_hp_3013_unsol_verbs },
6584 6585
		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
		.dac_nids = alc260_dac_nids,
6586 6587
		.num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
		.adc_nids = alc260_adc_nids_alt,
6588 6589 6590
		.num_channel_mode = ARRAY_SIZE(alc260_modes),
		.channel_mode = alc260_modes,
		.input_mux = &alc260_capture_source,
6591 6592
		.unsol_event = alc260_hp_3013_unsol_event,
		.init_hook = alc260_hp_3013_automute,
6593 6594
	},
	[ALC260_FUJITSU_S702X] = {
6595
		.mixers = { alc260_fujitsu_mixer },
6596 6597 6598
		.init_verbs = { alc260_fujitsu_init_verbs },
		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
		.dac_nids = alc260_dac_nids,
6599 6600
		.num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
		.adc_nids = alc260_dual_adc_nids,
6601 6602
		.num_channel_mode = ARRAY_SIZE(alc260_modes),
		.channel_mode = alc260_modes,
6603 6604
		.num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
		.input_mux = alc260_fujitsu_capture_sources,
6605
	},
6606
	[ALC260_ACER] = {
6607
		.mixers = { alc260_acer_mixer },
6608 6609 6610 6611 6612 6613 6614
		.init_verbs = { alc260_acer_init_verbs },
		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
		.dac_nids = alc260_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
		.adc_nids = alc260_dual_adc_nids,
		.num_channel_mode = ARRAY_SIZE(alc260_modes),
		.channel_mode = alc260_modes,
6615 6616
		.num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
		.input_mux = alc260_acer_capture_sources,
6617
	},
6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629
	[ALC260_FAVORIT100] = {
		.mixers = { alc260_favorit100_mixer },
		.init_verbs = { alc260_favorit100_init_verbs },
		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
		.dac_nids = alc260_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
		.adc_nids = alc260_dual_adc_nids,
		.num_channel_mode = ARRAY_SIZE(alc260_modes),
		.channel_mode = alc260_modes,
		.num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
		.input_mux = alc260_favorit100_capture_sources,
	},
6630
	[ALC260_WILL] = {
6631
		.mixers = { alc260_will_mixer },
6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642
		.init_verbs = { alc260_init_verbs, alc260_will_verbs },
		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
		.dac_nids = alc260_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
		.adc_nids = alc260_adc_nids,
		.dig_out_nid = ALC260_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc260_modes),
		.channel_mode = alc260_modes,
		.input_mux = &alc260_capture_source,
	},
	[ALC260_REPLACER_672V] = {
6643
		.mixers = { alc260_replacer_672v_mixer },
6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655
		.init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
		.num_dacs = ARRAY_SIZE(alc260_dac_nids),
		.dac_nids = alc260_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
		.adc_nids = alc260_adc_nids,
		.dig_out_nid = ALC260_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc260_modes),
		.channel_mode = alc260_modes,
		.input_mux = &alc260_capture_source,
		.unsol_event = alc260_replacer_672v_unsol_event,
		.init_hook = alc260_replacer_672v_automute,
	},
6656 6657
#ifdef CONFIG_SND_DEBUG
	[ALC260_TEST] = {
6658
		.mixers = { alc260_test_mixer },
6659 6660 6661 6662 6663 6664 6665
		.init_verbs = { alc260_test_init_verbs },
		.num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
		.dac_nids = alc260_test_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
		.adc_nids = alc260_test_adc_nids,
		.num_channel_mode = ARRAY_SIZE(alc260_modes),
		.channel_mode = alc260_modes,
6666 6667
		.num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
		.input_mux = alc260_test_capture_sources,
6668 6669
	},
#endif
6670 6671 6672
};

static int patch_alc260(struct hda_codec *codec)
L
Linus Torvalds 已提交
6673 6674
{
	struct alc_spec *spec;
6675
	int err, board_config;
L
Linus Torvalds 已提交
6676

6677
	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
L
Linus Torvalds 已提交
6678 6679 6680 6681 6682
	if (spec == NULL)
		return -ENOMEM;

	codec->spec = spec;

6683 6684 6685 6686
	board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
						  alc260_models,
						  alc260_cfg_tbl);
	if (board_config < 0) {
6687
		snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6688
			   codec->chip_name);
6689
		board_config = ALC260_AUTO;
6690
	}
L
Linus Torvalds 已提交
6691

6692 6693 6694 6695 6696 6697
	if (board_config == ALC260_AUTO) {
		/* automatic parse from the BIOS config */
		err = alc260_parse_auto_config(codec);
		if (err < 0) {
			alc_free(codec);
			return err;
6698
		} else if (!err) {
6699 6700 6701
			printk(KERN_INFO
			       "hda_codec: Cannot set up configuration "
			       "from BIOS.  Using base mode...\n");
6702 6703
			board_config = ALC260_BASIC;
		}
6704
	}
6705

6706 6707 6708 6709 6710 6711
	err = snd_hda_attach_beep_device(codec, 0x1);
	if (err < 0) {
		alc_free(codec);
		return err;
	}

6712
	if (board_config != ALC260_AUTO)
6713
		setup_preset(codec, &alc260_presets[board_config]);
L
Linus Torvalds 已提交
6714 6715 6716 6717

	spec->stream_analog_playback = &alc260_pcm_analog_playback;
	spec->stream_analog_capture = &alc260_pcm_analog_capture;

6718 6719 6720
	spec->stream_digital_playback = &alc260_pcm_digital_playback;
	spec->stream_digital_capture = &alc260_pcm_digital_capture;

6721 6722 6723
	if (!spec->adc_nids && spec->input_mux) {
		/* check whether NID 0x04 is valid */
		unsigned int wcap = get_wcaps(codec, 0x04);
6724
		wcap = get_wcaps_type(wcap);
6725 6726 6727 6728 6729 6730 6731 6732 6733
		/* get type */
		if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
			spec->adc_nids = alc260_adc_nids_alt;
			spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
		} else {
			spec->adc_nids = alc260_adc_nids;
			spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
		}
	}
6734
	set_capture_mixer(codec);
6735
	set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
6736

6737 6738
	spec->vmaster_nid = 0x08;

L
Linus Torvalds 已提交
6739
	codec->patch_ops = alc_patch_ops;
6740
	if (board_config == ALC260_AUTO)
6741
		spec->init_hook = alc260_auto_init;
6742 6743 6744 6745
#ifdef CONFIG_SND_HDA_POWER_SAVE
	if (!spec->loopback.amplist)
		spec->loopback.amplist = alc260_loopbacks;
#endif
L
Linus Torvalds 已提交
6746 6747 6748 6749

	return 0;
}

6750

L
Linus Torvalds 已提交
6751
/*
6752
 * ALC882/883/885/888/889 support
L
Linus Torvalds 已提交
6753 6754 6755 6756 6757 6758 6759 6760 6761
 *
 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
 * configuration.  Each pin widget can choose any input DACs and a mixer.
 * Each ADC is connected from a mixer of all inputs.  This makes possible
 * 6-channel independent captures.
 *
 * In addition, an independent DAC for the multi-playback (not used in this
 * driver yet).
 */
6762 6763
#define ALC882_DIGOUT_NID	0x06
#define ALC882_DIGIN_NID	0x0a
6764 6765 6766 6767
#define ALC883_DIGOUT_NID	ALC882_DIGOUT_NID
#define ALC883_DIGIN_NID	ALC882_DIGIN_NID
#define ALC1200_DIGOUT_NID	0x10

L
Linus Torvalds 已提交
6768

6769
static struct hda_channel_mode alc882_ch_modes[1] = {
L
Linus Torvalds 已提交
6770 6771 6772
	{ 8, NULL }
};

6773
/* DACs */
L
Linus Torvalds 已提交
6774 6775 6776 6777
static hda_nid_t alc882_dac_nids[4] = {
	/* front, rear, clfe, rear_surr */
	0x02, 0x03, 0x04, 0x05
};
6778
#define alc883_dac_nids		alc882_dac_nids
L
Linus Torvalds 已提交
6779

6780
/* ADCs */
6781 6782
#define alc882_adc_nids		alc880_adc_nids
#define alc882_adc_nids_alt	alc880_adc_nids_alt
6783 6784 6785 6786
#define alc883_adc_nids		alc882_adc_nids_alt
static hda_nid_t alc883_adc_nids_alt[1] = { 0x08 };
static hda_nid_t alc883_adc_nids_rev[2] = { 0x09, 0x08 };
#define alc889_adc_nids		alc880_adc_nids
L
Linus Torvalds 已提交
6787

6788 6789
static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
6790 6791 6792
#define alc883_capsrc_nids	alc882_capsrc_nids_alt
static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
#define alc889_capsrc_nids	alc882_capsrc_nids
6793

L
Linus Torvalds 已提交
6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805
/* input MUX */
/* FIXME: should be a matrix-type input source selection */

static struct hda_input_mux alc882_capture_source = {
	.num_items = 4,
	.items = {
		{ "Mic", 0x0 },
		{ "Front Mic", 0x1 },
		{ "Line", 0x2 },
		{ "CD", 0x4 },
	},
};
6806

6807 6808
#define alc883_capture_source	alc882_capture_source

6809 6810 6811 6812 6813 6814 6815 6816 6817
static struct hda_input_mux alc889_capture_source = {
	.num_items = 3,
	.items = {
		{ "Front Mic", 0x0 },
		{ "Mic", 0x3 },
		{ "Line", 0x2 },
	},
};

6818 6819 6820 6821 6822 6823 6824 6825 6826
static struct hda_input_mux mb5_capture_source = {
	.num_items = 3,
	.items = {
		{ "Mic", 0x1 },
		{ "Line", 0x2 },
		{ "CD", 0x4 },
	},
};

6827 6828 6829 6830 6831 6832 6833 6834
static struct hda_input_mux macmini3_capture_source = {
	.num_items = 2,
	.items = {
		{ "Line", 0x2 },
		{ "CD", 0x4 },
	},
};

6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894
static struct hda_input_mux alc883_3stack_6ch_intel = {
	.num_items = 4,
	.items = {
		{ "Mic", 0x1 },
		{ "Front Mic", 0x0 },
		{ "Line", 0x2 },
		{ "CD", 0x4 },
	},
};

static struct hda_input_mux alc883_lenovo_101e_capture_source = {
	.num_items = 2,
	.items = {
		{ "Mic", 0x1 },
		{ "Line", 0x2 },
	},
};

static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
	.num_items = 4,
	.items = {
		{ "Mic", 0x0 },
		{ "iMic", 0x1 },
		{ "Line", 0x2 },
		{ "CD", 0x4 },
	},
};

static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
	.num_items = 2,
	.items = {
		{ "Mic", 0x0 },
		{ "Int Mic", 0x1 },
	},
};

static struct hda_input_mux alc883_lenovo_sky_capture_source = {
	.num_items = 3,
	.items = {
		{ "Mic", 0x0 },
		{ "Front Mic", 0x1 },
		{ "Line", 0x4 },
	},
};

static struct hda_input_mux alc883_asus_eee1601_capture_source = {
	.num_items = 2,
	.items = {
		{ "Mic", 0x0 },
		{ "Line", 0x2 },
	},
};

static struct hda_input_mux alc889A_mb31_capture_source = {
	.num_items = 2,
	.items = {
		{ "Mic", 0x0 },
		/* Front Mic (0x01) unused */
		{ "Line", 0x2 },
		/* Line 2 (0x03) unused */
6895
		/* CD (0x04) unused? */
6896 6897 6898 6899 6900 6901 6902 6903 6904 6905
	},
};

/*
 * 2ch mode
 */
static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
	{ 2, NULL }
};

6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916
/*
 * 2ch mode
 */
static struct hda_verb alc882_3ST_ch2_init[] = {
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ } /* end */
};

6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928
/*
 * 4ch mode
 */
static struct hda_verb alc882_3ST_ch4_init[] = {
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ } /* end */
};

6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941
/*
 * 6ch mode
 */
static struct hda_verb alc882_3ST_ch6_init[] = {
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ } /* end */
};

6942
static struct hda_channel_mode alc882_3ST_6ch_modes[3] = {
6943
	{ 2, alc882_3ST_ch2_init },
6944
	{ 4, alc882_3ST_ch4_init },
6945 6946 6947
	{ 6, alc882_3ST_ch6_init },
};

6948 6949
#define alc883_3ST_6ch_modes	alc882_3ST_6ch_modes

6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995
/*
 * 2ch mode
 */
static struct hda_verb alc883_3ST_ch2_clevo_init[] = {
	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ } /* end */
};

/*
 * 4ch mode
 */
static struct hda_verb alc883_3ST_ch4_clevo_init[] = {
	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ } /* end */
};

/*
 * 6ch mode
 */
static struct hda_verb alc883_3ST_ch6_clevo_init[] = {
	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ } /* end */
};

static struct hda_channel_mode alc883_3ST_6ch_clevo_modes[3] = {
	{ 2, alc883_3ST_ch2_clevo_init },
	{ 4, alc883_3ST_ch4_clevo_init },
	{ 6, alc883_3ST_ch6_clevo_init },
};


6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022
/*
 * 6ch mode
 */
static struct hda_verb alc882_sixstack_ch6_init[] = {
	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ } /* end */
};

/*
 * 8ch mode
 */
static struct hda_verb alc882_sixstack_ch8_init[] = {
	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ } /* end */
};

static struct hda_channel_mode alc882_sixstack_modes[2] = {
	{ 6, alc882_sixstack_ch6_init },
	{ 8, alc882_sixstack_ch8_init },
};

7023 7024 7025 7026 7027 7028 7029

/* Macbook Air 2,1 */

static struct hda_channel_mode alc885_mba21_ch_modes[1] = {
      { 2, NULL },
};

7030
/*
7031
 * macbook pro ALC885 can switch LineIn to LineOut without losing Mic
7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044
 */

/*
 * 2ch mode
 */
static struct hda_verb alc885_mbp_ch2_init[] = {
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
	{ 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{ 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{ } /* end */
};

/*
7045
 * 4ch mode
7046
 */
7047
static struct hda_verb alc885_mbp_ch4_init[] = {
7048 7049 7050 7051 7052 7053 7054 7055
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{ 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{ } /* end */
};

7056
static struct hda_channel_mode alc885_mbp_4ch_modes[2] = {
7057
	{ 2, alc885_mbp_ch2_init },
7058
	{ 4, alc885_mbp_ch4_init },
7059 7060
};

7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088
/*
 * 2ch
 * Speakers/Woofer/HP = Front
 * LineIn = Input
 */
static struct hda_verb alc885_mb5_ch2_init[] = {
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{ } /* end */
};

/*
 * 6ch mode
 * Speakers/HP = Front
 * Woofer = LFE
 * LineIn = Surround
 */
static struct hda_verb alc885_mb5_ch6_init[] = {
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
	{ } /* end */
};

static struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
	{ 2, alc885_mb5_ch2_init },
	{ 6, alc885_mb5_ch6_init },
};
7089

7090
#define alc885_macmini3_6ch_modes	alc885_mb5_6ch_modes
7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199

/*
 * 2ch mode
 */
static struct hda_verb alc883_4ST_ch2_init[] = {
	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ } /* end */
};

/*
 * 4ch mode
 */
static struct hda_verb alc883_4ST_ch4_init[] = {
	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ } /* end */
};

/*
 * 6ch mode
 */
static struct hda_verb alc883_4ST_ch6_init[] = {
	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ } /* end */
};

/*
 * 8ch mode
 */
static struct hda_verb alc883_4ST_ch8_init[] = {
	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ } /* end */
};

static struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
	{ 2, alc883_4ST_ch2_init },
	{ 4, alc883_4ST_ch4_init },
	{ 6, alc883_4ST_ch6_init },
	{ 8, alc883_4ST_ch8_init },
};


/*
 * 2ch mode
 */
static struct hda_verb alc883_3ST_ch2_intel_init[] = {
	{ 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ } /* end */
};

/*
 * 4ch mode
 */
static struct hda_verb alc883_3ST_ch4_intel_init[] = {
	{ 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ } /* end */
};

/*
 * 6ch mode
 */
static struct hda_verb alc883_3ST_ch6_intel_init[] = {
	{ 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ } /* end */
};

static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
	{ 2, alc883_3ST_ch2_intel_init },
	{ 4, alc883_3ST_ch4_intel_init },
	{ 6, alc883_3ST_ch6_intel_init },
};

7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212
/*
 * 2ch mode
 */
static struct hda_verb alc889_ch2_intel_init[] = {
	{ 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
	{ 0x19, AC_VERB_SET_CONNECT_SEL, 0x00 },
	{ 0x16, AC_VERB_SET_CONNECT_SEL, 0x00 },
	{ 0x17, AC_VERB_SET_CONNECT_SEL, 0x00 },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ } /* end */
};

7213 7214 7215 7216
/*
 * 6ch mode
 */
static struct hda_verb alc889_ch6_intel_init[] = {
7217 7218 7219 7220 7221
	{ 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
	{ 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
	{ 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7222 7223 7224 7225 7226 7227 7228 7229
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ } /* end */
};

/*
 * 8ch mode
 */
static struct hda_verb alc889_ch8_intel_init[] = {
7230 7231 7232 7233 7234
	{ 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
	{ 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
	{ 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x03 },
7235 7236 7237 7238 7239
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ } /* end */
};

7240 7241
static struct hda_channel_mode alc889_8ch_intel_modes[3] = {
	{ 2, alc889_ch2_intel_init },
7242 7243 7244 7245
	{ 6, alc889_ch6_intel_init },
	{ 8, alc889_ch8_intel_init },
};

7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273
/*
 * 6ch mode
 */
static struct hda_verb alc883_sixstack_ch6_init[] = {
	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ } /* end */
};

/*
 * 8ch mode
 */
static struct hda_verb alc883_sixstack_ch8_init[] = {
	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ } /* end */
};

static struct hda_channel_mode alc883_sixstack_modes[2] = {
	{ 6, alc883_sixstack_ch6_init },
	{ 8, alc883_sixstack_ch8_init },
};


L
Linus Torvalds 已提交
7274 7275 7276
/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
 *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
 */
7277
static struct snd_kcontrol_new alc882_base_mixer[] = {
7278
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
7279
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7280
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
7281
	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7282 7283
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
7284 7285
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7286
	HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
7287
	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
L
Linus Torvalds 已提交
7288 7289 7290 7291 7292 7293
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7294
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
L
Linus Torvalds 已提交
7295 7296
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7297
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
L
Linus Torvalds 已提交
7298 7299 7300 7301
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

7302 7303 7304 7305 7306 7307 7308 7309 7310
/* Macbook Air 2,1 same control for HP and internal Speaker */

static struct snd_kcontrol_new alc885_mba21_mixer[] = {
      HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
      HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 0x02, HDA_OUTPUT),
     { }
};


7311
static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
7312 7313 7314 7315 7316
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
	HDA_BIND_MUTE   ("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
	HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0e, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7317 7318
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7319 7320
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
	HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
7321
	HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
7322 7323 7324
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
	{ } /* end */
};
7325 7326

static struct snd_kcontrol_new alc885_mb5_mixer[] = {
7327 7328 7329 7330 7331 7332
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
	HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
	HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
	HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
7333 7334
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
	HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0f, 0x02, HDA_INPUT),
7335 7336 7337 7338 7339 7340 7341 7342
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x19, 0x00, HDA_INPUT),
	{ } /* end */
};
7343

7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358
static struct snd_kcontrol_new alc885_macmini3_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
	HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
	HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
	HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
	HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0f, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x07, HDA_INPUT),
	HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x07, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT),
	{ } /* end */
};

7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372
static struct snd_kcontrol_new alc885_imac91_mixer[] = {
	HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
	HDA_BIND_MUTE   ("Line-Out Playback Switch", 0x0c, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
	HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
	{ } /* end */
};


7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385
static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
};

7386 7387 7388 7389 7390 7391 7392 7393 7394 7395
static struct snd_kcontrol_new alc882_targa_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7396
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7397 7398
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7399
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418
	{ } /* end */
};

/* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
 *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
 */
static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
	HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7419
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7420 7421 7422
	{ } /* end */
};

7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436
static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
};

7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447
static struct snd_kcontrol_new alc882_chmode_mixer[] = {
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Channel Mode",
		.info = alc_ch_mode_info,
		.get = alc_ch_mode_get,
		.put = alc_ch_mode_put,
	},
	{ } /* end */
};

7448
static struct hda_verb alc882_base_init_verbs[] = {
L
Linus Torvalds 已提交
7449
	/* Front mixer: unmute input/output amp left and right (volume = 0) */
7450 7451
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
L
Linus Torvalds 已提交
7452
	/* Rear mixer */
7453 7454
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
L
Linus Torvalds 已提交
7455
	/* CLFE mixer */
7456 7457
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
L
Linus Torvalds 已提交
7458
	/* Side mixer */
7459 7460
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
L
Linus Torvalds 已提交
7461

7462
	/* Front Pin: output 0 (0x0c) */
7463 7464
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
L
Linus Torvalds 已提交
7465
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7466
	/* Rear Pin: output 1 (0x0d) */
7467 7468
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
L
Linus Torvalds 已提交
7469
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7470
	/* CLFE Pin: output 2 (0x0e) */
7471 7472
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
L
Linus Torvalds 已提交
7473
	{0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7474
	/* Side Pin: output 3 (0x0f) */
7475 7476
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
L
Linus Torvalds 已提交
7477
	{0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7478
	/* Mic (rear) pin: input vref at 80% */
7479
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7480 7481
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Front Mic pin: input vref at 80% */
7482
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7483 7484
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Line In pin: input */
7485
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7486 7487 7488 7489 7490
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Line-2 In: Headphone output (output 0 - 0x0c) */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
L
Linus Torvalds 已提交
7491
	/* CD pin widget for input */
7492
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
L
Linus Torvalds 已提交
7493 7494 7495 7496

	/* FIXME: use matrix-type input source selection */
	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
	/* Input mixer2 */
7497
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
L
Linus Torvalds 已提交
7498
	/* Input mixer3 */
7499 7500 7501
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	/* ADC2: mute amp left and right */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7502
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7503 7504
	/* ADC3: mute amp left and right */
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7505
	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
L
Linus Torvalds 已提交
7506 7507 7508 7509

	{ }
};

7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521
static struct hda_verb alc882_adc1_init_verbs[] = {
	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	/* ADC1: mute amp left and right */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
	{ }
};

7522 7523 7524
static struct hda_verb alc882_eapd_verbs[] = {
	/* change to EAPD mode */
	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7525
	{0x20, AC_VERB_SET_PROC_COEF, 0x3060},
7526
	{ }
7527 7528
};

7529 7530 7531 7532 7533 7534
static struct hda_verb alc889_eapd_verbs[] = {
	{0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
	{0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
	{ }
};

7535 7536 7537 7538 7539
static struct hda_verb alc_hp15_unsol_verbs[] = {
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{}
};
7540 7541 7542

static struct hda_verb alc885_init_verbs[] = {
	/* Front mixer: unmute input/output amp left and right (volume = 0) */
7543 7544
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7545
	/* Rear mixer */
7546 7547
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7548
	/* CLFE mixer */
7549 7550
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7551
	/* Side mixer */
7552 7553
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7554 7555

	/* Front HP Pin: output 0 (0x0c) */
7556
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* Front Pin: output 0 (0x0c) */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* Rear Pin: output 1 (0x0d) */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x19, AC_VERB_SET_CONNECT_SEL, 0x01},
	/* CLFE Pin: output 2 (0x0e) */
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
	/* Side Pin: output 3 (0x0f) */
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
	/* Mic (rear) pin: input vref at 80% */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Front Mic pin: input vref at 80% */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Line In pin: input */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},

	/* Mixer elements: 0x18, , 0x1a, 0x1b */
	/* Input mixer1 */
7587
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7588 7589 7590
	/* Input mixer2 */
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	/* Input mixer3 */
7591
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615
	/* ADC2: mute amp left and right */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	/* ADC3: mute amp left and right */
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},

	{ }
};

static struct hda_verb alc885_init_input_verbs[] = {
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
	{ }
};


/* Unmute Selector 24h and set the default input to front mic */
static struct hda_verb alc889_init_input_verbs[] = {
	{0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{ }
};


7616 7617
#define alc883_init_verbs	alc882_base_init_verbs

7618 7619 7620 7621 7622 7623 7624
/* Mac Pro test */
static struct snd_kcontrol_new alc882_macpro_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7625
	/* FIXME: this looks suspicious...
7626 7627
	HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x02, HDA_INPUT),
7628
	*/
7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681
	{ } /* end */
};

static struct hda_verb alc882_macpro_init_verbs[] = {
	/* Front mixer: unmute input/output amp left and right (volume = 0) */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	/* Front Pin: output 0 (0x0c) */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* Front Mic pin: input vref at 80% */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Speaker:  output */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
	/* Headphone output (output 0 - 0x0c) */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x18, AC_VERB_SET_CONNECT_SEL, 0x00},

	/* FIXME: use matrix-type input source selection */
	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	/* Input mixer2 */
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	/* Input mixer3 */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	/* ADC1: mute amp left and right */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* ADC2: mute amp left and right */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* ADC3: mute amp left and right */
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},

	{ }
};
7682

7683 7684
/* Macbook 5,1 */
static struct hda_verb alc885_mb5_init_verbs[] = {
7685 7686 7687 7688 7689
	/* DACs */
	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7690 7691 7692 7693
	/* Front mixer */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706
	/* Surround mixer */
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	/* LFE mixer */
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	/* HP mixer */
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	/* Front Pin (0x0c) */
7707 7708
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7709 7710 7711 7712 7713 7714
	{0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* LFE Pin (0x0e) */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
	/* HP Pin (0x0f) */
7715 7716
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7717
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
7718
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732
	/* Front Mic pin: input vref at 80% */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Line In pin */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},

	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	{ }
};

7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779
/* Macmini 3,1 */
static struct hda_verb alc885_macmini3_init_verbs[] = {
	/* DACs */
	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* Front mixer */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	/* Surround mixer */
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	/* LFE mixer */
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	/* HP mixer */
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	/* Front Pin (0x0c) */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* LFE Pin (0x0e) */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
	/* HP Pin (0x0f) */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	/* Line In pin */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},

	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	{ }
};

7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802

static struct hda_verb alc885_mba21_init_verbs[] = {
	/*Internal and HP Speaker Mixer*/
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	/*Internal Speaker Pin (0x0c)*/
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, (PIN_OUT | AC_PINCTL_VREF_50) },
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* HP Pin: output 0 (0x0e) */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, (ALC880_HP_EVENT | AC_USRSP_EN)},
	/* Line in (is hp when jack connected)*/
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_VREF_50},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},

	{ }
 };


7803 7804 7805 7806 7807 7808 7809 7810 7811 7812
/* Macbook Pro rev3 */
static struct hda_verb alc885_mbp3_init_verbs[] = {
	/* Front mixer: unmute input/output amp left and right (volume = 0) */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	/* Rear mixer */
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7813 7814 7815 7816
	/* HP mixer */
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7817 7818 7819 7820
	/* Front Pin: output 0 (0x0c) */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7821
	/* HP Pin: output 0 (0x0e) */
7822
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
7823 7824
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x02},
7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	/* Mic (rear) pin: input vref at 80% */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Front Mic pin: input vref at 80% */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Line In pin: use output 1 when in LineOut mode */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},

	/* FIXME: use matrix-type input source selection */
	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	/* Input mixer2 */
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	/* Input mixer3 */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	/* ADC1: mute amp left and right */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* ADC2: mute amp left and right */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* ADC3: mute amp left and right */
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},

	{ }
};

7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926
/* iMac 9,1 */
static struct hda_verb alc885_imac91_init_verbs[] = {
	/* Line-Out mixer: unmute input/output amp left and right (volume = 0) */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	/* Rear mixer */
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	/* HP Pin: output 0 (0x0c) */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	/* Internal Speakers: output 0 (0x0d) */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* Mic (rear) pin: input vref at 80% */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Front Mic pin: input vref at 80% */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Line In pin: use output 1 when in LineOut mode */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},

	/* FIXME: use matrix-type input source selection */
	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	/* Input mixer2 */
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	/* Input mixer3 */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	/* ADC1: mute amp left and right */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* ADC2: mute amp left and right */
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* ADC3: mute amp left and right */
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},

	{ }
};

7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955
/* iMac 24 mixer. */
static struct snd_kcontrol_new alc885_imac24_mixer[] = {
	HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
	HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
	{ } /* end */
};

/* iMac 24 init verbs. */
static struct hda_verb alc885_imac24_init_verbs[] = {
	/* Internal speakers: output 0 (0x0c) */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* Internal speakers: output 0 (0x0c) */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* Headphone: output 0 (0x0c) */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	/* Front Mic: input vref at 80% */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{ }
};

/* Toggle speaker-output according to the hp-jack state */
7956
static void alc885_imac24_setup(struct hda_codec *codec)
7957
{
7958
	struct alc_spec *spec = codec->spec;
7959

7960 7961 7962
	spec->autocfg.hp_pins[0] = 0x14;
	spec->autocfg.speaker_pins[0] = 0x18;
	spec->autocfg.speaker_pins[1] = 0x1a;
7963 7964
}

7965 7966 7967
#define alc885_mb5_setup	alc885_imac24_setup
#define alc885_macmini3_setup	alc885_imac24_setup

7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978
/* Macbook Air 2,1 */
static void alc885_mba21_setup(struct hda_codec *codec)
{
       struct alc_spec *spec = codec->spec;

       spec->autocfg.hp_pins[0] = 0x14;
       spec->autocfg.speaker_pins[0] = 0x18;
}



7979
static void alc885_mbp3_setup(struct hda_codec *codec)
7980
{
7981
	struct alc_spec *spec = codec->spec;
7982

7983 7984
	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
7985 7986
}

7987
static void alc885_imac91_setup(struct hda_codec *codec)
7988
{
7989
	struct alc_spec *spec = codec->spec;
7990

7991 7992 7993
	spec->autocfg.hp_pins[0] = 0x14;
	spec->autocfg.speaker_pins[0] = 0x15;
	spec->autocfg.speaker_pins[1] = 0x1a;
7994
}
7995

7996 7997 7998 7999 8000 8001
static struct hda_verb alc882_targa_verbs[] = {
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},

	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8002

8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013
	{0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */

	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{ } /* end */
};

/* toggle speaker-output according to the hp-jack state */
static void alc882_targa_automute(struct hda_codec *codec)
{
8014 8015
	struct alc_spec *spec = codec->spec;
	alc_automute_amp(codec);
8016
	snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
8017 8018 8019
				  spec->jack_present ? 1 : 3);
}

8020
static void alc882_targa_setup(struct hda_codec *codec)
8021 8022 8023 8024 8025
{
	struct alc_spec *spec = codec->spec;

	spec->autocfg.hp_pins[0] = 0x14;
	spec->autocfg.speaker_pins[0] = 0x1b;
8026 8027 8028 8029
}

static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
{
8030
	if ((res >> 26) == ALC880_HP_EVENT)
8031 8032 8033 8034 8035 8036 8037 8038 8039 8040
		alc882_targa_automute(codec);
}

static struct hda_verb alc882_asus_a7j_verbs[] = {
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},

	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8041

8042 8043 8044 8045 8046 8047 8048 8049 8050 8051
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */

	{0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
	{ } /* end */
};

8052 8053 8054 8055 8056 8057 8058
static struct hda_verb alc882_asus_a7m_verbs[] = {
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},

	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8059

8060 8061 8062 8063 8064 8065 8066 8067 8068 8069
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */

	{0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
 	{ } /* end */
};

8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101
static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
{
	unsigned int gpiostate, gpiomask, gpiodir;

	gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
				       AC_VERB_GET_GPIO_DATA, 0);

	if (!muted)
		gpiostate |= (1 << pin);
	else
		gpiostate &= ~(1 << pin);

	gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
				      AC_VERB_GET_GPIO_MASK, 0);
	gpiomask |= (1 << pin);

	gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
				     AC_VERB_GET_GPIO_DIRECTION, 0);
	gpiodir |= (1 << pin);


	snd_hda_codec_write(codec, codec->afg, 0,
			    AC_VERB_SET_GPIO_MASK, gpiomask);
	snd_hda_codec_write(codec, codec->afg, 0,
			    AC_VERB_SET_GPIO_DIRECTION, gpiodir);

	msleep(1);

	snd_hda_codec_write(codec, codec->afg, 0,
			    AC_VERB_SET_GPIO_DATA, gpiostate);
}

8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112
/* set up GPIO at initialization */
static void alc885_macpro_init_hook(struct hda_codec *codec)
{
	alc882_gpio_mute(codec, 0, 0);
	alc882_gpio_mute(codec, 1, 0);
}

/* set up GPIO and update auto-muting at initialization */
static void alc885_imac24_init_hook(struct hda_codec *codec)
{
	alc885_macpro_init_hook(codec);
8113
	alc_automute_amp(codec);
8114 8115
}

8116 8117 8118
/*
 * generic initialization of ADC, input mixers and output mixers
 */
8119
static struct hda_verb alc883_auto_init_verbs[] = {
8120 8121 8122
	/*
	 * Unmute ADC0-2 and set the default input to mic-in
	 */
8123 8124 8125 8126
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8127

8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147
	/*
	 * Set up output mixers (0x0c - 0x0f)
	 */
	/* set vol=0 to output mixers */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	/* set up input amps for analog loopback */
	/* Amp Indices: DAC = 0, mixer = 1 */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8148

8149 8150 8151
	/* FIXME: use matrix-type input source selection */
	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
	/* Input mixer2 */
8152
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8153
	/* Input mixer3 */
8154
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8155
	{ }
8156 8157
};

8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200
/* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */
static struct hda_verb alc889A_mb31_ch2_init[] = {
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
	{ } /* end */
};

/* 4ch mode (Speaker:front, Subwoofer:CLFE, Line:CLFE, Headphones:front) */
static struct hda_verb alc889A_mb31_ch4_init[] = {
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
	{ } /* end */
};

/* 5ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:rear) */
static struct hda_verb alc889A_mb31_ch5_init[] = {
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as rear */
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
	{ } /* end */
};

/* 6ch mode (Speaker:front, Subwoofer:off, Line:CLFE, Headphones:Rear) */
static struct hda_verb alc889A_mb31_ch6_init[] = {
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as front */
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Subwoofer off */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
	{ } /* end */
};

static struct hda_channel_mode alc889A_mb31_6ch_modes[4] = {
	{ 2, alc889A_mb31_ch2_init },
	{ 4, alc889A_mb31_ch4_init },
	{ 5, alc889A_mb31_ch5_init },
	{ 6, alc889A_mb31_ch6_init },
};

8201 8202 8203 8204 8205 8206 8207
static struct hda_verb alc883_medion_eapd_verbs[] = {
        /* eanable EAPD on medion laptop */
	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
	{0x20, AC_VERB_SET_PROC_COEF, 0x3070},
	{ }
};

8208
#define alc883_base_mixer	alc882_base_mixer
8209

8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226
static struct snd_kcontrol_new alc883_mitac_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

8227
static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254
static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

8255 8256 8257 8258 8259 8260 8261 8262 8263
static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8264
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8265 8266
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8267
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8268 8269 8270
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};
8271

8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286
static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8287
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8288 8289
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8290
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8291 8292 8293 8294
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318
static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
			      HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
};

8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342
static struct snd_kcontrol_new alc885_8ch_intel_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
			      HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Speaker Playback Switch", 0x0f, 2, HDA_INPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x1b, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
};

T
Takashi Iwai 已提交
8343
static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
8344
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8345
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8346
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8347
	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8348 8349
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8350 8351
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8352 8353 8354 8355 8356 8357
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8358
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8359 8360
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8361
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8362 8363 8364 8365
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

8366
static struct snd_kcontrol_new alc883_targa_mixer[] = {
8367
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
8368
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8369
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
8370
	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8382
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8383 8384
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
8385
};
8386

8387
static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
8388
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
8389
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8390
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
T
Takashi Iwai 已提交
8391
	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8392 8393 8394
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8395
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8396
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8397 8398 8399
	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8400
	{ } /* end */
8401
};
8402

T
Takashi Iwai 已提交
8403 8404 8405 8406 8407 8408 8409 8410 8411
static struct snd_kcontrol_new alc883_targa_8ch_mixer[] = {
	HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

8412 8413 8414
static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8415 8416
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
8417 8418 8419 8420 8421
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
8422
};
8423

8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447
static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	{ } /* end */
8448
};
8449

8450
static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
8451 8452
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8453 8454 8455
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8456 8457 8458
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8459
	{ } /* end */
8460
};
8461

8462 8463 8464 8465 8466
static struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("LFE Playback Switch", 0x0f, 2, HDA_INPUT),
8467 8468
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8469 8470 8471 8472 8473 8474 8475 8476
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
};

8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501
static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
	HDA_CODEC_VOLUME_MONO("Center Playback Volume",
						0x0d, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527
static struct snd_kcontrol_new alc889A_mb31_mixer[] = {
	/* Output mixers */
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x00,
		HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x00, HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x02, HDA_INPUT),
	/* Output switches */
	HDA_CODEC_MUTE("Enable Speaker", 0x14, 0x00, HDA_OUTPUT),
	HDA_CODEC_MUTE("Enable Headphones", 0x15, 0x00, HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("Enable LFE", 0x16, 2, 0x00, HDA_OUTPUT),
	/* Boost mixers */
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
	/* Input mixers */
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	{ } /* end */
};

G
Guido Günther 已提交
8528 8529 8530 8531 8532 8533 8534 8535 8536 8537
static struct snd_kcontrol_new alc883_vaiott_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562
static struct hda_bind_ctls alc883_bind_cap_vol = {
	.ops = &snd_hda_bind_vol,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
		HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
		0
	},
};

static struct hda_bind_ctls alc883_bind_cap_switch = {
	.ops = &snd_hda_bind_sw,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
		HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
		0
	},
};

static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8563 8564 8565 8566
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
};
8567

8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581
static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
	HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
	HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		/* .name = "Capture Source", */
		.name = "Input Source",
		.count = 1,
		.info = alc_mux_enum_info,
		.get = alc_mux_enum_get,
		.put = alc_mux_enum_put,
	},
	{ } /* end */
};
8582

8583 8584 8585 8586 8587 8588 8589 8590 8591
static struct snd_kcontrol_new alc883_chmode_mixer[] = {
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Channel Mode",
		.info = alc_ch_mode_info,
		.get = alc_ch_mode_get,
		.put = alc_ch_mode_put,
	},
	{ } /* end */
8592 8593
};

8594
/* toggle speaker-output according to the hp-jack state */
8595
static void alc883_mitac_setup(struct hda_codec *codec)
8596
{
8597
	struct alc_spec *spec = codec->spec;
8598

8599 8600 8601
	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
	spec->autocfg.speaker_pins[1] = 0x17;
8602 8603 8604 8605 8606 8607
}

/* auto-toggle front mic */
/*
static void alc883_mitac_mic_automute(struct hda_codec *codec)
{
8608
	unsigned char bits = snd_hda_jack_detect(codec, 0x18) ? HDA_AMP_MUTE : 0;
8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628

	snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
}
*/

static struct hda_verb alc883_mitac_verbs[] = {
	/* HP */
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	/* Subwoofer */
	{0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},

	/* enable unsolicited event */
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	/* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */

	{ } /* end */
};

8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644
static struct hda_verb alc883_clevo_m540r_verbs[] = {
	/* HP */
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	/* Int speaker */
	/*{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},*/

	/* enable unsolicited event */
	/*
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
	*/

	{ } /* end */
};

8645
static struct hda_verb alc883_clevo_m720_verbs[] = {
8646 8647 8648 8649 8650 8651 8652 8653 8654
	/* HP */
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	/* Int speaker */
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},

	/* enable unsolicited event */
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8655
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8656 8657 8658 8659

	{ } /* end */
};

8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673
static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
	/* HP */
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	/* Subwoofer */
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},

	/* enable unsolicited event */
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},

	{ } /* end */
};

8674
static struct hda_verb alc883_targa_verbs[] = {
8675 8676 8677 8678 8679
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},

	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8680

8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696
/* Connect Line-Out side jack (SPDIF) to Side */
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
/* Connect Mic jack to CLFE */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
/* Connect Line-in jack to Surround */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
/* Connect HP out jack to Front */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8697 8698 8699 8700 8701 8702

	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},

	{ } /* end */
};

8703 8704 8705 8706 8707 8708 8709
static struct hda_verb alc883_lenovo_101e_verbs[] = {
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
        {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
	{ } /* end */
};

8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726
static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
        {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
        {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{ } /* end */
};

static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
	{ } /* end */
};

8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739
static struct hda_verb alc883_haier_w66_verbs[] = {
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},

	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},

	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{ } /* end */
};

8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751
static struct hda_verb alc888_lenovo_sky_verbs[] = {
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{ } /* end */
};

8752 8753 8754 8755 8756
static struct hda_verb alc888_6st_dell_verbs[] = {
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{ }
};

G
Guido Günther 已提交
8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767
static struct hda_verb alc883_vaiott_verbs[] = {
	/* HP */
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},

	/* enable unsolicited event */
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},

	{ } /* end */
};

8768
static void alc888_3st_hp_setup(struct hda_codec *codec)
8769
{
8770
	struct alc_spec *spec = codec->spec;
8771

8772 8773 8774 8775
	spec->autocfg.hp_pins[0] = 0x1b;
	spec->autocfg.speaker_pins[0] = 0x14;
	spec->autocfg.speaker_pins[1] = 0x16;
	spec->autocfg.speaker_pins[2] = 0x18;
8776 8777
}

8778
static struct hda_verb alc888_3st_hp_verbs[] = {
8779
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},	/* Front: output 0 (0x0c) */
8780 8781
	{0x16, AC_VERB_SET_CONNECT_SEL, 0x01},	/* Rear : output 1 (0x0d) */
	{0x18, AC_VERB_SET_CONNECT_SEL, 0x02},	/* CLFE : output 2 (0x0e) */
8782
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8783
	{ } /* end */
8784 8785
};

8786 8787 8788
/*
 * 2ch mode
 */
8789
static struct hda_verb alc888_3st_hp_2ch_init[] = {
8790 8791 8792 8793
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
	{ 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8794
	{ } /* end */
8795 8796
};

8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811
/*
 * 4ch mode
 */
static struct hda_verb alc888_3st_hp_4ch_init[] = {
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ } /* end */
};

/*
 * 6ch mode
 */
8812
static struct hda_verb alc888_3st_hp_6ch_init[] = {
8813 8814
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8815
	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8816 8817
	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8818 8819
	{ 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ } /* end */
8820 8821
};

8822
static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8823
	{ 2, alc888_3st_hp_2ch_init },
8824
	{ 4, alc888_3st_hp_4ch_init },
8825
	{ 6, alc888_3st_hp_6ch_init },
8826 8827
};

8828 8829 8830
/* toggle front-jack and RCA according to the hp-jack state */
static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
{
8831
 	unsigned int present = snd_hda_jack_detect(codec, 0x1b);
8832

8833 8834 8835 8836
	snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
	snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8837 8838 8839 8840 8841
}

/* toggle RCA according to the front-jack state */
static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
{
8842
 	unsigned int present = snd_hda_jack_detect(codec, 0x14);
8843

8844 8845
	snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8846
}
8847

8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867
static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
					     unsigned int res)
{
	if ((res >> 26) == ALC880_HP_EVENT)
		alc888_lenovo_ms7195_front_automute(codec);
	if ((res >> 26) == ALC880_FRONT_EVENT)
		alc888_lenovo_ms7195_rca_automute(codec);
}

static struct hda_verb alc883_medion_md2_verbs[] = {
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},

	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},

	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{ } /* end */
};

/* toggle speaker-output according to the hp-jack state */
8868
static void alc883_medion_md2_setup(struct hda_codec *codec)
8869
{
8870
	struct alc_spec *spec = codec->spec;
8871

8872 8873
	spec->autocfg.hp_pins[0] = 0x14;
	spec->autocfg.speaker_pins[0] = 0x15;
8874 8875
}

8876
/* toggle speaker-output according to the hp-jack state */
8877 8878
#define alc883_targa_init_hook		alc882_targa_init_hook
#define alc883_targa_unsol_event	alc882_targa_unsol_event
8879

8880 8881 8882 8883
static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
{
	unsigned int present;

8884
	present = snd_hda_jack_detect(codec, 0x18);
8885 8886 8887 8888
	snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
				 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
}

8889
static void alc883_clevo_m720_setup(struct hda_codec *codec)
8890
{
8891 8892 8893 8894
	struct alc_spec *spec = codec->spec;

	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
8895 8896 8897 8898
}

static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
{
8899
	alc_automute_amp(codec);
8900 8901 8902 8903
	alc883_clevo_m720_mic_automute(codec);
}

static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8904 8905
					   unsigned int res)
{
8906 8907 8908 8909
	switch (res >> 26) {
	case ALC880_MIC_EVENT:
		alc883_clevo_m720_mic_automute(codec);
		break;
8910 8911 8912
	default:
		alc_automute_amp_unsol_event(codec, res);
		break;
8913
	}
8914 8915
}

8916
/* toggle speaker-output according to the hp-jack state */
8917
static void alc883_2ch_fujitsu_pi2515_setup(struct hda_codec *codec)
8918
{
8919
	struct alc_spec *spec = codec->spec;
8920

8921 8922
	spec->autocfg.hp_pins[0] = 0x14;
	spec->autocfg.speaker_pins[0] = 0x15;
8923 8924
}

8925
static void alc883_haier_w66_setup(struct hda_codec *codec)
8926
{
8927
	struct alc_spec *spec = codec->spec;
8928

8929 8930
	spec->autocfg.hp_pins[0] = 0x1b;
	spec->autocfg.speaker_pins[0] = 0x14;
8931 8932
}

8933 8934
static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
{
8935
	int bits = snd_hda_jack_detect(codec, 0x14) ? HDA_AMP_MUTE : 0;
8936

8937 8938
	snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, bits);
8939 8940 8941 8942
}

static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
{
8943
	int bits = snd_hda_jack_detect(codec, 0x1b) ? HDA_AMP_MUTE : 0;
8944

8945 8946 8947 8948
	snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, bits);
	snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, bits);
8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959
}

static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
					   unsigned int res)
{
	if ((res >> 26) == ALC880_HP_EVENT)
		alc883_lenovo_101e_all_automute(codec);
	if ((res >> 26) == ALC880_FRONT_EVENT)
		alc883_lenovo_101e_ispeaker_automute(codec);
}

8960
/* toggle speaker-output according to the hp-jack state */
8961
static void alc883_acer_aspire_setup(struct hda_codec *codec)
8962
{
8963
	struct alc_spec *spec = codec->spec;
8964

8965 8966 8967
	spec->autocfg.hp_pins[0] = 0x14;
	spec->autocfg.speaker_pins[0] = 0x15;
	spec->autocfg.speaker_pins[1] = 0x16;
8968 8969
}

8970 8971 8972 8973 8974 8975
static struct hda_verb alc883_acer_eapd_verbs[] = {
	/* HP Pin: output 0 (0x0c) */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* Front Pin: output 0 (0x0c) */
8976 8977
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8978 8979 8980 8981 8982
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
        /* eanable EAPD on medion laptop */
	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
	{0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8983 8984
	/* enable unsolicited event */
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8985 8986 8987
	{ }
};

8988 8989 8990 8991 8992 8993 8994
static struct hda_verb alc888_acer_aspire_7730G_verbs[] = {
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{ } /* end */
};

8995
static void alc888_6st_dell_setup(struct hda_codec *codec)
8996
{
8997
	struct alc_spec *spec = codec->spec;
8998

8999 9000 9001 9002 9003
	spec->autocfg.hp_pins[0] = 0x1b;
	spec->autocfg.speaker_pins[0] = 0x14;
	spec->autocfg.speaker_pins[1] = 0x15;
	spec->autocfg.speaker_pins[2] = 0x16;
	spec->autocfg.speaker_pins[3] = 0x17;
9004 9005
}

9006
static void alc888_lenovo_sky_setup(struct hda_codec *codec)
9007
{
9008
	struct alc_spec *spec = codec->spec;
9009

9010 9011 9012 9013 9014 9015
	spec->autocfg.hp_pins[0] = 0x1b;
	spec->autocfg.speaker_pins[0] = 0x14;
	spec->autocfg.speaker_pins[1] = 0x15;
	spec->autocfg.speaker_pins[2] = 0x16;
	spec->autocfg.speaker_pins[3] = 0x17;
	spec->autocfg.speaker_pins[4] = 0x1a;
9016 9017
}

9018
static void alc883_vaiott_setup(struct hda_codec *codec)
G
Guido Günther 已提交
9019 9020 9021 9022 9023 9024 9025 9026
{
	struct alc_spec *spec = codec->spec;

	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
	spec->autocfg.speaker_pins[1] = 0x17;
}

9027 9028 9029 9030 9031 9032 9033 9034 9035 9036
static struct hda_verb alc888_asus_m90v_verbs[] = {
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	/* enable unsolicited event */
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
	{ } /* end */
};

9037
static void alc883_mode2_setup(struct hda_codec *codec)
9038
{
9039
	struct alc_spec *spec = codec->spec;
9040

9041 9042 9043 9044
	spec->autocfg.hp_pins[0] = 0x1b;
	spec->autocfg.speaker_pins[0] = 0x14;
	spec->autocfg.speaker_pins[1] = 0x15;
	spec->autocfg.speaker_pins[2] = 0x16;
9045 9046 9047 9048 9049
	spec->ext_mic.pin = 0x18;
	spec->int_mic.pin = 0x19;
	spec->ext_mic.mux_idx = 0;
	spec->int_mic.mux_idx = 1;
	spec->auto_mic = 1;
9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066
}

static struct hda_verb alc888_asus_eee1601_verbs[] = {
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
	{0x20, AC_VERB_SET_PROC_COEF,  0x0838},
	/* enable unsolicited event */
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{ } /* end */
};

static void alc883_eee1601_inithook(struct hda_codec *codec)
{
9067 9068 9069 9070 9071
	struct alc_spec *spec = codec->spec;

	spec->autocfg.hp_pins[0] = 0x14;
	spec->autocfg.speaker_pins[0] = 0x1b;
	alc_automute_pin(codec);
9072 9073
}

9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094
static struct hda_verb alc889A_mb31_verbs[] = {
	/* Init rear pin (used as headphone output) */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},    /* Apple Headphones */
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},           /* Connect to front */
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	/* Init line pin (used as output in 4ch and 6ch mode) */
	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},           /* Connect to CLFE */
	/* Init line 2 pin (used as headphone out by default) */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},  /* Use as input */
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Mute output */
	{ } /* end */
};

/* Mute speakers according to the headphone jack state */
static void alc889A_mb31_automute(struct hda_codec *codec)
{
	unsigned int present;

	/* Mute only in 2ch or 4ch mode */
	if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
	    == 0x00) {
9095
		present = snd_hda_jack_detect(codec, 0x15);
9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108
		snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
			HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
		snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
			HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
	}
}

static void alc889A_mb31_unsol_event(struct hda_codec *codec, unsigned int res)
{
	if ((res >> 26) == ALC880_HP_EVENT)
		alc889A_mb31_automute(codec);
}

9109

9110
#ifdef CONFIG_SND_HDA_POWER_SAVE
9111
#define alc882_loopbacks	alc880_loopbacks
9112 9113
#endif

9114
/* pcm configuration: identical with ALC880 */
9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126
#define alc882_pcm_analog_playback	alc880_pcm_analog_playback
#define alc882_pcm_analog_capture	alc880_pcm_analog_capture
#define alc882_pcm_digital_playback	alc880_pcm_digital_playback
#define alc882_pcm_digital_capture	alc880_pcm_digital_capture

static hda_nid_t alc883_slave_dig_outs[] = {
	ALC1200_DIGOUT_NID, 0,
};

static hda_nid_t alc1200_slave_dig_outs[] = {
	ALC883_DIGOUT_NID, 0,
};
9127 9128 9129 9130

/*
 * configuration and preset
 */
9131 9132 9133 9134 9135 9136 9137 9138 9139 9140
static const char *alc882_models[ALC882_MODEL_LAST] = {
	[ALC882_3ST_DIG]	= "3stack-dig",
	[ALC882_6ST_DIG]	= "6stack-dig",
	[ALC882_ARIMA]		= "arima",
	[ALC882_W2JC]		= "w2jc",
	[ALC882_TARGA]		= "targa",
	[ALC882_ASUS_A7J]	= "asus-a7j",
	[ALC882_ASUS_A7M]	= "asus-a7m",
	[ALC885_MACPRO]		= "macpro",
	[ALC885_MB5]		= "mb5",
9141
	[ALC885_MACMINI3]	= "macmini3",
9142
	[ALC885_MBA21]		= "mba21",
9143 9144
	[ALC885_MBP3]		= "mbp3",
	[ALC885_IMAC24]		= "imac24",
9145
	[ALC885_IMAC91]		= "imac91",
9146
	[ALC883_3ST_2ch_DIG]	= "3stack-2ch-dig",
9147 9148
	[ALC883_3ST_6ch_DIG]	= "3stack-6ch-dig",
	[ALC883_3ST_6ch]	= "3stack-6ch",
9149
	[ALC883_6ST_DIG]	= "alc883-6stack-dig",
9150 9151
	[ALC883_TARGA_DIG]	= "targa-dig",
	[ALC883_TARGA_2ch_DIG]	= "targa-2ch-dig",
9152
	[ALC883_TARGA_8ch_DIG]	= "targa-8ch-dig",
9153
	[ALC883_ACER]		= "acer",
9154
	[ALC883_ACER_ASPIRE]	= "acer-aspire",
9155
	[ALC888_ACER_ASPIRE_4930G]	= "acer-aspire-4930g",
9156
	[ALC888_ACER_ASPIRE_6530G]	= "acer-aspire-6530g",
9157
	[ALC888_ACER_ASPIRE_8930G]	= "acer-aspire-8930g",
9158
	[ALC888_ACER_ASPIRE_7730G]	= "acer-aspire-7730g",
9159
	[ALC883_MEDION]		= "medion",
9160
	[ALC883_MEDION_MD2]	= "medion-md2",
9161
	[ALC883_LAPTOP_EAPD]	= "laptop-eapd",
9162
	[ALC883_LENOVO_101E_2ch] = "lenovo-101e",
9163 9164
	[ALC883_LENOVO_NB0763]	= "lenovo-nb0763",
	[ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
9165
	[ALC888_LENOVO_SKY] = "lenovo-sky",
9166
	[ALC883_HAIER_W66] 	= "haier-w66",
9167
	[ALC888_3ST_HP]		= "3stack-hp",
9168
	[ALC888_6ST_DELL]	= "6stack-dell",
9169
	[ALC883_MITAC]		= "mitac",
9170
	[ALC883_CLEVO_M540R]	= "clevo-m540r",
9171
	[ALC883_CLEVO_M720]	= "clevo-m720",
9172
	[ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
9173
	[ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
9174
	[ALC883_3ST_6ch_INTEL]	= "3stack-6ch-intel",
9175 9176
	[ALC889A_INTEL]		= "intel-alc889a",
	[ALC889_INTEL]		= "intel-x58",
9177
	[ALC1200_ASUS_P5Q]	= "asus-p5q",
9178
	[ALC889A_MB31]		= "mb31",
G
Guido Günther 已提交
9179
	[ALC883_SONY_VAIO_TT]	= "sony-vaio-tt",
9180
	[ALC882_AUTO]		= "auto",
9181 9182
};

9183 9184 9185
static struct snd_pci_quirk alc882_cfg_tbl[] = {
	SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),

9186
	SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
9187
	SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
9188
	SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
9189 9190
	SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
	SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
9191
	SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
9192 9193
	SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
		ALC888_ACER_ASPIRE_4930G),
9194
	SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
9195
		ALC888_ACER_ASPIRE_4930G),
9196 9197
	SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
		ALC888_ACER_ASPIRE_8930G),
9198 9199
	SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
		ALC888_ACER_ASPIRE_8930G),
9200 9201
	SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC882_AUTO),
	SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC882_AUTO),
9202
	SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
9203
		ALC888_ACER_ASPIRE_6530G),
9204
	SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
9205
		ALC888_ACER_ASPIRE_6530G),
9206 9207
	SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
		ALC888_ACER_ASPIRE_7730G),
9208 9209 9210 9211
	/* default Acer -- disabled as it causes more problems.
	 *    model=auto should work fine now
	 */
	/* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */
9212

9213
	SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
9214

9215
	SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
9216 9217
	SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
	SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
9218
	SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
9219
	SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
9220
	SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
9221 9222 9223 9224

	SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
	SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
	SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
9225
	SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
9226 9227 9228
	SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
	SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
	SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
9229
	SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
9230
	SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
9231
	SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
9232
	SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
9233 9234

	SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
9235
	SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
9236
	SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
9237
	SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
9238 9239
	SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
	SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
9240
	SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
9241
	SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
9242 9243
	SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),

9244
	SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
9245
	SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
9246
	SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
9247
	SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
9248
	SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC882_AUTO),
9249
	SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
9250
	SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
9251
	SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
9252
	SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
9253
	SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
9254 9255
	SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
	SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
9256
	SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
9257
	SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
9258
	SND_PCI_QUIRK(0x1462, 0x42cd, "MSI", ALC883_TARGA_DIG),
9259 9260 9261
	SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
	SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
	SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
9262
	SND_PCI_QUIRK(0x1462, 0x4570, "MSI Wind Top AE2220", ALC883_TARGA_DIG),
9263
	SND_PCI_QUIRK(0x1462, 0x6510, "MSI GX620", ALC883_TARGA_8ch_DIG),
9264 9265 9266
	SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
	SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
	SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
9267
	SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
9268
	SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
9269 9270
	SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
	SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
9271
	SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG),
9272
	SND_PCI_QUIRK(0x1462, 0x7437, "MSI NetOn AP1900", ALC883_TARGA_DIG),
9273
	SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
9274
	SND_PCI_QUIRK(0x1462, 0xaa08, "MSI", ALC883_TARGA_2ch_DIG),
9275

9276
	SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
9277 9278
	SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
	SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
9279
	SND_PCI_QUIRK(0x1558, 0x5409, "Clevo laptop M540R", ALC883_CLEVO_M540R),
T
Takashi Iwai 已提交
9280
	SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
9281
	SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
9282
	/* SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA), */
9283
	SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
9284
	SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
9285
		      ALC883_FUJITSU_PI2515),
9286
	SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1130, "Fujitsu AMILO Xa35xx",
9287
		ALC888_FUJITSU_XA3530),
9288 9289
	SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
	SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
9290 9291
	SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
	SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
9292
	SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
9293
	SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
9294
	SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
9295
	SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
9296
	SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
9297

9298 9299
	SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
	SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
9300
	SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
9301 9302 9303
	SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_INTEL),
	SND_PCI_QUIRK(0x8086, 0x0021, "Intel IbexPeak", ALC889A_INTEL),
	SND_PCI_QUIRK(0x8086, 0x3b56, "Intel IbexPeak", ALC889A_INTEL),
9304
	SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC882_6ST_DIG),
9305

9306
	{}
9307 9308
};

9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320
/* codec SSID table for Intel Mac */
static struct snd_pci_quirk alc882_ssid_cfg_tbl[] = {
	SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC885_MBP3),
	SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC885_MBP3),
	SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC885_MBP3),
	SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_MACPRO),
	SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_IMAC24),
	SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_IMAC24),
	SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC885_MBP3),
	SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31),
	SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3),
	SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24),
9321
	SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC885_IMAC91),
9322
	SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5),
9323 9324
	/* FIXME: HP jack sense seems not working for MBP 5,1 or 5,2,
	 * so apparently no perfect solution yet
9325 9326
	 */
	SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC885_MB5),
9327
	SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC885_MB5),
9328
	SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC885_MACMINI3),
9329
	{} /* terminator */
9330 9331
};

9332 9333 9334
static struct alc_config_preset alc882_presets[] = {
	[ALC882_3ST_DIG] = {
		.mixers = { alc882_base_mixer },
9335 9336
		.init_verbs = { alc882_base_init_verbs,
				alc882_adc1_init_verbs },
9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347
		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
		.dac_nids = alc882_dac_nids,
		.dig_out_nid = ALC882_DIGOUT_NID,
		.dig_in_nid = ALC882_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
		.channel_mode = alc882_ch_modes,
		.need_dac_fix = 1,
		.input_mux = &alc882_capture_source,
	},
	[ALC882_6ST_DIG] = {
		.mixers = { alc882_base_mixer, alc882_chmode_mixer },
9348 9349
		.init_verbs = { alc882_base_init_verbs,
				alc882_adc1_init_verbs },
9350 9351 9352 9353 9354 9355 9356 9357 9358 9359
		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
		.dac_nids = alc882_dac_nids,
		.dig_out_nid = ALC882_DIGOUT_NID,
		.dig_in_nid = ALC882_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
		.channel_mode = alc882_sixstack_modes,
		.input_mux = &alc882_capture_source,
	},
	[ALC882_ARIMA] = {
		.mixers = { alc882_base_mixer, alc882_chmode_mixer },
9360 9361
		.init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
				alc882_eapd_verbs },
9362 9363 9364 9365 9366 9367 9368 9369
		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
		.dac_nids = alc882_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
		.channel_mode = alc882_sixstack_modes,
		.input_mux = &alc882_capture_source,
	},
	[ALC882_W2JC] = {
		.mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
9370 9371
		.init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
				alc882_eapd_verbs, alc880_gpio1_init_verbs },
9372 9373 9374 9375 9376 9377 9378 9379
		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
		.dac_nids = alc882_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
		.channel_mode = alc880_threestack_modes,
		.need_dac_fix = 1,
		.input_mux = &alc882_capture_source,
		.dig_out_nid = ALC882_DIGOUT_NID,
	},
9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391
	   [ALC885_MBA21] = {
			.mixers = { alc885_mba21_mixer },
			.init_verbs = { alc885_mba21_init_verbs, alc880_gpio1_init_verbs },
			.num_dacs = 2,
			.dac_nids = alc882_dac_nids,
			.channel_mode = alc885_mba21_ch_modes,
			.num_channel_mode = ARRAY_SIZE(alc885_mba21_ch_modes),
			.input_mux = &alc882_capture_source,
			.unsol_event = alc_automute_amp_unsol_event,
			.setup = alc885_mba21_setup,
			.init_hook = alc_automute_amp,
       },
9392 9393 9394 9395
	[ALC885_MBP3] = {
		.mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
		.init_verbs = { alc885_mbp3_init_verbs,
				alc880_gpio1_init_verbs },
9396
		.num_dacs = 2,
9397
		.dac_nids = alc882_dac_nids,
9398 9399 9400
		.hp_nid = 0x04,
		.channel_mode = alc885_mbp_4ch_modes,
		.num_channel_mode = ARRAY_SIZE(alc885_mbp_4ch_modes),
9401 9402 9403 9404
		.input_mux = &alc882_capture_source,
		.dig_out_nid = ALC882_DIGOUT_NID,
		.dig_in_nid = ALC882_DIGIN_NID,
		.unsol_event = alc_automute_amp_unsol_event,
9405 9406
		.setup = alc885_mbp3_setup,
		.init_hook = alc_automute_amp,
9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418
	},
	[ALC885_MB5] = {
		.mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
		.init_verbs = { alc885_mb5_init_verbs,
				alc880_gpio1_init_verbs },
		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
		.dac_nids = alc882_dac_nids,
		.channel_mode = alc885_mb5_6ch_modes,
		.num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
		.input_mux = &mb5_capture_source,
		.dig_out_nid = ALC882_DIGOUT_NID,
		.dig_in_nid = ALC882_DIGIN_NID,
9419 9420 9421
		.unsol_event = alc_automute_amp_unsol_event,
		.setup = alc885_mb5_setup,
		.init_hook = alc_automute_amp,
9422
	},
9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433
	[ALC885_MACMINI3] = {
		.mixers = { alc885_macmini3_mixer, alc882_chmode_mixer },
		.init_verbs = { alc885_macmini3_init_verbs,
				alc880_gpio1_init_verbs },
		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
		.dac_nids = alc882_dac_nids,
		.channel_mode = alc885_macmini3_6ch_modes,
		.num_channel_mode = ARRAY_SIZE(alc885_macmini3_6ch_modes),
		.input_mux = &macmini3_capture_source,
		.dig_out_nid = ALC882_DIGOUT_NID,
		.dig_in_nid = ALC882_DIGIN_NID,
9434 9435 9436
		.unsol_event = alc_automute_amp_unsol_event,
		.setup = alc885_macmini3_setup,
		.init_hook = alc_automute_amp,
9437
	},
9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460
	[ALC885_MACPRO] = {
		.mixers = { alc882_macpro_mixer },
		.init_verbs = { alc882_macpro_init_verbs },
		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
		.dac_nids = alc882_dac_nids,
		.dig_out_nid = ALC882_DIGOUT_NID,
		.dig_in_nid = ALC882_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
		.channel_mode = alc882_ch_modes,
		.input_mux = &alc882_capture_source,
		.init_hook = alc885_macpro_init_hook,
	},
	[ALC885_IMAC24] = {
		.mixers = { alc885_imac24_mixer },
		.init_verbs = { alc885_imac24_init_verbs },
		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
		.dac_nids = alc882_dac_nids,
		.dig_out_nid = ALC882_DIGOUT_NID,
		.dig_in_nid = ALC882_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
		.channel_mode = alc882_ch_modes,
		.input_mux = &alc882_capture_source,
		.unsol_event = alc_automute_amp_unsol_event,
9461
		.setup = alc885_imac24_setup,
9462 9463
		.init_hook = alc885_imac24_init_hook,
	},
9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474
	[ALC885_IMAC91] = {
		.mixers = { alc885_imac91_mixer, alc882_chmode_mixer },
		.init_verbs = { alc885_imac91_init_verbs,
				alc880_gpio1_init_verbs },
		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
		.dac_nids = alc882_dac_nids,
		.channel_mode = alc885_mbp_4ch_modes,
		.num_channel_mode = ARRAY_SIZE(alc885_mbp_4ch_modes),
		.input_mux = &alc882_capture_source,
		.dig_out_nid = ALC882_DIGOUT_NID,
		.dig_in_nid = ALC882_DIGIN_NID,
9475 9476 9477
		.unsol_event = alc_automute_amp_unsol_event,
		.setup = alc885_imac91_setup,
		.init_hook = alc_automute_amp,
9478
	},
9479 9480
	[ALC882_TARGA] = {
		.mixers = { alc882_targa_mixer, alc882_chmode_mixer },
9481
		.init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
T
Takashi Iwai 已提交
9482
				alc880_gpio3_init_verbs, alc882_targa_verbs},
9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493
		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
		.dac_nids = alc882_dac_nids,
		.dig_out_nid = ALC882_DIGOUT_NID,
		.num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
		.adc_nids = alc882_adc_nids,
		.capsrc_nids = alc882_capsrc_nids,
		.num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
		.channel_mode = alc882_3ST_6ch_modes,
		.need_dac_fix = 1,
		.input_mux = &alc882_capture_source,
		.unsol_event = alc882_targa_unsol_event,
9494 9495
		.setup = alc882_targa_setup,
		.init_hook = alc882_targa_automute,
9496 9497 9498
	},
	[ALC882_ASUS_A7J] = {
		.mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
9499 9500
		.init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
				alc882_asus_a7j_verbs},
9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513
		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
		.dac_nids = alc882_dac_nids,
		.dig_out_nid = ALC882_DIGOUT_NID,
		.num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
		.adc_nids = alc882_adc_nids,
		.capsrc_nids = alc882_capsrc_nids,
		.num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
		.channel_mode = alc882_3ST_6ch_modes,
		.need_dac_fix = 1,
		.input_mux = &alc882_capture_source,
	},
	[ALC882_ASUS_A7M] = {
		.mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
9514 9515
		.init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
				alc882_eapd_verbs, alc880_gpio1_init_verbs,
9516 9517 9518 9519 9520 9521 9522 9523 9524
				alc882_asus_a7m_verbs },
		.num_dacs = ARRAY_SIZE(alc882_dac_nids),
		.dac_nids = alc882_dac_nids,
		.dig_out_nid = ALC882_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
		.channel_mode = alc880_threestack_modes,
		.need_dac_fix = 1,
		.input_mux = &alc882_capture_source,
	},
9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544
	[ALC883_3ST_2ch_DIG] = {
		.mixers = { alc883_3ST_2ch_mixer },
		.init_verbs = { alc883_init_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.dig_in_nid = ALC883_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.input_mux = &alc883_capture_source,
	},
	[ALC883_3ST_6ch_DIG] = {
		.mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
		.init_verbs = { alc883_init_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.dig_in_nid = ALC883_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
		.channel_mode = alc883_3ST_6ch_modes,
9545
		.need_dac_fix = 1,
9546
		.input_mux = &alc883_capture_source,
9547
	},
9548 9549 9550 9551 9552 9553 9554
	[ALC883_3ST_6ch] = {
		.mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
		.init_verbs = { alc883_init_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
		.channel_mode = alc883_3ST_6ch_modes,
9555
		.need_dac_fix = 1,
9556
		.input_mux = &alc883_capture_source,
9557
	},
9558 9559 9560 9561 9562 9563 9564
	[ALC883_3ST_6ch_INTEL] = {
		.mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
		.init_verbs = { alc883_init_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.dig_in_nid = ALC883_DIGIN_NID,
9565
		.slave_dig_outs = alc883_slave_dig_outs,
9566 9567 9568 9569 9570
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
		.channel_mode = alc883_3ST_6ch_intel_modes,
		.need_dac_fix = 1,
		.input_mux = &alc883_3stack_6ch_intel,
	},
9571 9572
	[ALC889A_INTEL] = {
		.mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9573 9574
		.init_verbs = { alc885_init_verbs, alc885_init_input_verbs,
				alc_hp15_unsol_verbs },
9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
		.adc_nids = alc889_adc_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.dig_in_nid = ALC883_DIGIN_NID,
		.slave_dig_outs = alc883_slave_dig_outs,
		.num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
		.channel_mode = alc889_8ch_intel_modes,
		.capsrc_nids = alc889_capsrc_nids,
		.input_mux = &alc889_capture_source,
9586 9587
		.setup = alc889_automute_setup,
		.init_hook = alc_automute_amp,
9588
		.unsol_event = alc_automute_amp_unsol_event,
9589 9590 9591 9592 9593
		.need_dac_fix = 1,
	},
	[ALC889_INTEL] = {
		.mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
		.init_verbs = { alc885_init_verbs, alc889_init_input_verbs,
9594
				alc889_eapd_verbs, alc_hp15_unsol_verbs},
9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
		.adc_nids = alc889_adc_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.dig_in_nid = ALC883_DIGIN_NID,
		.slave_dig_outs = alc883_slave_dig_outs,
		.num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
		.channel_mode = alc889_8ch_intel_modes,
		.capsrc_nids = alc889_capsrc_nids,
		.input_mux = &alc889_capture_source,
9606
		.setup = alc889_automute_setup,
9607 9608
		.init_hook = alc889_intel_init_hook,
		.unsol_event = alc_automute_amp_unsol_event,
9609 9610
		.need_dac_fix = 1,
	},
9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621
	[ALC883_6ST_DIG] = {
		.mixers = { alc883_base_mixer, alc883_chmode_mixer },
		.init_verbs = { alc883_init_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.dig_in_nid = ALC883_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
		.channel_mode = alc883_sixstack_modes,
		.input_mux = &alc883_capture_source,
	},
9622
	[ALC883_TARGA_DIG] = {
9623
		.mixers = { alc883_targa_mixer, alc883_chmode_mixer },
9624 9625
		.init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
				alc883_targa_verbs},
9626 9627 9628 9629 9630 9631 9632
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
		.channel_mode = alc883_3ST_6ch_modes,
		.need_dac_fix = 1,
		.input_mux = &alc883_capture_source,
9633
		.unsol_event = alc883_targa_unsol_event,
9634 9635
		.setup = alc882_targa_setup,
		.init_hook = alc882_targa_automute,
9636 9637
	},
	[ALC883_TARGA_2ch_DIG] = {
9638
		.mixers = { alc883_targa_2ch_mixer},
9639 9640
		.init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
				alc883_targa_verbs},
9641 9642
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
9643 9644
		.adc_nids = alc883_adc_nids_alt,
		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9645
		.capsrc_nids = alc883_capsrc_nids,
9646 9647 9648 9649
		.dig_out_nid = ALC883_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.input_mux = &alc883_capture_source,
9650
		.unsol_event = alc883_targa_unsol_event,
9651 9652
		.setup = alc882_targa_setup,
		.init_hook = alc882_targa_automute,
9653
	},
9654
	[ALC883_TARGA_8ch_DIG] = {
T
Takashi Iwai 已提交
9655 9656
		.mixers = { alc883_targa_mixer, alc883_targa_8ch_mixer,
			    alc883_chmode_mixer },
9657
		.init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9658
				alc883_targa_verbs },
9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
		.adc_nids = alc883_adc_nids_rev,
		.capsrc_nids = alc883_capsrc_nids_rev,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.dig_in_nid = ALC883_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_4ST_8ch_modes),
		.channel_mode = alc883_4ST_8ch_modes,
		.need_dac_fix = 1,
		.input_mux = &alc883_capture_source,
9670
		.unsol_event = alc883_targa_unsol_event,
9671 9672
		.setup = alc882_targa_setup,
		.init_hook = alc882_targa_automute,
9673
	},
9674
	[ALC883_ACER] = {
9675
		.mixers = { alc883_base_mixer },
9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687
		/* On TravelMate laptops, GPIO 0 enables the internal speaker
		 * and the headphone jack.  Turn this on and rely on the
		 * standard mute methods whenever the user wants to turn
		 * these outputs off.
		 */
		.init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.input_mux = &alc883_capture_source,
	},
9688
	[ALC883_ACER_ASPIRE] = {
9689
		.mixers = { alc883_acer_aspire_mixer },
9690
		.init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
9691 9692 9693 9694 9695 9696
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.input_mux = &alc883_capture_source,
9697
		.unsol_event = alc_automute_amp_unsol_event,
9698 9699
		.setup = alc883_acer_aspire_setup,
		.init_hook = alc_automute_amp,
9700
	},
9701
	[ALC888_ACER_ASPIRE_4930G] = {
9702
		.mixers = { alc888_base_mixer,
9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714
				alc883_chmode_mixer },
		.init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
				alc888_acer_aspire_4930g_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
		.adc_nids = alc883_adc_nids_rev,
		.capsrc_nids = alc883_capsrc_nids_rev,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
		.channel_mode = alc883_3ST_6ch_modes,
		.need_dac_fix = 1,
9715
		.const_channel_count = 6,
9716
		.num_mux_defs =
9717 9718
			ARRAY_SIZE(alc888_2_capture_sources),
		.input_mux = alc888_2_capture_sources,
9719
		.unsol_event = alc_automute_amp_unsol_event,
9720 9721
		.setup = alc888_acer_aspire_4930g_setup,
		.init_hook = alc_automute_amp,
9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737
	},
	[ALC888_ACER_ASPIRE_6530G] = {
		.mixers = { alc888_acer_aspire_6530_mixer },
		.init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
				alc888_acer_aspire_6530g_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
		.adc_nids = alc883_adc_nids_rev,
		.capsrc_nids = alc883_capsrc_nids_rev,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.num_mux_defs =
			ARRAY_SIZE(alc888_2_capture_sources),
		.input_mux = alc888_acer_aspire_6530_sources,
9738
		.unsol_event = alc_automute_amp_unsol_event,
9739 9740
		.setup = alc888_acer_aspire_6530g_setup,
		.init_hook = alc_automute_amp,
9741
	},
9742
	[ALC888_ACER_ASPIRE_8930G] = {
9743
		.mixers = { alc889_acer_aspire_8930g_mixer,
9744 9745
				alc883_chmode_mixer },
		.init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9746 9747
				alc889_acer_aspire_8930g_verbs,
				alc889_eapd_verbs},
9748 9749
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
9750 9751 9752
		.num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
		.adc_nids = alc889_adc_nids,
		.capsrc_nids = alc889_capsrc_nids,
9753 9754 9755 9756 9757 9758
		.dig_out_nid = ALC883_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
		.channel_mode = alc883_3ST_6ch_modes,
		.need_dac_fix = 1,
		.const_channel_count = 6,
		.num_mux_defs =
9759 9760
			ARRAY_SIZE(alc889_capture_sources),
		.input_mux = alc889_capture_sources,
9761
		.unsol_event = alc_automute_amp_unsol_event,
9762 9763
		.setup = alc889_acer_aspire_8930g_setup,
		.init_hook = alc_automute_amp,
9764
#ifdef CONFIG_SND_HDA_POWER_SAVE
9765
		.power_hook = alc_power_eapd,
9766
#endif
9767
	},
9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787
	[ALC888_ACER_ASPIRE_7730G] = {
		.mixers = { alc883_3ST_6ch_mixer,
				alc883_chmode_mixer },
		.init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
				alc888_acer_aspire_7730G_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
		.adc_nids = alc883_adc_nids_rev,
		.capsrc_nids = alc883_capsrc_nids_rev,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
		.channel_mode = alc883_3ST_6ch_modes,
		.need_dac_fix = 1,
		.const_channel_count = 6,
		.input_mux = &alc883_capture_source,
		.unsol_event = alc_automute_amp_unsol_event,
		.setup = alc888_acer_aspire_6530g_setup,
		.init_hook = alc_automute_amp,
	},
9788 9789 9790 9791
	[ALC883_MEDION] = {
		.mixers = { alc883_fivestack_mixer,
			    alc883_chmode_mixer },
		.init_verbs = { alc883_init_verbs,
9792
				alc883_medion_eapd_verbs },
9793 9794
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
9795 9796
		.adc_nids = alc883_adc_nids_alt,
		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9797
		.capsrc_nids = alc883_capsrc_nids,
9798 9799 9800
		.num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
		.channel_mode = alc883_sixstack_modes,
		.input_mux = &alc883_capture_source,
9801
	},
9802 9803 9804 9805 9806 9807 9808 9809 9810
	[ALC883_MEDION_MD2] = {
		.mixers = { alc883_medion_md2_mixer},
		.init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.input_mux = &alc883_capture_source,
9811
		.unsol_event = alc_automute_amp_unsol_event,
9812 9813
		.setup = alc883_medion_md2_setup,
		.init_hook = alc_automute_amp,
9814
	},
9815
	[ALC883_LAPTOP_EAPD] = {
9816
		.mixers = { alc883_base_mixer },
9817 9818 9819 9820 9821 9822 9823
		.init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.input_mux = &alc883_capture_source,
	},
9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838
	[ALC883_CLEVO_M540R] = {
		.mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
		.init_verbs = { alc883_init_verbs, alc883_clevo_m540r_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.dig_in_nid = ALC883_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_clevo_modes),
		.channel_mode = alc883_3ST_6ch_clevo_modes,
		.need_dac_fix = 1,
		.input_mux = &alc883_capture_source,
		/* This machine has the hardware HP auto-muting, thus
		 * we need no software mute via unsol event
		 */
	},
9839 9840 9841
	[ALC883_CLEVO_M720] = {
		.mixers = { alc883_clevo_m720_mixer },
		.init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
9842 9843 9844 9845 9846 9847
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.input_mux = &alc883_capture_source,
9848
		.unsol_event = alc883_clevo_m720_unsol_event,
9849
		.setup = alc883_clevo_m720_setup,
9850
		.init_hook = alc883_clevo_m720_init_hook,
9851
	},
9852 9853 9854 9855 9856
	[ALC883_LENOVO_101E_2ch] = {
		.mixers = { alc883_lenovo_101e_2ch_mixer},
		.init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
9857 9858
		.adc_nids = alc883_adc_nids_alt,
		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9859
		.capsrc_nids = alc883_capsrc_nids,
9860 9861 9862 9863 9864 9865
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.input_mux = &alc883_lenovo_101e_capture_source,
		.unsol_event = alc883_lenovo_101e_unsol_event,
		.init_hook = alc883_lenovo_101e_all_automute,
	},
9866 9867 9868 9869 9870 9871 9872 9873 9874
	[ALC883_LENOVO_NB0763] = {
		.mixers = { alc883_lenovo_nb0763_mixer },
		.init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.need_dac_fix = 1,
		.input_mux = &alc883_lenovo_nb0763_capture_source,
9875
		.unsol_event = alc_automute_amp_unsol_event,
9876 9877
		.setup = alc883_medion_md2_setup,
		.init_hook = alc_automute_amp,
9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890
	},
	[ALC888_LENOVO_MS7195_DIG] = {
		.mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
		.init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
		.channel_mode = alc883_3ST_6ch_modes,
		.need_dac_fix = 1,
		.input_mux = &alc883_capture_source,
		.unsol_event = alc883_lenovo_ms7195_unsol_event,
		.init_hook = alc888_lenovo_ms7195_front_automute,
9891 9892
	},
	[ALC883_HAIER_W66] = {
9893
		.mixers = { alc883_targa_2ch_mixer},
9894 9895 9896 9897 9898 9899 9900
		.init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.input_mux = &alc883_capture_source,
9901
		.unsol_event = alc_automute_amp_unsol_event,
9902 9903
		.setup = alc883_haier_w66_setup,
		.init_hook = alc_automute_amp,
9904
	},
9905
	[ALC888_3ST_HP] = {
9906
		.mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9907
		.init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
9908 9909
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
9910 9911
		.num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
		.channel_mode = alc888_3st_hp_modes,
9912 9913
		.need_dac_fix = 1,
		.input_mux = &alc883_capture_source,
9914
		.unsol_event = alc_automute_amp_unsol_event,
9915 9916
		.setup = alc888_3st_hp_setup,
		.init_hook = alc_automute_amp,
9917
	},
9918
	[ALC888_6ST_DELL] = {
9919
		.mixers = { alc883_base_mixer, alc883_chmode_mixer },
9920 9921 9922 9923 9924 9925 9926 9927
		.init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.dig_in_nid = ALC883_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
		.channel_mode = alc883_sixstack_modes,
		.input_mux = &alc883_capture_source,
9928
		.unsol_event = alc_automute_amp_unsol_event,
9929 9930
		.setup = alc888_6st_dell_setup,
		.init_hook = alc_automute_amp,
9931
	},
9932 9933 9934 9935 9936 9937 9938 9939
	[ALC883_MITAC] = {
		.mixers = { alc883_mitac_mixer },
		.init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.input_mux = &alc883_capture_source,
9940
		.unsol_event = alc_automute_amp_unsol_event,
9941 9942
		.setup = alc883_mitac_setup,
		.init_hook = alc_automute_amp,
9943
	},
9944 9945 9946 9947 9948 9949 9950 9951 9952 9953
	[ALC883_FUJITSU_PI2515] = {
		.mixers = { alc883_2ch_fujitsu_pi2515_mixer },
		.init_verbs = { alc883_init_verbs,
				alc883_2ch_fujitsu_pi2515_verbs},
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.input_mux = &alc883_fujitsu_pi2515_capture_source,
9954
		.unsol_event = alc_automute_amp_unsol_event,
9955 9956
		.setup = alc883_2ch_fujitsu_pi2515_setup,
		.init_hook = alc_automute_amp,
9957
	},
9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972
	[ALC888_FUJITSU_XA3530] = {
		.mixers = { alc888_base_mixer, alc883_chmode_mixer },
		.init_verbs = { alc883_init_verbs,
			alc888_fujitsu_xa3530_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
		.adc_nids = alc883_adc_nids_rev,
		.capsrc_nids = alc883_capsrc_nids_rev,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
		.channel_mode = alc888_4ST_8ch_intel_modes,
		.num_mux_defs =
			ARRAY_SIZE(alc888_2_capture_sources),
		.input_mux = alc888_2_capture_sources,
9973
		.unsol_event = alc_automute_amp_unsol_event,
9974 9975
		.setup = alc888_fujitsu_xa3530_setup,
		.init_hook = alc_automute_amp,
9976
	},
9977 9978 9979 9980 9981 9982 9983 9984 9985 9986
	[ALC888_LENOVO_SKY] = {
		.mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
		.init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
		.channel_mode = alc883_sixstack_modes,
		.need_dac_fix = 1,
		.input_mux = &alc883_lenovo_sky_capture_source,
9987
		.unsol_event = alc_automute_amp_unsol_event,
9988 9989
		.setup = alc888_lenovo_sky_setup,
		.init_hook = alc_automute_amp,
9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001
	},
	[ALC888_ASUS_M90V] = {
		.mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
		.init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.dig_in_nid = ALC883_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
		.channel_mode = alc883_3ST_6ch_modes,
		.need_dac_fix = 1,
		.input_mux = &alc883_fujitsu_pi2515_capture_source,
10002 10003 10004
		.unsol_event = alc_sku_unsol_event,
		.setup = alc883_mode2_setup,
		.init_hook = alc_inithook,
10005 10006 10007
	},
	[ALC888_ASUS_EEE1601] = {
		.mixers = { alc883_asus_eee1601_mixer },
10008
		.cap_mixer = alc883_asus_eee1601_cap_mixer,
10009 10010 10011 10012 10013 10014 10015 10016 10017
		.init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.dig_in_nid = ALC883_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.need_dac_fix = 1,
		.input_mux = &alc883_asus_eee1601_capture_source,
10018
		.unsol_event = alc_sku_unsol_event,
10019 10020
		.init_hook = alc883_eee1601_inithook,
	},
10021 10022 10023 10024 10025 10026 10027
	[ALC1200_ASUS_P5Q] = {
		.mixers = { alc883_base_mixer, alc883_chmode_mixer },
		.init_verbs = { alc883_init_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.dig_out_nid = ALC1200_DIGOUT_NID,
		.dig_in_nid = ALC883_DIGIN_NID,
10028
		.slave_dig_outs = alc1200_slave_dig_outs,
10029 10030 10031 10032
		.num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
		.channel_mode = alc883_sixstack_modes,
		.input_mux = &alc883_capture_source,
	},
10033 10034 10035 10036 10037 10038
	[ALC889A_MB31] = {
		.mixers = { alc889A_mb31_mixer, alc883_chmode_mixer},
		.init_verbs = { alc883_init_verbs, alc889A_mb31_verbs,
			alc880_gpio1_init_verbs },
		.adc_nids = alc883_adc_nids,
		.num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
10039
		.capsrc_nids = alc883_capsrc_nids,
10040 10041 10042 10043 10044 10045 10046 10047 10048
		.dac_nids = alc883_dac_nids,
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.channel_mode = alc889A_mb31_6ch_modes,
		.num_channel_mode = ARRAY_SIZE(alc889A_mb31_6ch_modes),
		.input_mux = &alc889A_mb31_capture_source,
		.dig_out_nid = ALC883_DIGOUT_NID,
		.unsol_event = alc889A_mb31_unsol_event,
		.init_hook = alc889A_mb31_automute,
	},
G
Guido Günther 已提交
10049 10050 10051 10052 10053 10054 10055 10056 10057
	[ALC883_SONY_VAIO_TT] = {
		.mixers = { alc883_vaiott_mixer },
		.init_verbs = { alc883_init_verbs, alc883_vaiott_verbs },
		.num_dacs = ARRAY_SIZE(alc883_dac_nids),
		.dac_nids = alc883_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.input_mux = &alc883_capture_source,
		.unsol_event = alc_automute_amp_unsol_event,
10058 10059
		.setup = alc883_vaiott_setup,
		.init_hook = alc_automute_amp,
G
Guido Günther 已提交
10060
	},
10061 10062 10063
};


10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077
/*
 * Pin config fixes
 */
enum {
	PINFIX_ABIT_AW9D_MAX
};

static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
	{ 0x15, 0x01080104 }, /* side */
	{ 0x16, 0x01011012 }, /* rear */
	{ 0x17, 0x01016011 }, /* clfe */
	{ }
};

10078 10079 10080 10081
static const struct alc_fixup alc882_fixups[] = {
	[PINFIX_ABIT_AW9D_MAX] = {
		.pins = alc882_abit_aw9d_pinfix
	},
10082 10083
};

10084
static struct snd_pci_quirk alc882_fixup_tbl[] = {
10085 10086 10087 10088
	SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
	{}
};

10089 10090 10091
/*
 * BIOS auto configuration
 */
10092 10093 10094 10095 10096 10097
static int alc882_auto_create_input_ctls(struct hda_codec *codec,
						const struct auto_pin_cfg *cfg)
{
	return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x23, 0x22);
}

10098
static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
10099 10100 10101 10102 10103
					      hda_nid_t nid, int pin_type,
					      int dac_idx)
{
	/* set as output */
	struct alc_spec *spec = codec->spec;
10104 10105
	int idx;

10106
	alc_set_pin_output(codec, nid, pin_type);
10107 10108
	if (spec->multiout.dac_nids[dac_idx] == 0x25)
		idx = 4;
10109 10110 10111
	else {
		if (spec->multiout.num_dacs >= dac_idx)
			return;
10112
		idx = spec->multiout.dac_nids[dac_idx] - 2;
10113
	}
10114 10115 10116 10117
	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);

}

10118
static void alc882_auto_init_multi_out(struct hda_codec *codec)
10119 10120 10121 10122 10123
{
	struct alc_spec *spec = codec->spec;
	int i;

	for (i = 0; i <= HDA_SIDE; i++) {
10124
		hda_nid_t nid = spec->autocfg.line_out_pins[i];
10125
		int pin_type = get_pin_type(spec->autocfg.line_out_type);
10126
		if (nid)
10127
			alc882_auto_set_output_and_unmute(codec, nid, pin_type,
10128
							  i);
10129 10130 10131
	}
}

10132
static void alc882_auto_init_hp_out(struct hda_codec *codec)
10133 10134 10135 10136
{
	struct alc_spec *spec = codec->spec;
	hda_nid_t pin;

10137
	pin = spec->autocfg.hp_pins[0];
10138 10139
	if (pin) /* connect to front */
		/* use dac 0 */
10140
		alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
10141 10142
	pin = spec->autocfg.speaker_pins[0];
	if (pin)
10143
		alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
10144 10145
}

10146
static void alc882_auto_init_analog_input(struct hda_codec *codec)
10147 10148 10149 10150 10151 10152
{
	struct alc_spec *spec = codec->spec;
	int i;

	for (i = 0; i < AUTO_PIN_LAST; i++) {
		hda_nid_t nid = spec->autocfg.input_pins[i];
10153 10154
		if (!nid)
			continue;
10155
		alc_set_input_pin(codec, nid, i);
10156 10157 10158 10159 10160 10161 10162 10163 10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 10180
		if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
			snd_hda_codec_write(codec, nid, 0,
					    AC_VERB_SET_AMP_GAIN_MUTE,
					    AMP_OUT_MUTE);
	}
}

static void alc882_auto_init_input_src(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int c;

	for (c = 0; c < spec->num_adc_nids; c++) {
		hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
		hda_nid_t nid = spec->capsrc_nids[c];
		unsigned int mux_idx;
		const struct hda_input_mux *imux;
		int conns, mute, idx, item;

		conns = snd_hda_get_connections(codec, nid, conn_list,
						ARRAY_SIZE(conn_list));
		if (conns < 0)
			continue;
		mux_idx = c >= spec->num_mux_defs ? 0 : c;
		imux = &spec->input_mux[mux_idx];
10181 10182
		if (!imux->num_items && mux_idx > 0)
			imux = &spec->input_mux[0];
10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 10200 10201
		for (idx = 0; idx < conns; idx++) {
			/* if the current connection is the selected one,
			 * unmute it as default - otherwise mute it
			 */
			mute = AMP_IN_MUTE(idx);
			for (item = 0; item < imux->num_items; item++) {
				if (imux->items[item].index == idx) {
					if (spec->cur_mux[c] == item)
						mute = AMP_IN_UNMUTE(idx);
					break;
				}
			}
			/* check if we have a selector or mixer
			 * we could check for the widget type instead, but
			 * just check for Amp-In presence (in case of mixer
			 * without amp-in there is something wrong, this
			 * function shouldn't be used or capsrc nid is wrong)
			 */
			if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
10202 10203
				snd_hda_codec_write(codec, nid, 0,
						    AC_VERB_SET_AMP_GAIN_MUTE,
10204 10205 10206 10207 10208
						    mute);
			else if (mute != AMP_IN_MUTE(idx))
				snd_hda_codec_write(codec, nid, 0,
						    AC_VERB_SET_CONNECT_SEL,
						    idx);
10209 10210 10211 10212
		}
	}
}

10213 10214 10215 10216 10217 10218 10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 10237
/* add mic boosts if needed */
static int alc_auto_add_mic_boost(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int err;
	hda_nid_t nid;

	nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
	if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
		err = add_control(spec, ALC_CTL_WIDGET_VOL,
				  "Mic Boost",
				  HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
		if (err < 0)
			return err;
	}
	nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
	if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
		err = add_control(spec, ALC_CTL_WIDGET_VOL,
				  "Front Mic Boost",
				  HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
		if (err < 0)
			return err;
	}
	return 0;
}
10238

10239
/* almost identical with ALC880 parser... */
10240
static int alc882_parse_auto_config(struct hda_codec *codec)
10241 10242
{
	struct alc_spec *spec = codec->spec;
10243 10244
	static hda_nid_t alc882_ignore[] = { 0x1d, 0 };
	int i, err;
10245

10246 10247
	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
					   alc882_ignore);
10248 10249
	if (err < 0)
		return err;
10250 10251
	if (!spec->autocfg.line_outs)
		return 0; /* can't find valid BIOS pin config */
10252

10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268
	err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
	if (err < 0)
		return err;
	err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
	if (err < 0)
		return err;
	err = alc880_auto_create_extra_out(spec,
					   spec->autocfg.speaker_pins[0],
					   "Speaker");
	if (err < 0)
		return err;
	err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
					   "Headphone");
	if (err < 0)
		return err;
	err = alc882_auto_create_input_ctls(codec, &spec->autocfg);
10269 10270 10271
	if (err < 0)
		return err;

10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285
	spec->multiout.max_channels = spec->multiout.num_dacs * 2;

	/* check multiple SPDIF-out (for recent codecs) */
	for (i = 0; i < spec->autocfg.dig_outs; i++) {
		hda_nid_t dig_nid;
		err = snd_hda_get_connections(codec,
					      spec->autocfg.dig_out_pins[i],
					      &dig_nid, 1);
		if (err < 0)
			continue;
		if (!i)
			spec->multiout.dig_out_nid = dig_nid;
		else {
			spec->multiout.slave_dig_outs = spec->slave_dig_outs;
10286
			if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
10287
				break;
10288
			spec->slave_dig_outs[i - 1] = dig_nid;
10289 10290 10291 10292 10293 10294 10295 10296 10297
		}
	}
	if (spec->autocfg.dig_in_pin)
		spec->dig_in_nid = ALC880_DIGIN_NID;

	if (spec->kctls.list)
		add_mixer(spec, spec->kctls.list);

	add_verb(spec, alc883_auto_init_verbs);
10298
	/* if ADC 0x07 is available, initialize it, too */
10299
	if (get_wcaps_type(get_wcaps(codec, 0x07)) == AC_WID_AUD_IN)
10300
		add_verb(spec, alc882_adc1_init_verbs);
10301

10302 10303 10304
	spec->num_mux_defs = 1;
	spec->input_mux = &spec->private_imux[0];

10305
	alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
10306 10307 10308 10309

	err = alc_auto_add_mic_boost(codec);
	if (err < 0)
		return err;
10310

10311
	return 1; /* config found */
10312 10313 10314
}

/* additional initialization for auto-configuration model */
10315
static void alc882_auto_init(struct hda_codec *codec)
10316
{
10317
	struct alc_spec *spec = codec->spec;
10318 10319 10320 10321
	alc882_auto_init_multi_out(codec);
	alc882_auto_init_hp_out(codec);
	alc882_auto_init_analog_input(codec);
	alc882_auto_init_input_src(codec);
10322
	if (spec->unsol_event)
10323
		alc_inithook(codec);
10324 10325
}

10326
static int patch_alc882(struct hda_codec *codec)
10327 10328 10329 10330 10331 10332 10333 10334 10335 10336
{
	struct alc_spec *spec;
	int err, board_config;

	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
	if (spec == NULL)
		return -ENOMEM;

	codec->spec = spec;

10337 10338 10339 10340 10341 10342 10343 10344 10345
	switch (codec->vendor_id) {
	case 0x10ec0882:
	case 0x10ec0885:
		break;
	default:
		/* ALC883 and variants */
		alc_fix_pll_init(codec, 0x20, 0x0a, 10);
		break;
	}
10346

10347 10348 10349 10350 10351 10352 10353 10354 10355
	board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
						  alc882_models,
						  alc882_cfg_tbl);

	if (board_config < 0 || board_config >= ALC882_MODEL_LAST)
		board_config = snd_hda_check_board_codec_sid_config(codec,
			ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);

	if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
10356
		printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
10357 10358
		       codec->chip_name);
		board_config = ALC882_AUTO;
10359 10360
	}

10361
	alc_pick_fixup(codec, alc882_fixup_tbl, alc882_fixups);
10362 10363

	if (board_config == ALC882_AUTO) {
10364
		/* automatic parse from the BIOS config */
10365
		err = alc882_parse_auto_config(codec);
10366 10367 10368
		if (err < 0) {
			alc_free(codec);
			return err;
10369
		} else if (!err) {
10370 10371 10372
			printk(KERN_INFO
			       "hda_codec: Cannot set up configuration "
			       "from BIOS.  Using base mode...\n");
10373
			board_config = ALC882_3ST_DIG;
10374 10375 10376
		}
	}

10377 10378 10379 10380 10381 10382
	err = snd_hda_attach_beep_device(codec, 0x1);
	if (err < 0) {
		alc_free(codec);
		return err;
	}

10383
	if (board_config != ALC882_AUTO)
10384
		setup_preset(codec, &alc882_presets[board_config]);
10385

10386 10387 10388 10389 10390 10391 10392 10393 10394 10395
	spec->stream_analog_playback = &alc882_pcm_analog_playback;
	spec->stream_analog_capture = &alc882_pcm_analog_capture;
	/* FIXME: setup DAC5 */
	/*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
	spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;

	spec->stream_digital_playback = &alc882_pcm_digital_playback;
	spec->stream_digital_capture = &alc882_pcm_digital_capture;

	if (codec->vendor_id == 0x10ec0888)
10396
		spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
10397 10398

	if (!spec->adc_nids && spec->input_mux) {
10399
		int i, j;
10400 10401
		spec->num_adc_nids = 0;
		for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) {
10402
			const struct hda_input_mux *imux = spec->input_mux;
10403
			hda_nid_t cap;
10404
			hda_nid_t items[16];
10405 10406 10407
			hda_nid_t nid = alc882_adc_nids[i];
			unsigned int wcap = get_wcaps(codec, nid);
			/* get type */
10408
			wcap = get_wcaps_type(wcap);
10409 10410 10411 10412 10413 10414
			if (wcap != AC_WID_AUD_IN)
				continue;
			spec->private_adc_nids[spec->num_adc_nids] = nid;
			err = snd_hda_get_connections(codec, nid, &cap, 1);
			if (err < 0)
				continue;
10415 10416 10417 10418 10419 10420 10421 10422 10423
			err = snd_hda_get_connections(codec, cap, items,
						      ARRAY_SIZE(items));
			if (err < 0)
				continue;
			for (j = 0; j < imux->num_items; j++)
				if (imux->items[j].index >= err)
					break;
			if (j < imux->num_items)
				continue;
10424 10425
			spec->private_capsrc_nids[spec->num_adc_nids] = cap;
			spec->num_adc_nids++;
10426
		}
10427 10428
		spec->adc_nids = spec->private_adc_nids;
		spec->capsrc_nids = spec->private_capsrc_nids;
10429 10430
	}

10431
	set_capture_mixer(codec);
10432
	set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
10433

10434 10435
	spec->vmaster_nid = 0x0c;

10436
	codec->patch_ops = alc_patch_ops;
10437 10438
	if (board_config == ALC882_AUTO)
		spec->init_hook = alc882_auto_init;
10439 10440
#ifdef CONFIG_SND_HDA_POWER_SAVE
	if (!spec->loopback.amplist)
10441
		spec->loopback.amplist = alc882_loopbacks;
10442
#endif
10443 10444 10445 10446

	return 0;
}

10447

10448 10449 10450 10451 10452 10453 10454 10455 10456 10457
/*
 * ALC262 support
 */

#define ALC262_DIGOUT_NID	ALC880_DIGOUT_NID
#define ALC262_DIGIN_NID	ALC880_DIGIN_NID

#define alc262_dac_nids		alc260_dac_nids
#define alc262_adc_nids		alc882_adc_nids
#define alc262_adc_nids_alt	alc882_adc_nids_alt
10458 10459
#define alc262_capsrc_nids	alc882_capsrc_nids
#define alc262_capsrc_nids_alt	alc882_capsrc_nids_alt
10460 10461 10462 10463

#define alc262_modes		alc260_modes
#define alc262_capture_source	alc882_capture_source

10464 10465 10466 10467 10468 10469 10470
static hda_nid_t alc262_dmic_adc_nids[1] = {
	/* ADC0 */
	0x09
};

static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };

10471 10472 10473 10474 10475 10476 10477 10478 10479
static struct snd_kcontrol_new alc262_base_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10480
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10481 10482
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10483
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10484 10485 10486 10487 10488 10489 10490
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
	{ } /* end */
};

10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 10503 10504 10505 10506 10507 10508 10509 10510 10511 10512 10513
/* update HP, line and mono-out pins according to the master switch */
static void alc262_hp_master_update(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int val = spec->master_sw;

	/* HP & line-out */
	snd_hda_codec_write_cache(codec, 0x1b, 0,
				  AC_VERB_SET_PIN_WIDGET_CONTROL,
				  val ? PIN_HP : 0);
	snd_hda_codec_write_cache(codec, 0x15, 0,
				  AC_VERB_SET_PIN_WIDGET_CONTROL,
				  val ? PIN_HP : 0);
	/* mono (speaker) depending on the HP jack sense */
	val = val && !spec->jack_present;
	snd_hda_codec_write_cache(codec, 0x16, 0,
				  AC_VERB_SET_PIN_WIDGET_CONTROL,
				  val ? PIN_OUT : 0);
}

static void alc262_hp_bpc_automute(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
10514 10515

	spec->jack_present = snd_hda_jack_detect(codec, 0x1b);
10516 10517 10518 10519 10520 10521 10522 10523 10524 10525 10526 10527 10528
	alc262_hp_master_update(codec);
}

static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
{
	if ((res >> 26) != ALC880_HP_EVENT)
		return;
	alc262_hp_bpc_automute(codec);
}

static void alc262_hp_wildwest_automute(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
10529 10530

	spec->jack_present = snd_hda_jack_detect(codec, 0x15);
10531 10532 10533 10534 10535 10536 10537 10538 10539 10540 10541
	alc262_hp_master_update(codec);
}

static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
					   unsigned int res)
{
	if ((res >> 26) != ALC880_HP_EVENT)
		return;
	alc262_hp_wildwest_automute(codec);
}

10542
#define alc262_hp_master_sw_get		alc260_hp_master_sw_get
10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557

static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
				   struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct alc_spec *spec = codec->spec;
	int val = !!*ucontrol->value.integer.value;

	if (val == spec->master_sw)
		return 0;
	spec->master_sw = val;
	alc262_hp_master_update(codec);
	return 1;
}

10558 10559 10560 10561 10562 10563 10564
#define ALC262_HP_MASTER_SWITCH					\
	{							\
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		\
		.name = "Master Playback Switch",		\
		.info = snd_ctl_boolean_mono_info,		\
		.get = alc262_hp_master_sw_get,			\
		.put = alc262_hp_master_sw_put,			\
10565 10566 10567 10568 10569
	}, \
	{							\
		.iface = NID_MAPPING,				\
		.name = "Master Playback Switch",		\
		.private_value = 0x15 | (0x16 << 8) | (0x1b << 16),	\
10570 10571
	}

10572

10573
static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
10574
	ALC262_HP_MASTER_SWITCH,
10575 10576 10577
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10578 10579 10580 10581
	HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
			      HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
			    HDA_OUTPUT),
10582 10583
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10584
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10585 10586
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10587
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10588 10589 10590 10591 10592 10593 10594 10595 10596
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
	HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
	{ } /* end */
};

10597
static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
10598
	ALC262_HP_MASTER_SWITCH,
10599 10600 10601 10602
	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10603 10604 10605 10606
	HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
			      HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
			    HDA_OUTPUT),
10607 10608
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
10609
	HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
10610 10611 10612 10613 10614 10615 10616 10617 10618 10619
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	{ } /* end */
};

static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
	HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10620
	HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
10621 10622 10623
	{ } /* end */
};

10624
/* mute/unmute internal speaker according to the hp jack and mute state */
10625
static void alc262_hp_t5735_setup(struct hda_codec *codec)
10626 10627 10628
{
	struct alc_spec *spec = codec->spec;

10629
	spec->autocfg.hp_pins[0] = 0x15;
T
Takashi Iwai 已提交
10630
	spec->autocfg.speaker_pins[0] = 0x14;
10631 10632 10633
}

static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
10634 10635
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10636 10637 10638 10639 10640 10641 10642 10643 10644 10645 10646 10647 10648 10649 10650 10651
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	{ } /* end */
};

static struct hda_verb alc262_hp_t5735_verbs[] = {
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},

	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{ }
};

10652
static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
10653 10654
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10655 10656
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
10657 10658 10659 10660 10661 10662 10663 10664 10665 10666 10667 10668 10669 10670 10671 10672 10673 10674 10675 10676 10677 10678 10679 10680 10681 10682
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
	{ } /* end */
};

static struct hda_verb alc262_hp_rp5700_verbs[] = {
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
	{}
};

static struct hda_input_mux alc262_hp_rp5700_capture_source = {
	.num_items = 1,
	.items = {
		{ "Line", 0x1 },
	},
};

10683 10684
/* bind hp and internal speaker mute (with plug check) as master switch */
static void alc262_hippo_master_update(struct hda_codec *codec)
10685
{
10686 10687 10688 10689 10690
	struct alc_spec *spec = codec->spec;
	hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
	hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
	hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
	unsigned int mute;
10691

10692 10693 10694 10695 10696 10697 10698 10699 10700 10701 10702 10703
	/* HP */
	mute = spec->master_sw ? 0 : HDA_AMP_MUTE;
	snd_hda_codec_amp_stereo(codec, hp_nid, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, mute);
	/* mute internal speaker per jack sense */
	if (spec->jack_present)
		mute = HDA_AMP_MUTE;
	if (line_nid)
		snd_hda_codec_amp_stereo(codec, line_nid, HDA_OUTPUT, 0,
					 HDA_AMP_MUTE, mute);
	if (speaker_nid && speaker_nid != line_nid)
		snd_hda_codec_amp_stereo(codec, speaker_nid, HDA_OUTPUT, 0,
10704
					 HDA_AMP_MUTE, mute);
10705 10706 10707 10708 10709 10710 10711 10712 10713 10714 10715 10716 10717 10718 10719 10720 10721 10722 10723 10724 10725 10726 10727 10728 10729
}

#define alc262_hippo_master_sw_get	alc262_hp_master_sw_get

static int alc262_hippo_master_sw_put(struct snd_kcontrol *kcontrol,
				      struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct alc_spec *spec = codec->spec;
	int val = !!*ucontrol->value.integer.value;

	if (val == spec->master_sw)
		return 0;
	spec->master_sw = val;
	alc262_hippo_master_update(codec);
	return 1;
}

#define ALC262_HIPPO_MASTER_SWITCH				\
	{							\
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		\
		.name = "Master Playback Switch",		\
		.info = snd_ctl_boolean_mono_info,		\
		.get = alc262_hippo_master_sw_get,		\
		.put = alc262_hippo_master_sw_put,		\
10730 10731 10732 10733 10734 10735
	},							\
	{							\
		.iface = NID_MAPPING,				\
		.name = "Master Playback Switch",		\
		.subdevice = SUBDEV_HP(0) | (SUBDEV_LINE(0) << 8) | \
			     (SUBDEV_SPEAKER(0) << 16), \
10736
	}
10737 10738 10739 10740 10741 10742 10743 10744 10745 10746 10747 10748 10749 10750 10751 10752 10753 10754 10755 10756 10757 10758 10759 10760 10761 10762 10763 10764 10765 10766 10767 10768 10769 10770 10771 10772 10773 10774 10775 10776

static struct snd_kcontrol_new alc262_hippo_mixer[] = {
	ALC262_HIPPO_MASTER_SWITCH,
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	{ } /* end */
};

static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
	HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	ALC262_HIPPO_MASTER_SWITCH,
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
	{ } /* end */
};

/* mute/unmute internal speaker according to the hp jack and mute state */
static void alc262_hippo_automute(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	hda_nid_t hp_nid = spec->autocfg.hp_pins[0];

10777
	spec->jack_present = snd_hda_jack_detect(codec, hp_nid);
10778
	alc262_hippo_master_update(codec);
10779
}
10780

10781 10782 10783 10784 10785 10786 10787
static void alc262_hippo_unsol_event(struct hda_codec *codec, unsigned int res)
{
	if ((res >> 26) != ALC880_HP_EVENT)
		return;
	alc262_hippo_automute(codec);
}

10788
static void alc262_hippo_setup(struct hda_codec *codec)
10789 10790 10791 10792 10793 10794 10795
{
	struct alc_spec *spec = codec->spec;

	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
}

10796
static void alc262_hippo1_setup(struct hda_codec *codec)
10797 10798 10799 10800 10801 10802 10803 10804
{
	struct alc_spec *spec = codec->spec;

	spec->autocfg.hp_pins[0] = 0x1b;
	spec->autocfg.speaker_pins[0] = 0x14;
}


10805
static struct snd_kcontrol_new alc262_sony_mixer[] = {
10806
	HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10807
	ALC262_HIPPO_MASTER_SWITCH,
10808 10809 10810 10811 10812 10813 10814
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
	{ } /* end */
};

10815
static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
10816 10817
	HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	ALC262_HIPPO_MASTER_SWITCH,
10818 10819 10820 10821 10822 10823 10824
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
	{ } /* end */
};
10825

10826 10827 10828 10829 10830 10831 10832 10833 10834 10835 10836 10837 10838 10839 10840 10841 10842 10843 10844 10845 10846 10847 10848 10849 10850 10851 10852 10853 10854 10855 10856 10857
static struct snd_kcontrol_new alc262_tyan_mixer[] = {
	HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
	HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
	{ } /* end */
};

static struct hda_verb alc262_tyan_verbs[] = {
	/* Headphone automute */
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},

	/* P11 AUX_IN, white 4-pin connector */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
	{0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
	{0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},

	{}
};

/* unsolicited event for HP jack sensing */
10858
static void alc262_tyan_setup(struct hda_codec *codec)
10859
{
10860
	struct alc_spec *spec = codec->spec;
10861

10862 10863
	spec->autocfg.hp_pins[0] = 0x1b;
	spec->autocfg.speaker_pins[0] = 0x15;
10864 10865 10866
}


10867 10868 10869 10870 10871 10872 10873 10874 10875 10876 10877 10878 10879 10880 10881 10882 10883
#define alc262_capture_mixer		alc882_capture_mixer
#define alc262_capture_alt_mixer	alc882_capture_alt_mixer

/*
 * generic initialization of ADC, input mixers and output mixers
 */
static struct hda_verb alc262_init_verbs[] = {
	/*
	 * Unmute ADC0-2 and set the default input to mic-in
	 */
	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},

10884
	/* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10885
	 * mixer widget
10886 10887
	 * Note: PASD motherboards uses the Line In 2 as the input for
	 * front panel mic (mic 2)
10888 10889
	 */
	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10890 10891 10892 10893 10894
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10895 10896

	/*
10897 10898 10899 10900 10901 10902 10903 10904 10905 10906 10907 10908 10909 10910 10911 10912 10913 10914 10915 10916 10917 10918 10919 10920 10921 10922 10923
	 * Set up output mixers (0x0c - 0x0e)
	 */
	/* set vol=0 to output mixers */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	/* set up input amps for analog loopback */
	/* Amp Indices: DAC = 0, mixer = 1 */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},

	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},

	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10924

10925 10926
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10927

10928 10929 10930 10931 10932 10933 10934 10935 10936 10937 10938 10939 10940 10941 10942 10943
	/* FIXME: use matrix-type input source selection */
	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
	/* Input mixer2 */
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
	/* Input mixer3 */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10944
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10945 10946 10947

	{ }
};
L
Linus Torvalds 已提交
10948

10949 10950 10951 10952 10953 10954
static struct hda_verb alc262_eapd_verbs[] = {
	{0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
	{0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
	{ }
};

10955 10956 10957 10958 10959 10960 10961 10962 10963 10964
static struct hda_verb alc262_hippo1_unsol_verbs[] = {
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},

	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{}
};

10965 10966 10967 10968 10969 10970 10971
static struct hda_verb alc262_sony_unsol_verbs[] = {
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},	// Front Mic

	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10972
	{}
10973 10974
};

10975 10976 10977 10978 10979 10980 10981 10982 10983 10984 10985 10986 10987 10988 10989 10990 10991 10992 10993 10994 10995
static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
};

static struct hda_verb alc262_toshiba_s06_verbs[] = {
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

10996
static void alc262_toshiba_s06_setup(struct hda_codec *codec)
10997
{
10998 10999 11000 11001
	struct alc_spec *spec = codec->spec;

	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
11002 11003 11004 11005 11006
	spec->ext_mic.pin = 0x18;
	spec->ext_mic.mux_idx = 0;
	spec->int_mic.pin = 0x12;
	spec->int_mic.mux_idx = 9;
	spec->auto_mic = 1;
11007 11008
}

11009 11010 11011 11012 11013 11014 11015 11016 11017 11018 11019 11020 11021 11022 11023 11024 11025 11026 11027 11028 11029 11030 11031 11032 11033 11034 11035 11036 11037 11038 11039 11040 11041 11042 11043
/*
 * nec model
 *  0x15 = headphone
 *  0x16 = internal speaker
 *  0x18 = external mic
 */

static struct snd_kcontrol_new alc262_nec_mixer[] = {
	HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),

	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),

	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	{ } /* end */
};

static struct hda_verb alc262_nec_verbs[] = {
	/* Unmute Speaker */
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},

	/* Headphone */
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},

	/* External mic to headphone */
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	/* External mic to speaker */
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{}
};

11044 11045
/*
 * fujitsu model
11046 11047
 *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
 *  0x1b = port replicator headphone out
11048 11049 11050 11051 11052 11053 11054
 */

#define ALC_HP_EVENT	0x37

static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11055 11056
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11057 11058 11059
	{}
};

11060 11061 11062 11063 11064 11065
static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{}
};

11066 11067 11068 11069 11070 11071 11072
static struct hda_verb alc262_lenovo_3000_init_verbs[] = {
	/* Front Mic pin: input vref at 50% */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{}
};

11073
static struct hda_input_mux alc262_fujitsu_capture_source = {
11074
	.num_items = 3,
11075 11076
	.items = {
		{ "Mic", 0x0 },
11077
		{ "Int Mic", 0x1 },
11078 11079 11080 11081
		{ "CD", 0x4 },
	},
};

11082 11083 11084 11085
static struct hda_input_mux alc262_HP_capture_source = {
	.num_items = 5,
	.items = {
		{ "Mic", 0x0 },
11086
		{ "Front Mic", 0x1 },
11087 11088 11089 11090 11091 11092
		{ "Line", 0x2 },
		{ "CD", 0x4 },
		{ "AUX IN", 0x6 },
	},
};

11093 11094 11095 11096 11097 11098 11099 11100 11101 11102
static struct hda_input_mux alc262_HP_D7000_capture_source = {
	.num_items = 4,
	.items = {
		{ "Mic", 0x0 },
		{ "Front Mic", 0x2 },
		{ "Line", 0x1 },
		{ "CD", 0x4 },
	},
};

11103
/* mute/unmute internal speaker according to the hp jacks and mute state */
11104 11105 11106 11107 11108
static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
{
	struct alc_spec *spec = codec->spec;
	unsigned int mute;

11109
	if (force || !spec->sense_updated) {
11110 11111
		spec->jack_present = snd_hda_jack_detect(codec, 0x14) ||
				     snd_hda_jack_detect(codec, 0x1b);
11112 11113
		spec->sense_updated = 1;
	}
11114 11115 11116 11117 11118 11119
	/* unmute internal speaker only if both HPs are unplugged and
	 * master switch is on
	 */
	if (spec->jack_present)
		mute = HDA_AMP_MUTE;
	else
11120
		mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11121 11122
	snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, mute);
11123 11124 11125 11126 11127 11128 11129 11130 11131 11132 11133
}

/* unsolicited event for HP jack sensing */
static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
				       unsigned int res)
{
	if ((res >> 26) != ALC_HP_EVENT)
		return;
	alc262_fujitsu_automute(codec, 1);
}

11134 11135 11136 11137 11138
static void alc262_fujitsu_init_hook(struct hda_codec *codec)
{
	alc262_fujitsu_automute(codec, 1);
}

11139
/* bind volumes of both NID 0x0c and 0x0d */
11140 11141 11142 11143 11144 11145 11146 11147
static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
	.ops = &snd_hda_bind_vol,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
		0
	},
};
11148

11149 11150 11151 11152 11153 11154 11155
/* mute/unmute internal speaker according to the hp jack and mute state */
static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
{
	struct alc_spec *spec = codec->spec;
	unsigned int mute;

	if (force || !spec->sense_updated) {
11156
		spec->jack_present = snd_hda_jack_detect(codec, 0x1b);
11157 11158 11159 11160 11161 11162 11163 11164 11165 11166 11167 11168 11169 11170 11171 11172 11173 11174 11175 11176 11177 11178 11179 11180 11181 11182 11183
		spec->sense_updated = 1;
	}
	if (spec->jack_present) {
		/* mute internal speaker */
		snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
					 HDA_AMP_MUTE, HDA_AMP_MUTE);
		snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
					 HDA_AMP_MUTE, HDA_AMP_MUTE);
	} else {
		/* unmute internal speaker if necessary */
		mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
		snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
					 HDA_AMP_MUTE, mute);
		snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
					 HDA_AMP_MUTE, mute);
	}
}

/* unsolicited event for HP jack sensing */
static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
				       unsigned int res)
{
	if ((res >> 26) != ALC_HP_EVENT)
		return;
	alc262_lenovo_3000_automute(codec, 1);
}

11184 11185 11186 11187 11188 11189 11190 11191 11192 11193 11194 11195
static int amp_stereo_mute_update(struct hda_codec *codec, hda_nid_t nid,
				  int dir, int idx, long *valp)
{
	int i, change = 0;

	for (i = 0; i < 2; i++, valp++)
		change |= snd_hda_codec_amp_update(codec, nid, i, dir, idx,
						   HDA_AMP_MUTE,
						   *valp ? 0 : HDA_AMP_MUTE);
	return change;
}

11196 11197 11198 11199 11200 11201 11202 11203
/* bind hp and internal speaker mute (with plug check) */
static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
					 struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	long *valp = ucontrol->value.integer.value;
	int change;

11204 11205
	change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
	change |= amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
11206 11207
	if (change)
		alc262_fujitsu_automute(codec, 0);
11208 11209 11210 11211
	return change;
}

static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
11212
	HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
11213 11214 11215
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Master Playback Switch",
11216
		.subdevice = HDA_SUBDEV_AMP_FLAG,
11217 11218 11219 11220 11221
		.info = snd_hda_mixer_amp_switch_info,
		.get = snd_hda_mixer_amp_switch_get,
		.put = alc262_fujitsu_master_sw_put,
		.private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
	},
11222 11223 11224 11225 11226
	{
		.iface = NID_MAPPING,
		.name = "Master Playback Switch",
		.private_value = 0x1b,
	},
11227 11228 11229 11230 11231
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11232 11233 11234
	HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11235 11236 11237
	{ } /* end */
};

11238 11239 11240 11241 11242 11243 11244 11245
/* bind hp and internal speaker mute (with plug check) */
static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
					 struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	long *valp = ucontrol->value.integer.value;
	int change;

11246
	change = amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
11247 11248 11249 11250 11251 11252 11253 11254 11255 11256
	if (change)
		alc262_lenovo_3000_automute(codec, 0);
	return change;
}

static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
	HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Master Playback Switch",
11257
		.subdevice = HDA_SUBDEV_AMP_FLAG,
11258 11259 11260 11261 11262 11263 11264 11265 11266 11267 11268 11269 11270 11271 11272 11273
		.info = snd_hda_mixer_amp_switch_info,
		.get = snd_hda_mixer_amp_switch_get,
		.put = alc262_lenovo_3000_master_sw_put,
		.private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
	},
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

11274 11275
static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
	HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
11276
	ALC262_HIPPO_MASTER_SWITCH,
11277 11278 11279 11280 11281 11282 11283 11284 11285
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
	{ } /* end */
};

11286 11287 11288 11289 11290 11291 11292
/* additional init verbs for Benq laptops */
static struct hda_verb alc262_EAPD_verbs[] = {
	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
	{0x20, AC_VERB_SET_PROC_COEF,  0x3070},
	{}
};

11293 11294 11295 11296 11297 11298 11299 11300 11301
static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},

	{0x20, AC_VERB_SET_COEF_INDEX, 0x07},
	{0x20, AC_VERB_SET_PROC_COEF,  0x3050},
	{}
};

11302 11303
/* Samsung Q1 Ultra Vista model setup */
static struct snd_kcontrol_new alc262_ultra_mixer[] = {
11304 11305
	HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
11306 11307 11308
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
11309
	HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
11310 11311 11312 11313
	{ } /* end */
};

static struct hda_verb alc262_ultra_verbs[] = {
11314 11315 11316 11317 11318 11319 11320 11321 11322 11323
	/* output mixer */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	/* speaker */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* HP */
11324
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11325 11326 11327 11328 11329 11330 11331 11332 11333 11334 11335 11336 11337 11338 11339 11340 11341 11342
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	/* internal mic */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	/* ADC, choose mic */
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
11343 11344 11345 11346 11347 11348 11349 11350 11351
	{}
};

/* mute/unmute internal speaker according to the hp jack and mute state */
static void alc262_ultra_automute(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	unsigned int mute;

11352 11353 11354
	mute = 0;
	/* auto-mute only when HP is used as HP */
	if (!spec->cur_mux[0]) {
11355
		spec->jack_present = snd_hda_jack_detect(codec, 0x15);
11356 11357
		if (spec->jack_present)
			mute = HDA_AMP_MUTE;
11358
	}
11359 11360 11361 11362 11363 11364
	/* mute/unmute internal speaker */
	snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, mute);
	/* mute/unmute HP */
	snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
11365 11366 11367 11368 11369 11370 11371 11372 11373 11374 11375
}

/* unsolicited event for HP jack sensing */
static void alc262_ultra_unsol_event(struct hda_codec *codec,
				       unsigned int res)
{
	if ((res >> 26) != ALC880_HP_EVENT)
		return;
	alc262_ultra_automute(codec);
}

11376 11377 11378 11379 11380 11381 11382 11383 11384 11385 11386 11387 11388 11389 11390
static struct hda_input_mux alc262_ultra_capture_source = {
	.num_items = 2,
	.items = {
		{ "Mic", 0x1 },
		{ "Headphone", 0x7 },
	},
};

static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
				     struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct alc_spec *spec = codec->spec;
	int ret;

11391
	ret = alc_mux_enum_put(kcontrol, ucontrol);
11392 11393 11394 11395 11396 11397 11398 11399 11400 11401 11402 11403 11404 11405 11406 11407
	if (!ret)
		return 0;
	/* reprogram the HP pin as mic or HP according to the input source */
	snd_hda_codec_write_cache(codec, 0x15, 0,
				  AC_VERB_SET_PIN_WIDGET_CONTROL,
				  spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
	alc262_ultra_automute(codec); /* mute/unmute HP */
	return ret;
}

static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
	HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Capture Source",
11408 11409
		.info = alc_mux_enum_info,
		.get = alc_mux_enum_get,
11410 11411
		.put = alc262_ultra_mux_enum_put,
	},
11412 11413 11414 11415 11416
	{
		.iface = NID_MAPPING,
		.name = "Capture Source",
		.private_value = 0x15,
	},
11417 11418 11419
	{ } /* end */
};

11420 11421 11422 11423 11424 11425 11426 11427 11428 11429 11430 11431 11432 11433 11434 11435 11436 11437 11438 11439 11440 11441 11442 11443 11444 11445 11446 11447 11448 11449
/* We use two mixers depending on the output pin; 0x16 is a mono output
 * and thus it's bound with a different mixer.
 * This function returns which mixer amp should be used.
 */
static int alc262_check_volbit(hda_nid_t nid)
{
	if (!nid)
		return 0;
	else if (nid == 0x16)
		return 2;
	else
		return 1;
}

static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
				  const char *pfx, int *vbits)
{
	unsigned long val;
	int vbit;

	vbit = alc262_check_volbit(nid);
	if (!vbit)
		return 0;
	if (*vbits & vbit) /* a volume control for this mixer already there */
		return 0;
	*vbits |= vbit;
	if (vbit == 2)
		val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT);
	else
		val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT);
11450
	return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, val);
11451 11452 11453 11454 11455 11456 11457 11458 11459 11460 11461 11462 11463
}

static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid,
				 const char *pfx)
{
	unsigned long val;

	if (!nid)
		return 0;
	if (nid == 0x16)
		val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
	else
		val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
11464
	return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
11465 11466
}

11467
/* add playback controls from the parsed DAC table */
11468 11469
static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
					     const struct auto_pin_cfg *cfg)
11470
{
11471 11472
	const char *pfx;
	int vbits;
11473 11474 11475 11476 11477 11478
	int err;

	spec->multiout.num_dacs = 1;	/* only use one dac */
	spec->multiout.dac_nids = spec->private_dac_nids;
	spec->multiout.dac_nids[0] = 2;

11479 11480 11481 11482 11483 11484 11485 11486 11487 11488 11489 11490 11491 11492 11493
	if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
		pfx = "Master";
	else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
		pfx = "Speaker";
	else
		pfx = "Front";
	err = alc262_add_out_sw_ctl(spec, cfg->line_out_pins[0], pfx);
	if (err < 0)
		return err;
	err = alc262_add_out_sw_ctl(spec, cfg->speaker_pins[0], "Speaker");
	if (err < 0)
		return err;
	err = alc262_add_out_sw_ctl(spec, cfg->hp_pins[0], "Headphone");
	if (err < 0)
		return err;
11494

11495 11496 11497 11498 11499 11500 11501 11502 11503 11504 11505 11506 11507 11508 11509 11510 11511 11512 11513 11514 11515
	vbits = alc262_check_volbit(cfg->line_out_pins[0]) |
		alc262_check_volbit(cfg->speaker_pins[0]) |
		alc262_check_volbit(cfg->hp_pins[0]);
	if (vbits == 1 || vbits == 2)
		pfx = "Master"; /* only one mixer is used */
	else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
		pfx = "Speaker";
	else
		pfx = "Front";
	vbits = 0;
	err = alc262_add_out_vol_ctl(spec, cfg->line_out_pins[0], pfx, &vbits);
	if (err < 0)
		return err;
	err = alc262_add_out_vol_ctl(spec, cfg->speaker_pins[0], "Speaker",
				     &vbits);
	if (err < 0)
		return err;
	err = alc262_add_out_vol_ctl(spec, cfg->hp_pins[0], "Headphone",
				     &vbits);
	if (err < 0)
		return err;
11516
	return 0;
11517 11518
}

11519
#define alc262_auto_create_input_ctls \
11520
	alc882_auto_create_input_ctls
11521 11522 11523 11524 11525 11526 11527 11528 11529 11530 11531 11532 11533 11534 11535

/*
 * generic initialization of ADC, input mixers and output mixers
 */
static struct hda_verb alc262_volume_init_verbs[] = {
	/*
	 * Unmute ADC0-2 and set the default input to mic-in
	 */
	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},

11536
	/* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11537
	 * mixer widget
11538 11539
	 * Note: PASD motherboards uses the Line In 2 as the input for
	 * front panel mic (mic 2)
11540 11541
	 */
	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11542 11543 11544 11545 11546
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11547 11548 11549 11550 11551 11552 11553 11554

	/*
	 * Set up output mixers (0x0c - 0x0f)
	 */
	/* set vol=0 to output mixers */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11555

11556 11557 11558 11559 11560 11561 11562 11563 11564 11565 11566 11567 11568 11569 11570 11571 11572 11573 11574 11575 11576 11577 11578 11579 11580 11581 11582 11583 11584 11585
	/* set up input amps for analog loopback */
	/* Amp Indices: DAC = 0, mixer = 1 */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},

	/* FIXME: use matrix-type input source selection */
	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
	/* Input mixer2 */
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
	/* Input mixer3 */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},

	{ }
};

11586 11587 11588 11589 11590 11591 11592 11593 11594 11595 11596
static struct hda_verb alc262_HP_BPC_init_verbs[] = {
	/*
	 * Unmute ADC0-2 and set the default input to mic-in
	 */
	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},

11597
	/* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11598
	 * mixer widget
11599 11600
	 * Note: PASD motherboards uses the Line In 2 as the input for
	 * front panel mic (mic 2)
11601 11602
	 */
	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11603 11604 11605 11606 11607 11608 11609
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
        {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11610

11611 11612 11613 11614 11615 11616 11617 11618 11619 11620 11621 11622 11623 11624 11625 11626 11627
	/*
	 * Set up output mixers (0x0c - 0x0e)
	 */
	/* set vol=0 to output mixers */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},

	/* set up input amps for analog loopback */
	/* Amp Indices: DAC = 0, mixer = 1 */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},

11628
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11629 11630 11631 11632 11633 11634 11635 11636 11637 11638 11639 11640 11641 11642 11643
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },

	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },

	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},

	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},

11644
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11645 11646
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
        {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11647
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11648 11649 11650 11651 11652
	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },


	/* FIXME: use matrix-type input source selection */
11653 11654
	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 0b, 12 */
	/* Input mixer1: only unmute Mic */
11655
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11656 11657 11658 11659 11660 11661 11662 11663
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11664 11665
	/* Input mixer2 */
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11666 11667 11668 11669 11670 11671 11672 11673
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11674 11675
	/* Input mixer3 */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11676 11677 11678 11679 11680 11681 11682 11683
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11684

11685 11686
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},

11687 11688 11689
	{ }
};

11690 11691 11692 11693 11694 11695 11696 11697 11698 11699 11700
static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
	/*
	 * Unmute ADC0-2 and set the default input to mic-in
	 */
	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},

11701
	/* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11702 11703 11704 11705 11706
	 * mixer widget
	 * Note: PASD motherboards uses the Line In 2 as the input for front
	 * panel mic (mic 2)
	 */
	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11707 11708 11709 11710 11711 11712 11713 11714
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
11715 11716 11717 11718 11719 11720 11721 11722 11723 11724 11725 11726 11727 11728 11729 11730 11731 11732 11733 11734 11735 11736 11737 11738 11739 11740 11741 11742 11743 11744 11745 11746 11747 11748 11749 11750 11751 11752 11753 11754 11755 11756 11757 11758 11759 11760 11761 11762 11763 11764 11765 11766 11767 11768 11769 11770 11771 11772 11773 11774 11775 11776 11777 11778 11779 11780
	/*
	 * Set up output mixers (0x0c - 0x0e)
	 */
	/* set vol=0 to output mixers */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},

	/* set up input amps for analog loopback */
	/* Amp Indices: DAC = 0, mixer = 1 */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},


	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },	/* HP */
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },	/* Mono */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },	/* rear MIC */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },	/* Line in */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },	/* Front MIC */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },	/* Line out */
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },	/* CD in */

	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },

	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},

	/* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },

	/* FIXME: use matrix-type input source selection */
	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
        /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
	/* Input mixer2 */
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
        /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
	/* Input mixer3 */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
        /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},

11781 11782
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},

11783 11784 11785
	{ }
};

11786 11787 11788 11789 11790 11791 11792 11793 11794 11795 11796 11797 11798 11799 11800 11801 11802 11803
static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {

	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },	/* Front Speaker */
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x01},

	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },	/* MIC jack */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },	/* Front MIC */
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },

	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },	/* HP  jack */
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};


11804 11805 11806 11807
#ifdef CONFIG_SND_HDA_POWER_SAVE
#define alc262_loopbacks	alc880_loopbacks
#endif

11808
/* pcm configuration: identical with ALC880 */
11809 11810 11811 11812 11813 11814 11815 11816 11817 11818 11819 11820 11821 11822
#define alc262_pcm_analog_playback	alc880_pcm_analog_playback
#define alc262_pcm_analog_capture	alc880_pcm_analog_capture
#define alc262_pcm_digital_playback	alc880_pcm_digital_playback
#define alc262_pcm_digital_capture	alc880_pcm_digital_capture

/*
 * BIOS auto configuration
 */
static int alc262_parse_auto_config(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int err;
	static hda_nid_t alc262_ignore[] = { 0x1d, 0 };

11823 11824 11825
	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
					   alc262_ignore);
	if (err < 0)
11826
		return err;
11827
	if (!spec->autocfg.line_outs) {
11828
		if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
11829 11830 11831 11832
			spec->multiout.max_channels = 2;
			spec->no_analog = 1;
			goto dig_only;
		}
11833
		return 0; /* can't find valid BIOS pin config */
11834
	}
11835 11836 11837
	err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
	if (err < 0)
		return err;
11838
	err = alc262_auto_create_input_ctls(codec, &spec->autocfg);
11839
	if (err < 0)
11840 11841 11842 11843
		return err;

	spec->multiout.max_channels = spec->multiout.num_dacs * 2;

11844
 dig_only:
11845
	if (spec->autocfg.dig_outs) {
11846
		spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
11847
		spec->dig_out_type = spec->autocfg.dig_out_type[0];
11848
	}
11849 11850 11851
	if (spec->autocfg.dig_in_pin)
		spec->dig_in_nid = ALC262_DIGIN_NID;

11852
	if (spec->kctls.list)
11853
		add_mixer(spec, spec->kctls.list);
11854

11855
	add_verb(spec, alc262_volume_init_verbs);
11856
	spec->num_mux_defs = 1;
11857
	spec->input_mux = &spec->private_imux[0];
11858

11859 11860 11861 11862
	err = alc_auto_add_mic_boost(codec);
	if (err < 0)
		return err;

11863
	alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
11864

11865 11866 11867 11868 11869 11870
	return 1;
}

#define alc262_auto_init_multi_out	alc882_auto_init_multi_out
#define alc262_auto_init_hp_out		alc882_auto_init_hp_out
#define alc262_auto_init_analog_input	alc882_auto_init_analog_input
11871
#define alc262_auto_init_input_src	alc882_auto_init_input_src
11872 11873 11874


/* init callback for auto-configuration model -- overriding the default init */
11875
static void alc262_auto_init(struct hda_codec *codec)
11876
{
11877
	struct alc_spec *spec = codec->spec;
11878 11879 11880
	alc262_auto_init_multi_out(codec);
	alc262_auto_init_hp_out(codec);
	alc262_auto_init_analog_input(codec);
11881
	alc262_auto_init_input_src(codec);
11882
	if (spec->unsol_event)
11883
		alc_inithook(codec);
11884 11885 11886 11887 11888
}

/*
 * configuration and preset
 */
11889 11890 11891 11892 11893 11894
static const char *alc262_models[ALC262_MODEL_LAST] = {
	[ALC262_BASIC]		= "basic",
	[ALC262_HIPPO]		= "hippo",
	[ALC262_HIPPO_1]	= "hippo_1",
	[ALC262_FUJITSU]	= "fujitsu",
	[ALC262_HP_BPC]		= "hp-bpc",
11895
	[ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
11896
	[ALC262_HP_TC_T5735]	= "hp-tc-t5735",
11897
	[ALC262_HP_RP5700]	= "hp-rp5700",
11898
	[ALC262_BENQ_ED8]	= "benq",
11899 11900
	[ALC262_BENQ_T31]	= "benq-t31",
	[ALC262_SONY_ASSAMD]	= "sony-assamd",
11901
	[ALC262_TOSHIBA_S06]	= "toshiba-s06",
11902
	[ALC262_TOSHIBA_RX1]	= "toshiba-rx1",
11903
	[ALC262_ULTRA]		= "ultra",
11904
	[ALC262_LENOVO_3000]	= "lenovo-3000",
11905
	[ALC262_NEC]		= "nec",
11906
	[ALC262_TYAN]		= "tyan",
11907 11908 11909 11910 11911
	[ALC262_AUTO]		= "auto",
};

static struct snd_pci_quirk alc262_cfg_tbl[] = {
	SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
11912
	SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
T
Takashi Iwai 已提交
11913 11914 11915 11916
	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
			   ALC262_HP_BPC),
	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
			   ALC262_HP_BPC),
11917 11918
	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
			   ALC262_HP_BPC),
11919 11920
	SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
	SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
11921
	SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
11922
	SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
11923
	SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
11924
	SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
11925
	SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
11926
	SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
11927 11928 11929
	SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
	SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
	SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
11930 11931
	SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
		      ALC262_HP_TC_T5735),
11932
	SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
11933
	SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11934
	SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
11935
	SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11936
	SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
11937
	SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
11938
	SND_PCI_QUIRK(0x104d, 0x9035, "Sony VAIO VGN-FW170J", ALC262_AUTO),
11939
	SND_PCI_QUIRK(0x104d, 0x9047, "Sony VAIO Type G", ALC262_AUTO),
11940
#if 0 /* disable the quirk since model=auto works better in recent versions */
11941 11942
	SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
			   ALC262_SONY_ASSAMD),
11943
#endif
11944
	SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
11945
		      ALC262_TOSHIBA_RX1),
11946
	SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
11947
	SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
11948
	SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
11949
	SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
T
Takashi Iwai 已提交
11950 11951
	SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
			   ALC262_ULTRA),
11952
	SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
11953
	SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
11954 11955 11956
	SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
	SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
	SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
11957 11958 11959 11960 11961 11962 11963 11964 11965 11966 11967 11968
	{}
};

static struct alc_config_preset alc262_presets[] = {
	[ALC262_BASIC] = {
		.mixers = { alc262_base_mixer },
		.init_verbs = { alc262_init_verbs },
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
11969
		.input_mux = &alc262_capture_source,
11970
	},
11971
	[ALC262_HIPPO] = {
11972
		.mixers = { alc262_hippo_mixer },
11973
		.init_verbs = { alc262_init_verbs, alc_hp15_unsol_verbs},
11974 11975 11976 11977 11978 11979 11980 11981
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x03,
		.dig_out_nid = ALC262_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
		.input_mux = &alc262_capture_source,
		.unsol_event = alc262_hippo_unsol_event,
11982 11983
		.setup = alc262_hippo_setup,
		.init_hook = alc262_hippo_automute,
11984 11985 11986 11987 11988 11989 11990 11991 11992 11993 11994
	},
	[ALC262_HIPPO_1] = {
		.mixers = { alc262_hippo1_mixer },
		.init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x02,
		.dig_out_nid = ALC262_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
		.input_mux = &alc262_capture_source,
11995
		.unsol_event = alc262_hippo_unsol_event,
11996 11997
		.setup = alc262_hippo1_setup,
		.init_hook = alc262_hippo_automute,
11998
	},
11999 12000
	[ALC262_FUJITSU] = {
		.mixers = { alc262_fujitsu_mixer },
12001 12002
		.init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
				alc262_fujitsu_unsol_verbs },
12003 12004 12005 12006 12007 12008 12009
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x03,
		.dig_out_nid = ALC262_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
		.input_mux = &alc262_fujitsu_capture_source,
12010
		.unsol_event = alc262_fujitsu_unsol_event,
12011
		.init_hook = alc262_fujitsu_init_hook,
12012
	},
12013 12014 12015 12016 12017 12018 12019 12020 12021
	[ALC262_HP_BPC] = {
		.mixers = { alc262_HP_BPC_mixer },
		.init_verbs = { alc262_HP_BPC_init_verbs },
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
		.input_mux = &alc262_HP_capture_source,
12022 12023
		.unsol_event = alc262_hp_bpc_unsol_event,
		.init_hook = alc262_hp_bpc_automute,
12024
	},
12025 12026 12027 12028 12029 12030 12031 12032
	[ALC262_HP_BPC_D7000_WF] = {
		.mixers = { alc262_HP_BPC_WildWest_mixer },
		.init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
12033
		.input_mux = &alc262_HP_D7000_capture_source,
12034 12035
		.unsol_event = alc262_hp_wildwest_unsol_event,
		.init_hook = alc262_hp_wildwest_automute,
12036
	},
12037 12038 12039 12040 12041 12042 12043 12044 12045
	[ALC262_HP_BPC_D7000_WL] = {
		.mixers = { alc262_HP_BPC_WildWest_mixer,
			    alc262_HP_BPC_WildWest_option_mixer },
		.init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
12046
		.input_mux = &alc262_HP_D7000_capture_source,
12047 12048
		.unsol_event = alc262_hp_wildwest_unsol_event,
		.init_hook = alc262_hp_wildwest_automute,
12049
	},
12050 12051 12052 12053 12054 12055 12056 12057 12058
	[ALC262_HP_TC_T5735] = {
		.mixers = { alc262_hp_t5735_mixer },
		.init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
		.input_mux = &alc262_capture_source,
T
Takashi Iwai 已提交
12059
		.unsol_event = alc_sku_unsol_event,
12060
		.setup = alc262_hp_t5735_setup,
T
Takashi Iwai 已提交
12061
		.init_hook = alc_inithook,
12062 12063 12064 12065 12066 12067 12068 12069 12070
	},
	[ALC262_HP_RP5700] = {
		.mixers = { alc262_hp_rp5700_mixer },
		.init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
		.input_mux = &alc262_hp_rp5700_capture_source,
12071
        },
12072 12073 12074 12075 12076 12077 12078 12079 12080
	[ALC262_BENQ_ED8] = {
		.mixers = { alc262_base_mixer },
		.init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
		.input_mux = &alc262_capture_source,
12081
	},
12082 12083 12084 12085 12086 12087 12088 12089 12090 12091
	[ALC262_SONY_ASSAMD] = {
		.mixers = { alc262_sony_mixer },
		.init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x02,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
		.input_mux = &alc262_capture_source,
		.unsol_event = alc262_hippo_unsol_event,
12092 12093
		.setup = alc262_hippo_setup,
		.init_hook = alc262_hippo_automute,
12094 12095 12096
	},
	[ALC262_BENQ_T31] = {
		.mixers = { alc262_benq_t31_mixer },
12097 12098
		.init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs,
				alc_hp15_unsol_verbs },
12099 12100 12101 12102 12103 12104 12105
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
		.input_mux = &alc262_capture_source,
		.unsol_event = alc262_hippo_unsol_event,
12106 12107
		.setup = alc262_hippo_setup,
		.init_hook = alc262_hippo_automute,
12108
	},
12109
	[ALC262_ULTRA] = {
12110 12111
		.mixers = { alc262_ultra_mixer },
		.cap_mixer = alc262_ultra_capture_mixer,
12112
		.init_verbs = { alc262_ultra_verbs },
12113 12114 12115 12116 12117
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
		.input_mux = &alc262_ultra_capture_source,
12118 12119 12120
		.adc_nids = alc262_adc_nids, /* ADC0 */
		.capsrc_nids = alc262_capsrc_nids,
		.num_adc_nids = 1, /* single ADC */
12121 12122 12123
		.unsol_event = alc262_ultra_unsol_event,
		.init_hook = alc262_ultra_automute,
	},
12124 12125 12126
	[ALC262_LENOVO_3000] = {
		.mixers = { alc262_lenovo_3000_mixer },
		.init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
12127 12128
				alc262_lenovo_3000_unsol_verbs,
				alc262_lenovo_3000_init_verbs },
12129 12130 12131 12132 12133 12134 12135 12136 12137
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x03,
		.dig_out_nid = ALC262_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
		.input_mux = &alc262_fujitsu_capture_source,
		.unsol_event = alc262_lenovo_3000_unsol_event,
	},
12138 12139 12140 12141 12142 12143 12144 12145 12146 12147
	[ALC262_NEC] = {
		.mixers = { alc262_nec_mixer },
		.init_verbs = { alc262_nec_verbs },
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
		.input_mux = &alc262_capture_source,
	},
12148 12149 12150 12151 12152 12153 12154 12155
	[ALC262_TOSHIBA_S06] = {
		.mixers = { alc262_toshiba_s06_mixer },
		.init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
							alc262_eapd_verbs },
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.capsrc_nids = alc262_dmic_capsrc_nids,
		.dac_nids = alc262_dac_nids,
		.adc_nids = alc262_dmic_adc_nids, /* ADC0 */
12156
		.num_adc_nids = 1, /* single ADC */
12157 12158 12159
		.dig_out_nid = ALC262_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
12160 12161 12162
		.unsol_event = alc_sku_unsol_event,
		.setup = alc262_toshiba_s06_setup,
		.init_hook = alc_inithook,
12163
	},
12164 12165 12166 12167 12168 12169 12170 12171 12172 12173
	[ALC262_TOSHIBA_RX1] = {
		.mixers = { alc262_toshiba_rx1_mixer },
		.init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
		.input_mux = &alc262_capture_source,
		.unsol_event = alc262_hippo_unsol_event,
12174 12175
		.setup = alc262_hippo_setup,
		.init_hook = alc262_hippo_automute,
12176
	},
12177 12178 12179 12180 12181 12182 12183 12184 12185 12186
	[ALC262_TYAN] = {
		.mixers = { alc262_tyan_mixer },
		.init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
		.num_dacs = ARRAY_SIZE(alc262_dac_nids),
		.dac_nids = alc262_dac_nids,
		.hp_nid = 0x02,
		.dig_out_nid = ALC262_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc262_modes),
		.channel_mode = alc262_modes,
		.input_mux = &alc262_capture_source,
12187
		.unsol_event = alc_automute_amp_unsol_event,
12188 12189
		.setup = alc262_tyan_setup,
		.init_hook = alc_automute_amp,
12190
	},
12191 12192 12193 12194 12195 12196 12197 12198
};

static int patch_alc262(struct hda_codec *codec)
{
	struct alc_spec *spec;
	int board_config;
	int err;

12199
	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12200 12201 12202 12203 12204
	if (spec == NULL)
		return -ENOMEM;

	codec->spec = spec;
#if 0
12205 12206 12207
	/* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
	 * under-run
	 */
12208 12209 12210 12211 12212 12213 12214 12215 12216
	{
	int tmp;
	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
	tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
	}
#endif

12217 12218
	alc_fix_pll_init(codec, 0x20, 0x0a, 10);

12219 12220 12221
	board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
						  alc262_models,
						  alc262_cfg_tbl);
12222

12223
	if (board_config < 0) {
12224 12225
		printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
		       codec->chip_name);
12226 12227 12228 12229 12230 12231 12232 12233 12234
		board_config = ALC262_AUTO;
	}

	if (board_config == ALC262_AUTO) {
		/* automatic parse from the BIOS config */
		err = alc262_parse_auto_config(codec);
		if (err < 0) {
			alc_free(codec);
			return err;
12235
		} else if (!err) {
12236 12237 12238
			printk(KERN_INFO
			       "hda_codec: Cannot set up configuration "
			       "from BIOS.  Using base mode...\n");
12239 12240 12241 12242
			board_config = ALC262_BASIC;
		}
	}

12243 12244 12245 12246 12247 12248
	if (!spec->no_analog) {
		err = snd_hda_attach_beep_device(codec, 0x1);
		if (err < 0) {
			alc_free(codec);
			return err;
		}
12249 12250
	}

12251
	if (board_config != ALC262_AUTO)
12252
		setup_preset(codec, &alc262_presets[board_config]);
12253 12254 12255

	spec->stream_analog_playback = &alc262_pcm_analog_playback;
	spec->stream_analog_capture = &alc262_pcm_analog_capture;
12256

12257 12258 12259
	spec->stream_digital_playback = &alc262_pcm_digital_playback;
	spec->stream_digital_capture = &alc262_pcm_digital_capture;

12260
	if (!spec->adc_nids && spec->input_mux) {
12261 12262 12263 12264 12265 12266 12267 12268 12269 12270 12271
		int i;
		/* check whether the digital-mic has to be supported */
		for (i = 0; i < spec->input_mux->num_items; i++) {
			if (spec->input_mux->items[i].index >= 9)
				break;
		}
		if (i < spec->input_mux->num_items) {
			/* use only ADC0 */
			spec->adc_nids = alc262_dmic_adc_nids;
			spec->num_adc_nids = 1;
			spec->capsrc_nids = alc262_dmic_capsrc_nids;
12272
		} else {
12273 12274 12275 12276 12277
			/* all analog inputs */
			/* check whether NID 0x07 is valid */
			unsigned int wcap = get_wcaps(codec, 0x07);

			/* get type */
12278
			wcap = get_wcaps_type(wcap);
12279 12280 12281 12282 12283 12284 12285 12286 12287 12288 12289
			if (wcap != AC_WID_AUD_IN) {
				spec->adc_nids = alc262_adc_nids_alt;
				spec->num_adc_nids =
					ARRAY_SIZE(alc262_adc_nids_alt);
				spec->capsrc_nids = alc262_capsrc_nids_alt;
			} else {
				spec->adc_nids = alc262_adc_nids;
				spec->num_adc_nids =
					ARRAY_SIZE(alc262_adc_nids);
				spec->capsrc_nids = alc262_capsrc_nids;
			}
12290 12291
		}
	}
12292
	if (!spec->cap_mixer && !spec->no_analog)
12293
		set_capture_mixer(codec);
12294 12295
	if (!spec->no_analog)
		set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
12296

12297 12298
	spec->vmaster_nid = 0x0c;

12299 12300
	codec->patch_ops = alc_patch_ops;
	if (board_config == ALC262_AUTO)
12301
		spec->init_hook = alc262_auto_init;
12302 12303 12304 12305
#ifdef CONFIG_SND_HDA_POWER_SAVE
	if (!spec->loopback.amplist)
		spec->loopback.amplist = alc262_loopbacks;
#endif
12306

12307 12308 12309
	return 0;
}

12310 12311 12312 12313 12314
/*
 *  ALC268 channel source setting (2 channel)
 */
#define ALC268_DIGOUT_NID	ALC880_DIGOUT_NID
#define alc268_modes		alc260_modes
12315

12316 12317 12318 12319 12320 12321 12322 12323 12324 12325 12326 12327 12328 12329 12330
static hda_nid_t alc268_dac_nids[2] = {
	/* front, hp */
	0x02, 0x03
};

static hda_nid_t alc268_adc_nids[2] = {
	/* ADC0-1 */
	0x08, 0x07
};

static hda_nid_t alc268_adc_nids_alt[1] = {
	/* ADC0 */
	0x08
};

12331 12332
static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };

12333 12334 12335 12336 12337 12338
static struct snd_kcontrol_new alc268_base_mixer[] = {
	/* output mixer control */
	HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12339 12340 12341
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
12342 12343 12344
	{ }
};

12345 12346 12347 12348 12349 12350 12351 12352 12353 12354 12355
static struct snd_kcontrol_new alc268_toshiba_mixer[] = {
	/* output mixer control */
	HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
	ALC262_HIPPO_MASTER_SWITCH,
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
	{ }
};

12356 12357 12358 12359 12360 12361 12362 12363 12364 12365 12366 12367 12368 12369 12370 12371
/* bind Beep switches of both NID 0x0f and 0x10 */
static struct hda_bind_ctls alc268_bind_beep_sw = {
	.ops = &snd_hda_bind_sw,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
		HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
		0
	},
};

static struct snd_kcontrol_new alc268_beep_mixer[] = {
	HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
	HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
	{ }
};

12372 12373 12374 12375 12376 12377
static struct hda_verb alc268_eapd_verbs[] = {
	{0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
	{0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
	{ }
};

12378 12379 12380 12381 12382 12383 12384
/* Toshiba specific */
static struct hda_verb alc268_toshiba_verbs[] = {
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{ } /* end */
};

/* Acer specific */
12385
/* bind volumes of both NID 0x02 and 0x03 */
12386 12387 12388 12389 12390 12391 12392 12393 12394
static struct hda_bind_ctls alc268_acer_bind_master_vol = {
	.ops = &snd_hda_bind_vol,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
		0
	},
};

12395 12396 12397 12398 12399 12400 12401
/* mute/unmute internal speaker according to the hp jack and mute state */
static void alc268_acer_automute(struct hda_codec *codec, int force)
{
	struct alc_spec *spec = codec->spec;
	unsigned int mute;

	if (force || !spec->sense_updated) {
12402
		spec->jack_present = snd_hda_jack_detect(codec, 0x14);
12403 12404 12405 12406 12407 12408 12409 12410 12411 12412 12413 12414 12415 12416 12417 12418 12419 12420 12421
		spec->sense_updated = 1;
	}
	if (spec->jack_present)
		mute = HDA_AMP_MUTE; /* mute internal speaker */
	else /* unmute internal speaker if necessary */
		mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
	snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, mute);
}


/* bind hp and internal speaker mute (with plug check) */
static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
				     struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	long *valp = ucontrol->value.integer.value;
	int change;

12422
	change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
12423 12424 12425 12426
	if (change)
		alc268_acer_automute(codec, 0);
	return change;
}
12427

12428 12429 12430 12431 12432 12433
static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
	/* output mixer control */
	HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Master Playback Switch",
12434
		.subdevice = HDA_SUBDEV_AMP_FLAG,
12435 12436 12437 12438 12439 12440 12441 12442 12443
		.info = snd_hda_mixer_amp_switch_info,
		.get = snd_hda_mixer_amp_switch_get,
		.put = alc268_acer_master_sw_put,
		.private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
	},
	HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
	{ }
};

12444 12445 12446 12447 12448 12449
static struct snd_kcontrol_new alc268_acer_mixer[] = {
	/* output mixer control */
	HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Master Playback Switch",
12450
		.subdevice = HDA_SUBDEV_AMP_FLAG,
12451 12452 12453 12454 12455
		.info = snd_hda_mixer_amp_switch_info,
		.get = snd_hda_mixer_amp_switch_get,
		.put = alc268_acer_master_sw_put,
		.private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
	},
12456 12457 12458
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
12459 12460 12461
	{ }
};

T
Takashi Iwai 已提交
12462 12463 12464 12465 12466 12467
static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
	/* output mixer control */
	HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Master Playback Switch",
12468
		.subdevice = HDA_SUBDEV_AMP_FLAG,
T
Takashi Iwai 已提交
12469 12470 12471 12472 12473 12474 12475 12476 12477 12478
		.info = snd_hda_mixer_amp_switch_info,
		.get = snd_hda_mixer_amp_switch_get,
		.put = alc268_acer_master_sw_put,
		.private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
	},
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
	{ }
};

12479 12480 12481 12482 12483 12484 12485 12486 12487 12488
static struct hda_verb alc268_acer_aspire_one_verbs[] = {
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
	{ }
};

12489
static struct hda_verb alc268_acer_verbs[] = {
12490 12491
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12492 12493
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12494 12495
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12496 12497 12498 12499 12500
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{ }
};

/* unsolicited event for HP jack sensing */
12501
#define alc268_toshiba_unsol_event	alc262_hippo_unsol_event
12502 12503
#define alc268_toshiba_setup		alc262_hippo_setup
#define alc268_toshiba_automute		alc262_hippo_automute
12504 12505 12506 12507

static void alc268_acer_unsol_event(struct hda_codec *codec,
				       unsigned int res)
{
12508
	if ((res >> 26) != ALC880_HP_EVENT)
12509 12510 12511 12512
		return;
	alc268_acer_automute(codec, 1);
}

12513 12514 12515 12516 12517
static void alc268_acer_init_hook(struct hda_codec *codec)
{
	alc268_acer_automute(codec, 1);
}

12518 12519 12520 12521 12522 12523
/* toggle speaker-output according to the hp-jack state */
static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
{
	unsigned int present;
	unsigned char bits;

12524
	present = snd_hda_jack_detect(codec, 0x15);
12525
	bits = present ? HDA_AMP_MUTE : 0;
12526
	snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
12527
				 HDA_AMP_MUTE, bits);
12528
	snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
12529
				 HDA_AMP_MUTE, bits);
12530 12531 12532 12533 12534
}

static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
				    unsigned int res)
{
12535 12536
	switch (res >> 26) {
	case ALC880_HP_EVENT:
12537
		alc268_aspire_one_speaker_automute(codec);
12538 12539 12540 12541 12542 12543 12544 12545 12546 12547 12548 12549 12550 12551 12552
		break;
	case ALC880_MIC_EVENT:
		alc_mic_automute(codec);
		break;
	}
}

static void alc268_acer_lc_setup(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	spec->ext_mic.pin = 0x18;
	spec->ext_mic.mux_idx = 0;
	spec->int_mic.pin = 0x12;
	spec->int_mic.mux_idx = 6;
	spec->auto_mic = 1;
12553 12554 12555 12556 12557
}

static void alc268_acer_lc_init_hook(struct hda_codec *codec)
{
	alc268_aspire_one_speaker_automute(codec);
12558
	alc_mic_automute(codec);
12559 12560
}

12561 12562 12563 12564 12565 12566 12567 12568 12569 12570 12571 12572 12573 12574 12575
static struct snd_kcontrol_new alc268_dell_mixer[] = {
	/* output mixer control */
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
	{ }
};

static struct hda_verb alc268_dell_verbs[] = {
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12576
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12577 12578 12579 12580
	{ }
};

/* mute/unmute internal speaker according to the hp jack and mute state */
12581
static void alc268_dell_setup(struct hda_codec *codec)
12582
{
12583
	struct alc_spec *spec = codec->spec;
12584

12585 12586
	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
12587 12588 12589 12590 12591
	spec->ext_mic.pin = 0x18;
	spec->ext_mic.mux_idx = 0;
	spec->int_mic.pin = 0x19;
	spec->int_mic.mux_idx = 1;
	spec->auto_mic = 1;
12592 12593
}

12594 12595 12596 12597 12598 12599 12600 12601 12602 12603 12604 12605 12606 12607 12608 12609 12610 12611
static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
	{ }
};

static struct hda_verb alc267_quanta_il1_verbs[] = {
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
	{ }
};

12612
static void alc267_quanta_il1_setup(struct hda_codec *codec)
12613
{
12614 12615 12616
	struct alc_spec *spec = codec->spec;
	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
12617 12618 12619 12620 12621
	spec->ext_mic.pin = 0x18;
	spec->ext_mic.mux_idx = 0;
	spec->int_mic.pin = 0x19;
	spec->int_mic.mux_idx = 1;
	spec->auto_mic = 1;
12622 12623
}

12624 12625 12626 12627 12628 12629 12630 12631 12632 12633 12634 12635 12636 12637 12638 12639 12640 12641 12642 12643 12644 12645 12646 12647 12648 12649 12650 12651 12652 12653 12654 12655
/*
 * generic initialization of ADC, input mixers and output mixers
 */
static struct hda_verb alc268_base_init_verbs[] = {
	/* Unmute DAC0-1 and set vol = 0 */
	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},

	/*
	 * Set up output mixers (0x0c - 0x0e)
	 */
	/* set vol=0 to output mixers */
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},

	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},

	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},

	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12656 12657 12658 12659 12660

	/* set PCBEEP vol = 0, mute connections */
	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12661

12662
	/* Unmute Selector 23h,24h and set the default input to mic-in */
12663

12664 12665 12666 12667
	{0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12668 12669 12670 12671 12672 12673 12674 12675 12676

	{ }
};

/*
 * generic initialization of ADC, input mixers and output mixers
 */
static struct hda_verb alc268_volume_init_verbs[] = {
	/* set output DAC */
12677 12678
	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12679 12680 12681 12682 12683 12684 12685 12686 12687 12688 12689 12690 12691 12692

	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},

	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},

	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},

12693 12694 12695 12696
	/* set PCBEEP vol = 0, mute connections */
	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12697 12698 12699 12700

	{ }
};

12701 12702 12703 12704 12705 12706
static struct snd_kcontrol_new alc268_capture_nosrc_mixer[] = {
	HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
	{ } /* end */
};

12707 12708 12709
static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
	HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12710
	_DEFINE_CAPSRC(1),
12711 12712 12713 12714 12715 12716 12717 12718
	{ } /* end */
};

static struct snd_kcontrol_new alc268_capture_mixer[] = {
	HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
12719
	_DEFINE_CAPSRC(2),
12720 12721 12722 12723 12724 12725 12726 12727 12728 12729 12730 12731 12732
	{ } /* end */
};

static struct hda_input_mux alc268_capture_source = {
	.num_items = 4,
	.items = {
		{ "Mic", 0x0 },
		{ "Front Mic", 0x1 },
		{ "Line", 0x2 },
		{ "CD", 0x3 },
	},
};

12733
static struct hda_input_mux alc268_acer_capture_source = {
T
Takashi Iwai 已提交
12734 12735 12736 12737 12738 12739 12740 12741 12742
	.num_items = 3,
	.items = {
		{ "Mic", 0x0 },
		{ "Internal Mic", 0x1 },
		{ "Line", 0x2 },
	},
};

static struct hda_input_mux alc268_acer_dmic_capture_source = {
12743 12744 12745 12746 12747 12748 12749 12750
	.num_items = 3,
	.items = {
		{ "Mic", 0x0 },
		{ "Internal Mic", 0x6 },
		{ "Line", 0x2 },
	},
};

12751 12752 12753 12754 12755 12756 12757 12758 12759 12760 12761 12762 12763 12764 12765 12766
#ifdef CONFIG_SND_DEBUG
static struct snd_kcontrol_new alc268_test_mixer[] = {
	/* Volume widgets */
	HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
	HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
	HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
	HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
	HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
	HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
	HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
	HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
	HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
12767 12768
	/* The below appears problematic on some hardwares */
	/*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
12769 12770 12771 12772 12773 12774 12775 12776 12777 12778 12779 12780 12781 12782 12783 12784 12785 12786 12787 12788 12789 12790 12791 12792 12793 12794 12795 12796 12797 12798 12799 12800
	HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
	HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),

	/* Modes for retasking pin widgets */
	ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
	ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
	ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
	ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),

	/* Controls for GPIO pins, assuming they are configured as outputs */
	ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
	ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
	ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
	ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),

	/* Switches to allow the digital SPDIF output pin to be enabled.
	 * The ALC268 does not have an SPDIF input.
	 */
	ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),

	/* A switch allowing EAPD to be enabled.  Some laptops seem to use
	 * this output to turn on an external amplifier.
	 */
	ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
	ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),

	{ } /* end */
};
#endif

12801 12802 12803 12804
/* create input playback/capture controls for the given pin */
static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
				    const char *ctlname, int idx)
{
12805
	hda_nid_t dac;
12806 12807
	int err;

12808 12809 12810 12811 12812 12813 12814 12815 12816 12817 12818 12819 12820
	switch (nid) {
	case 0x14:
	case 0x16:
		dac = 0x02;
		break;
	case 0x15:
		dac = 0x03;
		break;
	default:
		return 0;
	}
	if (spec->multiout.dac_nids[0] != dac &&
	    spec->multiout.dac_nids[1] != dac) {
12821
		err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
12822
				  HDA_COMPOSE_AMP_VAL(dac, 3, idx,
12823 12824 12825
						      HDA_OUTPUT));
		if (err < 0)
			return err;
12826 12827 12828 12829
		spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
	}

	if (nid != 0x16)
12830
		err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12831
			  HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
12832
	else /* mono */
12833
		err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12834
			  HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT));
12835 12836 12837 12838 12839 12840 12841 12842 12843 12844 12845 12846 12847 12848 12849
	if (err < 0)
		return err;
	return 0;
}

/* add playback controls from the parsed DAC table */
static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
					     const struct auto_pin_cfg *cfg)
{
	hda_nid_t nid;
	int err;

	spec->multiout.dac_nids = spec->private_dac_nids;

	nid = cfg->line_out_pins[0];
12850 12851 12852 12853 12854 12855 12856 12857 12858 12859
	if (nid) {
		const char *name;
		if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
			name = "Speaker";
		else
			name = "Front";
		err = alc268_new_analog_output(spec, nid, name, 0);
		if (err < 0)
			return err;
	}
12860 12861 12862

	nid = cfg->speaker_pins[0];
	if (nid == 0x1d) {
12863
		err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, "Speaker",
12864 12865 12866
				  HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
		if (err < 0)
			return err;
12867 12868 12869 12870
	} else {
		err = alc268_new_analog_output(spec, nid, "Speaker", 0);
		if (err < 0)
			return err;
12871 12872
	}
	nid = cfg->hp_pins[0];
12873 12874 12875 12876 12877
	if (nid) {
		err = alc268_new_analog_output(spec, nid, "Headphone", 0);
		if (err < 0)
			return err;
	}
12878 12879 12880

	nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
	if (nid == 0x16) {
12881
		err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, "Mono",
12882
				  HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
12883 12884 12885
		if (err < 0)
			return err;
	}
12886
	return 0;
12887 12888 12889
}

/* create playback/capture controls for input pins */
12890
static int alc268_auto_create_input_ctls(struct hda_codec *codec,
12891 12892
						const struct auto_pin_cfg *cfg)
{
12893
	return alc_auto_create_input_ctls(codec, cfg, 0, 0x23, 0x24);
12894 12895
}

12896 12897 12898 12899 12900 12901 12902 12903 12904 12905 12906 12907 12908 12909 12910 12911 12912 12913 12914 12915 12916 12917 12918 12919 12920 12921 12922 12923 12924 12925 12926 12927 12928 12929 12930 12931
static void alc268_auto_set_output_and_unmute(struct hda_codec *codec,
					      hda_nid_t nid, int pin_type)
{
	int idx;

	alc_set_pin_output(codec, nid, pin_type);
	if (nid == 0x14 || nid == 0x16)
		idx = 0;
	else
		idx = 1;
	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
}

static void alc268_auto_init_multi_out(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	hda_nid_t nid = spec->autocfg.line_out_pins[0];
	if (nid) {
		int pin_type = get_pin_type(spec->autocfg.line_out_type);
		alc268_auto_set_output_and_unmute(codec, nid, pin_type);
	}
}

static void alc268_auto_init_hp_out(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	hda_nid_t pin;

	pin = spec->autocfg.hp_pins[0];
	if (pin)
		alc268_auto_set_output_and_unmute(codec, pin, PIN_HP);
	pin = spec->autocfg.speaker_pins[0];
	if (pin)
		alc268_auto_set_output_and_unmute(codec, pin, PIN_OUT);
}

12932 12933 12934 12935 12936 12937 12938 12939
static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
	hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
	hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
	unsigned int	dac_vol1, dac_vol2;

12940
	if (line_nid == 0x1d || speaker_nid == 0x1d) {
12941 12942
		snd_hda_codec_write(codec, speaker_nid, 0,
				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
12943
		/* mute mixer inputs from 0x1d */
12944 12945 12946 12947 12948 12949 12950
		snd_hda_codec_write(codec, 0x0f, 0,
				    AC_VERB_SET_AMP_GAIN_MUTE,
				    AMP_IN_UNMUTE(1));
		snd_hda_codec_write(codec, 0x10, 0,
				    AC_VERB_SET_AMP_GAIN_MUTE,
				    AMP_IN_UNMUTE(1));
	} else {
12951
		/* unmute mixer inputs from 0x1d */
12952 12953 12954 12955 12956 12957 12958
		snd_hda_codec_write(codec, 0x0f, 0,
				    AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
		snd_hda_codec_write(codec, 0x10, 0,
				    AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
	}

	dac_vol1 = dac_vol2 = 0xb000 | 0x40;	/* set max volume  */
12959
	if (line_nid == 0x14)
12960 12961 12962
		dac_vol2 = AMP_OUT_ZERO;
	else if (line_nid == 0x15)
		dac_vol1 = AMP_OUT_ZERO;
12963
	if (hp_nid == 0x14)
12964 12965 12966 12967 12968 12969 12970 12971 12972 12973 12974 12975 12976 12977
		dac_vol2 = AMP_OUT_ZERO;
	else if (hp_nid == 0x15)
		dac_vol1 = AMP_OUT_ZERO;
	if (line_nid != 0x16 || hp_nid != 0x16 ||
	    spec->autocfg.line_out_pins[1] != 0x16 ||
	    spec->autocfg.line_out_pins[2] != 0x16)
		dac_vol1 = dac_vol2 = AMP_OUT_ZERO;

	snd_hda_codec_write(codec, 0x02, 0,
			    AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
	snd_hda_codec_write(codec, 0x03, 0,
			    AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
}

12978
/* pcm configuration: identical with ALC880 */
12979 12980
#define alc268_pcm_analog_playback	alc880_pcm_analog_playback
#define alc268_pcm_analog_capture	alc880_pcm_analog_capture
12981
#define alc268_pcm_analog_alt_capture	alc880_pcm_analog_alt_capture
12982 12983 12984 12985 12986 12987 12988 12989 12990 12991 12992 12993 12994 12995 12996
#define alc268_pcm_digital_playback	alc880_pcm_digital_playback

/*
 * BIOS auto configuration
 */
static int alc268_parse_auto_config(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int err;
	static hda_nid_t alc268_ignore[] = { 0 };

	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
					   alc268_ignore);
	if (err < 0)
		return err;
12997 12998 12999 13000 13001 13002
	if (!spec->autocfg.line_outs) {
		if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
			spec->multiout.max_channels = 2;
			spec->no_analog = 1;
			goto dig_only;
		}
13003
		return 0; /* can't find valid BIOS pin config */
13004
	}
13005 13006 13007
	err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
	if (err < 0)
		return err;
13008
	err = alc268_auto_create_input_ctls(codec, &spec->autocfg);
13009 13010 13011 13012 13013
	if (err < 0)
		return err;

	spec->multiout.max_channels = 2;

13014
 dig_only:
13015
	/* digital only support output */
13016
	if (spec->autocfg.dig_outs) {
13017
		spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
13018 13019
		spec->dig_out_type = spec->autocfg.dig_out_type[0];
	}
13020
	if (spec->kctls.list)
13021
		add_mixer(spec, spec->kctls.list);
13022

13023
	if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d)
13024
		add_mixer(spec, alc268_beep_mixer);
13025

13026
	add_verb(spec, alc268_volume_init_verbs);
13027
	spec->num_mux_defs = 2;
13028
	spec->input_mux = &spec->private_imux[0];
13029

13030 13031 13032 13033
	err = alc_auto_add_mic_boost(codec);
	if (err < 0)
		return err;

13034
	alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
13035

13036 13037 13038 13039 13040 13041 13042 13043
	return 1;
}

#define alc268_auto_init_analog_input	alc882_auto_init_analog_input

/* init callback for auto-configuration model -- overriding the default init */
static void alc268_auto_init(struct hda_codec *codec)
{
13044
	struct alc_spec *spec = codec->spec;
13045 13046 13047 13048
	alc268_auto_init_multi_out(codec);
	alc268_auto_init_hp_out(codec);
	alc268_auto_init_mono_speaker_out(codec);
	alc268_auto_init_analog_input(codec);
13049
	if (spec->unsol_event)
13050
		alc_inithook(codec);
13051 13052 13053 13054 13055 13056
}

/*
 * configuration and preset
 */
static const char *alc268_models[ALC268_MODEL_LAST] = {
13057
	[ALC267_QUANTA_IL1]	= "quanta-il1",
13058
	[ALC268_3ST]		= "3stack",
13059
	[ALC268_TOSHIBA]	= "toshiba",
13060
	[ALC268_ACER]		= "acer",
T
Takashi Iwai 已提交
13061
	[ALC268_ACER_DMIC]	= "acer-dmic",
13062
	[ALC268_ACER_ASPIRE_ONE]	= "acer-aspire",
13063
	[ALC268_DELL]		= "dell",
13064
	[ALC268_ZEPTO]		= "zepto",
13065 13066 13067
#ifdef CONFIG_SND_DEBUG
	[ALC268_TEST]		= "test",
#endif
13068 13069 13070 13071
	[ALC268_AUTO]		= "auto",
};

static struct snd_pci_quirk alc268_cfg_tbl[] = {
13072
	SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
13073
	SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
13074
	SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
13075
	SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
13076
	SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
13077 13078
	SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
						ALC268_ACER_ASPIRE_ONE),
13079
	SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
13080 13081
	SND_PCI_QUIRK_MASK(0x1028, 0xfff0, 0x02b0,
			"Dell Inspiron Mini9/Vostro A90", ALC268_DELL),
13082 13083 13084
	/* almost compatible with toshiba but with optional digital outs;
	 * auto-probing seems working fine
	 */
13085
	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
13086
			   ALC268_AUTO),
13087
	SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
13088
	SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
13089
	SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
13090
	SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
13091
	SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
13092
	SND_PCI_QUIRK(0x1854, 0x1775, "LG R510", ALC268_DELL),
13093 13094 13095
	{}
};

13096 13097 13098 13099 13100 13101 13102 13103 13104
/* Toshiba laptops have no unique PCI SSID but only codec SSID */
static struct snd_pci_quirk alc268_ssid_cfg_tbl[] = {
	SND_PCI_QUIRK(0x1179, 0xff0a, "TOSHIBA X-200", ALC268_AUTO),
	SND_PCI_QUIRK(0x1179, 0xff0e, "TOSHIBA X-200 HDMI", ALC268_AUTO),
	SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
			   ALC268_TOSHIBA),
	{}
};

13105
static struct alc_config_preset alc268_presets[] = {
13106
	[ALC267_QUANTA_IL1] = {
13107 13108
		.mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer,
			    alc268_capture_nosrc_mixer },
13109 13110 13111 13112 13113 13114 13115 13116 13117
		.init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
				alc267_quanta_il1_verbs },
		.num_dacs = ARRAY_SIZE(alc268_dac_nids),
		.dac_nids = alc268_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
		.adc_nids = alc268_adc_nids_alt,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc268_modes),
		.channel_mode = alc268_modes,
13118 13119 13120
		.unsol_event = alc_sku_unsol_event,
		.setup = alc267_quanta_il1_setup,
		.init_hook = alc_inithook,
13121
	},
13122
	[ALC268_3ST] = {
13123 13124
		.mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
			    alc268_beep_mixer },
13125 13126 13127 13128 13129
		.init_verbs = { alc268_base_init_verbs },
		.num_dacs = ARRAY_SIZE(alc268_dac_nids),
		.dac_nids = alc268_dac_nids,
                .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
                .adc_nids = alc268_adc_nids_alt,
13130
		.capsrc_nids = alc268_capsrc_nids,
13131 13132 13133 13134 13135 13136
		.hp_nid = 0x03,
		.dig_out_nid = ALC268_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc268_modes),
		.channel_mode = alc268_modes,
		.input_mux = &alc268_capture_source,
	},
13137
	[ALC268_TOSHIBA] = {
13138
		.mixers = { alc268_toshiba_mixer, alc268_capture_alt_mixer,
13139
			    alc268_beep_mixer },
13140 13141
		.init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
				alc268_toshiba_verbs },
13142 13143 13144 13145
		.num_dacs = ARRAY_SIZE(alc268_dac_nids),
		.dac_nids = alc268_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
		.adc_nids = alc268_adc_nids_alt,
13146
		.capsrc_nids = alc268_capsrc_nids,
13147 13148 13149 13150
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc268_modes),
		.channel_mode = alc268_modes,
		.input_mux = &alc268_capture_source,
13151
		.unsol_event = alc268_toshiba_unsol_event,
13152 13153
		.setup = alc268_toshiba_setup,
		.init_hook = alc268_toshiba_automute,
13154 13155
	},
	[ALC268_ACER] = {
13156
		.mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
13157
			    alc268_beep_mixer },
13158 13159 13160 13161 13162 13163
		.init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
				alc268_acer_verbs },
		.num_dacs = ARRAY_SIZE(alc268_dac_nids),
		.dac_nids = alc268_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
		.adc_nids = alc268_adc_nids_alt,
13164
		.capsrc_nids = alc268_capsrc_nids,
13165 13166 13167
		.hp_nid = 0x02,
		.num_channel_mode = ARRAY_SIZE(alc268_modes),
		.channel_mode = alc268_modes,
13168
		.input_mux = &alc268_acer_capture_source,
13169
		.unsol_event = alc268_acer_unsol_event,
13170
		.init_hook = alc268_acer_init_hook,
13171
	},
T
Takashi Iwai 已提交
13172 13173 13174 13175 13176 13177 13178 13179 13180 13181 13182 13183 13184 13185 13186 13187 13188
	[ALC268_ACER_DMIC] = {
		.mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
			    alc268_beep_mixer },
		.init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
				alc268_acer_verbs },
		.num_dacs = ARRAY_SIZE(alc268_dac_nids),
		.dac_nids = alc268_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
		.adc_nids = alc268_adc_nids_alt,
		.capsrc_nids = alc268_capsrc_nids,
		.hp_nid = 0x02,
		.num_channel_mode = ARRAY_SIZE(alc268_modes),
		.channel_mode = alc268_modes,
		.input_mux = &alc268_acer_dmic_capture_source,
		.unsol_event = alc268_acer_unsol_event,
		.init_hook = alc268_acer_init_hook,
	},
13189 13190
	[ALC268_ACER_ASPIRE_ONE] = {
		.mixers = { alc268_acer_aspire_one_mixer,
13191
			    alc268_beep_mixer,
13192
			    alc268_capture_nosrc_mixer },
13193 13194 13195 13196 13197 13198 13199 13200 13201 13202 13203
		.init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
				alc268_acer_aspire_one_verbs },
		.num_dacs = ARRAY_SIZE(alc268_dac_nids),
		.dac_nids = alc268_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
		.adc_nids = alc268_adc_nids_alt,
		.capsrc_nids = alc268_capsrc_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc268_modes),
		.channel_mode = alc268_modes,
		.unsol_event = alc268_acer_lc_unsol_event,
13204
		.setup = alc268_acer_lc_setup,
13205 13206
		.init_hook = alc268_acer_lc_init_hook,
	},
13207
	[ALC268_DELL] = {
13208 13209
		.mixers = { alc268_dell_mixer, alc268_beep_mixer,
			    alc268_capture_nosrc_mixer },
13210 13211 13212 13213
		.init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
				alc268_dell_verbs },
		.num_dacs = ARRAY_SIZE(alc268_dac_nids),
		.dac_nids = alc268_dac_nids,
13214 13215 13216
		.num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
		.adc_nids = alc268_adc_nids_alt,
		.capsrc_nids = alc268_capsrc_nids,
13217 13218 13219
		.hp_nid = 0x02,
		.num_channel_mode = ARRAY_SIZE(alc268_modes),
		.channel_mode = alc268_modes,
13220
		.unsol_event = alc_sku_unsol_event,
13221 13222
		.setup = alc268_dell_setup,
		.init_hook = alc_inithook,
13223
	},
13224
	[ALC268_ZEPTO] = {
13225 13226
		.mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
			    alc268_beep_mixer },
13227 13228 13229 13230 13231 13232
		.init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
				alc268_toshiba_verbs },
		.num_dacs = ARRAY_SIZE(alc268_dac_nids),
		.dac_nids = alc268_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
		.adc_nids = alc268_adc_nids_alt,
13233
		.capsrc_nids = alc268_capsrc_nids,
13234 13235 13236 13237 13238
		.hp_nid = 0x03,
		.dig_out_nid = ALC268_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc268_modes),
		.channel_mode = alc268_modes,
		.input_mux = &alc268_capture_source,
13239 13240
		.setup = alc268_toshiba_setup,
		.init_hook = alc268_toshiba_automute,
13241
	},
13242 13243 13244 13245 13246 13247 13248 13249 13250
#ifdef CONFIG_SND_DEBUG
	[ALC268_TEST] = {
		.mixers = { alc268_test_mixer, alc268_capture_mixer },
		.init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
				alc268_volume_init_verbs },
		.num_dacs = ARRAY_SIZE(alc268_dac_nids),
		.dac_nids = alc268_dac_nids,
		.num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
		.adc_nids = alc268_adc_nids_alt,
13251
		.capsrc_nids = alc268_capsrc_nids,
13252 13253 13254 13255 13256 13257 13258
		.hp_nid = 0x03,
		.dig_out_nid = ALC268_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc268_modes),
		.channel_mode = alc268_modes,
		.input_mux = &alc268_capture_source,
	},
#endif
13259 13260 13261 13262 13263 13264
};

static int patch_alc268(struct hda_codec *codec)
{
	struct alc_spec *spec;
	int board_config;
13265
	int i, has_beep, err;
13266

13267
	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13268 13269 13270 13271 13272 13273 13274 13275 13276
	if (spec == NULL)
		return -ENOMEM;

	codec->spec = spec;

	board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
						  alc268_models,
						  alc268_cfg_tbl);

13277 13278
	if (board_config < 0 || board_config >= ALC268_MODEL_LAST)
		board_config = snd_hda_check_board_codec_sid_config(codec,
13279
			ALC268_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
13280

13281
	if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
13282 13283
		printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
		       codec->chip_name);
13284 13285 13286 13287 13288 13289 13290 13291 13292 13293 13294 13295 13296 13297 13298 13299 13300 13301
		board_config = ALC268_AUTO;
	}

	if (board_config == ALC268_AUTO) {
		/* automatic parse from the BIOS config */
		err = alc268_parse_auto_config(codec);
		if (err < 0) {
			alc_free(codec);
			return err;
		} else if (!err) {
			printk(KERN_INFO
			       "hda_codec: Cannot set up configuration "
			       "from BIOS.  Using base mode...\n");
			board_config = ALC268_3ST;
		}
	}

	if (board_config != ALC268_AUTO)
13302
		setup_preset(codec, &alc268_presets[board_config]);
13303 13304 13305

	spec->stream_analog_playback = &alc268_pcm_analog_playback;
	spec->stream_analog_capture = &alc268_pcm_analog_capture;
13306
	spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
13307 13308 13309

	spec->stream_digital_playback = &alc268_pcm_digital_playback;

13310 13311 13312 13313 13314 13315 13316 13317 13318 13319 13320 13321 13322 13323 13324 13325 13326
	has_beep = 0;
	for (i = 0; i < spec->num_mixers; i++) {
		if (spec->mixers[i] == alc268_beep_mixer) {
			has_beep = 1;
			break;
		}
	}

	if (has_beep) {
		err = snd_hda_attach_beep_device(codec, 0x1);
		if (err < 0) {
			alc_free(codec);
			return err;
		}
		if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
			/* override the amp caps for beep generator */
			snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
13327 13328 13329 13330
					  (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
					  (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
					  (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
					  (0 << AC_AMPCAP_MUTE_SHIFT));
13331
	}
13332

13333
	if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
13334 13335
		/* check whether NID 0x07 is valid */
		unsigned int wcap = get_wcaps(codec, 0x07);
13336
		int i;
13337

13338
		spec->capsrc_nids = alc268_capsrc_nids;
13339
		/* get type */
13340
		wcap = get_wcaps_type(wcap);
13341 13342
		if (spec->auto_mic ||
		    wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
13343 13344
			spec->adc_nids = alc268_adc_nids_alt;
			spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
13345 13346
			if (spec->auto_mic)
				fixup_automic_adc(codec);
13347 13348 13349 13350
			if (spec->auto_mic || spec->input_mux->num_items == 1)
				add_mixer(spec, alc268_capture_nosrc_mixer);
			else
				add_mixer(spec, alc268_capture_alt_mixer);
13351 13352 13353
		} else {
			spec->adc_nids = alc268_adc_nids;
			spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
13354
			add_mixer(spec, alc268_capture_mixer);
13355
		}
13356 13357 13358 13359
		/* set default input source */
		for (i = 0; i < spec->num_adc_nids; i++)
			snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
				0, AC_VERB_SET_CONNECT_SEL,
13360 13361
				i < spec->num_mux_defs ?
				spec->input_mux[i].items[0].index :
13362
				spec->input_mux->items[0].index);
13363
	}
13364 13365 13366

	spec->vmaster_nid = 0x02;

13367 13368 13369
	codec->patch_ops = alc_patch_ops;
	if (board_config == ALC268_AUTO)
		spec->init_hook = alc268_auto_init;
13370

13371 13372 13373
	return 0;
}

13374 13375 13376 13377 13378 13379 13380 13381 13382
/*
 *  ALC269 channel source setting (2 channel)
 */
#define ALC269_DIGOUT_NID	ALC880_DIGOUT_NID

#define alc269_dac_nids		alc260_dac_nids

static hda_nid_t alc269_adc_nids[1] = {
	/* ADC1 */
13383 13384 13385
	0x08,
};

13386 13387 13388 13389
static hda_nid_t alc269_capsrc_nids[1] = {
	0x23,
};

K
Kailang Yang 已提交
13390 13391 13392 13393 13394 13395 13396 13397 13398
static hda_nid_t alc269vb_adc_nids[1] = {
	/* ADC1 */
	0x09,
};

static hda_nid_t alc269vb_capsrc_nids[1] = {
	0x22,
};

13399 13400 13401
static hda_nid_t alc269_adc_candidates[] = {
	0x08, 0x09, 0x07,
};
13402

13403 13404 13405 13406 13407 13408 13409 13410 13411 13412 13413 13414 13415 13416 13417 13418 13419 13420 13421
#define alc269_modes		alc260_modes
#define alc269_capture_source	alc880_lg_lw_capture_source

static struct snd_kcontrol_new alc269_base_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
	{ } /* end */
};

13422 13423 13424 13425 13426 13427
static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
	/* output mixer control */
	HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Master Playback Switch",
13428
		.subdevice = HDA_SUBDEV_AMP_FLAG,
13429 13430 13431 13432 13433 13434 13435 13436 13437 13438 13439 13440 13441 13442
		.info = snd_hda_mixer_amp_switch_info,
		.get = snd_hda_mixer_amp_switch_get,
		.put = alc268_acer_master_sw_put,
		.private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
	},
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
	{ }
};

13443 13444 13445 13446 13447 13448
static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
	/* output mixer control */
	HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Master Playback Switch",
13449
		.subdevice = HDA_SUBDEV_AMP_FLAG,
13450 13451 13452 13453 13454 13455 13456 13457 13458 13459 13460 13461 13462 13463 13464 13465 13466
		.info = snd_hda_mixer_amp_switch_info,
		.get = snd_hda_mixer_amp_switch_get,
		.put = alc268_acer_master_sw_put,
		.private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
	},
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
	HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
	HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
	HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
	{ }
};

K
Kailang Yang 已提交
13467
static struct snd_kcontrol_new alc269_laptop_mixer[] = {
13468
	HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13469
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13470
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13471
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13472 13473 13474
	{ } /* end */
};

K
Kailang Yang 已提交
13475 13476 13477 13478 13479 13480 13481 13482
static struct snd_kcontrol_new alc269vb_laptop_mixer[] = {
	HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
	{ } /* end */
};

13483
/* capture mixer elements */
K
Kailang Yang 已提交
13484 13485 13486 13487 13488 13489 13490 13491 13492
static struct snd_kcontrol_new alc269_laptop_analog_capture_mixer[] = {
	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("IntMic Boost", 0x19, 0, HDA_INPUT),
	{ } /* end */
};

static struct snd_kcontrol_new alc269_laptop_digital_capture_mixer[] = {
13493 13494
	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
13495 13496 13497 13498
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	{ } /* end */
};

K
Kailang Yang 已提交
13499 13500 13501 13502 13503 13504 13505 13506 13507 13508 13509 13510 13511 13512 13513
static struct snd_kcontrol_new alc269vb_laptop_analog_capture_mixer[] = {
	HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("IntMic Boost", 0x19, 0, HDA_INPUT),
	{ } /* end */
};

static struct snd_kcontrol_new alc269vb_laptop_digital_capture_mixer[] = {
	HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	{ } /* end */
};

13514
/* FSC amilo */
K
Kailang Yang 已提交
13515
#define alc269_fujitsu_mixer	alc269_laptop_mixer
13516

13517 13518 13519 13520 13521 13522 13523 13524 13525
static struct hda_verb alc269_quanta_fl1_verbs[] = {
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{ }
};
13526

13527 13528 13529 13530 13531 13532 13533 13534 13535 13536 13537 13538 13539 13540
static struct hda_verb alc269_lifebook_verbs[] = {
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{ }
};

13541 13542 13543 13544 13545
/* toggle speaker-output according to the hp-jack state */
static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
{
	unsigned int present;
	unsigned char bits;
13546

13547
	present = snd_hda_jack_detect(codec, 0x15);
13548
	bits = present ? HDA_AMP_MUTE : 0;
13549
	snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13550
				 HDA_AMP_MUTE, bits);
13551
	snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13552
				 HDA_AMP_MUTE, bits);
13553

13554 13555 13556 13557
	snd_hda_codec_write(codec, 0x20, 0,
			AC_VERB_SET_COEF_INDEX, 0x0c);
	snd_hda_codec_write(codec, 0x20, 0,
			AC_VERB_SET_PROC_COEF, 0x680);
13558

13559 13560 13561 13562 13563
	snd_hda_codec_write(codec, 0x20, 0,
			AC_VERB_SET_COEF_INDEX, 0x0c);
	snd_hda_codec_write(codec, 0x20, 0,
			AC_VERB_SET_PROC_COEF, 0x480);
}
13564

13565 13566 13567 13568 13569 13570 13571
/* toggle speaker-output according to the hp-jacks state */
static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
{
	unsigned int present;
	unsigned char bits;

	/* Check laptop headphone socket */
13572
	present = snd_hda_jack_detect(codec, 0x15);
13573 13574

	/* Check port replicator headphone socket */
13575
	present |= snd_hda_jack_detect(codec, 0x1a);
13576

13577
	bits = present ? HDA_AMP_MUTE : 0;
13578
	snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13579
				 HDA_AMP_MUTE, bits);
13580
	snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13581
				 HDA_AMP_MUTE, bits);
13582 13583 13584 13585 13586 13587 13588 13589 13590 13591 13592 13593 13594 13595 13596 13597 13598

	snd_hda_codec_write(codec, 0x20, 0,
			AC_VERB_SET_COEF_INDEX, 0x0c);
	snd_hda_codec_write(codec, 0x20, 0,
			AC_VERB_SET_PROC_COEF, 0x680);

	snd_hda_codec_write(codec, 0x20, 0,
			AC_VERB_SET_COEF_INDEX, 0x0c);
	snd_hda_codec_write(codec, 0x20, 0,
			AC_VERB_SET_PROC_COEF, 0x480);
}

static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
{
	unsigned int present_laptop;
	unsigned int present_dock;

13599 13600
	present_laptop	= snd_hda_jack_detect(codec, 0x18);
	present_dock	= snd_hda_jack_detect(codec, 0x1b);
13601 13602 13603 13604 13605 13606 13607 13608 13609 13610 13611 13612 13613

	/* Laptop mic port overrides dock mic port, design decision */
	if (present_dock)
		snd_hda_codec_write(codec, 0x23, 0,
				AC_VERB_SET_CONNECT_SEL, 0x3);
	if (present_laptop)
		snd_hda_codec_write(codec, 0x23, 0,
				AC_VERB_SET_CONNECT_SEL, 0x0);
	if (!present_dock && !present_laptop)
		snd_hda_codec_write(codec, 0x23, 0,
				AC_VERB_SET_CONNECT_SEL, 0x1);
}

13614 13615 13616
static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
				    unsigned int res)
{
13617 13618
	switch (res >> 26) {
	case ALC880_HP_EVENT:
13619
		alc269_quanta_fl1_speaker_automute(codec);
13620 13621 13622 13623 13624
		break;
	case ALC880_MIC_EVENT:
		alc_mic_automute(codec);
		break;
	}
13625
}
13626

13627 13628 13629 13630 13631 13632 13633 13634 13635
static void alc269_lifebook_unsol_event(struct hda_codec *codec,
					unsigned int res)
{
	if ((res >> 26) == ALC880_HP_EVENT)
		alc269_lifebook_speaker_automute(codec);
	if ((res >> 26) == ALC880_MIC_EVENT)
		alc269_lifebook_mic_autoswitch(codec);
}

13636 13637 13638
static void alc269_quanta_fl1_setup(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
13639 13640
	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
13641 13642 13643 13644 13645 13646 13647
	spec->ext_mic.pin = 0x18;
	spec->ext_mic.mux_idx = 0;
	spec->int_mic.pin = 0x19;
	spec->int_mic.mux_idx = 1;
	spec->auto_mic = 1;
}

13648 13649 13650
static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
{
	alc269_quanta_fl1_speaker_automute(codec);
13651
	alc_mic_automute(codec);
13652
}
13653

13654 13655 13656 13657 13658 13659
static void alc269_lifebook_init_hook(struct hda_codec *codec)
{
	alc269_lifebook_speaker_automute(codec);
	alc269_lifebook_mic_autoswitch(codec);
}

K
Kailang Yang 已提交
13660
static struct hda_verb alc269_laptop_dmic_init_verbs[] = {
13661 13662 13663 13664 13665 13666 13667 13668 13669 13670
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

K
Kailang Yang 已提交
13671
static struct hda_verb alc269_laptop_amic_init_verbs[] = {
13672 13673 13674 13675 13676 13677 13678 13679 13680
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

K
Kailang Yang 已提交
13681 13682 13683 13684 13685 13686 13687 13688 13689 13690 13691 13692 13693 13694 13695 13696 13697 13698 13699 13700 13701 13702
static struct hda_verb alc269vb_laptop_dmic_init_verbs[] = {
	{0x21, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x22, AC_VERB_SET_CONNECT_SEL, 0x06},
	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

static struct hda_verb alc269vb_laptop_amic_init_verbs[] = {
	{0x21, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x22, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

13703 13704 13705
/* toggle speaker-output according to the hp-jack state */
static void alc269_speaker_automute(struct hda_codec *codec)
{
13706 13707
	struct alc_spec *spec = codec->spec;
	unsigned int nid = spec->autocfg.hp_pins[0];
13708
	unsigned int present;
13709
	unsigned char bits;
13710

13711
	present = snd_hda_jack_detect(codec, nid);
13712
	bits = present ? HDA_AMP_MUTE : 0;
13713
	snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13714
				 HDA_AMP_MUTE, bits);
13715
	snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13716
				 HDA_AMP_MUTE, bits);
13717 13718 13719
}

/* unsolicited event for HP jack sensing */
K
Kailang Yang 已提交
13720
static void alc269_laptop_unsol_event(struct hda_codec *codec,
13721
				     unsigned int res)
13722
{
13723 13724
	switch (res >> 26) {
	case ALC880_HP_EVENT:
13725
		alc269_speaker_automute(codec);
13726 13727 13728 13729 13730
		break;
	case ALC880_MIC_EVENT:
		alc_mic_automute(codec);
		break;
	}
13731 13732
}

K
Kailang Yang 已提交
13733
static void alc269_laptop_dmic_setup(struct hda_codec *codec)
13734
{
13735
	struct alc_spec *spec = codec->spec;
13736 13737
	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
13738 13739 13740 13741 13742
	spec->ext_mic.pin = 0x18;
	spec->ext_mic.mux_idx = 0;
	spec->int_mic.pin = 0x12;
	spec->int_mic.mux_idx = 5;
	spec->auto_mic = 1;
13743 13744
}

K
Kailang Yang 已提交
13745 13746 13747
static void alc269vb_laptop_dmic_setup(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
13748 13749
	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
K
Kailang Yang 已提交
13750 13751 13752 13753 13754 13755 13756 13757
	spec->ext_mic.pin = 0x18;
	spec->ext_mic.mux_idx = 0;
	spec->int_mic.pin = 0x12;
	spec->int_mic.mux_idx = 6;
	spec->auto_mic = 1;
}

static void alc269_laptop_amic_setup(struct hda_codec *codec)
13758
{
13759
	struct alc_spec *spec = codec->spec;
13760 13761
	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
13762 13763 13764 13765 13766
	spec->ext_mic.pin = 0x18;
	spec->ext_mic.mux_idx = 0;
	spec->int_mic.pin = 0x19;
	spec->int_mic.mux_idx = 1;
	spec->auto_mic = 1;
13767 13768
}

K
Kailang Yang 已提交
13769
static void alc269_laptop_inithook(struct hda_codec *codec)
13770 13771
{
	alc269_speaker_automute(codec);
13772
	alc_mic_automute(codec);
13773 13774
}

13775 13776 13777 13778 13779 13780 13781
/*
 * generic initialization of ADC, input mixers and output mixers
 */
static struct hda_verb alc269_init_verbs[] = {
	/*
	 * Unmute ADC0 and set the default input to mic-in
	 */
K
Kailang Yang 已提交
13782
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13783 13784

	/*
K
Kailang Yang 已提交
13785
	 * Set up output mixers (0x02 - 0x03)
13786 13787 13788 13789 13790 13791 13792 13793 13794 13795 13796 13797 13798 13799 13800 13801 13802 13803 13804 13805 13806 13807 13808 13809 13810
	 */
	/* set vol=0 to output mixers */
	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},

	/* set up input amps for analog loopback */
	/* Amp Indices: DAC = 0, mixer = 1 */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},

	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},

	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},

K
Kailang Yang 已提交
13811 13812 13813 13814
	/* FIXME: use Mux-type input source selection */
	/* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
	{0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
13815

K
Kailang Yang 已提交
13816 13817 13818 13819 13820 13821 13822 13823 13824 13825 13826 13827 13828 13829 13830 13831 13832 13833 13834 13835 13836 13837 13838 13839 13840 13841 13842 13843 13844 13845 13846 13847 13848 13849 13850 13851 13852 13853 13854
	/* set EAPD */
	{0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
	{ }
};

static struct hda_verb alc269vb_init_verbs[] = {
	/*
	 * Unmute ADC0 and set the default input to mic-in
	 */
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},

	/*
	 * Set up output mixers (0x02 - 0x03)
	 */
	/* set vol=0 to output mixers */
	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},

	/* set up input amps for analog loopback */
	/* Amp Indices: DAC = 0, mixer = 1 */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},

	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},

	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},

	/* FIXME: use Mux-type input source selection */
13855 13856
	/* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
	/* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
K
Kailang Yang 已提交
13857
	{0x22, AC_VERB_SET_CONNECT_SEL, 0x00},
13858 13859 13860 13861 13862 13863

	/* set EAPD */
	{0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
	{ }
};

13864 13865
#define alc269_auto_create_multi_out_ctls \
	alc268_auto_create_multi_out_ctls
13866 13867
#define alc269_auto_create_input_ctls \
	alc268_auto_create_input_ctls
13868 13869 13870 13871 13872

#ifdef CONFIG_SND_HDA_POWER_SAVE
#define alc269_loopbacks	alc880_loopbacks
#endif

13873
/* pcm configuration: identical with ALC880 */
13874 13875 13876 13877 13878
#define alc269_pcm_analog_playback	alc880_pcm_analog_playback
#define alc269_pcm_analog_capture	alc880_pcm_analog_capture
#define alc269_pcm_digital_playback	alc880_pcm_digital_playback
#define alc269_pcm_digital_capture	alc880_pcm_digital_capture

13879 13880 13881 13882 13883 13884 13885 13886 13887 13888 13889 13890 13891 13892 13893 13894 13895 13896 13897 13898 13899
static struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
	.substreams = 1,
	.channels_min = 2,
	.channels_max = 8,
	.rates = SNDRV_PCM_RATE_44100, /* fixed rate */
	/* NID is set in alc_build_pcms */
	.ops = {
		.open = alc880_playback_pcm_open,
		.prepare = alc880_playback_pcm_prepare,
		.cleanup = alc880_playback_pcm_cleanup
	},
};

static struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
	.substreams = 1,
	.channels_min = 2,
	.channels_max = 2,
	.rates = SNDRV_PCM_RATE_44100, /* fixed rate */
	/* NID is set in alc_build_pcms */
};

13900 13901 13902 13903 13904 13905
/*
 * BIOS auto configuration
 */
static int alc269_parse_auto_config(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
13906
	int err;
13907 13908 13909 13910 13911 13912 13913 13914 13915 13916
	static hda_nid_t alc269_ignore[] = { 0x1d, 0 };

	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
					   alc269_ignore);
	if (err < 0)
		return err;

	err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
	if (err < 0)
		return err;
13917
	err = alc269_auto_create_input_ctls(codec, &spec->autocfg);
13918 13919 13920 13921 13922
	if (err < 0)
		return err;

	spec->multiout.max_channels = spec->multiout.num_dacs * 2;

13923
	if (spec->autocfg.dig_outs)
13924 13925
		spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;

13926
	if (spec->kctls.list)
13927
		add_mixer(spec, spec->kctls.list);
13928

K
Kailang Yang 已提交
13929 13930
	if ((alc_read_coef_idx(codec, 0) & 0x00f0) == 0x0010) {
		add_verb(spec, alc269vb_init_verbs);
13931
		alc_ssid_check(codec, 0, 0x1b, 0x14, 0x21);
K
Kailang Yang 已提交
13932 13933
	} else {
		add_verb(spec, alc269_init_verbs);
13934
		alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
K
Kailang Yang 已提交
13935 13936
	}

13937
	spec->num_mux_defs = 1;
13938
	spec->input_mux = &spec->private_imux[0];
13939 13940 13941
	fillup_priv_adc_nids(codec, alc269_adc_candidates,
			     sizeof(alc269_adc_candidates));

13942
	/* set default input source */
13943
	snd_hda_codec_write_cache(codec, spec->capsrc_nids[0],
13944 13945
				  0, AC_VERB_SET_CONNECT_SEL,
				  spec->input_mux->items[0].index);
13946 13947 13948 13949 13950

	err = alc_auto_add_mic_boost(codec);
	if (err < 0)
		return err;

13951
	if (!spec->cap_mixer && !spec->no_analog)
13952
		set_capture_mixer(codec);
13953

13954 13955 13956
	return 1;
}

13957 13958
#define alc269_auto_init_multi_out	alc268_auto_init_multi_out
#define alc269_auto_init_hp_out		alc268_auto_init_hp_out
13959 13960 13961 13962 13963 13964
#define alc269_auto_init_analog_input	alc882_auto_init_analog_input


/* init callback for auto-configuration model -- overriding the default init */
static void alc269_auto_init(struct hda_codec *codec)
{
13965
	struct alc_spec *spec = codec->spec;
13966 13967 13968
	alc269_auto_init_multi_out(codec);
	alc269_auto_init_hp_out(codec);
	alc269_auto_init_analog_input(codec);
13969
	if (spec->unsol_event)
13970
		alc_inithook(codec);
13971 13972 13973 13974 13975 13976
}

/*
 * configuration and preset
 */
static const char *alc269_models[ALC269_MODEL_LAST] = {
13977
	[ALC269_BASIC]			= "basic",
13978
	[ALC269_QUANTA_FL1]		= "quanta",
K
Kailang Yang 已提交
13979 13980
	[ALC269_AMIC]			= "laptop-amic",
	[ALC269_DMIC]			= "laptop-dmic",
13981
	[ALC269_FUJITSU]		= "fujitsu",
13982 13983
	[ALC269_LIFEBOOK]		= "lifebook",
	[ALC269_AUTO]			= "auto",
13984 13985 13986
};

static struct snd_pci_quirk alc269_cfg_tbl[] = {
13987
	SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
13988
	SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
K
Kailang Yang 已提交
13989 13990 13991 13992 13993 13994 13995 13996 13997 13998 13999 14000 14001 14002 14003 14004 14005 14006 14007 14008 14009 14010 14011 14012 14013 14014 14015 14016 14017 14018 14019 14020 14021 14022 14023 14024 14025
		      ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269VB_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269VB_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269VB_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269VB_AMIC),
	SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269VB_AMIC),
	SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269VB_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269VB_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82Jv", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_DMIC),
	SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_AMIC),
	SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_AMIC),
14026
	SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
K
Kailang Yang 已提交
14027
		      ALC269_DMIC),
14028
	SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
K
Kailang Yang 已提交
14029 14030 14031
		      ALC269_DMIC),
	SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005HA", ALC269_DMIC),
	SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005HA", ALC269_DMIC),
14032
	SND_PCI_QUIRK(0x104d, 0x9071, "SONY XTB", ALC269_DMIC),
14033
	SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
14034 14035 14036 14037 14038 14039
	SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_DMIC),
	SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
	SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_AMIC),
	SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_AMIC),
	SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_DMIC),
	SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_DMIC),
14040 14041 14042 14043 14044
	{}
};

static struct alc_config_preset alc269_presets[] = {
	[ALC269_BASIC] = {
14045
		.mixers = { alc269_base_mixer },
14046 14047 14048 14049 14050 14051 14052 14053
		.init_verbs = { alc269_init_verbs },
		.num_dacs = ARRAY_SIZE(alc269_dac_nids),
		.dac_nids = alc269_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc269_modes),
		.channel_mode = alc269_modes,
		.input_mux = &alc269_capture_source,
	},
14054 14055 14056 14057 14058 14059 14060 14061 14062 14063
	[ALC269_QUANTA_FL1] = {
		.mixers = { alc269_quanta_fl1_mixer },
		.init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
		.num_dacs = ARRAY_SIZE(alc269_dac_nids),
		.dac_nids = alc269_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc269_modes),
		.channel_mode = alc269_modes,
		.input_mux = &alc269_capture_source,
		.unsol_event = alc269_quanta_fl1_unsol_event,
14064
		.setup = alc269_quanta_fl1_setup,
14065 14066
		.init_hook = alc269_quanta_fl1_init_hook,
	},
K
Kailang Yang 已提交
14067 14068 14069
	[ALC269_AMIC] = {
		.mixers = { alc269_laptop_mixer },
		.cap_mixer = alc269_laptop_analog_capture_mixer,
14070
		.init_verbs = { alc269_init_verbs,
K
Kailang Yang 已提交
14071
				alc269_laptop_amic_init_verbs },
14072 14073 14074 14075 14076
		.num_dacs = ARRAY_SIZE(alc269_dac_nids),
		.dac_nids = alc269_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc269_modes),
		.channel_mode = alc269_modes,
K
Kailang Yang 已提交
14077 14078 14079
		.unsol_event = alc269_laptop_unsol_event,
		.setup = alc269_laptop_amic_setup,
		.init_hook = alc269_laptop_inithook,
14080
	},
K
Kailang Yang 已提交
14081 14082 14083
	[ALC269_DMIC] = {
		.mixers = { alc269_laptop_mixer },
		.cap_mixer = alc269_laptop_digital_capture_mixer,
14084
		.init_verbs = { alc269_init_verbs,
K
Kailang Yang 已提交
14085 14086 14087 14088 14089 14090 14091 14092 14093 14094 14095 14096 14097 14098 14099
				alc269_laptop_dmic_init_verbs },
		.num_dacs = ARRAY_SIZE(alc269_dac_nids),
		.dac_nids = alc269_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc269_modes),
		.channel_mode = alc269_modes,
		.unsol_event = alc269_laptop_unsol_event,
		.setup = alc269_laptop_dmic_setup,
		.init_hook = alc269_laptop_inithook,
	},
	[ALC269VB_AMIC] = {
		.mixers = { alc269vb_laptop_mixer },
		.cap_mixer = alc269vb_laptop_analog_capture_mixer,
		.init_verbs = { alc269vb_init_verbs,
				alc269vb_laptop_amic_init_verbs },
14100 14101 14102 14103 14104
		.num_dacs = ARRAY_SIZE(alc269_dac_nids),
		.dac_nids = alc269_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc269_modes),
		.channel_mode = alc269_modes,
K
Kailang Yang 已提交
14105 14106 14107 14108 14109 14110 14111 14112 14113 14114 14115 14116 14117 14118 14119 14120 14121
		.unsol_event = alc269_laptop_unsol_event,
		.setup = alc269_laptop_amic_setup,
		.init_hook = alc269_laptop_inithook,
	},
	[ALC269VB_DMIC] = {
		.mixers = { alc269vb_laptop_mixer },
		.cap_mixer = alc269vb_laptop_digital_capture_mixer,
		.init_verbs = { alc269vb_init_verbs,
				alc269vb_laptop_dmic_init_verbs },
		.num_dacs = ARRAY_SIZE(alc269_dac_nids),
		.dac_nids = alc269_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc269_modes),
		.channel_mode = alc269_modes,
		.unsol_event = alc269_laptop_unsol_event,
		.setup = alc269vb_laptop_dmic_setup,
		.init_hook = alc269_laptop_inithook,
14122
	},
14123
	[ALC269_FUJITSU] = {
14124
		.mixers = { alc269_fujitsu_mixer },
K
Kailang Yang 已提交
14125
		.cap_mixer = alc269_laptop_digital_capture_mixer,
14126
		.init_verbs = { alc269_init_verbs,
K
Kailang Yang 已提交
14127
				alc269_laptop_dmic_init_verbs },
14128 14129 14130 14131 14132
		.num_dacs = ARRAY_SIZE(alc269_dac_nids),
		.dac_nids = alc269_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc269_modes),
		.channel_mode = alc269_modes,
K
Kailang Yang 已提交
14133 14134 14135
		.unsol_event = alc269_laptop_unsol_event,
		.setup = alc269_laptop_dmic_setup,
		.init_hook = alc269_laptop_inithook,
14136
	},
14137 14138 14139 14140 14141 14142 14143 14144 14145 14146 14147 14148
	[ALC269_LIFEBOOK] = {
		.mixers = { alc269_lifebook_mixer },
		.init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
		.num_dacs = ARRAY_SIZE(alc269_dac_nids),
		.dac_nids = alc269_dac_nids,
		.hp_nid = 0x03,
		.num_channel_mode = ARRAY_SIZE(alc269_modes),
		.channel_mode = alc269_modes,
		.input_mux = &alc269_capture_source,
		.unsol_event = alc269_lifebook_unsol_event,
		.init_hook = alc269_lifebook_init_hook,
	},
14149 14150 14151 14152 14153 14154 14155
};

static int patch_alc269(struct hda_codec *codec)
{
	struct alc_spec *spec;
	int board_config;
	int err;
K
Kailang Yang 已提交
14156
	int is_alc269vb = 0;
14157 14158 14159 14160 14161 14162 14163

	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
	if (spec == NULL)
		return -ENOMEM;

	codec->spec = spec;

14164 14165
	alc_fix_pll_init(codec, 0x20, 0x04, 15);

14166 14167 14168
	if ((alc_read_coef_idx(codec, 0) & 0x00f0) == 0x0010){
		kfree(codec->chip_name);
		codec->chip_name = kstrdup("ALC259", GFP_KERNEL);
14169 14170
		if (!codec->chip_name) {
			alc_free(codec);
14171
			return -ENOMEM;
14172
		}
K
Kailang Yang 已提交
14173
		is_alc269vb = 1;
14174 14175
	}

14176 14177 14178 14179 14180
	board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
						  alc269_models,
						  alc269_cfg_tbl);

	if (board_config < 0) {
14181 14182
		printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
		       codec->chip_name);
14183 14184 14185 14186 14187 14188 14189 14190 14191 14192 14193 14194 14195 14196 14197 14198 14199
		board_config = ALC269_AUTO;
	}

	if (board_config == ALC269_AUTO) {
		/* automatic parse from the BIOS config */
		err = alc269_parse_auto_config(codec);
		if (err < 0) {
			alc_free(codec);
			return err;
		} else if (!err) {
			printk(KERN_INFO
			       "hda_codec: Cannot set up configuration "
			       "from BIOS.  Using base mode...\n");
			board_config = ALC269_BASIC;
		}
	}

14200 14201 14202 14203 14204 14205
	err = snd_hda_attach_beep_device(codec, 0x1);
	if (err < 0) {
		alc_free(codec);
		return err;
	}

14206
	if (board_config != ALC269_AUTO)
14207
		setup_preset(codec, &alc269_presets[board_config]);
14208

K
Kailang Yang 已提交
14209
	if (board_config == ALC269_QUANTA_FL1) {
14210 14211 14212 14213 14214 14215 14216 14217 14218
		/* Due to a hardware problem on Lenovo Ideadpad, we need to
		 * fix the sample rate of analog I/O to 44.1kHz
		 */
		spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
		spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
	} else {
		spec->stream_analog_playback = &alc269_pcm_analog_playback;
		spec->stream_analog_capture = &alc269_pcm_analog_capture;
	}
14219 14220 14221
	spec->stream_digital_playback = &alc269_pcm_digital_playback;
	spec->stream_digital_capture = &alc269_pcm_digital_capture;

14222 14223 14224 14225 14226 14227 14228 14229 14230 14231
	if (!spec->adc_nids) { /* wasn't filled automatically? use default */
		if (!is_alc269vb) {
			spec->adc_nids = alc269_adc_nids;
			spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
			spec->capsrc_nids = alc269_capsrc_nids;
		} else {
			spec->adc_nids = alc269vb_adc_nids;
			spec->num_adc_nids = ARRAY_SIZE(alc269vb_adc_nids);
			spec->capsrc_nids = alc269vb_capsrc_nids;
		}
K
Kailang Yang 已提交
14232 14233
	}

14234
	if (!spec->cap_mixer)
14235
		set_capture_mixer(codec);
14236
	set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
14237

14238 14239
	spec->vmaster_nid = 0x02;

14240 14241 14242 14243 14244 14245 14246 14247 14248 14249 14250
	codec->patch_ops = alc_patch_ops;
	if (board_config == ALC269_AUTO)
		spec->init_hook = alc269_auto_init;
#ifdef CONFIG_SND_HDA_POWER_SAVE
	if (!spec->loopback.amplist)
		spec->loopback.amplist = alc269_loopbacks;
#endif

	return 0;
}

14251 14252 14253 14254 14255 14256 14257 14258 14259 14260 14261
/*
 *  ALC861 channel source setting (2/6 channel selection for 3-stack)
 */

/*
 * set the path ways for 2 channel output
 * need to set the codec line out and mic 1 pin widgets to inputs
 */
static struct hda_verb alc861_threestack_ch2_init[] = {
	/* set pin widget 1Ah (line in) for input */
	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14262 14263 14264
	/* set pin widget 18h (mic1/2) for input, for mic also enable
	 * the vref
	 */
14265 14266
	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },

14267 14268 14269 14270 14271
	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
#if 0
	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
#endif
14272 14273 14274 14275 14276 14277 14278 14279 14280 14281 14282 14283 14284
	{ } /* end */
};
/*
 * 6ch mode
 * need to set the codec line out and mic 1 pin widgets to outputs
 */
static struct hda_verb alc861_threestack_ch6_init[] = {
	/* set pin widget 1Ah (line in) for output (Back Surround)*/
	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
	/* set pin widget 18h (mic1) for output (CLFE)*/
	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },

	{ 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
14285
	{ 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
14286

14287 14288 14289 14290 14291
	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
#if 0
	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
#endif
14292 14293 14294 14295 14296 14297 14298
	{ } /* end */
};

static struct hda_channel_mode alc861_threestack_modes[2] = {
	{ 2, alc861_threestack_ch2_init },
	{ 6, alc861_threestack_ch6_init },
};
14299 14300 14301 14302 14303 14304 14305 14306 14307 14308 14309 14310 14311 14312 14313 14314 14315
/* Set mic1 as input and unmute the mixer */
static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
	{ } /* end */
};
/* Set mic1 as output and mute mixer */
static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
	{ } /* end */
};

static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
	{ 2, alc861_uniwill_m31_ch2_init },
	{ 4, alc861_uniwill_m31_ch4_init },
};
14316

14317 14318 14319 14320
/* Set mic1 and line-in as input and unmute the mixer */
static struct hda_verb alc861_asus_ch2_init[] = {
	/* set pin widget 1Ah (line in) for input */
	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14321 14322 14323
	/* set pin widget 18h (mic1/2) for input, for mic also enable
	 * the vref
	 */
14324 14325 14326 14327 14328 14329 14330 14331 14332 14333 14334 14335 14336 14337 14338 14339 14340 14341 14342 14343 14344 14345 14346 14347 14348 14349 14350 14351 14352 14353 14354 14355 14356
	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },

	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
#if 0
	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
#endif
	{ } /* end */
};
/* Set mic1 nad line-in as output and mute mixer */
static struct hda_verb alc861_asus_ch6_init[] = {
	/* set pin widget 1Ah (line in) for output (Back Surround)*/
	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
	/* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
	/* set pin widget 18h (mic1) for output (CLFE)*/
	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
	/* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
	{ 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
	{ 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },

	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
#if 0
	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
#endif
	{ } /* end */
};

static struct hda_channel_mode alc861_asus_modes[2] = {
	{ 2, alc861_asus_ch2_init },
	{ 6, alc861_asus_ch6_init },
};

14357 14358 14359 14360 14361 14362 14363 14364 14365 14366 14367 14368 14369 14370 14371 14372 14373 14374 14375 14376 14377
/* patch-ALC861 */

static struct snd_kcontrol_new alc861_base_mixer[] = {
        /* output mixer control */
	HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),

        /*Input mixer control */
	/* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
	   HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
	HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
14378

14379 14380 14381 14382 14383 14384 14385 14386 14387 14388 14389 14390 14391 14392 14393 14394 14395 14396 14397 14398 14399 14400
	{ } /* end */
};

static struct snd_kcontrol_new alc861_3ST_mixer[] = {
        /* output mixer control */
	HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
	/*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */

	/* Input mixer control */
	/* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
	   HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
	HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
14401

14402 14403 14404 14405 14406 14407 14408 14409 14410
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Channel Mode",
		.info = alc_ch_mode_info,
		.get = alc_ch_mode_get,
		.put = alc_ch_mode_put,
                .private_value = ARRAY_SIZE(alc861_threestack_modes),
	},
	{ } /* end */
14411 14412
};

T
Takashi Iwai 已提交
14413
static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
14414 14415 14416 14417
        /* output mixer control */
	HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
14418

14419
	{ } /* end */
14420
};
14421

14422 14423 14424 14425 14426 14427 14428 14429 14430 14431 14432 14433 14434 14435 14436 14437 14438 14439 14440
static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
        /* output mixer control */
	HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
	/*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */

	/* Input mixer control */
	/* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
	   HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
	HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
14441

14442 14443 14444 14445 14446 14447 14448 14449 14450
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Channel Mode",
		.info = alc_ch_mode_info,
		.get = alc_ch_mode_get,
		.put = alc_ch_mode_put,
                .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
	},
	{ } /* end */
14451
};
14452 14453 14454 14455 14456 14457 14458 14459 14460 14461 14462 14463 14464 14465 14466 14467 14468 14469 14470

static struct snd_kcontrol_new alc861_asus_mixer[] = {
        /* output mixer control */
	HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),

	/* Input mixer control */
	HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
14471 14472
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),

14473 14474 14475 14476 14477 14478 14479 14480 14481
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Channel Mode",
		.info = alc_ch_mode_info,
		.get = alc_ch_mode_get,
		.put = alc_ch_mode_put,
                .private_value = ARRAY_SIZE(alc861_asus_modes),
	},
	{ }
14482 14483 14484
};

/* additional mixer */
T
Takashi Iwai 已提交
14485
static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
14486 14487 14488 14489
	HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
	{ }
};
14490

14491 14492 14493 14494 14495 14496 14497 14498 14499 14500 14501 14502 14503 14504 14505 14506 14507 14508 14509 14510
/*
 * generic initialization of ADC, input mixers and output mixers
 */
static struct hda_verb alc861_base_init_verbs[] = {
	/*
	 * Unmute ADC0 and set the default input to mic-in
	 */
	/* port-A for surround (rear panel) */
	{ 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
	{ 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
	/* port-B for mic-in (rear panel) with vref */
	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
	/* port-C for line-in (rear panel) */
	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
	/* port-D for Front */
	{ 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
	{ 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
	/* port-E for HP out (front panel) */
	{ 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
	/* route front PCM to HP */
14511
	{ 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
14512 14513 14514 14515 14516 14517 14518 14519 14520 14521 14522 14523 14524
	/* port-F for mic-in (front panel) with vref */
	{ 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
	/* port-G for CLFE (rear panel) */
	{ 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
	{ 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
	/* port-H for side (rear panel) */
	{ 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
	{ 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
	/* CD-in */
	{ 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
	/* route front mic to ADC1*/
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14525

14526 14527 14528 14529 14530 14531
	/* Unmute DAC0~3 & spdif out*/
	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14532

14533 14534 14535 14536 14537
	/* Unmute Mixer 14 (mic) 1c (Line in)*/
	{0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14538

14539 14540 14541 14542
	/* Unmute Stereo Mixer 15 */
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14543
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14544 14545 14546 14547 14548 14549 14550 14551 14552

	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14553 14554
	/* hp used DAC 3 (Front) */
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14555 14556 14557 14558 14559 14560 14561 14562 14563 14564 14565 14566 14567 14568 14569 14570 14571 14572 14573 14574 14575
        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},

	{ }
};

static struct hda_verb alc861_threestack_init_verbs[] = {
	/*
	 * Unmute ADC0 and set the default input to mic-in
	 */
	/* port-A for surround (rear panel) */
	{ 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
	/* port-B for mic-in (rear panel) with vref */
	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
	/* port-C for line-in (rear panel) */
	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
	/* port-D for Front */
	{ 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
	{ 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
	/* port-E for HP out (front panel) */
	{ 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
	/* route front PCM to HP */
14576
	{ 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
14577 14578 14579 14580 14581 14582 14583 14584 14585 14586 14587 14588 14589 14590 14591 14592 14593
	/* port-F for mic-in (front panel) with vref */
	{ 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
	/* port-G for CLFE (rear panel) */
	{ 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
	/* port-H for side (rear panel) */
	{ 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
	/* CD-in */
	{ 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
	/* route front mic to ADC1*/
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	/* Unmute DAC0~3 & spdif out*/
	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14594

14595 14596 14597 14598 14599
	/* Unmute Mixer 14 (mic) 1c (Line in)*/
	{0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14600

14601 14602 14603 14604
	/* Unmute Stereo Mixer 15 */
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14605
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14606 14607 14608 14609 14610 14611 14612 14613 14614

	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14615 14616
	/* hp used DAC 3 (Front) */
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14617 14618 14619
        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
	{ }
};
14620 14621 14622 14623 14624 14625 14626 14627 14628 14629 14630 14631 14632 14633 14634

static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
	/*
	 * Unmute ADC0 and set the default input to mic-in
	 */
	/* port-A for surround (rear panel) */
	{ 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
	/* port-B for mic-in (rear panel) with vref */
	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
	/* port-C for line-in (rear panel) */
	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
	/* port-D for Front */
	{ 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
	{ 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
	/* port-E for HP out (front panel) */
14635 14636
	/* this has to be set to VREF80 */
	{ 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14637
	/* route front PCM to HP */
14638
	{ 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
14639 14640 14641 14642 14643 14644 14645 14646 14647 14648 14649 14650 14651 14652 14653 14654 14655
	/* port-F for mic-in (front panel) with vref */
	{ 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
	/* port-G for CLFE (rear panel) */
	{ 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
	/* port-H for side (rear panel) */
	{ 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
	/* CD-in */
	{ 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
	/* route front mic to ADC1*/
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	/* Unmute DAC0~3 & spdif out*/
	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14656

14657 14658 14659 14660 14661
	/* Unmute Mixer 14 (mic) 1c (Line in)*/
	{0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14662

14663 14664 14665 14666
	/* Unmute Stereo Mixer 15 */
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14667
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14668 14669 14670 14671 14672 14673 14674 14675 14676

	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14677 14678
	/* hp used DAC 3 (Front) */
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14679 14680 14681 14682
        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
	{ }
};

14683 14684 14685 14686
static struct hda_verb alc861_asus_init_verbs[] = {
	/*
	 * Unmute ADC0 and set the default input to mic-in
	 */
14687 14688 14689
	/* port-A for surround (rear panel)
	 * according to codec#0 this is the HP jack
	 */
14690 14691 14692 14693 14694 14695 14696 14697 14698 14699 14700
	{ 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
	/* route front PCM to HP */
	{ 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
	/* port-B for mic-in (rear panel) with vref */
	{ 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
	/* port-C for line-in (rear panel) */
	{ 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
	/* port-D for Front */
	{ 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
	{ 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
	/* port-E for HP out (front panel) */
14701 14702
	/* this has to be set to VREF80 */
	{ 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14703
	/* route front PCM to HP */
14704
	{ 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
14705 14706 14707 14708 14709 14710 14711 14712 14713 14714 14715 14716 14717 14718 14719 14720 14721 14722 14723 14724 14725 14726
	/* port-F for mic-in (front panel) with vref */
	{ 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
	/* port-G for CLFE (rear panel) */
	{ 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
	/* port-H for side (rear panel) */
	{ 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
	/* CD-in */
	{ 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
	/* route front mic to ADC1*/
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	/* Unmute DAC0~3 & spdif out*/
	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	/* Unmute Mixer 14 (mic) 1c (Line in)*/
	{0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14727

14728 14729 14730 14731
	/* Unmute Stereo Mixer 15 */
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14732
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14733 14734 14735 14736 14737 14738 14739 14740 14741

	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14742 14743
	/* hp used DAC 3 (Front) */
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14744 14745 14746 14747
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
	{ }
};

14748 14749 14750 14751 14752 14753
/* additional init verbs for ASUS laptops */
static struct hda_verb alc861_asus_laptop_init_verbs[] = {
	{ 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
	{ }
};
14754

14755 14756 14757 14758 14759 14760 14761
/*
 * generic initialization of ADC, input mixers and output mixers
 */
static struct hda_verb alc861_auto_init_verbs[] = {
	/*
	 * Unmute ADC0 and set the default input to mic-in
	 */
14762
	/* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
14763
	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14764

14765 14766 14767 14768 14769 14770
	/* Unmute DAC0~3 & spdif out*/
	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14771

14772 14773 14774 14775 14776
	/* Unmute Mixer 14 (mic) 1c (Line in)*/
	{0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14777

14778 14779 14780 14781 14782 14783
	/* Unmute Stereo Mixer 15 */
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},

14784 14785 14786 14787 14788 14789 14790 14791
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14792 14793 14794

	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14795 14796
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14797 14798
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14799 14800
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14801

14802
	{0x08, AC_VERB_SET_CONNECT_SEL, 0x00},	/* set Mic 1 */
14803 14804 14805 14806

	{ }
};

14807 14808
static struct hda_verb alc861_toshiba_init_verbs[] = {
	{0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14809

14810 14811 14812 14813 14814 14815
	{ }
};

/* toggle speaker-output according to the hp-jack state */
static void alc861_toshiba_automute(struct hda_codec *codec)
{
14816
	unsigned int present = snd_hda_jack_detect(codec, 0x0f);
14817

14818 14819 14820 14821
	snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
				 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
	snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
				 HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
14822 14823 14824 14825 14826 14827 14828 14829 14830
}

static void alc861_toshiba_unsol_event(struct hda_codec *codec,
				       unsigned int res)
{
	if ((res >> 26) == ALC880_HP_EVENT)
		alc861_toshiba_automute(codec);
}

14831
/* pcm configuration: identical with ALC880 */
14832 14833 14834 14835 14836 14837 14838 14839 14840 14841 14842 14843 14844 14845 14846 14847 14848
#define alc861_pcm_analog_playback	alc880_pcm_analog_playback
#define alc861_pcm_analog_capture	alc880_pcm_analog_capture
#define alc861_pcm_digital_playback	alc880_pcm_digital_playback
#define alc861_pcm_digital_capture	alc880_pcm_digital_capture


#define ALC861_DIGOUT_NID	0x07

static struct hda_channel_mode alc861_8ch_modes[1] = {
	{ 8, NULL }
};

static hda_nid_t alc861_dac_nids[4] = {
	/* front, surround, clfe, side */
	0x03, 0x06, 0x05, 0x04
};

14849 14850 14851 14852 14853
static hda_nid_t alc660_dac_nids[3] = {
	/* front, clfe, surround */
	0x03, 0x05, 0x06
};

14854 14855 14856 14857 14858 14859 14860 14861 14862 14863 14864 14865 14866 14867 14868 14869
static hda_nid_t alc861_adc_nids[1] = {
	/* ADC0-2 */
	0x08,
};

static struct hda_input_mux alc861_capture_source = {
	.num_items = 5,
	.items = {
		{ "Mic", 0x0 },
		{ "Front Mic", 0x3 },
		{ "Line", 0x1 },
		{ "CD", 0x4 },
		{ "Mixer", 0x5 },
	},
};

14870 14871 14872 14873 14874 14875 14876 14877 14878 14879 14880 14881 14882
static hda_nid_t alc861_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
{
	struct alc_spec *spec = codec->spec;
	hda_nid_t mix, srcs[5];
	int i, j, num;

	if (snd_hda_get_connections(codec, pin, &mix, 1) != 1)
		return 0;
	num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
	if (num < 0)
		return 0;
	for (i = 0; i < num; i++) {
		unsigned int type;
14883
		type = get_wcaps_type(get_wcaps(codec, srcs[i]));
14884 14885 14886 14887 14888 14889 14890 14891 14892 14893 14894
		if (type != AC_WID_AUD_OUT)
			continue;
		for (j = 0; j < spec->multiout.num_dacs; j++)
			if (spec->multiout.dac_nids[j] == srcs[i])
				break;
		if (j >= spec->multiout.num_dacs)
			return srcs[i];
	}
	return 0;
}

14895
/* fill in the dac_nids table from the parsed pin configuration */
14896
static int alc861_auto_fill_dac_nids(struct hda_codec *codec,
14897
				     const struct auto_pin_cfg *cfg)
14898
{
14899
	struct alc_spec *spec = codec->spec;
14900
	int i;
14901
	hda_nid_t nid, dac;
14902 14903 14904 14905

	spec->multiout.dac_nids = spec->private_dac_nids;
	for (i = 0; i < cfg->line_outs; i++) {
		nid = cfg->line_out_pins[i];
14906 14907 14908 14909
		dac = alc861_look_for_dac(codec, nid);
		if (!dac)
			continue;
		spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
14910 14911 14912 14913
	}
	return 0;
}

14914 14915 14916
static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
				hda_nid_t nid, unsigned int chs)
{
14917
	return add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx,
14918 14919 14920
			   HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
}

14921
/* add playback controls from the parsed DAC table */
14922
static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
14923 14924
					     const struct auto_pin_cfg *cfg)
{
14925
	struct alc_spec *spec = codec->spec;
14926 14927 14928
	static const char *chname[4] = {
		"Front", "Surround", NULL /*CLFE*/, "Side"
	};
14929
	hda_nid_t nid;
14930 14931 14932 14933 14934 14935 14936 14937 14938 14939 14940 14941 14942
	int i, err;

	if (cfg->line_outs == 1) {
		const char *pfx = NULL;
		if (!cfg->hp_outs)
			pfx = "Master";
		else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
			pfx = "Speaker";
		if (pfx) {
			nid = spec->multiout.dac_nids[0];
			return alc861_create_out_sw(codec, pfx, nid, 3);
		}
	}
14943 14944 14945

	for (i = 0; i < cfg->line_outs; i++) {
		nid = spec->multiout.dac_nids[i];
14946
		if (!nid)
14947
			continue;
14948
		if (i == 2) {
14949
			/* Center/LFE */
14950
			err = alc861_create_out_sw(codec, "Center", nid, 1);
14951
			if (err < 0)
14952
				return err;
14953
			err = alc861_create_out_sw(codec, "LFE", nid, 2);
14954
			if (err < 0)
14955 14956
				return err;
		} else {
14957
			err = alc861_create_out_sw(codec, chname[i], nid, 3);
14958
			if (err < 0)
14959 14960 14961 14962 14963 14964
				return err;
		}
	}
	return 0;
}

14965
static int alc861_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
14966
{
14967
	struct alc_spec *spec = codec->spec;
14968 14969 14970
	int err;
	hda_nid_t nid;

14971
	if (!pin)
14972 14973 14974
		return 0;

	if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
14975 14976 14977 14978 14979 14980 14981
		nid = alc861_look_for_dac(codec, pin);
		if (nid) {
			err = alc861_create_out_sw(codec, "Headphone", nid, 3);
			if (err < 0)
				return err;
			spec->multiout.hp_nid = nid;
		}
14982 14983 14984 14985 14986
	}
	return 0;
}

/* create playback/capture controls for input pins */
14987
static int alc861_auto_create_input_ctls(struct hda_codec *codec,
14988
						const struct auto_pin_cfg *cfg)
14989
{
14990
	return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x08, 0);
14991 14992
}

14993 14994
static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
					      hda_nid_t nid,
14995
					      int pin_type, hda_nid_t dac)
14996
{
14997 14998 14999
	hda_nid_t mix, srcs[5];
	int i, num;

15000 15001
	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
			    pin_type);
15002
	snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15003
			    AMP_OUT_UNMUTE);
15004 15005 15006 15007 15008 15009 15010 15011 15012 15013 15014 15015 15016 15017
	if (snd_hda_get_connections(codec, nid, &mix, 1) != 1)
		return;
	num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
	if (num < 0)
		return;
	for (i = 0; i < num; i++) {
		unsigned int mute;
		if (srcs[i] == dac || srcs[i] == 0x15)
			mute = AMP_IN_UNMUTE(i);
		else
			mute = AMP_IN_MUTE(i);
		snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
				    mute);
	}
15018 15019 15020 15021 15022 15023 15024 15025 15026
}

static void alc861_auto_init_multi_out(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int i;

	for (i = 0; i < spec->autocfg.line_outs; i++) {
		hda_nid_t nid = spec->autocfg.line_out_pins[i];
15027
		int pin_type = get_pin_type(spec->autocfg.line_out_type);
15028
		if (nid)
15029
			alc861_auto_set_output_and_unmute(codec, nid, pin_type,
15030
							  spec->multiout.dac_nids[i]);
15031 15032 15033 15034 15035 15036 15037
	}
}

static void alc861_auto_init_hp_out(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;

15038 15039 15040 15041
	if (spec->autocfg.hp_outs)
		alc861_auto_set_output_and_unmute(codec,
						  spec->autocfg.hp_pins[0],
						  PIN_HP,
15042
						  spec->multiout.hp_nid);
15043 15044 15045 15046
	if (spec->autocfg.speaker_outs)
		alc861_auto_set_output_and_unmute(codec,
						  spec->autocfg.speaker_pins[0],
						  PIN_OUT,
15047
						  spec->multiout.dac_nids[0]);
15048 15049 15050 15051 15052 15053 15054 15055 15056
}

static void alc861_auto_init_analog_input(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int i;

	for (i = 0; i < AUTO_PIN_LAST; i++) {
		hda_nid_t nid = spec->autocfg.input_pins[i];
15057 15058
		if (nid >= 0x0c && nid <= 0x11)
			alc_set_input_pin(codec, nid, i);
15059 15060 15061 15062
	}
}

/* parse the BIOS configuration and set up the alc_spec */
15063 15064 15065
/* return 1 if successful, 0 if the proper config is not found,
 * or a negative error code
 */
15066 15067 15068 15069 15070 15071
static int alc861_parse_auto_config(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int err;
	static hda_nid_t alc861_ignore[] = { 0x1d, 0 };

15072 15073 15074
	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
					   alc861_ignore);
	if (err < 0)
15075
		return err;
15076
	if (!spec->autocfg.line_outs)
15077 15078
		return 0; /* can't find valid BIOS pin config */

15079
	err = alc861_auto_fill_dac_nids(codec, &spec->autocfg);
15080 15081
	if (err < 0)
		return err;
15082
	err = alc861_auto_create_multi_out_ctls(codec, &spec->autocfg);
15083 15084
	if (err < 0)
		return err;
15085
	err = alc861_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
15086 15087
	if (err < 0)
		return err;
15088
	err = alc861_auto_create_input_ctls(codec, &spec->autocfg);
15089
	if (err < 0)
15090 15091 15092 15093
		return err;

	spec->multiout.max_channels = spec->multiout.num_dacs * 2;

15094
	if (spec->autocfg.dig_outs)
15095 15096
		spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;

15097
	if (spec->kctls.list)
15098
		add_mixer(spec, spec->kctls.list);
15099

15100
	add_verb(spec, alc861_auto_init_verbs);
15101

15102
	spec->num_mux_defs = 1;
15103
	spec->input_mux = &spec->private_imux[0];
15104 15105 15106

	spec->adc_nids = alc861_adc_nids;
	spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
15107
	set_capture_mixer(codec);
15108

15109
	alc_ssid_check(codec, 0x0e, 0x0f, 0x0b, 0);
15110

15111 15112 15113
	return 1;
}

15114 15115
/* additional initialization for auto-configuration model */
static void alc861_auto_init(struct hda_codec *codec)
15116
{
15117
	struct alc_spec *spec = codec->spec;
15118 15119 15120
	alc861_auto_init_multi_out(codec);
	alc861_auto_init_hp_out(codec);
	alc861_auto_init_analog_input(codec);
15121
	if (spec->unsol_event)
15122
		alc_inithook(codec);
15123 15124
}

15125 15126 15127 15128 15129 15130 15131 15132 15133 15134
#ifdef CONFIG_SND_HDA_POWER_SAVE
static struct hda_amp_list alc861_loopbacks[] = {
	{ 0x15, HDA_INPUT, 0 },
	{ 0x15, HDA_INPUT, 1 },
	{ 0x15, HDA_INPUT, 2 },
	{ 0x15, HDA_INPUT, 3 },
	{ } /* end */
};
#endif

15135 15136 15137 15138

/*
 * configuration and preset
 */
15139 15140 15141 15142 15143 15144 15145 15146 15147 15148 15149 15150 15151
static const char *alc861_models[ALC861_MODEL_LAST] = {
	[ALC861_3ST]		= "3stack",
	[ALC660_3ST]		= "3stack-660",
	[ALC861_3ST_DIG]	= "3stack-dig",
	[ALC861_6ST_DIG]	= "6stack-dig",
	[ALC861_UNIWILL_M31]	= "uniwill-m31",
	[ALC861_TOSHIBA]	= "toshiba",
	[ALC861_ASUS]		= "asus",
	[ALC861_ASUS_LAPTOP]	= "asus-laptop",
	[ALC861_AUTO]		= "auto",
};

static struct snd_pci_quirk alc861_cfg_tbl[] = {
15152
	SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
15153 15154 15155
	SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
	SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
	SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
15156
	SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
15157
	SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
15158
	SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
15159 15160 15161 15162
	/* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
	 *        Any other models that need this preset?
	 */
	/* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
15163 15164
	SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
	SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
15165
	SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
15166 15167 15168 15169
	SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
	SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
	/* FIXME: the below seems conflict */
	/* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
15170
	SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
15171
	SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
15172 15173 15174 15175 15176 15177 15178 15179 15180 15181 15182
	{}
};

static struct alc_config_preset alc861_presets[] = {
	[ALC861_3ST] = {
		.mixers = { alc861_3ST_mixer },
		.init_verbs = { alc861_threestack_init_verbs },
		.num_dacs = ARRAY_SIZE(alc861_dac_nids),
		.dac_nids = alc861_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
		.channel_mode = alc861_threestack_modes,
15183
		.need_dac_fix = 1,
15184 15185 15186 15187 15188 15189 15190 15191 15192 15193 15194 15195
		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
		.adc_nids = alc861_adc_nids,
		.input_mux = &alc861_capture_source,
	},
	[ALC861_3ST_DIG] = {
		.mixers = { alc861_base_mixer },
		.init_verbs = { alc861_threestack_init_verbs },
		.num_dacs = ARRAY_SIZE(alc861_dac_nids),
		.dac_nids = alc861_dac_nids,
		.dig_out_nid = ALC861_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
		.channel_mode = alc861_threestack_modes,
15196
		.need_dac_fix = 1,
15197 15198 15199 15200 15201 15202 15203 15204 15205 15206 15207 15208 15209 15210 15211 15212
		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
		.adc_nids = alc861_adc_nids,
		.input_mux = &alc861_capture_source,
	},
	[ALC861_6ST_DIG] = {
		.mixers = { alc861_base_mixer },
		.init_verbs = { alc861_base_init_verbs },
		.num_dacs = ARRAY_SIZE(alc861_dac_nids),
		.dac_nids = alc861_dac_nids,
		.dig_out_nid = ALC861_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
		.channel_mode = alc861_8ch_modes,
		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
		.adc_nids = alc861_adc_nids,
		.input_mux = &alc861_capture_source,
	},
15213 15214 15215 15216 15217 15218 15219
	[ALC660_3ST] = {
		.mixers = { alc861_3ST_mixer },
		.init_verbs = { alc861_threestack_init_verbs },
		.num_dacs = ARRAY_SIZE(alc660_dac_nids),
		.dac_nids = alc660_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
		.channel_mode = alc861_threestack_modes,
15220
		.need_dac_fix = 1,
15221 15222 15223 15224
		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
		.adc_nids = alc861_adc_nids,
		.input_mux = &alc861_capture_source,
	},
15225 15226 15227 15228 15229 15230 15231 15232 15233 15234 15235 15236 15237
	[ALC861_UNIWILL_M31] = {
		.mixers = { alc861_uniwill_m31_mixer },
		.init_verbs = { alc861_uniwill_m31_init_verbs },
		.num_dacs = ARRAY_SIZE(alc861_dac_nids),
		.dac_nids = alc861_dac_nids,
		.dig_out_nid = ALC861_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
		.channel_mode = alc861_uniwill_m31_modes,
		.need_dac_fix = 1,
		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
		.adc_nids = alc861_adc_nids,
		.input_mux = &alc861_capture_source,
	},
15238 15239
	[ALC861_TOSHIBA] = {
		.mixers = { alc861_toshiba_mixer },
15240 15241
		.init_verbs = { alc861_base_init_verbs,
				alc861_toshiba_init_verbs },
15242 15243 15244 15245 15246 15247 15248 15249 15250 15251
		.num_dacs = ARRAY_SIZE(alc861_dac_nids),
		.dac_nids = alc861_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
		.adc_nids = alc861_adc_nids,
		.input_mux = &alc861_capture_source,
		.unsol_event = alc861_toshiba_unsol_event,
		.init_hook = alc861_toshiba_automute,
	},
15252 15253 15254 15255 15256 15257 15258 15259 15260 15261 15262 15263 15264 15265
	[ALC861_ASUS] = {
		.mixers = { alc861_asus_mixer },
		.init_verbs = { alc861_asus_init_verbs },
		.num_dacs = ARRAY_SIZE(alc861_dac_nids),
		.dac_nids = alc861_dac_nids,
		.dig_out_nid = ALC861_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
		.channel_mode = alc861_asus_modes,
		.need_dac_fix = 1,
		.hp_nid = 0x06,
		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
		.adc_nids = alc861_adc_nids,
		.input_mux = &alc861_capture_source,
	},
15266 15267 15268 15269 15270 15271 15272 15273 15274 15275 15276 15277 15278 15279 15280
	[ALC861_ASUS_LAPTOP] = {
		.mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
		.init_verbs = { alc861_asus_init_verbs,
				alc861_asus_laptop_init_verbs },
		.num_dacs = ARRAY_SIZE(alc861_dac_nids),
		.dac_nids = alc861_dac_nids,
		.dig_out_nid = ALC861_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
		.channel_mode = alc883_3ST_2ch_modes,
		.need_dac_fix = 1,
		.num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
		.adc_nids = alc861_adc_nids,
		.input_mux = &alc861_capture_source,
	},
};
15281

15282 15283 15284 15285 15286 15287 15288 15289 15290 15291 15292 15293 15294 15295 15296 15297 15298 15299 15300 15301 15302
/* Pin config fixes */
enum {
	PINFIX_FSC_AMILO_PI1505,
};

static struct alc_pincfg alc861_fsc_amilo_pi1505_pinfix[] = {
	{ 0x0b, 0x0221101f }, /* HP */
	{ 0x0f, 0x90170310 }, /* speaker */
	{ }
};

static const struct alc_fixup alc861_fixups[] = {
	[PINFIX_FSC_AMILO_PI1505] = {
		.pins = alc861_fsc_amilo_pi1505_pinfix
	},
};

static struct snd_pci_quirk alc861_fixup_tbl[] = {
	SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
	{}
};
15303 15304 15305 15306 15307 15308 15309

static int patch_alc861(struct hda_codec *codec)
{
	struct alc_spec *spec;
	int board_config;
	int err;

15310
	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15311 15312 15313
	if (spec == NULL)
		return -ENOMEM;

15314
	codec->spec = spec;
15315

15316 15317 15318
        board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
						  alc861_models,
						  alc861_cfg_tbl);
15319

15320
	if (board_config < 0) {
15321 15322
		printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
		       codec->chip_name);
15323 15324 15325
		board_config = ALC861_AUTO;
	}

15326 15327
	alc_pick_fixup(codec, alc861_fixup_tbl, alc861_fixups);

15328 15329 15330 15331 15332 15333
	if (board_config == ALC861_AUTO) {
		/* automatic parse from the BIOS config */
		err = alc861_parse_auto_config(codec);
		if (err < 0) {
			alc_free(codec);
			return err;
15334
		} else if (!err) {
15335 15336 15337
			printk(KERN_INFO
			       "hda_codec: Cannot set up configuration "
			       "from BIOS.  Using base mode...\n");
15338 15339 15340 15341
		   board_config = ALC861_3ST_DIG;
		}
	}

15342 15343 15344 15345 15346 15347
	err = snd_hda_attach_beep_device(codec, 0x23);
	if (err < 0) {
		alc_free(codec);
		return err;
	}

15348
	if (board_config != ALC861_AUTO)
15349
		setup_preset(codec, &alc861_presets[board_config]);
15350 15351 15352 15353 15354 15355 15356

	spec->stream_analog_playback = &alc861_pcm_analog_playback;
	spec->stream_analog_capture = &alc861_pcm_analog_capture;

	spec->stream_digital_playback = &alc861_pcm_digital_playback;
	spec->stream_digital_capture = &alc861_pcm_digital_capture;

15357 15358
	if (!spec->cap_mixer)
		set_capture_mixer(codec);
15359 15360
	set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);

15361 15362
	spec->vmaster_nid = 0x03;

15363
	codec->patch_ops = alc_patch_ops;
15364
	if (board_config == ALC861_AUTO) {
15365
		spec->init_hook = alc861_auto_init;
15366 15367 15368 15369
#ifdef CONFIG_SND_HDA_POWER_SAVE
		spec->power_hook = alc_power_eapd;
#endif
	}
15370 15371 15372 15373
#ifdef CONFIG_SND_HDA_POWER_SAVE
	if (!spec->loopback.amplist)
		spec->loopback.amplist = alc861_loopbacks;
#endif
15374

L
Linus Torvalds 已提交
15375 15376 15377
	return 0;
}

15378 15379 15380 15381 15382 15383 15384 15385 15386 15387 15388 15389 15390 15391 15392 15393
/*
 * ALC861-VD support
 *
 * Based on ALC882
 *
 * In addition, an independent DAC
 */
#define ALC861VD_DIGOUT_NID	0x06

static hda_nid_t alc861vd_dac_nids[4] = {
	/* front, surr, clfe, side surr */
	0x02, 0x03, 0x04, 0x05
};

/* dac_nids for ALC660vd are in a different order - according to
 * Realtek's driver.
15394
 * This should probably result in a different mixer for 6stack models
15395 15396 15397 15398 15399 15400 15401 15402 15403 15404 15405 15406 15407 15408
 * of ALC660vd codecs, but for now there is only 3stack mixer
 * - and it is the same as in 861vd.
 * adc_nids in ALC660vd are (is) the same as in 861vd
 */
static hda_nid_t alc660vd_dac_nids[3] = {
	/* front, rear, clfe, rear_surr */
	0x02, 0x04, 0x03
};

static hda_nid_t alc861vd_adc_nids[1] = {
	/* ADC0 */
	0x09,
};

15409 15410
static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };

15411 15412 15413 15414 15415 15416 15417 15418 15419 15420 15421 15422
/* input MUX */
/* FIXME: should be a matrix-type input source selection */
static struct hda_input_mux alc861vd_capture_source = {
	.num_items = 4,
	.items = {
		{ "Mic", 0x0 },
		{ "Front Mic", 0x1 },
		{ "Line", 0x2 },
		{ "CD", 0x4 },
	},
};

15423
static struct hda_input_mux alc861vd_dallas_capture_source = {
15424
	.num_items = 2,
15425
	.items = {
15426 15427
		{ "Ext Mic", 0x0 },
		{ "Int Mic", 0x1 },
15428 15429 15430
	},
};

15431 15432 15433 15434 15435 15436 15437 15438
static struct hda_input_mux alc861vd_hp_capture_source = {
	.num_items = 2,
	.items = {
		{ "Front Mic", 0x0 },
		{ "ATAPI Mic", 0x1 },
	},
};

15439 15440 15441 15442 15443 15444 15445 15446 15447 15448 15449 15450 15451 15452 15453 15454 15455 15456 15457 15458 15459 15460 15461 15462 15463 15464 15465 15466 15467 15468 15469 15470 15471 15472 15473 15474 15475 15476 15477 15478 15479 15480 15481 15482 15483 15484 15485 15486 15487 15488 15489 15490 15491 15492 15493 15494 15495 15496 15497 15498 15499 15500 15501 15502 15503 15504 15505 15506 15507 15508 15509 15510 15511 15512 15513 15514 15515 15516 15517 15518 15519 15520 15521 15522 15523 15524 15525 15526 15527 15528 15529 15530 15531 15532 15533 15534 15535 15536 15537 15538 15539 15540 15541 15542 15543 15544 15545
/*
 * 2ch mode
 */
static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
	{ 2, NULL }
};

/*
 * 6ch mode
 */
static struct hda_verb alc861vd_6stack_ch6_init[] = {
	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ } /* end */
};

/*
 * 8ch mode
 */
static struct hda_verb alc861vd_6stack_ch8_init[] = {
	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ } /* end */
};

static struct hda_channel_mode alc861vd_6stack_modes[2] = {
	{ 6, alc861vd_6stack_ch6_init },
	{ 8, alc861vd_6stack_ch8_init },
};

static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Channel Mode",
		.info = alc_ch_mode_info,
		.get = alc_ch_mode_get,
		.put = alc_ch_mode_put,
	},
	{ } /* end */
};

/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
 *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
 */
static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),

	HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),

	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
				HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
				HDA_OUTPUT),
	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),

	HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),

	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),

	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),

	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),

	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),

	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),

	{ } /* end */
};

static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),

	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),

	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),

	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),

	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),

	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),

	{ } /* end */
};

15546 15547 15548 15549 15550 15551 15552 15553 15554 15555 15556 15557 15558 15559 15560 15561 15562 15563 15564 15565 15566
static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	/*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
	HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),

	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),

	HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),

	HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),

	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),

	{ } /* end */
};

15567 15568
/* Pin assignment: Speaker=0x14, HP = 0x15,
 *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
15569 15570
 */
static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
15571 15572
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
15573 15574
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
15575 15576 15577 15578 15579 15580
	HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15581 15582 15583
	{ } /* end */
};

15584 15585 15586 15587 15588 15589 15590 15591 15592 15593 15594 15595
/* Pin assignment: Speaker=0x14, Line-out = 0x15,
 *                 Front Mic=0x18, ATAPI Mic = 0x19,
 */
static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15596

15597 15598 15599
	{ } /* end */
};

15600 15601 15602 15603 15604 15605 15606 15607 15608 15609 15610 15611 15612 15613
/*
 * generic initialization of ADC, input mixers and output mixers
 */
static struct hda_verb alc861vd_volume_init_verbs[] = {
	/*
	 * Unmute ADC0 and set the default input to mic-in
	 */
	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},

	/* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
	 * the analog-loopback mixer widget
	 */
	/* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
15614 15615 15616 15617 15618
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15619 15620

	/* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
15621 15622 15623
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15624 15625 15626 15627 15628 15629 15630 15631 15632 15633 15634 15635 15636 15637 15638 15639 15640 15641 15642 15643 15644 15645 15646 15647 15648 15649 15650 15651 15652 15653 15654 15655 15656 15657 15658 15659 15660 15661 15662 15663 15664 15665 15666 15667 15668 15669 15670 15671 15672 15673 15674 15675 15676 15677 15678 15679 15680 15681 15682 15683 15684 15685 15686 15687 15688 15689 15690 15691 15692 15693 15694 15695 15696 15697 15698 15699 15700 15701 15702 15703 15704 15705 15706 15707 15708 15709 15710 15711 15712 15713 15714 15715 15716 15717 15718 15719 15720 15721 15722 15723 15724
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},

	/*
	 * Set up output mixers (0x02 - 0x05)
	 */
	/* set vol=0 to output mixers */
	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},

	/* set up input amps for analog loopback */
	/* Amp Indices: DAC = 0, mixer = 1 */
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},

	{ }
};

/*
 * 3-stack pin configuration:
 * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
 */
static struct hda_verb alc861vd_3stack_init_verbs[] = {
	/*
	 * Set pin mode and muting
	 */
	/* set front pin widgets 0x14 for output */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},

	/* Mic (rear) pin: input vref at 80% */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Front Mic pin: input vref at 80% */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Line In pin: input */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Line-2 In: Headphone output (output 0 - 0x0c) */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* CD pin widget for input */
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},

	{ }
};

/*
 * 6-stack pin configuration:
 */
static struct hda_verb alc861vd_6stack_init_verbs[] = {
	/*
	 * Set pin mode and muting
	 */
	/* set front pin widgets 0x14 for output */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x14, AC_VERB_SET_CONNECT_SEL, 0x00},

	/* Rear Pin: output 1 (0x0d) */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
	/* CLFE Pin: output 2 (0x0e) */
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
	/* Side Pin: output 3 (0x0f) */
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x17, AC_VERB_SET_CONNECT_SEL, 0x03},

	/* Mic (rear) pin: input vref at 80% */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Front Mic pin: input vref at 80% */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Line In pin: input */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Line-2 In: Headphone output (output 0 - 0x0c) */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* CD pin widget for input */
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},

	{ }
};

15725 15726 15727 15728 15729
static struct hda_verb alc861vd_eapd_verbs[] = {
	{0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
	{ }
};

15730 15731 15732 15733 15734 15735
static struct hda_verb alc660vd_eapd_verbs[] = {
	{0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
	{0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
	{ }
};

15736 15737 15738 15739 15740
static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15741
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15742 15743 15744 15745 15746 15747 15748 15749
	{}
};

static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
{
	unsigned int present;
	unsigned char bits;

15750
	present = snd_hda_jack_detect(codec, 0x18);
15751
	bits = present ? HDA_AMP_MUTE : 0;
15752

15753 15754
	snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
				 HDA_AMP_MUTE, bits);
15755 15756
}

15757
static void alc861vd_lenovo_setup(struct hda_codec *codec)
15758
{
15759 15760 15761
	struct alc_spec *spec = codec->spec;
	spec->autocfg.hp_pins[0] = 0x1b;
	spec->autocfg.speaker_pins[0] = 0x14;
15762 15763 15764 15765
}

static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
{
15766
	alc_automute_amp(codec);
15767 15768 15769 15770 15771 15772 15773 15774 15775 15776
	alc861vd_lenovo_mic_automute(codec);
}

static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
					unsigned int res)
{
	switch (res >> 26) {
	case ALC880_MIC_EVENT:
		alc861vd_lenovo_mic_automute(codec);
		break;
15777 15778 15779
	default:
		alc_automute_amp_unsol_event(codec, res);
		break;
15780 15781 15782
	}
}

15783 15784 15785 15786 15787 15788 15789 15790 15791 15792 15793 15794 15795 15796
static struct hda_verb alc861vd_dallas_verbs[] = {
	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},

	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15797

15798 15799 15800 15801 15802 15803 15804 15805 15806 15807 15808 15809 15810 15811 15812 15813 15814 15815 15816 15817 15818 15819 15820 15821
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},

	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},

	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},

	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15822
	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15823 15824 15825 15826 15827 15828
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},

	{ } /* end */
};

/* toggle speaker-output according to the hp-jack state */
15829
static void alc861vd_dallas_setup(struct hda_codec *codec)
15830
{
15831
	struct alc_spec *spec = codec->spec;
15832

15833 15834
	spec->autocfg.hp_pins[0] = 0x15;
	spec->autocfg.speaker_pins[0] = 0x14;
15835 15836
}

15837 15838 15839 15840
#ifdef CONFIG_SND_HDA_POWER_SAVE
#define alc861vd_loopbacks	alc880_loopbacks
#endif

15841
/* pcm configuration: identical with ALC880 */
15842 15843 15844 15845 15846 15847 15848 15849 15850 15851
#define alc861vd_pcm_analog_playback	alc880_pcm_analog_playback
#define alc861vd_pcm_analog_capture	alc880_pcm_analog_capture
#define alc861vd_pcm_digital_playback	alc880_pcm_digital_playback
#define alc861vd_pcm_digital_capture	alc880_pcm_digital_capture

/*
 * configuration and preset
 */
static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
	[ALC660VD_3ST]		= "3stack-660",
15852
	[ALC660VD_3ST_DIG]	= "3stack-660-digout",
T
Takashi Iwai 已提交
15853
	[ALC660VD_ASUS_V1S]	= "asus-v1s",
15854 15855 15856
	[ALC861VD_3ST]		= "3stack",
	[ALC861VD_3ST_DIG]	= "3stack-digout",
	[ALC861VD_6ST_DIG]	= "6stack-digout",
15857
	[ALC861VD_LENOVO]	= "lenovo",
15858
	[ALC861VD_DALLAS]	= "dallas",
15859
	[ALC861VD_HP]		= "hp",
15860 15861 15862 15863
	[ALC861VD_AUTO]		= "auto",
};

static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
15864 15865
	SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
	SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
15866
	SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
15867
	/*SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),*/ /* auto */
T
Takashi Iwai 已提交
15868
	SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
15869
	SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
15870
	SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
15871
	SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
15872
	/*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
15873
	SND_PCI_QUIRK(0x1179, 0xff01, "Toshiba A135", ALC861VD_LENOVO),
15874
	SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
15875
	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
15876
	SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
T
Takashi Iwai 已提交
15877
	SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
15878
	SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
15879 15880 15881 15882 15883 15884 15885 15886 15887 15888 15889 15890 15891 15892
	{}
};

static struct alc_config_preset alc861vd_presets[] = {
	[ALC660VD_3ST] = {
		.mixers = { alc861vd_3st_mixer },
		.init_verbs = { alc861vd_volume_init_verbs,
				 alc861vd_3stack_init_verbs },
		.num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
		.dac_nids = alc660vd_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
		.channel_mode = alc861vd_3stack_2ch_modes,
		.input_mux = &alc861vd_capture_source,
	},
15893 15894 15895 15896 15897 15898 15899 15900 15901 15902 15903
	[ALC660VD_3ST_DIG] = {
		.mixers = { alc861vd_3st_mixer },
		.init_verbs = { alc861vd_volume_init_verbs,
				 alc861vd_3stack_init_verbs },
		.num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
		.dac_nids = alc660vd_dac_nids,
		.dig_out_nid = ALC861VD_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
		.channel_mode = alc861vd_3stack_2ch_modes,
		.input_mux = &alc861vd_capture_source,
	},
15904 15905 15906 15907 15908 15909 15910 15911 15912 15913 15914 15915 15916 15917 15918 15919 15920 15921 15922 15923 15924 15925 15926 15927 15928 15929 15930 15931 15932 15933 15934 15935
	[ALC861VD_3ST] = {
		.mixers = { alc861vd_3st_mixer },
		.init_verbs = { alc861vd_volume_init_verbs,
				 alc861vd_3stack_init_verbs },
		.num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
		.dac_nids = alc861vd_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
		.channel_mode = alc861vd_3stack_2ch_modes,
		.input_mux = &alc861vd_capture_source,
	},
	[ALC861VD_3ST_DIG] = {
		.mixers = { alc861vd_3st_mixer },
		.init_verbs = { alc861vd_volume_init_verbs,
		 		 alc861vd_3stack_init_verbs },
		.num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
		.dac_nids = alc861vd_dac_nids,
		.dig_out_nid = ALC861VD_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
		.channel_mode = alc861vd_3stack_2ch_modes,
		.input_mux = &alc861vd_capture_source,
	},
	[ALC861VD_6ST_DIG] = {
		.mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
		.init_verbs = { alc861vd_volume_init_verbs,
				alc861vd_6stack_init_verbs },
		.num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
		.dac_nids = alc861vd_dac_nids,
		.dig_out_nid = ALC861VD_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
		.channel_mode = alc861vd_6stack_modes,
		.input_mux = &alc861vd_capture_source,
	},
15936 15937 15938 15939 15940 15941 15942 15943 15944 15945 15946 15947
	[ALC861VD_LENOVO] = {
		.mixers = { alc861vd_lenovo_mixer },
		.init_verbs = { alc861vd_volume_init_verbs,
				alc861vd_3stack_init_verbs,
				alc861vd_eapd_verbs,
				alc861vd_lenovo_unsol_verbs },
		.num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
		.dac_nids = alc660vd_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
		.channel_mode = alc861vd_3stack_2ch_modes,
		.input_mux = &alc861vd_capture_source,
		.unsol_event = alc861vd_lenovo_unsol_event,
15948
		.setup = alc861vd_lenovo_setup,
15949
		.init_hook = alc861vd_lenovo_init_hook,
15950
	},
15951 15952 15953 15954 15955 15956 15957 15958
	[ALC861VD_DALLAS] = {
		.mixers = { alc861vd_dallas_mixer },
		.init_verbs = { alc861vd_dallas_verbs },
		.num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
		.dac_nids = alc861vd_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
		.channel_mode = alc861vd_3stack_2ch_modes,
		.input_mux = &alc861vd_dallas_capture_source,
15959
		.unsol_event = alc_automute_amp_unsol_event,
15960 15961
		.setup = alc861vd_dallas_setup,
		.init_hook = alc_automute_amp,
15962 15963 15964 15965 15966 15967 15968 15969 15970 15971
	},
	[ALC861VD_HP] = {
		.mixers = { alc861vd_hp_mixer },
		.init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
		.num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
		.dac_nids = alc861vd_dac_nids,
		.dig_out_nid = ALC861VD_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
		.channel_mode = alc861vd_3stack_2ch_modes,
		.input_mux = &alc861vd_hp_capture_source,
15972
		.unsol_event = alc_automute_amp_unsol_event,
15973 15974
		.setup = alc861vd_dallas_setup,
		.init_hook = alc_automute_amp,
15975
	},
T
Takashi Iwai 已提交
15976 15977 15978 15979 15980 15981 15982 15983 15984 15985 15986 15987 15988
	[ALC660VD_ASUS_V1S] = {
		.mixers = { alc861vd_lenovo_mixer },
		.init_verbs = { alc861vd_volume_init_verbs,
				alc861vd_3stack_init_verbs,
				alc861vd_eapd_verbs,
				alc861vd_lenovo_unsol_verbs },
		.num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
		.dac_nids = alc660vd_dac_nids,
		.dig_out_nid = ALC861VD_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
		.channel_mode = alc861vd_3stack_2ch_modes,
		.input_mux = &alc861vd_capture_source,
		.unsol_event = alc861vd_lenovo_unsol_event,
15989
		.setup = alc861vd_lenovo_setup,
15990
		.init_hook = alc861vd_lenovo_init_hook,
T
Takashi Iwai 已提交
15991
	},
15992 15993 15994 15995 15996
};

/*
 * BIOS auto configuration
 */
15997 15998 15999
static int alc861vd_auto_create_input_ctls(struct hda_codec *codec,
						const struct auto_pin_cfg *cfg)
{
16000
	return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x09, 0);
16001 16002 16003
}


16004 16005 16006
static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
				hda_nid_t nid, int pin_type, int dac_idx)
{
16007
	alc_set_pin_output(codec, nid, pin_type);
16008 16009 16010 16011 16012 16013 16014 16015 16016
}

static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int i;

	for (i = 0; i <= HDA_SIDE; i++) {
		hda_nid_t nid = spec->autocfg.line_out_pins[i];
16017
		int pin_type = get_pin_type(spec->autocfg.line_out_type);
16018 16019
		if (nid)
			alc861vd_auto_set_output_and_unmute(codec, nid,
16020
							    pin_type, i);
16021 16022 16023 16024 16025 16026 16027 16028 16029 16030
	}
}


static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	hda_nid_t pin;

	pin = spec->autocfg.hp_pins[0];
16031
	if (pin) /* connect to front and use dac 0 */
16032
		alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16033 16034 16035
	pin = spec->autocfg.speaker_pins[0];
	if (pin)
		alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16036 16037 16038 16039 16040 16041 16042 16043 16044 16045 16046
}

#define ALC861VD_PIN_CD_NID		ALC880_PIN_CD_NID

static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int i;

	for (i = 0; i < AUTO_PIN_LAST; i++) {
		hda_nid_t nid = spec->autocfg.input_pins[i];
16047
		if (alc_is_input_pin(codec, nid)) {
16048
			alc_set_input_pin(codec, nid, i);
16049 16050
			if (nid != ALC861VD_PIN_CD_NID &&
			    (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
16051 16052 16053 16054 16055 16056 16057
				snd_hda_codec_write(codec, nid, 0,
						AC_VERB_SET_AMP_GAIN_MUTE,
						AMP_OUT_MUTE);
		}
	}
}

16058 16059
#define alc861vd_auto_init_input_src	alc882_auto_init_input_src

16060 16061 16062 16063 16064 16065 16066 16067 16068 16069 16070 16071 16072 16073
#define alc861vd_idx_to_mixer_vol(nid)		((nid) + 0x02)
#define alc861vd_idx_to_mixer_switch(nid)	((nid) + 0x0c)

/* add playback controls from the parsed DAC table */
/* Based on ALC880 version. But ALC861VD has separate,
 * different NIDs for mute/unmute switch and volume control */
static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
					     const struct auto_pin_cfg *cfg)
{
	static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
	hda_nid_t nid_v, nid_s;
	int i, err;

	for (i = 0; i < cfg->line_outs; i++) {
16074
		if (!spec->multiout.dac_nids[i])
16075 16076 16077 16078 16079 16080 16081 16082 16083 16084
			continue;
		nid_v = alc861vd_idx_to_mixer_vol(
				alc880_dac_to_idx(
					spec->multiout.dac_nids[i]));
		nid_s = alc861vd_idx_to_mixer_switch(
				alc880_dac_to_idx(
					spec->multiout.dac_nids[i]));

		if (i == 2) {
			/* Center/LFE */
16085 16086
			err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
					      "Center",
16087 16088 16089
					  HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
							      HDA_OUTPUT));
			if (err < 0)
16090
				return err;
16091 16092
			err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
					      "LFE",
16093 16094 16095
					  HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
							      HDA_OUTPUT));
			if (err < 0)
16096
				return err;
16097 16098
			err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
					     "Center",
16099 16100 16101
					  HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
							      HDA_INPUT));
			if (err < 0)
16102
				return err;
16103 16104
			err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
					     "LFE",
16105 16106 16107
					  HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
							      HDA_INPUT));
			if (err < 0)
16108 16109
				return err;
		} else {
16110 16111 16112 16113 16114 16115 16116 16117 16118
			const char *pfx;
			if (cfg->line_outs == 1 &&
			    cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
				if (!cfg->hp_pins)
					pfx = "Speaker";
				else
					pfx = "PCM";
			} else
				pfx = chname[i];
16119
			err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
16120 16121 16122
					  HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
							      HDA_OUTPUT));
			if (err < 0)
16123
				return err;
16124 16125 16126
			if (cfg->line_outs == 1 &&
			    cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
				pfx = "Speaker";
16127
			err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
16128
					  HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
16129 16130
							      HDA_INPUT));
			if (err < 0)
16131 16132 16133 16134 16135 16136 16137 16138 16139 16140 16141 16142 16143 16144 16145
				return err;
		}
	}
	return 0;
}

/* add playback controls for speaker and HP outputs */
/* Based on ALC880 version. But ALC861VD has separate,
 * different NIDs for mute/unmute switch and volume control */
static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
					hda_nid_t pin, const char *pfx)
{
	hda_nid_t nid_v, nid_s;
	int err;

16146
	if (!pin)
16147 16148 16149 16150 16151
		return 0;

	if (alc880_is_fixed_pin(pin)) {
		nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
		/* specify the DAC as the extra output */
16152
		if (!spec->multiout.hp_nid)
16153 16154 16155 16156 16157 16158 16159 16160 16161
			spec->multiout.hp_nid = nid_v;
		else
			spec->multiout.extra_out_nid[0] = nid_v;
		/* control HP volume/switch on the output mixer amp */
		nid_v = alc861vd_idx_to_mixer_vol(
				alc880_fixed_pin_idx(pin));
		nid_s = alc861vd_idx_to_mixer_switch(
				alc880_fixed_pin_idx(pin));

16162
		err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
16163 16164
				  HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
		if (err < 0)
16165
			return err;
16166
		err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
16167 16168
				  HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
		if (err < 0)
16169 16170 16171 16172
			return err;
	} else if (alc880_is_multi_pin(pin)) {
		/* set manual connection */
		/* we have only a switch on HP-out PIN */
16173
		err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
16174 16175
				  HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
		if (err < 0)
16176 16177 16178 16179 16180 16181 16182 16183 16184 16185 16186 16187 16188 16189 16190 16191
			return err;
	}
	return 0;
}

/* parse the BIOS configuration and set up the alc_spec
 * return 1 if successful, 0 if the proper config is not found,
 * or a negative error code
 * Based on ALC880 version - had to change it to override
 * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
static int alc861vd_parse_auto_config(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int err;
	static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };

16192 16193 16194
	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
					   alc861vd_ignore);
	if (err < 0)
16195
		return err;
16196
	if (!spec->autocfg.line_outs)
16197 16198
		return 0; /* can't find valid BIOS pin config */

16199 16200 16201 16202 16203 16204 16205 16206 16207 16208 16209 16210 16211 16212 16213 16214
	err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
	if (err < 0)
		return err;
	err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
	if (err < 0)
		return err;
	err = alc861vd_auto_create_extra_out(spec,
					     spec->autocfg.speaker_pins[0],
					     "Speaker");
	if (err < 0)
		return err;
	err = alc861vd_auto_create_extra_out(spec,
					     spec->autocfg.hp_pins[0],
					     "Headphone");
	if (err < 0)
		return err;
16215
	err = alc861vd_auto_create_input_ctls(codec, &spec->autocfg);
16216
	if (err < 0)
16217 16218 16219 16220
		return err;

	spec->multiout.max_channels = spec->multiout.num_dacs * 2;

16221
	if (spec->autocfg.dig_outs)
16222 16223
		spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;

16224
	if (spec->kctls.list)
16225
		add_mixer(spec, spec->kctls.list);
16226

16227
	add_verb(spec, alc861vd_volume_init_verbs);
16228 16229

	spec->num_mux_defs = 1;
16230
	spec->input_mux = &spec->private_imux[0];
16231

16232 16233 16234 16235
	err = alc_auto_add_mic_boost(codec);
	if (err < 0)
		return err;

16236
	alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
16237

16238 16239 16240 16241 16242 16243
	return 1;
}

/* additional initialization for auto-configuration model */
static void alc861vd_auto_init(struct hda_codec *codec)
{
16244
	struct alc_spec *spec = codec->spec;
16245 16246 16247
	alc861vd_auto_init_multi_out(codec);
	alc861vd_auto_init_hp_out(codec);
	alc861vd_auto_init_analog_input(codec);
16248
	alc861vd_auto_init_input_src(codec);
16249
	if (spec->unsol_event)
16250
		alc_inithook(codec);
16251 16252
}

16253 16254 16255 16256 16257 16258 16259 16260 16261 16262 16263 16264 16265 16266 16267 16268 16269 16270 16271 16272 16273 16274 16275
enum {
	ALC660VD_FIX_ASUS_GPIO1
};

/* reset GPIO1 */
static const struct hda_verb alc660vd_fix_asus_gpio1_verbs[] = {
	{0x01, AC_VERB_SET_GPIO_MASK, 0x03},
	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
	{0x01, AC_VERB_SET_GPIO_DATA, 0x01},
	{ }
};

static const struct alc_fixup alc861vd_fixups[] = {
	[ALC660VD_FIX_ASUS_GPIO1] = {
		.verbs = alc660vd_fix_asus_gpio1_verbs,
	},
};

static struct snd_pci_quirk alc861vd_fixup_tbl[] = {
	SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
	{}
};

16276 16277 16278 16279 16280 16281 16282 16283 16284 16285 16286 16287 16288 16289 16290 16291
static int patch_alc861vd(struct hda_codec *codec)
{
	struct alc_spec *spec;
	int err, board_config;

	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
	if (spec == NULL)
		return -ENOMEM;

	codec->spec = spec;

	board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
						  alc861vd_models,
						  alc861vd_cfg_tbl);

	if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
16292 16293
		printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
		       codec->chip_name);
16294 16295 16296
		board_config = ALC861VD_AUTO;
	}

16297 16298
	alc_pick_fixup(codec, alc861vd_fixup_tbl, alc861vd_fixups);

16299 16300 16301 16302 16303 16304
	if (board_config == ALC861VD_AUTO) {
		/* automatic parse from the BIOS config */
		err = alc861vd_parse_auto_config(codec);
		if (err < 0) {
			alc_free(codec);
			return err;
16305
		} else if (!err) {
16306 16307 16308 16309 16310 16311 16312
			printk(KERN_INFO
			       "hda_codec: Cannot set up configuration "
			       "from BIOS.  Using base mode...\n");
			board_config = ALC861VD_3ST;
		}
	}

16313 16314 16315 16316 16317 16318
	err = snd_hda_attach_beep_device(codec, 0x23);
	if (err < 0) {
		alc_free(codec);
		return err;
	}

16319
	if (board_config != ALC861VD_AUTO)
16320
		setup_preset(codec, &alc861vd_presets[board_config]);
16321

16322
	if (codec->vendor_id == 0x10ec0660) {
16323
		/* always turn on EAPD */
16324
		add_verb(spec, alc660vd_eapd_verbs);
16325 16326
	}

16327 16328 16329 16330 16331 16332
	spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
	spec->stream_analog_capture = &alc861vd_pcm_analog_capture;

	spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
	spec->stream_digital_capture = &alc861vd_pcm_digital_capture;

16333 16334 16335 16336 16337 16338
	if (!spec->adc_nids) {
		spec->adc_nids = alc861vd_adc_nids;
		spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
	}
	if (!spec->capsrc_nids)
		spec->capsrc_nids = alc861vd_capsrc_nids;
16339

16340
	set_capture_mixer(codec);
16341
	set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
16342

16343 16344
	spec->vmaster_nid = 0x02;

16345 16346 16347 16348
	codec->patch_ops = alc_patch_ops;

	if (board_config == ALC861VD_AUTO)
		spec->init_hook = alc861vd_auto_init;
16349 16350 16351 16352
#ifdef CONFIG_SND_HDA_POWER_SAVE
	if (!spec->loopback.amplist)
		spec->loopback.amplist = alc861vd_loopbacks;
#endif
16353 16354 16355 16356

	return 0;
}

16357 16358 16359 16360 16361 16362 16363 16364 16365 16366 16367 16368 16369 16370 16371 16372 16373 16374 16375
/*
 * ALC662 support
 *
 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
 * configuration.  Each pin widget can choose any input DACs and a mixer.
 * Each ADC is connected from a mixer of all inputs.  This makes possible
 * 6-channel independent captures.
 *
 * In addition, an independent DAC for the multi-playback (not used in this
 * driver yet).
 */
#define ALC662_DIGOUT_NID	0x06
#define ALC662_DIGIN_NID	0x0a

static hda_nid_t alc662_dac_nids[4] = {
	/* front, rear, clfe, rear_surr */
	0x02, 0x03, 0x04
};

16376 16377 16378 16379
static hda_nid_t alc272_dac_nids[2] = {
	0x02, 0x03
};

16380
static hda_nid_t alc662_adc_nids[2] = {
16381
	/* ADC1-2 */
16382
	0x09, 0x08
16383
};
16384

16385 16386 16387 16388 16389
static hda_nid_t alc272_adc_nids[1] = {
	/* ADC1-2 */
	0x08,
};

16390
static hda_nid_t alc662_capsrc_nids[2] = { 0x22, 0x23 };
16391 16392
static hda_nid_t alc272_capsrc_nids[1] = { 0x23 };

16393

16394 16395 16396 16397 16398 16399 16400 16401 16402 16403 16404 16405 16406 16407 16408 16409 16410 16411 16412
/* input MUX */
/* FIXME: should be a matrix-type input source selection */
static struct hda_input_mux alc662_capture_source = {
	.num_items = 4,
	.items = {
		{ "Mic", 0x0 },
		{ "Front Mic", 0x1 },
		{ "Line", 0x2 },
		{ "CD", 0x4 },
	},
};

static struct hda_input_mux alc662_lenovo_101e_capture_source = {
	.num_items = 2,
	.items = {
		{ "Mic", 0x1 },
		{ "Line", 0x2 },
	},
};
16413

K
Kailang Yang 已提交
16414 16415 16416 16417 16418 16419 16420 16421 16422
static struct hda_input_mux alc663_capture_source = {
	.num_items = 3,
	.items = {
		{ "Mic", 0x0 },
		{ "Front Mic", 0x1 },
		{ "Line", 0x2 },
	},
};

16423
#if 0 /* set to 1 for testing other input sources below */
16424 16425 16426 16427 16428 16429 16430 16431 16432 16433 16434 16435 16436 16437 16438 16439 16440 16441 16442 16443 16444 16445 16446
static struct hda_input_mux alc272_nc10_capture_source = {
	.num_items = 16,
	.items = {
		{ "Autoselect Mic", 0x0 },
		{ "Internal Mic", 0x1 },
		{ "In-0x02", 0x2 },
		{ "In-0x03", 0x3 },
		{ "In-0x04", 0x4 },
		{ "In-0x05", 0x5 },
		{ "In-0x06", 0x6 },
		{ "In-0x07", 0x7 },
		{ "In-0x08", 0x8 },
		{ "In-0x09", 0x9 },
		{ "In-0x0a", 0x0a },
		{ "In-0x0b", 0x0b },
		{ "In-0x0c", 0x0c },
		{ "In-0x0d", 0x0d },
		{ "In-0x0e", 0x0e },
		{ "In-0x0f", 0x0f },
	},
};
#endif

16447 16448 16449 16450 16451 16452 16453 16454 16455 16456 16457 16458 16459 16460 16461 16462 16463 16464 16465 16466 16467 16468 16469 16470 16471 16472 16473 16474 16475 16476 16477 16478 16479 16480 16481 16482 16483 16484 16485 16486 16487 16488 16489 16490 16491 16492 16493 16494 16495 16496 16497 16498 16499 16500 16501 16502 16503 16504 16505 16506 16507 16508 16509 16510 16511 16512 16513 16514
/*
 * 2ch mode
 */
static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
	{ 2, NULL }
};

/*
 * 2ch mode
 */
static struct hda_verb alc662_3ST_ch2_init[] = {
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
	{ } /* end */
};

/*
 * 6ch mode
 */
static struct hda_verb alc662_3ST_ch6_init[] = {
	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
	{ 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
	{ } /* end */
};

static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
	{ 2, alc662_3ST_ch2_init },
	{ 6, alc662_3ST_ch6_init },
};

/*
 * 2ch mode
 */
static struct hda_verb alc662_sixstack_ch6_init[] = {
	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ } /* end */
};

/*
 * 6ch mode
 */
static struct hda_verb alc662_sixstack_ch8_init[] = {
	{ 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
	{ } /* end */
};

static struct hda_channel_mode alc662_5stack_modes[2] = {
	{ 2, alc662_sixstack_ch6_init },
	{ 6, alc662_sixstack_ch8_init },
};

/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
 *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
 */

static struct snd_kcontrol_new alc662_base_mixer[] = {
	/* output mixer control */
	HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
16515
	HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
16516
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
16517
	HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
16518 16519
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
16520 16521
	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
16522 16523 16524 16525 16526 16527 16528 16529 16530 16531 16532 16533 16534 16535 16536 16537
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),

	/*Input mixer control */
	HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
	{ } /* end */
};

static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16538
	HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
16539 16540 16541 16542 16543 16544 16545 16546 16547 16548 16549 16550 16551 16552
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16553
	HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
16554
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16555
	HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
16556 16557
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
16558 16559
	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
16560 16561 16562 16563 16564 16565 16566 16567 16568 16569 16570 16571 16572 16573 16574
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
16575 16576
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
16577 16578 16579 16580 16581 16582 16583 16584
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

16585
static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
16586 16587
	HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	ALC262_HIPPO_MASTER_SWITCH,
16588 16589 16590 16591 16592 16593 16594 16595 16596 16597 16598

	HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),

	HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

16599
static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
16600 16601
	ALC262_HIPPO_MASTER_SWITCH,
	HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16602 16603 16604 16605 16606 16607 16608 16609 16610 16611 16612
	HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
	HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
};

16613 16614 16615 16616 16617 16618 16619 16620 16621 16622 16623 16624 16625 16626 16627 16628 16629 16630
static struct hda_bind_ctls alc663_asus_bind_master_vol = {
	.ops = &snd_hda_bind_vol,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
		0
	},
};

static struct hda_bind_ctls alc663_asus_one_bind_switch = {
	.ops = &snd_hda_bind_sw,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
		0
	},
};

K
Kailang Yang 已提交
16631
static struct snd_kcontrol_new alc663_m51va_mixer[] = {
16632 16633 16634 16635 16636 16637 16638 16639 16640 16641 16642 16643 16644 16645 16646 16647 16648 16649 16650 16651 16652 16653 16654 16655 16656 16657 16658 16659 16660 16661 16662 16663 16664 16665 16666 16667 16668 16669 16670 16671 16672 16673 16674 16675 16676 16677 16678 16679 16680
	HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
	HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
};

static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
	.ops = &snd_hda_bind_sw,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
		0
	},
};

static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
	HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
	HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),

	{ } /* end */
};

static struct hda_bind_ctls alc663_asus_four_bind_switch = {
	.ops = &snd_hda_bind_sw,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
		0
	},
};

static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
	HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
	HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
K
Kailang Yang 已提交
16681 16682
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16683 16684 16685 16686 16687 16688 16689 16690 16691 16692 16693 16694 16695 16696 16697 16698 16699 16700 16701 16702 16703 16704 16705 16706 16707 16708 16709 16710 16711 16712 16713
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
	.ops = &snd_hda_bind_vol,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
		0
	},
};

static struct hda_bind_ctls alc663_asus_two_bind_switch = {
	.ops = &snd_hda_bind_sw,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
		0
	},
};

static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
	HDA_BIND_VOL("Master Playback Volume",
				&alc663_asus_two_bind_master_vol),
	HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
K
Kailang Yang 已提交
16714 16715 16716
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16717 16718 16719 16720 16721 16722 16723 16724 16725 16726
	{ } /* end */
};

static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
	HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
	HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
K
Kailang Yang 已提交
16727 16728 16729 16730 16731 16732 16733 16734 16735 16736 16737 16738 16739 16740 16741 16742 16743 16744 16745 16746 16747 16748 16749 16750 16751 16752 16753 16754 16755 16756 16757
	{ } /* end */
};

static struct snd_kcontrol_new alc663_g71v_mixer[] = {
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),

	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

static struct snd_kcontrol_new alc663_g50v_mixer[] = {
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),

	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
	{ } /* end */
};

16758 16759 16760 16761 16762 16763 16764 16765 16766 16767 16768 16769 16770 16771 16772 16773 16774 16775 16776 16777 16778 16779 16780 16781 16782 16783 16784 16785 16786 16787 16788 16789 16790 16791 16792 16793 16794 16795 16796 16797 16798 16799 16800 16801 16802 16803
static struct hda_bind_ctls alc663_asus_mode7_8_all_bind_switch = {
	.ops = &snd_hda_bind_sw,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
		0
	},
};

static struct hda_bind_ctls alc663_asus_mode7_8_sp_bind_switch = {
	.ops = &snd_hda_bind_sw,
	.values = {
		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
		HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
		0
	},
};

static struct snd_kcontrol_new alc663_mode7_mixer[] = {
	HDA_BIND_SW("Master Playback Switch", &alc663_asus_mode7_8_all_bind_switch),
	HDA_BIND_VOL("Speaker Playback Volume", &alc663_asus_bind_master_vol),
	HDA_BIND_SW("Speaker Playback Switch", &alc663_asus_mode7_8_sp_bind_switch),
	HDA_CODEC_MUTE("Headphone1 Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone2 Playback Switch", 0x21, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("IntMic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("IntMic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

static struct snd_kcontrol_new alc663_mode8_mixer[] = {
	HDA_BIND_SW("Master Playback Switch", &alc663_asus_mode7_8_all_bind_switch),
	HDA_BIND_VOL("Speaker Playback Volume", &alc663_asus_bind_master_vol),
	HDA_BIND_SW("Speaker Playback Switch", &alc663_asus_mode7_8_sp_bind_switch),
	HDA_CODEC_MUTE("Headphone1 Playback Switch", 0x15, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone2 Playback Switch", 0x21, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	{ } /* end */
};


16804 16805 16806 16807 16808 16809 16810 16811 16812 16813 16814 16815 16816 16817 16818 16819
static struct snd_kcontrol_new alc662_chmode_mixer[] = {
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Channel Mode",
		.info = alc_ch_mode_info,
		.get = alc_ch_mode_get,
		.put = alc_ch_mode_put,
	},
	{ } /* end */
};

static struct hda_verb alc662_init_verbs[] = {
	/* ADC: mute amp left and right */
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x09, AC_VERB_SET_CONNECT_SEL, 0x00},

16820 16821 16822 16823 16824 16825
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16826 16827 16828 16829 16830 16831 16832 16833 16834 16835 16836 16837 16838 16839 16840 16841 16842 16843 16844 16845 16846 16847 16848 16849 16850 16851 16852 16853 16854 16855 16856 16857 16858

	/* Front Pin: output 0 (0x0c) */
	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},

	/* Rear Pin: output 1 (0x0d) */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},

	/* CLFE Pin: output 2 (0x0e) */
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},

	/* Mic (rear) pin: input vref at 80% */
	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Front Mic pin: input vref at 80% */
	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Line In pin: input */
	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	/* Line-2 In: Headphone output (output 0 - 0x0c) */
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
	/* CD pin widget for input */
	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},

	/* FIXME: use matrix-type input source selection */
	/* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
	/* Input mixer */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16859
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
K
Kailang Yang 已提交
16860 16861 16862 16863 16864

	/* always trun on EAPD */
	{0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
	{0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},

16865 16866 16867
	{ }
};

K
Kailang Yang 已提交
16868 16869 16870 16871 16872 16873 16874 16875 16876 16877 16878 16879 16880 16881 16882 16883 16884 16885 16886 16887 16888 16889
static struct hda_verb alc663_init_verbs[] = {
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{ }
};

static struct hda_verb alc272_init_verbs[] = {
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{ }
};

16890 16891 16892
static struct hda_verb alc662_sue_init_verbs[] = {
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16893 16894 16895 16896 16897 16898 16899
	{}
};

static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
16900 16901
};

16902 16903 16904 16905 16906 16907 16908
/* Set Unsolicited Event*/
static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

K
Kailang Yang 已提交
16909
static struct hda_verb alc663_m51va_init_verbs[] = {
16910 16911
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
K
Kailang Yang 已提交
16912 16913
	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16914 16915 16916 16917 16918 16919 16920 16921 16922 16923 16924 16925 16926 16927 16928 16929 16930 16931 16932 16933 16934 16935 16936 16937 16938 16939 16940 16941 16942 16943
	{0x21, AC_VERB_SET_CONNECT_SEL, 0x01},	/* Headphone */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

static struct hda_verb alc663_21jd_amic_init_verbs[] = {
	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x21, AC_VERB_SET_CONNECT_SEL, 0x01},	/* Headphone */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},	/* Headphone */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};
K
Kailang Yang 已提交
16944

16945 16946 16947 16948 16949 16950 16951 16952 16953 16954
static struct hda_verb alc663_15jd_amic_init_verbs[] = {
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},	/* Headphone */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};
K
Kailang Yang 已提交
16955

16956 16957 16958 16959 16960 16961 16962 16963 16964 16965
static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x21, AC_VERB_SET_CONNECT_SEL, 0x0},	/* Headphone */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x0},	/* Headphone */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
K
Kailang Yang 已提交
16966 16967
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16968 16969 16970 16971 16972 16973 16974 16975 16976 16977 16978 16979 16980 16981 16982 16983 16984
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},	/* Headphone */
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},	/* Headphone */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
K
Kailang Yang 已提交
16985 16986 16987 16988 16989 16990 16991 16992 16993 16994 16995 16996 16997 16998 16999 17000 17001 17002 17003 17004 17005 17006 17007 17008 17009 17010 17011 17012
	{}
};

static struct hda_verb alc663_g71v_init_verbs[] = {
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	/* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
	/* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */

	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x21, AC_VERB_SET_CONNECT_SEL, 0x00},	/* Headphone */

	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
	{}
};

static struct hda_verb alc663_g50v_init_verbs[] = {
	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x21, AC_VERB_SET_CONNECT_SEL, 0x00},	/* Headphone */

	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

17013 17014 17015 17016 17017 17018 17019 17020
static struct hda_verb alc662_ecs_init_verbs[] = {
	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

17021 17022 17023 17024 17025 17026 17027 17028 17029 17030 17031 17032 17033 17034 17035 17036 17037 17038 17039 17040 17041 17042 17043 17044 17045 17046 17047 17048 17049 17050
static struct hda_verb alc272_dell_zm1_init_verbs[] = {
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x21, AC_VERB_SET_CONNECT_SEL, 0x01},	/* Headphone */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

static struct hda_verb alc272_dell_init_verbs[] = {
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x21, AC_VERB_SET_CONNECT_SEL, 0x01},	/* Headphone */
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

17051 17052 17053 17054 17055 17056 17057 17058 17059 17060 17061 17062 17063 17064 17065 17066 17067 17068 17069 17070 17071 17072 17073 17074 17075 17076 17077 17078 17079 17080 17081 17082 17083 17084 17085 17086 17087 17088 17089
static struct hda_verb alc663_mode7_init_verbs[] = {
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x21, AC_VERB_SET_CONNECT_SEL, 0x01},	/* Headphone */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

static struct hda_verb alc663_mode8_init_verbs[] = {
	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
	{0x21, AC_VERB_SET_CONNECT_SEL, 0x01},	/* Headphone */
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
	{0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
	{}
};

17090 17091 17092 17093 17094 17095
static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
	HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
	{ } /* end */
};

17096 17097 17098 17099 17100 17101
static struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
	HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
	{ } /* end */
};

17102 17103 17104
static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
{
	unsigned int present;
17105
	unsigned char bits;
17106

17107
	present = snd_hda_jack_detect(codec, 0x14);
17108
	bits = present ? HDA_AMP_MUTE : 0;
17109

17110 17111
	snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, bits);
17112 17113 17114 17115 17116
}

static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
{
	unsigned int present;
17117
	unsigned char bits;
17118

17119
 	present = snd_hda_jack_detect(codec, 0x1b);
17120
	bits = present ? HDA_AMP_MUTE : 0;
17121

17122 17123 17124 17125
	snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, bits);
	snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, bits);
17126 17127 17128 17129 17130 17131 17132 17133 17134 17135 17136
}

static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
					   unsigned int res)
{
	if ((res >> 26) == ALC880_HP_EVENT)
		alc662_lenovo_101e_all_automute(codec);
	if ((res >> 26) == ALC880_FRONT_EVENT)
		alc662_lenovo_101e_ispeaker_automute(codec);
}

17137 17138 17139 17140 17141
/* unsolicited event for HP jack sensing */
static void alc662_eeepc_unsol_event(struct hda_codec *codec,
				     unsigned int res)
{
	if ((res >> 26) == ALC880_MIC_EVENT)
17142
		alc_mic_automute(codec);
17143 17144
	else
		alc262_hippo_unsol_event(codec, res);
17145 17146
}

17147 17148 17149 17150 17151 17152 17153 17154 17155 17156 17157 17158
static void alc662_eeepc_setup(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;

	alc262_hippo1_setup(codec);
	spec->ext_mic.pin = 0x18;
	spec->ext_mic.mux_idx = 0;
	spec->int_mic.pin = 0x19;
	spec->int_mic.mux_idx = 1;
	spec->auto_mic = 1;
}

17159 17160
static void alc662_eeepc_inithook(struct hda_codec *codec)
{
17161 17162
	alc262_hippo_automute(codec);
	alc_mic_automute(codec);
17163 17164
}

17165
static void alc662_eeepc_ep20_setup(struct hda_codec *codec)
17166
{
17167 17168 17169 17170
	struct alc_spec *spec = codec->spec;

	spec->autocfg.hp_pins[0] = 0x14;
	spec->autocfg.speaker_pins[0] = 0x1b;
17171 17172
}

17173 17174
#define alc662_eeepc_ep20_inithook	alc262_hippo_master_update

K
Kailang Yang 已提交
17175 17176 17177 17178 17179
static void alc663_m51va_speaker_automute(struct hda_codec *codec)
{
	unsigned int present;
	unsigned char bits;

17180
	present = snd_hda_jack_detect(codec, 0x21);
K
Kailang Yang 已提交
17181
	bits = present ? HDA_AMP_MUTE : 0;
17182
	snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
17183
				 HDA_AMP_MUTE, bits);
17184
	snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
17185
				 HDA_AMP_MUTE, bits);
17186 17187 17188 17189 17190 17191 17192
}

static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
{
	unsigned int present;
	unsigned char bits;

17193
	present = snd_hda_jack_detect(codec, 0x21);
17194 17195
	bits = present ? HDA_AMP_MUTE : 0;
	snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
17196
				 HDA_AMP_MUTE, bits);
17197
	snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
17198
				 HDA_AMP_MUTE, bits);
17199
	snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
17200
				 HDA_AMP_MUTE, bits);
17201
	snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
17202
				 HDA_AMP_MUTE, bits);
17203 17204 17205 17206 17207 17208 17209
}

static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
{
	unsigned int present;
	unsigned char bits;

17210
	present = snd_hda_jack_detect(codec, 0x15);
17211 17212
	bits = present ? HDA_AMP_MUTE : 0;
	snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
17213
				 HDA_AMP_MUTE, bits);
17214
	snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
17215
				 HDA_AMP_MUTE, bits);
17216
	snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
17217
				 HDA_AMP_MUTE, bits);
17218
	snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
17219
				 HDA_AMP_MUTE, bits);
17220 17221 17222 17223 17224 17225 17226
}

static void alc662_f5z_speaker_automute(struct hda_codec *codec)
{
	unsigned int present;
	unsigned char bits;

17227
	present = snd_hda_jack_detect(codec, 0x1b);
17228 17229 17230 17231 17232 17233 17234 17235 17236
	bits = present ? 0 : PIN_OUT;
	snd_hda_codec_write(codec, 0x14, 0,
			 AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
}

static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
{
	unsigned int present1, present2;

17237 17238
	present1 = snd_hda_jack_detect(codec, 0x21);
	present2 = snd_hda_jack_detect(codec, 0x15);
17239 17240 17241 17242 17243 17244 17245 17246 17247 17248 17249 17250 17251 17252

	if (present1 || present2) {
		snd_hda_codec_write_cache(codec, 0x14, 0,
			AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
	} else {
		snd_hda_codec_write_cache(codec, 0x14, 0,
			AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
	}
}

static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
{
	unsigned int present1, present2;

17253 17254
	present1 = snd_hda_jack_detect(codec, 0x1b);
	present2 = snd_hda_jack_detect(codec, 0x15);
17255 17256 17257

	if (present1 || present2) {
		snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
17258
					 HDA_AMP_MUTE, HDA_AMP_MUTE);
17259
		snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
17260
					 HDA_AMP_MUTE, HDA_AMP_MUTE);
17261 17262
	} else {
		snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
17263
					 HDA_AMP_MUTE, 0);
17264
		snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
17265
					 HDA_AMP_MUTE, 0);
17266
	}
K
Kailang Yang 已提交
17267 17268
}

17269 17270 17271 17272 17273 17274 17275 17276 17277 17278 17279 17280 17281 17282 17283 17284 17285 17286 17287 17288 17289 17290 17291 17292 17293 17294 17295 17296 17297 17298 17299 17300 17301 17302 17303 17304 17305 17306 17307 17308 17309 17310 17311 17312 17313 17314 17315 17316
static void alc663_two_hp_m7_speaker_automute(struct hda_codec *codec)
{
	unsigned int present1, present2;

	present1 = snd_hda_codec_read(codec, 0x1b, 0,
			AC_VERB_GET_PIN_SENSE, 0)
			& AC_PINSENSE_PRESENCE;
	present2 = snd_hda_codec_read(codec, 0x21, 0,
			AC_VERB_GET_PIN_SENSE, 0)
			& AC_PINSENSE_PRESENCE;

	if (present1 || present2) {
		snd_hda_codec_write_cache(codec, 0x14, 0,
			AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
		snd_hda_codec_write_cache(codec, 0x17, 0,
			AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
	} else {
		snd_hda_codec_write_cache(codec, 0x14, 0,
			AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
		snd_hda_codec_write_cache(codec, 0x17, 0,
			AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
	}
}

static void alc663_two_hp_m8_speaker_automute(struct hda_codec *codec)
{
	unsigned int present1, present2;

	present1 = snd_hda_codec_read(codec, 0x21, 0,
			AC_VERB_GET_PIN_SENSE, 0)
			& AC_PINSENSE_PRESENCE;
	present2 = snd_hda_codec_read(codec, 0x15, 0,
			AC_VERB_GET_PIN_SENSE, 0)
			& AC_PINSENSE_PRESENCE;

	if (present1 || present2) {
		snd_hda_codec_write_cache(codec, 0x14, 0,
			AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
		snd_hda_codec_write_cache(codec, 0x17, 0,
			AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
	} else {
		snd_hda_codec_write_cache(codec, 0x14, 0,
			AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
		snd_hda_codec_write_cache(codec, 0x17, 0,
			AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
	}
}

K
Kailang Yang 已提交
17317 17318 17319 17320 17321 17322 17323 17324
static void alc663_m51va_unsol_event(struct hda_codec *codec,
					   unsigned int res)
{
	switch (res >> 26) {
	case ALC880_HP_EVENT:
		alc663_m51va_speaker_automute(codec);
		break;
	case ALC880_MIC_EVENT:
17325
		alc_mic_automute(codec);
K
Kailang Yang 已提交
17326 17327 17328 17329
		break;
	}
}

17330 17331 17332 17333 17334 17335
static void alc663_m51va_setup(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	spec->ext_mic.pin = 0x18;
	spec->ext_mic.mux_idx = 0;
	spec->int_mic.pin = 0x12;
17336
	spec->int_mic.mux_idx = 9;
17337 17338 17339
	spec->auto_mic = 1;
}

K
Kailang Yang 已提交
17340 17341 17342
static void alc663_m51va_inithook(struct hda_codec *codec)
{
	alc663_m51va_speaker_automute(codec);
17343
	alc_mic_automute(codec);
K
Kailang Yang 已提交
17344 17345
}

17346
/* ***************** Mode1 ******************************/
17347
#define alc663_mode1_unsol_event	alc663_m51va_unsol_event
17348 17349 17350 17351 17352 17353 17354 17355 17356 17357 17358

static void alc663_mode1_setup(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	spec->ext_mic.pin = 0x18;
	spec->ext_mic.mux_idx = 0;
	spec->int_mic.pin = 0x19;
	spec->int_mic.mux_idx = 1;
	spec->auto_mic = 1;
}

17359
#define alc663_mode1_inithook		alc663_m51va_inithook
17360 17361 17362 17363 17364 17365 17366 17367 17368 17369

/* ***************** Mode2 ******************************/
static void alc662_mode2_unsol_event(struct hda_codec *codec,
					   unsigned int res)
{
	switch (res >> 26) {
	case ALC880_HP_EVENT:
		alc662_f5z_speaker_automute(codec);
		break;
	case ALC880_MIC_EVENT:
17370
		alc_mic_automute(codec);
17371 17372 17373 17374
		break;
	}
}

17375
#define alc662_mode2_setup	alc663_mode1_setup
17376

17377 17378 17379
static void alc662_mode2_inithook(struct hda_codec *codec)
{
	alc662_f5z_speaker_automute(codec);
17380
	alc_mic_automute(codec);
17381 17382 17383 17384 17385 17386 17387 17388 17389 17390
}
/* ***************** Mode3 ******************************/
static void alc663_mode3_unsol_event(struct hda_codec *codec,
					   unsigned int res)
{
	switch (res >> 26) {
	case ALC880_HP_EVENT:
		alc663_two_hp_m1_speaker_automute(codec);
		break;
	case ALC880_MIC_EVENT:
17391
		alc_mic_automute(codec);
17392 17393 17394 17395
		break;
	}
}

17396
#define alc663_mode3_setup	alc663_mode1_setup
17397

17398 17399 17400
static void alc663_mode3_inithook(struct hda_codec *codec)
{
	alc663_two_hp_m1_speaker_automute(codec);
17401
	alc_mic_automute(codec);
17402 17403 17404 17405 17406 17407 17408 17409 17410 17411
}
/* ***************** Mode4 ******************************/
static void alc663_mode4_unsol_event(struct hda_codec *codec,
					   unsigned int res)
{
	switch (res >> 26) {
	case ALC880_HP_EVENT:
		alc663_21jd_two_speaker_automute(codec);
		break;
	case ALC880_MIC_EVENT:
17412
		alc_mic_automute(codec);
17413 17414 17415 17416
		break;
	}
}

17417
#define alc663_mode4_setup	alc663_mode1_setup
17418

17419 17420 17421
static void alc663_mode4_inithook(struct hda_codec *codec)
{
	alc663_21jd_two_speaker_automute(codec);
17422
	alc_mic_automute(codec);
17423 17424 17425 17426 17427 17428 17429 17430 17431 17432
}
/* ***************** Mode5 ******************************/
static void alc663_mode5_unsol_event(struct hda_codec *codec,
					   unsigned int res)
{
	switch (res >> 26) {
	case ALC880_HP_EVENT:
		alc663_15jd_two_speaker_automute(codec);
		break;
	case ALC880_MIC_EVENT:
17433
		alc_mic_automute(codec);
17434 17435 17436 17437
		break;
	}
}

17438
#define alc663_mode5_setup	alc663_mode1_setup
17439

17440 17441 17442
static void alc663_mode5_inithook(struct hda_codec *codec)
{
	alc663_15jd_two_speaker_automute(codec);
17443
	alc_mic_automute(codec);
17444 17445 17446 17447 17448 17449 17450 17451 17452 17453
}
/* ***************** Mode6 ******************************/
static void alc663_mode6_unsol_event(struct hda_codec *codec,
					   unsigned int res)
{
	switch (res >> 26) {
	case ALC880_HP_EVENT:
		alc663_two_hp_m2_speaker_automute(codec);
		break;
	case ALC880_MIC_EVENT:
17454
		alc_mic_automute(codec);
17455 17456 17457 17458
		break;
	}
}

17459
#define alc663_mode6_setup	alc663_mode1_setup
17460

17461 17462 17463
static void alc663_mode6_inithook(struct hda_codec *codec)
{
	alc663_two_hp_m2_speaker_automute(codec);
17464
	alc_mic_automute(codec);
17465 17466
}

17467 17468 17469 17470 17471 17472 17473 17474 17475 17476 17477 17478 17479 17480 17481 17482 17483 17484 17485 17486 17487 17488 17489 17490 17491 17492 17493 17494 17495 17496 17497 17498 17499 17500 17501 17502 17503 17504 17505 17506 17507 17508 17509 17510
/* ***************** Mode7 ******************************/
static void alc663_mode7_unsol_event(struct hda_codec *codec,
					   unsigned int res)
{
	switch (res >> 26) {
	case ALC880_HP_EVENT:
		alc663_two_hp_m7_speaker_automute(codec);
		break;
	case ALC880_MIC_EVENT:
		alc_mic_automute(codec);
		break;
	}
}

#define alc663_mode7_setup	alc663_mode1_setup

static void alc663_mode7_inithook(struct hda_codec *codec)
{
	alc663_two_hp_m7_speaker_automute(codec);
	alc_mic_automute(codec);
}

/* ***************** Mode8 ******************************/
static void alc663_mode8_unsol_event(struct hda_codec *codec,
					   unsigned int res)
{
	switch (res >> 26) {
	case ALC880_HP_EVENT:
		alc663_two_hp_m8_speaker_automute(codec);
		break;
	case ALC880_MIC_EVENT:
		alc_mic_automute(codec);
		break;
	}
}

#define alc663_mode8_setup	alc663_m51va_setup

static void alc663_mode8_inithook(struct hda_codec *codec)
{
	alc663_two_hp_m8_speaker_automute(codec);
	alc_mic_automute(codec);
}

K
Kailang Yang 已提交
17511 17512 17513 17514 17515
static void alc663_g71v_hp_automute(struct hda_codec *codec)
{
	unsigned int present;
	unsigned char bits;

17516
	present = snd_hda_jack_detect(codec, 0x21);
K
Kailang Yang 已提交
17517 17518 17519 17520 17521 17522 17523 17524 17525 17526 17527 17528
	bits = present ? HDA_AMP_MUTE : 0;
	snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, bits);
	snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, bits);
}

static void alc663_g71v_front_automute(struct hda_codec *codec)
{
	unsigned int present;
	unsigned char bits;

17529
	present = snd_hda_jack_detect(codec, 0x15);
K
Kailang Yang 已提交
17530 17531 17532 17533 17534 17535 17536 17537 17538 17539 17540 17541 17542 17543 17544 17545
	bits = present ? HDA_AMP_MUTE : 0;
	snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
				 HDA_AMP_MUTE, bits);
}

static void alc663_g71v_unsol_event(struct hda_codec *codec,
					   unsigned int res)
{
	switch (res >> 26) {
	case ALC880_HP_EVENT:
		alc663_g71v_hp_automute(codec);
		break;
	case ALC880_FRONT_EVENT:
		alc663_g71v_front_automute(codec);
		break;
	case ALC880_MIC_EVENT:
17546
		alc_mic_automute(codec);
K
Kailang Yang 已提交
17547 17548 17549 17550
		break;
	}
}

17551 17552
#define alc663_g71v_setup	alc663_m51va_setup

K
Kailang Yang 已提交
17553 17554 17555 17556
static void alc663_g71v_inithook(struct hda_codec *codec)
{
	alc663_g71v_front_automute(codec);
	alc663_g71v_hp_automute(codec);
17557
	alc_mic_automute(codec);
K
Kailang Yang 已提交
17558 17559 17560 17561 17562 17563 17564 17565 17566 17567
}

static void alc663_g50v_unsol_event(struct hda_codec *codec,
					   unsigned int res)
{
	switch (res >> 26) {
	case ALC880_HP_EVENT:
		alc663_m51va_speaker_automute(codec);
		break;
	case ALC880_MIC_EVENT:
17568
		alc_mic_automute(codec);
K
Kailang Yang 已提交
17569 17570 17571 17572
		break;
	}
}

17573 17574
#define alc663_g50v_setup	alc663_m51va_setup

K
Kailang Yang 已提交
17575 17576 17577
static void alc663_g50v_inithook(struct hda_codec *codec)
{
	alc663_m51va_speaker_automute(codec);
17578
	alc_mic_automute(codec);
K
Kailang Yang 已提交
17579 17580
}

17581 17582
static struct snd_kcontrol_new alc662_ecs_mixer[] = {
	HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17583
	ALC262_HIPPO_MASTER_SWITCH,
17584 17585 17586 17587 17588 17589 17590 17591 17592 17593 17594

	HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),

	HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
	HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	{ } /* end */
};

17595 17596 17597 17598 17599 17600 17601 17602 17603 17604 17605 17606 17607 17608 17609 17610 17611
static struct snd_kcontrol_new alc272_nc10_mixer[] = {
	/* Master Playback automatically created from Speaker and Headphone */
	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
	HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),

	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
	HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),

	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
	HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
	{ } /* end */
};

17612 17613 17614 17615
#ifdef CONFIG_SND_HDA_POWER_SAVE
#define alc662_loopbacks	alc880_loopbacks
#endif

17616

17617
/* pcm configuration: identical with ALC880 */
17618 17619 17620 17621 17622 17623 17624 17625 17626 17627 17628 17629 17630 17631
#define alc662_pcm_analog_playback	alc880_pcm_analog_playback
#define alc662_pcm_analog_capture	alc880_pcm_analog_capture
#define alc662_pcm_digital_playback	alc880_pcm_digital_playback
#define alc662_pcm_digital_capture	alc880_pcm_digital_capture

/*
 * configuration and preset
 */
static const char *alc662_models[ALC662_MODEL_LAST] = {
	[ALC662_3ST_2ch_DIG]	= "3stack-dig",
	[ALC662_3ST_6ch_DIG]	= "3stack-6ch-dig",
	[ALC662_3ST_6ch]	= "3stack-6ch",
	[ALC662_5ST_DIG]	= "6stack-dig",
	[ALC662_LENOVO_101E]	= "lenovo-101e",
17632
	[ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
17633
	[ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
17634
	[ALC662_ECS] = "ecs",
K
Kailang Yang 已提交
17635 17636 17637 17638
	[ALC663_ASUS_M51VA] = "m51va",
	[ALC663_ASUS_G71V] = "g71v",
	[ALC663_ASUS_H13] = "h13",
	[ALC663_ASUS_G50V] = "g50v",
17639 17640 17641 17642 17643 17644
	[ALC663_ASUS_MODE1] = "asus-mode1",
	[ALC662_ASUS_MODE2] = "asus-mode2",
	[ALC663_ASUS_MODE3] = "asus-mode3",
	[ALC663_ASUS_MODE4] = "asus-mode4",
	[ALC663_ASUS_MODE5] = "asus-mode5",
	[ALC663_ASUS_MODE6] = "asus-mode6",
17645 17646
	[ALC663_ASUS_MODE7] = "asus-mode7",
	[ALC663_ASUS_MODE8] = "asus-mode8",
17647 17648
	[ALC272_DELL]		= "dell",
	[ALC272_DELL_ZM1]	= "dell-zm1",
17649
	[ALC272_SAMSUNG_NC10]	= "samsung-nc10",
17650 17651 17652 17653
	[ALC662_AUTO]		= "auto",
};

static struct snd_pci_quirk alc662_cfg_tbl[] = {
T
Takashi Iwai 已提交
17654
	SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
17655 17656
	SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
	SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
17657
	SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
T
Takashi Iwai 已提交
17658
	SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
K
Kailang Yang 已提交
17659
	SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC663_ASUS_MODE1),
T
Takashi Iwai 已提交
17660
	SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
17661
	SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
T
Takashi Iwai 已提交
17662
	SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
17663
	SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
17664 17665
	SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC663_ASUS_MODE1),
	SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC663_ASUS_MODE1),
17666
	SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
17667 17668 17669 17670 17671
	SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC663_ASUS_MODE7),
	SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC663_ASUS_MODE7),
	SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC663_ASUS_MODE8),
	SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC663_ASUS_MODE3),
	SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC663_ASUS_MODE1),
T
Takashi Iwai 已提交
17672
	SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
17673 17674
	SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_ASUS_MODE2),
	SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC663_ASUS_MODE1),
T
Takashi Iwai 已提交
17675 17676 17677 17678
	SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
	SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
	SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
	SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
17679
	SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC663_ASUS_MODE1),
17680 17681 17682
	SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
	SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
	SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
17683
	SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
T
Takashi Iwai 已提交
17684 17685 17686
	SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
	SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
	SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
17687
	SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
17688
	SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
T
Takashi Iwai 已提交
17689 17690 17691
	SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
	SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
	/*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
17692 17693
	SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
	SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
17694
	SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
K
Kailang Yang 已提交
17695
	SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC663_ASUS_MODE1),
17696 17697
	SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
	SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
T
Takashi Iwai 已提交
17698 17699 17700
	SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
	SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
	SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
17701
	SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
T
Takashi Iwai 已提交
17702 17703
	SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
	SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
17704
	SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
T
Takashi Iwai 已提交
17705 17706 17707 17708 17709
	SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
	SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
	/*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
	SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
	SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
17710
	SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
T
Takashi Iwai 已提交
17711
	SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
17712
	SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
T
Takashi Iwai 已提交
17713 17714 17715 17716
	SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
	SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
	SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
	SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
17717 17718
	SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
		      ALC662_3ST_6ch_DIG),
17719
	SND_PCI_QUIRK(0x1179, 0xff6e, "Toshiba NB20x", ALC662_AUTO),
17720
	SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
17721 17722
	SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
		      ALC662_3ST_6ch_DIG),
17723
	SND_PCI_QUIRK(0x152d, 0x2304, "Quanta WH1", ALC663_ASUS_H13),
17724
	SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
17725
	SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
T
Takashi Iwai 已提交
17726
	SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
17727
	SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
17728
					ALC662_3ST_6ch_DIG),
T
Takashi Iwai 已提交
17729 17730
	SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
			   ALC663_ASUS_H13),
17731
	SND_PCI_QUIRK(0x8086, 0xd604, "Intel mobo", ALC662_3ST_2ch_DIG),
17732 17733 17734 17735 17736
	{}
};

static struct alc_config_preset alc662_presets[] = {
	[ALC662_3ST_2ch_DIG] = {
17737
		.mixers = { alc662_3ST_2ch_mixer },
17738 17739 17740 17741 17742 17743 17744 17745 17746 17747
		.init_verbs = { alc662_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.dac_nids = alc662_dac_nids,
		.dig_out_nid = ALC662_DIGOUT_NID,
		.dig_in_nid = ALC662_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.input_mux = &alc662_capture_source,
	},
	[ALC662_3ST_6ch_DIG] = {
17748
		.mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
17749 17750 17751 17752 17753 17754 17755 17756 17757
		.init_verbs = { alc662_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.dac_nids = alc662_dac_nids,
		.dig_out_nid = ALC662_DIGOUT_NID,
		.dig_in_nid = ALC662_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
		.channel_mode = alc662_3ST_6ch_modes,
		.need_dac_fix = 1,
		.input_mux = &alc662_capture_source,
17758
	},
17759
	[ALC662_3ST_6ch] = {
17760
		.mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
17761 17762 17763 17764 17765 17766 17767
		.init_verbs = { alc662_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.dac_nids = alc662_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
		.channel_mode = alc662_3ST_6ch_modes,
		.need_dac_fix = 1,
		.input_mux = &alc662_capture_source,
17768
	},
17769
	[ALC662_5ST_DIG] = {
17770
		.mixers = { alc662_base_mixer, alc662_chmode_mixer },
17771 17772 17773 17774 17775 17776 17777 17778 17779 17780
		.init_verbs = { alc662_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.dac_nids = alc662_dac_nids,
		.dig_out_nid = ALC662_DIGOUT_NID,
		.dig_in_nid = ALC662_DIGIN_NID,
		.num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
		.channel_mode = alc662_5stack_modes,
		.input_mux = &alc662_capture_source,
	},
	[ALC662_LENOVO_101E] = {
17781
		.mixers = { alc662_lenovo_101e_mixer },
17782 17783 17784 17785 17786 17787 17788 17789 17790
		.init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.dac_nids = alc662_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.input_mux = &alc662_lenovo_101e_capture_source,
		.unsol_event = alc662_lenovo_101e_unsol_event,
		.init_hook = alc662_lenovo_101e_all_automute,
	},
17791
	[ALC662_ASUS_EEEPC_P701] = {
17792
		.mixers = { alc662_eeepc_p701_mixer },
17793 17794 17795 17796 17797 17798 17799
		.init_verbs = { alc662_init_verbs,
				alc662_eeepc_sue_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.dac_nids = alc662_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc662_eeepc_unsol_event,
17800
		.setup = alc662_eeepc_setup,
17801 17802
		.init_hook = alc662_eeepc_inithook,
	},
17803
	[ALC662_ASUS_EEEPC_EP20] = {
17804
		.mixers = { alc662_eeepc_ep20_mixer,
17805 17806 17807 17808 17809 17810 17811 17812
			    alc662_chmode_mixer },
		.init_verbs = { alc662_init_verbs,
				alc662_eeepc_ep20_sue_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.dac_nids = alc662_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
		.channel_mode = alc662_3ST_6ch_modes,
		.input_mux = &alc662_lenovo_101e_capture_source,
17813
		.unsol_event = alc662_eeepc_unsol_event,
17814
		.setup = alc662_eeepc_ep20_setup,
17815 17816
		.init_hook = alc662_eeepc_ep20_inithook,
	},
17817
	[ALC662_ECS] = {
17818
		.mixers = { alc662_ecs_mixer },
17819 17820 17821 17822 17823 17824 17825
		.init_verbs = { alc662_init_verbs,
				alc662_ecs_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.dac_nids = alc662_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc662_eeepc_unsol_event,
17826
		.setup = alc662_eeepc_setup,
17827 17828
		.init_hook = alc662_eeepc_inithook,
	},
K
Kailang Yang 已提交
17829
	[ALC663_ASUS_M51VA] = {
17830
		.mixers = { alc663_m51va_mixer },
K
Kailang Yang 已提交
17831 17832 17833 17834 17835 17836 17837
		.init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.dac_nids = alc662_dac_nids,
		.dig_out_nid = ALC662_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc663_m51va_unsol_event,
17838
		.setup = alc663_m51va_setup,
K
Kailang Yang 已提交
17839 17840 17841
		.init_hook = alc663_m51va_inithook,
	},
	[ALC663_ASUS_G71V] = {
17842
		.mixers = { alc663_g71v_mixer },
K
Kailang Yang 已提交
17843 17844 17845 17846 17847 17848 17849
		.init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.dac_nids = alc662_dac_nids,
		.dig_out_nid = ALC662_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc663_g71v_unsol_event,
17850
		.setup = alc663_g71v_setup,
K
Kailang Yang 已提交
17851 17852 17853
		.init_hook = alc663_g71v_inithook,
	},
	[ALC663_ASUS_H13] = {
17854
		.mixers = { alc663_m51va_mixer },
K
Kailang Yang 已提交
17855 17856 17857 17858 17859 17860 17861 17862 17863
		.init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.dac_nids = alc662_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc663_m51va_unsol_event,
		.init_hook = alc663_m51va_inithook,
	},
	[ALC663_ASUS_G50V] = {
17864
		.mixers = { alc663_g50v_mixer },
K
Kailang Yang 已提交
17865 17866 17867 17868 17869 17870 17871 17872
		.init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.dac_nids = alc662_dac_nids,
		.dig_out_nid = ALC662_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
		.channel_mode = alc662_3ST_6ch_modes,
		.input_mux = &alc663_capture_source,
		.unsol_event = alc663_g50v_unsol_event,
17873
		.setup = alc663_g50v_setup,
K
Kailang Yang 已提交
17874 17875
		.init_hook = alc663_g50v_inithook,
	},
17876
	[ALC663_ASUS_MODE1] = {
17877 17878
		.mixers = { alc663_m51va_mixer },
		.cap_mixer = alc662_auto_capture_mixer,
17879 17880 17881 17882 17883 17884 17885 17886 17887
		.init_verbs = { alc662_init_verbs,
				alc663_21jd_amic_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.hp_nid = 0x03,
		.dac_nids = alc662_dac_nids,
		.dig_out_nid = ALC662_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc663_mode1_unsol_event,
17888
		.setup = alc663_mode1_setup,
17889 17890 17891
		.init_hook = alc663_mode1_inithook,
	},
	[ALC662_ASUS_MODE2] = {
17892 17893
		.mixers = { alc662_1bjd_mixer },
		.cap_mixer = alc662_auto_capture_mixer,
17894 17895 17896 17897 17898 17899 17900 17901
		.init_verbs = { alc662_init_verbs,
				alc662_1bjd_amic_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.dac_nids = alc662_dac_nids,
		.dig_out_nid = ALC662_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc662_mode2_unsol_event,
17902
		.setup = alc662_mode2_setup,
17903 17904 17905
		.init_hook = alc662_mode2_inithook,
	},
	[ALC663_ASUS_MODE3] = {
17906 17907
		.mixers = { alc663_two_hp_m1_mixer },
		.cap_mixer = alc662_auto_capture_mixer,
17908 17909 17910 17911 17912 17913 17914 17915 17916
		.init_verbs = { alc662_init_verbs,
				alc663_two_hp_amic_m1_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.hp_nid = 0x03,
		.dac_nids = alc662_dac_nids,
		.dig_out_nid = ALC662_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc663_mode3_unsol_event,
17917
		.setup = alc663_mode3_setup,
17918 17919 17920
		.init_hook = alc663_mode3_inithook,
	},
	[ALC663_ASUS_MODE4] = {
17921 17922
		.mixers = { alc663_asus_21jd_clfe_mixer },
		.cap_mixer = alc662_auto_capture_mixer,
17923 17924 17925 17926 17927 17928 17929 17930 17931
		.init_verbs = { alc662_init_verbs,
				alc663_21jd_amic_init_verbs},
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.hp_nid = 0x03,
		.dac_nids = alc662_dac_nids,
		.dig_out_nid = ALC662_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc663_mode4_unsol_event,
17932
		.setup = alc663_mode4_setup,
17933 17934 17935
		.init_hook = alc663_mode4_inithook,
	},
	[ALC663_ASUS_MODE5] = {
17936 17937
		.mixers = { alc663_asus_15jd_clfe_mixer },
		.cap_mixer = alc662_auto_capture_mixer,
17938 17939 17940 17941 17942 17943 17944 17945 17946
		.init_verbs = { alc662_init_verbs,
				alc663_15jd_amic_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.hp_nid = 0x03,
		.dac_nids = alc662_dac_nids,
		.dig_out_nid = ALC662_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc663_mode5_unsol_event,
17947
		.setup = alc663_mode5_setup,
17948 17949 17950
		.init_hook = alc663_mode5_inithook,
	},
	[ALC663_ASUS_MODE6] = {
17951 17952
		.mixers = { alc663_two_hp_m2_mixer },
		.cap_mixer = alc662_auto_capture_mixer,
17953 17954 17955 17956 17957 17958 17959 17960 17961
		.init_verbs = { alc662_init_verbs,
				alc663_two_hp_amic_m2_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.hp_nid = 0x03,
		.dac_nids = alc662_dac_nids,
		.dig_out_nid = ALC662_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc663_mode6_unsol_event,
17962
		.setup = alc663_mode6_setup,
17963 17964
		.init_hook = alc663_mode6_inithook,
	},
17965 17966 17967 17968 17969 17970 17971 17972 17973 17974 17975 17976 17977 17978 17979 17980 17981 17982 17983 17984 17985 17986 17987 17988 17989 17990 17991 17992 17993 17994
	[ALC663_ASUS_MODE7] = {
		.mixers = { alc663_mode7_mixer },
		.cap_mixer = alc662_auto_capture_mixer,
		.init_verbs = { alc662_init_verbs,
				alc663_mode7_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.hp_nid = 0x03,
		.dac_nids = alc662_dac_nids,
		.dig_out_nid = ALC662_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc663_mode7_unsol_event,
		.setup = alc663_mode7_setup,
		.init_hook = alc663_mode7_inithook,
	},
	[ALC663_ASUS_MODE8] = {
		.mixers = { alc663_mode8_mixer },
		.cap_mixer = alc662_auto_capture_mixer,
		.init_verbs = { alc662_init_verbs,
				alc663_mode8_init_verbs },
		.num_dacs = ARRAY_SIZE(alc662_dac_nids),
		.hp_nid = 0x03,
		.dac_nids = alc662_dac_nids,
		.dig_out_nid = ALC662_DIGOUT_NID,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc663_mode8_unsol_event,
		.setup = alc663_mode8_setup,
		.init_hook = alc663_mode8_inithook,
	},
17995 17996 17997 17998 17999 18000 18001 18002 18003 18004 18005 18006
	[ALC272_DELL] = {
		.mixers = { alc663_m51va_mixer },
		.cap_mixer = alc272_auto_capture_mixer,
		.init_verbs = { alc662_init_verbs, alc272_dell_init_verbs },
		.num_dacs = ARRAY_SIZE(alc272_dac_nids),
		.dac_nids = alc662_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.adc_nids = alc272_adc_nids,
		.num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
		.capsrc_nids = alc272_capsrc_nids,
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc663_m51va_unsol_event,
18007
		.setup = alc663_m51va_setup,
18008 18009 18010 18011 18012 18013 18014 18015 18016 18017
		.init_hook = alc663_m51va_inithook,
	},
	[ALC272_DELL_ZM1] = {
		.mixers = { alc663_m51va_mixer },
		.cap_mixer = alc662_auto_capture_mixer,
		.init_verbs = { alc662_init_verbs, alc272_dell_zm1_init_verbs },
		.num_dacs = ARRAY_SIZE(alc272_dac_nids),
		.dac_nids = alc662_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.adc_nids = alc662_adc_nids,
18018
		.num_adc_nids = 1,
18019 18020 18021
		.capsrc_nids = alc662_capsrc_nids,
		.channel_mode = alc662_3ST_2ch_modes,
		.unsol_event = alc663_m51va_unsol_event,
18022
		.setup = alc663_m51va_setup,
18023 18024
		.init_hook = alc663_m51va_inithook,
	},
18025 18026 18027 18028 18029 18030 18031 18032
	[ALC272_SAMSUNG_NC10] = {
		.mixers = { alc272_nc10_mixer },
		.init_verbs = { alc662_init_verbs,
				alc663_21jd_amic_init_verbs },
		.num_dacs = ARRAY_SIZE(alc272_dac_nids),
		.dac_nids = alc272_dac_nids,
		.num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
		.channel_mode = alc662_3ST_2ch_modes,
18033
		/*.input_mux = &alc272_nc10_capture_source,*/
18034
		.unsol_event = alc663_mode4_unsol_event,
18035
		.setup = alc663_mode4_setup,
18036 18037
		.init_hook = alc663_mode4_inithook,
	},
18038 18039 18040 18041 18042 18043 18044
};


/*
 * BIOS auto configuration
 */

18045 18046 18047 18048 18049 18050 18051 18052 18053 18054 18055 18056 18057 18058 18059 18060 18061 18062 18063 18064 18065 18066 18067 18068 18069 18070 18071 18072 18073 18074 18075 18076 18077 18078 18079 18080 18081 18082 18083 18084 18085 18086 18087 18088 18089 18090 18091 18092 18093 18094 18095 18096 18097 18098 18099 18100 18101 18102 18103 18104 18105 18106 18107 18108 18109 18110 18111
/* convert from MIX nid to DAC */
static inline hda_nid_t alc662_mix_to_dac(hda_nid_t nid)
{
	if (nid == 0x0f)
		return 0x02;
	else if (nid >= 0x0c && nid <= 0x0e)
		return nid - 0x0c + 0x02;
	else
		return 0;
}

/* get MIX nid connected to the given pin targeted to DAC */
static hda_nid_t alc662_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
				   hda_nid_t dac)
{
	hda_nid_t mix[4];
	int i, num;

	num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
	for (i = 0; i < num; i++) {
		if (alc662_mix_to_dac(mix[i]) == dac)
			return mix[i];
	}
	return 0;
}

/* look for an empty DAC slot */
static hda_nid_t alc662_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
{
	struct alc_spec *spec = codec->spec;
	hda_nid_t srcs[5];
	int i, j, num;

	num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
	if (num < 0)
		return 0;
	for (i = 0; i < num; i++) {
		hda_nid_t nid = alc662_mix_to_dac(srcs[i]);
		if (!nid)
			continue;
		for (j = 0; j < spec->multiout.num_dacs; j++)
			if (spec->multiout.dac_nids[j] == nid)
				break;
		if (j >= spec->multiout.num_dacs)
			return nid;
	}
	return 0;
}

/* fill in the dac_nids table from the parsed pin configuration */
static int alc662_auto_fill_dac_nids(struct hda_codec *codec,
				     const struct auto_pin_cfg *cfg)
{
	struct alc_spec *spec = codec->spec;
	int i;
	hda_nid_t dac;

	spec->multiout.dac_nids = spec->private_dac_nids;
	for (i = 0; i < cfg->line_outs; i++) {
		dac = alc662_look_for_dac(codec, cfg->line_out_pins[i]);
		if (!dac)
			continue;
		spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
	}
	return 0;
}

18112
static inline int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx,
18113 18114
			      hda_nid_t nid, unsigned int chs)
{
18115
	return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
18116 18117 18118
			   HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
}

18119
static inline int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx,
18120 18121
			     hda_nid_t nid, unsigned int chs)
{
18122
	return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
18123 18124 18125 18126 18127 18128 18129 18130
			   HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT));
}

#define alc662_add_stereo_vol(spec, pfx, nid) \
	alc662_add_vol_ctl(spec, pfx, nid, 3)
#define alc662_add_stereo_sw(spec, pfx, nid) \
	alc662_add_sw_ctl(spec, pfx, nid, 3)

18131
/* add playback controls from the parsed DAC table */
18132
static int alc662_auto_create_multi_out_ctls(struct hda_codec *codec,
18133 18134
					     const struct auto_pin_cfg *cfg)
{
18135
	struct alc_spec *spec = codec->spec;
18136 18137 18138
	static const char *chname[4] = {
		"Front", "Surround", NULL /*CLFE*/, "Side"
	};
18139
	hda_nid_t nid, mix;
18140 18141 18142
	int i, err;

	for (i = 0; i < cfg->line_outs; i++) {
18143 18144 18145 18146 18147
		nid = spec->multiout.dac_nids[i];
		if (!nid)
			continue;
		mix = alc662_dac_to_mix(codec, cfg->line_out_pins[i], nid);
		if (!mix)
18148 18149 18150
			continue;
		if (i == 2) {
			/* Center/LFE */
18151
			err = alc662_add_vol_ctl(spec, "Center", nid, 1);
18152 18153
			if (err < 0)
				return err;
18154
			err = alc662_add_vol_ctl(spec, "LFE", nid, 2);
18155 18156
			if (err < 0)
				return err;
18157
			err = alc662_add_sw_ctl(spec, "Center", mix, 1);
18158 18159
			if (err < 0)
				return err;
18160
			err = alc662_add_sw_ctl(spec, "LFE", mix, 2);
18161 18162 18163
			if (err < 0)
				return err;
		} else {
18164 18165 18166
			const char *pfx;
			if (cfg->line_outs == 1 &&
			    cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
18167
				if (cfg->hp_outs)
18168 18169 18170 18171 18172
					pfx = "Speaker";
				else
					pfx = "PCM";
			} else
				pfx = chname[i];
18173
			err = alc662_add_vol_ctl(spec, pfx, nid, 3);
18174 18175
			if (err < 0)
				return err;
18176 18177 18178
			if (cfg->line_outs == 1 &&
			    cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
				pfx = "Speaker";
18179
			err = alc662_add_sw_ctl(spec, pfx, mix, 3);
18180 18181 18182 18183 18184 18185 18186 18187
			if (err < 0)
				return err;
		}
	}
	return 0;
}

/* add playback controls for speaker and HP outputs */
18188 18189
/* return DAC nid if any new DAC is assigned */
static int alc662_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
18190 18191
					const char *pfx)
{
18192 18193
	struct alc_spec *spec = codec->spec;
	hda_nid_t nid, mix;
18194 18195 18196 18197
	int err;

	if (!pin)
		return 0;
18198 18199 18200 18201 18202 18203
	nid = alc662_look_for_dac(codec, pin);
	if (!nid) {
		/* the corresponding DAC is already occupied */
		if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
			return 0; /* no way */
		/* create a switch only */
18204
		return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
18205
				   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
T
Takashi Iwai 已提交
18206 18207
	}

18208 18209 18210 18211 18212 18213 18214 18215 18216 18217
	mix = alc662_dac_to_mix(codec, pin, nid);
	if (!mix)
		return 0;
	err = alc662_add_vol_ctl(spec, pfx, nid, 3);
	if (err < 0)
		return err;
	err = alc662_add_sw_ctl(spec, pfx, mix, 3);
	if (err < 0)
		return err;
	return nid;
18218 18219 18220
}

/* create playback/capture controls for input pins */
18221
#define alc662_auto_create_input_ctls \
18222
	alc882_auto_create_input_ctls
18223 18224 18225

static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
					      hda_nid_t nid, int pin_type,
18226
					      hda_nid_t dac)
18227
{
18228 18229 18230
	int i, num;
	hda_nid_t srcs[4];

18231
	alc_set_pin_output(codec, nid, pin_type);
18232
	/* need the manual connection? */
18233 18234 18235 18236 18237 18238 18239 18240
	num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
	if (num <= 1)
		return;
	for (i = 0; i < num; i++) {
		if (alc662_mix_to_dac(srcs[i]) != dac)
			continue;
		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
		return;
18241 18242 18243 18244 18245 18246
	}
}

static void alc662_auto_init_multi_out(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
18247
	int pin_type = get_pin_type(spec->autocfg.line_out_type);
18248 18249 18250 18251 18252
	int i;

	for (i = 0; i <= HDA_SIDE; i++) {
		hda_nid_t nid = spec->autocfg.line_out_pins[i];
		if (nid)
18253
			alc662_auto_set_output_and_unmute(codec, nid, pin_type,
18254
					spec->multiout.dac_nids[i]);
18255 18256 18257 18258 18259 18260 18261 18262 18263
	}
}

static void alc662_auto_init_hp_out(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	hda_nid_t pin;

	pin = spec->autocfg.hp_pins[0];
18264 18265 18266
	if (pin)
		alc662_auto_set_output_and_unmute(codec, pin, PIN_HP,
						  spec->multiout.hp_nid);
18267 18268
	pin = spec->autocfg.speaker_pins[0];
	if (pin)
18269 18270
		alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT,
					spec->multiout.extra_out_nid[0]);
18271 18272 18273 18274 18275 18276 18277 18278 18279 18280 18281
}

#define ALC662_PIN_CD_NID		ALC880_PIN_CD_NID

static void alc662_auto_init_analog_input(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int i;

	for (i = 0; i < AUTO_PIN_LAST; i++) {
		hda_nid_t nid = spec->autocfg.input_pins[i];
18282
		if (alc_is_input_pin(codec, nid)) {
18283
			alc_set_input_pin(codec, nid, i);
18284
			if (nid != ALC662_PIN_CD_NID &&
18285
			    (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
18286 18287 18288 18289 18290 18291 18292
				snd_hda_codec_write(codec, nid, 0,
						    AC_VERB_SET_AMP_GAIN_MUTE,
						    AMP_OUT_MUTE);
		}
	}
}

18293 18294
#define alc662_auto_init_input_src	alc882_auto_init_input_src

18295 18296 18297 18298 18299 18300 18301 18302 18303 18304 18305 18306 18307
static int alc662_parse_auto_config(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;
	int err;
	static hda_nid_t alc662_ignore[] = { 0x1d, 0 };

	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
					   alc662_ignore);
	if (err < 0)
		return err;
	if (!spec->autocfg.line_outs)
		return 0; /* can't find valid BIOS pin config */

18308
	err = alc662_auto_fill_dac_nids(codec, &spec->autocfg);
18309 18310
	if (err < 0)
		return err;
18311
	err = alc662_auto_create_multi_out_ctls(codec, &spec->autocfg);
18312 18313
	if (err < 0)
		return err;
18314
	err = alc662_auto_create_extra_out(codec,
18315 18316 18317 18318
					   spec->autocfg.speaker_pins[0],
					   "Speaker");
	if (err < 0)
		return err;
18319 18320 18321
	if (err)
		spec->multiout.extra_out_nid[0] = err;
	err = alc662_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
18322 18323 18324
					   "Headphone");
	if (err < 0)
		return err;
18325 18326
	if (err)
		spec->multiout.hp_nid = err;
18327
	err = alc662_auto_create_input_ctls(codec, &spec->autocfg);
18328
	if (err < 0)
18329 18330 18331 18332
		return err;

	spec->multiout.max_channels = spec->multiout.num_dacs * 2;

18333
	if (spec->autocfg.dig_outs)
18334 18335
		spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;

18336
	if (spec->kctls.list)
18337
		add_mixer(spec, spec->kctls.list);
18338 18339

	spec->num_mux_defs = 1;
18340
	spec->input_mux = &spec->private_imux[0];
18341

K
Kailang Yang 已提交
18342 18343 18344 18345 18346 18347 18348
	add_verb(spec, alc662_init_verbs);
	if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
	    codec->vendor_id == 0x10ec0665)
		add_verb(spec, alc663_init_verbs);

	if (codec->vendor_id == 0x10ec0272)
		add_verb(spec, alc272_init_verbs);
18349 18350 18351 18352 18353

	err = alc_auto_add_mic_boost(codec);
	if (err < 0)
		return err;

18354 18355 18356 18357 18358
	if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
	    codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
	    alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0x21);
	else
	    alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
18359

18360
	return 1;
18361 18362 18363 18364 18365
}

/* additional initialization for auto-configuration model */
static void alc662_auto_init(struct hda_codec *codec)
{
18366
	struct alc_spec *spec = codec->spec;
18367 18368 18369
	alc662_auto_init_multi_out(codec);
	alc662_auto_init_hp_out(codec);
	alc662_auto_init_analog_input(codec);
18370
	alc662_auto_init_input_src(codec);
18371
	if (spec->unsol_event)
18372
		alc_inithook(codec);
18373 18374 18375 18376 18377 18378 18379 18380 18381 18382 18383 18384 18385
}

static int patch_alc662(struct hda_codec *codec)
{
	struct alc_spec *spec;
	int err, board_config;

	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
	if (!spec)
		return -ENOMEM;

	codec->spec = spec;

18386 18387
	alc_fix_pll_init(codec, 0x20, 0x04, 15);

18388 18389 18390
	if (alc_read_coef_idx(codec, 0)==0x8020){
		kfree(codec->chip_name);
		codec->chip_name = kstrdup("ALC661", GFP_KERNEL);
18391 18392
		if (!codec->chip_name) {
			alc_free(codec);
18393
			return -ENOMEM;
18394
		}
18395 18396
	}

18397 18398 18399 18400
	board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
						  alc662_models,
			  	                  alc662_cfg_tbl);
	if (board_config < 0) {
18401 18402
		printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
		       codec->chip_name);
18403 18404 18405 18406 18407 18408 18409 18410 18411
		board_config = ALC662_AUTO;
	}

	if (board_config == ALC662_AUTO) {
		/* automatic parse from the BIOS config */
		err = alc662_parse_auto_config(codec);
		if (err < 0) {
			alc_free(codec);
			return err;
18412
		} else if (!err) {
18413 18414 18415 18416 18417 18418 18419
			printk(KERN_INFO
			       "hda_codec: Cannot set up configuration "
			       "from BIOS.  Using base mode...\n");
			board_config = ALC662_3ST_2ch_DIG;
		}
	}

18420 18421 18422 18423 18424 18425
	err = snd_hda_attach_beep_device(codec, 0x1);
	if (err < 0) {
		alc_free(codec);
		return err;
	}

18426
	if (board_config != ALC662_AUTO)
18427
		setup_preset(codec, &alc662_presets[board_config]);
18428 18429 18430 18431 18432 18433 18434

	spec->stream_analog_playback = &alc662_pcm_analog_playback;
	spec->stream_analog_capture = &alc662_pcm_analog_capture;

	spec->stream_digital_playback = &alc662_pcm_digital_playback;
	spec->stream_digital_capture = &alc662_pcm_digital_capture;

18435 18436 18437 18438 18439 18440
	if (!spec->adc_nids) {
		spec->adc_nids = alc662_adc_nids;
		spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
	}
	if (!spec->capsrc_nids)
		spec->capsrc_nids = alc662_capsrc_nids;
18441

18442
	if (!spec->cap_mixer)
18443
		set_capture_mixer(codec);
K
Kailang Yang 已提交
18444 18445 18446

	switch (codec->vendor_id) {
	case 0x10ec0662:
T
Takashi Iwai 已提交
18447
		set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
K
Kailang Yang 已提交
18448 18449 18450 18451
		break;
	case 0x10ec0272:
	case 0x10ec0663:
	case 0x10ec0665:
T
Takashi Iwai 已提交
18452
		set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
K
Kailang Yang 已提交
18453 18454 18455 18456 18457
		break;
	case 0x10ec0273:
		set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
		break;
	}
18458 18459
	spec->vmaster_nid = 0x02;

18460 18461 18462
	codec->patch_ops = alc_patch_ops;
	if (board_config == ALC662_AUTO)
		spec->init_hook = alc662_auto_init;
18463 18464 18465 18466
#ifdef CONFIG_SND_HDA_POWER_SAVE
	if (!spec->loopback.amplist)
		spec->loopback.amplist = alc662_loopbacks;
#endif
18467 18468 18469 18470

	return 0;
}

18471 18472 18473 18474 18475
static int patch_alc888(struct hda_codec *codec)
{
	if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
		kfree(codec->chip_name);
		codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
18476 18477
		if (!codec->chip_name) {
			alc_free(codec);
18478
			return -ENOMEM;
18479 18480
		}
		return patch_alc662(codec);
18481
	}
18482
	return patch_alc882(codec);
18483 18484
}

L
Linus Torvalds 已提交
18485 18486 18487
/*
 * patch entries
 */
18488
static struct hda_codec_preset snd_hda_preset_realtek[] = {
L
Linus Torvalds 已提交
18489
	{ .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
18490
	{ .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
18491
	{ .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
18492
	{ .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
18493
	{ .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
18494
	{ .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
K
Kailang Yang 已提交
18495
	{ .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
18496
	{ .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
18497
	{ .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
18498
	  .patch = patch_alc861 },
18499 18500 18501
	{ .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
	{ .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
	{ .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
18502
	{ .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
18503
	  .patch = patch_alc882 },
18504 18505
	{ .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
	  .patch = patch_alc662 },
K
Kailang Yang 已提交
18506
	{ .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
K
Kailang Yang 已提交
18507
	{ .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
18508
	{ .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
18509
	{ .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
L
Linus Torvalds 已提交
18510
	{ .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
18511
	{ .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
18512
	{ .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
18513
	  .patch = patch_alc882 },
18514
	{ .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
18515
	  .patch = patch_alc882 },
18516
	{ .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
18517
	{ .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
K
Kailang Yang 已提交
18518
	{ .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
18519
	  .patch = patch_alc882 },
18520
	{ .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
18521
	{ .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
18522
	{ .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
L
Linus Torvalds 已提交
18523 18524
	{} /* terminator */
};
18525 18526 18527 18528 18529 18530 18531 18532 18533 18534 18535 18536 18537 18538 18539 18540 18541 18542 18543 18544 18545 18546 18547

MODULE_ALIAS("snd-hda-codec-id:10ec*");

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Realtek HD-audio codec");

static struct hda_codec_preset_list realtek_list = {
	.preset = snd_hda_preset_realtek,
	.owner = THIS_MODULE,
};

static int __init patch_realtek_init(void)
{
	return snd_hda_add_codec_preset(&realtek_list);
}

static void __exit patch_realtek_exit(void)
{
	snd_hda_delete_codec_preset(&realtek_list);
}

module_init(patch_realtek_init)
module_exit(patch_realtek_exit)