blob: 2c7960d87c38232d8f59425999140883a1c3abd3 [file] [log] [blame]
Soby Mathew7abebe82016-08-08 12:38:52 +01001/*
2 * Copyright (c) 2016, 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
38 /* -----------------------------------------------
39 * int console_core_init(unsigned long base_addr,
40 * unsigned int uart_clk, unsigned int baud_rate)
41 * Function to initialize the console without a
42 * C Runtime to print debug information. This
43 * function will be accessed by console_init and
44 * crash reporting.
45 * We assume that the bootloader already set up
46 * the HW (baud, ...) and only enable the trans-
47 * mitter and receiver here.
48 * In: x0 - console base address
49 * w1 - Uart clock in Hz
50 * w2 - Baud rate
51 * Out: return 1 on success else 0 on error
52 * Clobber list : x1, x2, x3
53 * -----------------------------------------------
54 */
55func console_core_init
56 /* Check the input base address */
57 cbz x0, core_init_fail
58 /* Check baud rate and uart clock for sanity */
59 cbz w1, core_init_fail
60 cbz w2, core_init_fail
61
62 /* RX/TX enabled & reset */
63 mov w3, #(R_UART_CR_TX_EN | R_UART_CR_RX_EN | R_UART_CR_TXRST | R_UART_CR_RXRST)
64 str w3, [x0, #R_UART_CR]
65
66 mov w0, #1
67 ret
68core_init_fail:
69 mov w0, wzr
70 ret
71endfunc console_core_init
72
73 /* --------------------------------------------------------
74 * int console_core_putc(int c, unsigned long base_addr)
75 * Function to output a character over the console. It
76 * returns the character printed on success or -1 on error.
77 * In : w0 - character to be printed
78 * x1 - console base address
79 * Out : return -1 on error else return character.
80 * Clobber list : x2
81 * --------------------------------------------------------
82 */
83func console_core_putc
84 /* Check the input parameter */
85 cbz x1, putc_error
86 /* Prepend '\r' to '\n' */
87 cmp w0, #0xA
88 b.ne 2f
891:
90 /* Check if the transmit FIFO is full */
91 ldr w2, [x1, #R_UART_SR]
92 tbnz w2, #UART_SR_INTR_TFUL_BIT, 1b
93 mov w2, #0xD
94 str w2, [x1, #R_UART_TX]
952:
96 /* Check if the transmit FIFO is full */
97 ldr w2, [x1, #R_UART_SR]
98 tbnz w2, #UART_SR_INTR_TFUL_BIT, 2b
99 str w0, [x1, #R_UART_TX]
100 ret
101putc_error:
102 mov w0, #-1
103 ret
104endfunc console_core_putc
105
106 /* ---------------------------------------------
107 * int console_core_getc(unsigned long base_addr)
108 * Function to get a character from the console.
109 * It returns the character grabbed on success
110 * or -1 on error.
111 * In : x0 - console base address
112 * Clobber list : x0, x1
113 * ---------------------------------------------
114 */
115func console_core_getc
116 cbz x0, getc_error
1171:
118 /* Check if the receive FIFO is empty */
119 ldr w1, [x0, #R_UART_SR]
120 tbnz w1, #UART_SR_INTR_REMPTY_BIT, 1b
121 ldr w1, [x0, #R_UART_RX]
122 mov w0, w1
123 ret
124getc_error:
125 mov w0, #-1
126 ret
127endfunc console_core_getc