uniphier_console.S 1.5 KB
Newer Older
1
/*
2
 * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#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
15
 *     x1 - pointer to console structure
 * Out: return the character written (always succeeds)
16
17
 * Clobber: x2
 */
18
19
20
	.globl	uniphier_console_putc
func uniphier_console_putc
	ldr	x1, [x1, #CONSOLE_T_DRVDATA]
21
22
23
24
25
26
27
28
29
30

	/* Wait until the transmitter FIFO gets empty */
0:	ldr	w2, [x1, #UNIPHIER_UART_LSR]
	tbz	w2, #UNIPHIER_UART_LSR_THRE_BIT, 0b

	mov	w2, w0

1:	str	w2, [x1, #UNIPHIER_UART_TX]

	cmp	w2, #'\n'
31
	b.ne	2f
32
33
	mov	w2, #'\r'	/* Append '\r' to '\n' */
	b	1b
34
35
2:	ret
endfunc uniphier_console_putc
36
37

/*
38
39
40
 * In: x0 - pointer to console structure
 * Out: return the character read, or ERROR_NO_PENDING_CHAR if no character
	is available
41
42
 * Clobber: x1
 */
43
44
45
	.globl	uniphier_console_getc
func uniphier_console_getc
	ldr	x0, [x0, #CONSOLE_T_DRVDATA]
46

47
48
	ldr	w1, [x0, #UNIPHIER_UART_LSR]
	tbz	w1, #UNIPHIER_UART_LSR_DR_BIT, 0f
49
50
51

	ldr	w0, [x0, #UNIPHIER_UART_RX]
	ret
52
53

0:	mov	w0, #ERROR_NO_PENDING_CHAR
54
	ret
55
endfunc uniphier_console_getc
56
57

/*
58
59
 * In: x0 - pointer to console structure
 * Out: return 0 (always succeeds)
60
61
 * Clobber: x1
 */
62
63
64
	.global uniphier_console_flush
func uniphier_console_flush
	ldr	x0, [x0, #CONSOLE_T_DRVDATA]
65
66
67
68
69
70
71

	/* wait until the transmitter gets empty */
0:	ldr	w1, [x0, #UNIPHIER_UART_LSR]
	tbz	w1, #UNIPHIER_UART_LSR_TEMT_BIT, 0b

	mov	w0, #0
	ret
72
endfunc uniphier_console_flush