~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/pci/hda/patch_realtek.c

Version: ~ [ linux-5.8-rc4 ] ~ [ linux-5.7.7 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.50 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.131 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.187 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.229 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.229 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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