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/pci.h>
25 #include <linux/module.h>
27 #include <sound/core.h>
28 #include "hda_codec.h"
29 #include "hda_local.h"
30 #include "hda_auto_parser.h"
33 #include "hda_generic.h"
37 struct hda_gen_spec gen;
41 unsigned int cur_smux;
44 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
48 #ifdef CONFIG_SND_HDA_INPUT_BEEP
49 /* additional beep mixers; the actual parameters are overwritten at build */
50 static const struct snd_kcontrol_new ad_beep_mixer[] = {
51 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
52 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
56 #define set_beep_amp(spec, nid, idx, dir) \
57 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
59 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
62 #ifdef CONFIG_SND_HDA_INPUT_BEEP
63 static int create_beep_ctls(struct hda_codec *codec)
65 struct ad198x_spec *spec = codec->spec;
66 const struct snd_kcontrol_new *knew;
71 for (knew = ad_beep_mixer ; knew->name; knew++) {
73 struct snd_kcontrol *kctl;
74 kctl = snd_ctl_new1(knew, codec);
77 kctl->private_value = spec->beep_amp;
78 err = snd_hda_ctl_add(codec, 0, kctl);
85 #define create_beep_ctls(codec) 0
89 static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
92 if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD)
93 snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
94 !codec->inv_eapd ? 0x00 : 0x02);
95 if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD)
96 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
97 !codec->inv_eapd ? 0x00 : 0x02);
100 static void ad198x_power_eapd(struct hda_codec *codec)
102 /* We currently only handle front, HP */
103 switch (codec->vendor_id) {
116 ad198x_power_eapd_write(codec, 0x12, 0x11);
120 ad198x_power_eapd_write(codec, 0x05, 0x06);
123 ad198x_power_eapd_write(codec, 0x1b, 0x1a);
128 static void ad198x_shutup(struct hda_codec *codec)
130 snd_hda_shutup_pins(codec);
131 ad198x_power_eapd(codec);
135 static int ad198x_suspend(struct hda_codec *codec)
137 ad198x_shutup(codec);
142 /* follow EAPD via vmaster hook */
143 static void ad_vmaster_eapd_hook(void *private_data, int enabled)
145 struct hda_codec *codec = private_data;
146 struct ad198x_spec *spec = codec->spec;
152 snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
153 AC_VERB_SET_EAPD_BTLENABLE,
154 enabled ? 0x02 : 0x00);
158 * Automatic parse of I/O pins from the BIOS configuration
161 static int ad198x_auto_build_controls(struct hda_codec *codec)
165 err = snd_hda_gen_build_controls(codec);
168 err = create_beep_ctls(codec);
174 static const struct hda_codec_ops ad198x_auto_patch_ops = {
175 .build_controls = ad198x_auto_build_controls,
176 .build_pcms = snd_hda_gen_build_pcms,
177 .init = snd_hda_gen_init,
178 .free = snd_hda_gen_free,
179 .unsol_event = snd_hda_jack_unsol_event,
181 .check_power_status = snd_hda_gen_check_power_status,
182 .suspend = ad198x_suspend,
184 .reboot_notify = ad198x_shutup,
188 static int ad198x_parse_auto_config(struct hda_codec *codec)
190 struct ad198x_spec *spec = codec->spec;
191 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
194 codec->spdif_status_reset = 1;
195 codec->no_trigger_sense = 1;
196 codec->no_sticky_stream = 1;
198 spec->gen.indep_hp = 1;
200 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
203 err = snd_hda_gen_parse_auto_config(codec, cfg);
207 codec->patch_ops = ad198x_auto_patch_ops;
216 static int alloc_ad_spec(struct hda_codec *codec)
218 struct ad198x_spec *spec;
220 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
224 snd_hda_gen_spec_init(&spec->gen);
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;
247 AD1986A_FIXUP_INV_JACK_DETECT,
249 AD1986A_FIXUP_SAMSUNG,
250 AD1986A_FIXUP_3STACK,
251 AD1986A_FIXUP_LAPTOP,
252 AD1986A_FIXUP_LAPTOP_IMIC,
255 static const struct hda_fixup ad1986a_fixups[] = {
256 [AD1986A_FIXUP_INV_JACK_DETECT] = {
257 .type = HDA_FIXUP_FUNC,
258 .v.func = ad_fixup_inv_jack_detect,
260 [AD1986A_FIXUP_ULTRA] = {
261 .type = HDA_FIXUP_PINS,
262 .v.pins = (const struct hda_pintbl[]) {
263 { 0x1b, 0x90170110 }, /* speaker */
264 { 0x1d, 0x90a7013e }, /* int mic */
268 [AD1986A_FIXUP_SAMSUNG] = {
269 .type = HDA_FIXUP_PINS,
270 .v.pins = (const struct hda_pintbl[]) {
271 { 0x1b, 0x90170110 }, /* speaker */
272 { 0x1d, 0x90a7013e }, /* int mic */
273 { 0x20, 0x411111f0 }, /* N/A */
274 { 0x24, 0x411111f0 }, /* N/A */
278 [AD1986A_FIXUP_3STACK] = {
279 .type = HDA_FIXUP_PINS,
280 .v.pins = (const struct hda_pintbl[]) {
281 { 0x1a, 0x02214021 }, /* headphone */
282 { 0x1b, 0x01014011 }, /* front */
283 { 0x1c, 0x01013012 }, /* surround */
284 { 0x1d, 0x01019015 }, /* clfe */
285 { 0x1e, 0x411111f0 }, /* N/A */
286 { 0x1f, 0x02a190f0 }, /* mic */
287 { 0x20, 0x018130f0 }, /* line-in */
291 [AD1986A_FIXUP_LAPTOP] = {
292 .type = HDA_FIXUP_PINS,
293 .v.pins = (const struct hda_pintbl[]) {
294 { 0x1a, 0x02214021 }, /* headphone */
295 { 0x1b, 0x90170110 }, /* speaker */
296 { 0x1c, 0x411111f0 }, /* N/A */
297 { 0x1d, 0x411111f0 }, /* N/A */
298 { 0x1e, 0x411111f0 }, /* N/A */
299 { 0x1f, 0x02a191f0 }, /* mic */
300 { 0x20, 0x411111f0 }, /* N/A */
304 [AD1986A_FIXUP_LAPTOP_IMIC] = {
305 .type = HDA_FIXUP_PINS,
306 .v.pins = (const struct hda_pintbl[]) {
307 { 0x1d, 0x90a7013e }, /* int mic */
311 .chain_id = AD1986A_FIXUP_LAPTOP,
315 static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
316 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC),
317 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK),
318 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK),
319 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK),
320 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP),
321 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG),
322 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
323 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
324 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK),
325 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK),
329 static const struct hda_model_fixup ad1986a_fixup_models[] = {
330 { .id = AD1986A_FIXUP_3STACK, .name = "3stack" },
331 { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" },
332 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" },
333 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */
339 static int patch_ad1986a(struct hda_codec *codec)
342 struct ad198x_spec *spec;
343 static hda_nid_t preferred_pairs[] = {
352 err = alloc_ad_spec(codec);
357 /* AD1986A has the inverted EAPD implementation */
360 spec->gen.mixer_nid = 0x07;
361 spec->gen.beep_nid = 0x19;
362 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
364 /* AD1986A has a hardware problem that it can't share a stream
365 * with multiple output pins. The copy of front to surrounds
366 * causes noisy or silent outputs at a certain timing, e.g.
367 * changing the volume.
368 * So, let's disable the shared stream.
370 spec->gen.multiout.no_share_stream = 1;
371 /* give fixed DAC/pin pairs */
372 spec->gen.preferred_dacs = preferred_pairs;
374 /* AD1986A can't manage the dynamic pin on/off smoothly */
375 spec->gen.auto_mute_via_amp = 1;
377 snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl,
379 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
381 err = ad198x_parse_auto_config(codec);
383 snd_hda_gen_free(codec);
387 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
398 * SPDIF mux control for AD1983 auto-parser
400 static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
401 struct snd_ctl_elem_info *uinfo)
403 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
404 struct ad198x_spec *spec = codec->spec;
405 static const char * const texts2[] = { "PCM", "ADC" };
406 static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
407 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
408 int num_conns = snd_hda_get_num_conns(codec, dig_out);
411 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
412 else if (num_conns == 3)
413 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
418 static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
419 struct snd_ctl_elem_value *ucontrol)
421 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
422 struct ad198x_spec *spec = codec->spec;
424 ucontrol->value.enumerated.item[0] = spec->cur_smux;
428 static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
429 struct snd_ctl_elem_value *ucontrol)
431 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
432 struct ad198x_spec *spec = codec->spec;
433 unsigned int val = ucontrol->value.enumerated.item[0];
434 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
435 int num_conns = snd_hda_get_num_conns(codec, dig_out);
437 if (val >= num_conns)
439 if (spec->cur_smux == val)
441 spec->cur_smux = val;
442 snd_hda_codec_write_cache(codec, dig_out, 0,
443 AC_VERB_SET_CONNECT_SEL, val);
447 static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
448 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
449 .name = "IEC958 Playback Source",
450 .info = ad1983_auto_smux_enum_info,
451 .get = ad1983_auto_smux_enum_get,
452 .put = ad1983_auto_smux_enum_put,
455 static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
457 struct ad198x_spec *spec = codec->spec;
458 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
463 num_conns = snd_hda_get_num_conns(codec, dig_out);
464 if (num_conns != 2 && num_conns != 3)
466 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
471 static int patch_ad1983(struct hda_codec *codec)
473 struct ad198x_spec *spec;
476 err = alloc_ad_spec(codec);
481 spec->gen.beep_nid = 0x10;
482 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
483 err = ad198x_parse_auto_config(codec);
486 err = ad1983_add_spdif_mux_ctl(codec);
492 snd_hda_gen_free(codec);
501 static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
502 const struct hda_fixup *fix, int action)
504 struct ad198x_spec *spec = codec->spec;
506 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
507 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
508 spec->eapd_nid = 0x05;
512 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
513 * damage by overloading
515 static void ad1981_fixup_amp_override(struct hda_codec *codec,
516 const struct hda_fixup *fix, int action)
518 if (action == HDA_FIXUP_ACT_PRE_PROBE)
519 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
520 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
521 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
522 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
523 (1 << AC_AMPCAP_MUTE_SHIFT));
527 AD1981_FIXUP_AMP_OVERRIDE,
528 AD1981_FIXUP_HP_EAPD,
531 static const struct hda_fixup ad1981_fixups[] = {
532 [AD1981_FIXUP_AMP_OVERRIDE] = {
533 .type = HDA_FIXUP_FUNC,
534 .v.func = ad1981_fixup_amp_override,
536 [AD1981_FIXUP_HP_EAPD] = {
537 .type = HDA_FIXUP_FUNC,
538 .v.func = ad1981_fixup_hp_eapd,
540 .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
544 static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
545 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
546 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
547 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
548 /* HP nx6320 (reversed SSID, H/W bug) */
549 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
553 static int patch_ad1981(struct hda_codec *codec)
555 struct ad198x_spec *spec;
558 err = alloc_ad_spec(codec);
563 spec->gen.mixer_nid = 0x0e;
564 spec->gen.beep_nid = 0x10;
565 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
567 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
568 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
570 err = ad198x_parse_auto_config(codec);
573 err = ad1983_add_spdif_mux_ctl(codec);
577 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
582 snd_hda_gen_free(codec);
590 * Output pins and routes
592 * Pin Mix Sel DAC (*)
593 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
594 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
595 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
596 * port-D 0x12 (mute/hp) <- 0x29 <- 04
597 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
598 * port-F 0x16 (mute) <- 0x2a <- 06
599 * port-G 0x24 (mute) <- 0x27 <- 05
600 * port-H 0x25 (mute) <- 0x28 <- 0a
601 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
603 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
604 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
606 * Input pins and routes
608 * pin boost mix input # / adc input #
609 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
610 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
611 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
612 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
613 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
614 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
615 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
616 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
620 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
621 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
623 * Inputs of Analog Mix (0x20)
624 * 0:Port-B (front mic)
625 * 1:Port-C/G/H (line-in)
627 * 3:Port-D (line-in/2)
628 * 4:Port-E/G/H (mic-in)
635 * 1:Port-B (front mic-in)
642 * 8:Port-D (line-in/2)
645 * Proposed pin assignments by the datasheet
648 * Port-A front headphone
658 * Port-A front headphone
660 * C rear line-in/surround
668 * D internal speaker (with EAPD)
672 #ifdef ENABLE_AD_STATIC_QUIRKS
673 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
674 struct snd_ctl_elem_info *uinfo)
676 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
677 struct ad198x_spec *spec = codec->spec;
678 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
679 spec->num_channel_mode);
682 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
683 struct snd_ctl_elem_value *ucontrol)
685 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
686 struct ad198x_spec *spec = codec->spec;
687 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
688 spec->num_channel_mode, spec->multiout.max_channels);
691 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
692 struct snd_ctl_elem_value *ucontrol)
694 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
695 struct ad198x_spec *spec = codec->spec;
696 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
697 spec->num_channel_mode,
698 &spec->multiout.max_channels);
699 if (err >= 0 && spec->need_dac_fix)
700 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
703 #endif /* ENABLE_AD_STATIC_QUIRKS */
705 static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
706 struct snd_ctl_elem_info *uinfo)
708 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
709 static const char * const texts[] = {
710 "PCM", "ADC1", "ADC2", "ADC3",
712 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
715 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
718 static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
719 struct snd_ctl_elem_value *ucontrol)
721 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
722 struct ad198x_spec *spec = codec->spec;
724 ucontrol->value.enumerated.item[0] = spec->cur_smux;
728 static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
729 struct snd_ctl_elem_value *ucontrol)
731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
732 struct ad198x_spec *spec = codec->spec;
733 unsigned int val = ucontrol->value.enumerated.item[0];
734 struct nid_path *path;
735 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
737 if (val >= num_conns)
739 if (spec->cur_smux == val)
742 mutex_lock(&codec->control_mutex);
743 codec->cached_write = 1;
744 path = snd_hda_get_path_from_idx(codec,
745 spec->smux_paths[spec->cur_smux]);
747 snd_hda_activate_path(codec, path, false, true);
748 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
750 snd_hda_activate_path(codec, path, true, true);
751 spec->cur_smux = val;
752 codec->cached_write = 0;
753 mutex_unlock(&codec->control_mutex);
754 snd_hda_codec_flush_cache(codec); /* flush the updates */
758 static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
759 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
760 .name = "IEC958 Playback Source",
761 .info = ad1988_auto_smux_enum_info,
762 .get = ad1988_auto_smux_enum_get,
763 .put = ad1988_auto_smux_enum_put,
766 static int ad1988_auto_init(struct hda_codec *codec)
768 struct ad198x_spec *spec = codec->spec;
771 err = snd_hda_gen_init(codec);
774 if (!spec->gen.autocfg.dig_outs)
777 for (i = 0; i < 4; i++) {
778 struct nid_path *path;
779 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
781 snd_hda_activate_path(codec, path, path->active, false);
787 static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
789 struct ad198x_spec *spec = codec->spec;
791 /* we create four static faked paths, since AD codecs have odd
792 * widget connections regarding the SPDIF out source
794 static struct nid_path fake_paths[4] = {
797 .path = { 0x02, 0x1d, 0x1b },
799 .multi = { 0, 0, 0 },
803 .path = { 0x08, 0x0b, 0x1d, 0x1b },
804 .idx = { 0, 0, 1, 0 },
805 .multi = { 0, 1, 0, 0 },
809 .path = { 0x09, 0x0b, 0x1d, 0x1b },
810 .idx = { 0, 1, 1, 0 },
811 .multi = { 0, 1, 0, 0 },
815 .path = { 0x0f, 0x0b, 0x1d, 0x1b },
816 .idx = { 0, 2, 1, 0 },
817 .multi = { 0, 1, 0, 0 },
821 /* SPDIF source mux appears to be present only on AD1988A */
822 if (!spec->gen.autocfg.dig_outs ||
823 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
826 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
827 if (num_conns != 3 && num_conns != 4)
830 for (i = 0; i < num_conns; i++) {
831 struct nid_path *path = snd_array_new(&spec->gen.paths);
834 *path = fake_paths[i];
837 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
840 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
843 codec->patch_ops.init = ad1988_auto_init;
852 AD1988_FIXUP_6STACK_DIG,
855 static const struct hda_fixup ad1988_fixups[] = {
856 [AD1988_FIXUP_6STACK_DIG] = {
857 .type = HDA_FIXUP_PINS,
858 .v.pins = (const struct hda_pintbl[]) {
859 { 0x11, 0x02214130 }, /* front-hp */
860 { 0x12, 0x01014010 }, /* line-out */
861 { 0x14, 0x02a19122 }, /* front-mic */
862 { 0x15, 0x01813021 }, /* line-in */
863 { 0x16, 0x01011012 }, /* line-out */
864 { 0x17, 0x01a19020 }, /* mic */
865 { 0x1b, 0x0145f1f0 }, /* SPDIF */
866 { 0x24, 0x01016011 }, /* line-out */
867 { 0x25, 0x01012013 }, /* line-out */
873 static const struct hda_model_fixup ad1988_fixup_models[] = {
874 { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
878 static int patch_ad1988(struct hda_codec *codec)
880 struct ad198x_spec *spec;
883 err = alloc_ad_spec(codec);
888 spec->gen.mixer_nid = 0x20;
889 spec->gen.mixer_merge_nid = 0x21;
890 spec->gen.beep_nid = 0x10;
891 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
893 snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
894 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
896 err = ad198x_parse_auto_config(codec);
899 err = ad1988_add_spdif_mux_ctl(codec);
903 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
908 snd_hda_gen_free(codec);
916 * port-B - front line/mic-in
917 * port-E - aux in/out
918 * port-F - aux in/out
919 * port-C - rear line/mic-in
920 * port-D - rear line/hp-out
921 * port-A - front line/hp-out
923 * AD1984 = AD1884 + two digital mic-ins
925 * AD1883 / AD1884A / AD1984A / AD1984B
927 * port-B (0x14) - front mic-in
928 * port-E (0x1c) - rear mic-in
929 * port-F (0x16) - CD / ext out
930 * port-C (0x15) - rear line-in
931 * port-D (0x12) - rear line-out
932 * port-A (0x11) - front hp-out
934 * AD1984A = AD1884A + digital-mic
935 * AD1883 = equivalent with AD1984A
936 * AD1984B = AD1984A + extra SPDIF-out
939 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
940 * damage by overloading
942 static void ad1884_fixup_amp_override(struct hda_codec *codec,
943 const struct hda_fixup *fix, int action)
945 if (action == HDA_FIXUP_ACT_PRE_PROBE)
946 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
947 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
948 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
949 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
950 (1 << AC_AMPCAP_MUTE_SHIFT));
953 /* toggle GPIO1 according to the mute state */
954 static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
956 struct hda_codec *codec = private_data;
957 struct ad198x_spec *spec = codec->spec;
960 ad_vmaster_eapd_hook(private_data, enabled);
961 snd_hda_codec_update_cache(codec, 0x01, 0,
962 AC_VERB_SET_GPIO_DATA,
963 enabled ? 0x00 : 0x02);
966 static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
967 const struct hda_fixup *fix, int action)
969 struct ad198x_spec *spec = codec->spec;
970 static const struct hda_verb gpio_init_verbs[] = {
971 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
972 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
973 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
978 case HDA_FIXUP_ACT_PRE_PROBE:
979 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
980 spec->gen.own_eapd_ctl = 1;
981 snd_hda_sequence_write_cache(codec, gpio_init_verbs);
983 case HDA_FIXUP_ACT_PROBE:
984 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
985 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
987 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
992 static void ad1884_fixup_thinkpad(struct hda_codec *codec,
993 const struct hda_fixup *fix, int action)
995 struct ad198x_spec *spec = codec->spec;
997 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
998 spec->gen.keep_eapd_on = 1;
999 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
1000 spec->eapd_nid = 0x12;
1004 /* set magic COEFs for dmic */
1005 static const struct hda_verb ad1884_dmic_init_verbs[] = {
1006 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
1007 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
1012 AD1884_FIXUP_AMP_OVERRIDE,
1013 AD1884_FIXUP_HP_EAPD,
1014 AD1884_FIXUP_DMIC_COEF,
1015 AD1884_FIXUP_THINKPAD,
1016 AD1884_FIXUP_HP_TOUCHSMART,
1019 static const struct hda_fixup ad1884_fixups[] = {
1020 [AD1884_FIXUP_AMP_OVERRIDE] = {
1021 .type = HDA_FIXUP_FUNC,
1022 .v.func = ad1884_fixup_amp_override,
1024 [AD1884_FIXUP_HP_EAPD] = {
1025 .type = HDA_FIXUP_FUNC,
1026 .v.func = ad1884_fixup_hp_eapd,
1028 .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
1030 [AD1884_FIXUP_DMIC_COEF] = {
1031 .type = HDA_FIXUP_VERBS,
1032 .v.verbs = ad1884_dmic_init_verbs,
1034 [AD1884_FIXUP_THINKPAD] = {
1035 .type = HDA_FIXUP_FUNC,
1036 .v.func = ad1884_fixup_thinkpad,
1038 .chain_id = AD1884_FIXUP_DMIC_COEF,
1040 [AD1884_FIXUP_HP_TOUCHSMART] = {
1041 .type = HDA_FIXUP_VERBS,
1042 .v.verbs = ad1884_dmic_init_verbs,
1044 .chain_id = AD1884_FIXUP_HP_EAPD,
1048 static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
1049 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
1050 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
1051 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
1056 static int patch_ad1884(struct hda_codec *codec)
1058 struct ad198x_spec *spec;
1061 err = alloc_ad_spec(codec);
1066 spec->gen.mixer_nid = 0x20;
1067 spec->gen.beep_nid = 0x10;
1068 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1070 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
1071 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1073 err = ad198x_parse_auto_config(codec);
1076 err = ad1983_add_spdif_mux_ctl(codec);
1080 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1085 snd_hda_gen_free(codec);
1092 * port-A - front hp-out
1093 * port-B - front mic-in
1094 * port-C - rear line-in, shared surr-out (3stack)
1095 * port-D - rear line-out
1096 * port-E - rear mic-in, shared clfe-out (3stack)
1097 * port-F - rear surr-out (6stack)
1098 * port-G - rear clfe-out (6stack)
1101 static int patch_ad1882(struct hda_codec *codec)
1103 struct ad198x_spec *spec;
1106 err = alloc_ad_spec(codec);
1111 spec->gen.mixer_nid = 0x20;
1112 spec->gen.mixer_merge_nid = 0x21;
1113 spec->gen.beep_nid = 0x10;
1114 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1115 err = ad198x_parse_auto_config(codec);
1118 err = ad1988_add_spdif_mux_ctl(codec);
1124 snd_hda_gen_free(codec);
1132 static const struct hda_codec_preset snd_hda_preset_analog[] = {
1133 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
1134 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
1135 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
1136 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
1137 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
1138 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
1139 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
1140 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
1141 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
1142 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
1143 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
1144 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
1145 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
1146 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
1147 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
1151 MODULE_ALIAS("snd-hda-codec-id:11d4*");
1153 MODULE_LICENSE("GPL");
1154 MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1156 static struct hda_codec_preset_list analog_list = {
1157 .preset = snd_hda_preset_analog,
1158 .owner = THIS_MODULE,
1161 static int __init patch_analog_init(void)
1163 return snd_hda_add_codec_preset(&analog_list);
1166 static void __exit patch_analog_exit(void)
1168 snd_hda_delete_codec_preset(&analog_list);
1171 module_init(patch_analog_init)
1172 module_exit(patch_analog_exit)