blob: f6a1532c92400cdd0ed2e6d860d86466007ea3d5 [file] [log] [blame]
Soby Mathew7abebe82016-08-08 12:38:52 +01001/*
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +00002 * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
Soby Mathew7abebe82016-08-08 12:38:52 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathew7abebe82016-08-08 12:38:52 +01005 */
6#include <arch.h>
7#include <asm_macros.S>
8#include <cadence/cdns_uart.h>
9
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +000010 .globl console_core_init
11 .globl console_core_putc
12 .globl console_core_getc
13 .globl console_core_flush
Soby Mathew7abebe82016-08-08 12:38:52 +010014
15 /* -----------------------------------------------
16 * int console_core_init(unsigned long base_addr,
17 * unsigned int uart_clk, unsigned int baud_rate)
18 * Function to initialize the console without a
19 * C Runtime to print debug information. This
20 * function will be accessed by console_init and
21 * crash reporting.
22 * We assume that the bootloader already set up
23 * the HW (baud, ...) and only enable the trans-
24 * mitter and receiver here.
25 * In: x0 - console base address
26 * w1 - Uart clock in Hz
27 * w2 - Baud rate
28 * Out: return 1 on success else 0 on error
29 * Clobber list : x1, x2, x3
30 * -----------------------------------------------
31 */
32func console_core_init
33 /* Check the input base address */
34 cbz x0, core_init_fail
35 /* Check baud rate and uart clock for sanity */
36 cbz w1, core_init_fail
37 cbz w2, core_init_fail
38
39 /* RX/TX enabled & reset */
40 mov w3, #(R_UART_CR_TX_EN | R_UART_CR_RX_EN | R_UART_CR_TXRST | R_UART_CR_RXRST)
41 str w3, [x0, #R_UART_CR]
42
43 mov w0, #1
44 ret
45core_init_fail:
46 mov w0, wzr
47 ret
48endfunc console_core_init
49
50 /* --------------------------------------------------------
51 * int console_core_putc(int c, unsigned long base_addr)
52 * Function to output a character over the console. It
53 * returns the character printed on success or -1 on error.
54 * In : w0 - character to be printed
55 * x1 - console base address
56 * Out : return -1 on error else return character.
57 * Clobber list : x2
58 * --------------------------------------------------------
59 */
60func console_core_putc
61 /* Check the input parameter */
62 cbz x1, putc_error
63 /* Prepend '\r' to '\n' */
64 cmp w0, #0xA
65 b.ne 2f
661:
67 /* Check if the transmit FIFO is full */
68 ldr w2, [x1, #R_UART_SR]
69 tbnz w2, #UART_SR_INTR_TFUL_BIT, 1b
70 mov w2, #0xD
71 str w2, [x1, #R_UART_TX]
722:
73 /* Check if the transmit FIFO is full */
74 ldr w2, [x1, #R_UART_SR]
75 tbnz w2, #UART_SR_INTR_TFUL_BIT, 2b
76 str w0, [x1, #R_UART_TX]
77 ret
78putc_error:
79 mov w0, #-1
80 ret
81endfunc console_core_putc
82
83 /* ---------------------------------------------
84 * int console_core_getc(unsigned long base_addr)
85 * Function to get a character from the console.
86 * It returns the character grabbed on success
87 * or -1 on error.
88 * In : x0 - console base address
89 * Clobber list : x0, x1
90 * ---------------------------------------------
91 */
92func console_core_getc
93 cbz x0, getc_error
941:
95 /* Check if the receive FIFO is empty */
96 ldr w1, [x0, #R_UART_SR]
97 tbnz w1, #UART_SR_INTR_REMPTY_BIT, 1b
98 ldr w1, [x0, #R_UART_RX]
99 mov w0, w1
100 ret
101getc_error:
102 mov w0, #-1
103 ret
104endfunc console_core_getc
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000105
106 /* ---------------------------------------------
107 * int console_core_flush(uintptr_t base_addr)
108 * Function to force a write of all buffered
109 * data that hasn't been output.
110 * In : x0 - console base address
111 * Out : return -1 on error else return 0.
112 * Clobber list : x0, x1
113 * ---------------------------------------------
114 */
115func console_core_flush
116 /* Placeholder */
117 mov w0, #0
118 ret
119endfunc console_core_flush