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