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
75 static void ad198x_power_eapd_write(struct hda_codec
*codec
, hda_nid_t front
,
78 if (snd_hda_query_pin_caps(codec
, front
) & AC_PINCAP_EAPD
)
79 snd_hda_codec_write(codec
, front
, 0, AC_VERB_SET_EAPD_BTLENABLE
,
80 !codec
->inv_eapd
? 0x00 : 0x02);
81 if (snd_hda_query_pin_caps(codec
, hp
) & AC_PINCAP_EAPD
)
82 snd_hda_codec_write(codec
, hp
, 0, AC_VERB_SET_EAPD_BTLENABLE
,
83 !codec
->inv_eapd
? 0x00 : 0x02);
86 static void ad198x_power_eapd(struct hda_codec
*codec
)
88 /* We currently only handle front, HP */
89 switch (codec
->core
.vendor_id
) {
102 ad198x_power_eapd_write(codec
, 0x12, 0x11);
106 ad198x_power_eapd_write(codec
, 0x05, 0x06);
109 ad198x_power_eapd_write(codec
, 0x1b, 0x1a);
114 static int ad198x_suspend(struct hda_codec
*codec
)
116 snd_hda_shutup_pins(codec
);
117 ad198x_power_eapd(codec
);
121 /* follow EAPD via vmaster hook */
122 static void ad_vmaster_eapd_hook(void *private_data
, int enabled
)
124 struct hda_codec
*codec
= private_data
;
125 struct ad198x_spec
*spec
= codec
->spec
;
131 snd_hda_codec_write_cache(codec
, spec
->eapd_nid
, 0,
132 AC_VERB_SET_EAPD_BTLENABLE
,
133 enabled
? 0x02 : 0x00);
137 * Automatic parse of I/O pins from the BIOS configuration
140 static int ad198x_auto_build_controls(struct hda_codec
*codec
)
144 err
= snd_hda_gen_build_controls(codec
);
147 err
= create_beep_ctls(codec
);
153 static const struct hda_codec_ops ad198x_auto_patch_ops
= {
154 .build_controls
= ad198x_auto_build_controls
,
155 .build_pcms
= snd_hda_gen_build_pcms
,
156 .init
= snd_hda_gen_init
,
157 .free
= snd_hda_gen_free
,
158 .unsol_event
= snd_hda_jack_unsol_event
,
159 .check_power_status
= snd_hda_gen_check_power_status
,
160 .suspend
= ad198x_suspend
,
164 static int ad198x_parse_auto_config(struct hda_codec
*codec
, bool indep_hp
)
166 struct ad198x_spec
*spec
= codec
->spec
;
167 struct auto_pin_cfg
*cfg
= &spec
->gen
.autocfg
;
170 codec
->spdif_status_reset
= 1;
171 codec
->no_trigger_sense
= 1;
172 codec
->no_sticky_stream
= 1;
174 spec
->gen
.indep_hp
= indep_hp
;
175 if (!spec
->gen
.add_stereo_mix_input
)
176 spec
->gen
.add_stereo_mix_input
= HDA_HINT_STEREO_MIX_AUTO
;
178 err
= snd_hda_parse_pin_defcfg(codec
, cfg
, NULL
, 0);
181 err
= snd_hda_gen_parse_auto_config(codec
, cfg
);
192 static int alloc_ad_spec(struct hda_codec
*codec
)
194 struct ad198x_spec
*spec
;
196 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
200 snd_hda_gen_spec_init(&spec
->gen
);
201 codec
->patch_ops
= ad198x_auto_patch_ops
;
206 * AD1986A fixup codes
209 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
210 static void ad_fixup_inv_jack_detect(struct hda_codec
*codec
,
211 const struct hda_fixup
*fix
, int action
)
213 struct ad198x_spec
*spec
= codec
->spec
;
215 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
216 codec
->inv_jack_detect
= 1;
217 spec
->gen
.keep_eapd_on
= 1;
218 spec
->gen
.vmaster_mute
.hook
= ad_vmaster_eapd_hook
;
219 spec
->eapd_nid
= 0x1b;
223 /* Toshiba Satellite L40 implements EAPD in a standard way unlike others */
224 static void ad1986a_fixup_eapd(struct hda_codec
*codec
,
225 const struct hda_fixup
*fix
, int action
)
227 struct ad198x_spec
*spec
= codec
->spec
;
229 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
231 spec
->gen
.keep_eapd_on
= 1;
232 spec
->eapd_nid
= 0x1b;
236 /* enable stereo-mix input for avoiding regression on KDE (bko#88251) */
237 static void ad1986a_fixup_eapd_mix_in(struct hda_codec
*codec
,
238 const struct hda_fixup
*fix
, int action
)
240 struct ad198x_spec
*spec
= codec
->spec
;
242 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
243 ad1986a_fixup_eapd(codec
, fix
, action
);
244 spec
->gen
.add_stereo_mix_input
= HDA_HINT_STEREO_MIX_ENABLE
;
249 AD1986A_FIXUP_INV_JACK_DETECT
,
251 AD1986A_FIXUP_SAMSUNG
,
252 AD1986A_FIXUP_3STACK
,
253 AD1986A_FIXUP_LAPTOP
,
254 AD1986A_FIXUP_LAPTOP_IMIC
,
256 AD1986A_FIXUP_EAPD_MIX_IN
,
257 AD1986A_FIXUP_EASYNOTE
,
260 static const struct hda_fixup ad1986a_fixups
[] = {
261 [AD1986A_FIXUP_INV_JACK_DETECT
] = {
262 .type
= HDA_FIXUP_FUNC
,
263 .v
.func
= ad_fixup_inv_jack_detect
,
265 [AD1986A_FIXUP_ULTRA
] = {
266 .type
= HDA_FIXUP_PINS
,
267 .v
.pins
= (const struct hda_pintbl
[]) {
268 { 0x1b, 0x90170110 }, /* speaker */
269 { 0x1d, 0x90a7013e }, /* int mic */
273 [AD1986A_FIXUP_SAMSUNG
] = {
274 .type
= HDA_FIXUP_PINS
,
275 .v
.pins
= (const struct hda_pintbl
[]) {
276 { 0x1b, 0x90170110 }, /* speaker */
277 { 0x1d, 0x90a7013e }, /* int mic */
278 { 0x20, 0x411111f0 }, /* N/A */
279 { 0x24, 0x411111f0 }, /* N/A */
283 [AD1986A_FIXUP_3STACK
] = {
284 .type
= HDA_FIXUP_PINS
,
285 .v
.pins
= (const struct hda_pintbl
[]) {
286 { 0x1a, 0x02214021 }, /* headphone */
287 { 0x1b, 0x01014011 }, /* front */
288 { 0x1c, 0x01813030 }, /* line-in */
289 { 0x1d, 0x01a19020 }, /* rear mic */
290 { 0x1e, 0x411111f0 }, /* N/A */
291 { 0x1f, 0x02a190f0 }, /* mic */
292 { 0x20, 0x411111f0 }, /* N/A */
296 [AD1986A_FIXUP_LAPTOP
] = {
297 .type
= HDA_FIXUP_PINS
,
298 .v
.pins
= (const struct hda_pintbl
[]) {
299 { 0x1a, 0x02214021 }, /* headphone */
300 { 0x1b, 0x90170110 }, /* speaker */
301 { 0x1c, 0x411111f0 }, /* N/A */
302 { 0x1d, 0x411111f0 }, /* N/A */
303 { 0x1e, 0x411111f0 }, /* N/A */
304 { 0x1f, 0x02a191f0 }, /* mic */
305 { 0x20, 0x411111f0 }, /* N/A */
309 [AD1986A_FIXUP_LAPTOP_IMIC
] = {
310 .type
= HDA_FIXUP_PINS
,
311 .v
.pins
= (const struct hda_pintbl
[]) {
312 { 0x1d, 0x90a7013e }, /* int mic */
316 .chain_id
= AD1986A_FIXUP_LAPTOP
,
318 [AD1986A_FIXUP_EAPD
] = {
319 .type
= HDA_FIXUP_FUNC
,
320 .v
.func
= ad1986a_fixup_eapd
,
322 [AD1986A_FIXUP_EAPD_MIX_IN
] = {
323 .type
= HDA_FIXUP_FUNC
,
324 .v
.func
= ad1986a_fixup_eapd_mix_in
,
326 [AD1986A_FIXUP_EASYNOTE
] = {
327 .type
= HDA_FIXUP_PINS
,
328 .v
.pins
= (const struct hda_pintbl
[]) {
329 { 0x1a, 0x0421402f }, /* headphone */
330 { 0x1b, 0x90170110 }, /* speaker */
331 { 0x1c, 0x411111f0 }, /* N/A */
332 { 0x1d, 0x90a70130 }, /* int mic */
333 { 0x1e, 0x411111f0 }, /* N/A */
334 { 0x1f, 0x04a19040 }, /* mic */
335 { 0x20, 0x411111f0 }, /* N/A */
336 { 0x21, 0x411111f0 }, /* N/A */
337 { 0x22, 0x411111f0 }, /* N/A */
338 { 0x23, 0x411111f0 }, /* N/A */
339 { 0x24, 0x411111f0 }, /* N/A */
340 { 0x25, 0x411111f0 }, /* N/A */
344 .chain_id
= AD1986A_FIXUP_EAPD_MIX_IN
,
348 static const struct hda_quirk ad1986a_fixup_tbl
[] = {
349 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC
),
350 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9V", AD1986A_FIXUP_LAPTOP_IMIC
),
351 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS Z99He", AD1986A_FIXUP_EAPD
),
352 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8JN", AD1986A_FIXUP_EAPD
),
353 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK
),
354 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK
),
355 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK
),
356 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40", AD1986A_FIXUP_EAPD
),
357 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP
),
358 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG
),
359 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA
),
360 SND_PCI_QUIRK(0x1631, 0xc022, "PackardBell EasyNote MX65", AD1986A_FIXUP_EASYNOTE
),
361 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT
),
362 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK
),
363 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK
),
367 static const struct hda_model_fixup ad1986a_fixup_models
[] = {
368 { .id
= AD1986A_FIXUP_3STACK
, .name
= "3stack" },
369 { .id
= AD1986A_FIXUP_LAPTOP
, .name
= "laptop" },
370 { .id
= AD1986A_FIXUP_LAPTOP_IMIC
, .name
= "laptop-imic" },
371 { .id
= AD1986A_FIXUP_LAPTOP_IMIC
, .name
= "laptop-eapd" }, /* alias */
372 { .id
= AD1986A_FIXUP_EAPD
, .name
= "eapd" },
378 static int patch_ad1986a(struct hda_codec
*codec
)
381 struct ad198x_spec
*spec
;
382 static const hda_nid_t preferred_pairs
[] = {
391 err
= alloc_ad_spec(codec
);
396 /* AD1986A has the inverted EAPD implementation */
399 spec
->gen
.mixer_nid
= 0x07;
400 spec
->gen
.beep_nid
= 0x19;
401 set_beep_amp(spec
, 0x18, 0, HDA_OUTPUT
);
403 /* AD1986A has a hardware problem that it can't share a stream
404 * with multiple output pins. The copy of front to surrounds
405 * causes noisy or silent outputs at a certain timing, e.g.
406 * changing the volume.
407 * So, let's disable the shared stream.
409 spec
->gen
.multiout
.no_share_stream
= 1;
410 /* give fixed DAC/pin pairs */
411 spec
->gen
.preferred_dacs
= preferred_pairs
;
413 /* AD1986A can't manage the dynamic pin on/off smoothly */
414 spec
->gen
.auto_mute_via_amp
= 1;
416 snd_hda_pick_fixup(codec
, ad1986a_fixup_models
, ad1986a_fixup_tbl
,
418 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
420 err
= ad198x_parse_auto_config(codec
, false);
422 snd_hda_gen_free(codec
);
426 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
437 * SPDIF mux control for AD1983 auto-parser
439 static int ad1983_auto_smux_enum_info(struct snd_kcontrol
*kcontrol
,
440 struct snd_ctl_elem_info
*uinfo
)
442 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
443 struct ad198x_spec
*spec
= codec
->spec
;
444 static const char * const texts2
[] = { "PCM", "ADC" };
445 static const char * const texts3
[] = { "PCM", "ADC1", "ADC2" };
446 int num_conns
= spec
->num_smux_conns
;
449 return snd_hda_enum_helper_info(kcontrol
, uinfo
, 2, texts2
);
450 else if (num_conns
== 3)
451 return snd_hda_enum_helper_info(kcontrol
, uinfo
, 3, texts3
);
456 static int ad1983_auto_smux_enum_get(struct snd_kcontrol
*kcontrol
,
457 struct snd_ctl_elem_value
*ucontrol
)
459 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
460 struct ad198x_spec
*spec
= codec
->spec
;
462 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_smux
;
466 static int ad1983_auto_smux_enum_put(struct snd_kcontrol
*kcontrol
,
467 struct snd_ctl_elem_value
*ucontrol
)
469 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
470 struct ad198x_spec
*spec
= codec
->spec
;
471 unsigned int val
= ucontrol
->value
.enumerated
.item
[0];
472 hda_nid_t dig_out
= spec
->gen
.multiout
.dig_out_nid
;
473 int num_conns
= spec
->num_smux_conns
;
475 if (val
>= num_conns
)
477 if (spec
->cur_smux
== val
)
479 spec
->cur_smux
= val
;
480 snd_hda_codec_write_cache(codec
, dig_out
, 0,
481 AC_VERB_SET_CONNECT_SEL
, val
);
485 static const struct snd_kcontrol_new ad1983_auto_smux_mixer
= {
486 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
487 .name
= "IEC958 Playback Source",
488 .info
= ad1983_auto_smux_enum_info
,
489 .get
= ad1983_auto_smux_enum_get
,
490 .put
= ad1983_auto_smux_enum_put
,
493 static int ad1983_add_spdif_mux_ctl(struct hda_codec
*codec
)
495 struct ad198x_spec
*spec
= codec
->spec
;
496 hda_nid_t dig_out
= spec
->gen
.multiout
.dig_out_nid
;
501 num_conns
= snd_hda_get_num_conns(codec
, dig_out
);
502 if (num_conns
!= 2 && num_conns
!= 3)
504 spec
->num_smux_conns
= num_conns
;
505 if (!snd_hda_gen_add_kctl(&spec
->gen
, NULL
, &ad1983_auto_smux_mixer
))
510 static int patch_ad1983(struct hda_codec
*codec
)
512 static const hda_nid_t conn_0c
[] = { 0x08 };
513 static const hda_nid_t conn_0d
[] = { 0x09 };
514 struct ad198x_spec
*spec
;
517 err
= alloc_ad_spec(codec
);
522 spec
->gen
.mixer_nid
= 0x0e;
523 spec
->gen
.beep_nid
= 0x10;
524 set_beep_amp(spec
, 0x10, 0, HDA_OUTPUT
);
526 /* limit the loopback routes not to confuse the parser */
527 snd_hda_override_conn_list(codec
, 0x0c, ARRAY_SIZE(conn_0c
), conn_0c
);
528 snd_hda_override_conn_list(codec
, 0x0d, ARRAY_SIZE(conn_0d
), conn_0d
);
530 err
= ad198x_parse_auto_config(codec
, false);
533 err
= ad1983_add_spdif_mux_ctl(codec
);
539 snd_hda_gen_free(codec
);
548 static void ad1981_fixup_hp_eapd(struct hda_codec
*codec
,
549 const struct hda_fixup
*fix
, int action
)
551 struct ad198x_spec
*spec
= codec
->spec
;
553 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
554 spec
->gen
.vmaster_mute
.hook
= ad_vmaster_eapd_hook
;
555 spec
->eapd_nid
= 0x05;
559 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
560 * damage by overloading
562 static void ad1981_fixup_amp_override(struct hda_codec
*codec
,
563 const struct hda_fixup
*fix
, int action
)
565 if (action
== HDA_FIXUP_ACT_PRE_PROBE
)
566 snd_hda_override_amp_caps(codec
, 0x11, HDA_INPUT
,
567 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
568 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
569 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
570 (1 << AC_AMPCAP_MUTE_SHIFT
));
574 AD1981_FIXUP_AMP_OVERRIDE
,
575 AD1981_FIXUP_HP_EAPD
,
578 static const struct hda_fixup ad1981_fixups
[] = {
579 [AD1981_FIXUP_AMP_OVERRIDE
] = {
580 .type
= HDA_FIXUP_FUNC
,
581 .v
.func
= ad1981_fixup_amp_override
,
583 [AD1981_FIXUP_HP_EAPD
] = {
584 .type
= HDA_FIXUP_FUNC
,
585 .v
.func
= ad1981_fixup_hp_eapd
,
587 .chain_id
= AD1981_FIXUP_AMP_OVERRIDE
,
591 static const struct hda_quirk ad1981_fixup_tbl
[] = {
592 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE
),
593 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD
),
594 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE
),
595 /* HP nx6320 (reversed SSID, H/W bug) */
596 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD
),
600 static int patch_ad1981(struct hda_codec
*codec
)
602 struct ad198x_spec
*spec
;
605 err
= alloc_ad_spec(codec
);
610 spec
->gen
.mixer_nid
= 0x0e;
611 spec
->gen
.beep_nid
= 0x10;
612 set_beep_amp(spec
, 0x0d, 0, HDA_OUTPUT
);
614 snd_hda_pick_fixup(codec
, NULL
, ad1981_fixup_tbl
, ad1981_fixups
);
615 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
617 err
= ad198x_parse_auto_config(codec
, false);
620 err
= ad1983_add_spdif_mux_ctl(codec
);
624 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
629 snd_hda_gen_free(codec
);
637 * Output pins and routes
639 * Pin Mix Sel DAC (*)
640 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
641 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
642 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
643 * port-D 0x12 (mute/hp) <- 0x29 <- 04
644 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
645 * port-F 0x16 (mute) <- 0x2a <- 06
646 * port-G 0x24 (mute) <- 0x27 <- 05
647 * port-H 0x25 (mute) <- 0x28 <- 0a
648 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
650 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
651 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
653 * Input pins and routes
655 * pin boost mix input # / adc input #
656 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
657 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
658 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
659 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
660 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
661 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
662 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
663 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
667 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
668 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
670 * Inputs of Analog Mix (0x20)
671 * 0:Port-B (front mic)
672 * 1:Port-C/G/H (line-in)
674 * 3:Port-D (line-in/2)
675 * 4:Port-E/G/H (mic-in)
682 * 1:Port-B (front mic-in)
689 * 8:Port-D (line-in/2)
692 * Proposed pin assignments by the datasheet
695 * Port-A front headphone
705 * Port-A front headphone
707 * C rear line-in/surround
715 * D internal speaker (with EAPD)
719 static int ad1988_auto_smux_enum_info(struct snd_kcontrol
*kcontrol
,
720 struct snd_ctl_elem_info
*uinfo
)
722 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
723 struct ad198x_spec
*spec
= codec
->spec
;
724 static const char * const texts
[] = {
725 "PCM", "ADC1", "ADC2", "ADC3",
727 int num_conns
= spec
->num_smux_conns
;
731 return snd_hda_enum_helper_info(kcontrol
, uinfo
, num_conns
, texts
);
734 static int ad1988_auto_smux_enum_get(struct snd_kcontrol
*kcontrol
,
735 struct snd_ctl_elem_value
*ucontrol
)
737 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
738 struct ad198x_spec
*spec
= codec
->spec
;
740 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_smux
;
744 static int ad1988_auto_smux_enum_put(struct snd_kcontrol
*kcontrol
,
745 struct snd_ctl_elem_value
*ucontrol
)
747 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
748 struct ad198x_spec
*spec
= codec
->spec
;
749 unsigned int val
= ucontrol
->value
.enumerated
.item
[0];
750 struct nid_path
*path
;
751 int num_conns
= spec
->num_smux_conns
;
753 if (val
>= num_conns
)
755 if (spec
->cur_smux
== val
)
758 mutex_lock(&codec
->control_mutex
);
759 path
= snd_hda_get_path_from_idx(codec
,
760 spec
->smux_paths
[spec
->cur_smux
]);
762 snd_hda_activate_path(codec
, path
, false, true);
763 path
= snd_hda_get_path_from_idx(codec
, spec
->smux_paths
[val
]);
765 snd_hda_activate_path(codec
, path
, true, true);
766 spec
->cur_smux
= val
;
767 mutex_unlock(&codec
->control_mutex
);
771 static const struct snd_kcontrol_new ad1988_auto_smux_mixer
= {
772 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
773 .name
= "IEC958 Playback Source",
774 .info
= ad1988_auto_smux_enum_info
,
775 .get
= ad1988_auto_smux_enum_get
,
776 .put
= ad1988_auto_smux_enum_put
,
779 static int ad1988_auto_init(struct hda_codec
*codec
)
781 struct ad198x_spec
*spec
= codec
->spec
;
784 err
= snd_hda_gen_init(codec
);
787 if (!spec
->gen
.autocfg
.dig_outs
)
790 for (i
= 0; i
< 4; i
++) {
791 struct nid_path
*path
;
792 path
= snd_hda_get_path_from_idx(codec
, spec
->smux_paths
[i
]);
794 snd_hda_activate_path(codec
, path
, path
->active
, false);
800 static int ad1988_add_spdif_mux_ctl(struct hda_codec
*codec
)
802 struct ad198x_spec
*spec
= codec
->spec
;
804 /* we create four static faked paths, since AD codecs have odd
805 * widget connections regarding the SPDIF out source
807 static const struct nid_path fake_paths
[4] = {
810 .path
= { 0x02, 0x1d, 0x1b },
812 .multi
= { 0, 0, 0 },
816 .path
= { 0x08, 0x0b, 0x1d, 0x1b },
817 .idx
= { 0, 0, 1, 0 },
818 .multi
= { 0, 1, 0, 0 },
822 .path
= { 0x09, 0x0b, 0x1d, 0x1b },
823 .idx
= { 0, 1, 1, 0 },
824 .multi
= { 0, 1, 0, 0 },
828 .path
= { 0x0f, 0x0b, 0x1d, 0x1b },
829 .idx
= { 0, 2, 1, 0 },
830 .multi
= { 0, 1, 0, 0 },
834 /* SPDIF source mux appears to be present only on AD1988A */
835 if (!spec
->gen
.autocfg
.dig_outs
||
836 get_wcaps_type(get_wcaps(codec
, 0x1d)) != AC_WID_AUD_MIX
)
839 num_conns
= snd_hda_get_num_conns(codec
, 0x0b) + 1;
840 if (num_conns
!= 3 && num_conns
!= 4)
842 spec
->num_smux_conns
= num_conns
;
844 for (i
= 0; i
< num_conns
; i
++) {
845 struct nid_path
*path
= snd_array_new(&spec
->gen
.paths
);
848 *path
= fake_paths
[i
];
851 spec
->smux_paths
[i
] = snd_hda_get_path_idx(codec
, path
);
854 if (!snd_hda_gen_add_kctl(&spec
->gen
, NULL
, &ad1988_auto_smux_mixer
))
857 codec
->patch_ops
.init
= ad1988_auto_init
;
866 AD1988_FIXUP_6STACK_DIG
,
869 static const struct hda_fixup ad1988_fixups
[] = {
870 [AD1988_FIXUP_6STACK_DIG
] = {
871 .type
= HDA_FIXUP_PINS
,
872 .v
.pins
= (const struct hda_pintbl
[]) {
873 { 0x11, 0x02214130 }, /* front-hp */
874 { 0x12, 0x01014010 }, /* line-out */
875 { 0x14, 0x02a19122 }, /* front-mic */
876 { 0x15, 0x01813021 }, /* line-in */
877 { 0x16, 0x01011012 }, /* line-out */
878 { 0x17, 0x01a19020 }, /* mic */
879 { 0x1b, 0x0145f1f0 }, /* SPDIF */
880 { 0x24, 0x01016011 }, /* line-out */
881 { 0x25, 0x01012013 }, /* line-out */
887 static const struct hda_model_fixup ad1988_fixup_models
[] = {
888 { .id
= AD1988_FIXUP_6STACK_DIG
, .name
= "6stack-dig" },
892 static int patch_ad1988(struct hda_codec
*codec
)
894 struct ad198x_spec
*spec
;
897 err
= alloc_ad_spec(codec
);
902 spec
->gen
.mixer_nid
= 0x20;
903 spec
->gen
.mixer_merge_nid
= 0x21;
904 spec
->gen
.beep_nid
= 0x10;
905 set_beep_amp(spec
, 0x10, 0, HDA_OUTPUT
);
907 snd_hda_pick_fixup(codec
, ad1988_fixup_models
, NULL
, ad1988_fixups
);
908 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
910 err
= ad198x_parse_auto_config(codec
, true);
913 err
= ad1988_add_spdif_mux_ctl(codec
);
917 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
922 snd_hda_gen_free(codec
);
930 * port-B - front line/mic-in
931 * port-E - aux in/out
932 * port-F - aux in/out
933 * port-C - rear line/mic-in
934 * port-D - rear line/hp-out
935 * port-A - front line/hp-out
937 * AD1984 = AD1884 + two digital mic-ins
939 * AD1883 / AD1884A / AD1984A / AD1984B
941 * port-B (0x14) - front mic-in
942 * port-E (0x1c) - rear mic-in
943 * port-F (0x16) - CD / ext out
944 * port-C (0x15) - rear line-in
945 * port-D (0x12) - rear line-out
946 * port-A (0x11) - front hp-out
948 * AD1984A = AD1884A + digital-mic
949 * AD1883 = equivalent with AD1984A
950 * AD1984B = AD1984A + extra SPDIF-out
953 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
954 * damage by overloading
956 static void ad1884_fixup_amp_override(struct hda_codec
*codec
,
957 const struct hda_fixup
*fix
, int action
)
959 if (action
== HDA_FIXUP_ACT_PRE_PROBE
)
960 snd_hda_override_amp_caps(codec
, 0x20, HDA_INPUT
,
961 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
962 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
963 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
964 (1 << AC_AMPCAP_MUTE_SHIFT
));
967 /* toggle GPIO1 according to the mute state */
968 static void ad1884_vmaster_hp_gpio_hook(void *private_data
, int enabled
)
970 struct hda_codec
*codec
= private_data
;
971 struct ad198x_spec
*spec
= codec
->spec
;
974 ad_vmaster_eapd_hook(private_data
, enabled
);
975 snd_hda_codec_write_cache(codec
, 0x01, 0,
976 AC_VERB_SET_GPIO_DATA
,
977 enabled
? 0x00 : 0x02);
980 static void ad1884_fixup_hp_eapd(struct hda_codec
*codec
,
981 const struct hda_fixup
*fix
, int action
)
983 struct ad198x_spec
*spec
= codec
->spec
;
986 case HDA_FIXUP_ACT_PRE_PROBE
:
987 spec
->gen
.vmaster_mute
.hook
= ad1884_vmaster_hp_gpio_hook
;
988 spec
->gen
.own_eapd_ctl
= 1;
989 snd_hda_codec_write_cache(codec
, 0x01, 0,
990 AC_VERB_SET_GPIO_MASK
, 0x02);
991 snd_hda_codec_write_cache(codec
, 0x01, 0,
992 AC_VERB_SET_GPIO_DIRECTION
, 0x02);
993 snd_hda_codec_write_cache(codec
, 0x01, 0,
994 AC_VERB_SET_GPIO_DATA
, 0x02);
996 case HDA_FIXUP_ACT_PROBE
:
997 if (spec
->gen
.autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
)
998 spec
->eapd_nid
= spec
->gen
.autocfg
.line_out_pins
[0];
1000 spec
->eapd_nid
= spec
->gen
.autocfg
.speaker_pins
[0];
1005 static void ad1884_fixup_thinkpad(struct hda_codec
*codec
,
1006 const struct hda_fixup
*fix
, int action
)
1008 struct ad198x_spec
*spec
= codec
->spec
;
1010 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
1011 spec
->gen
.keep_eapd_on
= 1;
1012 spec
->gen
.vmaster_mute
.hook
= ad_vmaster_eapd_hook
;
1013 spec
->eapd_nid
= 0x12;
1014 /* Analog PC Beeper - allow firmware/ACPI beeps */
1015 spec
->beep_amp
= HDA_COMPOSE_AMP_VAL(0x20, 3, 3, HDA_INPUT
);
1016 spec
->gen
.beep_nid
= 0; /* no digital beep */
1020 /* set magic COEFs for dmic */
1021 static const struct hda_verb ad1884_dmic_init_verbs
[] = {
1022 {0x01, AC_VERB_SET_COEF_INDEX
, 0x13f7},
1023 {0x01, AC_VERB_SET_PROC_COEF
, 0x08},
1028 AD1884_FIXUP_AMP_OVERRIDE
,
1029 AD1884_FIXUP_HP_EAPD
,
1030 AD1884_FIXUP_DMIC_COEF
,
1031 AD1884_FIXUP_THINKPAD
,
1032 AD1884_FIXUP_HP_TOUCHSMART
,
1035 static const struct hda_fixup ad1884_fixups
[] = {
1036 [AD1884_FIXUP_AMP_OVERRIDE
] = {
1037 .type
= HDA_FIXUP_FUNC
,
1038 .v
.func
= ad1884_fixup_amp_override
,
1040 [AD1884_FIXUP_HP_EAPD
] = {
1041 .type
= HDA_FIXUP_FUNC
,
1042 .v
.func
= ad1884_fixup_hp_eapd
,
1044 .chain_id
= AD1884_FIXUP_AMP_OVERRIDE
,
1046 [AD1884_FIXUP_DMIC_COEF
] = {
1047 .type
= HDA_FIXUP_VERBS
,
1048 .v
.verbs
= ad1884_dmic_init_verbs
,
1050 [AD1884_FIXUP_THINKPAD
] = {
1051 .type
= HDA_FIXUP_FUNC
,
1052 .v
.func
= ad1884_fixup_thinkpad
,
1054 .chain_id
= AD1884_FIXUP_DMIC_COEF
,
1056 [AD1884_FIXUP_HP_TOUCHSMART
] = {
1057 .type
= HDA_FIXUP_VERBS
,
1058 .v
.verbs
= ad1884_dmic_init_verbs
,
1060 .chain_id
= AD1884_FIXUP_HP_EAPD
,
1064 static const struct hda_quirk ad1884_fixup_tbl
[] = {
1065 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART
),
1066 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD
),
1067 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD
),
1072 static int patch_ad1884(struct hda_codec
*codec
)
1074 struct ad198x_spec
*spec
;
1077 err
= alloc_ad_spec(codec
);
1082 spec
->gen
.mixer_nid
= 0x20;
1083 spec
->gen
.mixer_merge_nid
= 0x21;
1084 spec
->gen
.beep_nid
= 0x10;
1085 set_beep_amp(spec
, 0x10, 0, HDA_OUTPUT
);
1087 snd_hda_pick_fixup(codec
, NULL
, ad1884_fixup_tbl
, ad1884_fixups
);
1088 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
1090 err
= ad198x_parse_auto_config(codec
, true);
1093 err
= ad1983_add_spdif_mux_ctl(codec
);
1097 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
1102 snd_hda_gen_free(codec
);
1109 * port-A - front hp-out
1110 * port-B - front mic-in
1111 * port-C - rear line-in, shared surr-out (3stack)
1112 * port-D - rear line-out
1113 * port-E - rear mic-in, shared clfe-out (3stack)
1114 * port-F - rear surr-out (6stack)
1115 * port-G - rear clfe-out (6stack)
1118 static int patch_ad1882(struct hda_codec
*codec
)
1120 struct ad198x_spec
*spec
;
1123 err
= alloc_ad_spec(codec
);
1128 spec
->gen
.mixer_nid
= 0x20;
1129 spec
->gen
.mixer_merge_nid
= 0x21;
1130 spec
->gen
.beep_nid
= 0x10;
1131 set_beep_amp(spec
, 0x10, 0, HDA_OUTPUT
);
1132 err
= ad198x_parse_auto_config(codec
, true);
1135 err
= ad1988_add_spdif_mux_ctl(codec
);
1141 snd_hda_gen_free(codec
);
1149 static const struct hda_device_id snd_hda_id_analog
[] = {
1150 HDA_CODEC_ENTRY(0x11d4184a, "AD1884A", patch_ad1884
),
1151 HDA_CODEC_ENTRY(0x11d41882, "AD1882", patch_ad1882
),
1152 HDA_CODEC_ENTRY(0x11d41883, "AD1883", patch_ad1884
),
1153 HDA_CODEC_ENTRY(0x11d41884, "AD1884", patch_ad1884
),
1154 HDA_CODEC_ENTRY(0x11d4194a, "AD1984A", patch_ad1884
),
1155 HDA_CODEC_ENTRY(0x11d4194b, "AD1984B", patch_ad1884
),
1156 HDA_CODEC_ENTRY(0x11d41981, "AD1981", patch_ad1981
),
1157 HDA_CODEC_ENTRY(0x11d41983, "AD1983", patch_ad1983
),
1158 HDA_CODEC_ENTRY(0x11d41984, "AD1984", patch_ad1884
),
1159 HDA_CODEC_ENTRY(0x11d41986, "AD1986A", patch_ad1986a
),
1160 HDA_CODEC_ENTRY(0x11d41988, "AD1988", patch_ad1988
),
1161 HDA_CODEC_ENTRY(0x11d4198b, "AD1988B", patch_ad1988
),
1162 HDA_CODEC_ENTRY(0x11d4882a, "AD1882A", patch_ad1882
),
1163 HDA_CODEC_ENTRY(0x11d4989a, "AD1989A", patch_ad1988
),
1164 HDA_CODEC_ENTRY(0x11d4989b, "AD1989B", patch_ad1988
),
1167 MODULE_DEVICE_TABLE(hdaudio
, snd_hda_id_analog
);
1169 MODULE_LICENSE("GPL");
1170 MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1172 static struct hda_codec_driver analog_driver
= {
1173 .id
= snd_hda_id_analog
,
1176 module_hda_codec_driver(analog_driver
);