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 | 58873ae | 2018-10-10 16:03:09 +0100 | [diff] [blame] | 9 | #include <console_macros.S> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | #include <drivers/cadence/cdns_uart.h> |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 11 | |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 12 | /* |
| 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 Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 19 | .globl console_cdns_core_flush |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 20 | |
| 21 | .globl console_cdns_putc |
| 22 | .globl console_cdns_getc |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 23 | .globl console_cdns_flush |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 24 | |
| 25 | /* ----------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 26 | * int console_cdns_core_init(uintptr_t base_addr) |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 27 | * 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 Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 35 | * Out: return 1 on success else 0 on error |
| 36 | * Clobber list : x1, x2, x3 |
| 37 | * ----------------------------------------------- |
| 38 | */ |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 39 | func console_cdns_core_init |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 40 | /* Check the input base address */ |
| 41 | cbz x0, core_init_fail |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 42 | |
| 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 |
| 49 | core_init_fail: |
| 50 | mov w0, wzr |
| 51 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 52 | endfunc console_cdns_core_init |
| 53 | |
| 54 | #if MULTI_CONSOLE_API |
| 55 | .globl console_cdns_register |
| 56 | |
| 57 | /* ----------------------------------------------- |
Alexei Colin | f04146b | 2018-11-09 17:36:55 -0500 | [diff] [blame] | 58 | * int console_cdns_register(uintptr_t baseaddr, |
Antonio Nino Diaz | 992c5ac | 2018-10-08 13:26:48 +0100 | [diff] [blame] | 59 | * uint32_t clock, uint32_t baud, |
| 60 | * console_cdns_t *console); |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 61 | * Function to initialize and register a new CDNS |
| 62 | * console. Storage passed in for the console struct |
| 63 | * *must* be persistent (i.e. not from the stack). |
| 64 | * In: x0 - UART register base address |
Alexei Colin | f04146b | 2018-11-09 17:36:55 -0500 | [diff] [blame] | 65 | * w1 - UART clock in Hz |
| 66 | * w2 - Baud rate |
| 67 | * x3 - pointer to empty console_16550_t struct |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 68 | * Out: return 1 on success, 0 on error |
| 69 | * Clobber list : x0, x1, x2, x6, x7, x14 |
| 70 | * ----------------------------------------------- |
| 71 | */ |
| 72 | func console_cdns_register |
| 73 | mov x7, x30 |
Alexei Colin | f04146b | 2018-11-09 17:36:55 -0500 | [diff] [blame] | 74 | mov x6, x3 |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 75 | cbz x6, register_fail |
| 76 | str x0, [x6, #CONSOLE_T_CDNS_BASE] |
| 77 | |
| 78 | bl console_cdns_core_init |
| 79 | cbz x0, register_fail |
| 80 | |
| 81 | mov x0, x6 |
Alexei Colin | f04146b | 2018-11-09 17:36:55 -0500 | [diff] [blame] | 82 | mov x30, x7 |
Soby Mathew | 58873ae | 2018-10-10 16:03:09 +0100 | [diff] [blame] | 83 | finish_console_register cdns putc=1, getc=1, flush=1 |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 84 | |
| 85 | register_fail: |
| 86 | ret x7 |
| 87 | endfunc console_cdns_register |
| 88 | #else |
| 89 | .globl console_core_init |
| 90 | .globl console_core_putc |
| 91 | .globl console_core_getc |
| 92 | .globl console_core_flush |
| 93 | .equ console_core_init,console_cdns_core_init |
| 94 | .equ console_core_putc,console_cdns_core_putc |
| 95 | .equ console_core_getc,console_cdns_core_getc |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 96 | .equ console_core_flush,console_cdns_core_flush |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 97 | #endif |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 98 | |
| 99 | /* -------------------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 100 | * int console_cdns_core_putc(int c, uintptr_t base_addr) |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 101 | * Function to output a character over the console. It |
| 102 | * returns the character printed on success or -1 on error. |
| 103 | * In : w0 - character to be printed |
| 104 | * x1 - console base address |
| 105 | * Out : return -1 on error else return character. |
| 106 | * Clobber list : x2 |
| 107 | * -------------------------------------------------------- |
| 108 | */ |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 109 | func console_cdns_core_putc |
| 110 | #if ENABLE_ASSERTIONS |
| 111 | cmp x1, #0 |
| 112 | ASM_ASSERT(ne) |
| 113 | #endif /* ENABLE_ASSERTIONS */ |
| 114 | |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 115 | /* Prepend '\r' to '\n' */ |
| 116 | cmp w0, #0xA |
| 117 | b.ne 2f |
| 118 | 1: |
| 119 | /* Check if the transmit FIFO is full */ |
| 120 | ldr w2, [x1, #R_UART_SR] |
| 121 | tbnz w2, #UART_SR_INTR_TFUL_BIT, 1b |
| 122 | mov w2, #0xD |
| 123 | str w2, [x1, #R_UART_TX] |
| 124 | 2: |
| 125 | /* Check if the transmit FIFO is full */ |
| 126 | ldr w2, [x1, #R_UART_SR] |
| 127 | tbnz w2, #UART_SR_INTR_TFUL_BIT, 2b |
| 128 | str w0, [x1, #R_UART_TX] |
| 129 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 130 | endfunc console_cdns_core_putc |
| 131 | |
| 132 | /* -------------------------------------------------------- |
| 133 | * int console_cdns_putc(int c, console_cdns_t *cdns) |
| 134 | * Function to output a character over the console. It |
| 135 | * returns the character printed on success or -1 on error. |
| 136 | * In : w0 - character to be printed |
| 137 | * x1 - pointer to console_t structure |
| 138 | * Out : return -1 on error else return character. |
| 139 | * Clobber list : x2 |
| 140 | * -------------------------------------------------------- |
| 141 | */ |
| 142 | func console_cdns_putc |
| 143 | #if ENABLE_ASSERTIONS |
| 144 | cmp x1, #0 |
| 145 | ASM_ASSERT(ne) |
| 146 | #endif /* ENABLE_ASSERTIONS */ |
| 147 | ldr x1, [x1, #CONSOLE_T_CDNS_BASE] |
| 148 | b console_cdns_core_putc |
| 149 | endfunc console_cdns_putc |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 150 | |
| 151 | /* --------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 152 | * int console_cdns_core_getc(uintptr_t base_addr) |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 153 | * Function to get a character from the console. |
| 154 | * It returns the character grabbed on success |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 155 | * or -1 if no character is available. |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 156 | * In : x0 - console base address |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 157 | * Out: w0 - character if available, else -1 |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 158 | * Clobber list : x0, x1 |
| 159 | * --------------------------------------------- |
| 160 | */ |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 161 | func console_cdns_core_getc |
| 162 | #if ENABLE_ASSERTIONS |
| 163 | cmp x0, #0 |
| 164 | ASM_ASSERT(ne) |
| 165 | #endif /* ENABLE_ASSERTIONS */ |
| 166 | |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 167 | /* Check if the receive FIFO is empty */ |
| 168 | ldr w1, [x0, #R_UART_SR] |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 169 | tbnz w1, #UART_SR_INTR_REMPTY_BIT, no_char |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 170 | ldr w1, [x0, #R_UART_RX] |
| 171 | mov w0, w1 |
| 172 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 173 | no_char: |
| 174 | mov w0, #ERROR_NO_PENDING_CHAR |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 175 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 176 | endfunc console_cdns_core_getc |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 177 | |
| 178 | /* --------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 179 | * int console_cdns_getc(console_cdns_t *console) |
| 180 | * Function to get a character from the console. |
| 181 | * It returns the character grabbed on success |
| 182 | * or -1 if no character is available. |
| 183 | * In : x0 - pointer to console_t structure |
| 184 | * Out: w0 - character if available, else -1 |
| 185 | * Clobber list : x0, x1 |
| 186 | * --------------------------------------------- |
| 187 | */ |
| 188 | func console_cdns_getc |
| 189 | #if ENABLE_ASSERTIONS |
| 190 | cmp x0, #0 |
| 191 | ASM_ASSERT(ne) |
| 192 | #endif /* ENABLE_ASSERTIONS */ |
| 193 | ldr x0, [x0, #CONSOLE_T_CDNS_BASE] |
| 194 | b console_cdns_core_getc |
| 195 | endfunc console_cdns_getc |
| 196 | |
| 197 | /* --------------------------------------------- |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 198 | * int console_cdns_core_flush(uintptr_t base_addr) |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 199 | * Function to force a write of all buffered |
| 200 | * data that hasn't been output. |
| 201 | * In : x0 - console base address |
| 202 | * Out : return -1 on error else return 0. |
| 203 | * Clobber list : x0, x1 |
| 204 | * --------------------------------------------- |
| 205 | */ |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 206 | func console_cdns_core_flush |
| 207 | #if ENABLE_ASSERTIONS |
| 208 | cmp x0, #0 |
| 209 | ASM_ASSERT(ne) |
| 210 | #endif /* ENABLE_ASSERTIONS */ |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 211 | /* Placeholder */ |
| 212 | mov w0, #0 |
| 213 | ret |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 214 | endfunc console_cdns_core_flush |
| 215 | |
| 216 | /* --------------------------------------------- |
| 217 | * int console_cdns_flush(console_pl011_t *console) |
| 218 | * Function to force a write of all buffered |
| 219 | * data that hasn't been output. |
| 220 | * In : x0 - pointer to console_t structure |
| 221 | * Out : return -1 on error else return 0. |
| 222 | * Clobber list : x0, x1 |
| 223 | * --------------------------------------------- |
| 224 | */ |
| 225 | func console_cdns_flush |
| 226 | #if ENABLE_ASSERTIONS |
| 227 | cmp x0, #0 |
| 228 | ASM_ASSERT(ne) |
| 229 | #endif /* ENABLE_ASSERTIONS */ |
| 230 | ldr x0, [x0, #CONSOLE_T_CDNS_BASE] |
| 231 | b console_cdns_core_flush |
| 232 | endfunc console_cdns_flush |