blob: 47608da31586a6113fa6474435eab9b7ae1ad223 [file] [log] [blame]
Soby Mathewc389d772014-06-24 12:28:41 +01001/*
Dan Handleyc863fa42015-04-01 16:51:20 +01002 * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved.
Soby Mathewc389d772014-06-24 12:28:41 +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#include <arch.h>
31#include <asm_macros.S>
32#include <pl011.h>
33
Dan Handleyc863fa42015-04-01 16:51:20 +010034/*
35 * Pull in generic functions to provide backwards compatibility for
36 * platform makefiles
37 */
38#include "../../console/console.S"
39
40
Soby Mathewc389d772014-06-24 12:28:41 +010041 .globl console_core_init
42 .globl console_core_putc
Dan Handleyc863fa42015-04-01 16:51:20 +010043 .globl console_core_getc
Soby Mathewc389d772014-06-24 12:28:41 +010044
Soby Mathewc389d772014-06-24 12:28:41 +010045
Soby Mathew69817f72014-07-14 15:43:21 +010046 /* -----------------------------------------------
Juan Castillo7f1f0622014-09-09 09:49:23 +010047 * int console_core_init(uintptr_t base_addr,
Soby Mathew69817f72014-07-14 15:43:21 +010048 * unsigned int uart_clk, unsigned int baud_rate)
Soby Mathewc389d772014-06-24 12:28:41 +010049 * Function to initialize the console without a
50 * C Runtime to print debug information. This
51 * function will be accessed by console_init and
52 * crash reporting.
53 * In: x0 - console base address
Soby Mathew69817f72014-07-14 15:43:21 +010054 * w1 - Uart clock in Hz
55 * w2 - Baud rate
Dan Handleyc863fa42015-04-01 16:51:20 +010056 * Out: return 1 on success else 0 on error
Soby Mathewc389d772014-06-24 12:28:41 +010057 * Clobber list : x1, x2
Soby Mathew69817f72014-07-14 15:43:21 +010058 * -----------------------------------------------
Soby Mathewc389d772014-06-24 12:28:41 +010059 */
60func console_core_init
61 /* Check the input base address */
Dan Handleyc863fa42015-04-01 16:51:20 +010062 cbz x0, core_init_fail
Juan Castillo7ac4b112015-11-16 16:53:38 +000063#if !PL011_GENERIC_UART
Soby Mathew69817f72014-07-14 15:43:21 +010064 /* Check baud rate and uart clock for sanity */
Dan Handleyc863fa42015-04-01 16:51:20 +010065 cbz w1, core_init_fail
66 cbz w2, core_init_fail
Soby Mathewc389d772014-06-24 12:28:41 +010067 /* Program the baudrate */
Soby Mathew69817f72014-07-14 15:43:21 +010068 /* Divisor = (Uart clock * 4) / baudrate */
69 lsl w1, w1, #2
70 udiv w2, w1, w2
71 /* IBRD = Divisor >> 6 */
72 lsr w1, w2, #6
Soby Mathewc389d772014-06-24 12:28:41 +010073 /* Write the IBRD */
Soby Mathewc389d772014-06-24 12:28:41 +010074 str w1, [x0, #UARTIBRD]
Soby Mathew69817f72014-07-14 15:43:21 +010075 /* FBRD = Divisor & 0x3F */
76 and w1, w2, #0x3f
Soby Mathewc389d772014-06-24 12:28:41 +010077 /* Write the FBRD */
Soby Mathewc389d772014-06-24 12:28:41 +010078 str w1, [x0, #UARTFBRD]
Soby Mathewc389d772014-06-24 12:28:41 +010079 mov w1, #PL011_LINE_CONTROL
80 str w1, [x0, #UARTLCR_H]
81 /* Clear any pending errors */
82 str wzr, [x0, #UARTECR]
83 /* Enable tx, rx, and uart overall */
84 mov w1, #(PL011_UARTCR_RXE | PL011_UARTCR_TXE | PL011_UARTCR_UARTEN)
85 str w1, [x0, #UARTCR]
Juan Castillo7ac4b112015-11-16 16:53:38 +000086#endif
Soby Mathewc389d772014-06-24 12:28:41 +010087 mov w0, #1
Dan Handleyc863fa42015-04-01 16:51:20 +010088 ret
89core_init_fail:
90 mov w0, wzr
Soby Mathewc389d772014-06-24 12:28:41 +010091 ret
Kévin Petita877c252015-03-24 14:03:57 +000092endfunc console_core_init
Soby Mathewc389d772014-06-24 12:28:41 +010093
Soby Mathewc389d772014-06-24 12:28:41 +010094 /* --------------------------------------------------------
Juan Castillo7f1f0622014-09-09 09:49:23 +010095 * int console_core_putc(int c, uintptr_t base_addr)
Soby Mathewc389d772014-06-24 12:28:41 +010096 * Function to output a character over the console. It
97 * returns the character printed on success or -1 on error.
Soby Mathew69817f72014-07-14 15:43:21 +010098 * In : w0 - character to be printed
Soby Mathewc389d772014-06-24 12:28:41 +010099 * 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 /* Prepend '\r' to '\n' */
Soby Mathew69817f72014-07-14 15:43:21 +0100108 cmp w0, #0xA
Soby Mathewc389d772014-06-24 12:28:41 +0100109 b.ne 2f
1101:
111 /* Check if the transmit FIFO is full */
112 ldr w2, [x1, #UARTFR]
113 tbnz w2, #PL011_UARTFR_TXFF_BIT, 1b
114 mov w2, #0xD
115 str w2, [x1, #UARTDR]
1162:
117 /* Check if the transmit FIFO is full */
118 ldr w2, [x1, #UARTFR]
119 tbnz w2, #PL011_UARTFR_TXFF_BIT, 2b
120 str w0, [x1, #UARTDR]
121 ret
122putc_error:
123 mov w0, #-1
124 ret
Kévin Petita877c252015-03-24 14:03:57 +0000125endfunc console_core_putc
Soby Mathewc389d772014-06-24 12:28:41 +0100126
127 /* ---------------------------------------------
Juan Castillo7f1f0622014-09-09 09:49:23 +0100128 * int console_core_getc(uintptr_t base_addr)
Soby Mathewc389d772014-06-24 12:28:41 +0100129 * Function to get a character from the console.
130 * It returns the character grabbed on success
131 * or -1 on error.
Dan Handleyc863fa42015-04-01 16:51:20 +0100132 * In : x0 - console base address
Soby Mathewc389d772014-06-24 12:28:41 +0100133 * Clobber list : x0, x1
134 * ---------------------------------------------
135 */
Dan Handleyc863fa42015-04-01 16:51:20 +0100136func console_core_getc
137 cbz x0, getc_error
Soby Mathewc389d772014-06-24 12:28:41 +01001381:
139 /* Check if the receive FIFO is empty */
Dan Handleyc863fa42015-04-01 16:51:20 +0100140 ldr w1, [x0, #UARTFR]
141 tbnz w1, #PL011_UARTFR_RXFE_BIT, 1b
142 ldr w1, [x0, #UARTDR]
143 mov w0, w1
Soby Mathewc389d772014-06-24 12:28:41 +0100144 ret
145getc_error:
146 mov w0, #-1
147 ret
Dan Handleyc863fa42015-04-01 16:51:20 +0100148endfunc console_core_getc