xref: /openbmc/linux/sound/pci/hda/patch_realtek.c (revision 93d90ad7)
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for Realtek ALC codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@just42.net>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25 
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <linux/dmi.h>
31 #include <linux/module.h>
32 #include <sound/core.h>
33 #include <sound/jack.h>
34 #include "hda_codec.h"
35 #include "hda_local.h"
36 #include "hda_auto_parser.h"
37 #include "hda_jack.h"
38 #include "hda_generic.h"
39 
40 /* keep halting ALC5505 DSP, for power saving */
41 #define HALT_REALTEK_ALC5505
42 
43 /* for GPIO Poll */
44 #define GPIO_MASK	0x03
45 
46 /* extra amp-initialization sequence types */
47 enum {
48 	ALC_INIT_NONE,
49 	ALC_INIT_DEFAULT,
50 	ALC_INIT_GPIO1,
51 	ALC_INIT_GPIO2,
52 	ALC_INIT_GPIO3,
53 };
54 
55 enum {
56 	ALC_HEADSET_MODE_UNKNOWN,
57 	ALC_HEADSET_MODE_UNPLUGGED,
58 	ALC_HEADSET_MODE_HEADSET,
59 	ALC_HEADSET_MODE_MIC,
60 	ALC_HEADSET_MODE_HEADPHONE,
61 };
62 
63 enum {
64 	ALC_HEADSET_TYPE_UNKNOWN,
65 	ALC_HEADSET_TYPE_CTIA,
66 	ALC_HEADSET_TYPE_OMTP,
67 };
68 
69 struct alc_customize_define {
70 	unsigned int  sku_cfg;
71 	unsigned char port_connectivity;
72 	unsigned char check_sum;
73 	unsigned char customization;
74 	unsigned char external_amp;
75 	unsigned int  enable_pcbeep:1;
76 	unsigned int  platform_type:1;
77 	unsigned int  swap:1;
78 	unsigned int  override:1;
79 	unsigned int  fixup:1; /* Means that this sku is set by driver, not read from hw */
80 };
81 
82 struct alc_spec {
83 	struct hda_gen_spec gen; /* must be at head */
84 
85 	/* codec parameterization */
86 	const struct snd_kcontrol_new *mixers[5];	/* mixer arrays */
87 	unsigned int num_mixers;
88 	unsigned int beep_amp;	/* beep amp value, set via set_beep_amp() */
89 
90 	struct alc_customize_define cdefine;
91 	unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
92 
93 	/* mute LED for HP laptops, see alc269_fixup_mic_mute_hook() */
94 	int mute_led_polarity;
95 	hda_nid_t mute_led_nid;
96 	hda_nid_t cap_mute_led_nid;
97 
98 	unsigned int gpio_led; /* used for alc269_fixup_hp_gpio_led() */
99 	unsigned int gpio_mute_led_mask;
100 	unsigned int gpio_mic_led_mask;
101 
102 	hda_nid_t headset_mic_pin;
103 	hda_nid_t headphone_mic_pin;
104 	int current_headset_mode;
105 	int current_headset_type;
106 
107 	/* hooks */
108 	void (*init_hook)(struct hda_codec *codec);
109 #ifdef CONFIG_PM
110 	void (*power_hook)(struct hda_codec *codec);
111 #endif
112 	void (*shutup)(struct hda_codec *codec);
113 
114 	int init_amp;
115 	int codec_variant;	/* flag for other variants */
116 	unsigned int has_alc5505_dsp:1;
117 	unsigned int no_depop_delay:1;
118 
119 	/* for PLL fix */
120 	hda_nid_t pll_nid;
121 	unsigned int pll_coef_idx, pll_coef_bit;
122 	unsigned int coef0;
123 };
124 
125 /*
126  * COEF access helper functions
127  */
128 
129 static int alc_read_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
130 			       unsigned int coef_idx)
131 {
132 	unsigned int val;
133 
134 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX, coef_idx);
135 	val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
136 	return val;
137 }
138 
139 #define alc_read_coef_idx(codec, coef_idx) \
140 	alc_read_coefex_idx(codec, 0x20, coef_idx)
141 
142 static void alc_write_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
143 				 unsigned int coef_idx, unsigned int coef_val)
144 {
145 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX, coef_idx);
146 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PROC_COEF, coef_val);
147 }
148 
149 #define alc_write_coef_idx(codec, coef_idx, coef_val) \
150 	alc_write_coefex_idx(codec, 0x20, coef_idx, coef_val)
151 
152 static void alc_update_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
153 				  unsigned int coef_idx, unsigned int mask,
154 				  unsigned int bits_set)
155 {
156 	unsigned int val = alc_read_coefex_idx(codec, nid, coef_idx);
157 
158 	if (val != -1)
159 		alc_write_coefex_idx(codec, nid, coef_idx,
160 				     (val & ~mask) | bits_set);
161 }
162 
163 #define alc_update_coef_idx(codec, coef_idx, mask, bits_set)	\
164 	alc_update_coefex_idx(codec, 0x20, coef_idx, mask, bits_set)
165 
166 /* a special bypass for COEF 0; read the cached value at the second time */
167 static unsigned int alc_get_coef0(struct hda_codec *codec)
168 {
169 	struct alc_spec *spec = codec->spec;
170 
171 	if (!spec->coef0)
172 		spec->coef0 = alc_read_coef_idx(codec, 0);
173 	return spec->coef0;
174 }
175 
176 /* coef writes/updates batch */
177 struct coef_fw {
178 	unsigned char nid;
179 	unsigned char idx;
180 	unsigned short mask;
181 	unsigned short val;
182 };
183 
184 #define UPDATE_COEFEX(_nid, _idx, _mask, _val) \
185 	{ .nid = (_nid), .idx = (_idx), .mask = (_mask), .val = (_val) }
186 #define WRITE_COEFEX(_nid, _idx, _val) UPDATE_COEFEX(_nid, _idx, -1, _val)
187 #define WRITE_COEF(_idx, _val) WRITE_COEFEX(0x20, _idx, _val)
188 #define UPDATE_COEF(_idx, _mask, _val) UPDATE_COEFEX(0x20, _idx, _mask, _val)
189 
190 static void alc_process_coef_fw(struct hda_codec *codec,
191 				const struct coef_fw *fw)
192 {
193 	for (; fw->nid; fw++) {
194 		if (fw->mask == (unsigned short)-1)
195 			alc_write_coefex_idx(codec, fw->nid, fw->idx, fw->val);
196 		else
197 			alc_update_coefex_idx(codec, fw->nid, fw->idx,
198 					      fw->mask, fw->val);
199 	}
200 }
201 
202 /*
203  * Append the given mixer and verb elements for the later use
204  * The mixer array is referred in build_controls(), and init_verbs are
205  * called in init().
206  */
207 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
208 {
209 	if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
210 		return;
211 	spec->mixers[spec->num_mixers++] = mix;
212 }
213 
214 /*
215  * GPIO setup tables, used in initialization
216  */
217 /* Enable GPIO mask and set output */
218 static const struct hda_verb alc_gpio1_init_verbs[] = {
219 	{0x01, AC_VERB_SET_GPIO_MASK, 0x01},
220 	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
221 	{0x01, AC_VERB_SET_GPIO_DATA, 0x01},
222 	{ }
223 };
224 
225 static const struct hda_verb alc_gpio2_init_verbs[] = {
226 	{0x01, AC_VERB_SET_GPIO_MASK, 0x02},
227 	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
228 	{0x01, AC_VERB_SET_GPIO_DATA, 0x02},
229 	{ }
230 };
231 
232 static const struct hda_verb alc_gpio3_init_verbs[] = {
233 	{0x01, AC_VERB_SET_GPIO_MASK, 0x03},
234 	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
235 	{0x01, AC_VERB_SET_GPIO_DATA, 0x03},
236 	{ }
237 };
238 
239 /*
240  * Fix hardware PLL issue
241  * On some codecs, the analog PLL gating control must be off while
242  * the default value is 1.
243  */
244 static void alc_fix_pll(struct hda_codec *codec)
245 {
246 	struct alc_spec *spec = codec->spec;
247 
248 	if (spec->pll_nid)
249 		alc_update_coefex_idx(codec, spec->pll_nid, spec->pll_coef_idx,
250 				      1 << spec->pll_coef_bit, 0);
251 }
252 
253 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
254 			     unsigned int coef_idx, unsigned int coef_bit)
255 {
256 	struct alc_spec *spec = codec->spec;
257 	spec->pll_nid = nid;
258 	spec->pll_coef_idx = coef_idx;
259 	spec->pll_coef_bit = coef_bit;
260 	alc_fix_pll(codec);
261 }
262 
263 /* update the master volume per volume-knob's unsol event */
264 static void alc_update_knob_master(struct hda_codec *codec,
265 				   struct hda_jack_callback *jack)
266 {
267 	unsigned int val;
268 	struct snd_kcontrol *kctl;
269 	struct snd_ctl_elem_value *uctl;
270 
271 	kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
272 	if (!kctl)
273 		return;
274 	uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
275 	if (!uctl)
276 		return;
277 	val = snd_hda_codec_read(codec, jack->tbl->nid, 0,
278 				 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
279 	val &= HDA_AMP_VOLMASK;
280 	uctl->value.integer.value[0] = val;
281 	uctl->value.integer.value[1] = val;
282 	kctl->put(kctl, uctl);
283 	kfree(uctl);
284 }
285 
286 static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
287 {
288 	/* For some reason, the res given from ALC880 is broken.
289 	   Here we adjust it properly. */
290 	snd_hda_jack_unsol_event(codec, res >> 2);
291 }
292 
293 /* Change EAPD to verb control */
294 static void alc_fill_eapd_coef(struct hda_codec *codec)
295 {
296 	int coef;
297 
298 	coef = alc_get_coef0(codec);
299 
300 	switch (codec->vendor_id) {
301 	case 0x10ec0262:
302 		alc_update_coef_idx(codec, 0x7, 0, 1<<5);
303 		break;
304 	case 0x10ec0267:
305 	case 0x10ec0268:
306 		alc_update_coef_idx(codec, 0x7, 0, 1<<13);
307 		break;
308 	case 0x10ec0269:
309 		if ((coef & 0x00f0) == 0x0010)
310 			alc_update_coef_idx(codec, 0xd, 0, 1<<14);
311 		if ((coef & 0x00f0) == 0x0020)
312 			alc_update_coef_idx(codec, 0x4, 1<<15, 0);
313 		if ((coef & 0x00f0) == 0x0030)
314 			alc_update_coef_idx(codec, 0x10, 1<<9, 0);
315 		break;
316 	case 0x10ec0280:
317 	case 0x10ec0284:
318 	case 0x10ec0290:
319 	case 0x10ec0292:
320 		alc_update_coef_idx(codec, 0x4, 1<<15, 0);
321 		break;
322 	case 0x10ec0233:
323 	case 0x10ec0255:
324 	case 0x10ec0256:
325 	case 0x10ec0282:
326 	case 0x10ec0283:
327 	case 0x10ec0286:
328 	case 0x10ec0288:
329 	case 0x10ec0298:
330 		alc_update_coef_idx(codec, 0x10, 1<<9, 0);
331 		break;
332 	case 0x10ec0285:
333 	case 0x10ec0293:
334 		alc_update_coef_idx(codec, 0xa, 1<<13, 0);
335 		break;
336 	case 0x10ec0662:
337 		if ((coef & 0x00f0) == 0x0030)
338 			alc_update_coef_idx(codec, 0x4, 1<<10, 0); /* EAPD Ctrl */
339 		break;
340 	case 0x10ec0272:
341 	case 0x10ec0273:
342 	case 0x10ec0663:
343 	case 0x10ec0665:
344 	case 0x10ec0670:
345 	case 0x10ec0671:
346 	case 0x10ec0672:
347 		alc_update_coef_idx(codec, 0xd, 0, 1<<14); /* EAPD Ctrl */
348 		break;
349 	case 0x10ec0668:
350 		alc_update_coef_idx(codec, 0x7, 3<<13, 0);
351 		break;
352 	case 0x10ec0867:
353 		alc_update_coef_idx(codec, 0x4, 1<<10, 0);
354 		break;
355 	case 0x10ec0888:
356 		if ((coef & 0x00f0) == 0x0020 || (coef & 0x00f0) == 0x0030)
357 			alc_update_coef_idx(codec, 0x7, 1<<5, 0);
358 		break;
359 	case 0x10ec0892:
360 		alc_update_coef_idx(codec, 0x7, 1<<5, 0);
361 		break;
362 	case 0x10ec0899:
363 	case 0x10ec0900:
364 		alc_update_coef_idx(codec, 0x7, 1<<1, 0);
365 		break;
366 	}
367 }
368 
369 /* additional initialization for ALC888 variants */
370 static void alc888_coef_init(struct hda_codec *codec)
371 {
372 	switch (alc_get_coef0(codec) & 0x00f0) {
373 	/* alc888-VA */
374 	case 0x00:
375 	/* alc888-VB */
376 	case 0x10:
377 		alc_update_coef_idx(codec, 7, 0, 0x2030); /* Turn EAPD to High */
378 		break;
379 	}
380 }
381 
382 /* turn on/off EAPD control (only if available) */
383 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
384 {
385 	if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
386 		return;
387 	if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
388 		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
389 				    on ? 2 : 0);
390 }
391 
392 /* turn on/off EAPD controls of the codec */
393 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
394 {
395 	/* We currently only handle front, HP */
396 	static hda_nid_t pins[] = {
397 		0x0f, 0x10, 0x14, 0x15, 0
398 	};
399 	hda_nid_t *p;
400 	for (p = pins; *p; p++)
401 		set_eapd(codec, *p, on);
402 }
403 
404 /* generic shutup callback;
405  * just turning off EPAD and a little pause for avoiding pop-noise
406  */
407 static void alc_eapd_shutup(struct hda_codec *codec)
408 {
409 	struct alc_spec *spec = codec->spec;
410 
411 	alc_auto_setup_eapd(codec, false);
412 	if (!spec->no_depop_delay)
413 		msleep(200);
414 	snd_hda_shutup_pins(codec);
415 }
416 
417 /* generic EAPD initialization */
418 static void alc_auto_init_amp(struct hda_codec *codec, int type)
419 {
420 	alc_fill_eapd_coef(codec);
421 	alc_auto_setup_eapd(codec, true);
422 	switch (type) {
423 	case ALC_INIT_GPIO1:
424 		snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
425 		break;
426 	case ALC_INIT_GPIO2:
427 		snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
428 		break;
429 	case ALC_INIT_GPIO3:
430 		snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
431 		break;
432 	case ALC_INIT_DEFAULT:
433 		switch (codec->vendor_id) {
434 		case 0x10ec0260:
435 			alc_update_coefex_idx(codec, 0x1a, 7, 0, 0x2010);
436 			break;
437 		case 0x10ec0880:
438 		case 0x10ec0882:
439 		case 0x10ec0883:
440 		case 0x10ec0885:
441 			alc_update_coef_idx(codec, 7, 0, 0x2030);
442 			break;
443 		case 0x10ec0888:
444 			alc888_coef_init(codec);
445 			break;
446 		}
447 		break;
448 	}
449 }
450 
451 
452 /*
453  * Realtek SSID verification
454  */
455 
456 /* Could be any non-zero and even value. When used as fixup, tells
457  * the driver to ignore any present sku defines.
458  */
459 #define ALC_FIXUP_SKU_IGNORE (2)
460 
461 static void alc_fixup_sku_ignore(struct hda_codec *codec,
462 				 const struct hda_fixup *fix, int action)
463 {
464 	struct alc_spec *spec = codec->spec;
465 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
466 		spec->cdefine.fixup = 1;
467 		spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
468 	}
469 }
470 
471 static void alc_fixup_no_depop_delay(struct hda_codec *codec,
472 				    const struct hda_fixup *fix, int action)
473 {
474 	struct alc_spec *spec = codec->spec;
475 
476 	if (action == HDA_FIXUP_ACT_PROBE) {
477 		spec->no_depop_delay = 1;
478 		codec->depop_delay = 0;
479 	}
480 }
481 
482 static int alc_auto_parse_customize_define(struct hda_codec *codec)
483 {
484 	unsigned int ass, tmp, i;
485 	unsigned nid = 0;
486 	struct alc_spec *spec = codec->spec;
487 
488 	spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
489 
490 	if (spec->cdefine.fixup) {
491 		ass = spec->cdefine.sku_cfg;
492 		if (ass == ALC_FIXUP_SKU_IGNORE)
493 			return -1;
494 		goto do_sku;
495 	}
496 
497 	if (!codec->bus->pci)
498 		return -1;
499 	ass = codec->subsystem_id & 0xffff;
500 	if (ass != codec->bus->pci->subsystem_device && (ass & 1))
501 		goto do_sku;
502 
503 	nid = 0x1d;
504 	if (codec->vendor_id == 0x10ec0260)
505 		nid = 0x17;
506 	ass = snd_hda_codec_get_pincfg(codec, nid);
507 
508 	if (!(ass & 1)) {
509 		codec_info(codec, "%s: SKU not ready 0x%08x\n",
510 			   codec->chip_name, ass);
511 		return -1;
512 	}
513 
514 	/* check sum */
515 	tmp = 0;
516 	for (i = 1; i < 16; i++) {
517 		if ((ass >> i) & 1)
518 			tmp++;
519 	}
520 	if (((ass >> 16) & 0xf) != tmp)
521 		return -1;
522 
523 	spec->cdefine.port_connectivity = ass >> 30;
524 	spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
525 	spec->cdefine.check_sum = (ass >> 16) & 0xf;
526 	spec->cdefine.customization = ass >> 8;
527 do_sku:
528 	spec->cdefine.sku_cfg = ass;
529 	spec->cdefine.external_amp = (ass & 0x38) >> 3;
530 	spec->cdefine.platform_type = (ass & 0x4) >> 2;
531 	spec->cdefine.swap = (ass & 0x2) >> 1;
532 	spec->cdefine.override = ass & 0x1;
533 
534 	codec_dbg(codec, "SKU: Nid=0x%x sku_cfg=0x%08x\n",
535 		   nid, spec->cdefine.sku_cfg);
536 	codec_dbg(codec, "SKU: port_connectivity=0x%x\n",
537 		   spec->cdefine.port_connectivity);
538 	codec_dbg(codec, "SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
539 	codec_dbg(codec, "SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
540 	codec_dbg(codec, "SKU: customization=0x%08x\n", spec->cdefine.customization);
541 	codec_dbg(codec, "SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
542 	codec_dbg(codec, "SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
543 	codec_dbg(codec, "SKU: swap=0x%x\n", spec->cdefine.swap);
544 	codec_dbg(codec, "SKU: override=0x%x\n", spec->cdefine.override);
545 
546 	return 0;
547 }
548 
549 /* return the position of NID in the list, or -1 if not found */
550 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
551 {
552 	int i;
553 	for (i = 0; i < nums; i++)
554 		if (list[i] == nid)
555 			return i;
556 	return -1;
557 }
558 /* return true if the given NID is found in the list */
559 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
560 {
561 	return find_idx_in_nid_list(nid, list, nums) >= 0;
562 }
563 
564 /* check subsystem ID and set up device-specific initialization;
565  * return 1 if initialized, 0 if invalid SSID
566  */
567 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
568  *	31 ~ 16 :	Manufacture ID
569  *	15 ~ 8	:	SKU ID
570  *	7  ~ 0	:	Assembly ID
571  *	port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
572  */
573 static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports)
574 {
575 	unsigned int ass, tmp, i;
576 	unsigned nid;
577 	struct alc_spec *spec = codec->spec;
578 
579 	if (spec->cdefine.fixup) {
580 		ass = spec->cdefine.sku_cfg;
581 		if (ass == ALC_FIXUP_SKU_IGNORE)
582 			return 0;
583 		goto do_sku;
584 	}
585 
586 	ass = codec->subsystem_id & 0xffff;
587 	if (codec->bus->pci &&
588 	    ass != codec->bus->pci->subsystem_device && (ass & 1))
589 		goto do_sku;
590 
591 	/* invalid SSID, check the special NID pin defcfg instead */
592 	/*
593 	 * 31~30	: port connectivity
594 	 * 29~21	: reserve
595 	 * 20		: PCBEEP input
596 	 * 19~16	: Check sum (15:1)
597 	 * 15~1		: Custom
598 	 * 0		: override
599 	*/
600 	nid = 0x1d;
601 	if (codec->vendor_id == 0x10ec0260)
602 		nid = 0x17;
603 	ass = snd_hda_codec_get_pincfg(codec, nid);
604 	codec_dbg(codec,
605 		  "realtek: No valid SSID, checking pincfg 0x%08x for NID 0x%x\n",
606 		   ass, nid);
607 	if (!(ass & 1))
608 		return 0;
609 	if ((ass >> 30) != 1)	/* no physical connection */
610 		return 0;
611 
612 	/* check sum */
613 	tmp = 0;
614 	for (i = 1; i < 16; i++) {
615 		if ((ass >> i) & 1)
616 			tmp++;
617 	}
618 	if (((ass >> 16) & 0xf) != tmp)
619 		return 0;
620 do_sku:
621 	codec_dbg(codec, "realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
622 		   ass & 0xffff, codec->vendor_id);
623 	/*
624 	 * 0 : override
625 	 * 1 :	Swap Jack
626 	 * 2 : 0 --> Desktop, 1 --> Laptop
627 	 * 3~5 : External Amplifier control
628 	 * 7~6 : Reserved
629 	*/
630 	tmp = (ass & 0x38) >> 3;	/* external Amp control */
631 	switch (tmp) {
632 	case 1:
633 		spec->init_amp = ALC_INIT_GPIO1;
634 		break;
635 	case 3:
636 		spec->init_amp = ALC_INIT_GPIO2;
637 		break;
638 	case 7:
639 		spec->init_amp = ALC_INIT_GPIO3;
640 		break;
641 	case 5:
642 	default:
643 		spec->init_amp = ALC_INIT_DEFAULT;
644 		break;
645 	}
646 
647 	/* is laptop or Desktop and enable the function "Mute internal speaker
648 	 * when the external headphone out jack is plugged"
649 	 */
650 	if (!(ass & 0x8000))
651 		return 1;
652 	/*
653 	 * 10~8 : Jack location
654 	 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
655 	 * 14~13: Resvered
656 	 * 15   : 1 --> enable the function "Mute internal speaker
657 	 *	        when the external headphone out jack is plugged"
658 	 */
659 	if (!spec->gen.autocfg.hp_pins[0] &&
660 	    !(spec->gen.autocfg.line_out_pins[0] &&
661 	      spec->gen.autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
662 		hda_nid_t nid;
663 		tmp = (ass >> 11) & 0x3;	/* HP to chassis */
664 		nid = ports[tmp];
665 		if (found_in_nid_list(nid, spec->gen.autocfg.line_out_pins,
666 				      spec->gen.autocfg.line_outs))
667 			return 1;
668 		spec->gen.autocfg.hp_pins[0] = nid;
669 	}
670 	return 1;
671 }
672 
673 /* Check the validity of ALC subsystem-id
674  * ports contains an array of 4 pin NIDs for port-A, E, D and I */
675 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
676 {
677 	if (!alc_subsystem_id(codec, ports)) {
678 		struct alc_spec *spec = codec->spec;
679 		codec_dbg(codec,
680 			  "realtek: Enable default setup for auto mode as fallback\n");
681 		spec->init_amp = ALC_INIT_DEFAULT;
682 	}
683 }
684 
685 /*
686  */
687 
688 static void alc_fixup_inv_dmic(struct hda_codec *codec,
689 			       const struct hda_fixup *fix, int action)
690 {
691 	struct alc_spec *spec = codec->spec;
692 
693 	spec->gen.inv_dmic_split = 1;
694 }
695 
696 
697 #ifdef CONFIG_SND_HDA_INPUT_BEEP
698 /* additional beep mixers; the actual parameters are overwritten at build */
699 static const struct snd_kcontrol_new alc_beep_mixer[] = {
700 	HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
701 	HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
702 	{ } /* end */
703 };
704 #endif
705 
706 static int alc_build_controls(struct hda_codec *codec)
707 {
708 	struct alc_spec *spec = codec->spec;
709 	int i, err;
710 
711 	err = snd_hda_gen_build_controls(codec);
712 	if (err < 0)
713 		return err;
714 
715 	for (i = 0; i < spec->num_mixers; i++) {
716 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
717 		if (err < 0)
718 			return err;
719 	}
720 
721 #ifdef CONFIG_SND_HDA_INPUT_BEEP
722 	/* create beep controls if needed */
723 	if (spec->beep_amp) {
724 		const struct snd_kcontrol_new *knew;
725 		for (knew = alc_beep_mixer; knew->name; knew++) {
726 			struct snd_kcontrol *kctl;
727 			kctl = snd_ctl_new1(knew, codec);
728 			if (!kctl)
729 				return -ENOMEM;
730 			kctl->private_value = spec->beep_amp;
731 			err = snd_hda_ctl_add(codec, 0, kctl);
732 			if (err < 0)
733 				return err;
734 		}
735 	}
736 #endif
737 
738 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD);
739 	return 0;
740 }
741 
742 
743 /*
744  * Common callbacks
745  */
746 
747 static int alc_init(struct hda_codec *codec)
748 {
749 	struct alc_spec *spec = codec->spec;
750 
751 	if (spec->init_hook)
752 		spec->init_hook(codec);
753 
754 	alc_fix_pll(codec);
755 	alc_auto_init_amp(codec, spec->init_amp);
756 
757 	snd_hda_gen_init(codec);
758 
759 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
760 
761 	return 0;
762 }
763 
764 static inline void alc_shutup(struct hda_codec *codec)
765 {
766 	struct alc_spec *spec = codec->spec;
767 
768 	if (spec && spec->shutup)
769 		spec->shutup(codec);
770 	else
771 		snd_hda_shutup_pins(codec);
772 }
773 
774 #define alc_free	snd_hda_gen_free
775 
776 #ifdef CONFIG_PM
777 static void alc_power_eapd(struct hda_codec *codec)
778 {
779 	alc_auto_setup_eapd(codec, false);
780 }
781 
782 static int alc_suspend(struct hda_codec *codec)
783 {
784 	struct alc_spec *spec = codec->spec;
785 	alc_shutup(codec);
786 	if (spec && spec->power_hook)
787 		spec->power_hook(codec);
788 	return 0;
789 }
790 #endif
791 
792 #ifdef CONFIG_PM
793 static int alc_resume(struct hda_codec *codec)
794 {
795 	struct alc_spec *spec = codec->spec;
796 
797 	if (!spec->no_depop_delay)
798 		msleep(150); /* to avoid pop noise */
799 	codec->patch_ops.init(codec);
800 	snd_hda_codec_resume_amp(codec);
801 	snd_hda_codec_resume_cache(codec);
802 	hda_call_check_power_status(codec, 0x01);
803 	return 0;
804 }
805 #endif
806 
807 /*
808  */
809 static const struct hda_codec_ops alc_patch_ops = {
810 	.build_controls = alc_build_controls,
811 	.build_pcms = snd_hda_gen_build_pcms,
812 	.init = alc_init,
813 	.free = alc_free,
814 	.unsol_event = snd_hda_jack_unsol_event,
815 #ifdef CONFIG_PM
816 	.resume = alc_resume,
817 	.suspend = alc_suspend,
818 	.check_power_status = snd_hda_gen_check_power_status,
819 #endif
820 	.reboot_notify = alc_shutup,
821 };
822 
823 
824 /* replace the codec chip_name with the given string */
825 static int alc_codec_rename(struct hda_codec *codec, const char *name)
826 {
827 	kfree(codec->chip_name);
828 	codec->chip_name = kstrdup(name, GFP_KERNEL);
829 	if (!codec->chip_name) {
830 		alc_free(codec);
831 		return -ENOMEM;
832 	}
833 	return 0;
834 }
835 
836 /*
837  * Rename codecs appropriately from COEF value or subvendor id
838  */
839 struct alc_codec_rename_table {
840 	unsigned int vendor_id;
841 	unsigned short coef_mask;
842 	unsigned short coef_bits;
843 	const char *name;
844 };
845 
846 struct alc_codec_rename_pci_table {
847 	unsigned int codec_vendor_id;
848 	unsigned short pci_subvendor;
849 	unsigned short pci_subdevice;
850 	const char *name;
851 };
852 
853 static struct alc_codec_rename_table rename_tbl[] = {
854 	{ 0x10ec0221, 0xf00f, 0x1003, "ALC231" },
855 	{ 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
856 	{ 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
857 	{ 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
858 	{ 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
859 	{ 0x10ec0269, 0xffff, 0xa023, "ALC259" },
860 	{ 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
861 	{ 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
862 	{ 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
863 	{ 0x10ec0662, 0xffff, 0x4020, "ALC656" },
864 	{ 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
865 	{ 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
866 	{ 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
867 	{ 0x10ec0899, 0x2000, 0x2000, "ALC899" },
868 	{ 0x10ec0892, 0xffff, 0x8020, "ALC661" },
869 	{ 0x10ec0892, 0xffff, 0x8011, "ALC661" },
870 	{ 0x10ec0892, 0xffff, 0x4011, "ALC656" },
871 	{ } /* terminator */
872 };
873 
874 static struct alc_codec_rename_pci_table rename_pci_tbl[] = {
875 	{ 0x10ec0280, 0x1028, 0, "ALC3220" },
876 	{ 0x10ec0282, 0x1028, 0, "ALC3221" },
877 	{ 0x10ec0283, 0x1028, 0, "ALC3223" },
878 	{ 0x10ec0288, 0x1028, 0, "ALC3263" },
879 	{ 0x10ec0292, 0x1028, 0, "ALC3226" },
880 	{ 0x10ec0293, 0x1028, 0, "ALC3235" },
881 	{ 0x10ec0255, 0x1028, 0, "ALC3234" },
882 	{ 0x10ec0668, 0x1028, 0, "ALC3661" },
883 	{ 0x10ec0275, 0x1028, 0, "ALC3260" },
884 	{ 0x10ec0899, 0x1028, 0, "ALC3861" },
885 	{ 0x10ec0670, 0x1025, 0, "ALC669X" },
886 	{ 0x10ec0676, 0x1025, 0, "ALC679X" },
887 	{ 0x10ec0282, 0x1043, 0, "ALC3229" },
888 	{ 0x10ec0233, 0x1043, 0, "ALC3236" },
889 	{ 0x10ec0280, 0x103c, 0, "ALC3228" },
890 	{ 0x10ec0282, 0x103c, 0, "ALC3227" },
891 	{ 0x10ec0286, 0x103c, 0, "ALC3242" },
892 	{ 0x10ec0290, 0x103c, 0, "ALC3241" },
893 	{ 0x10ec0668, 0x103c, 0, "ALC3662" },
894 	{ 0x10ec0283, 0x17aa, 0, "ALC3239" },
895 	{ 0x10ec0292, 0x17aa, 0, "ALC3232" },
896 	{ } /* terminator */
897 };
898 
899 static int alc_codec_rename_from_preset(struct hda_codec *codec)
900 {
901 	const struct alc_codec_rename_table *p;
902 	const struct alc_codec_rename_pci_table *q;
903 
904 	for (p = rename_tbl; p->vendor_id; p++) {
905 		if (p->vendor_id != codec->vendor_id)
906 			continue;
907 		if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
908 			return alc_codec_rename(codec, p->name);
909 	}
910 
911 	if (!codec->bus->pci)
912 		return 0;
913 	for (q = rename_pci_tbl; q->codec_vendor_id; q++) {
914 		if (q->codec_vendor_id != codec->vendor_id)
915 			continue;
916 		if (q->pci_subvendor != codec->bus->pci->subsystem_vendor)
917 			continue;
918 		if (!q->pci_subdevice ||
919 		    q->pci_subdevice == codec->bus->pci->subsystem_device)
920 			return alc_codec_rename(codec, q->name);
921 	}
922 
923 	return 0;
924 }
925 
926 
927 /*
928  * Digital-beep handlers
929  */
930 #ifdef CONFIG_SND_HDA_INPUT_BEEP
931 #define set_beep_amp(spec, nid, idx, dir) \
932 	((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
933 
934 static const struct snd_pci_quirk beep_white_list[] = {
935 	SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
936 	SND_PCI_QUIRK(0x1043, 0x115d, "ASUS", 1),
937 	SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
938 	SND_PCI_QUIRK(0x1043, 0x8376, "EeePC", 1),
939 	SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
940 	SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
941 	SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
942 	SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
943 	SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
944 	{}
945 };
946 
947 static inline int has_cdefine_beep(struct hda_codec *codec)
948 {
949 	struct alc_spec *spec = codec->spec;
950 	const struct snd_pci_quirk *q;
951 	q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
952 	if (q)
953 		return q->value;
954 	return spec->cdefine.enable_pcbeep;
955 }
956 #else
957 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
958 #define has_cdefine_beep(codec)		0
959 #endif
960 
961 /* parse the BIOS configuration and set up the alc_spec */
962 /* return 1 if successful, 0 if the proper config is not found,
963  * or a negative error code
964  */
965 static int alc_parse_auto_config(struct hda_codec *codec,
966 				 const hda_nid_t *ignore_nids,
967 				 const hda_nid_t *ssid_nids)
968 {
969 	struct alc_spec *spec = codec->spec;
970 	struct auto_pin_cfg *cfg = &spec->gen.autocfg;
971 	int err;
972 
973 	err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
974 				       spec->parse_flags);
975 	if (err < 0)
976 		return err;
977 
978 	if (ssid_nids)
979 		alc_ssid_check(codec, ssid_nids);
980 
981 	err = snd_hda_gen_parse_auto_config(codec, cfg);
982 	if (err < 0)
983 		return err;
984 
985 	return 1;
986 }
987 
988 /* common preparation job for alc_spec */
989 static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
990 {
991 	struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
992 	int err;
993 
994 	if (!spec)
995 		return -ENOMEM;
996 	codec->spec = spec;
997 	snd_hda_gen_spec_init(&spec->gen);
998 	spec->gen.mixer_nid = mixer_nid;
999 	spec->gen.own_eapd_ctl = 1;
1000 	codec->single_adc_amp = 1;
1001 	/* FIXME: do we need this for all Realtek codec models? */
1002 	codec->spdif_status_reset = 1;
1003 
1004 	err = alc_codec_rename_from_preset(codec);
1005 	if (err < 0) {
1006 		kfree(spec);
1007 		return err;
1008 	}
1009 	return 0;
1010 }
1011 
1012 static int alc880_parse_auto_config(struct hda_codec *codec)
1013 {
1014 	static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
1015 	static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
1016 	return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
1017 }
1018 
1019 /*
1020  * ALC880 fix-ups
1021  */
1022 enum {
1023 	ALC880_FIXUP_GPIO1,
1024 	ALC880_FIXUP_GPIO2,
1025 	ALC880_FIXUP_MEDION_RIM,
1026 	ALC880_FIXUP_LG,
1027 	ALC880_FIXUP_LG_LW25,
1028 	ALC880_FIXUP_W810,
1029 	ALC880_FIXUP_EAPD_COEF,
1030 	ALC880_FIXUP_TCL_S700,
1031 	ALC880_FIXUP_VOL_KNOB,
1032 	ALC880_FIXUP_FUJITSU,
1033 	ALC880_FIXUP_F1734,
1034 	ALC880_FIXUP_UNIWILL,
1035 	ALC880_FIXUP_UNIWILL_DIG,
1036 	ALC880_FIXUP_Z71V,
1037 	ALC880_FIXUP_ASUS_W5A,
1038 	ALC880_FIXUP_3ST_BASE,
1039 	ALC880_FIXUP_3ST,
1040 	ALC880_FIXUP_3ST_DIG,
1041 	ALC880_FIXUP_5ST_BASE,
1042 	ALC880_FIXUP_5ST,
1043 	ALC880_FIXUP_5ST_DIG,
1044 	ALC880_FIXUP_6ST_BASE,
1045 	ALC880_FIXUP_6ST,
1046 	ALC880_FIXUP_6ST_DIG,
1047 	ALC880_FIXUP_6ST_AUTOMUTE,
1048 };
1049 
1050 /* enable the volume-knob widget support on NID 0x21 */
1051 static void alc880_fixup_vol_knob(struct hda_codec *codec,
1052 				  const struct hda_fixup *fix, int action)
1053 {
1054 	if (action == HDA_FIXUP_ACT_PROBE)
1055 		snd_hda_jack_detect_enable_callback(codec, 0x21,
1056 						    alc_update_knob_master);
1057 }
1058 
1059 static const struct hda_fixup alc880_fixups[] = {
1060 	[ALC880_FIXUP_GPIO1] = {
1061 		.type = HDA_FIXUP_VERBS,
1062 		.v.verbs = alc_gpio1_init_verbs,
1063 	},
1064 	[ALC880_FIXUP_GPIO2] = {
1065 		.type = HDA_FIXUP_VERBS,
1066 		.v.verbs = alc_gpio2_init_verbs,
1067 	},
1068 	[ALC880_FIXUP_MEDION_RIM] = {
1069 		.type = HDA_FIXUP_VERBS,
1070 		.v.verbs = (const struct hda_verb[]) {
1071 			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1072 			{ 0x20, AC_VERB_SET_PROC_COEF,  0x3060 },
1073 			{ }
1074 		},
1075 		.chained = true,
1076 		.chain_id = ALC880_FIXUP_GPIO2,
1077 	},
1078 	[ALC880_FIXUP_LG] = {
1079 		.type = HDA_FIXUP_PINS,
1080 		.v.pins = (const struct hda_pintbl[]) {
1081 			/* disable bogus unused pins */
1082 			{ 0x16, 0x411111f0 },
1083 			{ 0x18, 0x411111f0 },
1084 			{ 0x1a, 0x411111f0 },
1085 			{ }
1086 		}
1087 	},
1088 	[ALC880_FIXUP_LG_LW25] = {
1089 		.type = HDA_FIXUP_PINS,
1090 		.v.pins = (const struct hda_pintbl[]) {
1091 			{ 0x1a, 0x0181344f }, /* line-in */
1092 			{ 0x1b, 0x0321403f }, /* headphone */
1093 			{ }
1094 		}
1095 	},
1096 	[ALC880_FIXUP_W810] = {
1097 		.type = HDA_FIXUP_PINS,
1098 		.v.pins = (const struct hda_pintbl[]) {
1099 			/* disable bogus unused pins */
1100 			{ 0x17, 0x411111f0 },
1101 			{ }
1102 		},
1103 		.chained = true,
1104 		.chain_id = ALC880_FIXUP_GPIO2,
1105 	},
1106 	[ALC880_FIXUP_EAPD_COEF] = {
1107 		.type = HDA_FIXUP_VERBS,
1108 		.v.verbs = (const struct hda_verb[]) {
1109 			/* change to EAPD mode */
1110 			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1111 			{ 0x20, AC_VERB_SET_PROC_COEF,  0x3060 },
1112 			{}
1113 		},
1114 	},
1115 	[ALC880_FIXUP_TCL_S700] = {
1116 		.type = HDA_FIXUP_VERBS,
1117 		.v.verbs = (const struct hda_verb[]) {
1118 			/* change to EAPD mode */
1119 			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1120 			{ 0x20, AC_VERB_SET_PROC_COEF,  0x3070 },
1121 			{}
1122 		},
1123 		.chained = true,
1124 		.chain_id = ALC880_FIXUP_GPIO2,
1125 	},
1126 	[ALC880_FIXUP_VOL_KNOB] = {
1127 		.type = HDA_FIXUP_FUNC,
1128 		.v.func = alc880_fixup_vol_knob,
1129 	},
1130 	[ALC880_FIXUP_FUJITSU] = {
1131 		/* override all pins as BIOS on old Amilo is broken */
1132 		.type = HDA_FIXUP_PINS,
1133 		.v.pins = (const struct hda_pintbl[]) {
1134 			{ 0x14, 0x0121411f }, /* HP */
1135 			{ 0x15, 0x99030120 }, /* speaker */
1136 			{ 0x16, 0x99030130 }, /* bass speaker */
1137 			{ 0x17, 0x411111f0 }, /* N/A */
1138 			{ 0x18, 0x411111f0 }, /* N/A */
1139 			{ 0x19, 0x01a19950 }, /* mic-in */
1140 			{ 0x1a, 0x411111f0 }, /* N/A */
1141 			{ 0x1b, 0x411111f0 }, /* N/A */
1142 			{ 0x1c, 0x411111f0 }, /* N/A */
1143 			{ 0x1d, 0x411111f0 }, /* N/A */
1144 			{ 0x1e, 0x01454140 }, /* SPDIF out */
1145 			{ }
1146 		},
1147 		.chained = true,
1148 		.chain_id = ALC880_FIXUP_VOL_KNOB,
1149 	},
1150 	[ALC880_FIXUP_F1734] = {
1151 		/* almost compatible with FUJITSU, but no bass and SPDIF */
1152 		.type = HDA_FIXUP_PINS,
1153 		.v.pins = (const struct hda_pintbl[]) {
1154 			{ 0x14, 0x0121411f }, /* HP */
1155 			{ 0x15, 0x99030120 }, /* speaker */
1156 			{ 0x16, 0x411111f0 }, /* N/A */
1157 			{ 0x17, 0x411111f0 }, /* N/A */
1158 			{ 0x18, 0x411111f0 }, /* N/A */
1159 			{ 0x19, 0x01a19950 }, /* mic-in */
1160 			{ 0x1a, 0x411111f0 }, /* N/A */
1161 			{ 0x1b, 0x411111f0 }, /* N/A */
1162 			{ 0x1c, 0x411111f0 }, /* N/A */
1163 			{ 0x1d, 0x411111f0 }, /* N/A */
1164 			{ 0x1e, 0x411111f0 }, /* N/A */
1165 			{ }
1166 		},
1167 		.chained = true,
1168 		.chain_id = ALC880_FIXUP_VOL_KNOB,
1169 	},
1170 	[ALC880_FIXUP_UNIWILL] = {
1171 		/* need to fix HP and speaker pins to be parsed correctly */
1172 		.type = HDA_FIXUP_PINS,
1173 		.v.pins = (const struct hda_pintbl[]) {
1174 			{ 0x14, 0x0121411f }, /* HP */
1175 			{ 0x15, 0x99030120 }, /* speaker */
1176 			{ 0x16, 0x99030130 }, /* bass speaker */
1177 			{ }
1178 		},
1179 	},
1180 	[ALC880_FIXUP_UNIWILL_DIG] = {
1181 		.type = HDA_FIXUP_PINS,
1182 		.v.pins = (const struct hda_pintbl[]) {
1183 			/* disable bogus unused pins */
1184 			{ 0x17, 0x411111f0 },
1185 			{ 0x19, 0x411111f0 },
1186 			{ 0x1b, 0x411111f0 },
1187 			{ 0x1f, 0x411111f0 },
1188 			{ }
1189 		}
1190 	},
1191 	[ALC880_FIXUP_Z71V] = {
1192 		.type = HDA_FIXUP_PINS,
1193 		.v.pins = (const struct hda_pintbl[]) {
1194 			/* set up the whole pins as BIOS is utterly broken */
1195 			{ 0x14, 0x99030120 }, /* speaker */
1196 			{ 0x15, 0x0121411f }, /* HP */
1197 			{ 0x16, 0x411111f0 }, /* N/A */
1198 			{ 0x17, 0x411111f0 }, /* N/A */
1199 			{ 0x18, 0x01a19950 }, /* mic-in */
1200 			{ 0x19, 0x411111f0 }, /* N/A */
1201 			{ 0x1a, 0x01813031 }, /* line-in */
1202 			{ 0x1b, 0x411111f0 }, /* N/A */
1203 			{ 0x1c, 0x411111f0 }, /* N/A */
1204 			{ 0x1d, 0x411111f0 }, /* N/A */
1205 			{ 0x1e, 0x0144111e }, /* SPDIF */
1206 			{ }
1207 		}
1208 	},
1209 	[ALC880_FIXUP_ASUS_W5A] = {
1210 		.type = HDA_FIXUP_PINS,
1211 		.v.pins = (const struct hda_pintbl[]) {
1212 			/* set up the whole pins as BIOS is utterly broken */
1213 			{ 0x14, 0x0121411f }, /* HP */
1214 			{ 0x15, 0x411111f0 }, /* N/A */
1215 			{ 0x16, 0x411111f0 }, /* N/A */
1216 			{ 0x17, 0x411111f0 }, /* N/A */
1217 			{ 0x18, 0x90a60160 }, /* mic */
1218 			{ 0x19, 0x411111f0 }, /* N/A */
1219 			{ 0x1a, 0x411111f0 }, /* N/A */
1220 			{ 0x1b, 0x411111f0 }, /* N/A */
1221 			{ 0x1c, 0x411111f0 }, /* N/A */
1222 			{ 0x1d, 0x411111f0 }, /* N/A */
1223 			{ 0x1e, 0xb743111e }, /* SPDIF out */
1224 			{ }
1225 		},
1226 		.chained = true,
1227 		.chain_id = ALC880_FIXUP_GPIO1,
1228 	},
1229 	[ALC880_FIXUP_3ST_BASE] = {
1230 		.type = HDA_FIXUP_PINS,
1231 		.v.pins = (const struct hda_pintbl[]) {
1232 			{ 0x14, 0x01014010 }, /* line-out */
1233 			{ 0x15, 0x411111f0 }, /* N/A */
1234 			{ 0x16, 0x411111f0 }, /* N/A */
1235 			{ 0x17, 0x411111f0 }, /* N/A */
1236 			{ 0x18, 0x01a19c30 }, /* mic-in */
1237 			{ 0x19, 0x0121411f }, /* HP */
1238 			{ 0x1a, 0x01813031 }, /* line-in */
1239 			{ 0x1b, 0x02a19c40 }, /* front-mic */
1240 			{ 0x1c, 0x411111f0 }, /* N/A */
1241 			{ 0x1d, 0x411111f0 }, /* N/A */
1242 			/* 0x1e is filled in below */
1243 			{ 0x1f, 0x411111f0 }, /* N/A */
1244 			{ }
1245 		}
1246 	},
1247 	[ALC880_FIXUP_3ST] = {
1248 		.type = HDA_FIXUP_PINS,
1249 		.v.pins = (const struct hda_pintbl[]) {
1250 			{ 0x1e, 0x411111f0 }, /* N/A */
1251 			{ }
1252 		},
1253 		.chained = true,
1254 		.chain_id = ALC880_FIXUP_3ST_BASE,
1255 	},
1256 	[ALC880_FIXUP_3ST_DIG] = {
1257 		.type = HDA_FIXUP_PINS,
1258 		.v.pins = (const struct hda_pintbl[]) {
1259 			{ 0x1e, 0x0144111e }, /* SPDIF */
1260 			{ }
1261 		},
1262 		.chained = true,
1263 		.chain_id = ALC880_FIXUP_3ST_BASE,
1264 	},
1265 	[ALC880_FIXUP_5ST_BASE] = {
1266 		.type = HDA_FIXUP_PINS,
1267 		.v.pins = (const struct hda_pintbl[]) {
1268 			{ 0x14, 0x01014010 }, /* front */
1269 			{ 0x15, 0x411111f0 }, /* N/A */
1270 			{ 0x16, 0x01011411 }, /* CLFE */
1271 			{ 0x17, 0x01016412 }, /* surr */
1272 			{ 0x18, 0x01a19c30 }, /* mic-in */
1273 			{ 0x19, 0x0121411f }, /* HP */
1274 			{ 0x1a, 0x01813031 }, /* line-in */
1275 			{ 0x1b, 0x02a19c40 }, /* front-mic */
1276 			{ 0x1c, 0x411111f0 }, /* N/A */
1277 			{ 0x1d, 0x411111f0 }, /* N/A */
1278 			/* 0x1e is filled in below */
1279 			{ 0x1f, 0x411111f0 }, /* N/A */
1280 			{ }
1281 		}
1282 	},
1283 	[ALC880_FIXUP_5ST] = {
1284 		.type = HDA_FIXUP_PINS,
1285 		.v.pins = (const struct hda_pintbl[]) {
1286 			{ 0x1e, 0x411111f0 }, /* N/A */
1287 			{ }
1288 		},
1289 		.chained = true,
1290 		.chain_id = ALC880_FIXUP_5ST_BASE,
1291 	},
1292 	[ALC880_FIXUP_5ST_DIG] = {
1293 		.type = HDA_FIXUP_PINS,
1294 		.v.pins = (const struct hda_pintbl[]) {
1295 			{ 0x1e, 0x0144111e }, /* SPDIF */
1296 			{ }
1297 		},
1298 		.chained = true,
1299 		.chain_id = ALC880_FIXUP_5ST_BASE,
1300 	},
1301 	[ALC880_FIXUP_6ST_BASE] = {
1302 		.type = HDA_FIXUP_PINS,
1303 		.v.pins = (const struct hda_pintbl[]) {
1304 			{ 0x14, 0x01014010 }, /* front */
1305 			{ 0x15, 0x01016412 }, /* surr */
1306 			{ 0x16, 0x01011411 }, /* CLFE */
1307 			{ 0x17, 0x01012414 }, /* side */
1308 			{ 0x18, 0x01a19c30 }, /* mic-in */
1309 			{ 0x19, 0x02a19c40 }, /* front-mic */
1310 			{ 0x1a, 0x01813031 }, /* line-in */
1311 			{ 0x1b, 0x0121411f }, /* HP */
1312 			{ 0x1c, 0x411111f0 }, /* N/A */
1313 			{ 0x1d, 0x411111f0 }, /* N/A */
1314 			/* 0x1e is filled in below */
1315 			{ 0x1f, 0x411111f0 }, /* N/A */
1316 			{ }
1317 		}
1318 	},
1319 	[ALC880_FIXUP_6ST] = {
1320 		.type = HDA_FIXUP_PINS,
1321 		.v.pins = (const struct hda_pintbl[]) {
1322 			{ 0x1e, 0x411111f0 }, /* N/A */
1323 			{ }
1324 		},
1325 		.chained = true,
1326 		.chain_id = ALC880_FIXUP_6ST_BASE,
1327 	},
1328 	[ALC880_FIXUP_6ST_DIG] = {
1329 		.type = HDA_FIXUP_PINS,
1330 		.v.pins = (const struct hda_pintbl[]) {
1331 			{ 0x1e, 0x0144111e }, /* SPDIF */
1332 			{ }
1333 		},
1334 		.chained = true,
1335 		.chain_id = ALC880_FIXUP_6ST_BASE,
1336 	},
1337 	[ALC880_FIXUP_6ST_AUTOMUTE] = {
1338 		.type = HDA_FIXUP_PINS,
1339 		.v.pins = (const struct hda_pintbl[]) {
1340 			{ 0x1b, 0x0121401f }, /* HP with jack detect */
1341 			{ }
1342 		},
1343 		.chained_before = true,
1344 		.chain_id = ALC880_FIXUP_6ST_BASE,
1345 	},
1346 };
1347 
1348 static const struct snd_pci_quirk alc880_fixup_tbl[] = {
1349 	SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
1350 	SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS W5A", ALC880_FIXUP_ASUS_W5A),
1351 	SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
1352 	SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
1353 	SND_PCI_QUIRK(0x147b, 0x1045, "ABit AA8XE", ALC880_FIXUP_6ST_AUTOMUTE),
1354 	SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
1355 	SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
1356 	SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
1357 	SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
1358 	SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
1359 	SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
1360 	SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
1361 	SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
1362 	SND_PCI_QUIRK(0x1631, 0xe011, "PB 13201056", ALC880_FIXUP_6ST_AUTOMUTE),
1363 	SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
1364 	SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
1365 	SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
1366 	SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
1367 	SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
1368 	SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
1369 	SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
1370 	SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_FIXUP_LG_LW25),
1371 	SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
1372 
1373 	/* Below is the copied entries from alc880_quirks.c.
1374 	 * It's not quite sure whether BIOS sets the correct pin-config table
1375 	 * on these machines, thus they are kept to be compatible with
1376 	 * the old static quirks.  Once when it's confirmed to work without
1377 	 * these overrides, it'd be better to remove.
1378 	 */
1379 	SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
1380 	SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
1381 	SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
1382 	SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
1383 	SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
1384 	SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
1385 	SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
1386 	SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
1387 	SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
1388 	SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
1389 	SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
1390 	SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
1391 	SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
1392 	SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
1393 	SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
1394 	SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
1395 	SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
1396 	SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
1397 	SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
1398 	SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
1399 	SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
1400 	SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
1401 	SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
1402 	SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1403 	SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1404 	SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1405 	SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
1406 	SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1407 	SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
1408 	SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
1409 	SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1410 	SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1411 	SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1412 	/* default Intel */
1413 	SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
1414 	SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
1415 	SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
1416 	{}
1417 };
1418 
1419 static const struct hda_model_fixup alc880_fixup_models[] = {
1420 	{.id = ALC880_FIXUP_3ST, .name = "3stack"},
1421 	{.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
1422 	{.id = ALC880_FIXUP_5ST, .name = "5stack"},
1423 	{.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
1424 	{.id = ALC880_FIXUP_6ST, .name = "6stack"},
1425 	{.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
1426 	{.id = ALC880_FIXUP_6ST_AUTOMUTE, .name = "6stack-automute"},
1427 	{}
1428 };
1429 
1430 
1431 /*
1432  * OK, here we have finally the patch for ALC880
1433  */
1434 static int patch_alc880(struct hda_codec *codec)
1435 {
1436 	struct alc_spec *spec;
1437 	int err;
1438 
1439 	err = alc_alloc_spec(codec, 0x0b);
1440 	if (err < 0)
1441 		return err;
1442 
1443 	spec = codec->spec;
1444 	spec->gen.need_dac_fix = 1;
1445 	spec->gen.beep_nid = 0x01;
1446 
1447 	snd_hda_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
1448 		       alc880_fixups);
1449 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1450 
1451 	/* automatic parse from the BIOS config */
1452 	err = alc880_parse_auto_config(codec);
1453 	if (err < 0)
1454 		goto error;
1455 
1456 	if (!spec->gen.no_analog)
1457 		set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
1458 
1459 	codec->patch_ops = alc_patch_ops;
1460 	codec->patch_ops.unsol_event = alc880_unsol_event;
1461 
1462 
1463 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1464 
1465 	return 0;
1466 
1467  error:
1468 	alc_free(codec);
1469 	return err;
1470 }
1471 
1472 
1473 /*
1474  * ALC260 support
1475  */
1476 static int alc260_parse_auto_config(struct hda_codec *codec)
1477 {
1478 	static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
1479 	static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
1480 	return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
1481 }
1482 
1483 /*
1484  * Pin config fixes
1485  */
1486 enum {
1487 	ALC260_FIXUP_HP_DC5750,
1488 	ALC260_FIXUP_HP_PIN_0F,
1489 	ALC260_FIXUP_COEF,
1490 	ALC260_FIXUP_GPIO1,
1491 	ALC260_FIXUP_GPIO1_TOGGLE,
1492 	ALC260_FIXUP_REPLACER,
1493 	ALC260_FIXUP_HP_B1900,
1494 	ALC260_FIXUP_KN1,
1495 	ALC260_FIXUP_FSC_S7020,
1496 	ALC260_FIXUP_FSC_S7020_JWSE,
1497 	ALC260_FIXUP_VAIO_PINS,
1498 };
1499 
1500 static void alc260_gpio1_automute(struct hda_codec *codec)
1501 {
1502 	struct alc_spec *spec = codec->spec;
1503 	snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
1504 			    spec->gen.hp_jack_present);
1505 }
1506 
1507 static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
1508 				      const struct hda_fixup *fix, int action)
1509 {
1510 	struct alc_spec *spec = codec->spec;
1511 	if (action == HDA_FIXUP_ACT_PROBE) {
1512 		/* although the machine has only one output pin, we need to
1513 		 * toggle GPIO1 according to the jack state
1514 		 */
1515 		spec->gen.automute_hook = alc260_gpio1_automute;
1516 		spec->gen.detect_hp = 1;
1517 		spec->gen.automute_speaker = 1;
1518 		spec->gen.autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
1519 		snd_hda_jack_detect_enable_callback(codec, 0x0f,
1520 						    snd_hda_gen_hp_automute);
1521 		snd_hda_add_verbs(codec, alc_gpio1_init_verbs);
1522 	}
1523 }
1524 
1525 static void alc260_fixup_kn1(struct hda_codec *codec,
1526 			     const struct hda_fixup *fix, int action)
1527 {
1528 	struct alc_spec *spec = codec->spec;
1529 	static const struct hda_pintbl pincfgs[] = {
1530 		{ 0x0f, 0x02214000 }, /* HP/speaker */
1531 		{ 0x12, 0x90a60160 }, /* int mic */
1532 		{ 0x13, 0x02a19000 }, /* ext mic */
1533 		{ 0x18, 0x01446000 }, /* SPDIF out */
1534 		/* disable bogus I/O pins */
1535 		{ 0x10, 0x411111f0 },
1536 		{ 0x11, 0x411111f0 },
1537 		{ 0x14, 0x411111f0 },
1538 		{ 0x15, 0x411111f0 },
1539 		{ 0x16, 0x411111f0 },
1540 		{ 0x17, 0x411111f0 },
1541 		{ 0x19, 0x411111f0 },
1542 		{ }
1543 	};
1544 
1545 	switch (action) {
1546 	case HDA_FIXUP_ACT_PRE_PROBE:
1547 		snd_hda_apply_pincfgs(codec, pincfgs);
1548 		break;
1549 	case HDA_FIXUP_ACT_PROBE:
1550 		spec->init_amp = ALC_INIT_NONE;
1551 		break;
1552 	}
1553 }
1554 
1555 static void alc260_fixup_fsc_s7020(struct hda_codec *codec,
1556 				   const struct hda_fixup *fix, int action)
1557 {
1558 	struct alc_spec *spec = codec->spec;
1559 	if (action == HDA_FIXUP_ACT_PROBE)
1560 		spec->init_amp = ALC_INIT_NONE;
1561 }
1562 
1563 static void alc260_fixup_fsc_s7020_jwse(struct hda_codec *codec,
1564 				   const struct hda_fixup *fix, int action)
1565 {
1566 	struct alc_spec *spec = codec->spec;
1567 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1568 		spec->gen.add_jack_modes = 1;
1569 		spec->gen.hp_mic = 1;
1570 	}
1571 }
1572 
1573 static const struct hda_fixup alc260_fixups[] = {
1574 	[ALC260_FIXUP_HP_DC5750] = {
1575 		.type = HDA_FIXUP_PINS,
1576 		.v.pins = (const struct hda_pintbl[]) {
1577 			{ 0x11, 0x90130110 }, /* speaker */
1578 			{ }
1579 		}
1580 	},
1581 	[ALC260_FIXUP_HP_PIN_0F] = {
1582 		.type = HDA_FIXUP_PINS,
1583 		.v.pins = (const struct hda_pintbl[]) {
1584 			{ 0x0f, 0x01214000 }, /* HP */
1585 			{ }
1586 		}
1587 	},
1588 	[ALC260_FIXUP_COEF] = {
1589 		.type = HDA_FIXUP_VERBS,
1590 		.v.verbs = (const struct hda_verb[]) {
1591 			{ 0x1a, AC_VERB_SET_COEF_INDEX, 0x07 },
1592 			{ 0x1a, AC_VERB_SET_PROC_COEF,  0x3040 },
1593 			{ }
1594 		},
1595 	},
1596 	[ALC260_FIXUP_GPIO1] = {
1597 		.type = HDA_FIXUP_VERBS,
1598 		.v.verbs = alc_gpio1_init_verbs,
1599 	},
1600 	[ALC260_FIXUP_GPIO1_TOGGLE] = {
1601 		.type = HDA_FIXUP_FUNC,
1602 		.v.func = alc260_fixup_gpio1_toggle,
1603 		.chained = true,
1604 		.chain_id = ALC260_FIXUP_HP_PIN_0F,
1605 	},
1606 	[ALC260_FIXUP_REPLACER] = {
1607 		.type = HDA_FIXUP_VERBS,
1608 		.v.verbs = (const struct hda_verb[]) {
1609 			{ 0x1a, AC_VERB_SET_COEF_INDEX, 0x07 },
1610 			{ 0x1a, AC_VERB_SET_PROC_COEF,  0x3050 },
1611 			{ }
1612 		},
1613 		.chained = true,
1614 		.chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
1615 	},
1616 	[ALC260_FIXUP_HP_B1900] = {
1617 		.type = HDA_FIXUP_FUNC,
1618 		.v.func = alc260_fixup_gpio1_toggle,
1619 		.chained = true,
1620 		.chain_id = ALC260_FIXUP_COEF,
1621 	},
1622 	[ALC260_FIXUP_KN1] = {
1623 		.type = HDA_FIXUP_FUNC,
1624 		.v.func = alc260_fixup_kn1,
1625 	},
1626 	[ALC260_FIXUP_FSC_S7020] = {
1627 		.type = HDA_FIXUP_FUNC,
1628 		.v.func = alc260_fixup_fsc_s7020,
1629 	},
1630 	[ALC260_FIXUP_FSC_S7020_JWSE] = {
1631 		.type = HDA_FIXUP_FUNC,
1632 		.v.func = alc260_fixup_fsc_s7020_jwse,
1633 		.chained = true,
1634 		.chain_id = ALC260_FIXUP_FSC_S7020,
1635 	},
1636 	[ALC260_FIXUP_VAIO_PINS] = {
1637 		.type = HDA_FIXUP_PINS,
1638 		.v.pins = (const struct hda_pintbl[]) {
1639 			/* Pin configs are missing completely on some VAIOs */
1640 			{ 0x0f, 0x01211020 },
1641 			{ 0x10, 0x0001003f },
1642 			{ 0x11, 0x411111f0 },
1643 			{ 0x12, 0x01a15930 },
1644 			{ 0x13, 0x411111f0 },
1645 			{ 0x14, 0x411111f0 },
1646 			{ 0x15, 0x411111f0 },
1647 			{ 0x16, 0x411111f0 },
1648 			{ 0x17, 0x411111f0 },
1649 			{ 0x18, 0x411111f0 },
1650 			{ 0x19, 0x411111f0 },
1651 			{ }
1652 		}
1653 	},
1654 };
1655 
1656 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
1657 	SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
1658 	SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
1659 	SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
1660 	SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
1661 	SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
1662 	SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_FIXUP_VAIO_PINS),
1663 	SND_PCI_QUIRK(0x104d, 0x81e2, "Sony VAIO TX", ALC260_FIXUP_HP_PIN_0F),
1664 	SND_PCI_QUIRK(0x10cf, 0x1326, "FSC LifeBook S7020", ALC260_FIXUP_FSC_S7020),
1665 	SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
1666 	SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
1667 	SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
1668 	SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
1669 	{}
1670 };
1671 
1672 static const struct hda_model_fixup alc260_fixup_models[] = {
1673 	{.id = ALC260_FIXUP_GPIO1, .name = "gpio1"},
1674 	{.id = ALC260_FIXUP_COEF, .name = "coef"},
1675 	{.id = ALC260_FIXUP_FSC_S7020, .name = "fujitsu"},
1676 	{.id = ALC260_FIXUP_FSC_S7020_JWSE, .name = "fujitsu-jwse"},
1677 	{}
1678 };
1679 
1680 /*
1681  */
1682 static int patch_alc260(struct hda_codec *codec)
1683 {
1684 	struct alc_spec *spec;
1685 	int err;
1686 
1687 	err = alc_alloc_spec(codec, 0x07);
1688 	if (err < 0)
1689 		return err;
1690 
1691 	spec = codec->spec;
1692 	/* as quite a few machines require HP amp for speaker outputs,
1693 	 * it's easier to enable it unconditionally; even if it's unneeded,
1694 	 * it's almost harmless.
1695 	 */
1696 	spec->gen.prefer_hp_amp = 1;
1697 	spec->gen.beep_nid = 0x01;
1698 
1699 	snd_hda_pick_fixup(codec, alc260_fixup_models, alc260_fixup_tbl,
1700 			   alc260_fixups);
1701 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1702 
1703 	/* automatic parse from the BIOS config */
1704 	err = alc260_parse_auto_config(codec);
1705 	if (err < 0)
1706 		goto error;
1707 
1708 	if (!spec->gen.no_analog)
1709 		set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
1710 
1711 	codec->patch_ops = alc_patch_ops;
1712 	spec->shutup = alc_eapd_shutup;
1713 
1714 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1715 
1716 	return 0;
1717 
1718  error:
1719 	alc_free(codec);
1720 	return err;
1721 }
1722 
1723 
1724 /*
1725  * ALC882/883/885/888/889 support
1726  *
1727  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
1728  * configuration.  Each pin widget can choose any input DACs and a mixer.
1729  * Each ADC is connected from a mixer of all inputs.  This makes possible
1730  * 6-channel independent captures.
1731  *
1732  * In addition, an independent DAC for the multi-playback (not used in this
1733  * driver yet).
1734  */
1735 
1736 /*
1737  * Pin config fixes
1738  */
1739 enum {
1740 	ALC882_FIXUP_ABIT_AW9D_MAX,
1741 	ALC882_FIXUP_LENOVO_Y530,
1742 	ALC882_FIXUP_PB_M5210,
1743 	ALC882_FIXUP_ACER_ASPIRE_7736,
1744 	ALC882_FIXUP_ASUS_W90V,
1745 	ALC889_FIXUP_CD,
1746 	ALC889_FIXUP_FRONT_HP_NO_PRESENCE,
1747 	ALC889_FIXUP_VAIO_TT,
1748 	ALC888_FIXUP_EEE1601,
1749 	ALC882_FIXUP_EAPD,
1750 	ALC883_FIXUP_EAPD,
1751 	ALC883_FIXUP_ACER_EAPD,
1752 	ALC882_FIXUP_GPIO1,
1753 	ALC882_FIXUP_GPIO2,
1754 	ALC882_FIXUP_GPIO3,
1755 	ALC889_FIXUP_COEF,
1756 	ALC882_FIXUP_ASUS_W2JC,
1757 	ALC882_FIXUP_ACER_ASPIRE_4930G,
1758 	ALC882_FIXUP_ACER_ASPIRE_8930G,
1759 	ALC882_FIXUP_ASPIRE_8930G_VERBS,
1760 	ALC885_FIXUP_MACPRO_GPIO,
1761 	ALC889_FIXUP_DAC_ROUTE,
1762 	ALC889_FIXUP_MBP_VREF,
1763 	ALC889_FIXUP_IMAC91_VREF,
1764 	ALC889_FIXUP_MBA11_VREF,
1765 	ALC889_FIXUP_MBA21_VREF,
1766 	ALC889_FIXUP_MP11_VREF,
1767 	ALC882_FIXUP_INV_DMIC,
1768 	ALC882_FIXUP_NO_PRIMARY_HP,
1769 	ALC887_FIXUP_ASUS_BASS,
1770 	ALC887_FIXUP_BASS_CHMAP,
1771 };
1772 
1773 static void alc889_fixup_coef(struct hda_codec *codec,
1774 			      const struct hda_fixup *fix, int action)
1775 {
1776 	if (action != HDA_FIXUP_ACT_INIT)
1777 		return;
1778 	alc_update_coef_idx(codec, 7, 0, 0x2030);
1779 }
1780 
1781 /* toggle speaker-output according to the hp-jack state */
1782 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
1783 {
1784 	unsigned int gpiostate, gpiomask, gpiodir;
1785 
1786 	gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1787 				       AC_VERB_GET_GPIO_DATA, 0);
1788 
1789 	if (!muted)
1790 		gpiostate |= (1 << pin);
1791 	else
1792 		gpiostate &= ~(1 << pin);
1793 
1794 	gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1795 				      AC_VERB_GET_GPIO_MASK, 0);
1796 	gpiomask |= (1 << pin);
1797 
1798 	gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1799 				     AC_VERB_GET_GPIO_DIRECTION, 0);
1800 	gpiodir |= (1 << pin);
1801 
1802 
1803 	snd_hda_codec_write(codec, codec->afg, 0,
1804 			    AC_VERB_SET_GPIO_MASK, gpiomask);
1805 	snd_hda_codec_write(codec, codec->afg, 0,
1806 			    AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1807 
1808 	msleep(1);
1809 
1810 	snd_hda_codec_write(codec, codec->afg, 0,
1811 			    AC_VERB_SET_GPIO_DATA, gpiostate);
1812 }
1813 
1814 /* set up GPIO at initialization */
1815 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
1816 				     const struct hda_fixup *fix, int action)
1817 {
1818 	if (action != HDA_FIXUP_ACT_INIT)
1819 		return;
1820 	alc882_gpio_mute(codec, 0, 0);
1821 	alc882_gpio_mute(codec, 1, 0);
1822 }
1823 
1824 /* Fix the connection of some pins for ALC889:
1825  * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
1826  * work correctly (bko#42740)
1827  */
1828 static void alc889_fixup_dac_route(struct hda_codec *codec,
1829 				   const struct hda_fixup *fix, int action)
1830 {
1831 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1832 		/* fake the connections during parsing the tree */
1833 		hda_nid_t conn1[2] = { 0x0c, 0x0d };
1834 		hda_nid_t conn2[2] = { 0x0e, 0x0f };
1835 		snd_hda_override_conn_list(codec, 0x14, 2, conn1);
1836 		snd_hda_override_conn_list(codec, 0x15, 2, conn1);
1837 		snd_hda_override_conn_list(codec, 0x18, 2, conn2);
1838 		snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
1839 	} else if (action == HDA_FIXUP_ACT_PROBE) {
1840 		/* restore the connections */
1841 		hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
1842 		snd_hda_override_conn_list(codec, 0x14, 5, conn);
1843 		snd_hda_override_conn_list(codec, 0x15, 5, conn);
1844 		snd_hda_override_conn_list(codec, 0x18, 5, conn);
1845 		snd_hda_override_conn_list(codec, 0x1a, 5, conn);
1846 	}
1847 }
1848 
1849 /* Set VREF on HP pin */
1850 static void alc889_fixup_mbp_vref(struct hda_codec *codec,
1851 				  const struct hda_fixup *fix, int action)
1852 {
1853 	struct alc_spec *spec = codec->spec;
1854 	static hda_nid_t nids[2] = { 0x14, 0x15 };
1855 	int i;
1856 
1857 	if (action != HDA_FIXUP_ACT_INIT)
1858 		return;
1859 	for (i = 0; i < ARRAY_SIZE(nids); i++) {
1860 		unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
1861 		if (get_defcfg_device(val) != AC_JACK_HP_OUT)
1862 			continue;
1863 		val = snd_hda_codec_get_pin_target(codec, nids[i]);
1864 		val |= AC_PINCTL_VREF_80;
1865 		snd_hda_set_pin_ctl(codec, nids[i], val);
1866 		spec->gen.keep_vref_in_automute = 1;
1867 		break;
1868 	}
1869 }
1870 
1871 static void alc889_fixup_mac_pins(struct hda_codec *codec,
1872 				  const hda_nid_t *nids, int num_nids)
1873 {
1874 	struct alc_spec *spec = codec->spec;
1875 	int i;
1876 
1877 	for (i = 0; i < num_nids; i++) {
1878 		unsigned int val;
1879 		val = snd_hda_codec_get_pin_target(codec, nids[i]);
1880 		val |= AC_PINCTL_VREF_50;
1881 		snd_hda_set_pin_ctl(codec, nids[i], val);
1882 	}
1883 	spec->gen.keep_vref_in_automute = 1;
1884 }
1885 
1886 /* Set VREF on speaker pins on imac91 */
1887 static void alc889_fixup_imac91_vref(struct hda_codec *codec,
1888 				     const struct hda_fixup *fix, int action)
1889 {
1890 	static hda_nid_t nids[2] = { 0x18, 0x1a };
1891 
1892 	if (action == HDA_FIXUP_ACT_INIT)
1893 		alc889_fixup_mac_pins(codec, nids, ARRAY_SIZE(nids));
1894 }
1895 
1896 /* Set VREF on speaker pins on mba11 */
1897 static void alc889_fixup_mba11_vref(struct hda_codec *codec,
1898 				    const struct hda_fixup *fix, int action)
1899 {
1900 	static hda_nid_t nids[1] = { 0x18 };
1901 
1902 	if (action == HDA_FIXUP_ACT_INIT)
1903 		alc889_fixup_mac_pins(codec, nids, ARRAY_SIZE(nids));
1904 }
1905 
1906 /* Set VREF on speaker pins on mba21 */
1907 static void alc889_fixup_mba21_vref(struct hda_codec *codec,
1908 				    const struct hda_fixup *fix, int action)
1909 {
1910 	static hda_nid_t nids[2] = { 0x18, 0x19 };
1911 
1912 	if (action == HDA_FIXUP_ACT_INIT)
1913 		alc889_fixup_mac_pins(codec, nids, ARRAY_SIZE(nids));
1914 }
1915 
1916 /* Don't take HP output as primary
1917  * Strangely, the speaker output doesn't work on Vaio Z and some Vaio
1918  * all-in-one desktop PCs (for example VGC-LN51JGB) through DAC 0x05
1919  */
1920 static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
1921 				       const struct hda_fixup *fix, int action)
1922 {
1923 	struct alc_spec *spec = codec->spec;
1924 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1925 		spec->gen.no_primary_hp = 1;
1926 		spec->gen.no_multi_io = 1;
1927 	}
1928 }
1929 
1930 static void alc_fixup_bass_chmap(struct hda_codec *codec,
1931 				 const struct hda_fixup *fix, int action);
1932 
1933 static const struct hda_fixup alc882_fixups[] = {
1934 	[ALC882_FIXUP_ABIT_AW9D_MAX] = {
1935 		.type = HDA_FIXUP_PINS,
1936 		.v.pins = (const struct hda_pintbl[]) {
1937 			{ 0x15, 0x01080104 }, /* side */
1938 			{ 0x16, 0x01011012 }, /* rear */
1939 			{ 0x17, 0x01016011 }, /* clfe */
1940 			{ }
1941 		}
1942 	},
1943 	[ALC882_FIXUP_LENOVO_Y530] = {
1944 		.type = HDA_FIXUP_PINS,
1945 		.v.pins = (const struct hda_pintbl[]) {
1946 			{ 0x15, 0x99130112 }, /* rear int speakers */
1947 			{ 0x16, 0x99130111 }, /* subwoofer */
1948 			{ }
1949 		}
1950 	},
1951 	[ALC882_FIXUP_PB_M5210] = {
1952 		.type = HDA_FIXUP_PINCTLS,
1953 		.v.pins = (const struct hda_pintbl[]) {
1954 			{ 0x19, PIN_VREF50 },
1955 			{}
1956 		}
1957 	},
1958 	[ALC882_FIXUP_ACER_ASPIRE_7736] = {
1959 		.type = HDA_FIXUP_FUNC,
1960 		.v.func = alc_fixup_sku_ignore,
1961 	},
1962 	[ALC882_FIXUP_ASUS_W90V] = {
1963 		.type = HDA_FIXUP_PINS,
1964 		.v.pins = (const struct hda_pintbl[]) {
1965 			{ 0x16, 0x99130110 }, /* fix sequence for CLFE */
1966 			{ }
1967 		}
1968 	},
1969 	[ALC889_FIXUP_CD] = {
1970 		.type = HDA_FIXUP_PINS,
1971 		.v.pins = (const struct hda_pintbl[]) {
1972 			{ 0x1c, 0x993301f0 }, /* CD */
1973 			{ }
1974 		}
1975 	},
1976 	[ALC889_FIXUP_FRONT_HP_NO_PRESENCE] = {
1977 		.type = HDA_FIXUP_PINS,
1978 		.v.pins = (const struct hda_pintbl[]) {
1979 			{ 0x1b, 0x02214120 }, /* Front HP jack is flaky, disable jack detect */
1980 			{ }
1981 		},
1982 		.chained = true,
1983 		.chain_id = ALC889_FIXUP_CD,
1984 	},
1985 	[ALC889_FIXUP_VAIO_TT] = {
1986 		.type = HDA_FIXUP_PINS,
1987 		.v.pins = (const struct hda_pintbl[]) {
1988 			{ 0x17, 0x90170111 }, /* hidden surround speaker */
1989 			{ }
1990 		}
1991 	},
1992 	[ALC888_FIXUP_EEE1601] = {
1993 		.type = HDA_FIXUP_VERBS,
1994 		.v.verbs = (const struct hda_verb[]) {
1995 			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
1996 			{ 0x20, AC_VERB_SET_PROC_COEF,  0x0838 },
1997 			{ }
1998 		}
1999 	},
2000 	[ALC882_FIXUP_EAPD] = {
2001 		.type = HDA_FIXUP_VERBS,
2002 		.v.verbs = (const struct hda_verb[]) {
2003 			/* change to EAPD mode */
2004 			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2005 			{ 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
2006 			{ }
2007 		}
2008 	},
2009 	[ALC883_FIXUP_EAPD] = {
2010 		.type = HDA_FIXUP_VERBS,
2011 		.v.verbs = (const struct hda_verb[]) {
2012 			/* change to EAPD mode */
2013 			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2014 			{ 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
2015 			{ }
2016 		}
2017 	},
2018 	[ALC883_FIXUP_ACER_EAPD] = {
2019 		.type = HDA_FIXUP_VERBS,
2020 		.v.verbs = (const struct hda_verb[]) {
2021 			/* eanable EAPD on Acer laptops */
2022 			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2023 			{ 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2024 			{ }
2025 		}
2026 	},
2027 	[ALC882_FIXUP_GPIO1] = {
2028 		.type = HDA_FIXUP_VERBS,
2029 		.v.verbs = alc_gpio1_init_verbs,
2030 	},
2031 	[ALC882_FIXUP_GPIO2] = {
2032 		.type = HDA_FIXUP_VERBS,
2033 		.v.verbs = alc_gpio2_init_verbs,
2034 	},
2035 	[ALC882_FIXUP_GPIO3] = {
2036 		.type = HDA_FIXUP_VERBS,
2037 		.v.verbs = alc_gpio3_init_verbs,
2038 	},
2039 	[ALC882_FIXUP_ASUS_W2JC] = {
2040 		.type = HDA_FIXUP_VERBS,
2041 		.v.verbs = alc_gpio1_init_verbs,
2042 		.chained = true,
2043 		.chain_id = ALC882_FIXUP_EAPD,
2044 	},
2045 	[ALC889_FIXUP_COEF] = {
2046 		.type = HDA_FIXUP_FUNC,
2047 		.v.func = alc889_fixup_coef,
2048 	},
2049 	[ALC882_FIXUP_ACER_ASPIRE_4930G] = {
2050 		.type = HDA_FIXUP_PINS,
2051 		.v.pins = (const struct hda_pintbl[]) {
2052 			{ 0x16, 0x99130111 }, /* CLFE speaker */
2053 			{ 0x17, 0x99130112 }, /* surround speaker */
2054 			{ }
2055 		},
2056 		.chained = true,
2057 		.chain_id = ALC882_FIXUP_GPIO1,
2058 	},
2059 	[ALC882_FIXUP_ACER_ASPIRE_8930G] = {
2060 		.type = HDA_FIXUP_PINS,
2061 		.v.pins = (const struct hda_pintbl[]) {
2062 			{ 0x16, 0x99130111 }, /* CLFE speaker */
2063 			{ 0x1b, 0x99130112 }, /* surround speaker */
2064 			{ }
2065 		},
2066 		.chained = true,
2067 		.chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
2068 	},
2069 	[ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
2070 		/* additional init verbs for Acer Aspire 8930G */
2071 		.type = HDA_FIXUP_VERBS,
2072 		.v.verbs = (const struct hda_verb[]) {
2073 			/* Enable all DACs */
2074 			/* DAC DISABLE/MUTE 1? */
2075 			/*  setting bits 1-5 disables DAC nids 0x02-0x06
2076 			 *  apparently. Init=0x38 */
2077 			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
2078 			{ 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
2079 			/* DAC DISABLE/MUTE 2? */
2080 			/*  some bit here disables the other DACs.
2081 			 *  Init=0x4900 */
2082 			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
2083 			{ 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
2084 			/* DMIC fix
2085 			 * This laptop has a stereo digital microphone.
2086 			 * The mics are only 1cm apart which makes the stereo
2087 			 * useless. However, either the mic or the ALC889
2088 			 * makes the signal become a difference/sum signal
2089 			 * instead of standard stereo, which is annoying.
2090 			 * So instead we flip this bit which makes the
2091 			 * codec replicate the sum signal to both channels,
2092 			 * turning it into a normal mono mic.
2093 			 */
2094 			/* DMIC_CONTROL? Init value = 0x0001 */
2095 			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
2096 			{ 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
2097 			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2098 			{ 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2099 			{ }
2100 		},
2101 		.chained = true,
2102 		.chain_id = ALC882_FIXUP_GPIO1,
2103 	},
2104 	[ALC885_FIXUP_MACPRO_GPIO] = {
2105 		.type = HDA_FIXUP_FUNC,
2106 		.v.func = alc885_fixup_macpro_gpio,
2107 	},
2108 	[ALC889_FIXUP_DAC_ROUTE] = {
2109 		.type = HDA_FIXUP_FUNC,
2110 		.v.func = alc889_fixup_dac_route,
2111 	},
2112 	[ALC889_FIXUP_MBP_VREF] = {
2113 		.type = HDA_FIXUP_FUNC,
2114 		.v.func = alc889_fixup_mbp_vref,
2115 		.chained = true,
2116 		.chain_id = ALC882_FIXUP_GPIO1,
2117 	},
2118 	[ALC889_FIXUP_IMAC91_VREF] = {
2119 		.type = HDA_FIXUP_FUNC,
2120 		.v.func = alc889_fixup_imac91_vref,
2121 		.chained = true,
2122 		.chain_id = ALC882_FIXUP_GPIO1,
2123 	},
2124 	[ALC889_FIXUP_MBA11_VREF] = {
2125 		.type = HDA_FIXUP_FUNC,
2126 		.v.func = alc889_fixup_mba11_vref,
2127 		.chained = true,
2128 		.chain_id = ALC889_FIXUP_MBP_VREF,
2129 	},
2130 	[ALC889_FIXUP_MBA21_VREF] = {
2131 		.type = HDA_FIXUP_FUNC,
2132 		.v.func = alc889_fixup_mba21_vref,
2133 		.chained = true,
2134 		.chain_id = ALC889_FIXUP_MBP_VREF,
2135 	},
2136 	[ALC889_FIXUP_MP11_VREF] = {
2137 		.type = HDA_FIXUP_FUNC,
2138 		.v.func = alc889_fixup_mba11_vref,
2139 		.chained = true,
2140 		.chain_id = ALC885_FIXUP_MACPRO_GPIO,
2141 	},
2142 	[ALC882_FIXUP_INV_DMIC] = {
2143 		.type = HDA_FIXUP_FUNC,
2144 		.v.func = alc_fixup_inv_dmic,
2145 	},
2146 	[ALC882_FIXUP_NO_PRIMARY_HP] = {
2147 		.type = HDA_FIXUP_FUNC,
2148 		.v.func = alc882_fixup_no_primary_hp,
2149 	},
2150 	[ALC887_FIXUP_ASUS_BASS] = {
2151 		.type = HDA_FIXUP_PINS,
2152 		.v.pins = (const struct hda_pintbl[]) {
2153 			{0x16, 0x99130130}, /* bass speaker */
2154 			{}
2155 		},
2156 		.chained = true,
2157 		.chain_id = ALC887_FIXUP_BASS_CHMAP,
2158 	},
2159 	[ALC887_FIXUP_BASS_CHMAP] = {
2160 		.type = HDA_FIXUP_FUNC,
2161 		.v.func = alc_fixup_bass_chmap,
2162 	},
2163 };
2164 
2165 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
2166 	SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
2167 	SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
2168 	SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
2169 	SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
2170 	SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
2171 	SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
2172 	SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
2173 		      ALC882_FIXUP_ACER_ASPIRE_4930G),
2174 	SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
2175 		      ALC882_FIXUP_ACER_ASPIRE_4930G),
2176 	SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
2177 		      ALC882_FIXUP_ACER_ASPIRE_8930G),
2178 	SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
2179 		      ALC882_FIXUP_ACER_ASPIRE_8930G),
2180 	SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
2181 		      ALC882_FIXUP_ACER_ASPIRE_4930G),
2182 	SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
2183 		      ALC882_FIXUP_ACER_ASPIRE_4930G),
2184 	SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
2185 		      ALC882_FIXUP_ACER_ASPIRE_4930G),
2186 	SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
2187 	SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
2188 		      ALC882_FIXUP_ACER_ASPIRE_4930G),
2189 	SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
2190 	SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
2191 	SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
2192 	SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
2193 	SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
2194 	SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
2195 	SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
2196 	SND_PCI_QUIRK(0x1043, 0x84bc, "ASUS ET2700", ALC887_FIXUP_ASUS_BASS),
2197 	SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
2198 	SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
2199 	SND_PCI_QUIRK(0x104d, 0x9043, "Sony Vaio VGC-LN51JGB", ALC882_FIXUP_NO_PRIMARY_HP),
2200 
2201 	/* All Apple entries are in codec SSIDs */
2202 	SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
2203 	SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
2204 	SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
2205 	SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC889_FIXUP_MP11_VREF),
2206 	SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
2207 	SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
2208 	SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
2209 	SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
2210 	SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
2211 	SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBA11_VREF),
2212 	SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBA21_VREF),
2213 	SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
2214 	SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
2215 	SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
2216 	SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
2217 	SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
2218 	SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
2219 	SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
2220 	SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
2221 	SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
2222 	SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
2223 	SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
2224 
2225 	SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
2226 	SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
2227 	SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
2228 	SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3/Z87X-UD3H", ALC889_FIXUP_FRONT_HP_NO_PRESENCE),
2229 	SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
2230 	SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
2231 	SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
2232 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
2233 	SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
2234 	{}
2235 };
2236 
2237 static const struct hda_model_fixup alc882_fixup_models[] = {
2238 	{.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
2239 	{.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
2240 	{.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
2241 	{.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
2242 	{.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
2243 	{}
2244 };
2245 
2246 /*
2247  * BIOS auto configuration
2248  */
2249 /* almost identical with ALC880 parser... */
2250 static int alc882_parse_auto_config(struct hda_codec *codec)
2251 {
2252 	static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
2253 	static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2254 	return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
2255 }
2256 
2257 /*
2258  */
2259 static int patch_alc882(struct hda_codec *codec)
2260 {
2261 	struct alc_spec *spec;
2262 	int err;
2263 
2264 	err = alc_alloc_spec(codec, 0x0b);
2265 	if (err < 0)
2266 		return err;
2267 
2268 	spec = codec->spec;
2269 
2270 	switch (codec->vendor_id) {
2271 	case 0x10ec0882:
2272 	case 0x10ec0885:
2273 	case 0x10ec0900:
2274 		break;
2275 	default:
2276 		/* ALC883 and variants */
2277 		alc_fix_pll_init(codec, 0x20, 0x0a, 10);
2278 		break;
2279 	}
2280 
2281 	snd_hda_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
2282 		       alc882_fixups);
2283 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2284 
2285 	alc_auto_parse_customize_define(codec);
2286 
2287 	if (has_cdefine_beep(codec))
2288 		spec->gen.beep_nid = 0x01;
2289 
2290 	/* automatic parse from the BIOS config */
2291 	err = alc882_parse_auto_config(codec);
2292 	if (err < 0)
2293 		goto error;
2294 
2295 	if (!spec->gen.no_analog && spec->gen.beep_nid)
2296 		set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
2297 
2298 	codec->patch_ops = alc_patch_ops;
2299 
2300 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2301 
2302 	return 0;
2303 
2304  error:
2305 	alc_free(codec);
2306 	return err;
2307 }
2308 
2309 
2310 /*
2311  * ALC262 support
2312  */
2313 static int alc262_parse_auto_config(struct hda_codec *codec)
2314 {
2315 	static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
2316 	static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2317 	return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
2318 }
2319 
2320 /*
2321  * Pin config fixes
2322  */
2323 enum {
2324 	ALC262_FIXUP_FSC_H270,
2325 	ALC262_FIXUP_FSC_S7110,
2326 	ALC262_FIXUP_HP_Z200,
2327 	ALC262_FIXUP_TYAN,
2328 	ALC262_FIXUP_LENOVO_3000,
2329 	ALC262_FIXUP_BENQ,
2330 	ALC262_FIXUP_BENQ_T31,
2331 	ALC262_FIXUP_INV_DMIC,
2332 	ALC262_FIXUP_INTEL_BAYLEYBAY,
2333 };
2334 
2335 static const struct hda_fixup alc262_fixups[] = {
2336 	[ALC262_FIXUP_FSC_H270] = {
2337 		.type = HDA_FIXUP_PINS,
2338 		.v.pins = (const struct hda_pintbl[]) {
2339 			{ 0x14, 0x99130110 }, /* speaker */
2340 			{ 0x15, 0x0221142f }, /* front HP */
2341 			{ 0x1b, 0x0121141f }, /* rear HP */
2342 			{ }
2343 		}
2344 	},
2345 	[ALC262_FIXUP_FSC_S7110] = {
2346 		.type = HDA_FIXUP_PINS,
2347 		.v.pins = (const struct hda_pintbl[]) {
2348 			{ 0x15, 0x90170110 }, /* speaker */
2349 			{ }
2350 		},
2351 		.chained = true,
2352 		.chain_id = ALC262_FIXUP_BENQ,
2353 	},
2354 	[ALC262_FIXUP_HP_Z200] = {
2355 		.type = HDA_FIXUP_PINS,
2356 		.v.pins = (const struct hda_pintbl[]) {
2357 			{ 0x16, 0x99130120 }, /* internal speaker */
2358 			{ }
2359 		}
2360 	},
2361 	[ALC262_FIXUP_TYAN] = {
2362 		.type = HDA_FIXUP_PINS,
2363 		.v.pins = (const struct hda_pintbl[]) {
2364 			{ 0x14, 0x1993e1f0 }, /* int AUX */
2365 			{ }
2366 		}
2367 	},
2368 	[ALC262_FIXUP_LENOVO_3000] = {
2369 		.type = HDA_FIXUP_PINCTLS,
2370 		.v.pins = (const struct hda_pintbl[]) {
2371 			{ 0x19, PIN_VREF50 },
2372 			{}
2373 		},
2374 		.chained = true,
2375 		.chain_id = ALC262_FIXUP_BENQ,
2376 	},
2377 	[ALC262_FIXUP_BENQ] = {
2378 		.type = HDA_FIXUP_VERBS,
2379 		.v.verbs = (const struct hda_verb[]) {
2380 			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2381 			{ 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
2382 			{}
2383 		}
2384 	},
2385 	[ALC262_FIXUP_BENQ_T31] = {
2386 		.type = HDA_FIXUP_VERBS,
2387 		.v.verbs = (const struct hda_verb[]) {
2388 			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2389 			{ 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2390 			{}
2391 		}
2392 	},
2393 	[ALC262_FIXUP_INV_DMIC] = {
2394 		.type = HDA_FIXUP_FUNC,
2395 		.v.func = alc_fixup_inv_dmic,
2396 	},
2397 	[ALC262_FIXUP_INTEL_BAYLEYBAY] = {
2398 		.type = HDA_FIXUP_FUNC,
2399 		.v.func = alc_fixup_no_depop_delay,
2400 	},
2401 };
2402 
2403 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
2404 	SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
2405 	SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu Lifebook S7110", ALC262_FIXUP_FSC_S7110),
2406 	SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
2407 	SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
2408 	SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
2409 	SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
2410 	SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
2411 	SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
2412 	SND_PCI_QUIRK(0x8086, 0x7270, "BayleyBay", ALC262_FIXUP_INTEL_BAYLEYBAY),
2413 	{}
2414 };
2415 
2416 static const struct hda_model_fixup alc262_fixup_models[] = {
2417 	{.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
2418 	{}
2419 };
2420 
2421 /*
2422  */
2423 static int patch_alc262(struct hda_codec *codec)
2424 {
2425 	struct alc_spec *spec;
2426 	int err;
2427 
2428 	err = alc_alloc_spec(codec, 0x0b);
2429 	if (err < 0)
2430 		return err;
2431 
2432 	spec = codec->spec;
2433 	spec->gen.shared_mic_vref_pin = 0x18;
2434 
2435 #if 0
2436 	/* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
2437 	 * under-run
2438 	 */
2439 	alc_update_coefex_idx(codec, 0x1a, 7, 0, 0x80);
2440 #endif
2441 	alc_fix_pll_init(codec, 0x20, 0x0a, 10);
2442 
2443 	snd_hda_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
2444 		       alc262_fixups);
2445 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2446 
2447 	alc_auto_parse_customize_define(codec);
2448 
2449 	if (has_cdefine_beep(codec))
2450 		spec->gen.beep_nid = 0x01;
2451 
2452 	/* automatic parse from the BIOS config */
2453 	err = alc262_parse_auto_config(codec);
2454 	if (err < 0)
2455 		goto error;
2456 
2457 	if (!spec->gen.no_analog && spec->gen.beep_nid)
2458 		set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
2459 
2460 	codec->patch_ops = alc_patch_ops;
2461 	spec->shutup = alc_eapd_shutup;
2462 
2463 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2464 
2465 	return 0;
2466 
2467  error:
2468 	alc_free(codec);
2469 	return err;
2470 }
2471 
2472 /*
2473  *  ALC268
2474  */
2475 /* bind Beep switches of both NID 0x0f and 0x10 */
2476 static const struct hda_bind_ctls alc268_bind_beep_sw = {
2477 	.ops = &snd_hda_bind_sw,
2478 	.values = {
2479 		HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
2480 		HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
2481 		0
2482 	},
2483 };
2484 
2485 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
2486 	HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
2487 	HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
2488 	{ }
2489 };
2490 
2491 /* set PCBEEP vol = 0, mute connections */
2492 static const struct hda_verb alc268_beep_init_verbs[] = {
2493 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2494 	{0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2495 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2496 	{ }
2497 };
2498 
2499 enum {
2500 	ALC268_FIXUP_INV_DMIC,
2501 	ALC268_FIXUP_HP_EAPD,
2502 	ALC268_FIXUP_SPDIF,
2503 };
2504 
2505 static const struct hda_fixup alc268_fixups[] = {
2506 	[ALC268_FIXUP_INV_DMIC] = {
2507 		.type = HDA_FIXUP_FUNC,
2508 		.v.func = alc_fixup_inv_dmic,
2509 	},
2510 	[ALC268_FIXUP_HP_EAPD] = {
2511 		.type = HDA_FIXUP_VERBS,
2512 		.v.verbs = (const struct hda_verb[]) {
2513 			{0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
2514 			{}
2515 		}
2516 	},
2517 	[ALC268_FIXUP_SPDIF] = {
2518 		.type = HDA_FIXUP_PINS,
2519 		.v.pins = (const struct hda_pintbl[]) {
2520 			{ 0x1e, 0x014b1180 }, /* enable SPDIF out */
2521 			{}
2522 		}
2523 	},
2524 };
2525 
2526 static const struct hda_model_fixup alc268_fixup_models[] = {
2527 	{.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
2528 	{.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
2529 	{}
2530 };
2531 
2532 static const struct snd_pci_quirk alc268_fixup_tbl[] = {
2533 	SND_PCI_QUIRK(0x1025, 0x0139, "Acer TravelMate 6293", ALC268_FIXUP_SPDIF),
2534 	SND_PCI_QUIRK(0x1025, 0x015b, "Acer AOA 150 (ZG5)", ALC268_FIXUP_INV_DMIC),
2535 	/* below is codec SSID since multiple Toshiba laptops have the
2536 	 * same PCI SSID 1179:ff00
2537 	 */
2538 	SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
2539 	{}
2540 };
2541 
2542 /*
2543  * BIOS auto configuration
2544  */
2545 static int alc268_parse_auto_config(struct hda_codec *codec)
2546 {
2547 	static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2548 	return alc_parse_auto_config(codec, NULL, alc268_ssids);
2549 }
2550 
2551 /*
2552  */
2553 static int patch_alc268(struct hda_codec *codec)
2554 {
2555 	struct alc_spec *spec;
2556 	int err;
2557 
2558 	/* ALC268 has no aa-loopback mixer */
2559 	err = alc_alloc_spec(codec, 0);
2560 	if (err < 0)
2561 		return err;
2562 
2563 	spec = codec->spec;
2564 	spec->gen.beep_nid = 0x01;
2565 
2566 	snd_hda_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
2567 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2568 
2569 	/* automatic parse from the BIOS config */
2570 	err = alc268_parse_auto_config(codec);
2571 	if (err < 0)
2572 		goto error;
2573 
2574 	if (err > 0 && !spec->gen.no_analog &&
2575 	    spec->gen.autocfg.speaker_pins[0] != 0x1d) {
2576 		add_mixer(spec, alc268_beep_mixer);
2577 		snd_hda_add_verbs(codec, alc268_beep_init_verbs);
2578 		if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
2579 			/* override the amp caps for beep generator */
2580 			snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
2581 					  (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
2582 					  (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
2583 					  (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2584 					  (0 << AC_AMPCAP_MUTE_SHIFT));
2585 	}
2586 
2587 	codec->patch_ops = alc_patch_ops;
2588 	spec->shutup = alc_eapd_shutup;
2589 
2590 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2591 
2592 	return 0;
2593 
2594  error:
2595 	alc_free(codec);
2596 	return err;
2597 }
2598 
2599 /*
2600  * ALC269
2601  */
2602 
2603 static int playback_pcm_open(struct hda_pcm_stream *hinfo,
2604 			     struct hda_codec *codec,
2605 			     struct snd_pcm_substream *substream)
2606 {
2607 	struct hda_gen_spec *spec = codec->spec;
2608 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2609 					     hinfo);
2610 }
2611 
2612 static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2613 				struct hda_codec *codec,
2614 				unsigned int stream_tag,
2615 				unsigned int format,
2616 				struct snd_pcm_substream *substream)
2617 {
2618 	struct hda_gen_spec *spec = codec->spec;
2619 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2620 						stream_tag, format, substream);
2621 }
2622 
2623 static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2624 				struct hda_codec *codec,
2625 				struct snd_pcm_substream *substream)
2626 {
2627 	struct hda_gen_spec *spec = codec->spec;
2628 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2629 }
2630 
2631 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
2632 	.substreams = 1,
2633 	.channels_min = 2,
2634 	.channels_max = 8,
2635 	.rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2636 	/* NID is set in alc_build_pcms */
2637 	.ops = {
2638 		.open = playback_pcm_open,
2639 		.prepare = playback_pcm_prepare,
2640 		.cleanup = playback_pcm_cleanup
2641 	},
2642 };
2643 
2644 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
2645 	.substreams = 1,
2646 	.channels_min = 2,
2647 	.channels_max = 2,
2648 	.rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2649 	/* NID is set in alc_build_pcms */
2650 };
2651 
2652 /* different alc269-variants */
2653 enum {
2654 	ALC269_TYPE_ALC269VA,
2655 	ALC269_TYPE_ALC269VB,
2656 	ALC269_TYPE_ALC269VC,
2657 	ALC269_TYPE_ALC269VD,
2658 	ALC269_TYPE_ALC280,
2659 	ALC269_TYPE_ALC282,
2660 	ALC269_TYPE_ALC283,
2661 	ALC269_TYPE_ALC284,
2662 	ALC269_TYPE_ALC285,
2663 	ALC269_TYPE_ALC286,
2664 	ALC269_TYPE_ALC298,
2665 	ALC269_TYPE_ALC255,
2666 	ALC269_TYPE_ALC256,
2667 };
2668 
2669 /*
2670  * BIOS auto configuration
2671  */
2672 static int alc269_parse_auto_config(struct hda_codec *codec)
2673 {
2674 	static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
2675 	static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
2676 	static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2677 	struct alc_spec *spec = codec->spec;
2678 	const hda_nid_t *ssids;
2679 
2680 	switch (spec->codec_variant) {
2681 	case ALC269_TYPE_ALC269VA:
2682 	case ALC269_TYPE_ALC269VC:
2683 	case ALC269_TYPE_ALC280:
2684 	case ALC269_TYPE_ALC284:
2685 	case ALC269_TYPE_ALC285:
2686 		ssids = alc269va_ssids;
2687 		break;
2688 	case ALC269_TYPE_ALC269VB:
2689 	case ALC269_TYPE_ALC269VD:
2690 	case ALC269_TYPE_ALC282:
2691 	case ALC269_TYPE_ALC283:
2692 	case ALC269_TYPE_ALC286:
2693 	case ALC269_TYPE_ALC298:
2694 	case ALC269_TYPE_ALC255:
2695 	case ALC269_TYPE_ALC256:
2696 		ssids = alc269_ssids;
2697 		break;
2698 	default:
2699 		ssids = alc269_ssids;
2700 		break;
2701 	}
2702 
2703 	return alc_parse_auto_config(codec, alc269_ignore, ssids);
2704 }
2705 
2706 static int find_ext_mic_pin(struct hda_codec *codec);
2707 
2708 static void alc286_shutup(struct hda_codec *codec)
2709 {
2710 	int i;
2711 	int mic_pin = find_ext_mic_pin(codec);
2712 	/* don't shut up pins when unloading the driver; otherwise it breaks
2713 	 * the default pin setup at the next load of the driver
2714 	 */
2715 	if (codec->bus->shutdown)
2716 		return;
2717 	for (i = 0; i < codec->init_pins.used; i++) {
2718 		struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
2719 		/* use read here for syncing after issuing each verb */
2720 		if (pin->nid != mic_pin)
2721 			snd_hda_codec_read(codec, pin->nid, 0,
2722 					AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2723 	}
2724 	codec->pins_shutup = 1;
2725 }
2726 
2727 static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
2728 {
2729 	alc_update_coef_idx(codec, 0x04, 1 << 11, power_up ? (1 << 11) : 0);
2730 }
2731 
2732 static void alc269_shutup(struct hda_codec *codec)
2733 {
2734 	struct alc_spec *spec = codec->spec;
2735 
2736 	if (spec->codec_variant == ALC269_TYPE_ALC269VB)
2737 		alc269vb_toggle_power_output(codec, 0);
2738 	if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
2739 			(alc_get_coef0(codec) & 0x00ff) == 0x018) {
2740 		msleep(150);
2741 	}
2742 	snd_hda_shutup_pins(codec);
2743 }
2744 
2745 static struct coef_fw alc282_coefs[] = {
2746 	WRITE_COEF(0x03, 0x0002), /* Power Down Control */
2747 	UPDATE_COEF(0x05, 0xff3f, 0x0700), /* FIFO and filter clock */
2748 	WRITE_COEF(0x07, 0x0200), /* DMIC control */
2749 	UPDATE_COEF(0x06, 0x00f0, 0), /* Analog clock */
2750 	UPDATE_COEF(0x08, 0xfffc, 0x0c2c), /* JD */
2751 	WRITE_COEF(0x0a, 0xcccc), /* JD offset1 */
2752 	WRITE_COEF(0x0b, 0xcccc), /* JD offset2 */
2753 	WRITE_COEF(0x0e, 0x6e00), /* LDO1/2/3, DAC/ADC */
2754 	UPDATE_COEF(0x0f, 0xf800, 0x1000), /* JD */
2755 	UPDATE_COEF(0x10, 0xfc00, 0x0c00), /* Capless */
2756 	WRITE_COEF(0x6f, 0x0), /* Class D test 4 */
2757 	UPDATE_COEF(0x0c, 0xfe00, 0), /* IO power down directly */
2758 	WRITE_COEF(0x34, 0xa0c0), /* ANC */
2759 	UPDATE_COEF(0x16, 0x0008, 0), /* AGC MUX */
2760 	UPDATE_COEF(0x1d, 0x00e0, 0), /* DAC simple content protection */
2761 	UPDATE_COEF(0x1f, 0x00e0, 0), /* ADC simple content protection */
2762 	WRITE_COEF(0x21, 0x8804), /* DAC ADC Zero Detection */
2763 	WRITE_COEF(0x63, 0x2902), /* PLL */
2764 	WRITE_COEF(0x68, 0xa080), /* capless control 2 */
2765 	WRITE_COEF(0x69, 0x3400), /* capless control 3 */
2766 	WRITE_COEF(0x6a, 0x2f3e), /* capless control 4 */
2767 	WRITE_COEF(0x6b, 0x0), /* capless control 5 */
2768 	UPDATE_COEF(0x6d, 0x0fff, 0x0900), /* class D test 2 */
2769 	WRITE_COEF(0x6e, 0x110a), /* class D test 3 */
2770 	UPDATE_COEF(0x70, 0x00f8, 0x00d8), /* class D test 5 */
2771 	WRITE_COEF(0x71, 0x0014), /* class D test 6 */
2772 	WRITE_COEF(0x72, 0xc2ba), /* classD OCP */
2773 	UPDATE_COEF(0x77, 0x0f80, 0), /* classD pure DC test */
2774 	WRITE_COEF(0x6c, 0xfc06), /* Class D amp control */
2775 	{}
2776 };
2777 
2778 static void alc282_restore_default_value(struct hda_codec *codec)
2779 {
2780 	alc_process_coef_fw(codec, alc282_coefs);
2781 }
2782 
2783 static void alc282_init(struct hda_codec *codec)
2784 {
2785 	struct alc_spec *spec = codec->spec;
2786 	hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
2787 	bool hp_pin_sense;
2788 	int coef78;
2789 
2790 	alc282_restore_default_value(codec);
2791 
2792 	if (!hp_pin)
2793 		return;
2794 	hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
2795 	coef78 = alc_read_coef_idx(codec, 0x78);
2796 
2797 	/* Index 0x78 Direct Drive HP AMP LPM Control 1 */
2798 	/* Headphone capless set to high power mode */
2799 	alc_write_coef_idx(codec, 0x78, 0x9004);
2800 
2801 	if (hp_pin_sense)
2802 		msleep(2);
2803 
2804 	snd_hda_codec_write(codec, hp_pin, 0,
2805 			    AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
2806 
2807 	if (hp_pin_sense)
2808 		msleep(85);
2809 
2810 	snd_hda_codec_write(codec, hp_pin, 0,
2811 			    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
2812 
2813 	if (hp_pin_sense)
2814 		msleep(100);
2815 
2816 	/* Headphone capless set to normal mode */
2817 	alc_write_coef_idx(codec, 0x78, coef78);
2818 }
2819 
2820 static void alc282_shutup(struct hda_codec *codec)
2821 {
2822 	struct alc_spec *spec = codec->spec;
2823 	hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
2824 	bool hp_pin_sense;
2825 	int coef78;
2826 
2827 	if (!hp_pin) {
2828 		alc269_shutup(codec);
2829 		return;
2830 	}
2831 
2832 	hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
2833 	coef78 = alc_read_coef_idx(codec, 0x78);
2834 	alc_write_coef_idx(codec, 0x78, 0x9004);
2835 
2836 	if (hp_pin_sense)
2837 		msleep(2);
2838 
2839 	snd_hda_codec_write(codec, hp_pin, 0,
2840 			    AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
2841 
2842 	if (hp_pin_sense)
2843 		msleep(85);
2844 
2845 	snd_hda_codec_write(codec, hp_pin, 0,
2846 			    AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0);
2847 
2848 	if (hp_pin_sense)
2849 		msleep(100);
2850 
2851 	alc_auto_setup_eapd(codec, false);
2852 	snd_hda_shutup_pins(codec);
2853 	alc_write_coef_idx(codec, 0x78, coef78);
2854 }
2855 
2856 static struct coef_fw alc283_coefs[] = {
2857 	WRITE_COEF(0x03, 0x0002), /* Power Down Control */
2858 	UPDATE_COEF(0x05, 0xff3f, 0x0700), /* FIFO and filter clock */
2859 	WRITE_COEF(0x07, 0x0200), /* DMIC control */
2860 	UPDATE_COEF(0x06, 0x00f0, 0), /* Analog clock */
2861 	UPDATE_COEF(0x08, 0xfffc, 0x0c2c), /* JD */
2862 	WRITE_COEF(0x0a, 0xcccc), /* JD offset1 */
2863 	WRITE_COEF(0x0b, 0xcccc), /* JD offset2 */
2864 	WRITE_COEF(0x0e, 0x6fc0), /* LDO1/2/3, DAC/ADC */
2865 	UPDATE_COEF(0x0f, 0xf800, 0x1000), /* JD */
2866 	UPDATE_COEF(0x10, 0xfc00, 0x0c00), /* Capless */
2867 	WRITE_COEF(0x3a, 0x0), /* Class D test 4 */
2868 	UPDATE_COEF(0x0c, 0xfe00, 0x0), /* IO power down directly */
2869 	WRITE_COEF(0x22, 0xa0c0), /* ANC */
2870 	UPDATE_COEFEX(0x53, 0x01, 0x000f, 0x0008), /* AGC MUX */
2871 	UPDATE_COEF(0x1d, 0x00e0, 0), /* DAC simple content protection */
2872 	UPDATE_COEF(0x1f, 0x00e0, 0), /* ADC simple content protection */
2873 	WRITE_COEF(0x21, 0x8804), /* DAC ADC Zero Detection */
2874 	WRITE_COEF(0x2e, 0x2902), /* PLL */
2875 	WRITE_COEF(0x33, 0xa080), /* capless control 2 */
2876 	WRITE_COEF(0x34, 0x3400), /* capless control 3 */
2877 	WRITE_COEF(0x35, 0x2f3e), /* capless control 4 */
2878 	WRITE_COEF(0x36, 0x0), /* capless control 5 */
2879 	UPDATE_COEF(0x38, 0x0fff, 0x0900), /* class D test 2 */
2880 	WRITE_COEF(0x39, 0x110a), /* class D test 3 */
2881 	UPDATE_COEF(0x3b, 0x00f8, 0x00d8), /* class D test 5 */
2882 	WRITE_COEF(0x3c, 0x0014), /* class D test 6 */
2883 	WRITE_COEF(0x3d, 0xc2ba), /* classD OCP */
2884 	UPDATE_COEF(0x42, 0x0f80, 0x0), /* classD pure DC test */
2885 	WRITE_COEF(0x49, 0x0), /* test mode */
2886 	UPDATE_COEF(0x40, 0xf800, 0x9800), /* Class D DC enable */
2887 	UPDATE_COEF(0x42, 0xf000, 0x2000), /* DC offset */
2888 	WRITE_COEF(0x37, 0xfc06), /* Class D amp control */
2889 	UPDATE_COEF(0x1b, 0x8000, 0), /* HP JD control */
2890 	{}
2891 };
2892 
2893 static void alc283_restore_default_value(struct hda_codec *codec)
2894 {
2895 	alc_process_coef_fw(codec, alc283_coefs);
2896 }
2897 
2898 static void alc283_init(struct hda_codec *codec)
2899 {
2900 	struct alc_spec *spec = codec->spec;
2901 	hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
2902 	bool hp_pin_sense;
2903 
2904 	if (!spec->gen.autocfg.hp_outs) {
2905 		if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
2906 			hp_pin = spec->gen.autocfg.line_out_pins[0];
2907 	}
2908 
2909 	alc283_restore_default_value(codec);
2910 
2911 	if (!hp_pin)
2912 		return;
2913 	hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
2914 
2915 	/* Index 0x43 Direct Drive HP AMP LPM Control 1 */
2916 	/* Headphone capless set to high power mode */
2917 	alc_write_coef_idx(codec, 0x43, 0x9004);
2918 
2919 	snd_hda_codec_write(codec, hp_pin, 0,
2920 			    AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
2921 
2922 	if (hp_pin_sense)
2923 		msleep(85);
2924 
2925 	snd_hda_codec_write(codec, hp_pin, 0,
2926 			    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
2927 
2928 	if (hp_pin_sense)
2929 		msleep(85);
2930 	/* Index 0x46 Combo jack auto switch control 2 */
2931 	/* 3k pull low control for Headset jack. */
2932 	alc_update_coef_idx(codec, 0x46, 3 << 12, 0);
2933 	/* Headphone capless set to normal mode */
2934 	alc_write_coef_idx(codec, 0x43, 0x9614);
2935 }
2936 
2937 static void alc283_shutup(struct hda_codec *codec)
2938 {
2939 	struct alc_spec *spec = codec->spec;
2940 	hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
2941 	bool hp_pin_sense;
2942 
2943 	if (!spec->gen.autocfg.hp_outs) {
2944 		if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
2945 			hp_pin = spec->gen.autocfg.line_out_pins[0];
2946 	}
2947 
2948 	if (!hp_pin) {
2949 		alc269_shutup(codec);
2950 		return;
2951 	}
2952 
2953 	hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
2954 
2955 	alc_write_coef_idx(codec, 0x43, 0x9004);
2956 
2957 	/*depop hp during suspend*/
2958 	alc_write_coef_idx(codec, 0x06, 0x2100);
2959 
2960 	snd_hda_codec_write(codec, hp_pin, 0,
2961 			    AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
2962 
2963 	if (hp_pin_sense)
2964 		msleep(100);
2965 
2966 	snd_hda_codec_write(codec, hp_pin, 0,
2967 			    AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0);
2968 
2969 	alc_update_coef_idx(codec, 0x46, 0, 3 << 12);
2970 
2971 	if (hp_pin_sense)
2972 		msleep(100);
2973 	alc_auto_setup_eapd(codec, false);
2974 	snd_hda_shutup_pins(codec);
2975 	alc_write_coef_idx(codec, 0x43, 0x9614);
2976 }
2977 
2978 static void alc5505_coef_set(struct hda_codec *codec, unsigned int index_reg,
2979 			     unsigned int val)
2980 {
2981 	snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_COEF_INDEX, index_reg >> 1);
2982 	snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_PROC_COEF, val & 0xffff); /* LSB */
2983 	snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_PROC_COEF, val >> 16); /* MSB */
2984 }
2985 
2986 static int alc5505_coef_get(struct hda_codec *codec, unsigned int index_reg)
2987 {
2988 	unsigned int val;
2989 
2990 	snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_COEF_INDEX, index_reg >> 1);
2991 	val = snd_hda_codec_read(codec, 0x51, 0, AC_VERB_GET_PROC_COEF, 0)
2992 		& 0xffff;
2993 	val |= snd_hda_codec_read(codec, 0x51, 0, AC_VERB_GET_PROC_COEF, 0)
2994 		<< 16;
2995 	return val;
2996 }
2997 
2998 static void alc5505_dsp_halt(struct hda_codec *codec)
2999 {
3000 	unsigned int val;
3001 
3002 	alc5505_coef_set(codec, 0x3000, 0x000c); /* DSP CPU stop */
3003 	alc5505_coef_set(codec, 0x880c, 0x0008); /* DDR enter self refresh */
3004 	alc5505_coef_set(codec, 0x61c0, 0x11110080); /* Clock control for PLL and CPU */
3005 	alc5505_coef_set(codec, 0x6230, 0xfc0d4011); /* Disable Input OP */
3006 	alc5505_coef_set(codec, 0x61b4, 0x040a2b03); /* Stop PLL2 */
3007 	alc5505_coef_set(codec, 0x61b0, 0x00005b17); /* Stop PLL1 */
3008 	alc5505_coef_set(codec, 0x61b8, 0x04133303); /* Stop PLL3 */
3009 	val = alc5505_coef_get(codec, 0x6220);
3010 	alc5505_coef_set(codec, 0x6220, (val | 0x3000)); /* switch Ringbuffer clock to DBUS clock */
3011 }
3012 
3013 static void alc5505_dsp_back_from_halt(struct hda_codec *codec)
3014 {
3015 	alc5505_coef_set(codec, 0x61b8, 0x04133302);
3016 	alc5505_coef_set(codec, 0x61b0, 0x00005b16);
3017 	alc5505_coef_set(codec, 0x61b4, 0x040a2b02);
3018 	alc5505_coef_set(codec, 0x6230, 0xf80d4011);
3019 	alc5505_coef_set(codec, 0x6220, 0x2002010f);
3020 	alc5505_coef_set(codec, 0x880c, 0x00000004);
3021 }
3022 
3023 static void alc5505_dsp_init(struct hda_codec *codec)
3024 {
3025 	unsigned int val;
3026 
3027 	alc5505_dsp_halt(codec);
3028 	alc5505_dsp_back_from_halt(codec);
3029 	alc5505_coef_set(codec, 0x61b0, 0x5b14); /* PLL1 control */
3030 	alc5505_coef_set(codec, 0x61b0, 0x5b16);
3031 	alc5505_coef_set(codec, 0x61b4, 0x04132b00); /* PLL2 control */
3032 	alc5505_coef_set(codec, 0x61b4, 0x04132b02);
3033 	alc5505_coef_set(codec, 0x61b8, 0x041f3300); /* PLL3 control*/
3034 	alc5505_coef_set(codec, 0x61b8, 0x041f3302);
3035 	snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_CODEC_RESET, 0); /* Function reset */
3036 	alc5505_coef_set(codec, 0x61b8, 0x041b3302);
3037 	alc5505_coef_set(codec, 0x61b8, 0x04173302);
3038 	alc5505_coef_set(codec, 0x61b8, 0x04163302);
3039 	alc5505_coef_set(codec, 0x8800, 0x348b328b); /* DRAM control */
3040 	alc5505_coef_set(codec, 0x8808, 0x00020022); /* DRAM control */
3041 	alc5505_coef_set(codec, 0x8818, 0x00000400); /* DRAM control */
3042 
3043 	val = alc5505_coef_get(codec, 0x6200) >> 16; /* Read revision ID */
3044 	if (val <= 3)
3045 		alc5505_coef_set(codec, 0x6220, 0x2002010f); /* I/O PAD Configuration */
3046 	else
3047 		alc5505_coef_set(codec, 0x6220, 0x6002018f);
3048 
3049 	alc5505_coef_set(codec, 0x61ac, 0x055525f0); /**/
3050 	alc5505_coef_set(codec, 0x61c0, 0x12230080); /* Clock control */
3051 	alc5505_coef_set(codec, 0x61b4, 0x040e2b02); /* PLL2 control */
3052 	alc5505_coef_set(codec, 0x61bc, 0x010234f8); /* OSC Control */
3053 	alc5505_coef_set(codec, 0x880c, 0x00000004); /* DRAM Function control */
3054 	alc5505_coef_set(codec, 0x880c, 0x00000003);
3055 	alc5505_coef_set(codec, 0x880c, 0x00000010);
3056 
3057 #ifdef HALT_REALTEK_ALC5505
3058 	alc5505_dsp_halt(codec);
3059 #endif
3060 }
3061 
3062 #ifdef HALT_REALTEK_ALC5505
3063 #define alc5505_dsp_suspend(codec)	/* NOP */
3064 #define alc5505_dsp_resume(codec)	/* NOP */
3065 #else
3066 #define alc5505_dsp_suspend(codec)	alc5505_dsp_halt(codec)
3067 #define alc5505_dsp_resume(codec)	alc5505_dsp_back_from_halt(codec)
3068 #endif
3069 
3070 #ifdef CONFIG_PM
3071 static int alc269_suspend(struct hda_codec *codec)
3072 {
3073 	struct alc_spec *spec = codec->spec;
3074 
3075 	if (spec->has_alc5505_dsp)
3076 		alc5505_dsp_suspend(codec);
3077 	return alc_suspend(codec);
3078 }
3079 
3080 static int alc269_resume(struct hda_codec *codec)
3081 {
3082 	struct alc_spec *spec = codec->spec;
3083 
3084 	if (spec->codec_variant == ALC269_TYPE_ALC269VB)
3085 		alc269vb_toggle_power_output(codec, 0);
3086 	if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
3087 			(alc_get_coef0(codec) & 0x00ff) == 0x018) {
3088 		msleep(150);
3089 	}
3090 
3091 	codec->patch_ops.init(codec);
3092 
3093 	if (spec->codec_variant == ALC269_TYPE_ALC269VB)
3094 		alc269vb_toggle_power_output(codec, 1);
3095 	if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
3096 			(alc_get_coef0(codec) & 0x00ff) == 0x017) {
3097 		msleep(200);
3098 	}
3099 
3100 	snd_hda_codec_resume_amp(codec);
3101 	snd_hda_codec_resume_cache(codec);
3102 	hda_call_check_power_status(codec, 0x01);
3103 
3104 	/* on some machine, the BIOS will clear the codec gpio data when enter
3105 	 * suspend, and won't restore the data after resume, so we restore it
3106 	 * in the driver.
3107 	 */
3108 	if (spec->gpio_led)
3109 		snd_hda_codec_write(codec, codec->afg, 0, AC_VERB_SET_GPIO_DATA,
3110 			    spec->gpio_led);
3111 
3112 	if (spec->has_alc5505_dsp)
3113 		alc5505_dsp_resume(codec);
3114 
3115 	return 0;
3116 }
3117 #endif /* CONFIG_PM */
3118 
3119 static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
3120 						 const struct hda_fixup *fix, int action)
3121 {
3122 	struct alc_spec *spec = codec->spec;
3123 
3124 	if (action == HDA_FIXUP_ACT_PRE_PROBE)
3125 		spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
3126 }
3127 
3128 static void alc269_fixup_hweq(struct hda_codec *codec,
3129 			       const struct hda_fixup *fix, int action)
3130 {
3131 	if (action == HDA_FIXUP_ACT_INIT)
3132 		alc_update_coef_idx(codec, 0x1e, 0, 0x80);
3133 }
3134 
3135 static void alc269_fixup_headset_mic(struct hda_codec *codec,
3136 				       const struct hda_fixup *fix, int action)
3137 {
3138 	struct alc_spec *spec = codec->spec;
3139 
3140 	if (action == HDA_FIXUP_ACT_PRE_PROBE)
3141 		spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
3142 }
3143 
3144 static void alc271_fixup_dmic(struct hda_codec *codec,
3145 			      const struct hda_fixup *fix, int action)
3146 {
3147 	static const struct hda_verb verbs[] = {
3148 		{0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
3149 		{0x20, AC_VERB_SET_PROC_COEF, 0x4000},
3150 		{}
3151 	};
3152 	unsigned int cfg;
3153 
3154 	if (strcmp(codec->chip_name, "ALC271X") &&
3155 	    strcmp(codec->chip_name, "ALC269VB"))
3156 		return;
3157 	cfg = snd_hda_codec_get_pincfg(codec, 0x12);
3158 	if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
3159 		snd_hda_sequence_write(codec, verbs);
3160 }
3161 
3162 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
3163 				 const struct hda_fixup *fix, int action)
3164 {
3165 	struct alc_spec *spec = codec->spec;
3166 
3167 	if (action != HDA_FIXUP_ACT_PROBE)
3168 		return;
3169 
3170 	/* Due to a hardware problem on Lenovo Ideadpad, we need to
3171 	 * fix the sample rate of analog I/O to 44.1kHz
3172 	 */
3173 	spec->gen.stream_analog_playback = &alc269_44k_pcm_analog_playback;
3174 	spec->gen.stream_analog_capture = &alc269_44k_pcm_analog_capture;
3175 }
3176 
3177 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
3178 				     const struct hda_fixup *fix, int action)
3179 {
3180 	/* The digital-mic unit sends PDM (differential signal) instead of
3181 	 * the standard PCM, thus you can't record a valid mono stream as is.
3182 	 * Below is a workaround specific to ALC269 to control the dmic
3183 	 * signal source as mono.
3184 	 */
3185 	if (action == HDA_FIXUP_ACT_INIT)
3186 		alc_update_coef_idx(codec, 0x07, 0, 0x80);
3187 }
3188 
3189 static void alc269_quanta_automute(struct hda_codec *codec)
3190 {
3191 	snd_hda_gen_update_outputs(codec);
3192 
3193 	alc_write_coef_idx(codec, 0x0c, 0x680);
3194 	alc_write_coef_idx(codec, 0x0c, 0x480);
3195 }
3196 
3197 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
3198 				     const struct hda_fixup *fix, int action)
3199 {
3200 	struct alc_spec *spec = codec->spec;
3201 	if (action != HDA_FIXUP_ACT_PROBE)
3202 		return;
3203 	spec->gen.automute_hook = alc269_quanta_automute;
3204 }
3205 
3206 static void alc269_x101_hp_automute_hook(struct hda_codec *codec,
3207 					 struct hda_jack_callback *jack)
3208 {
3209 	struct alc_spec *spec = codec->spec;
3210 	int vref;
3211 	msleep(200);
3212 	snd_hda_gen_hp_automute(codec, jack);
3213 
3214 	vref = spec->gen.hp_jack_present ? PIN_VREF80 : 0;
3215 	msleep(100);
3216 	snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3217 			    vref);
3218 	msleep(500);
3219 	snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3220 			    vref);
3221 }
3222 
3223 static void alc269_fixup_x101_headset_mic(struct hda_codec *codec,
3224 				     const struct hda_fixup *fix, int action)
3225 {
3226 	struct alc_spec *spec = codec->spec;
3227 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3228 		spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
3229 		spec->gen.hp_automute_hook = alc269_x101_hp_automute_hook;
3230 	}
3231 }
3232 
3233 
3234 /* update mute-LED according to the speaker mute state via mic VREF pin */
3235 static void alc269_fixup_mic_mute_hook(void *private_data, int enabled)
3236 {
3237 	struct hda_codec *codec = private_data;
3238 	struct alc_spec *spec = codec->spec;
3239 	unsigned int pinval;
3240 
3241 	if (spec->mute_led_polarity)
3242 		enabled = !enabled;
3243 	pinval = snd_hda_codec_get_pin_target(codec, spec->mute_led_nid);
3244 	pinval &= ~AC_PINCTL_VREFEN;
3245 	pinval |= enabled ? AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80;
3246 	if (spec->mute_led_nid)
3247 		snd_hda_set_pin_ctl_cache(codec, spec->mute_led_nid, pinval);
3248 }
3249 
3250 /* Make sure the led works even in runtime suspend */
3251 static unsigned int led_power_filter(struct hda_codec *codec,
3252 						  hda_nid_t nid,
3253 						  unsigned int power_state)
3254 {
3255 	struct alc_spec *spec = codec->spec;
3256 
3257 	if (power_state != AC_PWRST_D3 || nid == 0 ||
3258 	    (nid != spec->mute_led_nid && nid != spec->cap_mute_led_nid))
3259 		return power_state;
3260 
3261 	/* Set pin ctl again, it might have just been set to 0 */
3262 	snd_hda_set_pin_ctl(codec, nid,
3263 			    snd_hda_codec_get_pin_target(codec, nid));
3264 
3265 	return AC_PWRST_D0;
3266 }
3267 
3268 static void alc269_fixup_hp_mute_led(struct hda_codec *codec,
3269 				     const struct hda_fixup *fix, int action)
3270 {
3271 	struct alc_spec *spec = codec->spec;
3272 	const struct dmi_device *dev = NULL;
3273 
3274 	if (action != HDA_FIXUP_ACT_PRE_PROBE)
3275 		return;
3276 
3277 	while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
3278 		int pol, pin;
3279 		if (sscanf(dev->name, "HP_Mute_LED_%d_%x", &pol, &pin) != 2)
3280 			continue;
3281 		if (pin < 0x0a || pin >= 0x10)
3282 			break;
3283 		spec->mute_led_polarity = pol;
3284 		spec->mute_led_nid = pin - 0x0a + 0x18;
3285 		spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
3286 		spec->gen.vmaster_mute_enum = 1;
3287 		codec->power_filter = led_power_filter;
3288 		codec_dbg(codec,
3289 			  "Detected mute LED for %x:%d\n", spec->mute_led_nid,
3290 			   spec->mute_led_polarity);
3291 		break;
3292 	}
3293 }
3294 
3295 static void alc269_fixup_hp_mute_led_mic1(struct hda_codec *codec,
3296 				const struct hda_fixup *fix, int action)
3297 {
3298 	struct alc_spec *spec = codec->spec;
3299 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3300 		spec->mute_led_polarity = 0;
3301 		spec->mute_led_nid = 0x18;
3302 		spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
3303 		spec->gen.vmaster_mute_enum = 1;
3304 		codec->power_filter = led_power_filter;
3305 	}
3306 }
3307 
3308 static void alc269_fixup_hp_mute_led_mic2(struct hda_codec *codec,
3309 				const struct hda_fixup *fix, int action)
3310 {
3311 	struct alc_spec *spec = codec->spec;
3312 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3313 		spec->mute_led_polarity = 0;
3314 		spec->mute_led_nid = 0x19;
3315 		spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
3316 		spec->gen.vmaster_mute_enum = 1;
3317 		codec->power_filter = led_power_filter;
3318 	}
3319 }
3320 
3321 /* update LED status via GPIO */
3322 static void alc_update_gpio_led(struct hda_codec *codec, unsigned int mask,
3323 				bool enabled)
3324 {
3325 	struct alc_spec *spec = codec->spec;
3326 	unsigned int oldval = spec->gpio_led;
3327 
3328 	if (spec->mute_led_polarity)
3329 		enabled = !enabled;
3330 
3331 	if (enabled)
3332 		spec->gpio_led &= ~mask;
3333 	else
3334 		spec->gpio_led |= mask;
3335 	if (spec->gpio_led != oldval)
3336 		snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3337 				    spec->gpio_led);
3338 }
3339 
3340 /* turn on/off mute LED via GPIO per vmaster hook */
3341 static void alc_fixup_gpio_mute_hook(void *private_data, int enabled)
3342 {
3343 	struct hda_codec *codec = private_data;
3344 	struct alc_spec *spec = codec->spec;
3345 
3346 	alc_update_gpio_led(codec, spec->gpio_mute_led_mask, enabled);
3347 }
3348 
3349 /* turn on/off mic-mute LED via GPIO per capture hook */
3350 static void alc_fixup_gpio_mic_mute_hook(struct hda_codec *codec,
3351 					 struct snd_kcontrol *kcontrol,
3352 					 struct snd_ctl_elem_value *ucontrol)
3353 {
3354 	struct alc_spec *spec = codec->spec;
3355 
3356 	if (ucontrol)
3357 		alc_update_gpio_led(codec, spec->gpio_mic_led_mask,
3358 				    ucontrol->value.integer.value[0] ||
3359 				    ucontrol->value.integer.value[1]);
3360 }
3361 
3362 static void alc269_fixup_hp_gpio_led(struct hda_codec *codec,
3363 				const struct hda_fixup *fix, int action)
3364 {
3365 	struct alc_spec *spec = codec->spec;
3366 	static const struct hda_verb gpio_init[] = {
3367 		{ 0x01, AC_VERB_SET_GPIO_MASK, 0x18 },
3368 		{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x18 },
3369 		{}
3370 	};
3371 
3372 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3373 		spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
3374 		spec->gen.cap_sync_hook = alc_fixup_gpio_mic_mute_hook;
3375 		spec->gpio_led = 0;
3376 		spec->mute_led_polarity = 0;
3377 		spec->gpio_mute_led_mask = 0x08;
3378 		spec->gpio_mic_led_mask = 0x10;
3379 		snd_hda_add_verbs(codec, gpio_init);
3380 	}
3381 }
3382 
3383 static void alc286_fixup_hp_gpio_led(struct hda_codec *codec,
3384 				const struct hda_fixup *fix, int action)
3385 {
3386 	struct alc_spec *spec = codec->spec;
3387 	static const struct hda_verb gpio_init[] = {
3388 		{ 0x01, AC_VERB_SET_GPIO_MASK, 0x22 },
3389 		{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x22 },
3390 		{}
3391 	};
3392 
3393 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3394 		spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
3395 		spec->gen.cap_sync_hook = alc_fixup_gpio_mic_mute_hook;
3396 		spec->gpio_led = 0;
3397 		spec->mute_led_polarity = 0;
3398 		spec->gpio_mute_led_mask = 0x02;
3399 		spec->gpio_mic_led_mask = 0x20;
3400 		snd_hda_add_verbs(codec, gpio_init);
3401 	}
3402 }
3403 
3404 /* turn on/off mic-mute LED per capture hook */
3405 static void alc269_fixup_hp_cap_mic_mute_hook(struct hda_codec *codec,
3406 					       struct snd_kcontrol *kcontrol,
3407 					       struct snd_ctl_elem_value *ucontrol)
3408 {
3409 	struct alc_spec *spec = codec->spec;
3410 	unsigned int pinval, enable, disable;
3411 
3412 	pinval = snd_hda_codec_get_pin_target(codec, spec->cap_mute_led_nid);
3413 	pinval &= ~AC_PINCTL_VREFEN;
3414 	enable  = pinval | AC_PINCTL_VREF_80;
3415 	disable = pinval | AC_PINCTL_VREF_HIZ;
3416 
3417 	if (!ucontrol)
3418 		return;
3419 
3420 	if (ucontrol->value.integer.value[0] ||
3421 	    ucontrol->value.integer.value[1])
3422 		pinval = disable;
3423 	else
3424 		pinval = enable;
3425 
3426 	if (spec->cap_mute_led_nid)
3427 		snd_hda_set_pin_ctl_cache(codec, spec->cap_mute_led_nid, pinval);
3428 }
3429 
3430 static void alc269_fixup_hp_gpio_mic1_led(struct hda_codec *codec,
3431 				const struct hda_fixup *fix, int action)
3432 {
3433 	struct alc_spec *spec = codec->spec;
3434 	static const struct hda_verb gpio_init[] = {
3435 		{ 0x01, AC_VERB_SET_GPIO_MASK, 0x08 },
3436 		{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x08 },
3437 		{}
3438 	};
3439 
3440 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3441 		spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
3442 		spec->gen.cap_sync_hook = alc269_fixup_hp_cap_mic_mute_hook;
3443 		spec->gpio_led = 0;
3444 		spec->mute_led_polarity = 0;
3445 		spec->gpio_mute_led_mask = 0x08;
3446 		spec->cap_mute_led_nid = 0x18;
3447 		snd_hda_add_verbs(codec, gpio_init);
3448 		codec->power_filter = led_power_filter;
3449 	}
3450 }
3451 
3452 static void alc280_fixup_hp_gpio4(struct hda_codec *codec,
3453 				   const struct hda_fixup *fix, int action)
3454 {
3455 	/* Like hp_gpio_mic1_led, but also needs GPIO4 low to enable headphone amp */
3456 	struct alc_spec *spec = codec->spec;
3457 	static const struct hda_verb gpio_init[] = {
3458 		{ 0x01, AC_VERB_SET_GPIO_MASK, 0x18 },
3459 		{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x18 },
3460 		{}
3461 	};
3462 
3463 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3464 		spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
3465 		spec->gen.cap_sync_hook = alc269_fixup_hp_cap_mic_mute_hook;
3466 		spec->gpio_led = 0;
3467 		spec->mute_led_polarity = 0;
3468 		spec->gpio_mute_led_mask = 0x08;
3469 		spec->cap_mute_led_nid = 0x18;
3470 		snd_hda_add_verbs(codec, gpio_init);
3471 		codec->power_filter = led_power_filter;
3472 	}
3473 }
3474 
3475 static void alc269_fixup_hp_line1_mic1_led(struct hda_codec *codec,
3476 				const struct hda_fixup *fix, int action)
3477 {
3478 	struct alc_spec *spec = codec->spec;
3479 
3480 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3481 		spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
3482 		spec->gen.cap_sync_hook = alc269_fixup_hp_cap_mic_mute_hook;
3483 		spec->mute_led_polarity = 0;
3484 		spec->mute_led_nid = 0x1a;
3485 		spec->cap_mute_led_nid = 0x18;
3486 		spec->gen.vmaster_mute_enum = 1;
3487 		codec->power_filter = led_power_filter;
3488 	}
3489 }
3490 
3491 static void alc_headset_mode_unplugged(struct hda_codec *codec)
3492 {
3493 	static struct coef_fw coef0255[] = {
3494 		WRITE_COEF(0x1b, 0x0c0b), /* LDO and MISC control */
3495 		WRITE_COEF(0x45, 0xd089), /* UAJ function set to menual mode */
3496 		UPDATE_COEFEX(0x57, 0x05, 1<<14, 0), /* Direct Drive HP Amp control(Set to verb control)*/
3497 		WRITE_COEF(0x06, 0x6104), /* Set MIC2 Vref gate with HP */
3498 		WRITE_COEFEX(0x57, 0x03, 0x8aa6), /* Direct Drive HP Amp control */
3499 		{}
3500 	};
3501 	static struct coef_fw coef0233[] = {
3502 		WRITE_COEF(0x1b, 0x0c0b),
3503 		WRITE_COEF(0x45, 0xc429),
3504 		UPDATE_COEF(0x35, 0x4000, 0),
3505 		WRITE_COEF(0x06, 0x2104),
3506 		WRITE_COEF(0x1a, 0x0001),
3507 		WRITE_COEF(0x26, 0x0004),
3508 		WRITE_COEF(0x32, 0x42a3),
3509 		{}
3510 	};
3511 	static struct coef_fw coef0292[] = {
3512 		WRITE_COEF(0x76, 0x000e),
3513 		WRITE_COEF(0x6c, 0x2400),
3514 		WRITE_COEF(0x18, 0x7308),
3515 		WRITE_COEF(0x6b, 0xc429),
3516 		{}
3517 	};
3518 	static struct coef_fw coef0293[] = {
3519 		UPDATE_COEF(0x10, 7<<8, 6<<8), /* SET Line1 JD to 0 */
3520 		UPDATE_COEFEX(0x57, 0x05, 1<<15|1<<13, 0x0), /* SET charge pump by verb */
3521 		UPDATE_COEFEX(0x57, 0x03, 1<<10, 1<<10), /* SET EN_OSW to 1 */
3522 		UPDATE_COEF(0x1a, 1<<3, 1<<3), /* Combo JD gating with LINE1-VREFO */
3523 		WRITE_COEF(0x45, 0xc429), /* Set to TRS type */
3524 		UPDATE_COEF(0x4a, 0x000f, 0x000e), /* Combo Jack auto detect */
3525 		{}
3526 	};
3527 	static struct coef_fw coef0668[] = {
3528 		WRITE_COEF(0x15, 0x0d40),
3529 		WRITE_COEF(0xb7, 0x802b),
3530 		{}
3531 	};
3532 
3533 	switch (codec->vendor_id) {
3534 	case 0x10ec0255:
3535 		alc_process_coef_fw(codec, coef0255);
3536 		break;
3537 	case 0x10ec0233:
3538 	case 0x10ec0283:
3539 		alc_process_coef_fw(codec, coef0233);
3540 		break;
3541 	case 0x10ec0292:
3542 		alc_process_coef_fw(codec, coef0292);
3543 		break;
3544 	case 0x10ec0293:
3545 		alc_process_coef_fw(codec, coef0293);
3546 		break;
3547 	case 0x10ec0668:
3548 		alc_process_coef_fw(codec, coef0668);
3549 		break;
3550 	}
3551 	codec_dbg(codec, "Headset jack set to unplugged mode.\n");
3552 }
3553 
3554 
3555 static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
3556 				    hda_nid_t mic_pin)
3557 {
3558 	static struct coef_fw coef0255[] = {
3559 		WRITE_COEFEX(0x57, 0x03, 0x8aa6),
3560 		WRITE_COEF(0x06, 0x6100), /* Set MIC2 Vref gate to normal */
3561 		{}
3562 	};
3563 	static struct coef_fw coef0233[] = {
3564 		UPDATE_COEF(0x35, 0, 1<<14),
3565 		WRITE_COEF(0x06, 0x2100),
3566 		WRITE_COEF(0x1a, 0x0021),
3567 		WRITE_COEF(0x26, 0x008c),
3568 		{}
3569 	};
3570 	static struct coef_fw coef0292[] = {
3571 		WRITE_COEF(0x19, 0xa208),
3572 		WRITE_COEF(0x2e, 0xacf0),
3573 		{}
3574 	};
3575 	static struct coef_fw coef0293[] = {
3576 		UPDATE_COEFEX(0x57, 0x05, 0, 1<<15|1<<13), /* SET charge pump by verb */
3577 		UPDATE_COEFEX(0x57, 0x03, 1<<10, 0), /* SET EN_OSW to 0 */
3578 		UPDATE_COEF(0x1a, 1<<3, 0), /* Combo JD gating without LINE1-VREFO */
3579 		{}
3580 	};
3581 	static struct coef_fw coef0688[] = {
3582 		WRITE_COEF(0xb7, 0x802b),
3583 		WRITE_COEF(0xb5, 0x1040),
3584 		UPDATE_COEF(0xc3, 0, 1<<12),
3585 		{}
3586 	};
3587 
3588 	switch (codec->vendor_id) {
3589 	case 0x10ec0255:
3590 		alc_write_coef_idx(codec, 0x45, 0xc489);
3591 		snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3592 		alc_process_coef_fw(codec, coef0255);
3593 		snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3594 		break;
3595 	case 0x10ec0233:
3596 	case 0x10ec0283:
3597 		alc_write_coef_idx(codec, 0x45, 0xc429);
3598 		snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3599 		alc_process_coef_fw(codec, coef0233);
3600 		snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3601 		break;
3602 	case 0x10ec0292:
3603 		snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3604 		alc_process_coef_fw(codec, coef0292);
3605 		break;
3606 	case 0x10ec0293:
3607 		/* Set to TRS mode */
3608 		alc_write_coef_idx(codec, 0x45, 0xc429);
3609 		snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3610 		alc_process_coef_fw(codec, coef0293);
3611 		snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3612 		break;
3613 	case 0x10ec0668:
3614 		alc_write_coef_idx(codec, 0x11, 0x0001);
3615 		snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3616 		alc_process_coef_fw(codec, coef0688);
3617 		snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3618 		break;
3619 	}
3620 	codec_dbg(codec, "Headset jack set to mic-in mode.\n");
3621 }
3622 
3623 static void alc_headset_mode_default(struct hda_codec *codec)
3624 {
3625 	static struct coef_fw coef0255[] = {
3626 		WRITE_COEF(0x45, 0xc089),
3627 		WRITE_COEF(0x45, 0xc489),
3628 		WRITE_COEFEX(0x57, 0x03, 0x8ea6),
3629 		WRITE_COEF(0x49, 0x0049),
3630 		{}
3631 	};
3632 	static struct coef_fw coef0233[] = {
3633 		WRITE_COEF(0x06, 0x2100),
3634 		WRITE_COEF(0x32, 0x4ea3),
3635 		{}
3636 	};
3637 	static struct coef_fw coef0292[] = {
3638 		WRITE_COEF(0x76, 0x000e),
3639 		WRITE_COEF(0x6c, 0x2400),
3640 		WRITE_COEF(0x6b, 0xc429),
3641 		WRITE_COEF(0x18, 0x7308),
3642 		{}
3643 	};
3644 	static struct coef_fw coef0293[] = {
3645 		UPDATE_COEF(0x4a, 0x000f, 0x000e), /* Combo Jack auto detect */
3646 		WRITE_COEF(0x45, 0xC429), /* Set to TRS type */
3647 		UPDATE_COEF(0x1a, 1<<3, 0), /* Combo JD gating without LINE1-VREFO */
3648 		{}
3649 	};
3650 	static struct coef_fw coef0688[] = {
3651 		WRITE_COEF(0x11, 0x0041),
3652 		WRITE_COEF(0x15, 0x0d40),
3653 		WRITE_COEF(0xb7, 0x802b),
3654 		{}
3655 	};
3656 
3657 	switch (codec->vendor_id) {
3658 	case 0x10ec0255:
3659 		alc_process_coef_fw(codec, coef0255);
3660 		break;
3661 	case 0x10ec0233:
3662 	case 0x10ec0283:
3663 		alc_process_coef_fw(codec, coef0233);
3664 		break;
3665 	case 0x10ec0292:
3666 		alc_process_coef_fw(codec, coef0292);
3667 		break;
3668 	case 0x10ec0293:
3669 		alc_process_coef_fw(codec, coef0293);
3670 		break;
3671 	case 0x10ec0668:
3672 		alc_process_coef_fw(codec, coef0688);
3673 		break;
3674 	}
3675 	codec_dbg(codec, "Headset jack set to headphone (default) mode.\n");
3676 }
3677 
3678 /* Iphone type */
3679 static void alc_headset_mode_ctia(struct hda_codec *codec)
3680 {
3681 	static struct coef_fw coef0255[] = {
3682 		WRITE_COEF(0x45, 0xd489), /* Set to CTIA type */
3683 		WRITE_COEF(0x1b, 0x0c2b),
3684 		WRITE_COEFEX(0x57, 0x03, 0x8ea6),
3685 		{}
3686 	};
3687 	static struct coef_fw coef0233[] = {
3688 		WRITE_COEF(0x45, 0xd429),
3689 		WRITE_COEF(0x1b, 0x0c2b),
3690 		WRITE_COEF(0x32, 0x4ea3),
3691 		{}
3692 	};
3693 	static struct coef_fw coef0292[] = {
3694 		WRITE_COEF(0x6b, 0xd429),
3695 		WRITE_COEF(0x76, 0x0008),
3696 		WRITE_COEF(0x18, 0x7388),
3697 		{}
3698 	};
3699 	static struct coef_fw coef0293[] = {
3700 		WRITE_COEF(0x45, 0xd429), /* Set to ctia type */
3701 		UPDATE_COEF(0x10, 7<<8, 7<<8), /* SET Line1 JD to 1 */
3702 		{}
3703 	};
3704 	static struct coef_fw coef0688[] = {
3705 		WRITE_COEF(0x11, 0x0001),
3706 		WRITE_COEF(0x15, 0x0d60),
3707 		WRITE_COEF(0xc3, 0x0000),
3708 		{}
3709 	};
3710 
3711 	switch (codec->vendor_id) {
3712 	case 0x10ec0255:
3713 		alc_process_coef_fw(codec, coef0255);
3714 		break;
3715 	case 0x10ec0233:
3716 	case 0x10ec0283:
3717 		alc_process_coef_fw(codec, coef0233);
3718 		break;
3719 	case 0x10ec0292:
3720 		alc_process_coef_fw(codec, coef0292);
3721 		break;
3722 	case 0x10ec0293:
3723 		alc_process_coef_fw(codec, coef0293);
3724 		break;
3725 	case 0x10ec0668:
3726 		alc_process_coef_fw(codec, coef0688);
3727 		break;
3728 	}
3729 	codec_dbg(codec, "Headset jack set to iPhone-style headset mode.\n");
3730 }
3731 
3732 /* Nokia type */
3733 static void alc_headset_mode_omtp(struct hda_codec *codec)
3734 {
3735 	static struct coef_fw coef0255[] = {
3736 		WRITE_COEF(0x45, 0xe489), /* Set to OMTP Type */
3737 		WRITE_COEF(0x1b, 0x0c2b),
3738 		WRITE_COEFEX(0x57, 0x03, 0x8ea6),
3739 		{}
3740 	};
3741 	static struct coef_fw coef0233[] = {
3742 		WRITE_COEF(0x45, 0xe429),
3743 		WRITE_COEF(0x1b, 0x0c2b),
3744 		WRITE_COEF(0x32, 0x4ea3),
3745 		{}
3746 	};
3747 	static struct coef_fw coef0292[] = {
3748 		WRITE_COEF(0x6b, 0xe429),
3749 		WRITE_COEF(0x76, 0x0008),
3750 		WRITE_COEF(0x18, 0x7388),
3751 		{}
3752 	};
3753 	static struct coef_fw coef0293[] = {
3754 		WRITE_COEF(0x45, 0xe429), /* Set to omtp type */
3755 		UPDATE_COEF(0x10, 7<<8, 7<<8), /* SET Line1 JD to 1 */
3756 		{}
3757 	};
3758 	static struct coef_fw coef0688[] = {
3759 		WRITE_COEF(0x11, 0x0001),
3760 		WRITE_COEF(0x15, 0x0d50),
3761 		WRITE_COEF(0xc3, 0x0000),
3762 		{}
3763 	};
3764 
3765 	switch (codec->vendor_id) {
3766 	case 0x10ec0255:
3767 		alc_process_coef_fw(codec, coef0255);
3768 		break;
3769 	case 0x10ec0233:
3770 	case 0x10ec0283:
3771 		alc_process_coef_fw(codec, coef0233);
3772 		break;
3773 	case 0x10ec0292:
3774 		alc_process_coef_fw(codec, coef0292);
3775 		break;
3776 	case 0x10ec0293:
3777 		alc_process_coef_fw(codec, coef0293);
3778 		break;
3779 	case 0x10ec0668:
3780 		alc_process_coef_fw(codec, coef0688);
3781 		break;
3782 	}
3783 	codec_dbg(codec, "Headset jack set to Nokia-style headset mode.\n");
3784 }
3785 
3786 static void alc_determine_headset_type(struct hda_codec *codec)
3787 {
3788 	int val;
3789 	bool is_ctia = false;
3790 	struct alc_spec *spec = codec->spec;
3791 	static struct coef_fw coef0255[] = {
3792 		WRITE_COEF(0x45, 0xd089), /* combo jack auto switch control(Check type)*/
3793 		WRITE_COEF(0x49, 0x0149), /* combo jack auto switch control(Vref
3794  conteol) */
3795 		{}
3796 	};
3797 	static struct coef_fw coef0293[] = {
3798 		UPDATE_COEF(0x4a, 0x000f, 0x0008), /* Combo Jack auto detect */
3799 		WRITE_COEF(0x45, 0xD429), /* Set to ctia type */
3800 		{}
3801 	};
3802 	static struct coef_fw coef0688[] = {
3803 		WRITE_COEF(0x11, 0x0001),
3804 		WRITE_COEF(0xb7, 0x802b),
3805 		WRITE_COEF(0x15, 0x0d60),
3806 		WRITE_COEF(0xc3, 0x0c00),
3807 		{}
3808 	};
3809 
3810 	switch (codec->vendor_id) {
3811 	case 0x10ec0255:
3812 		alc_process_coef_fw(codec, coef0255);
3813 		msleep(300);
3814 		val = alc_read_coef_idx(codec, 0x46);
3815 		is_ctia = (val & 0x0070) == 0x0070;
3816 		break;
3817 	case 0x10ec0233:
3818 	case 0x10ec0283:
3819 		alc_write_coef_idx(codec, 0x45, 0xd029);
3820 		msleep(300);
3821 		val = alc_read_coef_idx(codec, 0x46);
3822 		is_ctia = (val & 0x0070) == 0x0070;
3823 		break;
3824 	case 0x10ec0292:
3825 		alc_write_coef_idx(codec, 0x6b, 0xd429);
3826 		msleep(300);
3827 		val = alc_read_coef_idx(codec, 0x6c);
3828 		is_ctia = (val & 0x001c) == 0x001c;
3829 		break;
3830 	case 0x10ec0293:
3831 		alc_process_coef_fw(codec, coef0293);
3832 		msleep(300);
3833 		val = alc_read_coef_idx(codec, 0x46);
3834 		is_ctia = (val & 0x0070) == 0x0070;
3835 		break;
3836 	case 0x10ec0668:
3837 		alc_process_coef_fw(codec, coef0688);
3838 		msleep(300);
3839 		val = alc_read_coef_idx(codec, 0xbe);
3840 		is_ctia = (val & 0x1c02) == 0x1c02;
3841 		break;
3842 	}
3843 
3844 	codec_dbg(codec, "Headset jack detected iPhone-style headset: %s\n",
3845 		    is_ctia ? "yes" : "no");
3846 	spec->current_headset_type = is_ctia ? ALC_HEADSET_TYPE_CTIA : ALC_HEADSET_TYPE_OMTP;
3847 }
3848 
3849 static void alc_update_headset_mode(struct hda_codec *codec)
3850 {
3851 	struct alc_spec *spec = codec->spec;
3852 
3853 	hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
3854 	hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3855 
3856 	int new_headset_mode;
3857 
3858 	if (!snd_hda_jack_detect(codec, hp_pin))
3859 		new_headset_mode = ALC_HEADSET_MODE_UNPLUGGED;
3860 	else if (mux_pin == spec->headset_mic_pin)
3861 		new_headset_mode = ALC_HEADSET_MODE_HEADSET;
3862 	else if (mux_pin == spec->headphone_mic_pin)
3863 		new_headset_mode = ALC_HEADSET_MODE_MIC;
3864 	else
3865 		new_headset_mode = ALC_HEADSET_MODE_HEADPHONE;
3866 
3867 	if (new_headset_mode == spec->current_headset_mode) {
3868 		snd_hda_gen_update_outputs(codec);
3869 		return;
3870 	}
3871 
3872 	switch (new_headset_mode) {
3873 	case ALC_HEADSET_MODE_UNPLUGGED:
3874 		alc_headset_mode_unplugged(codec);
3875 		spec->gen.hp_jack_present = false;
3876 		break;
3877 	case ALC_HEADSET_MODE_HEADSET:
3878 		if (spec->current_headset_type == ALC_HEADSET_TYPE_UNKNOWN)
3879 			alc_determine_headset_type(codec);
3880 		if (spec->current_headset_type == ALC_HEADSET_TYPE_CTIA)
3881 			alc_headset_mode_ctia(codec);
3882 		else if (spec->current_headset_type == ALC_HEADSET_TYPE_OMTP)
3883 			alc_headset_mode_omtp(codec);
3884 		spec->gen.hp_jack_present = true;
3885 		break;
3886 	case ALC_HEADSET_MODE_MIC:
3887 		alc_headset_mode_mic_in(codec, hp_pin, spec->headphone_mic_pin);
3888 		spec->gen.hp_jack_present = false;
3889 		break;
3890 	case ALC_HEADSET_MODE_HEADPHONE:
3891 		alc_headset_mode_default(codec);
3892 		spec->gen.hp_jack_present = true;
3893 		break;
3894 	}
3895 	if (new_headset_mode != ALC_HEADSET_MODE_MIC) {
3896 		snd_hda_set_pin_ctl_cache(codec, hp_pin,
3897 					  AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3898 		if (spec->headphone_mic_pin)
3899 			snd_hda_set_pin_ctl_cache(codec, spec->headphone_mic_pin,
3900 						  PIN_VREFHIZ);
3901 	}
3902 	spec->current_headset_mode = new_headset_mode;
3903 
3904 	snd_hda_gen_update_outputs(codec);
3905 }
3906 
3907 static void alc_update_headset_mode_hook(struct hda_codec *codec,
3908 					 struct snd_kcontrol *kcontrol,
3909 					 struct snd_ctl_elem_value *ucontrol)
3910 {
3911 	alc_update_headset_mode(codec);
3912 }
3913 
3914 static void alc_update_headset_jack_cb(struct hda_codec *codec,
3915 				       struct hda_jack_callback *jack)
3916 {
3917 	struct alc_spec *spec = codec->spec;
3918 	spec->current_headset_type = ALC_HEADSET_TYPE_UNKNOWN;
3919 	snd_hda_gen_hp_automute(codec, jack);
3920 }
3921 
3922 static void alc_probe_headset_mode(struct hda_codec *codec)
3923 {
3924 	int i;
3925 	struct alc_spec *spec = codec->spec;
3926 	struct auto_pin_cfg *cfg = &spec->gen.autocfg;
3927 
3928 	/* Find mic pins */
3929 	for (i = 0; i < cfg->num_inputs; i++) {
3930 		if (cfg->inputs[i].is_headset_mic && !spec->headset_mic_pin)
3931 			spec->headset_mic_pin = cfg->inputs[i].pin;
3932 		if (cfg->inputs[i].is_headphone_mic && !spec->headphone_mic_pin)
3933 			spec->headphone_mic_pin = cfg->inputs[i].pin;
3934 	}
3935 
3936 	spec->gen.cap_sync_hook = alc_update_headset_mode_hook;
3937 	spec->gen.automute_hook = alc_update_headset_mode;
3938 	spec->gen.hp_automute_hook = alc_update_headset_jack_cb;
3939 }
3940 
3941 static void alc_fixup_headset_mode(struct hda_codec *codec,
3942 				const struct hda_fixup *fix, int action)
3943 {
3944 	struct alc_spec *spec = codec->spec;
3945 
3946 	switch (action) {
3947 	case HDA_FIXUP_ACT_PRE_PROBE:
3948 		spec->parse_flags |= HDA_PINCFG_HEADSET_MIC | HDA_PINCFG_HEADPHONE_MIC;
3949 		break;
3950 	case HDA_FIXUP_ACT_PROBE:
3951 		alc_probe_headset_mode(codec);
3952 		break;
3953 	case HDA_FIXUP_ACT_INIT:
3954 		spec->current_headset_mode = 0;
3955 		alc_update_headset_mode(codec);
3956 		break;
3957 	}
3958 }
3959 
3960 static void alc_fixup_headset_mode_no_hp_mic(struct hda_codec *codec,
3961 				const struct hda_fixup *fix, int action)
3962 {
3963 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3964 		struct alc_spec *spec = codec->spec;
3965 		spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
3966 	}
3967 	else
3968 		alc_fixup_headset_mode(codec, fix, action);
3969 }
3970 
3971 static void alc255_set_default_jack_type(struct hda_codec *codec)
3972 {
3973 	/* Set to iphone type */
3974 	static struct coef_fw fw[] = {
3975 		WRITE_COEF(0x1b, 0x880b),
3976 		WRITE_COEF(0x45, 0xd089),
3977 		WRITE_COEF(0x1b, 0x080b),
3978 		WRITE_COEF(0x46, 0x0004),
3979 		WRITE_COEF(0x1b, 0x0c0b),
3980 		{}
3981 	};
3982 	alc_process_coef_fw(codec, fw);
3983 	msleep(30);
3984 }
3985 
3986 static void alc_fixup_headset_mode_alc255(struct hda_codec *codec,
3987 				const struct hda_fixup *fix, int action)
3988 {
3989 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3990 		alc255_set_default_jack_type(codec);
3991 	}
3992 	alc_fixup_headset_mode(codec, fix, action);
3993 }
3994 
3995 static void alc_fixup_headset_mode_alc255_no_hp_mic(struct hda_codec *codec,
3996 				const struct hda_fixup *fix, int action)
3997 {
3998 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3999 		struct alc_spec *spec = codec->spec;
4000 		spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
4001 		alc255_set_default_jack_type(codec);
4002 	}
4003 	else
4004 		alc_fixup_headset_mode(codec, fix, action);
4005 }
4006 
4007 static void alc_fixup_auto_mute_via_amp(struct hda_codec *codec,
4008 					const struct hda_fixup *fix, int action)
4009 {
4010 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4011 		struct alc_spec *spec = codec->spec;
4012 		spec->gen.auto_mute_via_amp = 1;
4013 	}
4014 }
4015 
4016 static void alc_no_shutup(struct hda_codec *codec)
4017 {
4018 }
4019 
4020 static void alc_fixup_no_shutup(struct hda_codec *codec,
4021 				const struct hda_fixup *fix, int action)
4022 {
4023 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4024 		struct alc_spec *spec = codec->spec;
4025 		spec->shutup = alc_no_shutup;
4026 	}
4027 }
4028 
4029 static void alc_fixup_disable_aamix(struct hda_codec *codec,
4030 				    const struct hda_fixup *fix, int action)
4031 {
4032 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4033 		struct alc_spec *spec = codec->spec;
4034 		/* Disable AA-loopback as it causes white noise */
4035 		spec->gen.mixer_nid = 0;
4036 	}
4037 }
4038 
4039 static unsigned int alc_power_filter_xps13(struct hda_codec *codec,
4040 				hda_nid_t nid,
4041 				unsigned int power_state)
4042 {
4043 	struct alc_spec *spec = codec->spec;
4044 
4045 	/* Avoid pop noises when headphones are plugged in */
4046 	if (spec->gen.hp_jack_present)
4047 		if (nid == codec->afg || nid == 0x02 || nid == 0x15)
4048 			return AC_PWRST_D0;
4049 	return power_state;
4050 }
4051 
4052 static void alc_fixup_dell_xps13(struct hda_codec *codec,
4053 				const struct hda_fixup *fix, int action)
4054 {
4055 	if (action == HDA_FIXUP_ACT_PROBE) {
4056 		struct alc_spec *spec = codec->spec;
4057 		struct hda_input_mux *imux = &spec->gen.input_mux;
4058 		int i;
4059 
4060 		spec->shutup = alc_no_shutup;
4061 		codec->power_filter = alc_power_filter_xps13;
4062 
4063 		/* Make the internal mic the default input source. */
4064 		for (i = 0; i < imux->num_items; i++) {
4065 			if (spec->gen.imux_pins[i] == 0x12) {
4066 				spec->gen.cur_mux[0] = i;
4067 				break;
4068 			}
4069 		}
4070 	}
4071 }
4072 
4073 static void alc_fixup_headset_mode_alc668(struct hda_codec *codec,
4074 				const struct hda_fixup *fix, int action)
4075 {
4076 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4077 		alc_write_coef_idx(codec, 0xc4, 0x8000);
4078 		alc_update_coef_idx(codec, 0xc2, ~0xfe, 0);
4079 		snd_hda_set_pin_ctl_cache(codec, 0x18, 0);
4080 	}
4081 	alc_fixup_headset_mode(codec, fix, action);
4082 }
4083 
4084 /* Returns the nid of the external mic input pin, or 0 if it cannot be found. */
4085 static int find_ext_mic_pin(struct hda_codec *codec)
4086 {
4087 	struct alc_spec *spec = codec->spec;
4088 	struct auto_pin_cfg *cfg = &spec->gen.autocfg;
4089 	hda_nid_t nid;
4090 	unsigned int defcfg;
4091 	int i;
4092 
4093 	for (i = 0; i < cfg->num_inputs; i++) {
4094 		if (cfg->inputs[i].type != AUTO_PIN_MIC)
4095 			continue;
4096 		nid = cfg->inputs[i].pin;
4097 		defcfg = snd_hda_codec_get_pincfg(codec, nid);
4098 		if (snd_hda_get_input_pin_attr(defcfg) == INPUT_PIN_ATTR_INT)
4099 			continue;
4100 		return nid;
4101 	}
4102 
4103 	return 0;
4104 }
4105 
4106 static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
4107 				    const struct hda_fixup *fix,
4108 				    int action)
4109 {
4110 	struct alc_spec *spec = codec->spec;
4111 
4112 	if (action == HDA_FIXUP_ACT_PROBE) {
4113 		int mic_pin = find_ext_mic_pin(codec);
4114 		int hp_pin = spec->gen.autocfg.hp_pins[0];
4115 
4116 		if (snd_BUG_ON(!mic_pin || !hp_pin))
4117 			return;
4118 		snd_hda_jack_set_gating_jack(codec, mic_pin, hp_pin);
4119 	}
4120 }
4121 
4122 static void alc269_fixup_limit_int_mic_boost(struct hda_codec *codec,
4123 					     const struct hda_fixup *fix,
4124 					     int action)
4125 {
4126 	struct alc_spec *spec = codec->spec;
4127 	struct auto_pin_cfg *cfg = &spec->gen.autocfg;
4128 	int i;
4129 
4130 	/* The mic boosts on level 2 and 3 are too noisy
4131 	   on the internal mic input.
4132 	   Therefore limit the boost to 0 or 1. */
4133 
4134 	if (action != HDA_FIXUP_ACT_PROBE)
4135 		return;
4136 
4137 	for (i = 0; i < cfg->num_inputs; i++) {
4138 		hda_nid_t nid = cfg->inputs[i].pin;
4139 		unsigned int defcfg;
4140 		if (cfg->inputs[i].type != AUTO_PIN_MIC)
4141 			continue;
4142 		defcfg = snd_hda_codec_get_pincfg(codec, nid);
4143 		if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
4144 			continue;
4145 
4146 		snd_hda_override_amp_caps(codec, nid, HDA_INPUT,
4147 					  (0x00 << AC_AMPCAP_OFFSET_SHIFT) |
4148 					  (0x01 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4149 					  (0x2f << AC_AMPCAP_STEP_SIZE_SHIFT) |
4150 					  (0 << AC_AMPCAP_MUTE_SHIFT));
4151 	}
4152 }
4153 
4154 static void alc283_hp_automute_hook(struct hda_codec *codec,
4155 				    struct hda_jack_callback *jack)
4156 {
4157 	struct alc_spec *spec = codec->spec;
4158 	int vref;
4159 
4160 	msleep(200);
4161 	snd_hda_gen_hp_automute(codec, jack);
4162 
4163 	vref = spec->gen.hp_jack_present ? PIN_VREF80 : 0;
4164 
4165 	msleep(600);
4166 	snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4167 			    vref);
4168 }
4169 
4170 static void alc283_fixup_chromebook(struct hda_codec *codec,
4171 				    const struct hda_fixup *fix, int action)
4172 {
4173 	struct alc_spec *spec = codec->spec;
4174 
4175 	switch (action) {
4176 	case HDA_FIXUP_ACT_PRE_PROBE:
4177 		snd_hda_override_wcaps(codec, 0x03, 0);
4178 		/* Disable AA-loopback as it causes white noise */
4179 		spec->gen.mixer_nid = 0;
4180 		break;
4181 	case HDA_FIXUP_ACT_INIT:
4182 		/* MIC2-VREF control */
4183 		/* Set to manual mode */
4184 		alc_update_coef_idx(codec, 0x06, 0x000c, 0);
4185 		/* Enable Line1 input control by verb */
4186 		alc_update_coef_idx(codec, 0x1a, 0, 1 << 4);
4187 		break;
4188 	}
4189 }
4190 
4191 static void alc283_fixup_sense_combo_jack(struct hda_codec *codec,
4192 				    const struct hda_fixup *fix, int action)
4193 {
4194 	struct alc_spec *spec = codec->spec;
4195 
4196 	switch (action) {
4197 	case HDA_FIXUP_ACT_PRE_PROBE:
4198 		spec->gen.hp_automute_hook = alc283_hp_automute_hook;
4199 		break;
4200 	case HDA_FIXUP_ACT_INIT:
4201 		/* MIC2-VREF control */
4202 		/* Set to manual mode */
4203 		alc_update_coef_idx(codec, 0x06, 0x000c, 0);
4204 		break;
4205 	}
4206 }
4207 
4208 /* mute tablet speaker pin (0x14) via dock plugging in addition */
4209 static void asus_tx300_automute(struct hda_codec *codec)
4210 {
4211 	struct alc_spec *spec = codec->spec;
4212 	snd_hda_gen_update_outputs(codec);
4213 	if (snd_hda_jack_detect(codec, 0x1b))
4214 		spec->gen.mute_bits |= (1ULL << 0x14);
4215 }
4216 
4217 static void alc282_fixup_asus_tx300(struct hda_codec *codec,
4218 				    const struct hda_fixup *fix, int action)
4219 {
4220 	struct alc_spec *spec = codec->spec;
4221 	/* TX300 needs to set up GPIO2 for the speaker amp */
4222 	static const struct hda_verb gpio2_verbs[] = {
4223 		{ 0x01, AC_VERB_SET_GPIO_MASK, 0x04 },
4224 		{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04 },
4225 		{ 0x01, AC_VERB_SET_GPIO_DATA, 0x04 },
4226 		{}
4227 	};
4228 	static const struct hda_pintbl dock_pins[] = {
4229 		{ 0x1b, 0x21114000 }, /* dock speaker pin */
4230 		{}
4231 	};
4232 	struct snd_kcontrol *kctl;
4233 
4234 	switch (action) {
4235 	case HDA_FIXUP_ACT_PRE_PROBE:
4236 		snd_hda_add_verbs(codec, gpio2_verbs);
4237 		snd_hda_apply_pincfgs(codec, dock_pins);
4238 		spec->gen.auto_mute_via_amp = 1;
4239 		spec->gen.automute_hook = asus_tx300_automute;
4240 		snd_hda_jack_detect_enable_callback(codec, 0x1b,
4241 						    snd_hda_gen_hp_automute);
4242 		break;
4243 	case HDA_FIXUP_ACT_BUILD:
4244 		/* this is a bit tricky; give more sane names for the main
4245 		 * (tablet) speaker and the dock speaker, respectively
4246 		 */
4247 		kctl = snd_hda_find_mixer_ctl(codec, "Speaker Playback Switch");
4248 		if (kctl)
4249 			strcpy(kctl->id.name, "Dock Speaker Playback Switch");
4250 		kctl = snd_hda_find_mixer_ctl(codec, "Bass Speaker Playback Switch");
4251 		if (kctl)
4252 			strcpy(kctl->id.name, "Speaker Playback Switch");
4253 		break;
4254 	}
4255 }
4256 
4257 static void alc290_fixup_mono_speakers(struct hda_codec *codec,
4258 				       const struct hda_fixup *fix, int action)
4259 {
4260 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4261 		/* DAC node 0x03 is giving mono output. We therefore want to
4262 		   make sure 0x14 (front speaker) and 0x15 (headphones) use the
4263 		   stereo DAC, while leaving 0x17 (bass speaker) for node 0x03. */
4264 		hda_nid_t conn1[2] = { 0x0c };
4265 		snd_hda_override_conn_list(codec, 0x14, 1, conn1);
4266 		snd_hda_override_conn_list(codec, 0x15, 1, conn1);
4267 	}
4268 }
4269 
4270 /* for hda_fixup_thinkpad_acpi() */
4271 #include "thinkpad_helper.c"
4272 
4273 /* for dell wmi mic mute led */
4274 #include "dell_wmi_helper.c"
4275 
4276 enum {
4277 	ALC269_FIXUP_SONY_VAIO,
4278 	ALC275_FIXUP_SONY_VAIO_GPIO2,
4279 	ALC269_FIXUP_DELL_M101Z,
4280 	ALC269_FIXUP_SKU_IGNORE,
4281 	ALC269_FIXUP_ASUS_G73JW,
4282 	ALC269_FIXUP_LENOVO_EAPD,
4283 	ALC275_FIXUP_SONY_HWEQ,
4284 	ALC275_FIXUP_SONY_DISABLE_AAMIX,
4285 	ALC271_FIXUP_DMIC,
4286 	ALC269_FIXUP_PCM_44K,
4287 	ALC269_FIXUP_STEREO_DMIC,
4288 	ALC269_FIXUP_HEADSET_MIC,
4289 	ALC269_FIXUP_QUANTA_MUTE,
4290 	ALC269_FIXUP_LIFEBOOK,
4291 	ALC269_FIXUP_LIFEBOOK_EXTMIC,
4292 	ALC269_FIXUP_AMIC,
4293 	ALC269_FIXUP_DMIC,
4294 	ALC269VB_FIXUP_AMIC,
4295 	ALC269VB_FIXUP_DMIC,
4296 	ALC269_FIXUP_HP_MUTE_LED,
4297 	ALC269_FIXUP_HP_MUTE_LED_MIC1,
4298 	ALC269_FIXUP_HP_MUTE_LED_MIC2,
4299 	ALC269_FIXUP_HP_GPIO_LED,
4300 	ALC269_FIXUP_HP_GPIO_MIC1_LED,
4301 	ALC269_FIXUP_HP_LINE1_MIC1_LED,
4302 	ALC269_FIXUP_INV_DMIC,
4303 	ALC269_FIXUP_LENOVO_DOCK,
4304 	ALC269_FIXUP_NO_SHUTUP,
4305 	ALC286_FIXUP_SONY_MIC_NO_PRESENCE,
4306 	ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
4307 	ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
4308 	ALC269_FIXUP_DELL2_MIC_NO_PRESENCE,
4309 	ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
4310 	ALC269_FIXUP_HEADSET_MODE,
4311 	ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC,
4312 	ALC269_FIXUP_ASUS_X101_FUNC,
4313 	ALC269_FIXUP_ASUS_X101_VERB,
4314 	ALC269_FIXUP_ASUS_X101,
4315 	ALC271_FIXUP_AMIC_MIC2,
4316 	ALC271_FIXUP_HP_GATE_MIC_JACK,
4317 	ALC271_FIXUP_HP_GATE_MIC_JACK_E1_572,
4318 	ALC269_FIXUP_ACER_AC700,
4319 	ALC269_FIXUP_LIMIT_INT_MIC_BOOST,
4320 	ALC269VB_FIXUP_ASUS_ZENBOOK,
4321 	ALC269VB_FIXUP_ASUS_ZENBOOK_UX31A,
4322 	ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED,
4323 	ALC269VB_FIXUP_ORDISSIMO_EVE2,
4324 	ALC283_FIXUP_CHROME_BOOK,
4325 	ALC283_FIXUP_SENSE_COMBO_JACK,
4326 	ALC282_FIXUP_ASUS_TX300,
4327 	ALC283_FIXUP_INT_MIC,
4328 	ALC290_FIXUP_MONO_SPEAKERS,
4329 	ALC290_FIXUP_MONO_SPEAKERS_HSJACK,
4330 	ALC290_FIXUP_SUBWOOFER,
4331 	ALC290_FIXUP_SUBWOOFER_HSJACK,
4332 	ALC269_FIXUP_THINKPAD_ACPI,
4333 	ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
4334 	ALC255_FIXUP_DELL2_MIC_NO_PRESENCE,
4335 	ALC255_FIXUP_HEADSET_MODE,
4336 	ALC255_FIXUP_HEADSET_MODE_NO_HP_MIC,
4337 	ALC293_FIXUP_DELL1_MIC_NO_PRESENCE,
4338 	ALC292_FIXUP_TPT440_DOCK,
4339 	ALC283_FIXUP_BXBT2807_MIC,
4340 	ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED,
4341 	ALC282_FIXUP_ASPIRE_V5_PINS,
4342 	ALC280_FIXUP_HP_GPIO4,
4343 	ALC286_FIXUP_HP_GPIO_LED,
4344 };
4345 
4346 static const struct hda_fixup alc269_fixups[] = {
4347 	[ALC269_FIXUP_SONY_VAIO] = {
4348 		.type = HDA_FIXUP_PINCTLS,
4349 		.v.pins = (const struct hda_pintbl[]) {
4350 			{0x19, PIN_VREFGRD},
4351 			{}
4352 		}
4353 	},
4354 	[ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4355 		.type = HDA_FIXUP_VERBS,
4356 		.v.verbs = (const struct hda_verb[]) {
4357 			{0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4358 			{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4359 			{0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4360 			{ }
4361 		},
4362 		.chained = true,
4363 		.chain_id = ALC269_FIXUP_SONY_VAIO
4364 	},
4365 	[ALC269_FIXUP_DELL_M101Z] = {
4366 		.type = HDA_FIXUP_VERBS,
4367 		.v.verbs = (const struct hda_verb[]) {
4368 			/* Enables internal speaker */
4369 			{0x20, AC_VERB_SET_COEF_INDEX, 13},
4370 			{0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4371 			{}
4372 		}
4373 	},
4374 	[ALC269_FIXUP_SKU_IGNORE] = {
4375 		.type = HDA_FIXUP_FUNC,
4376 		.v.func = alc_fixup_sku_ignore,
4377 	},
4378 	[ALC269_FIXUP_ASUS_G73JW] = {
4379 		.type = HDA_FIXUP_PINS,
4380 		.v.pins = (const struct hda_pintbl[]) {
4381 			{ 0x17, 0x99130111 }, /* subwoofer */
4382 			{ }
4383 		}
4384 	},
4385 	[ALC269_FIXUP_LENOVO_EAPD] = {
4386 		.type = HDA_FIXUP_VERBS,
4387 		.v.verbs = (const struct hda_verb[]) {
4388 			{0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4389 			{}
4390 		}
4391 	},
4392 	[ALC275_FIXUP_SONY_HWEQ] = {
4393 		.type = HDA_FIXUP_FUNC,
4394 		.v.func = alc269_fixup_hweq,
4395 		.chained = true,
4396 		.chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4397 	},
4398 	[ALC275_FIXUP_SONY_DISABLE_AAMIX] = {
4399 		.type = HDA_FIXUP_FUNC,
4400 		.v.func = alc_fixup_disable_aamix,
4401 		.chained = true,
4402 		.chain_id = ALC269_FIXUP_SONY_VAIO
4403 	},
4404 	[ALC271_FIXUP_DMIC] = {
4405 		.type = HDA_FIXUP_FUNC,
4406 		.v.func = alc271_fixup_dmic,
4407 	},
4408 	[ALC269_FIXUP_PCM_44K] = {
4409 		.type = HDA_FIXUP_FUNC,
4410 		.v.func = alc269_fixup_pcm_44k,
4411 		.chained = true,
4412 		.chain_id = ALC269_FIXUP_QUANTA_MUTE
4413 	},
4414 	[ALC269_FIXUP_STEREO_DMIC] = {
4415 		.type = HDA_FIXUP_FUNC,
4416 		.v.func = alc269_fixup_stereo_dmic,
4417 	},
4418 	[ALC269_FIXUP_HEADSET_MIC] = {
4419 		.type = HDA_FIXUP_FUNC,
4420 		.v.func = alc269_fixup_headset_mic,
4421 	},
4422 	[ALC269_FIXUP_QUANTA_MUTE] = {
4423 		.type = HDA_FIXUP_FUNC,
4424 		.v.func = alc269_fixup_quanta_mute,
4425 	},
4426 	[ALC269_FIXUP_LIFEBOOK] = {
4427 		.type = HDA_FIXUP_PINS,
4428 		.v.pins = (const struct hda_pintbl[]) {
4429 			{ 0x1a, 0x2101103f }, /* dock line-out */
4430 			{ 0x1b, 0x23a11040 }, /* dock mic-in */
4431 			{ }
4432 		},
4433 		.chained = true,
4434 		.chain_id = ALC269_FIXUP_QUANTA_MUTE
4435 	},
4436 	[ALC269_FIXUP_LIFEBOOK_EXTMIC] = {
4437 		.type = HDA_FIXUP_PINS,
4438 		.v.pins = (const struct hda_pintbl[]) {
4439 			{ 0x19, 0x01a1903c }, /* headset mic, with jack detect */
4440 			{ }
4441 		},
4442 	},
4443 	[ALC269_FIXUP_AMIC] = {
4444 		.type = HDA_FIXUP_PINS,
4445 		.v.pins = (const struct hda_pintbl[]) {
4446 			{ 0x14, 0x99130110 }, /* speaker */
4447 			{ 0x15, 0x0121401f }, /* HP out */
4448 			{ 0x18, 0x01a19c20 }, /* mic */
4449 			{ 0x19, 0x99a3092f }, /* int-mic */
4450 			{ }
4451 		},
4452 	},
4453 	[ALC269_FIXUP_DMIC] = {
4454 		.type = HDA_FIXUP_PINS,
4455 		.v.pins = (const struct hda_pintbl[]) {
4456 			{ 0x12, 0x99a3092f }, /* int-mic */
4457 			{ 0x14, 0x99130110 }, /* speaker */
4458 			{ 0x15, 0x0121401f }, /* HP out */
4459 			{ 0x18, 0x01a19c20 }, /* mic */
4460 			{ }
4461 		},
4462 	},
4463 	[ALC269VB_FIXUP_AMIC] = {
4464 		.type = HDA_FIXUP_PINS,
4465 		.v.pins = (const struct hda_pintbl[]) {
4466 			{ 0x14, 0x99130110 }, /* speaker */
4467 			{ 0x18, 0x01a19c20 }, /* mic */
4468 			{ 0x19, 0x99a3092f }, /* int-mic */
4469 			{ 0x21, 0x0121401f }, /* HP out */
4470 			{ }
4471 		},
4472 	},
4473 	[ALC269VB_FIXUP_DMIC] = {
4474 		.type = HDA_FIXUP_PINS,
4475 		.v.pins = (const struct hda_pintbl[]) {
4476 			{ 0x12, 0x99a3092f }, /* int-mic */
4477 			{ 0x14, 0x99130110 }, /* speaker */
4478 			{ 0x18, 0x01a19c20 }, /* mic */
4479 			{ 0x21, 0x0121401f }, /* HP out */
4480 			{ }
4481 		},
4482 	},
4483 	[ALC269_FIXUP_HP_MUTE_LED] = {
4484 		.type = HDA_FIXUP_FUNC,
4485 		.v.func = alc269_fixup_hp_mute_led,
4486 	},
4487 	[ALC269_FIXUP_HP_MUTE_LED_MIC1] = {
4488 		.type = HDA_FIXUP_FUNC,
4489 		.v.func = alc269_fixup_hp_mute_led_mic1,
4490 	},
4491 	[ALC269_FIXUP_HP_MUTE_LED_MIC2] = {
4492 		.type = HDA_FIXUP_FUNC,
4493 		.v.func = alc269_fixup_hp_mute_led_mic2,
4494 	},
4495 	[ALC269_FIXUP_HP_GPIO_LED] = {
4496 		.type = HDA_FIXUP_FUNC,
4497 		.v.func = alc269_fixup_hp_gpio_led,
4498 	},
4499 	[ALC269_FIXUP_HP_GPIO_MIC1_LED] = {
4500 		.type = HDA_FIXUP_FUNC,
4501 		.v.func = alc269_fixup_hp_gpio_mic1_led,
4502 	},
4503 	[ALC269_FIXUP_HP_LINE1_MIC1_LED] = {
4504 		.type = HDA_FIXUP_FUNC,
4505 		.v.func = alc269_fixup_hp_line1_mic1_led,
4506 	},
4507 	[ALC269_FIXUP_INV_DMIC] = {
4508 		.type = HDA_FIXUP_FUNC,
4509 		.v.func = alc_fixup_inv_dmic,
4510 	},
4511 	[ALC269_FIXUP_NO_SHUTUP] = {
4512 		.type = HDA_FIXUP_FUNC,
4513 		.v.func = alc_fixup_no_shutup,
4514 	},
4515 	[ALC269_FIXUP_LENOVO_DOCK] = {
4516 		.type = HDA_FIXUP_PINS,
4517 		.v.pins = (const struct hda_pintbl[]) {
4518 			{ 0x19, 0x23a11040 }, /* dock mic */
4519 			{ 0x1b, 0x2121103f }, /* dock headphone */
4520 			{ }
4521 		},
4522 		.chained = true,
4523 		.chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
4524 	},
4525 	[ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
4526 		.type = HDA_FIXUP_FUNC,
4527 		.v.func = alc269_fixup_pincfg_no_hp_to_lineout,
4528 		.chained = true,
4529 		.chain_id = ALC269_FIXUP_THINKPAD_ACPI,
4530 	},
4531 	[ALC269_FIXUP_DELL1_MIC_NO_PRESENCE] = {
4532 		.type = HDA_FIXUP_PINS,
4533 		.v.pins = (const struct hda_pintbl[]) {
4534 			{ 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4535 			{ 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
4536 			{ }
4537 		},
4538 		.chained = true,
4539 		.chain_id = ALC269_FIXUP_HEADSET_MODE
4540 	},
4541 	[ALC269_FIXUP_DELL2_MIC_NO_PRESENCE] = {
4542 		.type = HDA_FIXUP_PINS,
4543 		.v.pins = (const struct hda_pintbl[]) {
4544 			{ 0x16, 0x21014020 }, /* dock line out */
4545 			{ 0x19, 0x21a19030 }, /* dock mic */
4546 			{ 0x1a, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4547 			{ }
4548 		},
4549 		.chained = true,
4550 		.chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
4551 	},
4552 	[ALC269_FIXUP_DELL3_MIC_NO_PRESENCE] = {
4553 		.type = HDA_FIXUP_PINS,
4554 		.v.pins = (const struct hda_pintbl[]) {
4555 			{ 0x1a, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4556 			{ }
4557 		},
4558 		.chained = true,
4559 		.chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
4560 	},
4561 	[ALC269_FIXUP_HEADSET_MODE] = {
4562 		.type = HDA_FIXUP_FUNC,
4563 		.v.func = alc_fixup_headset_mode,
4564 		.chained = true,
4565 		.chain_id = ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED
4566 	},
4567 	[ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC] = {
4568 		.type = HDA_FIXUP_FUNC,
4569 		.v.func = alc_fixup_headset_mode_no_hp_mic,
4570 	},
4571 	[ALC286_FIXUP_SONY_MIC_NO_PRESENCE] = {
4572 		.type = HDA_FIXUP_PINS,
4573 		.v.pins = (const struct hda_pintbl[]) {
4574 			{ 0x18, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4575 			{ }
4576 		},
4577 		.chained = true,
4578 		.chain_id = ALC269_FIXUP_HEADSET_MIC
4579 	},
4580 	[ALC269_FIXUP_ASUS_X101_FUNC] = {
4581 		.type = HDA_FIXUP_FUNC,
4582 		.v.func = alc269_fixup_x101_headset_mic,
4583 	},
4584 	[ALC269_FIXUP_ASUS_X101_VERB] = {
4585 		.type = HDA_FIXUP_VERBS,
4586 		.v.verbs = (const struct hda_verb[]) {
4587 			{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4588 			{0x20, AC_VERB_SET_COEF_INDEX, 0x08},
4589 			{0x20, AC_VERB_SET_PROC_COEF,  0x0310},
4590 			{ }
4591 		},
4592 		.chained = true,
4593 		.chain_id = ALC269_FIXUP_ASUS_X101_FUNC
4594 	},
4595 	[ALC269_FIXUP_ASUS_X101] = {
4596 		.type = HDA_FIXUP_PINS,
4597 		.v.pins = (const struct hda_pintbl[]) {
4598 			{ 0x18, 0x04a1182c }, /* Headset mic */
4599 			{ }
4600 		},
4601 		.chained = true,
4602 		.chain_id = ALC269_FIXUP_ASUS_X101_VERB
4603 	},
4604 	[ALC271_FIXUP_AMIC_MIC2] = {
4605 		.type = HDA_FIXUP_PINS,
4606 		.v.pins = (const struct hda_pintbl[]) {
4607 			{ 0x14, 0x99130110 }, /* speaker */
4608 			{ 0x19, 0x01a19c20 }, /* mic */
4609 			{ 0x1b, 0x99a7012f }, /* int-mic */
4610 			{ 0x21, 0x0121401f }, /* HP out */
4611 			{ }
4612 		},
4613 	},
4614 	[ALC271_FIXUP_HP_GATE_MIC_JACK] = {
4615 		.type = HDA_FIXUP_FUNC,
4616 		.v.func = alc271_hp_gate_mic_jack,
4617 		.chained = true,
4618 		.chain_id = ALC271_FIXUP_AMIC_MIC2,
4619 	},
4620 	[ALC271_FIXUP_HP_GATE_MIC_JACK_E1_572] = {
4621 		.type = HDA_FIXUP_FUNC,
4622 		.v.func = alc269_fixup_limit_int_mic_boost,
4623 		.chained = true,
4624 		.chain_id = ALC271_FIXUP_HP_GATE_MIC_JACK,
4625 	},
4626 	[ALC269_FIXUP_ACER_AC700] = {
4627 		.type = HDA_FIXUP_PINS,
4628 		.v.pins = (const struct hda_pintbl[]) {
4629 			{ 0x12, 0x99a3092f }, /* int-mic */
4630 			{ 0x14, 0x99130110 }, /* speaker */
4631 			{ 0x18, 0x03a11c20 }, /* mic */
4632 			{ 0x1e, 0x0346101e }, /* SPDIF1 */
4633 			{ 0x21, 0x0321101f }, /* HP out */
4634 			{ }
4635 		},
4636 		.chained = true,
4637 		.chain_id = ALC271_FIXUP_DMIC,
4638 	},
4639 	[ALC269_FIXUP_LIMIT_INT_MIC_BOOST] = {
4640 		.type = HDA_FIXUP_FUNC,
4641 		.v.func = alc269_fixup_limit_int_mic_boost,
4642 		.chained = true,
4643 		.chain_id = ALC269_FIXUP_THINKPAD_ACPI,
4644 	},
4645 	[ALC269VB_FIXUP_ASUS_ZENBOOK] = {
4646 		.type = HDA_FIXUP_FUNC,
4647 		.v.func = alc269_fixup_limit_int_mic_boost,
4648 		.chained = true,
4649 		.chain_id = ALC269VB_FIXUP_DMIC,
4650 	},
4651 	[ALC269VB_FIXUP_ASUS_ZENBOOK_UX31A] = {
4652 		.type = HDA_FIXUP_VERBS,
4653 		.v.verbs = (const struct hda_verb[]) {
4654 			/* class-D output amp +5dB */
4655 			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x12 },
4656 			{ 0x20, AC_VERB_SET_PROC_COEF, 0x2800 },
4657 			{}
4658 		},
4659 		.chained = true,
4660 		.chain_id = ALC269VB_FIXUP_ASUS_ZENBOOK,
4661 	},
4662 	[ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED] = {
4663 		.type = HDA_FIXUP_FUNC,
4664 		.v.func = alc269_fixup_limit_int_mic_boost,
4665 		.chained = true,
4666 		.chain_id = ALC269_FIXUP_HP_MUTE_LED_MIC1,
4667 	},
4668 	[ALC269VB_FIXUP_ORDISSIMO_EVE2] = {
4669 		.type = HDA_FIXUP_PINS,
4670 		.v.pins = (const struct hda_pintbl[]) {
4671 			{ 0x12, 0x99a3092f }, /* int-mic */
4672 			{ 0x18, 0x03a11d20 }, /* mic */
4673 			{ 0x19, 0x411111f0 }, /* Unused bogus pin */
4674 			{ }
4675 		},
4676 	},
4677 	[ALC283_FIXUP_CHROME_BOOK] = {
4678 		.type = HDA_FIXUP_FUNC,
4679 		.v.func = alc283_fixup_chromebook,
4680 	},
4681 	[ALC283_FIXUP_SENSE_COMBO_JACK] = {
4682 		.type = HDA_FIXUP_FUNC,
4683 		.v.func = alc283_fixup_sense_combo_jack,
4684 		.chained = true,
4685 		.chain_id = ALC283_FIXUP_CHROME_BOOK,
4686 	},
4687 	[ALC282_FIXUP_ASUS_TX300] = {
4688 		.type = HDA_FIXUP_FUNC,
4689 		.v.func = alc282_fixup_asus_tx300,
4690 	},
4691 	[ALC283_FIXUP_INT_MIC] = {
4692 		.type = HDA_FIXUP_VERBS,
4693 		.v.verbs = (const struct hda_verb[]) {
4694 			{0x20, AC_VERB_SET_COEF_INDEX, 0x1a},
4695 			{0x20, AC_VERB_SET_PROC_COEF, 0x0011},
4696 			{ }
4697 		},
4698 		.chained = true,
4699 		.chain_id = ALC269_FIXUP_LIMIT_INT_MIC_BOOST
4700 	},
4701 	[ALC290_FIXUP_SUBWOOFER_HSJACK] = {
4702 		.type = HDA_FIXUP_PINS,
4703 		.v.pins = (const struct hda_pintbl[]) {
4704 			{ 0x17, 0x90170112 }, /* subwoofer */
4705 			{ }
4706 		},
4707 		.chained = true,
4708 		.chain_id = ALC290_FIXUP_MONO_SPEAKERS_HSJACK,
4709 	},
4710 	[ALC290_FIXUP_SUBWOOFER] = {
4711 		.type = HDA_FIXUP_PINS,
4712 		.v.pins = (const struct hda_pintbl[]) {
4713 			{ 0x17, 0x90170112 }, /* subwoofer */
4714 			{ }
4715 		},
4716 		.chained = true,
4717 		.chain_id = ALC290_FIXUP_MONO_SPEAKERS,
4718 	},
4719 	[ALC290_FIXUP_MONO_SPEAKERS] = {
4720 		.type = HDA_FIXUP_FUNC,
4721 		.v.func = alc290_fixup_mono_speakers,
4722 	},
4723 	[ALC290_FIXUP_MONO_SPEAKERS_HSJACK] = {
4724 		.type = HDA_FIXUP_FUNC,
4725 		.v.func = alc290_fixup_mono_speakers,
4726 		.chained = true,
4727 		.chain_id = ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
4728 	},
4729 	[ALC269_FIXUP_THINKPAD_ACPI] = {
4730 		.type = HDA_FIXUP_FUNC,
4731 		.v.func = hda_fixup_thinkpad_acpi,
4732 	},
4733 	[ALC255_FIXUP_DELL1_MIC_NO_PRESENCE] = {
4734 		.type = HDA_FIXUP_PINS,
4735 		.v.pins = (const struct hda_pintbl[]) {
4736 			{ 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4737 			{ 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
4738 			{ }
4739 		},
4740 		.chained = true,
4741 		.chain_id = ALC255_FIXUP_HEADSET_MODE
4742 	},
4743 	[ALC255_FIXUP_DELL2_MIC_NO_PRESENCE] = {
4744 		.type = HDA_FIXUP_PINS,
4745 		.v.pins = (const struct hda_pintbl[]) {
4746 			{ 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4747 			{ }
4748 		},
4749 		.chained = true,
4750 		.chain_id = ALC255_FIXUP_HEADSET_MODE_NO_HP_MIC
4751 	},
4752 	[ALC255_FIXUP_HEADSET_MODE] = {
4753 		.type = HDA_FIXUP_FUNC,
4754 		.v.func = alc_fixup_headset_mode_alc255,
4755 		.chained = true,
4756 		.chain_id = ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED
4757 	},
4758 	[ALC255_FIXUP_HEADSET_MODE_NO_HP_MIC] = {
4759 		.type = HDA_FIXUP_FUNC,
4760 		.v.func = alc_fixup_headset_mode_alc255_no_hp_mic,
4761 	},
4762 	[ALC293_FIXUP_DELL1_MIC_NO_PRESENCE] = {
4763 		.type = HDA_FIXUP_PINS,
4764 		.v.pins = (const struct hda_pintbl[]) {
4765 			{ 0x18, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
4766 			{ 0x1a, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4767 			{ }
4768 		},
4769 		.chained = true,
4770 		.chain_id = ALC269_FIXUP_HEADSET_MODE
4771 	},
4772 	[ALC292_FIXUP_TPT440_DOCK] = {
4773 		.type = HDA_FIXUP_PINS,
4774 		.v.pins = (const struct hda_pintbl[]) {
4775 			{ 0x16, 0x21211010 }, /* dock headphone */
4776 			{ 0x19, 0x21a11010 }, /* dock mic */
4777 			{ }
4778 		},
4779 		.chained = true,
4780 		.chain_id = ALC269_FIXUP_LIMIT_INT_MIC_BOOST
4781 	},
4782 	[ALC283_FIXUP_BXBT2807_MIC] = {
4783 		.type = HDA_FIXUP_PINS,
4784 		.v.pins = (const struct hda_pintbl[]) {
4785 			{ 0x19, 0x04a110f0 },
4786 			{ },
4787 		},
4788 	},
4789 	[ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED] = {
4790 		.type = HDA_FIXUP_FUNC,
4791 		.v.func = alc_fixup_dell_wmi,
4792 	},
4793 	[ALC282_FIXUP_ASPIRE_V5_PINS] = {
4794 		.type = HDA_FIXUP_PINS,
4795 		.v.pins = (const struct hda_pintbl[]) {
4796 			{ 0x12, 0x90a60130 },
4797 			{ 0x14, 0x90170110 },
4798 			{ 0x17, 0x40000008 },
4799 			{ 0x18, 0x411111f0 },
4800 			{ 0x19, 0x411111f0 },
4801 			{ 0x1a, 0x411111f0 },
4802 			{ 0x1b, 0x411111f0 },
4803 			{ 0x1d, 0x40f89b2d },
4804 			{ 0x1e, 0x411111f0 },
4805 			{ 0x21, 0x0321101f },
4806 			{ },
4807 		},
4808 	},
4809 	[ALC280_FIXUP_HP_GPIO4] = {
4810 		.type = HDA_FIXUP_FUNC,
4811 		.v.func = alc280_fixup_hp_gpio4,
4812 	},
4813 	[ALC286_FIXUP_HP_GPIO_LED] = {
4814 		.type = HDA_FIXUP_FUNC,
4815 		.v.func = alc286_fixup_hp_gpio_led,
4816 	},
4817 };
4818 
4819 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4820 	SND_PCI_QUIRK(0x1025, 0x0283, "Acer TravelMate 8371", ALC269_FIXUP_INV_DMIC),
4821 	SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
4822 	SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
4823 	SND_PCI_QUIRK(0x1025, 0x047c, "Acer AC700", ALC269_FIXUP_ACER_AC700),
4824 	SND_PCI_QUIRK(0x1025, 0x0740, "Acer AO725", ALC271_FIXUP_HP_GATE_MIC_JACK),
4825 	SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
4826 	SND_PCI_QUIRK(0x1025, 0x0775, "Acer Aspire E1-572", ALC271_FIXUP_HP_GATE_MIC_JACK_E1_572),
4827 	SND_PCI_QUIRK(0x1025, 0x079b, "Acer Aspire V5-573G", ALC282_FIXUP_ASPIRE_V5_PINS),
4828 	SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
4829 	SND_PCI_QUIRK(0x1028, 0x05da, "Dell Vostro 5460", ALC290_FIXUP_SUBWOOFER),
4830 	SND_PCI_QUIRK(0x1028, 0x05f4, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4831 	SND_PCI_QUIRK(0x1028, 0x05f5, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4832 	SND_PCI_QUIRK(0x1028, 0x05f6, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4833 	SND_PCI_QUIRK(0x1028, 0x0615, "Dell Vostro 5470", ALC290_FIXUP_SUBWOOFER_HSJACK),
4834 	SND_PCI_QUIRK(0x1028, 0x0616, "Dell Vostro 5470", ALC290_FIXUP_SUBWOOFER_HSJACK),
4835 	SND_PCI_QUIRK(0x1028, 0x0638, "Dell Inspiron 5439", ALC290_FIXUP_MONO_SPEAKERS_HSJACK),
4836 	SND_PCI_QUIRK(0x1028, 0x064a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
4837 	SND_PCI_QUIRK(0x1028, 0x064b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
4838 	SND_PCI_QUIRK(0x1028, 0x06c7, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
4839 	SND_PCI_QUIRK(0x1028, 0x06d9, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
4840 	SND_PCI_QUIRK(0x1028, 0x06da, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
4841 	SND_PCI_QUIRK(0x1028, 0x164a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
4842 	SND_PCI_QUIRK(0x1028, 0x164b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
4843 	SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
4844 	SND_PCI_QUIRK(0x103c, 0x18e6, "HP", ALC269_FIXUP_HP_GPIO_LED),
4845 	SND_PCI_QUIRK(0x103c, 0x218b, "HP", ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED),
4846 	/* ALC282 */
4847 	SND_PCI_QUIRK(0x103c, 0x2210, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4848 	SND_PCI_QUIRK(0x103c, 0x2214, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4849 	SND_PCI_QUIRK(0x103c, 0x2236, "HP", ALC269_FIXUP_HP_LINE1_MIC1_LED),
4850 	SND_PCI_QUIRK(0x103c, 0x2237, "HP", ALC269_FIXUP_HP_LINE1_MIC1_LED),
4851 	SND_PCI_QUIRK(0x103c, 0x2238, "HP", ALC269_FIXUP_HP_LINE1_MIC1_LED),
4852 	SND_PCI_QUIRK(0x103c, 0x2239, "HP", ALC269_FIXUP_HP_LINE1_MIC1_LED),
4853 	SND_PCI_QUIRK(0x103c, 0x224b, "HP", ALC269_FIXUP_HP_LINE1_MIC1_LED),
4854 	SND_PCI_QUIRK(0x103c, 0x2268, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4855 	SND_PCI_QUIRK(0x103c, 0x226a, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4856 	SND_PCI_QUIRK(0x103c, 0x226b, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4857 	SND_PCI_QUIRK(0x103c, 0x226e, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4858 	SND_PCI_QUIRK(0x103c, 0x2271, "HP", ALC286_FIXUP_HP_GPIO_LED),
4859 	SND_PCI_QUIRK(0x103c, 0x229e, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4860 	SND_PCI_QUIRK(0x103c, 0x22b2, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4861 	SND_PCI_QUIRK(0x103c, 0x22b7, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4862 	SND_PCI_QUIRK(0x103c, 0x22bf, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4863 	SND_PCI_QUIRK(0x103c, 0x22cf, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4864 	SND_PCI_QUIRK(0x103c, 0x22dc, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4865 	SND_PCI_QUIRK(0x103c, 0x22fb, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4866 	/* ALC290 */
4867 	SND_PCI_QUIRK(0x103c, 0x221b, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4868 	SND_PCI_QUIRK(0x103c, 0x2221, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4869 	SND_PCI_QUIRK(0x103c, 0x2225, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4870 	SND_PCI_QUIRK(0x103c, 0x2253, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4871 	SND_PCI_QUIRK(0x103c, 0x2254, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4872 	SND_PCI_QUIRK(0x103c, 0x2255, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4873 	SND_PCI_QUIRK(0x103c, 0x2256, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4874 	SND_PCI_QUIRK(0x103c, 0x2257, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4875 	SND_PCI_QUIRK(0x103c, 0x2259, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4876 	SND_PCI_QUIRK(0x103c, 0x225a, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4877 	SND_PCI_QUIRK(0x103c, 0x2260, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4878 	SND_PCI_QUIRK(0x103c, 0x2263, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4879 	SND_PCI_QUIRK(0x103c, 0x2264, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4880 	SND_PCI_QUIRK(0x103c, 0x2265, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4881 	SND_PCI_QUIRK(0x103c, 0x2272, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4882 	SND_PCI_QUIRK(0x103c, 0x2273, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4883 	SND_PCI_QUIRK(0x103c, 0x2278, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4884 	SND_PCI_QUIRK(0x103c, 0x227f, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4885 	SND_PCI_QUIRK(0x103c, 0x2282, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4886 	SND_PCI_QUIRK(0x103c, 0x228b, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4887 	SND_PCI_QUIRK(0x103c, 0x228e, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4888 	SND_PCI_QUIRK(0x103c, 0x22c5, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4889 	SND_PCI_QUIRK(0x103c, 0x22c7, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4890 	SND_PCI_QUIRK(0x103c, 0x22c8, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4891 	SND_PCI_QUIRK(0x103c, 0x22c4, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4892 	SND_PCI_QUIRK(0x103c, 0x2334, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4893 	SND_PCI_QUIRK(0x103c, 0x2335, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4894 	SND_PCI_QUIRK(0x103c, 0x2336, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4895 	SND_PCI_QUIRK(0x103c, 0x2337, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4896 	SND_PCI_QUIRK(0x1043, 0x103f, "ASUS TX300", ALC282_FIXUP_ASUS_TX300),
4897 	SND_PCI_QUIRK(0x1043, 0x106d, "Asus K53BE", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4898 	SND_PCI_QUIRK(0x1043, 0x115d, "Asus 1015E", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4899 	SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_ASUS_ZENBOOK),
4900 	SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_ASUS_ZENBOOK_UX31A),
4901 	SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
4902 	SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
4903 	SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
4904 	SND_PCI_QUIRK(0x1043, 0x1c23, "Asus X55U", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4905 	SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
4906 	SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
4907 	SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4908 	SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4909 	SND_PCI_QUIRK(0x1043, 0x8516, "ASUS X101CH", ALC269_FIXUP_ASUS_X101),
4910 	SND_PCI_QUIRK(0x104d, 0x90b5, "Sony VAIO Pro 11", ALC286_FIXUP_SONY_MIC_NO_PRESENCE),
4911 	SND_PCI_QUIRK(0x104d, 0x90b6, "Sony VAIO Pro 13", ALC286_FIXUP_SONY_MIC_NO_PRESENCE),
4912 	SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
4913 	SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4914 	SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4915 	SND_PCI_QUIRK(0x104d, 0x9099, "Sony VAIO S13", ALC275_FIXUP_SONY_DISABLE_AAMIX),
4916 	SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
4917 	SND_PCI_QUIRK(0x10cf, 0x1845, "Lifebook U904", ALC269_FIXUP_LIFEBOOK_EXTMIC),
4918 	SND_PCI_QUIRK(0x144d, 0xc109, "Samsung Ativ book 9 (NP900X3G)", ALC269_FIXUP_INV_DMIC),
4919 	SND_PCI_QUIRK(0x1458, 0xfa53, "Gigabyte BXBT-2807", ALC283_FIXUP_BXBT2807_MIC),
4920 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
4921 	SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
4922 	SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
4923 	SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
4924 	SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
4925 	SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
4926 	SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
4927 	SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
4928 	SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
4929 	SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
4930 	SND_PCI_QUIRK(0x17aa, 0x2208, "Thinkpad T431s", ALC269_FIXUP_LENOVO_DOCK),
4931 	SND_PCI_QUIRK(0x17aa, 0x220c, "Thinkpad T440s", ALC292_FIXUP_TPT440_DOCK),
4932 	SND_PCI_QUIRK(0x17aa, 0x220e, "Thinkpad T440p", ALC292_FIXUP_TPT440_DOCK),
4933 	SND_PCI_QUIRK(0x17aa, 0x2210, "Thinkpad T540p", ALC292_FIXUP_TPT440_DOCK),
4934 	SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad T440", ALC292_FIXUP_TPT440_DOCK),
4935 	SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad X240", ALC292_FIXUP_TPT440_DOCK),
4936 	SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4937 	SND_PCI_QUIRK(0x17aa, 0x3977, "IdeaPad S210", ALC283_FIXUP_INT_MIC),
4938 	SND_PCI_QUIRK(0x17aa, 0x3978, "IdeaPad Y410P", ALC269_FIXUP_NO_SHUTUP),
4939 	SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4940 	SND_PCI_QUIRK(0x17aa, 0x501a, "Thinkpad", ALC283_FIXUP_INT_MIC),
4941 	SND_PCI_QUIRK(0x17aa, 0x501e, "Thinkpad L440", ALC292_FIXUP_TPT440_DOCK),
4942 	SND_PCI_QUIRK(0x17aa, 0x5026, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4943 	SND_PCI_QUIRK(0x17aa, 0x5109, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4944 	SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
4945 	SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
4946 	SND_PCI_QUIRK(0x1b7d, 0xa831, "Ordissimo EVE2 ", ALC269VB_FIXUP_ORDISSIMO_EVE2), /* Also known as Malata PC-B1303 */
4947 
4948 #if 0
4949 	/* Below is a quirk table taken from the old code.
4950 	 * Basically the device should work as is without the fixup table.
4951 	 * If BIOS doesn't give a proper info, enable the corresponding
4952 	 * fixup entry.
4953 	 */
4954 	SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
4955 		      ALC269_FIXUP_AMIC),
4956 	SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
4957 	SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
4958 	SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
4959 	SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
4960 	SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
4961 	SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
4962 	SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
4963 	SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
4964 	SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
4965 	SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
4966 	SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
4967 	SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
4968 	SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
4969 	SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
4970 	SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
4971 	SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
4972 	SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
4973 	SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
4974 	SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
4975 	SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
4976 	SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
4977 	SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
4978 	SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
4979 	SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
4980 	SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
4981 	SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
4982 	SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
4983 	SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
4984 	SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
4985 	SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
4986 	SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
4987 	SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
4988 	SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
4989 	SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
4990 	SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
4991 	SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
4992 	SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
4993 	SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
4994 	SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
4995 #endif
4996 	{}
4997 };
4998 
4999 static const struct snd_pci_quirk alc269_fixup_vendor_tbl[] = {
5000 	SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
5001 	SND_PCI_QUIRK_VENDOR(0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED),
5002 	SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5003 	SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad", ALC269_FIXUP_THINKPAD_ACPI),
5004 	{}
5005 };
5006 
5007 static const struct hda_model_fixup alc269_fixup_models[] = {
5008 	{.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5009 	{.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
5010 	{.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
5011 	{.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
5012 	{.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
5013 	{.id = ALC269_FIXUP_HEADSET_MIC, .name = "headset-mic"},
5014 	{.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
5015 	{.id = ALC269_FIXUP_HP_GPIO_LED, .name = "hp-gpio-led"},
5016 	{.id = ALC269_FIXUP_DELL1_MIC_NO_PRESENCE, .name = "dell-headset-multi"},
5017 	{.id = ALC269_FIXUP_DELL2_MIC_NO_PRESENCE, .name = "dell-headset-dock"},
5018 	{.id = ALC283_FIXUP_CHROME_BOOK, .name = "alc283-dac-wcaps"},
5019 	{.id = ALC283_FIXUP_SENSE_COMBO_JACK, .name = "alc283-sense-combo"},
5020 	{.id = ALC292_FIXUP_TPT440_DOCK, .name = "tpt440-dock"},
5021 	{}
5022 };
5023 
5024 #define ALC255_STANDARD_PINS \
5025 	{0x18, 0x411111f0}, \
5026 	{0x19, 0x411111f0}, \
5027 	{0x1a, 0x411111f0}, \
5028 	{0x1b, 0x411111f0}, \
5029 	{0x1e, 0x411111f0}
5030 
5031 #define ALC282_STANDARD_PINS \
5032 	{0x14, 0x90170110}, \
5033 	{0x18, 0x411111f0}, \
5034 	{0x1a, 0x411111f0}, \
5035 	{0x1b, 0x411111f0}, \
5036 	{0x1e, 0x411111f0}
5037 
5038 #define ALC290_STANDARD_PINS \
5039 	{0x12, 0x99a30130}, \
5040 	{0x13, 0x40000000}, \
5041 	{0x16, 0x411111f0}, \
5042 	{0x17, 0x411111f0}, \
5043 	{0x19, 0x411111f0}, \
5044 	{0x1b, 0x411111f0}, \
5045 	{0x1e, 0x411111f0}
5046 
5047 #define ALC292_STANDARD_PINS \
5048 	{0x14, 0x90170110}, \
5049 	{0x15, 0x0221401f}, \
5050 	{0x1a, 0x411111f0}, \
5051 	{0x1b, 0x411111f0}, \
5052 	{0x1d, 0x40700001}, \
5053 	{0x1e, 0x411111f0}
5054 
5055 static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
5056 	SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL2_MIC_NO_PRESENCE,
5057 		ALC255_STANDARD_PINS,
5058 		{0x12, 0x40300000},
5059 		{0x14, 0x90170110},
5060 		{0x17, 0x411111f0},
5061 		{0x1d, 0x40538029},
5062 		{0x21, 0x02211020}),
5063 	SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5064 		ALC255_STANDARD_PINS,
5065 		{0x12, 0x90a60140},
5066 		{0x14, 0x90170110},
5067 		{0x17, 0x40000000},
5068 		{0x1d, 0x40700001},
5069 		{0x21, 0x02211020}),
5070 	SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5071 		ALC255_STANDARD_PINS,
5072 		{0x12, 0x90a60160},
5073 		{0x14, 0x90170120},
5074 		{0x17, 0x40000000},
5075 		{0x1d, 0x40700001},
5076 		{0x21, 0x02211030}),
5077 	SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5078 		{0x12, 0x90a60160},
5079 		{0x14, 0x90170120},
5080 		{0x17, 0x90170140},
5081 		{0x18, 0x40000000},
5082 		{0x19, 0x411111f0},
5083 		{0x1a, 0x411111f0},
5084 		{0x1b, 0x411111f0},
5085 		{0x1d, 0x41163b05},
5086 		{0x1e, 0x411111f0},
5087 		{0x21, 0x0321102f}),
5088 	SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5089 		ALC255_STANDARD_PINS,
5090 		{0x12, 0x90a60160},
5091 		{0x14, 0x90170130},
5092 		{0x17, 0x40000000},
5093 		{0x1d, 0x40700001},
5094 		{0x21, 0x02211040}),
5095 	SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5096 		ALC255_STANDARD_PINS,
5097 		{0x12, 0x90a60160},
5098 		{0x14, 0x90170140},
5099 		{0x17, 0x40000000},
5100 		{0x1d, 0x40700001},
5101 		{0x21, 0x02211050}),
5102 	SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5103 		ALC255_STANDARD_PINS,
5104 		{0x12, 0x90a60170},
5105 		{0x14, 0x90170120},
5106 		{0x17, 0x40000000},
5107 		{0x1d, 0x40700001},
5108 		{0x21, 0x02211030}),
5109 	SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5110 		ALC255_STANDARD_PINS,
5111 		{0x12, 0x90a60170},
5112 		{0x14, 0x90170130},
5113 		{0x17, 0x40000000},
5114 		{0x1d, 0x40700001},
5115 		{0x21, 0x02211040}),
5116 	SND_HDA_PIN_QUIRK(0x10ec0280, 0x103c, "HP", ALC280_FIXUP_HP_GPIO4,
5117 		{0x12, 0x90a60130},
5118 		{0x13, 0x40000000},
5119 		{0x14, 0x90170110},
5120 		{0x15, 0x0421101f},
5121 		{0x16, 0x411111f0},
5122 		{0x17, 0x411111f0},
5123 		{0x18, 0x411111f0},
5124 		{0x19, 0x411111f0},
5125 		{0x1a, 0x04a11020},
5126 		{0x1b, 0x411111f0},
5127 		{0x1d, 0x40748605},
5128 		{0x1e, 0x411111f0}),
5129 	SND_HDA_PIN_QUIRK(0x10ec0280, 0x103c, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED,
5130 		{0x12, 0x90a60140},
5131 		{0x13, 0x40000000},
5132 		{0x14, 0x90170110},
5133 		{0x15, 0x0421101f},
5134 		{0x16, 0x411111f0},
5135 		{0x17, 0x411111f0},
5136 		{0x18, 0x02811030},
5137 		{0x19, 0x411111f0},
5138 		{0x1a, 0x04a1103f},
5139 		{0x1b, 0x02011020},
5140 		{0x1d, 0x40700001},
5141 		{0x1e, 0x411111f0}),
5142 	SND_HDA_PIN_QUIRK(0x10ec0282, 0x103c, "HP 15 Touchsmart", ALC269_FIXUP_HP_MUTE_LED_MIC1,
5143 		ALC282_STANDARD_PINS,
5144 		{0x12, 0x99a30130},
5145 		{0x17, 0x40000000},
5146 		{0x19, 0x03a11020},
5147 		{0x1d, 0x40f41905},
5148 		{0x21, 0x0321101f}),
5149 	SND_HDA_PIN_QUIRK(0x10ec0282, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
5150 		ALC282_STANDARD_PINS,
5151 		{0x12, 0x99a30130},
5152 		{0x17, 0x40020008},
5153 		{0x19, 0x03a11020},
5154 		{0x1d, 0x40e00001},
5155 		{0x21, 0x03211040}),
5156 	SND_HDA_PIN_QUIRK(0x10ec0282, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
5157 		ALC282_STANDARD_PINS,
5158 		{0x12, 0x99a30130},
5159 		{0x17, 0x40000000},
5160 		{0x19, 0x03a11030},
5161 		{0x1d, 0x40e00001},
5162 		{0x21, 0x03211020}),
5163 	SND_HDA_PIN_QUIRK(0x10ec0282, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
5164 		ALC282_STANDARD_PINS,
5165 		{0x12, 0x99a30130},
5166 		{0x17, 0x40000000},
5167 		{0x19, 0x03a11030},
5168 		{0x1d, 0x40f00001},
5169 		{0x21, 0x03211020}),
5170 	SND_HDA_PIN_QUIRK(0x10ec0282, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
5171 		ALC282_STANDARD_PINS,
5172 		{0x12, 0x99a30130},
5173 		{0x17, 0x40000000},
5174 		{0x19, 0x04a11020},
5175 		{0x1d, 0x40f00001},
5176 		{0x21, 0x0421101f}),
5177 	SND_HDA_PIN_QUIRK(0x10ec0282, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
5178 		ALC282_STANDARD_PINS,
5179 		{0x12, 0x99a30130},
5180 		{0x17, 0x40000000},
5181 		{0x19, 0x03a11030},
5182 		{0x1d, 0x40f00001},
5183 		{0x21, 0x04211020}),
5184 	SND_HDA_PIN_QUIRK(0x10ec0282, 0x103c, "HP", ALC269_FIXUP_HP_LINE1_MIC1_LED,
5185 		ALC282_STANDARD_PINS,
5186 		{0x12, 0x90a60140},
5187 		{0x17, 0x40000000},
5188 		{0x19, 0x04a11030},
5189 		{0x1d, 0x40f00001},
5190 		{0x21, 0x04211020}),
5191 	SND_HDA_PIN_QUIRK(0x10ec0283, 0x1028, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
5192 		ALC282_STANDARD_PINS,
5193 		{0x12, 0x90a60130},
5194 		{0x17, 0x40020008},
5195 		{0x19, 0x411111f0},
5196 		{0x1d, 0x40e00001},
5197 		{0x21, 0x0321101f}),
5198 	SND_HDA_PIN_QUIRK(0x10ec0283, 0x1028, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
5199 		{0x12, 0x90a60160},
5200 		{0x14, 0x90170120},
5201 		{0x17, 0x40000000},
5202 		{0x18, 0x411111f0},
5203 		{0x19, 0x411111f0},
5204 		{0x1a, 0x411111f0},
5205 		{0x1b, 0x411111f0},
5206 		{0x1d, 0x40700001},
5207 		{0x1e, 0x411111f0},
5208 		{0x21, 0x02211030}),
5209 	SND_HDA_PIN_QUIRK(0x10ec0283, 0x1028, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
5210 		ALC282_STANDARD_PINS,
5211 		{0x12, 0x90a60130},
5212 		{0x17, 0x40020008},
5213 		{0x19, 0x03a11020},
5214 		{0x1d, 0x40e00001},
5215 		{0x21, 0x0321101f}),
5216 	SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
5217 		ALC290_STANDARD_PINS,
5218 		{0x14, 0x411111f0},
5219 		{0x15, 0x04211040},
5220 		{0x18, 0x90170112},
5221 		{0x1a, 0x04a11020},
5222 		{0x1d, 0x4075812d}),
5223 	SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
5224 		ALC290_STANDARD_PINS,
5225 		{0x14, 0x411111f0},
5226 		{0x15, 0x04211040},
5227 		{0x18, 0x90170110},
5228 		{0x1a, 0x04a11020},
5229 		{0x1d, 0x4075812d}),
5230 	SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
5231 		ALC290_STANDARD_PINS,
5232 		{0x14, 0x411111f0},
5233 		{0x15, 0x0421101f},
5234 		{0x18, 0x411111f0},
5235 		{0x1a, 0x04a11020},
5236 		{0x1d, 0x4075812d}),
5237 	SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
5238 		ALC290_STANDARD_PINS,
5239 		{0x14, 0x411111f0},
5240 		{0x15, 0x04211020},
5241 		{0x18, 0x411111f0},
5242 		{0x1a, 0x04a11040},
5243 		{0x1d, 0x4076a12d}),
5244 	SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
5245 		ALC290_STANDARD_PINS,
5246 		{0x14, 0x90170110},
5247 		{0x15, 0x04211020},
5248 		{0x18, 0x411111f0},
5249 		{0x1a, 0x04a11040},
5250 		{0x1d, 0x4076a12d}),
5251 	SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
5252 		ALC290_STANDARD_PINS,
5253 		{0x14, 0x90170110},
5254 		{0x15, 0x04211020},
5255 		{0x18, 0x411111f0},
5256 		{0x1a, 0x04a11020},
5257 		{0x1d, 0x4076a12d}),
5258 	SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
5259 		ALC290_STANDARD_PINS,
5260 		{0x14, 0x90170110},
5261 		{0x15, 0x0421101f},
5262 		{0x18, 0x411111f0},
5263 		{0x1a, 0x04a11020},
5264 		{0x1d, 0x4075812d}),
5265 	SND_HDA_PIN_QUIRK(0x10ec0292, 0x1028, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE,
5266 		ALC292_STANDARD_PINS,
5267 		{0x12, 0x90a60140},
5268 		{0x13, 0x411111f0},
5269 		{0x16, 0x01014020},
5270 		{0x18, 0x411111f0},
5271 		{0x19, 0x01a19030}),
5272 	SND_HDA_PIN_QUIRK(0x10ec0292, 0x1028, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE,
5273 		ALC292_STANDARD_PINS,
5274 		{0x12, 0x90a60140},
5275 		{0x13, 0x411111f0},
5276 		{0x16, 0x01014020},
5277 		{0x18, 0x02a19031},
5278 		{0x19, 0x01a1903e}),
5279 	SND_HDA_PIN_QUIRK(0x10ec0292, 0x1028, "Dell", ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
5280 		ALC292_STANDARD_PINS,
5281 		{0x12, 0x90a60140},
5282 		{0x13, 0x411111f0},
5283 		{0x16, 0x411111f0},
5284 		{0x18, 0x411111f0},
5285 		{0x19, 0x411111f0}),
5286 	SND_HDA_PIN_QUIRK(0x10ec0293, 0x1028, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE,
5287 		ALC292_STANDARD_PINS,
5288 		{0x12, 0x40000000},
5289 		{0x13, 0x90a60140},
5290 		{0x16, 0x21014020},
5291 		{0x18, 0x411111f0},
5292 		{0x19, 0x21a19030}),
5293 	SND_HDA_PIN_QUIRK(0x10ec0293, 0x1028, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE,
5294 		ALC292_STANDARD_PINS,
5295 		{0x12, 0x40000000},
5296 		{0x13, 0x90a60140},
5297 		{0x16, 0x411111f0},
5298 		{0x18, 0x411111f0},
5299 		{0x19, 0x411111f0}),
5300 	{}
5301 };
5302 
5303 static void alc269_fill_coef(struct hda_codec *codec)
5304 {
5305 	struct alc_spec *spec = codec->spec;
5306 	int val;
5307 
5308 	if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5309 		return;
5310 
5311 	if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
5312 		alc_write_coef_idx(codec, 0xf, 0x960b);
5313 		alc_write_coef_idx(codec, 0xe, 0x8817);
5314 	}
5315 
5316 	if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
5317 		alc_write_coef_idx(codec, 0xf, 0x960b);
5318 		alc_write_coef_idx(codec, 0xe, 0x8814);
5319 	}
5320 
5321 	if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
5322 		/* Power up output pin */
5323 		alc_update_coef_idx(codec, 0x04, 0, 1<<11);
5324 	}
5325 
5326 	if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
5327 		val = alc_read_coef_idx(codec, 0xd);
5328 		if (val != -1 && (val & 0x0c00) >> 10 != 0x1) {
5329 			/* Capless ramp up clock control */
5330 			alc_write_coef_idx(codec, 0xd, val | (1<<10));
5331 		}
5332 		val = alc_read_coef_idx(codec, 0x17);
5333 		if (val != -1 && (val & 0x01c0) >> 6 != 0x4) {
5334 			/* Class D power on reset */
5335 			alc_write_coef_idx(codec, 0x17, val | (1<<7));
5336 		}
5337 	}
5338 
5339 	/* HP */
5340 	alc_update_coef_idx(codec, 0x4, 0, 1<<11);
5341 }
5342 
5343 /*
5344  */
5345 static int patch_alc269(struct hda_codec *codec)
5346 {
5347 	struct alc_spec *spec;
5348 	int err;
5349 
5350 	err = alc_alloc_spec(codec, 0x0b);
5351 	if (err < 0)
5352 		return err;
5353 
5354 	spec = codec->spec;
5355 	spec->gen.shared_mic_vref_pin = 0x18;
5356 
5357 	snd_hda_pick_fixup(codec, alc269_fixup_models,
5358 		       alc269_fixup_tbl, alc269_fixups);
5359 	snd_hda_pick_pin_fixup(codec, alc269_pin_fixup_tbl, alc269_fixups);
5360 	snd_hda_pick_fixup(codec, NULL,	alc269_fixup_vendor_tbl,
5361 			   alc269_fixups);
5362 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5363 
5364 	alc_auto_parse_customize_define(codec);
5365 
5366 	if (has_cdefine_beep(codec))
5367 		spec->gen.beep_nid = 0x01;
5368 
5369 	switch (codec->vendor_id) {
5370 	case 0x10ec0269:
5371 		spec->codec_variant = ALC269_TYPE_ALC269VA;
5372 		switch (alc_get_coef0(codec) & 0x00f0) {
5373 		case 0x0010:
5374 			if (codec->bus->pci &&
5375 			    codec->bus->pci->subsystem_vendor == 0x1025 &&
5376 			    spec->cdefine.platform_type == 1)
5377 				err = alc_codec_rename(codec, "ALC271X");
5378 			spec->codec_variant = ALC269_TYPE_ALC269VB;
5379 			break;
5380 		case 0x0020:
5381 			if (codec->bus->pci &&
5382 			    codec->bus->pci->subsystem_vendor == 0x17aa &&
5383 			    codec->bus->pci->subsystem_device == 0x21f3)
5384 				err = alc_codec_rename(codec, "ALC3202");
5385 			spec->codec_variant = ALC269_TYPE_ALC269VC;
5386 			break;
5387 		case 0x0030:
5388 			spec->codec_variant = ALC269_TYPE_ALC269VD;
5389 			break;
5390 		default:
5391 			alc_fix_pll_init(codec, 0x20, 0x04, 15);
5392 		}
5393 		if (err < 0)
5394 			goto error;
5395 		spec->init_hook = alc269_fill_coef;
5396 		alc269_fill_coef(codec);
5397 		break;
5398 
5399 	case 0x10ec0280:
5400 	case 0x10ec0290:
5401 		spec->codec_variant = ALC269_TYPE_ALC280;
5402 		break;
5403 	case 0x10ec0282:
5404 		spec->codec_variant = ALC269_TYPE_ALC282;
5405 		spec->shutup = alc282_shutup;
5406 		spec->init_hook = alc282_init;
5407 		break;
5408 	case 0x10ec0233:
5409 	case 0x10ec0283:
5410 		spec->codec_variant = ALC269_TYPE_ALC283;
5411 		spec->shutup = alc283_shutup;
5412 		spec->init_hook = alc283_init;
5413 		break;
5414 	case 0x10ec0284:
5415 	case 0x10ec0292:
5416 		spec->codec_variant = ALC269_TYPE_ALC284;
5417 		break;
5418 	case 0x10ec0285:
5419 	case 0x10ec0293:
5420 		spec->codec_variant = ALC269_TYPE_ALC285;
5421 		break;
5422 	case 0x10ec0286:
5423 	case 0x10ec0288:
5424 		spec->codec_variant = ALC269_TYPE_ALC286;
5425 		spec->shutup = alc286_shutup;
5426 		break;
5427 	case 0x10ec0298:
5428 		spec->codec_variant = ALC269_TYPE_ALC298;
5429 		break;
5430 	case 0x10ec0255:
5431 		spec->codec_variant = ALC269_TYPE_ALC255;
5432 		break;
5433 	case 0x10ec0256:
5434 		spec->codec_variant = ALC269_TYPE_ALC256;
5435 		break;
5436 	}
5437 
5438 	if (snd_hda_codec_read(codec, 0x51, 0, AC_VERB_PARAMETERS, 0) == 0x10ec5505) {
5439 		spec->has_alc5505_dsp = 1;
5440 		spec->init_hook = alc5505_dsp_init;
5441 	}
5442 
5443 	/* automatic parse from the BIOS config */
5444 	err = alc269_parse_auto_config(codec);
5445 	if (err < 0)
5446 		goto error;
5447 
5448 	if (!spec->gen.no_analog && spec->gen.beep_nid)
5449 		set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5450 
5451 	codec->patch_ops = alc_patch_ops;
5452 #ifdef CONFIG_PM
5453 	codec->patch_ops.suspend = alc269_suspend;
5454 	codec->patch_ops.resume = alc269_resume;
5455 #endif
5456 	if (!spec->shutup)
5457 		spec->shutup = alc269_shutup;
5458 
5459 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5460 
5461 	return 0;
5462 
5463  error:
5464 	alc_free(codec);
5465 	return err;
5466 }
5467 
5468 /*
5469  * ALC861
5470  */
5471 
5472 static int alc861_parse_auto_config(struct hda_codec *codec)
5473 {
5474 	static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
5475 	static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5476 	return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
5477 }
5478 
5479 /* Pin config fixes */
5480 enum {
5481 	ALC861_FIXUP_FSC_AMILO_PI1505,
5482 	ALC861_FIXUP_AMP_VREF_0F,
5483 	ALC861_FIXUP_NO_JACK_DETECT,
5484 	ALC861_FIXUP_ASUS_A6RP,
5485 	ALC660_FIXUP_ASUS_W7J,
5486 };
5487 
5488 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
5489 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
5490 			const struct hda_fixup *fix, int action)
5491 {
5492 	struct alc_spec *spec = codec->spec;
5493 	unsigned int val;
5494 
5495 	if (action != HDA_FIXUP_ACT_INIT)
5496 		return;
5497 	val = snd_hda_codec_get_pin_target(codec, 0x0f);
5498 	if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
5499 		val |= AC_PINCTL_IN_EN;
5500 	val |= AC_PINCTL_VREF_50;
5501 	snd_hda_set_pin_ctl(codec, 0x0f, val);
5502 	spec->gen.keep_vref_in_automute = 1;
5503 }
5504 
5505 /* suppress the jack-detection */
5506 static void alc_fixup_no_jack_detect(struct hda_codec *codec,
5507 				     const struct hda_fixup *fix, int action)
5508 {
5509 	if (action == HDA_FIXUP_ACT_PRE_PROBE)
5510 		codec->no_jack_detect = 1;
5511 }
5512 
5513 static const struct hda_fixup alc861_fixups[] = {
5514 	[ALC861_FIXUP_FSC_AMILO_PI1505] = {
5515 		.type = HDA_FIXUP_PINS,
5516 		.v.pins = (const struct hda_pintbl[]) {
5517 			{ 0x0b, 0x0221101f }, /* HP */
5518 			{ 0x0f, 0x90170310 }, /* speaker */
5519 			{ }
5520 		}
5521 	},
5522 	[ALC861_FIXUP_AMP_VREF_0F] = {
5523 		.type = HDA_FIXUP_FUNC,
5524 		.v.func = alc861_fixup_asus_amp_vref_0f,
5525 	},
5526 	[ALC861_FIXUP_NO_JACK_DETECT] = {
5527 		.type = HDA_FIXUP_FUNC,
5528 		.v.func = alc_fixup_no_jack_detect,
5529 	},
5530 	[ALC861_FIXUP_ASUS_A6RP] = {
5531 		.type = HDA_FIXUP_FUNC,
5532 		.v.func = alc861_fixup_asus_amp_vref_0f,
5533 		.chained = true,
5534 		.chain_id = ALC861_FIXUP_NO_JACK_DETECT,
5535 	},
5536 	[ALC660_FIXUP_ASUS_W7J] = {
5537 		.type = HDA_FIXUP_VERBS,
5538 		.v.verbs = (const struct hda_verb[]) {
5539 			/* ASUS W7J needs a magic pin setup on unused NID 0x10
5540 			 * for enabling outputs
5541 			 */
5542 			{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5543 			{ }
5544 		},
5545 	}
5546 };
5547 
5548 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5549 	SND_PCI_QUIRK(0x1043, 0x1253, "ASUS W7J", ALC660_FIXUP_ASUS_W7J),
5550 	SND_PCI_QUIRK(0x1043, 0x1263, "ASUS Z35HL", ALC660_FIXUP_ASUS_W7J),
5551 	SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
5552 	SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
5553 	SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
5554 	SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
5555 	SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
5556 	SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
5557 	{}
5558 };
5559 
5560 /*
5561  */
5562 static int patch_alc861(struct hda_codec *codec)
5563 {
5564 	struct alc_spec *spec;
5565 	int err;
5566 
5567 	err = alc_alloc_spec(codec, 0x15);
5568 	if (err < 0)
5569 		return err;
5570 
5571 	spec = codec->spec;
5572 	spec->gen.beep_nid = 0x23;
5573 
5574 	snd_hda_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5575 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5576 
5577 	/* automatic parse from the BIOS config */
5578 	err = alc861_parse_auto_config(codec);
5579 	if (err < 0)
5580 		goto error;
5581 
5582 	if (!spec->gen.no_analog)
5583 		set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5584 
5585 	codec->patch_ops = alc_patch_ops;
5586 #ifdef CONFIG_PM
5587 	spec->power_hook = alc_power_eapd;
5588 #endif
5589 
5590 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5591 
5592 	return 0;
5593 
5594  error:
5595 	alc_free(codec);
5596 	return err;
5597 }
5598 
5599 /*
5600  * ALC861-VD support
5601  *
5602  * Based on ALC882
5603  *
5604  * In addition, an independent DAC
5605  */
5606 static int alc861vd_parse_auto_config(struct hda_codec *codec)
5607 {
5608 	static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
5609 	static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5610 	return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
5611 }
5612 
5613 enum {
5614 	ALC660VD_FIX_ASUS_GPIO1,
5615 	ALC861VD_FIX_DALLAS,
5616 };
5617 
5618 /* exclude VREF80 */
5619 static void alc861vd_fixup_dallas(struct hda_codec *codec,
5620 				  const struct hda_fixup *fix, int action)
5621 {
5622 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
5623 		snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
5624 		snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
5625 	}
5626 }
5627 
5628 static const struct hda_fixup alc861vd_fixups[] = {
5629 	[ALC660VD_FIX_ASUS_GPIO1] = {
5630 		.type = HDA_FIXUP_VERBS,
5631 		.v.verbs = (const struct hda_verb[]) {
5632 			/* reset GPIO1 */
5633 			{0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5634 			{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5635 			{0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5636 			{ }
5637 		}
5638 	},
5639 	[ALC861VD_FIX_DALLAS] = {
5640 		.type = HDA_FIXUP_FUNC,
5641 		.v.func = alc861vd_fixup_dallas,
5642 	},
5643 };
5644 
5645 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5646 	SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
5647 	SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5648 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
5649 	{}
5650 };
5651 
5652 /*
5653  */
5654 static int patch_alc861vd(struct hda_codec *codec)
5655 {
5656 	struct alc_spec *spec;
5657 	int err;
5658 
5659 	err = alc_alloc_spec(codec, 0x0b);
5660 	if (err < 0)
5661 		return err;
5662 
5663 	spec = codec->spec;
5664 	spec->gen.beep_nid = 0x23;
5665 
5666 	snd_hda_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5667 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5668 
5669 	/* automatic parse from the BIOS config */
5670 	err = alc861vd_parse_auto_config(codec);
5671 	if (err < 0)
5672 		goto error;
5673 
5674 	if (!spec->gen.no_analog)
5675 		set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5676 
5677 	codec->patch_ops = alc_patch_ops;
5678 
5679 	spec->shutup = alc_eapd_shutup;
5680 
5681 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5682 
5683 	return 0;
5684 
5685  error:
5686 	alc_free(codec);
5687 	return err;
5688 }
5689 
5690 /*
5691  * ALC662 support
5692  *
5693  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5694  * configuration.  Each pin widget can choose any input DACs and a mixer.
5695  * Each ADC is connected from a mixer of all inputs.  This makes possible
5696  * 6-channel independent captures.
5697  *
5698  * In addition, an independent DAC for the multi-playback (not used in this
5699  * driver yet).
5700  */
5701 
5702 /*
5703  * BIOS auto configuration
5704  */
5705 
5706 static int alc662_parse_auto_config(struct hda_codec *codec)
5707 {
5708 	static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
5709 	static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5710 	static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5711 	const hda_nid_t *ssids;
5712 
5713 	if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5714 	    codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670 ||
5715 	    codec->vendor_id == 0x10ec0671)
5716 		ssids = alc663_ssids;
5717 	else
5718 		ssids = alc662_ssids;
5719 	return alc_parse_auto_config(codec, alc662_ignore, ssids);
5720 }
5721 
5722 static void alc272_fixup_mario(struct hda_codec *codec,
5723 			       const struct hda_fixup *fix, int action)
5724 {
5725 	if (action != HDA_FIXUP_ACT_PRE_PROBE)
5726 		return;
5727 	if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5728 				      (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5729 				      (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5730 				      (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5731 				      (0 << AC_AMPCAP_MUTE_SHIFT)))
5732 		codec_warn(codec, "failed to override amp caps for NID 0x2\n");
5733 }
5734 
5735 static const struct snd_pcm_chmap_elem asus_pcm_2_1_chmaps[] = {
5736 	{ .channels = 2,
5737 	  .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } },
5738 	{ .channels = 4,
5739 	  .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
5740 		   SNDRV_CHMAP_NA, SNDRV_CHMAP_LFE } }, /* LFE only on right */
5741 	{ }
5742 };
5743 
5744 /* override the 2.1 chmap */
5745 static void alc_fixup_bass_chmap(struct hda_codec *codec,
5746 				    const struct hda_fixup *fix, int action)
5747 {
5748 	if (action == HDA_FIXUP_ACT_BUILD) {
5749 		struct alc_spec *spec = codec->spec;
5750 		spec->gen.pcm_rec[0].stream[0].chmap = asus_pcm_2_1_chmaps;
5751 	}
5752 }
5753 
5754 /* avoid D3 for keeping GPIO up */
5755 static unsigned int gpio_led_power_filter(struct hda_codec *codec,
5756 					  hda_nid_t nid,
5757 					  unsigned int power_state)
5758 {
5759 	struct alc_spec *spec = codec->spec;
5760 	if (nid == codec->afg && power_state == AC_PWRST_D3 && spec->gpio_led)
5761 		return AC_PWRST_D0;
5762 	return power_state;
5763 }
5764 
5765 static void alc662_fixup_led_gpio1(struct hda_codec *codec,
5766 				   const struct hda_fixup *fix, int action)
5767 {
5768 	struct alc_spec *spec = codec->spec;
5769 	static const struct hda_verb gpio_init[] = {
5770 		{ 0x01, AC_VERB_SET_GPIO_MASK, 0x01 },
5771 		{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 },
5772 		{}
5773 	};
5774 
5775 	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
5776 		spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
5777 		spec->gpio_led = 0;
5778 		spec->mute_led_polarity = 1;
5779 		spec->gpio_mute_led_mask = 0x01;
5780 		snd_hda_add_verbs(codec, gpio_init);
5781 		codec->power_filter = gpio_led_power_filter;
5782 	}
5783 }
5784 
5785 static struct coef_fw alc668_coefs[] = {
5786 	WRITE_COEF(0x01, 0xbebe), WRITE_COEF(0x02, 0xaaaa), WRITE_COEF(0x03,    0x0),
5787 	WRITE_COEF(0x04, 0x0180), WRITE_COEF(0x06,    0x0), WRITE_COEF(0x07, 0x0f80),
5788 	WRITE_COEF(0x08, 0x0031), WRITE_COEF(0x0a, 0x0060), WRITE_COEF(0x0b,    0x0),
5789 	WRITE_COEF(0x0c, 0x7cf7), WRITE_COEF(0x0d, 0x1080), WRITE_COEF(0x0e, 0x7f7f),
5790 	WRITE_COEF(0x0f, 0xcccc), WRITE_COEF(0x10, 0xddcc), WRITE_COEF(0x11, 0x0001),
5791 	WRITE_COEF(0x13,    0x0), WRITE_COEF(0x14, 0x2aa0), WRITE_COEF(0x17, 0xa940),
5792 	WRITE_COEF(0x19,    0x0), WRITE_COEF(0x1a,    0x0), WRITE_COEF(0x1b,    0x0),
5793 	WRITE_COEF(0x1c,    0x0), WRITE_COEF(0x1d,    0x0), WRITE_COEF(0x1e, 0x7418),
5794 	WRITE_COEF(0x1f, 0x0804), WRITE_COEF(0x20, 0x4200), WRITE_COEF(0x21, 0x0468),
5795 	WRITE_COEF(0x22, 0x8ccc), WRITE_COEF(0x23, 0x0250), WRITE_COEF(0x24, 0x7418),
5796 	WRITE_COEF(0x27,    0x0), WRITE_COEF(0x28, 0x8ccc), WRITE_COEF(0x2a, 0xff00),
5797 	WRITE_COEF(0x2b, 0x8000), WRITE_COEF(0xa7, 0xff00), WRITE_COEF(0xa8, 0x8000),
5798 	WRITE_COEF(0xaa, 0x2e17), WRITE_COEF(0xab, 0xa0c0), WRITE_COEF(0xac,    0x0),
5799 	WRITE_COEF(0xad,    0x0), WRITE_COEF(0xae, 0x2ac6), WRITE_COEF(0xaf, 0xa480),
5800 	WRITE_COEF(0xb0,    0x0), WRITE_COEF(0xb1,    0x0), WRITE_COEF(0xb2,    0x0),
5801 	WRITE_COEF(0xb3,    0x0), WRITE_COEF(0xb4,    0x0), WRITE_COEF(0xb5, 0x1040),
5802 	WRITE_COEF(0xb6, 0xd697), WRITE_COEF(0xb7, 0x902b), WRITE_COEF(0xb8, 0xd697),
5803 	WRITE_COEF(0xb9, 0x902b), WRITE_COEF(0xba, 0xb8ba), WRITE_COEF(0xbb, 0xaaab),
5804 	WRITE_COEF(0xbc, 0xaaaf), WRITE_COEF(0xbd, 0x6aaa), WRITE_COEF(0xbe, 0x1c02),
5805 	WRITE_COEF(0xc0, 0x00ff), WRITE_COEF(0xc1, 0x0fa6),
5806 	{}
5807 };
5808 
5809 static void alc668_restore_default_value(struct hda_codec *codec)
5810 {
5811 	alc_process_coef_fw(codec, alc668_coefs);
5812 }
5813 
5814 enum {
5815 	ALC662_FIXUP_ASPIRE,
5816 	ALC662_FIXUP_LED_GPIO1,
5817 	ALC662_FIXUP_IDEAPAD,
5818 	ALC272_FIXUP_MARIO,
5819 	ALC662_FIXUP_CZC_P10T,
5820 	ALC662_FIXUP_SKU_IGNORE,
5821 	ALC662_FIXUP_HP_RP5800,
5822 	ALC662_FIXUP_ASUS_MODE1,
5823 	ALC662_FIXUP_ASUS_MODE2,
5824 	ALC662_FIXUP_ASUS_MODE3,
5825 	ALC662_FIXUP_ASUS_MODE4,
5826 	ALC662_FIXUP_ASUS_MODE5,
5827 	ALC662_FIXUP_ASUS_MODE6,
5828 	ALC662_FIXUP_ASUS_MODE7,
5829 	ALC662_FIXUP_ASUS_MODE8,
5830 	ALC662_FIXUP_NO_JACK_DETECT,
5831 	ALC662_FIXUP_ZOTAC_Z68,
5832 	ALC662_FIXUP_INV_DMIC,
5833 	ALC668_FIXUP_DELL_MIC_NO_PRESENCE,
5834 	ALC668_FIXUP_HEADSET_MODE,
5835 	ALC662_FIXUP_BASS_MODE4_CHMAP,
5836 	ALC662_FIXUP_BASS_16,
5837 	ALC662_FIXUP_BASS_1A,
5838 	ALC662_FIXUP_BASS_CHMAP,
5839 	ALC668_FIXUP_AUTO_MUTE,
5840 	ALC668_FIXUP_DELL_DISABLE_AAMIX,
5841 	ALC668_FIXUP_DELL_XPS13,
5842 };
5843 
5844 static const struct hda_fixup alc662_fixups[] = {
5845 	[ALC662_FIXUP_ASPIRE] = {
5846 		.type = HDA_FIXUP_PINS,
5847 		.v.pins = (const struct hda_pintbl[]) {
5848 			{ 0x15, 0x99130112 }, /* subwoofer */
5849 			{ }
5850 		}
5851 	},
5852 	[ALC662_FIXUP_LED_GPIO1] = {
5853 		.type = HDA_FIXUP_FUNC,
5854 		.v.func = alc662_fixup_led_gpio1,
5855 	},
5856 	[ALC662_FIXUP_IDEAPAD] = {
5857 		.type = HDA_FIXUP_PINS,
5858 		.v.pins = (const struct hda_pintbl[]) {
5859 			{ 0x17, 0x99130112 }, /* subwoofer */
5860 			{ }
5861 		},
5862 		.chained = true,
5863 		.chain_id = ALC662_FIXUP_LED_GPIO1,
5864 	},
5865 	[ALC272_FIXUP_MARIO] = {
5866 		.type = HDA_FIXUP_FUNC,
5867 		.v.func = alc272_fixup_mario,
5868 	},
5869 	[ALC662_FIXUP_CZC_P10T] = {
5870 		.type = HDA_FIXUP_VERBS,
5871 		.v.verbs = (const struct hda_verb[]) {
5872 			{0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5873 			{}
5874 		}
5875 	},
5876 	[ALC662_FIXUP_SKU_IGNORE] = {
5877 		.type = HDA_FIXUP_FUNC,
5878 		.v.func = alc_fixup_sku_ignore,
5879 	},
5880 	[ALC662_FIXUP_HP_RP5800] = {
5881 		.type = HDA_FIXUP_PINS,
5882 		.v.pins = (const struct hda_pintbl[]) {
5883 			{ 0x14, 0x0221201f }, /* HP out */
5884 			{ }
5885 		},
5886 		.chained = true,
5887 		.chain_id = ALC662_FIXUP_SKU_IGNORE
5888 	},
5889 	[ALC662_FIXUP_ASUS_MODE1] = {
5890 		.type = HDA_FIXUP_PINS,
5891 		.v.pins = (const struct hda_pintbl[]) {
5892 			{ 0x14, 0x99130110 }, /* speaker */
5893 			{ 0x18, 0x01a19c20 }, /* mic */
5894 			{ 0x19, 0x99a3092f }, /* int-mic */
5895 			{ 0x21, 0x0121401f }, /* HP out */
5896 			{ }
5897 		},
5898 		.chained = true,
5899 		.chain_id = ALC662_FIXUP_SKU_IGNORE
5900 	},
5901 	[ALC662_FIXUP_ASUS_MODE2] = {
5902 		.type = HDA_FIXUP_PINS,
5903 		.v.pins = (const struct hda_pintbl[]) {
5904 			{ 0x14, 0x99130110 }, /* speaker */
5905 			{ 0x18, 0x01a19820 }, /* mic */
5906 			{ 0x19, 0x99a3092f }, /* int-mic */
5907 			{ 0x1b, 0x0121401f }, /* HP out */
5908 			{ }
5909 		},
5910 		.chained = true,
5911 		.chain_id = ALC662_FIXUP_SKU_IGNORE
5912 	},
5913 	[ALC662_FIXUP_ASUS_MODE3] = {
5914 		.type = HDA_FIXUP_PINS,
5915 		.v.pins = (const struct hda_pintbl[]) {
5916 			{ 0x14, 0x99130110 }, /* speaker */
5917 			{ 0x15, 0x0121441f }, /* HP */
5918 			{ 0x18, 0x01a19840 }, /* mic */
5919 			{ 0x19, 0x99a3094f }, /* int-mic */
5920 			{ 0x21, 0x01211420 }, /* HP2 */
5921 			{ }
5922 		},
5923 		.chained = true,
5924 		.chain_id = ALC662_FIXUP_SKU_IGNORE
5925 	},
5926 	[ALC662_FIXUP_ASUS_MODE4] = {
5927 		.type = HDA_FIXUP_PINS,
5928 		.v.pins = (const struct hda_pintbl[]) {
5929 			{ 0x14, 0x99130110 }, /* speaker */
5930 			{ 0x16, 0x99130111 }, /* speaker */
5931 			{ 0x18, 0x01a19840 }, /* mic */
5932 			{ 0x19, 0x99a3094f }, /* int-mic */
5933 			{ 0x21, 0x0121441f }, /* HP */
5934 			{ }
5935 		},
5936 		.chained = true,
5937 		.chain_id = ALC662_FIXUP_SKU_IGNORE
5938 	},
5939 	[ALC662_FIXUP_ASUS_MODE5] = {
5940 		.type = HDA_FIXUP_PINS,
5941 		.v.pins = (const struct hda_pintbl[]) {
5942 			{ 0x14, 0x99130110 }, /* speaker */
5943 			{ 0x15, 0x0121441f }, /* HP */
5944 			{ 0x16, 0x99130111 }, /* speaker */
5945 			{ 0x18, 0x01a19840 }, /* mic */
5946 			{ 0x19, 0x99a3094f }, /* int-mic */
5947 			{ }
5948 		},
5949 		.chained = true,
5950 		.chain_id = ALC662_FIXUP_SKU_IGNORE
5951 	},
5952 	[ALC662_FIXUP_ASUS_MODE6] = {
5953 		.type = HDA_FIXUP_PINS,
5954 		.v.pins = (const struct hda_pintbl[]) {
5955 			{ 0x14, 0x99130110 }, /* speaker */
5956 			{ 0x15, 0x01211420 }, /* HP2 */
5957 			{ 0x18, 0x01a19840 }, /* mic */
5958 			{ 0x19, 0x99a3094f }, /* int-mic */
5959 			{ 0x1b, 0x0121441f }, /* HP */
5960 			{ }
5961 		},
5962 		.chained = true,
5963 		.chain_id = ALC662_FIXUP_SKU_IGNORE
5964 	},
5965 	[ALC662_FIXUP_ASUS_MODE7] = {
5966 		.type = HDA_FIXUP_PINS,
5967 		.v.pins = (const struct hda_pintbl[]) {
5968 			{ 0x14, 0x99130110 }, /* speaker */
5969 			{ 0x17, 0x99130111 }, /* speaker */
5970 			{ 0x18, 0x01a19840 }, /* mic */
5971 			{ 0x19, 0x99a3094f }, /* int-mic */
5972 			{ 0x1b, 0x01214020 }, /* HP */
5973 			{ 0x21, 0x0121401f }, /* HP */
5974 			{ }
5975 		},
5976 		.chained = true,
5977 		.chain_id = ALC662_FIXUP_SKU_IGNORE
5978 	},
5979 	[ALC662_FIXUP_ASUS_MODE8] = {
5980 		.type = HDA_FIXUP_PINS,
5981 		.v.pins = (const struct hda_pintbl[]) {
5982 			{ 0x14, 0x99130110 }, /* speaker */
5983 			{ 0x12, 0x99a30970 }, /* int-mic */
5984 			{ 0x15, 0x01214020 }, /* HP */
5985 			{ 0x17, 0x99130111 }, /* speaker */
5986 			{ 0x18, 0x01a19840 }, /* mic */
5987 			{ 0x21, 0x0121401f }, /* HP */
5988 			{ }
5989 		},
5990 		.chained = true,
5991 		.chain_id = ALC662_FIXUP_SKU_IGNORE
5992 	},
5993 	[ALC662_FIXUP_NO_JACK_DETECT] = {
5994 		.type = HDA_FIXUP_FUNC,
5995 		.v.func = alc_fixup_no_jack_detect,
5996 	},
5997 	[ALC662_FIXUP_ZOTAC_Z68] = {
5998 		.type = HDA_FIXUP_PINS,
5999 		.v.pins = (const struct hda_pintbl[]) {
6000 			{ 0x1b, 0x02214020 }, /* Front HP */
6001 			{ }
6002 		}
6003 	},
6004 	[ALC662_FIXUP_INV_DMIC] = {
6005 		.type = HDA_FIXUP_FUNC,
6006 		.v.func = alc_fixup_inv_dmic,
6007 	},
6008 	[ALC668_FIXUP_DELL_XPS13] = {
6009 		.type = HDA_FIXUP_FUNC,
6010 		.v.func = alc_fixup_dell_xps13,
6011 		.chained = true,
6012 		.chain_id = ALC668_FIXUP_DELL_DISABLE_AAMIX
6013 	},
6014 	[ALC668_FIXUP_DELL_DISABLE_AAMIX] = {
6015 		.type = HDA_FIXUP_FUNC,
6016 		.v.func = alc_fixup_disable_aamix,
6017 		.chained = true,
6018 		.chain_id = ALC668_FIXUP_DELL_MIC_NO_PRESENCE
6019 	},
6020 	[ALC668_FIXUP_AUTO_MUTE] = {
6021 		.type = HDA_FIXUP_FUNC,
6022 		.v.func = alc_fixup_auto_mute_via_amp,
6023 		.chained = true,
6024 		.chain_id = ALC668_FIXUP_DELL_MIC_NO_PRESENCE
6025 	},
6026 	[ALC668_FIXUP_DELL_MIC_NO_PRESENCE] = {
6027 		.type = HDA_FIXUP_PINS,
6028 		.v.pins = (const struct hda_pintbl[]) {
6029 			{ 0x19, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
6030 			{ 0x1b, 0x03a1113c }, /* use as headset mic, without its own jack detect */
6031 			{ }
6032 		},
6033 		.chained = true,
6034 		.chain_id = ALC668_FIXUP_HEADSET_MODE
6035 	},
6036 	[ALC668_FIXUP_HEADSET_MODE] = {
6037 		.type = HDA_FIXUP_FUNC,
6038 		.v.func = alc_fixup_headset_mode_alc668,
6039 	},
6040 	[ALC662_FIXUP_BASS_MODE4_CHMAP] = {
6041 		.type = HDA_FIXUP_FUNC,
6042 		.v.func = alc_fixup_bass_chmap,
6043 		.chained = true,
6044 		.chain_id = ALC662_FIXUP_ASUS_MODE4
6045 	},
6046 	[ALC662_FIXUP_BASS_16] = {
6047 		.type = HDA_FIXUP_PINS,
6048 		.v.pins = (const struct hda_pintbl[]) {
6049 			{0x16, 0x80106111}, /* bass speaker */
6050 			{}
6051 		},
6052 		.chained = true,
6053 		.chain_id = ALC662_FIXUP_BASS_CHMAP,
6054 	},
6055 	[ALC662_FIXUP_BASS_1A] = {
6056 		.type = HDA_FIXUP_PINS,
6057 		.v.pins = (const struct hda_pintbl[]) {
6058 			{0x1a, 0x80106111}, /* bass speaker */
6059 			{}
6060 		},
6061 		.chained = true,
6062 		.chain_id = ALC662_FIXUP_BASS_CHMAP,
6063 	},
6064 	[ALC662_FIXUP_BASS_CHMAP] = {
6065 		.type = HDA_FIXUP_FUNC,
6066 		.v.func = alc_fixup_bass_chmap,
6067 	},
6068 };
6069 
6070 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
6071 	SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
6072 	SND_PCI_QUIRK(0x1025, 0x022f, "Acer Aspire One", ALC662_FIXUP_INV_DMIC),
6073 	SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
6074 	SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
6075 	SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
6076 	SND_PCI_QUIRK(0x1025, 0x034a, "Gateway LT27", ALC662_FIXUP_INV_DMIC),
6077 	SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
6078 	SND_PCI_QUIRK(0x1028, 0x05d8, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
6079 	SND_PCI_QUIRK(0x1028, 0x05db, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
6080 	SND_PCI_QUIRK(0x1028, 0x05fe, "Dell XPS 15", ALC668_FIXUP_DELL_XPS13),
6081 	SND_PCI_QUIRK(0x1028, 0x060a, "Dell XPS 13", ALC668_FIXUP_DELL_XPS13),
6082 	SND_PCI_QUIRK(0x1028, 0x0625, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
6083 	SND_PCI_QUIRK(0x1028, 0x0626, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
6084 	SND_PCI_QUIRK(0x1028, 0x0696, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
6085 	SND_PCI_QUIRK(0x1028, 0x0698, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
6086 	SND_PCI_QUIRK(0x1028, 0x069f, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
6087 	SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
6088 	SND_PCI_QUIRK(0x1043, 0x11cd, "Asus N550", ALC662_FIXUP_BASS_1A),
6089 	SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_BASS_MODE4_CHMAP),
6090 	SND_PCI_QUIRK(0x1043, 0x15a7, "ASUS UX51VZH", ALC662_FIXUP_BASS_16),
6091 	SND_PCI_QUIRK(0x1043, 0x1b73, "ASUS N55SF", ALC662_FIXUP_BASS_16),
6092 	SND_PCI_QUIRK(0x1043, 0x1bf3, "ASUS N76VZ", ALC662_FIXUP_BASS_MODE4_CHMAP),
6093 	SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
6094 	SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
6095 	SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
6096 	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
6097 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
6098 	SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
6099 	SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
6100 
6101 #if 0
6102 	/* Below is a quirk table taken from the old code.
6103 	 * Basically the device should work as is without the fixup table.
6104 	 * If BIOS doesn't give a proper info, enable the corresponding
6105 	 * fixup entry.
6106 	 */
6107 	SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6108 	SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6109 	SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6110 	SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6111 	SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6112 	SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6113 	SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6114 	SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6115 	SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6116 	SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6117 	SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6118 	SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6119 	SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6120 	SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6121 	SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6122 	SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6123 	SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6124 	SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6125 	SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6126 	SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6127 	SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6128 	SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6129 	SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6130 	SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6131 	SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6132 	SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6133 	SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6134 	SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6135 	SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6136 	SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6137 	SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6138 	SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6139 	SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6140 	SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6141 	SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6142 	SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6143 	SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6144 	SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6145 	SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6146 	SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6147 	SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6148 	SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6149 	SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6150 	SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6151 	SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6152 	SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6153 	SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6154 	SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6155 	SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6156 	SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6157 #endif
6158 	{}
6159 };
6160 
6161 static const struct hda_model_fixup alc662_fixup_models[] = {
6162 	{.id = ALC272_FIXUP_MARIO, .name = "mario"},
6163 	{.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6164 	{.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6165 	{.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6166 	{.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6167 	{.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6168 	{.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6169 	{.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6170 	{.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
6171 	{.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
6172 	{.id = ALC668_FIXUP_DELL_MIC_NO_PRESENCE, .name = "dell-headset-multi"},
6173 	{}
6174 };
6175 
6176 static const struct snd_hda_pin_quirk alc662_pin_fixup_tbl[] = {
6177 	SND_HDA_PIN_QUIRK(0x10ec0668, 0x1028, "Dell", ALC668_FIXUP_AUTO_MUTE,
6178 		{0x12, 0x99a30130},
6179 		{0x14, 0x90170110},
6180 		{0x15, 0x0321101f},
6181 		{0x16, 0x03011020},
6182 		{0x18, 0x40000008},
6183 		{0x19, 0x411111f0},
6184 		{0x1a, 0x411111f0},
6185 		{0x1b, 0x411111f0},
6186 		{0x1d, 0x41000001},
6187 		{0x1e, 0x411111f0},
6188 		{0x1f, 0x411111f0}),
6189 	SND_HDA_PIN_QUIRK(0x10ec0668, 0x1028, "Dell", ALC668_FIXUP_AUTO_MUTE,
6190 		{0x12, 0x99a30140},
6191 		{0x14, 0x90170110},
6192 		{0x15, 0x0321101f},
6193 		{0x16, 0x03011020},
6194 		{0x18, 0x40000008},
6195 		{0x19, 0x411111f0},
6196 		{0x1a, 0x411111f0},
6197 		{0x1b, 0x411111f0},
6198 		{0x1d, 0x41000001},
6199 		{0x1e, 0x411111f0},
6200 		{0x1f, 0x411111f0}),
6201 	SND_HDA_PIN_QUIRK(0x10ec0668, 0x1028, "Dell", ALC668_FIXUP_AUTO_MUTE,
6202 		{0x12, 0x99a30150},
6203 		{0x14, 0x90170110},
6204 		{0x15, 0x0321101f},
6205 		{0x16, 0x03011020},
6206 		{0x18, 0x40000008},
6207 		{0x19, 0x411111f0},
6208 		{0x1a, 0x411111f0},
6209 		{0x1b, 0x411111f0},
6210 		{0x1d, 0x41000001},
6211 		{0x1e, 0x411111f0},
6212 		{0x1f, 0x411111f0}),
6213 	SND_HDA_PIN_QUIRK(0x10ec0668, 0x1028, "Dell", ALC668_FIXUP_AUTO_MUTE,
6214 		{0x12, 0x411111f0},
6215 		{0x14, 0x90170110},
6216 		{0x15, 0x0321101f},
6217 		{0x16, 0x03011020},
6218 		{0x18, 0x40000008},
6219 		{0x19, 0x411111f0},
6220 		{0x1a, 0x411111f0},
6221 		{0x1b, 0x411111f0},
6222 		{0x1d, 0x41000001},
6223 		{0x1e, 0x411111f0},
6224 		{0x1f, 0x411111f0}),
6225 	SND_HDA_PIN_QUIRK(0x10ec0668, 0x1028, "Dell XPS 15", ALC668_FIXUP_AUTO_MUTE,
6226 		{0x12, 0x90a60130},
6227 		{0x14, 0x90170110},
6228 		{0x15, 0x0321101f},
6229 		{0x16, 0x40000000},
6230 		{0x18, 0x411111f0},
6231 		{0x19, 0x411111f0},
6232 		{0x1a, 0x411111f0},
6233 		{0x1b, 0x411111f0},
6234 		{0x1d, 0x40d6832d},
6235 		{0x1e, 0x411111f0},
6236 		{0x1f, 0x411111f0}),
6237 	{}
6238 };
6239 
6240 /*
6241  */
6242 static int patch_alc662(struct hda_codec *codec)
6243 {
6244 	struct alc_spec *spec;
6245 	int err;
6246 
6247 	err = alc_alloc_spec(codec, 0x0b);
6248 	if (err < 0)
6249 		return err;
6250 
6251 	spec = codec->spec;
6252 
6253 	/* handle multiple HPs as is */
6254 	spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6255 
6256 	alc_fix_pll_init(codec, 0x20, 0x04, 15);
6257 
6258 	switch (codec->vendor_id) {
6259 	case 0x10ec0668:
6260 		spec->init_hook = alc668_restore_default_value;
6261 		break;
6262 	}
6263 
6264 	snd_hda_pick_fixup(codec, alc662_fixup_models,
6265 		       alc662_fixup_tbl, alc662_fixups);
6266 	snd_hda_pick_pin_fixup(codec, alc662_pin_fixup_tbl, alc662_fixups);
6267 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
6268 
6269 	alc_auto_parse_customize_define(codec);
6270 
6271 	if (has_cdefine_beep(codec))
6272 		spec->gen.beep_nid = 0x01;
6273 
6274 	if ((alc_get_coef0(codec) & (1 << 14)) &&
6275 	    codec->bus->pci && codec->bus->pci->subsystem_vendor == 0x1025 &&
6276 	    spec->cdefine.platform_type == 1) {
6277 		err = alc_codec_rename(codec, "ALC272X");
6278 		if (err < 0)
6279 			goto error;
6280 	}
6281 
6282 	/* automatic parse from the BIOS config */
6283 	err = alc662_parse_auto_config(codec);
6284 	if (err < 0)
6285 		goto error;
6286 
6287 	if (!spec->gen.no_analog && spec->gen.beep_nid) {
6288 		switch (codec->vendor_id) {
6289 		case 0x10ec0662:
6290 			set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6291 			break;
6292 		case 0x10ec0272:
6293 		case 0x10ec0663:
6294 		case 0x10ec0665:
6295 		case 0x10ec0668:
6296 			set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6297 			break;
6298 		case 0x10ec0273:
6299 			set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6300 			break;
6301 		}
6302 	}
6303 
6304 	codec->patch_ops = alc_patch_ops;
6305 	spec->shutup = alc_eapd_shutup;
6306 
6307 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
6308 
6309 	return 0;
6310 
6311  error:
6312 	alc_free(codec);
6313 	return err;
6314 }
6315 
6316 /*
6317  * ALC680 support
6318  */
6319 
6320 static int alc680_parse_auto_config(struct hda_codec *codec)
6321 {
6322 	return alc_parse_auto_config(codec, NULL, NULL);
6323 }
6324 
6325 /*
6326  */
6327 static int patch_alc680(struct hda_codec *codec)
6328 {
6329 	int err;
6330 
6331 	/* ALC680 has no aa-loopback mixer */
6332 	err = alc_alloc_spec(codec, 0);
6333 	if (err < 0)
6334 		return err;
6335 
6336 	/* automatic parse from the BIOS config */
6337 	err = alc680_parse_auto_config(codec);
6338 	if (err < 0) {
6339 		alc_free(codec);
6340 		return err;
6341 	}
6342 
6343 	codec->patch_ops = alc_patch_ops;
6344 
6345 	return 0;
6346 }
6347 
6348 /*
6349  * patch entries
6350  */
6351 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
6352 	{ .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
6353 	{ .id = 0x10ec0231, .name = "ALC231", .patch = patch_alc269 },
6354 	{ .id = 0x10ec0233, .name = "ALC233", .patch = patch_alc269 },
6355 	{ .id = 0x10ec0235, .name = "ALC233", .patch = patch_alc269 },
6356 	{ .id = 0x10ec0255, .name = "ALC255", .patch = patch_alc269 },
6357 	{ .id = 0x10ec0256, .name = "ALC256", .patch = patch_alc269 },
6358 	{ .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
6359 	{ .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
6360 	{ .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
6361 	{ .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
6362 	{ .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
6363 	{ .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
6364 	{ .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
6365 	{ .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
6366 	{ .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
6367 	{ .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
6368 	{ .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
6369 	{ .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
6370 	{ .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
6371 	{ .id = 0x10ec0285, .name = "ALC285", .patch = patch_alc269 },
6372 	{ .id = 0x10ec0286, .name = "ALC286", .patch = patch_alc269 },
6373 	{ .id = 0x10ec0288, .name = "ALC288", .patch = patch_alc269 },
6374 	{ .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
6375 	{ .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
6376 	{ .id = 0x10ec0293, .name = "ALC293", .patch = patch_alc269 },
6377 	{ .id = 0x10ec0298, .name = "ALC298", .patch = patch_alc269 },
6378 	{ .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
6379 	  .patch = patch_alc861 },
6380 	{ .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6381 	{ .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6382 	{ .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
6383 	{ .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
6384 	  .patch = patch_alc882 },
6385 	{ .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6386 	  .patch = patch_alc662 },
6387 	{ .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6388 	  .patch = patch_alc662 },
6389 	{ .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
6390 	{ .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
6391 	{ .id = 0x10ec0667, .name = "ALC667", .patch = patch_alc662 },
6392 	{ .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
6393 	{ .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
6394 	{ .id = 0x10ec0671, .name = "ALC671", .patch = patch_alc662 },
6395 	{ .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
6396 	{ .id = 0x10ec0867, .name = "ALC891", .patch = patch_alc882 },
6397 	{ .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
6398 	{ .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
6399 	{ .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
6400 	{ .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
6401 	  .patch = patch_alc882 },
6402 	{ .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
6403 	  .patch = patch_alc882 },
6404 	{ .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
6405 	{ .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
6406 	{ .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
6407 	  .patch = patch_alc882 },
6408 	{ .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
6409 	{ .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
6410 	{ .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
6411 	{ .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
6412 	{ .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
6413 	{} /* terminator */
6414 };
6415 
6416 MODULE_ALIAS("snd-hda-codec-id:10ec*");
6417 
6418 MODULE_LICENSE("GPL");
6419 MODULE_DESCRIPTION("Realtek HD-audio codec");
6420 
6421 static struct hda_codec_preset_list realtek_list = {
6422 	.preset = snd_hda_preset_realtek,
6423 	.owner = THIS_MODULE,
6424 };
6425 
6426 static int __init patch_realtek_init(void)
6427 {
6428 	return snd_hda_add_codec_preset(&realtek_list);
6429 }
6430 
6431 static void __exit patch_realtek_exit(void)
6432 {
6433 	snd_hda_delete_codec_preset(&realtek_list);
6434 }
6435 
6436 module_init(patch_realtek_init)
6437 module_exit(patch_realtek_exit)
6438