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