1/* 2 * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6#include <arch.h> 7#include <asm_macros.S> 8#include <assert_macros.S> 9#include <cadence/cdns_uart.h> 10 11 /* 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 .globl console_cdns_core_flush 19 20 .globl console_cdns_putc 21 .globl console_cdns_getc 22 .globl console_cdns_flush 23 24 /* ----------------------------------------------- 25 * int console_cdns_core_init(uintptr_t base_addr) 26 * 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 34 * Out: return 1 on success else 0 on error 35 * Clobber list : x1, x2, x3 36 * ----------------------------------------------- 37 */ 38func console_cdns_core_init 39 /* Check the input base address */ 40 cbz x0, core_init_fail 41 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 51endfunc console_cdns_core_init 52 53#if MULTI_CONSOLE_API 54 .globl console_cdns_register 55 56 /* ----------------------------------------------- 57 * int console_cdns_register(uint64_t baseaddr, 58 * uint32_t clock, uint32_t baud, 59 * console_cdns_t *console); 60 * 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 93 .equ console_core_flush,console_cdns_core_flush 94#endif 95 96 /* -------------------------------------------------------- 97 * int console_cdns_core_putc(int c, uintptr_t base_addr) 98 * 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 */ 106func console_cdns_core_putc 107#if ENABLE_ASSERTIONS 108 cmp x1, #0 109 ASM_ASSERT(ne) 110#endif /* ENABLE_ASSERTIONS */ 111 112 /* 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 127endfunc 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 147 148 /* --------------------------------------------- 149 * int console_cdns_core_getc(uintptr_t base_addr) 150 * Function to get a character from the console. 151 * It returns the character grabbed on success 152 * or -1 if no character is available. 153 * In : x0 - console base address 154 * Out: w0 - character if available, else -1 155 * Clobber list : x0, x1 156 * --------------------------------------------- 157 */ 158func console_cdns_core_getc 159#if ENABLE_ASSERTIONS 160 cmp x0, #0 161 ASM_ASSERT(ne) 162#endif /* ENABLE_ASSERTIONS */ 163 164 /* Check if the receive FIFO is empty */ 165 ldr w1, [x0, #R_UART_SR] 166 tbnz w1, #UART_SR_INTR_REMPTY_BIT, no_char 167 ldr w1, [x0, #R_UART_RX] 168 mov w0, w1 169 ret 170no_char: 171 mov w0, #ERROR_NO_PENDING_CHAR 172 ret 173endfunc console_cdns_core_getc 174 175 /* --------------------------------------------- 176 * 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 /* --------------------------------------------- 195 * int console_cdns_core_flush(uintptr_t base_addr) 196 * 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 */ 203func console_cdns_core_flush 204#if ENABLE_ASSERTIONS 205 cmp x0, #0 206 ASM_ASSERT(ne) 207#endif /* ENABLE_ASSERTIONS */ 208 /* Placeholder */ 209 mov w0, #0 210 ret 211endfunc 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 230