xref: /rk3399_ARM-atf/plat/imx/common/imx_uart_console.S (revision 6627de53203516daaa7958751ecbd45d3c4d634a)
181136819SBai Ping/*
22e8ab4f5SAnson 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#include <console_macros.S>
1081136819SBai Ping#include <assert_macros.S>
1181136819SBai Ping#include "imx_uart.h"
1281136819SBai Ping
1381136819SBai Ping#define URXD  0x0  /* Receiver Register */
1481136819SBai Ping#define UTXD  0x40 /* Transmitter Register */
1581136819SBai Ping#define UTS   0xb4 /* UART Test Register (mx31) */
1681136819SBai Ping#define  URXD_RX_DATA    (0xFF)
1781136819SBai Ping
182e8ab4f5SAnson Huang	.globl	console_imx_uart_register
192e8ab4f5SAnson Huang	.globl	console_imx_uart_init
202e8ab4f5SAnson Huang	.globl	console_imx_uart_putc
212e8ab4f5SAnson Huang	.globl	console_imx_uart_getc
222e8ab4f5SAnson Huang	.globl	console_imx_uart_flush
2381136819SBai Ping
2481136819SBai Pingfunc console_imx_uart_register
2581136819SBai Ping	mov	x7, x30
2681136819SBai Ping	mov	x6, x3
2781136819SBai Ping	cbz	x6, register_fail
28*6627de53SAndre Przywara	str	x0, [x6, #CONSOLE_T_BASE]
2981136819SBai Ping
3081136819SBai Ping	bl	console_imx_uart_init
3181136819SBai Ping	cbz	x0, register_fail
3281136819SBai Ping
3381136819SBai Ping	mov	x0, x6
3481136819SBai Ping	mov	x30, x7
352e8ab4f5SAnson Huang	finish_console_register imx_uart putc=1, getc=1, flush=1
3681136819SBai Ping
3781136819SBai Pingregister_fail:
3881136819SBai Ping	ret	x7
3981136819SBai Pingendfunc console_imx_uart_register
4081136819SBai Ping
4181136819SBai Pingfunc console_imx_uart_init
4281136819SBai Ping	mov	w0, #1
4381136819SBai Ping	ret
4481136819SBai Pingendfunc console_imx_uart_init
4581136819SBai Ping
4681136819SBai Pingfunc console_imx_uart_putc
47*6627de53SAndre Przywara	ldr	x1, [x1, #CONSOLE_T_BASE]
4881136819SBai Ping	cbz	x1, putc_error
4981136819SBai Ping
5081136819SBai Ping	/* Prepare '\r' to '\n' */
5181136819SBai Ping	cmp	w0, #0xA
5281136819SBai Ping	b.ne	2f
5381136819SBai Ping1:
5481136819SBai Ping	/* Check if the transmit FIFO is full */
5581136819SBai Ping	ldr	w2, [x1, #UTS]
5681136819SBai Ping	tbz	w2, #6, 1b
5781136819SBai Ping	mov	w2, #0xD
5881136819SBai Ping	str	w2, [x1, #UTXD]
5981136819SBai Ping2:
6081136819SBai Ping	/* Check if the transmit FIFO is full */
6181136819SBai Ping	ldr	w2, [x1, #UTS]
6281136819SBai Ping	tbz	w2, #6, 2b
6381136819SBai Ping	str	w0, [x1, #UTXD]
6481136819SBai Ping	ret
6581136819SBai Pingputc_error:
6681136819SBai Ping	mov	w0, #-1
6781136819SBai Ping	ret
6881136819SBai Pingendfunc console_imx_uart_putc
6981136819SBai Ping
7081136819SBai Pingfunc console_imx_uart_getc
71*6627de53SAndre Przywara	ldr	x0, [x0, #CONSOLE_T_BASE]
7281136819SBai Ping	cbz	x0, getc_error
7381136819SBai Ping1:
7481136819SBai Ping	ldr	w1, [x0, #UTS]
7581136819SBai Ping	tbnz	w1, #5, 1b
7681136819SBai Ping
7781136819SBai Ping	ldr	w1, [x0, #URXD]
7881136819SBai Ping	and	w0, w1, #URXD_RX_DATA
7981136819SBai Ping
8081136819SBai Ping	ret
8181136819SBai Pinggetc_error:
8281136819SBai Ping	mov	w0, #-1
8381136819SBai Ping	ret
8481136819SBai Pingendfunc console_imx_uart_getc
852e8ab4f5SAnson Huang
862e8ab4f5SAnson Huangfunc console_imx_uart_flush
872e8ab4f5SAnson Huang	mov	x0, #0
882e8ab4f5SAnson Huang	ret
892e8ab4f5SAnson Huangendfunc console_imx_uart_flush
90