blob: 489fcbea5789d68ab9880127876dcd13081365b6 [file] [log] [blame]
Soby Mathew7abebe82016-08-08 12:38:52 +01001/*
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +00002 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
Soby Mathew7abebe82016-08-08 12:38:52 +01003 *
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
31#include <arch.h>
32#include <asm_macros.S>
33#include <uart_16550.h>
34
35 .globl console_core_init
36 .globl console_core_putc
37 .globl console_core_getc
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +000038 .globl console_core_flush
Soby Mathew7abebe82016-08-08 12:38:52 +010039
40 /* -----------------------------------------------
41 * int console_core_init(unsigned long base_addr,
42 * unsigned int uart_clk, unsigned int baud_rate)
43 * Function to initialize the console without a
44 * C Runtime to print debug information. This
45 * function will be accessed by console_init and
46 * crash reporting.
47 * In: x0 - console base address
48 * w1 - Uart clock in Hz
49 * w2 - Baud rate
50 * Out: return 1 on success
51 * Clobber list : x1, x2, x3
52 * -----------------------------------------------
53 */
54func console_core_init
55 /* Check the input base address */
56 cbz x0, init_fail
57 /* Check baud rate and uart clock for sanity */
58 cbz w1, init_fail
59 cbz w2, init_fail
60
61 /* Program the baudrate */
62 /* Divisor = Uart clock / (16 * baudrate) */
63 lsl w2, w2, #4
64 udiv w2, w1, w2
65 and w1, w2, #0xff /* w1 = DLL */
66 lsr w2, w2, #8
67 and w2, w2, #0xff /* w2 = DLLM */
68 ldr w3, [x0, #UARTLCR]
69 orr w3, w3, #UARTLCR_DLAB
70 str w3, [x0, #UARTLCR] /* enable DLL, DLLM programming */
71 str w1, [x0, #UARTDLL] /* program DLL */
72 str w2, [x0, #UARTDLLM] /* program DLLM */
73 mov w2, #~UARTLCR_DLAB
74 and w3, w3, w2
75 str w3, [x0, #UARTLCR] /* disable DLL, DLLM programming */
76
77 /* 8n1 */
78 mov w3, #3
79 str w3, [x0, #UARTLCR]
80 /* no interrupt */
81 mov w3, #0
82 str w3, [x0, #UARTIER]
83 /* enable fifo, DMA */
84 mov w3, #(UARTFCR_FIFOEN | UARTFCR_DMAEN)
85 str w3, [x0, #UARTFCR]
86 /* DTR + RTS */
87 mov w3, #3
88 str w3, [x0, #UARTMCR]
89 mov w0, #1
90init_fail:
91 ret
92endfunc console_core_init
93
94 /* --------------------------------------------------------
95 * int console_core_putc(int c, unsigned int base_addr)
96 * Function to output a character over the console. It
97 * returns the character printed on success or -1 on error.
98 * In : w0 - character to be printed
99 * x1 - console base address
100 * Out : return -1 on error else return character.
101 * Clobber list : x2
102 * --------------------------------------------------------
103 */
104func console_core_putc
105 /* Check the input parameter */
106 cbz x1, putc_error
107
108 /* Prepend '\r' to '\n' */
109 cmp w0, #0xA
110 b.ne 2f
111 /* Check if the transmit FIFO is full */
1121: ldr w2, [x1, #UARTLSR]
113 and w2, w2, #(UARTLSR_TEMT | UARTLSR_THRE)
114 cmp w2, #(UARTLSR_TEMT | UARTLSR_THRE)
115 b.ne 1b
116 mov w2, #0xD /* '\r' */
117 str w2, [x1, #UARTTX]
118 ldr w2, [x1, #UARTFCR]
119 orr w2, w2, #UARTFCR_TXCLR
120 str w2, [x1, #UARTFCR]
121
122 /* Check if the transmit FIFO is full */
1232: ldr w2, [x1, #UARTLSR]
124 and w2, w2, #(UARTLSR_TEMT | UARTLSR_THRE)
125 cmp w2, #(UARTLSR_TEMT | UARTLSR_THRE)
126 b.ne 2b
127 str w0, [x1, #UARTTX]
128 ldr w2, [x1, #UARTFCR]
129 orr w2, w2, #UARTFCR_TXCLR
130 str w2, [x1, #UARTFCR]
131 ret
132putc_error:
133 mov w0, #-1
134 ret
135endfunc console_core_putc
136
137 /* ---------------------------------------------
138 * int console_core_getc(void)
139 * Function to get a character from the console.
140 * It returns the character grabbed on success
141 * or -1 on error.
142 * In : w0 - console base address
143 * Out : return -1 on error else return character.
144 * Clobber list : x0, x1
145 * ---------------------------------------------
146 */
147func console_core_getc
148 /* Check if the receive FIFO is empty */
1491: ldr w1, [x0, #UARTLSR]
Nishanth Menon7b4b5132017-01-10 09:34:07 -0600150 tbz w1, #UARTLSR_RDR_BIT, 1b
Soby Mathew7abebe82016-08-08 12:38:52 +0100151 ldr w0, [x0, #UARTRX]
152 ret
153getc_error:
154 mov w0, #-1
155 ret
156endfunc console_core_getc
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000157
158 /* ---------------------------------------------
159 * int console_core_flush(uintptr_t base_addr)
160 * Function to force a write of all buffered
161 * data that hasn't been output.
162 * In : x0 - console base address
163 * Out : return -1 on error else return 0.
164 * Clobber list : x0, x1
165 * ---------------------------------------------
166 */
167func console_core_flush
168 /* Placeholder */
169 mov w0, #0
170 ret
171endfunc console_core_flush