1/* 2 * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of ARM nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific 16 * prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30#include <arch.h> 31#include <asm_macros.S> 32#include <cadence/cdns_uart.h> 33 34 .globl console_core_init 35 .globl console_core_putc 36 .globl console_core_getc 37 .globl console_core_flush 38 39 /* ----------------------------------------------- 40 * int console_core_init(unsigned long base_addr, 41 * unsigned int uart_clk, unsigned int baud_rate) 42 * Function to initialize the console without a 43 * C Runtime to print debug information. This 44 * function will be accessed by console_init and 45 * crash reporting. 46 * We assume that the bootloader already set up 47 * the HW (baud, ...) and only enable the trans- 48 * mitter and receiver here. 49 * In: x0 - console base address 50 * w1 - Uart clock in Hz 51 * w2 - Baud rate 52 * Out: return 1 on success else 0 on error 53 * Clobber list : x1, x2, x3 54 * ----------------------------------------------- 55 */ 56func console_core_init 57 /* Check the input base address */ 58 cbz x0, core_init_fail 59 /* Check baud rate and uart clock for sanity */ 60 cbz w1, core_init_fail 61 cbz w2, core_init_fail 62 63 /* RX/TX enabled & reset */ 64 mov w3, #(R_UART_CR_TX_EN | R_UART_CR_RX_EN | R_UART_CR_TXRST | R_UART_CR_RXRST) 65 str w3, [x0, #R_UART_CR] 66 67 mov w0, #1 68 ret 69core_init_fail: 70 mov w0, wzr 71 ret 72endfunc console_core_init 73 74 /* -------------------------------------------------------- 75 * int console_core_putc(int c, unsigned long base_addr) 76 * Function to output a character over the console. It 77 * returns the character printed on success or -1 on error. 78 * In : w0 - character to be printed 79 * x1 - console base address 80 * Out : return -1 on error else return character. 81 * Clobber list : x2 82 * -------------------------------------------------------- 83 */ 84func console_core_putc 85 /* Check the input parameter */ 86 cbz x1, putc_error 87 /* Prepend '\r' to '\n' */ 88 cmp w0, #0xA 89 b.ne 2f 901: 91 /* Check if the transmit FIFO is full */ 92 ldr w2, [x1, #R_UART_SR] 93 tbnz w2, #UART_SR_INTR_TFUL_BIT, 1b 94 mov w2, #0xD 95 str w2, [x1, #R_UART_TX] 962: 97 /* Check if the transmit FIFO is full */ 98 ldr w2, [x1, #R_UART_SR] 99 tbnz w2, #UART_SR_INTR_TFUL_BIT, 2b 100 str w0, [x1, #R_UART_TX] 101 ret 102putc_error: 103 mov w0, #-1 104 ret 105endfunc console_core_putc 106 107 /* --------------------------------------------- 108 * int console_core_getc(unsigned long base_addr) 109 * Function to get a character from the console. 110 * It returns the character grabbed on success 111 * or -1 on error. 112 * In : x0 - console base address 113 * Clobber list : x0, x1 114 * --------------------------------------------- 115 */ 116func console_core_getc 117 cbz x0, getc_error 1181: 119 /* Check if the receive FIFO is empty */ 120 ldr w1, [x0, #R_UART_SR] 121 tbnz w1, #UART_SR_INTR_REMPTY_BIT, 1b 122 ldr w1, [x0, #R_UART_RX] 123 mov w0, w1 124 ret 125getc_error: 126 mov w0, #-1 127 ret 128endfunc console_core_getc 129 130 /* --------------------------------------------- 131 * int console_core_flush(uintptr_t base_addr) 132 * Function to force a write of all buffered 133 * data that hasn't been output. 134 * In : x0 - console base address 135 * Out : return -1 on error else return 0. 136 * Clobber list : x0, x1 137 * --------------------------------------------- 138 */ 139func console_core_flush 140 /* Placeholder */ 141 mov w0, #0 142 ret 143endfunc console_core_flush 144