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