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