Skip to content

Commit

Permalink
Kernel: Report AC'97 vendor and device ID
Browse files Browse the repository at this point in the history
  • Loading branch information
gmta authored and linusg committed Mar 4, 2022
1 parent 9fcd3f7 commit 4f91616
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Kernel/Devices/Audio/AC97.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,20 @@ UNMAP_AFTER_INIT ErrorOr<void> AC97::initialize()
dbgln_if(AC97_DEBUG, "AC97 @ {}: mixer base: {:#04x}", pci_address(), m_io_mixer_base.get());
dbgln_if(AC97_DEBUG, "AC97 @ {}: bus base: {:#04x}", pci_address(), m_io_bus_base.get());

enable_pin_based_interrupts();
PCI::enable_bus_mastering(pci_address());
// Read out AC'97 codec revision and vendor
auto extended_audio_id = m_io_mixer_base.offset(NativeAudioMixerRegister::ExtendedAudioID).in<u16>();
m_codec_revision = static_cast<AC97Revision>(((extended_audio_id & ExtendedAudioMask::Revision) >> 10) & 0b11);
dbgln_if(AC97_DEBUG, "AC97 @ {}: codec revision {:#02b}", pci_address(), to_underlying(m_codec_revision));
if (m_codec_revision == AC97Revision::Reserved)
return ENOTSUP;

// Report vendor / device ID
u32 vendor_id = m_io_mixer_base.offset(NativeAudioMixerRegister::VendorID1).in<u16>() << 16 | m_io_mixer_base.offset(NativeAudioMixerRegister::VendorID2).in<u16>();
dbgln("AC97 @ {}: Vendor ID: {:#8x}", pci_address(), vendor_id);

// Bus cold reset, enable interrupts
enable_pin_based_interrupts();
PCI::enable_bus_mastering(pci_address());
auto control = m_io_bus_base.offset(NativeAudioBusRegister::GlobalControl).in<u32>();
control |= GlobalControlFlag::GPIInterruptEnable;
control |= GlobalControlFlag::AC97ColdReset;
Expand All @@ -90,13 +100,6 @@ UNMAP_AFTER_INIT ErrorOr<void> AC97::initialize()
// Reset mixer
m_io_mixer_base.offset(NativeAudioMixerRegister::Reset).out<u16>(1);

// Read out AC'97 codec revision
auto extended_audio_id = m_io_mixer_base.offset(NativeAudioMixerRegister::ExtendedAudioID).in<u16>();
m_codec_revision = static_cast<AC97Revision>(((extended_audio_id & ExtendedAudioMask::Revision) >> 10) & 0b11);
dbgln_if(AC97_DEBUG, "AC97 @ {}: codec revision {:#02b}", pci_address(), to_underlying(m_codec_revision));
if (m_codec_revision == AC97Revision::Reserved)
return ENOTSUP;

// Enable variable and double rate PCM audio if supported
auto extended_audio_status_control_register = m_io_mixer_base.offset(NativeAudioMixerRegister::ExtendedAudioStatusControl);
auto extended_audio_status = extended_audio_status_control_register.in<u16>();
Expand Down
2 changes: 2 additions & 0 deletions Kernel/Devices/Audio/AC97.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class AC97 final
ExtendedAudioID = 0x28,
ExtendedAudioStatusControl = 0x2a,
PCMFrontDACRate = 0x2c,
VendorID1 = 0x7c,
VendorID2 = 0x7e,
};

enum ExtendedAudioMask : u16 {
Expand Down

0 comments on commit 4f91616

Please sign in to comment.