blob: ceeb3a76c8a8bf2283a60641e86a0fa5572df4ae [file] [log] [blame]
Bai Ping06e325e2018-10-28 00:12:34 +08001/*
Jimmy Brisson39f9eee2020-08-05 13:44:05 -05002 * Copyright (c) 2018-2020, ARM Limited and Contributors. All rights reserved.
Bai Ping06e325e2018-10-28 00:12:34 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
Bai Ping06e325e2018-10-28 00:12:34 +08009#include <console_macros.S>
10#include <assert_macros.S>
11#include "imx_uart.h"
12
13#define URXD 0x0 /* Receiver Register */
14#define UTXD 0x40 /* Transmitter Register */
15#define UTS 0xb4 /* UART Test Register (mx31) */
16#define URXD_RX_DATA (0xFF)
17
Anson Huang1fc11bd2019-01-15 14:27:10 +080018 .globl console_imx_uart_register
19 .globl console_imx_uart_init
20 .globl console_imx_uart_putc
21 .globl console_imx_uart_getc
22 .globl console_imx_uart_flush
Bai Ping06e325e2018-10-28 00:12:34 +080023
24func console_imx_uart_register
25 mov x7, x30
26 mov x6, x3
27 cbz x6, register_fail
Andre Przywaraab269202020-03-05 13:56:56 +000028 str x0, [x6, #CONSOLE_T_BASE]
Bai Ping06e325e2018-10-28 00:12:34 +080029
30 bl console_imx_uart_init
31 cbz x0, register_fail
32
33 mov x0, x6
34 mov x30, x7
Anson Huang1fc11bd2019-01-15 14:27:10 +080035 finish_console_register imx_uart putc=1, getc=1, flush=1
Bai Ping06e325e2018-10-28 00:12:34 +080036
37register_fail:
38 ret x7
39endfunc console_imx_uart_register
40
41func console_imx_uart_init
42 mov w0, #1
43 ret
44endfunc console_imx_uart_init
45
46func console_imx_uart_putc
Andre Przywaraab269202020-03-05 13:56:56 +000047 ldr x1, [x1, #CONSOLE_T_BASE]
Bai Ping06e325e2018-10-28 00:12:34 +080048 cbz x1, putc_error
49
50 /* Prepare '\r' to '\n' */
51 cmp w0, #0xA
52 b.ne 2f
531:
54 /* Check if the transmit FIFO is full */
55 ldr w2, [x1, #UTS]
56 tbz w2, #6, 1b
57 mov w2, #0xD
58 str w2, [x1, #UTXD]
592:
60 /* Check if the transmit FIFO is full */
61 ldr w2, [x1, #UTS]
62 tbz w2, #6, 2b
63 str w0, [x1, #UTXD]
64 ret
65putc_error:
66 mov w0, #-1
67 ret
68endfunc console_imx_uart_putc
69
70func console_imx_uart_getc
Andre Przywaraab269202020-03-05 13:56:56 +000071 ldr x0, [x0, #CONSOLE_T_BASE]
Bai Ping06e325e2018-10-28 00:12:34 +080072 cbz x0, getc_error
731:
74 ldr w1, [x0, #UTS]
75 tbnz w1, #5, 1b
76
77 ldr w1, [x0, #URXD]
78 and w0, w1, #URXD_RX_DATA
79
80 ret
81getc_error:
82 mov w0, #-1
83 ret
84endfunc console_imx_uart_getc
Anson Huang1fc11bd2019-01-15 14:27:10 +080085
86func console_imx_uart_flush
Anson Huang1fc11bd2019-01-15 14:27:10 +080087 ret
88endfunc console_imx_uart_flush