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/module.h>
26 #include <sound/core.h>
27 #include "hda_codec.h"
28 #include "hda_local.h"
29 #include "hda_auto_parser.h"
32 #include "hda_generic.h"
36 struct hda_gen_spec gen
;
40 unsigned int cur_smux
;
43 unsigned int beep_amp
; /* beep amp value, set via set_beep_amp() */
47 #ifdef CONFIG_SND_HDA_INPUT_BEEP
48 /* additional beep mixers; the actual parameters are overwritten at build */
49 static const struct snd_kcontrol_new ad_beep_mixer
[] = {
50 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT
),
51 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT
),
55 #define set_beep_amp(spec, nid, idx, dir) \
56 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
58 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
61 #ifdef CONFIG_SND_HDA_INPUT_BEEP
62 static int create_beep_ctls(struct hda_codec
*codec
)
64 struct ad198x_spec
*spec
= codec
->spec
;
65 const struct snd_kcontrol_new
*knew
;
70 for (knew
= ad_beep_mixer
; knew
->name
; knew
++) {
72 struct snd_kcontrol
*kctl
;
73 kctl
= snd_ctl_new1(knew
, codec
);
76 kctl
->private_value
= spec
->beep_amp
;
77 err
= snd_hda_ctl_add(codec
, 0, kctl
);
84 #define create_beep_ctls(codec) 0
88 static void ad198x_power_eapd_write(struct hda_codec
*codec
, hda_nid_t front
,
91 if (snd_hda_query_pin_caps(codec
, front
) & AC_PINCAP_EAPD
)
92 snd_hda_codec_write(codec
, front
, 0, AC_VERB_SET_EAPD_BTLENABLE
,
93 !codec
->inv_eapd
? 0x00 : 0x02);
94 if (snd_hda_query_pin_caps(codec
, hp
) & AC_PINCAP_EAPD
)
95 snd_hda_codec_write(codec
, hp
, 0, AC_VERB_SET_EAPD_BTLENABLE
,
96 !codec
->inv_eapd
? 0x00 : 0x02);
99 static void ad198x_power_eapd(struct hda_codec
*codec
)
101 /* We currently only handle front, HP */
102 switch (codec
->vendor_id
) {
115 ad198x_power_eapd_write(codec
, 0x12, 0x11);
119 ad198x_power_eapd_write(codec
, 0x05, 0x06);
122 ad198x_power_eapd_write(codec
, 0x1b, 0x1a);
127 static void ad198x_shutup(struct hda_codec
*codec
)
129 snd_hda_shutup_pins(codec
);
130 ad198x_power_eapd(codec
);
134 static int ad198x_suspend(struct hda_codec
*codec
)
136 ad198x_shutup(codec
);
141 /* follow EAPD via vmaster hook */
142 static void ad_vmaster_eapd_hook(void *private_data
, int enabled
)
144 struct hda_codec
*codec
= private_data
;
145 struct ad198x_spec
*spec
= codec
->spec
;
151 snd_hda_codec_update_cache(codec
, spec
->eapd_nid
, 0,
152 AC_VERB_SET_EAPD_BTLENABLE
,
153 enabled
? 0x02 : 0x00);
157 * Automatic parse of I/O pins from the BIOS configuration
160 static int ad198x_auto_build_controls(struct hda_codec
*codec
)
164 err
= snd_hda_gen_build_controls(codec
);
167 err
= create_beep_ctls(codec
);
173 static const struct hda_codec_ops ad198x_auto_patch_ops
= {
174 .build_controls
= ad198x_auto_build_controls
,
175 .build_pcms
= snd_hda_gen_build_pcms
,
176 .init
= snd_hda_gen_init
,
177 .free
= snd_hda_gen_free
,
178 .unsol_event
= snd_hda_jack_unsol_event
,
180 .check_power_status
= snd_hda_gen_check_power_status
,
181 .suspend
= ad198x_suspend
,
183 .reboot_notify
= ad198x_shutup
,
187 static int ad198x_parse_auto_config(struct hda_codec
*codec
, bool indep_hp
)
189 struct ad198x_spec
*spec
= codec
->spec
;
190 struct auto_pin_cfg
*cfg
= &spec
->gen
.autocfg
;
193 codec
->spdif_status_reset
= 1;
194 codec
->no_trigger_sense
= 1;
195 codec
->no_sticky_stream
= 1;
197 spec
->gen
.indep_hp
= indep_hp
;
198 spec
->gen
.add_stereo_mix_input
= 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;
246 /* Toshiba Satellite L40 implements EAPD in a standard way unlike others */
247 static void ad1986a_fixup_eapd(struct hda_codec
*codec
,
248 const struct hda_fixup
*fix
, int action
)
250 struct ad198x_spec
*spec
= codec
->spec
;
252 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
254 spec
->gen
.keep_eapd_on
= 1;
255 spec
->eapd_nid
= 0x1b;
260 AD1986A_FIXUP_INV_JACK_DETECT
,
262 AD1986A_FIXUP_SAMSUNG
,
263 AD1986A_FIXUP_3STACK
,
264 AD1986A_FIXUP_LAPTOP
,
265 AD1986A_FIXUP_LAPTOP_IMIC
,
269 static const struct hda_fixup ad1986a_fixups
[] = {
270 [AD1986A_FIXUP_INV_JACK_DETECT
] = {
271 .type
= HDA_FIXUP_FUNC
,
272 .v
.func
= ad_fixup_inv_jack_detect
,
274 [AD1986A_FIXUP_ULTRA
] = {
275 .type
= HDA_FIXUP_PINS
,
276 .v
.pins
= (const struct hda_pintbl
[]) {
277 { 0x1b, 0x90170110 }, /* speaker */
278 { 0x1d, 0x90a7013e }, /* int mic */
282 [AD1986A_FIXUP_SAMSUNG
] = {
283 .type
= HDA_FIXUP_PINS
,
284 .v
.pins
= (const struct hda_pintbl
[]) {
285 { 0x1b, 0x90170110 }, /* speaker */
286 { 0x1d, 0x90a7013e }, /* int mic */
287 { 0x20, 0x411111f0 }, /* N/A */
288 { 0x24, 0x411111f0 }, /* N/A */
292 [AD1986A_FIXUP_3STACK
] = {
293 .type
= HDA_FIXUP_PINS
,
294 .v
.pins
= (const struct hda_pintbl
[]) {
295 { 0x1a, 0x02214021 }, /* headphone */
296 { 0x1b, 0x01014011 }, /* front */
297 { 0x1c, 0x01813030 }, /* line-in */
298 { 0x1d, 0x01a19020 }, /* rear mic */
299 { 0x1e, 0x411111f0 }, /* N/A */
300 { 0x1f, 0x02a190f0 }, /* mic */
301 { 0x20, 0x411111f0 }, /* N/A */
305 [AD1986A_FIXUP_LAPTOP
] = {
306 .type
= HDA_FIXUP_PINS
,
307 .v
.pins
= (const struct hda_pintbl
[]) {
308 { 0x1a, 0x02214021 }, /* headphone */
309 { 0x1b, 0x90170110 }, /* speaker */
310 { 0x1c, 0x411111f0 }, /* N/A */
311 { 0x1d, 0x411111f0 }, /* N/A */
312 { 0x1e, 0x411111f0 }, /* N/A */
313 { 0x1f, 0x02a191f0 }, /* mic */
314 { 0x20, 0x411111f0 }, /* N/A */
318 [AD1986A_FIXUP_LAPTOP_IMIC
] = {
319 .type
= HDA_FIXUP_PINS
,
320 .v
.pins
= (const struct hda_pintbl
[]) {
321 { 0x1d, 0x90a7013e }, /* int mic */
325 .chain_id
= AD1986A_FIXUP_LAPTOP
,
327 [AD1986A_FIXUP_EAPD
] = {
328 .type
= HDA_FIXUP_FUNC
,
329 .v
.func
= ad1986a_fixup_eapd
,
333 static const struct snd_pci_quirk ad1986a_fixup_tbl
[] = {
334 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC
),
335 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS Z99He", AD1986A_FIXUP_EAPD
),
336 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8JN", AD1986A_FIXUP_EAPD
),
337 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK
),
338 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK
),
339 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK
),
340 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40", AD1986A_FIXUP_EAPD
),
341 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP
),
342 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG
),
343 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA
),
344 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT
),
345 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK
),
346 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK
),
350 static const struct hda_model_fixup ad1986a_fixup_models
[] = {
351 { .id
= AD1986A_FIXUP_3STACK
, .name
= "3stack" },
352 { .id
= AD1986A_FIXUP_LAPTOP
, .name
= "laptop" },
353 { .id
= AD1986A_FIXUP_LAPTOP_IMIC
, .name
= "laptop-imic" },
354 { .id
= AD1986A_FIXUP_LAPTOP_IMIC
, .name
= "laptop-eapd" }, /* alias */
360 static int patch_ad1986a(struct hda_codec
*codec
)
363 struct ad198x_spec
*spec
;
364 static hda_nid_t preferred_pairs
[] = {
373 err
= alloc_ad_spec(codec
);
378 /* AD1986A has the inverted EAPD implementation */
381 spec
->gen
.mixer_nid
= 0x07;
382 spec
->gen
.beep_nid
= 0x19;
383 set_beep_amp(spec
, 0x18, 0, HDA_OUTPUT
);
385 /* AD1986A has a hardware problem that it can't share a stream
386 * with multiple output pins. The copy of front to surrounds
387 * causes noisy or silent outputs at a certain timing, e.g.
388 * changing the volume.
389 * So, let's disable the shared stream.
391 spec
->gen
.multiout
.no_share_stream
= 1;
392 /* give fixed DAC/pin pairs */
393 spec
->gen
.preferred_dacs
= preferred_pairs
;
395 /* AD1986A can't manage the dynamic pin on/off smoothly */
396 spec
->gen
.auto_mute_via_amp
= 1;
398 snd_hda_pick_fixup(codec
, ad1986a_fixup_models
, ad1986a_fixup_tbl
,
400 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
402 err
= ad198x_parse_auto_config(codec
, false);
404 snd_hda_gen_free(codec
);
408 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
419 * SPDIF mux control for AD1983 auto-parser
421 static int ad1983_auto_smux_enum_info(struct snd_kcontrol
*kcontrol
,
422 struct snd_ctl_elem_info
*uinfo
)
424 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
425 struct ad198x_spec
*spec
= codec
->spec
;
426 static const char * const texts2
[] = { "PCM", "ADC" };
427 static const char * const texts3
[] = { "PCM", "ADC1", "ADC2" };
428 hda_nid_t dig_out
= spec
->gen
.multiout
.dig_out_nid
;
429 int num_conns
= snd_hda_get_num_conns(codec
, dig_out
);
432 return snd_hda_enum_helper_info(kcontrol
, uinfo
, 2, texts2
);
433 else if (num_conns
== 3)
434 return snd_hda_enum_helper_info(kcontrol
, uinfo
, 3, texts3
);
439 static int ad1983_auto_smux_enum_get(struct snd_kcontrol
*kcontrol
,
440 struct snd_ctl_elem_value
*ucontrol
)
442 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
443 struct ad198x_spec
*spec
= codec
->spec
;
445 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_smux
;
449 static int ad1983_auto_smux_enum_put(struct snd_kcontrol
*kcontrol
,
450 struct snd_ctl_elem_value
*ucontrol
)
452 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
453 struct ad198x_spec
*spec
= codec
->spec
;
454 unsigned int val
= ucontrol
->value
.enumerated
.item
[0];
455 hda_nid_t dig_out
= spec
->gen
.multiout
.dig_out_nid
;
456 int num_conns
= snd_hda_get_num_conns(codec
, dig_out
);
458 if (val
>= num_conns
)
460 if (spec
->cur_smux
== val
)
462 spec
->cur_smux
= val
;
463 snd_hda_codec_write_cache(codec
, dig_out
, 0,
464 AC_VERB_SET_CONNECT_SEL
, val
);
468 static struct snd_kcontrol_new ad1983_auto_smux_mixer
= {
469 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
470 .name
= "IEC958 Playback Source",
471 .info
= ad1983_auto_smux_enum_info
,
472 .get
= ad1983_auto_smux_enum_get
,
473 .put
= ad1983_auto_smux_enum_put
,
476 static int ad1983_add_spdif_mux_ctl(struct hda_codec
*codec
)
478 struct ad198x_spec
*spec
= codec
->spec
;
479 hda_nid_t dig_out
= spec
->gen
.multiout
.dig_out_nid
;
484 num_conns
= snd_hda_get_num_conns(codec
, dig_out
);
485 if (num_conns
!= 2 && num_conns
!= 3)
487 if (!snd_hda_gen_add_kctl(&spec
->gen
, NULL
, &ad1983_auto_smux_mixer
))
492 static int patch_ad1983(struct hda_codec
*codec
)
494 struct ad198x_spec
*spec
;
495 static hda_nid_t conn_0c
[] = { 0x08 };
496 static hda_nid_t conn_0d
[] = { 0x09 };
499 err
= alloc_ad_spec(codec
);
504 spec
->gen
.mixer_nid
= 0x0e;
505 spec
->gen
.beep_nid
= 0x10;
506 set_beep_amp(spec
, 0x10, 0, HDA_OUTPUT
);
508 /* limit the loopback routes not to confuse the parser */
509 snd_hda_override_conn_list(codec
, 0x0c, ARRAY_SIZE(conn_0c
), conn_0c
);
510 snd_hda_override_conn_list(codec
, 0x0d, ARRAY_SIZE(conn_0d
), conn_0d
);
512 err
= ad198x_parse_auto_config(codec
, false);
515 err
= ad1983_add_spdif_mux_ctl(codec
);
521 snd_hda_gen_free(codec
);
530 static void ad1981_fixup_hp_eapd(struct hda_codec
*codec
,
531 const struct hda_fixup
*fix
, int action
)
533 struct ad198x_spec
*spec
= codec
->spec
;
535 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
536 spec
->gen
.vmaster_mute
.hook
= ad_vmaster_eapd_hook
;
537 spec
->eapd_nid
= 0x05;
541 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
542 * damage by overloading
544 static void ad1981_fixup_amp_override(struct hda_codec
*codec
,
545 const struct hda_fixup
*fix
, int action
)
547 if (action
== HDA_FIXUP_ACT_PRE_PROBE
)
548 snd_hda_override_amp_caps(codec
, 0x11, HDA_INPUT
,
549 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
550 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
551 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
552 (1 << AC_AMPCAP_MUTE_SHIFT
));
556 AD1981_FIXUP_AMP_OVERRIDE
,
557 AD1981_FIXUP_HP_EAPD
,
560 static const struct hda_fixup ad1981_fixups
[] = {
561 [AD1981_FIXUP_AMP_OVERRIDE
] = {
562 .type
= HDA_FIXUP_FUNC
,
563 .v
.func
= ad1981_fixup_amp_override
,
565 [AD1981_FIXUP_HP_EAPD
] = {
566 .type
= HDA_FIXUP_FUNC
,
567 .v
.func
= ad1981_fixup_hp_eapd
,
569 .chain_id
= AD1981_FIXUP_AMP_OVERRIDE
,
573 static const struct snd_pci_quirk ad1981_fixup_tbl
[] = {
574 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE
),
575 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD
),
576 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE
),
577 /* HP nx6320 (reversed SSID, H/W bug) */
578 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD
),
582 static int patch_ad1981(struct hda_codec
*codec
)
584 struct ad198x_spec
*spec
;
587 err
= alloc_ad_spec(codec
);
592 spec
->gen
.mixer_nid
= 0x0e;
593 spec
->gen
.beep_nid
= 0x10;
594 set_beep_amp(spec
, 0x0d, 0, HDA_OUTPUT
);
596 snd_hda_pick_fixup(codec
, NULL
, ad1981_fixup_tbl
, ad1981_fixups
);
597 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
599 err
= ad198x_parse_auto_config(codec
, false);
602 err
= ad1983_add_spdif_mux_ctl(codec
);
606 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
611 snd_hda_gen_free(codec
);
619 * Output pins and routes
621 * Pin Mix Sel DAC (*)
622 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
623 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
624 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
625 * port-D 0x12 (mute/hp) <- 0x29 <- 04
626 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
627 * port-F 0x16 (mute) <- 0x2a <- 06
628 * port-G 0x24 (mute) <- 0x27 <- 05
629 * port-H 0x25 (mute) <- 0x28 <- 0a
630 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
632 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
633 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
635 * Input pins and routes
637 * pin boost mix input # / adc input #
638 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
639 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
640 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
641 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
642 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
643 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
644 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
645 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
649 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
650 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
652 * Inputs of Analog Mix (0x20)
653 * 0:Port-B (front mic)
654 * 1:Port-C/G/H (line-in)
656 * 3:Port-D (line-in/2)
657 * 4:Port-E/G/H (mic-in)
664 * 1:Port-B (front mic-in)
671 * 8:Port-D (line-in/2)
674 * Proposed pin assignments by the datasheet
677 * Port-A front headphone
687 * Port-A front headphone
689 * C rear line-in/surround
697 * D internal speaker (with EAPD)
701 #ifdef ENABLE_AD_STATIC_QUIRKS
702 static int ad198x_ch_mode_info(struct snd_kcontrol
*kcontrol
,
703 struct snd_ctl_elem_info
*uinfo
)
705 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
706 struct ad198x_spec
*spec
= codec
->spec
;
707 return snd_hda_ch_mode_info(codec
, uinfo
, spec
->channel_mode
,
708 spec
->num_channel_mode
);
711 static int ad198x_ch_mode_get(struct snd_kcontrol
*kcontrol
,
712 struct snd_ctl_elem_value
*ucontrol
)
714 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
715 struct ad198x_spec
*spec
= codec
->spec
;
716 return snd_hda_ch_mode_get(codec
, ucontrol
, spec
->channel_mode
,
717 spec
->num_channel_mode
, spec
->multiout
.max_channels
);
720 static int ad198x_ch_mode_put(struct snd_kcontrol
*kcontrol
,
721 struct snd_ctl_elem_value
*ucontrol
)
723 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
724 struct ad198x_spec
*spec
= codec
->spec
;
725 int err
= snd_hda_ch_mode_put(codec
, ucontrol
, spec
->channel_mode
,
726 spec
->num_channel_mode
,
727 &spec
->multiout
.max_channels
);
728 if (err
>= 0 && spec
->need_dac_fix
)
729 spec
->multiout
.num_dacs
= spec
->multiout
.max_channels
/ 2;
732 #endif /* ENABLE_AD_STATIC_QUIRKS */
734 static int ad1988_auto_smux_enum_info(struct snd_kcontrol
*kcontrol
,
735 struct snd_ctl_elem_info
*uinfo
)
737 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
738 static const char * const texts
[] = {
739 "PCM", "ADC1", "ADC2", "ADC3",
741 int num_conns
= snd_hda_get_num_conns(codec
, 0x0b) + 1;
744 return snd_hda_enum_helper_info(kcontrol
, uinfo
, num_conns
, texts
);
747 static int ad1988_auto_smux_enum_get(struct snd_kcontrol
*kcontrol
,
748 struct snd_ctl_elem_value
*ucontrol
)
750 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
751 struct ad198x_spec
*spec
= codec
->spec
;
753 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_smux
;
757 static int ad1988_auto_smux_enum_put(struct snd_kcontrol
*kcontrol
,
758 struct snd_ctl_elem_value
*ucontrol
)
760 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
761 struct ad198x_spec
*spec
= codec
->spec
;
762 unsigned int val
= ucontrol
->value
.enumerated
.item
[0];
763 struct nid_path
*path
;
764 int num_conns
= snd_hda_get_num_conns(codec
, 0x0b) + 1;
766 if (val
>= num_conns
)
768 if (spec
->cur_smux
== val
)
771 mutex_lock(&codec
->control_mutex
);
772 codec
->cached_write
= 1;
773 path
= snd_hda_get_path_from_idx(codec
,
774 spec
->smux_paths
[spec
->cur_smux
]);
776 snd_hda_activate_path(codec
, path
, false, true);
777 path
= snd_hda_get_path_from_idx(codec
, spec
->smux_paths
[val
]);
779 snd_hda_activate_path(codec
, path
, true, true);
780 spec
->cur_smux
= val
;
781 codec
->cached_write
= 0;
782 mutex_unlock(&codec
->control_mutex
);
783 snd_hda_codec_flush_cache(codec
); /* flush the updates */
787 static struct snd_kcontrol_new ad1988_auto_smux_mixer
= {
788 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
789 .name
= "IEC958 Playback Source",
790 .info
= ad1988_auto_smux_enum_info
,
791 .get
= ad1988_auto_smux_enum_get
,
792 .put
= ad1988_auto_smux_enum_put
,
795 static int ad1988_auto_init(struct hda_codec
*codec
)
797 struct ad198x_spec
*spec
= codec
->spec
;
800 err
= snd_hda_gen_init(codec
);
803 if (!spec
->gen
.autocfg
.dig_outs
)
806 for (i
= 0; i
< 4; i
++) {
807 struct nid_path
*path
;
808 path
= snd_hda_get_path_from_idx(codec
, spec
->smux_paths
[i
]);
810 snd_hda_activate_path(codec
, path
, path
->active
, false);
816 static int ad1988_add_spdif_mux_ctl(struct hda_codec
*codec
)
818 struct ad198x_spec
*spec
= codec
->spec
;
820 /* we create four static faked paths, since AD codecs have odd
821 * widget connections regarding the SPDIF out source
823 static struct nid_path fake_paths
[4] = {
826 .path
= { 0x02, 0x1d, 0x1b },
828 .multi
= { 0, 0, 0 },
832 .path
= { 0x08, 0x0b, 0x1d, 0x1b },
833 .idx
= { 0, 0, 1, 0 },
834 .multi
= { 0, 1, 0, 0 },
838 .path
= { 0x09, 0x0b, 0x1d, 0x1b },
839 .idx
= { 0, 1, 1, 0 },
840 .multi
= { 0, 1, 0, 0 },
844 .path
= { 0x0f, 0x0b, 0x1d, 0x1b },
845 .idx
= { 0, 2, 1, 0 },
846 .multi
= { 0, 1, 0, 0 },
850 /* SPDIF source mux appears to be present only on AD1988A */
851 if (!spec
->gen
.autocfg
.dig_outs
||
852 get_wcaps_type(get_wcaps(codec
, 0x1d)) != AC_WID_AUD_MIX
)
855 num_conns
= snd_hda_get_num_conns(codec
, 0x0b) + 1;
856 if (num_conns
!= 3 && num_conns
!= 4)
859 for (i
= 0; i
< num_conns
; i
++) {
860 struct nid_path
*path
= snd_array_new(&spec
->gen
.paths
);
863 *path
= fake_paths
[i
];
866 spec
->smux_paths
[i
] = snd_hda_get_path_idx(codec
, path
);
869 if (!snd_hda_gen_add_kctl(&spec
->gen
, NULL
, &ad1988_auto_smux_mixer
))
872 codec
->patch_ops
.init
= ad1988_auto_init
;
881 AD1988_FIXUP_6STACK_DIG
,
884 static const struct hda_fixup ad1988_fixups
[] = {
885 [AD1988_FIXUP_6STACK_DIG
] = {
886 .type
= HDA_FIXUP_PINS
,
887 .v
.pins
= (const struct hda_pintbl
[]) {
888 { 0x11, 0x02214130 }, /* front-hp */
889 { 0x12, 0x01014010 }, /* line-out */
890 { 0x14, 0x02a19122 }, /* front-mic */
891 { 0x15, 0x01813021 }, /* line-in */
892 { 0x16, 0x01011012 }, /* line-out */
893 { 0x17, 0x01a19020 }, /* mic */
894 { 0x1b, 0x0145f1f0 }, /* SPDIF */
895 { 0x24, 0x01016011 }, /* line-out */
896 { 0x25, 0x01012013 }, /* line-out */
902 static const struct hda_model_fixup ad1988_fixup_models
[] = {
903 { .id
= AD1988_FIXUP_6STACK_DIG
, .name
= "6stack-dig" },
907 static int patch_ad1988(struct hda_codec
*codec
)
909 struct ad198x_spec
*spec
;
912 err
= alloc_ad_spec(codec
);
917 spec
->gen
.mixer_nid
= 0x20;
918 spec
->gen
.mixer_merge_nid
= 0x21;
919 spec
->gen
.beep_nid
= 0x10;
920 set_beep_amp(spec
, 0x10, 0, HDA_OUTPUT
);
922 snd_hda_pick_fixup(codec
, ad1988_fixup_models
, NULL
, ad1988_fixups
);
923 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
925 err
= ad198x_parse_auto_config(codec
, true);
928 err
= ad1988_add_spdif_mux_ctl(codec
);
932 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
937 snd_hda_gen_free(codec
);
945 * port-B - front line/mic-in
946 * port-E - aux in/out
947 * port-F - aux in/out
948 * port-C - rear line/mic-in
949 * port-D - rear line/hp-out
950 * port-A - front line/hp-out
952 * AD1984 = AD1884 + two digital mic-ins
954 * AD1883 / AD1884A / AD1984A / AD1984B
956 * port-B (0x14) - front mic-in
957 * port-E (0x1c) - rear mic-in
958 * port-F (0x16) - CD / ext out
959 * port-C (0x15) - rear line-in
960 * port-D (0x12) - rear line-out
961 * port-A (0x11) - front hp-out
963 * AD1984A = AD1884A + digital-mic
964 * AD1883 = equivalent with AD1984A
965 * AD1984B = AD1984A + extra SPDIF-out
968 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
969 * damage by overloading
971 static void ad1884_fixup_amp_override(struct hda_codec
*codec
,
972 const struct hda_fixup
*fix
, int action
)
974 if (action
== HDA_FIXUP_ACT_PRE_PROBE
)
975 snd_hda_override_amp_caps(codec
, 0x20, HDA_INPUT
,
976 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
977 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
978 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
979 (1 << AC_AMPCAP_MUTE_SHIFT
));
982 /* toggle GPIO1 according to the mute state */
983 static void ad1884_vmaster_hp_gpio_hook(void *private_data
, int enabled
)
985 struct hda_codec
*codec
= private_data
;
986 struct ad198x_spec
*spec
= codec
->spec
;
989 ad_vmaster_eapd_hook(private_data
, enabled
);
990 snd_hda_codec_update_cache(codec
, 0x01, 0,
991 AC_VERB_SET_GPIO_DATA
,
992 enabled
? 0x00 : 0x02);
995 static void ad1884_fixup_hp_eapd(struct hda_codec
*codec
,
996 const struct hda_fixup
*fix
, int action
)
998 struct ad198x_spec
*spec
= codec
->spec
;
999 static const struct hda_verb gpio_init_verbs
[] = {
1000 {0x01, AC_VERB_SET_GPIO_MASK
, 0x02},
1001 {0x01, AC_VERB_SET_GPIO_DIRECTION
, 0x02},
1002 {0x01, AC_VERB_SET_GPIO_DATA
, 0x02},
1007 case HDA_FIXUP_ACT_PRE_PROBE
:
1008 spec
->gen
.vmaster_mute
.hook
= ad1884_vmaster_hp_gpio_hook
;
1009 spec
->gen
.own_eapd_ctl
= 1;
1010 snd_hda_sequence_write_cache(codec
, gpio_init_verbs
);
1012 case HDA_FIXUP_ACT_PROBE
:
1013 if (spec
->gen
.autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
)
1014 spec
->eapd_nid
= spec
->gen
.autocfg
.line_out_pins
[0];
1016 spec
->eapd_nid
= spec
->gen
.autocfg
.speaker_pins
[0];
1021 static void ad1884_fixup_thinkpad(struct hda_codec
*codec
,
1022 const struct hda_fixup
*fix
, int action
)
1024 struct ad198x_spec
*spec
= codec
->spec
;
1026 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
1027 spec
->gen
.keep_eapd_on
= 1;
1028 spec
->gen
.vmaster_mute
.hook
= ad_vmaster_eapd_hook
;
1029 spec
->eapd_nid
= 0x12;
1030 /* Analog PC Beeper - allow firmware/ACPI beeps */
1031 spec
->beep_amp
= HDA_COMPOSE_AMP_VAL(0x20, 3, 3, HDA_INPUT
);
1032 spec
->gen
.beep_nid
= 0; /* no digital beep */
1036 /* set magic COEFs for dmic */
1037 static const struct hda_verb ad1884_dmic_init_verbs
[] = {
1038 {0x01, AC_VERB_SET_COEF_INDEX
, 0x13f7},
1039 {0x01, AC_VERB_SET_PROC_COEF
, 0x08},
1044 AD1884_FIXUP_AMP_OVERRIDE
,
1045 AD1884_FIXUP_HP_EAPD
,
1046 AD1884_FIXUP_DMIC_COEF
,
1047 AD1884_FIXUP_THINKPAD
,
1048 AD1884_FIXUP_HP_TOUCHSMART
,
1051 static const struct hda_fixup ad1884_fixups
[] = {
1052 [AD1884_FIXUP_AMP_OVERRIDE
] = {
1053 .type
= HDA_FIXUP_FUNC
,
1054 .v
.func
= ad1884_fixup_amp_override
,
1056 [AD1884_FIXUP_HP_EAPD
] = {
1057 .type
= HDA_FIXUP_FUNC
,
1058 .v
.func
= ad1884_fixup_hp_eapd
,
1060 .chain_id
= AD1884_FIXUP_AMP_OVERRIDE
,
1062 [AD1884_FIXUP_DMIC_COEF
] = {
1063 .type
= HDA_FIXUP_VERBS
,
1064 .v
.verbs
= ad1884_dmic_init_verbs
,
1066 [AD1884_FIXUP_THINKPAD
] = {
1067 .type
= HDA_FIXUP_FUNC
,
1068 .v
.func
= ad1884_fixup_thinkpad
,
1070 .chain_id
= AD1884_FIXUP_DMIC_COEF
,
1072 [AD1884_FIXUP_HP_TOUCHSMART
] = {
1073 .type
= HDA_FIXUP_VERBS
,
1074 .v
.verbs
= ad1884_dmic_init_verbs
,
1076 .chain_id
= AD1884_FIXUP_HP_EAPD
,
1080 static const struct snd_pci_quirk ad1884_fixup_tbl
[] = {
1081 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART
),
1082 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD
),
1083 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD
),
1088 static int patch_ad1884(struct hda_codec
*codec
)
1090 struct ad198x_spec
*spec
;
1093 err
= alloc_ad_spec(codec
);
1098 spec
->gen
.mixer_nid
= 0x20;
1099 spec
->gen
.mixer_merge_nid
= 0x21;
1100 spec
->gen
.beep_nid
= 0x10;
1101 set_beep_amp(spec
, 0x10, 0, HDA_OUTPUT
);
1103 snd_hda_pick_fixup(codec
, NULL
, ad1884_fixup_tbl
, ad1884_fixups
);
1104 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
1106 err
= ad198x_parse_auto_config(codec
, true);
1109 err
= ad1983_add_spdif_mux_ctl(codec
);
1113 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
1118 snd_hda_gen_free(codec
);
1125 * port-A - front hp-out
1126 * port-B - front mic-in
1127 * port-C - rear line-in, shared surr-out (3stack)
1128 * port-D - rear line-out
1129 * port-E - rear mic-in, shared clfe-out (3stack)
1130 * port-F - rear surr-out (6stack)
1131 * port-G - rear clfe-out (6stack)
1134 static int patch_ad1882(struct hda_codec
*codec
)
1136 struct ad198x_spec
*spec
;
1139 err
= alloc_ad_spec(codec
);
1144 spec
->gen
.mixer_nid
= 0x20;
1145 spec
->gen
.mixer_merge_nid
= 0x21;
1146 spec
->gen
.beep_nid
= 0x10;
1147 set_beep_amp(spec
, 0x10, 0, HDA_OUTPUT
);
1148 err
= ad198x_parse_auto_config(codec
, true);
1151 err
= ad1988_add_spdif_mux_ctl(codec
);
1157 snd_hda_gen_free(codec
);
1165 static const struct hda_codec_preset snd_hda_preset_analog
[] = {
1166 { .id
= 0x11d4184a, .name
= "AD1884A", .patch
= patch_ad1884
},
1167 { .id
= 0x11d41882, .name
= "AD1882", .patch
= patch_ad1882
},
1168 { .id
= 0x11d41883, .name
= "AD1883", .patch
= patch_ad1884
},
1169 { .id
= 0x11d41884, .name
= "AD1884", .patch
= patch_ad1884
},
1170 { .id
= 0x11d4194a, .name
= "AD1984A", .patch
= patch_ad1884
},
1171 { .id
= 0x11d4194b, .name
= "AD1984B", .patch
= patch_ad1884
},
1172 { .id
= 0x11d41981, .name
= "AD1981", .patch
= patch_ad1981
},
1173 { .id
= 0x11d41983, .name
= "AD1983", .patch
= patch_ad1983
},
1174 { .id
= 0x11d41984, .name
= "AD1984", .patch
= patch_ad1884
},
1175 { .id
= 0x11d41986, .name
= "AD1986A", .patch
= patch_ad1986a
},
1176 { .id
= 0x11d41988, .name
= "AD1988", .patch
= patch_ad1988
},
1177 { .id
= 0x11d4198b, .name
= "AD1988B", .patch
= patch_ad1988
},
1178 { .id
= 0x11d4882a, .name
= "AD1882A", .patch
= patch_ad1882
},
1179 { .id
= 0x11d4989a, .name
= "AD1989A", .patch
= patch_ad1988
},
1180 { .id
= 0x11d4989b, .name
= "AD1989B", .patch
= patch_ad1988
},
1184 MODULE_ALIAS("snd-hda-codec-id:11d4*");
1186 MODULE_LICENSE("GPL");
1187 MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1189 static struct hda_codec_preset_list analog_list
= {
1190 .preset
= snd_hda_preset_analog
,
1191 .owner
= THIS_MODULE
,
1194 static int __init
patch_analog_init(void)
1196 return snd_hda_add_codec_preset(&analog_list
);
1199 static void __exit
patch_analog_exit(void)
1201 snd_hda_delete_codec_preset(&analog_list
);
1204 module_init(patch_analog_init
)
1205 module_exit(patch_analog_exit
)