1 /*
2  * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3  *
4  * SPDX-License-Identifier: GPL-2.0-only
5  */
6 
7 #include <config.h>
8 #include <stdint.h>
9 #include <util.h>
10 #include <machine/io.h>
11 #include <plat/machine/devices_gen.h>
12 
13 #define UART_WFIFO  0x0
14 #define UART_RFIFO  0x4
15 #define UART_STATUS 0xC
16 
17 #define UART_TX_FULL        BIT(21)
18 #define UART_RX_EMPTY       BIT(20)
19 
20 #define UART_REG(x) ((volatile uint32_t *)(UART_PPTR + (x)))
21 
22 #ifdef CONFIG_PRINTING
uart_drv_putchar(unsigned char c)23 void uart_drv_putchar(unsigned char c)
24 {
25     while ((*UART_REG(UART_STATUS) & UART_TX_FULL));
26 
27     /* Add character to the buffer. */
28     *UART_REG(UART_WFIFO) = c;
29 }
30 #endif /* CONFIG_PRINTING */
31 
32 #ifdef CONFIG_DEBUG_BUILD
uart_drv_getchar(void)33 unsigned char uart_drv_getchar(void)
34 {
35     while ((*UART_REG(UART_STATUS) & UART_RX_EMPTY));
36     return *UART_REG(UART_RFIFO);
37 }
38 #endif /* CONFIG_DEBUG_BUILD */
39