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);
144 * Automatic parse of I/O pins from the BIOS configuration
147 static int ad198x_auto_build_controls(struct hda_codec *codec)
151 err = snd_hda_gen_build_controls(codec);
154 err = create_beep_ctls(codec);
160 static 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,
164 .free = snd_hda_gen_free,
165 .unsol_event = snd_hda_jack_unsol_event,
167 .check_power_status = snd_hda_gen_check_power_status,
168 .suspend = ad198x_suspend,
170 .reboot_notify = ad198x_shutup,
174 static int ad198x_parse_auto_config(struct hda_codec *codec)
176 struct ad198x_spec *spec = codec->spec;
177 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
180 codec->spdif_status_reset = 1;
181 codec->no_trigger_sense = 1;
182 codec->no_sticky_stream = 1;
184 spec->gen.indep_hp = 1;
186 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
189 err = snd_hda_gen_parse_auto_config(codec, cfg);
193 codec->patch_ops = ad198x_auto_patch_ops;
202 static int alloc_ad_spec(struct hda_codec *codec)
204 struct ad198x_spec *spec;
206 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
210 snd_hda_gen_spec_init(&spec->gen);
215 * AD1986A fixup codes
218 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
219 static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
220 const struct hda_fixup *fix, int action)
222 struct ad198x_spec *spec = codec->spec;
224 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
225 codec->inv_jack_detect = 1;
226 spec->gen.keep_eapd_on = 1;
231 AD1986A_FIXUP_INV_JACK_DETECT,
233 AD1986A_FIXUP_SAMSUNG,
234 AD1986A_FIXUP_3STACK,
235 AD1986A_FIXUP_LAPTOP,
236 AD1986A_FIXUP_LAPTOP_IMIC,
239 static const struct hda_fixup ad1986a_fixups[] = {
240 [AD1986A_FIXUP_INV_JACK_DETECT] = {
241 .type = HDA_FIXUP_FUNC,
242 .v.func = ad_fixup_inv_jack_detect,
244 [AD1986A_FIXUP_ULTRA] = {
245 .type = HDA_FIXUP_PINS,
246 .v.pins = (const struct hda_pintbl[]) {
247 { 0x1b, 0x90170110 }, /* speaker */
248 { 0x1d, 0x90a7013e }, /* int mic */
252 [AD1986A_FIXUP_SAMSUNG] = {
253 .type = HDA_FIXUP_PINS,
254 .v.pins = (const struct hda_pintbl[]) {
255 { 0x1b, 0x90170110 }, /* speaker */
256 { 0x1d, 0x90a7013e }, /* int mic */
257 { 0x20, 0x411111f0 }, /* N/A */
258 { 0x24, 0x411111f0 }, /* N/A */
262 [AD1986A_FIXUP_3STACK] = {
263 .type = HDA_FIXUP_PINS,
264 .v.pins = (const struct hda_pintbl[]) {
265 { 0x1a, 0x02214021 }, /* headphone */
266 { 0x1b, 0x01014011 }, /* front */
267 { 0x1c, 0x01013012 }, /* surround */
268 { 0x1d, 0x01019015 }, /* clfe */
269 { 0x1e, 0x411111f0 }, /* N/A */
270 { 0x1f, 0x02a190f0 }, /* mic */
271 { 0x20, 0x018130f0 }, /* line-in */
275 [AD1986A_FIXUP_LAPTOP] = {
276 .type = HDA_FIXUP_PINS,
277 .v.pins = (const struct hda_pintbl[]) {
278 { 0x1a, 0x02214021 }, /* headphone */
279 { 0x1b, 0x90170110 }, /* speaker */
280 { 0x1c, 0x411111f0 }, /* N/A */
281 { 0x1d, 0x411111f0 }, /* N/A */
282 { 0x1e, 0x411111f0 }, /* N/A */
283 { 0x1f, 0x02a191f0 }, /* mic */
284 { 0x20, 0x411111f0 }, /* N/A */
288 [AD1986A_FIXUP_LAPTOP_IMIC] = {
289 .type = HDA_FIXUP_PINS,
290 .v.pins = (const struct hda_pintbl[]) {
291 { 0x1d, 0x90a7013e }, /* int mic */
295 .chain_id = AD1986A_FIXUP_LAPTOP,
299 static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
300 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC),
301 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK),
302 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK),
303 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK),
304 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP),
305 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG),
306 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
307 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
308 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK),
309 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK),
313 static const struct hda_model_fixup ad1986a_fixup_models[] = {
314 { .id = AD1986A_FIXUP_3STACK, .name = "3stack" },
315 { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" },
316 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" },
317 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */
323 static int patch_ad1986a(struct hda_codec *codec)
326 struct ad198x_spec *spec;
328 err = alloc_ad_spec(codec);
333 /* AD1986A has the inverted EAPD implementation */
336 spec->gen.mixer_nid = 0x07;
337 spec->gen.beep_nid = 0x19;
338 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
340 /* AD1986A has a hardware problem that it can't share a stream
341 * with multiple output pins. The copy of front to surrounds
342 * causes noisy or silent outputs at a certain timing, e.g.
343 * changing the volume.
344 * So, let's disable the shared stream.
346 spec->gen.multiout.no_share_stream = 1;
348 snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl,
350 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
352 err = ad198x_parse_auto_config(codec);
354 snd_hda_gen_free(codec);
358 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
369 * SPDIF mux control for AD1983 auto-parser
371 static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
372 struct snd_ctl_elem_info *uinfo)
374 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
375 struct ad198x_spec *spec = codec->spec;
376 static const char * const texts2[] = { "PCM", "ADC" };
377 static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
378 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
379 int num_conns = snd_hda_get_num_conns(codec, dig_out);
382 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
383 else if (num_conns == 3)
384 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
389 static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
390 struct snd_ctl_elem_value *ucontrol)
392 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
393 struct ad198x_spec *spec = codec->spec;
395 ucontrol->value.enumerated.item[0] = spec->cur_smux;
399 static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
400 struct snd_ctl_elem_value *ucontrol)
402 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
403 struct ad198x_spec *spec = codec->spec;
404 unsigned int val = ucontrol->value.enumerated.item[0];
405 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
406 int num_conns = snd_hda_get_num_conns(codec, dig_out);
408 if (val >= num_conns)
410 if (spec->cur_smux == val)
412 spec->cur_smux = val;
413 snd_hda_codec_write_cache(codec, dig_out, 0,
414 AC_VERB_SET_CONNECT_SEL, val);
418 static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
419 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
420 .name = "IEC958 Playback Source",
421 .info = ad1983_auto_smux_enum_info,
422 .get = ad1983_auto_smux_enum_get,
423 .put = ad1983_auto_smux_enum_put,
426 static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
428 struct ad198x_spec *spec = codec->spec;
429 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
434 num_conns = snd_hda_get_num_conns(codec, dig_out);
435 if (num_conns != 2 && num_conns != 3)
437 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
442 static int patch_ad1983(struct hda_codec *codec)
444 struct ad198x_spec *spec;
447 err = alloc_ad_spec(codec);
452 spec->gen.beep_nid = 0x10;
453 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
454 err = ad198x_parse_auto_config(codec);
457 err = ad1983_add_spdif_mux_ctl(codec);
463 snd_hda_gen_free(codec);
472 /* follow EAPD via vmaster hook */
473 static void ad_vmaster_eapd_hook(void *private_data, int enabled)
475 struct hda_codec *codec = private_data;
476 struct ad198x_spec *spec = codec->spec;
480 snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
481 AC_VERB_SET_EAPD_BTLENABLE,
482 enabled ? 0x02 : 0x00);
485 static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
486 const struct hda_fixup *fix, int action)
488 struct ad198x_spec *spec = codec->spec;
490 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
491 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
492 spec->eapd_nid = 0x05;
496 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
497 * damage by overloading
499 static void ad1981_fixup_amp_override(struct hda_codec *codec,
500 const struct hda_fixup *fix, int action)
502 if (action == HDA_FIXUP_ACT_PRE_PROBE)
503 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
504 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
505 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
506 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
507 (1 << AC_AMPCAP_MUTE_SHIFT));
511 AD1981_FIXUP_AMP_OVERRIDE,
512 AD1981_FIXUP_HP_EAPD,
515 static const struct hda_fixup ad1981_fixups[] = {
516 [AD1981_FIXUP_AMP_OVERRIDE] = {
517 .type = HDA_FIXUP_FUNC,
518 .v.func = ad1981_fixup_amp_override,
520 [AD1981_FIXUP_HP_EAPD] = {
521 .type = HDA_FIXUP_FUNC,
522 .v.func = ad1981_fixup_hp_eapd,
524 .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
528 static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
529 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
530 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
531 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
532 /* HP nx6320 (reversed SSID, H/W bug) */
533 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
537 static int patch_ad1981(struct hda_codec *codec)
539 struct ad198x_spec *spec;
542 err = alloc_ad_spec(codec);
547 spec->gen.mixer_nid = 0x0e;
548 spec->gen.beep_nid = 0x10;
549 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
551 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
552 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
554 err = ad198x_parse_auto_config(codec);
557 err = ad1983_add_spdif_mux_ctl(codec);
561 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
566 snd_hda_gen_free(codec);
574 * Output pins and routes
576 * Pin Mix Sel DAC (*)
577 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
578 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
579 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
580 * port-D 0x12 (mute/hp) <- 0x29 <- 04
581 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
582 * port-F 0x16 (mute) <- 0x2a <- 06
583 * port-G 0x24 (mute) <- 0x27 <- 05
584 * port-H 0x25 (mute) <- 0x28 <- 0a
585 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
587 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
588 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
590 * Input pins and routes
592 * pin boost mix input # / adc input #
593 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
594 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
595 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
596 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
597 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
598 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
599 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
600 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
604 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
605 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
607 * Inputs of Analog Mix (0x20)
608 * 0:Port-B (front mic)
609 * 1:Port-C/G/H (line-in)
611 * 3:Port-D (line-in/2)
612 * 4:Port-E/G/H (mic-in)
619 * 1:Port-B (front mic-in)
626 * 8:Port-D (line-in/2)
629 * Proposed pin assignments by the datasheet
632 * Port-A front headphone
642 * Port-A front headphone
644 * C rear line-in/surround
652 * D internal speaker (with EAPD)
656 #ifdef ENABLE_AD_STATIC_QUIRKS
657 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
658 struct snd_ctl_elem_info *uinfo)
660 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
661 struct ad198x_spec *spec = codec->spec;
662 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
663 spec->num_channel_mode);
666 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
667 struct snd_ctl_elem_value *ucontrol)
669 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670 struct ad198x_spec *spec = codec->spec;
671 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
672 spec->num_channel_mode, spec->multiout.max_channels);
675 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
676 struct snd_ctl_elem_value *ucontrol)
678 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
679 struct ad198x_spec *spec = codec->spec;
680 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
681 spec->num_channel_mode,
682 &spec->multiout.max_channels);
683 if (err >= 0 && spec->need_dac_fix)
684 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
687 #endif /* ENABLE_AD_STATIC_QUIRKS */
689 static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
690 struct snd_ctl_elem_info *uinfo)
692 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
693 static const char * const texts[] = {
694 "PCM", "ADC1", "ADC2", "ADC3",
696 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
699 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
702 static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
703 struct snd_ctl_elem_value *ucontrol)
705 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
706 struct ad198x_spec *spec = codec->spec;
708 ucontrol->value.enumerated.item[0] = spec->cur_smux;
712 static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
713 struct snd_ctl_elem_value *ucontrol)
715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
716 struct ad198x_spec *spec = codec->spec;
717 unsigned int val = ucontrol->value.enumerated.item[0];
718 struct nid_path *path;
719 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
721 if (val >= num_conns)
723 if (spec->cur_smux == val)
726 mutex_lock(&codec->control_mutex);
727 codec->cached_write = 1;
728 path = snd_hda_get_path_from_idx(codec,
729 spec->smux_paths[spec->cur_smux]);
731 snd_hda_activate_path(codec, path, false, true);
732 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
734 snd_hda_activate_path(codec, path, true, true);
735 spec->cur_smux = val;
736 codec->cached_write = 0;
737 mutex_unlock(&codec->control_mutex);
738 snd_hda_codec_flush_cache(codec); /* flush the updates */
742 static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
743 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
744 .name = "IEC958 Playback Source",
745 .info = ad1988_auto_smux_enum_info,
746 .get = ad1988_auto_smux_enum_get,
747 .put = ad1988_auto_smux_enum_put,
750 static int ad1988_auto_init(struct hda_codec *codec)
752 struct ad198x_spec *spec = codec->spec;
755 err = snd_hda_gen_init(codec);
758 if (!spec->gen.autocfg.dig_outs)
761 for (i = 0; i < 4; i++) {
762 struct nid_path *path;
763 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
765 snd_hda_activate_path(codec, path, path->active, false);
771 static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
773 struct ad198x_spec *spec = codec->spec;
775 /* we create four static faked paths, since AD codecs have odd
776 * widget connections regarding the SPDIF out source
778 static struct nid_path fake_paths[4] = {
781 .path = { 0x02, 0x1d, 0x1b },
783 .multi = { 0, 0, 0 },
787 .path = { 0x08, 0x0b, 0x1d, 0x1b },
788 .idx = { 0, 0, 1, 0 },
789 .multi = { 0, 1, 0, 0 },
793 .path = { 0x09, 0x0b, 0x1d, 0x1b },
794 .idx = { 0, 1, 1, 0 },
795 .multi = { 0, 1, 0, 0 },
799 .path = { 0x0f, 0x0b, 0x1d, 0x1b },
800 .idx = { 0, 2, 1, 0 },
801 .multi = { 0, 1, 0, 0 },
805 /* SPDIF source mux appears to be present only on AD1988A */
806 if (!spec->gen.autocfg.dig_outs ||
807 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
810 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
811 if (num_conns != 3 && num_conns != 4)
814 for (i = 0; i < num_conns; i++) {
815 struct nid_path *path = snd_array_new(&spec->gen.paths);
818 *path = fake_paths[i];
821 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
824 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
827 codec->patch_ops.init = ad1988_auto_init;
836 AD1988_FIXUP_6STACK_DIG,
839 static const struct hda_fixup ad1988_fixups[] = {
840 [AD1988_FIXUP_6STACK_DIG] = {
841 .type = HDA_FIXUP_PINS,
842 .v.pins = (const struct hda_pintbl[]) {
843 { 0x11, 0x02214130 }, /* front-hp */
844 { 0x12, 0x01014010 }, /* line-out */
845 { 0x14, 0x02a19122 }, /* front-mic */
846 { 0x15, 0x01813021 }, /* line-in */
847 { 0x16, 0x01011012 }, /* line-out */
848 { 0x17, 0x01a19020 }, /* mic */
849 { 0x1b, 0x0145f1f0 }, /* SPDIF */
850 { 0x24, 0x01016011 }, /* line-out */
851 { 0x25, 0x01012013 }, /* line-out */
857 static const struct hda_model_fixup ad1988_fixup_models[] = {
858 { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
862 static int patch_ad1988(struct hda_codec *codec)
864 struct ad198x_spec *spec;
867 err = alloc_ad_spec(codec);
872 spec->gen.mixer_nid = 0x20;
873 spec->gen.mixer_merge_nid = 0x21;
874 spec->gen.beep_nid = 0x10;
875 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
877 snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
878 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
880 err = ad198x_parse_auto_config(codec);
883 err = ad1988_add_spdif_mux_ctl(codec);
887 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
892 snd_hda_gen_free(codec);
900 * port-B - front line/mic-in
901 * port-E - aux in/out
902 * port-F - aux in/out
903 * port-C - rear line/mic-in
904 * port-D - rear line/hp-out
905 * port-A - front line/hp-out
907 * AD1984 = AD1884 + two digital mic-ins
909 * AD1883 / AD1884A / AD1984A / AD1984B
911 * port-B (0x14) - front mic-in
912 * port-E (0x1c) - rear mic-in
913 * port-F (0x16) - CD / ext out
914 * port-C (0x15) - rear line-in
915 * port-D (0x12) - rear line-out
916 * port-A (0x11) - front hp-out
918 * AD1984A = AD1884A + digital-mic
919 * AD1883 = equivalent with AD1984A
920 * AD1984B = AD1984A + extra SPDIF-out
923 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
924 * damage by overloading
926 static void ad1884_fixup_amp_override(struct hda_codec *codec,
927 const struct hda_fixup *fix, int action)
929 if (action == HDA_FIXUP_ACT_PRE_PROBE)
930 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
931 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
932 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
933 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
934 (1 << AC_AMPCAP_MUTE_SHIFT));
937 /* toggle GPIO1 according to the mute state */
938 static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
940 struct hda_codec *codec = private_data;
941 struct ad198x_spec *spec = codec->spec;
944 ad_vmaster_eapd_hook(private_data, enabled);
945 snd_hda_codec_update_cache(codec, 0x01, 0,
946 AC_VERB_SET_GPIO_DATA,
947 enabled ? 0x00 : 0x02);
950 static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
951 const struct hda_fixup *fix, int action)
953 struct ad198x_spec *spec = codec->spec;
954 static const struct hda_verb gpio_init_verbs[] = {
955 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
956 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
957 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
962 case HDA_FIXUP_ACT_PRE_PROBE:
963 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
964 snd_hda_sequence_write_cache(codec, gpio_init_verbs);
966 case HDA_FIXUP_ACT_PROBE:
967 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
968 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
970 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
975 static void ad1884_fixup_thinkpad(struct hda_codec *codec,
976 const struct hda_fixup *fix, int action)
978 struct ad198x_spec *spec = codec->spec;
980 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
981 spec->gen.keep_eapd_on = 1;
982 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
983 spec->eapd_nid = 0x12;
987 /* set magic COEFs for dmic */
988 static const struct hda_verb ad1884_dmic_init_verbs[] = {
989 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
990 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
995 AD1884_FIXUP_AMP_OVERRIDE,
996 AD1884_FIXUP_HP_EAPD,
997 AD1884_FIXUP_DMIC_COEF,
998 AD1884_FIXUP_THINKPAD,
999 AD1884_FIXUP_HP_TOUCHSMART,
1002 static const struct hda_fixup ad1884_fixups[] = {
1003 [AD1884_FIXUP_AMP_OVERRIDE] = {
1004 .type = HDA_FIXUP_FUNC,
1005 .v.func = ad1884_fixup_amp_override,
1007 [AD1884_FIXUP_HP_EAPD] = {
1008 .type = HDA_FIXUP_FUNC,
1009 .v.func = ad1884_fixup_hp_eapd,
1011 .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
1013 [AD1884_FIXUP_DMIC_COEF] = {
1014 .type = HDA_FIXUP_VERBS,
1015 .v.verbs = ad1884_dmic_init_verbs,
1017 [AD1884_FIXUP_THINKPAD] = {
1018 .type = HDA_FIXUP_FUNC,
1019 .v.func = ad1884_fixup_thinkpad,
1021 .chain_id = AD1884_FIXUP_DMIC_COEF,
1023 [AD1884_FIXUP_HP_TOUCHSMART] = {
1024 .type = HDA_FIXUP_VERBS,
1025 .v.verbs = ad1884_dmic_init_verbs,
1027 .chain_id = AD1884_FIXUP_HP_EAPD,
1031 static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
1032 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
1033 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
1034 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
1039 static int patch_ad1884(struct hda_codec *codec)
1041 struct ad198x_spec *spec;
1044 err = alloc_ad_spec(codec);
1049 spec->gen.mixer_nid = 0x20;
1050 spec->gen.beep_nid = 0x10;
1051 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1053 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
1054 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1056 err = ad198x_parse_auto_config(codec);
1059 err = ad1983_add_spdif_mux_ctl(codec);
1063 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1068 snd_hda_gen_free(codec);
1075 * port-A - front hp-out
1076 * port-B - front mic-in
1077 * port-C - rear line-in, shared surr-out (3stack)
1078 * port-D - rear line-out
1079 * port-E - rear mic-in, shared clfe-out (3stack)
1080 * port-F - rear surr-out (6stack)
1081 * port-G - rear clfe-out (6stack)
1084 static int patch_ad1882(struct hda_codec *codec)
1086 struct ad198x_spec *spec;
1089 err = alloc_ad_spec(codec);
1094 spec->gen.mixer_nid = 0x20;
1095 spec->gen.mixer_merge_nid = 0x21;
1096 spec->gen.beep_nid = 0x10;
1097 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1098 err = ad198x_parse_auto_config(codec);
1101 err = ad1988_add_spdif_mux_ctl(codec);
1107 snd_hda_gen_free(codec);
1115 static const struct hda_codec_preset snd_hda_preset_analog[] = {
1116 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
1117 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
1118 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
1119 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
1120 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
1121 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
1122 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
1123 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
1124 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
1125 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
1126 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
1127 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
1128 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
1129 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
1130 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
1134 MODULE_ALIAS("snd-hda-codec-id:11d4*");
1136 MODULE_LICENSE("GPL");
1137 MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1139 static struct hda_codec_preset_list analog_list = {
1140 .preset = snd_hda_preset_analog,
1141 .owner = THIS_MODULE,
1144 static int __init patch_analog_init(void)
1146 return snd_hda_add_codec_preset(&analog_list);
1149 static void __exit patch_analog_exit(void)
1151 snd_hda_delete_codec_preset(&analog_list);
1154 module_init(patch_analog_init)
1155 module_exit(patch_analog_exit)