mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
Kernel: Update SB16 driver to use the new IRQHandler class
Also, add methods to allow changing of IRQ line in the SB16 card.
This commit is contained in:
parent
895e874eb4
commit
c51a57fb32
Notes:
sideshowbarker
2024-07-19 09:06:19 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/c51a57fb320 Pull-request: https://github.com/SerenityOS/serenity/pull/1274 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/shannonbooth
2 changed files with 58 additions and 5 deletions
|
@ -33,6 +33,7 @@
|
|||
//#define SB16_DEBUG
|
||||
|
||||
namespace Kernel {
|
||||
#define SB16_DEFAULT_IRQ 5
|
||||
|
||||
enum class SampleFormat : u8 {
|
||||
Signed = 0x10,
|
||||
|
@ -76,7 +77,7 @@ void SB16::set_sample_rate(uint16_t hz)
|
|||
static SB16* s_the;
|
||||
|
||||
SB16::SB16()
|
||||
: IRQHandler(5)
|
||||
: IRQHandler(SB16_DEFAULT_IRQ)
|
||||
, CharacterDevice(42, 42) // ### ?
|
||||
{
|
||||
s_the = this;
|
||||
|
@ -112,6 +113,56 @@ void SB16::initialize()
|
|||
auto vmin = dsp_read();
|
||||
|
||||
kprintf("SB16: found version %d.%d\n", m_major_version, vmin);
|
||||
set_irq_register(SB16_DEFAULT_IRQ);
|
||||
kprintf("SB16: IRQ %d\n", get_irq_line());
|
||||
}
|
||||
|
||||
void SB16::set_irq_register(u8 irq_number)
|
||||
{
|
||||
u8 bitmask;
|
||||
switch (irq_number) {
|
||||
case 2:
|
||||
bitmask = 0;
|
||||
break;
|
||||
case 5:
|
||||
bitmask = 0b10;
|
||||
break;
|
||||
case 7:
|
||||
bitmask = 0b100;
|
||||
break;
|
||||
case 10:
|
||||
bitmask = 0b1000;
|
||||
break;
|
||||
default:
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
IO::out8(0x224, 0x80);
|
||||
IO::out8(0x225, bitmask);
|
||||
}
|
||||
|
||||
u8 SB16::get_irq_line()
|
||||
{
|
||||
IO::out8(0x224, 0x80);
|
||||
u8 bitmask = IO::in8(0x225);
|
||||
switch (bitmask) {
|
||||
case 0:
|
||||
return 2;
|
||||
case 0b10:
|
||||
return 5;
|
||||
case 0b100:
|
||||
return 7;
|
||||
case 0b1000:
|
||||
return 10;
|
||||
}
|
||||
return bitmask;
|
||||
}
|
||||
void SB16::set_irq_line(u8 irq_number)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
if (irq_number == get_irq_line())
|
||||
return;
|
||||
set_irq_register(irq_number);
|
||||
change_irq_number(irq_number);
|
||||
}
|
||||
|
||||
bool SB16::can_read(const FileDescription&) const
|
||||
|
@ -155,7 +206,7 @@ void SB16::dma_start(uint32_t length)
|
|||
IO::out8(0xd4, (channel % 4));
|
||||
}
|
||||
|
||||
void SB16::handle_irq()
|
||||
void SB16::handle_irq(RegisterState&)
|
||||
{
|
||||
// Stop sound output ready for the next block.
|
||||
dsp_write(0xd5);
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <Kernel/Devices/CharacterDevice.h>
|
||||
#include <Kernel/IRQHandler.h>
|
||||
#include <Kernel/Interrupts/IRQHandler.h>
|
||||
#include <Kernel/VM/PhysicalPage.h>
|
||||
#include <Kernel/WaitQueue.h>
|
||||
#include <LibBareMetal/Memory/PhysicalAddress.h>
|
||||
|
@ -52,7 +52,7 @@ public:
|
|||
|
||||
private:
|
||||
// ^IRQHandler
|
||||
virtual void handle_irq() override;
|
||||
virtual void handle_irq(RegisterState&) override;
|
||||
|
||||
// ^CharacterDevice
|
||||
virtual const char* class_name() const override { return "SB16"; }
|
||||
|
@ -63,11 +63,13 @@ private:
|
|||
void set_sample_rate(uint16_t hz);
|
||||
void dsp_write(u8 value);
|
||||
u8 dsp_read();
|
||||
u8 get_irq_line();
|
||||
void set_irq_register(u8 irq_number);
|
||||
void set_irq_line(u8 irq_number);
|
||||
|
||||
OwnPtr<Region> m_dma_region;
|
||||
int m_major_version { 0 };
|
||||
|
||||
WaitQueue m_irq_queue;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue