xref: /rk3399_ARM-atf/plat/socionext/uniphier/uniphier_console.S (revision 36cfbf3ca28be833116a1ac7c7c1b98da50db95a)
1/*
2 * Copyright (c) 2017-2019, 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_DRVDATA]
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	mov	w2, w0
27
281:	str	w2, [x1, #UNIPHIER_UART_TX]
29
30	cmp	w2, #'\n'
31	b.ne	2f
32	mov	w2, #'\r'	/* Append '\r' to '\n' */
33	b	1b
342:	ret
35endfunc uniphier_console_putc
36
37/*
38 * In: x0 - pointer to console structure
39 * Out: return the character read, or ERROR_NO_PENDING_CHAR if no character
40	is available
41 * Clobber: x1
42 */
43	.globl	uniphier_console_getc
44func uniphier_console_getc
45	ldr	x0, [x0, #CONSOLE_T_DRVDATA]
46
47	ldr	w1, [x0, #UNIPHIER_UART_LSR]
48	tbz	w1, #UNIPHIER_UART_LSR_DR_BIT, 0f
49
50	ldr	w0, [x0, #UNIPHIER_UART_RX]
51	ret
52
530:	mov	w0, #ERROR_NO_PENDING_CHAR
54	ret
55endfunc uniphier_console_getc
56
57/*
58 * In: x0 - pointer to console structure
59 * Out: return 0 (always succeeds)
60 * Clobber: x1
61 */
62	.global uniphier_console_flush
63func uniphier_console_flush
64	ldr	x0, [x0, #CONSOLE_T_DRVDATA]
65
66	/* wait until the transmitter gets empty */
670:	ldr	w1, [x0, #UNIPHIER_UART_LSR]
68	tbz	w1, #UNIPHIER_UART_LSR_TEMT_BIT, 0b
69
70	mov	w0, #0
71	ret
72endfunc uniphier_console_flush
73