Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 1 | /* |
Jimmy Brisson | 39f9eee | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 2 | * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved. |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <asm_macros.S> |
Masahiro Yamada | ca8b80e | 2019-07-02 22:03:16 +0900 | [diff] [blame] | 8 | #include <drivers/console.h> |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 9 | |
Masahiro Yamada | ca8b80e | 2019-07-02 22:03:16 +0900 | [diff] [blame] | 10 | #include "uniphier_console.h" |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 11 | |
| 12 | /* |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 13 | * In: w0 - character to be printed |
Masahiro Yamada | ca8b80e | 2019-07-02 22:03:16 +0900 | [diff] [blame] | 14 | * x1 - pointer to console structure |
| 15 | * Out: return the character written (always succeeds) |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 16 | * Clobber: x2 |
| 17 | */ |
Masahiro Yamada | ca8b80e | 2019-07-02 22:03:16 +0900 | [diff] [blame] | 18 | .globl uniphier_console_putc |
| 19 | func uniphier_console_putc |
Andre Przywara | 3380631 | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 20 | ldr x1, [x1, #CONSOLE_T_BASE] |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 21 | |
| 22 | /* Wait until the transmitter FIFO gets empty */ |
| 23 | 0: ldr w2, [x1, #UNIPHIER_UART_LSR] |
| 24 | tbz w2, #UNIPHIER_UART_LSR_THRE_BIT, 0b |
| 25 | |
Masahiro Yamada | 0d42b55 | 2019-07-23 12:53:41 +0900 | [diff] [blame] | 26 | str w0, [x1, #UNIPHIER_UART_TX] |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 27 | |
Masahiro Yamada | 0d42b55 | 2019-07-23 12:53:41 +0900 | [diff] [blame] | 28 | ret |
Masahiro Yamada | ca8b80e | 2019-07-02 22:03:16 +0900 | [diff] [blame] | 29 | endfunc uniphier_console_putc |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 30 | |
| 31 | /* |
Masahiro Yamada | ca8b80e | 2019-07-02 22:03:16 +0900 | [diff] [blame] | 32 | * In: x0 - pointer to console structure |
| 33 | * Out: return the character read, or ERROR_NO_PENDING_CHAR if no character |
| 34 | is available |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 35 | * Clobber: x1 |
| 36 | */ |
Masahiro Yamada | ca8b80e | 2019-07-02 22:03:16 +0900 | [diff] [blame] | 37 | .globl uniphier_console_getc |
| 38 | func uniphier_console_getc |
Andre Przywara | 3380631 | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 39 | ldr x0, [x0, #CONSOLE_T_BASE] |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 40 | |
Masahiro Yamada | ca8b80e | 2019-07-02 22:03:16 +0900 | [diff] [blame] | 41 | ldr w1, [x0, #UNIPHIER_UART_LSR] |
| 42 | tbz w1, #UNIPHIER_UART_LSR_DR_BIT, 0f |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 43 | |
| 44 | ldr w0, [x0, #UNIPHIER_UART_RX] |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 45 | ret |
Masahiro Yamada | ca8b80e | 2019-07-02 22:03:16 +0900 | [diff] [blame] | 46 | |
| 47 | 0: mov w0, #ERROR_NO_PENDING_CHAR |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 48 | ret |
Masahiro Yamada | ca8b80e | 2019-07-02 22:03:16 +0900 | [diff] [blame] | 49 | endfunc uniphier_console_getc |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 50 | |
| 51 | /* |
Masahiro Yamada | ca8b80e | 2019-07-02 22:03:16 +0900 | [diff] [blame] | 52 | * In: x0 - pointer to console structure |
| 53 | * Out: return 0 (always succeeds) |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 54 | * Clobber: x1 |
| 55 | */ |
Masahiro Yamada | ca8b80e | 2019-07-02 22:03:16 +0900 | [diff] [blame] | 56 | .global uniphier_console_flush |
| 57 | func uniphier_console_flush |
Andre Przywara | 3380631 | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 58 | ldr x0, [x0, #CONSOLE_T_BASE] |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 59 | |
| 60 | /* wait until the transmitter gets empty */ |
| 61 | 0: ldr w1, [x0, #UNIPHIER_UART_LSR] |
| 62 | tbz w1, #UNIPHIER_UART_LSR_TEMT_BIT, 0b |
| 63 | |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 64 | ret |
Masahiro Yamada | ca8b80e | 2019-07-02 22:03:16 +0900 | [diff] [blame] | 65 | endfunc uniphier_console_flush |