2 * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
7 #include <asm_macros.S>
8 #include <assert_macros.S>
9 #define USE_FINISH_CONSOLE_REG_2
10 #include <console_macros.S>
13 #if !MULTI_CONSOLE_API
15 * Pull in generic functions to provide backwards compatibility for
18 #include "../../../console/aarch32/console.S"
22 * "core" functions are low-level implementations that don't require
23 * writeable memory and are thus safe to call in BL1 crash context.
25 .globl console_pl011_core_init
26 .globl console_pl011_core_putc
27 .globl console_pl011_core_getc
28 .globl console_pl011_core_flush
30 .globl console_pl011_putc
31 .globl console_pl011_getc
32 .globl console_pl011_flush
35 /* -----------------------------------------------
36 * int console_core_init(uintptr_t base_addr,
37 * unsigned int uart_clk, unsigned int baud_rate)
38 * Function to initialize the console without a
39 * C Runtime to print debug information. This
40 * function will be accessed by console_init and
42 * In: r0 - console base address
43 * r1 - Uart clock in Hz
45 * Out: return 1 on success else 0 on error
46 * Clobber list : r1, r2, r3
47 * -----------------------------------------------
49 func console_pl011_core_init
50 /* Check the input base address */
53 #if !PL011_GENERIC_UART
54 /* Check baud rate and uart clock for sanity */
59 /* Disable the UART before initialization */
61 bic r3, r3, #PL011_UARTCR_UARTEN
63 /* Program the baudrate */
64 /* Divisor = (Uart clock * 4) / baudrate */
67 /* IBRD = Divisor >> 6 */
70 str r1, [r0, #UARTIBRD]
71 /* FBRD = Divisor & 0x3F */
74 str r1, [r0, #UARTFBRD]
75 mov r1, #PL011_LINE_CONTROL
76 str r1, [r0, #UARTLCR_H]
77 /* Clear any pending errors */
79 str r1, [r0, #UARTECR]
80 /* Enable tx, rx, and uart overall */
81 ldr r1, =(PL011_UARTCR_RXE | PL011_UARTCR_TXE | PL011_UARTCR_UARTEN)
89 endfunc console_pl011_core_init
92 .globl console_pl011_register
94 /* -------------------------------------------------------
95 * int console_pl011_register(uintptr_t baseaddr,
96 * uint32_t clock, uint32_t baud,
97 * console_pl011_t *console);
98 * Function to initialize and register a new PL011
99 * console. Storage passed in for the console struct
100 * *must* be persistent (i.e. not from the stack).
101 * In: r0 - UART register base address
102 * r1 - UART clock in Hz
104 * r3 - pointer to empty console_pl011_t struct
105 * Out: return 1 on success, 0 on error
106 * Clobber list : r0, r1, r2
107 * -------------------------------------------------------
109 func console_pl011_register
114 str r0, [r4, #CONSOLE_T_PL011_BASE]
116 bl console_pl011_core_init
122 finish_console_register pl011 putc=1, getc=1, flush=1
126 endfunc console_pl011_register
128 .globl console_core_init
129 .globl console_core_putc
130 .globl console_core_getc
131 .globl console_core_flush
132 .equ console_core_init, console_pl011_core_init
133 .equ console_core_putc, console_pl011_core_putc
134 .equ console_core_getc, console_pl011_core_getc
135 .equ console_core_flush, console_pl011_core_flush
138 /* --------------------------------------------------------
139 * int console_core_putc(int c, uintptr_t base_addr)
140 * Function to output a character over the console. It
141 * returns the character printed on success or -1 on error.
142 * In : r0 - character to be printed
143 * r1 - console base address
144 * Out : return -1 on error else return character.
146 * --------------------------------------------------------
148 func console_pl011_core_putc
149 /* Check the input parameter */
152 /* Prepend '\r' to '\n' */
156 /* Check if the transmit FIFO is full */
157 ldr r2, [r1, #UARTFR]
158 tst r2, #PL011_UARTFR_TXFF
161 str r2, [r1, #UARTDR]
163 /* Check if the transmit FIFO is full */
164 ldr r2, [r1, #UARTFR]
165 tst r2, #PL011_UARTFR_TXFF
167 str r0, [r1, #UARTDR]
172 endfunc console_pl011_core_putc
174 /* --------------------------------------------------------
175 * int console_pl011_putc(int c, console_pl011_t *console)
176 * Function to output a character over the console. It
177 * returns the character printed on success or -1 on error.
178 * In: r0 - character to be printed
179 * r1 - pointer to console_t structure
180 * Out : return -1 on error else return character.
182 * -------------------------------------------------------
184 func console_pl011_putc
185 #if ENABLE_ASSERTIONS
188 #endif /* ENABLE_ASSERTIONS */
189 ldr r1, [r1, #CONSOLE_T_PL011_BASE]
190 b console_pl011_core_putc
191 endfunc console_pl011_putc
193 /* ---------------------------------------------
194 * int console_core_getc(uintptr_t base_addr)
195 * Function to get a character from the console.
196 * It returns the character grabbed on success
198 * In : r0 - console base address
199 * Clobber list : r0, r1
200 * ---------------------------------------------
202 func console_pl011_core_getc
206 /* Check if the receive FIFO is empty */
207 ldr r1, [r0, #UARTFR]
208 tst r1, #PL011_UARTFR_RXFE
210 ldr r1, [r0, #UARTDR]
216 endfunc console_pl011_core_getc
218 /* ------------------------------------------------
219 * int console_pl011_getc(console_pl011_t *console)
220 * Function to get a character from the console.
221 * It returns the character grabbed on success
222 * or -1 if no character is available.
223 * In : r0 - pointer to console_t structure
224 * Out: r0 - character if available, else -1
225 * Clobber list: r0, r1
226 * ------------------------------------------------
228 func console_pl011_getc
229 #if ENABLE_ASSERTIONS
232 #endif /* ENABLE_ASSERTIONS */
233 ldr r0, [r0, #CONSOLE_T_PL011_BASE]
234 b console_pl011_core_getc
235 endfunc console_pl011_getc
237 /* ---------------------------------------------
238 * int console_core_flush(uintptr_t base_addr)
239 * Function to force a write of all buffered
240 * data that hasn't been output.
241 * In : r0 - console base address
242 * Out : return -1 on error else return 0.
243 * Clobber list : r0, r1
244 * ---------------------------------------------
246 func console_pl011_core_flush
251 /* Loop while the transmit FIFO is busy */
252 ldr r1, [r0, #UARTFR]
253 tst r1, #PL011_UARTFR_BUSY
261 endfunc console_pl011_core_flush
263 /* ---------------------------------------------
264 * int console_pl011_flush(console_pl011_t *console)
265 * Function to force a write of all buffered
266 * data that hasn't been output.
267 * In : r0 - pointer to console_t structure
268 * Out : return -1 on error else return 0.
269 * Clobber list: r0, r1
270 * ---------------------------------------------
272 func console_pl011_flush
273 #if ENABLE_ASSERTIONS
276 #endif /* ENABLE_ASSERTIONS */
277 ldr r0, [r0, #CONSOLE_T_PL011_BASE]
278 b console_pl011_core_flush
279 endfunc console_pl011_flush