Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 1 | /* |
Jimmy Brisson | 39f9eee | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 2 | * Copyright (c) 2016-2020, 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 | |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 54 | .globl console_cdns_register |
| 55 | |
| 56 | /* ----------------------------------------------- |
Alexei Colin | f04146b | 2018-11-09 17:36:55 -0500 | [diff] [blame] | 57 | * int console_cdns_register(uintptr_t baseaddr, |
Antonio Nino Diaz | 992c5ac | 2018-10-08 13:26:48 +0100 | [diff] [blame] | 58 | * uint32_t clock, uint32_t baud, |
Andre Przywara | 8ccc4a4 | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 59 | * console_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 |
Alexei Colin | f04146b | 2018-11-09 17:36:55 -0500 | [diff] [blame] | 64 | * w1 - UART clock in Hz |
| 65 | * w2 - Baud rate |
Andre Przywara | 8ccc4a4 | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 66 | * x3 - pointer to empty console_t struct |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 67 | * Out: return 1 on success, 0 on error |
| 68 | * Clobber list : x0, x1, x2, x6, x7, x14 |
| 69 | * ----------------------------------------------- |
| 70 | */ |
| 71 | func console_cdns_register |
| 72 | mov x7, x30 |
Alexei Colin | f04146b | 2018-11-09 17:36:55 -0500 | [diff] [blame] | 73 | mov x6, x3 |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 74 | cbz x6, register_fail |
Andre Przywara | 8ccc4a4 | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 75 | str x0, [x6, #CONSOLE_T_BASE] |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 76 | |
| 77 | bl console_cdns_core_init |
| 78 | cbz x0, register_fail |
| 79 | |
| 80 | mov x0, x6 |
Alexei Colin | f04146b | 2018-11-09 17:36:55 -0500 | [diff] [blame] | 81 | mov x30, x7 |
Soby Mathew | 58873ae | 2018-10-10 16:03:09 +0100 | [diff] [blame] | 82 | finish_console_register cdns putc=1, getc=1, flush=1 |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 83 | |
| 84 | register_fail: |
| 85 | ret x7 |
| 86 | endfunc console_cdns_register |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 87 | |
| 88 | /* -------------------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 89 | * int console_cdns_core_putc(int c, uintptr_t base_addr) |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 90 | * 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 Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 98 | func console_cdns_core_putc |
| 99 | #if ENABLE_ASSERTIONS |
| 100 | cmp x1, #0 |
| 101 | ASM_ASSERT(ne) |
| 102 | #endif /* ENABLE_ASSERTIONS */ |
| 103 | |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 104 | /* Prepend '\r' to '\n' */ |
| 105 | cmp w0, #0xA |
| 106 | b.ne 2f |
| 107 | 1: |
Michal Simek | bd0992d | 2017-10-06 10:24:17 +0200 | [diff] [blame] | 108 | /* Check if the transmit FIFO is empty */ |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 109 | ldr w2, [x1, #R_UART_SR] |
Michal Simek | bd0992d | 2017-10-06 10:24:17 +0200 | [diff] [blame] | 110 | tbz w2, #UART_SR_INTR_TEMPTY_BIT, 1b |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 111 | mov w2, #0xD |
| 112 | str w2, [x1, #R_UART_TX] |
| 113 | 2: |
Michal Simek | bd0992d | 2017-10-06 10:24:17 +0200 | [diff] [blame] | 114 | /* Check if the transmit FIFO is empty */ |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 115 | ldr w2, [x1, #R_UART_SR] |
Michal Simek | bd0992d | 2017-10-06 10:24:17 +0200 | [diff] [blame] | 116 | tbz w2, #UART_SR_INTR_TEMPTY_BIT, 2b |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 117 | str w0, [x1, #R_UART_TX] |
| 118 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 119 | endfunc console_cdns_core_putc |
| 120 | |
| 121 | /* -------------------------------------------------------- |
Andre Przywara | 8ccc4a4 | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 122 | * int console_cdns_putc(int c, console_t *cdns) |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 123 | * 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 | */ |
| 131 | func console_cdns_putc |
| 132 | #if ENABLE_ASSERTIONS |
| 133 | cmp x1, #0 |
| 134 | ASM_ASSERT(ne) |
| 135 | #endif /* ENABLE_ASSERTIONS */ |
Andre Przywara | 8ccc4a4 | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 136 | ldr x1, [x1, #CONSOLE_T_BASE] |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 137 | b console_cdns_core_putc |
| 138 | endfunc console_cdns_putc |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 139 | |
| 140 | /* --------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 141 | * int console_cdns_core_getc(uintptr_t base_addr) |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 142 | * Function to get a character from the console. |
| 143 | * It returns the character grabbed on success |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 144 | * or -1 if no character is available. |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 145 | * In : x0 - console base address |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 146 | * Out: w0 - character if available, else -1 |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 147 | * Clobber list : x0, x1 |
| 148 | * --------------------------------------------- |
| 149 | */ |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 150 | func console_cdns_core_getc |
| 151 | #if ENABLE_ASSERTIONS |
| 152 | cmp x0, #0 |
| 153 | ASM_ASSERT(ne) |
| 154 | #endif /* ENABLE_ASSERTIONS */ |
| 155 | |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 156 | /* Check if the receive FIFO is empty */ |
| 157 | ldr w1, [x0, #R_UART_SR] |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 158 | tbnz w1, #UART_SR_INTR_REMPTY_BIT, no_char |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 159 | ldr w1, [x0, #R_UART_RX] |
| 160 | mov w0, w1 |
| 161 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 162 | no_char: |
| 163 | mov w0, #ERROR_NO_PENDING_CHAR |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 164 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 165 | endfunc console_cdns_core_getc |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 166 | |
| 167 | /* --------------------------------------------- |
Andre Przywara | 8ccc4a4 | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 168 | * int console_cdns_getc(console_t *console) |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 169 | * 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 | */ |
| 177 | func console_cdns_getc |
| 178 | #if ENABLE_ASSERTIONS |
| 179 | cmp x0, #0 |
| 180 | ASM_ASSERT(ne) |
| 181 | #endif /* ENABLE_ASSERTIONS */ |
Andre Przywara | 8ccc4a4 | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 182 | ldr x0, [x0, #CONSOLE_T_BASE] |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 183 | b console_cdns_core_getc |
| 184 | endfunc console_cdns_getc |
| 185 | |
| 186 | /* --------------------------------------------- |
Jimmy Brisson | 39f9eee | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 187 | * void console_cdns_core_flush(uintptr_t base_addr) |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 188 | * Function to force a write of all buffered |
| 189 | * data that hasn't been output. |
| 190 | * In : x0 - console base address |
Jimmy Brisson | 39f9eee | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 191 | * Out : void |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 192 | * Clobber list : x0, x1 |
| 193 | * --------------------------------------------- |
| 194 | */ |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 195 | func console_cdns_core_flush |
| 196 | #if ENABLE_ASSERTIONS |
| 197 | cmp x0, #0 |
| 198 | ASM_ASSERT(ne) |
| 199 | #endif /* ENABLE_ASSERTIONS */ |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 200 | /* Placeholder */ |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 201 | ret |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 202 | endfunc console_cdns_core_flush |
| 203 | |
| 204 | /* --------------------------------------------- |
Jimmy Brisson | 39f9eee | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 205 | * void console_cdns_flush(console_t *console) |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 206 | * Function to force a write of all buffered |
| 207 | * data that hasn't been output. |
| 208 | * In : x0 - pointer to console_t structure |
Jimmy Brisson | 39f9eee | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 209 | * Out : void. |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 210 | * Clobber list : x0, x1 |
| 211 | * --------------------------------------------- |
| 212 | */ |
| 213 | func console_cdns_flush |
| 214 | #if ENABLE_ASSERTIONS |
| 215 | cmp x0, #0 |
| 216 | ASM_ASSERT(ne) |
| 217 | #endif /* ENABLE_ASSERTIONS */ |
Andre Przywara | 8ccc4a4 | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 218 | ldr x0, [x0, #CONSOLE_T_BASE] |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 219 | b console_cdns_core_flush |
| 220 | endfunc console_cdns_flush |