Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 5 | */ |
| 6 | #include <arch.h> |
| 7 | #include <asm_macros.S> |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 8 | #include <assert_macros.S> |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 9 | #include <cadence/cdns_uart.h> |
| 10 | |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 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 |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 18 | .globl console_cdns_core_flush |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 19 | |
| 20 | .globl console_cdns_putc |
| 21 | .globl console_cdns_getc |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 22 | .globl console_cdns_flush |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 23 | |
| 24 | /* ----------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 25 | * int console_cdns_core_init(uintptr_t base_addr) |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 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 |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 34 | * Out: return 1 on success else 0 on error |
| 35 | * Clobber list : x1, x2, x3 |
| 36 | * ----------------------------------------------- |
| 37 | */ |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 38 | func console_cdns_core_init |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 39 | /* Check the input base address */ |
| 40 | cbz x0, core_init_fail |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 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 |
| 48 | core_init_fail: |
| 49 | mov w0, wzr |
| 50 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 51 | endfunc console_cdns_core_init |
| 52 | |
| 53 | #if MULTI_CONSOLE_API |
| 54 | .globl console_cdns_register |
| 55 | |
| 56 | /* ----------------------------------------------- |
Antonio Nino Diaz | 992c5ac | 2018-10-08 13:26:48 +0100 | [diff] [blame] | 57 | * int console_cdns_register(uint64_t baseaddr, |
| 58 | * uint32_t clock, uint32_t baud, |
| 59 | * console_cdns_t *console); |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 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 | */ |
| 69 | func 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 | |
| 82 | register_fail: |
| 83 | ret x7 |
| 84 | endfunc 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 |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 93 | .equ console_core_flush,console_cdns_core_flush |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 94 | #endif |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 95 | |
| 96 | /* -------------------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 97 | * int console_cdns_core_putc(int c, uintptr_t base_addr) |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 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 | */ |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 106 | func console_cdns_core_putc |
| 107 | #if ENABLE_ASSERTIONS |
| 108 | cmp x1, #0 |
| 109 | ASM_ASSERT(ne) |
| 110 | #endif /* ENABLE_ASSERTIONS */ |
| 111 | |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 112 | /* Prepend '\r' to '\n' */ |
| 113 | cmp w0, #0xA |
| 114 | b.ne 2f |
| 115 | 1: |
| 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] |
| 121 | 2: |
| 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 |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 127 | endfunc 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 | */ |
| 139 | func 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 |
| 146 | endfunc console_cdns_putc |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 147 | |
| 148 | /* --------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 149 | * int console_cdns_core_getc(uintptr_t base_addr) |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 150 | * Function to get a character from the console. |
| 151 | * It returns the character grabbed on success |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 152 | * or -1 if no character is available. |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 153 | * In : x0 - console base address |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 154 | * Out: w0 - character if available, else -1 |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 155 | * Clobber list : x0, x1 |
| 156 | * --------------------------------------------- |
| 157 | */ |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 158 | func console_cdns_core_getc |
| 159 | #if ENABLE_ASSERTIONS |
| 160 | cmp x0, #0 |
| 161 | ASM_ASSERT(ne) |
| 162 | #endif /* ENABLE_ASSERTIONS */ |
| 163 | |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 164 | /* Check if the receive FIFO is empty */ |
| 165 | ldr w1, [x0, #R_UART_SR] |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 166 | tbnz w1, #UART_SR_INTR_REMPTY_BIT, no_char |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 167 | ldr w1, [x0, #R_UART_RX] |
| 168 | mov w0, w1 |
| 169 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 170 | no_char: |
| 171 | mov w0, #ERROR_NO_PENDING_CHAR |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 172 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 173 | endfunc console_cdns_core_getc |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 174 | |
| 175 | /* --------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 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 | */ |
| 185 | func 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 |
| 192 | endfunc console_cdns_getc |
| 193 | |
| 194 | /* --------------------------------------------- |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 195 | * int console_cdns_core_flush(uintptr_t base_addr) |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 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 | */ |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 203 | func console_cdns_core_flush |
| 204 | #if ENABLE_ASSERTIONS |
| 205 | cmp x0, #0 |
| 206 | ASM_ASSERT(ne) |
| 207 | #endif /* ENABLE_ASSERTIONS */ |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 208 | /* Placeholder */ |
| 209 | mov w0, #0 |
| 210 | ret |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 211 | endfunc 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 | */ |
| 222 | func 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 |
| 229 | endfunc console_cdns_flush |