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;
344 err = alloc_ad_spec(codec);
349 /* AD1986A has the inverted EAPD implementation */
352 spec->gen.mixer_nid = 0x07;
353 spec->gen.beep_nid = 0x19;
354 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
356 /* AD1986A has a hardware problem that it can't share a stream
357 * with multiple output pins. The copy of front to surrounds
358 * causes noisy or silent outputs at a certain timing, e.g.
359 * changing the volume.
360 * So, let's disable the shared stream.
362 spec->gen.multiout.no_share_stream = 1;
364 /* AD1986A can't manage the dynamic pin on/off smoothly */
365 spec->gen.auto_mute_via_amp = 1;
367 snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl,
369 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
371 err = ad198x_parse_auto_config(codec);
373 snd_hda_gen_free(codec);
377 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
388 * SPDIF mux control for AD1983 auto-parser
390 static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
391 struct snd_ctl_elem_info *uinfo)
393 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
394 struct ad198x_spec *spec = codec->spec;
395 static const char * const texts2[] = { "PCM", "ADC" };
396 static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
397 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
398 int num_conns = snd_hda_get_num_conns(codec, dig_out);
401 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
402 else if (num_conns == 3)
403 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
408 static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
409 struct snd_ctl_elem_value *ucontrol)
411 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
412 struct ad198x_spec *spec = codec->spec;
414 ucontrol->value.enumerated.item[0] = spec->cur_smux;
418 static int ad1983_auto_smux_enum_put(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;
423 unsigned int val = ucontrol->value.enumerated.item[0];
424 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
425 int num_conns = snd_hda_get_num_conns(codec, dig_out);
427 if (val >= num_conns)
429 if (spec->cur_smux == val)
431 spec->cur_smux = val;
432 snd_hda_codec_write_cache(codec, dig_out, 0,
433 AC_VERB_SET_CONNECT_SEL, val);
437 static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
438 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
439 .name = "IEC958 Playback Source",
440 .info = ad1983_auto_smux_enum_info,
441 .get = ad1983_auto_smux_enum_get,
442 .put = ad1983_auto_smux_enum_put,
445 static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
447 struct ad198x_spec *spec = codec->spec;
448 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
453 num_conns = snd_hda_get_num_conns(codec, dig_out);
454 if (num_conns != 2 && num_conns != 3)
456 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
461 static int patch_ad1983(struct hda_codec *codec)
463 struct ad198x_spec *spec;
466 err = alloc_ad_spec(codec);
471 spec->gen.beep_nid = 0x10;
472 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
473 err = ad198x_parse_auto_config(codec);
476 err = ad1983_add_spdif_mux_ctl(codec);
482 snd_hda_gen_free(codec);
491 static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
492 const struct hda_fixup *fix, int action)
494 struct ad198x_spec *spec = codec->spec;
496 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
497 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
498 spec->eapd_nid = 0x05;
502 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
503 * damage by overloading
505 static void ad1981_fixup_amp_override(struct hda_codec *codec,
506 const struct hda_fixup *fix, int action)
508 if (action == HDA_FIXUP_ACT_PRE_PROBE)
509 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
510 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
511 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
512 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
513 (1 << AC_AMPCAP_MUTE_SHIFT));
517 AD1981_FIXUP_AMP_OVERRIDE,
518 AD1981_FIXUP_HP_EAPD,
521 static const struct hda_fixup ad1981_fixups[] = {
522 [AD1981_FIXUP_AMP_OVERRIDE] = {
523 .type = HDA_FIXUP_FUNC,
524 .v.func = ad1981_fixup_amp_override,
526 [AD1981_FIXUP_HP_EAPD] = {
527 .type = HDA_FIXUP_FUNC,
528 .v.func = ad1981_fixup_hp_eapd,
530 .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
534 static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
535 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
536 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
537 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
538 /* HP nx6320 (reversed SSID, H/W bug) */
539 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
543 static int patch_ad1981(struct hda_codec *codec)
545 struct ad198x_spec *spec;
548 err = alloc_ad_spec(codec);
553 spec->gen.mixer_nid = 0x0e;
554 spec->gen.beep_nid = 0x10;
555 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
557 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
558 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
560 err = ad198x_parse_auto_config(codec);
563 err = ad1983_add_spdif_mux_ctl(codec);
567 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
572 snd_hda_gen_free(codec);
580 * Output pins and routes
582 * Pin Mix Sel DAC (*)
583 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
584 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
585 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
586 * port-D 0x12 (mute/hp) <- 0x29 <- 04
587 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
588 * port-F 0x16 (mute) <- 0x2a <- 06
589 * port-G 0x24 (mute) <- 0x27 <- 05
590 * port-H 0x25 (mute) <- 0x28 <- 0a
591 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
593 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
594 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
596 * Input pins and routes
598 * pin boost mix input # / adc input #
599 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
600 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
601 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
602 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
603 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
604 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
605 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
606 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
610 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
611 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
613 * Inputs of Analog Mix (0x20)
614 * 0:Port-B (front mic)
615 * 1:Port-C/G/H (line-in)
617 * 3:Port-D (line-in/2)
618 * 4:Port-E/G/H (mic-in)
625 * 1:Port-B (front mic-in)
632 * 8:Port-D (line-in/2)
635 * Proposed pin assignments by the datasheet
638 * Port-A front headphone
648 * Port-A front headphone
650 * C rear line-in/surround
658 * D internal speaker (with EAPD)
662 #ifdef ENABLE_AD_STATIC_QUIRKS
663 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
664 struct snd_ctl_elem_info *uinfo)
666 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
667 struct ad198x_spec *spec = codec->spec;
668 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
669 spec->num_channel_mode);
672 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
673 struct snd_ctl_elem_value *ucontrol)
675 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
676 struct ad198x_spec *spec = codec->spec;
677 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
678 spec->num_channel_mode, spec->multiout.max_channels);
681 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
682 struct snd_ctl_elem_value *ucontrol)
684 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
685 struct ad198x_spec *spec = codec->spec;
686 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
687 spec->num_channel_mode,
688 &spec->multiout.max_channels);
689 if (err >= 0 && spec->need_dac_fix)
690 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
693 #endif /* ENABLE_AD_STATIC_QUIRKS */
695 static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
696 struct snd_ctl_elem_info *uinfo)
698 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
699 static const char * const texts[] = {
700 "PCM", "ADC1", "ADC2", "ADC3",
702 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
705 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
708 static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
709 struct snd_ctl_elem_value *ucontrol)
711 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
712 struct ad198x_spec *spec = codec->spec;
714 ucontrol->value.enumerated.item[0] = spec->cur_smux;
718 static int ad1988_auto_smux_enum_put(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;
723 unsigned int val = ucontrol->value.enumerated.item[0];
724 struct nid_path *path;
725 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
727 if (val >= num_conns)
729 if (spec->cur_smux == val)
732 mutex_lock(&codec->control_mutex);
733 codec->cached_write = 1;
734 path = snd_hda_get_path_from_idx(codec,
735 spec->smux_paths[spec->cur_smux]);
737 snd_hda_activate_path(codec, path, false, true);
738 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
740 snd_hda_activate_path(codec, path, true, true);
741 spec->cur_smux = val;
742 codec->cached_write = 0;
743 mutex_unlock(&codec->control_mutex);
744 snd_hda_codec_flush_cache(codec); /* flush the updates */
748 static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
749 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
750 .name = "IEC958 Playback Source",
751 .info = ad1988_auto_smux_enum_info,
752 .get = ad1988_auto_smux_enum_get,
753 .put = ad1988_auto_smux_enum_put,
756 static int ad1988_auto_init(struct hda_codec *codec)
758 struct ad198x_spec *spec = codec->spec;
761 err = snd_hda_gen_init(codec);
764 if (!spec->gen.autocfg.dig_outs)
767 for (i = 0; i < 4; i++) {
768 struct nid_path *path;
769 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
771 snd_hda_activate_path(codec, path, path->active, false);
777 static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
779 struct ad198x_spec *spec = codec->spec;
781 /* we create four static faked paths, since AD codecs have odd
782 * widget connections regarding the SPDIF out source
784 static struct nid_path fake_paths[4] = {
787 .path = { 0x02, 0x1d, 0x1b },
789 .multi = { 0, 0, 0 },
793 .path = { 0x08, 0x0b, 0x1d, 0x1b },
794 .idx = { 0, 0, 1, 0 },
795 .multi = { 0, 1, 0, 0 },
799 .path = { 0x09, 0x0b, 0x1d, 0x1b },
800 .idx = { 0, 1, 1, 0 },
801 .multi = { 0, 1, 0, 0 },
805 .path = { 0x0f, 0x0b, 0x1d, 0x1b },
806 .idx = { 0, 2, 1, 0 },
807 .multi = { 0, 1, 0, 0 },
811 /* SPDIF source mux appears to be present only on AD1988A */
812 if (!spec->gen.autocfg.dig_outs ||
813 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
816 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
817 if (num_conns != 3 && num_conns != 4)
820 for (i = 0; i < num_conns; i++) {
821 struct nid_path *path = snd_array_new(&spec->gen.paths);
824 *path = fake_paths[i];
827 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
830 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
833 codec->patch_ops.init = ad1988_auto_init;
842 AD1988_FIXUP_6STACK_DIG,
845 static const struct hda_fixup ad1988_fixups[] = {
846 [AD1988_FIXUP_6STACK_DIG] = {
847 .type = HDA_FIXUP_PINS,
848 .v.pins = (const struct hda_pintbl[]) {
849 { 0x11, 0x02214130 }, /* front-hp */
850 { 0x12, 0x01014010 }, /* line-out */
851 { 0x14, 0x02a19122 }, /* front-mic */
852 { 0x15, 0x01813021 }, /* line-in */
853 { 0x16, 0x01011012 }, /* line-out */
854 { 0x17, 0x01a19020 }, /* mic */
855 { 0x1b, 0x0145f1f0 }, /* SPDIF */
856 { 0x24, 0x01016011 }, /* line-out */
857 { 0x25, 0x01012013 }, /* line-out */
863 static const struct hda_model_fixup ad1988_fixup_models[] = {
864 { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
868 static int patch_ad1988(struct hda_codec *codec)
870 struct ad198x_spec *spec;
873 err = alloc_ad_spec(codec);
878 spec->gen.mixer_nid = 0x20;
879 spec->gen.mixer_merge_nid = 0x21;
880 spec->gen.beep_nid = 0x10;
881 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
883 snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
884 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
886 err = ad198x_parse_auto_config(codec);
889 err = ad1988_add_spdif_mux_ctl(codec);
893 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
898 snd_hda_gen_free(codec);
906 * port-B - front line/mic-in
907 * port-E - aux in/out
908 * port-F - aux in/out
909 * port-C - rear line/mic-in
910 * port-D - rear line/hp-out
911 * port-A - front line/hp-out
913 * AD1984 = AD1884 + two digital mic-ins
915 * AD1883 / AD1884A / AD1984A / AD1984B
917 * port-B (0x14) - front mic-in
918 * port-E (0x1c) - rear mic-in
919 * port-F (0x16) - CD / ext out
920 * port-C (0x15) - rear line-in
921 * port-D (0x12) - rear line-out
922 * port-A (0x11) - front hp-out
924 * AD1984A = AD1884A + digital-mic
925 * AD1883 = equivalent with AD1984A
926 * AD1984B = AD1984A + extra SPDIF-out
929 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
930 * damage by overloading
932 static void ad1884_fixup_amp_override(struct hda_codec *codec,
933 const struct hda_fixup *fix, int action)
935 if (action == HDA_FIXUP_ACT_PRE_PROBE)
936 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
937 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
938 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
939 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
940 (1 << AC_AMPCAP_MUTE_SHIFT));
943 /* toggle GPIO1 according to the mute state */
944 static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
946 struct hda_codec *codec = private_data;
947 struct ad198x_spec *spec = codec->spec;
950 ad_vmaster_eapd_hook(private_data, enabled);
951 snd_hda_codec_update_cache(codec, 0x01, 0,
952 AC_VERB_SET_GPIO_DATA,
953 enabled ? 0x00 : 0x02);
956 static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
957 const struct hda_fixup *fix, int action)
959 struct ad198x_spec *spec = codec->spec;
960 static const struct hda_verb gpio_init_verbs[] = {
961 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
962 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
963 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
968 case HDA_FIXUP_ACT_PRE_PROBE:
969 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
970 spec->gen.own_eapd_ctl = 1;
971 snd_hda_sequence_write_cache(codec, gpio_init_verbs);
973 case HDA_FIXUP_ACT_PROBE:
974 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
975 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
977 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
982 static void ad1884_fixup_thinkpad(struct hda_codec *codec,
983 const struct hda_fixup *fix, int action)
985 struct ad198x_spec *spec = codec->spec;
987 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
988 spec->gen.keep_eapd_on = 1;
989 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
990 spec->eapd_nid = 0x12;
994 /* set magic COEFs for dmic */
995 static const struct hda_verb ad1884_dmic_init_verbs[] = {
996 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
997 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
1002 AD1884_FIXUP_AMP_OVERRIDE,
1003 AD1884_FIXUP_HP_EAPD,
1004 AD1884_FIXUP_DMIC_COEF,
1005 AD1884_FIXUP_THINKPAD,
1006 AD1884_FIXUP_HP_TOUCHSMART,
1009 static const struct hda_fixup ad1884_fixups[] = {
1010 [AD1884_FIXUP_AMP_OVERRIDE] = {
1011 .type = HDA_FIXUP_FUNC,
1012 .v.func = ad1884_fixup_amp_override,
1014 [AD1884_FIXUP_HP_EAPD] = {
1015 .type = HDA_FIXUP_FUNC,
1016 .v.func = ad1884_fixup_hp_eapd,
1018 .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
1020 [AD1884_FIXUP_DMIC_COEF] = {
1021 .type = HDA_FIXUP_VERBS,
1022 .v.verbs = ad1884_dmic_init_verbs,
1024 [AD1884_FIXUP_THINKPAD] = {
1025 .type = HDA_FIXUP_FUNC,
1026 .v.func = ad1884_fixup_thinkpad,
1028 .chain_id = AD1884_FIXUP_DMIC_COEF,
1030 [AD1884_FIXUP_HP_TOUCHSMART] = {
1031 .type = HDA_FIXUP_VERBS,
1032 .v.verbs = ad1884_dmic_init_verbs,
1034 .chain_id = AD1884_FIXUP_HP_EAPD,
1038 static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
1039 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
1040 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
1041 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
1046 static int patch_ad1884(struct hda_codec *codec)
1048 struct ad198x_spec *spec;
1051 err = alloc_ad_spec(codec);
1056 spec->gen.mixer_nid = 0x20;
1057 spec->gen.beep_nid = 0x10;
1058 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1060 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
1061 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1063 err = ad198x_parse_auto_config(codec);
1066 err = ad1983_add_spdif_mux_ctl(codec);
1070 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1075 snd_hda_gen_free(codec);
1082 * port-A - front hp-out
1083 * port-B - front mic-in
1084 * port-C - rear line-in, shared surr-out (3stack)
1085 * port-D - rear line-out
1086 * port-E - rear mic-in, shared clfe-out (3stack)
1087 * port-F - rear surr-out (6stack)
1088 * port-G - rear clfe-out (6stack)
1091 static int patch_ad1882(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);
1105 err = ad198x_parse_auto_config(codec);
1108 err = ad1988_add_spdif_mux_ctl(codec);
1114 snd_hda_gen_free(codec);
1122 static const struct hda_codec_preset snd_hda_preset_analog[] = {
1123 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
1124 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
1125 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
1126 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
1127 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
1128 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
1129 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
1130 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
1131 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
1132 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
1133 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
1134 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
1135 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
1136 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
1137 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
1141 MODULE_ALIAS("snd-hda-codec-id:11d4*");
1143 MODULE_LICENSE("GPL");
1144 MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1146 static struct hda_codec_preset_list analog_list = {
1147 .preset = snd_hda_preset_analog,
1148 .owner = THIS_MODULE,
1151 static int __init patch_analog_init(void)
1153 return snd_hda_add_codec_preset(&analog_list);
1156 static void __exit patch_analog_exit(void)
1158 snd_hda_delete_codec_preset(&analog_list);
1161 module_init(patch_analog_init)
1162 module_exit(patch_analog_exit)