blob: 2c8dc8f8455bbf7e02edd18c20a208423237909f [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
26 mov w2, w0
27
281: str w2, [x1, #UNIPHIER_UART_TX]
29
30 cmp w2, #'\n'
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090031 b.ne 2f
Masahiro Yamada574388c2016-09-03 11:37:40 +090032 mov w2, #'\r' /* Append '\r' to '\n' */
33 b 1b
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +0900342: ret
35endfunc uniphier_console_putc
Masahiro Yamada574388c2016-09-03 11:37:40 +090036
37/*
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090038 * In: x0 - pointer to console structure
39 * Out: return the character read, or ERROR_NO_PENDING_CHAR if no character
40 is available
Masahiro Yamada574388c2016-09-03 11:37:40 +090041 * Clobber: x1
42 */
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090043 .globl uniphier_console_getc
44func uniphier_console_getc
45 ldr x0, [x0, #CONSOLE_T_DRVDATA]
Masahiro Yamada574388c2016-09-03 11:37:40 +090046
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090047 ldr w1, [x0, #UNIPHIER_UART_LSR]
48 tbz w1, #UNIPHIER_UART_LSR_DR_BIT, 0f
Masahiro Yamada574388c2016-09-03 11:37:40 +090049
50 ldr w0, [x0, #UNIPHIER_UART_RX]
Masahiro Yamada574388c2016-09-03 11:37:40 +090051 ret
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090052
530: mov w0, #ERROR_NO_PENDING_CHAR
Masahiro Yamada574388c2016-09-03 11:37:40 +090054 ret
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090055endfunc uniphier_console_getc
Masahiro Yamada574388c2016-09-03 11:37:40 +090056
57/*
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090058 * In: x0 - pointer to console structure
59 * Out: return 0 (always succeeds)
Masahiro Yamada574388c2016-09-03 11:37:40 +090060 * Clobber: x1
61 */
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090062 .global uniphier_console_flush
63func uniphier_console_flush
64 ldr x0, [x0, #CONSOLE_T_DRVDATA]
Masahiro Yamada574388c2016-09-03 11:37:40 +090065
66 /* wait until the transmitter gets empty */
670: ldr w1, [x0, #UNIPHIER_UART_LSR]
68 tbz w1, #UNIPHIER_UART_LSR_TEMT_BIT, 0b
69
70 mov w0, #0
71 ret
Masahiro Yamadaca8b80e2019-07-02 22:03:16 +090072endfunc uniphier_console_flush