1 /*
2  * Copyright 2014, General Dynamics C4 Systems
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 URXD  0x00 /* UART Receiver Register */
14 #define UTXD  0x40 /* UART Transmitter Register */
15 #define UCR1  0x80 /* UART Control Register 1 */
16 #define UCR2  0x84 /* UART Control Register 2 */
17 #define UCR3  0x88 /* UART Control Register 3 */
18 #define UCR4  0x8c /* UART Control Register 4 */
19 #define UFCR  0x90 /* UART FIFO Control Register */
20 #define USR1  0x94 /* UART Status Register 1 */
21 #define USR2  0x98 /* UART Status Register 2 */
22 #define UESC  0x9c /* UART Escape Character Register */
23 #define UTIM  0xa0 /* UART Escape Timer Register */
24 #define UBIR  0xa4 /* UART BRM Incremental Register */
25 #define UBMR  0xa8 /* UART BRM Modulator Register */
26 #define UBRC  0xac /* UART Baud Rate Counter Register */
27 #define ONEMS 0xb0 /* UART One Millisecond Register */
28 #define UTS   0xb4 /* UART Test Register */
29 
30 #define UART_SR1_TRDY         BIT(13)
31 #define UART_SR1_RRDY         BIT(9)
32 #define UART_SR2_TXFIFO_EMPTY BIT(14)
33 #define UART_SR2_RXFIFO_RDR   BIT(0)
34 
35 #define UART_REG(x) ((volatile uint32_t *)(UART_PPTR + (x)))
36 
37 #ifdef CONFIG_PRINTING
uart_drv_putchar(unsigned char c)38 void uart_drv_putchar(unsigned char c)
39 {
40     while (!(*UART_REG(USR2) & UART_SR2_TXFIFO_EMPTY));
41     *UART_REG(UTXD) = c;
42 }
43 #endif /* CONFIG_PRINTING */
44 
45 #ifdef CONFIG_DEBUG_BUILD
uart_drv_getchar(void)46 unsigned char uart_drv_getchar(void)
47 {
48     while (!(*UART_REG(USR2) & UART_SR2_RXFIFO_RDR));
49     return *UART_REG(URXD);
50 }
51 #endif /* CONFIG_DEBUG_BUILD */
52