Skip to content

Commit

Permalink
Merge branch 'ad1980' of https://github.com/thp/sbemu into thp-ad1980
Browse files Browse the repository at this point in the history
  • Loading branch information
crazii committed Nov 18, 2023
2 parents 735c8c0 + 3a2c1dd commit 0459593
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mpxplay/au_cards/sc_ich.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
#include "pcibios.h"
#include "ac97_def.h"

// https://www.analog.com/media/en/technical-documentation/data-sheets/AD1980.pdf
#define AC97_VENDOR_ID1_AD 0x4144 /* 'A' 'D' */
#define AC97_VENDOR_ID2_AD1980 0x5370 /* 'S' + 0x70 for AD1980 */
#define AC97_AD_MISC 0x76 /* Misc Control Bits */
#define AC97_AD_MISC_AC97NC 0x4000 /* AC'97 No Compatibility Mode (aka ADI compatibility mode) */
#define AC97_AD_MISC_HPSEL 0x0400 /* Headphone Amplifier Input Select */
#define AC97_AD_MISC_LOSEL 0x0020 /* LINE_OUT Amplifiers Input Select */

#define ICH_PO_CR_REG 0x1b // PCM out Control Register
#define ICH_PO_CR_START 0x01 // start codec
#define ICH_PO_CR_RESET 0x02 // reset codec
Expand Down Expand Up @@ -321,6 +329,18 @@ static void snd_intel_prepare_playback(struct intel_card_s *card,struct mpxplay_
snd_intel_codec_write(card,AC97_SPDIF_CONTROL,cmd);
pds_delay_10us(10);

uint16_t vendor_id1 = snd_intel_codec_read(card, AC97_VENDOR_ID1);
uint16_t vendor_id2 = snd_intel_codec_read(card, AC97_VENDOR_ID2);

// Analog Devices AD1980: Fix audio routing (set AC97NC, HPSEL and LOSEL bits)
// Thanks to dr.zeissler on the Vogons forum for providing register dumps + testing
// https://www.analog.com/media/en/technical-documentation/data-sheets/AD1980.pdf
// https://cgit.freebsd.org/src/tree/sys/dev/sound/pcm/ac97_patch.c#n49
// https://github.com/torvalds/linux/blob/master/sound/soc/codecs/ad1980.c#L133
if (vendor_id1 == AC97_VENDOR_ID1_AD && vendor_id2 == AC97_VENDOR_ID2_AD1980) {
snd_intel_codec_write(card, AC97_AD_MISC, AC97_AD_MISC_AC97NC | AC97_AD_MISC_HPSEL | AC97_AD_MISC_LOSEL);
}

//set analog ac97 freq
mpxplay_debugf(ICH_DEBUG_OUTPUT,"AC97 front dac freq:%d ",aui->freq_card);
if(card->ac97_clock_corrector){
Expand Down

0 comments on commit 0459593

Please sign in to comment.