blob: 1113c6e81efe7af7f4fd9225a6d242141f0b09d6 [file] [log] [blame]
Masahiro Yamada574388c2016-09-03 11:37:40 +09001/*
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +09002 * Copyright (c) 2017-2019, 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
20 ldr x1, [x1, #CONSOLE_T_DRVDATA]
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
39 ldr x0, [x0, #CONSOLE_T_DRVDATA]
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
58 ldr x0, [x0, #CONSOLE_T_DRVDATA]
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
64 mov w0, #0
65 ret
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090066endfunc uniphier_console_flush