@ -2,6 +2,10 @@
#include <stdbool.h>
#include "console.h"
#include "microwatt_soc.h"
#include "io.h"
#define UART_FREQ 115200
/*
* Core UART functions to implement for a port
@ -9,32 +13,14 @@
static uint64_t potato_uart_base;
#define PROC_FREQ 100000000
#define UART_FREQ 115200
#define UART_BASE 0xc0002000
#define POTATO_CONSOLE_TX 0x00
#define POTATO_CONSOLE_RX 0x08
#define POTATO_CONSOLE_STATUS 0x10
#define POTATO_CONSOLE_STATUS_RX_EMPTY 0x01
#define POTATO_CONSOLE_STATUS_TX_EMPTY 0x02
#define POTATO_CONSOLE_STATUS_RX_FULL 0x04
#define POTATO_CONSOLE_STATUS_TX_FULL 0x08
#define POTATO_CONSOLE_CLOCK_DIV 0x18
#define POTATO_CONSOLE_IRQ_EN 0x20
static uint64_t potato_uart_reg_read(int offset)
{
uint64_t val;
__asm__ volatile("ldcix %0,%1,%2" : "=r" (val) : "b" (potato_uart_base), "r" (offset));
return val;
return readq(potato_uart_base + offset);
}
static void potato_uart_reg_write(int offset, uint64_t val)
{
__asm__ volatile("stdcix %0,%1,%2" : : "r" (val), "b" (potato_uart_base), "r" (offset));
writeq(val, potato_uart_base + offset);
}
static int potato_uart_rx_empty(void)
@ -86,9 +72,12 @@ static unsigned long potato_uart_divisor(unsigned long proc_freq, unsigned long
void potato_uart_init(void)
{
uint64_t proc_freq;
potato_uart_base = UART_BASE;
proc_freq = readq(SYSCON_BASE + SYS_REG_CLKINFO);
potato_uart_reg_write(POTATO_CONSOLE_CLOCK_DIV, potato_uart_divisor(PROC_FREQ, UART_FREQ));
potato_uart_reg_write(POTATO_CONSOLE_CLOCK_DIV, potato_uart_divisor(proc_freq, UART_FREQ));
}
void potato_uart_irq_en(void)