ALSA: hda - Add laptop imic fixup for ASUS M9V laptop
[linux-2.6-block.git] / sound / pci / hda / patch_analog.c
CommitLineData
d0fa1179 1// SPDX-License-Identifier: GPL-2.0-or-later
1da177e4 2/*
0ac8551e
TI
3 * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
4 * AD1986A, AD1988
1da177e4 5 *
2bac647c 6 * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de>
1da177e4
LT
7 */
8
1da177e4 9#include <linux/init.h>
1da177e4 10#include <linux/slab.h>
da155d5b 11#include <linux/module.h>
62932df8 12
1da177e4 13#include <sound/core.h>
be57bfff 14#include <sound/hda_codec.h>
1da177e4 15#include "hda_local.h"
128bc4ba 16#include "hda_auto_parser.h"
c5a4bcd0 17#include "hda_beep.h"
1835a0f9 18#include "hda_jack.h"
78bb3cb0 19#include "hda_generic.h"
1da177e4 20
9ff4bc8f 21
4a3fdf3d 22struct ad198x_spec {
78bb3cb0
TI
23 struct hda_gen_spec gen;
24
272f3ea3
TI
25 /* for auto parser */
26 int smux_paths[4];
27 unsigned int cur_smux;
a928bd2c 28 hda_nid_t eapd_nid;
272f3ea3 29
c5a4bcd0 30 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
2134ea4f
TI
31};
32
2134ea4f 33
67d634c0 34#ifdef CONFIG_SND_HDA_INPUT_BEEP
c5a4bcd0 35/* additional beep mixers; the actual parameters are overwritten at build */
498f5b17 36static const struct snd_kcontrol_new ad_beep_mixer[] = {
c5a4bcd0 37 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
123c07ae 38 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
c5a4bcd0
TI
39 { } /* end */
40};
41
42#define set_beep_amp(spec, nid, idx, dir) \
43 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
67d634c0
TI
44#else
45#define set_beep_amp(spec, nid, idx, dir) /* NOP */
46#endif
c5a4bcd0 47
78bb3cb0
TI
48#ifdef CONFIG_SND_HDA_INPUT_BEEP
49static int create_beep_ctls(struct hda_codec *codec)
50{
51 struct ad198x_spec *spec = codec->spec;
52 const struct snd_kcontrol_new *knew;
53
54 if (!spec->beep_amp)
55 return 0;
56
632408ad 57 for (knew = ad_beep_mixer ; knew->name; knew++) {
78bb3cb0
TI
58 int err;
59 struct snd_kcontrol *kctl;
60 kctl = snd_ctl_new1(knew, codec);
61 if (!kctl)
62 return -ENOMEM;
63 kctl->private_value = spec->beep_amp;
64 err = snd_hda_ctl_add(codec, 0, kctl);
65 if (err < 0)
66 return err;
67 }
68 return 0;
69}
70#else
71#define create_beep_ctls(codec) 0
72#endif
73
4a3fdf3d 74
ea52bf26
DC
75static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
76 hda_nid_t hp)
77{
a01ef051
RY
78 if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD)
79 snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
78bb3cb0 80 !codec->inv_eapd ? 0x00 : 0x02);
a01ef051
RY
81 if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD)
82 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
78bb3cb0 83 !codec->inv_eapd ? 0x00 : 0x02);
ea52bf26
DC
84}
85
86static void ad198x_power_eapd(struct hda_codec *codec)
87{
88 /* We currently only handle front, HP */
7639a06c 89 switch (codec->core.vendor_id) {
ea52bf26
DC
90 case 0x11d41882:
91 case 0x11d4882a:
92 case 0x11d41884:
93 case 0x11d41984:
94 case 0x11d41883:
95 case 0x11d4184a:
96 case 0x11d4194a:
97 case 0x11d4194b:
4dffbe03
TI
98 case 0x11d41988:
99 case 0x11d4198b:
100 case 0x11d4989a:
101 case 0x11d4989b:
ea52bf26
DC
102 ad198x_power_eapd_write(codec, 0x12, 0x11);
103 break;
104 case 0x11d41981:
105 case 0x11d41983:
106 ad198x_power_eapd_write(codec, 0x05, 0x06);
107 break;
108 case 0x11d41986:
109 ad198x_power_eapd_write(codec, 0x1b, 0x1a);
110 break;
ea52bf26
DC
111 }
112}
113
0da26922
TI
114static void ad198x_shutup(struct hda_codec *codec)
115{
116 snd_hda_shutup_pins(codec);
117 ad198x_power_eapd(codec);
118}
119
2a43952a 120#ifdef CONFIG_PM
68cb2b55 121static int ad198x_suspend(struct hda_codec *codec)
ea52bf26
DC
122{
123 ad198x_shutup(codec);
ea52bf26
DC
124 return 0;
125}
ea52bf26
DC
126#endif
127
f710a9fb
TI
128/* follow EAPD via vmaster hook */
129static void ad_vmaster_eapd_hook(void *private_data, int enabled)
130{
131 struct hda_codec *codec = private_data;
132 struct ad198x_spec *spec = codec->spec;
133
134 if (!spec->eapd_nid)
135 return;
ce8e0fd2
TI
136 if (codec->inv_eapd)
137 enabled = !enabled;
401caff7 138 snd_hda_codec_write_cache(codec, spec->eapd_nid, 0,
f710a9fb
TI
139 AC_VERB_SET_EAPD_BTLENABLE,
140 enabled ? 0x02 : 0x00);
141}
9230d214 142
78bb3cb0
TI
143/*
144 * Automatic parse of I/O pins from the BIOS configuration
145 */
146
147static int ad198x_auto_build_controls(struct hda_codec *codec)
148{
149 int err;
150
151 err = snd_hda_gen_build_controls(codec);
152 if (err < 0)
153 return err;
154 err = create_beep_ctls(codec);
155 if (err < 0)
156 return err;
157 return 0;
158}
159
160static const struct hda_codec_ops ad198x_auto_patch_ops = {
161 .build_controls = ad198x_auto_build_controls,
162 .build_pcms = snd_hda_gen_build_pcms,
163 .init = snd_hda_gen_init,
7504b6cd 164 .free = snd_hda_gen_free,
8a6c21ae 165 .unsol_event = snd_hda_jack_unsol_event,
78bb3cb0
TI
166#ifdef CONFIG_PM
167 .check_power_status = snd_hda_gen_check_power_status,
168 .suspend = ad198x_suspend,
169#endif
170 .reboot_notify = ad198x_shutup,
171};
172
173
cbd209f4 174static int ad198x_parse_auto_config(struct hda_codec *codec, bool indep_hp)
78bb3cb0
TI
175{
176 struct ad198x_spec *spec = codec->spec;
177 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
178 int err;
179
180 codec->spdif_status_reset = 1;
181 codec->no_trigger_sense = 1;
182 codec->no_sticky_stream = 1;
183
cbd209f4 184 spec->gen.indep_hp = indep_hp;
74f14b36
TI
185 if (!spec->gen.add_stereo_mix_input)
186 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
78bb3cb0
TI
187
188 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
189 if (err < 0)
190 return err;
191 err = snd_hda_gen_parse_auto_config(codec, cfg);
192 if (err < 0)
193 return err;
194
78bb3cb0
TI
195 return 0;
196}
197
4a3fdf3d
TI
198/*
199 * AD1986A specific
200 */
201
361dab3e 202static int alloc_ad_spec(struct hda_codec *codec)
1da177e4 203{
4a3fdf3d 204 struct ad198x_spec *spec;
1da177e4 205
e560d8d8 206 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
361dab3e 207 if (!spec)
4a3fdf3d 208 return -ENOMEM;
4a3fdf3d 209 codec->spec = spec;
78bb3cb0 210 snd_hda_gen_spec_init(&spec->gen);
225068ab 211 codec->patch_ops = ad198x_auto_patch_ops;
361dab3e
TI
212 return 0;
213}
214
a928bd2c
TI
215/*
216 * AD1986A fixup codes
217 */
218
219/* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
220static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
221 const struct hda_fixup *fix, int action)
222{
7a3e6107
TI
223 struct ad198x_spec *spec = codec->spec;
224
225 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
a928bd2c 226 codec->inv_jack_detect = 1;
7a3e6107 227 spec->gen.keep_eapd_on = 1;
f710a9fb
TI
228 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
229 spec->eapd_nid = 0x1b;
7a3e6107 230 }
a928bd2c
TI
231}
232
4528eb19
TI
233/* Toshiba Satellite L40 implements EAPD in a standard way unlike others */
234static void ad1986a_fixup_eapd(struct hda_codec *codec,
235 const struct hda_fixup *fix, int action)
236{
237 struct ad198x_spec *spec = codec->spec;
238
239 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
240 codec->inv_eapd = 0;
241 spec->gen.keep_eapd_on = 1;
242 spec->eapd_nid = 0x1b;
243 }
244}
245
7327643b
TI
246/* enable stereo-mix input for avoiding regression on KDE (bko#88251) */
247static void ad1986a_fixup_eapd_mix_in(struct hda_codec *codec,
248 const struct hda_fixup *fix, int action)
249{
250 struct ad198x_spec *spec = codec->spec;
251
252 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
253 ad1986a_fixup_eapd(codec, fix, action);
254 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_ENABLE;
255 }
256}
257
a928bd2c
TI
258enum {
259 AD1986A_FIXUP_INV_JACK_DETECT,
e0b27167 260 AD1986A_FIXUP_ULTRA,
f8c0ab17 261 AD1986A_FIXUP_SAMSUNG,
632408ad
TI
262 AD1986A_FIXUP_3STACK,
263 AD1986A_FIXUP_LAPTOP,
264 AD1986A_FIXUP_LAPTOP_IMIC,
4528eb19 265 AD1986A_FIXUP_EAPD,
7327643b
TI
266 AD1986A_FIXUP_EAPD_MIX_IN,
267 AD1986A_FIXUP_EASYNOTE,
a928bd2c
TI
268};
269
270static const struct hda_fixup ad1986a_fixups[] = {
271 [AD1986A_FIXUP_INV_JACK_DETECT] = {
272 .type = HDA_FIXUP_FUNC,
273 .v.func = ad_fixup_inv_jack_detect,
274 },
e0b27167
TI
275 [AD1986A_FIXUP_ULTRA] = {
276 .type = HDA_FIXUP_PINS,
277 .v.pins = (const struct hda_pintbl[]) {
278 { 0x1b, 0x90170110 }, /* speaker */
279 { 0x1d, 0x90a7013e }, /* int mic */
280 {}
281 },
282 },
f8c0ab17
TI
283 [AD1986A_FIXUP_SAMSUNG] = {
284 .type = HDA_FIXUP_PINS,
285 .v.pins = (const struct hda_pintbl[]) {
286 { 0x1b, 0x90170110 }, /* speaker */
287 { 0x1d, 0x90a7013e }, /* int mic */
288 { 0x20, 0x411111f0 }, /* N/A */
289 { 0x24, 0x411111f0 }, /* N/A */
290 {}
291 },
292 },
632408ad
TI
293 [AD1986A_FIXUP_3STACK] = {
294 .type = HDA_FIXUP_PINS,
295 .v.pins = (const struct hda_pintbl[]) {
296 { 0x1a, 0x02214021 }, /* headphone */
297 { 0x1b, 0x01014011 }, /* front */
ed0e0d06
TI
298 { 0x1c, 0x01813030 }, /* line-in */
299 { 0x1d, 0x01a19020 }, /* rear mic */
632408ad
TI
300 { 0x1e, 0x411111f0 }, /* N/A */
301 { 0x1f, 0x02a190f0 }, /* mic */
ed0e0d06 302 { 0x20, 0x411111f0 }, /* N/A */
632408ad
TI
303 {}
304 },
305 },
306 [AD1986A_FIXUP_LAPTOP] = {
307 .type = HDA_FIXUP_PINS,
308 .v.pins = (const struct hda_pintbl[]) {
309 { 0x1a, 0x02214021 }, /* headphone */
310 { 0x1b, 0x90170110 }, /* speaker */
311 { 0x1c, 0x411111f0 }, /* N/A */
312 { 0x1d, 0x411111f0 }, /* N/A */
313 { 0x1e, 0x411111f0 }, /* N/A */
314 { 0x1f, 0x02a191f0 }, /* mic */
315 { 0x20, 0x411111f0 }, /* N/A */
316 {}
317 },
318 },
319 [AD1986A_FIXUP_LAPTOP_IMIC] = {
320 .type = HDA_FIXUP_PINS,
321 .v.pins = (const struct hda_pintbl[]) {
322 { 0x1d, 0x90a7013e }, /* int mic */
323 {}
324 },
325 .chained_before = 1,
326 .chain_id = AD1986A_FIXUP_LAPTOP,
327 },
4528eb19
TI
328 [AD1986A_FIXUP_EAPD] = {
329 .type = HDA_FIXUP_FUNC,
330 .v.func = ad1986a_fixup_eapd,
331 },
7327643b
TI
332 [AD1986A_FIXUP_EAPD_MIX_IN] = {
333 .type = HDA_FIXUP_FUNC,
334 .v.func = ad1986a_fixup_eapd_mix_in,
335 },
336 [AD1986A_FIXUP_EASYNOTE] = {
337 .type = HDA_FIXUP_PINS,
338 .v.pins = (const struct hda_pintbl[]) {
339 { 0x1a, 0x0421402f }, /* headphone */
340 { 0x1b, 0x90170110 }, /* speaker */
341 { 0x1c, 0x411111f0 }, /* N/A */
342 { 0x1d, 0x90a70130 }, /* int mic */
343 { 0x1e, 0x411111f0 }, /* N/A */
344 { 0x1f, 0x04a19040 }, /* mic */
345 { 0x20, 0x411111f0 }, /* N/A */
346 { 0x21, 0x411111f0 }, /* N/A */
347 { 0x22, 0x411111f0 }, /* N/A */
348 { 0x23, 0x411111f0 }, /* N/A */
349 { 0x24, 0x411111f0 }, /* N/A */
350 { 0x25, 0x411111f0 }, /* N/A */
351 {}
352 },
353 .chained = true,
354 .chain_id = AD1986A_FIXUP_EAPD_MIX_IN,
355 },
a928bd2c
TI
356};
357
358static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
632408ad 359 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC),
7b485d17 360 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9V", AD1986A_FIXUP_LAPTOP_IMIC),
f62f5eff 361 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS Z99He", AD1986A_FIXUP_EAPD),
598e3061 362 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8JN", AD1986A_FIXUP_EAPD),
632408ad
TI
363 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK),
364 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK),
365 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK),
4528eb19 366 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40", AD1986A_FIXUP_EAPD),
632408ad 367 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP),
f8c0ab17 368 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG),
e0b27167 369 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
7327643b 370 SND_PCI_QUIRK(0x1631, 0xc022, "PackardBell EasyNote MX65", AD1986A_FIXUP_EASYNOTE),
a928bd2c 371 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
632408ad
TI
372 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK),
373 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK),
374 {}
375};
376
377static const struct hda_model_fixup ad1986a_fixup_models[] = {
378 { .id = AD1986A_FIXUP_3STACK, .name = "3stack" },
379 { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" },
380 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" },
381 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */
9faa73f0 382 { .id = AD1986A_FIXUP_EAPD, .name = "eapd" },
a928bd2c
TI
383 {}
384};
385
78bb3cb0
TI
386/*
387 */
632408ad 388static int patch_ad1986a(struct hda_codec *codec)
78bb3cb0 389{
9ff4bc8f
TI
390 int err;
391 struct ad198x_spec *spec;
3690739b
TI
392 static hda_nid_t preferred_pairs[] = {
393 0x1a, 0x03,
394 0x1b, 0x03,
395 0x1c, 0x04,
396 0x1d, 0x05,
397 0x1e, 0x03,
398 0
399 };
9ff4bc8f
TI
400
401 err = alloc_ad_spec(codec);
402 if (err < 0)
403 return err;
404 spec = codec->spec;
78bb3cb0
TI
405
406 /* AD1986A has the inverted EAPD implementation */
407 codec->inv_eapd = 1;
408
f2f8be43 409 spec->gen.mixer_nid = 0x07;
7504b6cd 410 spec->gen.beep_nid = 0x19;
78bb3cb0
TI
411 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
412
413 /* AD1986A has a hardware problem that it can't share a stream
414 * with multiple output pins. The copy of front to surrounds
415 * causes noisy or silent outputs at a certain timing, e.g.
416 * changing the volume.
417 * So, let's disable the shared stream.
418 */
419 spec->gen.multiout.no_share_stream = 1;
3690739b
TI
420 /* give fixed DAC/pin pairs */
421 spec->gen.preferred_dacs = preferred_pairs;
78bb3cb0 422
b3bd4fc3
TI
423 /* AD1986A can't manage the dynamic pin on/off smoothly */
424 spec->gen.auto_mute_via_amp = 1;
78bb3cb0 425
632408ad
TI
426 snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl,
427 ad1986a_fixups);
a928bd2c
TI
428 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
429
cbd209f4 430 err = ad198x_parse_auto_config(codec, false);
9ff4bc8f 431 if (err < 0) {
7504b6cd 432 snd_hda_gen_free(codec);
9ff4bc8f
TI
433 return err;
434 }
435
a928bd2c
TI
436 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
437
9ff4bc8f 438 return 0;
78bb3cb0
TI
439}
440
1da177e4
LT
441
442/*
4a3fdf3d 443 * AD1983 specific
1da177e4 444 */
1da177e4 445
272f3ea3
TI
446/*
447 * SPDIF mux control for AD1983 auto-parser
448 */
449static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
450 struct snd_ctl_elem_info *uinfo)
451{
452 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
453 struct ad198x_spec *spec = codec->spec;
454 static const char * const texts2[] = { "PCM", "ADC" };
455 static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
456 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
457 int num_conns = snd_hda_get_num_conns(codec, dig_out);
458
459 if (num_conns == 2)
460 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
461 else if (num_conns == 3)
462 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
463 else
464 return -EINVAL;
465}
466
467static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
468 struct snd_ctl_elem_value *ucontrol)
469{
470 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
471 struct ad198x_spec *spec = codec->spec;
472
473 ucontrol->value.enumerated.item[0] = spec->cur_smux;
474 return 0;
475}
476
477static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
478 struct snd_ctl_elem_value *ucontrol)
479{
480 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
481 struct ad198x_spec *spec = codec->spec;
482 unsigned int val = ucontrol->value.enumerated.item[0];
483 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
484 int num_conns = snd_hda_get_num_conns(codec, dig_out);
485
486 if (val >= num_conns)
487 return -EINVAL;
488 if (spec->cur_smux == val)
489 return 0;
490 spec->cur_smux = val;
491 snd_hda_codec_write_cache(codec, dig_out, 0,
492 AC_VERB_SET_CONNECT_SEL, val);
493 return 1;
494}
495
fdbf0488 496static const struct snd_kcontrol_new ad1983_auto_smux_mixer = {
272f3ea3
TI
497 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
498 .name = "IEC958 Playback Source",
499 .info = ad1983_auto_smux_enum_info,
500 .get = ad1983_auto_smux_enum_get,
501 .put = ad1983_auto_smux_enum_put,
502};
503
504static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
505{
506 struct ad198x_spec *spec = codec->spec;
507 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
508 int num_conns;
509
510 if (!dig_out)
511 return 0;
512 num_conns = snd_hda_get_num_conns(codec, dig_out);
513 if (num_conns != 2 && num_conns != 3)
514 return 0;
515 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
516 return -ENOMEM;
517 return 0;
518}
519
bd450dcc 520static int patch_ad1983(struct hda_codec *codec)
78bb3cb0 521{
9ff4bc8f 522 struct ad198x_spec *spec;
276ab336
TI
523 static hda_nid_t conn_0c[] = { 0x08 };
524 static hda_nid_t conn_0d[] = { 0x09 };
272f3ea3 525 int err;
78bb3cb0 526
9ff4bc8f
TI
527 err = alloc_ad_spec(codec);
528 if (err < 0)
529 return err;
530 spec = codec->spec;
531
c7579fed 532 spec->gen.mixer_nid = 0x0e;
7504b6cd 533 spec->gen.beep_nid = 0x10;
78bb3cb0 534 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
276ab336
TI
535
536 /* limit the loopback routes not to confuse the parser */
537 snd_hda_override_conn_list(codec, 0x0c, ARRAY_SIZE(conn_0c), conn_0c);
538 snd_hda_override_conn_list(codec, 0x0d, ARRAY_SIZE(conn_0d), conn_0d);
539
cbd209f4 540 err = ad198x_parse_auto_config(codec, false);
272f3ea3 541 if (err < 0)
9ff4bc8f 542 goto error;
272f3ea3
TI
543 err = ad1983_add_spdif_mux_ctl(codec);
544 if (err < 0)
9ff4bc8f 545 goto error;
272f3ea3 546 return 0;
9ff4bc8f
TI
547
548 error:
7504b6cd 549 snd_hda_gen_free(codec);
9ff4bc8f 550 return err;
78bb3cb0
TI
551}
552
1da177e4 553
4a3fdf3d
TI
554/*
555 * AD1981 HD specific
556 */
1da177e4 557
a928bd2c
TI
558static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
559 const struct hda_fixup *fix, int action)
560{
561 struct ad198x_spec *spec = codec->spec;
562
563 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
564 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
565 spec->eapd_nid = 0x05;
566 }
567}
568
569/* set the upper-limit for mixer amp to 0dB for avoiding the possible
570 * damage by overloading
571 */
572static void ad1981_fixup_amp_override(struct hda_codec *codec,
573 const struct hda_fixup *fix, int action)
574{
575 if (action == HDA_FIXUP_ACT_PRE_PROBE)
576 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
577 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
578 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
579 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
580 (1 << AC_AMPCAP_MUTE_SHIFT));
581}
582
583enum {
584 AD1981_FIXUP_AMP_OVERRIDE,
585 AD1981_FIXUP_HP_EAPD,
586};
587
588static const struct hda_fixup ad1981_fixups[] = {
589 [AD1981_FIXUP_AMP_OVERRIDE] = {
590 .type = HDA_FIXUP_FUNC,
591 .v.func = ad1981_fixup_amp_override,
592 },
593 [AD1981_FIXUP_HP_EAPD] = {
594 .type = HDA_FIXUP_FUNC,
595 .v.func = ad1981_fixup_hp_eapd,
596 .chained = true,
597 .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
598 },
599};
600
601static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
602 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
603 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
604 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
605 /* HP nx6320 (reversed SSID, H/W bug) */
606 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
607 {}
608};
609
bd450dcc 610static int patch_ad1981(struct hda_codec *codec)
78bb3cb0 611{
9ff4bc8f 612 struct ad198x_spec *spec;
272f3ea3 613 int err;
78bb3cb0 614
9ff4bc8f
TI
615 err = alloc_ad_spec(codec);
616 if (err < 0)
617 return -ENOMEM;
618 spec = codec->spec;
619
f2f8be43 620 spec->gen.mixer_nid = 0x0e;
7504b6cd 621 spec->gen.beep_nid = 0x10;
78bb3cb0 622 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
a928bd2c
TI
623
624 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
625 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
626
cbd209f4 627 err = ad198x_parse_auto_config(codec, false);
272f3ea3 628 if (err < 0)
9ff4bc8f 629 goto error;
272f3ea3
TI
630 err = ad1983_add_spdif_mux_ctl(codec);
631 if (err < 0)
9ff4bc8f 632 goto error;
a928bd2c
TI
633
634 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
635
272f3ea3 636 return 0;
9ff4bc8f
TI
637
638 error:
7504b6cd 639 snd_hda_gen_free(codec);
9ff4bc8f 640 return err;
78bb3cb0
TI
641}
642
4a3fdf3d 643
fd66e0d0
TI
644/*
645 * AD1988
646 *
647 * Output pins and routes
648 *
d32410b1 649 * Pin Mix Sel DAC (*)
fd66e0d0
TI
650 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
651 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
652 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
653 * port-D 0x12 (mute/hp) <- 0x29 <- 04
654 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
655 * port-F 0x16 (mute) <- 0x2a <- 06
656 * port-G 0x24 (mute) <- 0x27 <- 05
657 * port-H 0x25 (mute) <- 0x28 <- 0a
658 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
659 *
d32410b1
TI
660 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
661 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
fd66e0d0
TI
662 *
663 * Input pins and routes
664 *
665 * pin boost mix input # / adc input #
666 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
667 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
668 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
669 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
670 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
671 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
672 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
673 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
674 *
675 *
676 * DAC assignment
d32410b1 677 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
f8c7c7b8 678 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
fd66e0d0
TI
679 *
680 * Inputs of Analog Mix (0x20)
681 * 0:Port-B (front mic)
682 * 1:Port-C/G/H (line-in)
683 * 2:Port-A
684 * 3:Port-D (line-in/2)
685 * 4:Port-E/G/H (mic-in)
686 * 5:Port-F (mic2-in)
687 * 6:CD
688 * 7:Beep
689 *
690 * ADC selection
691 * 0:Port-A
692 * 1:Port-B (front mic-in)
693 * 2:Port-C (line-in)
694 * 3:Port-F (mic2-in)
695 * 4:Port-E (mic-in)
696 * 5:CD
697 * 6:Port-G
698 * 7:Port-H
699 * 8:Port-D (line-in/2)
700 * 9:Mix
701 *
702 * Proposed pin assignments by the datasheet
703 *
704 * 6-stack
705 * Port-A front headphone
706 * B front mic-in
707 * C rear line-in
708 * D rear front-out
709 * E rear mic-in
710 * F rear surround
711 * G rear CLFE
712 * H rear side
713 *
714 * 3-stack
715 * Port-A front headphone
716 * B front mic
717 * C rear line-in/surround
718 * D rear front-out
719 * E rear mic-in/CLFE
720 *
721 * laptop
722 * Port-A headphone
723 * B mic-in
724 * C docking station
725 * D internal speaker (with EAPD)
726 * E/F quad mic array
727 */
728
272f3ea3
TI
729static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
730 struct snd_ctl_elem_info *uinfo)
731{
732 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
733 static const char * const texts[] = {
734 "PCM", "ADC1", "ADC2", "ADC3",
735 };
736 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
737 if (num_conns > 4)
738 num_conns = 4;
739 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
740}
741
742static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
743 struct snd_ctl_elem_value *ucontrol)
744{
745 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
746 struct ad198x_spec *spec = codec->spec;
747
748 ucontrol->value.enumerated.item[0] = spec->cur_smux;
749 return 0;
750}
751
752static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
753 struct snd_ctl_elem_value *ucontrol)
754{
755 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
756 struct ad198x_spec *spec = codec->spec;
757 unsigned int val = ucontrol->value.enumerated.item[0];
758 struct nid_path *path;
759 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
760
761 if (val >= num_conns)
762 return -EINVAL;
763 if (spec->cur_smux == val)
764 return 0;
765
766 mutex_lock(&codec->control_mutex);
272f3ea3
TI
767 path = snd_hda_get_path_from_idx(codec,
768 spec->smux_paths[spec->cur_smux]);
769 if (path)
770 snd_hda_activate_path(codec, path, false, true);
771 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
772 if (path)
773 snd_hda_activate_path(codec, path, true, true);
774 spec->cur_smux = val;
272f3ea3 775 mutex_unlock(&codec->control_mutex);
272f3ea3
TI
776 return 1;
777}
778
fdbf0488 779static const struct snd_kcontrol_new ad1988_auto_smux_mixer = {
272f3ea3
TI
780 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
781 .name = "IEC958 Playback Source",
782 .info = ad1988_auto_smux_enum_info,
783 .get = ad1988_auto_smux_enum_get,
784 .put = ad1988_auto_smux_enum_put,
785};
786
787static int ad1988_auto_init(struct hda_codec *codec)
788{
789 struct ad198x_spec *spec = codec->spec;
790 int i, err;
791
792 err = snd_hda_gen_init(codec);
793 if (err < 0)
794 return err;
795 if (!spec->gen.autocfg.dig_outs)
796 return 0;
797
798 for (i = 0; i < 4; i++) {
799 struct nid_path *path;
800 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
801 if (path)
802 snd_hda_activate_path(codec, path, path->active, false);
803 }
804
805 return 0;
806}
807
808static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
809{
810 struct ad198x_spec *spec = codec->spec;
811 int i, num_conns;
812 /* we create four static faked paths, since AD codecs have odd
813 * widget connections regarding the SPDIF out source
814 */
815 static struct nid_path fake_paths[4] = {
816 {
817 .depth = 3,
818 .path = { 0x02, 0x1d, 0x1b },
819 .idx = { 0, 0, 0 },
820 .multi = { 0, 0, 0 },
821 },
822 {
823 .depth = 4,
824 .path = { 0x08, 0x0b, 0x1d, 0x1b },
825 .idx = { 0, 0, 1, 0 },
826 .multi = { 0, 1, 0, 0 },
827 },
828 {
829 .depth = 4,
830 .path = { 0x09, 0x0b, 0x1d, 0x1b },
831 .idx = { 0, 1, 1, 0 },
832 .multi = { 0, 1, 0, 0 },
833 },
834 {
835 .depth = 4,
836 .path = { 0x0f, 0x0b, 0x1d, 0x1b },
837 .idx = { 0, 2, 1, 0 },
838 .multi = { 0, 1, 0, 0 },
839 },
840 };
841
842 /* SPDIF source mux appears to be present only on AD1988A */
843 if (!spec->gen.autocfg.dig_outs ||
844 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
845 return 0;
846
847 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
848 if (num_conns != 3 && num_conns != 4)
849 return 0;
850
851 for (i = 0; i < num_conns; i++) {
852 struct nid_path *path = snd_array_new(&spec->gen.paths);
853 if (!path)
854 return -ENOMEM;
855 *path = fake_paths[i];
856 if (!i)
857 path->active = 1;
858 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
859 }
860
861 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
862 return -ENOMEM;
863
864 codec->patch_ops.init = ad1988_auto_init;
865
866 return 0;
867}
868
d32410b1 869/*
d32410b1
TI
870 */
871
36ad4530
TI
872enum {
873 AD1988_FIXUP_6STACK_DIG,
874};
875
876static const struct hda_fixup ad1988_fixups[] = {
877 [AD1988_FIXUP_6STACK_DIG] = {
878 .type = HDA_FIXUP_PINS,
879 .v.pins = (const struct hda_pintbl[]) {
880 { 0x11, 0x02214130 }, /* front-hp */
881 { 0x12, 0x01014010 }, /* line-out */
882 { 0x14, 0x02a19122 }, /* front-mic */
883 { 0x15, 0x01813021 }, /* line-in */
884 { 0x16, 0x01011012 }, /* line-out */
885 { 0x17, 0x01a19020 }, /* mic */
886 { 0x1b, 0x0145f1f0 }, /* SPDIF */
887 { 0x24, 0x01016011 }, /* line-out */
888 { 0x25, 0x01012013 }, /* line-out */
889 { }
890 }
891 },
892};
893
894static const struct hda_model_fixup ad1988_fixup_models[] = {
895 { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
896 {}
897};
898
899static int patch_ad1988(struct hda_codec *codec)
d32410b1 900{
9ff4bc8f 901 struct ad198x_spec *spec;
272f3ea3 902 int err;
d32410b1 903
9ff4bc8f
TI
904 err = alloc_ad_spec(codec);
905 if (err < 0)
906 return err;
907 spec = codec->spec;
908
f2f8be43 909 spec->gen.mixer_nid = 0x20;
e4a395e7 910 spec->gen.mixer_merge_nid = 0x21;
7504b6cd 911 spec->gen.beep_nid = 0x10;
78bb3cb0 912 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
36ad4530
TI
913
914 snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
915 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
916
cbd209f4 917 err = ad198x_parse_auto_config(codec, true);
272f3ea3 918 if (err < 0)
9ff4bc8f 919 goto error;
272f3ea3
TI
920 err = ad1988_add_spdif_mux_ctl(codec);
921 if (err < 0)
9ff4bc8f 922 goto error;
36ad4530
TI
923
924 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
925
272f3ea3 926 return 0;
9ff4bc8f
TI
927
928 error:
7504b6cd 929 snd_hda_gen_free(codec);
9ff4bc8f 930 return err;
d32410b1
TI
931}
932
fd66e0d0 933
2bac647c
TI
934/*
935 * AD1884 / AD1984
936 *
937 * port-B - front line/mic-in
938 * port-E - aux in/out
939 * port-F - aux in/out
940 * port-C - rear line/mic-in
941 * port-D - rear line/hp-out
942 * port-A - front line/hp-out
943 *
944 * AD1984 = AD1884 + two digital mic-ins
945 *
5ccc618f
TI
946 * AD1883 / AD1884A / AD1984A / AD1984B
947 *
948 * port-B (0x14) - front mic-in
949 * port-E (0x1c) - rear mic-in
950 * port-F (0x16) - CD / ext out
951 * port-C (0x15) - rear line-in
952 * port-D (0x12) - rear line-out
953 * port-A (0x11) - front hp-out
954 *
955 * AD1984A = AD1884A + digital-mic
956 * AD1883 = equivalent with AD1984A
957 * AD1984B = AD1984A + extra SPDIF-out
2bac647c 958 */
a928bd2c
TI
959
960/* set the upper-limit for mixer amp to 0dB for avoiding the possible
961 * damage by overloading
962 */
963static void ad1884_fixup_amp_override(struct hda_codec *codec,
964 const struct hda_fixup *fix, int action)
965{
966 if (action == HDA_FIXUP_ACT_PRE_PROBE)
967 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
968 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
969 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
970 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
971 (1 << AC_AMPCAP_MUTE_SHIFT));
972}
973
1a39b5e1
TI
974/* toggle GPIO1 according to the mute state */
975static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
976{
977 struct hda_codec *codec = private_data;
978 struct ad198x_spec *spec = codec->spec;
979
980 if (spec->eapd_nid)
981 ad_vmaster_eapd_hook(private_data, enabled);
401caff7 982 snd_hda_codec_write_cache(codec, 0x01, 0,
1a39b5e1
TI
983 AC_VERB_SET_GPIO_DATA,
984 enabled ? 0x00 : 0x02);
985}
986
a928bd2c
TI
987static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
988 const struct hda_fixup *fix, int action)
989{
990 struct ad198x_spec *spec = codec->spec;
991
8f0b3b7e
TI
992 switch (action) {
993 case HDA_FIXUP_ACT_PRE_PROBE:
1a39b5e1 994 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
1cd9b2f7 995 spec->gen.own_eapd_ctl = 1;
a551d914
TI
996 snd_hda_codec_write_cache(codec, 0x01, 0,
997 AC_VERB_SET_GPIO_MASK, 0x02);
998 snd_hda_codec_write_cache(codec, 0x01, 0,
999 AC_VERB_SET_GPIO_DIRECTION, 0x02);
1000 snd_hda_codec_write_cache(codec, 0x01, 0,
1001 AC_VERB_SET_GPIO_DATA, 0x02);
8f0b3b7e
TI
1002 break;
1003 case HDA_FIXUP_ACT_PROBE:
a928bd2c
TI
1004 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1005 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
1006 else
1007 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
8f0b3b7e 1008 break;
a928bd2c
TI
1009 }
1010}
1011
1ac32930
TI
1012static void ad1884_fixup_thinkpad(struct hda_codec *codec,
1013 const struct hda_fixup *fix, int action)
1014{
1015 struct ad198x_spec *spec = codec->spec;
1016
afb5a779 1017 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1ac32930 1018 spec->gen.keep_eapd_on = 1;
afb5a779
TI
1019 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
1020 spec->eapd_nid = 0x12;
f3e9b59c
TI
1021 /* Analog PC Beeper - allow firmware/ACPI beeps */
1022 spec->beep_amp = HDA_COMPOSE_AMP_VAL(0x20, 3, 3, HDA_INPUT);
1023 spec->gen.beep_nid = 0; /* no digital beep */
afb5a779 1024 }
1ac32930
TI
1025}
1026
6a699bec
TI
1027/* set magic COEFs for dmic */
1028static const struct hda_verb ad1884_dmic_init_verbs[] = {
1029 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
1030 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
1031 {}
1032};
1033
a928bd2c
TI
1034enum {
1035 AD1884_FIXUP_AMP_OVERRIDE,
1036 AD1884_FIXUP_HP_EAPD,
6a699bec 1037 AD1884_FIXUP_DMIC_COEF,
1ac32930 1038 AD1884_FIXUP_THINKPAD,
f404627d 1039 AD1884_FIXUP_HP_TOUCHSMART,
a928bd2c
TI
1040};
1041
1042static const struct hda_fixup ad1884_fixups[] = {
1043 [AD1884_FIXUP_AMP_OVERRIDE] = {
1044 .type = HDA_FIXUP_FUNC,
1045 .v.func = ad1884_fixup_amp_override,
1046 },
1047 [AD1884_FIXUP_HP_EAPD] = {
1048 .type = HDA_FIXUP_FUNC,
1049 .v.func = ad1884_fixup_hp_eapd,
1050 .chained = true,
1051 .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
1052 },
6a699bec
TI
1053 [AD1884_FIXUP_DMIC_COEF] = {
1054 .type = HDA_FIXUP_VERBS,
1055 .v.verbs = ad1884_dmic_init_verbs,
1056 },
1ac32930
TI
1057 [AD1884_FIXUP_THINKPAD] = {
1058 .type = HDA_FIXUP_FUNC,
1059 .v.func = ad1884_fixup_thinkpad,
1060 .chained = true,
1061 .chain_id = AD1884_FIXUP_DMIC_COEF,
1062 },
f404627d
TI
1063 [AD1884_FIXUP_HP_TOUCHSMART] = {
1064 .type = HDA_FIXUP_VERBS,
1065 .v.verbs = ad1884_dmic_init_verbs,
1066 .chained = true,
1067 .chain_id = AD1884_FIXUP_HP_EAPD,
1068 },
a928bd2c
TI
1069};
1070
1071static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
f404627d 1072 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
a928bd2c 1073 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
1ac32930 1074 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
a928bd2c
TI
1075 {}
1076};
1077
1078
5ccc618f 1079static int patch_ad1884(struct hda_codec *codec)
78bb3cb0 1080{
9ff4bc8f 1081 struct ad198x_spec *spec;
272f3ea3 1082 int err;
78bb3cb0 1083
9ff4bc8f
TI
1084 err = alloc_ad_spec(codec);
1085 if (err < 0)
1086 return err;
1087 spec = codec->spec;
1088
f2f8be43 1089 spec->gen.mixer_nid = 0x20;
c5eda4c1 1090 spec->gen.mixer_merge_nid = 0x21;
7504b6cd 1091 spec->gen.beep_nid = 0x10;
78bb3cb0 1092 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
a928bd2c
TI
1093
1094 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
1095 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1096
cbd209f4 1097 err = ad198x_parse_auto_config(codec, true);
272f3ea3 1098 if (err < 0)
9ff4bc8f 1099 goto error;
272f3ea3
TI
1100 err = ad1983_add_spdif_mux_ctl(codec);
1101 if (err < 0)
9ff4bc8f 1102 goto error;
a928bd2c
TI
1103
1104 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1105
272f3ea3 1106 return 0;
78bb3cb0 1107
9ff4bc8f 1108 error:
7504b6cd 1109 snd_hda_gen_free(codec);
9ff4bc8f 1110 return err;
78bb3cb0
TI
1111}
1112
0ac8551e 1113/*
9e44c6e4 1114 * AD1882 / AD1882A
0ac8551e
TI
1115 *
1116 * port-A - front hp-out
1117 * port-B - front mic-in
1118 * port-C - rear line-in, shared surr-out (3stack)
1119 * port-D - rear line-out
1120 * port-E - rear mic-in, shared clfe-out (3stack)
1121 * port-F - rear surr-out (6stack)
1122 * port-G - rear clfe-out (6stack)
1123 */
1124
aa95d61b 1125static int patch_ad1882(struct hda_codec *codec)
78bb3cb0 1126{
9ff4bc8f 1127 struct ad198x_spec *spec;
272f3ea3 1128 int err;
78bb3cb0 1129
9ff4bc8f
TI
1130 err = alloc_ad_spec(codec);
1131 if (err < 0)
1132 return err;
1133 spec = codec->spec;
1134
f2f8be43 1135 spec->gen.mixer_nid = 0x20;
e4a395e7 1136 spec->gen.mixer_merge_nid = 0x21;
7504b6cd 1137 spec->gen.beep_nid = 0x10;
78bb3cb0 1138 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
cbd209f4 1139 err = ad198x_parse_auto_config(codec, true);
272f3ea3 1140 if (err < 0)
9ff4bc8f 1141 goto error;
272f3ea3
TI
1142 err = ad1988_add_spdif_mux_ctl(codec);
1143 if (err < 0)
9ff4bc8f 1144 goto error;
272f3ea3 1145 return 0;
9ff4bc8f
TI
1146
1147 error:
7504b6cd 1148 snd_hda_gen_free(codec);
9ff4bc8f 1149 return err;
78bb3cb0 1150}
0ac8551e 1151
0ac8551e 1152
1da177e4
LT
1153/*
1154 * patch entries
1155 */
b9a94a9c
TI
1156static const struct hda_device_id snd_hda_id_analog[] = {
1157 HDA_CODEC_ENTRY(0x11d4184a, "AD1884A", patch_ad1884),
1158 HDA_CODEC_ENTRY(0x11d41882, "AD1882", patch_ad1882),
1159 HDA_CODEC_ENTRY(0x11d41883, "AD1883", patch_ad1884),
1160 HDA_CODEC_ENTRY(0x11d41884, "AD1884", patch_ad1884),
1161 HDA_CODEC_ENTRY(0x11d4194a, "AD1984A", patch_ad1884),
1162 HDA_CODEC_ENTRY(0x11d4194b, "AD1984B", patch_ad1884),
1163 HDA_CODEC_ENTRY(0x11d41981, "AD1981", patch_ad1981),
1164 HDA_CODEC_ENTRY(0x11d41983, "AD1983", patch_ad1983),
1165 HDA_CODEC_ENTRY(0x11d41984, "AD1984", patch_ad1884),
1166 HDA_CODEC_ENTRY(0x11d41986, "AD1986A", patch_ad1986a),
1167 HDA_CODEC_ENTRY(0x11d41988, "AD1988", patch_ad1988),
1168 HDA_CODEC_ENTRY(0x11d4198b, "AD1988B", patch_ad1988),
1169 HDA_CODEC_ENTRY(0x11d4882a, "AD1882A", patch_ad1882),
1170 HDA_CODEC_ENTRY(0x11d4989a, "AD1989A", patch_ad1988),
1171 HDA_CODEC_ENTRY(0x11d4989b, "AD1989B", patch_ad1988),
1da177e4
LT
1172 {} /* terminator */
1173};
b9a94a9c 1174MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_analog);
1289e9e8
TI
1175
1176MODULE_LICENSE("GPL");
1177MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1178
d8a766a1 1179static struct hda_codec_driver analog_driver = {
b9a94a9c 1180 .id = snd_hda_id_analog,
1289e9e8
TI
1181};
1182
d8a766a1 1183module_hda_codec_driver(analog_driver);