1/*
2 * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <asm_macros.S>
8#include <drivers/console.h>
9
10#include "uniphier_console.h"
11
12/*
13 * In: w0 - character to be printed
14 *     x1 - pointer to console structure
15 * Out: return the character written (always succeeds)
16 * Clobber: x2
17 */
18	.globl	uniphier_console_putc
19func uniphier_console_putc
20	ldr	x1, [x1, #CONSOLE_T_BASE]
21
22	/* Wait until the transmitter FIFO gets empty */
230:	ldr	w2, [x1, #UNIPHIER_UART_LSR]
24	tbz	w2, #UNIPHIER_UART_LSR_THRE_BIT, 0b
25
26	str	w0, [x1, #UNIPHIER_UART_TX]
27
28	ret
29endfunc uniphier_console_putc
30
31/*
32 * In: x0 - pointer to console structure
33 * Out: return the character read, or ERROR_NO_PENDING_CHAR if no character
34	is available
35 * Clobber: x1
36 */
37	.globl	uniphier_console_getc
38func uniphier_console_getc
39	ldr	x0, [x0, #CONSOLE_T_BASE]
40
41	ldr	w1, [x0, #UNIPHIER_UART_LSR]
42	tbz	w1, #UNIPHIER_UART_LSR_DR_BIT, 0f
43
44	ldr	w0, [x0, #UNIPHIER_UART_RX]
45	ret
46
470:	mov	w0, #ERROR_NO_PENDING_CHAR
48	ret
49endfunc uniphier_console_getc
50
51/*
52 * In: x0 - pointer to console structure
53 * Out: return 0 (always succeeds)
54 * Clobber: x1
55 */
56	.global uniphier_console_flush
57func uniphier_console_flush
58	ldr	x0, [x0, #CONSOLE_T_BASE]
59
60	/* wait until the transmitter gets empty */
610:	ldr	w1, [x0, #UNIPHIER_UART_LSR]
62	tbz	w1, #UNIPHIER_UART_LSR_TEMT_BIT, 0b
63
64	ret
65endfunc uniphier_console_flush
66