xref: /rk3399_ARM-atf/plat/imx/common/lpuart_console.S (revision 61f72a34250d063da67f4fc2b0eb8c3fda3376be)
1/*
2 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <console_macros.S>
10#include <assert_macros.S>
11#include "imx8_lpuart.h"
12
13	.globl	console_lpuart_register
14	.globl	console_lpuart_init
15	.globl	console_lpuart_putc
16	.globl	console_lpuart_getc
17
18func console_lpuart_register
19	mov	x7, x30
20	mov	x6, x3
21	cbz	x6, register_fail
22	str	x0, [x6, #CONSOLE_T_DRVDATA]
23
24	bl	console_lpuart_init
25	cbz	x0, register_fail
26
27	mov	x0, x6
28	mov	x30, x7
29	finish_console_register lpuart
30
31register_fail:
32	ret	x7
33endfunc console_lpuart_register
34
35func console_lpuart_init
36	mov	w0, #1
37	ret
38endfunc console_lpuart_init
39
40func console_lpuart_putc
41	ldr	x1, [x1, #CONSOLE_T_DRVDATA]
42	cbz	x1, putc_error
43	/* Prepare '\r' to '\n' */
44	cmp	w0, #0xA
45	b.ne	2f
461:
47	/* Check if the transmit FIFO is full */
48	ldr	w2, [x1, #STAT]
49	tbz	w2, #23, 1b
50	mov	w2, #0xD
51	str	w2, [x1, #DATA]
522:
53	/* Check if the transmit FIFO is full */
54	ldr	w2, [x1, #STAT]
55	tbz	w2, #23, 2b
56	str	w0, [x1, #DATA]
57	ret
58putc_error:
59	mov	w0, #-1
60	ret
61endfunc console_lpuart_putc
62
63func console_lpuart_getc
64	ldr	x0, [x0, #CONSOLE_T_DRVDATA]
65	cbz	x0, getc_error
66	/* Check if the receive FIFO state */
67	ret
68getc_error:
69	mov	w0, #-1
70	ret
71endfunc console_lpuart_getc
72