blob: a9f0334f1ae23e52fda24db1826cdec3abbd12e8 [file] [log] [blame]
Varun Wadekar68e4ee42017-11-15 15:48:51 -08001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6#include <asm_macros.S>
7
8#define CONSOLE_NUM_BYTES_SHIFT 24
9#define CONSOLE_FLUSH_DATA_TO_PORT (1 << 26)
10#define CONSOLE_RING_DOORBELL (1 << 31)
11#define CONSOLE_IS_BUSY (1 << 31)
12#define CONSOLE_WRITE (CONSOLE_RING_DOORBELL | CONSOLE_FLUSH_DATA_TO_PORT)
13
14 /*
15 * This file contains a driver implementation to make use of the
16 * real console implementation provided by the SPE firmware running
17 * SoCs after Tegra186.
18 *
19 * This console is shared by multiple components and the SPE firmware
20 * finally displays everything on the UART port.
21 */
22
23 .globl console_core_init
24 .globl console_core_putc
25 .globl console_core_getc
26 .globl console_core_flush
27
28 /* -----------------------------------------------
29 * int console_core_init(uintptr_t base_addr,
30 * unsigned int uart_clk, unsigned int baud_rate)
31 * Function to initialize the console without a
32 * C Runtime to print debug information. This
33 * function will be accessed by console_init and
34 * crash reporting.
35 * In: x0 - console base address
36 * w1 - Uart clock in Hz
37 * w2 - Baud rate
38 * Out: return 1 on success else 0 on error
39 * Clobber list : x1, x2
40 * -----------------------------------------------
41 */
42func console_core_init
43 /* Check the input base address */
44 cbz x0, core_init_fail
45 mov w0, #1
46 ret
47core_init_fail:
48 mov w0, wzr
49 ret
50endfunc console_core_init
51
52 /* --------------------------------------------------------
53 * int console_core_putc(int c, uintptr_t base_addr)
54 * Function to output a character over the console. It
55 * returns the character printed on success or -1 on error.
56 * In : w0 - character to be printed
57 * x1 - console base address
58 * Out : return -1 on error else return character.
59 * Clobber list : x2
60 * --------------------------------------------------------
61 */
62func console_core_putc
63 /* Check the input parameter */
64 cbz x1, putc_error
65
66 /* wait until spe is ready */
671: ldr w2, [x1]
68 and w2, w2, #CONSOLE_IS_BUSY
69 cbnz w2, 1b
70
71 /* spe is ready */
72 mov w2, w0
73 and w2, w2, #0xFF
74 mov w3, #(CONSOLE_WRITE | (1 << CONSOLE_NUM_BYTES_SHIFT))
75 orr w2, w2, w3
76 str w2, [x1]
77
78 ret
79putc_error:
80 mov w0, #-1
81 ret
82endfunc console_core_putc
83
84 /* ---------------------------------------------
85 * int console_core_getc(uintptr_t base_addr)
86 * Function to get a character from the console.
87 * It returns the character grabbed on success
88 * or -1 on error.
89 * In : x0 - console base address
90 * Clobber list : x0, x1
91 * ---------------------------------------------
92 */
93func console_core_getc
94 mov w0, #-1
95 ret
96endfunc console_core_getc
97
98 /* ---------------------------------------------
99 * int console_core_flush(uintptr_t base_addr)
100 * Function to force a write of all buffered
101 * data that hasn't been output.
102 * In : x0 - console base address
103 * Out : return -1 on error else return 0.
104 * Clobber list : x0, x1
105 * ---------------------------------------------
106 */
107func console_core_flush
108 cbz x0, flush_error
109
110 /* flush console */
111 mov w1, #CONSOLE_WRITE
112 str w1, [x0]
113 mov w0, #0
114 ret
115flush_error:
116 mov w0, #-1
117 ret
118endfunc console_core_flush