xref: /rk3399_ARM-atf/drivers/cadence/uart/aarch64/cdns_console.S (revision ad4c2ec6880f2f13f36e46a2bc3b624525b89c15)
19c94d3b3SSoby Mathew/*
2*ad4c2ec6SAntonio Nino Diaz * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
39c94d3b3SSoby Mathew *
49c94d3b3SSoby Mathew * Redistribution and use in source and binary forms, with or without
59c94d3b3SSoby Mathew * modification, are permitted provided that the following conditions are met:
69c94d3b3SSoby Mathew *
79c94d3b3SSoby Mathew * Redistributions of source code must retain the above copyright notice, this
89c94d3b3SSoby Mathew * list of conditions and the following disclaimer.
99c94d3b3SSoby Mathew *
109c94d3b3SSoby Mathew * Redistributions in binary form must reproduce the above copyright notice,
119c94d3b3SSoby Mathew * this list of conditions and the following disclaimer in the documentation
129c94d3b3SSoby Mathew * and/or other materials provided with the distribution.
139c94d3b3SSoby Mathew *
149c94d3b3SSoby Mathew * Neither the name of ARM nor the names of its contributors may be used
159c94d3b3SSoby Mathew * to endorse or promote products derived from this software without specific
169c94d3b3SSoby Mathew * prior written permission.
179c94d3b3SSoby Mathew *
189c94d3b3SSoby Mathew * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
199c94d3b3SSoby Mathew * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
209c94d3b3SSoby Mathew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
219c94d3b3SSoby Mathew * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
229c94d3b3SSoby Mathew * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
239c94d3b3SSoby Mathew * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
249c94d3b3SSoby Mathew * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
259c94d3b3SSoby Mathew * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
269c94d3b3SSoby Mathew * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
279c94d3b3SSoby Mathew * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
289c94d3b3SSoby Mathew * POSSIBILITY OF SUCH DAMAGE.
299c94d3b3SSoby Mathew */
309c94d3b3SSoby Mathew#include <arch.h>
319c94d3b3SSoby Mathew#include <asm_macros.S>
329c94d3b3SSoby Mathew#include <cadence/cdns_uart.h>
339c94d3b3SSoby Mathew
349c94d3b3SSoby Mathew	.globl  console_core_init
359c94d3b3SSoby Mathew	.globl  console_core_putc
369c94d3b3SSoby Mathew	.globl  console_core_getc
37*ad4c2ec6SAntonio Nino Diaz	.globl	console_core_flush
389c94d3b3SSoby Mathew
399c94d3b3SSoby Mathew	/* -----------------------------------------------
409c94d3b3SSoby Mathew	 * int console_core_init(unsigned long base_addr,
419c94d3b3SSoby Mathew	 * unsigned int uart_clk, unsigned int baud_rate)
429c94d3b3SSoby Mathew	 * Function to initialize the console without a
439c94d3b3SSoby Mathew	 * C Runtime to print debug information. This
449c94d3b3SSoby Mathew	 * function will be accessed by console_init and
459c94d3b3SSoby Mathew	 * crash reporting.
469c94d3b3SSoby Mathew	 * We assume that the bootloader already set up
479c94d3b3SSoby Mathew	 * the HW (baud, ...) and only enable the trans-
489c94d3b3SSoby Mathew	 * mitter and receiver here.
499c94d3b3SSoby Mathew	 * In: x0 - console base address
509c94d3b3SSoby Mathew	 *     w1 - Uart clock in Hz
519c94d3b3SSoby Mathew	 *     w2 - Baud rate
529c94d3b3SSoby Mathew	 * Out: return 1 on success else 0 on error
539c94d3b3SSoby Mathew	 * Clobber list : x1, x2, x3
549c94d3b3SSoby Mathew	 * -----------------------------------------------
559c94d3b3SSoby Mathew	 */
569c94d3b3SSoby Mathewfunc console_core_init
579c94d3b3SSoby Mathew	/* Check the input base address */
589c94d3b3SSoby Mathew	cbz	x0, core_init_fail
599c94d3b3SSoby Mathew	/* Check baud rate and uart clock for sanity */
609c94d3b3SSoby Mathew	cbz	w1, core_init_fail
619c94d3b3SSoby Mathew	cbz	w2, core_init_fail
629c94d3b3SSoby Mathew
639c94d3b3SSoby Mathew	/* RX/TX enabled & reset */
649c94d3b3SSoby Mathew	mov	w3, #(R_UART_CR_TX_EN | R_UART_CR_RX_EN | R_UART_CR_TXRST | R_UART_CR_RXRST)
659c94d3b3SSoby Mathew	str	w3, [x0, #R_UART_CR]
669c94d3b3SSoby Mathew
679c94d3b3SSoby Mathew	mov	w0, #1
689c94d3b3SSoby Mathew	ret
699c94d3b3SSoby Mathewcore_init_fail:
709c94d3b3SSoby Mathew	mov	w0, wzr
719c94d3b3SSoby Mathew	ret
729c94d3b3SSoby Mathewendfunc console_core_init
739c94d3b3SSoby Mathew
749c94d3b3SSoby Mathew	/* --------------------------------------------------------
759c94d3b3SSoby Mathew	 * int console_core_putc(int c, unsigned long base_addr)
769c94d3b3SSoby Mathew	 * Function to output a character over the console. It
779c94d3b3SSoby Mathew	 * returns the character printed on success or -1 on error.
789c94d3b3SSoby Mathew	 * In : w0 - character to be printed
799c94d3b3SSoby Mathew	 *      x1 - console base address
809c94d3b3SSoby Mathew	 * Out : return -1 on error else return character.
819c94d3b3SSoby Mathew	 * Clobber list : x2
829c94d3b3SSoby Mathew	 * --------------------------------------------------------
839c94d3b3SSoby Mathew	 */
849c94d3b3SSoby Mathewfunc console_core_putc
859c94d3b3SSoby Mathew	/* Check the input parameter */
869c94d3b3SSoby Mathew	cbz	x1, putc_error
879c94d3b3SSoby Mathew	/* Prepend '\r' to '\n' */
889c94d3b3SSoby Mathew	cmp	w0, #0xA
899c94d3b3SSoby Mathew	b.ne	2f
909c94d3b3SSoby Mathew1:
919c94d3b3SSoby Mathew	/* Check if the transmit FIFO is full */
929c94d3b3SSoby Mathew	ldr	w2, [x1, #R_UART_SR]
939c94d3b3SSoby Mathew	tbnz	w2, #UART_SR_INTR_TFUL_BIT, 1b
949c94d3b3SSoby Mathew	mov	w2, #0xD
959c94d3b3SSoby Mathew	str	w2, [x1, #R_UART_TX]
969c94d3b3SSoby Mathew2:
979c94d3b3SSoby Mathew	/* Check if the transmit FIFO is full */
989c94d3b3SSoby Mathew	ldr	w2, [x1, #R_UART_SR]
999c94d3b3SSoby Mathew	tbnz	w2, #UART_SR_INTR_TFUL_BIT, 2b
1009c94d3b3SSoby Mathew	str	w0, [x1, #R_UART_TX]
1019c94d3b3SSoby Mathew	ret
1029c94d3b3SSoby Mathewputc_error:
1039c94d3b3SSoby Mathew	mov	w0, #-1
1049c94d3b3SSoby Mathew	ret
1059c94d3b3SSoby Mathewendfunc console_core_putc
1069c94d3b3SSoby Mathew
1079c94d3b3SSoby Mathew	/* ---------------------------------------------
1089c94d3b3SSoby Mathew	 * int console_core_getc(unsigned long base_addr)
1099c94d3b3SSoby Mathew	 * Function to get a character from the console.
1109c94d3b3SSoby Mathew	 * It returns the character grabbed on success
1119c94d3b3SSoby Mathew	 * or -1 on error.
1129c94d3b3SSoby Mathew	 * In : x0 - console base address
1139c94d3b3SSoby Mathew	 * Clobber list : x0, x1
1149c94d3b3SSoby Mathew	 * ---------------------------------------------
1159c94d3b3SSoby Mathew	 */
1169c94d3b3SSoby Mathewfunc console_core_getc
1179c94d3b3SSoby Mathew	cbz	x0, getc_error
1189c94d3b3SSoby Mathew1:
1199c94d3b3SSoby Mathew	/* Check if the receive FIFO is empty */
1209c94d3b3SSoby Mathew	ldr	w1, [x0, #R_UART_SR]
1219c94d3b3SSoby Mathew	tbnz	w1, #UART_SR_INTR_REMPTY_BIT, 1b
1229c94d3b3SSoby Mathew	ldr	w1, [x0, #R_UART_RX]
1239c94d3b3SSoby Mathew	mov	w0, w1
1249c94d3b3SSoby Mathew	ret
1259c94d3b3SSoby Mathewgetc_error:
1269c94d3b3SSoby Mathew	mov	w0, #-1
1279c94d3b3SSoby Mathew	ret
1289c94d3b3SSoby Mathewendfunc console_core_getc
129*ad4c2ec6SAntonio Nino Diaz
130*ad4c2ec6SAntonio Nino Diaz	/* ---------------------------------------------
131*ad4c2ec6SAntonio Nino Diaz	 * int console_core_flush(uintptr_t base_addr)
132*ad4c2ec6SAntonio Nino Diaz	 * Function to force a write of all buffered
133*ad4c2ec6SAntonio Nino Diaz	 * data that hasn't been output.
134*ad4c2ec6SAntonio Nino Diaz	 * In : x0 - console base address
135*ad4c2ec6SAntonio Nino Diaz	 * Out : return -1 on error else return 0.
136*ad4c2ec6SAntonio Nino Diaz	 * Clobber list : x0, x1
137*ad4c2ec6SAntonio Nino Diaz	 * ---------------------------------------------
138*ad4c2ec6SAntonio Nino Diaz	 */
139*ad4c2ec6SAntonio Nino Diazfunc console_core_flush
140*ad4c2ec6SAntonio Nino Diaz	/* Placeholder */
141*ad4c2ec6SAntonio Nino Diaz	mov	w0, #0
142*ad4c2ec6SAntonio Nino Diaz	ret
143*ad4c2ec6SAntonio Nino Diazendfunc console_core_flush
144