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