Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 1 | /* |
Varun Wadekar | cbdcbd1 | 2018-05-07 11:21:57 -0700 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | #include <asm_macros.S> |
| 7 | |
| 8 | #define CONSOLE_NUM_BYTES_SHIFT 24 |
| 9 | #define CONSOLE_FLUSH_DATA_TO_PORT (1 << 26) |
| 10 | #define CONSOLE_RING_DOORBELL (1 << 31) |
| 11 | #define CONSOLE_IS_BUSY (1 << 31) |
| 12 | #define CONSOLE_WRITE (CONSOLE_RING_DOORBELL | CONSOLE_FLUSH_DATA_TO_PORT) |
| 13 | |
| 14 | /* |
| 15 | * This file contains a driver implementation to make use of the |
| 16 | * real console implementation provided by the SPE firmware running |
| 17 | * SoCs after Tegra186. |
| 18 | * |
| 19 | * This console is shared by multiple components and the SPE firmware |
| 20 | * finally displays everything on the UART port. |
| 21 | */ |
| 22 | |
| 23 | .globl console_core_init |
| 24 | .globl console_core_putc |
| 25 | .globl console_core_getc |
| 26 | .globl console_core_flush |
| 27 | |
| 28 | /* ----------------------------------------------- |
| 29 | * int console_core_init(uintptr_t base_addr, |
| 30 | * unsigned int uart_clk, unsigned int baud_rate) |
| 31 | * Function to initialize the console without a |
| 32 | * C Runtime to print debug information. This |
| 33 | * function will be accessed by console_init and |
| 34 | * crash reporting. |
| 35 | * In: x0 - console base address |
| 36 | * w1 - Uart clock in Hz |
| 37 | * w2 - Baud rate |
| 38 | * Out: return 1 on success else 0 on error |
| 39 | * Clobber list : x1, x2 |
| 40 | * ----------------------------------------------- |
| 41 | */ |
| 42 | func console_core_init |
| 43 | /* Check the input base address */ |
| 44 | cbz x0, core_init_fail |
| 45 | mov w0, #1 |
| 46 | ret |
| 47 | core_init_fail: |
| 48 | mov w0, wzr |
| 49 | ret |
| 50 | endfunc console_core_init |
| 51 | |
| 52 | /* -------------------------------------------------------- |
| 53 | * int console_core_putc(int c, uintptr_t base_addr) |
| 54 | * Function to output a character over the console. It |
| 55 | * returns the character printed on success or -1 on error. |
| 56 | * In : w0 - character to be printed |
| 57 | * x1 - console base address |
| 58 | * Out : return -1 on error else return character. |
| 59 | * Clobber list : x2 |
| 60 | * -------------------------------------------------------- |
| 61 | */ |
| 62 | func console_core_putc |
| 63 | /* Check the input parameter */ |
| 64 | cbz x1, putc_error |
| 65 | |
Varun Wadekar | cbdcbd1 | 2018-05-07 11:21:57 -0700 | [diff] [blame] | 66 | /* Prepend '\r' to '\n' */ |
| 67 | cmp w0, #0xA |
| 68 | b.ne 2f |
| 69 | |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 70 | /* wait until spe is ready */ |
| 71 | 1: ldr w2, [x1] |
| 72 | and w2, w2, #CONSOLE_IS_BUSY |
| 73 | cbnz w2, 1b |
| 74 | |
| 75 | /* spe is ready */ |
Varun Wadekar | cbdcbd1 | 2018-05-07 11:21:57 -0700 | [diff] [blame] | 76 | mov w2, #0xD /* '\r' */ |
| 77 | and w2, w2, #0xFF |
| 78 | mov w3, #(CONSOLE_WRITE | (1 << CONSOLE_NUM_BYTES_SHIFT)) |
| 79 | orr w2, w2, w3 |
| 80 | str w2, [x1] |
| 81 | |
| 82 | /* wait until spe is ready */ |
| 83 | 2: ldr w2, [x1] |
| 84 | and w2, w2, #CONSOLE_IS_BUSY |
| 85 | cbnz w2, 2b |
| 86 | |
| 87 | /* spe is ready */ |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 88 | mov w2, w0 |
| 89 | and w2, w2, #0xFF |
| 90 | mov w3, #(CONSOLE_WRITE | (1 << CONSOLE_NUM_BYTES_SHIFT)) |
| 91 | orr w2, w2, w3 |
| 92 | str w2, [x1] |
| 93 | |
| 94 | ret |
| 95 | putc_error: |
| 96 | mov w0, #-1 |
| 97 | ret |
| 98 | endfunc console_core_putc |
| 99 | |
| 100 | /* --------------------------------------------- |
| 101 | * int console_core_getc(uintptr_t base_addr) |
| 102 | * Function to get a character from the console. |
| 103 | * It returns the character grabbed on success |
| 104 | * or -1 on error. |
| 105 | * In : x0 - console base address |
| 106 | * Clobber list : x0, x1 |
| 107 | * --------------------------------------------- |
| 108 | */ |
| 109 | func console_core_getc |
| 110 | mov w0, #-1 |
| 111 | ret |
| 112 | endfunc console_core_getc |
| 113 | |
| 114 | /* --------------------------------------------- |
| 115 | * int console_core_flush(uintptr_t base_addr) |
| 116 | * Function to force a write of all buffered |
| 117 | * data that hasn't been output. |
| 118 | * In : x0 - console base address |
| 119 | * Out : return -1 on error else return 0. |
| 120 | * Clobber list : x0, x1 |
| 121 | * --------------------------------------------- |
| 122 | */ |
| 123 | func console_core_flush |
| 124 | cbz x0, flush_error |
| 125 | |
| 126 | /* flush console */ |
| 127 | mov w1, #CONSOLE_WRITE |
| 128 | str w1, [x0] |
| 129 | mov w0, #0 |
| 130 | ret |
| 131 | flush_error: |
| 132 | mov w0, #-1 |
| 133 | ret |
| 134 | endfunc console_core_flush |