Bai Ping | 06e325e | 2018-10-28 00:12:34 +0800 | [diff] [blame] | 1 | /* |
Jimmy Brisson | 39f9eee | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 2 | * Copyright (c) 2018-2020, ARM Limited and Contributors. All rights reserved. |
Bai Ping | 06e325e | 2018-10-28 00:12:34 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
| 8 | #include <asm_macros.S> |
Bai Ping | 06e325e | 2018-10-28 00:12:34 +0800 | [diff] [blame] | 9 | #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 Huang | 1fc11bd | 2019-01-15 14:27:10 +0800 | [diff] [blame] | 18 | .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 Ping | 06e325e | 2018-10-28 00:12:34 +0800 | [diff] [blame] | 23 | |
| 24 | func console_imx_uart_register |
| 25 | mov x7, x30 |
| 26 | mov x6, x3 |
| 27 | cbz x6, register_fail |
Andre Przywara | ab26920 | 2020-03-05 13:56:56 +0000 | [diff] [blame] | 28 | str x0, [x6, #CONSOLE_T_BASE] |
Bai Ping | 06e325e | 2018-10-28 00:12:34 +0800 | [diff] [blame] | 29 | |
| 30 | bl console_imx_uart_init |
| 31 | cbz x0, register_fail |
| 32 | |
| 33 | mov x0, x6 |
| 34 | mov x30, x7 |
Anson Huang | 1fc11bd | 2019-01-15 14:27:10 +0800 | [diff] [blame] | 35 | finish_console_register imx_uart putc=1, getc=1, flush=1 |
Bai Ping | 06e325e | 2018-10-28 00:12:34 +0800 | [diff] [blame] | 36 | |
| 37 | register_fail: |
| 38 | ret x7 |
| 39 | endfunc console_imx_uart_register |
| 40 | |
| 41 | func console_imx_uart_init |
| 42 | mov w0, #1 |
| 43 | ret |
| 44 | endfunc console_imx_uart_init |
| 45 | |
| 46 | func console_imx_uart_putc |
Andre Przywara | ab26920 | 2020-03-05 13:56:56 +0000 | [diff] [blame] | 47 | ldr x1, [x1, #CONSOLE_T_BASE] |
Bai Ping | 06e325e | 2018-10-28 00:12:34 +0800 | [diff] [blame] | 48 | cbz x1, putc_error |
| 49 | |
| 50 | /* Prepare '\r' to '\n' */ |
| 51 | cmp w0, #0xA |
| 52 | b.ne 2f |
| 53 | 1: |
| 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] |
| 59 | 2: |
| 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 |
| 65 | putc_error: |
| 66 | mov w0, #-1 |
| 67 | ret |
| 68 | endfunc console_imx_uart_putc |
| 69 | |
| 70 | func console_imx_uart_getc |
Andre Przywara | ab26920 | 2020-03-05 13:56:56 +0000 | [diff] [blame] | 71 | ldr x0, [x0, #CONSOLE_T_BASE] |
Bai Ping | 06e325e | 2018-10-28 00:12:34 +0800 | [diff] [blame] | 72 | cbz x0, getc_error |
| 73 | 1: |
| 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 |
| 81 | getc_error: |
| 82 | mov w0, #-1 |
| 83 | ret |
| 84 | endfunc console_imx_uart_getc |
Anson Huang | 1fc11bd | 2019-01-15 14:27:10 +0800 | [diff] [blame] | 85 | |
| 86 | func console_imx_uart_flush |
Anson Huang | 1fc11bd | 2019-01-15 14:27:10 +0800 | [diff] [blame] | 87 | ret |
| 88 | endfunc console_imx_uart_flush |