blob: f9ccd5773fb987ed071c3c4f4a2119919ff8a1fd [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 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathew7abebe82016-08-08 12:38:52 +01005 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <uart_16550.h>
10
11 .globl console_core_init
12 .globl console_core_putc
13 .globl console_core_getc
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +000014 .globl console_core_flush
Soby Mathew7abebe82016-08-08 12:38:52 +010015
16 /* -----------------------------------------------
17 * int console_core_init(unsigned long base_addr,
18 * unsigned int uart_clk, unsigned int baud_rate)
19 * Function to initialize the console without a
20 * C Runtime to print debug information. This
21 * function will be accessed by console_init and
22 * crash reporting.
23 * In: x0 - console base address
24 * w1 - Uart clock in Hz
25 * w2 - Baud rate
26 * Out: return 1 on success
27 * Clobber list : x1, x2, x3
28 * -----------------------------------------------
29 */
30func console_core_init
31 /* Check the input base address */
32 cbz x0, init_fail
33 /* Check baud rate and uart clock for sanity */
34 cbz w1, init_fail
35 cbz w2, init_fail
36
37 /* Program the baudrate */
38 /* Divisor = Uart clock / (16 * baudrate) */
39 lsl w2, w2, #4
40 udiv w2, w1, w2
41 and w1, w2, #0xff /* w1 = DLL */
42 lsr w2, w2, #8
43 and w2, w2, #0xff /* w2 = DLLM */
44 ldr w3, [x0, #UARTLCR]
45 orr w3, w3, #UARTLCR_DLAB
46 str w3, [x0, #UARTLCR] /* enable DLL, DLLM programming */
47 str w1, [x0, #UARTDLL] /* program DLL */
48 str w2, [x0, #UARTDLLM] /* program DLLM */
49 mov w2, #~UARTLCR_DLAB
50 and w3, w3, w2
51 str w3, [x0, #UARTLCR] /* disable DLL, DLLM programming */
52
53 /* 8n1 */
54 mov w3, #3
55 str w3, [x0, #UARTLCR]
56 /* no interrupt */
57 mov w3, #0
58 str w3, [x0, #UARTIER]
59 /* enable fifo, DMA */
60 mov w3, #(UARTFCR_FIFOEN | UARTFCR_DMAEN)
61 str w3, [x0, #UARTFCR]
62 /* DTR + RTS */
63 mov w3, #3
64 str w3, [x0, #UARTMCR]
65 mov w0, #1
66init_fail:
67 ret
68endfunc console_core_init
69
70 /* --------------------------------------------------------
71 * int console_core_putc(int c, unsigned int base_addr)
72 * Function to output a character over the console. It
73 * returns the character printed on success or -1 on error.
74 * In : w0 - character to be printed
75 * x1 - console base address
76 * Out : return -1 on error else return character.
77 * Clobber list : x2
78 * --------------------------------------------------------
79 */
80func console_core_putc
81 /* Check the input parameter */
82 cbz x1, putc_error
83
84 /* Prepend '\r' to '\n' */
85 cmp w0, #0xA
86 b.ne 2f
87 /* Check if the transmit FIFO is full */
881: ldr w2, [x1, #UARTLSR]
89 and w2, w2, #(UARTLSR_TEMT | UARTLSR_THRE)
90 cmp w2, #(UARTLSR_TEMT | UARTLSR_THRE)
91 b.ne 1b
92 mov w2, #0xD /* '\r' */
93 str w2, [x1, #UARTTX]
Soby Mathew7abebe82016-08-08 12:38:52 +010094
95 /* Check if the transmit FIFO is full */
962: ldr w2, [x1, #UARTLSR]
97 and w2, w2, #(UARTLSR_TEMT | UARTLSR_THRE)
98 cmp w2, #(UARTLSR_TEMT | UARTLSR_THRE)
99 b.ne 2b
100 str w0, [x1, #UARTTX]
Soby Mathew7abebe82016-08-08 12:38:52 +0100101 ret
102putc_error:
103 mov w0, #-1
104 ret
105endfunc console_core_putc
106
107 /* ---------------------------------------------
108 * int console_core_getc(void)
109 * Function to get a character from the console.
110 * It returns the character grabbed on success
111 * or -1 on error.
112 * In : w0 - console base address
113 * Out : return -1 on error else return character.
114 * Clobber list : x0, x1
115 * ---------------------------------------------
116 */
117func console_core_getc
118 /* Check if the receive FIFO is empty */
1191: ldr w1, [x0, #UARTLSR]
Nishanth Menon7b4b5132017-01-10 09:34:07 -0600120 tbz w1, #UARTLSR_RDR_BIT, 1b
Soby Mathew7abebe82016-08-08 12:38:52 +0100121 ldr w0, [x0, #UARTRX]
122 ret
123getc_error:
124 mov w0, #-1
125 ret
126endfunc console_core_getc
Antonio Nino Diaz56ec1d52017-02-08 15:58:12 +0000127
128 /* ---------------------------------------------
129 * int console_core_flush(uintptr_t base_addr)
130 * Function to force a write of all buffered
131 * data that hasn't been output.
132 * In : x0 - console base address
133 * Out : return -1 on error else return 0.
134 * Clobber list : x0, x1
135 * ---------------------------------------------
136 */
137func console_core_flush
138 /* Placeholder */
139 mov w0, #0
140 ret
141endfunc console_core_flush