2 * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
5 * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de>
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/module.h>
26 #include <sound/core.h>
27 #include "hda_codec.h"
28 #include "hda_local.h"
29 #include "hda_auto_parser.h"
32 #include "hda_generic.h"
36 struct hda_gen_spec gen;
40 unsigned int cur_smux;
43 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
47 #ifdef CONFIG_SND_HDA_INPUT_BEEP
48 /* additional beep mixers; the actual parameters are overwritten at build */
49 static const struct snd_kcontrol_new ad_beep_mixer[] = {
50 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
51 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
55 #define set_beep_amp(spec, nid, idx, dir) \
56 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
58 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
61 #ifdef CONFIG_SND_HDA_INPUT_BEEP
62 static int create_beep_ctls(struct hda_codec *codec)
64 struct ad198x_spec *spec = codec->spec;
65 const struct snd_kcontrol_new *knew;
70 for (knew = ad_beep_mixer ; knew->name; knew++) {
72 struct snd_kcontrol *kctl;
73 kctl = snd_ctl_new1(knew, codec);
76 kctl->private_value = spec->beep_amp;
77 err = snd_hda_ctl_add(codec, 0, kctl);
84 #define create_beep_ctls(codec) 0
88 static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
91 if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD)
92 snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
93 !codec->inv_eapd ? 0x00 : 0x02);
94 if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD)
95 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
96 !codec->inv_eapd ? 0x00 : 0x02);
99 static void ad198x_power_eapd(struct hda_codec *codec)
101 /* We currently only handle front, HP */
102 switch (codec->core.vendor_id) {
115 ad198x_power_eapd_write(codec, 0x12, 0x11);
119 ad198x_power_eapd_write(codec, 0x05, 0x06);
122 ad198x_power_eapd_write(codec, 0x1b, 0x1a);
127 static void ad198x_shutup(struct hda_codec *codec)
129 snd_hda_shutup_pins(codec);
130 ad198x_power_eapd(codec);
134 static int ad198x_suspend(struct hda_codec *codec)
136 ad198x_shutup(codec);
141 /* follow EAPD via vmaster hook */
142 static void ad_vmaster_eapd_hook(void *private_data, int enabled)
144 struct hda_codec *codec = private_data;
145 struct ad198x_spec *spec = codec->spec;
151 snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
152 AC_VERB_SET_EAPD_BTLENABLE,
153 enabled ? 0x02 : 0x00);
157 * Automatic parse of I/O pins from the BIOS configuration
160 static int ad198x_auto_build_controls(struct hda_codec *codec)
164 err = snd_hda_gen_build_controls(codec);
167 err = create_beep_ctls(codec);
173 static const struct hda_codec_ops ad198x_auto_patch_ops = {
174 .build_controls = ad198x_auto_build_controls,
175 .build_pcms = snd_hda_gen_build_pcms,
176 .init = snd_hda_gen_init,
177 .free = snd_hda_gen_free,
178 .unsol_event = snd_hda_jack_unsol_event,
180 .check_power_status = snd_hda_gen_check_power_status,
181 .suspend = ad198x_suspend,
183 .reboot_notify = ad198x_shutup,
187 static int ad198x_parse_auto_config(struct hda_codec *codec, bool indep_hp)
189 struct ad198x_spec *spec = codec->spec;
190 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
193 codec->spdif_status_reset = 1;
194 codec->no_trigger_sense = 1;
195 codec->no_sticky_stream = 1;
197 spec->gen.indep_hp = indep_hp;
198 if (!spec->gen.add_stereo_mix_input)
199 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
201 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
204 err = snd_hda_gen_parse_auto_config(codec, cfg);
215 static int alloc_ad_spec(struct hda_codec *codec)
217 struct ad198x_spec *spec;
219 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
223 snd_hda_gen_spec_init(&spec->gen);
224 codec->patch_ops = ad198x_auto_patch_ops;
229 * AD1986A fixup codes
232 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
233 static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
234 const struct hda_fixup *fix, int action)
236 struct ad198x_spec *spec = codec->spec;
238 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
239 codec->inv_jack_detect = 1;
240 spec->gen.keep_eapd_on = 1;
241 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
242 spec->eapd_nid = 0x1b;
246 /* Toshiba Satellite L40 implements EAPD in a standard way unlike others */
247 static void ad1986a_fixup_eapd(struct hda_codec *codec,
248 const struct hda_fixup *fix, int action)
250 struct ad198x_spec *spec = codec->spec;
252 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
254 spec->gen.keep_eapd_on = 1;
255 spec->eapd_nid = 0x1b;
259 /* enable stereo-mix input for avoiding regression on KDE (bko#88251) */
260 static void ad1986a_fixup_eapd_mix_in(struct hda_codec *codec,
261 const struct hda_fixup *fix, int action)
263 struct ad198x_spec *spec = codec->spec;
265 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
266 ad1986a_fixup_eapd(codec, fix, action);
267 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_ENABLE;
272 AD1986A_FIXUP_INV_JACK_DETECT,
274 AD1986A_FIXUP_SAMSUNG,
275 AD1986A_FIXUP_3STACK,
276 AD1986A_FIXUP_LAPTOP,
277 AD1986A_FIXUP_LAPTOP_IMIC,
279 AD1986A_FIXUP_EAPD_MIX_IN,
280 AD1986A_FIXUP_EASYNOTE,
283 static const struct hda_fixup ad1986a_fixups[] = {
284 [AD1986A_FIXUP_INV_JACK_DETECT] = {
285 .type = HDA_FIXUP_FUNC,
286 .v.func = ad_fixup_inv_jack_detect,
288 [AD1986A_FIXUP_ULTRA] = {
289 .type = HDA_FIXUP_PINS,
290 .v.pins = (const struct hda_pintbl[]) {
291 { 0x1b, 0x90170110 }, /* speaker */
292 { 0x1d, 0x90a7013e }, /* int mic */
296 [AD1986A_FIXUP_SAMSUNG] = {
297 .type = HDA_FIXUP_PINS,
298 .v.pins = (const struct hda_pintbl[]) {
299 { 0x1b, 0x90170110 }, /* speaker */
300 { 0x1d, 0x90a7013e }, /* int mic */
301 { 0x20, 0x411111f0 }, /* N/A */
302 { 0x24, 0x411111f0 }, /* N/A */
306 [AD1986A_FIXUP_3STACK] = {
307 .type = HDA_FIXUP_PINS,
308 .v.pins = (const struct hda_pintbl[]) {
309 { 0x1a, 0x02214021 }, /* headphone */
310 { 0x1b, 0x01014011 }, /* front */
311 { 0x1c, 0x01813030 }, /* line-in */
312 { 0x1d, 0x01a19020 }, /* rear mic */
313 { 0x1e, 0x411111f0 }, /* N/A */
314 { 0x1f, 0x02a190f0 }, /* mic */
315 { 0x20, 0x411111f0 }, /* N/A */
319 [AD1986A_FIXUP_LAPTOP] = {
320 .type = HDA_FIXUP_PINS,
321 .v.pins = (const struct hda_pintbl[]) {
322 { 0x1a, 0x02214021 }, /* headphone */
323 { 0x1b, 0x90170110 }, /* speaker */
324 { 0x1c, 0x411111f0 }, /* N/A */
325 { 0x1d, 0x411111f0 }, /* N/A */
326 { 0x1e, 0x411111f0 }, /* N/A */
327 { 0x1f, 0x02a191f0 }, /* mic */
328 { 0x20, 0x411111f0 }, /* N/A */
332 [AD1986A_FIXUP_LAPTOP_IMIC] = {
333 .type = HDA_FIXUP_PINS,
334 .v.pins = (const struct hda_pintbl[]) {
335 { 0x1d, 0x90a7013e }, /* int mic */
339 .chain_id = AD1986A_FIXUP_LAPTOP,
341 [AD1986A_FIXUP_EAPD] = {
342 .type = HDA_FIXUP_FUNC,
343 .v.func = ad1986a_fixup_eapd,
345 [AD1986A_FIXUP_EAPD_MIX_IN] = {
346 .type = HDA_FIXUP_FUNC,
347 .v.func = ad1986a_fixup_eapd_mix_in,
349 [AD1986A_FIXUP_EASYNOTE] = {
350 .type = HDA_FIXUP_PINS,
351 .v.pins = (const struct hda_pintbl[]) {
352 { 0x1a, 0x0421402f }, /* headphone */
353 { 0x1b, 0x90170110 }, /* speaker */
354 { 0x1c, 0x411111f0 }, /* N/A */
355 { 0x1d, 0x90a70130 }, /* int mic */
356 { 0x1e, 0x411111f0 }, /* N/A */
357 { 0x1f, 0x04a19040 }, /* mic */
358 { 0x20, 0x411111f0 }, /* N/A */
359 { 0x21, 0x411111f0 }, /* N/A */
360 { 0x22, 0x411111f0 }, /* N/A */
361 { 0x23, 0x411111f0 }, /* N/A */
362 { 0x24, 0x411111f0 }, /* N/A */
363 { 0x25, 0x411111f0 }, /* N/A */
367 .chain_id = AD1986A_FIXUP_EAPD_MIX_IN,
371 static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
372 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC),
373 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS Z99He", AD1986A_FIXUP_EAPD),
374 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8JN", AD1986A_FIXUP_EAPD),
375 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK),
376 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK),
377 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK),
378 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40", AD1986A_FIXUP_EAPD),
379 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP),
380 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG),
381 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
382 SND_PCI_QUIRK(0x1631, 0xc022, "PackardBell EasyNote MX65", AD1986A_FIXUP_EASYNOTE),
383 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
384 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK),
385 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK),
389 static const struct hda_model_fixup ad1986a_fixup_models[] = {
390 { .id = AD1986A_FIXUP_3STACK, .name = "3stack" },
391 { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" },
392 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" },
393 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */
394 { .id = AD1986A_FIXUP_EAPD, .name = "eapd" },
400 static int patch_ad1986a(struct hda_codec *codec)
403 struct ad198x_spec *spec;
404 static hda_nid_t preferred_pairs[] = {
413 err = alloc_ad_spec(codec);
418 /* AD1986A has the inverted EAPD implementation */
421 spec->gen.mixer_nid = 0x07;
422 spec->gen.beep_nid = 0x19;
423 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
425 /* AD1986A has a hardware problem that it can't share a stream
426 * with multiple output pins. The copy of front to surrounds
427 * causes noisy or silent outputs at a certain timing, e.g.
428 * changing the volume.
429 * So, let's disable the shared stream.
431 spec->gen.multiout.no_share_stream = 1;
432 /* give fixed DAC/pin pairs */
433 spec->gen.preferred_dacs = preferred_pairs;
435 /* AD1986A can't manage the dynamic pin on/off smoothly */
436 spec->gen.auto_mute_via_amp = 1;
438 snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl,
440 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
442 err = ad198x_parse_auto_config(codec, false);
444 snd_hda_gen_free(codec);
448 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
459 * SPDIF mux control for AD1983 auto-parser
461 static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
462 struct snd_ctl_elem_info *uinfo)
464 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
465 struct ad198x_spec *spec = codec->spec;
466 static const char * const texts2[] = { "PCM", "ADC" };
467 static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
468 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
469 int num_conns = snd_hda_get_num_conns(codec, dig_out);
472 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
473 else if (num_conns == 3)
474 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
479 static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
480 struct snd_ctl_elem_value *ucontrol)
482 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
483 struct ad198x_spec *spec = codec->spec;
485 ucontrol->value.enumerated.item[0] = spec->cur_smux;
489 static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
490 struct snd_ctl_elem_value *ucontrol)
492 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
493 struct ad198x_spec *spec = codec->spec;
494 unsigned int val = ucontrol->value.enumerated.item[0];
495 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
496 int num_conns = snd_hda_get_num_conns(codec, dig_out);
498 if (val >= num_conns)
500 if (spec->cur_smux == val)
502 spec->cur_smux = val;
503 snd_hda_codec_write_cache(codec, dig_out, 0,
504 AC_VERB_SET_CONNECT_SEL, val);
508 static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
509 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
510 .name = "IEC958 Playback Source",
511 .info = ad1983_auto_smux_enum_info,
512 .get = ad1983_auto_smux_enum_get,
513 .put = ad1983_auto_smux_enum_put,
516 static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
518 struct ad198x_spec *spec = codec->spec;
519 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
524 num_conns = snd_hda_get_num_conns(codec, dig_out);
525 if (num_conns != 2 && num_conns != 3)
527 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
532 static int patch_ad1983(struct hda_codec *codec)
534 struct ad198x_spec *spec;
535 static hda_nid_t conn_0c[] = { 0x08 };
536 static hda_nid_t conn_0d[] = { 0x09 };
539 err = alloc_ad_spec(codec);
544 spec->gen.mixer_nid = 0x0e;
545 spec->gen.beep_nid = 0x10;
546 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
548 /* limit the loopback routes not to confuse the parser */
549 snd_hda_override_conn_list(codec, 0x0c, ARRAY_SIZE(conn_0c), conn_0c);
550 snd_hda_override_conn_list(codec, 0x0d, ARRAY_SIZE(conn_0d), conn_0d);
552 err = ad198x_parse_auto_config(codec, false);
555 err = ad1983_add_spdif_mux_ctl(codec);
561 snd_hda_gen_free(codec);
570 static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
571 const struct hda_fixup *fix, int action)
573 struct ad198x_spec *spec = codec->spec;
575 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
576 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
577 spec->eapd_nid = 0x05;
581 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
582 * damage by overloading
584 static void ad1981_fixup_amp_override(struct hda_codec *codec,
585 const struct hda_fixup *fix, int action)
587 if (action == HDA_FIXUP_ACT_PRE_PROBE)
588 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
589 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
590 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
591 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
592 (1 << AC_AMPCAP_MUTE_SHIFT));
596 AD1981_FIXUP_AMP_OVERRIDE,
597 AD1981_FIXUP_HP_EAPD,
600 static const struct hda_fixup ad1981_fixups[] = {
601 [AD1981_FIXUP_AMP_OVERRIDE] = {
602 .type = HDA_FIXUP_FUNC,
603 .v.func = ad1981_fixup_amp_override,
605 [AD1981_FIXUP_HP_EAPD] = {
606 .type = HDA_FIXUP_FUNC,
607 .v.func = ad1981_fixup_hp_eapd,
609 .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
613 static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
614 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
615 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
616 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
617 /* HP nx6320 (reversed SSID, H/W bug) */
618 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
622 static int patch_ad1981(struct hda_codec *codec)
624 struct ad198x_spec *spec;
627 err = alloc_ad_spec(codec);
632 spec->gen.mixer_nid = 0x0e;
633 spec->gen.beep_nid = 0x10;
634 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
636 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
637 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
639 err = ad198x_parse_auto_config(codec, false);
642 err = ad1983_add_spdif_mux_ctl(codec);
646 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
651 snd_hda_gen_free(codec);
659 * Output pins and routes
661 * Pin Mix Sel DAC (*)
662 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
663 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
664 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
665 * port-D 0x12 (mute/hp) <- 0x29 <- 04
666 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
667 * port-F 0x16 (mute) <- 0x2a <- 06
668 * port-G 0x24 (mute) <- 0x27 <- 05
669 * port-H 0x25 (mute) <- 0x28 <- 0a
670 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
672 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
673 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
675 * Input pins and routes
677 * pin boost mix input # / adc input #
678 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
679 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
680 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
681 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
682 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
683 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
684 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
685 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
689 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
690 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
692 * Inputs of Analog Mix (0x20)
693 * 0:Port-B (front mic)
694 * 1:Port-C/G/H (line-in)
696 * 3:Port-D (line-in/2)
697 * 4:Port-E/G/H (mic-in)
704 * 1:Port-B (front mic-in)
711 * 8:Port-D (line-in/2)
714 * Proposed pin assignments by the datasheet
717 * Port-A front headphone
727 * Port-A front headphone
729 * C rear line-in/surround
737 * D internal speaker (with EAPD)
741 static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
742 struct snd_ctl_elem_info *uinfo)
744 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
745 static const char * const texts[] = {
746 "PCM", "ADC1", "ADC2", "ADC3",
748 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
751 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
754 static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
755 struct snd_ctl_elem_value *ucontrol)
757 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
758 struct ad198x_spec *spec = codec->spec;
760 ucontrol->value.enumerated.item[0] = spec->cur_smux;
764 static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
765 struct snd_ctl_elem_value *ucontrol)
767 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
768 struct ad198x_spec *spec = codec->spec;
769 unsigned int val = ucontrol->value.enumerated.item[0];
770 struct nid_path *path;
771 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
773 if (val >= num_conns)
775 if (spec->cur_smux == val)
778 mutex_lock(&codec->control_mutex);
779 path = snd_hda_get_path_from_idx(codec,
780 spec->smux_paths[spec->cur_smux]);
782 snd_hda_activate_path(codec, path, false, true);
783 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
785 snd_hda_activate_path(codec, path, true, true);
786 spec->cur_smux = val;
787 mutex_unlock(&codec->control_mutex);
791 static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
792 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
793 .name = "IEC958 Playback Source",
794 .info = ad1988_auto_smux_enum_info,
795 .get = ad1988_auto_smux_enum_get,
796 .put = ad1988_auto_smux_enum_put,
799 static int ad1988_auto_init(struct hda_codec *codec)
801 struct ad198x_spec *spec = codec->spec;
804 err = snd_hda_gen_init(codec);
807 if (!spec->gen.autocfg.dig_outs)
810 for (i = 0; i < 4; i++) {
811 struct nid_path *path;
812 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
814 snd_hda_activate_path(codec, path, path->active, false);
820 static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
822 struct ad198x_spec *spec = codec->spec;
824 /* we create four static faked paths, since AD codecs have odd
825 * widget connections regarding the SPDIF out source
827 static struct nid_path fake_paths[4] = {
830 .path = { 0x02, 0x1d, 0x1b },
832 .multi = { 0, 0, 0 },
836 .path = { 0x08, 0x0b, 0x1d, 0x1b },
837 .idx = { 0, 0, 1, 0 },
838 .multi = { 0, 1, 0, 0 },
842 .path = { 0x09, 0x0b, 0x1d, 0x1b },
843 .idx = { 0, 1, 1, 0 },
844 .multi = { 0, 1, 0, 0 },
848 .path = { 0x0f, 0x0b, 0x1d, 0x1b },
849 .idx = { 0, 2, 1, 0 },
850 .multi = { 0, 1, 0, 0 },
854 /* SPDIF source mux appears to be present only on AD1988A */
855 if (!spec->gen.autocfg.dig_outs ||
856 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
859 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
860 if (num_conns != 3 && num_conns != 4)
863 for (i = 0; i < num_conns; i++) {
864 struct nid_path *path = snd_array_new(&spec->gen.paths);
867 *path = fake_paths[i];
870 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
873 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
876 codec->patch_ops.init = ad1988_auto_init;
885 AD1988_FIXUP_6STACK_DIG,
888 static const struct hda_fixup ad1988_fixups[] = {
889 [AD1988_FIXUP_6STACK_DIG] = {
890 .type = HDA_FIXUP_PINS,
891 .v.pins = (const struct hda_pintbl[]) {
892 { 0x11, 0x02214130 }, /* front-hp */
893 { 0x12, 0x01014010 }, /* line-out */
894 { 0x14, 0x02a19122 }, /* front-mic */
895 { 0x15, 0x01813021 }, /* line-in */
896 { 0x16, 0x01011012 }, /* line-out */
897 { 0x17, 0x01a19020 }, /* mic */
898 { 0x1b, 0x0145f1f0 }, /* SPDIF */
899 { 0x24, 0x01016011 }, /* line-out */
900 { 0x25, 0x01012013 }, /* line-out */
906 static const struct hda_model_fixup ad1988_fixup_models[] = {
907 { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
911 static int patch_ad1988(struct hda_codec *codec)
913 struct ad198x_spec *spec;
916 err = alloc_ad_spec(codec);
921 spec->gen.mixer_nid = 0x20;
922 spec->gen.mixer_merge_nid = 0x21;
923 spec->gen.beep_nid = 0x10;
924 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
926 snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
927 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
929 err = ad198x_parse_auto_config(codec, true);
932 err = ad1988_add_spdif_mux_ctl(codec);
936 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
941 snd_hda_gen_free(codec);
949 * port-B - front line/mic-in
950 * port-E - aux in/out
951 * port-F - aux in/out
952 * port-C - rear line/mic-in
953 * port-D - rear line/hp-out
954 * port-A - front line/hp-out
956 * AD1984 = AD1884 + two digital mic-ins
958 * AD1883 / AD1884A / AD1984A / AD1984B
960 * port-B (0x14) - front mic-in
961 * port-E (0x1c) - rear mic-in
962 * port-F (0x16) - CD / ext out
963 * port-C (0x15) - rear line-in
964 * port-D (0x12) - rear line-out
965 * port-A (0x11) - front hp-out
967 * AD1984A = AD1884A + digital-mic
968 * AD1883 = equivalent with AD1984A
969 * AD1984B = AD1984A + extra SPDIF-out
972 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
973 * damage by overloading
975 static void ad1884_fixup_amp_override(struct hda_codec *codec,
976 const struct hda_fixup *fix, int action)
978 if (action == HDA_FIXUP_ACT_PRE_PROBE)
979 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
980 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
981 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
982 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
983 (1 << AC_AMPCAP_MUTE_SHIFT));
986 /* toggle GPIO1 according to the mute state */
987 static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
989 struct hda_codec *codec = private_data;
990 struct ad198x_spec *spec = codec->spec;
993 ad_vmaster_eapd_hook(private_data, enabled);
994 snd_hda_codec_update_cache(codec, 0x01, 0,
995 AC_VERB_SET_GPIO_DATA,
996 enabled ? 0x00 : 0x02);
999 static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
1000 const struct hda_fixup *fix, int action)
1002 struct ad198x_spec *spec = codec->spec;
1005 case HDA_FIXUP_ACT_PRE_PROBE:
1006 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
1007 spec->gen.own_eapd_ctl = 1;
1008 snd_hda_codec_write_cache(codec, 0x01, 0,
1009 AC_VERB_SET_GPIO_MASK, 0x02);
1010 snd_hda_codec_write_cache(codec, 0x01, 0,
1011 AC_VERB_SET_GPIO_DIRECTION, 0x02);
1012 snd_hda_codec_write_cache(codec, 0x01, 0,
1013 AC_VERB_SET_GPIO_DATA, 0x02);
1015 case HDA_FIXUP_ACT_PROBE:
1016 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1017 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
1019 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
1024 static void ad1884_fixup_thinkpad(struct hda_codec *codec,
1025 const struct hda_fixup *fix, int action)
1027 struct ad198x_spec *spec = codec->spec;
1029 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1030 spec->gen.keep_eapd_on = 1;
1031 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
1032 spec->eapd_nid = 0x12;
1033 /* Analog PC Beeper - allow firmware/ACPI beeps */
1034 spec->beep_amp = HDA_COMPOSE_AMP_VAL(0x20, 3, 3, HDA_INPUT);
1035 spec->gen.beep_nid = 0; /* no digital beep */
1039 /* set magic COEFs for dmic */
1040 static const struct hda_verb ad1884_dmic_init_verbs[] = {
1041 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
1042 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
1047 AD1884_FIXUP_AMP_OVERRIDE,
1048 AD1884_FIXUP_HP_EAPD,
1049 AD1884_FIXUP_DMIC_COEF,
1050 AD1884_FIXUP_THINKPAD,
1051 AD1884_FIXUP_HP_TOUCHSMART,
1054 static const struct hda_fixup ad1884_fixups[] = {
1055 [AD1884_FIXUP_AMP_OVERRIDE] = {
1056 .type = HDA_FIXUP_FUNC,
1057 .v.func = ad1884_fixup_amp_override,
1059 [AD1884_FIXUP_HP_EAPD] = {
1060 .type = HDA_FIXUP_FUNC,
1061 .v.func = ad1884_fixup_hp_eapd,
1063 .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
1065 [AD1884_FIXUP_DMIC_COEF] = {
1066 .type = HDA_FIXUP_VERBS,
1067 .v.verbs = ad1884_dmic_init_verbs,
1069 [AD1884_FIXUP_THINKPAD] = {
1070 .type = HDA_FIXUP_FUNC,
1071 .v.func = ad1884_fixup_thinkpad,
1073 .chain_id = AD1884_FIXUP_DMIC_COEF,
1075 [AD1884_FIXUP_HP_TOUCHSMART] = {
1076 .type = HDA_FIXUP_VERBS,
1077 .v.verbs = ad1884_dmic_init_verbs,
1079 .chain_id = AD1884_FIXUP_HP_EAPD,
1083 static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
1084 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
1085 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
1086 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
1091 static int patch_ad1884(struct hda_codec *codec)
1093 struct ad198x_spec *spec;
1096 err = alloc_ad_spec(codec);
1101 spec->gen.mixer_nid = 0x20;
1102 spec->gen.mixer_merge_nid = 0x21;
1103 spec->gen.beep_nid = 0x10;
1104 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1106 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
1107 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1109 err = ad198x_parse_auto_config(codec, true);
1112 err = ad1983_add_spdif_mux_ctl(codec);
1116 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1121 snd_hda_gen_free(codec);
1128 * port-A - front hp-out
1129 * port-B - front mic-in
1130 * port-C - rear line-in, shared surr-out (3stack)
1131 * port-D - rear line-out
1132 * port-E - rear mic-in, shared clfe-out (3stack)
1133 * port-F - rear surr-out (6stack)
1134 * port-G - rear clfe-out (6stack)
1137 static int patch_ad1882(struct hda_codec *codec)
1139 struct ad198x_spec *spec;
1142 err = alloc_ad_spec(codec);
1147 spec->gen.mixer_nid = 0x20;
1148 spec->gen.mixer_merge_nid = 0x21;
1149 spec->gen.beep_nid = 0x10;
1150 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1151 err = ad198x_parse_auto_config(codec, true);
1154 err = ad1988_add_spdif_mux_ctl(codec);
1160 snd_hda_gen_free(codec);
1168 static const struct hda_device_id snd_hda_id_analog[] = {
1169 HDA_CODEC_ENTRY(0x11d4184a, "AD1884A", patch_ad1884),
1170 HDA_CODEC_ENTRY(0x11d41882, "AD1882", patch_ad1882),
1171 HDA_CODEC_ENTRY(0x11d41883, "AD1883", patch_ad1884),
1172 HDA_CODEC_ENTRY(0x11d41884, "AD1884", patch_ad1884),
1173 HDA_CODEC_ENTRY(0x11d4194a, "AD1984A", patch_ad1884),
1174 HDA_CODEC_ENTRY(0x11d4194b, "AD1984B", patch_ad1884),
1175 HDA_CODEC_ENTRY(0x11d41981, "AD1981", patch_ad1981),
1176 HDA_CODEC_ENTRY(0x11d41983, "AD1983", patch_ad1983),
1177 HDA_CODEC_ENTRY(0x11d41984, "AD1984", patch_ad1884),
1178 HDA_CODEC_ENTRY(0x11d41986, "AD1986A", patch_ad1986a),
1179 HDA_CODEC_ENTRY(0x11d41988, "AD1988", patch_ad1988),
1180 HDA_CODEC_ENTRY(0x11d4198b, "AD1988B", patch_ad1988),
1181 HDA_CODEC_ENTRY(0x11d4882a, "AD1882A", patch_ad1882),
1182 HDA_CODEC_ENTRY(0x11d4989a, "AD1989A", patch_ad1988),
1183 HDA_CODEC_ENTRY(0x11d4989b, "AD1989B", patch_ad1988),
1186 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_analog);
1188 MODULE_LICENSE("GPL");
1189 MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1191 static struct hda_codec_driver analog_driver = {
1192 .id = snd_hda_id_analog,
1195 module_hda_codec_driver(analog_driver);