blob: 71359a6d2006cfff21b428dd2045b801e1ff908f [file] [log] [blame]
Soby Mathew7abebe82016-08-08 12:38:52 +01001/*
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +00002 * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
Soby Mathew7abebe82016-08-08 12:38:52 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathew7abebe82016-08-08 12:38:52 +01005 */
6#include <arch.h>
7#include <asm_macros.S>
Julius Werner1343ad52017-09-18 17:01:06 -07008#include <assert_macros.S>
Soby Mathew7abebe82016-08-08 12:38:52 +01009#include <cadence/cdns_uart.h>
10
Julius Werner1343ad52017-09-18 17:01:06 -070011 /*
12 * "core" functions are low-level implementations that don't require
13 * writable memory and are thus safe to call in BL1 crash context.
14 */
15 .globl console_cdns_core_init
16 .globl console_cdns_core_putc
17 .globl console_cdns_core_getc
Antonio Nino Diazebfa4082018-09-24 22:07:58 +010018 .globl console_cdns_core_flush
Julius Werner1343ad52017-09-18 17:01:06 -070019
20 .globl console_cdns_putc
21 .globl console_cdns_getc
Antonio Nino Diazebfa4082018-09-24 22:07:58 +010022 .globl console_cdns_flush
Soby Mathew7abebe82016-08-08 12:38:52 +010023
24 /* -----------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -070025 * int console_cdns_core_init(uintptr_t base_addr)
Soby Mathew7abebe82016-08-08 12:38:52 +010026 * Function to initialize the console without a
27 * C Runtime to print debug information. This
28 * function will be accessed by console_init and
29 * crash reporting.
30 * We assume that the bootloader already set up
31 * the HW (baud, ...) and only enable the trans-
32 * mitter and receiver here.
33 * In: x0 - console base address
Soby Mathew7abebe82016-08-08 12:38:52 +010034 * Out: return 1 on success else 0 on error
35 * Clobber list : x1, x2, x3
36 * -----------------------------------------------
37 */
Julius Werner1343ad52017-09-18 17:01:06 -070038func console_cdns_core_init
Soby Mathew7abebe82016-08-08 12:38:52 +010039 /* Check the input base address */
40 cbz x0, core_init_fail
Soby Mathew7abebe82016-08-08 12:38:52 +010041
42 /* RX/TX enabled & reset */
43 mov w3, #(R_UART_CR_TX_EN | R_UART_CR_RX_EN | R_UART_CR_TXRST | R_UART_CR_RXRST)
44 str w3, [x0, #R_UART_CR]
45
46 mov w0, #1
47 ret
48core_init_fail:
49 mov w0, wzr
50 ret
Julius Werner1343ad52017-09-18 17:01:06 -070051endfunc console_cdns_core_init
52
53#if MULTI_CONSOLE_API
54 .globl console_cdns_register
55
56 /* -----------------------------------------------
Antonio Nino Diaz992c5ac2018-10-08 13:26:48 +010057 * int console_cdns_register(uint64_t baseaddr,
58 * uint32_t clock, uint32_t baud,
59 * console_cdns_t *console);
Julius Werner1343ad52017-09-18 17:01:06 -070060 * Function to initialize and register a new CDNS
61 * console. Storage passed in for the console struct
62 * *must* be persistent (i.e. not from the stack).
63 * In: x0 - UART register base address
64 * x1 - pointer to empty console_cdns_t struct
65 * Out: return 1 on success, 0 on error
66 * Clobber list : x0, x1, x2, x6, x7, x14
67 * -----------------------------------------------
68 */
69func console_cdns_register
70 mov x7, x30
71 mov x6, x1
72 cbz x6, register_fail
73 str x0, [x6, #CONSOLE_T_CDNS_BASE]
74
75 bl console_cdns_core_init
76 cbz x0, register_fail
77
78 mov x0, x6
79 mov x30, v7
80 finish_console_register cdns
81
82register_fail:
83 ret x7
84endfunc console_cdns_register
85#else
86 .globl console_core_init
87 .globl console_core_putc
88 .globl console_core_getc
89 .globl console_core_flush
90 .equ console_core_init,console_cdns_core_init
91 .equ console_core_putc,console_cdns_core_putc
92 .equ console_core_getc,console_cdns_core_getc
Antonio Nino Diazebfa4082018-09-24 22:07:58 +010093 .equ console_core_flush,console_cdns_core_flush
Julius Werner1343ad52017-09-18 17:01:06 -070094#endif
Soby Mathew7abebe82016-08-08 12:38:52 +010095
96 /* --------------------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -070097 * int console_cdns_core_putc(int c, uintptr_t base_addr)
Soby Mathew7abebe82016-08-08 12:38:52 +010098 * Function to output a character over the console. It
99 * returns the character printed on success or -1 on error.
100 * In : w0 - character to be printed
101 * x1 - console base address
102 * Out : return -1 on error else return character.
103 * Clobber list : x2
104 * --------------------------------------------------------
105 */
Julius Werner1343ad52017-09-18 17:01:06 -0700106func console_cdns_core_putc
107#if ENABLE_ASSERTIONS
108 cmp x1, #0
109 ASM_ASSERT(ne)
110#endif /* ENABLE_ASSERTIONS */
111
Soby Mathew7abebe82016-08-08 12:38:52 +0100112 /* Prepend '\r' to '\n' */
113 cmp w0, #0xA
114 b.ne 2f
1151:
116 /* Check if the transmit FIFO is full */
117 ldr w2, [x1, #R_UART_SR]
118 tbnz w2, #UART_SR_INTR_TFUL_BIT, 1b
119 mov w2, #0xD
120 str w2, [x1, #R_UART_TX]
1212:
122 /* Check if the transmit FIFO is full */
123 ldr w2, [x1, #R_UART_SR]
124 tbnz w2, #UART_SR_INTR_TFUL_BIT, 2b
125 str w0, [x1, #R_UART_TX]
126 ret
Julius Werner1343ad52017-09-18 17:01:06 -0700127endfunc console_cdns_core_putc
128
129 /* --------------------------------------------------------
130 * int console_cdns_putc(int c, console_cdns_t *cdns)
131 * Function to output a character over the console. It
132 * returns the character printed on success or -1 on error.
133 * In : w0 - character to be printed
134 * x1 - pointer to console_t structure
135 * Out : return -1 on error else return character.
136 * Clobber list : x2
137 * --------------------------------------------------------
138 */
139func console_cdns_putc
140#if ENABLE_ASSERTIONS
141 cmp x1, #0
142 ASM_ASSERT(ne)
143#endif /* ENABLE_ASSERTIONS */
144 ldr x1, [x1, #CONSOLE_T_CDNS_BASE]
145 b console_cdns_core_putc
146endfunc console_cdns_putc
Soby Mathew7abebe82016-08-08 12:38:52 +0100147
148 /* ---------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -0700149 * int console_cdns_core_getc(uintptr_t base_addr)
Soby Mathew7abebe82016-08-08 12:38:52 +0100150 * Function to get a character from the console.
151 * It returns the character grabbed on success
Julius Werner1343ad52017-09-18 17:01:06 -0700152 * or -1 if no character is available.
Soby Mathew7abebe82016-08-08 12:38:52 +0100153 * In : x0 - console base address
Julius Werner1343ad52017-09-18 17:01:06 -0700154 * Out: w0 - character if available, else -1
Soby Mathew7abebe82016-08-08 12:38:52 +0100155 * Clobber list : x0, x1
156 * ---------------------------------------------
157 */
Julius Werner1343ad52017-09-18 17:01:06 -0700158func console_cdns_core_getc
159#if ENABLE_ASSERTIONS
160 cmp x0, #0
161 ASM_ASSERT(ne)
162#endif /* ENABLE_ASSERTIONS */
163
Soby Mathew7abebe82016-08-08 12:38:52 +0100164 /* Check if the receive FIFO is empty */
165 ldr w1, [x0, #R_UART_SR]
Julius Werner1343ad52017-09-18 17:01:06 -0700166 tbnz w1, #UART_SR_INTR_REMPTY_BIT, no_char
Soby Mathew7abebe82016-08-08 12:38:52 +0100167 ldr w1, [x0, #R_UART_RX]
168 mov w0, w1
169 ret
Julius Werner1343ad52017-09-18 17:01:06 -0700170no_char:
171 mov w0, #ERROR_NO_PENDING_CHAR
Soby Mathew7abebe82016-08-08 12:38:52 +0100172 ret
Julius Werner1343ad52017-09-18 17:01:06 -0700173endfunc console_cdns_core_getc
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000174
175 /* ---------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -0700176 * int console_cdns_getc(console_cdns_t *console)
177 * Function to get a character from the console.
178 * It returns the character grabbed on success
179 * or -1 if no character is available.
180 * In : x0 - pointer to console_t structure
181 * Out: w0 - character if available, else -1
182 * Clobber list : x0, x1
183 * ---------------------------------------------
184 */
185func console_cdns_getc
186#if ENABLE_ASSERTIONS
187 cmp x0, #0
188 ASM_ASSERT(ne)
189#endif /* ENABLE_ASSERTIONS */
190 ldr x0, [x0, #CONSOLE_T_CDNS_BASE]
191 b console_cdns_core_getc
192endfunc console_cdns_getc
193
194 /* ---------------------------------------------
Antonio Nino Diazebfa4082018-09-24 22:07:58 +0100195 * int console_cdns_core_flush(uintptr_t base_addr)
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000196 * Function to force a write of all buffered
197 * data that hasn't been output.
198 * In : x0 - console base address
199 * Out : return -1 on error else return 0.
200 * Clobber list : x0, x1
201 * ---------------------------------------------
202 */
Antonio Nino Diazebfa4082018-09-24 22:07:58 +0100203func console_cdns_core_flush
204#if ENABLE_ASSERTIONS
205 cmp x0, #0
206 ASM_ASSERT(ne)
207#endif /* ENABLE_ASSERTIONS */
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000208 /* Placeholder */
209 mov w0, #0
210 ret
Antonio Nino Diazebfa4082018-09-24 22:07:58 +0100211endfunc console_cdns_core_flush
212
213 /* ---------------------------------------------
214 * int console_cdns_flush(console_pl011_t *console)
215 * Function to force a write of all buffered
216 * data that hasn't been output.
217 * In : x0 - pointer to console_t structure
218 * Out : return -1 on error else return 0.
219 * Clobber list : x0, x1
220 * ---------------------------------------------
221 */
222func console_cdns_flush
223#if ENABLE_ASSERTIONS
224 cmp x0, #0
225 ASM_ASSERT(ne)
226#endif /* ENABLE_ASSERTIONS */
227 ldr x0, [x0, #CONSOLE_T_CDNS_BASE]
228 b console_cdns_core_flush
229endfunc console_cdns_flush