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