2 * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
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, bool indep_hp)
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 = indep_hp;
199 spec->gen.add_stereo_mix_input = 1;
201 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
204 err = snd_hda_gen_parse_auto_config(codec, cfg);
208 codec->patch_ops = ad198x_auto_patch_ops;
217 static int alloc_ad_spec(struct hda_codec *codec)
219 struct ad198x_spec *spec;
221 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
225 snd_hda_gen_spec_init(&spec->gen);
230 * AD1986A fixup codes
233 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
234 static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
235 const struct hda_fixup *fix, int action)
237 struct ad198x_spec *spec = codec->spec;
239 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
240 codec->inv_jack_detect = 1;
241 spec->gen.keep_eapd_on = 1;
242 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
243 spec->eapd_nid = 0x1b;
247 /* Toshiba Satellite L40 implements EAPD in a standard way unlike others */
248 static void ad1986a_fixup_eapd(struct hda_codec *codec,
249 const struct hda_fixup *fix, int action)
251 struct ad198x_spec *spec = codec->spec;
253 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
255 spec->gen.keep_eapd_on = 1;
256 spec->eapd_nid = 0x1b;
261 AD1986A_FIXUP_INV_JACK_DETECT,
263 AD1986A_FIXUP_SAMSUNG,
264 AD1986A_FIXUP_3STACK,
265 AD1986A_FIXUP_LAPTOP,
266 AD1986A_FIXUP_LAPTOP_IMIC,
270 static 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,
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 */
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 */
293 [AD1986A_FIXUP_3STACK] = {
294 .type = HDA_FIXUP_PINS,
295 .v.pins = (const struct hda_pintbl[]) {
296 { 0x1a, 0x02214021 }, /* headphone */
297 { 0x1b, 0x01014011 }, /* front */
298 { 0x1c, 0x01813030 }, /* line-in */
299 { 0x1d, 0x01a19020 }, /* rear mic */
300 { 0x1e, 0x411111f0 }, /* N/A */
301 { 0x1f, 0x02a190f0 }, /* mic */
302 { 0x20, 0x411111f0 }, /* N/A */
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 */
319 [AD1986A_FIXUP_LAPTOP_IMIC] = {
320 .type = HDA_FIXUP_PINS,
321 .v.pins = (const struct hda_pintbl[]) {
322 { 0x1d, 0x90a7013e }, /* int mic */
326 .chain_id = AD1986A_FIXUP_LAPTOP,
328 [AD1986A_FIXUP_EAPD] = {
329 .type = HDA_FIXUP_FUNC,
330 .v.func = ad1986a_fixup_eapd,
334 static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
335 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC),
336 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK),
337 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK),
338 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK),
339 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40", AD1986A_FIXUP_EAPD),
340 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP),
341 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG),
342 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
343 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
344 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK),
345 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK),
349 static const struct hda_model_fixup ad1986a_fixup_models[] = {
350 { .id = AD1986A_FIXUP_3STACK, .name = "3stack" },
351 { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" },
352 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" },
353 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */
359 static int patch_ad1986a(struct hda_codec *codec)
362 struct ad198x_spec *spec;
363 static hda_nid_t preferred_pairs[] = {
372 err = alloc_ad_spec(codec);
377 /* AD1986A has the inverted EAPD implementation */
380 spec->gen.mixer_nid = 0x07;
381 spec->gen.beep_nid = 0x19;
382 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
384 /* AD1986A has a hardware problem that it can't share a stream
385 * with multiple output pins. The copy of front to surrounds
386 * causes noisy or silent outputs at a certain timing, e.g.
387 * changing the volume.
388 * So, let's disable the shared stream.
390 spec->gen.multiout.no_share_stream = 1;
391 /* give fixed DAC/pin pairs */
392 spec->gen.preferred_dacs = preferred_pairs;
394 /* AD1986A can't manage the dynamic pin on/off smoothly */
395 spec->gen.auto_mute_via_amp = 1;
397 snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl,
399 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
401 err = ad198x_parse_auto_config(codec, false);
403 snd_hda_gen_free(codec);
407 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
418 * SPDIF mux control for AD1983 auto-parser
420 static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
421 struct snd_ctl_elem_info *uinfo)
423 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
424 struct ad198x_spec *spec = codec->spec;
425 static const char * const texts2[] = { "PCM", "ADC" };
426 static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
427 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
428 int num_conns = snd_hda_get_num_conns(codec, dig_out);
431 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
432 else if (num_conns == 3)
433 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
438 static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
439 struct snd_ctl_elem_value *ucontrol)
441 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
442 struct ad198x_spec *spec = codec->spec;
444 ucontrol->value.enumerated.item[0] = spec->cur_smux;
448 static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
449 struct snd_ctl_elem_value *ucontrol)
451 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
452 struct ad198x_spec *spec = codec->spec;
453 unsigned int val = ucontrol->value.enumerated.item[0];
454 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
455 int num_conns = snd_hda_get_num_conns(codec, dig_out);
457 if (val >= num_conns)
459 if (spec->cur_smux == val)
461 spec->cur_smux = val;
462 snd_hda_codec_write_cache(codec, dig_out, 0,
463 AC_VERB_SET_CONNECT_SEL, val);
467 static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
468 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
469 .name = "IEC958 Playback Source",
470 .info = ad1983_auto_smux_enum_info,
471 .get = ad1983_auto_smux_enum_get,
472 .put = ad1983_auto_smux_enum_put,
475 static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
477 struct ad198x_spec *spec = codec->spec;
478 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
483 num_conns = snd_hda_get_num_conns(codec, dig_out);
484 if (num_conns != 2 && num_conns != 3)
486 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
491 static int patch_ad1983(struct hda_codec *codec)
493 struct ad198x_spec *spec;
494 static hda_nid_t conn_0c[] = { 0x08 };
495 static hda_nid_t conn_0d[] = { 0x09 };
498 err = alloc_ad_spec(codec);
503 spec->gen.mixer_nid = 0x0e;
504 spec->gen.beep_nid = 0x10;
505 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
507 /* limit the loopback routes not to confuse the parser */
508 snd_hda_override_conn_list(codec, 0x0c, ARRAY_SIZE(conn_0c), conn_0c);
509 snd_hda_override_conn_list(codec, 0x0d, ARRAY_SIZE(conn_0d), conn_0d);
511 err = ad198x_parse_auto_config(codec, false);
514 err = ad1983_add_spdif_mux_ctl(codec);
520 snd_hda_gen_free(codec);
529 static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
530 const struct hda_fixup *fix, int action)
532 struct ad198x_spec *spec = codec->spec;
534 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
535 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
536 spec->eapd_nid = 0x05;
540 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
541 * damage by overloading
543 static void ad1981_fixup_amp_override(struct hda_codec *codec,
544 const struct hda_fixup *fix, int action)
546 if (action == HDA_FIXUP_ACT_PRE_PROBE)
547 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
548 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
549 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
550 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
551 (1 << AC_AMPCAP_MUTE_SHIFT));
555 AD1981_FIXUP_AMP_OVERRIDE,
556 AD1981_FIXUP_HP_EAPD,
559 static const struct hda_fixup ad1981_fixups[] = {
560 [AD1981_FIXUP_AMP_OVERRIDE] = {
561 .type = HDA_FIXUP_FUNC,
562 .v.func = ad1981_fixup_amp_override,
564 [AD1981_FIXUP_HP_EAPD] = {
565 .type = HDA_FIXUP_FUNC,
566 .v.func = ad1981_fixup_hp_eapd,
568 .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
572 static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
573 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
574 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
575 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
576 /* HP nx6320 (reversed SSID, H/W bug) */
577 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
581 static int patch_ad1981(struct hda_codec *codec)
583 struct ad198x_spec *spec;
586 err = alloc_ad_spec(codec);
591 spec->gen.mixer_nid = 0x0e;
592 spec->gen.beep_nid = 0x10;
593 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
595 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
596 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
598 err = ad198x_parse_auto_config(codec, false);
601 err = ad1983_add_spdif_mux_ctl(codec);
605 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
610 snd_hda_gen_free(codec);
618 * Output pins and routes
620 * Pin Mix Sel DAC (*)
621 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
622 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
623 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
624 * port-D 0x12 (mute/hp) <- 0x29 <- 04
625 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
626 * port-F 0x16 (mute) <- 0x2a <- 06
627 * port-G 0x24 (mute) <- 0x27 <- 05
628 * port-H 0x25 (mute) <- 0x28 <- 0a
629 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
631 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
632 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
634 * Input pins and routes
636 * pin boost mix input # / adc input #
637 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
638 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
639 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
640 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
641 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
642 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
643 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
644 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
648 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
649 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
651 * Inputs of Analog Mix (0x20)
652 * 0:Port-B (front mic)
653 * 1:Port-C/G/H (line-in)
655 * 3:Port-D (line-in/2)
656 * 4:Port-E/G/H (mic-in)
663 * 1:Port-B (front mic-in)
670 * 8:Port-D (line-in/2)
673 * Proposed pin assignments by the datasheet
676 * Port-A front headphone
686 * Port-A front headphone
688 * C rear line-in/surround
696 * D internal speaker (with EAPD)
700 #ifdef ENABLE_AD_STATIC_QUIRKS
701 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
702 struct snd_ctl_elem_info *uinfo)
704 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
705 struct ad198x_spec *spec = codec->spec;
706 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
707 spec->num_channel_mode);
710 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
711 struct snd_ctl_elem_value *ucontrol)
713 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
714 struct ad198x_spec *spec = codec->spec;
715 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
716 spec->num_channel_mode, spec->multiout.max_channels);
719 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
720 struct snd_ctl_elem_value *ucontrol)
722 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
723 struct ad198x_spec *spec = codec->spec;
724 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
725 spec->num_channel_mode,
726 &spec->multiout.max_channels);
727 if (err >= 0 && spec->need_dac_fix)
728 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
731 #endif /* ENABLE_AD_STATIC_QUIRKS */
733 static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
734 struct snd_ctl_elem_info *uinfo)
736 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
737 static const char * const texts[] = {
738 "PCM", "ADC1", "ADC2", "ADC3",
740 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
743 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
746 static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
747 struct snd_ctl_elem_value *ucontrol)
749 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
750 struct ad198x_spec *spec = codec->spec;
752 ucontrol->value.enumerated.item[0] = spec->cur_smux;
756 static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
757 struct snd_ctl_elem_value *ucontrol)
759 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
760 struct ad198x_spec *spec = codec->spec;
761 unsigned int val = ucontrol->value.enumerated.item[0];
762 struct nid_path *path;
763 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
765 if (val >= num_conns)
767 if (spec->cur_smux == val)
770 mutex_lock(&codec->control_mutex);
771 codec->cached_write = 1;
772 path = snd_hda_get_path_from_idx(codec,
773 spec->smux_paths[spec->cur_smux]);
775 snd_hda_activate_path(codec, path, false, true);
776 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
778 snd_hda_activate_path(codec, path, true, true);
779 spec->cur_smux = val;
780 codec->cached_write = 0;
781 mutex_unlock(&codec->control_mutex);
782 snd_hda_codec_flush_cache(codec); /* flush the updates */
786 static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
787 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
788 .name = "IEC958 Playback Source",
789 .info = ad1988_auto_smux_enum_info,
790 .get = ad1988_auto_smux_enum_get,
791 .put = ad1988_auto_smux_enum_put,
794 static int ad1988_auto_init(struct hda_codec *codec)
796 struct ad198x_spec *spec = codec->spec;
799 err = snd_hda_gen_init(codec);
802 if (!spec->gen.autocfg.dig_outs)
805 for (i = 0; i < 4; i++) {
806 struct nid_path *path;
807 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
809 snd_hda_activate_path(codec, path, path->active, false);
815 static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
817 struct ad198x_spec *spec = codec->spec;
819 /* we create four static faked paths, since AD codecs have odd
820 * widget connections regarding the SPDIF out source
822 static struct nid_path fake_paths[4] = {
825 .path = { 0x02, 0x1d, 0x1b },
827 .multi = { 0, 0, 0 },
831 .path = { 0x08, 0x0b, 0x1d, 0x1b },
832 .idx = { 0, 0, 1, 0 },
833 .multi = { 0, 1, 0, 0 },
837 .path = { 0x09, 0x0b, 0x1d, 0x1b },
838 .idx = { 0, 1, 1, 0 },
839 .multi = { 0, 1, 0, 0 },
843 .path = { 0x0f, 0x0b, 0x1d, 0x1b },
844 .idx = { 0, 2, 1, 0 },
845 .multi = { 0, 1, 0, 0 },
849 /* SPDIF source mux appears to be present only on AD1988A */
850 if (!spec->gen.autocfg.dig_outs ||
851 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
854 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
855 if (num_conns != 3 && num_conns != 4)
858 for (i = 0; i < num_conns; i++) {
859 struct nid_path *path = snd_array_new(&spec->gen.paths);
862 *path = fake_paths[i];
865 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
868 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
871 codec->patch_ops.init = ad1988_auto_init;
880 AD1988_FIXUP_6STACK_DIG,
883 static const struct hda_fixup ad1988_fixups[] = {
884 [AD1988_FIXUP_6STACK_DIG] = {
885 .type = HDA_FIXUP_PINS,
886 .v.pins = (const struct hda_pintbl[]) {
887 { 0x11, 0x02214130 }, /* front-hp */
888 { 0x12, 0x01014010 }, /* line-out */
889 { 0x14, 0x02a19122 }, /* front-mic */
890 { 0x15, 0x01813021 }, /* line-in */
891 { 0x16, 0x01011012 }, /* line-out */
892 { 0x17, 0x01a19020 }, /* mic */
893 { 0x1b, 0x0145f1f0 }, /* SPDIF */
894 { 0x24, 0x01016011 }, /* line-out */
895 { 0x25, 0x01012013 }, /* line-out */
901 static const struct hda_model_fixup ad1988_fixup_models[] = {
902 { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
906 static int patch_ad1988(struct hda_codec *codec)
908 struct ad198x_spec *spec;
911 err = alloc_ad_spec(codec);
916 spec->gen.mixer_nid = 0x20;
917 spec->gen.mixer_merge_nid = 0x21;
918 spec->gen.beep_nid = 0x10;
919 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
921 snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
922 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
924 err = ad198x_parse_auto_config(codec, true);
927 err = ad1988_add_spdif_mux_ctl(codec);
931 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
936 snd_hda_gen_free(codec);
944 * port-B - front line/mic-in
945 * port-E - aux in/out
946 * port-F - aux in/out
947 * port-C - rear line/mic-in
948 * port-D - rear line/hp-out
949 * port-A - front line/hp-out
951 * AD1984 = AD1884 + two digital mic-ins
953 * AD1883 / AD1884A / AD1984A / AD1984B
955 * port-B (0x14) - front mic-in
956 * port-E (0x1c) - rear mic-in
957 * port-F (0x16) - CD / ext out
958 * port-C (0x15) - rear line-in
959 * port-D (0x12) - rear line-out
960 * port-A (0x11) - front hp-out
962 * AD1984A = AD1884A + digital-mic
963 * AD1883 = equivalent with AD1984A
964 * AD1984B = AD1984A + extra SPDIF-out
967 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
968 * damage by overloading
970 static void ad1884_fixup_amp_override(struct hda_codec *codec,
971 const struct hda_fixup *fix, int action)
973 if (action == HDA_FIXUP_ACT_PRE_PROBE)
974 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
975 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
976 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
977 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
978 (1 << AC_AMPCAP_MUTE_SHIFT));
981 /* toggle GPIO1 according to the mute state */
982 static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
984 struct hda_codec *codec = private_data;
985 struct ad198x_spec *spec = codec->spec;
988 ad_vmaster_eapd_hook(private_data, enabled);
989 snd_hda_codec_update_cache(codec, 0x01, 0,
990 AC_VERB_SET_GPIO_DATA,
991 enabled ? 0x00 : 0x02);
994 static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
995 const struct hda_fixup *fix, int action)
997 struct ad198x_spec *spec = codec->spec;
998 static const struct hda_verb gpio_init_verbs[] = {
999 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
1000 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
1001 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
1006 case HDA_FIXUP_ACT_PRE_PROBE:
1007 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
1008 spec->gen.own_eapd_ctl = 1;
1009 snd_hda_sequence_write_cache(codec, gpio_init_verbs);
1011 case HDA_FIXUP_ACT_PROBE:
1012 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1013 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
1015 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
1020 static void ad1884_fixup_thinkpad(struct hda_codec *codec,
1021 const struct hda_fixup *fix, int action)
1023 struct ad198x_spec *spec = codec->spec;
1025 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1026 spec->gen.keep_eapd_on = 1;
1027 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
1028 spec->eapd_nid = 0x12;
1032 /* set magic COEFs for dmic */
1033 static const struct hda_verb ad1884_dmic_init_verbs[] = {
1034 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
1035 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
1040 AD1884_FIXUP_AMP_OVERRIDE,
1041 AD1884_FIXUP_HP_EAPD,
1042 AD1884_FIXUP_DMIC_COEF,
1043 AD1884_FIXUP_THINKPAD,
1044 AD1884_FIXUP_HP_TOUCHSMART,
1047 static const struct hda_fixup ad1884_fixups[] = {
1048 [AD1884_FIXUP_AMP_OVERRIDE] = {
1049 .type = HDA_FIXUP_FUNC,
1050 .v.func = ad1884_fixup_amp_override,
1052 [AD1884_FIXUP_HP_EAPD] = {
1053 .type = HDA_FIXUP_FUNC,
1054 .v.func = ad1884_fixup_hp_eapd,
1056 .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
1058 [AD1884_FIXUP_DMIC_COEF] = {
1059 .type = HDA_FIXUP_VERBS,
1060 .v.verbs = ad1884_dmic_init_verbs,
1062 [AD1884_FIXUP_THINKPAD] = {
1063 .type = HDA_FIXUP_FUNC,
1064 .v.func = ad1884_fixup_thinkpad,
1066 .chain_id = AD1884_FIXUP_DMIC_COEF,
1068 [AD1884_FIXUP_HP_TOUCHSMART] = {
1069 .type = HDA_FIXUP_VERBS,
1070 .v.verbs = ad1884_dmic_init_verbs,
1072 .chain_id = AD1884_FIXUP_HP_EAPD,
1076 static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
1077 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
1078 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
1079 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
1084 static int patch_ad1884(struct hda_codec *codec)
1086 struct ad198x_spec *spec;
1089 err = alloc_ad_spec(codec);
1094 spec->gen.mixer_nid = 0x20;
1095 spec->gen.beep_nid = 0x10;
1096 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1098 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
1099 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1101 err = ad198x_parse_auto_config(codec, true);
1104 err = ad1983_add_spdif_mux_ctl(codec);
1108 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1113 snd_hda_gen_free(codec);
1120 * port-A - front hp-out
1121 * port-B - front mic-in
1122 * port-C - rear line-in, shared surr-out (3stack)
1123 * port-D - rear line-out
1124 * port-E - rear mic-in, shared clfe-out (3stack)
1125 * port-F - rear surr-out (6stack)
1126 * port-G - rear clfe-out (6stack)
1129 static int patch_ad1882(struct hda_codec *codec)
1131 struct ad198x_spec *spec;
1134 err = alloc_ad_spec(codec);
1139 spec->gen.mixer_nid = 0x20;
1140 spec->gen.mixer_merge_nid = 0x21;
1141 spec->gen.beep_nid = 0x10;
1142 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1143 err = ad198x_parse_auto_config(codec, true);
1146 err = ad1988_add_spdif_mux_ctl(codec);
1152 snd_hda_gen_free(codec);
1160 static const struct hda_codec_preset snd_hda_preset_analog[] = {
1161 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
1162 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
1163 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
1164 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
1165 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
1166 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
1167 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
1168 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
1169 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
1170 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
1171 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
1172 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
1173 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
1174 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
1175 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
1179 MODULE_ALIAS("snd-hda-codec-id:11d4*");
1181 MODULE_LICENSE("GPL");
1182 MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1184 static struct hda_codec_preset_list analog_list = {
1185 .preset = snd_hda_preset_analog,
1186 .owner = THIS_MODULE,
1189 static int __init patch_analog_init(void)
1191 return snd_hda_add_codec_preset(&analog_list);
1194 static void __exit patch_analog_exit(void)
1196 snd_hda_delete_codec_preset(&analog_list);
1199 module_init(patch_analog_init)
1200 module_exit(patch_analog_exit)