ALSA: hda/realtek - Add unplug function into unplug state of Headset Mode for ALC225
[platform/kernel/linux-exynos.git] / sound / pci / hda / patch_realtek.c
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 <linux/input.h>
33 #include <sound/core.h>
34 #include <sound/jack.h>
35 #include "hda_codec.h"
36 #include "hda_local.h"
37 #include "hda_auto_parser.h"
38 #include "hda_jack.h"
39 #include "hda_generic.h"
40
41 /* keep halting ALC5505 DSP, for power saving */
42 #define HALT_REALTEK_ALC5505
43
44 /* extra amp-initialization sequence types */
45 enum {
46         ALC_INIT_NONE,
47         ALC_INIT_DEFAULT,
48         ALC_INIT_GPIO1,
49         ALC_INIT_GPIO2,
50         ALC_INIT_GPIO3,
51 };
52
53 enum {
54         ALC_HEADSET_MODE_UNKNOWN,
55         ALC_HEADSET_MODE_UNPLUGGED,
56         ALC_HEADSET_MODE_HEADSET,
57         ALC_HEADSET_MODE_MIC,
58         ALC_HEADSET_MODE_HEADPHONE,
59 };
60
61 enum {
62         ALC_HEADSET_TYPE_UNKNOWN,
63         ALC_HEADSET_TYPE_CTIA,
64         ALC_HEADSET_TYPE_OMTP,
65 };
66
67 enum {
68         ALC_KEY_MICMUTE_INDEX,
69 };
70
71 struct alc_customize_define {
72         unsigned int  sku_cfg;
73         unsigned char port_connectivity;
74         unsigned char check_sum;
75         unsigned char customization;
76         unsigned char external_amp;
77         unsigned int  enable_pcbeep:1;
78         unsigned int  platform_type:1;
79         unsigned int  swap:1;
80         unsigned int  override:1;
81         unsigned int  fixup:1; /* Means that this sku is set by driver, not read from hw */
82 };
83
84 struct alc_spec {
85         struct hda_gen_spec gen; /* must be at head */
86
87         /* codec parameterization */
88         const struct snd_kcontrol_new *mixers[5];       /* mixer arrays */
89         unsigned int num_mixers;
90         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
91
92         struct alc_customize_define cdefine;
93         unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
94
95         /* mute LED for HP laptops, see alc269_fixup_mic_mute_hook() */
96         int mute_led_polarity;
97         hda_nid_t mute_led_nid;
98         hda_nid_t cap_mute_led_nid;
99
100         unsigned int gpio_led; /* used for alc269_fixup_hp_gpio_led() */
101         unsigned int gpio_mute_led_mask;
102         unsigned int gpio_mic_led_mask;
103
104         hda_nid_t headset_mic_pin;
105         hda_nid_t headphone_mic_pin;
106         int current_headset_mode;
107         int current_headset_type;
108
109         /* hooks */
110         void (*init_hook)(struct hda_codec *codec);
111 #ifdef CONFIG_PM
112         void (*power_hook)(struct hda_codec *codec);
113 #endif
114         void (*shutup)(struct hda_codec *codec);
115         void (*reboot_notify)(struct hda_codec *codec);
116
117         int init_amp;
118         int codec_variant;      /* flag for other variants */
119         unsigned int has_alc5505_dsp:1;
120         unsigned int no_depop_delay:1;
121
122         /* for PLL fix */
123         hda_nid_t pll_nid;
124         unsigned int pll_coef_idx, pll_coef_bit;
125         unsigned int coef0;
126         struct input_dev *kb_dev;
127         u8 alc_mute_keycode_map[1];
128 };
129
130 /*
131  * COEF access helper functions
132  */
133
134 static int alc_read_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
135                                unsigned int coef_idx)
136 {
137         unsigned int val;
138
139         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX, coef_idx);
140         val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
141         return val;
142 }
143
144 #define alc_read_coef_idx(codec, coef_idx) \
145         alc_read_coefex_idx(codec, 0x20, coef_idx)
146
147 static void alc_write_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
148                                  unsigned int coef_idx, unsigned int coef_val)
149 {
150         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX, coef_idx);
151         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PROC_COEF, coef_val);
152 }
153
154 #define alc_write_coef_idx(codec, coef_idx, coef_val) \
155         alc_write_coefex_idx(codec, 0x20, coef_idx, coef_val)
156
157 static void alc_update_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
158                                   unsigned int coef_idx, unsigned int mask,
159                                   unsigned int bits_set)
160 {
161         unsigned int val = alc_read_coefex_idx(codec, nid, coef_idx);
162
163         if (val != -1)
164                 alc_write_coefex_idx(codec, nid, coef_idx,
165                                      (val & ~mask) | bits_set);
166 }
167
168 #define alc_update_coef_idx(codec, coef_idx, mask, bits_set)    \
169         alc_update_coefex_idx(codec, 0x20, coef_idx, mask, bits_set)
170
171 /* a special bypass for COEF 0; read the cached value at the second time */
172 static unsigned int alc_get_coef0(struct hda_codec *codec)
173 {
174         struct alc_spec *spec = codec->spec;
175
176         if (!spec->coef0)
177                 spec->coef0 = alc_read_coef_idx(codec, 0);
178         return spec->coef0;
179 }
180
181 /* coef writes/updates batch */
182 struct coef_fw {
183         unsigned char nid;
184         unsigned char idx;
185         unsigned short mask;
186         unsigned short val;
187 };
188
189 #define UPDATE_COEFEX(_nid, _idx, _mask, _val) \
190         { .nid = (_nid), .idx = (_idx), .mask = (_mask), .val = (_val) }
191 #define WRITE_COEFEX(_nid, _idx, _val) UPDATE_COEFEX(_nid, _idx, -1, _val)
192 #define WRITE_COEF(_idx, _val) WRITE_COEFEX(0x20, _idx, _val)
193 #define UPDATE_COEF(_idx, _mask, _val) UPDATE_COEFEX(0x20, _idx, _mask, _val)
194
195 static void alc_process_coef_fw(struct hda_codec *codec,
196                                 const struct coef_fw *fw)
197 {
198         for (; fw->nid; fw++) {
199                 if (fw->mask == (unsigned short)-1)
200                         alc_write_coefex_idx(codec, fw->nid, fw->idx, fw->val);
201                 else
202                         alc_update_coefex_idx(codec, fw->nid, fw->idx,
203                                               fw->mask, fw->val);
204         }
205 }
206
207 /*
208  * Append the given mixer and verb elements for the later use
209  * The mixer array is referred in build_controls(), and init_verbs are
210  * called in init().
211  */
212 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
213 {
214         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
215                 return;
216         spec->mixers[spec->num_mixers++] = mix;
217 }
218
219 /*
220  * GPIO setup tables, used in initialization
221  */
222 /* Enable GPIO mask and set output */
223 static const struct hda_verb alc_gpio1_init_verbs[] = {
224         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
225         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
226         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
227         { }
228 };
229
230 static const struct hda_verb alc_gpio2_init_verbs[] = {
231         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
232         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
233         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
234         { }
235 };
236
237 static const struct hda_verb alc_gpio3_init_verbs[] = {
238         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
239         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
240         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
241         { }
242 };
243
244 /*
245  * Fix hardware PLL issue
246  * On some codecs, the analog PLL gating control must be off while
247  * the default value is 1.
248  */
249 static void alc_fix_pll(struct hda_codec *codec)
250 {
251         struct alc_spec *spec = codec->spec;
252
253         if (spec->pll_nid)
254                 alc_update_coefex_idx(codec, spec->pll_nid, spec->pll_coef_idx,
255                                       1 << spec->pll_coef_bit, 0);
256 }
257
258 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
259                              unsigned int coef_idx, unsigned int coef_bit)
260 {
261         struct alc_spec *spec = codec->spec;
262         spec->pll_nid = nid;
263         spec->pll_coef_idx = coef_idx;
264         spec->pll_coef_bit = coef_bit;
265         alc_fix_pll(codec);
266 }
267
268 /* update the master volume per volume-knob's unsol event */
269 static void alc_update_knob_master(struct hda_codec *codec,
270                                    struct hda_jack_callback *jack)
271 {
272         unsigned int val;
273         struct snd_kcontrol *kctl;
274         struct snd_ctl_elem_value *uctl;
275
276         kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
277         if (!kctl)
278                 return;
279         uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
280         if (!uctl)
281                 return;
282         val = snd_hda_codec_read(codec, jack->nid, 0,
283                                  AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
284         val &= HDA_AMP_VOLMASK;
285         uctl->value.integer.value[0] = val;
286         uctl->value.integer.value[1] = val;
287         kctl->put(kctl, uctl);
288         kfree(uctl);
289 }
290
291 static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
292 {
293         /* For some reason, the res given from ALC880 is broken.
294            Here we adjust it properly. */
295         snd_hda_jack_unsol_event(codec, res >> 2);
296 }
297
298 /* Change EAPD to verb control */
299 static void alc_fill_eapd_coef(struct hda_codec *codec)
300 {
301         int coef;
302
303         coef = alc_get_coef0(codec);
304
305         switch (codec->core.vendor_id) {
306         case 0x10ec0262:
307                 alc_update_coef_idx(codec, 0x7, 0, 1<<5);
308                 break;
309         case 0x10ec0267:
310         case 0x10ec0268:
311                 alc_update_coef_idx(codec, 0x7, 0, 1<<13);
312                 break;
313         case 0x10ec0269:
314                 if ((coef & 0x00f0) == 0x0010)
315                         alc_update_coef_idx(codec, 0xd, 0, 1<<14);
316                 if ((coef & 0x00f0) == 0x0020)
317                         alc_update_coef_idx(codec, 0x4, 1<<15, 0);
318                 if ((coef & 0x00f0) == 0x0030)
319                         alc_update_coef_idx(codec, 0x10, 1<<9, 0);
320                 break;
321         case 0x10ec0280:
322         case 0x10ec0284:
323         case 0x10ec0290:
324         case 0x10ec0292:
325                 alc_update_coef_idx(codec, 0x4, 1<<15, 0);
326                 break;
327         case 0x10ec0225:
328         case 0x10ec0295:
329         case 0x10ec0299:
330                 alc_update_coef_idx(codec, 0x67, 0xf000, 0x3000);
331                 /* fallthrough */
332         case 0x10ec0215:
333         case 0x10ec0233:
334         case 0x10ec0235:
335         case 0x10ec0236:
336         case 0x10ec0255:
337         case 0x10ec0256:
338         case 0x10ec0257:
339         case 0x10ec0282:
340         case 0x10ec0283:
341         case 0x10ec0286:
342         case 0x10ec0288:
343         case 0x10ec0285:
344         case 0x10ec0298:
345         case 0x10ec0289:
346         case 0x10ec0300:
347                 alc_update_coef_idx(codec, 0x10, 1<<9, 0);
348                 break;
349         case 0x10ec0275:
350                 alc_update_coef_idx(codec, 0xe, 0, 1<<0);
351                 break;
352         case 0x10ec0293:
353                 alc_update_coef_idx(codec, 0xa, 1<<13, 0);
354                 break;
355         case 0x10ec0234:
356         case 0x10ec0274:
357         case 0x10ec0294:
358         case 0x10ec0700:
359         case 0x10ec0701:
360         case 0x10ec0703:
361                 alc_update_coef_idx(codec, 0x10, 1<<15, 0);
362                 break;
363         case 0x10ec0662:
364                 if ((coef & 0x00f0) == 0x0030)
365                         alc_update_coef_idx(codec, 0x4, 1<<10, 0); /* EAPD Ctrl */
366                 break;
367         case 0x10ec0272:
368         case 0x10ec0273:
369         case 0x10ec0663:
370         case 0x10ec0665:
371         case 0x10ec0670:
372         case 0x10ec0671:
373         case 0x10ec0672:
374                 alc_update_coef_idx(codec, 0xd, 0, 1<<14); /* EAPD Ctrl */
375                 break;
376         case 0x10ec0668:
377                 alc_update_coef_idx(codec, 0x7, 3<<13, 0);
378                 break;
379         case 0x10ec0867:
380                 alc_update_coef_idx(codec, 0x4, 1<<10, 0);
381                 break;
382         case 0x10ec0888:
383                 if ((coef & 0x00f0) == 0x0020 || (coef & 0x00f0) == 0x0030)
384                         alc_update_coef_idx(codec, 0x7, 1<<5, 0);
385                 break;
386         case 0x10ec0892:
387                 alc_update_coef_idx(codec, 0x7, 1<<5, 0);
388                 break;
389         case 0x10ec0899:
390         case 0x10ec0900:
391         case 0x10ec1168:
392         case 0x10ec1220:
393                 alc_update_coef_idx(codec, 0x7, 1<<1, 0);
394                 break;
395         }
396 }
397
398 /* additional initialization for ALC888 variants */
399 static void alc888_coef_init(struct hda_codec *codec)
400 {
401         switch (alc_get_coef0(codec) & 0x00f0) {
402         /* alc888-VA */
403         case 0x00:
404         /* alc888-VB */
405         case 0x10:
406                 alc_update_coef_idx(codec, 7, 0, 0x2030); /* Turn EAPD to High */
407                 break;
408         }
409 }
410
411 /* turn on/off EAPD control (only if available) */
412 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
413 {
414         if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
415                 return;
416         if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
417                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
418                                     on ? 2 : 0);
419 }
420
421 /* turn on/off EAPD controls of the codec */
422 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
423 {
424         /* We currently only handle front, HP */
425         static hda_nid_t pins[] = {
426                 0x0f, 0x10, 0x14, 0x15, 0x17, 0
427         };
428         hda_nid_t *p;
429         for (p = pins; *p; p++)
430                 set_eapd(codec, *p, on);
431 }
432
433 /* generic shutup callback;
434  * just turning off EAPD and a little pause for avoiding pop-noise
435  */
436 static void alc_eapd_shutup(struct hda_codec *codec)
437 {
438         struct alc_spec *spec = codec->spec;
439
440         alc_auto_setup_eapd(codec, false);
441         if (!spec->no_depop_delay)
442                 msleep(200);
443         snd_hda_shutup_pins(codec);
444 }
445
446 /* generic EAPD initialization */
447 static void alc_auto_init_amp(struct hda_codec *codec, int type)
448 {
449         alc_fill_eapd_coef(codec);
450         alc_auto_setup_eapd(codec, true);
451         switch (type) {
452         case ALC_INIT_GPIO1:
453                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
454                 break;
455         case ALC_INIT_GPIO2:
456                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
457                 break;
458         case ALC_INIT_GPIO3:
459                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
460                 break;
461         case ALC_INIT_DEFAULT:
462                 switch (codec->core.vendor_id) {
463                 case 0x10ec0260:
464                         alc_update_coefex_idx(codec, 0x1a, 7, 0, 0x2010);
465                         break;
466                 case 0x10ec0880:
467                 case 0x10ec0882:
468                 case 0x10ec0883:
469                 case 0x10ec0885:
470                         alc_update_coef_idx(codec, 7, 0, 0x2030);
471                         break;
472                 case 0x10ec0888:
473                         alc888_coef_init(codec);
474                         break;
475                 }
476                 break;
477         }
478 }
479
480
481 /*
482  * Realtek SSID verification
483  */
484
485 /* Could be any non-zero and even value. When used as fixup, tells
486  * the driver to ignore any present sku defines.
487  */
488 #define ALC_FIXUP_SKU_IGNORE (2)
489
490 static void alc_fixup_sku_ignore(struct hda_codec *codec,
491                                  const struct hda_fixup *fix, int action)
492 {
493         struct alc_spec *spec = codec->spec;
494         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
495                 spec->cdefine.fixup = 1;
496                 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
497         }
498 }
499
500 static void alc_fixup_no_depop_delay(struct hda_codec *codec,
501                                     const struct hda_fixup *fix, int action)
502 {
503         struct alc_spec *spec = codec->spec;
504
505         if (action == HDA_FIXUP_ACT_PROBE) {
506                 spec->no_depop_delay = 1;
507                 codec->depop_delay = 0;
508         }
509 }
510
511 static int alc_auto_parse_customize_define(struct hda_codec *codec)
512 {
513         unsigned int ass, tmp, i;
514         unsigned nid = 0;
515         struct alc_spec *spec = codec->spec;
516
517         spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
518
519         if (spec->cdefine.fixup) {
520                 ass = spec->cdefine.sku_cfg;
521                 if (ass == ALC_FIXUP_SKU_IGNORE)
522                         return -1;
523                 goto do_sku;
524         }
525
526         if (!codec->bus->pci)
527                 return -1;
528         ass = codec->core.subsystem_id & 0xffff;
529         if (ass != codec->bus->pci->subsystem_device && (ass & 1))
530                 goto do_sku;
531
532         nid = 0x1d;
533         if (codec->core.vendor_id == 0x10ec0260)
534                 nid = 0x17;
535         ass = snd_hda_codec_get_pincfg(codec, nid);
536
537         if (!(ass & 1)) {
538                 codec_info(codec, "%s: SKU not ready 0x%08x\n",
539                            codec->core.chip_name, ass);
540                 return -1;
541         }
542
543         /* check sum */
544         tmp = 0;
545         for (i = 1; i < 16; i++) {
546                 if ((ass >> i) & 1)
547                         tmp++;
548         }
549         if (((ass >> 16) & 0xf) != tmp)
550                 return -1;
551
552         spec->cdefine.port_connectivity = ass >> 30;
553         spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
554         spec->cdefine.check_sum = (ass >> 16) & 0xf;
555         spec->cdefine.customization = ass >> 8;
556 do_sku:
557         spec->cdefine.sku_cfg = ass;
558         spec->cdefine.external_amp = (ass & 0x38) >> 3;
559         spec->cdefine.platform_type = (ass & 0x4) >> 2;
560         spec->cdefine.swap = (ass & 0x2) >> 1;
561         spec->cdefine.override = ass & 0x1;
562
563         codec_dbg(codec, "SKU: Nid=0x%x sku_cfg=0x%08x\n",
564                    nid, spec->cdefine.sku_cfg);
565         codec_dbg(codec, "SKU: port_connectivity=0x%x\n",
566                    spec->cdefine.port_connectivity);
567         codec_dbg(codec, "SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
568         codec_dbg(codec, "SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
569         codec_dbg(codec, "SKU: customization=0x%08x\n", spec->cdefine.customization);
570         codec_dbg(codec, "SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
571         codec_dbg(codec, "SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
572         codec_dbg(codec, "SKU: swap=0x%x\n", spec->cdefine.swap);
573         codec_dbg(codec, "SKU: override=0x%x\n", spec->cdefine.override);
574
575         return 0;
576 }
577
578 /* return the position of NID in the list, or -1 if not found */
579 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
580 {
581         int i;
582         for (i = 0; i < nums; i++)
583                 if (list[i] == nid)
584                         return i;
585         return -1;
586 }
587 /* return true if the given NID is found in the list */
588 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
589 {
590         return find_idx_in_nid_list(nid, list, nums) >= 0;
591 }
592
593 /* check subsystem ID and set up device-specific initialization;
594  * return 1 if initialized, 0 if invalid SSID
595  */
596 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
597  *      31 ~ 16 :       Manufacture ID
598  *      15 ~ 8  :       SKU ID
599  *      7  ~ 0  :       Assembly ID
600  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
601  */
602 static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports)
603 {
604         unsigned int ass, tmp, i;
605         unsigned nid;
606         struct alc_spec *spec = codec->spec;
607
608         if (spec->cdefine.fixup) {
609                 ass = spec->cdefine.sku_cfg;
610                 if (ass == ALC_FIXUP_SKU_IGNORE)
611                         return 0;
612                 goto do_sku;
613         }
614
615         ass = codec->core.subsystem_id & 0xffff;
616         if (codec->bus->pci &&
617             ass != codec->bus->pci->subsystem_device && (ass & 1))
618                 goto do_sku;
619
620         /* invalid SSID, check the special NID pin defcfg instead */
621         /*
622          * 31~30        : port connectivity
623          * 29~21        : reserve
624          * 20           : PCBEEP input
625          * 19~16        : Check sum (15:1)
626          * 15~1         : Custom
627          * 0            : override
628         */
629         nid = 0x1d;
630         if (codec->core.vendor_id == 0x10ec0260)
631                 nid = 0x17;
632         ass = snd_hda_codec_get_pincfg(codec, nid);
633         codec_dbg(codec,
634                   "realtek: No valid SSID, checking pincfg 0x%08x for NID 0x%x\n",
635                    ass, nid);
636         if (!(ass & 1))
637                 return 0;
638         if ((ass >> 30) != 1)   /* no physical connection */
639                 return 0;
640
641         /* check sum */
642         tmp = 0;
643         for (i = 1; i < 16; i++) {
644                 if ((ass >> i) & 1)
645                         tmp++;
646         }
647         if (((ass >> 16) & 0xf) != tmp)
648                 return 0;
649 do_sku:
650         codec_dbg(codec, "realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
651                    ass & 0xffff, codec->core.vendor_id);
652         /*
653          * 0 : override
654          * 1 :  Swap Jack
655          * 2 : 0 --> Desktop, 1 --> Laptop
656          * 3~5 : External Amplifier control
657          * 7~6 : Reserved
658         */
659         tmp = (ass & 0x38) >> 3;        /* external Amp control */
660         switch (tmp) {
661         case 1:
662                 spec->init_amp = ALC_INIT_GPIO1;
663                 break;
664         case 3:
665                 spec->init_amp = ALC_INIT_GPIO2;
666                 break;
667         case 7:
668                 spec->init_amp = ALC_INIT_GPIO3;
669                 break;
670         case 5:
671         default:
672                 spec->init_amp = ALC_INIT_DEFAULT;
673                 break;
674         }
675
676         /* is laptop or Desktop and enable the function "Mute internal speaker
677          * when the external headphone out jack is plugged"
678          */
679         if (!(ass & 0x8000))
680                 return 1;
681         /*
682          * 10~8 : Jack location
683          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
684          * 14~13: Resvered
685          * 15   : 1 --> enable the function "Mute internal speaker
686          *              when the external headphone out jack is plugged"
687          */
688         if (!spec->gen.autocfg.hp_pins[0] &&
689             !(spec->gen.autocfg.line_out_pins[0] &&
690               spec->gen.autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
691                 hda_nid_t nid;
692                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
693                 nid = ports[tmp];
694                 if (found_in_nid_list(nid, spec->gen.autocfg.line_out_pins,
695                                       spec->gen.autocfg.line_outs))
696                         return 1;
697                 spec->gen.autocfg.hp_pins[0] = nid;
698         }
699         return 1;
700 }
701
702 /* Check the validity of ALC subsystem-id
703  * ports contains an array of 4 pin NIDs for port-A, E, D and I */
704 static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
705 {
706         if (!alc_subsystem_id(codec, ports)) {
707                 struct alc_spec *spec = codec->spec;
708                 codec_dbg(codec,
709                           "realtek: Enable default setup for auto mode as fallback\n");
710                 spec->init_amp = ALC_INIT_DEFAULT;
711         }
712 }
713
714 /*
715  */
716
717 static void alc_fixup_inv_dmic(struct hda_codec *codec,
718                                const struct hda_fixup *fix, int action)
719 {
720         struct alc_spec *spec = codec->spec;
721
722         spec->gen.inv_dmic_split = 1;
723 }
724
725
726 #ifdef CONFIG_SND_HDA_INPUT_BEEP
727 /* additional beep mixers; the actual parameters are overwritten at build */
728 static const struct snd_kcontrol_new alc_beep_mixer[] = {
729         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
730         HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
731         { } /* end */
732 };
733 #endif
734
735 static int alc_build_controls(struct hda_codec *codec)
736 {
737         struct alc_spec *spec = codec->spec;
738         int i, err;
739
740         err = snd_hda_gen_build_controls(codec);
741         if (err < 0)
742                 return err;
743
744         for (i = 0; i < spec->num_mixers; i++) {
745                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
746                 if (err < 0)
747                         return err;
748         }
749
750 #ifdef CONFIG_SND_HDA_INPUT_BEEP
751         /* create beep controls if needed */
752         if (spec->beep_amp) {
753                 const struct snd_kcontrol_new *knew;
754                 for (knew = alc_beep_mixer; knew->name; knew++) {
755                         struct snd_kcontrol *kctl;
756                         kctl = snd_ctl_new1(knew, codec);
757                         if (!kctl)
758                                 return -ENOMEM;
759                         kctl->private_value = spec->beep_amp;
760                         err = snd_hda_ctl_add(codec, 0, kctl);
761                         if (err < 0)
762                                 return err;
763                 }
764         }
765 #endif
766
767         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD);
768         return 0;
769 }
770
771
772 /*
773  * Common callbacks
774  */
775
776 static int alc_init(struct hda_codec *codec)
777 {
778         struct alc_spec *spec = codec->spec;
779
780         if (spec->init_hook)
781                 spec->init_hook(codec);
782
783         alc_fix_pll(codec);
784         alc_auto_init_amp(codec, spec->init_amp);
785
786         snd_hda_gen_init(codec);
787
788         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
789
790         return 0;
791 }
792
793 static inline void alc_shutup(struct hda_codec *codec)
794 {
795         struct alc_spec *spec = codec->spec;
796
797         if (spec && spec->shutup)
798                 spec->shutup(codec);
799         else
800                 snd_hda_shutup_pins(codec);
801 }
802
803 static void alc_reboot_notify(struct hda_codec *codec)
804 {
805         struct alc_spec *spec = codec->spec;
806
807         if (spec && spec->reboot_notify)
808                 spec->reboot_notify(codec);
809         else
810                 alc_shutup(codec);
811 }
812
813 /* power down codec to D3 at reboot/shutdown; set as reboot_notify ops */
814 static void alc_d3_at_reboot(struct hda_codec *codec)
815 {
816         snd_hda_codec_set_power_to_all(codec, codec->core.afg, AC_PWRST_D3);
817         snd_hda_codec_write(codec, codec->core.afg, 0,
818                             AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
819         msleep(10);
820 }
821
822 #define alc_free        snd_hda_gen_free
823
824 #ifdef CONFIG_PM
825 static void alc_power_eapd(struct hda_codec *codec)
826 {
827         alc_auto_setup_eapd(codec, false);
828 }
829
830 static int alc_suspend(struct hda_codec *codec)
831 {
832         struct alc_spec *spec = codec->spec;
833         alc_shutup(codec);
834         if (spec && spec->power_hook)
835                 spec->power_hook(codec);
836         return 0;
837 }
838 #endif
839
840 #ifdef CONFIG_PM
841 static int alc_resume(struct hda_codec *codec)
842 {
843         struct alc_spec *spec = codec->spec;
844
845         if (!spec->no_depop_delay)
846                 msleep(150); /* to avoid pop noise */
847         codec->patch_ops.init(codec);
848         regcache_sync(codec->core.regmap);
849         hda_call_check_power_status(codec, 0x01);
850         return 0;
851 }
852 #endif
853
854 /*
855  */
856 static const struct hda_codec_ops alc_patch_ops = {
857         .build_controls = alc_build_controls,
858         .build_pcms = snd_hda_gen_build_pcms,
859         .init = alc_init,
860         .free = alc_free,
861         .unsol_event = snd_hda_jack_unsol_event,
862 #ifdef CONFIG_PM
863         .resume = alc_resume,
864         .suspend = alc_suspend,
865         .check_power_status = snd_hda_gen_check_power_status,
866 #endif
867         .reboot_notify = alc_reboot_notify,
868 };
869
870
871 #define alc_codec_rename(codec, name) snd_hda_codec_set_name(codec, name)
872
873 /*
874  * Rename codecs appropriately from COEF value or subvendor id
875  */
876 struct alc_codec_rename_table {
877         unsigned int vendor_id;
878         unsigned short coef_mask;
879         unsigned short coef_bits;
880         const char *name;
881 };
882
883 struct alc_codec_rename_pci_table {
884         unsigned int codec_vendor_id;
885         unsigned short pci_subvendor;
886         unsigned short pci_subdevice;
887         const char *name;
888 };
889
890 static struct alc_codec_rename_table rename_tbl[] = {
891         { 0x10ec0221, 0xf00f, 0x1003, "ALC231" },
892         { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
893         { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
894         { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
895         { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
896         { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
897         { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
898         { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
899         { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
900         { 0x10ec0662, 0xffff, 0x4020, "ALC656" },
901         { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
902         { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
903         { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
904         { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
905         { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
906         { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
907         { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
908         { } /* terminator */
909 };
910
911 static struct alc_codec_rename_pci_table rename_pci_tbl[] = {
912         { 0x10ec0280, 0x1028, 0, "ALC3220" },
913         { 0x10ec0282, 0x1028, 0, "ALC3221" },
914         { 0x10ec0283, 0x1028, 0, "ALC3223" },
915         { 0x10ec0288, 0x1028, 0, "ALC3263" },
916         { 0x10ec0292, 0x1028, 0, "ALC3226" },
917         { 0x10ec0293, 0x1028, 0, "ALC3235" },
918         { 0x10ec0255, 0x1028, 0, "ALC3234" },
919         { 0x10ec0668, 0x1028, 0, "ALC3661" },
920         { 0x10ec0275, 0x1028, 0, "ALC3260" },
921         { 0x10ec0899, 0x1028, 0, "ALC3861" },
922         { 0x10ec0298, 0x1028, 0, "ALC3266" },
923         { 0x10ec0236, 0x1028, 0, "ALC3204" },
924         { 0x10ec0256, 0x1028, 0, "ALC3246" },
925         { 0x10ec0225, 0x1028, 0, "ALC3253" },
926         { 0x10ec0295, 0x1028, 0, "ALC3254" },
927         { 0x10ec0299, 0x1028, 0, "ALC3271" },
928         { 0x10ec0670, 0x1025, 0, "ALC669X" },
929         { 0x10ec0676, 0x1025, 0, "ALC679X" },
930         { 0x10ec0282, 0x1043, 0, "ALC3229" },
931         { 0x10ec0233, 0x1043, 0, "ALC3236" },
932         { 0x10ec0280, 0x103c, 0, "ALC3228" },
933         { 0x10ec0282, 0x103c, 0, "ALC3227" },
934         { 0x10ec0286, 0x103c, 0, "ALC3242" },
935         { 0x10ec0290, 0x103c, 0, "ALC3241" },
936         { 0x10ec0668, 0x103c, 0, "ALC3662" },
937         { 0x10ec0283, 0x17aa, 0, "ALC3239" },
938         { 0x10ec0292, 0x17aa, 0, "ALC3232" },
939         { } /* terminator */
940 };
941
942 static int alc_codec_rename_from_preset(struct hda_codec *codec)
943 {
944         const struct alc_codec_rename_table *p;
945         const struct alc_codec_rename_pci_table *q;
946
947         for (p = rename_tbl; p->vendor_id; p++) {
948                 if (p->vendor_id != codec->core.vendor_id)
949                         continue;
950                 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
951                         return alc_codec_rename(codec, p->name);
952         }
953
954         if (!codec->bus->pci)
955                 return 0;
956         for (q = rename_pci_tbl; q->codec_vendor_id; q++) {
957                 if (q->codec_vendor_id != codec->core.vendor_id)
958                         continue;
959                 if (q->pci_subvendor != codec->bus->pci->subsystem_vendor)
960                         continue;
961                 if (!q->pci_subdevice ||
962                     q->pci_subdevice == codec->bus->pci->subsystem_device)
963                         return alc_codec_rename(codec, q->name);
964         }
965
966         return 0;
967 }
968
969
970 /*
971  * Digital-beep handlers
972  */
973 #ifdef CONFIG_SND_HDA_INPUT_BEEP
974 #define set_beep_amp(spec, nid, idx, dir) \
975         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
976
977 static const struct snd_pci_quirk beep_white_list[] = {
978         SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
979         SND_PCI_QUIRK(0x1043, 0x115d, "ASUS", 1),
980         SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
981         SND_PCI_QUIRK(0x1043, 0x8376, "EeePC", 1),
982         SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
983         SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
984         SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
985         SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
986         SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
987         {}
988 };
989
990 static inline int has_cdefine_beep(struct hda_codec *codec)
991 {
992         struct alc_spec *spec = codec->spec;
993         const struct snd_pci_quirk *q;
994         q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
995         if (q)
996                 return q->value;
997         return spec->cdefine.enable_pcbeep;
998 }
999 #else
1000 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
1001 #define has_cdefine_beep(codec)         0
1002 #endif
1003
1004 /* parse the BIOS configuration and set up the alc_spec */
1005 /* return 1 if successful, 0 if the proper config is not found,
1006  * or a negative error code
1007  */
1008 static int alc_parse_auto_config(struct hda_codec *codec,
1009                                  const hda_nid_t *ignore_nids,
1010                                  const hda_nid_t *ssid_nids)
1011 {
1012         struct alc_spec *spec = codec->spec;
1013         struct auto_pin_cfg *cfg = &spec->gen.autocfg;
1014         int err;
1015
1016         err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
1017                                        spec->parse_flags);
1018         if (err < 0)
1019                 return err;
1020
1021         if (ssid_nids)
1022                 alc_ssid_check(codec, ssid_nids);
1023
1024         err = snd_hda_gen_parse_auto_config(codec, cfg);
1025         if (err < 0)
1026                 return err;
1027
1028         return 1;
1029 }
1030
1031 /* common preparation job for alc_spec */
1032 static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
1033 {
1034         struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1035         int err;
1036
1037         if (!spec)
1038                 return -ENOMEM;
1039         codec->spec = spec;
1040         snd_hda_gen_spec_init(&spec->gen);
1041         spec->gen.mixer_nid = mixer_nid;
1042         spec->gen.own_eapd_ctl = 1;
1043         codec->single_adc_amp = 1;
1044         /* FIXME: do we need this for all Realtek codec models? */
1045         codec->spdif_status_reset = 1;
1046         codec->patch_ops = alc_patch_ops;
1047
1048         err = alc_codec_rename_from_preset(codec);
1049         if (err < 0) {
1050                 kfree(spec);
1051                 return err;
1052         }
1053         return 0;
1054 }
1055
1056 static int alc880_parse_auto_config(struct hda_codec *codec)
1057 {
1058         static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
1059         static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
1060         return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
1061 }
1062
1063 /*
1064  * ALC880 fix-ups
1065  */
1066 enum {
1067         ALC880_FIXUP_GPIO1,
1068         ALC880_FIXUP_GPIO2,
1069         ALC880_FIXUP_MEDION_RIM,
1070         ALC880_FIXUP_LG,
1071         ALC880_FIXUP_LG_LW25,
1072         ALC880_FIXUP_W810,
1073         ALC880_FIXUP_EAPD_COEF,
1074         ALC880_FIXUP_TCL_S700,
1075         ALC880_FIXUP_VOL_KNOB,
1076         ALC880_FIXUP_FUJITSU,
1077         ALC880_FIXUP_F1734,
1078         ALC880_FIXUP_UNIWILL,
1079         ALC880_FIXUP_UNIWILL_DIG,
1080         ALC880_FIXUP_Z71V,
1081         ALC880_FIXUP_ASUS_W5A,
1082         ALC880_FIXUP_3ST_BASE,
1083         ALC880_FIXUP_3ST,
1084         ALC880_FIXUP_3ST_DIG,
1085         ALC880_FIXUP_5ST_BASE,
1086         ALC880_FIXUP_5ST,
1087         ALC880_FIXUP_5ST_DIG,
1088         ALC880_FIXUP_6ST_BASE,
1089         ALC880_FIXUP_6ST,
1090         ALC880_FIXUP_6ST_DIG,
1091         ALC880_FIXUP_6ST_AUTOMUTE,
1092 };
1093
1094 /* enable the volume-knob widget support on NID 0x21 */
1095 static void alc880_fixup_vol_knob(struct hda_codec *codec,
1096                                   const struct hda_fixup *fix, int action)
1097 {
1098         if (action == HDA_FIXUP_ACT_PROBE)
1099                 snd_hda_jack_detect_enable_callback(codec, 0x21,
1100                                                     alc_update_knob_master);
1101 }
1102
1103 static const struct hda_fixup alc880_fixups[] = {
1104         [ALC880_FIXUP_GPIO1] = {
1105                 .type = HDA_FIXUP_VERBS,
1106                 .v.verbs = alc_gpio1_init_verbs,
1107         },
1108         [ALC880_FIXUP_GPIO2] = {
1109                 .type = HDA_FIXUP_VERBS,
1110                 .v.verbs = alc_gpio2_init_verbs,
1111         },
1112         [ALC880_FIXUP_MEDION_RIM] = {
1113                 .type = HDA_FIXUP_VERBS,
1114                 .v.verbs = (const struct hda_verb[]) {
1115                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1116                         { 0x20, AC_VERB_SET_PROC_COEF,  0x3060 },
1117                         { }
1118                 },
1119                 .chained = true,
1120                 .chain_id = ALC880_FIXUP_GPIO2,
1121         },
1122         [ALC880_FIXUP_LG] = {
1123                 .type = HDA_FIXUP_PINS,
1124                 .v.pins = (const struct hda_pintbl[]) {
1125                         /* disable bogus unused pins */
1126                         { 0x16, 0x411111f0 },
1127                         { 0x18, 0x411111f0 },
1128                         { 0x1a, 0x411111f0 },
1129                         { }
1130                 }
1131         },
1132         [ALC880_FIXUP_LG_LW25] = {
1133                 .type = HDA_FIXUP_PINS,
1134                 .v.pins = (const struct hda_pintbl[]) {
1135                         { 0x1a, 0x0181344f }, /* line-in */
1136                         { 0x1b, 0x0321403f }, /* headphone */
1137                         { }
1138                 }
1139         },
1140         [ALC880_FIXUP_W810] = {
1141                 .type = HDA_FIXUP_PINS,
1142                 .v.pins = (const struct hda_pintbl[]) {
1143                         /* disable bogus unused pins */
1144                         { 0x17, 0x411111f0 },
1145                         { }
1146                 },
1147                 .chained = true,
1148                 .chain_id = ALC880_FIXUP_GPIO2,
1149         },
1150         [ALC880_FIXUP_EAPD_COEF] = {
1151                 .type = HDA_FIXUP_VERBS,
1152                 .v.verbs = (const struct hda_verb[]) {
1153                         /* change to EAPD mode */
1154                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1155                         { 0x20, AC_VERB_SET_PROC_COEF,  0x3060 },
1156                         {}
1157                 },
1158         },
1159         [ALC880_FIXUP_TCL_S700] = {
1160                 .type = HDA_FIXUP_VERBS,
1161                 .v.verbs = (const struct hda_verb[]) {
1162                         /* change to EAPD mode */
1163                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1164                         { 0x20, AC_VERB_SET_PROC_COEF,  0x3070 },
1165                         {}
1166                 },
1167                 .chained = true,
1168                 .chain_id = ALC880_FIXUP_GPIO2,
1169         },
1170         [ALC880_FIXUP_VOL_KNOB] = {
1171                 .type = HDA_FIXUP_FUNC,
1172                 .v.func = alc880_fixup_vol_knob,
1173         },
1174         [ALC880_FIXUP_FUJITSU] = {
1175                 /* override all pins as BIOS on old Amilo is broken */
1176                 .type = HDA_FIXUP_PINS,
1177                 .v.pins = (const struct hda_pintbl[]) {
1178                         { 0x14, 0x0121401f }, /* HP */
1179                         { 0x15, 0x99030120 }, /* speaker */
1180                         { 0x16, 0x99030130 }, /* bass speaker */
1181                         { 0x17, 0x411111f0 }, /* N/A */
1182                         { 0x18, 0x411111f0 }, /* N/A */
1183                         { 0x19, 0x01a19950 }, /* mic-in */
1184                         { 0x1a, 0x411111f0 }, /* N/A */
1185                         { 0x1b, 0x411111f0 }, /* N/A */
1186                         { 0x1c, 0x411111f0 }, /* N/A */
1187                         { 0x1d, 0x411111f0 }, /* N/A */
1188                         { 0x1e, 0x01454140 }, /* SPDIF out */
1189                         { }
1190                 },
1191                 .chained = true,
1192                 .chain_id = ALC880_FIXUP_VOL_KNOB,
1193         },
1194         [ALC880_FIXUP_F1734] = {
1195                 /* almost compatible with FUJITSU, but no bass and SPDIF */
1196                 .type = HDA_FIXUP_PINS,
1197                 .v.pins = (const struct hda_pintbl[]) {
1198                         { 0x14, 0x0121401f }, /* HP */
1199                         { 0x15, 0x99030120 }, /* speaker */
1200                         { 0x16, 0x411111f0 }, /* N/A */
1201                         { 0x17, 0x411111f0 }, /* N/A */
1202                         { 0x18, 0x411111f0 }, /* N/A */
1203                         { 0x19, 0x01a19950 }, /* mic-in */
1204                         { 0x1a, 0x411111f0 }, /* N/A */
1205                         { 0x1b, 0x411111f0 }, /* N/A */
1206                         { 0x1c, 0x411111f0 }, /* N/A */
1207                         { 0x1d, 0x411111f0 }, /* N/A */
1208                         { 0x1e, 0x411111f0 }, /* N/A */
1209                         { }
1210                 },
1211                 .chained = true,
1212                 .chain_id = ALC880_FIXUP_VOL_KNOB,
1213         },
1214         [ALC880_FIXUP_UNIWILL] = {
1215                 /* need to fix HP and speaker pins to be parsed correctly */
1216                 .type = HDA_FIXUP_PINS,
1217                 .v.pins = (const struct hda_pintbl[]) {
1218                         { 0x14, 0x0121411f }, /* HP */
1219                         { 0x15, 0x99030120 }, /* speaker */
1220                         { 0x16, 0x99030130 }, /* bass speaker */
1221                         { }
1222                 },
1223         },
1224         [ALC880_FIXUP_UNIWILL_DIG] = {
1225                 .type = HDA_FIXUP_PINS,
1226                 .v.pins = (const struct hda_pintbl[]) {
1227                         /* disable bogus unused pins */
1228                         { 0x17, 0x411111f0 },
1229                         { 0x19, 0x411111f0 },
1230                         { 0x1b, 0x411111f0 },
1231                         { 0x1f, 0x411111f0 },
1232                         { }
1233                 }
1234         },
1235         [ALC880_FIXUP_Z71V] = {
1236                 .type = HDA_FIXUP_PINS,
1237                 .v.pins = (const struct hda_pintbl[]) {
1238                         /* set up the whole pins as BIOS is utterly broken */
1239                         { 0x14, 0x99030120 }, /* speaker */
1240                         { 0x15, 0x0121411f }, /* HP */
1241                         { 0x16, 0x411111f0 }, /* N/A */
1242                         { 0x17, 0x411111f0 }, /* N/A */
1243                         { 0x18, 0x01a19950 }, /* mic-in */
1244                         { 0x19, 0x411111f0 }, /* N/A */
1245                         { 0x1a, 0x01813031 }, /* line-in */
1246                         { 0x1b, 0x411111f0 }, /* N/A */
1247                         { 0x1c, 0x411111f0 }, /* N/A */
1248                         { 0x1d, 0x411111f0 }, /* N/A */
1249                         { 0x1e, 0x0144111e }, /* SPDIF */
1250                         { }
1251                 }
1252         },
1253         [ALC880_FIXUP_ASUS_W5A] = {
1254                 .type = HDA_FIXUP_PINS,
1255                 .v.pins = (const struct hda_pintbl[]) {
1256                         /* set up the whole pins as BIOS is utterly broken */
1257                         { 0x14, 0x0121411f }, /* HP */
1258                         { 0x15, 0x411111f0 }, /* N/A */
1259                         { 0x16, 0x411111f0 }, /* N/A */
1260                         { 0x17, 0x411111f0 }, /* N/A */
1261                         { 0x18, 0x90a60160 }, /* mic */
1262                         { 0x19, 0x411111f0 }, /* N/A */
1263                         { 0x1a, 0x411111f0 }, /* N/A */
1264                         { 0x1b, 0x411111f0 }, /* N/A */
1265                         { 0x1c, 0x411111f0 }, /* N/A */
1266                         { 0x1d, 0x411111f0 }, /* N/A */
1267                         { 0x1e, 0xb743111e }, /* SPDIF out */
1268                         { }
1269                 },
1270                 .chained = true,
1271                 .chain_id = ALC880_FIXUP_GPIO1,
1272         },
1273         [ALC880_FIXUP_3ST_BASE] = {
1274                 .type = HDA_FIXUP_PINS,
1275                 .v.pins = (const struct hda_pintbl[]) {
1276                         { 0x14, 0x01014010 }, /* line-out */
1277                         { 0x15, 0x411111f0 }, /* N/A */
1278                         { 0x16, 0x411111f0 }, /* N/A */
1279                         { 0x17, 0x411111f0 }, /* N/A */
1280                         { 0x18, 0x01a19c30 }, /* mic-in */
1281                         { 0x19, 0x0121411f }, /* HP */
1282                         { 0x1a, 0x01813031 }, /* line-in */
1283                         { 0x1b, 0x02a19c40 }, /* front-mic */
1284                         { 0x1c, 0x411111f0 }, /* N/A */
1285                         { 0x1d, 0x411111f0 }, /* N/A */
1286                         /* 0x1e is filled in below */
1287                         { 0x1f, 0x411111f0 }, /* N/A */
1288                         { }
1289                 }
1290         },
1291         [ALC880_FIXUP_3ST] = {
1292                 .type = HDA_FIXUP_PINS,
1293                 .v.pins = (const struct hda_pintbl[]) {
1294                         { 0x1e, 0x411111f0 }, /* N/A */
1295                         { }
1296                 },
1297                 .chained = true,
1298                 .chain_id = ALC880_FIXUP_3ST_BASE,
1299         },
1300         [ALC880_FIXUP_3ST_DIG] = {
1301                 .type = HDA_FIXUP_PINS,
1302                 .v.pins = (const struct hda_pintbl[]) {
1303                         { 0x1e, 0x0144111e }, /* SPDIF */
1304                         { }
1305                 },
1306                 .chained = true,
1307                 .chain_id = ALC880_FIXUP_3ST_BASE,
1308         },
1309         [ALC880_FIXUP_5ST_BASE] = {
1310                 .type = HDA_FIXUP_PINS,
1311                 .v.pins = (const struct hda_pintbl[]) {
1312                         { 0x14, 0x01014010 }, /* front */
1313                         { 0x15, 0x411111f0 }, /* N/A */
1314                         { 0x16, 0x01011411 }, /* CLFE */
1315                         { 0x17, 0x01016412 }, /* surr */
1316                         { 0x18, 0x01a19c30 }, /* mic-in */
1317                         { 0x19, 0x0121411f }, /* HP */
1318                         { 0x1a, 0x01813031 }, /* line-in */
1319                         { 0x1b, 0x02a19c40 }, /* front-mic */
1320                         { 0x1c, 0x411111f0 }, /* N/A */
1321                         { 0x1d, 0x411111f0 }, /* N/A */
1322                         /* 0x1e is filled in below */
1323                         { 0x1f, 0x411111f0 }, /* N/A */
1324                         { }
1325                 }
1326         },
1327         [ALC880_FIXUP_5ST] = {
1328                 .type = HDA_FIXUP_PINS,
1329                 .v.pins = (const struct hda_pintbl[]) {
1330                         { 0x1e, 0x411111f0 }, /* N/A */
1331                         { }
1332                 },
1333                 .chained = true,
1334                 .chain_id = ALC880_FIXUP_5ST_BASE,
1335         },
1336         [ALC880_FIXUP_5ST_DIG] = {
1337                 .type = HDA_FIXUP_PINS,
1338                 .v.pins = (const struct hda_pintbl[]) {
1339                         { 0x1e, 0x0144111e }, /* SPDIF */
1340                         { }
1341                 },
1342                 .chained = true,
1343                 .chain_id = ALC880_FIXUP_5ST_BASE,
1344         },
1345         [ALC880_FIXUP_6ST_BASE] = {
1346                 .type = HDA_FIXUP_PINS,
1347                 .v.pins = (const struct hda_pintbl[]) {
1348                         { 0x14, 0x01014010 }, /* front */
1349                         { 0x15, 0x01016412 }, /* surr */
1350                         { 0x16, 0x01011411 }, /* CLFE */
1351                         { 0x17, 0x01012414 }, /* side */
1352                         { 0x18, 0x01a19c30 }, /* mic-in */
1353                         { 0x19, 0x02a19c40 }, /* front-mic */
1354                         { 0x1a, 0x01813031 }, /* line-in */
1355                         { 0x1b, 0x0121411f }, /* HP */
1356                         { 0x1c, 0x411111f0 }, /* N/A */
1357                         { 0x1d, 0x411111f0 }, /* N/A */
1358                         /* 0x1e is filled in below */
1359                         { 0x1f, 0x411111f0 }, /* N/A */
1360                         { }
1361                 }
1362         },
1363         [ALC880_FIXUP_6ST] = {
1364                 .type = HDA_FIXUP_PINS,
1365                 .v.pins = (const struct hda_pintbl[]) {
1366                         { 0x1e, 0x411111f0 }, /* N/A */
1367                         { }
1368                 },
1369                 .chained = true,
1370                 .chain_id = ALC880_FIXUP_6ST_BASE,
1371         },
1372         [ALC880_FIXUP_6ST_DIG] = {
1373                 .type = HDA_FIXUP_PINS,
1374                 .v.pins = (const struct hda_pintbl[]) {
1375                         { 0x1e, 0x0144111e }, /* SPDIF */
1376                         { }
1377                 },
1378                 .chained = true,
1379                 .chain_id = ALC880_FIXUP_6ST_BASE,
1380         },
1381         [ALC880_FIXUP_6ST_AUTOMUTE] = {
1382                 .type = HDA_FIXUP_PINS,
1383                 .v.pins = (const struct hda_pintbl[]) {
1384                         { 0x1b, 0x0121401f }, /* HP with jack detect */
1385                         { }
1386                 },
1387                 .chained_before = true,
1388                 .chain_id = ALC880_FIXUP_6ST_BASE,
1389         },
1390 };
1391
1392 static const struct snd_pci_quirk alc880_fixup_tbl[] = {
1393         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
1394         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS W5A", ALC880_FIXUP_ASUS_W5A),
1395         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
1396         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
1397         SND_PCI_QUIRK(0x147b, 0x1045, "ABit AA8XE", ALC880_FIXUP_6ST_AUTOMUTE),
1398         SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
1399         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
1400         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
1401         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
1402         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
1403         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
1404         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
1405         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
1406         SND_PCI_QUIRK(0x1631, 0xe011, "PB 13201056", ALC880_FIXUP_6ST_AUTOMUTE),
1407         SND_PCI_QUIRK(0x1734, 0x107c, "FSC Amilo M1437", ALC880_FIXUP_FUJITSU),
1408         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
1409         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
1410         SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
1411         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
1412         SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
1413         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
1414         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_FIXUP_LG_LW25),
1415         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
1416
1417         /* Below is the copied entries from alc880_quirks.c.
1418          * It's not quite sure whether BIOS sets the correct pin-config table
1419          * on these machines, thus they are kept to be compatible with
1420          * the old static quirks.  Once when it's confirmed to work without
1421          * these overrides, it'd be better to remove.
1422          */
1423         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
1424         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
1425         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
1426         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
1427         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
1428         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
1429         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
1430         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
1431         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
1432         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
1433         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
1434         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
1435         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
1436         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
1437         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
1438         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
1439         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
1440         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
1441         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
1442         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
1443         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
1444         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
1445         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
1446         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1447         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1448         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1449         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
1450         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1451         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
1452         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
1453         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1454         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1455         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1456         /* default Intel */
1457         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
1458         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
1459         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
1460         {}
1461 };
1462
1463 static const struct hda_model_fixup alc880_fixup_models[] = {
1464         {.id = ALC880_FIXUP_3ST, .name = "3stack"},
1465         {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
1466         {.id = ALC880_FIXUP_5ST, .name = "5stack"},
1467         {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
1468         {.id = ALC880_FIXUP_6ST, .name = "6stack"},
1469         {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
1470         {.id = ALC880_FIXUP_6ST_AUTOMUTE, .name = "6stack-automute"},
1471         {}
1472 };
1473
1474
1475 /*
1476  * OK, here we have finally the patch for ALC880
1477  */
1478 static int patch_alc880(struct hda_codec *codec)
1479 {
1480         struct alc_spec *spec;
1481         int err;
1482
1483         err = alc_alloc_spec(codec, 0x0b);
1484         if (err < 0)
1485                 return err;
1486
1487         spec = codec->spec;
1488         spec->gen.need_dac_fix = 1;
1489         spec->gen.beep_nid = 0x01;
1490
1491         codec->patch_ops.unsol_event = alc880_unsol_event;
1492
1493         snd_hda_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
1494                        alc880_fixups);
1495         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1496
1497         /* automatic parse from the BIOS config */
1498         err = alc880_parse_auto_config(codec);
1499         if (err < 0)
1500                 goto error;
1501
1502         if (!spec->gen.no_analog)
1503                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
1504
1505         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1506
1507         return 0;
1508
1509  error:
1510         alc_free(codec);
1511         return err;
1512 }
1513
1514
1515 /*
1516  * ALC260 support
1517  */
1518 static int alc260_parse_auto_config(struct hda_codec *codec)
1519 {
1520         static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
1521         static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
1522         return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
1523 }
1524
1525 /*
1526  * Pin config fixes
1527  */
1528 enum {
1529         ALC260_FIXUP_HP_DC5750,
1530         ALC260_FIXUP_HP_PIN_0F,
1531         ALC260_FIXUP_COEF,
1532         ALC260_FIXUP_GPIO1,
1533         ALC260_FIXUP_GPIO1_TOGGLE,
1534         ALC260_FIXUP_REPLACER,
1535         ALC260_FIXUP_HP_B1900,
1536         ALC260_FIXUP_KN1,
1537         ALC260_FIXUP_FSC_S7020,
1538         ALC260_FIXUP_FSC_S7020_JWSE,
1539         ALC260_FIXUP_VAIO_PINS,
1540 };
1541
1542 static void alc260_gpio1_automute(struct hda_codec *codec)
1543 {
1544         struct alc_spec *spec = codec->spec;
1545         snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
1546                             spec->gen.hp_jack_present);
1547 }
1548
1549 static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
1550                                       const struct hda_fixup *fix, int action)
1551 {
1552         struct alc_spec *spec = codec->spec;
1553         if (action == HDA_FIXUP_ACT_PROBE) {
1554                 /* although the machine has only one output pin, we need to
1555                  * toggle GPIO1 according to the jack state
1556                  */
1557                 spec->gen.automute_hook = alc260_gpio1_automute;
1558                 spec->gen.detect_hp = 1;
1559                 spec->gen.automute_speaker = 1;
1560                 spec->gen.autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
1561                 snd_hda_jack_detect_enable_callback(codec, 0x0f,
1562                                                     snd_hda_gen_hp_automute);
1563                 snd_hda_add_verbs(codec, alc_gpio1_init_verbs);
1564         }
1565 }
1566
1567 static void alc260_fixup_kn1(struct hda_codec *codec,
1568                              const struct hda_fixup *fix, int action)
1569 {
1570         struct alc_spec *spec = codec->spec;
1571         static const struct hda_pintbl pincfgs[] = {
1572                 { 0x0f, 0x02214000 }, /* HP/speaker */
1573                 { 0x12, 0x90a60160 }, /* int mic */
1574                 { 0x13, 0x02a19000 }, /* ext mic */
1575                 { 0x18, 0x01446000 }, /* SPDIF out */
1576                 /* disable bogus I/O pins */
1577                 { 0x10, 0x411111f0 },
1578                 { 0x11, 0x411111f0 },
1579                 { 0x14, 0x411111f0 },
1580                 { 0x15, 0x411111f0 },
1581                 { 0x16, 0x411111f0 },
1582                 { 0x17, 0x411111f0 },
1583                 { 0x19, 0x411111f0 },
1584                 { }
1585         };
1586
1587         switch (action) {
1588         case HDA_FIXUP_ACT_PRE_PROBE:
1589                 snd_hda_apply_pincfgs(codec, pincfgs);
1590                 break;
1591         case HDA_FIXUP_ACT_PROBE:
1592                 spec->init_amp = ALC_INIT_NONE;
1593                 break;
1594         }
1595 }
1596
1597 static void alc260_fixup_fsc_s7020(struct hda_codec *codec,
1598                                    const struct hda_fixup *fix, int action)
1599 {
1600         struct alc_spec *spec = codec->spec;
1601         if (action == HDA_FIXUP_ACT_PROBE)
1602                 spec->init_amp = ALC_INIT_NONE;
1603 }
1604
1605 static void alc260_fixup_fsc_s7020_jwse(struct hda_codec *codec,
1606                                    const struct hda_fixup *fix, int action)
1607 {
1608         struct alc_spec *spec = codec->spec;
1609         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1610                 spec->gen.add_jack_modes = 1;
1611                 spec->gen.hp_mic = 1;
1612         }
1613 }
1614
1615 static const struct hda_fixup alc260_fixups[] = {
1616         [ALC260_FIXUP_HP_DC5750] = {
1617                 .type = HDA_FIXUP_PINS,
1618                 .v.pins = (const struct hda_pintbl[]) {
1619                         { 0x11, 0x90130110 }, /* speaker */
1620                         { }
1621                 }
1622         },
1623         [ALC260_FIXUP_HP_PIN_0F] = {
1624                 .type = HDA_FIXUP_PINS,
1625                 .v.pins = (const struct hda_pintbl[]) {
1626                         { 0x0f, 0x01214000 }, /* HP */
1627                         { }
1628                 }
1629         },
1630         [ALC260_FIXUP_COEF] = {
1631                 .type = HDA_FIXUP_VERBS,
1632                 .v.verbs = (const struct hda_verb[]) {
1633                         { 0x1a, AC_VERB_SET_COEF_INDEX, 0x07 },
1634                         { 0x1a, AC_VERB_SET_PROC_COEF,  0x3040 },
1635                         { }
1636                 },
1637         },
1638         [ALC260_FIXUP_GPIO1] = {
1639                 .type = HDA_FIXUP_VERBS,
1640                 .v.verbs = alc_gpio1_init_verbs,
1641         },
1642         [ALC260_FIXUP_GPIO1_TOGGLE] = {
1643                 .type = HDA_FIXUP_FUNC,
1644                 .v.func = alc260_fixup_gpio1_toggle,
1645                 .chained = true,
1646                 .chain_id = ALC260_FIXUP_HP_PIN_0F,
1647         },
1648         [ALC260_FIXUP_REPLACER] = {
1649                 .type = HDA_FIXUP_VERBS,
1650                 .v.verbs = (const struct hda_verb[]) {
1651                         { 0x1a, AC_VERB_SET_COEF_INDEX, 0x07 },
1652                         { 0x1a, AC_VERB_SET_PROC_COEF,  0x3050 },
1653                         { }
1654                 },
1655                 .chained = true,
1656                 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
1657         },
1658         [ALC260_FIXUP_HP_B1900] = {
1659                 .type = HDA_FIXUP_FUNC,
1660                 .v.func = alc260_fixup_gpio1_toggle,
1661                 .chained = true,
1662                 .chain_id = ALC260_FIXUP_COEF,
1663         },
1664         [ALC260_FIXUP_KN1] = {
1665                 .type = HDA_FIXUP_FUNC,
1666                 .v.func = alc260_fixup_kn1,
1667         },
1668         [ALC260_FIXUP_FSC_S7020] = {
1669                 .type = HDA_FIXUP_FUNC,
1670                 .v.func = alc260_fixup_fsc_s7020,
1671         },
1672         [ALC260_FIXUP_FSC_S7020_JWSE] = {
1673                 .type = HDA_FIXUP_FUNC,
1674                 .v.func = alc260_fixup_fsc_s7020_jwse,
1675                 .chained = true,
1676                 .chain_id = ALC260_FIXUP_FSC_S7020,
1677         },
1678         [ALC260_FIXUP_VAIO_PINS] = {
1679                 .type = HDA_FIXUP_PINS,
1680                 .v.pins = (const struct hda_pintbl[]) {
1681                         /* Pin configs are missing completely on some VAIOs */
1682                         { 0x0f, 0x01211020 },
1683                         { 0x10, 0x0001003f },
1684                         { 0x11, 0x411111f0 },
1685                         { 0x12, 0x01a15930 },
1686                         { 0x13, 0x411111f0 },
1687                         { 0x14, 0x411111f0 },
1688                         { 0x15, 0x411111f0 },
1689                         { 0x16, 0x411111f0 },
1690                         { 0x17, 0x411111f0 },
1691                         { 0x18, 0x411111f0 },
1692                         { 0x19, 0x411111f0 },
1693                         { }
1694                 }
1695         },
1696 };
1697
1698 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
1699         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
1700         SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
1701         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
1702         SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
1703         SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
1704         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_FIXUP_VAIO_PINS),
1705         SND_PCI_QUIRK(0x104d, 0x81e2, "Sony VAIO TX", ALC260_FIXUP_HP_PIN_0F),
1706         SND_PCI_QUIRK(0x10cf, 0x1326, "FSC LifeBook S7020", ALC260_FIXUP_FSC_S7020),
1707         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
1708         SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
1709         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
1710         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
1711         {}
1712 };
1713
1714 static const struct hda_model_fixup alc260_fixup_models[] = {
1715         {.id = ALC260_FIXUP_GPIO1, .name = "gpio1"},
1716         {.id = ALC260_FIXUP_COEF, .name = "coef"},
1717         {.id = ALC260_FIXUP_FSC_S7020, .name = "fujitsu"},
1718         {.id = ALC260_FIXUP_FSC_S7020_JWSE, .name = "fujitsu-jwse"},
1719         {}
1720 };
1721
1722 /*
1723  */
1724 static int patch_alc260(struct hda_codec *codec)
1725 {
1726         struct alc_spec *spec;
1727         int err;
1728
1729         err = alc_alloc_spec(codec, 0x07);
1730         if (err < 0)
1731                 return err;
1732
1733         spec = codec->spec;
1734         /* as quite a few machines require HP amp for speaker outputs,
1735          * it's easier to enable it unconditionally; even if it's unneeded,
1736          * it's almost harmless.
1737          */
1738         spec->gen.prefer_hp_amp = 1;
1739         spec->gen.beep_nid = 0x01;
1740
1741         spec->shutup = alc_eapd_shutup;
1742
1743         snd_hda_pick_fixup(codec, alc260_fixup_models, alc260_fixup_tbl,
1744                            alc260_fixups);
1745         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1746
1747         /* automatic parse from the BIOS config */
1748         err = alc260_parse_auto_config(codec);
1749         if (err < 0)
1750                 goto error;
1751
1752         if (!spec->gen.no_analog)
1753                 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
1754
1755         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1756
1757         return 0;
1758
1759  error:
1760         alc_free(codec);
1761         return err;
1762 }
1763
1764
1765 /*
1766  * ALC882/883/885/888/889 support
1767  *
1768  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
1769  * configuration.  Each pin widget can choose any input DACs and a mixer.
1770  * Each ADC is connected from a mixer of all inputs.  This makes possible
1771  * 6-channel independent captures.
1772  *
1773  * In addition, an independent DAC for the multi-playback (not used in this
1774  * driver yet).
1775  */
1776
1777 /*
1778  * Pin config fixes
1779  */
1780 enum {
1781         ALC882_FIXUP_ABIT_AW9D_MAX,
1782         ALC882_FIXUP_LENOVO_Y530,
1783         ALC882_FIXUP_PB_M5210,
1784         ALC882_FIXUP_ACER_ASPIRE_7736,
1785         ALC882_FIXUP_ASUS_W90V,
1786         ALC889_FIXUP_CD,
1787         ALC889_FIXUP_FRONT_HP_NO_PRESENCE,
1788         ALC889_FIXUP_VAIO_TT,
1789         ALC888_FIXUP_EEE1601,
1790         ALC882_FIXUP_EAPD,
1791         ALC883_FIXUP_EAPD,
1792         ALC883_FIXUP_ACER_EAPD,
1793         ALC882_FIXUP_GPIO1,
1794         ALC882_FIXUP_GPIO2,
1795         ALC882_FIXUP_GPIO3,
1796         ALC889_FIXUP_COEF,
1797         ALC882_FIXUP_ASUS_W2JC,
1798         ALC882_FIXUP_ACER_ASPIRE_4930G,
1799         ALC882_FIXUP_ACER_ASPIRE_8930G,
1800         ALC882_FIXUP_ASPIRE_8930G_VERBS,
1801         ALC885_FIXUP_MACPRO_GPIO,
1802         ALC889_FIXUP_DAC_ROUTE,
1803         ALC889_FIXUP_MBP_VREF,
1804         ALC889_FIXUP_IMAC91_VREF,
1805         ALC889_FIXUP_MBA11_VREF,
1806         ALC889_FIXUP_MBA21_VREF,
1807         ALC889_FIXUP_MP11_VREF,
1808         ALC889_FIXUP_MP41_VREF,
1809         ALC882_FIXUP_INV_DMIC,
1810         ALC882_FIXUP_NO_PRIMARY_HP,
1811         ALC887_FIXUP_ASUS_BASS,
1812         ALC887_FIXUP_BASS_CHMAP,
1813         ALC1220_FIXUP_GB_DUAL_CODECS,
1814 };
1815
1816 static void alc889_fixup_coef(struct hda_codec *codec,
1817                               const struct hda_fixup *fix, int action)
1818 {
1819         if (action != HDA_FIXUP_ACT_INIT)
1820                 return;
1821         alc_update_coef_idx(codec, 7, 0, 0x2030);
1822 }
1823
1824 /* toggle speaker-output according to the hp-jack state */
1825 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
1826 {
1827         unsigned int gpiostate, gpiomask, gpiodir;
1828
1829         gpiostate = snd_hda_codec_read(codec, codec->core.afg, 0,
1830                                        AC_VERB_GET_GPIO_DATA, 0);
1831
1832         if (!muted)
1833                 gpiostate |= (1 << pin);
1834         else
1835                 gpiostate &= ~(1 << pin);
1836
1837         gpiomask = snd_hda_codec_read(codec, codec->core.afg, 0,
1838                                       AC_VERB_GET_GPIO_MASK, 0);
1839         gpiomask |= (1 << pin);
1840
1841         gpiodir = snd_hda_codec_read(codec, codec->core.afg, 0,
1842                                      AC_VERB_GET_GPIO_DIRECTION, 0);
1843         gpiodir |= (1 << pin);
1844
1845
1846         snd_hda_codec_write(codec, codec->core.afg, 0,
1847                             AC_VERB_SET_GPIO_MASK, gpiomask);
1848         snd_hda_codec_write(codec, codec->core.afg, 0,
1849                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1850
1851         msleep(1);
1852
1853         snd_hda_codec_write(codec, codec->core.afg, 0,
1854                             AC_VERB_SET_GPIO_DATA, gpiostate);
1855 }
1856
1857 /* set up GPIO at initialization */
1858 static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
1859                                      const struct hda_fixup *fix, int action)
1860 {
1861         if (action != HDA_FIXUP_ACT_INIT)
1862                 return;
1863         alc882_gpio_mute(codec, 0, 0);
1864         alc882_gpio_mute(codec, 1, 0);
1865 }
1866
1867 /* Fix the connection of some pins for ALC889:
1868  * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
1869  * work correctly (bko#42740)
1870  */
1871 static void alc889_fixup_dac_route(struct hda_codec *codec,
1872                                    const struct hda_fixup *fix, int action)
1873 {
1874         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1875                 /* fake the connections during parsing the tree */
1876                 hda_nid_t conn1[2] = { 0x0c, 0x0d };
1877                 hda_nid_t conn2[2] = { 0x0e, 0x0f };
1878                 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
1879                 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
1880                 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
1881                 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
1882         } else if (action == HDA_FIXUP_ACT_PROBE) {
1883                 /* restore the connections */
1884                 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
1885                 snd_hda_override_conn_list(codec, 0x14, 5, conn);
1886                 snd_hda_override_conn_list(codec, 0x15, 5, conn);
1887                 snd_hda_override_conn_list(codec, 0x18, 5, conn);
1888                 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
1889         }
1890 }
1891
1892 /* Set VREF on HP pin */
1893 static void alc889_fixup_mbp_vref(struct hda_codec *codec,
1894                                   const struct hda_fixup *fix, int action)
1895 {
1896         struct alc_spec *spec = codec->spec;
1897         static hda_nid_t nids[3] = { 0x14, 0x15, 0x19 };
1898         int i;
1899
1900         if (action != HDA_FIXUP_ACT_INIT)
1901                 return;
1902         for (i = 0; i < ARRAY_SIZE(nids); i++) {
1903                 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
1904                 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
1905                         continue;
1906                 val = snd_hda_codec_get_pin_target(codec, nids[i]);
1907                 val |= AC_PINCTL_VREF_80;
1908                 snd_hda_set_pin_ctl(codec, nids[i], val);
1909                 spec->gen.keep_vref_in_automute = 1;
1910                 break;
1911         }
1912 }
1913
1914 static void alc889_fixup_mac_pins(struct hda_codec *codec,
1915                                   const hda_nid_t *nids, int num_nids)
1916 {
1917         struct alc_spec *spec = codec->spec;
1918         int i;
1919
1920         for (i = 0; i < num_nids; i++) {
1921                 unsigned int val;
1922                 val = snd_hda_codec_get_pin_target(codec, nids[i]);
1923                 val |= AC_PINCTL_VREF_50;
1924                 snd_hda_set_pin_ctl(codec, nids[i], val);
1925         }
1926         spec->gen.keep_vref_in_automute = 1;
1927 }
1928
1929 /* Set VREF on speaker pins on imac91 */
1930 static void alc889_fixup_imac91_vref(struct hda_codec *codec,
1931                                      const struct hda_fixup *fix, int action)
1932 {
1933         static hda_nid_t nids[2] = { 0x18, 0x1a };
1934
1935         if (action == HDA_FIXUP_ACT_INIT)
1936                 alc889_fixup_mac_pins(codec, nids, ARRAY_SIZE(nids));
1937 }
1938
1939 /* Set VREF on speaker pins on mba11 */
1940 static void alc889_fixup_mba11_vref(struct hda_codec *codec,
1941                                     const struct hda_fixup *fix, int action)
1942 {
1943         static hda_nid_t nids[1] = { 0x18 };
1944
1945         if (action == HDA_FIXUP_ACT_INIT)
1946                 alc889_fixup_mac_pins(codec, nids, ARRAY_SIZE(nids));
1947 }
1948
1949 /* Set VREF on speaker pins on mba21 */
1950 static void alc889_fixup_mba21_vref(struct hda_codec *codec,
1951                                     const struct hda_fixup *fix, int action)
1952 {
1953         static hda_nid_t nids[2] = { 0x18, 0x19 };
1954
1955         if (action == HDA_FIXUP_ACT_INIT)
1956                 alc889_fixup_mac_pins(codec, nids, ARRAY_SIZE(nids));
1957 }
1958
1959 /* Don't take HP output as primary
1960  * Strangely, the speaker output doesn't work on Vaio Z and some Vaio
1961  * all-in-one desktop PCs (for example VGC-LN51JGB) through DAC 0x05
1962  */
1963 static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
1964                                        const struct hda_fixup *fix, int action)
1965 {
1966         struct alc_spec *spec = codec->spec;
1967         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1968                 spec->gen.no_primary_hp = 1;
1969                 spec->gen.no_multi_io = 1;
1970         }
1971 }
1972
1973 static void alc_fixup_bass_chmap(struct hda_codec *codec,
1974                                  const struct hda_fixup *fix, int action);
1975
1976 /* For dual-codec configuration, we need to disable some features to avoid
1977  * conflicts of kctls and PCM streams
1978  */
1979 static void alc_fixup_dual_codecs(struct hda_codec *codec,
1980                                   const struct hda_fixup *fix, int action)
1981 {
1982         struct alc_spec *spec = codec->spec;
1983
1984         if (action != HDA_FIXUP_ACT_PRE_PROBE)
1985                 return;
1986         /* disable vmaster */
1987         spec->gen.suppress_vmaster = 1;
1988         /* auto-mute and auto-mic switch don't work with multiple codecs */
1989         spec->gen.suppress_auto_mute = 1;
1990         spec->gen.suppress_auto_mic = 1;
1991         /* disable aamix as well */
1992         spec->gen.mixer_nid = 0;
1993         /* add location prefix to avoid conflicts */
1994         codec->force_pin_prefix = 1;
1995 }
1996
1997 static void rename_ctl(struct hda_codec *codec, const char *oldname,
1998                        const char *newname)
1999 {
2000         struct snd_kcontrol *kctl;
2001
2002         kctl = snd_hda_find_mixer_ctl(codec, oldname);
2003         if (kctl)
2004                 strcpy(kctl->id.name, newname);
2005 }
2006
2007 static void alc1220_fixup_gb_dual_codecs(struct hda_codec *codec,
2008                                          const struct hda_fixup *fix,
2009                                          int action)
2010 {
2011         alc_fixup_dual_codecs(codec, fix, action);
2012         switch (action) {
2013         case HDA_FIXUP_ACT_PRE_PROBE:
2014                 /* override card longname to provide a unique UCM profile */
2015                 strcpy(codec->card->longname, "HDAudio-Gigabyte-ALC1220DualCodecs");
2016                 break;
2017         case HDA_FIXUP_ACT_BUILD:
2018                 /* rename Capture controls depending on the codec */
2019                 rename_ctl(codec, "Capture Volume",
2020                            codec->addr == 0 ?
2021                            "Rear-Panel Capture Volume" :
2022                            "Front-Panel Capture Volume");
2023                 rename_ctl(codec, "Capture Switch",
2024                            codec->addr == 0 ?
2025                            "Rear-Panel Capture Switch" :
2026                            "Front-Panel Capture Switch");
2027                 break;
2028         }
2029 }
2030
2031 static const struct hda_fixup alc882_fixups[] = {
2032         [ALC882_FIXUP_ABIT_AW9D_MAX] = {
2033                 .type = HDA_FIXUP_PINS,
2034                 .v.pins = (const struct hda_pintbl[]) {
2035                         { 0x15, 0x01080104 }, /* side */
2036                         { 0x16, 0x01011012 }, /* rear */
2037                         { 0x17, 0x01016011 }, /* clfe */
2038                         { }
2039                 }
2040         },
2041         [ALC882_FIXUP_LENOVO_Y530] = {
2042                 .type = HDA_FIXUP_PINS,
2043                 .v.pins = (const struct hda_pintbl[]) {
2044                         { 0x15, 0x99130112 }, /* rear int speakers */
2045                         { 0x16, 0x99130111 }, /* subwoofer */
2046                         { }
2047                 }
2048         },
2049         [ALC882_FIXUP_PB_M5210] = {
2050                 .type = HDA_FIXUP_PINCTLS,
2051                 .v.pins = (const struct hda_pintbl[]) {
2052                         { 0x19, PIN_VREF50 },
2053                         {}
2054                 }
2055         },
2056         [ALC882_FIXUP_ACER_ASPIRE_7736] = {
2057                 .type = HDA_FIXUP_FUNC,
2058                 .v.func = alc_fixup_sku_ignore,
2059         },
2060         [ALC882_FIXUP_ASUS_W90V] = {
2061                 .type = HDA_FIXUP_PINS,
2062                 .v.pins = (const struct hda_pintbl[]) {
2063                         { 0x16, 0x99130110 }, /* fix sequence for CLFE */
2064                         { }
2065                 }
2066         },
2067         [ALC889_FIXUP_CD] = {
2068                 .type = HDA_FIXUP_PINS,
2069                 .v.pins = (const struct hda_pintbl[]) {
2070                         { 0x1c, 0x993301f0 }, /* CD */
2071                         { }
2072                 }
2073         },
2074         [ALC889_FIXUP_FRONT_HP_NO_PRESENCE] = {
2075                 .type = HDA_FIXUP_PINS,
2076                 .v.pins = (const struct hda_pintbl[]) {
2077                         { 0x1b, 0x02214120 }, /* Front HP jack is flaky, disable jack detect */
2078                         { }
2079                 },
2080                 .chained = true,
2081                 .chain_id = ALC889_FIXUP_CD,
2082         },
2083         [ALC889_FIXUP_VAIO_TT] = {
2084                 .type = HDA_FIXUP_PINS,
2085                 .v.pins = (const struct hda_pintbl[]) {
2086                         { 0x17, 0x90170111 }, /* hidden surround speaker */
2087                         { }
2088                 }
2089         },
2090         [ALC888_FIXUP_EEE1601] = {
2091                 .type = HDA_FIXUP_VERBS,
2092                 .v.verbs = (const struct hda_verb[]) {
2093                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
2094                         { 0x20, AC_VERB_SET_PROC_COEF,  0x0838 },
2095                         { }
2096                 }
2097         },
2098         [ALC882_FIXUP_EAPD] = {
2099                 .type = HDA_FIXUP_VERBS,
2100                 .v.verbs = (const struct hda_verb[]) {
2101                         /* change to EAPD mode */
2102                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2103                         { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
2104                         { }
2105                 }
2106         },
2107         [ALC883_FIXUP_EAPD] = {
2108                 .type = HDA_FIXUP_VERBS,
2109                 .v.verbs = (const struct hda_verb[]) {
2110                         /* change to EAPD mode */
2111                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2112                         { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
2113                         { }
2114                 }
2115         },
2116         [ALC883_FIXUP_ACER_EAPD] = {
2117                 .type = HDA_FIXUP_VERBS,
2118                 .v.verbs = (const struct hda_verb[]) {
2119                         /* eanable EAPD on Acer laptops */
2120                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2121                         { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2122                         { }
2123                 }
2124         },
2125         [ALC882_FIXUP_GPIO1] = {
2126                 .type = HDA_FIXUP_VERBS,
2127                 .v.verbs = alc_gpio1_init_verbs,
2128         },
2129         [ALC882_FIXUP_GPIO2] = {
2130                 .type = HDA_FIXUP_VERBS,
2131                 .v.verbs = alc_gpio2_init_verbs,
2132         },
2133         [ALC882_FIXUP_GPIO3] = {
2134                 .type = HDA_FIXUP_VERBS,
2135                 .v.verbs = alc_gpio3_init_verbs,
2136         },
2137         [ALC882_FIXUP_ASUS_W2JC] = {
2138                 .type = HDA_FIXUP_VERBS,
2139                 .v.verbs = alc_gpio1_init_verbs,
2140                 .chained = true,
2141                 .chain_id = ALC882_FIXUP_EAPD,
2142         },
2143         [ALC889_FIXUP_COEF] = {
2144                 .type = HDA_FIXUP_FUNC,
2145                 .v.func = alc889_fixup_coef,
2146         },
2147         [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
2148                 .type = HDA_FIXUP_PINS,
2149                 .v.pins = (const struct hda_pintbl[]) {
2150                         { 0x16, 0x99130111 }, /* CLFE speaker */
2151                         { 0x17, 0x99130112 }, /* surround speaker */
2152                         { }
2153                 },
2154                 .chained = true,
2155                 .chain_id = ALC882_FIXUP_GPIO1,
2156         },
2157         [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
2158                 .type = HDA_FIXUP_PINS,
2159                 .v.pins = (const struct hda_pintbl[]) {
2160                         { 0x16, 0x99130111 }, /* CLFE speaker */
2161                         { 0x1b, 0x99130112 }, /* surround speaker */
2162                         { }
2163                 },
2164                 .chained = true,
2165                 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
2166         },
2167         [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
2168                 /* additional init verbs for Acer Aspire 8930G */
2169                 .type = HDA_FIXUP_VERBS,
2170                 .v.verbs = (const struct hda_verb[]) {
2171                         /* Enable all DACs */
2172                         /* DAC DISABLE/MUTE 1? */
2173                         /*  setting bits 1-5 disables DAC nids 0x02-0x06
2174                          *  apparently. Init=0x38 */
2175                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
2176                         { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
2177                         /* DAC DISABLE/MUTE 2? */
2178                         /*  some bit here disables the other DACs.
2179                          *  Init=0x4900 */
2180                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
2181                         { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
2182                         /* DMIC fix
2183                          * This laptop has a stereo digital microphone.
2184                          * The mics are only 1cm apart which makes the stereo
2185                          * useless. However, either the mic or the ALC889
2186                          * makes the signal become a difference/sum signal
2187                          * instead of standard stereo, which is annoying.
2188                          * So instead we flip this bit which makes the
2189                          * codec replicate the sum signal to both channels,
2190                          * turning it into a normal mono mic.
2191                          */
2192                         /* DMIC_CONTROL? Init value = 0x0001 */
2193                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
2194                         { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
2195                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2196                         { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2197                         { }
2198                 },
2199                 .chained = true,
2200                 .chain_id = ALC882_FIXUP_GPIO1,
2201         },
2202         [ALC885_FIXUP_MACPRO_GPIO] = {
2203                 .type = HDA_FIXUP_FUNC,
2204                 .v.func = alc885_fixup_macpro_gpio,
2205         },
2206         [ALC889_FIXUP_DAC_ROUTE] = {
2207                 .type = HDA_FIXUP_FUNC,
2208                 .v.func = alc889_fixup_dac_route,
2209         },
2210         [ALC889_FIXUP_MBP_VREF] = {
2211                 .type = HDA_FIXUP_FUNC,
2212                 .v.func = alc889_fixup_mbp_vref,
2213                 .chained = true,
2214                 .chain_id = ALC882_FIXUP_GPIO1,
2215         },
2216         [ALC889_FIXUP_IMAC91_VREF] = {
2217                 .type = HDA_FIXUP_FUNC,
2218                 .v.func = alc889_fixup_imac91_vref,
2219                 .chained = true,
2220                 .chain_id = ALC882_FIXUP_GPIO1,
2221         },
2222         [ALC889_FIXUP_MBA11_VREF] = {
2223                 .type = HDA_FIXUP_FUNC,
2224                 .v.func = alc889_fixup_mba11_vref,
2225                 .chained = true,
2226                 .chain_id = ALC889_FIXUP_MBP_VREF,
2227         },
2228         [ALC889_FIXUP_MBA21_VREF] = {
2229                 .type = HDA_FIXUP_FUNC,
2230                 .v.func = alc889_fixup_mba21_vref,
2231                 .chained = true,
2232                 .chain_id = ALC889_FIXUP_MBP_VREF,
2233         },
2234         [ALC889_FIXUP_MP11_VREF] = {
2235                 .type = HDA_FIXUP_FUNC,
2236                 .v.func = alc889_fixup_mba11_vref,
2237                 .chained = true,
2238                 .chain_id = ALC885_FIXUP_MACPRO_GPIO,
2239         },
2240         [ALC889_FIXUP_MP41_VREF] = {
2241                 .type = HDA_FIXUP_FUNC,
2242                 .v.func = alc889_fixup_mbp_vref,
2243                 .chained = true,
2244                 .chain_id = ALC885_FIXUP_MACPRO_GPIO,
2245         },
2246         [ALC882_FIXUP_INV_DMIC] = {
2247                 .type = HDA_FIXUP_FUNC,
2248                 .v.func = alc_fixup_inv_dmic,
2249         },
2250         [ALC882_FIXUP_NO_PRIMARY_HP] = {
2251                 .type = HDA_FIXUP_FUNC,
2252                 .v.func = alc882_fixup_no_primary_hp,
2253         },
2254         [ALC887_FIXUP_ASUS_BASS] = {
2255                 .type = HDA_FIXUP_PINS,
2256                 .v.pins = (const struct hda_pintbl[]) {
2257                         {0x16, 0x99130130}, /* bass speaker */
2258                         {}
2259                 },
2260                 .chained = true,
2261                 .chain_id = ALC887_FIXUP_BASS_CHMAP,
2262         },
2263         [ALC887_FIXUP_BASS_CHMAP] = {
2264                 .type = HDA_FIXUP_FUNC,
2265                 .v.func = alc_fixup_bass_chmap,
2266         },
2267         [ALC1220_FIXUP_GB_DUAL_CODECS] = {
2268                 .type = HDA_FIXUP_FUNC,
2269                 .v.func = alc1220_fixup_gb_dual_codecs,
2270         },
2271 };
2272
2273 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
2274         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
2275         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
2276         SND_PCI_QUIRK(0x1025, 0x0107, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
2277         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
2278         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
2279         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
2280         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
2281         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
2282                       ALC882_FIXUP_ACER_ASPIRE_4930G),
2283         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
2284                       ALC882_FIXUP_ACER_ASPIRE_4930G),
2285         SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
2286                       ALC882_FIXUP_ACER_ASPIRE_8930G),
2287         SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
2288                       ALC882_FIXUP_ACER_ASPIRE_8930G),
2289         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
2290                       ALC882_FIXUP_ACER_ASPIRE_4930G),
2291         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
2292                       ALC882_FIXUP_ACER_ASPIRE_4930G),
2293         SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
2294                       ALC882_FIXUP_ACER_ASPIRE_4930G),
2295         SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
2296         SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
2297                       ALC882_FIXUP_ACER_ASPIRE_4930G),
2298         SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
2299         SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
2300         SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
2301         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
2302         SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
2303         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
2304         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
2305         SND_PCI_QUIRK(0x1043, 0x84bc, "ASUS ET2700", ALC887_FIXUP_ASUS_BASS),
2306         SND_PCI_QUIRK(0x1043, 0x8691, "ASUS ROG Ranger VIII", ALC882_FIXUP_GPIO3),
2307         SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
2308         SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
2309         SND_PCI_QUIRK(0x104d, 0x9060, "Sony Vaio VPCL14M1R", ALC882_FIXUP_NO_PRIMARY_HP),
2310         SND_PCI_QUIRK(0x104d, 0x9043, "Sony Vaio VGC-LN51JGB", ALC882_FIXUP_NO_PRIMARY_HP),
2311         SND_PCI_QUIRK(0x104d, 0x9044, "Sony VAIO AiO", ALC882_FIXUP_NO_PRIMARY_HP),
2312
2313         /* All Apple entries are in codec SSIDs */
2314         SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
2315         SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
2316         SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
2317         SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC889_FIXUP_MP11_VREF),
2318         SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
2319         SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
2320         SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
2321         SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
2322         SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
2323         SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBA11_VREF),
2324         SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBA21_VREF),
2325         SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
2326         SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
2327         SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
2328         SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
2329         SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
2330         SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
2331         SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 4,1/5,1", ALC889_FIXUP_MP41_VREF),
2332         SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
2333         SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
2334         SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
2335         SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_MBA11_VREF),
2336
2337         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
2338         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3/Z87X-UD3H", ALC889_FIXUP_FRONT_HP_NO_PRESENCE),
2339         SND_PCI_QUIRK(0x1458, 0xa0b8, "Gigabyte AZ370-Gaming", ALC1220_FIXUP_GB_DUAL_CODECS),
2340         SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
2341         SND_PCI_QUIRK(0x1462, 0xda57, "MSI Z270-Gaming", ALC1220_FIXUP_GB_DUAL_CODECS),
2342         SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
2343         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
2344         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
2345         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
2346         SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
2347         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
2348         {}
2349 };
2350
2351 static const struct hda_model_fixup alc882_fixup_models[] = {
2352         {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
2353         {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
2354         {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
2355         {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
2356         {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
2357         {.id = ALC1220_FIXUP_GB_DUAL_CODECS, .name = "dual-codecs"},
2358         {}
2359 };
2360
2361 /*
2362  * BIOS auto configuration
2363  */
2364 /* almost identical with ALC880 parser... */
2365 static int alc882_parse_auto_config(struct hda_codec *codec)
2366 {
2367         static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
2368         static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2369         return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
2370 }
2371
2372 /*
2373  */
2374 static int patch_alc882(struct hda_codec *codec)
2375 {
2376         struct alc_spec *spec;
2377         int err;
2378
2379         err = alc_alloc_spec(codec, 0x0b);
2380         if (err < 0)
2381                 return err;
2382
2383         spec = codec->spec;
2384
2385         switch (codec->core.vendor_id) {
2386         case 0x10ec0882:
2387         case 0x10ec0885:
2388         case 0x10ec0900:
2389         case 0x10ec1220:
2390                 break;
2391         default:
2392                 /* ALC883 and variants */
2393                 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
2394                 break;
2395         }
2396
2397         snd_hda_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
2398                        alc882_fixups);
2399         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2400
2401         alc_auto_parse_customize_define(codec);
2402
2403         if (has_cdefine_beep(codec))
2404                 spec->gen.beep_nid = 0x01;
2405
2406         /* automatic parse from the BIOS config */
2407         err = alc882_parse_auto_config(codec);
2408         if (err < 0)
2409                 goto error;
2410
2411         if (!spec->gen.no_analog && spec->gen.beep_nid)
2412                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
2413
2414         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2415
2416         return 0;
2417
2418  error:
2419         alc_free(codec);
2420         return err;
2421 }
2422
2423
2424 /*
2425  * ALC262 support
2426  */
2427 static int alc262_parse_auto_config(struct hda_codec *codec)
2428 {
2429         static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
2430         static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2431         return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
2432 }
2433
2434 /*
2435  * Pin config fixes
2436  */
2437 enum {
2438         ALC262_FIXUP_FSC_H270,
2439         ALC262_FIXUP_FSC_S7110,
2440         ALC262_FIXUP_HP_Z200,
2441         ALC262_FIXUP_TYAN,
2442         ALC262_FIXUP_LENOVO_3000,
2443         ALC262_FIXUP_BENQ,
2444         ALC262_FIXUP_BENQ_T31,
2445         ALC262_FIXUP_INV_DMIC,
2446         ALC262_FIXUP_INTEL_BAYLEYBAY,
2447 };
2448
2449 static const struct hda_fixup alc262_fixups[] = {
2450         [ALC262_FIXUP_FSC_H270] = {
2451                 .type = HDA_FIXUP_PINS,
2452                 .v.pins = (const struct hda_pintbl[]) {
2453                         { 0x14, 0x99130110 }, /* speaker */
2454                         { 0x15, 0x0221142f }, /* front HP */
2455                         { 0x1b, 0x0121141f }, /* rear HP */
2456                         { }
2457                 }
2458         },
2459         [ALC262_FIXUP_FSC_S7110] = {
2460                 .type = HDA_FIXUP_PINS,
2461                 .v.pins = (const struct hda_pintbl[]) {
2462                         { 0x15, 0x90170110 }, /* speaker */
2463                         { }
2464                 },
2465                 .chained = true,
2466                 .chain_id = ALC262_FIXUP_BENQ,
2467         },
2468         [ALC262_FIXUP_HP_Z200] = {
2469                 .type = HDA_FIXUP_PINS,
2470                 .v.pins = (const struct hda_pintbl[]) {
2471                         { 0x16, 0x99130120 }, /* internal speaker */
2472                         { }
2473                 }
2474         },
2475         [ALC262_FIXUP_TYAN] = {
2476                 .type = HDA_FIXUP_PINS,
2477                 .v.pins = (const struct hda_pintbl[]) {
2478                         { 0x14, 0x1993e1f0 }, /* int AUX */
2479                         { }
2480                 }
2481         },
2482         [ALC262_FIXUP_LENOVO_3000] = {
2483                 .type = HDA_FIXUP_PINCTLS,
2484                 .v.pins = (const struct hda_pintbl[]) {
2485                         { 0x19, PIN_VREF50 },
2486                         {}
2487                 },
2488                 .chained = true,
2489                 .chain_id = ALC262_FIXUP_BENQ,
2490         },
2491         [ALC262_FIXUP_BENQ] = {
2492                 .type = HDA_FIXUP_VERBS,
2493                 .v.verbs = (const struct hda_verb[]) {
2494                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2495                         { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
2496                         {}
2497                 }
2498         },
2499         [ALC262_FIXUP_BENQ_T31] = {
2500                 .type = HDA_FIXUP_VERBS,
2501                 .v.verbs = (const struct hda_verb[]) {
2502                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2503                         { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2504                         {}
2505                 }
2506         },
2507         [ALC262_FIXUP_INV_DMIC] = {
2508                 .type = HDA_FIXUP_FUNC,
2509                 .v.func = alc_fixup_inv_dmic,
2510         },
2511         [ALC262_FIXUP_INTEL_BAYLEYBAY] = {
2512                 .type = HDA_FIXUP_FUNC,
2513                 .v.func = alc_fixup_no_depop_delay,
2514         },
2515 };
2516
2517 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
2518         SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
2519         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu Lifebook S7110", ALC262_FIXUP_FSC_S7110),
2520         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
2521         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
2522         SND_PCI_QUIRK(0x1734, 0x1141, "FSC ESPRIMO U9210", ALC262_FIXUP_FSC_H270),
2523         SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
2524         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
2525         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
2526         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
2527         SND_PCI_QUIRK(0x8086, 0x7270, "BayleyBay", ALC262_FIXUP_INTEL_BAYLEYBAY),
2528         {}
2529 };
2530
2531 static const struct hda_model_fixup alc262_fixup_models[] = {
2532         {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
2533         {}
2534 };
2535
2536 /*
2537  */
2538 static int patch_alc262(struct hda_codec *codec)
2539 {
2540         struct alc_spec *spec;
2541         int err;
2542
2543         err = alc_alloc_spec(codec, 0x0b);
2544         if (err < 0)
2545                 return err;
2546
2547         spec = codec->spec;
2548         spec->gen.shared_mic_vref_pin = 0x18;
2549
2550         spec->shutup = alc_eapd_shutup;
2551
2552 #if 0
2553         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
2554          * under-run
2555          */
2556         alc_update_coefex_idx(codec, 0x1a, 7, 0, 0x80);
2557 #endif
2558         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
2559
2560         snd_hda_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
2561                        alc262_fixups);
2562         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2563
2564         alc_auto_parse_customize_define(codec);
2565
2566         if (has_cdefine_beep(codec))
2567                 spec->gen.beep_nid = 0x01;
2568
2569         /* automatic parse from the BIOS config */
2570         err = alc262_parse_auto_config(codec);
2571         if (err < 0)
2572                 goto error;
2573
2574         if (!spec->gen.no_analog && spec->gen.beep_nid)
2575                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
2576
2577         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2578
2579         return 0;
2580
2581  error:
2582         alc_free(codec);
2583         return err;
2584 }
2585
2586 /*
2587  *  ALC268
2588  */
2589 /* bind Beep switches of both NID 0x0f and 0x10 */
2590 static int alc268_beep_switch_put(struct snd_kcontrol *kcontrol,
2591                                   struct snd_ctl_elem_value *ucontrol)
2592 {
2593         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2594         unsigned long pval;
2595         int err;
2596
2597         mutex_lock(&codec->control_mutex);
2598         pval = kcontrol->private_value;
2599         kcontrol->private_value = (pval & ~0xff) | 0x0f;
2600         err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
2601         if (err >= 0) {
2602                 kcontrol->private_value = (pval & ~0xff) | 0x10;
2603                 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
2604         }
2605         kcontrol->private_value = pval;
2606         mutex_unlock(&codec->control_mutex);
2607         return err;
2608 }
2609
2610 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
2611         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
2612         {
2613                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2614                 .name = "Beep Playback Switch",
2615                 .subdevice = HDA_SUBDEV_AMP_FLAG,
2616                 .info = snd_hda_mixer_amp_switch_info,
2617                 .get = snd_hda_mixer_amp_switch_get,
2618                 .put = alc268_beep_switch_put,
2619                 .private_value = HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT)
2620         },
2621         { }
2622 };
2623
2624 /* set PCBEEP vol = 0, mute connections */
2625 static const struct hda_verb alc268_beep_init_verbs[] = {
2626         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2627         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2628         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2629         { }
2630 };
2631
2632 enum {
2633         ALC268_FIXUP_INV_DMIC,
2634         ALC268_FIXUP_HP_EAPD,
2635         ALC268_FIXUP_SPDIF,
2636 };
2637
2638 static const struct hda_fixup alc268_fixups[] = {
2639         [ALC268_FIXUP_INV_DMIC] = {
2640                 .type = HDA_FIXUP_FUNC,
2641                 .v.func = alc_fixup_inv_dmic,
2642         },
2643         [ALC268_FIXUP_HP_EAPD] = {
2644                 .type = HDA_FIXUP_VERBS,
2645                 .v.verbs = (const struct hda_verb[]) {
2646                         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
2647                         {}
2648                 }
2649         },
2650         [ALC268_FIXUP_SPDIF] = {
2651                 .type = HDA_FIXUP_PINS,
2652                 .v.pins = (const struct hda_pintbl[]) {
2653                         { 0x1e, 0x014b1180 }, /* enable SPDIF out */
2654                         {}
2655                 }
2656         },
2657 };
2658
2659 static const struct hda_model_fixup alc268_fixup_models[] = {
2660         {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
2661         {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
2662         {}
2663 };
2664
2665 static const struct snd_pci_quirk alc268_fixup_tbl[] = {
2666         SND_PCI_QUIRK(0x1025, 0x0139, "Acer TravelMate 6293", ALC268_FIXUP_SPDIF),
2667         SND_PCI_QUIRK(0x1025, 0x015b, "Acer AOA 150 (ZG5)", ALC268_FIXUP_INV_DMIC),
2668         /* below is codec SSID since multiple Toshiba laptops have the
2669          * same PCI SSID 1179:ff00
2670          */
2671         SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
2672         {}
2673 };
2674
2675 /*
2676  * BIOS auto configuration
2677  */
2678 static int alc268_parse_auto_config(struct hda_codec *codec)
2679 {
2680         static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2681         return alc_parse_auto_config(codec, NULL, alc268_ssids);
2682 }
2683
2684 /*
2685  */
2686 static int patch_alc268(struct hda_codec *codec)
2687 {
2688         struct alc_spec *spec;
2689         int err;
2690
2691         /* ALC268 has no aa-loopback mixer */
2692         err = alc_alloc_spec(codec, 0);
2693         if (err < 0)
2694                 return err;
2695
2696         spec = codec->spec;
2697         spec->gen.beep_nid = 0x01;
2698
2699         spec->shutup = alc_eapd_shutup;
2700
2701         snd_hda_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
2702         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2703
2704         /* automatic parse from the BIOS config */
2705         err = alc268_parse_auto_config(codec);
2706         if (err < 0)
2707                 goto error;
2708
2709         if (err > 0 && !spec->gen.no_analog &&
2710             spec->gen.autocfg.speaker_pins[0] != 0x1d) {
2711                 add_mixer(spec, alc268_beep_mixer);
2712                 snd_hda_add_verbs(codec, alc268_beep_init_verbs);
2713                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
2714                         /* override the amp caps for beep generator */
2715                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
2716                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
2717                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
2718                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2719                                           (0 << AC_AMPCAP_MUTE_SHIFT));
2720         }
2721
2722         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2723
2724         return 0;
2725
2726  error:
2727         alc_free(codec);
2728         return err;
2729 }
2730
2731 /*
2732  * ALC269
2733  */
2734
2735 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
2736         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2737 };
2738
2739 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
2740         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2741 };
2742
2743 /* different alc269-variants */
2744 enum {
2745         ALC269_TYPE_ALC269VA,
2746         ALC269_TYPE_ALC269VB,
2747         ALC269_TYPE_ALC269VC,
2748         ALC269_TYPE_ALC269VD,
2749         ALC269_TYPE_ALC280,
2750         ALC269_TYPE_ALC282,
2751         ALC269_TYPE_ALC283,
2752         ALC269_TYPE_ALC284,
2753         ALC269_TYPE_ALC293,
2754         ALC269_TYPE_ALC286,
2755         ALC269_TYPE_ALC298,
2756         ALC269_TYPE_ALC255,
2757         ALC269_TYPE_ALC256,
2758         ALC269_TYPE_ALC257,
2759         ALC269_TYPE_ALC215,
2760         ALC269_TYPE_ALC225,
2761         ALC269_TYPE_ALC294,
2762         ALC269_TYPE_ALC300,
2763         ALC269_TYPE_ALC700,
2764 };
2765
2766 /*
2767  * BIOS auto configuration
2768  */
2769 static int alc269_parse_auto_config(struct hda_codec *codec)
2770 {
2771         static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
2772         static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
2773         static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2774         struct alc_spec *spec = codec->spec;
2775         const hda_nid_t *ssids;
2776
2777         switch (spec->codec_variant) {
2778         case ALC269_TYPE_ALC269VA:
2779         case ALC269_TYPE_ALC269VC:
2780         case ALC269_TYPE_ALC280:
2781         case ALC269_TYPE_ALC284:
2782         case ALC269_TYPE_ALC293:
2783                 ssids = alc269va_ssids;
2784                 break;
2785         case ALC269_TYPE_ALC269VB:
2786         case ALC269_TYPE_ALC269VD:
2787         case ALC269_TYPE_ALC282:
2788         case ALC269_TYPE_ALC283:
2789         case ALC269_TYPE_ALC286:
2790         case ALC269_TYPE_ALC298:
2791         case ALC269_TYPE_ALC255:
2792         case ALC269_TYPE_ALC256:
2793         case ALC269_TYPE_ALC257:
2794         case ALC269_TYPE_ALC215:
2795         case ALC269_TYPE_ALC225:
2796         case ALC269_TYPE_ALC294:
2797         case ALC269_TYPE_ALC300:
2798         case ALC269_TYPE_ALC700:
2799                 ssids = alc269_ssids;
2800                 break;
2801         default:
2802                 ssids = alc269_ssids;
2803                 break;
2804         }
2805
2806         return alc_parse_auto_config(codec, alc269_ignore, ssids);
2807 }
2808
2809 static int find_ext_mic_pin(struct hda_codec *codec);
2810
2811 static void alc286_shutup(struct hda_codec *codec)
2812 {
2813         int i;
2814         int mic_pin = find_ext_mic_pin(codec);
2815         /* don't shut up pins when unloading the driver; otherwise it breaks
2816          * the default pin setup at the next load of the driver
2817          */
2818         if (codec->bus->shutdown)
2819                 return;
2820         for (i = 0; i < codec->init_pins.used; i++) {
2821                 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
2822                 /* use read here for syncing after issuing each verb */
2823                 if (pin->nid != mic_pin)
2824                         snd_hda_codec_read(codec, pin->nid, 0,
2825                                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2826         }
2827         codec->pins_shutup = 1;
2828 }
2829
2830 static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
2831 {
2832         alc_update_coef_idx(codec, 0x04, 1 << 11, power_up ? (1 << 11) : 0);
2833 }
2834
2835 static void alc269_shutup(struct hda_codec *codec)
2836 {
2837         struct alc_spec *spec = codec->spec;
2838
2839         if (spec->codec_variant == ALC269_TYPE_ALC269VB)
2840                 alc269vb_toggle_power_output(codec, 0);
2841         if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
2842                         (alc_get_coef0(codec) & 0x00ff) == 0x018) {
2843                 msleep(150);
2844         }
2845         snd_hda_shutup_pins(codec);
2846 }
2847
2848 static struct coef_fw alc282_coefs[] = {
2849         WRITE_COEF(0x03, 0x0002), /* Power Down Control */
2850         UPDATE_COEF(0x05, 0xff3f, 0x0700), /* FIFO and filter clock */
2851         WRITE_COEF(0x07, 0x0200), /* DMIC control */
2852         UPDATE_COEF(0x06, 0x00f0, 0), /* Analog clock */
2853         UPDATE_COEF(0x08, 0xfffc, 0x0c2c), /* JD */
2854         WRITE_COEF(0x0a, 0xcccc), /* JD offset1 */
2855         WRITE_COEF(0x0b, 0xcccc), /* JD offset2 */
2856         WRITE_COEF(0x0e, 0x6e00), /* LDO1/2/3, DAC/ADC */
2857         UPDATE_COEF(0x0f, 0xf800, 0x1000), /* JD */
2858         UPDATE_COEF(0x10, 0xfc00, 0x0c00), /* Capless */
2859         WRITE_COEF(0x6f, 0x0), /* Class D test 4 */
2860         UPDATE_COEF(0x0c, 0xfe00, 0), /* IO power down directly */
2861         WRITE_COEF(0x34, 0xa0c0), /* ANC */
2862         UPDATE_COEF(0x16, 0x0008, 0), /* AGC MUX */
2863         UPDATE_COEF(0x1d, 0x00e0, 0), /* DAC simple content protection */
2864         UPDATE_COEF(0x1f, 0x00e0, 0), /* ADC simple content protection */
2865         WRITE_COEF(0x21, 0x8804), /* DAC ADC Zero Detection */
2866         WRITE_COEF(0x63, 0x2902), /* PLL */
2867         WRITE_COEF(0x68, 0xa080), /* capless control 2 */
2868         WRITE_COEF(0x69, 0x3400), /* capless control 3 */
2869         WRITE_COEF(0x6a, 0x2f3e), /* capless control 4 */
2870         WRITE_COEF(0x6b, 0x0), /* capless control 5 */
2871         UPDATE_COEF(0x6d, 0x0fff, 0x0900), /* class D test 2 */
2872         WRITE_COEF(0x6e, 0x110a), /* class D test 3 */
2873         UPDATE_COEF(0x70, 0x00f8, 0x00d8), /* class D test 5 */
2874         WRITE_COEF(0x71, 0x0014), /* class D test 6 */
2875         WRITE_COEF(0x72, 0xc2ba), /* classD OCP */
2876         UPDATE_COEF(0x77, 0x0f80, 0), /* classD pure DC test */
2877         WRITE_COEF(0x6c, 0xfc06), /* Class D amp control */
2878         {}
2879 };
2880
2881 static void alc282_restore_default_value(struct hda_codec *codec)
2882 {
2883         alc_process_coef_fw(codec, alc282_coefs);
2884 }
2885
2886 static void alc282_init(struct hda_codec *codec)
2887 {
2888         struct alc_spec *spec = codec->spec;
2889         hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
2890         bool hp_pin_sense;
2891         int coef78;
2892
2893         alc282_restore_default_value(codec);
2894
2895         if (!hp_pin)
2896                 return;
2897         hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
2898         coef78 = alc_read_coef_idx(codec, 0x78);
2899
2900         /* Index 0x78 Direct Drive HP AMP LPM Control 1 */
2901         /* Headphone capless set to high power mode */
2902         alc_write_coef_idx(codec, 0x78, 0x9004);
2903
2904         if (hp_pin_sense)
2905                 msleep(2);
2906
2907         snd_hda_codec_write(codec, hp_pin, 0,
2908                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
2909
2910         if (hp_pin_sense)
2911                 msleep(85);
2912
2913         snd_hda_codec_write(codec, hp_pin, 0,
2914                             AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
2915
2916         if (hp_pin_sense)
2917                 msleep(100);
2918
2919         /* Headphone capless set to normal mode */
2920         alc_write_coef_idx(codec, 0x78, coef78);
2921 }
2922
2923 static void alc282_shutup(struct hda_codec *codec)
2924 {
2925         struct alc_spec *spec = codec->spec;
2926         hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
2927         bool hp_pin_sense;
2928         int coef78;
2929
2930         if (!hp_pin) {
2931                 alc269_shutup(codec);
2932                 return;
2933         }
2934
2935         hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
2936         coef78 = alc_read_coef_idx(codec, 0x78);
2937         alc_write_coef_idx(codec, 0x78, 0x9004);
2938
2939         if (hp_pin_sense)
2940                 msleep(2);
2941
2942         snd_hda_codec_write(codec, hp_pin, 0,
2943                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
2944
2945         if (hp_pin_sense)
2946                 msleep(85);
2947
2948         snd_hda_codec_write(codec, hp_pin, 0,
2949                             AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0);
2950
2951         if (hp_pin_sense)
2952                 msleep(100);
2953
2954         alc_auto_setup_eapd(codec, false);
2955         snd_hda_shutup_pins(codec);
2956         alc_write_coef_idx(codec, 0x78, coef78);
2957 }
2958
2959 static struct coef_fw alc283_coefs[] = {
2960         WRITE_COEF(0x03, 0x0002), /* Power Down Control */
2961         UPDATE_COEF(0x05, 0xff3f, 0x0700), /* FIFO and filter clock */
2962         WRITE_COEF(0x07, 0x0200), /* DMIC control */
2963         UPDATE_COEF(0x06, 0x00f0, 0), /* Analog clock */
2964         UPDATE_COEF(0x08, 0xfffc, 0x0c2c), /* JD */
2965         WRITE_COEF(0x0a, 0xcccc), /* JD offset1 */
2966         WRITE_COEF(0x0b, 0xcccc), /* JD offset2 */
2967         WRITE_COEF(0x0e, 0x6fc0), /* LDO1/2/3, DAC/ADC */
2968         UPDATE_COEF(0x0f, 0xf800, 0x1000), /* JD */
2969         UPDATE_COEF(0x10, 0xfc00, 0x0c00), /* Capless */
2970         WRITE_COEF(0x3a, 0x0), /* Class D test 4 */
2971         UPDATE_COEF(0x0c, 0xfe00, 0x0), /* IO power down directly */
2972         WRITE_COEF(0x22, 0xa0c0), /* ANC */
2973         UPDATE_COEFEX(0x53, 0x01, 0x000f, 0x0008), /* AGC MUX */
2974         UPDATE_COEF(0x1d, 0x00e0, 0), /* DAC simple content protection */
2975         UPDATE_COEF(0x1f, 0x00e0, 0), /* ADC simple content protection */
2976         WRITE_COEF(0x21, 0x8804), /* DAC ADC Zero Detection */
2977         WRITE_COEF(0x2e, 0x2902), /* PLL */
2978         WRITE_COEF(0x33, 0xa080), /* capless control 2 */
2979         WRITE_COEF(0x34, 0x3400), /* capless control 3 */
2980         WRITE_COEF(0x35, 0x2f3e), /* capless control 4 */
2981         WRITE_COEF(0x36, 0x0), /* capless control 5 */
2982         UPDATE_COEF(0x38, 0x0fff, 0x0900), /* class D test 2 */
2983         WRITE_COEF(0x39, 0x110a), /* class D test 3 */
2984         UPDATE_COEF(0x3b, 0x00f8, 0x00d8), /* class D test 5 */
2985         WRITE_COEF(0x3c, 0x0014), /* class D test 6 */
2986         WRITE_COEF(0x3d, 0xc2ba), /* classD OCP */
2987         UPDATE_COEF(0x42, 0x0f80, 0x0), /* classD pure DC test */
2988         WRITE_COEF(0x49, 0x0), /* test mode */
2989         UPDATE_COEF(0x40, 0xf800, 0x9800), /* Class D DC enable */
2990         UPDATE_COEF(0x42, 0xf000, 0x2000), /* DC offset */
2991         WRITE_COEF(0x37, 0xfc06), /* Class D amp control */
2992         UPDATE_COEF(0x1b, 0x8000, 0), /* HP JD control */
2993         {}
2994 };
2995
2996 static void alc283_restore_default_value(struct hda_codec *codec)
2997 {
2998         alc_process_coef_fw(codec, alc283_coefs);
2999 }
3000
3001 static void alc283_init(struct hda_codec *codec)
3002 {
3003         struct alc_spec *spec = codec->spec;
3004         hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3005         bool hp_pin_sense;
3006
3007         if (!spec->gen.autocfg.hp_outs) {
3008                 if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
3009                         hp_pin = spec->gen.autocfg.line_out_pins[0];
3010         }
3011
3012         alc283_restore_default_value(codec);
3013
3014         if (!hp_pin)
3015                 return;
3016
3017         msleep(30);
3018         hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
3019
3020         /* Index 0x43 Direct Drive HP AMP LPM Control 1 */
3021         /* Headphone capless set to high power mode */
3022         alc_write_coef_idx(codec, 0x43, 0x9004);
3023
3024         snd_hda_codec_write(codec, hp_pin, 0,
3025                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
3026
3027         if (hp_pin_sense)
3028                 msleep(85);
3029
3030         snd_hda_codec_write(codec, hp_pin, 0,
3031                             AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3032
3033         if (hp_pin_sense)
3034                 msleep(85);
3035         /* Index 0x46 Combo jack auto switch control 2 */
3036         /* 3k pull low control for Headset jack. */
3037         alc_update_coef_idx(codec, 0x46, 3 << 12, 0);
3038         /* Headphone capless set to normal mode */
3039         alc_write_coef_idx(codec, 0x43, 0x9614);
3040 }
3041
3042 static void alc283_shutup(struct hda_codec *codec)
3043 {
3044         struct alc_spec *spec = codec->spec;
3045         hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3046         bool hp_pin_sense;
3047
3048         if (!spec->gen.autocfg.hp_outs) {
3049                 if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
3050                         hp_pin = spec->gen.autocfg.line_out_pins[0];
3051         }
3052
3053         if (!hp_pin) {
3054                 alc269_shutup(codec);
3055                 return;
3056         }
3057
3058         hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
3059
3060         alc_write_coef_idx(codec, 0x43, 0x9004);
3061
3062         /*depop hp during suspend*/
3063         alc_write_coef_idx(codec, 0x06, 0x2100);
3064
3065         snd_hda_codec_write(codec, hp_pin, 0,
3066                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
3067
3068         if (hp_pin_sense)
3069                 msleep(100);
3070
3071         snd_hda_codec_write(codec, hp_pin, 0,
3072                             AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0);
3073
3074         alc_update_coef_idx(codec, 0x46, 0, 3 << 12);
3075
3076         if (hp_pin_sense)
3077                 msleep(100);
3078         alc_auto_setup_eapd(codec, false);
3079         snd_hda_shutup_pins(codec);
3080         alc_write_coef_idx(codec, 0x43, 0x9614);
3081 }
3082
3083 static void alc256_init(struct hda_codec *codec)
3084 {
3085         struct alc_spec *spec = codec->spec;
3086         hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3087         bool hp_pin_sense;
3088
3089         if (!hp_pin)
3090                 return;
3091
3092         msleep(30);
3093
3094         hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
3095
3096         if (hp_pin_sense)
3097                 msleep(2);
3098
3099         alc_update_coefex_idx(codec, 0x57, 0x04, 0x0007, 0x1); /* Low power */
3100
3101         snd_hda_codec_write(codec, hp_pin, 0,
3102                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
3103
3104         if (hp_pin_sense)
3105                 msleep(85);
3106
3107         snd_hda_codec_write(codec, hp_pin, 0,
3108                             AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3109
3110         if (hp_pin_sense)
3111                 msleep(100);
3112
3113         alc_update_coef_idx(codec, 0x46, 3 << 12, 0);
3114         alc_update_coefex_idx(codec, 0x57, 0x04, 0x0007, 0x4); /* Hight power */
3115         alc_update_coefex_idx(codec, 0x53, 0x02, 0x8000, 1 << 15); /* Clear bit */
3116         alc_update_coefex_idx(codec, 0x53, 0x02, 0x8000, 0 << 15);
3117 }
3118
3119 static void alc256_shutup(struct hda_codec *codec)
3120 {
3121         struct alc_spec *spec = codec->spec;
3122         hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3123         bool hp_pin_sense;
3124
3125         if (!hp_pin) {
3126                 alc269_shutup(codec);
3127                 return;
3128         }
3129
3130         hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
3131
3132         if (hp_pin_sense)
3133                 msleep(2);
3134
3135         snd_hda_codec_write(codec, hp_pin, 0,
3136                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
3137
3138         if (hp_pin_sense)
3139                 msleep(85);
3140
3141         /* 3k pull low control for Headset jack. */
3142         /* NOTE: call this before clearing the pin, otherwise codec stalls */
3143         alc_update_coef_idx(codec, 0x46, 0, 3 << 12);
3144
3145         snd_hda_codec_write(codec, hp_pin, 0,
3146                             AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0);
3147
3148         if (hp_pin_sense)
3149                 msleep(100);
3150
3151         alc_auto_setup_eapd(codec, false);
3152         snd_hda_shutup_pins(codec);
3153 }
3154
3155 static void alc_default_init(struct hda_codec *codec)
3156 {
3157         struct alc_spec *spec = codec->spec;
3158         hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3159         bool hp_pin_sense;
3160
3161         if (!hp_pin)
3162                 return;
3163
3164         msleep(30);
3165
3166         hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
3167
3168         if (hp_pin_sense)
3169                 msleep(2);
3170
3171         snd_hda_codec_write(codec, hp_pin, 0,
3172                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
3173
3174         if (hp_pin_sense)
3175                 msleep(85);
3176
3177         snd_hda_codec_write(codec, hp_pin, 0,
3178                             AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3179
3180         if (hp_pin_sense)
3181                 msleep(100);
3182 }
3183
3184 static void alc_default_shutup(struct hda_codec *codec)
3185 {
3186         struct alc_spec *spec = codec->spec;
3187         hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3188         bool hp_pin_sense;
3189
3190         if (!hp_pin) {
3191                 alc269_shutup(codec);
3192                 return;
3193         }
3194
3195         hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
3196
3197         if (hp_pin_sense)
3198                 msleep(2);
3199
3200         snd_hda_codec_write(codec, hp_pin, 0,
3201                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
3202
3203         if (hp_pin_sense)
3204                 msleep(85);
3205
3206         snd_hda_codec_write(codec, hp_pin, 0,
3207                             AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0);
3208
3209         if (hp_pin_sense)
3210                 msleep(100);
3211
3212         alc_auto_setup_eapd(codec, false);
3213         snd_hda_shutup_pins(codec);
3214 }
3215
3216 static void alc5505_coef_set(struct hda_codec *codec, unsigned int index_reg,
3217                              unsigned int val)
3218 {
3219         snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_COEF_INDEX, index_reg >> 1);
3220         snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_PROC_COEF, val & 0xffff); /* LSB */
3221         snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_PROC_COEF, val >> 16); /* MSB */
3222 }
3223
3224 static int alc5505_coef_get(struct hda_codec *codec, unsigned int index_reg)
3225 {
3226         unsigned int val;
3227
3228         snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_COEF_INDEX, index_reg >> 1);
3229         val = snd_hda_codec_read(codec, 0x51, 0, AC_VERB_GET_PROC_COEF, 0)
3230                 & 0xffff;
3231         val |= snd_hda_codec_read(codec, 0x51, 0, AC_VERB_GET_PROC_COEF, 0)
3232                 << 16;
3233         return val;
3234 }
3235
3236 static void alc5505_dsp_halt(struct hda_codec *codec)
3237 {
3238         unsigned int val;
3239
3240         alc5505_coef_set(codec, 0x3000, 0x000c); /* DSP CPU stop */
3241         alc5505_coef_set(codec, 0x880c, 0x0008); /* DDR enter self refresh */
3242         alc5505_coef_set(codec, 0x61c0, 0x11110080); /* Clock control for PLL and CPU */
3243         alc5505_coef_set(codec, 0x6230, 0xfc0d4011); /* Disable Input OP */
3244         alc5505_coef_set(codec, 0x61b4, 0x040a2b03); /* Stop PLL2 */
3245         alc5505_coef_set(codec, 0x61b0, 0x00005b17); /* Stop PLL1 */
3246         alc5505_coef_set(codec, 0x61b8, 0x04133303); /* Stop PLL3 */
3247         val = alc5505_coef_get(codec, 0x6220);
3248         alc5505_coef_set(codec, 0x6220, (val | 0x3000)); /* switch Ringbuffer clock to DBUS clock */
3249 }
3250
3251 static void alc5505_dsp_back_from_halt(struct hda_codec *codec)
3252 {
3253         alc5505_coef_set(codec, 0x61b8, 0x04133302);
3254         alc5505_coef_set(codec, 0x61b0, 0x00005b16);
3255         alc5505_coef_set(codec, 0x61b4, 0x040a2b02);
3256         alc5505_coef_set(codec, 0x6230, 0xf80d4011);
3257         alc5505_coef_set(codec, 0x6220, 0x2002010f);
3258         alc5505_coef_set(codec, 0x880c, 0x00000004);
3259 }
3260
3261 static void alc5505_dsp_init(struct hda_codec *codec)
3262 {
3263         unsigned int val;
3264
3265         alc5505_dsp_halt(codec);
3266         alc5505_dsp_back_from_halt(codec);
3267         alc5505_coef_set(codec, 0x61b0, 0x5b14); /* PLL1 control */
3268         alc5505_coef_set(codec, 0x61b0, 0x5b16);
3269         alc5505_coef_set(codec, 0x61b4, 0x04132b00); /* PLL2 control */
3270         alc5505_coef_set(codec, 0x61b4, 0x04132b02);
3271         alc5505_coef_set(codec, 0x61b8, 0x041f3300); /* PLL3 control*/
3272         alc5505_coef_set(codec, 0x61b8, 0x041f3302);
3273         snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_CODEC_RESET, 0); /* Function reset */
3274         alc5505_coef_set(codec, 0x61b8, 0x041b3302);
3275         alc5505_coef_set(codec, 0x61b8, 0x04173302);
3276         alc5505_coef_set(codec, 0x61b8, 0x04163302);
3277         alc5505_coef_set(codec, 0x8800, 0x348b328b); /* DRAM control */
3278         alc5505_coef_set(codec, 0x8808, 0x00020022); /* DRAM control */
3279         alc5505_coef_set(codec, 0x8818, 0x00000400); /* DRAM control */
3280
3281         val = alc5505_coef_get(codec, 0x6200) >> 16; /* Read revision ID */
3282         if (val <= 3)
3283                 alc5505_coef_set(codec, 0x6220, 0x2002010f); /* I/O PAD Configuration */
3284         else
3285                 alc5505_coef_set(codec, 0x6220, 0x6002018f);
3286
3287         alc5505_coef_set(codec, 0x61ac, 0x055525f0); /**/
3288         alc5505_coef_set(codec, 0x61c0, 0x12230080); /* Clock control */
3289         alc5505_coef_set(codec, 0x61b4, 0x040e2b02); /* PLL2 control */
3290         alc5505_coef_set(codec, 0x61bc, 0x010234f8); /* OSC Control */
3291         alc5505_coef_set(codec, 0x880c, 0x00000004); /* DRAM Function control */
3292         alc5505_coef_set(codec, 0x880c, 0x00000003);
3293         alc5505_coef_set(codec, 0x880c, 0x00000010);
3294
3295 #ifdef HALT_REALTEK_ALC5505
3296         alc5505_dsp_halt(codec);
3297 #endif
3298 }
3299
3300 #ifdef HALT_REALTEK_ALC5505
3301 #define alc5505_dsp_suspend(codec)      /* NOP */
3302 #define alc5505_dsp_resume(codec)       /* NOP */
3303 #else
3304 #define alc5505_dsp_suspend(codec)      alc5505_dsp_halt(codec)
3305 #define alc5505_dsp_resume(codec)       alc5505_dsp_back_from_halt(codec)
3306 #endif
3307
3308 #ifdef CONFIG_PM
3309 static int alc269_suspend(struct hda_codec *codec)
3310 {
3311         struct alc_spec *spec = codec->spec;
3312
3313         if (spec->has_alc5505_dsp)
3314                 alc5505_dsp_suspend(codec);
3315         return alc_suspend(codec);
3316 }
3317
3318 static int alc269_resume(struct hda_codec *codec)
3319 {
3320         struct alc_spec *spec = codec->spec;
3321
3322         if (spec->codec_variant == ALC269_TYPE_ALC269VB)
3323                 alc269vb_toggle_power_output(codec, 0);
3324         if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
3325                         (alc_get_coef0(codec) & 0x00ff) == 0x018) {
3326                 msleep(150);
3327         }
3328
3329         codec->patch_ops.init(codec);
3330
3331         if (spec->codec_variant == ALC269_TYPE_ALC269VB)
3332                 alc269vb_toggle_power_output(codec, 1);
3333         if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
3334                         (alc_get_coef0(codec) & 0x00ff) == 0x017) {
3335                 msleep(200);
3336         }
3337
3338         regcache_sync(codec->core.regmap);
3339         hda_call_check_power_status(codec, 0x01);
3340
3341         /* on some machine, the BIOS will clear the codec gpio data when enter
3342          * suspend, and won't restore the data after resume, so we restore it
3343          * in the driver.
3344          */
3345         if (spec->gpio_led)
3346                 snd_hda_codec_write(codec, codec->core.afg, 0, AC_VERB_SET_GPIO_DATA,
3347                             spec->gpio_led);
3348
3349         if (spec->has_alc5505_dsp)
3350                 alc5505_dsp_resume(codec);
3351
3352         return 0;
3353 }
3354 #endif /* CONFIG_PM */
3355
3356 static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
3357                                                  const struct hda_fixup *fix, int action)
3358 {
3359         struct alc_spec *spec = codec->spec;
3360
3361         if (action == HDA_FIXUP_ACT_PRE_PROBE)
3362                 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
3363 }
3364
3365 static void alc269_fixup_pincfg_U7x7_headset_mic(struct hda_codec *codec,
3366                                                  const struct hda_fixup *fix,
3367                                                  int action)
3368 {
3369         unsigned int cfg_headphone = snd_hda_codec_get_pincfg(codec, 0x21);
3370         unsigned int cfg_headset_mic = snd_hda_codec_get_pincfg(codec, 0x19);
3371
3372         if (cfg_headphone && cfg_headset_mic == 0x411111f0)
3373                 snd_hda_codec_set_pincfg(codec, 0x19,
3374                         (cfg_headphone & ~AC_DEFCFG_DEVICE) |
3375                         (AC_JACK_MIC_IN << AC_DEFCFG_DEVICE_SHIFT));
3376 }
3377
3378 static void alc269_fixup_hweq(struct hda_codec *codec,
3379                                const struct hda_fixup *fix, int action)
3380 {
3381         if (action == HDA_FIXUP_ACT_INIT)
3382                 alc_update_coef_idx(codec, 0x1e, 0, 0x80);
3383 }
3384
3385 static void alc269_fixup_headset_mic(struct hda_codec *codec,
3386                                        const struct hda_fixup *fix, int action)
3387 {
3388         struct alc_spec *spec = codec->spec;
3389
3390         if (action == HDA_FIXUP_ACT_PRE_PROBE)
3391                 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
3392 }
3393
3394 static void alc271_fixup_dmic(struct hda_codec *codec,
3395                               const struct hda_fixup *fix, int action)
3396 {
3397         static const struct hda_verb verbs[] = {
3398                 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
3399                 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
3400                 {}
3401         };
3402         unsigned int cfg;
3403
3404         if (strcmp(codec->core.chip_name, "ALC271X") &&
3405             strcmp(codec->core.chip_name, "ALC269VB"))
3406                 return;
3407         cfg = snd_hda_codec_get_pincfg(codec, 0x12);
3408         if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
3409                 snd_hda_sequence_write(codec, verbs);
3410 }
3411
3412 static void alc269_fixup_pcm_44k(struct hda_codec *codec,
3413                                  const struct hda_fixup *fix, int action)
3414 {
3415         struct alc_spec *spec = codec->spec;
3416
3417         if (action != HDA_FIXUP_ACT_PROBE)
3418                 return;
3419
3420         /* Due to a hardware problem on Lenovo Ideadpad, we need to
3421          * fix the sample rate of analog I/O to 44.1kHz
3422          */
3423         spec->gen.stream_analog_playback = &alc269_44k_pcm_analog_playback;
3424         spec->gen.stream_analog_capture = &alc269_44k_pcm_analog_capture;
3425 }
3426
3427 static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
3428                                      const struct hda_fixup *fix, int action)
3429 {
3430         /* The digital-mic unit sends PDM (differential signal) instead of
3431          * the standard PCM, thus you can't record a valid mono stream as is.
3432          * Below is a workaround specific to ALC269 to control the dmic
3433          * signal source as mono.
3434          */
3435         if (action == HDA_FIXUP_ACT_INIT)
3436                 alc_update_coef_idx(codec, 0x07, 0, 0x80);
3437 }
3438
3439 static void alc269_quanta_automute(struct hda_codec *codec)
3440 {
3441         snd_hda_gen_update_outputs(codec);
3442
3443         alc_write_coef_idx(codec, 0x0c, 0x680);
3444         alc_write_coef_idx(codec, 0x0c, 0x480);
3445 }
3446
3447 static void alc269_fixup_quanta_mute(struct hda_codec *codec,
3448                                      const struct hda_fixup *fix, int action)
3449 {
3450         struct alc_spec *spec = codec->spec;
3451         if (action != HDA_FIXUP_ACT_PROBE)
3452                 return;
3453         spec->gen.automute_hook = alc269_quanta_automute;
3454 }
3455
3456 static void alc269_x101_hp_automute_hook(struct hda_codec *codec,
3457                                          struct hda_jack_callback *jack)
3458 {
3459         struct alc_spec *spec = codec->spec;
3460         int vref;
3461         msleep(200);
3462         snd_hda_gen_hp_automute(codec, jack);
3463
3464         vref = spec->gen.hp_jack_present ? PIN_VREF80 : 0;
3465         msleep(100);
3466         snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3467                             vref);
3468         msleep(500);
3469         snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3470                             vref);
3471 }
3472
3473 static void alc269_fixup_x101_headset_mic(struct hda_codec *codec,
3474                                      const struct hda_fixup *fix, int action)
3475 {
3476         struct alc_spec *spec = codec->spec;
3477         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3478                 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
3479                 spec->gen.hp_automute_hook = alc269_x101_hp_automute_hook;
3480         }
3481 }
3482
3483
3484 /* update mute-LED according to the speaker mute state via mic VREF pin */
3485 static void alc269_fixup_mic_mute_hook(void *private_data, int enabled)
3486 {
3487         struct hda_codec *codec = private_data;
3488         struct alc_spec *spec = codec->spec;
3489         unsigned int pinval;
3490
3491         if (spec->mute_led_polarity)
3492                 enabled = !enabled;
3493         pinval = snd_hda_codec_get_pin_target(codec, spec->mute_led_nid);
3494         pinval &= ~AC_PINCTL_VREFEN;
3495         pinval |= enabled ? AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80;
3496         if (spec->mute_led_nid) {
3497                 /* temporarily power up/down for setting VREF */
3498                 snd_hda_power_up_pm(codec);
3499                 snd_hda_set_pin_ctl_cache(codec, spec->mute_led_nid, pinval);
3500                 snd_hda_power_down_pm(codec);
3501         }
3502 }
3503
3504 /* Make sure the led works even in runtime suspend */
3505 static unsigned int led_power_filter(struct hda_codec *codec,
3506                                                   hda_nid_t nid,
3507                                                   unsigned int power_state)
3508 {
3509         struct alc_spec *spec = codec->spec;
3510
3511         if (power_state != AC_PWRST_D3 || nid == 0 ||
3512             (nid != spec->mute_led_nid && nid != spec->cap_mute_led_nid))
3513                 return power_state;
3514
3515         /* Set pin ctl again, it might have just been set to 0 */
3516         snd_hda_set_pin_ctl(codec, nid,
3517                             snd_hda_codec_get_pin_target(codec, nid));
3518
3519         return snd_hda_gen_path_power_filter(codec, nid, power_state);
3520 }
3521
3522 static void alc269_fixup_hp_mute_led(struct hda_codec *codec,
3523                                      const struct hda_fixup *fix, int action)
3524 {
3525         struct alc_spec *spec = codec->spec;
3526         const struct dmi_device *dev = NULL;
3527
3528         if (action != HDA_FIXUP_ACT_PRE_PROBE)
3529                 return;
3530
3531         while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
3532                 int pol, pin;
3533                 if (sscanf(dev->name, "HP_Mute_LED_%d_%x", &pol, &pin) != 2)
3534                         continue;
3535                 if (pin < 0x0a || pin >= 0x10)
3536                         break;
3537                 spec->mute_led_polarity = pol;
3538                 spec->mute_led_nid = pin - 0x0a + 0x18;
3539                 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
3540                 spec->gen.vmaster_mute_enum = 1;
3541                 codec->power_filter = led_power_filter;
3542                 codec_dbg(codec,
3543                           "Detected mute LED for %x:%d\n", spec->mute_led_nid,
3544                            spec->mute_led_polarity);
3545                 break;
3546         }
3547 }
3548
3549 static void alc269_fixup_hp_mute_led_mic1(struct hda_codec *codec,
3550                                 const struct hda_fixup *fix, int action)
3551 {
3552         struct alc_spec *spec = codec->spec;
3553         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3554                 spec->mute_led_polarity = 0;
3555                 spec->mute_led_nid = 0x18;
3556                 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
3557                 spec->gen.vmaster_mute_enum = 1;
3558                 codec->power_filter = led_power_filter;
3559         }
3560 }
3561
3562 static void alc269_fixup_hp_mute_led_mic2(struct hda_codec *codec,
3563                                 const struct hda_fixup *fix, int action)
3564 {
3565         struct alc_spec *spec = codec->spec;
3566         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3567                 spec->mute_led_polarity = 0;
3568                 spec->mute_led_nid = 0x19;
3569                 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
3570                 spec->gen.vmaster_mute_enum = 1;
3571                 codec->power_filter = led_power_filter;
3572         }
3573 }
3574
3575 /* update LED status via GPIO */
3576 static void alc_update_gpio_led(struct hda_codec *codec, unsigned int mask,
3577                                 bool enabled)
3578 {
3579         struct alc_spec *spec = codec->spec;
3580         unsigned int oldval = spec->gpio_led;
3581
3582         if (spec->mute_led_polarity)
3583                 enabled = !enabled;
3584
3585         if (enabled)
3586                 spec->gpio_led &= ~mask;
3587         else
3588                 spec->gpio_led |= mask;
3589         if (spec->gpio_led != oldval)
3590                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3591                                     spec->gpio_led);
3592 }
3593
3594 /* turn on/off mute LED via GPIO per vmaster hook */
3595 static void alc_fixup_gpio_mute_hook(void *private_data, int enabled)
3596 {
3597         struct hda_codec *codec = private_data;
3598         struct alc_spec *spec = codec->spec;
3599
3600         alc_update_gpio_led(codec, spec->gpio_mute_led_mask, enabled);
3601 }
3602
3603 /* turn on/off mic-mute LED via GPIO per capture hook */
3604 static void alc_fixup_gpio_mic_mute_hook(struct hda_codec *codec,
3605                                          struct snd_kcontrol *kcontrol,
3606                                          struct snd_ctl_elem_value *ucontrol)
3607 {
3608         struct alc_spec *spec = codec->spec;
3609
3610         if (ucontrol)
3611                 alc_update_gpio_led(codec, spec->gpio_mic_led_mask,
3612                                     ucontrol->value.integer.value[0] ||
3613                                     ucontrol->value.integer.value[1]);
3614 }
3615
3616 static void alc269_fixup_hp_gpio_led(struct hda_codec *codec,
3617                                 const struct hda_fixup *fix, int action)
3618 {
3619         struct alc_spec *spec = codec->spec;
3620         static const struct hda_verb gpio_init[] = {
3621                 { 0x01, AC_VERB_SET_GPIO_MASK, 0x18 },
3622                 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x18 },
3623                 {}
3624         };
3625
3626         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3627                 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
3628                 spec->gen.cap_sync_hook = alc_fixup_gpio_mic_mute_hook;
3629                 spec->gpio_led = 0;
3630                 spec->mute_led_polarity = 0;
3631                 spec->gpio_mute_led_mask = 0x08;
3632                 spec->gpio_mic_led_mask = 0x10;
3633                 snd_hda_add_verbs(codec, gpio_init);
3634         }
3635 }
3636
3637 static void alc286_fixup_hp_gpio_led(struct hda_codec *codec,
3638                                 const struct hda_fixup *fix, int action)
3639 {
3640         struct alc_spec *spec = codec->spec;
3641         static const struct hda_verb gpio_init[] = {
3642                 { 0x01, AC_VERB_SET_GPIO_MASK, 0x22 },
3643                 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x22 },
3644                 {}
3645         };
3646
3647         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3648                 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
3649                 spec->gen.cap_sync_hook = alc_fixup_gpio_mic_mute_hook;
3650                 spec->gpio_led = 0;
3651                 spec->mute_led_polarity = 0;
3652                 spec->gpio_mute_led_mask = 0x02;
3653                 spec->gpio_mic_led_mask = 0x20;
3654                 snd_hda_add_verbs(codec, gpio_init);
3655         }
3656 }
3657
3658 /* turn on/off mic-mute LED per capture hook */
3659 static void alc269_fixup_hp_cap_mic_mute_hook(struct hda_codec *codec,
3660                                                struct snd_kcontrol *kcontrol,
3661                                                struct snd_ctl_elem_value *ucontrol)
3662 {
3663         struct alc_spec *spec = codec->spec;
3664         unsigned int pinval, enable, disable;
3665
3666         pinval = snd_hda_codec_get_pin_target(codec, spec->cap_mute_led_nid);
3667         pinval &= ~AC_PINCTL_VREFEN;
3668         enable  = pinval | AC_PINCTL_VREF_80;
3669         disable = pinval | AC_PINCTL_VREF_HIZ;
3670
3671         if (!ucontrol)
3672                 return;
3673
3674         if (ucontrol->value.integer.value[0] ||
3675             ucontrol->value.integer.value[1])
3676                 pinval = disable;
3677         else
3678                 pinval = enable;
3679
3680         if (spec->cap_mute_led_nid)
3681                 snd_hda_set_pin_ctl_cache(codec, spec->cap_mute_led_nid, pinval);
3682 }
3683
3684 static void alc269_fixup_hp_gpio_mic1_led(struct hda_codec *codec,
3685                                 const struct hda_fixup *fix, int action)
3686 {
3687         struct alc_spec *spec = codec->spec;
3688         static const struct hda_verb gpio_init[] = {
3689                 { 0x01, AC_VERB_SET_GPIO_MASK, 0x08 },
3690                 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x08 },
3691                 {}
3692         };
3693
3694         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3695                 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
3696                 spec->gen.cap_sync_hook = alc269_fixup_hp_cap_mic_mute_hook;
3697                 spec->gpio_led = 0;
3698                 spec->mute_led_polarity = 0;
3699                 spec->gpio_mute_led_mask = 0x08;
3700                 spec->cap_mute_led_nid = 0x18;
3701                 snd_hda_add_verbs(codec, gpio_init);
3702                 codec->power_filter = led_power_filter;
3703         }
3704 }
3705
3706 static void alc280_fixup_hp_gpio4(struct hda_codec *codec,
3707                                    const struct hda_fixup *fix, int action)
3708 {
3709         /* Like hp_gpio_mic1_led, but also needs GPIO4 low to enable headphone amp */
3710         struct alc_spec *spec = codec->spec;
3711         static const struct hda_verb gpio_init[] = {
3712                 { 0x01, AC_VERB_SET_GPIO_MASK, 0x18 },
3713                 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x18 },
3714                 {}
3715         };
3716
3717         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3718                 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
3719                 spec->gen.cap_sync_hook = alc269_fixup_hp_cap_mic_mute_hook;
3720                 spec->gpio_led = 0;
3721                 spec->mute_led_polarity = 0;
3722                 spec->gpio_mute_led_mask = 0x08;
3723                 spec->cap_mute_led_nid = 0x18;
3724                 snd_hda_add_verbs(codec, gpio_init);
3725                 codec->power_filter = led_power_filter;
3726         }
3727 }
3728
3729 #if IS_REACHABLE(CONFIG_INPUT)
3730 static void gpio2_mic_hotkey_event(struct hda_codec *codec,
3731                                    struct hda_jack_callback *event)
3732 {
3733         struct alc_spec *spec = codec->spec;
3734
3735         /* GPIO2 just toggles on a keypress/keyrelease cycle. Therefore
3736            send both key on and key off event for every interrupt. */
3737         input_report_key(spec->kb_dev, spec->alc_mute_keycode_map[ALC_KEY_MICMUTE_INDEX], 1);
3738         input_sync(spec->kb_dev);
3739         input_report_key(spec->kb_dev, spec->alc_mute_keycode_map[ALC_KEY_MICMUTE_INDEX], 0);
3740         input_sync(spec->kb_dev);
3741 }
3742
3743 static int alc_register_micmute_input_device(struct hda_codec *codec)
3744 {
3745         struct alc_spec *spec = codec->spec;
3746         int i;
3747
3748         spec->kb_dev = input_allocate_device();
3749         if (!spec->kb_dev) {
3750                 codec_err(codec, "Out of memory (input_allocate_device)\n");
3751                 return -ENOMEM;
3752         }
3753
3754         spec->alc_mute_keycode_map[ALC_KEY_MICMUTE_INDEX] = KEY_MICMUTE;
3755
3756         spec->kb_dev->name = "Microphone Mute Button";
3757         spec->kb_dev->evbit[0] = BIT_MASK(EV_KEY);
3758         spec->kb_dev->keycodesize = sizeof(spec->alc_mute_keycode_map[0]);
3759         spec->kb_dev->keycodemax = ARRAY_SIZE(spec->alc_mute_keycode_map);
3760         spec->kb_dev->keycode = spec->alc_mute_keycode_map;
3761         for (i = 0; i < ARRAY_SIZE(spec->alc_mute_keycode_map); i++)
3762                 set_bit(spec->alc_mute_keycode_map[i], spec->kb_dev->keybit);
3763
3764         if (input_register_device(spec->kb_dev)) {
3765                 codec_err(codec, "input_register_device failed\n");
3766                 input_free_device(spec->kb_dev);
3767                 spec->kb_dev = NULL;
3768                 return -ENOMEM;
3769         }
3770
3771         return 0;
3772 }
3773
3774 static void alc280_fixup_hp_gpio2_mic_hotkey(struct hda_codec *codec,
3775                                              const struct hda_fixup *fix, int action)
3776 {
3777         /* GPIO1 = set according to SKU external amp
3778            GPIO2 = mic mute hotkey
3779            GPIO3 = mute LED
3780            GPIO4 = mic mute LED */
3781         static const struct hda_verb gpio_init[] = {
3782                 { 0x01, AC_VERB_SET_GPIO_MASK, 0x1e },
3783                 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x1a },
3784                 { 0x01, AC_VERB_SET_GPIO_DATA, 0x02 },
3785                 {}
3786         };
3787
3788         struct alc_spec *spec = codec->spec;
3789
3790         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3791                 if (alc_register_micmute_input_device(codec) != 0)
3792                         return;
3793
3794                 snd_hda_add_verbs(codec, gpio_init);
3795                 snd_hda_codec_write_cache(codec, codec->core.afg, 0,
3796                                           AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x04);
3797                 snd_hda_jack_detect_enable_callback(codec, codec->core.afg,
3798                                                     gpio2_mic_hotkey_event);
3799
3800                 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
3801                 spec->gen.cap_sync_hook = alc_fixup_gpio_mic_mute_hook;
3802                 spec->gpio_led = 0;
3803                 spec->mute_led_polarity = 0;
3804                 spec->gpio_mute_led_mask = 0x08;
3805                 spec->gpio_mic_led_mask = 0x10;
3806                 return;
3807         }
3808
3809         if (!spec->kb_dev)
3810                 return;
3811
3812         switch (action) {
3813         case HDA_FIXUP_ACT_PROBE:
3814                 spec->init_amp = ALC_INIT_DEFAULT;
3815                 break;
3816         case HDA_FIXUP_ACT_FREE:
3817                 input_unregister_device(spec->kb_dev);
3818                 spec->kb_dev = NULL;
3819         }
3820 }
3821
3822 static void alc233_fixup_lenovo_line2_mic_hotkey(struct hda_codec *codec,
3823                                              const struct hda_fixup *fix, int action)
3824 {
3825         /* Line2 = mic mute hotkey
3826            GPIO2 = mic mute LED */
3827         static const struct hda_verb gpio_init[] = {
3828                 { 0x01, AC_VERB_SET_GPIO_MASK, 0x04 },
3829                 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04 },
3830                 {}
3831         };
3832
3833         struct alc_spec *spec = codec->spec;
3834
3835         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3836                 if (alc_register_micmute_input_device(codec) != 0)
3837                         return;
3838
3839                 snd_hda_add_verbs(codec, gpio_init);
3840                 snd_hda_jack_detect_enable_callback(codec, 0x1b,
3841                                                     gpio2_mic_hotkey_event);
3842
3843                 spec->gen.cap_sync_hook = alc_fixup_gpio_mic_mute_hook;
3844                 spec->gpio_led = 0;
3845                 spec->mute_led_polarity = 0;
3846                 spec->gpio_mic_led_mask = 0x04;
3847                 return;
3848         }
3849
3850         if (!spec->kb_dev)
3851                 return;
3852
3853         switch (action) {
3854         case HDA_FIXUP_ACT_PROBE:
3855                 spec->init_amp = ALC_INIT_DEFAULT;
3856                 break;
3857         case HDA_FIXUP_ACT_FREE:
3858                 input_unregister_device(spec->kb_dev);
3859                 spec->kb_dev = NULL;
3860         }
3861 }
3862 #else /* INPUT */
3863 #define alc280_fixup_hp_gpio2_mic_hotkey        NULL
3864 #define alc233_fixup_lenovo_line2_mic_hotkey    NULL
3865 #endif /* INPUT */
3866
3867 static void alc269_fixup_hp_line1_mic1_led(struct hda_codec *codec,
3868                                 const struct hda_fixup *fix, int action)
3869 {
3870         struct alc_spec *spec = codec->spec;
3871
3872         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3873                 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
3874                 spec->gen.cap_sync_hook = alc269_fixup_hp_cap_mic_mute_hook;
3875                 spec->mute_led_polarity = 0;
3876                 spec->mute_led_nid = 0x1a;
3877                 spec->cap_mute_led_nid = 0x18;
3878                 spec->gen.vmaster_mute_enum = 1;
3879                 codec->power_filter = led_power_filter;
3880         }
3881 }
3882
3883 static struct coef_fw alc225_pre_hsmode[] = {
3884         UPDATE_COEF(0x4a, 1<<8, 0),
3885         UPDATE_COEFEX(0x57, 0x05, 1<<14, 0),
3886         UPDATE_COEF(0x63, 3<<14, 3<<14),
3887         UPDATE_COEF(0x4a, 3<<4, 2<<4),
3888         UPDATE_COEF(0x4a, 3<<10, 3<<10),
3889         UPDATE_COEF(0x45, 0x3f<<10, 0x34<<10),
3890         UPDATE_COEF(0x4a, 3<<10, 0),
3891         {}
3892 };
3893
3894 static void alc_headset_mode_unplugged(struct hda_codec *codec)
3895 {
3896         static struct coef_fw coef0255[] = {
3897                 WRITE_COEF(0x45, 0xd089), /* UAJ function set to menual mode */
3898                 UPDATE_COEFEX(0x57, 0x05, 1<<14, 0), /* Direct Drive HP Amp control(Set to verb control)*/
3899                 WRITE_COEF(0x06, 0x6104), /* Set MIC2 Vref gate with HP */
3900                 WRITE_COEFEX(0x57, 0x03, 0x8aa6), /* Direct Drive HP Amp control */
3901                 {}
3902         };
3903         static struct coef_fw coef0255_1[] = {
3904                 WRITE_COEF(0x1b, 0x0c0b), /* LDO and MISC control */
3905                 {}
3906         };
3907         static struct coef_fw coef0256[] = {
3908                 WRITE_COEF(0x1b, 0x0c4b), /* LDO and MISC control */
3909                 {}
3910         };
3911         static struct coef_fw coef0233[] = {
3912                 WRITE_COEF(0x1b, 0x0c0b),
3913                 WRITE_COEF(0x45, 0xc429),
3914                 UPDATE_COEF(0x35, 0x4000, 0),
3915                 WRITE_COEF(0x06, 0x2104),
3916                 WRITE_COEF(0x1a, 0x0001),
3917                 WRITE_COEF(0x26, 0x0004),
3918                 WRITE_COEF(0x32, 0x42a3),
3919                 {}
3920         };
3921         static struct coef_fw coef0288[] = {
3922                 UPDATE_COEF(0x4f, 0xfcc0, 0xc400),
3923                 UPDATE_COEF(0x50, 0x2000, 0x2000),
3924                 UPDATE_COEF(0x56, 0x0006, 0x0006),
3925                 UPDATE_COEF(0x66, 0x0008, 0),
3926                 UPDATE_COEF(0x67, 0x2000, 0),
3927                 {}
3928         };
3929         static struct coef_fw coef0298[] = {
3930                 UPDATE_COEF(0x19, 0x1300, 0x0300),
3931                 {}
3932         };
3933         static struct coef_fw coef0292[] = {
3934                 WRITE_COEF(0x76, 0x000e),
3935                 WRITE_COEF(0x6c, 0x2400),
3936                 WRITE_COEF(0x18, 0x7308),
3937                 WRITE_COEF(0x6b, 0xc429),
3938                 {}
3939         };
3940         static struct coef_fw coef0293[] = {
3941                 UPDATE_COEF(0x10, 7<<8, 6<<8), /* SET Line1 JD to 0 */
3942                 UPDATE_COEFEX(0x57, 0x05, 1<<15|1<<13, 0x0), /* SET charge pump by verb */
3943                 UPDATE_COEFEX(0x57, 0x03, 1<<10, 1<<10), /* SET EN_OSW to 1 */
3944                 UPDATE_COEF(0x1a, 1<<3, 1<<3), /* Combo JD gating with LINE1-VREFO */
3945                 WRITE_COEF(0x45, 0xc429), /* Set to TRS type */
3946                 UPDATE_COEF(0x4a, 0x000f, 0x000e), /* Combo Jack auto detect */
3947                 {}
3948         };
3949         static struct coef_fw coef0668[] = {
3950                 WRITE_COEF(0x15, 0x0d40),
3951                 WRITE_COEF(0xb7, 0x802b),
3952                 {}
3953         };
3954         static struct coef_fw coef0225[] = {
3955                 UPDATE_COEF(0x63, 3<<14, 0),
3956                 {}
3957         };
3958         static struct coef_fw coef0274[] = {
3959                 UPDATE_COEF(0x4a, 0x0100, 0),
3960                 UPDATE_COEFEX(0x57, 0x05, 0x4000, 0),
3961                 UPDATE_COEF(0x6b, 0xf000, 0x5000),
3962                 UPDATE_COEF(0x4a, 0x0010, 0),
3963                 UPDATE_COEF(0x4a, 0x0c00, 0x0c00),
3964                 WRITE_COEF(0x45, 0x5289),
3965                 UPDATE_COEF(0x4a, 0x0c00, 0),
3966                 {}
3967         };
3968
3969         switch (codec->core.vendor_id) {
3970         case 0x10ec0255:
3971                 alc_process_coef_fw(codec, coef0255_1);
3972                 alc_process_coef_fw(codec, coef0255);
3973                 break;
3974         case 0x10ec0236:
3975         case 0x10ec0256:
3976                 alc_process_coef_fw(codec, coef0256);
3977                 alc_process_coef_fw(codec, coef0255);
3978                 break;
3979         case 0x10ec0234:
3980         case 0x10ec0274:
3981         case 0x10ec0294:
3982                 alc_process_coef_fw(codec, coef0274);
3983                 break;
3984         case 0x10ec0233:
3985         case 0x10ec0283:
3986                 alc_process_coef_fw(codec, coef0233);
3987                 break;
3988         case 0x10ec0286:
3989         case 0x10ec0288:
3990                 alc_process_coef_fw(codec, coef0288);
3991                 break;
3992         case 0x10ec0298:
3993                 alc_process_coef_fw(codec, coef0298);
3994                 alc_process_coef_fw(codec, coef0288);
3995                 break;
3996         case 0x10ec0292:
3997                 alc_process_coef_fw(codec, coef0292);
3998                 break;
3999         case 0x10ec0293:
4000                 alc_process_coef_fw(codec, coef0293);
4001                 break;
4002         case 0x10ec0668:
4003                 alc_process_coef_fw(codec, coef0668);
4004                 break;
4005         case 0x10ec0225:
4006         case 0x10ec0295:
4007         case 0x10ec0299:
4008                 alc_process_coef_fw(codec, alc225_pre_hsmode);
4009                 alc_process_coef_fw(codec, coef0225);
4010                 break;
4011         case 0x10ec0867:
4012                 alc_update_coefex_idx(codec, 0x57, 0x5, 1<<14, 0);
4013                 break;
4014         }
4015         codec_dbg(codec, "Headset jack set to unplugged mode.\n");
4016 }
4017
4018
4019 static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
4020                                     hda_nid_t mic_pin)
4021 {
4022         static struct coef_fw coef0255[] = {
4023                 WRITE_COEFEX(0x57, 0x03, 0x8aa6),
4024                 WRITE_COEF(0x06, 0x6100), /* Set MIC2 Vref gate to normal */
4025                 {}
4026         };
4027         static struct coef_fw coef0233[] = {
4028                 UPDATE_COEF(0x35, 0, 1<<14),
4029                 WRITE_COEF(0x06, 0x2100),
4030                 WRITE_COEF(0x1a, 0x0021),
4031                 WRITE_COEF(0x26, 0x008c),
4032                 {}
4033         };
4034         static struct coef_fw coef0288[] = {
4035                 UPDATE_COEF(0x4f, 0x00c0, 0),
4036                 UPDATE_COEF(0x50, 0x2000, 0),
4037                 UPDATE_COEF(0x56, 0x0006, 0),
4038                 UPDATE_COEF(0x4f, 0xfcc0, 0xc400),
4039                 UPDATE_COEF(0x66, 0x0008, 0x0008),
4040                 UPDATE_COEF(0x67, 0x2000, 0x2000),
4041                 {}
4042         };
4043         static struct coef_fw coef0292[] = {
4044                 WRITE_COEF(0x19, 0xa208),
4045                 WRITE_COEF(0x2e, 0xacf0),
4046                 {}
4047         };
4048         static struct coef_fw coef0293[] = {
4049                 UPDATE_COEFEX(0x57, 0x05, 0, 1<<15|1<<13), /* SET charge pump by verb */
4050                 UPDATE_COEFEX(0x57, 0x03, 1<<10, 0), /* SET EN_OSW to 0 */
4051                 UPDATE_COEF(0x1a, 1<<3, 0), /* Combo JD gating without LINE1-VREFO */
4052                 {}
4053         };
4054         static struct coef_fw coef0688[] = {
4055                 WRITE_COEF(0xb7, 0x802b),
4056                 WRITE_COEF(0xb5, 0x1040),
4057                 UPDATE_COEF(0xc3, 0, 1<<12),
4058                 {}
4059         };
4060         static struct coef_fw coef0225[] = {
4061                 UPDATE_COEFEX(0x57, 0x05, 1<<14, 1<<14),
4062                 UPDATE_COEF(0x4a, 3<<4, 2<<4),
4063                 UPDATE_COEF(0x63, 3<<14, 0),
4064                 {}
4065         };
4066         static struct coef_fw coef0274[] = {
4067                 UPDATE_COEFEX(0x57, 0x05, 0x4000, 0x4000),
4068                 UPDATE_COEF(0x4a, 0x0010, 0),
4069                 UPDATE_COEF(0x6b, 0xf000, 0),
4070                 {}
4071         };
4072
4073         switch (codec->core.vendor_id) {
4074         case 0x10ec0236:
4075         case 0x10ec0255:
4076         case 0x10ec0256:
4077                 alc_write_coef_idx(codec, 0x45, 0xc489);
4078                 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
4079                 alc_process_coef_fw(codec, coef0255);
4080                 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
4081                 break;
4082         case 0x10ec0234:
4083         case 0x10ec0274:
4084         case 0x10ec0294:
4085                 alc_write_coef_idx(codec, 0x45, 0x4689);
4086                 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
4087                 alc_process_coef_fw(codec, coef0274);
4088                 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
4089                 break;
4090         case 0x10ec0233:
4091         case 0x10ec0283:
4092                 alc_write_coef_idx(codec, 0x45, 0xc429);
4093                 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
4094                 alc_process_coef_fw(codec, coef0233);
4095                 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
4096                 break;
4097         case 0x10ec0286:
4098         case 0x10ec0288:
4099         case 0x10ec0298:
4100                 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
4101                 alc_process_coef_fw(codec, coef0288);
4102                 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
4103                 break;
4104         case 0x10ec0292:
4105                 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
4106                 alc_process_coef_fw(codec, coef0292);
4107                 break;
4108         case 0x10ec0293:
4109                 /* Set to TRS mode */
4110                 alc_write_coef_idx(codec, 0x45, 0xc429);
4111                 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
4112                 alc_process_coef_fw(codec, coef0293);
4113                 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
4114                 break;
4115         case 0x10ec0867:
4116                 alc_update_coefex_idx(codec, 0x57, 0x5, 0, 1<<14);
4117                 /* fallthru */
4118         case 0x10ec0221:
4119         case 0x10ec0662:
4120                 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
4121                 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
4122                 break;
4123         case 0x10ec0668:
4124                 alc_write_coef_idx(codec, 0x11, 0x0001);
4125                 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
4126                 alc_process_coef_fw(codec, coef0688);
4127                 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
4128                 break;
4129         case 0x10ec0225:
4130         case 0x10ec0295:
4131         case 0x10ec0299:
4132                 alc_process_coef_fw(codec, alc225_pre_hsmode);
4133                 alc_update_coef_idx(codec, 0x45, 0x3f<<10, 0x31<<10);
4134                 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
4135                 alc_process_coef_fw(codec, coef0225);
4136                 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
4137                 break;
4138         }
4139         codec_dbg(codec, "Headset jack set to mic-in mode.\n");
4140 }
4141
4142 static void alc_headset_mode_default(struct hda_codec *codec)
4143 {
4144         static struct coef_fw coef0225[] = {
4145                 UPDATE_COEF(0x45, 0x3f<<10, 0x30<<10),
4146                 UPDATE_COEF(0x45, 0x3f<<10, 0x31<<10),
4147                 UPDATE_COEF(0x49, 3<<8, 0<<8),
4148                 UPDATE_COEF(0x4a, 3<<4, 3<<4),
4149                 UPDATE_COEF(0x63, 3<<14, 0),
4150                 UPDATE_COEF(0x67, 0xf000, 0x3000),
4151                 {}
4152         };
4153         static struct coef_fw coef0255[] = {
4154                 WRITE_COEF(0x45, 0xc089),
4155                 WRITE_COEF(0x45, 0xc489),
4156                 WRITE_COEFEX(0x57, 0x03, 0x8ea6),
4157                 WRITE_COEF(0x49, 0x0049),
4158                 {}
4159         };
4160         static struct coef_fw coef0233[] = {
4161                 WRITE_COEF(0x06, 0x2100),
4162                 WRITE_COEF(0x32, 0x4ea3),
4163                 {}
4164         };
4165         static struct coef_fw coef0288[] = {
4166                 UPDATE_COEF(0x4f, 0xfcc0, 0xc400), /* Set to TRS type */
4167                 UPDATE_COEF(0x50, 0x2000, 0x2000),
4168                 UPDATE_COEF(0x56, 0x0006, 0x0006),
4169                 UPDATE_COEF(0x66, 0x0008, 0),
4170                 UPDATE_COEF(0x67, 0x2000, 0),
4171                 {}
4172         };
4173         static struct coef_fw coef0292[] = {
4174                 WRITE_COEF(0x76, 0x000e),
4175                 WRITE_COEF(0x6c, 0x2400),
4176                 WRITE_COEF(0x6b, 0xc429),
4177                 WRITE_COEF(0x18, 0x7308),
4178                 {}
4179         };
4180         static struct coef_fw coef0293[] = {
4181                 UPDATE_COEF(0x4a, 0x000f, 0x000e), /* Combo Jack auto detect */
4182                 WRITE_COEF(0x45, 0xC429), /* Set to TRS type */
4183                 UPDATE_COEF(0x1a, 1<<3, 0), /* Combo JD gating without LINE1-VREFO */
4184                 {}
4185         };
4186         static struct coef_fw coef0688[] = {
4187                 WRITE_COEF(0x11, 0x0041),
4188                 WRITE_COEF(0x15, 0x0d40),
4189                 WRITE_COEF(0xb7, 0x802b),
4190                 {}
4191         };
4192         static struct coef_fw coef0274[] = {
4193                 WRITE_COEF(0x45, 0x4289),
4194                 UPDATE_COEF(0x4a, 0x0010, 0x0010),
4195                 UPDATE_COEF(0x6b, 0x0f00, 0),
4196                 UPDATE_COEF(0x49, 0x0300, 0x0300),
4197                 {}
4198         };
4199
4200         switch (codec->core.vendor_id) {
4201         case 0x10ec0225:
4202         case 0x10ec0295:
4203         case 0x10ec0299:
4204                 alc_process_coef_fw(codec, alc225_pre_hsmode);
4205                 alc_process_coef_fw(codec, coef0225);
4206                 break;
4207         case 0x10ec0236:
4208         case 0x10ec0255:
4209         case 0x10ec0256:
4210                 alc_process_coef_fw(codec, coef0255);
4211                 break;
4212         case 0x10ec0234:
4213         case 0x10ec0274:
4214         case 0x10ec0294:
4215                 alc_process_coef_fw(codec, coef0274);
4216                 break;
4217         case 0x10ec0233:
4218         case 0x10ec0283:
4219                 alc_process_coef_fw(codec, coef0233);
4220                 break;
4221         case 0x10ec0286:
4222         case 0x10ec0288:
4223         case 0x10ec0298:
4224                 alc_process_coef_fw(codec, coef0288);
4225                 break;
4226         case 0x10ec0292:
4227                 alc_process_coef_fw(codec, coef0292);
4228                 break;
4229         case 0x10ec0293:
4230                 alc_process_coef_fw(codec, coef0293);
4231                 break;
4232         case 0x10ec0668:
4233                 alc_process_coef_fw(codec, coef0688);
4234                 break;
4235         case 0x10ec0867:
4236                 alc_update_coefex_idx(codec, 0x57, 0x5, 1<<14, 0);
4237                 break;
4238         }
4239         codec_dbg(codec, "Headset jack set to headphone (default) mode.\n");
4240 }
4241
4242 /* Iphone type */
4243 static void alc_headset_mode_ctia(struct hda_codec *codec)
4244 {
4245         int val;
4246
4247         static struct coef_fw coef0255[] = {
4248                 WRITE_COEF(0x45, 0xd489), /* Set to CTIA type */
4249                 WRITE_COEF(0x1b, 0x0c2b),
4250                 WRITE_COEFEX(0x57, 0x03, 0x8ea6),
4251                 {}
4252         };
4253         static struct coef_fw coef0256[] = {
4254                 WRITE_COEF(0x45, 0xd489), /* Set to CTIA type */
4255                 WRITE_COEF(0x1b, 0x0c6b),
4256                 WRITE_COEFEX(0x57, 0x03, 0x8ea6),
4257                 {}
4258         };
4259         static struct coef_fw coef0233[] = {
4260                 WRITE_COEF(0x45, 0xd429),
4261                 WRITE_COEF(0x1b, 0x0c2b),
4262                 WRITE_COEF(0x32, 0x4ea3),
4263                 {}
4264         };
4265         static struct coef_fw coef0288[] = {
4266                 UPDATE_COEF(0x50, 0x2000, 0x2000),
4267                 UPDATE_COEF(0x56, 0x0006, 0x0006),
4268                 UPDATE_COEF(0x66, 0x0008, 0),
4269                 UPDATE_COEF(0x67, 0x2000, 0),
4270                 {}
4271         };
4272         static struct coef_fw coef0292[] = {
4273                 WRITE_COEF(0x6b, 0xd429),
4274                 WRITE_COEF(0x76, 0x0008),
4275                 WRITE_COEF(0x18, 0x7388),
4276                 {}
4277         };
4278         static struct coef_fw coef0293[] = {
4279                 WRITE_COEF(0x45, 0xd429), /* Set to ctia type */
4280                 UPDATE_COEF(0x10, 7<<8, 7<<8), /* SET Line1 JD to 1 */
4281                 {}
4282         };
4283         static struct coef_fw coef0688[] = {
4284                 WRITE_COEF(0x11, 0x0001),
4285                 WRITE_COEF(0x15, 0x0d60),
4286                 WRITE_COEF(0xc3, 0x0000),
4287                 {}
4288         };
4289         static struct coef_fw coef0225_1[] = {
4290                 UPDATE_COEF(0x45, 0x3f<<10, 0x35<<10),
4291                 UPDATE_COEF(0x63, 3<<14, 2<<14),
4292                 {}
4293         };
4294         static struct coef_fw coef0225_2[] = {
4295                 UPDATE_COEF(0x45, 0x3f<<10, 0x35<<10),
4296                 UPDATE_COEF(0x63, 3<<14, 1<<14),
4297                 {}
4298         };
4299
4300         switch (codec->core.vendor_id) {
4301         case 0x10ec0255:
4302                 alc_process_coef_fw(codec, coef0255);
4303                 break;
4304         case 0x10ec0236:
4305         case 0x10ec0256:
4306                 alc_process_coef_fw(codec, coef0256);
4307                 break;
4308         case 0x10ec0234:
4309         case 0x10ec0274:
4310         case 0x10ec0294:
4311                 alc_write_coef_idx(codec, 0x45, 0xd689);
4312                 break;
4313         case 0x10ec0233:
4314         case 0x10ec0283:
4315                 alc_process_coef_fw(codec, coef0233);
4316                 break;
4317         case 0x10ec0298:
4318                 val = alc_read_coef_idx(codec, 0x50);
4319                 if (val & (1 << 12)) {
4320                         alc_update_coef_idx(codec, 0x8e, 0x0070, 0x0020);
4321                         alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xd400);
4322                         msleep(300);
4323                 } else {
4324                         alc_update_coef_idx(codec, 0x8e, 0x0070, 0x0010);
4325                         alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xd400);
4326                         msleep(300);
4327                 }
4328                 break;
4329         case 0x10ec0286:
4330         case 0x10ec0288:
4331                 alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xd400);
4332                 msleep(300);
4333                 alc_process_coef_fw(codec, coef0288);
4334                 break;
4335         case 0x10ec0292:
4336                 alc_process_coef_fw(codec, coef0292);
4337                 break;
4338         case 0x10ec0293:
4339                 alc_process_coef_fw(codec, coef0293);
4340                 break;
4341         case 0x10ec0668:
4342                 alc_process_coef_fw(codec, coef0688);
4343                 break;
4344         case 0x10ec0225:
4345         case 0x10ec0295:
4346         case 0x10ec0299:
4347                 val = alc_read_coef_idx(codec, 0x45);
4348                 if (val & (1 << 9))
4349                         alc_process_coef_fw(codec, coef0225_2);
4350                 else
4351                         alc_process_coef_fw(codec, coef0225_1);
4352                 break;
4353         case 0x10ec0867:
4354                 alc_update_coefex_idx(codec, 0x57, 0x5, 1<<14, 0);
4355                 break;
4356         }
4357         codec_dbg(codec, "Headset jack set to iPhone-style headset mode.\n");
4358 }
4359
4360 /* Nokia type */
4361 static void alc_headset_mode_omtp(struct hda_codec *codec)
4362 {
4363         static struct coef_fw coef0255[] = {
4364                 WRITE_COEF(0x45, 0xe489), /* Set to OMTP Type */
4365                 WRITE_COEF(0x1b, 0x0c2b),
4366                 WRITE_COEFEX(0x57, 0x03, 0x8ea6),
4367                 {}
4368         };
4369         static struct coef_fw coef0256[] = {
4370                 WRITE_COEF(0x45, 0xe489), /* Set to OMTP Type */
4371                 WRITE_COEF(0x1b, 0x0c6b),
4372                 WRITE_COEFEX(0x57, 0x03, 0x8ea6),
4373                 {}
4374         };
4375         static struct coef_fw coef0233[] = {
4376                 WRITE_COEF(0x45, 0xe429),
4377                 WRITE_COEF(0x1b, 0x0c2b),
4378                 WRITE_COEF(0x32, 0x4ea3),
4379                 {}
4380         };
4381         static struct coef_fw coef0288[] = {
4382                 UPDATE_COEF(0x50, 0x2000, 0x2000),
4383                 UPDATE_COEF(0x56, 0x0006, 0x0006),
4384                 UPDATE_COEF(0x66, 0x0008, 0),
4385                 UPDATE_COEF(0x67, 0x2000, 0),
4386                 {}
4387         };
4388         static struct coef_fw coef0292[] = {
4389                 WRITE_COEF(0x6b, 0xe429),
4390                 WRITE_COEF(0x76, 0x0008),
4391                 WRITE_COEF(0x18, 0x7388),
4392                 {}
4393         };
4394         static struct coef_fw coef0293[] = {
4395                 WRITE_COEF(0x45, 0xe429), /* Set to omtp type */
4396                 UPDATE_COEF(0x10, 7<<8, 7<<8), /* SET Line1 JD to 1 */
4397                 {}
4398         };
4399         static struct coef_fw coef0688[] = {
4400                 WRITE_COEF(0x11, 0x0001),
4401                 WRITE_COEF(0x15, 0x0d50),
4402                 WRITE_COEF(0xc3, 0x0000),
4403                 {}
4404         };
4405         static struct coef_fw coef0225[] = {
4406                 UPDATE_COEF(0x45, 0x3f<<10, 0x39<<10),
4407                 UPDATE_COEF(0x63, 3<<14, 2<<14),
4408                 {}
4409         };
4410
4411         switch (codec->core.vendor_id) {
4412         case 0x10ec0255:
4413                 alc_process_coef_fw(codec, coef0255);
4414                 break;
4415         case 0x10ec0236:
4416         case 0x10ec0256:
4417                 alc_process_coef_fw(codec, coef0256);
4418                 break;
4419         case 0x10ec0234:
4420         case 0x10ec0274:
4421         case 0x10ec0294:
4422                 alc_write_coef_idx(codec, 0x45, 0xe689);
4423                 break;
4424         case 0x10ec0233:
4425         case 0x10ec0283:
4426                 alc_process_coef_fw(codec, coef0233);
4427                 break;
4428         case 0x10ec0298:
4429                 alc_update_coef_idx(codec, 0x8e, 0x0070, 0x0010);/* Headset output enable */
4430                 alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xe400);
4431                 msleep(300);
4432                 break;
4433         case 0x10ec0286:
4434         case 0x10ec0288:
4435                 alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xe400);
4436                 msleep(300);
4437                 alc_process_coef_fw(codec, coef0288);
4438                 break;
4439         case 0x10ec0292:
4440                 alc_process_coef_fw(codec, coef0292);
4441                 break;
4442         case 0x10ec0293:
4443                 alc_process_coef_fw(codec, coef0293);
4444                 break;
4445         case 0x10ec0668:
4446                 alc_process_coef_fw(codec, coef0688);
4447                 break;
4448         case 0x10ec0225:
4449         case 0x10ec0295:
4450         case 0x10ec0299:
4451                 alc_process_coef_fw(codec, coef0225);
4452                 break;
4453         }
4454         codec_dbg(codec, "Headset jack set to Nokia-style headset mode.\n");
4455 }
4456
4457 static void alc_determine_headset_type(struct hda_codec *codec)
4458 {
4459         int val;
4460         bool is_ctia = false;
4461         struct alc_spec *spec = codec->spec;
4462         static struct coef_fw coef0255[] = {
4463                 WRITE_COEF(0x45, 0xd089), /* combo jack auto switch control(Check type)*/
4464                 WRITE_COEF(0x49, 0x0149), /* combo jack auto switch control(Vref
4465  conteol) */
4466                 {}
4467         };
4468         static struct coef_fw coef0288[] = {
4469                 UPDATE_COEF(0x4f, 0xfcc0, 0xd400), /* Check Type */
4470                 {}
4471         };
4472         static struct coef_fw coef0298[] = {
4473                 UPDATE_COEF(0x50, 0x2000, 0x2000),
4474                 UPDATE_COEF(0x56, 0x0006, 0x0006),
4475                 UPDATE_COEF(0x66, 0x0008, 0),
4476                 UPDATE_COEF(0x67, 0x2000, 0),
4477                 UPDATE_COEF(0x19, 0x1300, 0x1300),
4478                 {}
4479         };
4480         static struct coef_fw coef0293[] = {
4481                 UPDATE_COEF(0x4a, 0x000f, 0x0008), /* Combo Jack auto detect */
4482                 WRITE_COEF(0x45, 0xD429), /* Set to ctia type */
4483                 {}
4484         };
4485         static struct coef_fw coef0688[] = {
4486                 WRITE_COEF(0x11, 0x0001),
4487                 WRITE_COEF(0xb7, 0x802b),
4488                 WRITE_COEF(0x15, 0x0d60),
4489                 WRITE_COEF(0xc3, 0x0c00),
4490                 {}
4491         };
4492         static struct coef_fw coef0274[] = {
4493                 UPDATE_COEF(0x4a, 0x0010, 0),
4494                 UPDATE_COEF(0x4a, 0x8000, 0),
4495                 WRITE_COEF(0x45, 0xd289),
4496                 UPDATE_COEF(0x49, 0x0300, 0x0300),
4497                 {}
4498         };
4499
4500         switch (codec->core.vendor_id) {
4501         case 0x10ec0236:
4502         case 0x10ec0255:
4503         case 0x10ec0256:
4504                 alc_process_coef_fw(codec, coef0255);
4505                 msleep(300);
4506                 val = alc_read_coef_idx(codec, 0x46);
4507                 is_ctia = (val & 0x0070) == 0x0070;
4508                 break;
4509         case 0x10ec0234:
4510         case 0x10ec0274:
4511         case 0x10ec0294:
4512                 alc_process_coef_fw(codec, coef0274);
4513                 msleep(80);
4514                 val = alc_read_coef_idx(codec, 0x46);
4515                 is_ctia = (val & 0x00f0) == 0x00f0;
4516                 break;
4517         case 0x10ec0233:
4518         case 0x10ec0283:
4519                 alc_write_coef_idx(codec, 0x45, 0xd029);
4520                 msleep(300);
4521                 val = alc_read_coef_idx(codec, 0x46);
4522                 is_ctia = (val & 0x0070) == 0x0070;
4523                 break;
4524         case 0x10ec0298:
4525                 snd_hda_codec_write(codec, 0x21, 0,
4526                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
4527                 msleep(100);
4528                 snd_hda_codec_write(codec, 0x21, 0,
4529                             AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0);
4530                 msleep(200);
4531
4532                 val = alc_read_coef_idx(codec, 0x50);
4533                 if (val & (1 << 12)) {
4534                         alc_update_coef_idx(codec, 0x8e, 0x0070, 0x0020);
4535                         alc_process_coef_fw(codec, coef0288);
4536                         msleep(350);
4537                         val = alc_read_coef_idx(codec, 0x50);
4538                         is_ctia = (val & 0x0070) == 0x0070;
4539                 } else {
4540                         alc_update_coef_idx(codec, 0x8e, 0x0070, 0x0010);
4541                         alc_process_coef_fw(codec, coef0288);
4542                         msleep(350);
4543                         val = alc_read_coef_idx(codec, 0x50);
4544                         is_ctia = (val & 0x0070) == 0x0070;
4545                 }
4546                 alc_process_coef_fw(codec, coef0298);
4547                 snd_hda_codec_write(codec, 0x21, 0,
4548                             AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
4549                 msleep(75);
4550                 snd_hda_codec_write(codec, 0x21, 0,
4551                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
4552                 break;
4553         case 0x10ec0286:
4554         case 0x10ec0288:
4555                 alc_process_coef_fw(codec, coef0288);
4556                 msleep(350);
4557                 val = alc_read_coef_idx(codec, 0x50);
4558                 is_ctia = (val & 0x0070) == 0x0070;
4559                 break;
4560         case 0x10ec0292:
4561                 alc_write_coef_idx(codec, 0x6b, 0xd429);
4562                 msleep(300);
4563                 val = alc_read_coef_idx(codec, 0x6c);
4564                 is_ctia = (val & 0x001c) == 0x001c;
4565                 break;
4566         case 0x10ec0293:
4567                 alc_process_coef_fw(codec, coef0293);
4568                 msleep(300);
4569                 val = alc_read_coef_idx(codec, 0x46);
4570                 is_ctia = (val & 0x0070) == 0x0070;
4571                 break;
4572         case 0x10ec0668:
4573                 alc_process_coef_fw(codec, coef0688);
4574                 msleep(300);
4575                 val = alc_read_coef_idx(codec, 0xbe);
4576                 is_ctia = (val & 0x1c02) == 0x1c02;
4577                 break;
4578         case 0x10ec0225:
4579         case 0x10ec0295:
4580         case 0x10ec0299:
4581                 alc_process_coef_fw(codec, alc225_pre_hsmode);
4582                 alc_update_coef_idx(codec, 0x67, 0xf000, 0x1000);
4583                 val = alc_read_coef_idx(codec, 0x45);
4584                 if (val & (1 << 9)) {
4585                         alc_update_coef_idx(codec, 0x45, 0x3f<<10, 0x34<<10);
4586                         alc_update_coef_idx(codec, 0x49, 3<<8, 2<<8);
4587                         msleep(800);
4588                         val = alc_read_coef_idx(codec, 0x46);
4589                         is_ctia = (val & 0x00f0) == 0x00f0;
4590                 } else {
4591                         alc_update_coef_idx(codec, 0x45, 0x3f<<10, 0x34<<10);
4592                         alc_update_coef_idx(codec, 0x49, 3<<8, 1<<8);
4593                         msleep(800);
4594                         val = alc_read_coef_idx(codec, 0x46);
4595                         is_ctia = (val & 0x00f0) == 0x00f0;
4596                 }
4597                 alc_update_coef_idx(codec, 0x4a, 7<<6, 7<<6);
4598                 alc_update_coef_idx(codec, 0x4a, 3<<4, 3<<4);
4599                 alc_update_coef_idx(codec, 0x67, 0xf000, 0x3000);
4600                 break;
4601         case 0x10ec0867:
4602                 is_ctia = true;
4603                 break;
4604         }
4605
4606         codec_dbg(codec, "Headset jack detected iPhone-style headset: %s\n",
4607                     is_ctia ? "yes" : "no");
4608         spec->current_headset_type = is_ctia ? ALC_HEADSET_TYPE_CTIA : ALC_HEADSET_TYPE_OMTP;
4609 }
4610
4611 static void alc_update_headset_mode(struct hda_codec *codec)
4612 {
4613         struct alc_spec *spec = codec->spec;
4614
4615         hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
4616         hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
4617
4618         int new_headset_mode;
4619
4620         if (!snd_hda_jack_detect(codec, hp_pin))
4621                 new_headset_mode = ALC_HEADSET_MODE_UNPLUGGED;
4622         else if (mux_pin == spec->headset_mic_pin)
4623                 new_headset_mode = ALC_HEADSET_MODE_HEADSET;
4624         else if (mux_pin == spec->headphone_mic_pin)
4625                 new_headset_mode = ALC_HEADSET_MODE_MIC;
4626         else
4627                 new_headset_mode = ALC_HEADSET_MODE_HEADPHONE;
4628
4629         if (new_headset_mode == spec->current_headset_mode) {
4630                 snd_hda_gen_update_outputs(codec);
4631                 return;
4632         }
4633
4634         switch (new_headset_mode) {
4635         case ALC_HEADSET_MODE_UNPLUGGED:
4636                 alc_headset_mode_unplugged(codec);
4637                 spec->gen.hp_jack_present = false;
4638                 break;
4639         case ALC_HEADSET_MODE_HEADSET:
4640                 if (spec->current_headset_type == ALC_HEADSET_TYPE_UNKNOWN)
4641                         alc_determine_headset_type(codec);
4642                 if (spec->current_headset_type == ALC_HEADSET_TYPE_CTIA)
4643                         alc_headset_mode_ctia(codec);
4644                 else if (spec->current_headset_type == ALC_HEADSET_TYPE_OMTP)
4645                         alc_headset_mode_omtp(codec);
4646                 spec->gen.hp_jack_present = true;
4647                 break;
4648         case ALC_HEADSET_MODE_MIC:
4649                 alc_headset_mode_mic_in(codec, hp_pin, spec->headphone_mic_pin);
4650                 spec->gen.hp_jack_present = false;
4651                 break;
4652         case ALC_HEADSET_MODE_HEADPHONE:
4653                 alc_headset_mode_default(codec);
4654                 spec->gen.hp_jack_present = true;
4655                 break;
4656         }
4657         if (new_headset_mode != ALC_HEADSET_MODE_MIC) {
4658                 snd_hda_set_pin_ctl_cache(codec, hp_pin,
4659                                           AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
4660                 if (spec->headphone_mic_pin && spec->headphone_mic_pin != hp_pin)
4661                         snd_hda_set_pin_ctl_cache(codec, spec->headphone_mic_pin,
4662                                                   PIN_VREFHIZ);
4663         }
4664         spec->current_headset_mode = new_headset_mode;
4665
4666         snd_hda_gen_update_outputs(codec);
4667 }
4668
4669 static void alc_update_headset_mode_hook(struct hda_codec *codec,
4670                                          struct snd_kcontrol *kcontrol,
4671                                          struct snd_ctl_elem_value *ucontrol)
4672 {
4673         alc_update_headset_mode(codec);
4674 }
4675
4676 static void alc_update_headset_jack_cb(struct hda_codec *codec,
4677                                        struct hda_jack_callback *jack)
4678 {
4679         struct alc_spec *spec = codec->spec;
4680         spec->current_headset_type = ALC_HEADSET_TYPE_UNKNOWN;
4681         snd_hda_gen_hp_automute(codec, jack);
4682 }
4683
4684 static void alc_probe_headset_mode(struct hda_codec *codec)
4685 {
4686         int i;
4687         struct alc_spec *spec = codec->spec;
4688         struct auto_pin_cfg *cfg = &spec->gen.autocfg;
4689
4690         /* Find mic pins */
4691         for (i = 0; i < cfg->num_inputs; i++) {
4692                 if (cfg->inputs[i].is_headset_mic && !spec->headset_mic_pin)
4693                         spec->headset_mic_pin = cfg->inputs[i].pin;
4694                 if (cfg->inputs[i].is_headphone_mic && !spec->headphone_mic_pin)
4695                         spec->headphone_mic_pin = cfg->inputs[i].pin;
4696         }
4697
4698         spec->gen.cap_sync_hook = alc_update_headset_mode_hook;
4699         spec->gen.automute_hook = alc_update_headset_mode;
4700         spec->gen.hp_automute_hook = alc_update_headset_jack_cb;
4701 }
4702
4703 static void alc_fixup_headset_mode(struct hda_codec *codec,
4704                                 const struct hda_fixup *fix, int action)
4705 {
4706         struct alc_spec *spec = codec->spec;
4707
4708         switch (action) {
4709         case HDA_FIXUP_ACT_PRE_PROBE:
4710                 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC | HDA_PINCFG_HEADPHONE_MIC;
4711                 break;
4712         case HDA_FIXUP_ACT_PROBE:
4713                 alc_probe_headset_mode(codec);
4714                 break;
4715         case HDA_FIXUP_ACT_INIT:
4716                 spec->current_headset_mode = 0;
4717                 alc_update_headset_mode(codec);
4718                 break;
4719         }
4720 }
4721
4722 static void alc_fixup_headset_mode_no_hp_mic(struct hda_codec *codec,
4723                                 const struct hda_fixup *fix, int action)
4724 {
4725         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4726                 struct alc_spec *spec = codec->spec;
4727                 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
4728         }
4729         else
4730                 alc_fixup_headset_mode(codec, fix, action);
4731 }
4732
4733 static void alc255_set_default_jack_type(struct hda_codec *codec)
4734 {
4735         /* Set to iphone type */
4736         static struct coef_fw alc255fw[] = {
4737                 WRITE_COEF(0x1b, 0x880b),
4738                 WRITE_COEF(0x45, 0xd089),
4739                 WRITE_COEF(0x1b, 0x080b),
4740                 WRITE_COEF(0x46, 0x0004),
4741                 WRITE_COEF(0x1b, 0x0c0b),
4742                 {}
4743         };
4744         static struct coef_fw alc256fw[] = {
4745                 WRITE_COEF(0x1b, 0x884b),
4746                 WRITE_COEF(0x45, 0xd089),
4747                 WRITE_COEF(0x1b, 0x084b),
4748                 WRITE_COEF(0x46, 0x0004),
4749                 WRITE_COEF(0x1b, 0x0c4b),
4750                 {}
4751         };
4752         switch (codec->core.vendor_id) {
4753         case 0x10ec0255:
4754                 alc_process_coef_fw(codec, alc255fw);
4755                 break;
4756         case 0x10ec0236:
4757         case 0x10ec0256:
4758                 alc_process_coef_fw(codec, alc256fw);
4759                 break;
4760         }
4761         msleep(30);
4762 }
4763
4764 static void alc_fixup_headset_mode_alc255(struct hda_codec *codec,
4765                                 const struct hda_fixup *fix, int action)
4766 {
4767         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4768                 alc255_set_default_jack_type(codec);
4769         }
4770         alc_fixup_headset_mode(codec, fix, action);
4771 }
4772
4773 static void alc_fixup_headset_mode_alc255_no_hp_mic(struct hda_codec *codec,
4774                                 const struct hda_fixup *fix, int action)
4775 {
4776         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4777                 struct alc_spec *spec = codec->spec;
4778                 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
4779                 alc255_set_default_jack_type(codec);
4780         } 
4781         else
4782                 alc_fixup_headset_mode(codec, fix, action);
4783 }
4784
4785 static void alc288_update_headset_jack_cb(struct hda_codec *codec,
4786                                        struct hda_jack_callback *jack)
4787 {
4788         struct alc_spec *spec = codec->spec;
4789         int present;
4790
4791         alc_update_headset_jack_cb(codec, jack);
4792         /* Headset Mic enable or disable, only for Dell Dino */
4793         present = spec->gen.hp_jack_present ? 0x40 : 0;
4794         snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4795                                 present);
4796 }
4797
4798 static void alc_fixup_headset_mode_dell_alc288(struct hda_codec *codec,
4799                                 const struct hda_fixup *fix, int action)
4800 {
4801         alc_fixup_headset_mode(codec, fix, action);
4802         if (action == HDA_FIXUP_ACT_PROBE) {
4803                 struct alc_spec *spec = codec->spec;
4804                 spec->gen.hp_automute_hook = alc288_update_headset_jack_cb;
4805         }
4806 }
4807
4808 static void alc_fixup_auto_mute_via_amp(struct hda_codec *codec,
4809                                         const struct hda_fixup *fix, int action)
4810 {
4811         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4812                 struct alc_spec *spec = codec->spec;
4813                 spec->gen.auto_mute_via_amp = 1;
4814         }
4815 }
4816
4817 static void alc_no_shutup(struct hda_codec *codec)
4818 {
4819 }
4820
4821 static void alc_fixup_no_shutup(struct hda_codec *codec,
4822                                 const struct hda_fixup *fix, int action)
4823 {
4824         if (action == HDA_FIXUP_ACT_PROBE) {
4825                 struct alc_spec *spec = codec->spec;
4826                 spec->shutup = alc_no_shutup;
4827         }
4828 }
4829
4830 static void alc_fixup_disable_aamix(struct hda_codec *codec,
4831                                     const struct hda_fixup *fix, int action)
4832 {
4833         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4834                 struct alc_spec *spec = codec->spec;
4835                 /* Disable AA-loopback as it causes white noise */
4836                 spec->gen.mixer_nid = 0;
4837         }
4838 }
4839
4840 /* fixup for Thinkpad docks: add dock pins, avoid HP parser fixup */
4841 static void alc_fixup_tpt440_dock(struct hda_codec *codec,
4842                                   const struct hda_fixup *fix, int action)
4843 {
4844         static const struct hda_pintbl pincfgs[] = {
4845                 { 0x16, 0x21211010 }, /* dock headphone */
4846                 { 0x19, 0x21a11010 }, /* dock mic */
4847                 { }
4848         };
4849         struct alc_spec *spec = codec->spec;
4850
4851         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4852                 spec->reboot_notify = alc_d3_at_reboot; /* reduce noise */
4853                 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
4854                 codec->power_save_node = 0; /* avoid click noises */
4855                 snd_hda_apply_pincfgs(codec, pincfgs);
4856         }
4857 }
4858
4859 static void alc_fixup_tpt470_dock(struct hda_codec *codec,
4860                                   const struct hda_fixup *fix, int action)
4861 {
4862         static const struct hda_pintbl pincfgs[] = {
4863                 { 0x17, 0x21211010 }, /* dock headphone */
4864                 { 0x19, 0x21a11010 }, /* dock mic */
4865                 { }
4866         };
4867         /* Assure the speaker pin to be coupled with DAC NID 0x03; otherwise
4868          * the speaker output becomes too low by some reason on Thinkpads with
4869          * ALC298 codec
4870          */
4871         static hda_nid_t preferred_pairs[] = {
4872                 0x14, 0x03, 0x17, 0x02, 0x21, 0x02,
4873                 0
4874         };
4875         struct alc_spec *spec = codec->spec;
4876
4877         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4878                 spec->gen.preferred_dacs = preferred_pairs;
4879                 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
4880                 snd_hda_apply_pincfgs(codec, pincfgs);
4881         } else if (action == HDA_FIXUP_ACT_INIT) {
4882                 /* Enable DOCK device */
4883                 snd_hda_codec_write(codec, 0x17, 0,
4884                             AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0);
4885                 /* Enable DOCK device */
4886                 snd_hda_codec_write(codec, 0x19, 0,
4887                             AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0);
4888         }
4889 }
4890
4891 static void alc_shutup_dell_xps13(struct hda_codec *codec)
4892 {
4893         struct alc_spec *spec = codec->spec;
4894         int hp_pin = spec->gen.autocfg.hp_pins[0];
4895
4896         /* Prevent pop noises when headphones are plugged in */
4897         snd_hda_codec_write(codec, hp_pin, 0,
4898                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
4899         msleep(20);
4900 }
4901
4902 static void alc_fixup_dell_xps13(struct hda_codec *codec,
4903                                 const struct hda_fixup *fix, int action)
4904 {
4905         struct alc_spec *spec = codec->spec;
4906         struct hda_input_mux *imux = &spec->gen.input_mux;
4907         int i;
4908
4909         switch (action) {
4910         case HDA_FIXUP_ACT_PRE_PROBE:
4911                 /* mic pin 0x19 must be initialized with Vref Hi-Z, otherwise
4912                  * it causes a click noise at start up
4913                  */
4914                 snd_hda_codec_set_pin_target(codec, 0x19, PIN_VREFHIZ);
4915                 break;
4916         case HDA_FIXUP_ACT_PROBE:
4917                 spec->shutup = alc_shutup_dell_xps13;
4918
4919                 /* Make the internal mic the default input source. */
4920                 for (i = 0; i < imux->num_items; i++) {
4921                         if (spec->gen.imux_pins[i] == 0x12) {
4922                                 spec->gen.cur_mux[0] = i;
4923                                 break;
4924                         }
4925                 }
4926                 break;
4927         }
4928 }
4929
4930 static void alc_fixup_headset_mode_alc662(struct hda_codec *codec,
4931                                 const struct hda_fixup *fix, int action)
4932 {
4933         struct alc_spec *spec = codec->spec;
4934
4935         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4936                 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
4937                 spec->gen.hp_mic = 1; /* Mic-in is same pin as headphone */
4938
4939                 /* Disable boost for mic-in permanently. (This code is only called
4940                    from quirks that guarantee that the headphone is at NID 0x1b.) */
4941                 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000);
4942                 snd_hda_override_wcaps(codec, 0x1b, get_wcaps(codec, 0x1b) & ~AC_WCAP_IN_AMP);
4943         } else
4944                 alc_fixup_headset_mode(codec, fix, action);
4945 }
4946
4947 static void alc_fixup_headset_mode_alc668(struct hda_codec *codec,
4948                                 const struct hda_fixup *fix, int action)
4949 {
4950         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4951                 alc_write_coef_idx(codec, 0xc4, 0x8000);
4952                 alc_update_coef_idx(codec, 0xc2, ~0xfe, 0);
4953                 snd_hda_set_pin_ctl_cache(codec, 0x18, 0);
4954         }
4955         alc_fixup_headset_mode(codec, fix, action);
4956 }
4957
4958 /* Returns the nid of the external mic input pin, or 0 if it cannot be found. */
4959 static int find_ext_mic_pin(struct hda_codec *codec)
4960 {
4961         struct alc_spec *spec = codec->spec;
4962         struct auto_pin_cfg *cfg = &spec->gen.autocfg;
4963         hda_nid_t nid;
4964         unsigned int defcfg;
4965         int i;
4966
4967         for (i = 0; i < cfg->num_inputs; i++) {
4968                 if (cfg->inputs[i].type != AUTO_PIN_MIC)
4969                         continue;
4970                 nid = cfg->inputs[i].pin;
4971                 defcfg = snd_hda_codec_get_pincfg(codec, nid);
4972                 if (snd_hda_get_input_pin_attr(defcfg) == INPUT_PIN_ATTR_INT)
4973                         continue;
4974                 return nid;
4975         }
4976
4977         return 0;
4978 }
4979
4980 static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
4981                                     const struct hda_fixup *fix,
4982                                     int action)
4983 {
4984         struct alc_spec *spec = codec->spec;
4985
4986         if (action == HDA_FIXUP_ACT_PROBE) {
4987                 int mic_pin = find_ext_mic_pin(codec);
4988                 int hp_pin = spec->gen.autocfg.hp_pins[0];
4989
4990                 if (snd_BUG_ON(!mic_pin || !hp_pin))
4991                         return;
4992                 snd_hda_jack_set_gating_jack(codec, mic_pin, hp_pin);
4993         }
4994 }
4995
4996 static void alc269_fixup_limit_int_mic_boost(struct hda_codec *codec,
4997                                              const struct hda_fixup *fix,
4998                                              int action)
4999 {
5000         struct alc_spec *spec = codec->spec;
5001         struct auto_pin_cfg *cfg = &spec->gen.autocfg;
5002         int i;
5003
5004         /* The mic boosts on level 2 and 3 are too noisy
5005            on the internal mic input.
5006            Therefore limit the boost to 0 or 1. */
5007
5008         if (action != HDA_FIXUP_ACT_PROBE)
5009                 return;
5010
5011         for (i = 0; i < cfg->num_inputs; i++) {
5012                 hda_nid_t nid = cfg->inputs[i].pin;
5013                 unsigned int defcfg;
5014                 if (cfg->inputs[i].type != AUTO_PIN_MIC)
5015                         continue;
5016                 defcfg = snd_hda_codec_get_pincfg(codec, nid);
5017                 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
5018                         continue;
5019
5020                 snd_hda_override_amp_caps(codec, nid, HDA_INPUT,
5021                                           (0x00 << AC_AMPCAP_OFFSET_SHIFT) |
5022                                           (0x01 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5023                                           (0x2f << AC_AMPCAP_STEP_SIZE_SHIFT) |
5024                                           (0 << AC_AMPCAP_MUTE_SHIFT));
5025         }
5026 }
5027
5028 static void alc283_hp_automute_hook(struct hda_codec *codec,
5029                                     struct hda_jack_callback *jack)
5030 {
5031         struct alc_spec *spec = codec->spec;
5032         int vref;
5033
5034         msleep(200);
5035         snd_hda_gen_hp_automute(codec, jack);
5036
5037         vref = spec->gen.hp_jack_present ? PIN_VREF80 : 0;
5038
5039         msleep(600);
5040         snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5041                             vref);
5042 }
5043
5044 static void alc283_fixup_chromebook(struct hda_codec *codec,
5045                                     const struct hda_fixup *fix, int action)
5046 {
5047         struct alc_spec *spec = codec->spec;
5048
5049         switch (action) {
5050         case HDA_FIXUP_ACT_PRE_PROBE:
5051                 snd_hda_override_wcaps(codec, 0x03, 0);
5052                 /* Disable AA-loopback as it causes white noise */
5053                 spec->gen.mixer_nid = 0;
5054                 break;
5055         case HDA_FIXUP_ACT_INIT:
5056                 /* MIC2-VREF control */
5057                 /* Set to manual mode */
5058                 alc_update_coef_idx(codec, 0x06, 0x000c, 0);
5059                 /* Enable Line1 input control by verb */
5060                 alc_update_coef_idx(codec, 0x1a, 0, 1 << 4);
5061                 break;
5062         }
5063 }
5064
5065 static void alc283_fixup_sense_combo_jack(struct hda_codec *codec,
5066                                     const struct hda_fixup *fix, int action)
5067 {
5068         struct alc_spec *spec = codec->spec;
5069
5070         switch (action) {
5071         case HDA_FIXUP_ACT_PRE_PROBE:
5072                 spec->gen.hp_automute_hook = alc283_hp_automute_hook;
5073                 break;
5074         case HDA_FIXUP_ACT_INIT:
5075                 /* MIC2-VREF control */
5076                 /* Set to manual mode */
5077                 alc_update_coef_idx(codec, 0x06, 0x000c, 0);
5078                 break;
5079         }
5080 }
5081
5082 /* mute tablet speaker pin (0x14) via dock plugging in addition */
5083 static void asus_tx300_automute(struct hda_codec *codec)
5084 {
5085         struct alc_spec *spec = codec->spec;
5086         snd_hda_gen_update_outputs(codec);
5087         if (snd_hda_jack_detect(codec, 0x1b))
5088                 spec->gen.mute_bits |= (1ULL << 0x14);
5089 }
5090
5091 static void alc282_fixup_asus_tx300(struct hda_codec *codec,
5092                                     const struct hda_fixup *fix, int action)
5093 {
5094         struct alc_spec *spec = codec->spec;
5095         /* TX300 needs to set up GPIO2 for the speaker amp */
5096         static const struct hda_verb gpio2_verbs[] = {
5097                 { 0x01, AC_VERB_SET_GPIO_MASK, 0x04 },
5098                 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04 },
5099                 { 0x01, AC_VERB_SET_GPIO_DATA, 0x04 },
5100                 {}
5101         };
5102         static const struct hda_pintbl dock_pins[] = {
5103                 { 0x1b, 0x21114000 }, /* dock speaker pin */
5104                 {}
5105         };
5106
5107         switch (action) {
5108         case HDA_FIXUP_ACT_PRE_PROBE:
5109                 snd_hda_add_verbs(codec, gpio2_verbs);
5110                 snd_hda_apply_pincfgs(codec, dock_pins);
5111                 spec->gen.auto_mute_via_amp = 1;
5112                 spec->gen.automute_hook = asus_tx300_automute;
5113                 snd_hda_jack_detect_enable_callback(codec, 0x1b,
5114                                                     snd_hda_gen_hp_automute);
5115                 break;
5116         case HDA_FIXUP_ACT_BUILD:
5117                 /* this is a bit tricky; give more sane names for the main
5118                  * (tablet) speaker and the dock speaker, respectively
5119                  */
5120                 rename_ctl(codec, "Speaker Playback Switch",
5121                            "Dock Speaker Playback Switch");
5122                 rename_ctl(codec, "Bass Speaker Playback Switch",
5123                            "Speaker Playback Switch");
5124                 break;
5125         }
5126 }
5127
5128 static void alc290_fixup_mono_speakers(struct hda_codec *codec,
5129                                        const struct hda_fixup *fix, int action)
5130 {
5131         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
5132                 /* DAC node 0x03 is giving mono output. We therefore want to
5133                    make sure 0x14 (front speaker) and 0x15 (headphones) use the
5134                    stereo DAC, while leaving 0x17 (bass speaker) for node 0x03. */
5135                 hda_nid_t conn1[2] = { 0x0c };
5136                 snd_hda_override_conn_list(codec, 0x14, 1, conn1);
5137                 snd_hda_override_conn_list(codec, 0x15, 1, conn1);
5138         }
5139 }
5140
5141 static void alc298_fixup_speaker_volume(struct hda_codec *codec,
5142                                         const struct hda_fixup *fix, int action)
5143 {
5144         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
5145                 /* The speaker is routed to the Node 0x06 by a mistake, as a result
5146                    we can't adjust the speaker's volume since this node does not has
5147                    Amp-out capability. we change the speaker's route to:
5148                    Node 0x02 (Audio Output) -> Node 0x0c (Audio Mixer) -> Node 0x17 (
5149                    Pin Complex), since Node 0x02 has Amp-out caps, we can adjust
5150                    speaker's volume now. */
5151
5152                 hda_nid_t conn1[1] = { 0x0c };
5153                 snd_hda_override_conn_list(codec, 0x17, 1, conn1);
5154         }
5155 }
5156
5157 /* disable DAC3 (0x06) selection on NID 0x17 as it has no volume amp control */
5158 static void alc295_fixup_disable_dac3(struct hda_codec *codec,
5159                                       const struct hda_fixup *fix, int action)
5160 {
5161         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
5162                 hda_nid_t conn[2] = { 0x02, 0x03 };
5163                 snd_hda_override_conn_list(codec, 0x17, 2, conn);
5164         }
5165 }
5166
5167 /* Hook to update amp GPIO4 for automute */
5168 static void alc280_hp_gpio4_automute_hook(struct hda_codec *codec,
5169                                           struct hda_jack_callback *jack)
5170 {
5171         struct alc_spec *spec = codec->spec;
5172
5173         snd_hda_gen_hp_automute(codec, jack);
5174         /* mute_led_polarity is set to 0, so we pass inverted value here */
5175         alc_update_gpio_led(codec, 0x10, !spec->gen.hp_jack_present);
5176 }
5177
5178 /* Manage GPIOs for HP EliteBook Folio 9480m.
5179  *
5180  * GPIO4 is the headphone amplifier power control
5181  * GPIO3 is the audio output mute indicator LED
5182  */
5183
5184 static void alc280_fixup_hp_9480m(struct hda_codec *codec,
5185                                   const struct hda_fixup *fix,
5186                                   int action)
5187 {
5188         struct alc_spec *spec = codec->spec;
5189         static const struct hda_verb gpio_init[] = {
5190                 { 0x01, AC_VERB_SET_GPIO_MASK, 0x18 },
5191                 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x18 },
5192                 {}
5193         };
5194
5195         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
5196                 /* Set the hooks to turn the headphone amp on/off
5197                  * as needed
5198                  */
5199                 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
5200                 spec->gen.hp_automute_hook = alc280_hp_gpio4_automute_hook;
5201
5202                 /* The GPIOs are currently off */
5203                 spec->gpio_led = 0;
5204
5205                 /* GPIO3 is connected to the output mute LED,
5206                  * high is on, low is off
5207                  */
5208                 spec->mute_led_polarity = 0;
5209                 spec->gpio_mute_led_mask = 0x08;
5210
5211                 /* Initialize GPIO configuration */
5212                 snd_hda_add_verbs(codec, gpio_init);
5213         }
5214 }
5215
5216 static void alc233_alc662_fixup_lenovo_dual_codecs(struct hda_codec *codec,
5217                                          const struct hda_fixup *fix,
5218                                          int action)
5219 {
5220         alc_fixup_dual_codecs(codec, fix, action);
5221         switch (action) {
5222         case HDA_FIXUP_ACT_PRE_PROBE:
5223                 /* override card longname to provide a unique UCM profile */
5224                 strcpy(codec->card->longname, "HDAudio-Lenovo-DualCodecs");
5225                 break;
5226         case HDA_FIXUP_ACT_BUILD:
5227                 /* rename Capture controls depending on the codec */
5228                 rename_ctl(codec, "Capture Volume",
5229                            codec->addr == 0 ?
5230                            "Rear-Panel Capture Volume" :
5231                            "Front-Panel Capture Volume");
5232                 rename_ctl(codec, "Capture Switch",
5233                            codec->addr == 0 ?
5234                            "Rear-Panel Capture Switch" :
5235                            "Front-Panel Capture Switch");
5236                 break;
5237         }
5238 }
5239
5240 /* Forcibly assign NID 0x03 to HP/LO while NID 0x02 to SPK for EQ */
5241 static void alc274_fixup_bind_dacs(struct hda_codec *codec,
5242                                     const struct hda_fixup *fix, int action)
5243 {
5244         struct alc_spec *spec = codec->spec;
5245         static hda_nid_t preferred_pairs[] = {
5246                 0x21, 0x03, 0x1b, 0x03, 0x16, 0x02,
5247                 0
5248         };
5249
5250         if (action != HDA_FIXUP_ACT_PRE_PROBE)
5251                 return;
5252
5253         spec->gen.preferred_dacs = preferred_pairs;
5254 }
5255
5256 /* for hda_fixup_thinkpad_acpi() */
5257 #include "thinkpad_helper.c"
5258
5259 static void alc_fixup_thinkpad_acpi(struct hda_codec *codec,
5260                                     const struct hda_fixup *fix, int action)
5261 {
5262         alc_fixup_no_shutup(codec, fix, action); /* reduce click noise */
5263         hda_fixup_thinkpad_acpi(codec, fix, action);
5264 }
5265
5266 /* for dell wmi mic mute led */
5267 #include "dell_wmi_helper.c"
5268
5269 enum {
5270         ALC269_FIXUP_SONY_VAIO,
5271         ALC275_FIXUP_SONY_VAIO_GPIO2,
5272         ALC269_FIXUP_DELL_M101Z,
5273         ALC269_FIXUP_SKU_IGNORE,
5274         ALC269_FIXUP_ASUS_G73JW,
5275         ALC269_FIXUP_LENOVO_EAPD,
5276         ALC275_FIXUP_SONY_HWEQ,
5277         ALC275_FIXUP_SONY_DISABLE_AAMIX,
5278         ALC271_FIXUP_DMIC,
5279         ALC269_FIXUP_PCM_44K,
5280         ALC269_FIXUP_STEREO_DMIC,
5281         ALC269_FIXUP_HEADSET_MIC,
5282         ALC269_FIXUP_QUANTA_MUTE,
5283         ALC269_FIXUP_LIFEBOOK,
5284         ALC269_FIXUP_LIFEBOOK_EXTMIC,
5285         ALC269_FIXUP_LIFEBOOK_HP_PIN,
5286         ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT,
5287         ALC255_FIXUP_LIFEBOOK_U7x7_HEADSET_MIC,
5288         ALC269_FIXUP_AMIC,
5289         ALC269_FIXUP_DMIC,
5290         ALC269VB_FIXUP_AMIC,
5291         ALC269VB_FIXUP_DMIC,
5292         ALC269_FIXUP_HP_MUTE_LED,
5293         ALC269_FIXUP_HP_MUTE_LED_MIC1,
5294         ALC269_FIXUP_HP_MUTE_LED_MIC2,
5295         ALC269_FIXUP_HP_GPIO_LED,
5296         ALC269_FIXUP_HP_GPIO_MIC1_LED,
5297         ALC269_FIXUP_HP_LINE1_MIC1_LED,
5298         ALC269_FIXUP_INV_DMIC,
5299         ALC269_FIXUP_LENOVO_DOCK,
5300         ALC269_FIXUP_NO_SHUTUP,
5301         ALC286_FIXUP_SONY_MIC_NO_PRESENCE,
5302         ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
5303         ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
5304         ALC269_FIXUP_DELL2_MIC_NO_PRESENCE,
5305         ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
5306         ALC269_FIXUP_DELL4_MIC_NO_PRESENCE,
5307         ALC269_FIXUP_HEADSET_MODE,
5308         ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC,
5309         ALC269_FIXUP_ASPIRE_HEADSET_MIC,
5310         ALC269_FIXUP_ASUS_X101_FUNC,
5311         ALC269_FIXUP_ASUS_X101_VERB,
5312         ALC269_FIXUP_ASUS_X101,
5313         ALC271_FIXUP_AMIC_MIC2,
5314         ALC271_FIXUP_HP_GATE_MIC_JACK,
5315         ALC271_FIXUP_HP_GATE_MIC_JACK_E1_572,
5316         ALC269_FIXUP_ACER_AC700,
5317         ALC269_FIXUP_LIMIT_INT_MIC_BOOST,
5318         ALC269VB_FIXUP_ASUS_ZENBOOK,
5319         ALC269VB_FIXUP_ASUS_ZENBOOK_UX31A,
5320         ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED,
5321         ALC269VB_FIXUP_ORDISSIMO_EVE2,
5322         ALC283_FIXUP_CHROME_BOOK,
5323         ALC283_FIXUP_SENSE_COMBO_JACK,
5324         ALC282_FIXUP_ASUS_TX300,
5325         ALC283_FIXUP_INT_MIC,
5326         ALC290_FIXUP_MONO_SPEAKERS,
5327         ALC290_FIXUP_MONO_SPEAKERS_HSJACK,
5328         ALC290_FIXUP_SUBWOOFER,
5329         ALC290_FIXUP_SUBWOOFER_HSJACK,
5330         ALC269_FIXUP_THINKPAD_ACPI,
5331         ALC269_FIXUP_DMIC_THINKPAD_ACPI,
5332         ALC255_FIXUP_ACER_MIC_NO_PRESENCE,
5333         ALC255_FIXUP_ASUS_MIC_NO_PRESENCE,
5334         ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5335         ALC255_FIXUP_DELL2_MIC_NO_PRESENCE,
5336         ALC255_FIXUP_HEADSET_MODE,
5337         ALC255_FIXUP_HEADSET_MODE_NO_HP_MIC,
5338         ALC293_FIXUP_DELL1_MIC_NO_PRESENCE,
5339         ALC292_FIXUP_TPT440_DOCK,
5340         ALC292_FIXUP_TPT440,
5341         ALC283_FIXUP_HEADSET_MIC,
5342         ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED,
5343         ALC282_FIXUP_ASPIRE_V5_PINS,
5344         ALC280_FIXUP_HP_GPIO4,
5345         ALC286_FIXUP_HP_GPIO_LED,
5346         ALC280_FIXUP_HP_GPIO2_MIC_HOTKEY,
5347         ALC280_FIXUP_HP_DOCK_PINS,
5348         ALC269_FIXUP_HP_DOCK_GPIO_MIC1_LED,
5349         ALC280_FIXUP_HP_9480M,
5350         ALC288_FIXUP_DELL_HEADSET_MODE,
5351         ALC288_FIXUP_DELL1_MIC_NO_PRESENCE,
5352         ALC288_FIXUP_DELL_XPS_13_GPIO6,
5353         ALC288_FIXUP_DELL_XPS_13,
5354         ALC288_FIXUP_DISABLE_AAMIX,
5355         ALC292_FIXUP_DELL_E7X,
5356         ALC292_FIXUP_DISABLE_AAMIX,
5357         ALC293_FIXUP_DISABLE_AAMIX_MULTIJACK,
5358         ALC298_FIXUP_DELL1_MIC_NO_PRESENCE,
5359         ALC298_FIXUP_DELL_AIO_MIC_NO_PRESENCE,
5360         ALC275_FIXUP_DELL_XPS,
5361         ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE,
5362         ALC293_FIXUP_LENOVO_SPK_NOISE,
5363         ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY,
5364         ALC255_FIXUP_DELL_SPK_NOISE,
5365         ALC225_FIXUP_DELL1_MIC_NO_PRESENCE,
5366         ALC295_FIXUP_DISABLE_DAC3,
5367         ALC280_FIXUP_HP_HEADSET_MIC,
5368         ALC221_FIXUP_HP_FRONT_MIC,
5369         ALC292_FIXUP_TPT460,
5370         ALC298_FIXUP_SPK_VOLUME,
5371         ALC256_FIXUP_DELL_INSPIRON_7559_SUBWOOFER,
5372         ALC269_FIXUP_ATIV_BOOK_8,
5373         ALC221_FIXUP_HP_MIC_NO_PRESENCE,
5374         ALC256_FIXUP_ASUS_HEADSET_MODE,
5375         ALC256_FIXUP_ASUS_MIC,
5376         ALC256_FIXUP_ASUS_AIO_GPIO2,
5377         ALC233_FIXUP_ASUS_MIC_NO_PRESENCE,
5378         ALC233_FIXUP_EAPD_COEF_AND_MIC_NO_PRESENCE,
5379         ALC233_FIXUP_LENOVO_MULTI_CODECS,
5380         ALC294_FIXUP_LENOVO_MIC_LOCATION,
5381         ALC225_FIXUP_DELL_WYSE_MIC_NO_PRESENCE,
5382         ALC700_FIXUP_INTEL_REFERENCE,
5383         ALC274_FIXUP_DELL_BIND_DACS,
5384         ALC274_FIXUP_DELL_AIO_LINEOUT_VERB,
5385         ALC298_FIXUP_TPT470_DOCK,
5386         ALC255_FIXUP_DUMMY_LINEOUT_VERB,
5387         ALC255_FIXUP_DELL_HEADSET_MIC,
5388 };
5389
5390 static const struct hda_fixup alc269_fixups[] = {
5391         [ALC269_FIXUP_SONY_VAIO] = {
5392                 .type = HDA_FIXUP_PINCTLS,
5393                 .v.pins = (const struct hda_pintbl[]) {
5394                         {0x19, PIN_VREFGRD},
5395                         {}
5396                 }
5397         },
5398         [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5399                 .type = HDA_FIXUP_VERBS,
5400                 .v.verbs = (const struct hda_verb[]) {
5401                         {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5402                         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5403                         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5404                         { }
5405                 },
5406                 .chained = true,
5407                 .chain_id = ALC269_FIXUP_SONY_VAIO
5408         },
5409         [ALC269_FIXUP_DELL_M101Z] = {
5410                 .type = HDA_FIXUP_VERBS,
5411                 .v.verbs = (const struct hda_verb[]) {
5412                         /* Enables internal speaker */
5413                         {0x20, AC_VERB_SET_COEF_INDEX, 13},
5414                         {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5415                         {}
5416                 }
5417         },
5418         [ALC269_FIXUP_SKU_IGNORE] = {
5419                 .type = HDA_FIXUP_FUNC,
5420                 .v.func = alc_fixup_sku_ignore,
5421         },
5422         [ALC269_FIXUP_ASUS_G73JW] = {
5423                 .type = HDA_FIXUP_PINS,
5424                 .v.pins = (const struct hda_pintbl[]) {
5425                         { 0x17, 0x99130111 }, /* subwoofer */
5426                         { }
5427                 }
5428         },
5429         [ALC269_FIXUP_LENOVO_EAPD] = {
5430                 .type = HDA_FIXUP_VERBS,
5431                 .v.verbs = (const struct hda_verb[]) {
5432                         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5433                         {}
5434                 }
5435         },
5436         [ALC275_FIXUP_SONY_HWEQ] = {
5437                 .type = HDA_FIXUP_FUNC,
5438                 .v.func = alc269_fixup_hweq,
5439                 .chained = true,
5440                 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5441         },
5442         [ALC275_FIXUP_SONY_DISABLE_AAMIX] = {
5443                 .type = HDA_FIXUP_FUNC,
5444                 .v.func = alc_fixup_disable_aamix,
5445                 .chained = true,
5446                 .chain_id = ALC269_FIXUP_SONY_VAIO
5447         },
5448         [ALC271_FIXUP_DMIC] = {
5449                 .type = HDA_FIXUP_FUNC,
5450                 .v.func = alc271_fixup_dmic,
5451         },
5452         [ALC269_FIXUP_PCM_44K] = {
5453                 .type = HDA_FIXUP_FUNC,
5454                 .v.func = alc269_fixup_pcm_44k,
5455                 .chained = true,
5456                 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5457         },
5458         [ALC269_FIXUP_STEREO_DMIC] = {
5459                 .type = HDA_FIXUP_FUNC,
5460                 .v.func = alc269_fixup_stereo_dmic,
5461         },
5462         [ALC269_FIXUP_HEADSET_MIC] = {
5463                 .type = HDA_FIXUP_FUNC,
5464                 .v.func = alc269_fixup_headset_mic,
5465         },
5466         [ALC269_FIXUP_QUANTA_MUTE] = {
5467                 .type = HDA_FIXUP_FUNC,
5468                 .v.func = alc269_fixup_quanta_mute,
5469         },
5470         [ALC269_FIXUP_LIFEBOOK] = {
5471                 .type = HDA_FIXUP_PINS,
5472                 .v.pins = (const struct hda_pintbl[]) {
5473                         { 0x1a, 0x2101103f }, /* dock line-out */
5474                         { 0x1b, 0x23a11040 }, /* dock mic-in */
5475                         { }
5476                 },
5477                 .chained = true,
5478                 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5479         },
5480         [ALC269_FIXUP_LIFEBOOK_EXTMIC] = {
5481                 .type = HDA_FIXUP_PINS,
5482                 .v.pins = (const struct hda_pintbl[]) {
5483                         { 0x19, 0x01a1903c }, /* headset mic, with jack detect */
5484                         { }
5485                 },
5486         },
5487         [ALC269_FIXUP_LIFEBOOK_HP_PIN] = {
5488                 .type = HDA_FIXUP_PINS,
5489                 .v.pins = (const struct hda_pintbl[]) {
5490                         { 0x21, 0x0221102f }, /* HP out */
5491                         { }
5492                 },
5493         },
5494         [ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT] = {
5495                 .type = HDA_FIXUP_FUNC,
5496                 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
5497         },
5498         [ALC255_FIXUP_LIFEBOOK_U7x7_HEADSET_MIC] = {
5499                 .type = HDA_FIXUP_FUNC,
5500                 .v.func = alc269_fixup_pincfg_U7x7_headset_mic,
5501         },
5502         [ALC269_FIXUP_AMIC] = {
5503                 .type = HDA_FIXUP_PINS,
5504                 .v.pins = (const struct hda_pintbl[]) {
5505                         { 0x14, 0x99130110 }, /* speaker */
5506                         { 0x15, 0x0121401f }, /* HP out */
5507                         { 0x18, 0x01a19c20 }, /* mic */
5508                         { 0x19, 0x99a3092f }, /* int-mic */
5509                         { }
5510                 },
5511         },
5512         [ALC269_FIXUP_DMIC] = {
5513                 .type = HDA_FIXUP_PINS,
5514                 .v.pins = (const struct hda_pintbl[]) {
5515                         { 0x12, 0x99a3092f }, /* int-mic */
5516                         { 0x14, 0x99130110 }, /* speaker */
5517                         { 0x15, 0x0121401f }, /* HP out */
5518                         { 0x18, 0x01a19c20 }, /* mic */
5519                         { }
5520                 },
5521         },
5522         [ALC269VB_FIXUP_AMIC] = {
5523                 .type = HDA_FIXUP_PINS,
5524                 .v.pins = (const struct hda_pintbl[]) {
5525                         { 0x14, 0x99130110 }, /* speaker */
5526                         { 0x18, 0x01a19c20 }, /* mic */
5527                         { 0x19, 0x99a3092f }, /* int-mic */
5528                         { 0x21, 0x0121401f }, /* HP out */
5529                         { }
5530                 },
5531         },
5532         [ALC269VB_FIXUP_DMIC] = {
5533                 .type = HDA_FIXUP_PINS,
5534                 .v.pins = (const struct hda_pintbl[]) {
5535                         { 0x12, 0x99a3092f }, /* int-mic */
5536                         { 0x14, 0x99130110 }, /* speaker */
5537                         { 0x18, 0x01a19c20 }, /* mic */
5538                         { 0x21, 0x0121401f }, /* HP out */
5539                         { }
5540                 },
5541         },
5542         [ALC269_FIXUP_HP_MUTE_LED] = {
5543                 .type = HDA_FIXUP_FUNC,
5544                 .v.func = alc269_fixup_hp_mute_led,
5545         },
5546         [ALC269_FIXUP_HP_MUTE_LED_MIC1] = {
5547                 .type = HDA_FIXUP_FUNC,
5548                 .v.func = alc269_fixup_hp_mute_led_mic1,
5549         },
5550         [ALC269_FIXUP_HP_MUTE_LED_MIC2] = {
5551                 .type = HDA_FIXUP_FUNC,
5552                 .v.func = alc269_fixup_hp_mute_led_mic2,
5553         },
5554         [ALC269_FIXUP_HP_GPIO_LED] = {
5555                 .type = HDA_FIXUP_FUNC,
5556                 .v.func = alc269_fixup_hp_gpio_led,
5557         },
5558         [ALC269_FIXUP_HP_GPIO_MIC1_LED] = {
5559                 .type = HDA_FIXUP_FUNC,
5560                 .v.func = alc269_fixup_hp_gpio_mic1_led,
5561         },
5562         [ALC269_FIXUP_HP_LINE1_MIC1_LED] = {
5563                 .type = HDA_FIXUP_FUNC,
5564                 .v.func = alc269_fixup_hp_line1_mic1_led,
5565         },
5566         [ALC269_FIXUP_INV_DMIC] = {
5567                 .type = HDA_FIXUP_FUNC,
5568                 .v.func = alc_fixup_inv_dmic,
5569         },
5570         [ALC269_FIXUP_NO_SHUTUP] = {
5571                 .type = HDA_FIXUP_FUNC,
5572                 .v.func = alc_fixup_no_shutup,
5573         },
5574         [ALC269_FIXUP_LENOVO_DOCK] = {
5575                 .type = HDA_FIXUP_PINS,
5576                 .v.pins = (const struct hda_pintbl[]) {
5577                         { 0x19, 0x23a11040 }, /* dock mic */
5578                         { 0x1b, 0x2121103f }, /* dock headphone */
5579                         { }
5580                 },
5581                 .chained = true,
5582                 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
5583         },
5584         [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
5585                 .type = HDA_FIXUP_FUNC,
5586                 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
5587                 .chained = true,
5588                 .chain_id = ALC269_FIXUP_THINKPAD_ACPI,
5589         },
5590         [ALC269_FIXUP_DELL1_MIC_NO_PRESENCE] = {
5591                 .type = HDA_FIXUP_PINS,
5592                 .v.pins = (const struct hda_pintbl[]) {
5593                         { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
5594                         { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
5595                         { }
5596                 },
5597                 .chained = true,
5598                 .chain_id = ALC269_FIXUP_HEADSET_MODE
5599         },
5600         [ALC269_FIXUP_DELL2_MIC_NO_PRESENCE] = {
5601                 .type = HDA_FIXUP_PINS,
5602                 .v.pins = (const struct hda_pintbl[]) {
5603                         { 0x16, 0x21014020 }, /* dock line out */
5604                         { 0x19, 0x21a19030 }, /* dock mic */
5605                         { 0x1a, 0x01a1913c }, /* use as headset mic, without its own jack detect */
5606                         { }
5607                 },
5608                 .chained = true,
5609                 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
5610         },
5611         [ALC269_FIXUP_DELL3_MIC_NO_PRESENCE] = {
5612                 .type = HDA_FIXUP_PINS,
5613                 .v.pins = (const struct hda_pintbl[]) {
5614                         { 0x1a, 0x01a1913c }, /* use as headset mic, without its own jack detect */
5615                         { }
5616                 },
5617                 .chained = true,
5618                 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
5619         },
5620         [ALC269_FIXUP_DELL4_MIC_NO_PRESENCE] = {
5621                 .type = HDA_FIXUP_PINS,
5622                 .v.pins = (const struct hda_pintbl[]) {
5623                         { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
5624                         { 0x1b, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
5625                         { }
5626                 },
5627                 .chained = true,
5628                 .chain_id = ALC269_FIXUP_HEADSET_MODE
5629         },
5630         [ALC269_FIXUP_HEADSET_MODE] = {
5631                 .type = HDA_FIXUP_FUNC,
5632                 .v.func = alc_fixup_headset_mode,
5633                 .chained = true,
5634                 .chain_id = ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED
5635         },
5636         [ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC] = {
5637                 .type = HDA_FIXUP_FUNC,
5638                 .v.func = alc_fixup_headset_mode_no_hp_mic,
5639         },
5640         [ALC269_FIXUP_ASPIRE_HEADSET_MIC] = {
5641                 .type = HDA_FIXUP_PINS,
5642                 .v.pins = (const struct hda_pintbl[]) {
5643                         { 0x19, 0x01a1913c }, /* headset mic w/o jack detect */
5644                         { }
5645                 },
5646                 .chained = true,
5647                 .chain_id = ALC269_FIXUP_HEADSET_MODE,
5648         },
5649         [ALC286_FIXUP_SONY_MIC_NO_PRESENCE] = {
5650                 .type = HDA_FIXUP_PINS,
5651                 .v.pins = (const struct hda_pintbl[]) {
5652                         { 0x18, 0x01a1913c }, /* use as headset mic, without its own jack detect */
5653                         { }
5654                 },
5655                 .chained = true,
5656                 .chain_id = ALC269_FIXUP_HEADSET_MIC
5657         },
5658         [ALC269_FIXUP_ASUS_X101_FUNC] = {
5659                 .type = HDA_FIXUP_FUNC,
5660                 .v.func = alc269_fixup_x101_headset_mic,
5661         },
5662         [ALC269_FIXUP_ASUS_X101_VERB] = {
5663                 .type = HDA_FIXUP_VERBS,
5664                 .v.verbs = (const struct hda_verb[]) {
5665                         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5666                         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
5667                         {0x20, AC_VERB_SET_PROC_COEF,  0x0310},
5668                         { }
5669                 },
5670                 .chained = true,
5671                 .chain_id = ALC269_FIXUP_ASUS_X101_FUNC
5672         },
5673         [ALC269_FIXUP_ASUS_X101] = {
5674                 .type = HDA_FIXUP_PINS,
5675                 .v.pins = (const struct hda_pintbl[]) {
5676                         { 0x18, 0x04a1182c }, /* Headset mic */
5677                         { }
5678                 },
5679                 .chained = true,
5680                 .chain_id = ALC269_FIXUP_ASUS_X101_VERB
5681         },
5682         [ALC271_FIXUP_AMIC_MIC2] = {
5683                 .type = HDA_FIXUP_PINS,
5684                 .v.pins = (const struct hda_pintbl[]) {
5685                         { 0x14, 0x99130110 }, /* speaker */
5686                         { 0x19, 0x01a19c20 }, /* mic */
5687                         { 0x1b, 0x99a7012f }, /* int-mic */
5688                         { 0x21, 0x0121401f }, /* HP out */
5689                         { }
5690                 },
5691         },
5692         [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
5693                 .type = HDA_FIXUP_FUNC,
5694                 .v.func = alc271_hp_gate_mic_jack,
5695                 .chained = true,
5696                 .chain_id = ALC271_FIXUP_AMIC_MIC2,
5697         },
5698         [ALC271_FIXUP_HP_GATE_MIC_JACK_E1_572] = {
5699                 .type = HDA_FIXUP_FUNC,
5700                 .v.func = alc269_fixup_limit_int_mic_boost,
5701                 .chained = true,
5702                 .chain_id = ALC271_FIXUP_HP_GATE_MIC_JACK,
5703         },
5704         [ALC269_FIXUP_ACER_AC700] = {
5705                 .type = HDA_FIXUP_PINS,
5706                 .v.pins = (const struct hda_pintbl[]) {
5707                         { 0x12, 0x99a3092f }, /* int-mic */
5708                         { 0x14, 0x99130110 }, /* speaker */
5709                         { 0x18, 0x03a11c20 }, /* mic */
5710                         { 0x1e, 0x0346101e }, /* SPDIF1 */
5711                         { 0x21, 0x0321101f }, /* HP out */
5712                         { }
5713                 },
5714                 .chained = true,
5715                 .chain_id = ALC271_FIXUP_DMIC,
5716         },
5717         [ALC269_FIXUP_LIMIT_INT_MIC_BOOST] = {
5718                 .type = HDA_FIXUP_FUNC,
5719                 .v.func = alc269_fixup_limit_int_mic_boost,
5720                 .chained = true,
5721                 .chain_id = ALC269_FIXUP_THINKPAD_ACPI,
5722         },
5723         [ALC269VB_FIXUP_ASUS_ZENBOOK] = {
5724                 .type = HDA_FIXUP_FUNC,
5725                 .v.func = alc269_fixup_limit_int_mic_boost,
5726                 .chained = true,
5727                 .chain_id = ALC269VB_FIXUP_DMIC,
5728         },
5729         [ALC269VB_FIXUP_ASUS_ZENBOOK_UX31A] = {
5730                 .type = HDA_FIXUP_VERBS,
5731                 .v.verbs = (const struct hda_verb[]) {
5732                         /* class-D output amp +5dB */
5733                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x12 },
5734                         { 0x20, AC_VERB_SET_PROC_COEF, 0x2800 },
5735                         {}
5736                 },
5737                 .chained = true,
5738                 .chain_id = ALC269VB_FIXUP_ASUS_ZENBOOK,
5739         },
5740         [ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED] = {
5741                 .type = HDA_FIXUP_FUNC,
5742                 .v.func = alc269_fixup_limit_int_mic_boost,
5743                 .chained = true,
5744                 .chain_id = ALC269_FIXUP_HP_MUTE_LED_MIC1,
5745         },
5746         [ALC269VB_FIXUP_ORDISSIMO_EVE2] = {
5747                 .type = HDA_FIXUP_PINS,
5748                 .v.pins = (const struct hda_pintbl[]) {
5749                         { 0x12, 0x99a3092f }, /* int-mic */
5750                         { 0x18, 0x03a11d20 }, /* mic */
5751                         { 0x19, 0x411111f0 }, /* Unused bogus pin */
5752                         { }
5753                 },
5754         },
5755         [ALC283_FIXUP_CHROME_BOOK] = {
5756                 .type = HDA_FIXUP_FUNC,
5757                 .v.func = alc283_fixup_chromebook,
5758         },
5759         [ALC283_FIXUP_SENSE_COMBO_JACK] = {
5760                 .type = HDA_FIXUP_FUNC,
5761                 .v.func = alc283_fixup_sense_combo_jack,
5762                 .chained = true,
5763                 .chain_id = ALC283_FIXUP_CHROME_BOOK,
5764         },
5765         [ALC282_FIXUP_ASUS_TX300] = {
5766                 .type = HDA_FIXUP_FUNC,
5767                 .v.func = alc282_fixup_asus_tx300,
5768         },
5769         [ALC283_FIXUP_INT_MIC] = {
5770                 .type = HDA_FIXUP_VERBS,
5771                 .v.verbs = (const struct hda_verb[]) {
5772                         {0x20, AC_VERB_SET_COEF_INDEX, 0x1a},
5773                         {0x20, AC_VERB_SET_PROC_COEF, 0x0011},
5774                         { }
5775                 },
5776                 .chained = true,
5777                 .chain_id = ALC269_FIXUP_LIMIT_INT_MIC_BOOST
5778         },
5779         [ALC290_FIXUP_SUBWOOFER_HSJACK] = {
5780                 .type = HDA_FIXUP_PINS,
5781                 .v.pins = (const struct hda_pintbl[]) {
5782                         { 0x17, 0x90170112 }, /* subwoofer */
5783                         { }
5784                 },
5785                 .chained = true,
5786                 .chain_id = ALC290_FIXUP_MONO_SPEAKERS_HSJACK,
5787         },
5788         [ALC290_FIXUP_SUBWOOFER] = {
5789                 .type = HDA_FIXUP_PINS,
5790                 .v.pins = (const struct hda_pintbl[]) {
5791                         { 0x17, 0x90170112 }, /* subwoofer */
5792                         { }
5793                 },
5794                 .chained = true,
5795                 .chain_id = ALC290_FIXUP_MONO_SPEAKERS,
5796         },
5797         [ALC290_FIXUP_MONO_SPEAKERS] = {
5798                 .type = HDA_FIXUP_FUNC,
5799                 .v.func = alc290_fixup_mono_speakers,
5800         },
5801         [ALC290_FIXUP_MONO_SPEAKERS_HSJACK] = {
5802                 .type = HDA_FIXUP_FUNC,
5803                 .v.func = alc290_fixup_mono_speakers,
5804                 .chained = true,
5805                 .chain_id = ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
5806         },
5807         [ALC269_FIXUP_THINKPAD_ACPI] = {
5808                 .type = HDA_FIXUP_FUNC,
5809                 .v.func = alc_fixup_thinkpad_acpi,
5810                 .chained = true,
5811                 .chain_id = ALC269_FIXUP_SKU_IGNORE,
5812         },
5813         [ALC269_FIXUP_DMIC_THINKPAD_ACPI] = {
5814                 .type = HDA_FIXUP_FUNC,
5815                 .v.func = alc_fixup_inv_dmic,
5816                 .chained = true,
5817                 .chain_id = ALC269_FIXUP_THINKPAD_ACPI,
5818         },
5819         [ALC255_FIXUP_ACER_MIC_NO_PRESENCE] = {
5820                 .type = HDA_FIXUP_PINS,
5821                 .v.pins = (const struct hda_pintbl[]) {
5822                         { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
5823                         { }
5824                 },
5825                 .chained = true,
5826                 .chain_id = ALC255_FIXUP_HEADSET_MODE
5827         },
5828         [ALC255_FIXUP_ASUS_MIC_NO_PRESENCE] = {
5829                 .type = HDA_FIXUP_PINS,
5830                 .v.pins = (const struct hda_pintbl[]) {
5831                         { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
5832                         { }
5833                 },
5834                 .chained = true,
5835                 .chain_id = ALC255_FIXUP_HEADSET_MODE
5836         },
5837         [ALC255_FIXUP_DELL1_MIC_NO_PRESENCE] = {
5838                 .type = HDA_FIXUP_PINS,
5839                 .v.pins = (const struct hda_pintbl[]) {
5840                         { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
5841                         { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
5842                         { }
5843                 },
5844                 .chained = true,
5845                 .chain_id = ALC255_FIXUP_HEADSET_MODE
5846         },
5847         [ALC255_FIXUP_DELL2_MIC_NO_PRESENCE] = {
5848                 .type = HDA_FIXUP_PINS,
5849                 .v.pins = (const struct hda_pintbl[]) {
5850                         { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
5851                         { }
5852                 },
5853                 .chained = true,
5854                 .chain_id = ALC255_FIXUP_HEADSET_MODE_NO_HP_MIC
5855         },
5856         [ALC255_FIXUP_HEADSET_MODE] = {
5857                 .type = HDA_FIXUP_FUNC,
5858                 .v.func = alc_fixup_headset_mode_alc255,
5859                 .chained = true,
5860                 .chain_id = ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED
5861         },
5862         [ALC255_FIXUP_HEADSET_MODE_NO_HP_MIC] = {
5863                 .type = HDA_FIXUP_FUNC,
5864                 .v.func = alc_fixup_headset_mode_alc255_no_hp_mic,
5865         },
5866         [ALC293_FIXUP_DELL1_MIC_NO_PRESENCE] = {
5867                 .type = HDA_FIXUP_PINS,
5868                 .v.pins = (const struct hda_pintbl[]) {
5869                         { 0x18, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
5870                         { 0x1a, 0x01a1913c }, /* use as headset mic, without its own jack detect */
5871                         { }
5872                 },
5873                 .chained = true,
5874                 .chain_id = ALC269_FIXUP_HEADSET_MODE
5875         },
5876         [ALC292_FIXUP_TPT440_DOCK] = {
5877                 .type = HDA_FIXUP_FUNC,
5878                 .v.func = alc_fixup_tpt440_dock,
5879                 .chained = true,
5880                 .chain_id = ALC269_FIXUP_LIMIT_INT_MIC_BOOST
5881         },
5882         [ALC292_FIXUP_TPT440] = {
5883                 .type = HDA_FIXUP_FUNC,
5884                 .v.func = alc_fixup_disable_aamix,
5885                 .chained = true,
5886                 .chain_id = ALC292_FIXUP_TPT440_DOCK,
5887         },
5888         [ALC283_FIXUP_HEADSET_MIC] = {
5889                 .type = HDA_FIXUP_PINS,
5890                 .v.pins = (const struct hda_pintbl[]) {
5891                         { 0x19, 0x04a110f0 },
5892                         { },
5893                 },
5894         },
5895         [ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED] = {
5896                 .type = HDA_FIXUP_FUNC,
5897                 .v.func = alc_fixup_dell_wmi,
5898         },
5899         [ALC282_FIXUP_ASPIRE_V5_PINS] = {
5900                 .type = HDA_FIXUP_PINS,
5901                 .v.pins = (const struct hda_pintbl[]) {
5902                         { 0x12, 0x90a60130 },
5903                         { 0x14, 0x90170110 },
5904                         { 0x17, 0x40000008 },
5905                         { 0x18, 0x411111f0 },
5906                         { 0x19, 0x01a1913c },
5907                         { 0x1a, 0x411111f0 },
5908                         { 0x1b, 0x411111f0 },
5909                         { 0x1d, 0x40f89b2d },
5910                         { 0x1e, 0x411111f0 },
5911                         { 0x21, 0x0321101f },
5912                         { },
5913                 },
5914         },
5915         [ALC280_FIXUP_HP_GPIO4] = {
5916                 .type = HDA_FIXUP_FUNC,
5917                 .v.func = alc280_fixup_hp_gpio4,
5918         },
5919         [ALC286_FIXUP_HP_GPIO_LED] = {
5920                 .type = HDA_FIXUP_FUNC,
5921                 .v.func = alc286_fixup_hp_gpio_led,
5922         },
5923         [ALC280_FIXUP_HP_GPIO2_MIC_HOTKEY] = {
5924                 .type = HDA_FIXUP_FUNC,
5925                 .v.func = alc280_fixup_hp_gpio2_mic_hotkey,
5926         },
5927         [ALC280_FIXUP_HP_DOCK_PINS] = {
5928                 .type = HDA_FIXUP_PINS,
5929                 .v.pins = (const struct hda_pintbl[]) {
5930                         { 0x1b, 0x21011020 }, /* line-out */
5931                         { 0x1a, 0x01a1903c }, /* headset mic */
5932                         { 0x18, 0x2181103f }, /* line-in */
5933                         { },
5934                 },
5935                 .chained = true,
5936                 .chain_id = ALC280_FIXUP_HP_GPIO4
5937         },
5938         [ALC269_FIXUP_HP_DOCK_GPIO_MIC1_LED] = {
5939                 .type = HDA_FIXUP_PINS,
5940                 .v.pins = (const struct hda_pintbl[]) {
5941                         { 0x1b, 0x21011020 }, /* line-out */
5942                         { 0x18, 0x2181103f }, /* line-in */
5943                         { },
5944                 },
5945                 .chained = true,
5946                 .chain_id = ALC269_FIXUP_HP_GPIO_MIC1_LED
5947         },
5948         [ALC280_FIXUP_HP_9480M] = {
5949                 .type = HDA_FIXUP_FUNC,
5950                 .v.func = alc280_fixup_hp_9480m,
5951         },
5952         [ALC288_FIXUP_DELL_HEADSET_MODE] = {
5953                 .type = HDA_FIXUP_FUNC,
5954                 .v.func = alc_fixup_headset_mode_dell_alc288,
5955                 .chained = true,
5956                 .chain_id = ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED
5957         },
5958         [ALC288_FIXUP_DELL1_MIC_NO_PRESENCE] = {
5959                 .type = HDA_FIXUP_PINS,
5960                 .v.pins = (const struct hda_pintbl[]) {
5961                         { 0x18, 0x01a1913c }, /* use as headset mic, without its own jack detect */
5962                         { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
5963                         { }
5964                 },
5965                 .chained = true,
5966                 .chain_id = ALC288_FIXUP_DELL_HEADSET_MODE
5967         },
5968         [ALC288_FIXUP_DELL_XPS_13_GPIO6] = {
5969                 .type = HDA_FIXUP_VERBS,
5970                 .v.verbs = (const struct hda_verb[]) {
5971                         {0x01, AC_VERB_SET_GPIO_MASK, 0x40},
5972                         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x40},
5973                         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5974                         { }
5975                 },
5976                 .chained = true,
5977                 .chain_id = ALC288_FIXUP_DELL1_MIC_NO_PRESENCE
5978         },
5979         [ALC288_FIXUP_DISABLE_AAMIX] = {
5980                 .type = HDA_FIXUP_FUNC,
5981                 .v.func = alc_fixup_disable_aamix,
5982                 .chained = true,
5983                 .chain_id = ALC288_FIXUP_DELL_XPS_13_GPIO6
5984         },
5985         [ALC288_FIXUP_DELL_XPS_13] = {
5986                 .type = HDA_FIXUP_FUNC,
5987                 .v.func = alc_fixup_dell_xps13,
5988                 .chained = true,
5989                 .chain_id = ALC288_FIXUP_DISABLE_AAMIX
5990         },
5991         [ALC292_FIXUP_DISABLE_AAMIX] = {
5992                 .type = HDA_FIXUP_FUNC,
5993                 .v.func = alc_fixup_disable_aamix,
5994                 .chained = true,
5995                 .chain_id = ALC269_FIXUP_DELL2_MIC_NO_PRESENCE
5996         },
5997         [ALC293_FIXUP_DISABLE_AAMIX_MULTIJACK] = {
5998                 .type = HDA_FIXUP_FUNC,
5999                 .v.func = alc_fixup_disable_aamix,
6000                 .chained = true,
6001                 .chain_id = ALC293_FIXUP_DELL1_MIC_NO_PRESENCE
6002         },
6003         [ALC292_FIXUP_DELL_E7X] = {
6004                 .type = HDA_FIXUP_FUNC,
6005                 .v.func = alc_fixup_dell_xps13,
6006                 .chained = true,
6007                 .chain_id = ALC292_FIXUP_DISABLE_AAMIX
6008         },
6009         [ALC298_FIXUP_DELL1_MIC_NO_PRESENCE] = {
6010                 .type = HDA_FIXUP_PINS,
6011                 .v.pins = (const struct hda_pintbl[]) {
6012                         { 0x18, 0x01a1913c }, /* use as headset mic, without its own jack detect */
6013                         { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
6014                         { }
6015                 },
6016                 .chained = true,
6017                 .chain_id = ALC269_FIXUP_HEADSET_MODE
6018         },
6019         [ALC298_FIXUP_DELL_AIO_MIC_NO_PRESENCE] = {
6020                 .type = HDA_FIXUP_PINS,
6021                 .v.pins = (const struct hda_pintbl[]) {
6022                         { 0x18, 0x01a1913c }, /* use as headset mic, without its own jack detect */
6023                         { }
6024                 },
6025                 .chained = true,
6026                 .chain_id = ALC269_FIXUP_HEADSET_MODE
6027         },
6028         [ALC275_FIXUP_DELL_XPS] = {
6029                 .type = HDA_FIXUP_VERBS,
6030                 .v.verbs = (const struct hda_verb[]) {
6031                         /* Enables internal speaker */
6032                         {0x20, AC_VERB_SET_COEF_INDEX, 0x1f},
6033                         {0x20, AC_VERB_SET_PROC_COEF, 0x00c0},
6034                         {0x20, AC_VERB_SET_COEF_INDEX, 0x30},
6035                         {0x20, AC_VERB_SET_PROC_COEF, 0x00b1},
6036                         {}
6037                 }
6038         },
6039         [ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE] = {
6040                 .type = HDA_FIXUP_VERBS,
6041                 .v.verbs = (const struct hda_verb[]) {
6042                         /* Disable pass-through path for FRONT 14h */
6043                         {0x20, AC_VERB_SET_COEF_INDEX, 0x36},
6044                         {0x20, AC_VERB_SET_PROC_COEF, 0x1737},
6045                         {}
6046                 },
6047                 .chained = true,
6048                 .chain_id = ALC255_FIXUP_DELL1_MIC_NO_PRESENCE
6049         },
6050         [ALC293_FIXUP_LENOVO_SPK_NOISE] = {
6051                 .type = HDA_FIXUP_FUNC,
6052                 .v.func = alc_fixup_disable_aamix,
6053                 .chained = true,
6054                 .chain_id = ALC269_FIXUP_THINKPAD_ACPI
6055         },
6056         [ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY] = {
6057                 .type = HDA_FIXUP_FUNC,
6058                 .v.func = alc233_fixup_lenovo_line2_mic_hotkey,
6059         },
6060         [ALC255_FIXUP_DELL_SPK_NOISE] = {
6061                 .type = HDA_FIXUP_FUNC,
6062                 .v.func = alc_fixup_disable_aamix,
6063                 .chained = true,
6064                 .chain_id = ALC255_FIXUP_DELL1_MIC_NO_PRESENCE
6065         },
6066         [ALC225_FIXUP_DELL1_MIC_NO_PRESENCE] = {
6067                 .type = HDA_FIXUP_VERBS,
6068                 .v.verbs = (const struct hda_verb[]) {
6069                         /* Disable pass-through path for FRONT 14h */
6070                         { 0x20, AC_VERB_SET_COEF_INDEX, 0x36 },
6071                         { 0x20, AC_VERB_SET_PROC_COEF, 0x57d7 },
6072                         {}
6073                 },
6074                 .chained = true,
6075                 .chain_id = ALC269_FIXUP_DELL1_MIC_NO_PRESENCE
6076         },
6077         [ALC280_FIXUP_HP_HEADSET_MIC] = {
6078                 .type = HDA_FIXUP_FUNC,
6079                 .v.func = alc_fixup_disable_aamix,
6080                 .chained = true,
6081                 .chain_id = ALC269_FIXUP_HEADSET_MIC,
6082         },
6083         [ALC221_FIXUP_HP_FRONT_MIC] = {
6084                 .type = HDA_FIXUP_PINS,
6085                 .v.pins = (const struct hda_pintbl[]) {
6086                         { 0x19, 0x02a19020 }, /* Front Mic */
6087                         { }
6088                 },
6089         },
6090         [ALC292_FIXUP_TPT460] = {
6091                 .type = HDA_FIXUP_FUNC,
6092                 .v.func = alc_fixup_tpt440_dock,
6093                 .chained = true,
6094                 .chain_id = ALC293_FIXUP_LENOVO_SPK_NOISE,
6095         },
6096         [ALC298_FIXUP_SPK_VOLUME] = {
6097                 .type = HDA_FIXUP_FUNC,
6098                 .v.func = alc298_fixup_speaker_volume,
6099                 .chained = true,
6100                 .chain_id = ALC298_FIXUP_DELL_AIO_MIC_NO_PRESENCE,
6101         },
6102         [ALC295_FIXUP_DISABLE_DAC3] = {
6103                 .type = HDA_FIXUP_FUNC,
6104                 .v.func = alc295_fixup_disable_dac3,
6105         },
6106         [ALC256_FIXUP_DELL_INSPIRON_7559_SUBWOOFER] = {
6107                 .type = HDA_FIXUP_PINS,
6108                 .v.pins = (const struct hda_pintbl[]) {
6109                         { 0x1b, 0x90170151 },
6110                         { }
6111                 },
6112                 .chained = true,
6113                 .chain_id = ALC255_FIXUP_DELL1_MIC_NO_PRESENCE
6114         },
6115         [ALC269_FIXUP_ATIV_BOOK_8] = {
6116                 .type = HDA_FIXUP_FUNC,
6117                 .v.func = alc_fixup_auto_mute_via_amp,
6118                 .chained = true,
6119                 .chain_id = ALC269_FIXUP_NO_SHUTUP
6120         },
6121         [ALC221_FIXUP_HP_MIC_NO_PRESENCE] = {
6122                 .type = HDA_FIXUP_PINS,
6123                 .v.pins = (const struct hda_pintbl[]) {
6124                         { 0x18, 0x01a1913c }, /* use as headset mic, without its own jack detect */
6125                         { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
6126                         { }
6127                 },
6128                 .chained = true,
6129                 .chain_id = ALC269_FIXUP_HEADSET_MODE
6130         },
6131         [ALC256_FIXUP_ASUS_HEADSET_MODE] = {
6132                 .type = HDA_FIXUP_FUNC,
6133                 .v.func = alc_fixup_headset_mode,
6134         },
6135         [ALC256_FIXUP_ASUS_MIC] = {
6136                 .type = HDA_FIXUP_PINS,
6137                 .v.pins = (const struct hda_pintbl[]) {
6138                         { 0x13, 0x90a60160 }, /* use as internal mic */
6139                         { 0x19, 0x04a11120 }, /* use as headset mic, without its own jack detect */
6140                         { }
6141                 },
6142                 .chained = true,
6143                 .chain_id = ALC256_FIXUP_ASUS_HEADSET_MODE
6144         },
6145         [ALC256_FIXUP_ASUS_AIO_GPIO2] = {
6146                 .type = HDA_FIXUP_VERBS,
6147                 .v.verbs = (const struct hda_verb[]) {
6148                         /* Set up GPIO2 for the speaker amp */
6149                         { 0x01, AC_VERB_SET_GPIO_MASK, 0x04 },
6150                         { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04 },
6151                         { 0x01, AC_VERB_SET_GPIO_DATA, 0x04 },
6152                         {}
6153                 },
6154         },
6155         [ALC233_FIXUP_ASUS_MIC_NO_PRESENCE] = {
6156                 .type = HDA_FIXUP_PINS,
6157                 .v.pins = (const struct hda_pintbl[]) {
6158                         { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
6159                         { }
6160                 },
6161                 .chained = true,
6162                 .chain_id = ALC269_FIXUP_HEADSET_MIC
6163         },
6164         [ALC233_FIXUP_EAPD_COEF_AND_MIC_NO_PRESENCE] = {
6165                 .type = HDA_FIXUP_VERBS,
6166                 .v.verbs = (const struct hda_verb[]) {
6167                         /* Enables internal speaker */
6168                         {0x20, AC_VERB_SET_COEF_INDEX, 0x40},
6169                         {0x20, AC_VERB_SET_PROC_COEF, 0x8800},
6170                         {}
6171                 },
6172                 .chained = true,
6173                 .chain_id = ALC233_FIXUP_ASUS_MIC_NO_PRESENCE
6174         },
6175         [ALC233_FIXUP_LENOVO_MULTI_CODECS] = {
6176                 .type = HDA_FIXUP_FUNC,
6177                 .v.func = alc233_alc662_fixup_lenovo_dual_codecs,
6178         },
6179         [ALC294_FIXUP_LENOVO_MIC_LOCATION] = {
6180                 .type = HDA_FIXUP_PINS,
6181                 .v.pins = (const struct hda_pintbl[]) {
6182                         /* Change the mic location from front to right, otherwise there are
6183                            two front mics with the same name, pulseaudio can't handle them.
6184                            This is just a temporary workaround, after applying this fixup,
6185                            there will be one "Front Mic" and one "Mic" in this machine.
6186                          */
6187                         { 0x1a, 0x04a19040 },
6188                         { }
6189                 },
6190         },
6191         [ALC225_FIXUP_DELL_WYSE_MIC_NO_PRESENCE] = {
6192                 .type = HDA_FIXUP_PINS,
6193                 .v.pins = (const struct hda_pintbl[]) {
6194                         { 0x16, 0x0101102f }, /* Rear Headset HP */
6195                         { 0x19, 0x02a1913c }, /* use as Front headset mic, without its own jack detect */
6196                         { 0x1a, 0x01a19030 }, /* Rear Headset MIC */
6197                         { 0x1b, 0x02011020 },
6198                         { }
6199                 },
6200                 .chained = true,
6201                 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
6202         },
6203         [ALC700_FIXUP_INTEL_REFERENCE] = {
6204                 .type = HDA_FIXUP_VERBS,
6205                 .v.verbs = (const struct hda_verb[]) {
6206                         /* Enables internal speaker */
6207                         {0x20, AC_VERB_SET_COEF_INDEX, 0x45},
6208                         {0x20, AC_VERB_SET_PROC_COEF, 0x5289},
6209                         {0x20, AC_VERB_SET_COEF_INDEX, 0x4A},
6210                         {0x20, AC_VERB_SET_PROC_COEF, 0x001b},
6211                         {0x58, AC_VERB_SET_COEF_INDEX, 0x00},
6212                         {0x58, AC_VERB_SET_PROC_COEF, 0x3888},
6213                         {0x20, AC_VERB_SET_COEF_INDEX, 0x6f},
6214                         {0x20, AC_VERB_SET_PROC_COEF, 0x2c0b},
6215                         {}
6216                 }
6217         },
6218         [ALC274_FIXUP_DELL_BIND_DACS] = {
6219                 .type = HDA_FIXUP_FUNC,
6220                 .v.func = alc274_fixup_bind_dacs,
6221                 .chained = true,
6222                 .chain_id = ALC269_FIXUP_DELL1_MIC_NO_PRESENCE
6223         },
6224         [ALC274_FIXUP_DELL_AIO_LINEOUT_VERB] = {
6225                 .type = HDA_FIXUP_PINS,
6226                 .v.pins = (const struct hda_pintbl[]) {
6227                         { 0x1b, 0x0401102f },
6228                         { }
6229                 },
6230                 .chained = true,
6231                 .chain_id = ALC274_FIXUP_DELL_BIND_DACS
6232         },
6233         [ALC298_FIXUP_TPT470_DOCK] = {
6234                 .type = HDA_FIXUP_FUNC,
6235                 .v.func = alc_fixup_tpt470_dock,
6236                 .chained = true,
6237                 .chain_id = ALC293_FIXUP_LENOVO_SPK_NOISE
6238         },
6239         [ALC255_FIXUP_DUMMY_LINEOUT_VERB] = {
6240                 .type = HDA_FIXUP_PINS,
6241                 .v.pins = (const struct hda_pintbl[]) {
6242                         { 0x14, 0x0201101f },
6243                         { }
6244                 },
6245                 .chained = true,
6246                 .chain_id = ALC255_FIXUP_DELL1_MIC_NO_PRESENCE
6247         },
6248         [ALC255_FIXUP_DELL_HEADSET_MIC] = {
6249                 .type = HDA_FIXUP_PINS,
6250                 .v.pins = (const struct hda_pintbl[]) {
6251                         { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
6252                         { }
6253                 },
6254                 .chained = true,
6255                 .chain_id = ALC269_FIXUP_HEADSET_MIC
6256         },
6257 };
6258
6259 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6260         SND_PCI_QUIRK(0x1025, 0x0283, "Acer TravelMate 8371", ALC269_FIXUP_INV_DMIC),
6261         SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6262         SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
6263         SND_PCI_QUIRK(0x1025, 0x047c, "Acer AC700", ALC269_FIXUP_ACER_AC700),
6264         SND_PCI_QUIRK(0x1025, 0x072d, "Acer Aspire V5-571G", ALC269_FIXUP_ASPIRE_HEADSET_MIC),
6265         SND_PCI_QUIRK(0x1025, 0x080d, "Acer Aspire V5-122P", ALC269_FIXUP_ASPIRE_HEADSET_MIC),
6266         SND_PCI_QUIRK(0x1025, 0x0740, "Acer AO725", ALC271_FIXUP_HP_GATE_MIC_JACK),
6267         SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
6268         SND_PCI_QUIRK(0x1025, 0x0762, "Acer Aspire E1-472", ALC271_FIXUP_HP_GATE_MIC_JACK_E1_572),
6269         SND_PCI_QUIRK(0x1025, 0x0775, "Acer Aspire E1-572", ALC271_FIXUP_HP_GATE_MIC_JACK_E1_572),
6270         SND_PCI_QUIRK(0x1025, 0x079b, "Acer Aspire V5-573G", ALC282_FIXUP_ASPIRE_V5_PINS),
6271         SND_PCI_QUIRK(0x1025, 0x106d, "Acer Cloudbook 14", ALC283_FIXUP_CHROME_BOOK),
6272         SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6273         SND_PCI_QUIRK(0x1028, 0x054b, "Dell XPS one 2710", ALC275_FIXUP_DELL_XPS),
6274         SND_PCI_QUIRK(0x1028, 0x05bd, "Dell Latitude E6440", ALC292_FIXUP_DELL_E7X),
6275         SND_PCI_QUIRK(0x1028, 0x05be, "Dell Latitude E6540", ALC292_FIXUP_DELL_E7X),
6276         SND_PCI_QUIRK(0x1028, 0x05ca, "Dell Latitude E7240", ALC292_FIXUP_DELL_E7X),
6277         SND_PCI_QUIRK(0x1028, 0x05cb, "Dell Latitude E7440", ALC292_FIXUP_DELL_E7X),
6278         SND_PCI_QUIRK(0x1028, 0x05da, "Dell Vostro 5460", ALC290_FIXUP_SUBWOOFER),
6279         SND_PCI_QUIRK(0x1028, 0x05f4, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
6280         SND_PCI_QUIRK(0x1028, 0x05f5, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
6281         SND_PCI_QUIRK(0x1028, 0x05f6, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
6282         SND_PCI_QUIRK(0x1028, 0x0615, "Dell Vostro 5470", ALC290_FIXUP_SUBWOOFER_HSJACK),
6283         SND_PCI_QUIRK(0x1028, 0x0616, "Dell Vostro 5470", ALC290_FIXUP_SUBWOOFER_HSJACK),
6284         SND_PCI_QUIRK(0x1028, 0x062c, "Dell Latitude E5550", ALC292_FIXUP_DELL_E7X),
6285         SND_PCI_QUIRK(0x1028, 0x062e, "Dell Latitude E7450", ALC292_FIXUP_DELL_E7X),
6286         SND_PCI_QUIRK(0x1028, 0x0638, "Dell Inspiron 5439", ALC290_FIXUP_MONO_SPEAKERS_HSJACK),
6287         SND_PCI_QUIRK(0x1028, 0x064a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
6288         SND_PCI_QUIRK(0x1028, 0x064b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
6289         SND_PCI_QUIRK(0x1028, 0x0665, "Dell XPS 13", ALC288_FIXUP_DELL_XPS_13),
6290         SND_PCI_QUIRK(0x1028, 0x0669, "Dell Optiplex 9020m", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
6291         SND_PCI_QUIRK(0x1028, 0x069a, "Dell Vostro 5480", ALC290_FIXUP_SUBWOOFER_HSJACK),
6292         SND_PCI_QUIRK(0x1028, 0x06c7, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
6293         SND_PCI_QUIRK(0x1028, 0x06d9, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
6294         SND_PCI_QUIRK(0x1028, 0x06da, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
6295         SND_PCI_QUIRK(0x1028, 0x06db, "Dell", ALC293_FIXUP_DISABLE_AAMIX_MULTIJACK),
6296         SND_PCI_QUIRK(0x1028, 0x06dd, "Dell", ALC293_FIXUP_DISABLE_AAMIX_MULTIJACK),
6297         SND_PCI_QUIRK(0x1028, 0x06de, "Dell", ALC293_FIXUP_DISABLE_AAMIX_MULTIJACK),
6298         SND_PCI_QUIRK(0x1028, 0x06df, "Dell", ALC293_FIXUP_DISABLE_AAMIX_MULTIJACK),
6299         SND_PCI_QUIRK(0x1028, 0x06e0, "Dell", ALC293_FIXUP_DISABLE_AAMIX_MULTIJACK),
6300         SND_PCI_QUIRK(0x1028, 0x0704, "Dell XPS 13 9350", ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE),
6301         SND_PCI_QUIRK(0x1028, 0x0706, "Dell Inspiron 7559", ALC256_FIXUP_DELL_INSPIRON_7559_SUBWOOFER),
6302         SND_PCI_QUIRK(0x1028, 0x0725, "Dell Inspiron 3162", ALC255_FIXUP_DELL_SPK_NOISE),
6303         SND_PCI_QUIRK(0x1028, 0x075b, "Dell XPS 13 9360", ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE),
6304         SND_PCI_QUIRK(0x1028, 0x075c, "Dell XPS 27 7760", ALC298_FIXUP_SPK_VOLUME),
6305         SND_PCI_QUIRK(0x1028, 0x075d, "Dell AIO", ALC298_FIXUP_SPK_VOLUME),
6306         SND_PCI_QUIRK(0x1028, 0x07b0, "Dell Precision 7520", ALC295_FIXUP_DISABLE_DAC3),
6307         SND_PCI_QUIRK(0x1028, 0x0798, "Dell Inspiron 17 7000 Gaming", ALC256_FIXUP_DELL_INSPIRON_7559_SUBWOOFER),
6308         SND_PCI_QUIRK(0x1028, 0x080c, "Dell WYSE", ALC225_FIXUP_DELL_WYSE_MIC_NO_PRESENCE),
6309         SND_PCI_QUIRK(0x1028, 0x082a, "Dell XPS 13 9360", ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE),
6310         SND_PCI_QUIRK(0x1028, 0x084b, "Dell", ALC274_FIXUP_DELL_AIO_LINEOUT_VERB),
6311         SND_PCI_QUIRK(0x1028, 0x084e, "Dell", ALC274_FIXUP_DELL_AIO_LINEOUT_VERB),
6312         SND_PCI_QUIRK(0x1028, 0x0871, "Dell Precision 3630", ALC255_FIXUP_DELL_HEADSET_MIC),
6313         SND_PCI_QUIRK(0x1028, 0x0872, "Dell Precision 3630", ALC255_FIXUP_DELL_HEADSET_MIC),
6314         SND_PCI_QUIRK(0x1028, 0x0873, "Dell Precision 3930", ALC255_FIXUP_DUMMY_LINEOUT_VERB),
6315         SND_PCI_QUIRK(0x1028, 0x0935, "Dell", ALC274_FIXUP_DELL_AIO_LINEOUT_VERB),
6316         SND_PCI_QUIRK(0x1028, 0x164a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
6317         SND_PCI_QUIRK(0x1028, 0x164b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
6318         SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
6319         SND_PCI_QUIRK(0x103c, 0x18e6, "HP", ALC269_FIXUP_HP_GPIO_LED),
6320         SND_PCI_QUIRK(0x103c, 0x218b, "HP", ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED),
6321         SND_PCI_QUIRK(0x103c, 0x225f, "HP", ALC280_FIXUP_HP_GPIO2_MIC_HOTKEY),
6322         /* ALC282 */
6323         SND_PCI_QUIRK(0x103c, 0x21f9, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6324         SND_PCI_QUIRK(0x103c, 0x2210, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6325         SND_PCI_QUIRK(0x103c, 0x2214, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6326         SND_PCI_QUIRK(0x103c, 0x2236, "HP", ALC269_FIXUP_HP_LINE1_MIC1_LED),
6327         SND_PCI_QUIRK(0x103c, 0x2237, "HP", ALC269_FIXUP_HP_LINE1_MIC1_LED),
6328         SND_PCI_QUIRK(0x103c, 0x2238, "HP", ALC269_FIXUP_HP_LINE1_MIC1_LED),
6329         SND_PCI_QUIRK(0x103c, 0x2239, "HP", ALC269_FIXUP_HP_LINE1_MIC1_LED),
6330         SND_PCI_QUIRK(0x103c, 0x224b, "HP", ALC269_FIXUP_HP_LINE1_MIC1_LED),
6331         SND_PCI_QUIRK(0x103c, 0x2268, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6332         SND_PCI_QUIRK(0x103c, 0x226a, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6333         SND_PCI_QUIRK(0x103c, 0x226b, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6334         SND_PCI_QUIRK(0x103c, 0x226e, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6335         SND_PCI_QUIRK(0x103c, 0x2271, "HP", ALC286_FIXUP_HP_GPIO_LED),
6336         SND_PCI_QUIRK(0x103c, 0x2272, "HP", ALC280_FIXUP_HP_DOCK_PINS),
6337         SND_PCI_QUIRK(0x103c, 0x2273, "HP", ALC280_FIXUP_HP_DOCK_PINS),
6338         SND_PCI_QUIRK(0x103c, 0x229e, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6339         SND_PCI_QUIRK(0x103c, 0x22b2, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6340         SND_PCI_QUIRK(0x103c, 0x22b7, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6341         SND_PCI_QUIRK(0x103c, 0x22bf, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6342         SND_PCI_QUIRK(0x103c, 0x22cf, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6343         SND_PCI_QUIRK(0x103c, 0x22db, "HP", ALC280_FIXUP_HP_9480M),
6344         SND_PCI_QUIRK(0x103c, 0x22dc, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
6345         SND_PCI_QUIRK(0x103c, 0x22fb, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
6346         /* ALC290 */
6347         SND_PCI_QUIRK(0x103c, 0x221b, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
6348         SND_PCI_QUIRK(0x103c, 0x2221, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
6349         SND_PCI_QUIRK(0x103c, 0x2225, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
6350         SND_PCI_QUIRK(0x103c, 0x2253, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
6351         SND_PCI_QUIRK(0x103c, 0x2254, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
6352         SND_PCI_QUIRK(0x103c, 0x2255, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
6353         SND_PCI_QUIRK(0x103c, 0x2256, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
6354         SND_PCI_QUIRK(0x103c, 0x2257, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
6355         SND_PCI_QUIRK(0x103c, 0x2259, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
6356         SND_PCI_QUIRK(0x103c, 0x225a, "HP", ALC269_FIXUP_HP_DOCK_GPIO_MIC1_LED),
6357         SND_PCI_QUIRK(0x103c, 0x2260, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6358         SND_PCI_QUIRK(0x103c, 0x2263, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6359         SND_PCI_QUIRK(0x103c, 0x2264, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6360         SND_PCI_QUIRK(0x103c, 0x2265, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6361         SND_PCI_QUIRK(0x103c, 0x2272, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
6362         SND_PCI_QUIRK(0x103c, 0x2273, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
6363         SND_PCI_QUIRK(0x103c, 0x2278, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
6364         SND_PCI_QUIRK(0x103c, 0x227f, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6365         SND_PCI_QUIRK(0x103c, 0x2282, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6366         SND_PCI_QUIRK(0x103c, 0x228b, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6367         SND_PCI_QUIRK(0x103c, 0x228e, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6368         SND_PCI_QUIRK(0x103c, 0x22c5, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6369         SND_PCI_QUIRK(0x103c, 0x22c7, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6370         SND_PCI_QUIRK(0x103c, 0x22c8, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6371         SND_PCI_QUIRK(0x103c, 0x22c4, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6372         SND_PCI_QUIRK(0x103c, 0x2334, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6373         SND_PCI_QUIRK(0x103c, 0x2335, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6374         SND_PCI_QUIRK(0x103c, 0x2336, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6375         SND_PCI_QUIRK(0x103c, 0x2337, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6376         SND_PCI_QUIRK(0x103c, 0x221c, "HP EliteBook 755 G2", ALC280_FIXUP_HP_HEADSET_MIC),
6377         SND_PCI_QUIRK(0x103c, 0x8256, "HP", ALC221_FIXUP_HP_FRONT_MIC),
6378         SND_PCI_QUIRK(0x103c, 0x82bf, "HP", ALC221_FIXUP_HP_MIC_NO_PRESENCE),
6379         SND_PCI_QUIRK(0x103c, 0x82c0, "HP", ALC221_FIXUP_HP_MIC_NO_PRESENCE),
6380         SND_PCI_QUIRK(0x1043, 0x103e, "ASUS X540SA", ALC256_FIXUP_ASUS_MIC),
6381         SND_PCI_QUIRK(0x1043, 0x103f, "ASUS TX300", ALC282_FIXUP_ASUS_TX300),
6382         SND_PCI_QUIRK(0x1043, 0x106d, "Asus K53BE", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
6383         SND_PCI_QUIRK(0x1043, 0x10c0, "ASUS X540SA", ALC256_FIXUP_ASUS_MIC),
6384         SND_PCI_QUIRK(0x1043, 0x10d0, "ASUS X540LA/X540LJ", ALC255_FIXUP_ASUS_MIC_NO_PRESENCE),
6385         SND_PCI_QUIRK(0x1043, 0x115d, "Asus 1015E", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
6386         SND_PCI_QUIRK(0x1043, 0x11c0, "ASUS X556UR", ALC255_FIXUP_ASUS_MIC_NO_PRESENCE),
6387         SND_PCI_QUIRK(0x1043, 0x1290, "ASUS X441SA", ALC233_FIXUP_EAPD_COEF_AND_MIC_NO_PRESENCE),
6388         SND_PCI_QUIRK(0x1043, 0x12a0, "ASUS X441UV", ALC233_FIXUP_EAPD_COEF_AND_MIC_NO_PRESENCE),
6389         SND_PCI_QUIRK(0x1043, 0x12f0, "ASUS X541UV", ALC256_FIXUP_ASUS_MIC),
6390         SND_PCI_QUIRK(0x1043, 0x12e0, "ASUS X541SA", ALC256_FIXUP_ASUS_MIC),
6391         SND_PCI_QUIRK(0x1043, 0x13b0, "ASUS Z550SA", ALC256_FIXUP_ASUS_MIC),
6392         SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_ASUS_ZENBOOK),
6393         SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_ASUS_ZENBOOK_UX31A),
6394         SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6395         SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
6396         SND_PCI_QUIRK(0x1043, 0x1a30, "ASUS X705UD", ALC256_FIXUP_ASUS_MIC),
6397         SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
6398         SND_PCI_QUIRK(0x1043, 0x1bbd, "ASUS Z550MA", ALC255_FIXUP_ASUS_MIC_NO_PRESENCE),
6399         SND_PCI_QUIRK(0x1043, 0x1c23, "Asus X55U", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
6400         SND_PCI_QUIRK(0x1043, 0x1ccd, "ASUS X555UB", ALC256_FIXUP_ASUS_MIC),
6401         SND_PCI_QUIRK(0x1043, 0x3030, "ASUS ZN270IE", ALC256_FIXUP_ASUS_AIO_GPIO2),
6402         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6403         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6404         SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6405         SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6406         SND_PCI_QUIRK(0x1043, 0x8516, "ASUS X101CH", ALC269_FIXUP_ASUS_X101),
6407         SND_PCI_QUIRK(0x104d, 0x90b5, "Sony VAIO Pro 11", ALC286_FIXUP_SONY_MIC_NO_PRESENCE),
6408         SND_PCI_QUIRK(0x104d, 0x90b6, "Sony VAIO Pro 13", ALC286_FIXUP_SONY_MIC_NO_PRESENCE),
6409         SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6410         SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6411         SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6412         SND_PCI_QUIRK(0x104d, 0x9099, "Sony VAIO S13", ALC275_FIXUP_SONY_DISABLE_AAMIX),
6413         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
6414         SND_PCI_QUIRK(0x10cf, 0x159f, "Lifebook E780", ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT),
6415         SND_PCI_QUIRK(0x10cf, 0x15dc, "Lifebook T731", ALC269_FIXUP_LIFEBOOK_HP_PIN),
6416         SND_PCI_QUIRK(0x10cf, 0x1757, "Lifebook E752", ALC269_FIXUP_LIFEBOOK_HP_PIN),
6417         SND_PCI_QUIRK(0x10cf, 0x1629, "Lifebook U7x7", ALC255_FIXUP_LIFEBOOK_U7x7_HEADSET_MIC),
6418         SND_PCI_QUIRK(0x10cf, 0x1845, "Lifebook U904", ALC269_FIXUP_LIFEBOOK_EXTMIC),
6419         SND_PCI_QUIRK(0x10ec, 0x10f2, "Intel Reference board", ALC700_FIXUP_INTEL_REFERENCE),
6420         SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-SZ6", ALC269_FIXUP_HEADSET_MODE),
6421         SND_PCI_QUIRK(0x144d, 0xc109, "Samsung Ativ book 9 (NP900X3G)", ALC269_FIXUP_INV_DMIC),
6422         SND_PCI_QUIRK(0x144d, 0xc740, "Samsung Ativ book 8 (NP870Z5G)", ALC269_FIXUP_ATIV_BOOK_8),
6423         SND_PCI_QUIRK(0x1458, 0xfa53, "Gigabyte BXBT-2807", ALC283_FIXUP_HEADSET_MIC),
6424         SND_PCI_QUIRK(0x1462, 0xb120, "MSI Cubi MS-B120", ALC283_FIXUP_HEADSET_MIC),
6425         SND_PCI_QUIRK(0x1462, 0xb171, "Cubi N 8GL (MS-B171)", ALC283_FIXUP_HEADSET_MIC),
6426         SND_PCI_QUIRK(0x17aa, 0x1036, "Lenovo P520", ALC233_FIXUP_LENOVO_MULTI_CODECS),
6427         SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6428         SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6429         SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6430         SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6431         SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
6432         SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
6433         SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
6434         SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
6435         SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
6436         SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
6437         SND_PCI_QUIRK(0x17aa, 0x2208, "Thinkpad T431s", ALC269_FIXUP_LENOVO_DOCK),
6438         SND_PCI_QUIRK(0x17aa, 0x220c, "Thinkpad T440s", ALC292_FIXUP_TPT440),
6439         SND_PCI_QUIRK(0x17aa, 0x220e, "Thinkpad T440p", ALC292_FIXUP_TPT440_DOCK),
6440         SND_PCI_QUIRK(0x17aa, 0x2210, "Thinkpad T540p", ALC292_FIXUP_TPT440_DOCK),
6441         SND_PCI_QUIRK(0x17aa, 0x2211, "Thinkpad W541", ALC292_FIXUP_TPT440_DOCK),
6442         SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad T440", ALC292_FIXUP_TPT440_DOCK),
6443         SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad X240", ALC292_FIXUP_TPT440_DOCK),
6444         SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
6445         SND_PCI_QUIRK(0x17aa, 0x2218, "Thinkpad X1 Carbon 2nd", ALC292_FIXUP_TPT440_DOCK),
6446         SND_PCI_QUIRK(0x17aa, 0x2223, "ThinkPad T550", ALC292_FIXUP_TPT440_DOCK),
6447         SND_PCI_QUIRK(0x17aa, 0x2226, "ThinkPad X250", ALC292_FIXUP_TPT440_DOCK),
6448         SND_PCI_QUIRK(0x17aa, 0x222d, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6449         SND_PCI_QUIRK(0x17aa, 0x222e, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6450         SND_PCI_QUIRK(0x17aa, 0x2231, "Thinkpad T560", ALC292_FIXUP_TPT460),
6451         SND_PCI_QUIRK(0x17aa, 0x2233, "Thinkpad", ALC292_FIXUP_TPT460),
6452         SND_PCI_QUIRK(0x17aa, 0x2245, "Thinkpad T470", ALC298_FIXUP_TPT470_DOCK),
6453         SND_PCI_QUIRK(0x17aa, 0x2246, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6454         SND_PCI_QUIRK(0x17aa, 0x2247, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6455         SND_PCI_QUIRK(0x17aa, 0x2249, "Thinkpad", ALC292_FIXUP_TPT460),
6456         SND_PCI_QUIRK(0x17aa, 0x224b, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6457         SND_PCI_QUIRK(0x17aa, 0x224c, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6458         SND_PCI_QUIRK(0x17aa, 0x224d, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6459         SND_PCI_QUIRK(0x17aa, 0x225d, "Thinkpad T480", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
6460         SND_PCI_QUIRK(0x17aa, 0x30bb, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
6461         SND_PCI_QUIRK(0x17aa, 0x30e2, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
6462         SND_PCI_QUIRK(0x17aa, 0x310c, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
6463         SND_PCI_QUIRK(0x17aa, 0x312a, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
6464         SND_PCI_QUIRK(0x17aa, 0x312f, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
6465         SND_PCI_QUIRK(0x17aa, 0x313c, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
6466         SND_PCI_QUIRK(0x17aa, 0x3902, "Lenovo E50-80", ALC269_FIXUP_DMIC_THINKPAD_ACPI),
6467         SND_PCI_QUIRK(0x17aa, 0x3977, "IdeaPad S210", ALC283_FIXUP_INT_MIC),
6468         SND_PCI_QUIRK(0x17aa, 0x3978, "IdeaPad Y410P", ALC269_FIXUP_NO_SHUTUP),
6469         SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
6470         SND_PCI_QUIRK(0x17aa, 0x501a, "Thinkpad", ALC283_FIXUP_INT_MIC),
6471         SND_PCI_QUIRK(0x17aa, 0x501e, "Thinkpad L440", ALC292_FIXUP_TPT440_DOCK),
6472         SND_PCI_QUIRK(0x17aa, 0x5026, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
6473         SND_PCI_QUIRK(0x17aa, 0x5034, "Thinkpad T450", ALC292_FIXUP_TPT440_DOCK),
6474         SND_PCI_QUIRK(0x17aa, 0x5036, "Thinkpad T450s", ALC292_FIXUP_TPT440_DOCK),
6475         SND_PCI_QUIRK(0x17aa, 0x503c, "Thinkpad L450", ALC292_FIXUP_TPT440_DOCK),
6476         SND_PCI_QUIRK(0x17aa, 0x504a, "ThinkPad X260", ALC292_FIXUP_TPT440_DOCK),
6477         SND_PCI_QUIRK(0x17aa, 0x504b, "Thinkpad", ALC293_FIXUP_LENOVO_SPK_NOISE),
6478         SND_PCI_QUIRK(0x17aa, 0x5050, "Thinkpad T560p", ALC292_FIXUP_TPT460),
6479         SND_PCI_QUIRK(0x17aa, 0x5051, "Thinkpad L460", ALC292_FIXUP_TPT460),
6480         SND_PCI_QUIRK(0x17aa, 0x5053, "Thinkpad T460", ALC292_FIXUP_TPT460),
6481         SND_PCI_QUIRK(0x17aa, 0x505d, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6482         SND_PCI_QUIRK(0x17aa, 0x505f, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6483         SND_PCI_QUIRK(0x17aa, 0x5062, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6484         SND_PCI_QUIRK(0x17aa, 0x5109, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
6485         SND_PCI_QUIRK(0x17aa, 0x511e, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6486         SND_PCI_QUIRK(0x17aa, 0x511f, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6487         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
6488         SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
6489         SND_PCI_QUIRK(0x1b7d, 0xa831, "Ordissimo EVE2 ", ALC269VB_FIXUP_ORDISSIMO_EVE2), /* Also known as Malata PC-B1303 */
6490
6491 #if 0
6492         /* Below is a quirk table taken from the old code.
6493          * Basically the device should work as is without the fixup table.
6494          * If BIOS doesn't give a proper info, enable the corresponding
6495          * fixup entry.
6496          */
6497         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6498                       ALC269_FIXUP_AMIC),
6499         SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
6500         SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6501         SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6502         SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6503         SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6504         SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6505         SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6506         SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6507         SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6508         SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6509         SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6510         SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6511         SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6512         SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6513         SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6514         SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6515         SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6516         SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6517         SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6518         SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6519         SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6520         SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6521         SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6522         SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6523         SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6524         SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6525         SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6526         SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6527         SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6528         SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6529         SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6530         SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6531         SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6532         SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6533         SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6534         SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6535         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6536         SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6537         SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6538 #endif
6539         {}
6540 };
6541
6542 static const struct snd_pci_quirk alc269_fixup_vendor_tbl[] = {
6543         SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
6544         SND_PCI_QUIRK_VENDOR(0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED),
6545         SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6546         SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad", ALC269_FIXUP_THINKPAD_ACPI),
6547         {}
6548 };
6549
6550 static const struct hda_model_fixup alc269_fixup_models[] = {
6551         {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6552         {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
6553         {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6554         {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6555         {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
6556         {.id = ALC269_FIXUP_HEADSET_MIC, .name = "headset-mic"},
6557         {.id = ALC269_FIXUP_HEADSET_MODE, .name = "headset-mode"},
6558         {.id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC, .name = "headset-mode-no-hp-mic"},
6559         {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
6560         {.id = ALC269_FIXUP_HP_GPIO_LED, .name = "hp-gpio-led"},
6561         {.id = ALC269_FIXUP_HP_DOCK_GPIO_MIC1_LED, .name = "hp-dock-gpio-mic1-led"},
6562         {.id = ALC269_FIXUP_DELL1_MIC_NO_PRESENCE, .name = "dell-headset-multi"},
6563         {.id = ALC269_FIXUP_DELL2_MIC_NO_PRESENCE, .name = "dell-headset-dock"},
6564         {.id = ALC283_FIXUP_CHROME_BOOK, .name = "alc283-dac-wcaps"},
6565         {.id = ALC283_FIXUP_SENSE_COMBO_JACK, .name = "alc283-sense-combo"},
6566         {.id = ALC292_FIXUP_TPT440_DOCK, .name = "tpt440-dock"},
6567         {.id = ALC292_FIXUP_TPT440, .name = "tpt440"},
6568         {.id = ALC292_FIXUP_TPT460, .name = "tpt460"},
6569         {.id = ALC233_FIXUP_LENOVO_MULTI_CODECS, .name = "dual-codecs"},
6570         {}
6571 };
6572 #define ALC225_STANDARD_PINS \
6573         {0x21, 0x04211020}
6574
6575 #define ALC256_STANDARD_PINS \
6576         {0x12, 0x90a60140}, \
6577         {0x14, 0x90170110}, \
6578         {0x21, 0x02211020}
6579
6580 #define ALC282_STANDARD_PINS \
6581         {0x14, 0x90170110}
6582
6583 #define ALC290_STANDARD_PINS \
6584         {0x12, 0x99a30130}
6585
6586 #define ALC292_STANDARD_PINS \
6587         {0x14, 0x90170110}, \
6588         {0x15, 0x0221401f}
6589
6590 #define ALC295_STANDARD_PINS \
6591         {0x12, 0xb7a60130}, \
6592         {0x14, 0x90170110}, \
6593         {0x21, 0x04211020}
6594
6595 #define ALC298_STANDARD_PINS \
6596         {0x12, 0x90a60130}, \
6597         {0x21, 0x03211020}
6598
6599 static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
6600         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1025, "Acer", ALC255_FIXUP_ACER_MIC_NO_PRESENCE,
6601                 {0x12, 0x90a601c0},
6602                 {0x14, 0x90171120},
6603                 {0x21, 0x02211030}),
6604         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1043, "ASUS", ALC255_FIXUP_ASUS_MIC_NO_PRESENCE,
6605                 {0x14, 0x90170110},
6606                 {0x1b, 0x90a70130},
6607                 {0x21, 0x03211020}),
6608         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1043, "ASUS", ALC255_FIXUP_ASUS_MIC_NO_PRESENCE,
6609                 {0x1a, 0x90a70130},
6610                 {0x1b, 0x90170110},
6611                 {0x21, 0x03211020}),
6612         SND_HDA_PIN_QUIRK(0x10ec0225, 0x1028, "Dell", ALC225_FIXUP_DELL1_MIC_NO_PRESENCE,
6613                 ALC225_STANDARD_PINS,
6614                 {0x12, 0xb7a60130},
6615                 {0x14, 0x901701a0}),
6616         SND_HDA_PIN_QUIRK(0x10ec0225, 0x1028, "Dell", ALC225_FIXUP_DELL1_MIC_NO_PRESENCE,
6617                 ALC225_STANDARD_PINS,
6618                 {0x12, 0xb7a60130},
6619                 {0x14, 0x901701b0}),
6620         SND_HDA_PIN_QUIRK(0x10ec0225, 0x1028, "Dell", ALC225_FIXUP_DELL1_MIC_NO_PRESENCE,
6621                 ALC225_STANDARD_PINS,
6622                 {0x12, 0xb7a60150},
6623                 {0x14, 0x901701a0}),
6624         SND_HDA_PIN_QUIRK(0x10ec0225, 0x1028, "Dell", ALC225_FIXUP_DELL1_MIC_NO_PRESENCE,
6625                 ALC225_STANDARD_PINS,
6626                 {0x12, 0xb7a60150},
6627                 {0x14, 0x901701b0}),
6628         SND_HDA_PIN_QUIRK(0x10ec0225, 0x1028, "Dell", ALC225_FIXUP_DELL1_MIC_NO_PRESENCE,
6629                 ALC225_STANDARD_PINS,
6630                 {0x12, 0xb7a60130},
6631                 {0x1b, 0x90170110}),
6632         SND_HDA_PIN_QUIRK(0x10ec0236, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6633                 {0x12, 0x90a60140},
6634                 {0x14, 0x90170110},
6635                 {0x21, 0x02211020}),
6636         SND_HDA_PIN_QUIRK(0x10ec0235, 0x17aa, "Lenovo", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY,
6637                 {0x12, 0x90a60140},
6638                 {0x14, 0x90170110},
6639                 {0x19, 0x02a11030},
6640                 {0x21, 0x02211020}),
6641         SND_HDA_PIN_QUIRK(0x10ec0235, 0x17aa, "Lenovo", ALC294_FIXUP_LENOVO_MIC_LOCATION,
6642                 {0x14, 0x90170110},
6643                 {0x19, 0x02a11030},
6644                 {0x1a, 0x02a11040},
6645                 {0x1b, 0x01014020},
6646                 {0x21, 0x0221101f}),
6647         SND_HDA_PIN_QUIRK(0x10ec0235, 0x17aa, "Lenovo", ALC294_FIXUP_LENOVO_MIC_LOCATION,
6648                 {0x14, 0x90170110},
6649                 {0x19, 0x02a11030},
6650                 {0x1a, 0x02a11040},
6651                 {0x1b, 0x01011020},
6652                 {0x21, 0x0221101f}),
6653         SND_HDA_PIN_QUIRK(0x10ec0235, 0x17aa, "Lenovo", ALC294_FIXUP_LENOVO_MIC_LOCATION,
6654                 {0x14, 0x90170110},
6655                 {0x19, 0x02a11020},
6656                 {0x1a, 0x02a11030},
6657                 {0x21, 0x0221101f}),
6658         SND_HDA_PIN_QUIRK(0x10ec0236, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6659                 {0x12, 0x90a60140},
6660                 {0x14, 0x90170150},
6661                 {0x21, 0x02211020}),
6662         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL2_MIC_NO_PRESENCE,
6663                 {0x14, 0x90170110},
6664                 {0x21, 0x02211020}),
6665         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6666                 {0x14, 0x90170130},
6667                 {0x21, 0x02211040}),
6668         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6669                 {0x12, 0x90a60140},
6670                 {0x14, 0x90170110},
6671                 {0x21, 0x02211020}),
6672         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6673                 {0x12, 0x90a60160},
6674                 {0x14, 0x90170120},
6675                 {0x21, 0x02211030}),
6676         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6677                 {0x14, 0x90170110},
6678                 {0x1b, 0x02011020},
6679                 {0x21, 0x0221101f}),
6680         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6681                 {0x14, 0x90170110},
6682                 {0x1b, 0x01011020},
6683                 {0x21, 0x0221101f}),
6684         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6685                 {0x14, 0x90170130},
6686                 {0x1b, 0x01014020},
6687                 {0x21, 0x0221103f}),
6688         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6689                 {0x14, 0x90170130},
6690                 {0x1b, 0x01011020},
6691                 {0x21, 0x0221103f}),
6692         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6693                 {0x14, 0x90170130},
6694                 {0x1b, 0x02011020},
6695                 {0x21, 0x0221103f}),
6696         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6697                 {0x14, 0x90170150},
6698                 {0x1b, 0x02011020},
6699                 {0x21, 0x0221105f}),
6700         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6701                 {0x14, 0x90170110},
6702                 {0x1b, 0x01014020},
6703                 {0x21, 0x0221101f}),
6704         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6705                 {0x12, 0x90a60160},
6706                 {0x14, 0x90170120},
6707                 {0x17, 0x90170140},
6708                 {0x21, 0x0321102f}),
6709         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6710                 {0x12, 0x90a60160},
6711                 {0x14, 0x90170130},
6712                 {0x21, 0x02211040}),
6713         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6714                 {0x12, 0x90a60160},
6715                 {0x14, 0x90170140},
6716                 {0x21, 0x02211050}),
6717         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6718                 {0x12, 0x90a60170},
6719                 {0x14, 0x90170120},
6720                 {0x21, 0x02211030}),
6721         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6722                 {0x12, 0x90a60170},
6723                 {0x14, 0x90170130},
6724                 {0x21, 0x02211040}),
6725         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6726                 {0x12, 0x90a60170},
6727                 {0x14, 0x90171130},
6728                 {0x21, 0x02211040}),
6729         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6730                 {0x12, 0x90a60170},
6731                 {0x14, 0x90170140},
6732                 {0x21, 0x02211050}),
6733         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell Inspiron 5548", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6734                 {0x12, 0x90a60180},
6735                 {0x14, 0x90170130},
6736                 {0x21, 0x02211040}),
6737         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell Inspiron 5565", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6738                 {0x12, 0x90a60180},
6739                 {0x14, 0x90170120},
6740                 {0x21, 0x02211030}),
6741         SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6742                 {0x1b, 0x01011020},
6743                 {0x21, 0x02211010}),
6744         SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6745                 {0x12, 0x90a60130},
6746                 {0x14, 0x90170110},
6747                 {0x1b, 0x01011020},
6748                 {0x21, 0x0221101f}),
6749         SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6750                 {0x12, 0x90a60160},
6751                 {0x14, 0x90170120},
6752                 {0x21, 0x02211030}),
6753         SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6754                 {0x12, 0x90a60170},
6755                 {0x14, 0x90170120},
6756                 {0x21, 0x02211030}),
6757         SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell Inspiron 5468", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6758                 {0x12, 0x90a60180},
6759                 {0x14, 0x90170120},
6760                 {0x21, 0x02211030}),
6761         SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6762                 {0x12, 0xb7a60130},
6763                 {0x14, 0x90170110},
6764                 {0x21, 0x02211020}),
6765         SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6766                 {0x12, 0x90a60130},
6767                 {0x14, 0x90170110},
6768                 {0x14, 0x01011020},
6769                 {0x21, 0x0221101f}),
6770         SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6771                 ALC256_STANDARD_PINS),
6772         SND_HDA_PIN_QUIRK(0x10ec0256, 0x1043, "ASUS", ALC256_FIXUP_ASUS_MIC,
6773                 {0x14, 0x90170110},
6774                 {0x1b, 0x90a70130},
6775                 {0x21, 0x04211020}),
6776         SND_HDA_PIN_QUIRK(0x10ec0256, 0x1043, "ASUS", ALC256_FIXUP_ASUS_MIC,
6777                 {0x14, 0x90170110},
6778                 {0x1b, 0x90a70130},
6779                 {0x21, 0x03211020}),
6780         SND_HDA_PIN_QUIRK(0x10ec0274, 0x1028, "Dell", ALC274_FIXUP_DELL_AIO_LINEOUT_VERB,
6781                 {0x12, 0xb7a60130},
6782                 {0x13, 0xb8a61140},
6783                 {0x16, 0x90170110},
6784                 {0x21, 0x04211020}),
6785         SND_HDA_PIN_QUIRK(0x10ec0280, 0x103c, "HP", ALC280_FIXUP_HP_GPIO4,
6786                 {0x12, 0x90a60130},
6787                 {0x14, 0x90170110},
6788                 {0x15, 0x0421101f},
6789                 {0x1a, 0x04a11020}),
6790         SND_HDA_PIN_QUIRK(0x10ec0280, 0x103c, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED,
6791                 {0x12, 0x90a60140},
6792                 {0x14, 0x90170110},
6793                 {0x15, 0x0421101f},
6794                 {0x18, 0x02811030},
6795                 {0x1a, 0x04a1103f},
6796                 {0x1b, 0x02011020}),
6797         SND_HDA_PIN_QUIRK(0x10ec0282, 0x103c, "HP 15 Touchsmart", ALC269_FIXUP_HP_MUTE_LED_MIC1,
6798                 ALC282_STANDARD_PINS,
6799                 {0x12, 0x99a30130},
6800                 {0x19, 0x03a11020},
6801                 {0x21, 0x0321101f}),
6802         SND_HDA_PIN_QUIRK(0x10ec0282, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
6803                 ALC282_STANDARD_PINS,
6804                 {0x12, 0x99a30130},
6805                 {0x19, 0x03a11020},
6806                 {0x21, 0x03211040}),
6807         SND_HDA_PIN_QUIRK(0x10ec0282, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
6808                 ALC282_STANDARD_PINS,
6809                 {0x12, 0x99a30130},
6810                 {0x19, 0x03a11030},
6811                 {0x21, 0x03211020}),
6812         SND_HDA_PIN_QUIRK(0x10ec0282, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
6813                 ALC282_STANDARD_PINS,
6814                 {0x12, 0x99a30130},
6815                 {0x19, 0x04a11020},
6816                 {0x21, 0x0421101f}),
6817         SND_HDA_PIN_QUIRK(0x10ec0282, 0x103c, "HP", ALC269_FIXUP_HP_LINE1_MIC1_LED,
6818                 ALC282_STANDARD_PINS,
6819                 {0x12, 0x90a60140},
6820                 {0x19, 0x04a11030},
6821                 {0x21, 0x04211020}),
6822         SND_HDA_PIN_QUIRK(0x10ec0283, 0x1028, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
6823                 ALC282_STANDARD_PINS,
6824                 {0x12, 0x90a60130},
6825                 {0x21, 0x0321101f}),
6826         SND_HDA_PIN_QUIRK(0x10ec0283, 0x1028, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
6827                 {0x12, 0x90a60160},
6828                 {0x14, 0x90170120},
6829                 {0x21, 0x02211030}),
6830         SND_HDA_PIN_QUIRK(0x10ec0283, 0x1028, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
6831                 ALC282_STANDARD_PINS,
6832                 {0x12, 0x90a60130},
6833                 {0x19, 0x03a11020},
6834                 {0x21, 0x0321101f}),
6835         SND_HDA_PIN_QUIRK(0x10ec0288, 0x1028, "Dell", ALC288_FIXUP_DELL_XPS_13_GPIO6,
6836                 {0x12, 0x90a60120},
6837                 {0x14, 0x90170110},
6838                 {0x21, 0x0321101f}),
6839         SND_HDA_PIN_QUIRK(0x10ec0289, 0x1028, "Dell", ALC269_FIXUP_DELL4_MIC_NO_PRESENCE,
6840                 {0x12, 0xb7a60130},
6841                 {0x14, 0x90170110},
6842                 {0x21, 0x04211020}),
6843         SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
6844                 ALC290_STANDARD_PINS,
6845                 {0x15, 0x04211040},
6846                 {0x18, 0x90170112},
6847                 {0x1a, 0x04a11020}),
6848         SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
6849                 ALC290_STANDARD_PINS,
6850                 {0x15, 0x04211040},
6851                 {0x18, 0x90170110},
6852                 {0x1a, 0x04a11020}),
6853         SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
6854                 ALC290_STANDARD_PINS,
6855                 {0x15, 0x0421101f},
6856                 {0x1a, 0x04a11020}),
6857         SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
6858                 ALC290_STANDARD_PINS,
6859                 {0x15, 0x04211020},
6860                 {0x1a, 0x04a11040}),
6861         SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
6862                 ALC290_STANDARD_PINS,
6863                 {0x14, 0x90170110},
6864                 {0x15, 0x04211020},
6865                 {0x1a, 0x04a11040}),
6866         SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
6867                 ALC290_STANDARD_PINS,
6868                 {0x14, 0x90170110},
6869                 {0x15, 0x04211020},
6870                 {0x1a, 0x04a11020}),
6871         SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
6872                 ALC290_STANDARD_PINS,
6873                 {0x14, 0x90170110},
6874                 {0x15, 0x0421101f},
6875                 {0x1a, 0x04a11020}),
6876         SND_HDA_PIN_QUIRK(0x10ec0292, 0x1028, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE,
6877                 ALC292_STANDARD_PINS,
6878                 {0x12, 0x90a60140},
6879                 {0x16, 0x01014020},
6880                 {0x19, 0x01a19030}),
6881         SND_HDA_PIN_QUIRK(0x10ec0292, 0x1028, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE,
6882                 ALC292_STANDARD_PINS,
6883                 {0x12, 0x90a60140},
6884                 {0x16, 0x01014020},
6885                 {0x18, 0x02a19031},
6886                 {0x19, 0x01a1903e}),
6887         SND_HDA_PIN_QUIRK(0x10ec0292, 0x1028, "Dell", ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
6888                 ALC292_STANDARD_PINS,
6889                 {0x12, 0x90a60140}),
6890         SND_HDA_PIN_QUIRK(0x10ec0293, 0x1028, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE,
6891                 ALC292_STANDARD_PINS,
6892                 {0x13, 0x90a60140},
6893                 {0x16, 0x21014020},
6894                 {0x19, 0x21a19030}),
6895         SND_HDA_PIN_QUIRK(0x10ec0293, 0x1028, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE,
6896                 ALC292_STANDARD_PINS,
6897                 {0x13, 0x90a60140}),
6898         SND_HDA_PIN_QUIRK(0x10ec0295, 0x1028, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
6899                 ALC295_STANDARD_PINS,
6900                 {0x17, 0x21014020},
6901                 {0x18, 0x21a19030}),
6902         SND_HDA_PIN_QUIRK(0x10ec0295, 0x1028, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
6903                 ALC295_STANDARD_PINS,
6904                 {0x17, 0x21014040},
6905                 {0x18, 0x21a19050}),
6906         SND_HDA_PIN_QUIRK(0x10ec0295, 0x1028, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
6907                 ALC295_STANDARD_PINS),
6908         SND_HDA_PIN_QUIRK(0x10ec0298, 0x1028, "Dell", ALC298_FIXUP_DELL1_MIC_NO_PRESENCE,
6909                 ALC298_STANDARD_PINS,
6910                 {0x17, 0x90170110}),
6911         SND_HDA_PIN_QUIRK(0x10ec0298, 0x1028, "Dell", ALC298_FIXUP_DELL1_MIC_NO_PRESENCE,
6912                 ALC298_STANDARD_PINS,
6913                 {0x17, 0x90170140}),
6914         SND_HDA_PIN_QUIRK(0x10ec0298, 0x1028, "Dell", ALC298_FIXUP_DELL1_MIC_NO_PRESENCE,
6915                 ALC298_STANDARD_PINS,
6916                 {0x17, 0x90170150}),
6917         SND_HDA_PIN_QUIRK(0x10ec0298, 0x1028, "Dell", ALC298_FIXUP_SPK_VOLUME,
6918                 {0x12, 0xb7a60140},
6919                 {0x13, 0xb7a60150},
6920                 {0x17, 0x90170110},
6921                 {0x1a, 0x03011020},
6922                 {0x21, 0x03211030}),
6923         SND_HDA_PIN_QUIRK(0x10ec0299, 0x1028, "Dell", ALC269_FIXUP_DELL4_MIC_NO_PRESENCE,
6924                 ALC225_STANDARD_PINS,
6925                 {0x12, 0xb7a60130},
6926                 {0x17, 0x90170110}),
6927         {}
6928 };
6929
6930 static void alc269_fill_coef(struct hda_codec *codec)
6931 {
6932         struct alc_spec *spec = codec->spec;
6933         int val;
6934
6935         if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6936                 return;
6937
6938         if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
6939                 alc_write_coef_idx(codec, 0xf, 0x960b);
6940                 alc_write_coef_idx(codec, 0xe, 0x8817);
6941         }
6942
6943         if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
6944                 alc_write_coef_idx(codec, 0xf, 0x960b);
6945                 alc_write_coef_idx(codec, 0xe, 0x8814);
6946         }
6947
6948         if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
6949                 /* Power up output pin */
6950                 alc_update_coef_idx(codec, 0x04, 0, 1<<11);
6951         }
6952
6953         if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
6954                 val = alc_read_coef_idx(codec, 0xd);
6955                 if (val != -1 && (val & 0x0c00) >> 10 != 0x1) {
6956                         /* Capless ramp up clock control */
6957                         alc_write_coef_idx(codec, 0xd, val | (1<<10));
6958                 }
6959                 val = alc_read_coef_idx(codec, 0x17);
6960                 if (val != -1 && (val & 0x01c0) >> 6 != 0x4) {
6961                         /* Class D power on reset */
6962                         alc_write_coef_idx(codec, 0x17, val | (1<<7));
6963                 }
6964         }
6965
6966         /* HP */
6967         alc_update_coef_idx(codec, 0x4, 0, 1<<11);
6968 }
6969
6970 static void alc294_hp_init(struct hda_codec *codec)
6971 {
6972         struct alc_spec *spec = codec->spec;
6973         hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
6974         int i, val;
6975
6976         if (!hp_pin)
6977                 return;
6978
6979         snd_hda_codec_write(codec, hp_pin, 0,
6980                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
6981
6982         msleep(100);
6983
6984         snd_hda_codec_write(codec, hp_pin, 0,
6985                             AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0);
6986
6987         alc_update_coef_idx(codec, 0x6f, 0x000f, 0);/* Set HP depop to manual mode */
6988         alc_update_coefex_idx(codec, 0x58, 0x00, 0x8000, 0x8000); /* HP depop procedure start */
6989
6990         /* Wait for depop procedure finish  */
6991         val = alc_read_coefex_idx(codec, 0x58, 0x01);
6992         for (i = 0; i < 20 && val & 0x0080; i++) {
6993                 msleep(50);
6994                 val = alc_read_coefex_idx(codec, 0x58, 0x01);
6995         }
6996         /* Set HP depop to auto mode */
6997         alc_update_coef_idx(codec, 0x6f, 0x000f, 0x000b);
6998         msleep(50);
6999 }
7000
7001 /*
7002  */
7003 static int patch_alc269(struct hda_codec *codec)
7004 {
7005         struct alc_spec *spec;
7006         int err;
7007
7008         err = alc_alloc_spec(codec, 0x0b);
7009         if (err < 0)
7010                 return err;
7011
7012         spec = codec->spec;
7013         spec->gen.shared_mic_vref_pin = 0x18;
7014         codec->power_save_node = 1;
7015
7016 #ifdef CONFIG_PM
7017         codec->patch_ops.suspend = alc269_suspend;
7018         codec->patch_ops.resume = alc269_resume;
7019 #endif
7020         spec->shutup = alc_default_shutup;
7021         spec->init_hook = alc_default_init;
7022
7023         snd_hda_pick_fixup(codec, alc269_fixup_models,
7024                        alc269_fixup_tbl, alc269_fixups);
7025         snd_hda_pick_pin_fixup(codec, alc269_pin_fixup_tbl, alc269_fixups);
7026         snd_hda_pick_fixup(codec, NULL, alc269_fixup_vendor_tbl,
7027                            alc269_fixups);
7028         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
7029
7030         alc_auto_parse_customize_define(codec);
7031
7032         if (has_cdefine_beep(codec))
7033                 spec->gen.beep_nid = 0x01;
7034
7035         switch (codec->core.vendor_id) {
7036         case 0x10ec0269:
7037                 spec->codec_variant = ALC269_TYPE_ALC269VA;
7038                 switch (alc_get_coef0(codec) & 0x00f0) {
7039                 case 0x0010:
7040                         if (codec->bus->pci &&
7041                             codec->bus->pci->subsystem_vendor == 0x1025 &&
7042                             spec->cdefine.platform_type == 1)
7043                                 err = alc_codec_rename(codec, "ALC271X");
7044                         spec->codec_variant = ALC269_TYPE_ALC269VB;
7045                         break;
7046                 case 0x0020:
7047                         if (codec->bus->pci &&
7048                             codec->bus->pci->subsystem_vendor == 0x17aa &&
7049                             codec->bus->pci->subsystem_device == 0x21f3)
7050                                 err = alc_codec_rename(codec, "ALC3202");
7051                         spec->codec_variant = ALC269_TYPE_ALC269VC;
7052                         break;
7053                 case 0x0030:
7054                         spec->codec_variant = ALC269_TYPE_ALC269VD;
7055                         break;
7056                 default:
7057                         alc_fix_pll_init(codec, 0x20, 0x04, 15);
7058                 }
7059                 if (err < 0)
7060                         goto error;
7061                 spec->shutup = alc269_shutup;
7062                 spec->init_hook = alc269_fill_coef;
7063                 alc269_fill_coef(codec);
7064                 break;
7065
7066         case 0x10ec0280:
7067         case 0x10ec0290:
7068                 spec->codec_variant = ALC269_TYPE_ALC280;
7069                 break;
7070         case 0x10ec0282:
7071                 spec->codec_variant = ALC269_TYPE_ALC282;
7072                 spec->shutup = alc282_shutup;
7073                 spec->init_hook = alc282_init;
7074                 break;
7075         case 0x10ec0233:
7076         case 0x10ec0283:
7077                 spec->codec_variant = ALC269_TYPE_ALC283;
7078                 spec->shutup = alc283_shutup;
7079                 spec->init_hook = alc283_init;
7080                 break;
7081         case 0x10ec0284:
7082         case 0x10ec0292:
7083                 spec->codec_variant = ALC269_TYPE_ALC284;
7084                 break;
7085         case 0x10ec0293:
7086                 spec->codec_variant = ALC269_TYPE_ALC293;
7087                 break;
7088         case 0x10ec0286:
7089         case 0x10ec0288:
7090                 spec->codec_variant = ALC269_TYPE_ALC286;
7091                 spec->shutup = alc286_shutup;
7092                 break;
7093         case 0x10ec0298:
7094                 spec->codec_variant = ALC269_TYPE_ALC298;
7095                 break;
7096         case 0x10ec0235:
7097         case 0x10ec0255:
7098                 spec->codec_variant = ALC269_TYPE_ALC255;
7099                 spec->shutup = alc256_shutup;
7100                 spec->init_hook = alc256_init;
7101                 break;
7102         case 0x10ec0236:
7103         case 0x10ec0256:
7104                 spec->codec_variant = ALC269_TYPE_ALC256;
7105                 spec->shutup = alc256_shutup;
7106                 spec->init_hook = alc256_init;
7107                 spec->gen.mixer_nid = 0; /* ALC256 does not have any loopback mixer path */
7108                 alc_update_coef_idx(codec, 0x36, 1 << 13, 1 << 5); /* Switch pcbeep path to Line in path*/
7109                 break;
7110         case 0x10ec0257:
7111                 spec->codec_variant = ALC269_TYPE_ALC257;
7112                 spec->shutup = alc256_shutup;
7113                 spec->init_hook = alc256_init;
7114                 spec->gen.mixer_nid = 0;
7115                 break;
7116         case 0x10ec0215:
7117         case 0x10ec0285:
7118         case 0x10ec0289:
7119                 spec->codec_variant = ALC269_TYPE_ALC215;
7120                 spec->gen.mixer_nid = 0;
7121                 break;
7122         case 0x10ec0225:
7123         case 0x10ec0295:
7124                 spec->codec_variant = ALC269_TYPE_ALC225;
7125                 spec->gen.mixer_nid = 0; /* no loopback on ALC225 ALC295 */
7126                 break;
7127         case 0x10ec0299:
7128                 spec->codec_variant = ALC269_TYPE_ALC225;
7129                 spec->gen.mixer_nid = 0; /* no loopback on ALC299 */
7130                 break;
7131         case 0x10ec0234:
7132         case 0x10ec0274:
7133         case 0x10ec0294:
7134                 spec->codec_variant = ALC269_TYPE_ALC294;
7135                 spec->gen.mixer_nid = 0; /* ALC2x4 does not have any loopback mixer path */
7136                 alc_update_coef_idx(codec, 0x6b, 0x0018, (1<<4) | (1<<3)); /* UAJ MIC Vref control by verb */
7137                 alc294_hp_init(codec);
7138                 break;
7139         case 0x10ec0300:
7140                 spec->codec_variant = ALC269_TYPE_ALC300;
7141                 spec->gen.mixer_nid = 0; /* no loopback on ALC300 */
7142                 break;
7143         case 0x10ec0700:
7144         case 0x10ec0701:
7145         case 0x10ec0703:
7146                 spec->codec_variant = ALC269_TYPE_ALC700;
7147                 spec->gen.mixer_nid = 0; /* ALC700 does not have any loopback mixer path */
7148                 alc_update_coef_idx(codec, 0x4a, 1 << 15, 0); /* Combo jack auto trigger control */
7149                 alc294_hp_init(codec);
7150                 break;
7151
7152         }
7153
7154         if (snd_hda_codec_read(codec, 0x51, 0, AC_VERB_PARAMETERS, 0) == 0x10ec5505) {
7155                 spec->has_alc5505_dsp = 1;
7156                 spec->init_hook = alc5505_dsp_init;
7157         }
7158
7159         /* automatic parse from the BIOS config */
7160         err = alc269_parse_auto_config(codec);
7161         if (err < 0)
7162                 goto error;
7163
7164         if (!spec->gen.no_analog && spec->gen.beep_nid && spec->gen.mixer_nid)
7165                 set_beep_amp(spec, spec->gen.mixer_nid, 0x04, HDA_INPUT);
7166
7167         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
7168
7169         return 0;
7170
7171  error:
7172         alc_free(codec);
7173         return err;
7174 }
7175
7176 /*
7177  * ALC861
7178  */
7179
7180 static int alc861_parse_auto_config(struct hda_codec *codec)
7181 {
7182         static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
7183         static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
7184         return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
7185 }
7186
7187 /* Pin config fixes */
7188 enum {
7189         ALC861_FIXUP_FSC_AMILO_PI1505,
7190         ALC861_FIXUP_AMP_VREF_0F,
7191         ALC861_FIXUP_NO_JACK_DETECT,
7192         ALC861_FIXUP_ASUS_A6RP,
7193         ALC660_FIXUP_ASUS_W7J,
7194 };
7195
7196 /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
7197 static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
7198                         const struct hda_fixup *fix, int action)
7199 {
7200         struct alc_spec *spec = codec->spec;
7201         unsigned int val;
7202
7203         if (action != HDA_FIXUP_ACT_INIT)
7204                 return;
7205         val = snd_hda_codec_get_pin_target(codec, 0x0f);
7206         if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
7207                 val |= AC_PINCTL_IN_EN;
7208         val |= AC_PINCTL_VREF_50;
7209         snd_hda_set_pin_ctl(codec, 0x0f, val);
7210         spec->gen.keep_vref_in_automute = 1;
7211 }
7212
7213 /* suppress the jack-detection */
7214 static void alc_fixup_no_jack_detect(struct hda_codec *codec,
7215                                      const struct hda_fixup *fix, int action)
7216 {
7217         if (action == HDA_FIXUP_ACT_PRE_PROBE)
7218                 codec->no_jack_detect = 1;
7219 }
7220
7221 static const struct hda_fixup alc861_fixups[] = {
7222         [ALC861_FIXUP_FSC_AMILO_PI1505] = {
7223                 .type = HDA_FIXUP_PINS,
7224                 .v.pins = (const struct hda_pintbl[]) {
7225                         { 0x0b, 0x0221101f }, /* HP */
7226                         { 0x0f, 0x90170310 }, /* speaker */
7227                         { }
7228                 }
7229         },
7230         [ALC861_FIXUP_AMP_VREF_0F] = {
7231                 .type = HDA_FIXUP_FUNC,
7232                 .v.func = alc861_fixup_asus_amp_vref_0f,
7233         },
7234         [ALC861_FIXUP_NO_JACK_DETECT] = {
7235                 .type = HDA_FIXUP_FUNC,
7236                 .v.func = alc_fixup_no_jack_detect,
7237         },
7238         [ALC861_FIXUP_ASUS_A6RP] = {
7239                 .type = HDA_FIXUP_FUNC,
7240                 .v.func = alc861_fixup_asus_amp_vref_0f,
7241                 .chained = true,
7242                 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
7243         },
7244         [ALC660_FIXUP_ASUS_W7J] = {
7245                 .type = HDA_FIXUP_VERBS,
7246                 .v.verbs = (const struct hda_verb[]) {
7247                         /* ASUS W7J needs a magic pin setup on unused NID 0x10
7248                          * for enabling outputs
7249                          */
7250                         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7251                         { }
7252                 },
7253         }
7254 };
7255
7256 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
7257         SND_PCI_QUIRK(0x1043, 0x1253, "ASUS W7J", ALC660_FIXUP_ASUS_W7J),
7258         SND_PCI_QUIRK(0x1043, 0x1263, "ASUS Z35HL", ALC660_FIXUP_ASUS_W7J),
7259         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
7260         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
7261         SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
7262         SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
7263         SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
7264         SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
7265         {}
7266 };
7267
7268 /*
7269  */
7270 static int patch_alc861(struct hda_codec *codec)
7271 {
7272         struct alc_spec *spec;
7273         int err;
7274
7275         err = alc_alloc_spec(codec, 0x15);
7276         if (err < 0)
7277                 return err;
7278
7279         spec = codec->spec;
7280         spec->gen.beep_nid = 0x23;
7281
7282 #ifdef CONFIG_PM
7283         spec->power_hook = alc_power_eapd;
7284 #endif
7285
7286         snd_hda_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
7287         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
7288
7289         /* automatic parse from the BIOS config */
7290         err = alc861_parse_auto_config(codec);
7291         if (err < 0)
7292                 goto error;
7293
7294         if (!spec->gen.no_analog)
7295                 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
7296
7297         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
7298
7299         return 0;
7300
7301  error:
7302         alc_free(codec);
7303         return err;
7304 }
7305
7306 /*
7307  * ALC861-VD support
7308  *
7309  * Based on ALC882
7310  *
7311  * In addition, an independent DAC
7312  */
7313 static int alc861vd_parse_auto_config(struct hda_codec *codec)
7314 {
7315         static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
7316         static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
7317         return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
7318 }
7319
7320 enum {
7321         ALC660VD_FIX_ASUS_GPIO1,
7322         ALC861VD_FIX_DALLAS,
7323 };
7324
7325 /* exclude VREF80 */
7326 static void alc861vd_fixup_dallas(struct hda_codec *codec,
7327                                   const struct hda_fixup *fix, int action)
7328 {
7329         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
7330                 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
7331                 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
7332         }
7333 }
7334
7335 static const struct hda_fixup alc861vd_fixups[] = {
7336         [ALC660VD_FIX_ASUS_GPIO1] = {
7337                 .type = HDA_FIXUP_VERBS,
7338                 .v.verbs = (const struct hda_verb[]) {
7339                         /* reset GPIO1 */
7340                         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7341                         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
7342                         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
7343                         { }
7344                 }
7345         },
7346         [ALC861VD_FIX_DALLAS] = {
7347                 .type = HDA_FIXUP_FUNC,
7348                 .v.func = alc861vd_fixup_dallas,
7349         },
7350 };
7351
7352 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
7353         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
7354         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
7355         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
7356         {}
7357 };
7358
7359 /*
7360  */
7361 static int patch_alc861vd(struct hda_codec *codec)
7362 {
7363         struct alc_spec *spec;
7364         int err;
7365
7366         err = alc_alloc_spec(codec, 0x0b);
7367         if (err < 0)
7368                 return err;
7369
7370         spec = codec->spec;
7371         spec->gen.beep_nid = 0x23;
7372
7373         spec->shutup = alc_eapd_shutup;
7374
7375         snd_hda_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
7376         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
7377
7378         /* automatic parse from the BIOS config */
7379         err = alc861vd_parse_auto_config(codec);
7380         if (err < 0)
7381                 goto error;
7382
7383         if (!spec->gen.no_analog)
7384                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7385
7386         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
7387
7388         return 0;
7389
7390  error:
7391         alc_free(codec);
7392         return err;
7393 }
7394
7395 /*
7396  * ALC662 support
7397  *
7398  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
7399  * configuration.  Each pin widget can choose any input DACs and a mixer.
7400  * Each ADC is connected from a mixer of all inputs.  This makes possible
7401  * 6-channel independent captures.
7402  *
7403  * In addition, an independent DAC for the multi-playback (not used in this
7404  * driver yet).
7405  */
7406
7407 /*
7408  * BIOS auto configuration
7409  */
7410
7411 static int alc662_parse_auto_config(struct hda_codec *codec)
7412 {
7413         static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
7414         static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
7415         static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
7416         const hda_nid_t *ssids;
7417
7418         if (codec->core.vendor_id == 0x10ec0272 || codec->core.vendor_id == 0x10ec0663 ||
7419             codec->core.vendor_id == 0x10ec0665 || codec->core.vendor_id == 0x10ec0670 ||
7420             codec->core.vendor_id == 0x10ec0671)
7421                 ssids = alc663_ssids;
7422         else
7423                 ssids = alc662_ssids;
7424         return alc_parse_auto_config(codec, alc662_ignore, ssids);
7425 }
7426
7427 static void alc272_fixup_mario(struct hda_codec *codec,
7428                                const struct hda_fixup *fix, int action)
7429 {
7430         if (action != HDA_FIXUP_ACT_PRE_PROBE)
7431                 return;
7432         if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
7433                                       (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
7434                                       (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
7435                                       (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
7436                                       (0 << AC_AMPCAP_MUTE_SHIFT)))
7437                 codec_warn(codec, "failed to override amp caps for NID 0x2\n");
7438 }
7439
7440 static const struct snd_pcm_chmap_elem asus_pcm_2_1_chmaps[] = {
7441         { .channels = 2,
7442           .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } },
7443         { .channels = 4,
7444           .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
7445                    SNDRV_CHMAP_NA, SNDRV_CHMAP_LFE } }, /* LFE only on right */
7446         { }
7447 };
7448
7449 /* override the 2.1 chmap */
7450 static void alc_fixup_bass_chmap(struct hda_codec *codec,
7451                                     const struct hda_fixup *fix, int action)
7452 {
7453         if (action == HDA_FIXUP_ACT_BUILD) {
7454                 struct alc_spec *spec = codec->spec;
7455                 spec->gen.pcm_rec[0]->stream[0].chmap = asus_pcm_2_1_chmaps;
7456         }
7457 }
7458
7459 /* avoid D3 for keeping GPIO up */
7460 static unsigned int gpio_led_power_filter(struct hda_codec *codec,
7461                                           hda_nid_t nid,
7462                                           unsigned int power_state)
7463 {
7464         struct alc_spec *spec = codec->spec;
7465         if (nid == codec->core.afg && power_state == AC_PWRST_D3 && spec->gpio_led)
7466                 return AC_PWRST_D0;
7467         return power_state;
7468 }
7469
7470 static void alc662_fixup_led_gpio1(struct hda_codec *codec,
7471                                    const struct hda_fixup *fix, int action)
7472 {
7473         struct alc_spec *spec = codec->spec;
7474         static const struct hda_verb gpio_init[] = {
7475                 { 0x01, AC_VERB_SET_GPIO_MASK, 0x01 },
7476                 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 },
7477                 {}
7478         };
7479
7480         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
7481                 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
7482                 spec->gpio_led = 0;
7483                 spec->mute_led_polarity = 1;
7484                 spec->gpio_mute_led_mask = 0x01;
7485                 snd_hda_add_verbs(codec, gpio_init);
7486                 codec->power_filter = gpio_led_power_filter;
7487         }
7488 }
7489
7490 static void alc662_usi_automute_hook(struct hda_codec *codec,
7491                                          struct hda_jack_callback *jack)
7492 {
7493         struct alc_spec *spec = codec->spec;
7494         int vref;
7495         msleep(200);
7496         snd_hda_gen_hp_automute(codec, jack);
7497
7498         vref = spec->gen.hp_jack_present ? PIN_VREF80 : 0;
7499         msleep(100);
7500         snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
7501                             vref);
7502 }
7503
7504 static void alc662_fixup_usi_headset_mic(struct hda_codec *codec,
7505                                      const struct hda_fixup *fix, int action)
7506 {
7507         struct alc_spec *spec = codec->spec;
7508         if (action == HDA_FIXUP_ACT_PRE_PROBE) {
7509                 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
7510                 spec->gen.hp_automute_hook = alc662_usi_automute_hook;
7511         }
7512 }
7513
7514 static struct coef_fw alc668_coefs[] = {
7515         WRITE_COEF(0x01, 0xbebe), WRITE_COEF(0x02, 0xaaaa), WRITE_COEF(0x03,    0x0),
7516         WRITE_COEF(0x04, 0x0180), WRITE_COEF(0x06,    0x0), WRITE_COEF(0x07, 0x0f80),
7517         WRITE_COEF(0x08, 0x0031), WRITE_COEF(0x0a, 0x0060), WRITE_COEF(0x0b,    0x0),
7518         WRITE_COEF(0x0c, 0x7cf7), WRITE_COEF(0x0d, 0x1080), WRITE_COEF(0x0e, 0x7f7f),
7519         WRITE_COEF(0x0f, 0xcccc), WRITE_COEF(0x10, 0xddcc), WRITE_COEF(0x11, 0x0001),
7520         WRITE_COEF(0x13,    0x0), WRITE_COEF(0x14, 0x2aa0), WRITE_COEF(0x17, 0xa940),
7521         WRITE_COEF(0x19,    0x0), WRITE_COEF(0x1a,    0x0), WRITE_COEF(0x1b,    0x0),
7522         WRITE_COEF(0x1c,    0x0), WRITE_COEF(0x1d,    0x0), WRITE_COEF(0x1e, 0x7418),
7523         WRITE_COEF(0x1f, 0x0804), WRITE_COEF(0x20, 0x4200), WRITE_COEF(0x21, 0x0468),
7524         WRITE_COEF(0x22, 0x8ccc), WRITE_COEF(0x23, 0x0250), WRITE_COEF(0x24, 0x7418),
7525         WRITE_COEF(0x27,    0x0), WRITE_COEF(0x28, 0x8ccc), WRITE_COEF(0x2a, 0xff00),
7526         WRITE_COEF(0x2b, 0x8000), WRITE_COEF(0xa7, 0xff00), WRITE_COEF(0xa8, 0x8000),
7527         WRITE_COEF(0xaa, 0x2e17), WRITE_COEF(0xab, 0xa0c0), WRITE_COEF(0xac,    0x0),
7528         WRITE_COEF(0xad,    0x0), WRITE_COEF(0xae, 0x2ac6), WRITE_COEF(0xaf, 0xa480),
7529         WRITE_COEF(0xb0,    0x0), WRITE_COEF(0xb1,    0x0), WRITE_COEF(0xb2,    0x0),
7530         WRITE_COEF(0xb3,    0x0), WRITE_COEF(0xb4,    0x0), WRITE_COEF(0xb5, 0x1040),
7531         WRITE_COEF(0xb6, 0xd697), WRITE_COEF(0xb7, 0x902b), WRITE_COEF(0xb8, 0xd697),
7532         WRITE_COEF(0xb9, 0x902b), WRITE_COEF(0xba, 0xb8ba), WRITE_COEF(0xbb, 0xaaab),
7533         WRITE_COEF(0xbc, 0xaaaf), WRITE_COEF(0xbd, 0x6aaa), WRITE_COEF(0xbe, 0x1c02),
7534         WRITE_COEF(0xc0, 0x00ff), WRITE_COEF(0xc1, 0x0fa6),
7535         {}
7536 };
7537
7538 static void alc668_restore_default_value(struct hda_codec *codec)
7539 {
7540         alc_process_coef_fw(codec, alc668_coefs);
7541 }
7542
7543 enum {
7544         ALC662_FIXUP_ASPIRE,
7545         ALC662_FIXUP_LED_GPIO1,
7546         ALC662_FIXUP_IDEAPAD,
7547         ALC272_FIXUP_MARIO,
7548         ALC662_FIXUP_CZC_P10T,
7549         ALC662_FIXUP_SKU_IGNORE,
7550         ALC662_FIXUP_HP_RP5800,
7551         ALC662_FIXUP_ASUS_MODE1,
7552         ALC662_FIXUP_ASUS_MODE2,
7553         ALC662_FIXUP_ASUS_MODE3,
7554         ALC662_FIXUP_ASUS_MODE4,
7555         ALC662_FIXUP_ASUS_MODE5,
7556         ALC662_FIXUP_ASUS_MODE6,
7557         ALC662_FIXUP_ASUS_MODE7,
7558         ALC662_FIXUP_ASUS_MODE8,
7559         ALC662_FIXUP_NO_JACK_DETECT,
7560         ALC662_FIXUP_ZOTAC_Z68,
7561         ALC662_FIXUP_INV_DMIC,
7562         ALC662_FIXUP_DELL_MIC_NO_PRESENCE,
7563         ALC668_FIXUP_DELL_MIC_NO_PRESENCE,
7564         ALC662_FIXUP_HEADSET_MODE,
7565         ALC668_FIXUP_HEADSET_MODE,
7566         ALC662_FIXUP_BASS_MODE4_CHMAP,
7567         ALC662_FIXUP_BASS_16,
7568         ALC662_FIXUP_BASS_1A,
7569         ALC662_FIXUP_BASS_CHMAP,
7570         ALC668_FIXUP_AUTO_MUTE,
7571         ALC668_FIXUP_DELL_DISABLE_AAMIX,
7572         ALC668_FIXUP_DELL_XPS13,
7573         ALC662_FIXUP_ASUS_Nx50,
7574         ALC668_FIXUP_ASUS_Nx51_HEADSET_MODE,
7575         ALC668_FIXUP_ASUS_Nx51,
7576         ALC668_FIXUP_MIC_COEF,
7577         ALC668_FIXUP_ASUS_G751,
7578         ALC891_FIXUP_HEADSET_MODE,
7579         ALC891_FIXUP_DELL_MIC_NO_PRESENCE,
7580         ALC662_FIXUP_ACER_VERITON,
7581         ALC892_FIXUP_ASROCK_MOBO,
7582         ALC662_FIXUP_USI_FUNC,
7583         ALC662_FIXUP_USI_HEADSET_MODE,
7584         ALC662_FIXUP_LENOVO_MULTI_CODECS,
7585 };
7586
7587 static const struct hda_fixup alc662_fixups[] = {
7588         [ALC662_FIXUP_ASPIRE] = {
7589                 .type = HDA_FIXUP_PINS,
7590                 .v.pins = (const struct hda_pintbl[]) {
7591                         { 0x15, 0x99130112 }, /* subwoofer */
7592                         { }
7593                 }
7594         },
7595         [ALC662_FIXUP_LED_GPIO1] = {
7596                 .type = HDA_FIXUP_FUNC,
7597                 .v.func = alc662_fixup_led_gpio1,
7598         },
7599         [ALC662_FIXUP_IDEAPAD] = {
7600                 .type = HDA_FIXUP_PINS,
7601                 .v.pins = (const struct hda_pintbl[]) {
7602                         { 0x17, 0x99130112 }, /* subwoofer */
7603                         { }
7604                 },
7605                 .chained = true,
7606                 .chain_id = ALC662_FIXUP_LED_GPIO1,
7607         },
7608         [ALC272_FIXUP_MARIO] = {
7609                 .type = HDA_FIXUP_FUNC,
7610                 .v.func = alc272_fixup_mario,
7611         },
7612         [ALC662_FIXUP_CZC_P10T] = {
7613                 .type = HDA_FIXUP_VERBS,
7614                 .v.verbs = (const struct hda_verb[]) {
7615                         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
7616                         {}
7617                 }
7618         },
7619         [ALC662_FIXUP_SKU_IGNORE] = {
7620                 .type = HDA_FIXUP_FUNC,
7621                 .v.func = alc_fixup_sku_ignore,
7622         },
7623         [ALC662_FIXUP_HP_RP5800] = {
7624                 .type = HDA_FIXUP_PINS,
7625                 .v.pins = (const struct hda_pintbl[]) {
7626                         { 0x14, 0x0221201f }, /* HP out */
7627                         { }
7628                 },
7629                 .chained = true,
7630                 .chain_id = ALC662_FIXUP_SKU_IGNORE
7631         },
7632         [ALC662_FIXUP_ASUS_MODE1] = {
7633                 .type = HDA_FIXUP_PINS,
7634                 .v.pins = (const struct hda_pintbl[]) {
7635                         { 0x14, 0x99130110 }, /* speaker */
7636                         { 0x18, 0x01a19c20 }, /* mic */
7637                         { 0x19, 0x99a3092f }, /* int-mic */
7638                         { 0x21, 0x0121401f }, /* HP out */
7639                         { }
7640                 },
7641                 .chained = true,
7642                 .chain_id = ALC662_FIXUP_SKU_IGNORE
7643         },
7644         [ALC662_FIXUP_ASUS_MODE2] = {
7645                 .type = HDA_FIXUP_PINS,
7646                 .v.pins = (const struct hda_pintbl[]) {
7647                         { 0x14, 0x99130110 }, /* speaker */
7648                         { 0x18, 0x01a19820 }, /* mic */
7649                         { 0x19, 0x99a3092f }, /* int-mic */
7650                         { 0x1b, 0x0121401f }, /* HP out */
7651                         { }
7652                 },
7653                 .chained = true,
7654                 .chain_id = ALC662_FIXUP_SKU_IGNORE
7655         },
7656         [ALC662_FIXUP_ASUS_MODE3] = {
7657                 .type = HDA_FIXUP_PINS,
7658                 .v.pins = (const struct hda_pintbl[]) {
7659                         { 0x14, 0x99130110 }, /* speaker */
7660                         { 0x15, 0x0121441f }, /* HP */
7661                         { 0x18, 0x01a19840 }, /* mic */
7662                         { 0x19, 0x99a3094f }, /* int-mic */
7663                         { 0x21, 0x01211420 }, /* HP2 */
7664                         { }
7665                 },
7666                 .chained = true,
7667                 .chain_id = ALC662_FIXUP_SKU_IGNORE
7668         },
7669         [ALC662_FIXUP_ASUS_MODE4] = {
7670                 .type = HDA_FIXUP_PINS,
7671                 .v.pins = (const struct hda_pintbl[]) {
7672                         { 0x14, 0x99130110 }, /* speaker */
7673                         { 0x16, 0x99130111 }, /* speaker */
7674                         { 0x18, 0x01a19840 }, /* mic */
7675                         { 0x19, 0x99a3094f }, /* int-mic */
7676                         { 0x21, 0x0121441f }, /* HP */
7677                         { }
7678                 },
7679                 .chained = true,
7680                 .chain_id = ALC662_FIXUP_SKU_IGNORE
7681         },
7682         [ALC662_FIXUP_ASUS_MODE5] = {
7683                 .type = HDA_FIXUP_PINS,
7684                 .v.pins = (const struct hda_pintbl[]) {
7685                         { 0x14, 0x99130110 }, /* speaker */
7686                         { 0x15, 0x0121441f }, /* HP */
7687                         { 0x16, 0x99130111 }, /* speaker */
7688                         { 0x18, 0x01a19840 }, /* mic */
7689                         { 0x19, 0x99a3094f }, /* int-mic */
7690                         { }
7691                 },
7692                 .chained = true,
7693                 .chain_id = ALC662_FIXUP_SKU_IGNORE
7694         },
7695         [ALC662_FIXUP_ASUS_MODE6] = {
7696                 .type = HDA_FIXUP_PINS,
7697                 .v.pins = (const struct hda_pintbl[]) {
7698                         { 0x14, 0x99130110 }, /* speaker */
7699                         { 0x15, 0x01211420 }, /* HP2 */
7700                         { 0x18, 0x01a19840 }, /* mic */
7701                         { 0x19, 0x99a3094f }, /* int-mic */
7702                         { 0x1b, 0x0121441f }, /* HP */
7703                         { }
7704                 },
7705                 .chained = true,
7706                 .chain_id = ALC662_FIXUP_SKU_IGNORE
7707         },
7708         [ALC662_FIXUP_ASUS_MODE7] = {
7709                 .type = HDA_FIXUP_PINS,
7710                 .v.pins = (const struct hda_pintbl[]) {
7711                         { 0x14, 0x99130110 }, /* speaker */
7712                         { 0x17, 0x99130111 }, /* speaker */
7713                         { 0x18, 0x01a19840 }, /* mic */
7714                         { 0x19, 0x99a3094f }, /* int-mic */
7715                         { 0x1b, 0x01214020 }, /* HP */
7716                         { 0x21, 0x0121401f }, /* HP */
7717                         { }
7718                 },
7719                 .chained = true,
7720                 .chain_id = ALC662_FIXUP_SKU_IGNORE
7721         },
7722         [ALC662_FIXUP_ASUS_MODE8] = {
7723                 .type = HDA_FIXUP_PINS,
7724                 .v.pins = (const struct hda_pintbl[]) {
7725                         { 0x14, 0x99130110 }, /* speaker */
7726                         { 0x12, 0x99a30970 }, /* int-mic */
7727                         { 0x15, 0x01214020 }, /* HP */
7728                         { 0x17, 0x99130111 }, /* speaker */
7729                         { 0x18, 0x01a19840 }, /* mic */
7730                         { 0x21, 0x0121401f }, /* HP */
7731                         { }
7732                 },
7733                 .chained = true,
7734                 .chain_id = ALC662_FIXUP_SKU_IGNORE
7735         },
7736         [ALC662_FIXUP_NO_JACK_DETECT] = {
7737                 .type = HDA_FIXUP_FUNC,
7738                 .v.func = alc_fixup_no_jack_detect,
7739         },
7740         [ALC662_FIXUP_ZOTAC_Z68] = {
7741                 .type = HDA_FIXUP_PINS,
7742                 .v.pins = (const struct hda_pintbl[]) {
7743                         { 0x1b, 0x02214020 }, /* Front HP */
7744                         { }
7745                 }
7746         },
7747         [ALC662_FIXUP_INV_DMIC] = {
7748                 .type = HDA_FIXUP_FUNC,
7749                 .v.func = alc_fixup_inv_dmic,
7750         },
7751         [ALC668_FIXUP_DELL_XPS13] = {
7752                 .type = HDA_FIXUP_FUNC,
7753                 .v.func = alc_fixup_dell_xps13,
7754                 .chained = true,
7755                 .chain_id = ALC668_FIXUP_DELL_DISABLE_AAMIX
7756         },
7757         [ALC668_FIXUP_DELL_DISABLE_AAMIX] = {
7758                 .type = HDA_FIXUP_FUNC,
7759                 .v.func = alc_fixup_disable_aamix,
7760                 .chained = true,
7761                 .chain_id = ALC668_FIXUP_DELL_MIC_NO_PRESENCE
7762         },
7763         [ALC668_FIXUP_AUTO_MUTE] = {
7764                 .type = HDA_FIXUP_FUNC,
7765                 .v.func = alc_fixup_auto_mute_via_amp,
7766                 .chained = true,
7767                 .chain_id = ALC668_FIXUP_DELL_MIC_NO_PRESENCE
7768         },
7769         [ALC662_FIXUP_DELL_MIC_NO_PRESENCE] = {
7770                 .type = HDA_FIXUP_PINS,
7771                 .v.pins = (const struct hda_pintbl[]) {
7772                         { 0x19, 0x03a1113c }, /* use as headset mic, without its own jack detect */
7773                         /* headphone mic by setting pin control of 0x1b (headphone out) to in + vref_50 */
7774                         { }
7775                 },
7776                 .chained = true,
7777                 .chain_id = ALC662_FIXUP_HEADSET_MODE
7778         },
7779         [ALC662_FIXUP_HEADSET_MODE] = {
7780                 .type = HDA_FIXUP_FUNC,
7781                 .v.func = alc_fixup_headset_mode_alc662,
7782         },
7783         [ALC668_FIXUP_DELL_MIC_NO_PRESENCE] = {
7784                 .type = HDA_FIXUP_PINS,
7785                 .v.pins = (const struct hda_pintbl[]) {
7786                         { 0x19, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
7787                         { 0x1b, 0x03a1113c }, /* use as headset mic, without its own jack detect */
7788                         { }
7789                 },
7790                 .chained = true,
7791                 .chain_id = ALC668_FIXUP_HEADSET_MODE
7792         },
7793         [ALC668_FIXUP_HEADSET_MODE] = {
7794                 .type = HDA_FIXUP_FUNC,
7795                 .v.func = alc_fixup_headset_mode_alc668,
7796         },
7797         [ALC662_FIXUP_BASS_MODE4_CHMAP] = {
7798                 .type = HDA_FIXUP_FUNC,
7799                 .v.func = alc_fixup_bass_chmap,
7800                 .chained = true,
7801                 .chain_id = ALC662_FIXUP_ASUS_MODE4
7802         },
7803         [ALC662_FIXUP_BASS_16] = {
7804                 .type = HDA_FIXUP_PINS,
7805                 .v.pins = (const struct hda_pintbl[]) {
7806                         {0x16, 0x80106111}, /* bass speaker */
7807                         {}
7808                 },
7809                 .chained = true,
7810                 .chain_id = ALC662_FIXUP_BASS_CHMAP,
7811         },
7812         [ALC662_FIXUP_BASS_1A] = {
7813                 .type = HDA_FIXUP_PINS,
7814                 .v.pins = (const struct hda_pintbl[]) {
7815                         {0x1a, 0x80106111}, /* bass speaker */
7816                         {}
7817                 },
7818                 .chained = true,
7819                 .chain_id = ALC662_FIXUP_BASS_CHMAP,
7820         },
7821         [ALC662_FIXUP_BASS_CHMAP] = {
7822                 .type = HDA_FIXUP_FUNC,
7823                 .v.func = alc_fixup_bass_chmap,
7824         },
7825         [ALC662_FIXUP_ASUS_Nx50] = {
7826                 .type = HDA_FIXUP_FUNC,
7827                 .v.func = alc_fixup_auto_mute_via_amp,
7828                 .chained = true,
7829                 .chain_id = ALC662_FIXUP_BASS_1A
7830         },
7831         [ALC668_FIXUP_ASUS_Nx51_HEADSET_MODE] = {
7832                 .type = HDA_FIXUP_FUNC,
7833                 .v.func = alc_fixup_headset_mode_alc668,
7834                 .chain_id = ALC662_FIXUP_BASS_CHMAP
7835         },
7836         [ALC668_FIXUP_ASUS_Nx51] = {
7837                 .type = HDA_FIXUP_PINS,
7838                 .v.pins = (const struct hda_pintbl[]) {
7839                         { 0x19, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
7840                         { 0x1a, 0x90170151 }, /* bass speaker */
7841                         { 0x1b, 0x03a1113c }, /* use as headset mic, without its own jack detect */
7842                         {}
7843                 },
7844                 .chained = true,
7845                 .chain_id = ALC668_FIXUP_ASUS_Nx51_HEADSET_MODE,
7846         },
7847         [ALC668_FIXUP_MIC_COEF] = {
7848                 .type = HDA_FIXUP_VERBS,
7849                 .v.verbs = (const struct hda_verb[]) {
7850                         { 0x20, AC_VERB_SET_COEF_INDEX, 0xc3 },
7851                         { 0x20, AC_VERB_SET_PROC_COEF, 0x4000 },
7852                         {}
7853                 },
7854         },
7855         [ALC668_FIXUP_ASUS_G751] = {
7856                 .type = HDA_FIXUP_PINS,
7857                 .v.pins = (const struct hda_pintbl[]) {
7858                         { 0x16, 0x0421101f }, /* HP */
7859                         {}
7860                 },
7861                 .chained = true,
7862                 .chain_id = ALC668_FIXUP_MIC_COEF
7863         },
7864         [ALC891_FIXUP_HEADSET_MODE] = {
7865                 .type = HDA_FIXUP_FUNC,
7866                 .v.func = alc_fixup_headset_mode,
7867         },
7868         [ALC891_FIXUP_DELL_MIC_NO_PRESENCE] = {
7869                 .type = HDA_FIXUP_PINS,
7870                 .v.pins = (const struct hda_pintbl[]) {
7871                         { 0x19, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
7872                         { 0x1b, 0x03a1113c }, /* use as headset mic, without its own jack detect */
7873                         { }
7874                 },
7875                 .chained = true,
7876                 .chain_id = ALC891_FIXUP_HEADSET_MODE
7877         },
7878         [ALC662_FIXUP_ACER_VERITON] = {
7879                 .type = HDA_FIXUP_PINS,
7880                 .v.pins = (const struct hda_pintbl[]) {
7881                         { 0x15, 0x50170120 }, /* no internal speaker */
7882                         { }
7883                 }
7884         },
7885         [ALC892_FIXUP_ASROCK_MOBO] = {
7886                 .type = HDA_FIXUP_PINS,
7887                 .v.pins = (const struct hda_pintbl[]) {
7888                         { 0x15, 0x40f000f0 }, /* disabled */
7889                         { 0x16, 0x40f000f0 }, /* disabled */
7890                         { }
7891                 }
7892         },
7893         [ALC662_FIXUP_USI_FUNC] = {
7894                 .type = HDA_FIXUP_FUNC,
7895                 .v.func = alc662_fixup_usi_headset_mic,
7896         },
7897         [ALC662_FIXUP_USI_HEADSET_MODE] = {
7898                 .type = HDA_FIXUP_PINS,
7899                 .v.pins = (const struct hda_pintbl[]) {
7900                         { 0x19, 0x02a1913c }, /* use as headset mic, without its own jack detect */
7901                         { 0x18, 0x01a1903d },
7902                         { }
7903                 },
7904                 .chained = true,
7905                 .chain_id = ALC662_FIXUP_USI_FUNC
7906         },
7907         [ALC662_FIXUP_LENOVO_MULTI_CODECS] = {
7908                 .type = HDA_FIXUP_FUNC,
7909                 .v.func = alc233_alc662_fixup_lenovo_dual_codecs,
7910         },
7911 };
7912
7913 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
7914         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
7915         SND_PCI_QUIRK(0x1025, 0x022f, "Acer Aspire One", ALC662_FIXUP_INV_DMIC),
7916         SND_PCI_QUIRK(0x1025, 0x0241, "Packard Bell DOTS", ALC662_FIXUP_INV_DMIC),
7917         SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
7918         SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
7919         SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
7920         SND_PCI_QUIRK(0x1025, 0x034a, "Gateway LT27", ALC662_FIXUP_INV_DMIC),
7921         SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
7922         SND_PCI_QUIRK(0x1028, 0x05d8, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
7923         SND_PCI_QUIRK(0x1028, 0x05db, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
7924         SND_PCI_QUIRK(0x1028, 0x05fe, "Dell XPS 15", ALC668_FIXUP_DELL_XPS13),
7925         SND_PCI_QUIRK(0x1028, 0x060a, "Dell XPS 13", ALC668_FIXUP_DELL_XPS13),
7926         SND_PCI_QUIRK(0x1028, 0x060d, "Dell M3800", ALC668_FIXUP_DELL_XPS13),
7927         SND_PCI_QUIRK(0x1028, 0x0625, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
7928         SND_PCI_QUIRK(0x1028, 0x0626, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
7929         SND_PCI_QUIRK(0x1028, 0x0696, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
7930         SND_PCI_QUIRK(0x1028, 0x0698, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
7931         SND_PCI_QUIRK(0x1028, 0x069f, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
7932         SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
7933         SND_PCI_QUIRK(0x1043, 0x1080, "Asus UX501VW", ALC668_FIXUP_HEADSET_MODE),
7934         SND_PCI_QUIRK(0x1043, 0x11cd, "Asus N550", ALC662_FIXUP_ASUS_Nx50),
7935         SND_PCI_QUIRK(0x1043, 0x13df, "Asus N550JX", ALC662_FIXUP_BASS_1A),
7936         SND_PCI_QUIRK(0x1043, 0x129d, "Asus N750", ALC662_FIXUP_ASUS_Nx50),
7937         SND_PCI_QUIRK(0x1043, 0x12ff, "ASUS G751", ALC668_FIXUP_ASUS_G751),
7938         SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_BASS_MODE4_CHMAP),
7939         SND_PCI_QUIRK(0x1043, 0x15a7, "ASUS UX51VZH", ALC662_FIXUP_BASS_16),
7940         SND_PCI_QUIRK(0x1043, 0x177d, "ASUS N551", ALC668_FIXUP_ASUS_Nx51),
7941         SND_PCI_QUIRK(0x1043, 0x17bd, "ASUS N751", ALC668_FIXUP_ASUS_Nx51),
7942         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71SL", ALC662_FIXUP_ASUS_MODE8),
7943         SND_PCI_QUIRK(0x1043, 0x1b73, "ASUS N55SF", ALC662_FIXUP_BASS_16),
7944         SND_PCI_QUIRK(0x1043, 0x1bf3, "ASUS N76VZ", ALC662_FIXUP_BASS_MODE4_CHMAP),
7945         SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
7946         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
7947         SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
7948         SND_PCI_QUIRK(0x14cd, 0x5003, "USI", ALC662_FIXUP_USI_HEADSET_MODE),
7949         SND_PCI_QUIRK(0x17aa, 0x1036, "Lenovo P520", ALC662_FIXUP_LENOVO_MULTI_CODECS),
7950         SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
7951         SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
7952         SND_PCI_QUIRK(0x1849, 0x5892, "ASRock B150M", ALC892_FIXUP_ASROCK_MOBO),
7953         SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
7954         SND_PCI_QUIRK(0x1b0a, 0x01b8, "ACER Veriton", ALC662_FIXUP_ACER_VERITON),
7955         SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
7956
7957 #if 0
7958         /* Below is a quirk table taken from the old code.
7959          * Basically the device should work as is without the fixup table.
7960          * If BIOS doesn't give a proper info, enable the corresponding
7961          * fixup entry.
7962          */
7963         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7964         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7965         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7966         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7967         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7968         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7969         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7970         SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7971         SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7972         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7973         SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7974         SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7975         SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7976         SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7977         SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7978         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7979         SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7980         SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7981         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7982         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7983         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7984         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7985         SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7986         SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7987         SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7988         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7989         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7990         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7991         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7992         SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7993         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7994         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7995         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7996         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7997         SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7998         SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7999         SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
8000         SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
8001         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
8002         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
8003         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
8004         SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
8005         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
8006         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
8007         SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
8008         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
8009         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
8010         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
8011         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
8012         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
8013 #endif
8014         {}
8015 };
8016
8017 static const struct hda_model_fixup alc662_fixup_models[] = {
8018         {.id = ALC272_FIXUP_MARIO, .name = "mario"},
8019         {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
8020         {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
8021         {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
8022         {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
8023         {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
8024         {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
8025         {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
8026         {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
8027         {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
8028         {.id = ALC668_FIXUP_DELL_MIC_NO_PRESENCE, .name = "dell-headset-multi"},
8029         {.id = ALC662_FIXUP_LENOVO_MULTI_CODECS, .name = "dual-codecs"},
8030         {}
8031 };
8032
8033 static const struct snd_hda_pin_quirk alc662_pin_fixup_tbl[] = {
8034         SND_HDA_PIN_QUIRK(0x10ec0867, 0x1028, "Dell", ALC891_FIXUP_DELL_MIC_NO_PRESENCE,
8035                 {0x17, 0x02211010},
8036                 {0x18, 0x01a19030},
8037                 {0x1a, 0x01813040},
8038                 {0x21, 0x01014020}),
8039         SND_HDA_PIN_QUIRK(0x10ec0662, 0x1028, "Dell", ALC662_FIXUP_DELL_MIC_NO_PRESENCE,
8040                 {0x14, 0x01014010},
8041                 {0x18, 0x01a19020},
8042                 {0x1a, 0x0181302f},
8043                 {0x1b, 0x0221401f}),
8044         SND_HDA_PIN_QUIRK(0x10ec0668, 0x1028, "Dell", ALC668_FIXUP_AUTO_MUTE,
8045                 {0x12, 0x99a30130},
8046                 {0x14, 0x90170110},
8047                 {0x15, 0x0321101f},
8048                 {0x16, 0x03011020}),
8049         SND_HDA_PIN_QUIRK(0x10ec0668, 0x1028, "Dell", ALC668_FIXUP_AUTO_MUTE,
8050                 {0x12, 0x99a30140},
8051                 {0x14, 0x90170110},
8052                 {0x15, 0x0321101f},
8053                 {0x16, 0x03011020}),
8054         SND_HDA_PIN_QUIRK(0x10ec0668, 0x1028, "Dell", ALC668_FIXUP_AUTO_MUTE,
8055                 {0x12, 0x99a30150},
8056                 {0x14, 0x90170110},
8057                 {0x15, 0x0321101f},
8058                 {0x16, 0x03011020}),
8059         SND_HDA_PIN_QUIRK(0x10ec0668, 0x1028, "Dell", ALC668_FIXUP_AUTO_MUTE,
8060                 {0x14, 0x90170110},
8061                 {0x15, 0x0321101f},
8062                 {0x16, 0x03011020}),
8063         SND_HDA_PIN_QUIRK(0x10ec0668, 0x1028, "Dell XPS 15", ALC668_FIXUP_AUTO_MUTE,
8064                 {0x12, 0x90a60130},
8065                 {0x14, 0x90170110},
8066                 {0x15, 0x0321101f}),
8067         {}
8068 };
8069
8070 /*
8071  */
8072 static int patch_alc662(struct hda_codec *codec)
8073 {
8074         struct alc_spec *spec;
8075         int err;
8076
8077         err = alc_alloc_spec(codec, 0x0b);
8078         if (err < 0)
8079                 return err;
8080
8081         spec = codec->spec;
8082
8083         spec->shutup = alc_eapd_shutup;
8084
8085         /* handle multiple HPs as is */
8086         spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
8087
8088         alc_fix_pll_init(codec, 0x20, 0x04, 15);
8089
8090         switch (codec->core.vendor_id) {
8091         case 0x10ec0668:
8092                 spec->init_hook = alc668_restore_default_value;
8093                 break;
8094         }
8095
8096         snd_hda_pick_fixup(codec, alc662_fixup_models,
8097                        alc662_fixup_tbl, alc662_fixups);
8098         snd_hda_pick_pin_fixup(codec, alc662_pin_fixup_tbl, alc662_fixups);
8099         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
8100
8101         alc_auto_parse_customize_define(codec);
8102
8103         if (has_cdefine_beep(codec))
8104                 spec->gen.beep_nid = 0x01;
8105
8106         if ((alc_get_coef0(codec) & (1 << 14)) &&
8107             codec->bus->pci && codec->bus->pci->subsystem_vendor == 0x1025 &&
8108             spec->cdefine.platform_type == 1) {
8109                 err = alc_codec_rename(codec, "ALC272X");
8110                 if (err < 0)
8111                         goto error;
8112         }
8113
8114         /* automatic parse from the BIOS config */
8115         err = alc662_parse_auto_config(codec);
8116         if (err < 0)
8117                 goto error;
8118
8119         if (!spec->gen.no_analog && spec->gen.beep_nid) {
8120                 switch (codec->core.vendor_id) {
8121                 case 0x10ec0662:
8122                         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
8123                         break;
8124                 case 0x10ec0272:
8125                 case 0x10ec0663:
8126                 case 0x10ec0665:
8127                 case 0x10ec0668:
8128                         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
8129                         break;
8130                 case 0x10ec0273:
8131                         set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
8132                         break;
8133                 }
8134         }
8135
8136         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
8137
8138         return 0;
8139
8140  error:
8141         alc_free(codec);
8142         return err;
8143 }
8144
8145 /*
8146  * ALC680 support
8147  */
8148
8149 static int alc680_parse_auto_config(struct hda_codec *codec)
8150 {
8151         return alc_parse_auto_config(codec, NULL, NULL);
8152 }
8153
8154 /*
8155  */
8156 static int patch_alc680(struct hda_codec *codec)
8157 {
8158         int err;
8159
8160         /* ALC680 has no aa-loopback mixer */
8161         err = alc_alloc_spec(codec, 0);
8162         if (err < 0)
8163                 return err;
8164
8165         /* automatic parse from the BIOS config */
8166         err = alc680_parse_auto_config(codec);
8167         if (err < 0) {
8168                 alc_free(codec);
8169                 return err;
8170         }
8171
8172         return 0;
8173 }
8174
8175 /*
8176  * patch entries
8177  */
8178 static const struct hda_device_id snd_hda_id_realtek[] = {
8179         HDA_CODEC_ENTRY(0x10ec0215, "ALC215", patch_alc269),
8180         HDA_CODEC_ENTRY(0x10ec0221, "ALC221", patch_alc269),
8181         HDA_CODEC_ENTRY(0x10ec0225, "ALC225", patch_alc269),
8182         HDA_CODEC_ENTRY(0x10ec0231, "ALC231", patch_alc269),
8183         HDA_CODEC_ENTRY(0x10ec0233, "ALC233", patch_alc269),
8184         HDA_CODEC_ENTRY(0x10ec0234, "ALC234", patch_alc269),
8185         HDA_CODEC_ENTRY(0x10ec0235, "ALC233", patch_alc269),
8186         HDA_CODEC_ENTRY(0x10ec0236, "ALC236", patch_alc269),
8187         HDA_CODEC_ENTRY(0x10ec0255, "ALC255", patch_alc269),
8188         HDA_CODEC_ENTRY(0x10ec0256, "ALC256", patch_alc269),
8189         HDA_CODEC_ENTRY(0x10ec0257, "ALC257", patch_alc269),
8190         HDA_CODEC_ENTRY(0x10ec0260, "ALC260", patch_alc260),
8191         HDA_CODEC_ENTRY(0x10ec0262, "ALC262", patch_alc262),
8192         HDA_CODEC_ENTRY(0x10ec0267, "ALC267", patch_alc268),
8193         HDA_CODEC_ENTRY(0x10ec0268, "ALC268", patch_alc268),
8194         HDA_CODEC_ENTRY(0x10ec0269, "ALC269", patch_alc269),
8195         HDA_CODEC_ENTRY(0x10ec0270, "ALC270", patch_alc269),
8196         HDA_CODEC_ENTRY(0x10ec0272, "ALC272", patch_alc662),
8197         HDA_CODEC_ENTRY(0x10ec0274, "ALC274", patch_alc269),
8198         HDA_CODEC_ENTRY(0x10ec0275, "ALC275", patch_alc269),
8199         HDA_CODEC_ENTRY(0x10ec0276, "ALC276", patch_alc269),
8200         HDA_CODEC_ENTRY(0x10ec0280, "ALC280", patch_alc269),
8201         HDA_CODEC_ENTRY(0x10ec0282, "ALC282", patch_alc269),
8202         HDA_CODEC_ENTRY(0x10ec0283, "ALC283", patch_alc269),
8203         HDA_CODEC_ENTRY(0x10ec0284, "ALC284", patch_alc269),
8204         HDA_CODEC_ENTRY(0x10ec0285, "ALC285", patch_alc269),
8205         HDA_CODEC_ENTRY(0x10ec0286, "ALC286", patch_alc269),
8206         HDA_CODEC_ENTRY(0x10ec0288, "ALC288", patch_alc269),
8207         HDA_CODEC_ENTRY(0x10ec0289, "ALC289", patch_alc269),
8208         HDA_CODEC_ENTRY(0x10ec0290, "ALC290", patch_alc269),
8209         HDA_CODEC_ENTRY(0x10ec0292, "ALC292", patch_alc269),
8210         HDA_CODEC_ENTRY(0x10ec0293, "ALC293", patch_alc269),
8211         HDA_CODEC_ENTRY(0x10ec0294, "ALC294", patch_alc269),
8212         HDA_CODEC_ENTRY(0x10ec0295, "ALC295", patch_alc269),
8213         HDA_CODEC_ENTRY(0x10ec0298, "ALC298", patch_alc269),
8214         HDA_CODEC_ENTRY(0x10ec0299, "ALC299", patch_alc269),
8215         HDA_CODEC_ENTRY(0x10ec0300, "ALC300", patch_alc269),
8216         HDA_CODEC_REV_ENTRY(0x10ec0861, 0x100340, "ALC660", patch_alc861),
8217         HDA_CODEC_ENTRY(0x10ec0660, "ALC660-VD", patch_alc861vd),
8218         HDA_CODEC_ENTRY(0x10ec0861, "ALC861", patch_alc861),
8219         HDA_CODEC_ENTRY(0x10ec0862, "ALC861-VD", patch_alc861vd),
8220         HDA_CODEC_REV_ENTRY(0x10ec0662, 0x100002, "ALC662 rev2", patch_alc882),
8221         HDA_CODEC_REV_ENTRY(0x10ec0662, 0x100101, "ALC662 rev1", patch_alc662),
8222         HDA_CODEC_REV_ENTRY(0x10ec0662, 0x100300, "ALC662 rev3", patch_alc662),
8223         HDA_CODEC_ENTRY(0x10ec0663, "ALC663", patch_alc662),
8224         HDA_CODEC_ENTRY(0x10ec0665, "ALC665", patch_alc662),
8225         HDA_CODEC_ENTRY(0x10ec0667, "ALC667", patch_alc662),
8226         HDA_CODEC_ENTRY(0x10ec0668, "ALC668", patch_alc662),
8227         HDA_CODEC_ENTRY(0x10ec0670, "ALC670", patch_alc662),
8228         HDA_CODEC_ENTRY(0x10ec0671, "ALC671", patch_alc662),
8229         HDA_CODEC_ENTRY(0x10ec0680, "ALC680", patch_alc680),
8230         HDA_CODEC_ENTRY(0x10ec0700, "ALC700", patch_alc269),
8231         HDA_CODEC_ENTRY(0x10ec0701, "ALC701", patch_alc269),
8232         HDA_CODEC_ENTRY(0x10ec0703, "ALC703", patch_alc269),
8233         HDA_CODEC_ENTRY(0x10ec0867, "ALC891", patch_alc662),
8234         HDA_CODEC_ENTRY(0x10ec0880, "ALC880", patch_alc880),
8235         HDA_CODEC_ENTRY(0x10ec0882, "ALC882", patch_alc882),
8236         HDA_CODEC_ENTRY(0x10ec0883, "ALC883", patch_alc882),
8237         HDA_CODEC_REV_ENTRY(0x10ec0885, 0x100101, "ALC889A", patch_alc882),
8238         HDA_CODEC_REV_ENTRY(0x10ec0885, 0x100103, "ALC889A", patch_alc882),
8239         HDA_CODEC_ENTRY(0x10ec0885, "ALC885", patch_alc882),
8240         HDA_CODEC_ENTRY(0x10ec0887, "ALC887", patch_alc882),
8241         HDA_CODEC_REV_ENTRY(0x10ec0888, 0x100101, "ALC1200", patch_alc882),
8242         HDA_CODEC_ENTRY(0x10ec0888, "ALC888", patch_alc882),
8243         HDA_CODEC_ENTRY(0x10ec0889, "ALC889", patch_alc882),
8244         HDA_CODEC_ENTRY(0x10ec0892, "ALC892", patch_alc662),
8245         HDA_CODEC_ENTRY(0x10ec0899, "ALC898", patch_alc882),
8246         HDA_CODEC_ENTRY(0x10ec0900, "ALC1150", patch_alc882),
8247         HDA_CODEC_ENTRY(0x10ec1168, "ALC1220", patch_alc882),
8248         HDA_CODEC_ENTRY(0x10ec1220, "ALC1220", patch_alc882),
8249         {} /* terminator */
8250 };
8251 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_realtek);
8252
8253 MODULE_LICENSE("GPL");
8254 MODULE_DESCRIPTION("Realtek HD-audio codec");
8255
8256 static struct hda_codec_driver realtek_driver = {
8257         .id = snd_hda_id_realtek,
8258 };
8259
8260 module_hda_codec_driver(realtek_driver);