]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - sound/pci/hda/patch_realtek.c
ALSA: hda/realtek - Add more codecs alias name for Dell
[thirdparty/kernel/stable.git] / sound / pci / hda / patch_realtek.c
CommitLineData
1da177e4
LT
1/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
1d045db9 4 * HD audio interface patch for Realtek ALC codecs
1da177e4 5 *
df694daa
KY
6 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
1da177e4 8 * Takashi Iwai <tiwai@suse.de>
409a3e98 9 * Jonathan Woithe <jwoithe@just42.net>
1da177e4
LT
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
1da177e4
LT
26#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
08fb0d0e 30#include <linux/dmi.h>
da155d5b 31#include <linux/module.h>
1da177e4 32#include <sound/core.h>
9ad0e496 33#include <sound/jack.h>
1da177e4
LT
34#include "hda_codec.h"
35#include "hda_local.h"
23d30f28 36#include "hda_auto_parser.h"
1835a0f9 37#include "hda_jack.h"
08c189f2 38#include "hda_generic.h"
1da177e4 39
cd63a5ff
TI
40/* keep halting ALC5505 DSP, for power saving */
41#define HALT_REALTEK_ALC5505
42
1d045db9 43/* unsol event tags */
08c189f2 44#define ALC_DCVOL_EVENT 0x08
d4a86d81 45
df694daa
KY
46/* for GPIO Poll */
47#define GPIO_MASK 0x03
48
4a79ba34
TI
49/* extra amp-initialization sequence types */
50enum {
51 ALC_INIT_NONE,
52 ALC_INIT_DEFAULT,
53 ALC_INIT_GPIO1,
54 ALC_INIT_GPIO2,
55 ALC_INIT_GPIO3,
56};
57
73bdd597
DH
58enum {
59 ALC_HEADSET_MODE_UNKNOWN,
60 ALC_HEADSET_MODE_UNPLUGGED,
61 ALC_HEADSET_MODE_HEADSET,
62 ALC_HEADSET_MODE_MIC,
63 ALC_HEADSET_MODE_HEADPHONE,
64};
65
66enum {
67 ALC_HEADSET_TYPE_UNKNOWN,
68 ALC_HEADSET_TYPE_CTIA,
69 ALC_HEADSET_TYPE_OMTP,
70};
71
da00c244
KY
72struct alc_customize_define {
73 unsigned int sku_cfg;
74 unsigned char port_connectivity;
75 unsigned char check_sum;
76 unsigned char customization;
77 unsigned char external_amp;
78 unsigned int enable_pcbeep:1;
79 unsigned int platform_type:1;
80 unsigned int swap:1;
81 unsigned int override:1;
90622917 82 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
da00c244
KY
83};
84
1da177e4 85struct alc_spec {
08c189f2 86 struct hda_gen_spec gen; /* must be at head */
23d30f28 87
1da177e4 88 /* codec parameterization */
a9111321 89 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
1da177e4 90 unsigned int num_mixers;
45bdd1c1 91 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
1da177e4 92
da00c244 93 struct alc_customize_define cdefine;
08c189f2 94 unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
834be88d 95
08c189f2
TI
96 /* inverted dmic fix */
97 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
98 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
125821ae 99 hda_nid_t inv_dmic_pin;
834be88d 100
08fb0d0e
TI
101 /* mute LED for HP laptops, see alc269_fixup_mic_mute_hook() */
102 int mute_led_polarity;
103 hda_nid_t mute_led_nid;
104
9f5c6faf
TI
105 unsigned int gpio_led; /* used for alc269_fixup_hp_gpio_led() */
106
73bdd597
DH
107 hda_nid_t headset_mic_pin;
108 hda_nid_t headphone_mic_pin;
109 int current_headset_mode;
110 int current_headset_type;
111
ae6b813a
TI
112 /* hooks */
113 void (*init_hook)(struct hda_codec *codec);
83012a7c 114#ifdef CONFIG_PM
c97259df 115 void (*power_hook)(struct hda_codec *codec);
f5de24b0 116#endif
1c716153 117 void (*shutup)(struct hda_codec *codec);
d922b51d 118
4a79ba34 119 int init_amp;
d433a678 120 int codec_variant; /* flag for other variants */
ad60d502 121 bool has_alc5505_dsp;
e64f14f4 122
2c3bf9ab
TI
123 /* for PLL fix */
124 hda_nid_t pll_nid;
125 unsigned int pll_coef_idx, pll_coef_bit;
1bb7e43e 126 unsigned int coef0;
df694daa
KY
127};
128
d88897ea 129/*
1d045db9
TI
130 * Append the given mixer and verb elements for the later use
131 * The mixer array is referred in build_controls(), and init_verbs are
132 * called in init().
d88897ea 133 */
a9111321 134static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
d88897ea
TI
135{
136 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
137 return;
138 spec->mixers[spec->num_mixers++] = mix;
139}
140
df694daa 141/*
1d045db9 142 * GPIO setup tables, used in initialization
df694daa 143 */
bc9f98a9 144/* Enable GPIO mask and set output */
a9111321 145static const struct hda_verb alc_gpio1_init_verbs[] = {
bc9f98a9
KY
146 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
147 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
148 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
149 { }
150};
151
a9111321 152static const struct hda_verb alc_gpio2_init_verbs[] = {
bc9f98a9
KY
153 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
154 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
155 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
156 { }
157};
158
a9111321 159static const struct hda_verb alc_gpio3_init_verbs[] = {
bdd148a3
KY
160 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
161 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
162 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
163 { }
164};
165
2c3bf9ab
TI
166/*
167 * Fix hardware PLL issue
168 * On some codecs, the analog PLL gating control must be off while
169 * the default value is 1.
170 */
171static void alc_fix_pll(struct hda_codec *codec)
172{
173 struct alc_spec *spec = codec->spec;
174 unsigned int val;
175
176 if (!spec->pll_nid)
177 return;
178 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
179 spec->pll_coef_idx);
180 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
181 AC_VERB_GET_PROC_COEF, 0);
182 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
183 spec->pll_coef_idx);
184 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
185 val & ~(1 << spec->pll_coef_bit));
186}
187
188static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
189 unsigned int coef_idx, unsigned int coef_bit)
190{
191 struct alc_spec *spec = codec->spec;
192 spec->pll_nid = nid;
193 spec->pll_coef_idx = coef_idx;
194 spec->pll_coef_bit = coef_bit;
195 alc_fix_pll(codec);
196}
197
cf5a2279 198/* update the master volume per volume-knob's unsol event */
29adc4b9 199static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
cf5a2279
TI
200{
201 unsigned int val;
202 struct snd_kcontrol *kctl;
203 struct snd_ctl_elem_value *uctl;
204
205 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
206 if (!kctl)
207 return;
208 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
209 if (!uctl)
210 return;
29adc4b9 211 val = snd_hda_codec_read(codec, jack->nid, 0,
cf5a2279
TI
212 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
213 val &= HDA_AMP_VOLMASK;
214 uctl->value.integer.value[0] = val;
215 uctl->value.integer.value[1] = val;
216 kctl->put(kctl, uctl);
217 kfree(uctl);
218}
219
29adc4b9 220static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
f21d78e2 221{
29adc4b9
DH
222 /* For some reason, the res given from ALC880 is broken.
223 Here we adjust it properly. */
224 snd_hda_jack_unsol_event(codec, res >> 2);
f21d78e2
TI
225}
226
f9423e7a
KY
227/* additional initialization for ALC888 variants */
228static void alc888_coef_init(struct hda_codec *codec)
229{
230 unsigned int tmp;
231
232 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
233 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
234 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
37db623a 235 if ((tmp & 0xf0) == 0x20)
f9423e7a
KY
236 /* alc888S-VC */
237 snd_hda_codec_read(codec, 0x20, 0,
238 AC_VERB_SET_PROC_COEF, 0x830);
239 else
240 /* alc888-VB */
241 snd_hda_codec_read(codec, 0x20, 0,
242 AC_VERB_SET_PROC_COEF, 0x3030);
243}
244
1d045db9 245/* additional initialization for ALC889 variants */
87a8c370
JK
246static void alc889_coef_init(struct hda_codec *codec)
247{
248 unsigned int tmp;
249
250 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
251 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
252 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
253 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
254}
255
3fb4a508
TI
256/* turn on/off EAPD control (only if available) */
257static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
258{
259 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
260 return;
261 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
262 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
263 on ? 2 : 0);
264}
265
691f1fcc
TI
266/* turn on/off EAPD controls of the codec */
267static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
268{
269 /* We currently only handle front, HP */
39fa84e9
TI
270 static hda_nid_t pins[] = {
271 0x0f, 0x10, 0x14, 0x15, 0
272 };
273 hda_nid_t *p;
274 for (p = pins; *p; p++)
275 set_eapd(codec, *p, on);
691f1fcc
TI
276}
277
1c716153
TI
278/* generic shutup callback;
279 * just turning off EPAD and a little pause for avoiding pop-noise
280 */
281static void alc_eapd_shutup(struct hda_codec *codec)
282{
283 alc_auto_setup_eapd(codec, false);
284 msleep(200);
9bfb2844 285 snd_hda_shutup_pins(codec);
1c716153
TI
286}
287
1d045db9 288/* generic EAPD initialization */
4a79ba34 289static void alc_auto_init_amp(struct hda_codec *codec, int type)
bc9f98a9 290{
4a79ba34 291 unsigned int tmp;
bc9f98a9 292
39fa84e9 293 alc_auto_setup_eapd(codec, true);
4a79ba34
TI
294 switch (type) {
295 case ALC_INIT_GPIO1:
bc9f98a9
KY
296 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
297 break;
4a79ba34 298 case ALC_INIT_GPIO2:
bc9f98a9
KY
299 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
300 break;
4a79ba34 301 case ALC_INIT_GPIO3:
bdd148a3
KY
302 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
303 break;
4a79ba34 304 case ALC_INIT_DEFAULT:
c9b58006
KY
305 switch (codec->vendor_id) {
306 case 0x10ec0260:
307 snd_hda_codec_write(codec, 0x1a, 0,
308 AC_VERB_SET_COEF_INDEX, 7);
309 tmp = snd_hda_codec_read(codec, 0x1a, 0,
310 AC_VERB_GET_PROC_COEF, 0);
311 snd_hda_codec_write(codec, 0x1a, 0,
312 AC_VERB_SET_COEF_INDEX, 7);
313 snd_hda_codec_write(codec, 0x1a, 0,
314 AC_VERB_SET_PROC_COEF,
315 tmp | 0x2010);
316 break;
317 case 0x10ec0262:
318 case 0x10ec0880:
319 case 0x10ec0882:
320 case 0x10ec0883:
321 case 0x10ec0885:
4a5a4c56 322 case 0x10ec0887:
20b67ddd 323 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
87a8c370 324 alc889_coef_init(codec);
c9b58006 325 break;
f9423e7a 326 case 0x10ec0888:
4a79ba34 327 alc888_coef_init(codec);
f9423e7a 328 break;
0aea778e 329#if 0 /* XXX: This may cause the silent output on speaker on some machines */
c9b58006
KY
330 case 0x10ec0267:
331 case 0x10ec0268:
332 snd_hda_codec_write(codec, 0x20, 0,
333 AC_VERB_SET_COEF_INDEX, 7);
334 tmp = snd_hda_codec_read(codec, 0x20, 0,
335 AC_VERB_GET_PROC_COEF, 0);
336 snd_hda_codec_write(codec, 0x20, 0,
ea1fb29a 337 AC_VERB_SET_COEF_INDEX, 7);
c9b58006
KY
338 snd_hda_codec_write(codec, 0x20, 0,
339 AC_VERB_SET_PROC_COEF,
340 tmp | 0x3000);
341 break;
0aea778e 342#endif /* XXX */
bc9f98a9 343 }
4a79ba34
TI
344 break;
345 }
346}
347
08c189f2 348
1d045db9 349/*
08c189f2 350 * Realtek SSID verification
1d045db9 351 */
42cf0d01 352
08c189f2
TI
353/* Could be any non-zero and even value. When used as fixup, tells
354 * the driver to ignore any present sku defines.
355 */
356#define ALC_FIXUP_SKU_IGNORE (2)
1a1455de 357
08c189f2
TI
358static void alc_fixup_sku_ignore(struct hda_codec *codec,
359 const struct hda_fixup *fix, int action)
1a1455de 360{
1a1455de 361 struct alc_spec *spec = codec->spec;
08c189f2
TI
362 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
363 spec->cdefine.fixup = 1;
364 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1a1455de 365 }
1a1455de
TI
366}
367
08c189f2 368static int alc_auto_parse_customize_define(struct hda_codec *codec)
4a79ba34 369{
08c189f2
TI
370 unsigned int ass, tmp, i;
371 unsigned nid = 0;
4a79ba34
TI
372 struct alc_spec *spec = codec->spec;
373
08c189f2 374 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
4a79ba34 375
08c189f2
TI
376 if (spec->cdefine.fixup) {
377 ass = spec->cdefine.sku_cfg;
378 if (ass == ALC_FIXUP_SKU_IGNORE)
379 return -1;
380 goto do_sku;
bb35febd
TI
381 }
382
08c189f2
TI
383 ass = codec->subsystem_id & 0xffff;
384 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
385 goto do_sku;
4a79ba34 386
08c189f2
TI
387 nid = 0x1d;
388 if (codec->vendor_id == 0x10ec0260)
389 nid = 0x17;
390 ass = snd_hda_codec_get_pincfg(codec, nid);
42cf0d01 391
08c189f2
TI
392 if (!(ass & 1)) {
393 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
394 codec->chip_name, ass);
395 return -1;
42cf0d01
DH
396 }
397
08c189f2
TI
398 /* check sum */
399 tmp = 0;
400 for (i = 1; i < 16; i++) {
401 if ((ass >> i) & 1)
402 tmp++;
ae8a60a5 403 }
08c189f2
TI
404 if (((ass >> 16) & 0xf) != tmp)
405 return -1;
ae8a60a5 406
da00c244
KY
407 spec->cdefine.port_connectivity = ass >> 30;
408 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
409 spec->cdefine.check_sum = (ass >> 16) & 0xf;
410 spec->cdefine.customization = ass >> 8;
411do_sku:
412 spec->cdefine.sku_cfg = ass;
413 spec->cdefine.external_amp = (ass & 0x38) >> 3;
414 spec->cdefine.platform_type = (ass & 0x4) >> 2;
415 spec->cdefine.swap = (ass & 0x2) >> 1;
416 spec->cdefine.override = ass & 0x1;
417
418 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
419 nid, spec->cdefine.sku_cfg);
420 snd_printd("SKU: port_connectivity=0x%x\n",
421 spec->cdefine.port_connectivity);
422 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
423 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
424 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
425 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
426 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
427 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
428 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
429
430 return 0;
431}
432
08c189f2
TI
433/* return the position of NID in the list, or -1 if not found */
434static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
435{
436 int i;
437 for (i = 0; i < nums; i++)
438 if (list[i] == nid)
439 return i;
440 return -1;
441}
1d045db9 442/* return true if the given NID is found in the list */
3af9ee6b
TI
443static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
444{
21268961 445 return find_idx_in_nid_list(nid, list, nums) >= 0;
3af9ee6b
TI
446}
447
4a79ba34
TI
448/* check subsystem ID and set up device-specific initialization;
449 * return 1 if initialized, 0 if invalid SSID
450 */
451/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
452 * 31 ~ 16 : Manufacture ID
453 * 15 ~ 8 : SKU ID
454 * 7 ~ 0 : Assembly ID
455 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
456 */
457static int alc_subsystem_id(struct hda_codec *codec,
458 hda_nid_t porta, hda_nid_t porte,
6227cdce 459 hda_nid_t portd, hda_nid_t porti)
4a79ba34
TI
460{
461 unsigned int ass, tmp, i;
462 unsigned nid;
463 struct alc_spec *spec = codec->spec;
464
90622917
DH
465 if (spec->cdefine.fixup) {
466 ass = spec->cdefine.sku_cfg;
467 if (ass == ALC_FIXUP_SKU_IGNORE)
468 return 0;
469 goto do_sku;
470 }
471
4a79ba34
TI
472 ass = codec->subsystem_id & 0xffff;
473 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
474 goto do_sku;
475
476 /* invalid SSID, check the special NID pin defcfg instead */
477 /*
def319f9 478 * 31~30 : port connectivity
4a79ba34
TI
479 * 29~21 : reserve
480 * 20 : PCBEEP input
481 * 19~16 : Check sum (15:1)
482 * 15~1 : Custom
483 * 0 : override
484 */
485 nid = 0x1d;
486 if (codec->vendor_id == 0x10ec0260)
487 nid = 0x17;
488 ass = snd_hda_codec_get_pincfg(codec, nid);
489 snd_printd("realtek: No valid SSID, "
490 "checking pincfg 0x%08x for NID 0x%x\n",
cb6605c1 491 ass, nid);
6227cdce 492 if (!(ass & 1))
4a79ba34
TI
493 return 0;
494 if ((ass >> 30) != 1) /* no physical connection */
495 return 0;
496
497 /* check sum */
498 tmp = 0;
499 for (i = 1; i < 16; i++) {
500 if ((ass >> i) & 1)
501 tmp++;
502 }
503 if (((ass >> 16) & 0xf) != tmp)
504 return 0;
505do_sku:
506 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
507 ass & 0xffff, codec->vendor_id);
508 /*
509 * 0 : override
510 * 1 : Swap Jack
511 * 2 : 0 --> Desktop, 1 --> Laptop
512 * 3~5 : External Amplifier control
513 * 7~6 : Reserved
514 */
515 tmp = (ass & 0x38) >> 3; /* external Amp control */
516 switch (tmp) {
517 case 1:
518 spec->init_amp = ALC_INIT_GPIO1;
519 break;
520 case 3:
521 spec->init_amp = ALC_INIT_GPIO2;
522 break;
523 case 7:
524 spec->init_amp = ALC_INIT_GPIO3;
525 break;
526 case 5:
5a8cfb4e 527 default:
4a79ba34 528 spec->init_amp = ALC_INIT_DEFAULT;
bc9f98a9
KY
529 break;
530 }
ea1fb29a 531
8c427226 532 /* is laptop or Desktop and enable the function "Mute internal speaker
c9b58006
KY
533 * when the external headphone out jack is plugged"
534 */
8c427226 535 if (!(ass & 0x8000))
4a79ba34 536 return 1;
c9b58006
KY
537 /*
538 * 10~8 : Jack location
539 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
540 * 14~13: Resvered
541 * 15 : 1 --> enable the function "Mute internal speaker
542 * when the external headphone out jack is plugged"
543 */
08c189f2
TI
544 if (!spec->gen.autocfg.hp_pins[0] &&
545 !(spec->gen.autocfg.line_out_pins[0] &&
546 spec->gen.autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
01d4825d 547 hda_nid_t nid;
c9b58006
KY
548 tmp = (ass >> 11) & 0x3; /* HP to chassis */
549 if (tmp == 0)
01d4825d 550 nid = porta;
c9b58006 551 else if (tmp == 1)
01d4825d 552 nid = porte;
c9b58006 553 else if (tmp == 2)
01d4825d 554 nid = portd;
6227cdce
KY
555 else if (tmp == 3)
556 nid = porti;
08c189f2
TI
557 if (found_in_nid_list(nid, spec->gen.autocfg.line_out_pins,
558 spec->gen.autocfg.line_outs))
3af9ee6b 559 return 1;
08c189f2 560 spec->gen.autocfg.hp_pins[0] = nid;
c9b58006 561 }
4a79ba34
TI
562 return 1;
563}
ea1fb29a 564
3e6179b8
TI
565/* Check the validity of ALC subsystem-id
566 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
567static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
4a79ba34 568{
3e6179b8 569 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
4a79ba34
TI
570 struct alc_spec *spec = codec->spec;
571 snd_printd("realtek: "
572 "Enable default setup for auto mode as fallback\n");
573 spec->init_amp = ALC_INIT_DEFAULT;
4a79ba34 574 }
21268961 575}
1a1455de 576
1d045db9
TI
577/*
578 * COEF access helper functions
579 */
9a22a8f5
KY
580
581static int alc_read_coefex_idx(struct hda_codec *codec,
582 hda_nid_t nid,
583 unsigned int coef_idx)
274693f3
KY
584{
585 unsigned int val;
9a22a8f5 586 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX,
274693f3 587 coef_idx);
9a22a8f5 588 val = snd_hda_codec_read(codec, nid, 0,
274693f3
KY
589 AC_VERB_GET_PROC_COEF, 0);
590 return val;
591}
592
9a22a8f5
KY
593#define alc_read_coef_idx(codec, coef_idx) \
594 alc_read_coefex_idx(codec, 0x20, coef_idx)
595
596static void alc_write_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
597 unsigned int coef_idx,
977ddd6b
KY
598 unsigned int coef_val)
599{
9a22a8f5 600 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX,
977ddd6b 601 coef_idx);
9a22a8f5 602 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PROC_COEF,
977ddd6b
KY
603 coef_val);
604}
605
9a22a8f5
KY
606#define alc_write_coef_idx(codec, coef_idx, coef_val) \
607 alc_write_coefex_idx(codec, 0x20, coef_idx, coef_val)
608
1bb7e43e
TI
609/* a special bypass for COEF 0; read the cached value at the second time */
610static unsigned int alc_get_coef0(struct hda_codec *codec)
611{
612 struct alc_spec *spec = codec->spec;
613 if (!spec->coef0)
614 spec->coef0 = alc_read_coef_idx(codec, 0);
615 return spec->coef0;
616}
617
1d045db9 618/*
ef8ef5fb 619 */
f9e336f6 620
08c189f2 621static hda_nid_t get_adc_nid(struct hda_codec *codec, int adc_idx, int imux_idx)
f9e336f6 622{
08c189f2
TI
623 struct hda_gen_spec *spec = codec->spec;
624 if (spec->dyn_adc_switch)
625 adc_idx = spec->dyn_adc_idx[imux_idx];
626 return spec->adc_nids[adc_idx];
f9e336f6
TI
627}
628
666a70d4 629static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx)
f9e336f6 630{
f9e336f6 631 struct alc_spec *spec = codec->spec;
08c189f2 632 struct hda_input_mux *imux = &spec->gen.input_mux;
666a70d4
TI
633 struct nid_path *path;
634 hda_nid_t nid;
635 int i, dir, parm;
636 unsigned int val;
f9e336f6 637
666a70d4 638 for (i = 0; i < imux->num_items; i++) {
08c189f2 639 if (spec->gen.imux_pins[i] == spec->inv_dmic_pin)
666a70d4 640 break;
a23b688f 641 }
666a70d4
TI
642 if (i >= imux->num_items)
643 return;
a23b688f 644
08c189f2
TI
645 path = snd_hda_get_nid_path(codec, spec->inv_dmic_pin,
646 get_adc_nid(codec, adc_idx, i));
666a70d4
TI
647 val = path->ctls[NID_PATH_MUTE_CTL];
648 if (!val)
649 return;
650 nid = get_amp_nid_(val);
651 dir = get_amp_direction_(val);
652 parm = AC_AMP_SET_RIGHT |
653 (dir == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT);
a23b688f 654
c4f3ebed 655 /* flush all cached amps at first */
dc870f38 656 snd_hda_codec_flush_cache(codec);
a23b688f 657
666a70d4
TI
658 /* we care only right channel */
659 val = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
660 if (val & 0x80) /* if already muted, we don't need to touch */
661 return;
662 val |= 0x80;
663 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
664 parm | val);
f9e336f6
TI
665}
666
125821ae
TI
667/*
668 * Inverted digital-mic handling
669 *
670 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
671 * gives the additional mute only to the right channel of the digital mic
672 * capture stream. This is a workaround for avoiding the almost silence
673 * by summing the stereo stream from some (known to be ForteMedia)
674 * digital mic unit.
675 *
676 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
677 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
678 * without caching so that the cache can still keep the original value.
679 * The cached value is then restored when the flag is set off or any other
680 * than d-mic is used as the current input source.
681 */
682static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
683{
684 struct alc_spec *spec = codec->spec;
666a70d4 685 int src, nums;
125821ae
TI
686
687 if (!spec->inv_dmic_fixup)
688 return;
689 if (!spec->inv_dmic_muted && !force)
690 return;
08c189f2 691 nums = spec->gen.dyn_adc_switch ? 1 : spec->gen.num_adc_nids;
666a70d4 692 for (src = 0; src < nums; src++) {
125821ae 693 bool dmic_fixup = false;
125821ae
TI
694
695 if (spec->inv_dmic_muted &&
08c189f2 696 spec->gen.imux_pins[spec->gen.cur_mux[src]] == spec->inv_dmic_pin)
125821ae
TI
697 dmic_fixup = true;
698 if (!dmic_fixup && !force)
699 continue;
666a70d4 700 alc_inv_dmic_sync_adc(codec, src);
125821ae
TI
701 }
702}
703
a90229e0
TI
704static void alc_inv_dmic_hook(struct hda_codec *codec,
705 struct snd_ctl_elem_value *ucontrol)
08c189f2
TI
706{
707 alc_inv_dmic_sync(codec, false);
708}
709
125821ae
TI
710static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
711 struct snd_ctl_elem_value *ucontrol)
712{
713 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
714 struct alc_spec *spec = codec->spec;
715
716 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
717 return 0;
718}
719
720static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
721 struct snd_ctl_elem_value *ucontrol)
722{
723 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
724 struct alc_spec *spec = codec->spec;
725 unsigned int val = !ucontrol->value.integer.value[0];
726
727 if (val == spec->inv_dmic_muted)
728 return 0;
729 spec->inv_dmic_muted = val;
730 alc_inv_dmic_sync(codec, true);
731 return 0;
732}
733
734static const struct snd_kcontrol_new alc_inv_dmic_sw = {
735 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
bc549767 736 .name = "Inverted Internal Mic Capture Switch",
125821ae
TI
737 .info = snd_ctl_boolean_mono_info,
738 .get = alc_inv_dmic_sw_get,
739 .put = alc_inv_dmic_sw_put,
740};
741
742static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
743{
744 struct alc_spec *spec = codec->spec;
668d1e96 745
08c189f2 746 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &alc_inv_dmic_sw))
125821ae
TI
747 return -ENOMEM;
748 spec->inv_dmic_fixup = 1;
749 spec->inv_dmic_muted = 0;
750 spec->inv_dmic_pin = nid;
08c189f2 751 spec->gen.cap_sync_hook = alc_inv_dmic_hook;
125821ae
TI
752 return 0;
753}
754
6e72aa5f
TI
755/* typically the digital mic is put at node 0x12 */
756static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1727a771 757 const struct hda_fixup *fix, int action)
6e72aa5f 758{
1727a771 759 if (action == HDA_FIXUP_ACT_PROBE)
6e72aa5f
TI
760 alc_add_inv_dmic_mixer(codec, 0x12);
761}
762
e9edcee0 763
1d045db9
TI
764#ifdef CONFIG_SND_HDA_INPUT_BEEP
765/* additional beep mixers; the actual parameters are overwritten at build */
766static const struct snd_kcontrol_new alc_beep_mixer[] = {
767 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
768 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
16ded525
TI
769 { } /* end */
770};
1d045db9 771#endif
16ded525 772
08c189f2 773static int alc_build_controls(struct hda_codec *codec)
1d045db9
TI
774{
775 struct alc_spec *spec = codec->spec;
08c189f2 776 int i, err;
e9427969 777
08c189f2
TI
778 err = snd_hda_gen_build_controls(codec);
779 if (err < 0)
780 return err;
1da177e4
LT
781
782 for (i = 0; i < spec->num_mixers; i++) {
783 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
784 if (err < 0)
785 return err;
786 }
2134ea4f 787
67d634c0 788#ifdef CONFIG_SND_HDA_INPUT_BEEP
45bdd1c1
TI
789 /* create beep controls if needed */
790 if (spec->beep_amp) {
a9111321 791 const struct snd_kcontrol_new *knew;
45bdd1c1
TI
792 for (knew = alc_beep_mixer; knew->name; knew++) {
793 struct snd_kcontrol *kctl;
794 kctl = snd_ctl_new1(knew, codec);
795 if (!kctl)
08c189f2
TI
796 return -ENOMEM;
797 kctl->private_value = spec->beep_amp;
798 err = snd_hda_ctl_add(codec, 0, kctl);
799 if (err < 0)
800 return err;
1d045db9 801 }
863b4518 802 }
08c189f2 803#endif
1c4a54b4 804
1727a771 805 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD);
1c4a54b4 806 return 0;
a361d84b
KY
807}
808
a361d84b 809
df694daa 810/*
08c189f2 811 * Common callbacks
df694daa 812 */
a361d84b 813
08c189f2 814static int alc_init(struct hda_codec *codec)
1d045db9
TI
815{
816 struct alc_spec *spec = codec->spec;
a361d84b 817
08c189f2
TI
818 if (spec->init_hook)
819 spec->init_hook(codec);
a361d84b 820
08c189f2
TI
821 alc_fix_pll(codec);
822 alc_auto_init_amp(codec, spec->init_amp);
3abf2f36 823
08c189f2 824 snd_hda_gen_init(codec);
a361d84b 825
1727a771 826 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
a361d84b 827
1d045db9
TI
828 return 0;
829}
a361d84b 830
08c189f2 831static inline void alc_shutup(struct hda_codec *codec)
1d045db9
TI
832{
833 struct alc_spec *spec = codec->spec;
a361d84b 834
08c189f2
TI
835 if (spec && spec->shutup)
836 spec->shutup(codec);
9bfb2844
TI
837 else
838 snd_hda_shutup_pins(codec);
1d045db9
TI
839}
840
b67ae3f1
DH
841static void alc_free(struct hda_codec *codec)
842{
843 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
844 snd_hda_gen_free(codec);
845}
2134ea4f 846
08c189f2
TI
847#ifdef CONFIG_PM
848static void alc_power_eapd(struct hda_codec *codec)
1d045db9 849{
08c189f2 850 alc_auto_setup_eapd(codec, false);
1d045db9 851}
2134ea4f 852
08c189f2 853static int alc_suspend(struct hda_codec *codec)
1d045db9
TI
854{
855 struct alc_spec *spec = codec->spec;
08c189f2
TI
856 alc_shutup(codec);
857 if (spec && spec->power_hook)
858 spec->power_hook(codec);
a361d84b
KY
859 return 0;
860}
08c189f2 861#endif
a361d84b 862
08c189f2
TI
863#ifdef CONFIG_PM
864static int alc_resume(struct hda_codec *codec)
1d045db9 865{
08c189f2
TI
866 msleep(150); /* to avoid pop noise */
867 codec->patch_ops.init(codec);
868 snd_hda_codec_resume_amp(codec);
869 snd_hda_codec_resume_cache(codec);
870 alc_inv_dmic_sync(codec, true);
871 hda_call_check_power_status(codec, 0x01);
872 return 0;
1d045db9 873}
08c189f2 874#endif
f6a92248 875
1d045db9 876/*
1d045db9 877 */
08c189f2
TI
878static const struct hda_codec_ops alc_patch_ops = {
879 .build_controls = alc_build_controls,
880 .build_pcms = snd_hda_gen_build_pcms,
881 .init = alc_init,
882 .free = alc_free,
883 .unsol_event = snd_hda_jack_unsol_event,
884#ifdef CONFIG_PM
885 .resume = alc_resume,
08c189f2 886 .suspend = alc_suspend,
fce52a3b 887 .check_power_status = snd_hda_gen_check_power_status,
08c189f2
TI
888#endif
889 .reboot_notify = alc_shutup,
890};
f6a92248 891
f53281e6 892
08c189f2
TI
893/* replace the codec chip_name with the given string */
894static int alc_codec_rename(struct hda_codec *codec, const char *name)
1d045db9 895{
08c189f2
TI
896 kfree(codec->chip_name);
897 codec->chip_name = kstrdup(name, GFP_KERNEL);
898 if (!codec->chip_name) {
899 alc_free(codec);
900 return -ENOMEM;
1d045db9 901 }
a361d84b 902 return 0;
1d045db9 903}
e01bf509 904
e4770629 905/*
4b016931 906 * Rename codecs appropriately from COEF value or subvendor id
e4770629 907 */
08c189f2
TI
908struct alc_codec_rename_table {
909 unsigned int vendor_id;
910 unsigned short coef_mask;
911 unsigned short coef_bits;
912 const char *name;
913};
84898e87 914
4b016931
KY
915struct alc_codec_rename_pci_table {
916 unsigned int codec_vendor_id;
917 unsigned short pci_subvendor;
918 unsigned short pci_subdevice;
919 const char *name;
920};
921
08c189f2
TI
922static struct alc_codec_rename_table rename_tbl[] = {
923 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
924 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
925 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
926 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
927 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
928 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
929 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
930 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
931 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
932 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
933 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
934 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
935 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
936 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
937 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
938 { } /* terminator */
939};
84898e87 940
4b016931
KY
941static struct alc_codec_rename_pci_table rename_pci_tbl[] = {
942 { 0x10ec0280, 0x1028, 0, "ALC3220" },
943 { 0x10ec0282, 0x1028, 0, "ALC3221" },
944 { 0x10ec0283, 0x1028, 0, "ALC3223" },
945 { 0x10ec0292, 0x1028, 0, "ALC3226" },
946 { 0x10ec0255, 0x1028, 0, "ALC3234" },
947 { 0x10ec0668, 0x1028, 0, "ALC3661" },
948 { } /* terminator */
949};
950
08c189f2 951static int alc_codec_rename_from_preset(struct hda_codec *codec)
1d045db9 952{
08c189f2 953 const struct alc_codec_rename_table *p;
4b016931 954 const struct alc_codec_rename_pci_table *q;
60db6b53 955
08c189f2
TI
956 for (p = rename_tbl; p->vendor_id; p++) {
957 if (p->vendor_id != codec->vendor_id)
958 continue;
959 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
960 return alc_codec_rename(codec, p->name);
1d045db9 961 }
4b016931
KY
962
963 for (q = rename_pci_tbl; q->codec_vendor_id; q++) {
964 if (q->codec_vendor_id != codec->vendor_id)
965 continue;
966 if (q->pci_subvendor != codec->bus->pci->subsystem_vendor)
967 continue;
968 if (!q->pci_subdevice ||
969 q->pci_subdevice == codec->bus->pci->subsystem_device)
970 return alc_codec_rename(codec, q->name);
971 }
972
08c189f2 973 return 0;
1d045db9 974}
f53281e6 975
e4770629 976
1d045db9
TI
977/*
978 * Digital-beep handlers
979 */
980#ifdef CONFIG_SND_HDA_INPUT_BEEP
981#define set_beep_amp(spec, nid, idx, dir) \
982 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
84898e87 983
1d045db9 984static const struct snd_pci_quirk beep_white_list[] = {
7110005e 985 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
1d045db9 986 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
8554ee40 987 SND_PCI_QUIRK(0x1043, 0x8376, "EeePC", 1),
1d045db9
TI
988 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
989 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
990 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
78f8baf1 991 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
1d045db9
TI
992 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
993 {}
fe3eb0a7
KY
994};
995
1d045db9
TI
996static inline int has_cdefine_beep(struct hda_codec *codec)
997{
998 struct alc_spec *spec = codec->spec;
999 const struct snd_pci_quirk *q;
1000 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
1001 if (q)
1002 return q->value;
1003 return spec->cdefine.enable_pcbeep;
1004}
1005#else
1006#define set_beep_amp(spec, nid, idx, dir) /* NOP */
1007#define has_cdefine_beep(codec) 0
1008#endif
84898e87 1009
1d045db9
TI
1010/* parse the BIOS configuration and set up the alc_spec */
1011/* return 1 if successful, 0 if the proper config is not found,
1012 * or a negative error code
1013 */
3e6179b8
TI
1014static int alc_parse_auto_config(struct hda_codec *codec,
1015 const hda_nid_t *ignore_nids,
1016 const hda_nid_t *ssid_nids)
1d045db9
TI
1017{
1018 struct alc_spec *spec = codec->spec;
08c189f2 1019 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
1d045db9 1020 int err;
26f5df26 1021
53c334ad
TI
1022 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
1023 spec->parse_flags);
1d045db9
TI
1024 if (err < 0)
1025 return err;
3e6179b8
TI
1026
1027 if (ssid_nids)
1028 alc_ssid_check(codec, ssid_nids);
64154835 1029
08c189f2
TI
1030 err = snd_hda_gen_parse_auto_config(codec, cfg);
1031 if (err < 0)
1032 return err;
070cff4c 1033
1d045db9 1034 return 1;
60db6b53 1035}
f6a92248 1036
3de95173
TI
1037/* common preparation job for alc_spec */
1038static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
1039{
1040 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1041 int err;
1042
1043 if (!spec)
1044 return -ENOMEM;
1045 codec->spec = spec;
08c189f2
TI
1046 snd_hda_gen_spec_init(&spec->gen);
1047 spec->gen.mixer_nid = mixer_nid;
1048 spec->gen.own_eapd_ctl = 1;
1098b7c2 1049 codec->single_adc_amp = 1;
08c189f2
TI
1050 /* FIXME: do we need this for all Realtek codec models? */
1051 codec->spdif_status_reset = 1;
3de95173
TI
1052
1053 err = alc_codec_rename_from_preset(codec);
1054 if (err < 0) {
1055 kfree(spec);
1056 return err;
1057 }
1058 return 0;
1059}
1060
3e6179b8
TI
1061static int alc880_parse_auto_config(struct hda_codec *codec)
1062{
1063 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
7d7eb9ea 1064 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3e6179b8
TI
1065 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
1066}
1067
ee3b2969
TI
1068/*
1069 * ALC880 fix-ups
1070 */
1071enum {
411225a0 1072 ALC880_FIXUP_GPIO1,
ee3b2969
TI
1073 ALC880_FIXUP_GPIO2,
1074 ALC880_FIXUP_MEDION_RIM,
dc6af52d 1075 ALC880_FIXUP_LG,
db8a38e5 1076 ALC880_FIXUP_LG_LW25,
f02aab5d 1077 ALC880_FIXUP_W810,
27e917f8 1078 ALC880_FIXUP_EAPD_COEF,
b9368f5c 1079 ALC880_FIXUP_TCL_S700,
cf5a2279
TI
1080 ALC880_FIXUP_VOL_KNOB,
1081 ALC880_FIXUP_FUJITSU,
ba533818 1082 ALC880_FIXUP_F1734,
817de92f 1083 ALC880_FIXUP_UNIWILL,
967b88c4 1084 ALC880_FIXUP_UNIWILL_DIG,
96e225f6 1085 ALC880_FIXUP_Z71V,
487a588d 1086 ALC880_FIXUP_ASUS_W5A,
67b6ec31
TI
1087 ALC880_FIXUP_3ST_BASE,
1088 ALC880_FIXUP_3ST,
1089 ALC880_FIXUP_3ST_DIG,
1090 ALC880_FIXUP_5ST_BASE,
1091 ALC880_FIXUP_5ST,
1092 ALC880_FIXUP_5ST_DIG,
1093 ALC880_FIXUP_6ST_BASE,
1094 ALC880_FIXUP_6ST,
1095 ALC880_FIXUP_6ST_DIG,
5397145f 1096 ALC880_FIXUP_6ST_AUTOMUTE,
ee3b2969
TI
1097};
1098
cf5a2279
TI
1099/* enable the volume-knob widget support on NID 0x21 */
1100static void alc880_fixup_vol_knob(struct hda_codec *codec,
1727a771 1101 const struct hda_fixup *fix, int action)
cf5a2279 1102{
1727a771 1103 if (action == HDA_FIXUP_ACT_PROBE)
29adc4b9 1104 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
cf5a2279
TI
1105}
1106
1727a771 1107static const struct hda_fixup alc880_fixups[] = {
411225a0 1108 [ALC880_FIXUP_GPIO1] = {
1727a771 1109 .type = HDA_FIXUP_VERBS,
411225a0
TI
1110 .v.verbs = alc_gpio1_init_verbs,
1111 },
ee3b2969 1112 [ALC880_FIXUP_GPIO2] = {
1727a771 1113 .type = HDA_FIXUP_VERBS,
ee3b2969
TI
1114 .v.verbs = alc_gpio2_init_verbs,
1115 },
1116 [ALC880_FIXUP_MEDION_RIM] = {
1727a771 1117 .type = HDA_FIXUP_VERBS,
ee3b2969
TI
1118 .v.verbs = (const struct hda_verb[]) {
1119 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1120 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
1121 { }
1122 },
1123 .chained = true,
1124 .chain_id = ALC880_FIXUP_GPIO2,
1125 },
dc6af52d 1126 [ALC880_FIXUP_LG] = {
1727a771
TI
1127 .type = HDA_FIXUP_PINS,
1128 .v.pins = (const struct hda_pintbl[]) {
dc6af52d
TI
1129 /* disable bogus unused pins */
1130 { 0x16, 0x411111f0 },
1131 { 0x18, 0x411111f0 },
1132 { 0x1a, 0x411111f0 },
1133 { }
1134 }
1135 },
db8a38e5
TI
1136 [ALC880_FIXUP_LG_LW25] = {
1137 .type = HDA_FIXUP_PINS,
1138 .v.pins = (const struct hda_pintbl[]) {
1139 { 0x1a, 0x0181344f }, /* line-in */
1140 { 0x1b, 0x0321403f }, /* headphone */
1141 { }
1142 }
1143 },
f02aab5d 1144 [ALC880_FIXUP_W810] = {
1727a771
TI
1145 .type = HDA_FIXUP_PINS,
1146 .v.pins = (const struct hda_pintbl[]) {
f02aab5d
TI
1147 /* disable bogus unused pins */
1148 { 0x17, 0x411111f0 },
1149 { }
1150 },
1151 .chained = true,
1152 .chain_id = ALC880_FIXUP_GPIO2,
1153 },
27e917f8 1154 [ALC880_FIXUP_EAPD_COEF] = {
1727a771 1155 .type = HDA_FIXUP_VERBS,
27e917f8
TI
1156 .v.verbs = (const struct hda_verb[]) {
1157 /* change to EAPD mode */
1158 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1159 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
1160 {}
1161 },
1162 },
b9368f5c 1163 [ALC880_FIXUP_TCL_S700] = {
1727a771 1164 .type = HDA_FIXUP_VERBS,
b9368f5c
TI
1165 .v.verbs = (const struct hda_verb[]) {
1166 /* change to EAPD mode */
1167 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1168 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
1169 {}
1170 },
1171 .chained = true,
1172 .chain_id = ALC880_FIXUP_GPIO2,
1173 },
cf5a2279 1174 [ALC880_FIXUP_VOL_KNOB] = {
1727a771 1175 .type = HDA_FIXUP_FUNC,
cf5a2279
TI
1176 .v.func = alc880_fixup_vol_knob,
1177 },
1178 [ALC880_FIXUP_FUJITSU] = {
1179 /* override all pins as BIOS on old Amilo is broken */
1727a771
TI
1180 .type = HDA_FIXUP_PINS,
1181 .v.pins = (const struct hda_pintbl[]) {
cf5a2279
TI
1182 { 0x14, 0x0121411f }, /* HP */
1183 { 0x15, 0x99030120 }, /* speaker */
1184 { 0x16, 0x99030130 }, /* bass speaker */
1185 { 0x17, 0x411111f0 }, /* N/A */
1186 { 0x18, 0x411111f0 }, /* N/A */
1187 { 0x19, 0x01a19950 }, /* mic-in */
1188 { 0x1a, 0x411111f0 }, /* N/A */
1189 { 0x1b, 0x411111f0 }, /* N/A */
1190 { 0x1c, 0x411111f0 }, /* N/A */
1191 { 0x1d, 0x411111f0 }, /* N/A */
1192 { 0x1e, 0x01454140 }, /* SPDIF out */
1193 { }
1194 },
1195 .chained = true,
1196 .chain_id = ALC880_FIXUP_VOL_KNOB,
1197 },
ba533818
TI
1198 [ALC880_FIXUP_F1734] = {
1199 /* almost compatible with FUJITSU, but no bass and SPDIF */
1727a771
TI
1200 .type = HDA_FIXUP_PINS,
1201 .v.pins = (const struct hda_pintbl[]) {
ba533818
TI
1202 { 0x14, 0x0121411f }, /* HP */
1203 { 0x15, 0x99030120 }, /* speaker */
1204 { 0x16, 0x411111f0 }, /* N/A */
1205 { 0x17, 0x411111f0 }, /* N/A */
1206 { 0x18, 0x411111f0 }, /* N/A */
1207 { 0x19, 0x01a19950 }, /* mic-in */
1208 { 0x1a, 0x411111f0 }, /* N/A */
1209 { 0x1b, 0x411111f0 }, /* N/A */
1210 { 0x1c, 0x411111f0 }, /* N/A */
1211 { 0x1d, 0x411111f0 }, /* N/A */
1212 { 0x1e, 0x411111f0 }, /* N/A */
1213 { }
1214 },
1215 .chained = true,
1216 .chain_id = ALC880_FIXUP_VOL_KNOB,
1217 },
817de92f
TI
1218 [ALC880_FIXUP_UNIWILL] = {
1219 /* need to fix HP and speaker pins to be parsed correctly */
1727a771
TI
1220 .type = HDA_FIXUP_PINS,
1221 .v.pins = (const struct hda_pintbl[]) {
817de92f
TI
1222 { 0x14, 0x0121411f }, /* HP */
1223 { 0x15, 0x99030120 }, /* speaker */
1224 { 0x16, 0x99030130 }, /* bass speaker */
1225 { }
1226 },
1227 },
967b88c4 1228 [ALC880_FIXUP_UNIWILL_DIG] = {
1727a771
TI
1229 .type = HDA_FIXUP_PINS,
1230 .v.pins = (const struct hda_pintbl[]) {
967b88c4
TI
1231 /* disable bogus unused pins */
1232 { 0x17, 0x411111f0 },
1233 { 0x19, 0x411111f0 },
1234 { 0x1b, 0x411111f0 },
1235 { 0x1f, 0x411111f0 },
1236 { }
1237 }
1238 },
96e225f6 1239 [ALC880_FIXUP_Z71V] = {
1727a771
TI
1240 .type = HDA_FIXUP_PINS,
1241 .v.pins = (const struct hda_pintbl[]) {
96e225f6
TI
1242 /* set up the whole pins as BIOS is utterly broken */
1243 { 0x14, 0x99030120 }, /* speaker */
1244 { 0x15, 0x0121411f }, /* HP */
1245 { 0x16, 0x411111f0 }, /* N/A */
1246 { 0x17, 0x411111f0 }, /* N/A */
1247 { 0x18, 0x01a19950 }, /* mic-in */
1248 { 0x19, 0x411111f0 }, /* N/A */
1249 { 0x1a, 0x01813031 }, /* line-in */
1250 { 0x1b, 0x411111f0 }, /* N/A */
1251 { 0x1c, 0x411111f0 }, /* N/A */
1252 { 0x1d, 0x411111f0 }, /* N/A */
1253 { 0x1e, 0x0144111e }, /* SPDIF */
1254 { }
1255 }
1256 },
487a588d
TI
1257 [ALC880_FIXUP_ASUS_W5A] = {
1258 .type = HDA_FIXUP_PINS,
1259 .v.pins = (const struct hda_pintbl[]) {
1260 /* set up the whole pins as BIOS is utterly broken */
1261 { 0x14, 0x0121411f }, /* HP */
1262 { 0x15, 0x411111f0 }, /* N/A */
1263 { 0x16, 0x411111f0 }, /* N/A */
1264 { 0x17, 0x411111f0 }, /* N/A */
1265 { 0x18, 0x90a60160 }, /* mic */
1266 { 0x19, 0x411111f0 }, /* N/A */
1267 { 0x1a, 0x411111f0 }, /* N/A */
1268 { 0x1b, 0x411111f0 }, /* N/A */
1269 { 0x1c, 0x411111f0 }, /* N/A */
1270 { 0x1d, 0x411111f0 }, /* N/A */
1271 { 0x1e, 0xb743111e }, /* SPDIF out */
1272 { }
1273 },
1274 .chained = true,
1275 .chain_id = ALC880_FIXUP_GPIO1,
1276 },
67b6ec31 1277 [ALC880_FIXUP_3ST_BASE] = {
1727a771
TI
1278 .type = HDA_FIXUP_PINS,
1279 .v.pins = (const struct hda_pintbl[]) {
67b6ec31
TI
1280 { 0x14, 0x01014010 }, /* line-out */
1281 { 0x15, 0x411111f0 }, /* N/A */
1282 { 0x16, 0x411111f0 }, /* N/A */
1283 { 0x17, 0x411111f0 }, /* N/A */
1284 { 0x18, 0x01a19c30 }, /* mic-in */
1285 { 0x19, 0x0121411f }, /* HP */
1286 { 0x1a, 0x01813031 }, /* line-in */
1287 { 0x1b, 0x02a19c40 }, /* front-mic */
1288 { 0x1c, 0x411111f0 }, /* N/A */
1289 { 0x1d, 0x411111f0 }, /* N/A */
1290 /* 0x1e is filled in below */
1291 { 0x1f, 0x411111f0 }, /* N/A */
1292 { }
1293 }
1294 },
1295 [ALC880_FIXUP_3ST] = {
1727a771
TI
1296 .type = HDA_FIXUP_PINS,
1297 .v.pins = (const struct hda_pintbl[]) {
67b6ec31
TI
1298 { 0x1e, 0x411111f0 }, /* N/A */
1299 { }
1300 },
1301 .chained = true,
1302 .chain_id = ALC880_FIXUP_3ST_BASE,
1303 },
1304 [ALC880_FIXUP_3ST_DIG] = {
1727a771
TI
1305 .type = HDA_FIXUP_PINS,
1306 .v.pins = (const struct hda_pintbl[]) {
67b6ec31
TI
1307 { 0x1e, 0x0144111e }, /* SPDIF */
1308 { }
1309 },
1310 .chained = true,
1311 .chain_id = ALC880_FIXUP_3ST_BASE,
1312 },
1313 [ALC880_FIXUP_5ST_BASE] = {
1727a771
TI
1314 .type = HDA_FIXUP_PINS,
1315 .v.pins = (const struct hda_pintbl[]) {
67b6ec31
TI
1316 { 0x14, 0x01014010 }, /* front */
1317 { 0x15, 0x411111f0 }, /* N/A */
1318 { 0x16, 0x01011411 }, /* CLFE */
1319 { 0x17, 0x01016412 }, /* surr */
1320 { 0x18, 0x01a19c30 }, /* mic-in */
1321 { 0x19, 0x0121411f }, /* HP */
1322 { 0x1a, 0x01813031 }, /* line-in */
1323 { 0x1b, 0x02a19c40 }, /* front-mic */
1324 { 0x1c, 0x411111f0 }, /* N/A */
1325 { 0x1d, 0x411111f0 }, /* N/A */
1326 /* 0x1e is filled in below */
1327 { 0x1f, 0x411111f0 }, /* N/A */
1328 { }
1329 }
1330 },
1331 [ALC880_FIXUP_5ST] = {
1727a771
TI
1332 .type = HDA_FIXUP_PINS,
1333 .v.pins = (const struct hda_pintbl[]) {
67b6ec31
TI
1334 { 0x1e, 0x411111f0 }, /* N/A */
1335 { }
1336 },
1337 .chained = true,
1338 .chain_id = ALC880_FIXUP_5ST_BASE,
1339 },
1340 [ALC880_FIXUP_5ST_DIG] = {
1727a771
TI
1341 .type = HDA_FIXUP_PINS,
1342 .v.pins = (const struct hda_pintbl[]) {
67b6ec31
TI
1343 { 0x1e, 0x0144111e }, /* SPDIF */
1344 { }
1345 },
1346 .chained = true,
1347 .chain_id = ALC880_FIXUP_5ST_BASE,
1348 },
1349 [ALC880_FIXUP_6ST_BASE] = {
1727a771
TI
1350 .type = HDA_FIXUP_PINS,
1351 .v.pins = (const struct hda_pintbl[]) {
67b6ec31
TI
1352 { 0x14, 0x01014010 }, /* front */
1353 { 0x15, 0x01016412 }, /* surr */
1354 { 0x16, 0x01011411 }, /* CLFE */
1355 { 0x17, 0x01012414 }, /* side */
1356 { 0x18, 0x01a19c30 }, /* mic-in */
1357 { 0x19, 0x02a19c40 }, /* front-mic */
1358 { 0x1a, 0x01813031 }, /* line-in */
1359 { 0x1b, 0x0121411f }, /* HP */
1360 { 0x1c, 0x411111f0 }, /* N/A */
1361 { 0x1d, 0x411111f0 }, /* N/A */
1362 /* 0x1e is filled in below */
1363 { 0x1f, 0x411111f0 }, /* N/A */
1364 { }
1365 }
1366 },
1367 [ALC880_FIXUP_6ST] = {
1727a771
TI
1368 .type = HDA_FIXUP_PINS,
1369 .v.pins = (const struct hda_pintbl[]) {
67b6ec31
TI
1370 { 0x1e, 0x411111f0 }, /* N/A */
1371 { }
1372 },
1373 .chained = true,
1374 .chain_id = ALC880_FIXUP_6ST_BASE,
1375 },
1376 [ALC880_FIXUP_6ST_DIG] = {
1727a771
TI
1377 .type = HDA_FIXUP_PINS,
1378 .v.pins = (const struct hda_pintbl[]) {
67b6ec31
TI
1379 { 0x1e, 0x0144111e }, /* SPDIF */
1380 { }
1381 },
1382 .chained = true,
1383 .chain_id = ALC880_FIXUP_6ST_BASE,
1384 },
5397145f
TI
1385 [ALC880_FIXUP_6ST_AUTOMUTE] = {
1386 .type = HDA_FIXUP_PINS,
1387 .v.pins = (const struct hda_pintbl[]) {
1388 { 0x1b, 0x0121401f }, /* HP with jack detect */
1389 { }
1390 },
1391 .chained_before = true,
1392 .chain_id = ALC880_FIXUP_6ST_BASE,
1393 },
ee3b2969
TI
1394};
1395
1396static const struct snd_pci_quirk alc880_fixup_tbl[] = {
f02aab5d 1397 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
487a588d 1398 SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS W5A", ALC880_FIXUP_ASUS_W5A),
96e225f6 1399 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
29e3fdcc
TI
1400 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
1401 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
27e917f8 1402 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
967b88c4 1403 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
ba533818 1404 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
817de92f 1405 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
7833c7e8 1406 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
f02aab5d 1407 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
ee3b2969 1408 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
5397145f 1409 SND_PCI_QUIRK(0x1631, 0xe011, "PB 13201056", ALC880_FIXUP_6ST_AUTOMUTE),
ba533818 1410 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
cf5a2279 1411 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
ba533818 1412 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
cf5a2279 1413 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
dc6af52d
TI
1414 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
1415 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
1416 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
db8a38e5 1417 SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_FIXUP_LG_LW25),
b9368f5c 1418 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
67b6ec31
TI
1419
1420 /* Below is the copied entries from alc880_quirks.c.
1421 * It's not quite sure whether BIOS sets the correct pin-config table
1422 * on these machines, thus they are kept to be compatible with
1423 * the old static quirks. Once when it's confirmed to work without
1424 * these overrides, it'd be better to remove.
1425 */
1426 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
1427 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
1428 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
1429 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
1430 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
1431 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
1432 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
1433 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
1434 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
1435 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
1436 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
1437 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
1438 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
1439 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
1440 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
1441 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
1442 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
1443 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
1444 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
1445 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
1446 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
1447 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
1448 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
1449 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1450 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1451 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1452 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
1453 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1454 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
1455 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
1456 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1457 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1458 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
1459 /* default Intel */
1460 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
1461 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
1462 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
1463 {}
1464};
1465
1727a771 1466static const struct hda_model_fixup alc880_fixup_models[] = {
67b6ec31
TI
1467 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
1468 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
1469 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
1470 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
1471 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
1472 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
5397145f 1473 {.id = ALC880_FIXUP_6ST_AUTOMUTE, .name = "6stack-automute"},
ee3b2969
TI
1474 {}
1475};
1476
1477
1d045db9
TI
1478/*
1479 * OK, here we have finally the patch for ALC880
1480 */
1d045db9 1481static int patch_alc880(struct hda_codec *codec)
60db6b53 1482{
1d045db9 1483 struct alc_spec *spec;
1d045db9 1484 int err;
f6a92248 1485
3de95173
TI
1486 err = alc_alloc_spec(codec, 0x0b);
1487 if (err < 0)
1488 return err;
64154835 1489
3de95173 1490 spec = codec->spec;
08c189f2 1491 spec->gen.need_dac_fix = 1;
7504b6cd 1492 spec->gen.beep_nid = 0x01;
f53281e6 1493
1727a771 1494 snd_hda_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
67b6ec31 1495 alc880_fixups);
1727a771 1496 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
ee3b2969 1497
67b6ec31
TI
1498 /* automatic parse from the BIOS config */
1499 err = alc880_parse_auto_config(codec);
1500 if (err < 0)
1501 goto error;
fe3eb0a7 1502
7504b6cd 1503 if (!spec->gen.no_analog)
3e6179b8 1504 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
f53281e6 1505
1d045db9 1506 codec->patch_ops = alc_patch_ops;
29adc4b9
DH
1507 codec->patch_ops.unsol_event = alc880_unsol_event;
1508
f53281e6 1509
1727a771 1510 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
589876e2 1511
1d045db9 1512 return 0;
e16fb6d1
TI
1513
1514 error:
1515 alc_free(codec);
1516 return err;
226b1ec8
KY
1517}
1518
1d045db9 1519
60db6b53 1520/*
1d045db9 1521 * ALC260 support
60db6b53 1522 */
1d045db9 1523static int alc260_parse_auto_config(struct hda_codec *codec)
f6a92248 1524{
1d045db9 1525 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
3e6179b8
TI
1526 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
1527 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
f6a92248
KY
1528}
1529
1d045db9
TI
1530/*
1531 * Pin config fixes
1532 */
1533enum {
ca8f0424
TI
1534 ALC260_FIXUP_HP_DC5750,
1535 ALC260_FIXUP_HP_PIN_0F,
1536 ALC260_FIXUP_COEF,
15317ab2 1537 ALC260_FIXUP_GPIO1,
20f7d928
TI
1538 ALC260_FIXUP_GPIO1_TOGGLE,
1539 ALC260_FIXUP_REPLACER,
0a1c4fa2 1540 ALC260_FIXUP_HP_B1900,
118cb4a4 1541 ALC260_FIXUP_KN1,
39aedee7 1542 ALC260_FIXUP_FSC_S7020,
5ebd3bbd 1543 ALC260_FIXUP_FSC_S7020_JWSE,
d08c5ef2 1544 ALC260_FIXUP_VAIO_PINS,
1d045db9
TI
1545};
1546
20f7d928
TI
1547static void alc260_gpio1_automute(struct hda_codec *codec)
1548{
1549 struct alc_spec *spec = codec->spec;
1550 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
08c189f2 1551 spec->gen.hp_jack_present);
20f7d928
TI
1552}
1553
1554static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
1727a771 1555 const struct hda_fixup *fix, int action)
20f7d928
TI
1556{
1557 struct alc_spec *spec = codec->spec;
1727a771 1558 if (action == HDA_FIXUP_ACT_PROBE) {
20f7d928
TI
1559 /* although the machine has only one output pin, we need to
1560 * toggle GPIO1 according to the jack state
1561 */
08c189f2
TI
1562 spec->gen.automute_hook = alc260_gpio1_automute;
1563 spec->gen.detect_hp = 1;
1564 spec->gen.automute_speaker = 1;
1565 spec->gen.autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
1566 snd_hda_jack_detect_enable_callback(codec, 0x0f, HDA_GEN_HP_EVENT,
1567 snd_hda_gen_hp_automute);
c9ce6b26 1568 snd_hda_add_verbs(codec, alc_gpio1_init_verbs);
20f7d928
TI
1569 }
1570}
1571
118cb4a4 1572static void alc260_fixup_kn1(struct hda_codec *codec,
1727a771 1573 const struct hda_fixup *fix, int action)
118cb4a4
TI
1574{
1575 struct alc_spec *spec = codec->spec;
1727a771 1576 static const struct hda_pintbl pincfgs[] = {
118cb4a4
TI
1577 { 0x0f, 0x02214000 }, /* HP/speaker */
1578 { 0x12, 0x90a60160 }, /* int mic */
1579 { 0x13, 0x02a19000 }, /* ext mic */
1580 { 0x18, 0x01446000 }, /* SPDIF out */
1581 /* disable bogus I/O pins */
1582 { 0x10, 0x411111f0 },
1583 { 0x11, 0x411111f0 },
1584 { 0x14, 0x411111f0 },
1585 { 0x15, 0x411111f0 },
1586 { 0x16, 0x411111f0 },
1587 { 0x17, 0x411111f0 },
1588 { 0x19, 0x411111f0 },
1589 { }
1590 };
1591
1592 switch (action) {
1727a771
TI
1593 case HDA_FIXUP_ACT_PRE_PROBE:
1594 snd_hda_apply_pincfgs(codec, pincfgs);
118cb4a4 1595 break;
1727a771 1596 case HDA_FIXUP_ACT_PROBE:
118cb4a4
TI
1597 spec->init_amp = ALC_INIT_NONE;
1598 break;
1599 }
1600}
1601
39aedee7
TI
1602static void alc260_fixup_fsc_s7020(struct hda_codec *codec,
1603 const struct hda_fixup *fix, int action)
1604{
1605 struct alc_spec *spec = codec->spec;
5ebd3bbd
TI
1606 if (action == HDA_FIXUP_ACT_PROBE)
1607 spec->init_amp = ALC_INIT_NONE;
1608}
39aedee7 1609
5ebd3bbd
TI
1610static void alc260_fixup_fsc_s7020_jwse(struct hda_codec *codec,
1611 const struct hda_fixup *fix, int action)
1612{
1613 struct alc_spec *spec = codec->spec;
1614 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
f811c3cf 1615 spec->gen.add_jack_modes = 1;
5ebd3bbd 1616 spec->gen.hp_mic = 1;
e6e0ee50 1617 }
39aedee7
TI
1618}
1619
1727a771 1620static const struct hda_fixup alc260_fixups[] = {
ca8f0424 1621 [ALC260_FIXUP_HP_DC5750] = {
1727a771
TI
1622 .type = HDA_FIXUP_PINS,
1623 .v.pins = (const struct hda_pintbl[]) {
1d045db9
TI
1624 { 0x11, 0x90130110 }, /* speaker */
1625 { }
1626 }
1627 },
ca8f0424 1628 [ALC260_FIXUP_HP_PIN_0F] = {
1727a771
TI
1629 .type = HDA_FIXUP_PINS,
1630 .v.pins = (const struct hda_pintbl[]) {
ca8f0424
TI
1631 { 0x0f, 0x01214000 }, /* HP */
1632 { }
1633 }
1634 },
1635 [ALC260_FIXUP_COEF] = {
1727a771 1636 .type = HDA_FIXUP_VERBS,
ca8f0424
TI
1637 .v.verbs = (const struct hda_verb[]) {
1638 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1639 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
1640 { }
1641 },
1642 .chained = true,
1643 .chain_id = ALC260_FIXUP_HP_PIN_0F,
1644 },
15317ab2 1645 [ALC260_FIXUP_GPIO1] = {
1727a771 1646 .type = HDA_FIXUP_VERBS,
15317ab2
TI
1647 .v.verbs = alc_gpio1_init_verbs,
1648 },
20f7d928 1649 [ALC260_FIXUP_GPIO1_TOGGLE] = {
1727a771 1650 .type = HDA_FIXUP_FUNC,
20f7d928
TI
1651 .v.func = alc260_fixup_gpio1_toggle,
1652 .chained = true,
1653 .chain_id = ALC260_FIXUP_HP_PIN_0F,
1654 },
1655 [ALC260_FIXUP_REPLACER] = {
1727a771 1656 .type = HDA_FIXUP_VERBS,
20f7d928
TI
1657 .v.verbs = (const struct hda_verb[]) {
1658 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
1659 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
1660 { }
1661 },
1662 .chained = true,
1663 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
1664 },
0a1c4fa2 1665 [ALC260_FIXUP_HP_B1900] = {
1727a771 1666 .type = HDA_FIXUP_FUNC,
0a1c4fa2
TI
1667 .v.func = alc260_fixup_gpio1_toggle,
1668 .chained = true,
1669 .chain_id = ALC260_FIXUP_COEF,
118cb4a4
TI
1670 },
1671 [ALC260_FIXUP_KN1] = {
1727a771 1672 .type = HDA_FIXUP_FUNC,
118cb4a4
TI
1673 .v.func = alc260_fixup_kn1,
1674 },
39aedee7
TI
1675 [ALC260_FIXUP_FSC_S7020] = {
1676 .type = HDA_FIXUP_FUNC,
1677 .v.func = alc260_fixup_fsc_s7020,
1678 },
5ebd3bbd
TI
1679 [ALC260_FIXUP_FSC_S7020_JWSE] = {
1680 .type = HDA_FIXUP_FUNC,
1681 .v.func = alc260_fixup_fsc_s7020_jwse,
1682 .chained = true,
1683 .chain_id = ALC260_FIXUP_FSC_S7020,
1684 },
d08c5ef2
TI
1685 [ALC260_FIXUP_VAIO_PINS] = {
1686 .type = HDA_FIXUP_PINS,
1687 .v.pins = (const struct hda_pintbl[]) {
1688 /* Pin configs are missing completely on some VAIOs */
1689 { 0x0f, 0x01211020 },
1690 { 0x10, 0x0001003f },
1691 { 0x11, 0x411111f0 },
1692 { 0x12, 0x01a15930 },
1693 { 0x13, 0x411111f0 },
1694 { 0x14, 0x411111f0 },
1695 { 0x15, 0x411111f0 },
1696 { 0x16, 0x411111f0 },
1697 { 0x17, 0x411111f0 },
1698 { 0x18, 0x411111f0 },
1699 { 0x19, 0x411111f0 },
1700 { }
1701 }
1702 },
1d045db9
TI
1703};
1704
1705static const struct snd_pci_quirk alc260_fixup_tbl[] = {
15317ab2 1706 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
ca8f0424 1707 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
15317ab2 1708 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
ca8f0424 1709 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
0a1c4fa2 1710 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
d08c5ef2 1711 SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_FIXUP_VAIO_PINS),
0f5a5b85 1712 SND_PCI_QUIRK(0x104d, 0x81e2, "Sony VAIO TX", ALC260_FIXUP_HP_PIN_0F),
39aedee7 1713 SND_PCI_QUIRK(0x10cf, 0x1326, "FSC LifeBook S7020", ALC260_FIXUP_FSC_S7020),
b1f58085 1714 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
118cb4a4 1715 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
20f7d928 1716 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
ca8f0424 1717 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
1d045db9
TI
1718 {}
1719};
1720
5ebd3bbd
TI
1721static const struct hda_model_fixup alc260_fixup_models[] = {
1722 {.id = ALC260_FIXUP_GPIO1, .name = "gpio1"},
1723 {.id = ALC260_FIXUP_COEF, .name = "coef"},
1724 {.id = ALC260_FIXUP_FSC_S7020, .name = "fujitsu"},
1725 {.id = ALC260_FIXUP_FSC_S7020_JWSE, .name = "fujitsu-jwse"},
1726 {}
1727};
1728
1d045db9
TI
1729/*
1730 */
1d045db9 1731static int patch_alc260(struct hda_codec *codec)
977ddd6b 1732{
1d045db9 1733 struct alc_spec *spec;
c3c2c9e7 1734 int err;
1d045db9 1735
3de95173
TI
1736 err = alc_alloc_spec(codec, 0x07);
1737 if (err < 0)
1738 return err;
1d045db9 1739
3de95173 1740 spec = codec->spec;
ea46c3c8
TI
1741 /* as quite a few machines require HP amp for speaker outputs,
1742 * it's easier to enable it unconditionally; even if it's unneeded,
1743 * it's almost harmless.
1744 */
1745 spec->gen.prefer_hp_amp = 1;
7504b6cd 1746 spec->gen.beep_nid = 0x01;
1d045db9 1747
5ebd3bbd
TI
1748 snd_hda_pick_fixup(codec, alc260_fixup_models, alc260_fixup_tbl,
1749 alc260_fixups);
1727a771 1750 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
977ddd6b 1751
c3c2c9e7
TI
1752 /* automatic parse from the BIOS config */
1753 err = alc260_parse_auto_config(codec);
1754 if (err < 0)
1755 goto error;
977ddd6b 1756
7504b6cd 1757 if (!spec->gen.no_analog)
3e6179b8 1758 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
977ddd6b 1759
1d045db9 1760 codec->patch_ops = alc_patch_ops;
1d045db9 1761 spec->shutup = alc_eapd_shutup;
6981d184 1762
1727a771 1763 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
589876e2 1764
1d045db9 1765 return 0;
e16fb6d1
TI
1766
1767 error:
1768 alc_free(codec);
1769 return err;
6981d184
TI
1770}
1771
1d045db9
TI
1772
1773/*
1774 * ALC882/883/885/888/889 support
1775 *
1776 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
1777 * configuration. Each pin widget can choose any input DACs and a mixer.
1778 * Each ADC is connected from a mixer of all inputs. This makes possible
1779 * 6-channel independent captures.
1780 *
1781 * In addition, an independent DAC for the multi-playback (not used in this
1782 * driver yet).
1783 */
1d045db9
TI
1784
1785/*
1786 * Pin config fixes
1787 */
ff818c24 1788enum {
5c0ebfbe
TI
1789 ALC882_FIXUP_ABIT_AW9D_MAX,
1790 ALC882_FIXUP_LENOVO_Y530,
1791 ALC882_FIXUP_PB_M5210,
1792 ALC882_FIXUP_ACER_ASPIRE_7736,
1793 ALC882_FIXUP_ASUS_W90V,
8f239214 1794 ALC889_FIXUP_CD,
5c0ebfbe 1795 ALC889_FIXUP_VAIO_TT,
0e7cc2e7 1796 ALC888_FIXUP_EEE1601,
177943a3 1797 ALC882_FIXUP_EAPD,
7a6069bf 1798 ALC883_FIXUP_EAPD,
8812c4f9 1799 ALC883_FIXUP_ACER_EAPD,
1a97b7f2
TI
1800 ALC882_FIXUP_GPIO1,
1801 ALC882_FIXUP_GPIO2,
eb844d51 1802 ALC882_FIXUP_GPIO3,
68ef0561
TI
1803 ALC889_FIXUP_COEF,
1804 ALC882_FIXUP_ASUS_W2JC,
c3e837bb
TI
1805 ALC882_FIXUP_ACER_ASPIRE_4930G,
1806 ALC882_FIXUP_ACER_ASPIRE_8930G,
1807 ALC882_FIXUP_ASPIRE_8930G_VERBS,
5671087f 1808 ALC885_FIXUP_MACPRO_GPIO,
02a237b2 1809 ALC889_FIXUP_DAC_ROUTE,
1a97b7f2
TI
1810 ALC889_FIXUP_MBP_VREF,
1811 ALC889_FIXUP_IMAC91_VREF,
6e72aa5f 1812 ALC882_FIXUP_INV_DMIC,
e427c237 1813 ALC882_FIXUP_NO_PRIMARY_HP,
ff818c24
TI
1814};
1815
68ef0561 1816static void alc889_fixup_coef(struct hda_codec *codec,
1727a771 1817 const struct hda_fixup *fix, int action)
68ef0561 1818{
1727a771 1819 if (action != HDA_FIXUP_ACT_INIT)
68ef0561
TI
1820 return;
1821 alc889_coef_init(codec);
1822}
1823
5671087f
TI
1824/* toggle speaker-output according to the hp-jack state */
1825static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
1826{
1827 unsigned int gpiostate, gpiomask, gpiodir;
1828
1829 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1830 AC_VERB_GET_GPIO_DATA, 0);
1831
1832 if (!muted)
1833 gpiostate |= (1 << pin);
1834 else
1835 gpiostate &= ~(1 << pin);
1836
1837 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1838 AC_VERB_GET_GPIO_MASK, 0);
1839 gpiomask |= (1 << pin);
1840
1841 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1842 AC_VERB_GET_GPIO_DIRECTION, 0);
1843 gpiodir |= (1 << pin);
1844
1845
1846 snd_hda_codec_write(codec, codec->afg, 0,
1847 AC_VERB_SET_GPIO_MASK, gpiomask);
1848 snd_hda_codec_write(codec, codec->afg, 0,
1849 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1850
1851 msleep(1);
1852
1853 snd_hda_codec_write(codec, codec->afg, 0,
1854 AC_VERB_SET_GPIO_DATA, gpiostate);
1855}
1856
1857/* set up GPIO at initialization */
1858static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
1727a771 1859 const struct hda_fixup *fix, int action)
5671087f 1860{
1727a771 1861 if (action != HDA_FIXUP_ACT_INIT)
5671087f
TI
1862 return;
1863 alc882_gpio_mute(codec, 0, 0);
1864 alc882_gpio_mute(codec, 1, 0);
1865}
1866
02a237b2
TI
1867/* Fix the connection of some pins for ALC889:
1868 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
1869 * work correctly (bko#42740)
1870 */
1871static void alc889_fixup_dac_route(struct hda_codec *codec,
1727a771 1872 const struct hda_fixup *fix, int action)
02a237b2 1873{
1727a771 1874 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
ef8d60fb 1875 /* fake the connections during parsing the tree */
02a237b2
TI
1876 hda_nid_t conn1[2] = { 0x0c, 0x0d };
1877 hda_nid_t conn2[2] = { 0x0e, 0x0f };
1878 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
1879 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
1880 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
1881 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
1727a771 1882 } else if (action == HDA_FIXUP_ACT_PROBE) {
ef8d60fb
TI
1883 /* restore the connections */
1884 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
1885 snd_hda_override_conn_list(codec, 0x14, 5, conn);
1886 snd_hda_override_conn_list(codec, 0x15, 5, conn);
1887 snd_hda_override_conn_list(codec, 0x18, 5, conn);
1888 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
02a237b2
TI
1889 }
1890}
1891
1a97b7f2
TI
1892/* Set VREF on HP pin */
1893static void alc889_fixup_mbp_vref(struct hda_codec *codec,
1727a771 1894 const struct hda_fixup *fix, int action)
1a97b7f2
TI
1895{
1896 struct alc_spec *spec = codec->spec;
1897 static hda_nid_t nids[2] = { 0x14, 0x15 };
1898 int i;
1899
1727a771 1900 if (action != HDA_FIXUP_ACT_INIT)
1a97b7f2
TI
1901 return;
1902 for (i = 0; i < ARRAY_SIZE(nids); i++) {
1903 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
1904 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
1905 continue;
d3f02d60 1906 val = snd_hda_codec_get_pin_target(codec, nids[i]);
1a97b7f2 1907 val |= AC_PINCTL_VREF_80;
cdd03ced 1908 snd_hda_set_pin_ctl(codec, nids[i], val);
08c189f2 1909 spec->gen.keep_vref_in_automute = 1;
1a97b7f2
TI
1910 break;
1911 }
1912}
1913
1914/* Set VREF on speaker pins on imac91 */
1915static void alc889_fixup_imac91_vref(struct hda_codec *codec,
1727a771 1916 const struct hda_fixup *fix, int action)
1a97b7f2
TI
1917{
1918 struct alc_spec *spec = codec->spec;
1919 static hda_nid_t nids[2] = { 0x18, 0x1a };
1920 int i;
1921
1727a771 1922 if (action != HDA_FIXUP_ACT_INIT)
1a97b7f2
TI
1923 return;
1924 for (i = 0; i < ARRAY_SIZE(nids); i++) {
1925 unsigned int val;
d3f02d60 1926 val = snd_hda_codec_get_pin_target(codec, nids[i]);
1a97b7f2 1927 val |= AC_PINCTL_VREF_50;
cdd03ced 1928 snd_hda_set_pin_ctl(codec, nids[i], val);
1a97b7f2 1929 }
08c189f2 1930 spec->gen.keep_vref_in_automute = 1;
1a97b7f2
TI
1931}
1932
e427c237 1933/* Don't take HP output as primary
d9111496
FLVC
1934 * Strangely, the speaker output doesn't work on Vaio Z and some Vaio
1935 * all-in-one desktop PCs (for example VGC-LN51JGB) through DAC 0x05
e427c237
TI
1936 */
1937static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
1727a771 1938 const struct hda_fixup *fix, int action)
e427c237
TI
1939{
1940 struct alc_spec *spec = codec->spec;
da96fb5b 1941 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
08c189f2 1942 spec->gen.no_primary_hp = 1;
da96fb5b
TI
1943 spec->gen.no_multi_io = 1;
1944 }
e427c237
TI
1945}
1946
1727a771 1947static const struct hda_fixup alc882_fixups[] = {
5c0ebfbe 1948 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
1727a771
TI
1949 .type = HDA_FIXUP_PINS,
1950 .v.pins = (const struct hda_pintbl[]) {
1d045db9
TI
1951 { 0x15, 0x01080104 }, /* side */
1952 { 0x16, 0x01011012 }, /* rear */
1953 { 0x17, 0x01016011 }, /* clfe */
2785591a 1954 { }
145a902b
DH
1955 }
1956 },
5c0ebfbe 1957 [ALC882_FIXUP_LENOVO_Y530] = {
1727a771
TI
1958 .type = HDA_FIXUP_PINS,
1959 .v.pins = (const struct hda_pintbl[]) {
1d045db9
TI
1960 { 0x15, 0x99130112 }, /* rear int speakers */
1961 { 0x16, 0x99130111 }, /* subwoofer */
ac612407
DH
1962 { }
1963 }
1964 },
5c0ebfbe 1965 [ALC882_FIXUP_PB_M5210] = {
fd108215
TI
1966 .type = HDA_FIXUP_PINCTLS,
1967 .v.pins = (const struct hda_pintbl[]) {
1968 { 0x19, PIN_VREF50 },
357f915e
KY
1969 {}
1970 }
1971 },
5c0ebfbe 1972 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
1727a771 1973 .type = HDA_FIXUP_FUNC,
23d30f28 1974 .v.func = alc_fixup_sku_ignore,
6981d184 1975 },
5c0ebfbe 1976 [ALC882_FIXUP_ASUS_W90V] = {
1727a771
TI
1977 .type = HDA_FIXUP_PINS,
1978 .v.pins = (const struct hda_pintbl[]) {
5cdf745e
TI
1979 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
1980 { }
1981 }
1982 },
8f239214 1983 [ALC889_FIXUP_CD] = {
1727a771
TI
1984 .type = HDA_FIXUP_PINS,
1985 .v.pins = (const struct hda_pintbl[]) {
8f239214
MB
1986 { 0x1c, 0x993301f0 }, /* CD */
1987 { }
1988 }
1989 },
5c0ebfbe 1990 [ALC889_FIXUP_VAIO_TT] = {
1727a771
TI
1991 .type = HDA_FIXUP_PINS,
1992 .v.pins = (const struct hda_pintbl[]) {
5c0ebfbe
TI
1993 { 0x17, 0x90170111 }, /* hidden surround speaker */
1994 { }
1995 }
1996 },
0e7cc2e7 1997 [ALC888_FIXUP_EEE1601] = {
1727a771 1998 .type = HDA_FIXUP_VERBS,
0e7cc2e7
TI
1999 .v.verbs = (const struct hda_verb[]) {
2000 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
2001 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
2002 { }
2003 }
177943a3
TI
2004 },
2005 [ALC882_FIXUP_EAPD] = {
1727a771 2006 .type = HDA_FIXUP_VERBS,
177943a3
TI
2007 .v.verbs = (const struct hda_verb[]) {
2008 /* change to EAPD mode */
2009 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2010 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
2011 { }
2012 }
2013 },
7a6069bf 2014 [ALC883_FIXUP_EAPD] = {
1727a771 2015 .type = HDA_FIXUP_VERBS,
7a6069bf
TI
2016 .v.verbs = (const struct hda_verb[]) {
2017 /* change to EAPD mode */
2018 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2019 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
2020 { }
2021 }
2022 },
8812c4f9 2023 [ALC883_FIXUP_ACER_EAPD] = {
1727a771 2024 .type = HDA_FIXUP_VERBS,
8812c4f9
TI
2025 .v.verbs = (const struct hda_verb[]) {
2026 /* eanable EAPD on Acer laptops */
2027 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2028 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2029 { }
2030 }
2031 },
1a97b7f2 2032 [ALC882_FIXUP_GPIO1] = {
1727a771 2033 .type = HDA_FIXUP_VERBS,
1a97b7f2
TI
2034 .v.verbs = alc_gpio1_init_verbs,
2035 },
2036 [ALC882_FIXUP_GPIO2] = {
1727a771 2037 .type = HDA_FIXUP_VERBS,
1a97b7f2
TI
2038 .v.verbs = alc_gpio2_init_verbs,
2039 },
eb844d51 2040 [ALC882_FIXUP_GPIO3] = {
1727a771 2041 .type = HDA_FIXUP_VERBS,
eb844d51
TI
2042 .v.verbs = alc_gpio3_init_verbs,
2043 },
68ef0561 2044 [ALC882_FIXUP_ASUS_W2JC] = {
1727a771 2045 .type = HDA_FIXUP_VERBS,
68ef0561
TI
2046 .v.verbs = alc_gpio1_init_verbs,
2047 .chained = true,
2048 .chain_id = ALC882_FIXUP_EAPD,
2049 },
2050 [ALC889_FIXUP_COEF] = {
1727a771 2051 .type = HDA_FIXUP_FUNC,
68ef0561
TI
2052 .v.func = alc889_fixup_coef,
2053 },
c3e837bb 2054 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
1727a771
TI
2055 .type = HDA_FIXUP_PINS,
2056 .v.pins = (const struct hda_pintbl[]) {
c3e837bb
TI
2057 { 0x16, 0x99130111 }, /* CLFE speaker */
2058 { 0x17, 0x99130112 }, /* surround speaker */
2059 { }
038d4fef
TI
2060 },
2061 .chained = true,
2062 .chain_id = ALC882_FIXUP_GPIO1,
c3e837bb
TI
2063 },
2064 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
1727a771
TI
2065 .type = HDA_FIXUP_PINS,
2066 .v.pins = (const struct hda_pintbl[]) {
c3e837bb
TI
2067 { 0x16, 0x99130111 }, /* CLFE speaker */
2068 { 0x1b, 0x99130112 }, /* surround speaker */
2069 { }
2070 },
2071 .chained = true,
2072 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
2073 },
2074 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
2075 /* additional init verbs for Acer Aspire 8930G */
1727a771 2076 .type = HDA_FIXUP_VERBS,
c3e837bb
TI
2077 .v.verbs = (const struct hda_verb[]) {
2078 /* Enable all DACs */
2079 /* DAC DISABLE/MUTE 1? */
2080 /* setting bits 1-5 disables DAC nids 0x02-0x06
2081 * apparently. Init=0x38 */
2082 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
2083 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
2084 /* DAC DISABLE/MUTE 2? */
2085 /* some bit here disables the other DACs.
2086 * Init=0x4900 */
2087 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
2088 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
2089 /* DMIC fix
2090 * This laptop has a stereo digital microphone.
2091 * The mics are only 1cm apart which makes the stereo
2092 * useless. However, either the mic or the ALC889
2093 * makes the signal become a difference/sum signal
2094 * instead of standard stereo, which is annoying.
2095 * So instead we flip this bit which makes the
2096 * codec replicate the sum signal to both channels,
2097 * turning it into a normal mono mic.
2098 */
2099 /* DMIC_CONTROL? Init value = 0x0001 */
2100 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
2101 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
2102 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2103 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2104 { }
038d4fef
TI
2105 },
2106 .chained = true,
2107 .chain_id = ALC882_FIXUP_GPIO1,
c3e837bb 2108 },
5671087f 2109 [ALC885_FIXUP_MACPRO_GPIO] = {
1727a771 2110 .type = HDA_FIXUP_FUNC,
5671087f
TI
2111 .v.func = alc885_fixup_macpro_gpio,
2112 },
02a237b2 2113 [ALC889_FIXUP_DAC_ROUTE] = {
1727a771 2114 .type = HDA_FIXUP_FUNC,
02a237b2
TI
2115 .v.func = alc889_fixup_dac_route,
2116 },
1a97b7f2 2117 [ALC889_FIXUP_MBP_VREF] = {
1727a771 2118 .type = HDA_FIXUP_FUNC,
1a97b7f2
TI
2119 .v.func = alc889_fixup_mbp_vref,
2120 .chained = true,
2121 .chain_id = ALC882_FIXUP_GPIO1,
2122 },
2123 [ALC889_FIXUP_IMAC91_VREF] = {
1727a771 2124 .type = HDA_FIXUP_FUNC,
1a97b7f2
TI
2125 .v.func = alc889_fixup_imac91_vref,
2126 .chained = true,
2127 .chain_id = ALC882_FIXUP_GPIO1,
2128 },
6e72aa5f 2129 [ALC882_FIXUP_INV_DMIC] = {
1727a771 2130 .type = HDA_FIXUP_FUNC,
6e72aa5f
TI
2131 .v.func = alc_fixup_inv_dmic_0x12,
2132 },
e427c237 2133 [ALC882_FIXUP_NO_PRIMARY_HP] = {
1727a771 2134 .type = HDA_FIXUP_FUNC,
e427c237
TI
2135 .v.func = alc882_fixup_no_primary_hp,
2136 },
ff818c24
TI
2137};
2138
1d045db9 2139static const struct snd_pci_quirk alc882_fixup_tbl[] = {
8812c4f9
TI
2140 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
2141 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
2142 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
2143 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
2144 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
2145 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
c3e837bb
TI
2146 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
2147 ALC882_FIXUP_ACER_ASPIRE_4930G),
2148 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
2149 ALC882_FIXUP_ACER_ASPIRE_4930G),
2150 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
2151 ALC882_FIXUP_ACER_ASPIRE_8930G),
2152 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
2153 ALC882_FIXUP_ACER_ASPIRE_8930G),
2154 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
2155 ALC882_FIXUP_ACER_ASPIRE_4930G),
2156 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
2157 ALC882_FIXUP_ACER_ASPIRE_4930G),
2158 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
2159 ALC882_FIXUP_ACER_ASPIRE_4930G),
5c0ebfbe 2160 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
f5c53d89
TI
2161 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
2162 ALC882_FIXUP_ACER_ASPIRE_4930G),
02a237b2 2163 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
fe97da1f 2164 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
ac9b1cdd 2165 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
177943a3 2166 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
5c0ebfbe 2167 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
68ef0561 2168 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
0e7cc2e7 2169 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
ac9b1cdd 2170 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
e427c237 2171 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
12e31a78 2172 SND_PCI_QUIRK(0x104d, 0x9043, "Sony Vaio VGC-LN51JGB", ALC882_FIXUP_NO_PRIMARY_HP),
5671087f
TI
2173
2174 /* All Apple entries are in codec SSIDs */
1a97b7f2
TI
2175 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
2176 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
2177 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
5671087f
TI
2178 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
2179 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
2180 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
1a97b7f2
TI
2181 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
2182 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
5671087f 2183 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
1a97b7f2
TI
2184 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
2185 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
2186 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
2187 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
5671087f 2188 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
1a97b7f2
TI
2189 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
2190 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
2191 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
29ebe402 2192 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
05193639 2193 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
1a97b7f2
TI
2194 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
2195 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
2196 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
5671087f 2197
7a6069bf 2198 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
bca40138 2199 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
eb844d51 2200 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
8f239214 2201 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
5c0ebfbe 2202 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
7a6069bf
TI
2203 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
2204 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
ac9b1cdd 2205 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
68ef0561 2206 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
ff818c24
TI
2207 {}
2208};
2209
1727a771 2210static const struct hda_model_fixup alc882_fixup_models[] = {
912093bc
TI
2211 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
2212 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
2213 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
6e72aa5f 2214 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
e427c237 2215 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
912093bc
TI
2216 {}
2217};
2218
f6a92248 2219/*
1d045db9 2220 * BIOS auto configuration
f6a92248 2221 */
1d045db9
TI
2222/* almost identical with ALC880 parser... */
2223static int alc882_parse_auto_config(struct hda_codec *codec)
2224{
1d045db9 2225 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
3e6179b8
TI
2226 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2227 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
1d045db9 2228}
b896b4eb 2229
1d045db9
TI
2230/*
2231 */
1d045db9 2232static int patch_alc882(struct hda_codec *codec)
f6a92248
KY
2233{
2234 struct alc_spec *spec;
1a97b7f2 2235 int err;
f6a92248 2236
3de95173
TI
2237 err = alc_alloc_spec(codec, 0x0b);
2238 if (err < 0)
2239 return err;
f6a92248 2240
3de95173 2241 spec = codec->spec;
1f0f4b80 2242
1d045db9
TI
2243 switch (codec->vendor_id) {
2244 case 0x10ec0882:
2245 case 0x10ec0885:
2246 break;
2247 default:
2248 /* ALC883 and variants */
2249 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
2250 break;
c793bec5 2251 }
977ddd6b 2252
1727a771 2253 snd_hda_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
912093bc 2254 alc882_fixups);
1727a771 2255 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
ff818c24 2256
1d045db9
TI
2257 alc_auto_parse_customize_define(codec);
2258
7504b6cd
TI
2259 if (has_cdefine_beep(codec))
2260 spec->gen.beep_nid = 0x01;
2261
1a97b7f2
TI
2262 /* automatic parse from the BIOS config */
2263 err = alc882_parse_auto_config(codec);
2264 if (err < 0)
2265 goto error;
f6a92248 2266
7504b6cd 2267 if (!spec->gen.no_analog && spec->gen.beep_nid)
1d045db9 2268 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
f6a92248
KY
2269
2270 codec->patch_ops = alc_patch_ops;
bf1b0225 2271
1727a771 2272 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
589876e2 2273
f6a92248 2274 return 0;
e16fb6d1
TI
2275
2276 error:
2277 alc_free(codec);
2278 return err;
f6a92248
KY
2279}
2280
df694daa 2281
df694daa 2282/*
1d045db9 2283 * ALC262 support
df694daa 2284 */
1d045db9 2285static int alc262_parse_auto_config(struct hda_codec *codec)
df694daa 2286{
1d045db9 2287 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
3e6179b8
TI
2288 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2289 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
df694daa
KY
2290}
2291
df694daa 2292/*
1d045db9 2293 * Pin config fixes
df694daa 2294 */
cfc9b06f 2295enum {
ea4e7af1 2296 ALC262_FIXUP_FSC_H270,
7513e6da 2297 ALC262_FIXUP_FSC_S7110,
ea4e7af1
TI
2298 ALC262_FIXUP_HP_Z200,
2299 ALC262_FIXUP_TYAN,
c470150c 2300 ALC262_FIXUP_LENOVO_3000,
b42590b8
TI
2301 ALC262_FIXUP_BENQ,
2302 ALC262_FIXUP_BENQ_T31,
6e72aa5f 2303 ALC262_FIXUP_INV_DMIC,
cfc9b06f
TI
2304};
2305
1727a771 2306static const struct hda_fixup alc262_fixups[] = {
ea4e7af1 2307 [ALC262_FIXUP_FSC_H270] = {
1727a771
TI
2308 .type = HDA_FIXUP_PINS,
2309 .v.pins = (const struct hda_pintbl[]) {
1d045db9
TI
2310 { 0x14, 0x99130110 }, /* speaker */
2311 { 0x15, 0x0221142f }, /* front HP */
2312 { 0x1b, 0x0121141f }, /* rear HP */
2313 { }
2314 }
2315 },
7513e6da
TI
2316 [ALC262_FIXUP_FSC_S7110] = {
2317 .type = HDA_FIXUP_PINS,
2318 .v.pins = (const struct hda_pintbl[]) {
2319 { 0x15, 0x90170110 }, /* speaker */
2320 { }
2321 },
2322 .chained = true,
2323 .chain_id = ALC262_FIXUP_BENQ,
2324 },
ea4e7af1 2325 [ALC262_FIXUP_HP_Z200] = {
1727a771
TI
2326 .type = HDA_FIXUP_PINS,
2327 .v.pins = (const struct hda_pintbl[]) {
1d045db9 2328 { 0x16, 0x99130120 }, /* internal speaker */
73413b12
TI
2329 { }
2330 }
cfc9b06f 2331 },
ea4e7af1 2332 [ALC262_FIXUP_TYAN] = {
1727a771
TI
2333 .type = HDA_FIXUP_PINS,
2334 .v.pins = (const struct hda_pintbl[]) {
ea4e7af1
TI
2335 { 0x14, 0x1993e1f0 }, /* int AUX */
2336 { }
2337 }
2338 },
c470150c 2339 [ALC262_FIXUP_LENOVO_3000] = {
fd108215
TI
2340 .type = HDA_FIXUP_PINCTLS,
2341 .v.pins = (const struct hda_pintbl[]) {
2342 { 0x19, PIN_VREF50 },
b42590b8
TI
2343 {}
2344 },
2345 .chained = true,
2346 .chain_id = ALC262_FIXUP_BENQ,
2347 },
2348 [ALC262_FIXUP_BENQ] = {
1727a771 2349 .type = HDA_FIXUP_VERBS,
b42590b8 2350 .v.verbs = (const struct hda_verb[]) {
c470150c
TI
2351 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2352 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
2353 {}
2354 }
2355 },
b42590b8 2356 [ALC262_FIXUP_BENQ_T31] = {
1727a771 2357 .type = HDA_FIXUP_VERBS,
b42590b8
TI
2358 .v.verbs = (const struct hda_verb[]) {
2359 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
2360 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
2361 {}
2362 }
2363 },
6e72aa5f 2364 [ALC262_FIXUP_INV_DMIC] = {
1727a771 2365 .type = HDA_FIXUP_FUNC,
6e72aa5f
TI
2366 .v.func = alc_fixup_inv_dmic_0x12,
2367 },
cfc9b06f
TI
2368};
2369
1d045db9 2370static const struct snd_pci_quirk alc262_fixup_tbl[] = {
ea4e7af1 2371 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
7513e6da 2372 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu Lifebook S7110", ALC262_FIXUP_FSC_S7110),
3dcd3be3 2373 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
ea4e7af1
TI
2374 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
2375 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
c470150c 2376 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
b42590b8
TI
2377 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
2378 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
cfc9b06f
TI
2379 {}
2380};
df694daa 2381
1727a771 2382static const struct hda_model_fixup alc262_fixup_models[] = {
6e72aa5f
TI
2383 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
2384 {}
2385};
1d045db9 2386
1d045db9
TI
2387/*
2388 */
1d045db9 2389static int patch_alc262(struct hda_codec *codec)
df694daa
KY
2390{
2391 struct alc_spec *spec;
df694daa
KY
2392 int err;
2393
3de95173
TI
2394 err = alc_alloc_spec(codec, 0x0b);
2395 if (err < 0)
2396 return err;
df694daa 2397
3de95173 2398 spec = codec->spec;
08c189f2 2399 spec->gen.shared_mic_vref_pin = 0x18;
1d045db9
TI
2400
2401#if 0
2402 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
2403 * under-run
2404 */
2405 {
2406 int tmp;
2407 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
2408 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
2409 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
2410 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
2411 }
2412#endif
1d045db9
TI
2413 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
2414
1727a771 2415 snd_hda_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
6e72aa5f 2416 alc262_fixups);
1727a771 2417 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
9c7f852e 2418
af741c15
TI
2419 alc_auto_parse_customize_define(codec);
2420
7504b6cd
TI
2421 if (has_cdefine_beep(codec))
2422 spec->gen.beep_nid = 0x01;
2423
42399f7a
TI
2424 /* automatic parse from the BIOS config */
2425 err = alc262_parse_auto_config(codec);
2426 if (err < 0)
2427 goto error;
df694daa 2428
7504b6cd 2429 if (!spec->gen.no_analog && spec->gen.beep_nid)
1d045db9 2430 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
2134ea4f 2431
df694daa 2432 codec->patch_ops = alc_patch_ops;
1d045db9
TI
2433 spec->shutup = alc_eapd_shutup;
2434
1727a771 2435 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
589876e2 2436
1da177e4 2437 return 0;
e16fb6d1
TI
2438
2439 error:
2440 alc_free(codec);
2441 return err;
1da177e4
LT
2442}
2443
f32610ed 2444/*
1d045db9 2445 * ALC268
f32610ed 2446 */
1d045db9
TI
2447/* bind Beep switches of both NID 0x0f and 0x10 */
2448static const struct hda_bind_ctls alc268_bind_beep_sw = {
2449 .ops = &snd_hda_bind_sw,
2450 .values = {
2451 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
2452 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
2453 0
2454 },
f32610ed
JS
2455};
2456
1d045db9
TI
2457static const struct snd_kcontrol_new alc268_beep_mixer[] = {
2458 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
2459 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
2460 { }
f32610ed
JS
2461};
2462
1d045db9
TI
2463/* set PCBEEP vol = 0, mute connections */
2464static const struct hda_verb alc268_beep_init_verbs[] = {
2465 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2466 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2467 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2468 { }
f32610ed
JS
2469};
2470
6e72aa5f
TI
2471enum {
2472 ALC268_FIXUP_INV_DMIC,
cb766404 2473 ALC268_FIXUP_HP_EAPD,
24eff328 2474 ALC268_FIXUP_SPDIF,
6e72aa5f
TI
2475};
2476
1727a771 2477static const struct hda_fixup alc268_fixups[] = {
6e72aa5f 2478 [ALC268_FIXUP_INV_DMIC] = {
1727a771 2479 .type = HDA_FIXUP_FUNC,
6e72aa5f
TI
2480 .v.func = alc_fixup_inv_dmic_0x12,
2481 },
cb766404 2482 [ALC268_FIXUP_HP_EAPD] = {
1727a771 2483 .type = HDA_FIXUP_VERBS,
cb766404
TI
2484 .v.verbs = (const struct hda_verb[]) {
2485 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
2486 {}
2487 }
2488 },
24eff328
TI
2489 [ALC268_FIXUP_SPDIF] = {
2490 .type = HDA_FIXUP_PINS,
2491 .v.pins = (const struct hda_pintbl[]) {
2492 { 0x1e, 0x014b1180 }, /* enable SPDIF out */
2493 {}
2494 }
2495 },
6e72aa5f
TI
2496};
2497
1727a771 2498static const struct hda_model_fixup alc268_fixup_models[] = {
6e72aa5f 2499 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
cb766404
TI
2500 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
2501 {}
2502};
2503
2504static const struct snd_pci_quirk alc268_fixup_tbl[] = {
24eff328 2505 SND_PCI_QUIRK(0x1025, 0x0139, "Acer TravelMate 6293", ALC268_FIXUP_SPDIF),
fcd8f3b1 2506 SND_PCI_QUIRK(0x1025, 0x015b, "Acer AOA 150 (ZG5)", ALC268_FIXUP_INV_DMIC),
cb766404
TI
2507 /* below is codec SSID since multiple Toshiba laptops have the
2508 * same PCI SSID 1179:ff00
2509 */
2510 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
6e72aa5f
TI
2511 {}
2512};
2513
f32610ed
JS
2514/*
2515 * BIOS auto configuration
2516 */
1d045db9 2517static int alc268_parse_auto_config(struct hda_codec *codec)
f32610ed 2518{
3e6179b8 2519 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
7504b6cd 2520 return alc_parse_auto_config(codec, NULL, alc268_ssids);
f32610ed
JS
2521}
2522
1d045db9
TI
2523/*
2524 */
1d045db9 2525static int patch_alc268(struct hda_codec *codec)
f32610ed
JS
2526{
2527 struct alc_spec *spec;
7504b6cd 2528 int err;
f32610ed 2529
1d045db9 2530 /* ALC268 has no aa-loopback mixer */
3de95173
TI
2531 err = alc_alloc_spec(codec, 0);
2532 if (err < 0)
2533 return err;
2534
2535 spec = codec->spec;
7504b6cd 2536 spec->gen.beep_nid = 0x01;
1f0f4b80 2537
1727a771
TI
2538 snd_hda_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
2539 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
6e72aa5f 2540
6ebb8053
TI
2541 /* automatic parse from the BIOS config */
2542 err = alc268_parse_auto_config(codec);
e16fb6d1
TI
2543 if (err < 0)
2544 goto error;
f32610ed 2545
7504b6cd
TI
2546 if (err > 0 && !spec->gen.no_analog &&
2547 spec->gen.autocfg.speaker_pins[0] != 0x1d) {
2548 add_mixer(spec, alc268_beep_mixer);
2549 snd_hda_add_verbs(codec, alc268_beep_init_verbs);
1d045db9
TI
2550 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
2551 /* override the amp caps for beep generator */
2552 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
2553 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
2554 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
2555 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2556 (0 << AC_AMPCAP_MUTE_SHIFT));
2f893286
KY
2557 }
2558
f32610ed 2559 codec->patch_ops = alc_patch_ops;
1c716153 2560 spec->shutup = alc_eapd_shutup;
1d045db9 2561
1727a771 2562 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
6e72aa5f 2563
f32610ed 2564 return 0;
e16fb6d1
TI
2565
2566 error:
2567 alc_free(codec);
2568 return err;
f32610ed
JS
2569}
2570
bc9f98a9 2571/*
1d045db9 2572 * ALC269
bc9f98a9 2573 */
08c189f2
TI
2574
2575static int playback_pcm_open(struct hda_pcm_stream *hinfo,
2576 struct hda_codec *codec,
2577 struct snd_pcm_substream *substream)
2578{
2579 struct hda_gen_spec *spec = codec->spec;
2580 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2581 hinfo);
2582}
2583
2584static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2585 struct hda_codec *codec,
2586 unsigned int stream_tag,
2587 unsigned int format,
2588 struct snd_pcm_substream *substream)
2589{
2590 struct hda_gen_spec *spec = codec->spec;
2591 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2592 stream_tag, format, substream);
2593}
2594
2595static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2596 struct hda_codec *codec,
2597 struct snd_pcm_substream *substream)
2598{
2599 struct hda_gen_spec *spec = codec->spec;
2600 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2601}
2602
1d045db9
TI
2603static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
2604 .substreams = 1,
2605 .channels_min = 2,
2606 .channels_max = 8,
2607 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2608 /* NID is set in alc_build_pcms */
2609 .ops = {
08c189f2
TI
2610 .open = playback_pcm_open,
2611 .prepare = playback_pcm_prepare,
2612 .cleanup = playback_pcm_cleanup
bc9f98a9
KY
2613 },
2614};
2615
1d045db9
TI
2616static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
2617 .substreams = 1,
2618 .channels_min = 2,
2619 .channels_max = 2,
2620 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2621 /* NID is set in alc_build_pcms */
bc9f98a9 2622};
291702f0 2623
1d045db9
TI
2624/* different alc269-variants */
2625enum {
2626 ALC269_TYPE_ALC269VA,
2627 ALC269_TYPE_ALC269VB,
2628 ALC269_TYPE_ALC269VC,
adcc70b2 2629 ALC269_TYPE_ALC269VD,
065380f0
KY
2630 ALC269_TYPE_ALC280,
2631 ALC269_TYPE_ALC282,
2af02be7 2632 ALC269_TYPE_ALC283,
065380f0 2633 ALC269_TYPE_ALC284,
161ebf29 2634 ALC269_TYPE_ALC285,
7fc7d047 2635 ALC269_TYPE_ALC286,
1d04c9de 2636 ALC269_TYPE_ALC255,
bc9f98a9
KY
2637};
2638
2639/*
1d045db9 2640 * BIOS auto configuration
bc9f98a9 2641 */
1d045db9
TI
2642static int alc269_parse_auto_config(struct hda_codec *codec)
2643{
1d045db9 2644 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
3e6179b8
TI
2645 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
2646 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
2647 struct alc_spec *spec = codec->spec;
adcc70b2
KY
2648 const hda_nid_t *ssids;
2649
2650 switch (spec->codec_variant) {
2651 case ALC269_TYPE_ALC269VA:
2652 case ALC269_TYPE_ALC269VC:
065380f0
KY
2653 case ALC269_TYPE_ALC280:
2654 case ALC269_TYPE_ALC284:
161ebf29 2655 case ALC269_TYPE_ALC285:
adcc70b2
KY
2656 ssids = alc269va_ssids;
2657 break;
2658 case ALC269_TYPE_ALC269VB:
2659 case ALC269_TYPE_ALC269VD:
065380f0 2660 case ALC269_TYPE_ALC282:
2af02be7 2661 case ALC269_TYPE_ALC283:
7fc7d047 2662 case ALC269_TYPE_ALC286:
1d04c9de 2663 case ALC269_TYPE_ALC255:
adcc70b2
KY
2664 ssids = alc269_ssids;
2665 break;
2666 default:
2667 ssids = alc269_ssids;
2668 break;
2669 }
bc9f98a9 2670
3e6179b8 2671 return alc_parse_auto_config(codec, alc269_ignore, ssids);
1d045db9 2672}
bc9f98a9 2673
1387e2d1 2674static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
1d045db9
TI
2675{
2676 int val = alc_read_coef_idx(codec, 0x04);
2677 if (power_up)
2678 val |= 1 << 11;
2679 else
2680 val &= ~(1 << 11);
2681 alc_write_coef_idx(codec, 0x04, val);
2682}
291702f0 2683
1d045db9
TI
2684static void alc269_shutup(struct hda_codec *codec)
2685{
adcc70b2
KY
2686 struct alc_spec *spec = codec->spec;
2687
1387e2d1
KY
2688 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
2689 alc269vb_toggle_power_output(codec, 0);
2690 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
2691 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
1d045db9
TI
2692 msleep(150);
2693 }
9bfb2844 2694 snd_hda_shutup_pins(codec);
1d045db9 2695}
291702f0 2696
2af02be7
KY
2697static void alc283_init(struct hda_codec *codec)
2698{
2699 struct alc_spec *spec = codec->spec;
2700 hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
2701 bool hp_pin_sense;
2702 int val;
2703
2704 if (!hp_pin)
2705 return;
2706 hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
2707
2708 /* Index 0x43 Direct Drive HP AMP LPM Control 1 */
2709 /* Headphone capless set to high power mode */
2710 alc_write_coef_idx(codec, 0x43, 0x9004);
2711
2712 snd_hda_codec_write(codec, hp_pin, 0,
2713 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
2714
2715 if (hp_pin_sense)
2716 msleep(85);
2717
2718 snd_hda_codec_write(codec, hp_pin, 0,
2719 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
2720
2721 if (hp_pin_sense)
2722 msleep(85);
2723 /* Index 0x46 Combo jack auto switch control 2 */
2724 /* 3k pull low control for Headset jack. */
2725 val = alc_read_coef_idx(codec, 0x46);
2726 alc_write_coef_idx(codec, 0x46, val & ~(3 << 12));
2727 /* Headphone capless set to normal mode */
2728 alc_write_coef_idx(codec, 0x43, 0x9614);
2729}
2730
2731static void alc283_shutup(struct hda_codec *codec)
2732{
2733 struct alc_spec *spec = codec->spec;
2734 hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
2735 bool hp_pin_sense;
2736 int val;
2737
2738 if (!hp_pin) {
2739 alc269_shutup(codec);
2740 return;
2741 }
2742
2743 hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
2744
2745 alc_write_coef_idx(codec, 0x43, 0x9004);
2746
2747 snd_hda_codec_write(codec, hp_pin, 0,
2748 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
2749
2750 if (hp_pin_sense)
88011c09 2751 msleep(100);
2af02be7
KY
2752
2753 snd_hda_codec_write(codec, hp_pin, 0,
2754 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0);
2755
2756 val = alc_read_coef_idx(codec, 0x46);
2757 alc_write_coef_idx(codec, 0x46, val | (3 << 12));
2758
2759 if (hp_pin_sense)
88011c09 2760 msleep(100);
2af02be7
KY
2761 snd_hda_shutup_pins(codec);
2762 alc_write_coef_idx(codec, 0x43, 0x9614);
2763}
2764
ad60d502
KY
2765static void alc5505_coef_set(struct hda_codec *codec, unsigned int index_reg,
2766 unsigned int val)
2767{
2768 snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_COEF_INDEX, index_reg >> 1);
2769 snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_PROC_COEF, val & 0xffff); /* LSB */
2770 snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_PROC_COEF, val >> 16); /* MSB */
2771}
2772
2773static int alc5505_coef_get(struct hda_codec *codec, unsigned int index_reg)
2774{
2775 unsigned int val;
2776
2777 snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_COEF_INDEX, index_reg >> 1);
2778 val = snd_hda_codec_read(codec, 0x51, 0, AC_VERB_GET_PROC_COEF, 0)
2779 & 0xffff;
2780 val |= snd_hda_codec_read(codec, 0x51, 0, AC_VERB_GET_PROC_COEF, 0)
2781 << 16;
2782 return val;
2783}
2784
2785static void alc5505_dsp_halt(struct hda_codec *codec)
2786{
2787 unsigned int val;
2788
2789 alc5505_coef_set(codec, 0x3000, 0x000c); /* DSP CPU stop */
2790 alc5505_coef_set(codec, 0x880c, 0x0008); /* DDR enter self refresh */
2791 alc5505_coef_set(codec, 0x61c0, 0x11110080); /* Clock control for PLL and CPU */
2792 alc5505_coef_set(codec, 0x6230, 0xfc0d4011); /* Disable Input OP */
2793 alc5505_coef_set(codec, 0x61b4, 0x040a2b03); /* Stop PLL2 */
2794 alc5505_coef_set(codec, 0x61b0, 0x00005b17); /* Stop PLL1 */
2795 alc5505_coef_set(codec, 0x61b8, 0x04133303); /* Stop PLL3 */
2796 val = alc5505_coef_get(codec, 0x6220);
2797 alc5505_coef_set(codec, 0x6220, (val | 0x3000)); /* switch Ringbuffer clock to DBUS clock */
2798}
2799
2800static void alc5505_dsp_back_from_halt(struct hda_codec *codec)
2801{
2802 alc5505_coef_set(codec, 0x61b8, 0x04133302);
2803 alc5505_coef_set(codec, 0x61b0, 0x00005b16);
2804 alc5505_coef_set(codec, 0x61b4, 0x040a2b02);
2805 alc5505_coef_set(codec, 0x6230, 0xf80d4011);
2806 alc5505_coef_set(codec, 0x6220, 0x2002010f);
2807 alc5505_coef_set(codec, 0x880c, 0x00000004);
2808}
2809
2810static void alc5505_dsp_init(struct hda_codec *codec)
2811{
2812 unsigned int val;
2813
2814 alc5505_dsp_halt(codec);
2815 alc5505_dsp_back_from_halt(codec);
2816 alc5505_coef_set(codec, 0x61b0, 0x5b14); /* PLL1 control */
2817 alc5505_coef_set(codec, 0x61b0, 0x5b16);
2818 alc5505_coef_set(codec, 0x61b4, 0x04132b00); /* PLL2 control */
2819 alc5505_coef_set(codec, 0x61b4, 0x04132b02);
2820 alc5505_coef_set(codec, 0x61b8, 0x041f3300); /* PLL3 control*/
2821 alc5505_coef_set(codec, 0x61b8, 0x041f3302);
2822 snd_hda_codec_write(codec, 0x51, 0, AC_VERB_SET_CODEC_RESET, 0); /* Function reset */
2823 alc5505_coef_set(codec, 0x61b8, 0x041b3302);
2824 alc5505_coef_set(codec, 0x61b8, 0x04173302);
2825 alc5505_coef_set(codec, 0x61b8, 0x04163302);
2826 alc5505_coef_set(codec, 0x8800, 0x348b328b); /* DRAM control */
2827 alc5505_coef_set(codec, 0x8808, 0x00020022); /* DRAM control */
2828 alc5505_coef_set(codec, 0x8818, 0x00000400); /* DRAM control */
2829
2830 val = alc5505_coef_get(codec, 0x6200) >> 16; /* Read revision ID */
2831 if (val <= 3)
2832 alc5505_coef_set(codec, 0x6220, 0x2002010f); /* I/O PAD Configuration */
2833 else
2834 alc5505_coef_set(codec, 0x6220, 0x6002018f);
2835
2836 alc5505_coef_set(codec, 0x61ac, 0x055525f0); /**/
2837 alc5505_coef_set(codec, 0x61c0, 0x12230080); /* Clock control */
2838 alc5505_coef_set(codec, 0x61b4, 0x040e2b02); /* PLL2 control */
2839 alc5505_coef_set(codec, 0x61bc, 0x010234f8); /* OSC Control */
2840 alc5505_coef_set(codec, 0x880c, 0x00000004); /* DRAM Function control */
2841 alc5505_coef_set(codec, 0x880c, 0x00000003);
2842 alc5505_coef_set(codec, 0x880c, 0x00000010);
cd63a5ff
TI
2843
2844#ifdef HALT_REALTEK_ALC5505
2845 alc5505_dsp_halt(codec);
2846#endif
ad60d502
KY
2847}
2848
cd63a5ff
TI
2849#ifdef HALT_REALTEK_ALC5505
2850#define alc5505_dsp_suspend(codec) /* NOP */
2851#define alc5505_dsp_resume(codec) /* NOP */
2852#else
2853#define alc5505_dsp_suspend(codec) alc5505_dsp_halt(codec)
2854#define alc5505_dsp_resume(codec) alc5505_dsp_back_from_halt(codec)
2855#endif
2856
2a43952a 2857#ifdef CONFIG_PM
ad60d502
KY
2858static int alc269_suspend(struct hda_codec *codec)
2859{
2860 struct alc_spec *spec = codec->spec;
2861
2862 if (spec->has_alc5505_dsp)
cd63a5ff 2863 alc5505_dsp_suspend(codec);
ad60d502
KY
2864 return alc_suspend(codec);
2865}
2866
1d045db9
TI
2867static int alc269_resume(struct hda_codec *codec)
2868{
adcc70b2
KY
2869 struct alc_spec *spec = codec->spec;
2870
1387e2d1
KY
2871 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
2872 alc269vb_toggle_power_output(codec, 0);
2873 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
adcc70b2 2874 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
1d045db9
TI
2875 msleep(150);
2876 }
8c427226 2877
1d045db9 2878 codec->patch_ops.init(codec);
f1d4e28b 2879
1387e2d1
KY
2880 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
2881 alc269vb_toggle_power_output(codec, 1);
2882 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
adcc70b2 2883 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
1d045db9
TI
2884 msleep(200);
2885 }
f1d4e28b 2886
1d045db9
TI
2887 snd_hda_codec_resume_amp(codec);
2888 snd_hda_codec_resume_cache(codec);
0623a889 2889 alc_inv_dmic_sync(codec, true);
1d045db9 2890 hda_call_check_power_status(codec, 0x01);
ad60d502 2891 if (spec->has_alc5505_dsp)
cd63a5ff 2892 alc5505_dsp_resume(codec);
c5177c86 2893
1d045db9
TI
2894 return 0;
2895}
2a43952a 2896#endif /* CONFIG_PM */
f1d4e28b 2897
108cc108 2898static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
1727a771 2899 const struct hda_fixup *fix, int action)
108cc108
DH
2900{
2901 struct alc_spec *spec = codec->spec;
2902
1727a771 2903 if (action == HDA_FIXUP_ACT_PRE_PROBE)
108cc108
DH
2904 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
2905}
2906
1d045db9 2907static void alc269_fixup_hweq(struct hda_codec *codec,
1727a771 2908 const struct hda_fixup *fix, int action)
1d045db9
TI
2909{
2910 int coef;
f1d4e28b 2911
1727a771 2912 if (action != HDA_FIXUP_ACT_INIT)
1d045db9
TI
2913 return;
2914 coef = alc_read_coef_idx(codec, 0x1e);
2915 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
2916}
f1d4e28b 2917
7c478f03
DH
2918static void alc269_fixup_headset_mic(struct hda_codec *codec,
2919 const struct hda_fixup *fix, int action)
2920{
2921 struct alc_spec *spec = codec->spec;
2922
2923 if (action == HDA_FIXUP_ACT_PRE_PROBE)
2924 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
2925}
2926
1d045db9 2927static void alc271_fixup_dmic(struct hda_codec *codec,
1727a771 2928 const struct hda_fixup *fix, int action)
1d045db9
TI
2929{
2930 static const struct hda_verb verbs[] = {
2931 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
2932 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
2933 {}
2934 };
2935 unsigned int cfg;
f1d4e28b 2936
42397004
DR
2937 if (strcmp(codec->chip_name, "ALC271X") &&
2938 strcmp(codec->chip_name, "ALC269VB"))
1d045db9
TI
2939 return;
2940 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
2941 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
2942 snd_hda_sequence_write(codec, verbs);
2943}
f1d4e28b 2944
017f2a10 2945static void alc269_fixup_pcm_44k(struct hda_codec *codec,
1727a771 2946 const struct hda_fixup *fix, int action)
017f2a10
TI
2947{
2948 struct alc_spec *spec = codec->spec;
2949
1727a771 2950 if (action != HDA_FIXUP_ACT_PROBE)
017f2a10
TI
2951 return;
2952
2953 /* Due to a hardware problem on Lenovo Ideadpad, we need to
2954 * fix the sample rate of analog I/O to 44.1kHz
2955 */
08c189f2
TI
2956 spec->gen.stream_analog_playback = &alc269_44k_pcm_analog_playback;
2957 spec->gen.stream_analog_capture = &alc269_44k_pcm_analog_capture;
017f2a10
TI
2958}
2959
adabb3ec 2960static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
1727a771 2961 const struct hda_fixup *fix, int action)
adabb3ec
TI
2962{
2963 int coef;
2964
1727a771 2965 if (action != HDA_FIXUP_ACT_INIT)
adabb3ec
TI
2966 return;
2967 /* The digital-mic unit sends PDM (differential signal) instead of
2968 * the standard PCM, thus you can't record a valid mono stream as is.
2969 * Below is a workaround specific to ALC269 to control the dmic
2970 * signal source as mono.
2971 */
2972 coef = alc_read_coef_idx(codec, 0x07);
2973 alc_write_coef_idx(codec, 0x07, coef | 0x80);
2974}
2975
24519911
TI
2976static void alc269_quanta_automute(struct hda_codec *codec)
2977{
08c189f2 2978 snd_hda_gen_update_outputs(codec);
24519911
TI
2979
2980 snd_hda_codec_write(codec, 0x20, 0,
2981 AC_VERB_SET_COEF_INDEX, 0x0c);
2982 snd_hda_codec_write(codec, 0x20, 0,
2983 AC_VERB_SET_PROC_COEF, 0x680);
2984
2985 snd_hda_codec_write(codec, 0x20, 0,
2986 AC_VERB_SET_COEF_INDEX, 0x0c);
2987 snd_hda_codec_write(codec, 0x20, 0,
2988 AC_VERB_SET_PROC_COEF, 0x480);
2989}
2990
2991static void alc269_fixup_quanta_mute(struct hda_codec *codec,
1727a771 2992 const struct hda_fixup *fix, int action)
24519911
TI
2993{
2994 struct alc_spec *spec = codec->spec;
1727a771 2995 if (action != HDA_FIXUP_ACT_PROBE)
24519911 2996 return;
08c189f2 2997 spec->gen.automute_hook = alc269_quanta_automute;
24519911
TI
2998}
2999
d240d1dc
DH
3000static void alc269_x101_hp_automute_hook(struct hda_codec *codec,
3001 struct hda_jack_tbl *jack)
3002{
3003 struct alc_spec *spec = codec->spec;
3004 int vref;
3005 msleep(200);
3006 snd_hda_gen_hp_automute(codec, jack);
3007
3008 vref = spec->gen.hp_jack_present ? PIN_VREF80 : 0;
3009 msleep(100);
3010 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3011 vref);
3012 msleep(500);
3013 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3014 vref);
3015}
3016
3017static void alc269_fixup_x101_headset_mic(struct hda_codec *codec,
3018 const struct hda_fixup *fix, int action)
3019{
3020 struct alc_spec *spec = codec->spec;
3021 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3022 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
3023 spec->gen.hp_automute_hook = alc269_x101_hp_automute_hook;
3024 }
3025}
3026
3027
08fb0d0e
TI
3028/* update mute-LED according to the speaker mute state via mic VREF pin */
3029static void alc269_fixup_mic_mute_hook(void *private_data, int enabled)
6d3cd5d4
DH
3030{
3031 struct hda_codec *codec = private_data;
08fb0d0e
TI
3032 struct alc_spec *spec = codec->spec;
3033 unsigned int pinval;
3034
3035 if (spec->mute_led_polarity)
3036 enabled = !enabled;
3037 pinval = AC_PINCTL_IN_EN |
3038 (enabled ? AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
3039 if (spec->mute_led_nid)
3040 snd_hda_set_pin_ctl_cache(codec, spec->mute_led_nid, pinval);
6d3cd5d4
DH
3041}
3042
d5b6b65e
DH
3043/* Make sure the led works even in runtime suspend */
3044static unsigned int led_power_filter(struct hda_codec *codec,
3045 hda_nid_t nid,
3046 unsigned int power_state)
3047{
3048 struct alc_spec *spec = codec->spec;
3049
3050 if (power_state != AC_PWRST_D3 || nid != spec->mute_led_nid)
3051 return power_state;
3052
3053 /* Set pin ctl again, it might have just been set to 0 */
3054 snd_hda_set_pin_ctl(codec, nid,
3055 snd_hda_codec_get_pin_target(codec, nid));
3056
3057 return AC_PWRST_D0;
3058}
3059
08fb0d0e
TI
3060static void alc269_fixup_hp_mute_led(struct hda_codec *codec,
3061 const struct hda_fixup *fix, int action)
6d3cd5d4
DH
3062{
3063 struct alc_spec *spec = codec->spec;
08fb0d0e
TI
3064 const struct dmi_device *dev = NULL;
3065
3066 if (action != HDA_FIXUP_ACT_PRE_PROBE)
3067 return;
3068
3069 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
3070 int pol, pin;
3071 if (sscanf(dev->name, "HP_Mute_LED_%d_%x", &pol, &pin) != 2)
3072 continue;
3073 if (pin < 0x0a || pin >= 0x10)
3074 break;
3075 spec->mute_led_polarity = pol;
3076 spec->mute_led_nid = pin - 0x0a + 0x18;
3077 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
fd25a97a 3078 spec->gen.vmaster_mute_enum = 1;
d5b6b65e 3079 codec->power_filter = led_power_filter;
08fb0d0e
TI
3080 snd_printd("Detected mute LED for %x:%d\n", spec->mute_led_nid,
3081 spec->mute_led_polarity);
6d3cd5d4
DH
3082 break;
3083 }
3084}
3085
d06ac143
DH
3086static void alc269_fixup_hp_mute_led_mic1(struct hda_codec *codec,
3087 const struct hda_fixup *fix, int action)
3088{
3089 struct alc_spec *spec = codec->spec;
3090 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3091 spec->mute_led_polarity = 0;
3092 spec->mute_led_nid = 0x18;
3093 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
3094 spec->gen.vmaster_mute_enum = 1;
d5b6b65e 3095 codec->power_filter = led_power_filter;
d06ac143
DH
3096 }
3097}
3098
08fb0d0e
TI
3099static void alc269_fixup_hp_mute_led_mic2(struct hda_codec *codec,
3100 const struct hda_fixup *fix, int action)
420b0feb
TI
3101{
3102 struct alc_spec *spec = codec->spec;
9bb1f06f 3103 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
08fb0d0e
TI
3104 spec->mute_led_polarity = 0;
3105 spec->mute_led_nid = 0x19;
3106 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
fd25a97a 3107 spec->gen.vmaster_mute_enum = 1;
d5b6b65e 3108 codec->power_filter = led_power_filter;
420b0feb
TI
3109 }
3110}
3111
9f5c6faf
TI
3112/* turn on/off mute LED per vmaster hook */
3113static void alc269_fixup_hp_gpio_mute_hook(void *private_data, int enabled)
3114{
3115 struct hda_codec *codec = private_data;
3116 struct alc_spec *spec = codec->spec;
3117 unsigned int oldval = spec->gpio_led;
3118
3119 if (enabled)
3120 spec->gpio_led &= ~0x08;
3121 else
3122 spec->gpio_led |= 0x08;
3123 if (spec->gpio_led != oldval)
3124 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3125 spec->gpio_led);
3126}
3127
3128/* turn on/off mic-mute LED per capture hook */
3129static void alc269_fixup_hp_gpio_mic_mute_hook(struct hda_codec *codec,
3130 struct snd_ctl_elem_value *ucontrol)
3131{
3132 struct alc_spec *spec = codec->spec;
3133 unsigned int oldval = spec->gpio_led;
3134
3135 if (!ucontrol)
3136 return;
3137
3138 if (ucontrol->value.integer.value[0] ||
3139 ucontrol->value.integer.value[1])
3140 spec->gpio_led &= ~0x10;
3141 else
3142 spec->gpio_led |= 0x10;
3143 if (spec->gpio_led != oldval)
3144 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3145 spec->gpio_led);
3146}
3147
3148static void alc269_fixup_hp_gpio_led(struct hda_codec *codec,
3149 const struct hda_fixup *fix, int action)
3150{
3151 struct alc_spec *spec = codec->spec;
3152 static const struct hda_verb gpio_init[] = {
3153 { 0x01, AC_VERB_SET_GPIO_MASK, 0x18 },
3154 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x18 },
3155 {}
3156 };
3157
3158 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3159 spec->gen.vmaster_mute.hook = alc269_fixup_hp_gpio_mute_hook;
3160 spec->gen.cap_sync_hook = alc269_fixup_hp_gpio_mic_mute_hook;
3161 spec->gpio_led = 0;
3162 snd_hda_add_verbs(codec, gpio_init);
3163 }
3164}
3165
73bdd597
DH
3166static void alc_headset_mode_unplugged(struct hda_codec *codec)
3167{
3168 int val;
3169
3170 switch (codec->vendor_id) {
9a22a8f5
KY
3171 case 0x10ec0255:
3172 /* LDO and MISC control */
3173 alc_write_coef_idx(codec, 0x1b, 0x0c0b);
3174 /* UAJ function set to menual mode */
3175 alc_write_coef_idx(codec, 0x45, 0xd089);
3176 /* Direct Drive HP Amp control(Set to verb control)*/
3177 val = alc_read_coefex_idx(codec, 0x57, 0x05);
3178 alc_write_coefex_idx(codec, 0x57, 0x05, val & ~(1<<14));
3179 /* Set MIC2 Vref gate with HP */
3180 alc_write_coef_idx(codec, 0x06, 0x6104);
3181 /* Direct Drive HP Amp control */
3182 alc_write_coefex_idx(codec, 0x57, 0x03, 0x8aa6);
3183 break;
73bdd597
DH
3184 case 0x10ec0283:
3185 alc_write_coef_idx(codec, 0x1b, 0x0c0b);
3186 alc_write_coef_idx(codec, 0x45, 0xc429);
3187 val = alc_read_coef_idx(codec, 0x35);
3188 alc_write_coef_idx(codec, 0x35, val & 0xbfff);
3189 alc_write_coef_idx(codec, 0x06, 0x2104);
3190 alc_write_coef_idx(codec, 0x1a, 0x0001);
3191 alc_write_coef_idx(codec, 0x26, 0x0004);
3192 alc_write_coef_idx(codec, 0x32, 0x42a3);
3193 break;
3194 case 0x10ec0292:
3195 alc_write_coef_idx(codec, 0x76, 0x000e);
3196 alc_write_coef_idx(codec, 0x6c, 0x2400);
3197 alc_write_coef_idx(codec, 0x18, 0x7308);
3198 alc_write_coef_idx(codec, 0x6b, 0xc429);
3199 break;
3200 case 0x10ec0668:
3201 alc_write_coef_idx(codec, 0x15, 0x0d40);
3202 alc_write_coef_idx(codec, 0xb7, 0x802b);
3203 break;
3204 }
3205 snd_printdd("Headset jack set to unplugged mode.\n");
3206}
3207
3208
3209static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
3210 hda_nid_t mic_pin)
3211{
3212 int val;
3213
3214 switch (codec->vendor_id) {
9a22a8f5
KY
3215 case 0x10ec0255:
3216 alc_write_coef_idx(codec, 0x45, 0xc489);
3217 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3218 alc_write_coefex_idx(codec, 0x57, 0x03, 0x8aa6);
3219 /* Set MIC2 Vref gate to normal */
3220 alc_write_coef_idx(codec, 0x06, 0x6100);
3221 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3222 break;
73bdd597
DH
3223 case 0x10ec0283:
3224 alc_write_coef_idx(codec, 0x45, 0xc429);
3225 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3226 val = alc_read_coef_idx(codec, 0x35);
3227 alc_write_coef_idx(codec, 0x35, val | 1<<14);
3228 alc_write_coef_idx(codec, 0x06, 0x2100);
3229 alc_write_coef_idx(codec, 0x1a, 0x0021);
3230 alc_write_coef_idx(codec, 0x26, 0x008c);
3231 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3232 break;
3233 case 0x10ec0292:
3234 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3235 alc_write_coef_idx(codec, 0x19, 0xa208);
3236 alc_write_coef_idx(codec, 0x2e, 0xacf0);
3237 break;
3238 case 0x10ec0668:
3239 alc_write_coef_idx(codec, 0x11, 0x0001);
3240 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3241 alc_write_coef_idx(codec, 0xb7, 0x802b);
3242 alc_write_coef_idx(codec, 0xb5, 0x1040);
3243 val = alc_read_coef_idx(codec, 0xc3);
3244 alc_write_coef_idx(codec, 0xc3, val | 1<<12);
3245 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3246 break;
3247 }
3248 snd_printdd("Headset jack set to mic-in mode.\n");
3249}
3250
3251static void alc_headset_mode_default(struct hda_codec *codec)
3252{
3253 switch (codec->vendor_id) {
9a22a8f5
KY
3254 case 0x10ec0255:
3255 alc_write_coef_idx(codec, 0x45, 0xc089);
3256 alc_write_coef_idx(codec, 0x45, 0xc489);
3257 alc_write_coefex_idx(codec, 0x57, 0x03, 0x8ea6);
3258 alc_write_coef_idx(codec, 0x49, 0x0049);
3259 break;
73bdd597
DH
3260 case 0x10ec0283:
3261 alc_write_coef_idx(codec, 0x06, 0x2100);
3262 alc_write_coef_idx(codec, 0x32, 0x4ea3);
3263 break;
3264 case 0x10ec0292:
3265 alc_write_coef_idx(codec, 0x76, 0x000e);
3266 alc_write_coef_idx(codec, 0x6c, 0x2400);
3267 alc_write_coef_idx(codec, 0x6b, 0xc429);
3268 alc_write_coef_idx(codec, 0x18, 0x7308);
3269 break;
3270 case 0x10ec0668:
3271 alc_write_coef_idx(codec, 0x11, 0x0041);
3272 alc_write_coef_idx(codec, 0x15, 0x0d40);
3273 alc_write_coef_idx(codec, 0xb7, 0x802b);
3274 break;
3275 }
3276 snd_printdd("Headset jack set to headphone (default) mode.\n");
3277}
3278
3279/* Iphone type */
3280static void alc_headset_mode_ctia(struct hda_codec *codec)
3281{
3282 switch (codec->vendor_id) {
9a22a8f5
KY
3283 case 0x10ec0255:
3284 /* Set to CTIA type */
3285 alc_write_coef_idx(codec, 0x45, 0xd489);
3286 alc_write_coef_idx(codec, 0x1b, 0x0c2b);
3287 alc_write_coefex_idx(codec, 0x57, 0x03, 0x8ea6);
3288 break;
73bdd597
DH
3289 case 0x10ec0283:
3290 alc_write_coef_idx(codec, 0x45, 0xd429);
3291 alc_write_coef_idx(codec, 0x1b, 0x0c2b);
3292 alc_write_coef_idx(codec, 0x32, 0x4ea3);
3293 break;
3294 case 0x10ec0292:
3295 alc_write_coef_idx(codec, 0x6b, 0xd429);
3296 alc_write_coef_idx(codec, 0x76, 0x0008);
3297 alc_write_coef_idx(codec, 0x18, 0x7388);
3298 break;
3299 case 0x10ec0668:
3300 alc_write_coef_idx(codec, 0x15, 0x0d60);
3301 alc_write_coef_idx(codec, 0xc3, 0x0000);
3302 break;
3303 }
3304 snd_printdd("Headset jack set to iPhone-style headset mode.\n");
3305}
3306
3307/* Nokia type */
3308static void alc_headset_mode_omtp(struct hda_codec *codec)
3309{
3310 switch (codec->vendor_id) {
9a22a8f5
KY
3311 case 0x10ec0255:
3312 /* Set to OMTP Type */
3313 alc_write_coef_idx(codec, 0x45, 0xe489);
3314 alc_write_coef_idx(codec, 0x1b, 0x0c2b);
3315 alc_write_coefex_idx(codec, 0x57, 0x03, 0x8ea6);
3316 break;
73bdd597
DH
3317 case 0x10ec0283:
3318 alc_write_coef_idx(codec, 0x45, 0xe429);
3319 alc_write_coef_idx(codec, 0x1b, 0x0c2b);
3320 alc_write_coef_idx(codec, 0x32, 0x4ea3);
3321 break;
3322 case 0x10ec0292:
3323 alc_write_coef_idx(codec, 0x6b, 0xe429);
3324 alc_write_coef_idx(codec, 0x76, 0x0008);
3325 alc_write_coef_idx(codec, 0x18, 0x7388);
3326 break;
3327 case 0x10ec0668:
3328 alc_write_coef_idx(codec, 0x15, 0x0d50);
3329 alc_write_coef_idx(codec, 0xc3, 0x0000);
3330 break;
3331 }
3332 snd_printdd("Headset jack set to Nokia-style headset mode.\n");
3333}
3334
3335static void alc_determine_headset_type(struct hda_codec *codec)
3336{
3337 int val;
3338 bool is_ctia = false;
3339 struct alc_spec *spec = codec->spec;
3340
3341 switch (codec->vendor_id) {
9a22a8f5
KY
3342 case 0x10ec0255:
3343 /* combo jack auto switch control(Check type)*/
3344 alc_write_coef_idx(codec, 0x45, 0xd089);
3345 /* combo jack auto switch control(Vref conteol) */
3346 alc_write_coef_idx(codec, 0x49, 0x0149);
3347 msleep(300);
3348 val = alc_read_coef_idx(codec, 0x46);
3349 is_ctia = (val & 0x0070) == 0x0070;
3350 break;
73bdd597
DH
3351 case 0x10ec0283:
3352 alc_write_coef_idx(codec, 0x45, 0xd029);
3353 msleep(300);
3354 val = alc_read_coef_idx(codec, 0x46);
3355 is_ctia = (val & 0x0070) == 0x0070;
3356 break;
3357 case 0x10ec0292:
3358 alc_write_coef_idx(codec, 0x6b, 0xd429);
3359 msleep(300);
3360 val = alc_read_coef_idx(codec, 0x6c);
3361 is_ctia = (val & 0x001c) == 0x001c;
3362 break;
3363 case 0x10ec0668:
3364 alc_write_coef_idx(codec, 0x11, 0x0001);
3365 alc_write_coef_idx(codec, 0xb7, 0x802b);
3366 alc_write_coef_idx(codec, 0x15, 0x0d60);
3367 alc_write_coef_idx(codec, 0xc3, 0x0c00);
3368 msleep(300);
3369 val = alc_read_coef_idx(codec, 0xbe);
3370 is_ctia = (val & 0x1c02) == 0x1c02;
3371 break;
3372 }
3373
3374 snd_printdd("Headset jack detected iPhone-style headset: %s\n",
3375 is_ctia ? "yes" : "no");
3376 spec->current_headset_type = is_ctia ? ALC_HEADSET_TYPE_CTIA : ALC_HEADSET_TYPE_OMTP;
3377}
3378
3379static void alc_update_headset_mode(struct hda_codec *codec)
3380{
3381 struct alc_spec *spec = codec->spec;
3382
3383 hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
3384 hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3385
3386 int new_headset_mode;
3387
3388 if (!snd_hda_jack_detect(codec, hp_pin))
3389 new_headset_mode = ALC_HEADSET_MODE_UNPLUGGED;
3390 else if (mux_pin == spec->headset_mic_pin)
3391 new_headset_mode = ALC_HEADSET_MODE_HEADSET;
3392 else if (mux_pin == spec->headphone_mic_pin)
3393 new_headset_mode = ALC_HEADSET_MODE_MIC;
3394 else
3395 new_headset_mode = ALC_HEADSET_MODE_HEADPHONE;
3396
5959a6bc
DH
3397 if (new_headset_mode == spec->current_headset_mode) {
3398 snd_hda_gen_update_outputs(codec);
73bdd597 3399 return;
5959a6bc 3400 }
73bdd597
DH
3401
3402 switch (new_headset_mode) {
3403 case ALC_HEADSET_MODE_UNPLUGGED:
3404 alc_headset_mode_unplugged(codec);
3405 spec->gen.hp_jack_present = false;
3406 break;
3407 case ALC_HEADSET_MODE_HEADSET:
3408 if (spec->current_headset_type == ALC_HEADSET_TYPE_UNKNOWN)
3409 alc_determine_headset_type(codec);
3410 if (spec->current_headset_type == ALC_HEADSET_TYPE_CTIA)
3411 alc_headset_mode_ctia(codec);
3412 else if (spec->current_headset_type == ALC_HEADSET_TYPE_OMTP)
3413 alc_headset_mode_omtp(codec);
3414 spec->gen.hp_jack_present = true;
3415 break;
3416 case ALC_HEADSET_MODE_MIC:
3417 alc_headset_mode_mic_in(codec, hp_pin, spec->headphone_mic_pin);
3418 spec->gen.hp_jack_present = false;
3419 break;
3420 case ALC_HEADSET_MODE_HEADPHONE:
3421 alc_headset_mode_default(codec);
3422 spec->gen.hp_jack_present = true;
3423 break;
3424 }
3425 if (new_headset_mode != ALC_HEADSET_MODE_MIC) {
3426 snd_hda_set_pin_ctl_cache(codec, hp_pin,
3427 AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3428 if (spec->headphone_mic_pin)
3429 snd_hda_set_pin_ctl_cache(codec, spec->headphone_mic_pin,
3430 PIN_VREFHIZ);
3431 }
3432 spec->current_headset_mode = new_headset_mode;
3433
3434 snd_hda_gen_update_outputs(codec);
3435}
3436
3437static void alc_update_headset_mode_hook(struct hda_codec *codec,
3438 struct snd_ctl_elem_value *ucontrol)
3439{
3440 alc_update_headset_mode(codec);
3441}
3442
3443static void alc_update_headset_jack_cb(struct hda_codec *codec, struct hda_jack_tbl *jack)
3444{
3445 struct alc_spec *spec = codec->spec;
5db4d34b 3446 spec->current_headset_type = ALC_HEADSET_TYPE_UNKNOWN;
73bdd597
DH
3447 snd_hda_gen_hp_automute(codec, jack);
3448}
3449
3450static void alc_probe_headset_mode(struct hda_codec *codec)
3451{
3452 int i;
3453 struct alc_spec *spec = codec->spec;
3454 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
3455
3456 /* Find mic pins */
3457 for (i = 0; i < cfg->num_inputs; i++) {
3458 if (cfg->inputs[i].is_headset_mic && !spec->headset_mic_pin)
3459 spec->headset_mic_pin = cfg->inputs[i].pin;
3460 if (cfg->inputs[i].is_headphone_mic && !spec->headphone_mic_pin)
3461 spec->headphone_mic_pin = cfg->inputs[i].pin;
3462 }
3463
3464 spec->gen.cap_sync_hook = alc_update_headset_mode_hook;
3465 spec->gen.automute_hook = alc_update_headset_mode;
3466 spec->gen.hp_automute_hook = alc_update_headset_jack_cb;
3467}
3468
3469static void alc_fixup_headset_mode(struct hda_codec *codec,
3470 const struct hda_fixup *fix, int action)
3471{
3472 struct alc_spec *spec = codec->spec;
3473
3474 switch (action) {
3475 case HDA_FIXUP_ACT_PRE_PROBE:
3476 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC | HDA_PINCFG_HEADPHONE_MIC;
3477 break;
3478 case HDA_FIXUP_ACT_PROBE:
3479 alc_probe_headset_mode(codec);
3480 break;
3481 case HDA_FIXUP_ACT_INIT:
3482 spec->current_headset_mode = 0;
3483 alc_update_headset_mode(codec);
3484 break;
3485 }
3486}
3487
3488static void alc_fixup_headset_mode_no_hp_mic(struct hda_codec *codec,
3489 const struct hda_fixup *fix, int action)
3490{
3491 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3492 struct alc_spec *spec = codec->spec;
3493 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
3494 }
3495 else
3496 alc_fixup_headset_mode(codec, fix, action);
3497}
3498
9a22a8f5
KY
3499static void alc_fixup_headset_mode_alc255(struct hda_codec *codec,
3500 const struct hda_fixup *fix, int action)
3501{
3502 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3503 /* Set to iphone type */
3504 alc_write_coef_idx(codec, 0x1b, 0x880b);
3505 alc_write_coef_idx(codec, 0x45, 0xd089);
3506 alc_write_coef_idx(codec, 0x1b, 0x080b);
3507 alc_write_coef_idx(codec, 0x46, 0x0004);
3508 alc_write_coef_idx(codec, 0x1b, 0x0c0b);
3509 msleep(30);
3510 }
3511 alc_fixup_headset_mode(codec, fix, action);
3512}
3513
73bdd597
DH
3514static void alc_fixup_headset_mode_alc668(struct hda_codec *codec,
3515 const struct hda_fixup *fix, int action)
3516{
3517 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3518 int val;
3519 alc_write_coef_idx(codec, 0xc4, 0x8000);
3520 val = alc_read_coef_idx(codec, 0xc2);
3521 alc_write_coef_idx(codec, 0xc2, val & 0xfe);
3522 snd_hda_set_pin_ctl_cache(codec, 0x18, 0);
3523 }
3524 alc_fixup_headset_mode(codec, fix, action);
3525}
3526
bde7bc60
CCC
3527/* Returns the nid of the external mic input pin, or 0 if it cannot be found. */
3528static int find_ext_mic_pin(struct hda_codec *codec)
3529{
3530 struct alc_spec *spec = codec->spec;
3531 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
3532 hda_nid_t nid;
3533 unsigned int defcfg;
3534 int i;
3535
3536 for (i = 0; i < cfg->num_inputs; i++) {
3537 if (cfg->inputs[i].type != AUTO_PIN_MIC)
3538 continue;
3539 nid = cfg->inputs[i].pin;
3540 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3541 if (snd_hda_get_input_pin_attr(defcfg) == INPUT_PIN_ATTR_INT)
3542 continue;
3543 return nid;
3544 }
3545
3546 return 0;
3547}
3548
08a978db 3549static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
1727a771 3550 const struct hda_fixup *fix,
08a978db
DR
3551 int action)
3552{
3553 struct alc_spec *spec = codec->spec;
3554
0db75790 3555 if (action == HDA_FIXUP_ACT_PROBE) {
bde7bc60
CCC
3556 int mic_pin = find_ext_mic_pin(codec);
3557 int hp_pin = spec->gen.autocfg.hp_pins[0];
3558
3559 if (snd_BUG_ON(!mic_pin || !hp_pin))
0db75790 3560 return;
bde7bc60 3561 snd_hda_jack_set_gating_jack(codec, mic_pin, hp_pin);
0db75790 3562 }
08a978db 3563}
693b613d 3564
3e0d611b
DH
3565static void alc269_fixup_limit_int_mic_boost(struct hda_codec *codec,
3566 const struct hda_fixup *fix,
3567 int action)
3568{
3569 struct alc_spec *spec = codec->spec;
3570 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
3571 int i;
3572
3573 /* The mic boosts on level 2 and 3 are too noisy
3574 on the internal mic input.
3575 Therefore limit the boost to 0 or 1. */
3576
3577 if (action != HDA_FIXUP_ACT_PROBE)
3578 return;
3579
3580 for (i = 0; i < cfg->num_inputs; i++) {
3581 hda_nid_t nid = cfg->inputs[i].pin;
3582 unsigned int defcfg;
3583 if (cfg->inputs[i].type != AUTO_PIN_MIC)
3584 continue;
3585 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3586 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
3587 continue;
3588
3589 snd_hda_override_amp_caps(codec, nid, HDA_INPUT,
3590 (0x00 << AC_AMPCAP_OFFSET_SHIFT) |
3591 (0x01 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3592 (0x2f << AC_AMPCAP_STEP_SIZE_SHIFT) |
3593 (0 << AC_AMPCAP_MUTE_SHIFT));
3594 }
3595}
3596
cd217a63
KY
3597static void alc283_hp_automute_hook(struct hda_codec *codec,
3598 struct hda_jack_tbl *jack)
3599{
3600 struct alc_spec *spec = codec->spec;
3601 int vref;
3602
3603 msleep(200);
3604 snd_hda_gen_hp_automute(codec, jack);
3605
3606 vref = spec->gen.hp_jack_present ? PIN_VREF80 : 0;
3607
3608 msleep(600);
3609 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3610 vref);
3611}
3612
3613static void alc283_chromebook_caps(struct hda_codec *codec)
3614{
3615 snd_hda_override_wcaps(codec, 0x03, 0);
3616}
3617
3618static void alc283_fixup_chromebook(struct hda_codec *codec,
3619 const struct hda_fixup *fix, int action)
3620{
3621 struct alc_spec *spec = codec->spec;
3622 int val;
3623
3624 switch (action) {
3625 case HDA_FIXUP_ACT_PRE_PROBE:
3626 alc283_chromebook_caps(codec);
d2e92709
TI
3627 /* Disable AA-loopback as it causes white noise */
3628 spec->gen.mixer_nid = 0;
cd217a63 3629 spec->gen.hp_automute_hook = alc283_hp_automute_hook;
38070219
KY
3630 break;
3631 case HDA_FIXUP_ACT_INIT:
cd217a63
KY
3632 /* MIC2-VREF control */
3633 /* Set to manual mode */
3634 val = alc_read_coef_idx(codec, 0x06);
3635 alc_write_coef_idx(codec, 0x06, val & ~0x000c);
068fd3a0
KY
3636 /* Enable Line1 input control by verb */
3637 val = alc_read_coef_idx(codec, 0x1a);
3638 alc_write_coef_idx(codec, 0x1a, val | (1 << 4));
cd217a63
KY
3639 break;
3640 }
3641}
3642
7bba2157
TI
3643/* mute tablet speaker pin (0x14) via dock plugging in addition */
3644static void asus_tx300_automute(struct hda_codec *codec)
3645{
3646 struct alc_spec *spec = codec->spec;
3647 snd_hda_gen_update_outputs(codec);
3648 if (snd_hda_jack_detect(codec, 0x1b))
3649 spec->gen.mute_bits |= (1ULL << 0x14);
3650}
3651
3652static void alc282_fixup_asus_tx300(struct hda_codec *codec,
3653 const struct hda_fixup *fix, int action)
3654{
3655 struct alc_spec *spec = codec->spec;
3656 /* TX300 needs to set up GPIO2 for the speaker amp */
3657 static const struct hda_verb gpio2_verbs[] = {
3658 { 0x01, AC_VERB_SET_GPIO_MASK, 0x04 },
3659 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04 },
3660 { 0x01, AC_VERB_SET_GPIO_DATA, 0x04 },
3661 {}
3662 };
3663 static const struct hda_pintbl dock_pins[] = {
3664 { 0x1b, 0x21114000 }, /* dock speaker pin */
3665 {}
3666 };
3667 struct snd_kcontrol *kctl;
3668
3669 switch (action) {
3670 case HDA_FIXUP_ACT_PRE_PROBE:
3671 snd_hda_add_verbs(codec, gpio2_verbs);
3672 snd_hda_apply_pincfgs(codec, dock_pins);
3673 spec->gen.auto_mute_via_amp = 1;
3674 spec->gen.automute_hook = asus_tx300_automute;
3675 snd_hda_jack_detect_enable_callback(codec, 0x1b,
3676 HDA_GEN_HP_EVENT,
3677 snd_hda_gen_hp_automute);
3678 break;
3679 case HDA_FIXUP_ACT_BUILD:
3680 /* this is a bit tricky; give more sane names for the main
3681 * (tablet) speaker and the dock speaker, respectively
3682 */
3683 kctl = snd_hda_find_mixer_ctl(codec, "Speaker Playback Switch");
3684 if (kctl)
3685 strcpy(kctl->id.name, "Dock Speaker Playback Switch");
3686 kctl = snd_hda_find_mixer_ctl(codec, "Bass Speaker Playback Switch");
3687 if (kctl)
3688 strcpy(kctl->id.name, "Speaker Playback Switch");
3689 break;
3690 }
3691}
3692
338cae56
DH
3693static void alc290_fixup_mono_speakers(struct hda_codec *codec,
3694 const struct hda_fixup *fix, int action)
3695{
3696 if (action == HDA_FIXUP_ACT_PRE_PROBE)
3697 /* Remove DAC node 0x03, as it seems to be
3698 giving mono output */
3699 snd_hda_override_wcaps(codec, 0x03, 0);
3700}
3701
b67ae3f1
DH
3702#if IS_ENABLED(CONFIG_THINKPAD_ACPI)
3703
3704#include <linux/thinkpad_acpi.h>
2793769f 3705#include <acpi/acpi.h>
b67ae3f1
DH
3706
3707static int (*led_set_func)(int, bool);
3708
2793769f
DH
3709static acpi_status acpi_check_cb(acpi_handle handle, u32 lvl, void *context,
3710 void **rv)
3711{
3712 bool *found = context;
3713 *found = true;
3714 return AE_OK;
3715}
3716
3717static bool is_thinkpad(struct hda_codec *codec)
3718{
3719 bool found = false;
3720 if (codec->subsystem_id >> 16 != 0x17aa)
3721 return false;
3722 if (ACPI_SUCCESS(acpi_get_devices("LEN0068", acpi_check_cb, &found, NULL)) && found)
3723 return true;
3724 found = false;
3725 return ACPI_SUCCESS(acpi_get_devices("IBM0068", acpi_check_cb, &found, NULL)) && found;
3726}
3727
b67ae3f1
DH
3728static void update_tpacpi_mute_led(void *private_data, int enabled)
3729{
3730 if (led_set_func)
3731 led_set_func(TPACPI_LED_MUTE, !enabled);
3732}
3733
3734static void update_tpacpi_micmute_led(struct hda_codec *codec,
3735 struct snd_ctl_elem_value *ucontrol)
3736{
3737 if (!ucontrol || !led_set_func)
3738 return;
3739 if (strcmp("Capture Switch", ucontrol->id.name) == 0 && ucontrol->id.index == 0) {
3740 /* TODO: How do I verify if it's a mono or stereo here? */
3741 bool val = ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1];
3742 led_set_func(TPACPI_LED_MICMUTE, !val);
3743 }
3744}
3745
3746static void alc_fixup_thinkpad_acpi(struct hda_codec *codec,
3747 const struct hda_fixup *fix, int action)
3748{
3749 struct alc_spec *spec = codec->spec;
3750 bool removefunc = false;
3751
3752 if (action == HDA_FIXUP_ACT_PROBE) {
2793769f
DH
3753 if (!is_thinkpad(codec))
3754 return;
b67ae3f1
DH
3755 if (!led_set_func)
3756 led_set_func = symbol_request(tpacpi_led_set);
3757 if (!led_set_func) {
3758 snd_printk(KERN_WARNING "Failed to find thinkpad-acpi symbol tpacpi_led_set\n");
3759 return;
3760 }
3761
3762 removefunc = true;
3763 if (led_set_func(TPACPI_LED_MUTE, false) >= 0) {
3764 spec->gen.vmaster_mute.hook = update_tpacpi_mute_led;
3765 removefunc = false;
3766 }
3767 if (led_set_func(TPACPI_LED_MICMUTE, false) >= 0) {
3768 if (spec->gen.num_adc_nids > 1)
3769 snd_printdd("Skipping micmute LED control due to several ADCs");
3770 else {
3771 spec->gen.cap_sync_hook = update_tpacpi_micmute_led;
3772 removefunc = false;
3773 }
3774 }
3775 }
3776
3777 if (led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) {
3778 symbol_put(tpacpi_led_set);
3779 led_set_func = NULL;
3780 }
3781}
3782
3783#else
3784
3785static void alc_fixup_thinkpad_acpi(struct hda_codec *codec,
3786 const struct hda_fixup *fix, int action)
3787{
3788}
3789
3790#endif
3791
1d045db9
TI
3792enum {
3793 ALC269_FIXUP_SONY_VAIO,
3794 ALC275_FIXUP_SONY_VAIO_GPIO2,
3795 ALC269_FIXUP_DELL_M101Z,
3796 ALC269_FIXUP_SKU_IGNORE,
3797 ALC269_FIXUP_ASUS_G73JW,
3798 ALC269_FIXUP_LENOVO_EAPD,
3799 ALC275_FIXUP_SONY_HWEQ,
3800 ALC271_FIXUP_DMIC,
017f2a10 3801 ALC269_FIXUP_PCM_44K,
adabb3ec 3802 ALC269_FIXUP_STEREO_DMIC,
7c478f03 3803 ALC269_FIXUP_HEADSET_MIC,
24519911
TI
3804 ALC269_FIXUP_QUANTA_MUTE,
3805 ALC269_FIXUP_LIFEBOOK,
a4297b5d
TI
3806 ALC269_FIXUP_AMIC,
3807 ALC269_FIXUP_DMIC,
3808 ALC269VB_FIXUP_AMIC,
3809 ALC269VB_FIXUP_DMIC,
08fb0d0e 3810 ALC269_FIXUP_HP_MUTE_LED,
d06ac143 3811 ALC269_FIXUP_HP_MUTE_LED_MIC1,
08fb0d0e 3812 ALC269_FIXUP_HP_MUTE_LED_MIC2,
9f5c6faf 3813 ALC269_FIXUP_HP_GPIO_LED,
693b613d 3814 ALC269_FIXUP_INV_DMIC,
108cc108 3815 ALC269_FIXUP_LENOVO_DOCK,
88cfcf86 3816 ALC286_FIXUP_SONY_MIC_NO_PRESENCE,
108cc108 3817 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
73bdd597
DH
3818 ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
3819 ALC269_FIXUP_DELL2_MIC_NO_PRESENCE,
338cae56 3820 ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
73bdd597
DH
3821 ALC269_FIXUP_HEADSET_MODE,
3822 ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC,
d240d1dc
DH
3823 ALC269_FIXUP_ASUS_X101_FUNC,
3824 ALC269_FIXUP_ASUS_X101_VERB,
3825 ALC269_FIXUP_ASUS_X101,
08a978db
DR
3826 ALC271_FIXUP_AMIC_MIC2,
3827 ALC271_FIXUP_HP_GATE_MIC_JACK,
42397004 3828 ALC269_FIXUP_ACER_AC700,
3e0d611b 3829 ALC269_FIXUP_LIMIT_INT_MIC_BOOST,
2cede303 3830 ALC269VB_FIXUP_ASUS_ZENBOOK,
8e35cd4a 3831 ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED,
02b504d9 3832 ALC269VB_FIXUP_ORDISSIMO_EVE2,
cd217a63 3833 ALC283_FIXUP_CHROME_BOOK,
7bba2157 3834 ALC282_FIXUP_ASUS_TX300,
1bb3e062 3835 ALC283_FIXUP_INT_MIC,
338cae56 3836 ALC290_FIXUP_MONO_SPEAKERS,
b67ae3f1 3837 ALC269_FIXUP_THINKPAD_ACPI,
9a22a8f5
KY
3838 ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
3839 ALC255_FIXUP_HEADSET_MODE,
f1d4e28b
KY
3840};
3841
1727a771 3842static const struct hda_fixup alc269_fixups[] = {
1d045db9 3843 [ALC269_FIXUP_SONY_VAIO] = {
fd108215
TI
3844 .type = HDA_FIXUP_PINCTLS,
3845 .v.pins = (const struct hda_pintbl[]) {
3846 {0x19, PIN_VREFGRD},
1d045db9
TI
3847 {}
3848 }
f1d4e28b 3849 },
1d045db9 3850 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
1727a771 3851 .type = HDA_FIXUP_VERBS,
1d045db9
TI
3852 .v.verbs = (const struct hda_verb[]) {
3853 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
3854 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
3855 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
3856 { }
3857 },
3858 .chained = true,
3859 .chain_id = ALC269_FIXUP_SONY_VAIO
3860 },
3861 [ALC269_FIXUP_DELL_M101Z] = {
1727a771 3862 .type = HDA_FIXUP_VERBS,
1d045db9
TI
3863 .v.verbs = (const struct hda_verb[]) {
3864 /* Enables internal speaker */
3865 {0x20, AC_VERB_SET_COEF_INDEX, 13},
3866 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
3867 {}
3868 }
3869 },
3870 [ALC269_FIXUP_SKU_IGNORE] = {
1727a771 3871 .type = HDA_FIXUP_FUNC,
23d30f28 3872 .v.func = alc_fixup_sku_ignore,
1d045db9
TI
3873 },
3874 [ALC269_FIXUP_ASUS_G73JW] = {
1727a771
TI
3875 .type = HDA_FIXUP_PINS,
3876 .v.pins = (const struct hda_pintbl[]) {
1d045db9
TI
3877 { 0x17, 0x99130111 }, /* subwoofer */
3878 { }
3879 }
3880 },
3881 [ALC269_FIXUP_LENOVO_EAPD] = {
1727a771 3882 .type = HDA_FIXUP_VERBS,
1d045db9
TI
3883 .v.verbs = (const struct hda_verb[]) {
3884 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
3885 {}
3886 }
3887 },
3888 [ALC275_FIXUP_SONY_HWEQ] = {
1727a771 3889 .type = HDA_FIXUP_FUNC,
1d045db9
TI
3890 .v.func = alc269_fixup_hweq,
3891 .chained = true,
3892 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
3893 },
3894 [ALC271_FIXUP_DMIC] = {
1727a771 3895 .type = HDA_FIXUP_FUNC,
1d045db9 3896 .v.func = alc271_fixup_dmic,
f1d4e28b 3897 },
017f2a10 3898 [ALC269_FIXUP_PCM_44K] = {
1727a771 3899 .type = HDA_FIXUP_FUNC,
017f2a10 3900 .v.func = alc269_fixup_pcm_44k,
012e7eb1
DH
3901 .chained = true,
3902 .chain_id = ALC269_FIXUP_QUANTA_MUTE
017f2a10 3903 },
adabb3ec 3904 [ALC269_FIXUP_STEREO_DMIC] = {
1727a771 3905 .type = HDA_FIXUP_FUNC,
adabb3ec
TI
3906 .v.func = alc269_fixup_stereo_dmic,
3907 },
7c478f03
DH
3908 [ALC269_FIXUP_HEADSET_MIC] = {
3909 .type = HDA_FIXUP_FUNC,
3910 .v.func = alc269_fixup_headset_mic,
3911 },
24519911 3912 [ALC269_FIXUP_QUANTA_MUTE] = {
1727a771 3913 .type = HDA_FIXUP_FUNC,
24519911
TI
3914 .v.func = alc269_fixup_quanta_mute,
3915 },
3916 [ALC269_FIXUP_LIFEBOOK] = {
1727a771
TI
3917 .type = HDA_FIXUP_PINS,
3918 .v.pins = (const struct hda_pintbl[]) {
24519911
TI
3919 { 0x1a, 0x2101103f }, /* dock line-out */
3920 { 0x1b, 0x23a11040 }, /* dock mic-in */
3921 { }
3922 },
3923 .chained = true,
3924 .chain_id = ALC269_FIXUP_QUANTA_MUTE
3925 },
a4297b5d 3926 [ALC269_FIXUP_AMIC] = {
1727a771
TI
3927 .type = HDA_FIXUP_PINS,
3928 .v.pins = (const struct hda_pintbl[]) {
a4297b5d
TI
3929 { 0x14, 0x99130110 }, /* speaker */
3930 { 0x15, 0x0121401f }, /* HP out */
3931 { 0x18, 0x01a19c20 }, /* mic */
3932 { 0x19, 0x99a3092f }, /* int-mic */
3933 { }
3934 },
3935 },
3936 [ALC269_FIXUP_DMIC] = {
1727a771
TI
3937 .type = HDA_FIXUP_PINS,
3938 .v.pins = (const struct hda_pintbl[]) {
a4297b5d
TI
3939 { 0x12, 0x99a3092f }, /* int-mic */
3940 { 0x14, 0x99130110 }, /* speaker */
3941 { 0x15, 0x0121401f }, /* HP out */
3942 { 0x18, 0x01a19c20 }, /* mic */
3943 { }
3944 },
3945 },
3946 [ALC269VB_FIXUP_AMIC] = {
1727a771
TI
3947 .type = HDA_FIXUP_PINS,
3948 .v.pins = (const struct hda_pintbl[]) {
a4297b5d
TI
3949 { 0x14, 0x99130110 }, /* speaker */
3950 { 0x18, 0x01a19c20 }, /* mic */
3951 { 0x19, 0x99a3092f }, /* int-mic */
3952 { 0x21, 0x0121401f }, /* HP out */
3953 { }
3954 },
3955 },
2267ea97 3956 [ALC269VB_FIXUP_DMIC] = {
1727a771
TI
3957 .type = HDA_FIXUP_PINS,
3958 .v.pins = (const struct hda_pintbl[]) {
a4297b5d
TI
3959 { 0x12, 0x99a3092f }, /* int-mic */
3960 { 0x14, 0x99130110 }, /* speaker */
3961 { 0x18, 0x01a19c20 }, /* mic */
3962 { 0x21, 0x0121401f }, /* HP out */
3963 { }
3964 },
3965 },
08fb0d0e 3966 [ALC269_FIXUP_HP_MUTE_LED] = {
1727a771 3967 .type = HDA_FIXUP_FUNC,
08fb0d0e 3968 .v.func = alc269_fixup_hp_mute_led,
6d3cd5d4 3969 },
d06ac143
DH
3970 [ALC269_FIXUP_HP_MUTE_LED_MIC1] = {
3971 .type = HDA_FIXUP_FUNC,
3972 .v.func = alc269_fixup_hp_mute_led_mic1,
3973 },
08fb0d0e 3974 [ALC269_FIXUP_HP_MUTE_LED_MIC2] = {
1727a771 3975 .type = HDA_FIXUP_FUNC,
08fb0d0e 3976 .v.func = alc269_fixup_hp_mute_led_mic2,
420b0feb 3977 },
9f5c6faf
TI
3978 [ALC269_FIXUP_HP_GPIO_LED] = {
3979 .type = HDA_FIXUP_FUNC,
3980 .v.func = alc269_fixup_hp_gpio_led,
3981 },
693b613d 3982 [ALC269_FIXUP_INV_DMIC] = {
1727a771 3983 .type = HDA_FIXUP_FUNC,
6e72aa5f 3984 .v.func = alc_fixup_inv_dmic_0x12,
693b613d 3985 },
108cc108 3986 [ALC269_FIXUP_LENOVO_DOCK] = {
1727a771
TI
3987 .type = HDA_FIXUP_PINS,
3988 .v.pins = (const struct hda_pintbl[]) {
108cc108
DH
3989 { 0x19, 0x23a11040 }, /* dock mic */
3990 { 0x1b, 0x2121103f }, /* dock headphone */
3991 { }
3992 },
3993 .chained = true,
3994 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
3995 },
3996 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
1727a771 3997 .type = HDA_FIXUP_FUNC,
108cc108 3998 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
52129000
DH
3999 .chained = true,
4000 .chain_id = ALC269_FIXUP_THINKPAD_ACPI,
108cc108 4001 },
73bdd597
DH
4002 [ALC269_FIXUP_DELL1_MIC_NO_PRESENCE] = {
4003 .type = HDA_FIXUP_PINS,
4004 .v.pins = (const struct hda_pintbl[]) {
4005 { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4006 { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
4007 { }
4008 },
4009 .chained = true,
4010 .chain_id = ALC269_FIXUP_HEADSET_MODE
4011 },
4012 [ALC269_FIXUP_DELL2_MIC_NO_PRESENCE] = {
4013 .type = HDA_FIXUP_PINS,
4014 .v.pins = (const struct hda_pintbl[]) {
4015 { 0x16, 0x21014020 }, /* dock line out */
4016 { 0x19, 0x21a19030 }, /* dock mic */
4017 { 0x1a, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4018 { }
4019 },
4020 .chained = true,
4021 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
4022 },
338cae56
DH
4023 [ALC269_FIXUP_DELL3_MIC_NO_PRESENCE] = {
4024 .type = HDA_FIXUP_PINS,
4025 .v.pins = (const struct hda_pintbl[]) {
4026 { 0x1a, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4027 { }
4028 },
4029 .chained = true,
4030 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
4031 },
73bdd597
DH
4032 [ALC269_FIXUP_HEADSET_MODE] = {
4033 .type = HDA_FIXUP_FUNC,
4034 .v.func = alc_fixup_headset_mode,
4035 },
4036 [ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC] = {
4037 .type = HDA_FIXUP_FUNC,
4038 .v.func = alc_fixup_headset_mode_no_hp_mic,
4039 },
88cfcf86
DH
4040 [ALC286_FIXUP_SONY_MIC_NO_PRESENCE] = {
4041 .type = HDA_FIXUP_PINS,
4042 .v.pins = (const struct hda_pintbl[]) {
4043 { 0x18, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4044 { }
4045 },
fbc78ad6
DH
4046 .chained = true,
4047 .chain_id = ALC269_FIXUP_HEADSET_MIC
88cfcf86 4048 },
d240d1dc
DH
4049 [ALC269_FIXUP_ASUS_X101_FUNC] = {
4050 .type = HDA_FIXUP_FUNC,
4051 .v.func = alc269_fixup_x101_headset_mic,
4052 },
4053 [ALC269_FIXUP_ASUS_X101_VERB] = {
4054 .type = HDA_FIXUP_VERBS,
4055 .v.verbs = (const struct hda_verb[]) {
4056 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4057 {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
4058 {0x20, AC_VERB_SET_PROC_COEF, 0x0310},
4059 { }
4060 },
4061 .chained = true,
4062 .chain_id = ALC269_FIXUP_ASUS_X101_FUNC
4063 },
4064 [ALC269_FIXUP_ASUS_X101] = {
4065 .type = HDA_FIXUP_PINS,
4066 .v.pins = (const struct hda_pintbl[]) {
4067 { 0x18, 0x04a1182c }, /* Headset mic */
4068 { }
4069 },
4070 .chained = true,
4071 .chain_id = ALC269_FIXUP_ASUS_X101_VERB
4072 },
08a978db 4073 [ALC271_FIXUP_AMIC_MIC2] = {
1727a771
TI
4074 .type = HDA_FIXUP_PINS,
4075 .v.pins = (const struct hda_pintbl[]) {
08a978db
DR
4076 { 0x14, 0x99130110 }, /* speaker */
4077 { 0x19, 0x01a19c20 }, /* mic */
4078 { 0x1b, 0x99a7012f }, /* int-mic */
4079 { 0x21, 0x0121401f }, /* HP out */
4080 { }
4081 },
4082 },
4083 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
1727a771 4084 .type = HDA_FIXUP_FUNC,
08a978db
DR
4085 .v.func = alc271_hp_gate_mic_jack,
4086 .chained = true,
4087 .chain_id = ALC271_FIXUP_AMIC_MIC2,
4088 },
42397004
DR
4089 [ALC269_FIXUP_ACER_AC700] = {
4090 .type = HDA_FIXUP_PINS,
4091 .v.pins = (const struct hda_pintbl[]) {
4092 { 0x12, 0x99a3092f }, /* int-mic */
4093 { 0x14, 0x99130110 }, /* speaker */
4094 { 0x18, 0x03a11c20 }, /* mic */
4095 { 0x1e, 0x0346101e }, /* SPDIF1 */
4096 { 0x21, 0x0321101f }, /* HP out */
4097 { }
4098 },
4099 .chained = true,
4100 .chain_id = ALC271_FIXUP_DMIC,
4101 },
3e0d611b
DH
4102 [ALC269_FIXUP_LIMIT_INT_MIC_BOOST] = {
4103 .type = HDA_FIXUP_FUNC,
4104 .v.func = alc269_fixup_limit_int_mic_boost,
2793769f
DH
4105 .chained = true,
4106 .chain_id = ALC269_FIXUP_THINKPAD_ACPI,
3e0d611b 4107 },
2cede303
OR
4108 [ALC269VB_FIXUP_ASUS_ZENBOOK] = {
4109 .type = HDA_FIXUP_FUNC,
4110 .v.func = alc269_fixup_limit_int_mic_boost,
4111 .chained = true,
4112 .chain_id = ALC269VB_FIXUP_DMIC,
4113 },
8e35cd4a
DH
4114 [ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED] = {
4115 .type = HDA_FIXUP_FUNC,
4116 .v.func = alc269_fixup_limit_int_mic_boost,
4117 .chained = true,
4118 .chain_id = ALC269_FIXUP_HP_MUTE_LED_MIC1,
4119 },
02b504d9
AA
4120 [ALC269VB_FIXUP_ORDISSIMO_EVE2] = {
4121 .type = HDA_FIXUP_PINS,
4122 .v.pins = (const struct hda_pintbl[]) {
4123 { 0x12, 0x99a3092f }, /* int-mic */
4124 { 0x18, 0x03a11d20 }, /* mic */
4125 { 0x19, 0x411111f0 }, /* Unused bogus pin */
4126 { }
4127 },
4128 },
cd217a63
KY
4129 [ALC283_FIXUP_CHROME_BOOK] = {
4130 .type = HDA_FIXUP_FUNC,
4131 .v.func = alc283_fixup_chromebook,
4132 },
7bba2157
TI
4133 [ALC282_FIXUP_ASUS_TX300] = {
4134 .type = HDA_FIXUP_FUNC,
4135 .v.func = alc282_fixup_asus_tx300,
4136 },
1bb3e062
KY
4137 [ALC283_FIXUP_INT_MIC] = {
4138 .type = HDA_FIXUP_VERBS,
4139 .v.verbs = (const struct hda_verb[]) {
4140 {0x20, AC_VERB_SET_COEF_INDEX, 0x1a},
4141 {0x20, AC_VERB_SET_PROC_COEF, 0x0011},
4142 { }
4143 },
4144 .chained = true,
4145 .chain_id = ALC269_FIXUP_LIMIT_INT_MIC_BOOST
4146 },
338cae56
DH
4147 [ALC290_FIXUP_MONO_SPEAKERS] = {
4148 .type = HDA_FIXUP_FUNC,
4149 .v.func = alc290_fixup_mono_speakers,
4150 .chained = true,
4151 .chain_id = ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
4152 },
b67ae3f1
DH
4153 [ALC269_FIXUP_THINKPAD_ACPI] = {
4154 .type = HDA_FIXUP_FUNC,
4155 .v.func = alc_fixup_thinkpad_acpi,
b67ae3f1 4156 },
9a22a8f5
KY
4157 [ALC255_FIXUP_DELL1_MIC_NO_PRESENCE] = {
4158 .type = HDA_FIXUP_PINS,
4159 .v.pins = (const struct hda_pintbl[]) {
4160 { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4161 { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
4162 { }
4163 },
4164 .chained = true,
4165 .chain_id = ALC255_FIXUP_HEADSET_MODE
4166 },
4167 [ALC255_FIXUP_HEADSET_MODE] = {
4168 .type = HDA_FIXUP_FUNC,
4169 .v.func = alc_fixup_headset_mode_alc255,
4170 },
f1d4e28b
KY
4171};
4172
1d045db9 4173static const struct snd_pci_quirk alc269_fixup_tbl[] = {
693b613d
DH
4174 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
4175 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
aaedfb47
DH
4176 SND_PCI_QUIRK(0x1025, 0x047c, "Acer AC700", ALC269_FIXUP_ACER_AC700),
4177 SND_PCI_QUIRK(0x1025, 0x0740, "Acer AO725", ALC271_FIXUP_HP_GATE_MIC_JACK),
4178 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
4179 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
4180 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
73bdd597
DH
4181 SND_PCI_QUIRK(0x1028, 0x05bd, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
4182 SND_PCI_QUIRK(0x1028, 0x05be, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
4183 SND_PCI_QUIRK(0x1028, 0x05c4, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4184 SND_PCI_QUIRK(0x1028, 0x05c5, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4185 SND_PCI_QUIRK(0x1028, 0x05c6, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4186 SND_PCI_QUIRK(0x1028, 0x05c7, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4187 SND_PCI_QUIRK(0x1028, 0x05c8, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4188 SND_PCI_QUIRK(0x1028, 0x05c9, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4189 SND_PCI_QUIRK(0x1028, 0x05ca, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
4190 SND_PCI_QUIRK(0x1028, 0x05cb, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
05843c07
KY
4191 SND_PCI_QUIRK(0x1028, 0x05cc, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
4192 SND_PCI_QUIRK(0x1028, 0x05cd, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
436c4a0c 4193 SND_PCI_QUIRK(0x1028, 0x05de, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
d81bf8cf 4194 SND_PCI_QUIRK(0x1028, 0x05e0, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
73bdd597
DH
4195 SND_PCI_QUIRK(0x1028, 0x05e9, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4196 SND_PCI_QUIRK(0x1028, 0x05ea, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4197 SND_PCI_QUIRK(0x1028, 0x05eb, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4198 SND_PCI_QUIRK(0x1028, 0x05ec, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4199 SND_PCI_QUIRK(0x1028, 0x05ed, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4200 SND_PCI_QUIRK(0x1028, 0x05ee, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4201 SND_PCI_QUIRK(0x1028, 0x05f3, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4202 SND_PCI_QUIRK(0x1028, 0x05f4, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4203 SND_PCI_QUIRK(0x1028, 0x05f5, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4204 SND_PCI_QUIRK(0x1028, 0x05f6, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3ee2102f 4205 SND_PCI_QUIRK(0x1028, 0x05f8, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
cd6fb679
DH
4206 SND_PCI_QUIRK(0x1028, 0x05f9, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4207 SND_PCI_QUIRK(0x1028, 0x05fb, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
d81bf8cf
DH
4208 SND_PCI_QUIRK(0x1028, 0x0606, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4209 SND_PCI_QUIRK(0x1028, 0x0608, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3ee2102f 4210 SND_PCI_QUIRK(0x1028, 0x0609, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
6c29d68a 4211 SND_PCI_QUIRK(0x1028, 0x0613, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
b8362e70 4212 SND_PCI_QUIRK(0x1028, 0x0614, "Dell Inspiron 3135", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
338cae56 4213 SND_PCI_QUIRK(0x1028, 0x0616, "Dell Vostro 5470", ALC290_FIXUP_MONO_SPEAKERS),
9a22a8f5
KY
4214 SND_PCI_QUIRK(0x1028, 0x061f, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
4215 SND_PCI_QUIRK(0x1028, 0x063f, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
05843c07
KY
4216 SND_PCI_QUIRK(0x1028, 0x15cc, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
4217 SND_PCI_QUIRK(0x1028, 0x15cd, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
08fb0d0e 4218 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
9f5c6faf 4219 SND_PCI_QUIRK(0x103c, 0x18e6, "HP", ALC269_FIXUP_HP_GPIO_LED),
d06ac143
DH
4220 SND_PCI_QUIRK(0x103c, 0x1973, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4221 SND_PCI_QUIRK(0x103c, 0x1983, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
8e35cd4a 4222 SND_PCI_QUIRK(0x103c, 0x218b, "HP", ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED),
cd217a63 4223 SND_PCI_QUIRK(0x103c, 0x21ed, "HP Falco Chromebook", ALC283_FIXUP_CHROME_BOOK),
08fb0d0e 4224 SND_PCI_QUIRK_VENDOR(0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED),
7bba2157 4225 SND_PCI_QUIRK(0x1043, 0x103f, "ASUS TX300", ALC282_FIXUP_ASUS_TX300),
3e0d611b
DH
4226 SND_PCI_QUIRK(0x1043, 0x106d, "Asus K53BE", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4227 SND_PCI_QUIRK(0x1043, 0x115d, "Asus 1015E", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
2cede303
OR
4228 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_ASUS_ZENBOOK),
4229 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_ASUS_ZENBOOK),
3e0d611b 4230 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
017f2a10 4231 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
693b613d 4232 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
3e0d611b 4233 SND_PCI_QUIRK(0x1043, 0x1c23, "Asus X55U", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
adabb3ec
TI
4234 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
4235 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
4236 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4237 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
d240d1dc 4238 SND_PCI_QUIRK(0x1043, 0x8516, "ASUS X101CH", ALC269_FIXUP_ASUS_X101),
88cfcf86 4239 SND_PCI_QUIRK(0x104d, 0x90b6, "Sony VAIO Pro 13", ALC286_FIXUP_SONY_MIC_NO_PRESENCE),
1d045db9
TI
4240 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
4241 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4242 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4243 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
24519911 4244 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
1d045db9
TI
4245 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
4246 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
4247 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
4248 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
4249 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
707fba3f 4250 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
c8415a48 4251 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
84f98fdf 4252 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
4407be6b 4253 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
108cc108 4254 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
aaedfb47 4255 SND_PCI_QUIRK(0x17aa, 0x2208, "Thinkpad T431s", ALC269_FIXUP_LENOVO_DOCK),
cd5302c0
DH
4256 SND_PCI_QUIRK(0x17aa, 0x220c, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4257 SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
2793769f 4258 SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
a4a9e082
DH
4259 SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4260 SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
1bb3e062 4261 SND_PCI_QUIRK(0x17aa, 0x501a, "Thinkpad", ALC283_FIXUP_INT_MIC),
cd5302c0
DH
4262 SND_PCI_QUIRK(0x17aa, 0x5026, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4263 SND_PCI_QUIRK(0x17aa, 0x5109, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
012e7eb1 4264 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
1d045db9 4265 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
2793769f 4266 SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad", ALC269_FIXUP_THINKPAD_ACPI),
02b504d9 4267 SND_PCI_QUIRK(0x1b7d, 0xa831, "Ordissimo EVE2 ", ALC269VB_FIXUP_ORDISSIMO_EVE2), /* Also known as Malata PC-B1303 */
a4297b5d 4268
a7f3eedc 4269#if 0
a4297b5d
TI
4270 /* Below is a quirk table taken from the old code.
4271 * Basically the device should work as is without the fixup table.
4272 * If BIOS doesn't give a proper info, enable the corresponding
4273 * fixup entry.
7d7eb9ea 4274 */
a4297b5d
TI
4275 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
4276 ALC269_FIXUP_AMIC),
4277 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
a4297b5d
TI
4278 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
4279 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
4280 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
4281 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
4282 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
4283 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
4284 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
4285 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
4286 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
4287 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
4288 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
4289 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
4290 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
4291 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
4292 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
4293 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
4294 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
4295 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
4296 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
4297 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
4298 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
4299 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
4300 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
4301 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
4302 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
4303 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
4304 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
4305 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
4306 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
4307 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
4308 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
4309 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
4310 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
4311 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
4312 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
4313 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
4314 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
4315 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
4316#endif
4317 {}
4318};
4319
1727a771 4320static const struct hda_model_fixup alc269_fixup_models[] = {
a4297b5d
TI
4321 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
4322 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
6e72aa5f
TI
4323 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
4324 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
4325 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
7c478f03 4326 {.id = ALC269_FIXUP_HEADSET_MIC, .name = "headset-mic"},
108cc108 4327 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
9f5c6faf 4328 {.id = ALC269_FIXUP_HP_GPIO_LED, .name = "hp-gpio-led"},
e32aa85a
DH
4329 {.id = ALC269_FIXUP_DELL1_MIC_NO_PRESENCE, .name = "dell-headset-multi"},
4330 {.id = ALC269_FIXUP_DELL2_MIC_NO_PRESENCE, .name = "dell-headset-dock"},
1d045db9 4331 {}
6dda9f4a
KY
4332};
4333
6dda9f4a 4334
546bb678 4335static void alc269_fill_coef(struct hda_codec *codec)
1d045db9 4336{
526af6eb 4337 struct alc_spec *spec = codec->spec;
1d045db9 4338 int val;
ebb83eeb 4339
526af6eb 4340 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
546bb678 4341 return;
526af6eb 4342
1bb7e43e 4343 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
1d045db9
TI
4344 alc_write_coef_idx(codec, 0xf, 0x960b);
4345 alc_write_coef_idx(codec, 0xe, 0x8817);
4346 }
ebb83eeb 4347
1bb7e43e 4348 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
1d045db9
TI
4349 alc_write_coef_idx(codec, 0xf, 0x960b);
4350 alc_write_coef_idx(codec, 0xe, 0x8814);
4351 }
ebb83eeb 4352
1bb7e43e 4353 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
1d045db9
TI
4354 val = alc_read_coef_idx(codec, 0x04);
4355 /* Power up output pin */
4356 alc_write_coef_idx(codec, 0x04, val | (1<<11));
4357 }
ebb83eeb 4358
1bb7e43e 4359 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
1d045db9
TI
4360 val = alc_read_coef_idx(codec, 0xd);
4361 if ((val & 0x0c00) >> 10 != 0x1) {
4362 /* Capless ramp up clock control */
4363 alc_write_coef_idx(codec, 0xd, val | (1<<10));
4364 }
4365 val = alc_read_coef_idx(codec, 0x17);
4366 if ((val & 0x01c0) >> 6 != 0x4) {
4367 /* Class D power on reset */
4368 alc_write_coef_idx(codec, 0x17, val | (1<<7));
4369 }
4370 }
ebb83eeb 4371
1d045db9
TI
4372 val = alc_read_coef_idx(codec, 0xd); /* Class D */
4373 alc_write_coef_idx(codec, 0xd, val | (1<<14));
bc9f98a9 4374
1d045db9
TI
4375 val = alc_read_coef_idx(codec, 0x4); /* HP */
4376 alc_write_coef_idx(codec, 0x4, val | (1<<11));
1d045db9 4377}
a7f2371f 4378
1d045db9
TI
4379/*
4380 */
1d045db9
TI
4381static int patch_alc269(struct hda_codec *codec)
4382{
4383 struct alc_spec *spec;
3de95173 4384 int err;
f1d4e28b 4385
3de95173 4386 err = alc_alloc_spec(codec, 0x0b);
e16fb6d1 4387 if (err < 0)
3de95173
TI
4388 return err;
4389
4390 spec = codec->spec;
08c189f2 4391 spec->gen.shared_mic_vref_pin = 0x18;
e16fb6d1 4392
1727a771 4393 snd_hda_pick_fixup(codec, alc269_fixup_models,
9f720bb9 4394 alc269_fixup_tbl, alc269_fixups);
1727a771 4395 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
9f720bb9
HRK
4396
4397 alc_auto_parse_customize_define(codec);
4398
7504b6cd
TI
4399 if (has_cdefine_beep(codec))
4400 spec->gen.beep_nid = 0x01;
4401
065380f0
KY
4402 switch (codec->vendor_id) {
4403 case 0x10ec0269:
1d045db9 4404 spec->codec_variant = ALC269_TYPE_ALC269VA;
1bb7e43e
TI
4405 switch (alc_get_coef0(codec) & 0x00f0) {
4406 case 0x0010:
1d045db9 4407 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
e16fb6d1 4408 spec->cdefine.platform_type == 1)
20ca0c35 4409 err = alc_codec_rename(codec, "ALC271X");
1d045db9 4410 spec->codec_variant = ALC269_TYPE_ALC269VB;
1bb7e43e
TI
4411 break;
4412 case 0x0020:
e16fb6d1
TI
4413 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
4414 codec->bus->pci->subsystem_device == 0x21f3)
20ca0c35 4415 err = alc_codec_rename(codec, "ALC3202");
1d045db9 4416 spec->codec_variant = ALC269_TYPE_ALC269VC;
1bb7e43e 4417 break;
adcc70b2
KY
4418 case 0x0030:
4419 spec->codec_variant = ALC269_TYPE_ALC269VD;
4420 break;
1bb7e43e 4421 default:
1d045db9 4422 alc_fix_pll_init(codec, 0x20, 0x04, 15);
1bb7e43e 4423 }
e16fb6d1
TI
4424 if (err < 0)
4425 goto error;
546bb678 4426 spec->init_hook = alc269_fill_coef;
1d045db9 4427 alc269_fill_coef(codec);
065380f0
KY
4428 break;
4429
4430 case 0x10ec0280:
4431 case 0x10ec0290:
4432 spec->codec_variant = ALC269_TYPE_ALC280;
4433 break;
4434 case 0x10ec0282:
065380f0
KY
4435 spec->codec_variant = ALC269_TYPE_ALC282;
4436 break;
2af02be7
KY
4437 case 0x10ec0233:
4438 case 0x10ec0283:
4439 spec->codec_variant = ALC269_TYPE_ALC283;
4440 spec->shutup = alc283_shutup;
4441 spec->init_hook = alc283_init;
4442 break;
065380f0
KY
4443 case 0x10ec0284:
4444 case 0x10ec0292:
4445 spec->codec_variant = ALC269_TYPE_ALC284;
4446 break;
161ebf29
KY
4447 case 0x10ec0285:
4448 case 0x10ec0293:
4449 spec->codec_variant = ALC269_TYPE_ALC285;
4450 break;
7fc7d047
KY
4451 case 0x10ec0286:
4452 spec->codec_variant = ALC269_TYPE_ALC286;
4453 break;
1d04c9de
KY
4454 case 0x10ec0255:
4455 spec->codec_variant = ALC269_TYPE_ALC255;
4456 break;
1d045db9 4457 }
6dda9f4a 4458
ad60d502
KY
4459 if (snd_hda_codec_read(codec, 0x51, 0, AC_VERB_PARAMETERS, 0) == 0x10ec5505) {
4460 spec->has_alc5505_dsp = true;
4461 spec->init_hook = alc5505_dsp_init;
4462 }
4463
a4297b5d
TI
4464 /* automatic parse from the BIOS config */
4465 err = alc269_parse_auto_config(codec);
e16fb6d1
TI
4466 if (err < 0)
4467 goto error;
6dda9f4a 4468
7504b6cd 4469 if (!spec->gen.no_analog && spec->gen.beep_nid)
1d045db9 4470 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
f1d4e28b 4471
1d045db9 4472 codec->patch_ops = alc_patch_ops;
2a43952a 4473#ifdef CONFIG_PM
ad60d502 4474 codec->patch_ops.suspend = alc269_suspend;
1d045db9
TI
4475 codec->patch_ops.resume = alc269_resume;
4476#endif
c5177c86
KY
4477 if (!spec->shutup)
4478 spec->shutup = alc269_shutup;
ebb83eeb 4479
1727a771 4480 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
589876e2 4481
1d045db9 4482 return 0;
e16fb6d1
TI
4483
4484 error:
4485 alc_free(codec);
4486 return err;
1d045db9 4487}
f1d4e28b 4488
1d045db9
TI
4489/*
4490 * ALC861
4491 */
622e84cd 4492
1d045db9 4493static int alc861_parse_auto_config(struct hda_codec *codec)
6dda9f4a 4494{
1d045db9 4495 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
3e6179b8
TI
4496 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
4497 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
604401a9
TI
4498}
4499
1d045db9
TI
4500/* Pin config fixes */
4501enum {
e652f4c8
TI
4502 ALC861_FIXUP_FSC_AMILO_PI1505,
4503 ALC861_FIXUP_AMP_VREF_0F,
4504 ALC861_FIXUP_NO_JACK_DETECT,
4505 ALC861_FIXUP_ASUS_A6RP,
1d045db9 4506};
7085ec12 4507
31150f23
TI
4508/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
4509static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
1727a771 4510 const struct hda_fixup *fix, int action)
31150f23
TI
4511{
4512 struct alc_spec *spec = codec->spec;
4513 unsigned int val;
4514
1727a771 4515 if (action != HDA_FIXUP_ACT_INIT)
31150f23 4516 return;
d3f02d60 4517 val = snd_hda_codec_get_pin_target(codec, 0x0f);
31150f23
TI
4518 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
4519 val |= AC_PINCTL_IN_EN;
4520 val |= AC_PINCTL_VREF_50;
cdd03ced 4521 snd_hda_set_pin_ctl(codec, 0x0f, val);
08c189f2 4522 spec->gen.keep_vref_in_automute = 1;
31150f23
TI
4523}
4524
e652f4c8
TI
4525/* suppress the jack-detection */
4526static void alc_fixup_no_jack_detect(struct hda_codec *codec,
1727a771 4527 const struct hda_fixup *fix, int action)
e652f4c8 4528{
1727a771 4529 if (action == HDA_FIXUP_ACT_PRE_PROBE)
e652f4c8 4530 codec->no_jack_detect = 1;
7d7eb9ea 4531}
e652f4c8 4532
1727a771 4533static const struct hda_fixup alc861_fixups[] = {
e652f4c8 4534 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
1727a771
TI
4535 .type = HDA_FIXUP_PINS,
4536 .v.pins = (const struct hda_pintbl[]) {
1d045db9
TI
4537 { 0x0b, 0x0221101f }, /* HP */
4538 { 0x0f, 0x90170310 }, /* speaker */
4539 { }
4540 }
4541 },
e652f4c8 4542 [ALC861_FIXUP_AMP_VREF_0F] = {
1727a771 4543 .type = HDA_FIXUP_FUNC,
31150f23 4544 .v.func = alc861_fixup_asus_amp_vref_0f,
3b25eb69 4545 },
e652f4c8 4546 [ALC861_FIXUP_NO_JACK_DETECT] = {
1727a771 4547 .type = HDA_FIXUP_FUNC,
e652f4c8
TI
4548 .v.func = alc_fixup_no_jack_detect,
4549 },
4550 [ALC861_FIXUP_ASUS_A6RP] = {
1727a771 4551 .type = HDA_FIXUP_FUNC,
e652f4c8
TI
4552 .v.func = alc861_fixup_asus_amp_vref_0f,
4553 .chained = true,
4554 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
4555 }
1d045db9 4556};
7085ec12 4557
1d045db9 4558static const struct snd_pci_quirk alc861_fixup_tbl[] = {
e652f4c8
TI
4559 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
4560 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
4561 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
4562 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
4563 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
4564 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
1d045db9
TI
4565 {}
4566};
3af9ee6b 4567
1d045db9
TI
4568/*
4569 */
1d045db9 4570static int patch_alc861(struct hda_codec *codec)
7085ec12 4571{
1d045db9 4572 struct alc_spec *spec;
1d045db9 4573 int err;
7085ec12 4574
3de95173
TI
4575 err = alc_alloc_spec(codec, 0x15);
4576 if (err < 0)
4577 return err;
1d045db9 4578
3de95173 4579 spec = codec->spec;
7504b6cd 4580 spec->gen.beep_nid = 0x23;
1d045db9 4581
1727a771
TI
4582 snd_hda_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
4583 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3af9ee6b 4584
cb4e4824
TI
4585 /* automatic parse from the BIOS config */
4586 err = alc861_parse_auto_config(codec);
e16fb6d1
TI
4587 if (err < 0)
4588 goto error;
3af9ee6b 4589
7504b6cd 4590 if (!spec->gen.no_analog)
3e6179b8 4591 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
7085ec12 4592
1d045db9 4593 codec->patch_ops = alc_patch_ops;
83012a7c 4594#ifdef CONFIG_PM
cb4e4824 4595 spec->power_hook = alc_power_eapd;
1d045db9
TI
4596#endif
4597
1727a771 4598 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
589876e2 4599
1d045db9 4600 return 0;
e16fb6d1
TI
4601
4602 error:
4603 alc_free(codec);
4604 return err;
7085ec12
TI
4605}
4606
1d045db9
TI
4607/*
4608 * ALC861-VD support
4609 *
4610 * Based on ALC882
4611 *
4612 * In addition, an independent DAC
4613 */
1d045db9 4614static int alc861vd_parse_auto_config(struct hda_codec *codec)
bc9f98a9 4615{
1d045db9 4616 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
3e6179b8
TI
4617 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4618 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
ce764ab2
TI
4619}
4620
1d045db9 4621enum {
8fdcb6fe
TI
4622 ALC660VD_FIX_ASUS_GPIO1,
4623 ALC861VD_FIX_DALLAS,
1d045db9 4624};
ce764ab2 4625
8fdcb6fe
TI
4626/* exclude VREF80 */
4627static void alc861vd_fixup_dallas(struct hda_codec *codec,
1727a771 4628 const struct hda_fixup *fix, int action)
8fdcb6fe 4629{
1727a771 4630 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
b78562b1
TI
4631 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
4632 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
8fdcb6fe
TI
4633 }
4634}
4635
1727a771 4636static const struct hda_fixup alc861vd_fixups[] = {
1d045db9 4637 [ALC660VD_FIX_ASUS_GPIO1] = {
1727a771 4638 .type = HDA_FIXUP_VERBS,
1d045db9 4639 .v.verbs = (const struct hda_verb[]) {
8fdcb6fe 4640 /* reset GPIO1 */
1d045db9
TI
4641 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
4642 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4643 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4644 { }
4645 }
4646 },
8fdcb6fe 4647 [ALC861VD_FIX_DALLAS] = {
1727a771 4648 .type = HDA_FIXUP_FUNC,
8fdcb6fe
TI
4649 .v.func = alc861vd_fixup_dallas,
4650 },
1d045db9 4651};
ce764ab2 4652
1d045db9 4653static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
8fdcb6fe 4654 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
1d045db9 4655 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
8fdcb6fe 4656 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
1d045db9
TI
4657 {}
4658};
ce764ab2 4659
1d045db9
TI
4660/*
4661 */
1d045db9 4662static int patch_alc861vd(struct hda_codec *codec)
ce764ab2 4663{
1d045db9 4664 struct alc_spec *spec;
cb4e4824 4665 int err;
ce764ab2 4666
3de95173
TI
4667 err = alc_alloc_spec(codec, 0x0b);
4668 if (err < 0)
4669 return err;
1d045db9 4670
3de95173 4671 spec = codec->spec;
7504b6cd 4672 spec->gen.beep_nid = 0x23;
1d045db9 4673
1727a771
TI
4674 snd_hda_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
4675 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1d045db9 4676
cb4e4824
TI
4677 /* automatic parse from the BIOS config */
4678 err = alc861vd_parse_auto_config(codec);
e16fb6d1
TI
4679 if (err < 0)
4680 goto error;
ce764ab2 4681
7504b6cd 4682 if (!spec->gen.no_analog)
3e6179b8 4683 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
1d045db9 4684
1d045db9
TI
4685 codec->patch_ops = alc_patch_ops;
4686
1d045db9 4687 spec->shutup = alc_eapd_shutup;
1d045db9 4688
1727a771 4689 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
589876e2 4690
ce764ab2 4691 return 0;
e16fb6d1
TI
4692
4693 error:
4694 alc_free(codec);
4695 return err;
ce764ab2
TI
4696}
4697
1d045db9
TI
4698/*
4699 * ALC662 support
4700 *
4701 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
4702 * configuration. Each pin widget can choose any input DACs and a mixer.
4703 * Each ADC is connected from a mixer of all inputs. This makes possible
4704 * 6-channel independent captures.
4705 *
4706 * In addition, an independent DAC for the multi-playback (not used in this
4707 * driver yet).
4708 */
1d045db9
TI
4709
4710/*
4711 * BIOS auto configuration
4712 */
4713
bc9f98a9
KY
4714static int alc662_parse_auto_config(struct hda_codec *codec)
4715{
4c6d72d1 4716 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
3e6179b8
TI
4717 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
4718 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4719 const hda_nid_t *ssids;
ee979a14 4720
6227cdce 4721 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
1d87caa6
RK
4722 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670 ||
4723 codec->vendor_id == 0x10ec0671)
3e6179b8 4724 ssids = alc663_ssids;
6227cdce 4725 else
3e6179b8
TI
4726 ssids = alc662_ssids;
4727 return alc_parse_auto_config(codec, alc662_ignore, ssids);
bc9f98a9
KY
4728}
4729
6be7948f 4730static void alc272_fixup_mario(struct hda_codec *codec,
1727a771 4731 const struct hda_fixup *fix, int action)
6fc398cb 4732{
9bb1f06f 4733 if (action != HDA_FIXUP_ACT_PRE_PROBE)
6fc398cb 4734 return;
6be7948f
TB
4735 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
4736 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
4737 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
4738 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4739 (0 << AC_AMPCAP_MUTE_SHIFT)))
4740 printk(KERN_WARNING
4741 "hda_codec: failed to override amp caps for NID 0x2\n");
4742}
4743
8e383953
TI
4744static const struct snd_pcm_chmap_elem asus_pcm_2_1_chmaps[] = {
4745 { .channels = 2,
4746 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } },
4747 { .channels = 4,
4748 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
4749 SNDRV_CHMAP_NA, SNDRV_CHMAP_LFE } }, /* LFE only on right */
4750 { }
4751};
4752
4753/* override the 2.1 chmap */
4754static void alc662_fixup_bass_chmap(struct hda_codec *codec,
4755 const struct hda_fixup *fix, int action)
4756{
4757 if (action == HDA_FIXUP_ACT_BUILD) {
4758 struct alc_spec *spec = codec->spec;
4759 spec->gen.pcm_rec[0].stream[0].chmap = asus_pcm_2_1_chmaps;
4760 }
4761}
4762
6cb3b707 4763enum {
2df03514 4764 ALC662_FIXUP_ASPIRE,
6cb3b707 4765 ALC662_FIXUP_IDEAPAD,
6be7948f 4766 ALC272_FIXUP_MARIO,
d2ebd479 4767 ALC662_FIXUP_CZC_P10T,
94024cd1 4768 ALC662_FIXUP_SKU_IGNORE,
e59ea3ed 4769 ALC662_FIXUP_HP_RP5800,
53c334ad
TI
4770 ALC662_FIXUP_ASUS_MODE1,
4771 ALC662_FIXUP_ASUS_MODE2,
4772 ALC662_FIXUP_ASUS_MODE3,
4773 ALC662_FIXUP_ASUS_MODE4,
4774 ALC662_FIXUP_ASUS_MODE5,
4775 ALC662_FIXUP_ASUS_MODE6,
4776 ALC662_FIXUP_ASUS_MODE7,
4777 ALC662_FIXUP_ASUS_MODE8,
1565cc35 4778 ALC662_FIXUP_NO_JACK_DETECT,
edfe3bfc 4779 ALC662_FIXUP_ZOTAC_Z68,
125821ae 4780 ALC662_FIXUP_INV_DMIC,
73bdd597
DH
4781 ALC668_FIXUP_DELL_MIC_NO_PRESENCE,
4782 ALC668_FIXUP_HEADSET_MODE,
8e383953 4783 ALC662_FIXUP_BASS_CHMAP,
a30c9aaa
TI
4784 ALC662_FIXUP_BASS_1A,
4785 ALC662_FIXUP_BASS_1A_CHMAP,
6cb3b707
DH
4786};
4787
1727a771 4788static const struct hda_fixup alc662_fixups[] = {
2df03514 4789 [ALC662_FIXUP_ASPIRE] = {
1727a771
TI
4790 .type = HDA_FIXUP_PINS,
4791 .v.pins = (const struct hda_pintbl[]) {
2df03514
DC
4792 { 0x15, 0x99130112 }, /* subwoofer */
4793 { }
4794 }
4795 },
6cb3b707 4796 [ALC662_FIXUP_IDEAPAD] = {
1727a771
TI
4797 .type = HDA_FIXUP_PINS,
4798 .v.pins = (const struct hda_pintbl[]) {
6cb3b707
DH
4799 { 0x17, 0x99130112 }, /* subwoofer */
4800 { }
4801 }
4802 },
6be7948f 4803 [ALC272_FIXUP_MARIO] = {
1727a771 4804 .type = HDA_FIXUP_FUNC,
b5bfbc67 4805 .v.func = alc272_fixup_mario,
d2ebd479
AA
4806 },
4807 [ALC662_FIXUP_CZC_P10T] = {
1727a771 4808 .type = HDA_FIXUP_VERBS,
d2ebd479
AA
4809 .v.verbs = (const struct hda_verb[]) {
4810 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4811 {}
4812 }
4813 },
94024cd1 4814 [ALC662_FIXUP_SKU_IGNORE] = {
1727a771 4815 .type = HDA_FIXUP_FUNC,
23d30f28 4816 .v.func = alc_fixup_sku_ignore,
c6b35874 4817 },
e59ea3ed 4818 [ALC662_FIXUP_HP_RP5800] = {
1727a771
TI
4819 .type = HDA_FIXUP_PINS,
4820 .v.pins = (const struct hda_pintbl[]) {
e59ea3ed
TI
4821 { 0x14, 0x0221201f }, /* HP out */
4822 { }
4823 },
4824 .chained = true,
4825 .chain_id = ALC662_FIXUP_SKU_IGNORE
4826 },
53c334ad 4827 [ALC662_FIXUP_ASUS_MODE1] = {
1727a771
TI
4828 .type = HDA_FIXUP_PINS,
4829 .v.pins = (const struct hda_pintbl[]) {
53c334ad
TI
4830 { 0x14, 0x99130110 }, /* speaker */
4831 { 0x18, 0x01a19c20 }, /* mic */
4832 { 0x19, 0x99a3092f }, /* int-mic */
4833 { 0x21, 0x0121401f }, /* HP out */
4834 { }
4835 },
4836 .chained = true,
4837 .chain_id = ALC662_FIXUP_SKU_IGNORE
4838 },
4839 [ALC662_FIXUP_ASUS_MODE2] = {
1727a771
TI
4840 .type = HDA_FIXUP_PINS,
4841 .v.pins = (const struct hda_pintbl[]) {
2996bdba
TI
4842 { 0x14, 0x99130110 }, /* speaker */
4843 { 0x18, 0x01a19820 }, /* mic */
4844 { 0x19, 0x99a3092f }, /* int-mic */
4845 { 0x1b, 0x0121401f }, /* HP out */
4846 { }
4847 },
53c334ad
TI
4848 .chained = true,
4849 .chain_id = ALC662_FIXUP_SKU_IGNORE
4850 },
4851 [ALC662_FIXUP_ASUS_MODE3] = {
1727a771
TI
4852 .type = HDA_FIXUP_PINS,
4853 .v.pins = (const struct hda_pintbl[]) {
53c334ad
TI
4854 { 0x14, 0x99130110 }, /* speaker */
4855 { 0x15, 0x0121441f }, /* HP */
4856 { 0x18, 0x01a19840 }, /* mic */
4857 { 0x19, 0x99a3094f }, /* int-mic */
4858 { 0x21, 0x01211420 }, /* HP2 */
4859 { }
4860 },
4861 .chained = true,
4862 .chain_id = ALC662_FIXUP_SKU_IGNORE
4863 },
4864 [ALC662_FIXUP_ASUS_MODE4] = {
1727a771
TI
4865 .type = HDA_FIXUP_PINS,
4866 .v.pins = (const struct hda_pintbl[]) {
53c334ad
TI
4867 { 0x14, 0x99130110 }, /* speaker */
4868 { 0x16, 0x99130111 }, /* speaker */
4869 { 0x18, 0x01a19840 }, /* mic */
4870 { 0x19, 0x99a3094f }, /* int-mic */
4871 { 0x21, 0x0121441f }, /* HP */
4872 { }
4873 },
4874 .chained = true,
4875 .chain_id = ALC662_FIXUP_SKU_IGNORE
4876 },
4877 [ALC662_FIXUP_ASUS_MODE5] = {
1727a771
TI
4878 .type = HDA_FIXUP_PINS,
4879 .v.pins = (const struct hda_pintbl[]) {
53c334ad
TI
4880 { 0x14, 0x99130110 }, /* speaker */
4881 { 0x15, 0x0121441f }, /* HP */
4882 { 0x16, 0x99130111 }, /* speaker */
4883 { 0x18, 0x01a19840 }, /* mic */
4884 { 0x19, 0x99a3094f }, /* int-mic */
4885 { }
4886 },
4887 .chained = true,
4888 .chain_id = ALC662_FIXUP_SKU_IGNORE
4889 },
4890 [ALC662_FIXUP_ASUS_MODE6] = {
1727a771
TI
4891 .type = HDA_FIXUP_PINS,
4892 .v.pins = (const struct hda_pintbl[]) {
53c334ad
TI
4893 { 0x14, 0x99130110 }, /* speaker */
4894 { 0x15, 0x01211420 }, /* HP2 */
4895 { 0x18, 0x01a19840 }, /* mic */
4896 { 0x19, 0x99a3094f }, /* int-mic */
4897 { 0x1b, 0x0121441f }, /* HP */
4898 { }
4899 },
4900 .chained = true,
4901 .chain_id = ALC662_FIXUP_SKU_IGNORE
4902 },
4903 [ALC662_FIXUP_ASUS_MODE7] = {
1727a771
TI
4904 .type = HDA_FIXUP_PINS,
4905 .v.pins = (const struct hda_pintbl[]) {
53c334ad
TI
4906 { 0x14, 0x99130110 }, /* speaker */
4907 { 0x17, 0x99130111 }, /* speaker */
4908 { 0x18, 0x01a19840 }, /* mic */
4909 { 0x19, 0x99a3094f }, /* int-mic */
4910 { 0x1b, 0x01214020 }, /* HP */
4911 { 0x21, 0x0121401f }, /* HP */
4912 { }
4913 },
4914 .chained = true,
4915 .chain_id = ALC662_FIXUP_SKU_IGNORE
4916 },
4917 [ALC662_FIXUP_ASUS_MODE8] = {
1727a771
TI
4918 .type = HDA_FIXUP_PINS,
4919 .v.pins = (const struct hda_pintbl[]) {
53c334ad
TI
4920 { 0x14, 0x99130110 }, /* speaker */
4921 { 0x12, 0x99a30970 }, /* int-mic */
4922 { 0x15, 0x01214020 }, /* HP */
4923 { 0x17, 0x99130111 }, /* speaker */
4924 { 0x18, 0x01a19840 }, /* mic */
4925 { 0x21, 0x0121401f }, /* HP */
4926 { }
4927 },
4928 .chained = true,
4929 .chain_id = ALC662_FIXUP_SKU_IGNORE
2996bdba 4930 },
1565cc35 4931 [ALC662_FIXUP_NO_JACK_DETECT] = {
1727a771 4932 .type = HDA_FIXUP_FUNC,
1565cc35
TI
4933 .v.func = alc_fixup_no_jack_detect,
4934 },
edfe3bfc 4935 [ALC662_FIXUP_ZOTAC_Z68] = {
1727a771
TI
4936 .type = HDA_FIXUP_PINS,
4937 .v.pins = (const struct hda_pintbl[]) {
edfe3bfc
DH
4938 { 0x1b, 0x02214020 }, /* Front HP */
4939 { }
4940 }
4941 },
125821ae 4942 [ALC662_FIXUP_INV_DMIC] = {
1727a771 4943 .type = HDA_FIXUP_FUNC,
6e72aa5f 4944 .v.func = alc_fixup_inv_dmic_0x12,
125821ae 4945 },
73bdd597
DH
4946 [ALC668_FIXUP_DELL_MIC_NO_PRESENCE] = {
4947 .type = HDA_FIXUP_PINS,
4948 .v.pins = (const struct hda_pintbl[]) {
4949 { 0x19, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
4950 { 0x1b, 0x03a1113c }, /* use as headset mic, without its own jack detect */
4951 { }
4952 },
4953 .chained = true,
4954 .chain_id = ALC668_FIXUP_HEADSET_MODE
4955 },
4956 [ALC668_FIXUP_HEADSET_MODE] = {
4957 .type = HDA_FIXUP_FUNC,
4958 .v.func = alc_fixup_headset_mode_alc668,
4959 },
8e383953
TI
4960 [ALC662_FIXUP_BASS_CHMAP] = {
4961 .type = HDA_FIXUP_FUNC,
4962 .v.func = alc662_fixup_bass_chmap,
4963 .chained = true,
4964 .chain_id = ALC662_FIXUP_ASUS_MODE4
4965 },
a30c9aaa
TI
4966 [ALC662_FIXUP_BASS_1A] = {
4967 .type = HDA_FIXUP_PINS,
4968 .v.pins = (const struct hda_pintbl[]) {
4969 {0x1a, 0x80106111}, /* bass speaker */
4970 {}
4971 },
4972 },
4973 [ALC662_FIXUP_BASS_1A_CHMAP] = {
4974 .type = HDA_FIXUP_FUNC,
4975 .v.func = alc662_fixup_bass_chmap,
4976 .chained = true,
4977 .chain_id = ALC662_FIXUP_BASS_1A,
4978 },
6cb3b707
DH
4979};
4980
a9111321 4981static const struct snd_pci_quirk alc662_fixup_tbl[] = {
53c334ad 4982 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
d3d3835c 4983 SND_PCI_QUIRK(0x1025, 0x022f, "Acer Aspire One", ALC662_FIXUP_INV_DMIC),
a6c47a85 4984 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
94024cd1 4985 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
125821ae 4986 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
1801928e 4987 SND_PCI_QUIRK(0x1025, 0x034a, "Gateway LT27", ALC662_FIXUP_INV_DMIC),
2df03514 4988 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
73bdd597
DH
4989 SND_PCI_QUIRK(0x1028, 0x05d8, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
4990 SND_PCI_QUIRK(0x1028, 0x05db, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
09d2014f 4991 SND_PCI_QUIRK(0x1028, 0x0625, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
ad8ff99e 4992 SND_PCI_QUIRK(0x1028, 0x0626, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
e59ea3ed 4993 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
a30c9aaa 4994 SND_PCI_QUIRK(0x1043, 0x11cd, "Asus N550", ALC662_FIXUP_BASS_1A_CHMAP),
8e383953
TI
4995 SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_BASS_CHMAP),
4996 SND_PCI_QUIRK(0x1043, 0x1bf3, "ASUS N76VZ", ALC662_FIXUP_BASS_CHMAP),
1565cc35 4997 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
53c334ad 4998 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
a0e90acc 4999 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
d4118588 5000 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
6cb3b707 5001 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
edfe3bfc 5002 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
d2ebd479 5003 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
53c334ad
TI
5004
5005#if 0
5006 /* Below is a quirk table taken from the old code.
5007 * Basically the device should work as is without the fixup table.
5008 * If BIOS doesn't give a proper info, enable the corresponding
5009 * fixup entry.
7d7eb9ea 5010 */
53c334ad
TI
5011 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5012 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5013 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5014 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5015 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5016 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5017 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5018 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5019 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5020 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5021 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5022 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5023 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5024 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5025 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5026 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5027 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5028 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5029 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5030 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5031 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5032 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5033 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5034 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5035 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5036 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5037 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5038 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5039 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5040 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5041 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5042 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5043 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5044 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5045 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5046 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5047 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5048 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
5049 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
5050 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5051 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
5052 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
5053 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5054 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
5055 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
5056 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
5057 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
5058 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
5059 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5060 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
5061#endif
6cb3b707
DH
5062 {}
5063};
5064
1727a771 5065static const struct hda_model_fixup alc662_fixup_models[] = {
6be7948f 5066 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
53c334ad
TI
5067 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
5068 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
5069 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
5070 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
5071 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
5072 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
5073 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
5074 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
6e72aa5f 5075 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
e32aa85a 5076 {.id = ALC668_FIXUP_DELL_MIC_NO_PRESENCE, .name = "dell-headset-multi"},
6be7948f
TB
5077 {}
5078};
6cb3b707 5079
8663ff75
KY
5080static void alc662_fill_coef(struct hda_codec *codec)
5081{
5082 int val, coef;
5083
5084 coef = alc_get_coef0(codec);
5085
5086 switch (codec->vendor_id) {
5087 case 0x10ec0662:
5088 if ((coef & 0x00f0) == 0x0030) {
5089 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
5090 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
5091 }
5092 break;
5093 case 0x10ec0272:
5094 case 0x10ec0273:
5095 case 0x10ec0663:
5096 case 0x10ec0665:
5097 case 0x10ec0670:
5098 case 0x10ec0671:
5099 case 0x10ec0672:
5100 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
5101 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5102 break;
5103 }
5104}
6cb3b707 5105
1d045db9
TI
5106/*
5107 */
bc9f98a9
KY
5108static int patch_alc662(struct hda_codec *codec)
5109{
5110 struct alc_spec *spec;
3de95173 5111 int err;
bc9f98a9 5112
3de95173
TI
5113 err = alc_alloc_spec(codec, 0x0b);
5114 if (err < 0)
5115 return err;
bc9f98a9 5116
3de95173 5117 spec = codec->spec;
1f0f4b80 5118
53c334ad
TI
5119 /* handle multiple HPs as is */
5120 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5121
2c3bf9ab
TI
5122 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5123
8663ff75
KY
5124 spec->init_hook = alc662_fill_coef;
5125 alc662_fill_coef(codec);
5126
1727a771 5127 snd_hda_pick_fixup(codec, alc662_fixup_models,
8e5a0509 5128 alc662_fixup_tbl, alc662_fixups);
1727a771 5129 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
8e5a0509
TI
5130
5131 alc_auto_parse_customize_define(codec);
5132
7504b6cd
TI
5133 if (has_cdefine_beep(codec))
5134 spec->gen.beep_nid = 0x01;
5135
1bb7e43e 5136 if ((alc_get_coef0(codec) & (1 << 14)) &&
e16fb6d1
TI
5137 codec->bus->pci->subsystem_vendor == 0x1025 &&
5138 spec->cdefine.platform_type == 1) {
6134b1a2
WY
5139 err = alc_codec_rename(codec, "ALC272X");
5140 if (err < 0)
e16fb6d1 5141 goto error;
20ca0c35 5142 }
274693f3 5143
b9c5106c
TI
5144 /* automatic parse from the BIOS config */
5145 err = alc662_parse_auto_config(codec);
e16fb6d1
TI
5146 if (err < 0)
5147 goto error;
bc9f98a9 5148
7504b6cd 5149 if (!spec->gen.no_analog && spec->gen.beep_nid) {
da00c244
KY
5150 switch (codec->vendor_id) {
5151 case 0x10ec0662:
5152 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5153 break;
5154 case 0x10ec0272:
5155 case 0x10ec0663:
5156 case 0x10ec0665:
9ad54547 5157 case 0x10ec0668:
da00c244
KY
5158 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5159 break;
5160 case 0x10ec0273:
5161 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5162 break;
5163 }
cec27c89 5164 }
2134ea4f 5165
bc9f98a9 5166 codec->patch_ops = alc_patch_ops;
1c716153 5167 spec->shutup = alc_eapd_shutup;
6cb3b707 5168
1727a771 5169 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
589876e2 5170
bc9f98a9 5171 return 0;
801f49d3 5172
e16fb6d1
TI
5173 error:
5174 alc_free(codec);
5175 return err;
b478b998
KY
5176}
5177
d1eb57f4
KY
5178/*
5179 * ALC680 support
5180 */
d1eb57f4 5181
d1eb57f4
KY
5182static int alc680_parse_auto_config(struct hda_codec *codec)
5183{
3e6179b8 5184 return alc_parse_auto_config(codec, NULL, NULL);
d1eb57f4
KY
5185}
5186
d1eb57f4 5187/*
d1eb57f4 5188 */
d1eb57f4
KY
5189static int patch_alc680(struct hda_codec *codec)
5190{
d1eb57f4
KY
5191 int err;
5192
1f0f4b80 5193 /* ALC680 has no aa-loopback mixer */
3de95173
TI
5194 err = alc_alloc_spec(codec, 0);
5195 if (err < 0)
5196 return err;
1f0f4b80 5197
1ebec5f2
TI
5198 /* automatic parse from the BIOS config */
5199 err = alc680_parse_auto_config(codec);
5200 if (err < 0) {
5201 alc_free(codec);
5202 return err;
d1eb57f4
KY
5203 }
5204
d1eb57f4 5205 codec->patch_ops = alc_patch_ops;
d1eb57f4
KY
5206
5207 return 0;
5208}
5209
1da177e4
LT
5210/*
5211 * patch entries
5212 */
a9111321 5213static const struct hda_codec_preset snd_hda_preset_realtek[] = {
296f0338 5214 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
ba4c4d0a 5215 { .id = 0x10ec0231, .name = "ALC231", .patch = patch_alc269 },
84dfd0ac 5216 { .id = 0x10ec0233, .name = "ALC233", .patch = patch_alc269 },
1d04c9de 5217 { .id = 0x10ec0255, .name = "ALC255", .patch = patch_alc269 },
1da177e4 5218 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
df694daa 5219 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
f6a92248 5220 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
a361d84b 5221 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
f6a92248 5222 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
ebb83eeb 5223 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
01afd41f 5224 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
ebb83eeb 5225 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
296f0338 5226 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
befae82e 5227 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
4e01ec63 5228 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
7ff34ad8 5229 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
065380f0 5230 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
161ebf29 5231 { .id = 0x10ec0285, .name = "ALC285", .patch = patch_alc269 },
7fc7d047 5232 { .id = 0x10ec0286, .name = "ALC286", .patch = patch_alc269 },
7ff34ad8 5233 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
af02dde8 5234 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
161ebf29 5235 { .id = 0x10ec0293, .name = "ALC293", .patch = patch_alc269 },
f32610ed 5236 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
bc9f98a9 5237 .patch = patch_alc861 },
f32610ed
JS
5238 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
5239 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
5240 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
bc9f98a9 5241 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
4953550a 5242 .patch = patch_alc882 },
bc9f98a9
KY
5243 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5244 .patch = patch_alc662 },
cc667a72
DH
5245 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
5246 .patch = patch_alc662 },
6dda9f4a 5247 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
cec27c89 5248 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
19a62823 5249 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
6227cdce 5250 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
1d87caa6 5251 { .id = 0x10ec0671, .name = "ALC671", .patch = patch_alc662 },
d1eb57f4 5252 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
f32610ed 5253 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
1da177e4 5254 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
4953550a 5255 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
669faba2 5256 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
4953550a 5257 .patch = patch_alc882 },
cb308f97 5258 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
4953550a 5259 .patch = patch_alc882 },
df694daa 5260 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
e16fb6d1 5261 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
4442608d 5262 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
4953550a 5263 .patch = patch_alc882 },
e16fb6d1 5264 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
4953550a 5265 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
274693f3 5266 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
e16fb6d1 5267 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
19a62823 5268 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
1da177e4
LT
5269 {} /* terminator */
5270};
1289e9e8
TI
5271
5272MODULE_ALIAS("snd-hda-codec-id:10ec*");
5273
5274MODULE_LICENSE("GPL");
5275MODULE_DESCRIPTION("Realtek HD-audio codec");
5276
5277static struct hda_codec_preset_list realtek_list = {
5278 .preset = snd_hda_preset_realtek,
5279 .owner = THIS_MODULE,
5280};
5281
5282static int __init patch_realtek_init(void)
5283{
5284 return snd_hda_add_codec_preset(&realtek_list);
5285}
5286
5287static void __exit patch_realtek_exit(void)
5288{
5289 snd_hda_delete_codec_preset(&realtek_list);
5290}
5291
5292module_init(patch_realtek_init)
5293module_exit(patch_realtek_exit)