181136819SBai Ping/* 2831b0e98SJimmy Brisson * Copyright (c) 2018-2020, 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 */ 15*4be8c099SLoic Poulain#define USR2 0x98 /* UART Status Register 2 */ 1681136819SBai Ping#define UTS 0xb4 /* UART Test Register (mx31) */ 1781136819SBai Ping#define URXD_RX_DATA (0xFF) 1881136819SBai Ping 192e8ab4f5SAnson Huang .globl console_imx_uart_register 202e8ab4f5SAnson Huang .globl console_imx_uart_init 212e8ab4f5SAnson Huang .globl console_imx_uart_putc 222e8ab4f5SAnson Huang .globl console_imx_uart_getc 232e8ab4f5SAnson 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 296627de53SAndre Przywara str x0, [x6, #CONSOLE_T_BASE] 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 362e8ab4f5SAnson 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 486627de53SAndre Przywara ldr x1, [x1, #CONSOLE_T_BASE] 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] 57*4be8c099SLoic Poulain tbnz w2, #4, 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] 63*4be8c099SLoic Poulain tbnz w2, #4, 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 726627de53SAndre Przywara ldr x0, [x0, #CONSOLE_T_BASE] 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 862e8ab4f5SAnson Huang 872e8ab4f5SAnson Huangfunc console_imx_uart_flush 88*4be8c099SLoic Poulain ldr x0, [x0, #CONSOLE_T_BASE] 89*4be8c099SLoic Poulain cbz x0, flush_exit 90*4be8c099SLoic Poulain1: 91*4be8c099SLoic Poulain /* Wait for the transmit complete bit */ 92*4be8c099SLoic Poulain ldr w1, [x0, #USR2] 93*4be8c099SLoic Poulain tbz w1, #3, 1b 94*4be8c099SLoic Poulain 95*4be8c099SLoic Poulainflush_exit: 962e8ab4f5SAnson Huang ret 972e8ab4f5SAnson Huangendfunc console_imx_uart_flush 98