1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
6 * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de>
9 #include <linux/init.h>
10 #include <linux/slab.h>
11 #include <linux/module.h>
13 #include <sound/core.h>
14 #include <sound/hda_codec.h>
15 #include "hda_local.h"
16 #include "hda_auto_parser.h"
19 #include "hda_generic.h"
23 struct hda_gen_spec gen
;
27 unsigned int cur_smux
;
30 unsigned int beep_amp
; /* beep amp value, set via set_beep_amp() */
35 #ifdef CONFIG_SND_HDA_INPUT_BEEP
36 /* additional beep mixers; the actual parameters are overwritten at build */
37 static const struct snd_kcontrol_new ad_beep_mixer
[] = {
38 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT
),
39 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT
),
43 #define set_beep_amp(spec, nid, idx, dir) \
44 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
46 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
49 #ifdef CONFIG_SND_HDA_INPUT_BEEP
50 static int create_beep_ctls(struct hda_codec
*codec
)
52 struct ad198x_spec
*spec
= codec
->spec
;
53 const struct snd_kcontrol_new
*knew
;
58 for (knew
= ad_beep_mixer
; knew
->name
; knew
++) {
60 struct snd_kcontrol
*kctl
;
61 kctl
= snd_ctl_new1(knew
, codec
);
64 kctl
->private_value
= spec
->beep_amp
;
65 err
= snd_hda_ctl_add(codec
, 0, kctl
);
72 #define create_beep_ctls(codec) 0
76 static void ad198x_power_eapd_write(struct hda_codec
*codec
, hda_nid_t front
,
79 if (snd_hda_query_pin_caps(codec
, front
) & AC_PINCAP_EAPD
)
80 snd_hda_codec_write(codec
, front
, 0, AC_VERB_SET_EAPD_BTLENABLE
,
81 !codec
->inv_eapd
? 0x00 : 0x02);
82 if (snd_hda_query_pin_caps(codec
, hp
) & AC_PINCAP_EAPD
)
83 snd_hda_codec_write(codec
, hp
, 0, AC_VERB_SET_EAPD_BTLENABLE
,
84 !codec
->inv_eapd
? 0x00 : 0x02);
87 static void ad198x_power_eapd(struct hda_codec
*codec
)
89 /* We currently only handle front, HP */
90 switch (codec
->core
.vendor_id
) {
103 ad198x_power_eapd_write(codec
, 0x12, 0x11);
107 ad198x_power_eapd_write(codec
, 0x05, 0x06);
110 ad198x_power_eapd_write(codec
, 0x1b, 0x1a);
115 static void ad198x_shutup(struct hda_codec
*codec
)
117 snd_hda_shutup_pins(codec
);
118 ad198x_power_eapd(codec
);
122 static int ad198x_suspend(struct hda_codec
*codec
)
124 ad198x_shutup(codec
);
129 /* follow EAPD via vmaster hook */
130 static void ad_vmaster_eapd_hook(void *private_data
, int enabled
)
132 struct hda_codec
*codec
= private_data
;
133 struct ad198x_spec
*spec
= codec
->spec
;
139 snd_hda_codec_write_cache(codec
, spec
->eapd_nid
, 0,
140 AC_VERB_SET_EAPD_BTLENABLE
,
141 enabled
? 0x02 : 0x00);
145 * Automatic parse of I/O pins from the BIOS configuration
148 static int ad198x_auto_build_controls(struct hda_codec
*codec
)
152 err
= snd_hda_gen_build_controls(codec
);
155 err
= create_beep_ctls(codec
);
161 static const struct hda_codec_ops ad198x_auto_patch_ops
= {
162 .build_controls
= ad198x_auto_build_controls
,
163 .build_pcms
= snd_hda_gen_build_pcms
,
164 .init
= snd_hda_gen_init
,
165 .free
= snd_hda_gen_free
,
166 .unsol_event
= snd_hda_jack_unsol_event
,
168 .check_power_status
= snd_hda_gen_check_power_status
,
169 .suspend
= ad198x_suspend
,
171 .reboot_notify
= ad198x_shutup
,
175 static int ad198x_parse_auto_config(struct hda_codec
*codec
, bool indep_hp
)
177 struct ad198x_spec
*spec
= codec
->spec
;
178 struct auto_pin_cfg
*cfg
= &spec
->gen
.autocfg
;
181 codec
->spdif_status_reset
= 1;
182 codec
->no_trigger_sense
= 1;
183 codec
->no_sticky_stream
= 1;
185 spec
->gen
.indep_hp
= indep_hp
;
186 if (!spec
->gen
.add_stereo_mix_input
)
187 spec
->gen
.add_stereo_mix_input
= HDA_HINT_STEREO_MIX_AUTO
;
189 err
= snd_hda_parse_pin_defcfg(codec
, cfg
, NULL
, 0);
192 err
= snd_hda_gen_parse_auto_config(codec
, cfg
);
203 static int alloc_ad_spec(struct hda_codec
*codec
)
205 struct ad198x_spec
*spec
;
207 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
211 snd_hda_gen_spec_init(&spec
->gen
);
212 codec
->patch_ops
= ad198x_auto_patch_ops
;
217 * AD1986A fixup codes
220 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
221 static void ad_fixup_inv_jack_detect(struct hda_codec
*codec
,
222 const struct hda_fixup
*fix
, int action
)
224 struct ad198x_spec
*spec
= codec
->spec
;
226 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
227 codec
->inv_jack_detect
= 1;
228 spec
->gen
.keep_eapd_on
= 1;
229 spec
->gen
.vmaster_mute
.hook
= ad_vmaster_eapd_hook
;
230 spec
->eapd_nid
= 0x1b;
234 /* Toshiba Satellite L40 implements EAPD in a standard way unlike others */
235 static void ad1986a_fixup_eapd(struct hda_codec
*codec
,
236 const struct hda_fixup
*fix
, int action
)
238 struct ad198x_spec
*spec
= codec
->spec
;
240 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
242 spec
->gen
.keep_eapd_on
= 1;
243 spec
->eapd_nid
= 0x1b;
247 /* enable stereo-mix input for avoiding regression on KDE (bko#88251) */
248 static void ad1986a_fixup_eapd_mix_in(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
) {
254 ad1986a_fixup_eapd(codec
, fix
, action
);
255 spec
->gen
.add_stereo_mix_input
= HDA_HINT_STEREO_MIX_ENABLE
;
260 AD1986A_FIXUP_INV_JACK_DETECT
,
262 AD1986A_FIXUP_SAMSUNG
,
263 AD1986A_FIXUP_3STACK
,
264 AD1986A_FIXUP_LAPTOP
,
265 AD1986A_FIXUP_LAPTOP_IMIC
,
267 AD1986A_FIXUP_EAPD_MIX_IN
,
268 AD1986A_FIXUP_EASYNOTE
,
271 static const struct hda_fixup ad1986a_fixups
[] = {
272 [AD1986A_FIXUP_INV_JACK_DETECT
] = {
273 .type
= HDA_FIXUP_FUNC
,
274 .v
.func
= ad_fixup_inv_jack_detect
,
276 [AD1986A_FIXUP_ULTRA
] = {
277 .type
= HDA_FIXUP_PINS
,
278 .v
.pins
= (const struct hda_pintbl
[]) {
279 { 0x1b, 0x90170110 }, /* speaker */
280 { 0x1d, 0x90a7013e }, /* int mic */
284 [AD1986A_FIXUP_SAMSUNG
] = {
285 .type
= HDA_FIXUP_PINS
,
286 .v
.pins
= (const struct hda_pintbl
[]) {
287 { 0x1b, 0x90170110 }, /* speaker */
288 { 0x1d, 0x90a7013e }, /* int mic */
289 { 0x20, 0x411111f0 }, /* N/A */
290 { 0x24, 0x411111f0 }, /* N/A */
294 [AD1986A_FIXUP_3STACK
] = {
295 .type
= HDA_FIXUP_PINS
,
296 .v
.pins
= (const struct hda_pintbl
[]) {
297 { 0x1a, 0x02214021 }, /* headphone */
298 { 0x1b, 0x01014011 }, /* front */
299 { 0x1c, 0x01813030 }, /* line-in */
300 { 0x1d, 0x01a19020 }, /* rear mic */
301 { 0x1e, 0x411111f0 }, /* N/A */
302 { 0x1f, 0x02a190f0 }, /* mic */
303 { 0x20, 0x411111f0 }, /* N/A */
307 [AD1986A_FIXUP_LAPTOP
] = {
308 .type
= HDA_FIXUP_PINS
,
309 .v
.pins
= (const struct hda_pintbl
[]) {
310 { 0x1a, 0x02214021 }, /* headphone */
311 { 0x1b, 0x90170110 }, /* speaker */
312 { 0x1c, 0x411111f0 }, /* N/A */
313 { 0x1d, 0x411111f0 }, /* N/A */
314 { 0x1e, 0x411111f0 }, /* N/A */
315 { 0x1f, 0x02a191f0 }, /* mic */
316 { 0x20, 0x411111f0 }, /* N/A */
320 [AD1986A_FIXUP_LAPTOP_IMIC
] = {
321 .type
= HDA_FIXUP_PINS
,
322 .v
.pins
= (const struct hda_pintbl
[]) {
323 { 0x1d, 0x90a7013e }, /* int mic */
327 .chain_id
= AD1986A_FIXUP_LAPTOP
,
329 [AD1986A_FIXUP_EAPD
] = {
330 .type
= HDA_FIXUP_FUNC
,
331 .v
.func
= ad1986a_fixup_eapd
,
333 [AD1986A_FIXUP_EAPD_MIX_IN
] = {
334 .type
= HDA_FIXUP_FUNC
,
335 .v
.func
= ad1986a_fixup_eapd_mix_in
,
337 [AD1986A_FIXUP_EASYNOTE
] = {
338 .type
= HDA_FIXUP_PINS
,
339 .v
.pins
= (const struct hda_pintbl
[]) {
340 { 0x1a, 0x0421402f }, /* headphone */
341 { 0x1b, 0x90170110 }, /* speaker */
342 { 0x1c, 0x411111f0 }, /* N/A */
343 { 0x1d, 0x90a70130 }, /* int mic */
344 { 0x1e, 0x411111f0 }, /* N/A */
345 { 0x1f, 0x04a19040 }, /* mic */
346 { 0x20, 0x411111f0 }, /* N/A */
347 { 0x21, 0x411111f0 }, /* N/A */
348 { 0x22, 0x411111f0 }, /* N/A */
349 { 0x23, 0x411111f0 }, /* N/A */
350 { 0x24, 0x411111f0 }, /* N/A */
351 { 0x25, 0x411111f0 }, /* N/A */
355 .chain_id
= AD1986A_FIXUP_EAPD_MIX_IN
,
359 static const struct snd_pci_quirk ad1986a_fixup_tbl
[] = {
360 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC
),
361 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9V", AD1986A_FIXUP_LAPTOP_IMIC
),
362 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS Z99He", AD1986A_FIXUP_EAPD
),
363 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8JN", AD1986A_FIXUP_EAPD
),
364 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK
),
365 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK
),
366 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK
),
367 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40", AD1986A_FIXUP_EAPD
),
368 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP
),
369 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG
),
370 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA
),
371 SND_PCI_QUIRK(0x1631, 0xc022, "PackardBell EasyNote MX65", AD1986A_FIXUP_EASYNOTE
),
372 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT
),
373 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK
),
374 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK
),
378 static const struct hda_model_fixup ad1986a_fixup_models
[] = {
379 { .id
= AD1986A_FIXUP_3STACK
, .name
= "3stack" },
380 { .id
= AD1986A_FIXUP_LAPTOP
, .name
= "laptop" },
381 { .id
= AD1986A_FIXUP_LAPTOP_IMIC
, .name
= "laptop-imic" },
382 { .id
= AD1986A_FIXUP_LAPTOP_IMIC
, .name
= "laptop-eapd" }, /* alias */
383 { .id
= AD1986A_FIXUP_EAPD
, .name
= "eapd" },
389 static int patch_ad1986a(struct hda_codec
*codec
)
392 struct ad198x_spec
*spec
;
393 static const hda_nid_t preferred_pairs
[] = {
402 err
= alloc_ad_spec(codec
);
407 /* AD1986A has the inverted EAPD implementation */
410 spec
->gen
.mixer_nid
= 0x07;
411 spec
->gen
.beep_nid
= 0x19;
412 set_beep_amp(spec
, 0x18, 0, HDA_OUTPUT
);
414 /* AD1986A has a hardware problem that it can't share a stream
415 * with multiple output pins. The copy of front to surrounds
416 * causes noisy or silent outputs at a certain timing, e.g.
417 * changing the volume.
418 * So, let's disable the shared stream.
420 spec
->gen
.multiout
.no_share_stream
= 1;
421 /* give fixed DAC/pin pairs */
422 spec
->gen
.preferred_dacs
= preferred_pairs
;
424 /* AD1986A can't manage the dynamic pin on/off smoothly */
425 spec
->gen
.auto_mute_via_amp
= 1;
427 snd_hda_pick_fixup(codec
, ad1986a_fixup_models
, ad1986a_fixup_tbl
,
429 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
431 err
= ad198x_parse_auto_config(codec
, false);
433 snd_hda_gen_free(codec
);
437 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
448 * SPDIF mux control for AD1983 auto-parser
450 static int ad1983_auto_smux_enum_info(struct snd_kcontrol
*kcontrol
,
451 struct snd_ctl_elem_info
*uinfo
)
453 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
454 struct ad198x_spec
*spec
= codec
->spec
;
455 static const char * const texts2
[] = { "PCM", "ADC" };
456 static const char * const texts3
[] = { "PCM", "ADC1", "ADC2" };
457 int num_conns
= spec
->num_smux_conns
;
460 return snd_hda_enum_helper_info(kcontrol
, uinfo
, 2, texts2
);
461 else if (num_conns
== 3)
462 return snd_hda_enum_helper_info(kcontrol
, uinfo
, 3, texts3
);
467 static int ad1983_auto_smux_enum_get(struct snd_kcontrol
*kcontrol
,
468 struct snd_ctl_elem_value
*ucontrol
)
470 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
471 struct ad198x_spec
*spec
= codec
->spec
;
473 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_smux
;
477 static int ad1983_auto_smux_enum_put(struct snd_kcontrol
*kcontrol
,
478 struct snd_ctl_elem_value
*ucontrol
)
480 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
481 struct ad198x_spec
*spec
= codec
->spec
;
482 unsigned int val
= ucontrol
->value
.enumerated
.item
[0];
483 hda_nid_t dig_out
= spec
->gen
.multiout
.dig_out_nid
;
484 int num_conns
= spec
->num_smux_conns
;
486 if (val
>= num_conns
)
488 if (spec
->cur_smux
== val
)
490 spec
->cur_smux
= val
;
491 snd_hda_codec_write_cache(codec
, dig_out
, 0,
492 AC_VERB_SET_CONNECT_SEL
, val
);
496 static const struct snd_kcontrol_new ad1983_auto_smux_mixer
= {
497 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
498 .name
= "IEC958 Playback Source",
499 .info
= ad1983_auto_smux_enum_info
,
500 .get
= ad1983_auto_smux_enum_get
,
501 .put
= ad1983_auto_smux_enum_put
,
504 static int ad1983_add_spdif_mux_ctl(struct hda_codec
*codec
)
506 struct ad198x_spec
*spec
= codec
->spec
;
507 hda_nid_t dig_out
= spec
->gen
.multiout
.dig_out_nid
;
512 num_conns
= snd_hda_get_num_conns(codec
, dig_out
);
513 if (num_conns
!= 2 && num_conns
!= 3)
515 spec
->num_smux_conns
= num_conns
;
516 if (!snd_hda_gen_add_kctl(&spec
->gen
, NULL
, &ad1983_auto_smux_mixer
))
521 static int patch_ad1983(struct hda_codec
*codec
)
523 static const hda_nid_t conn_0c
[] = { 0x08 };
524 static const hda_nid_t conn_0d
[] = { 0x09 };
525 struct ad198x_spec
*spec
;
528 err
= alloc_ad_spec(codec
);
533 spec
->gen
.mixer_nid
= 0x0e;
534 spec
->gen
.beep_nid
= 0x10;
535 set_beep_amp(spec
, 0x10, 0, HDA_OUTPUT
);
537 /* limit the loopback routes not to confuse the parser */
538 snd_hda_override_conn_list(codec
, 0x0c, ARRAY_SIZE(conn_0c
), conn_0c
);
539 snd_hda_override_conn_list(codec
, 0x0d, ARRAY_SIZE(conn_0d
), conn_0d
);
541 err
= ad198x_parse_auto_config(codec
, false);
544 err
= ad1983_add_spdif_mux_ctl(codec
);
550 snd_hda_gen_free(codec
);
559 static void ad1981_fixup_hp_eapd(struct hda_codec
*codec
,
560 const struct hda_fixup
*fix
, int action
)
562 struct ad198x_spec
*spec
= codec
->spec
;
564 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
565 spec
->gen
.vmaster_mute
.hook
= ad_vmaster_eapd_hook
;
566 spec
->eapd_nid
= 0x05;
570 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
571 * damage by overloading
573 static void ad1981_fixup_amp_override(struct hda_codec
*codec
,
574 const struct hda_fixup
*fix
, int action
)
576 if (action
== HDA_FIXUP_ACT_PRE_PROBE
)
577 snd_hda_override_amp_caps(codec
, 0x11, HDA_INPUT
,
578 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
579 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
580 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
581 (1 << AC_AMPCAP_MUTE_SHIFT
));
585 AD1981_FIXUP_AMP_OVERRIDE
,
586 AD1981_FIXUP_HP_EAPD
,
589 static const struct hda_fixup ad1981_fixups
[] = {
590 [AD1981_FIXUP_AMP_OVERRIDE
] = {
591 .type
= HDA_FIXUP_FUNC
,
592 .v
.func
= ad1981_fixup_amp_override
,
594 [AD1981_FIXUP_HP_EAPD
] = {
595 .type
= HDA_FIXUP_FUNC
,
596 .v
.func
= ad1981_fixup_hp_eapd
,
598 .chain_id
= AD1981_FIXUP_AMP_OVERRIDE
,
602 static const struct snd_pci_quirk ad1981_fixup_tbl
[] = {
603 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE
),
604 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD
),
605 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE
),
606 /* HP nx6320 (reversed SSID, H/W bug) */
607 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD
),
611 static int patch_ad1981(struct hda_codec
*codec
)
613 struct ad198x_spec
*spec
;
616 err
= alloc_ad_spec(codec
);
621 spec
->gen
.mixer_nid
= 0x0e;
622 spec
->gen
.beep_nid
= 0x10;
623 set_beep_amp(spec
, 0x0d, 0, HDA_OUTPUT
);
625 snd_hda_pick_fixup(codec
, NULL
, ad1981_fixup_tbl
, ad1981_fixups
);
626 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
628 err
= ad198x_parse_auto_config(codec
, false);
631 err
= ad1983_add_spdif_mux_ctl(codec
);
635 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
640 snd_hda_gen_free(codec
);
648 * Output pins and routes
650 * Pin Mix Sel DAC (*)
651 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
652 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
653 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
654 * port-D 0x12 (mute/hp) <- 0x29 <- 04
655 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
656 * port-F 0x16 (mute) <- 0x2a <- 06
657 * port-G 0x24 (mute) <- 0x27 <- 05
658 * port-H 0x25 (mute) <- 0x28 <- 0a
659 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
661 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
662 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
664 * Input pins and routes
666 * pin boost mix input # / adc input #
667 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
668 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
669 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
670 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
671 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
672 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
673 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
674 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
678 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
679 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
681 * Inputs of Analog Mix (0x20)
682 * 0:Port-B (front mic)
683 * 1:Port-C/G/H (line-in)
685 * 3:Port-D (line-in/2)
686 * 4:Port-E/G/H (mic-in)
693 * 1:Port-B (front mic-in)
700 * 8:Port-D (line-in/2)
703 * Proposed pin assignments by the datasheet
706 * Port-A front headphone
716 * Port-A front headphone
718 * C rear line-in/surround
726 * D internal speaker (with EAPD)
730 static int ad1988_auto_smux_enum_info(struct snd_kcontrol
*kcontrol
,
731 struct snd_ctl_elem_info
*uinfo
)
733 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
734 struct ad198x_spec
*spec
= codec
->spec
;
735 static const char * const texts
[] = {
736 "PCM", "ADC1", "ADC2", "ADC3",
738 int num_conns
= spec
->num_smux_conns
;
742 return snd_hda_enum_helper_info(kcontrol
, uinfo
, num_conns
, texts
);
745 static int ad1988_auto_smux_enum_get(struct snd_kcontrol
*kcontrol
,
746 struct snd_ctl_elem_value
*ucontrol
)
748 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
749 struct ad198x_spec
*spec
= codec
->spec
;
751 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_smux
;
755 static int ad1988_auto_smux_enum_put(struct snd_kcontrol
*kcontrol
,
756 struct snd_ctl_elem_value
*ucontrol
)
758 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
759 struct ad198x_spec
*spec
= codec
->spec
;
760 unsigned int val
= ucontrol
->value
.enumerated
.item
[0];
761 struct nid_path
*path
;
762 int num_conns
= spec
->num_smux_conns
;
764 if (val
>= num_conns
)
766 if (spec
->cur_smux
== val
)
769 mutex_lock(&codec
->control_mutex
);
770 path
= snd_hda_get_path_from_idx(codec
,
771 spec
->smux_paths
[spec
->cur_smux
]);
773 snd_hda_activate_path(codec
, path
, false, true);
774 path
= snd_hda_get_path_from_idx(codec
, spec
->smux_paths
[val
]);
776 snd_hda_activate_path(codec
, path
, true, true);
777 spec
->cur_smux
= val
;
778 mutex_unlock(&codec
->control_mutex
);
782 static const struct snd_kcontrol_new ad1988_auto_smux_mixer
= {
783 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
784 .name
= "IEC958 Playback Source",
785 .info
= ad1988_auto_smux_enum_info
,
786 .get
= ad1988_auto_smux_enum_get
,
787 .put
= ad1988_auto_smux_enum_put
,
790 static int ad1988_auto_init(struct hda_codec
*codec
)
792 struct ad198x_spec
*spec
= codec
->spec
;
795 err
= snd_hda_gen_init(codec
);
798 if (!spec
->gen
.autocfg
.dig_outs
)
801 for (i
= 0; i
< 4; i
++) {
802 struct nid_path
*path
;
803 path
= snd_hda_get_path_from_idx(codec
, spec
->smux_paths
[i
]);
805 snd_hda_activate_path(codec
, path
, path
->active
, false);
811 static int ad1988_add_spdif_mux_ctl(struct hda_codec
*codec
)
813 struct ad198x_spec
*spec
= codec
->spec
;
815 /* we create four static faked paths, since AD codecs have odd
816 * widget connections regarding the SPDIF out source
818 static const struct nid_path fake_paths
[4] = {
821 .path
= { 0x02, 0x1d, 0x1b },
823 .multi
= { 0, 0, 0 },
827 .path
= { 0x08, 0x0b, 0x1d, 0x1b },
828 .idx
= { 0, 0, 1, 0 },
829 .multi
= { 0, 1, 0, 0 },
833 .path
= { 0x09, 0x0b, 0x1d, 0x1b },
834 .idx
= { 0, 1, 1, 0 },
835 .multi
= { 0, 1, 0, 0 },
839 .path
= { 0x0f, 0x0b, 0x1d, 0x1b },
840 .idx
= { 0, 2, 1, 0 },
841 .multi
= { 0, 1, 0, 0 },
845 /* SPDIF source mux appears to be present only on AD1988A */
846 if (!spec
->gen
.autocfg
.dig_outs
||
847 get_wcaps_type(get_wcaps(codec
, 0x1d)) != AC_WID_AUD_MIX
)
850 num_conns
= snd_hda_get_num_conns(codec
, 0x0b) + 1;
851 if (num_conns
!= 3 && num_conns
!= 4)
853 spec
->num_smux_conns
= num_conns
;
855 for (i
= 0; i
< num_conns
; i
++) {
856 struct nid_path
*path
= snd_array_new(&spec
->gen
.paths
);
859 *path
= fake_paths
[i
];
862 spec
->smux_paths
[i
] = snd_hda_get_path_idx(codec
, path
);
865 if (!snd_hda_gen_add_kctl(&spec
->gen
, NULL
, &ad1988_auto_smux_mixer
))
868 codec
->patch_ops
.init
= ad1988_auto_init
;
877 AD1988_FIXUP_6STACK_DIG
,
880 static const struct hda_fixup ad1988_fixups
[] = {
881 [AD1988_FIXUP_6STACK_DIG
] = {
882 .type
= HDA_FIXUP_PINS
,
883 .v
.pins
= (const struct hda_pintbl
[]) {
884 { 0x11, 0x02214130 }, /* front-hp */
885 { 0x12, 0x01014010 }, /* line-out */
886 { 0x14, 0x02a19122 }, /* front-mic */
887 { 0x15, 0x01813021 }, /* line-in */
888 { 0x16, 0x01011012 }, /* line-out */
889 { 0x17, 0x01a19020 }, /* mic */
890 { 0x1b, 0x0145f1f0 }, /* SPDIF */
891 { 0x24, 0x01016011 }, /* line-out */
892 { 0x25, 0x01012013 }, /* line-out */
898 static const struct hda_model_fixup ad1988_fixup_models
[] = {
899 { .id
= AD1988_FIXUP_6STACK_DIG
, .name
= "6stack-dig" },
903 static int patch_ad1988(struct hda_codec
*codec
)
905 struct ad198x_spec
*spec
;
908 err
= alloc_ad_spec(codec
);
913 spec
->gen
.mixer_nid
= 0x20;
914 spec
->gen
.mixer_merge_nid
= 0x21;
915 spec
->gen
.beep_nid
= 0x10;
916 set_beep_amp(spec
, 0x10, 0, HDA_OUTPUT
);
918 snd_hda_pick_fixup(codec
, ad1988_fixup_models
, NULL
, ad1988_fixups
);
919 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
921 err
= ad198x_parse_auto_config(codec
, true);
924 err
= ad1988_add_spdif_mux_ctl(codec
);
928 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
933 snd_hda_gen_free(codec
);
941 * port-B - front line/mic-in
942 * port-E - aux in/out
943 * port-F - aux in/out
944 * port-C - rear line/mic-in
945 * port-D - rear line/hp-out
946 * port-A - front line/hp-out
948 * AD1984 = AD1884 + two digital mic-ins
950 * AD1883 / AD1884A / AD1984A / AD1984B
952 * port-B (0x14) - front mic-in
953 * port-E (0x1c) - rear mic-in
954 * port-F (0x16) - CD / ext out
955 * port-C (0x15) - rear line-in
956 * port-D (0x12) - rear line-out
957 * port-A (0x11) - front hp-out
959 * AD1984A = AD1884A + digital-mic
960 * AD1883 = equivalent with AD1984A
961 * AD1984B = AD1984A + extra SPDIF-out
964 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
965 * damage by overloading
967 static void ad1884_fixup_amp_override(struct hda_codec
*codec
,
968 const struct hda_fixup
*fix
, int action
)
970 if (action
== HDA_FIXUP_ACT_PRE_PROBE
)
971 snd_hda_override_amp_caps(codec
, 0x20, HDA_INPUT
,
972 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
973 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
974 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
975 (1 << AC_AMPCAP_MUTE_SHIFT
));
978 /* toggle GPIO1 according to the mute state */
979 static void ad1884_vmaster_hp_gpio_hook(void *private_data
, int enabled
)
981 struct hda_codec
*codec
= private_data
;
982 struct ad198x_spec
*spec
= codec
->spec
;
985 ad_vmaster_eapd_hook(private_data
, enabled
);
986 snd_hda_codec_write_cache(codec
, 0x01, 0,
987 AC_VERB_SET_GPIO_DATA
,
988 enabled
? 0x00 : 0x02);
991 static void ad1884_fixup_hp_eapd(struct hda_codec
*codec
,
992 const struct hda_fixup
*fix
, int action
)
994 struct ad198x_spec
*spec
= codec
->spec
;
997 case HDA_FIXUP_ACT_PRE_PROBE
:
998 spec
->gen
.vmaster_mute
.hook
= ad1884_vmaster_hp_gpio_hook
;
999 spec
->gen
.own_eapd_ctl
= 1;
1000 snd_hda_codec_write_cache(codec
, 0x01, 0,
1001 AC_VERB_SET_GPIO_MASK
, 0x02);
1002 snd_hda_codec_write_cache(codec
, 0x01, 0,
1003 AC_VERB_SET_GPIO_DIRECTION
, 0x02);
1004 snd_hda_codec_write_cache(codec
, 0x01, 0,
1005 AC_VERB_SET_GPIO_DATA
, 0x02);
1007 case HDA_FIXUP_ACT_PROBE
:
1008 if (spec
->gen
.autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
)
1009 spec
->eapd_nid
= spec
->gen
.autocfg
.line_out_pins
[0];
1011 spec
->eapd_nid
= spec
->gen
.autocfg
.speaker_pins
[0];
1016 static void ad1884_fixup_thinkpad(struct hda_codec
*codec
,
1017 const struct hda_fixup
*fix
, int action
)
1019 struct ad198x_spec
*spec
= codec
->spec
;
1021 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
1022 spec
->gen
.keep_eapd_on
= 1;
1023 spec
->gen
.vmaster_mute
.hook
= ad_vmaster_eapd_hook
;
1024 spec
->eapd_nid
= 0x12;
1025 /* Analog PC Beeper - allow firmware/ACPI beeps */
1026 spec
->beep_amp
= HDA_COMPOSE_AMP_VAL(0x20, 3, 3, HDA_INPUT
);
1027 spec
->gen
.beep_nid
= 0; /* no digital beep */
1031 /* set magic COEFs for dmic */
1032 static const struct hda_verb ad1884_dmic_init_verbs
[] = {
1033 {0x01, AC_VERB_SET_COEF_INDEX
, 0x13f7},
1034 {0x01, AC_VERB_SET_PROC_COEF
, 0x08},
1039 AD1884_FIXUP_AMP_OVERRIDE
,
1040 AD1884_FIXUP_HP_EAPD
,
1041 AD1884_FIXUP_DMIC_COEF
,
1042 AD1884_FIXUP_THINKPAD
,
1043 AD1884_FIXUP_HP_TOUCHSMART
,
1046 static const struct hda_fixup ad1884_fixups
[] = {
1047 [AD1884_FIXUP_AMP_OVERRIDE
] = {
1048 .type
= HDA_FIXUP_FUNC
,
1049 .v
.func
= ad1884_fixup_amp_override
,
1051 [AD1884_FIXUP_HP_EAPD
] = {
1052 .type
= HDA_FIXUP_FUNC
,
1053 .v
.func
= ad1884_fixup_hp_eapd
,
1055 .chain_id
= AD1884_FIXUP_AMP_OVERRIDE
,
1057 [AD1884_FIXUP_DMIC_COEF
] = {
1058 .type
= HDA_FIXUP_VERBS
,
1059 .v
.verbs
= ad1884_dmic_init_verbs
,
1061 [AD1884_FIXUP_THINKPAD
] = {
1062 .type
= HDA_FIXUP_FUNC
,
1063 .v
.func
= ad1884_fixup_thinkpad
,
1065 .chain_id
= AD1884_FIXUP_DMIC_COEF
,
1067 [AD1884_FIXUP_HP_TOUCHSMART
] = {
1068 .type
= HDA_FIXUP_VERBS
,
1069 .v
.verbs
= ad1884_dmic_init_verbs
,
1071 .chain_id
= AD1884_FIXUP_HP_EAPD
,
1075 static const struct snd_pci_quirk ad1884_fixup_tbl
[] = {
1076 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART
),
1077 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD
),
1078 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD
),
1083 static int patch_ad1884(struct hda_codec
*codec
)
1085 struct ad198x_spec
*spec
;
1088 err
= alloc_ad_spec(codec
);
1093 spec
->gen
.mixer_nid
= 0x20;
1094 spec
->gen
.mixer_merge_nid
= 0x21;
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_device_id snd_hda_id_analog
[] = {
1161 HDA_CODEC_ENTRY(0x11d4184a, "AD1884A", patch_ad1884
),
1162 HDA_CODEC_ENTRY(0x11d41882, "AD1882", patch_ad1882
),
1163 HDA_CODEC_ENTRY(0x11d41883, "AD1883", patch_ad1884
),
1164 HDA_CODEC_ENTRY(0x11d41884, "AD1884", patch_ad1884
),
1165 HDA_CODEC_ENTRY(0x11d4194a, "AD1984A", patch_ad1884
),
1166 HDA_CODEC_ENTRY(0x11d4194b, "AD1984B", patch_ad1884
),
1167 HDA_CODEC_ENTRY(0x11d41981, "AD1981", patch_ad1981
),
1168 HDA_CODEC_ENTRY(0x11d41983, "AD1983", patch_ad1983
),
1169 HDA_CODEC_ENTRY(0x11d41984, "AD1984", patch_ad1884
),
1170 HDA_CODEC_ENTRY(0x11d41986, "AD1986A", patch_ad1986a
),
1171 HDA_CODEC_ENTRY(0x11d41988, "AD1988", patch_ad1988
),
1172 HDA_CODEC_ENTRY(0x11d4198b, "AD1988B", patch_ad1988
),
1173 HDA_CODEC_ENTRY(0x11d4882a, "AD1882A", patch_ad1882
),
1174 HDA_CODEC_ENTRY(0x11d4989a, "AD1989A", patch_ad1988
),
1175 HDA_CODEC_ENTRY(0x11d4989b, "AD1989B", patch_ad1988
),
1178 MODULE_DEVICE_TABLE(hdaudio
, snd_hda_id_analog
);
1180 MODULE_LICENSE("GPL");
1181 MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1183 static struct hda_codec_driver analog_driver
= {
1184 .id
= snd_hda_id_analog
,
1187 module_hda_codec_driver(analog_driver
);