blob: 7dbde795b9eba316a6e67d94459677b555283d26 [file] [log] [blame]
Bai Ping06e325e2018-10-28 00:12:34 +08001/*
2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#define USE_FINISH_CONSOLE_REG_2
10#include <console_macros.S>
11#include <assert_macros.S>
12#include "imx_uart.h"
13
14#define URXD 0x0 /* Receiver Register */
15#define UTXD 0x40 /* Transmitter Register */
16#define UTS 0xb4 /* UART Test Register (mx31) */
17#define URXD_RX_DATA (0xFF)
18
19 .globl console_uart_register
20 .globl console_uart_init
21 .globl console_uart_putc
22 .globl console_uart_getc
23
24func console_imx_uart_register
25 mov x7, x30
26 mov x6, x3
27 cbz x6, register_fail
28 str x0, [x6, #CONSOLE_T_DRVDATA]
29
30 bl console_imx_uart_init
31 cbz x0, register_fail
32
33 mov x0, x6
34 mov x30, x7
35 finish_console_register imx_uart putc=1, getc=1
36
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
47 ldr x1, [x1, #CONSOLE_T_DRVDATA]
48 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
71 ldr x0, [x0, #CONSOLE_T_DRVDATA]
72 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