blob: 8e5d6a1aab07a23e4405fbb6973ce8d10d42fcfa [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 Mathew58873ae2018-10-10 16:03:09 +01009#include <console_macros.S>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <drivers/cadence/cdns_uart.h>
Soby Mathew7abebe82016-08-08 12:38:52 +010011
Julius Werner1343ad52017-09-18 17:01:06 -070012 /*
13 * "core" functions are low-level implementations that don't require
14 * writable memory and are thus safe to call in BL1 crash context.
15 */
16 .globl console_cdns_core_init
17 .globl console_cdns_core_putc
18 .globl console_cdns_core_getc
Antonio Nino Diazebfa4082018-09-24 22:07:58 +010019 .globl console_cdns_core_flush
Julius Werner1343ad52017-09-18 17:01:06 -070020
21 .globl console_cdns_putc
22 .globl console_cdns_getc
Antonio Nino Diazebfa4082018-09-24 22:07:58 +010023 .globl console_cdns_flush
Soby Mathew7abebe82016-08-08 12:38:52 +010024
25 /* -----------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -070026 * int console_cdns_core_init(uintptr_t base_addr)
Soby Mathew7abebe82016-08-08 12:38:52 +010027 * Function to initialize the console without a
28 * C Runtime to print debug information. This
29 * function will be accessed by console_init and
30 * crash reporting.
31 * We assume that the bootloader already set up
32 * the HW (baud, ...) and only enable the trans-
33 * mitter and receiver here.
34 * In: x0 - console base address
Soby Mathew7abebe82016-08-08 12:38:52 +010035 * Out: return 1 on success else 0 on error
36 * Clobber list : x1, x2, x3
37 * -----------------------------------------------
38 */
Julius Werner1343ad52017-09-18 17:01:06 -070039func console_cdns_core_init
Soby Mathew7abebe82016-08-08 12:38:52 +010040 /* Check the input base address */
41 cbz x0, core_init_fail
Soby Mathew7abebe82016-08-08 12:38:52 +010042
43 /* RX/TX enabled & reset */
44 mov w3, #(R_UART_CR_TX_EN | R_UART_CR_RX_EN | R_UART_CR_TXRST | R_UART_CR_RXRST)
45 str w3, [x0, #R_UART_CR]
46
47 mov w0, #1
48 ret
49core_init_fail:
50 mov w0, wzr
51 ret
Julius Werner1343ad52017-09-18 17:01:06 -070052endfunc console_cdns_core_init
53
Julius Werner1343ad52017-09-18 17:01:06 -070054 .globl console_cdns_register
55
56 /* -----------------------------------------------
Alexei Colinf04146b2018-11-09 17:36:55 -050057 * int console_cdns_register(uintptr_t baseaddr,
Antonio Nino Diaz992c5ac2018-10-08 13:26:48 +010058 * uint32_t clock, uint32_t baud,
Andre Przywara8ccc4a42020-01-25 00:58:35 +000059 * console_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
Alexei Colinf04146b2018-11-09 17:36:55 -050064 * w1 - UART clock in Hz
65 * w2 - Baud rate
Andre Przywara8ccc4a42020-01-25 00:58:35 +000066 * x3 - pointer to empty console_t struct
Julius Werner1343ad52017-09-18 17:01:06 -070067 * Out: return 1 on success, 0 on error
68 * Clobber list : x0, x1, x2, x6, x7, x14
69 * -----------------------------------------------
70 */
71func console_cdns_register
72 mov x7, x30
Alexei Colinf04146b2018-11-09 17:36:55 -050073 mov x6, x3
Julius Werner1343ad52017-09-18 17:01:06 -070074 cbz x6, register_fail
Andre Przywara8ccc4a42020-01-25 00:58:35 +000075 str x0, [x6, #CONSOLE_T_BASE]
Julius Werner1343ad52017-09-18 17:01:06 -070076
77 bl console_cdns_core_init
78 cbz x0, register_fail
79
80 mov x0, x6
Alexei Colinf04146b2018-11-09 17:36:55 -050081 mov x30, x7
Soby Mathew58873ae2018-10-10 16:03:09 +010082 finish_console_register cdns putc=1, getc=1, flush=1
Julius Werner1343ad52017-09-18 17:01:06 -070083
84register_fail:
85 ret x7
86endfunc console_cdns_register
Soby Mathew7abebe82016-08-08 12:38:52 +010087
88 /* --------------------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -070089 * int console_cdns_core_putc(int c, uintptr_t base_addr)
Soby Mathew7abebe82016-08-08 12:38:52 +010090 * Function to output a character over the console. It
91 * returns the character printed on success or -1 on error.
92 * In : w0 - character to be printed
93 * x1 - console base address
94 * Out : return -1 on error else return character.
95 * Clobber list : x2
96 * --------------------------------------------------------
97 */
Julius Werner1343ad52017-09-18 17:01:06 -070098func console_cdns_core_putc
99#if ENABLE_ASSERTIONS
100 cmp x1, #0
101 ASM_ASSERT(ne)
102#endif /* ENABLE_ASSERTIONS */
103
Soby Mathew7abebe82016-08-08 12:38:52 +0100104 /* Prepend '\r' to '\n' */
105 cmp w0, #0xA
106 b.ne 2f
1071:
108 /* Check if the transmit FIFO is full */
109 ldr w2, [x1, #R_UART_SR]
110 tbnz w2, #UART_SR_INTR_TFUL_BIT, 1b
111 mov w2, #0xD
112 str w2, [x1, #R_UART_TX]
1132:
114 /* Check if the transmit FIFO is full */
115 ldr w2, [x1, #R_UART_SR]
116 tbnz w2, #UART_SR_INTR_TFUL_BIT, 2b
117 str w0, [x1, #R_UART_TX]
118 ret
Julius Werner1343ad52017-09-18 17:01:06 -0700119endfunc console_cdns_core_putc
120
121 /* --------------------------------------------------------
Andre Przywara8ccc4a42020-01-25 00:58:35 +0000122 * int console_cdns_putc(int c, console_t *cdns)
Julius Werner1343ad52017-09-18 17:01:06 -0700123 * Function to output a character over the console. It
124 * returns the character printed on success or -1 on error.
125 * In : w0 - character to be printed
126 * x1 - pointer to console_t structure
127 * Out : return -1 on error else return character.
128 * Clobber list : x2
129 * --------------------------------------------------------
130 */
131func console_cdns_putc
132#if ENABLE_ASSERTIONS
133 cmp x1, #0
134 ASM_ASSERT(ne)
135#endif /* ENABLE_ASSERTIONS */
Andre Przywara8ccc4a42020-01-25 00:58:35 +0000136 ldr x1, [x1, #CONSOLE_T_BASE]
Julius Werner1343ad52017-09-18 17:01:06 -0700137 b console_cdns_core_putc
138endfunc console_cdns_putc
Soby Mathew7abebe82016-08-08 12:38:52 +0100139
140 /* ---------------------------------------------
Julius Werner1343ad52017-09-18 17:01:06 -0700141 * int console_cdns_core_getc(uintptr_t base_addr)
Soby Mathew7abebe82016-08-08 12:38:52 +0100142 * Function to get a character from the console.
143 * It returns the character grabbed on success
Julius Werner1343ad52017-09-18 17:01:06 -0700144 * or -1 if no character is available.
Soby Mathew7abebe82016-08-08 12:38:52 +0100145 * In : x0 - console base address
Julius Werner1343ad52017-09-18 17:01:06 -0700146 * Out: w0 - character if available, else -1
Soby Mathew7abebe82016-08-08 12:38:52 +0100147 * Clobber list : x0, x1
148 * ---------------------------------------------
149 */
Julius Werner1343ad52017-09-18 17:01:06 -0700150func console_cdns_core_getc
151#if ENABLE_ASSERTIONS
152 cmp x0, #0
153 ASM_ASSERT(ne)
154#endif /* ENABLE_ASSERTIONS */
155
Soby Mathew7abebe82016-08-08 12:38:52 +0100156 /* Check if the receive FIFO is empty */
157 ldr w1, [x0, #R_UART_SR]
Julius Werner1343ad52017-09-18 17:01:06 -0700158 tbnz w1, #UART_SR_INTR_REMPTY_BIT, no_char
Soby Mathew7abebe82016-08-08 12:38:52 +0100159 ldr w1, [x0, #R_UART_RX]
160 mov w0, w1
161 ret
Julius Werner1343ad52017-09-18 17:01:06 -0700162no_char:
163 mov w0, #ERROR_NO_PENDING_CHAR
Soby Mathew7abebe82016-08-08 12:38:52 +0100164 ret
Julius Werner1343ad52017-09-18 17:01:06 -0700165endfunc console_cdns_core_getc
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000166
167 /* ---------------------------------------------
Andre Przywara8ccc4a42020-01-25 00:58:35 +0000168 * int console_cdns_getc(console_t *console)
Julius Werner1343ad52017-09-18 17:01:06 -0700169 * Function to get a character from the console.
170 * It returns the character grabbed on success
171 * or -1 if no character is available.
172 * In : x0 - pointer to console_t structure
173 * Out: w0 - character if available, else -1
174 * Clobber list : x0, x1
175 * ---------------------------------------------
176 */
177func console_cdns_getc
178#if ENABLE_ASSERTIONS
179 cmp x0, #0
180 ASM_ASSERT(ne)
181#endif /* ENABLE_ASSERTIONS */
Andre Przywara8ccc4a42020-01-25 00:58:35 +0000182 ldr x0, [x0, #CONSOLE_T_BASE]
Julius Werner1343ad52017-09-18 17:01:06 -0700183 b console_cdns_core_getc
184endfunc console_cdns_getc
185
186 /* ---------------------------------------------
Antonio Nino Diazebfa4082018-09-24 22:07:58 +0100187 * int console_cdns_core_flush(uintptr_t base_addr)
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000188 * Function to force a write of all buffered
189 * data that hasn't been output.
190 * In : x0 - console base address
191 * Out : return -1 on error else return 0.
192 * Clobber list : x0, x1
193 * ---------------------------------------------
194 */
Antonio Nino Diazebfa4082018-09-24 22:07:58 +0100195func console_cdns_core_flush
196#if ENABLE_ASSERTIONS
197 cmp x0, #0
198 ASM_ASSERT(ne)
199#endif /* ENABLE_ASSERTIONS */
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000200 /* Placeholder */
201 mov w0, #0
202 ret
Antonio Nino Diazebfa4082018-09-24 22:07:58 +0100203endfunc console_cdns_core_flush
204
205 /* ---------------------------------------------
Andre Przywara8ccc4a42020-01-25 00:58:35 +0000206 * int console_cdns_flush(console_t *console)
Antonio Nino Diazebfa4082018-09-24 22:07:58 +0100207 * Function to force a write of all buffered
208 * data that hasn't been output.
209 * In : x0 - pointer to console_t structure
210 * Out : return -1 on error else return 0.
211 * Clobber list : x0, x1
212 * ---------------------------------------------
213 */
214func console_cdns_flush
215#if ENABLE_ASSERTIONS
216 cmp x0, #0
217 ASM_ASSERT(ne)
218#endif /* ENABLE_ASSERTIONS */
Andre Przywara8ccc4a42020-01-25 00:58:35 +0000219 ldr x0, [x0, #CONSOLE_T_BASE]
Antonio Nino Diazebfa4082018-09-24 22:07:58 +0100220 b console_cdns_core_flush
221endfunc console_cdns_flush