blob: fc357f8a409f5c41f0a15231c356536a7f4f7fc6 [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
18
19 .globl console_cdns_putc
20 .globl console_cdns_getc
Soby Mathew7abebe82016-08-08 12:38:52 +010021
22 /* -----------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -070023 * int console_cdns_core_init(uintptr_t base_addr)
Soby Mathew7abebe82016-08-08 12:38:52 +010024 * Function to initialize the console without a
25 * C Runtime to print debug information. This
26 * function will be accessed by console_init and
27 * crash reporting.
28 * We assume that the bootloader already set up
29 * the HW (baud, ...) and only enable the trans-
30 * mitter and receiver here.
31 * In: x0 - console base address
Soby Mathew7abebe82016-08-08 12:38:52 +010032 * Out: return 1 on success else 0 on error
33 * Clobber list : x1, x2, x3
34 * -----------------------------------------------
35 */
Julius Werner1343ad52017-09-18 17:01:06 -070036func console_cdns_core_init
Soby Mathew7abebe82016-08-08 12:38:52 +010037 /* Check the input base address */
38 cbz x0, core_init_fail
Soby Mathew7abebe82016-08-08 12:38:52 +010039
40 /* RX/TX enabled & reset */
41 mov w3, #(R_UART_CR_TX_EN | R_UART_CR_RX_EN | R_UART_CR_TXRST | R_UART_CR_RXRST)
42 str w3, [x0, #R_UART_CR]
43
44 mov w0, #1
45 ret
46core_init_fail:
47 mov w0, wzr
48 ret
Julius Werner1343ad52017-09-18 17:01:06 -070049endfunc console_cdns_core_init
50
51#if MULTI_CONSOLE_API
52 .globl console_cdns_register
53
54 /* -----------------------------------------------
55 * int console_cdns_register(console_cdns_t *console,
56 uintptr_t base, uint32_t clk, uint32_t baud)
57 * Function to initialize and register a new CDNS
58 * console. Storage passed in for the console struct
59 * *must* be persistent (i.e. not from the stack).
60 * In: x0 - UART register base address
61 * x1 - pointer to empty console_cdns_t struct
62 * Out: return 1 on success, 0 on error
63 * Clobber list : x0, x1, x2, x6, x7, x14
64 * -----------------------------------------------
65 */
66func console_cdns_register
67 mov x7, x30
68 mov x6, x1
69 cbz x6, register_fail
70 str x0, [x6, #CONSOLE_T_CDNS_BASE]
71
72 bl console_cdns_core_init
73 cbz x0, register_fail
74
75 mov x0, x6
76 mov x30, v7
77 finish_console_register cdns
78
79register_fail:
80 ret x7
81endfunc console_cdns_register
82#else
83 .globl console_core_init
84 .globl console_core_putc
85 .globl console_core_getc
86 .globl console_core_flush
87 .equ console_core_init,console_cdns_core_init
88 .equ console_core_putc,console_cdns_core_putc
89 .equ console_core_getc,console_cdns_core_getc
90#endif
Soby Mathew7abebe82016-08-08 12:38:52 +010091
92 /* --------------------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -070093 * int console_cdns_core_putc(int c, uintptr_t base_addr)
Soby Mathew7abebe82016-08-08 12:38:52 +010094 * Function to output a character over the console. It
95 * returns the character printed on success or -1 on error.
96 * In : w0 - character to be printed
97 * x1 - console base address
98 * Out : return -1 on error else return character.
99 * Clobber list : x2
100 * --------------------------------------------------------
101 */
Julius Werner1343ad52017-09-18 17:01:06 -0700102func console_cdns_core_putc
103#if ENABLE_ASSERTIONS
104 cmp x1, #0
105 ASM_ASSERT(ne)
106#endif /* ENABLE_ASSERTIONS */
107
Soby Mathew7abebe82016-08-08 12:38:52 +0100108 /* Prepend '\r' to '\n' */
109 cmp w0, #0xA
110 b.ne 2f
1111:
112 /* Check if the transmit FIFO is full */
113 ldr w2, [x1, #R_UART_SR]
114 tbnz w2, #UART_SR_INTR_TFUL_BIT, 1b
115 mov w2, #0xD
116 str w2, [x1, #R_UART_TX]
1172:
118 /* Check if the transmit FIFO is full */
119 ldr w2, [x1, #R_UART_SR]
120 tbnz w2, #UART_SR_INTR_TFUL_BIT, 2b
121 str w0, [x1, #R_UART_TX]
122 ret
Julius Werner1343ad52017-09-18 17:01:06 -0700123endfunc console_cdns_core_putc
124
125 /* --------------------------------------------------------
126 * int console_cdns_putc(int c, console_cdns_t *cdns)
127 * Function to output a character over the console. It
128 * returns the character printed on success or -1 on error.
129 * In : w0 - character to be printed
130 * x1 - pointer to console_t structure
131 * Out : return -1 on error else return character.
132 * Clobber list : x2
133 * --------------------------------------------------------
134 */
135func console_cdns_putc
136#if ENABLE_ASSERTIONS
137 cmp x1, #0
138 ASM_ASSERT(ne)
139#endif /* ENABLE_ASSERTIONS */
140 ldr x1, [x1, #CONSOLE_T_CDNS_BASE]
141 b console_cdns_core_putc
142endfunc console_cdns_putc
Soby Mathew7abebe82016-08-08 12:38:52 +0100143
144 /* ---------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -0700145 * int console_cdns_core_getc(uintptr_t base_addr)
Soby Mathew7abebe82016-08-08 12:38:52 +0100146 * Function to get a character from the console.
147 * It returns the character grabbed on success
Julius Werner1343ad52017-09-18 17:01:06 -0700148 * or -1 if no character is available.
Soby Mathew7abebe82016-08-08 12:38:52 +0100149 * In : x0 - console base address
Julius Werner1343ad52017-09-18 17:01:06 -0700150 * Out: w0 - character if available, else -1
Soby Mathew7abebe82016-08-08 12:38:52 +0100151 * Clobber list : x0, x1
152 * ---------------------------------------------
153 */
Julius Werner1343ad52017-09-18 17:01:06 -0700154func console_cdns_core_getc
155#if ENABLE_ASSERTIONS
156 cmp x0, #0
157 ASM_ASSERT(ne)
158#endif /* ENABLE_ASSERTIONS */
159
Soby Mathew7abebe82016-08-08 12:38:52 +0100160 /* Check if the receive FIFO is empty */
161 ldr w1, [x0, #R_UART_SR]
Julius Werner1343ad52017-09-18 17:01:06 -0700162 tbnz w1, #UART_SR_INTR_REMPTY_BIT, no_char
Soby Mathew7abebe82016-08-08 12:38:52 +0100163 ldr w1, [x0, #R_UART_RX]
164 mov w0, w1
165 ret
Julius Werner1343ad52017-09-18 17:01:06 -0700166no_char:
167 mov w0, #ERROR_NO_PENDING_CHAR
Soby Mathew7abebe82016-08-08 12:38:52 +0100168 ret
Julius Werner1343ad52017-09-18 17:01:06 -0700169endfunc console_cdns_core_getc
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000170
171 /* ---------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -0700172 * int console_cdns_getc(console_cdns_t *console)
173 * Function to get a character from the console.
174 * It returns the character grabbed on success
175 * or -1 if no character is available.
176 * In : x0 - pointer to console_t structure
177 * Out: w0 - character if available, else -1
178 * Clobber list : x0, x1
179 * ---------------------------------------------
180 */
181func console_cdns_getc
182#if ENABLE_ASSERTIONS
183 cmp x0, #0
184 ASM_ASSERT(ne)
185#endif /* ENABLE_ASSERTIONS */
186 ldr x0, [x0, #CONSOLE_T_CDNS_BASE]
187 b console_cdns_core_getc
188endfunc console_cdns_getc
189
190 /* ---------------------------------------------
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000191 * int console_core_flush(uintptr_t base_addr)
Julius Werner1343ad52017-09-18 17:01:06 -0700192 * DEPRECATED: Not used with MULTI_CONSOLE_API!
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000193 * Function to force a write of all buffered
194 * data that hasn't been output.
195 * In : x0 - console base address
196 * Out : return -1 on error else return 0.
197 * Clobber list : x0, x1
198 * ---------------------------------------------
199 */
200func console_core_flush
201 /* Placeholder */
202 mov w0, #0
203 ret
204endfunc console_core_flush