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 |
| 18 | |
| 19 | .globl console_cdns_putc |
| 20 | .globl console_cdns_getc |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 21 | |
| 22 | /* ----------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 23 | * int console_cdns_core_init(uintptr_t base_addr) |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 24 | * Function to initialize the console without a |
| 25 | * C Runtime to print debug information. This |
| 26 | * function will be accessed by console_init and |
| 27 | * crash reporting. |
| 28 | * We assume that the bootloader already set up |
| 29 | * the HW (baud, ...) and only enable the trans- |
| 30 | * mitter and receiver here. |
| 31 | * In: x0 - console base address |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 32 | * Out: return 1 on success else 0 on error |
| 33 | * Clobber list : x1, x2, x3 |
| 34 | * ----------------------------------------------- |
| 35 | */ |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 36 | func console_cdns_core_init |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 37 | /* Check the input base address */ |
| 38 | cbz x0, core_init_fail |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 39 | |
| 40 | /* RX/TX enabled & reset */ |
| 41 | mov w3, #(R_UART_CR_TX_EN | R_UART_CR_RX_EN | R_UART_CR_TXRST | R_UART_CR_RXRST) |
| 42 | str w3, [x0, #R_UART_CR] |
| 43 | |
| 44 | mov w0, #1 |
| 45 | ret |
| 46 | core_init_fail: |
| 47 | mov w0, wzr |
| 48 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 49 | endfunc console_cdns_core_init |
| 50 | |
| 51 | #if MULTI_CONSOLE_API |
| 52 | .globl console_cdns_register |
| 53 | |
| 54 | /* ----------------------------------------------- |
| 55 | * int console_cdns_register(console_cdns_t *console, |
| 56 | uintptr_t base, uint32_t clk, uint32_t baud) |
| 57 | * Function to initialize and register a new CDNS |
| 58 | * console. Storage passed in for the console struct |
| 59 | * *must* be persistent (i.e. not from the stack). |
| 60 | * In: x0 - UART register base address |
| 61 | * x1 - pointer to empty console_cdns_t struct |
| 62 | * Out: return 1 on success, 0 on error |
| 63 | * Clobber list : x0, x1, x2, x6, x7, x14 |
| 64 | * ----------------------------------------------- |
| 65 | */ |
| 66 | func console_cdns_register |
| 67 | mov x7, x30 |
| 68 | mov x6, x1 |
| 69 | cbz x6, register_fail |
| 70 | str x0, [x6, #CONSOLE_T_CDNS_BASE] |
| 71 | |
| 72 | bl console_cdns_core_init |
| 73 | cbz x0, register_fail |
| 74 | |
| 75 | mov x0, x6 |
| 76 | mov x30, v7 |
| 77 | finish_console_register cdns |
| 78 | |
| 79 | register_fail: |
| 80 | ret x7 |
| 81 | endfunc console_cdns_register |
| 82 | #else |
| 83 | .globl console_core_init |
| 84 | .globl console_core_putc |
| 85 | .globl console_core_getc |
| 86 | .globl console_core_flush |
| 87 | .equ console_core_init,console_cdns_core_init |
| 88 | .equ console_core_putc,console_cdns_core_putc |
| 89 | .equ console_core_getc,console_cdns_core_getc |
| 90 | #endif |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 91 | |
| 92 | /* -------------------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 93 | * int console_cdns_core_putc(int c, uintptr_t base_addr) |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 94 | * Function to output a character over the console. It |
| 95 | * returns the character printed on success or -1 on error. |
| 96 | * In : w0 - character to be printed |
| 97 | * x1 - console base address |
| 98 | * Out : return -1 on error else return character. |
| 99 | * Clobber list : x2 |
| 100 | * -------------------------------------------------------- |
| 101 | */ |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 102 | func console_cdns_core_putc |
| 103 | #if ENABLE_ASSERTIONS |
| 104 | cmp x1, #0 |
| 105 | ASM_ASSERT(ne) |
| 106 | #endif /* ENABLE_ASSERTIONS */ |
| 107 | |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 108 | /* Prepend '\r' to '\n' */ |
| 109 | cmp w0, #0xA |
| 110 | b.ne 2f |
| 111 | 1: |
| 112 | /* Check if the transmit FIFO is full */ |
| 113 | ldr w2, [x1, #R_UART_SR] |
| 114 | tbnz w2, #UART_SR_INTR_TFUL_BIT, 1b |
| 115 | mov w2, #0xD |
| 116 | str w2, [x1, #R_UART_TX] |
| 117 | 2: |
| 118 | /* Check if the transmit FIFO is full */ |
| 119 | ldr w2, [x1, #R_UART_SR] |
| 120 | tbnz w2, #UART_SR_INTR_TFUL_BIT, 2b |
| 121 | str w0, [x1, #R_UART_TX] |
| 122 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 123 | endfunc console_cdns_core_putc |
| 124 | |
| 125 | /* -------------------------------------------------------- |
| 126 | * int console_cdns_putc(int c, console_cdns_t *cdns) |
| 127 | * Function to output a character over the console. It |
| 128 | * returns the character printed on success or -1 on error. |
| 129 | * In : w0 - character to be printed |
| 130 | * x1 - pointer to console_t structure |
| 131 | * Out : return -1 on error else return character. |
| 132 | * Clobber list : x2 |
| 133 | * -------------------------------------------------------- |
| 134 | */ |
| 135 | func console_cdns_putc |
| 136 | #if ENABLE_ASSERTIONS |
| 137 | cmp x1, #0 |
| 138 | ASM_ASSERT(ne) |
| 139 | #endif /* ENABLE_ASSERTIONS */ |
| 140 | ldr x1, [x1, #CONSOLE_T_CDNS_BASE] |
| 141 | b console_cdns_core_putc |
| 142 | endfunc console_cdns_putc |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 143 | |
| 144 | /* --------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 145 | * int console_cdns_core_getc(uintptr_t base_addr) |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 146 | * Function to get a character from the console. |
| 147 | * It returns the character grabbed on success |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 148 | * or -1 if no character is available. |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 149 | * In : x0 - console base address |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 150 | * Out: w0 - character if available, else -1 |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 151 | * Clobber list : x0, x1 |
| 152 | * --------------------------------------------- |
| 153 | */ |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 154 | func console_cdns_core_getc |
| 155 | #if ENABLE_ASSERTIONS |
| 156 | cmp x0, #0 |
| 157 | ASM_ASSERT(ne) |
| 158 | #endif /* ENABLE_ASSERTIONS */ |
| 159 | |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 160 | /* Check if the receive FIFO is empty */ |
| 161 | ldr w1, [x0, #R_UART_SR] |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 162 | tbnz w1, #UART_SR_INTR_REMPTY_BIT, no_char |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 163 | ldr w1, [x0, #R_UART_RX] |
| 164 | mov w0, w1 |
| 165 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 166 | no_char: |
| 167 | mov w0, #ERROR_NO_PENDING_CHAR |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 168 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 169 | endfunc console_cdns_core_getc |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 170 | |
| 171 | /* --------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 172 | * int console_cdns_getc(console_cdns_t *console) |
| 173 | * Function to get a character from the console. |
| 174 | * It returns the character grabbed on success |
| 175 | * or -1 if no character is available. |
| 176 | * In : x0 - pointer to console_t structure |
| 177 | * Out: w0 - character if available, else -1 |
| 178 | * Clobber list : x0, x1 |
| 179 | * --------------------------------------------- |
| 180 | */ |
| 181 | func console_cdns_getc |
| 182 | #if ENABLE_ASSERTIONS |
| 183 | cmp x0, #0 |
| 184 | ASM_ASSERT(ne) |
| 185 | #endif /* ENABLE_ASSERTIONS */ |
| 186 | ldr x0, [x0, #CONSOLE_T_CDNS_BASE] |
| 187 | b console_cdns_core_getc |
| 188 | endfunc console_cdns_getc |
| 189 | |
| 190 | /* --------------------------------------------- |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 191 | * int console_core_flush(uintptr_t base_addr) |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 192 | * DEPRECATED: Not used with MULTI_CONSOLE_API! |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 193 | * Function to force a write of all buffered |
| 194 | * data that hasn't been output. |
| 195 | * In : x0 - console base address |
| 196 | * Out : return -1 on error else return 0. |
| 197 | * Clobber list : x0, x1 |
| 198 | * --------------------------------------------- |
| 199 | */ |
| 200 | func console_core_flush |
| 201 | /* Placeholder */ |
| 202 | mov w0, #0 |
| 203 | ret |
| 204 | endfunc console_core_flush |