xref: /rk3399_ARM-atf/plat/imx/common/imx_uart_console.S (revision 2e8ab4f538032dda4f0c3e69e3d94c6f37a9bd25)
181136819SBai Ping/*
2*2e8ab4f5SAnson Huang * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
381136819SBai Ping *
481136819SBai Ping * SPDX-License-Identifier: BSD-3-Clause
581136819SBai Ping */
681136819SBai Ping
781136819SBai Ping#include <arch.h>
881136819SBai Ping#include <asm_macros.S>
981136819SBai Ping#define USE_FINISH_CONSOLE_REG_2
1081136819SBai Ping#include <console_macros.S>
1181136819SBai Ping#include <assert_macros.S>
1281136819SBai Ping#include "imx_uart.h"
1381136819SBai Ping
1481136819SBai Ping#define URXD  0x0  /* Receiver Register */
1581136819SBai Ping#define UTXD  0x40 /* Transmitter Register */
1681136819SBai Ping#define UTS   0xb4 /* UART Test Register (mx31) */
1781136819SBai Ping#define  URXD_RX_DATA    (0xFF)
1881136819SBai Ping
19*2e8ab4f5SAnson Huang	.globl	console_imx_uart_register
20*2e8ab4f5SAnson Huang	.globl	console_imx_uart_init
21*2e8ab4f5SAnson Huang	.globl	console_imx_uart_putc
22*2e8ab4f5SAnson Huang	.globl	console_imx_uart_getc
23*2e8ab4f5SAnson Huang	.globl	console_imx_uart_flush
2481136819SBai Ping
2581136819SBai Pingfunc console_imx_uart_register
2681136819SBai Ping	mov	x7, x30
2781136819SBai Ping	mov	x6, x3
2881136819SBai Ping	cbz	x6, register_fail
2981136819SBai Ping	str	x0, [x6, #CONSOLE_T_DRVDATA]
3081136819SBai Ping
3181136819SBai Ping	bl	console_imx_uart_init
3281136819SBai Ping	cbz	x0, register_fail
3381136819SBai Ping
3481136819SBai Ping	mov	x0, x6
3581136819SBai Ping	mov	x30, x7
36*2e8ab4f5SAnson Huang	finish_console_register imx_uart putc=1, getc=1, flush=1
3781136819SBai Ping
3881136819SBai Pingregister_fail:
3981136819SBai Ping	ret	x7
4081136819SBai Pingendfunc console_imx_uart_register
4181136819SBai Ping
4281136819SBai Pingfunc console_imx_uart_init
4381136819SBai Ping	mov	w0, #1
4481136819SBai Ping	ret
4581136819SBai Pingendfunc console_imx_uart_init
4681136819SBai Ping
4781136819SBai Pingfunc console_imx_uart_putc
4881136819SBai Ping	ldr	x1, [x1, #CONSOLE_T_DRVDATA]
4981136819SBai Ping	cbz	x1, putc_error
5081136819SBai Ping
5181136819SBai Ping	/* Prepare '\r' to '\n' */
5281136819SBai Ping	cmp	w0, #0xA
5381136819SBai Ping	b.ne	2f
5481136819SBai Ping1:
5581136819SBai Ping	/* Check if the transmit FIFO is full */
5681136819SBai Ping	ldr	w2, [x1, #UTS]
5781136819SBai Ping	tbz	w2, #6, 1b
5881136819SBai Ping	mov	w2, #0xD
5981136819SBai Ping	str	w2, [x1, #UTXD]
6081136819SBai Ping2:
6181136819SBai Ping	/* Check if the transmit FIFO is full */
6281136819SBai Ping	ldr	w2, [x1, #UTS]
6381136819SBai Ping	tbz	w2, #6, 2b
6481136819SBai Ping	str	w0, [x1, #UTXD]
6581136819SBai Ping	ret
6681136819SBai Pingputc_error:
6781136819SBai Ping	mov	w0, #-1
6881136819SBai Ping	ret
6981136819SBai Pingendfunc console_imx_uart_putc
7081136819SBai Ping
7181136819SBai Pingfunc console_imx_uart_getc
7281136819SBai Ping	ldr	x0, [x0, #CONSOLE_T_DRVDATA]
7381136819SBai Ping	cbz	x0, getc_error
7481136819SBai Ping1:
7581136819SBai Ping	ldr	w1, [x0, #UTS]
7681136819SBai Ping	tbnz	w1, #5, 1b
7781136819SBai Ping
7881136819SBai Ping	ldr	w1, [x0, #URXD]
7981136819SBai Ping	and	w0, w1, #URXD_RX_DATA
8081136819SBai Ping
8181136819SBai Ping	ret
8281136819SBai Pinggetc_error:
8381136819SBai Ping	mov	w0, #-1
8481136819SBai Ping	ret
8581136819SBai Pingendfunc console_imx_uart_getc
86*2e8ab4f5SAnson Huang
87*2e8ab4f5SAnson Huangfunc console_imx_uart_flush
88*2e8ab4f5SAnson Huang	mov	x0, #0
89*2e8ab4f5SAnson Huang	ret
90*2e8ab4f5SAnson Huangendfunc console_imx_uart_flush
91