#include <arch/generic/debug_uart.h>
#include <arch/arm64/arch_uart_samsung.h>
#include <new>
#define ULCON 0x00
#define UCON 0x04
#define UFCON 0x08
#define UTRSTAT 0x10
#define UFSTAT 0x18
#define UTXH 0x20
#define URXH 0x24
#define UBRDIV 0x28
#define UCON_TXTHRESH_ENA (1 << 13)
#define UCON_RXTHRESH_ENA (1 << 12)
#define UCON_RXTO_ENA (1 << 9)
#define UCON_TXMODE (3 << 2)
#define UCON_RXMODE (3 << 0)
#define UCON_MODE_OFF 0
#define UCON_MODE_IRQ 1
#define UTRSTAT_RXTO (1 << 9)
#define UTRSTAT_TXTHRESH (1 << 5)
#define UTRSTAT_RXTHRESH (1 << 4)
#define UTRSTAT_TXE (1 << 2)
#define UTRSTAT_TXBE (1 << 1)
#define UTRSTAT_RXD (1 << 0)
#define UFSTAT_TXFULL (1 << 9)
#define UFSTAT_RXFULL (1 << 8)
#define UFSTAT_TXCNT (15 << 4)
#define UFSTAT_RXCNT (15 << 0)
ArchUARTSamsung::ArchUARTSamsung(addr_t base, int64 clock)
:
DebugUART(base, clock)
{
}
ArchUARTSamsung::~ArchUARTSamsung()
{
}
void
ArchUARTSamsung::Out32(int reg, uint32 data)
{
*(volatile uint32*)(Base() + reg) = data;
}
uint32
ArchUARTSamsung::In32(int reg)
{
return *(volatile uint32*)(Base() + reg);
}
void
ArchUARTSamsung::InitPort(uint32 baud)
{
}
void
ArchUARTSamsung::Enable()
{
DebugUART::Enable();
}
void
ArchUARTSamsung::Disable()
{
DebugUART::Disable();
}
int
ArchUARTSamsung::PutChar(char c)
{
if (Enabled()) {
while ((In32(UFSTAT) & UFSTAT_TXFULL) != 0)
;
Out32(UTXH, c);
return 0;
}
return -1;
}
int
ArchUARTSamsung::GetChar(bool wait)
{
if (Enabled()) {
while (wait && ((In32(UFSTAT) & UFSTAT_RXCNT) == 0))
;
if ((In32(UFSTAT) & UFSTAT_RXCNT) == 0)
return -1;
return In32(URXH);
}
return -1;
}
void
ArchUARTSamsung::FlushTx()
{
}
void
ArchUARTSamsung::FlushRx()
{
}
ArchUARTSamsung*
arch_get_uart_samsung(addr_t base, int64 clock)
{
static char buffer[sizeof(ArchUARTSamsung)];
ArchUARTSamsung* uart = new(buffer) ArchUARTSamsung(base, clock);
return uart;
}