5 #include "microwatt_soc.h"
8 #define UART_FREQ 115200
11 * Core UART functions to implement for a port
14 static uint64_t potato_uart_base
;
16 static uint64_t potato_uart_reg_read(int offset
)
18 return readq(potato_uart_base
+ offset
);
21 static void potato_uart_reg_write(int offset
, uint64_t val
)
23 writeq(val
, potato_uart_base
+ offset
);
26 static int potato_uart_rx_empty(void)
30 val
= potato_uart_reg_read(POTATO_CONSOLE_STATUS
);
32 if (val
& POTATO_CONSOLE_STATUS_RX_EMPTY
)
38 static int potato_uart_tx_full(void)
42 val
= potato_uart_reg_read(POTATO_CONSOLE_STATUS
);
44 if (val
& POTATO_CONSOLE_STATUS_TX_FULL
)
50 static char potato_uart_read(void)
54 val
= potato_uart_reg_read(POTATO_CONSOLE_RX
);
56 return (char)(val
& 0x000000ff);
59 static void potato_uart_write(char c
)
65 potato_uart_reg_write(POTATO_CONSOLE_TX
, val
);
68 static unsigned long potato_uart_divisor(unsigned long proc_freq
, unsigned long uart_freq
)
70 return proc_freq
/ (uart_freq
* 16) - 1;
73 void potato_uart_init(void)
77 potato_uart_base
= UART_BASE
;
78 proc_freq
= readq(SYSCON_BASE
+ SYS_REG_CLKINFO
);
80 potato_uart_reg_write(POTATO_CONSOLE_CLOCK_DIV
, potato_uart_divisor(proc_freq
, UART_FREQ
));
83 void potato_uart_irq_en(void)
85 potato_uart_reg_write(POTATO_CONSOLE_IRQ_EN
, 0xff);
88 void potato_uart_irq_dis(void)
90 potato_uart_reg_write(POTATO_CONSOLE_IRQ_EN
, 0x00);
95 while (potato_uart_rx_empty())
98 return potato_uart_read();
103 while (potato_uart_tx_full())
106 potato_uart_write(c
);
110 int puts(const char *str
)
114 for (i
= 0; *str
; i
++) {
123 size_t strlen(const char *s
)