blob: 48927f41453c8f3e02543f1704a027c2a9e5c8c0 [file] [log] [blame]
Masahiro Yamada574388c2016-09-03 11:37:40 +09001/*
Jimmy Brisson39f9eee2020-08-05 13:44:05 -05002 * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
Masahiro Yamada574388c2016-09-03 11:37:40 +09003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <asm_macros.S>
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +09008#include <drivers/console.h>
Masahiro Yamada574388c2016-09-03 11:37:40 +09009
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090010#include "uniphier_console.h"
Masahiro Yamada574388c2016-09-03 11:37:40 +090011
12/*
Masahiro Yamada574388c2016-09-03 11:37:40 +090013 * In: w0 - character to be printed
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090014 * x1 - pointer to console structure
15 * Out: return the character written (always succeeds)
Masahiro Yamada574388c2016-09-03 11:37:40 +090016 * Clobber: x2
17 */
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090018 .globl uniphier_console_putc
19func uniphier_console_putc
Andre Przywara33806312020-01-25 00:58:35 +000020 ldr x1, [x1, #CONSOLE_T_BASE]
Masahiro Yamada574388c2016-09-03 11:37:40 +090021
22 /* Wait until the transmitter FIFO gets empty */
230: ldr w2, [x1, #UNIPHIER_UART_LSR]
24 tbz w2, #UNIPHIER_UART_LSR_THRE_BIT, 0b
25
Masahiro Yamada0d42b552019-07-23 12:53:41 +090026 str w0, [x1, #UNIPHIER_UART_TX]
Masahiro Yamada574388c2016-09-03 11:37:40 +090027
Masahiro Yamada0d42b552019-07-23 12:53:41 +090028 ret
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090029endfunc uniphier_console_putc
Masahiro Yamada574388c2016-09-03 11:37:40 +090030
31/*
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090032 * In: x0 - pointer to console structure
33 * Out: return the character read, or ERROR_NO_PENDING_CHAR if no character
34 is available
Masahiro Yamada574388c2016-09-03 11:37:40 +090035 * Clobber: x1
36 */
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090037 .globl uniphier_console_getc
38func uniphier_console_getc
Andre Przywara33806312020-01-25 00:58:35 +000039 ldr x0, [x0, #CONSOLE_T_BASE]
Masahiro Yamada574388c2016-09-03 11:37:40 +090040
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090041 ldr w1, [x0, #UNIPHIER_UART_LSR]
42 tbz w1, #UNIPHIER_UART_LSR_DR_BIT, 0f
Masahiro Yamada574388c2016-09-03 11:37:40 +090043
44 ldr w0, [x0, #UNIPHIER_UART_RX]
Masahiro Yamada574388c2016-09-03 11:37:40 +090045 ret
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090046
470: mov w0, #ERROR_NO_PENDING_CHAR
Masahiro Yamada574388c2016-09-03 11:37:40 +090048 ret
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090049endfunc uniphier_console_getc
Masahiro Yamada574388c2016-09-03 11:37:40 +090050
51/*
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090052 * In: x0 - pointer to console structure
53 * Out: return 0 (always succeeds)
Masahiro Yamada574388c2016-09-03 11:37:40 +090054 * Clobber: x1
55 */
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090056 .global uniphier_console_flush
57func uniphier_console_flush
Andre Przywara33806312020-01-25 00:58:35 +000058 ldr x0, [x0, #CONSOLE_T_BASE]
Masahiro Yamada574388c2016-09-03 11:37:40 +090059
60 /* wait until the transmitter gets empty */
610: ldr w1, [x0, #UNIPHIER_UART_LSR]
62 tbz w1, #UNIPHIER_UART_LSR_TEMT_BIT, 0b
63
Masahiro Yamada574388c2016-09-03 11:37:40 +090064 ret
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090065endfunc uniphier_console_flush