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