blob: 418810e15caa50b5a7ccfe4bf90c288f1b6ae738 [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>
Soby Mathew58873ae2018-10-10 16:03:09 +010010#define USE_FINISH_CONSOLE_REG_2
11#include <console_macros.S>
Soby Mathew7abebe82016-08-08 12:38:52 +010012
Julius Werner1343ad52017-09-18 17:01:06 -070013 /*
14 * "core" functions are low-level implementations that don't require
15 * writable memory and are thus safe to call in BL1 crash context.
16 */
17 .globl console_cdns_core_init
18 .globl console_cdns_core_putc
19 .globl console_cdns_core_getc
Antonio Nino Diazebfa4082018-09-24 22:07:58 +010020 .globl console_cdns_core_flush
Julius Werner1343ad52017-09-18 17:01:06 -070021
22 .globl console_cdns_putc
23 .globl console_cdns_getc
Antonio Nino Diazebfa4082018-09-24 22:07:58 +010024 .globl console_cdns_flush
Soby Mathew7abebe82016-08-08 12:38:52 +010025
26 /* -----------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -070027 * int console_cdns_core_init(uintptr_t base_addr)
Soby Mathew7abebe82016-08-08 12:38:52 +010028 * Function to initialize the console without a
29 * C Runtime to print debug information. This
30 * function will be accessed by console_init and
31 * crash reporting.
32 * We assume that the bootloader already set up
33 * the HW (baud, ...) and only enable the trans-
34 * mitter and receiver here.
35 * In: x0 - console base address
Soby Mathew7abebe82016-08-08 12:38:52 +010036 * Out: return 1 on success else 0 on error
37 * Clobber list : x1, x2, x3
38 * -----------------------------------------------
39 */
Julius Werner1343ad52017-09-18 17:01:06 -070040func console_cdns_core_init
Soby Mathew7abebe82016-08-08 12:38:52 +010041 /* Check the input base address */
42 cbz x0, core_init_fail
Soby Mathew7abebe82016-08-08 12:38:52 +010043
44 /* RX/TX enabled & reset */
45 mov w3, #(R_UART_CR_TX_EN | R_UART_CR_RX_EN | R_UART_CR_TXRST | R_UART_CR_RXRST)
46 str w3, [x0, #R_UART_CR]
47
48 mov w0, #1
49 ret
50core_init_fail:
51 mov w0, wzr
52 ret
Julius Werner1343ad52017-09-18 17:01:06 -070053endfunc console_cdns_core_init
54
55#if MULTI_CONSOLE_API
56 .globl console_cdns_register
57
58 /* -----------------------------------------------
Alexei Colinf04146b2018-11-09 17:36:55 -050059 * int console_cdns_register(uintptr_t baseaddr,
Antonio Nino Diaz992c5ac2018-10-08 13:26:48 +010060 * uint32_t clock, uint32_t baud,
61 * console_cdns_t *console);
Julius Werner1343ad52017-09-18 17:01:06 -070062 * Function to initialize and register a new CDNS
63 * console. Storage passed in for the console struct
64 * *must* be persistent (i.e. not from the stack).
65 * In: x0 - UART register base address
Alexei Colinf04146b2018-11-09 17:36:55 -050066 * w1 - UART clock in Hz
67 * w2 - Baud rate
68 * x3 - pointer to empty console_16550_t struct
Julius Werner1343ad52017-09-18 17:01:06 -070069 * Out: return 1 on success, 0 on error
70 * Clobber list : x0, x1, x2, x6, x7, x14
71 * -----------------------------------------------
72 */
73func console_cdns_register
74 mov x7, x30
Alexei Colinf04146b2018-11-09 17:36:55 -050075 mov x6, x3
Julius Werner1343ad52017-09-18 17:01:06 -070076 cbz x6, register_fail
77 str x0, [x6, #CONSOLE_T_CDNS_BASE]
78
79 bl console_cdns_core_init
80 cbz x0, register_fail
81
82 mov x0, x6
Alexei Colinf04146b2018-11-09 17:36:55 -050083 mov x30, x7
Soby Mathew58873ae2018-10-10 16:03:09 +010084 finish_console_register cdns putc=1, getc=1, flush=1
Julius Werner1343ad52017-09-18 17:01:06 -070085
86register_fail:
87 ret x7
88endfunc console_cdns_register
89#else
90 .globl console_core_init
91 .globl console_core_putc
92 .globl console_core_getc
93 .globl console_core_flush
94 .equ console_core_init,console_cdns_core_init
95 .equ console_core_putc,console_cdns_core_putc
96 .equ console_core_getc,console_cdns_core_getc
Antonio Nino Diazebfa4082018-09-24 22:07:58 +010097 .equ console_core_flush,console_cdns_core_flush
Julius Werner1343ad52017-09-18 17:01:06 -070098#endif
Soby Mathew7abebe82016-08-08 12:38:52 +010099
100 /* --------------------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -0700101 * int console_cdns_core_putc(int c, uintptr_t base_addr)
Soby Mathew7abebe82016-08-08 12:38:52 +0100102 * Function to output a character over the console. It
103 * returns the character printed on success or -1 on error.
104 * In : w0 - character to be printed
105 * x1 - console base address
106 * Out : return -1 on error else return character.
107 * Clobber list : x2
108 * --------------------------------------------------------
109 */
Julius Werner1343ad52017-09-18 17:01:06 -0700110func console_cdns_core_putc
111#if ENABLE_ASSERTIONS
112 cmp x1, #0
113 ASM_ASSERT(ne)
114#endif /* ENABLE_ASSERTIONS */
115
Soby Mathew7abebe82016-08-08 12:38:52 +0100116 /* Prepend '\r' to '\n' */
117 cmp w0, #0xA
118 b.ne 2f
1191:
120 /* Check if the transmit FIFO is full */
121 ldr w2, [x1, #R_UART_SR]
122 tbnz w2, #UART_SR_INTR_TFUL_BIT, 1b
123 mov w2, #0xD
124 str w2, [x1, #R_UART_TX]
1252:
126 /* Check if the transmit FIFO is full */
127 ldr w2, [x1, #R_UART_SR]
128 tbnz w2, #UART_SR_INTR_TFUL_BIT, 2b
129 str w0, [x1, #R_UART_TX]
130 ret
Julius Werner1343ad52017-09-18 17:01:06 -0700131endfunc console_cdns_core_putc
132
133 /* --------------------------------------------------------
134 * int console_cdns_putc(int c, console_cdns_t *cdns)
135 * Function to output a character over the console. It
136 * returns the character printed on success or -1 on error.
137 * In : w0 - character to be printed
138 * x1 - pointer to console_t structure
139 * Out : return -1 on error else return character.
140 * Clobber list : x2
141 * --------------------------------------------------------
142 */
143func console_cdns_putc
144#if ENABLE_ASSERTIONS
145 cmp x1, #0
146 ASM_ASSERT(ne)
147#endif /* ENABLE_ASSERTIONS */
148 ldr x1, [x1, #CONSOLE_T_CDNS_BASE]
149 b console_cdns_core_putc
150endfunc console_cdns_putc
Soby Mathew7abebe82016-08-08 12:38:52 +0100151
152 /* ---------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -0700153 * int console_cdns_core_getc(uintptr_t base_addr)
Soby Mathew7abebe82016-08-08 12:38:52 +0100154 * Function to get a character from the console.
155 * It returns the character grabbed on success
Julius Werner1343ad52017-09-18 17:01:06 -0700156 * or -1 if no character is available.
Soby Mathew7abebe82016-08-08 12:38:52 +0100157 * In : x0 - console base address
Julius Werner1343ad52017-09-18 17:01:06 -0700158 * Out: w0 - character if available, else -1
Soby Mathew7abebe82016-08-08 12:38:52 +0100159 * Clobber list : x0, x1
160 * ---------------------------------------------
161 */
Julius Werner1343ad52017-09-18 17:01:06 -0700162func console_cdns_core_getc
163#if ENABLE_ASSERTIONS
164 cmp x0, #0
165 ASM_ASSERT(ne)
166#endif /* ENABLE_ASSERTIONS */
167
Soby Mathew7abebe82016-08-08 12:38:52 +0100168 /* Check if the receive FIFO is empty */
169 ldr w1, [x0, #R_UART_SR]
Julius Werner1343ad52017-09-18 17:01:06 -0700170 tbnz w1, #UART_SR_INTR_REMPTY_BIT, no_char
Soby Mathew7abebe82016-08-08 12:38:52 +0100171 ldr w1, [x0, #R_UART_RX]
172 mov w0, w1
173 ret
Julius Werner1343ad52017-09-18 17:01:06 -0700174no_char:
175 mov w0, #ERROR_NO_PENDING_CHAR
Soby Mathew7abebe82016-08-08 12:38:52 +0100176 ret
Julius Werner1343ad52017-09-18 17:01:06 -0700177endfunc console_cdns_core_getc
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000178
179 /* ---------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -0700180 * int console_cdns_getc(console_cdns_t *console)
181 * Function to get a character from the console.
182 * It returns the character grabbed on success
183 * or -1 if no character is available.
184 * In : x0 - pointer to console_t structure
185 * Out: w0 - character if available, else -1
186 * Clobber list : x0, x1
187 * ---------------------------------------------
188 */
189func console_cdns_getc
190#if ENABLE_ASSERTIONS
191 cmp x0, #0
192 ASM_ASSERT(ne)
193#endif /* ENABLE_ASSERTIONS */
194 ldr x0, [x0, #CONSOLE_T_CDNS_BASE]
195 b console_cdns_core_getc
196endfunc console_cdns_getc
197
198 /* ---------------------------------------------
Antonio Nino Diazebfa4082018-09-24 22:07:58 +0100199 * int console_cdns_core_flush(uintptr_t base_addr)
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000200 * Function to force a write of all buffered
201 * data that hasn't been output.
202 * In : x0 - console base address
203 * Out : return -1 on error else return 0.
204 * Clobber list : x0, x1
205 * ---------------------------------------------
206 */
Antonio Nino Diazebfa4082018-09-24 22:07:58 +0100207func console_cdns_core_flush
208#if ENABLE_ASSERTIONS
209 cmp x0, #0
210 ASM_ASSERT(ne)
211#endif /* ENABLE_ASSERTIONS */
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000212 /* Placeholder */
213 mov w0, #0
214 ret
Antonio Nino Diazebfa4082018-09-24 22:07:58 +0100215endfunc console_cdns_core_flush
216
217 /* ---------------------------------------------
218 * int console_cdns_flush(console_pl011_t *console)
219 * Function to force a write of all buffered
220 * data that hasn't been output.
221 * In : x0 - pointer to console_t structure
222 * Out : return -1 on error else return 0.
223 * Clobber list : x0, x1
224 * ---------------------------------------------
225 */
226func console_cdns_flush
227#if ENABLE_ASSERTIONS
228 cmp x0, #0
229 ASM_ASSERT(ne)
230#endif /* ENABLE_ASSERTIONS */
231 ldr x0, [x0, #CONSOLE_T_CDNS_BASE]
232 b console_cdns_core_flush
233endfunc console_cdns_flush