xref: /rk3399_ARM-atf/plat/imx/common/imx_uart_console.S (revision 81136819928e373f7753b88d81fa5c11700b11e1)
1*81136819SBai Ping/*
2*81136819SBai Ping * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3*81136819SBai Ping *
4*81136819SBai Ping * SPDX-License-Identifier: BSD-3-Clause
5*81136819SBai Ping */
6*81136819SBai Ping
7*81136819SBai Ping#include <arch.h>
8*81136819SBai Ping#include <asm_macros.S>
9*81136819SBai Ping#define USE_FINISH_CONSOLE_REG_2
10*81136819SBai Ping#include <console_macros.S>
11*81136819SBai Ping#include <assert_macros.S>
12*81136819SBai Ping#include "imx_uart.h"
13*81136819SBai Ping
14*81136819SBai Ping#define URXD  0x0  /* Receiver Register */
15*81136819SBai Ping#define UTXD  0x40 /* Transmitter Register */
16*81136819SBai Ping#define UTS   0xb4 /* UART Test Register (mx31) */
17*81136819SBai Ping#define  URXD_RX_DATA    (0xFF)
18*81136819SBai Ping
19*81136819SBai Ping	.globl	console_uart_register
20*81136819SBai Ping	.globl	console_uart_init
21*81136819SBai Ping	.globl	console_uart_putc
22*81136819SBai Ping	.globl	console_uart_getc
23*81136819SBai Ping
24*81136819SBai Pingfunc console_imx_uart_register
25*81136819SBai Ping	mov	x7, x30
26*81136819SBai Ping	mov	x6, x3
27*81136819SBai Ping	cbz	x6, register_fail
28*81136819SBai Ping	str	x0, [x6, #CONSOLE_T_DRVDATA]
29*81136819SBai Ping
30*81136819SBai Ping	bl	console_imx_uart_init
31*81136819SBai Ping	cbz	x0, register_fail
32*81136819SBai Ping
33*81136819SBai Ping	mov	x0, x6
34*81136819SBai Ping	mov	x30, x7
35*81136819SBai Ping	finish_console_register imx_uart putc=1, getc=1
36*81136819SBai Ping
37*81136819SBai Pingregister_fail:
38*81136819SBai Ping	ret	x7
39*81136819SBai Pingendfunc console_imx_uart_register
40*81136819SBai Ping
41*81136819SBai Pingfunc console_imx_uart_init
42*81136819SBai Ping	mov	w0, #1
43*81136819SBai Ping	ret
44*81136819SBai Pingendfunc console_imx_uart_init
45*81136819SBai Ping
46*81136819SBai Pingfunc console_imx_uart_putc
47*81136819SBai Ping	ldr	x1, [x1, #CONSOLE_T_DRVDATA]
48*81136819SBai Ping	cbz	x1, putc_error
49*81136819SBai Ping
50*81136819SBai Ping	/* Prepare '\r' to '\n' */
51*81136819SBai Ping	cmp	w0, #0xA
52*81136819SBai Ping	b.ne	2f
53*81136819SBai Ping1:
54*81136819SBai Ping	/* Check if the transmit FIFO is full */
55*81136819SBai Ping	ldr	w2, [x1, #UTS]
56*81136819SBai Ping	tbz	w2, #6, 1b
57*81136819SBai Ping	mov	w2, #0xD
58*81136819SBai Ping	str	w2, [x1, #UTXD]
59*81136819SBai Ping2:
60*81136819SBai Ping	/* Check if the transmit FIFO is full */
61*81136819SBai Ping	ldr	w2, [x1, #UTS]
62*81136819SBai Ping	tbz	w2, #6, 2b
63*81136819SBai Ping	str	w0, [x1, #UTXD]
64*81136819SBai Ping	ret
65*81136819SBai Pingputc_error:
66*81136819SBai Ping	mov	w0, #-1
67*81136819SBai Ping	ret
68*81136819SBai Pingendfunc console_imx_uart_putc
69*81136819SBai Ping
70*81136819SBai Pingfunc console_imx_uart_getc
71*81136819SBai Ping	ldr	x0, [x0, #CONSOLE_T_DRVDATA]
72*81136819SBai Ping	cbz	x0, getc_error
73*81136819SBai Ping1:
74*81136819SBai Ping	ldr	w1, [x0, #UTS]
75*81136819SBai Ping	tbnz	w1, #5, 1b
76*81136819SBai Ping
77*81136819SBai Ping	ldr	w1, [x0, #URXD]
78*81136819SBai Ping	and	w0, w1, #URXD_RX_DATA
79*81136819SBai Ping
80*81136819SBai Ping	ret
81*81136819SBai Pinggetc_error:
82*81136819SBai Ping	mov	w0, #-1
83*81136819SBai Ping	ret
84*81136819SBai Pingendfunc console_imx_uart_getc
85