xref: /rk3399_ARM-atf/drivers/cadence/uart/aarch64/cdns_console.S (revision 82cb2c1ad9897473743f08437d0a3995bed561b9)
19c94d3b3SSoby Mathew/*
2ad4c2ec6SAntonio Nino Diaz * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
39c94d3b3SSoby Mathew *
4*82cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
59c94d3b3SSoby Mathew */
69c94d3b3SSoby Mathew#include <arch.h>
79c94d3b3SSoby Mathew#include <asm_macros.S>
89c94d3b3SSoby Mathew#include <cadence/cdns_uart.h>
99c94d3b3SSoby Mathew
109c94d3b3SSoby Mathew	.globl  console_core_init
119c94d3b3SSoby Mathew	.globl  console_core_putc
129c94d3b3SSoby Mathew	.globl  console_core_getc
13ad4c2ec6SAntonio Nino Diaz	.globl	console_core_flush
149c94d3b3SSoby Mathew
159c94d3b3SSoby Mathew	/* -----------------------------------------------
169c94d3b3SSoby Mathew	 * int console_core_init(unsigned long base_addr,
179c94d3b3SSoby Mathew	 * unsigned int uart_clk, unsigned int baud_rate)
189c94d3b3SSoby Mathew	 * Function to initialize the console without a
199c94d3b3SSoby Mathew	 * C Runtime to print debug information. This
209c94d3b3SSoby Mathew	 * function will be accessed by console_init and
219c94d3b3SSoby Mathew	 * crash reporting.
229c94d3b3SSoby Mathew	 * We assume that the bootloader already set up
239c94d3b3SSoby Mathew	 * the HW (baud, ...) and only enable the trans-
249c94d3b3SSoby Mathew	 * mitter and receiver here.
259c94d3b3SSoby Mathew	 * In: x0 - console base address
269c94d3b3SSoby Mathew	 *     w1 - Uart clock in Hz
279c94d3b3SSoby Mathew	 *     w2 - Baud rate
289c94d3b3SSoby Mathew	 * Out: return 1 on success else 0 on error
299c94d3b3SSoby Mathew	 * Clobber list : x1, x2, x3
309c94d3b3SSoby Mathew	 * -----------------------------------------------
319c94d3b3SSoby Mathew	 */
329c94d3b3SSoby Mathewfunc console_core_init
339c94d3b3SSoby Mathew	/* Check the input base address */
349c94d3b3SSoby Mathew	cbz	x0, core_init_fail
359c94d3b3SSoby Mathew	/* Check baud rate and uart clock for sanity */
369c94d3b3SSoby Mathew	cbz	w1, core_init_fail
379c94d3b3SSoby Mathew	cbz	w2, core_init_fail
389c94d3b3SSoby Mathew
399c94d3b3SSoby Mathew	/* RX/TX enabled & reset */
409c94d3b3SSoby Mathew	mov	w3, #(R_UART_CR_TX_EN | R_UART_CR_RX_EN | R_UART_CR_TXRST | R_UART_CR_RXRST)
419c94d3b3SSoby Mathew	str	w3, [x0, #R_UART_CR]
429c94d3b3SSoby Mathew
439c94d3b3SSoby Mathew	mov	w0, #1
449c94d3b3SSoby Mathew	ret
459c94d3b3SSoby Mathewcore_init_fail:
469c94d3b3SSoby Mathew	mov	w0, wzr
479c94d3b3SSoby Mathew	ret
489c94d3b3SSoby Mathewendfunc console_core_init
499c94d3b3SSoby Mathew
509c94d3b3SSoby Mathew	/* --------------------------------------------------------
519c94d3b3SSoby Mathew	 * int console_core_putc(int c, unsigned long base_addr)
529c94d3b3SSoby Mathew	 * Function to output a character over the console. It
539c94d3b3SSoby Mathew	 * returns the character printed on success or -1 on error.
549c94d3b3SSoby Mathew	 * In : w0 - character to be printed
559c94d3b3SSoby Mathew	 *      x1 - console base address
569c94d3b3SSoby Mathew	 * Out : return -1 on error else return character.
579c94d3b3SSoby Mathew	 * Clobber list : x2
589c94d3b3SSoby Mathew	 * --------------------------------------------------------
599c94d3b3SSoby Mathew	 */
609c94d3b3SSoby Mathewfunc console_core_putc
619c94d3b3SSoby Mathew	/* Check the input parameter */
629c94d3b3SSoby Mathew	cbz	x1, putc_error
639c94d3b3SSoby Mathew	/* Prepend '\r' to '\n' */
649c94d3b3SSoby Mathew	cmp	w0, #0xA
659c94d3b3SSoby Mathew	b.ne	2f
669c94d3b3SSoby Mathew1:
679c94d3b3SSoby Mathew	/* Check if the transmit FIFO is full */
689c94d3b3SSoby Mathew	ldr	w2, [x1, #R_UART_SR]
699c94d3b3SSoby Mathew	tbnz	w2, #UART_SR_INTR_TFUL_BIT, 1b
709c94d3b3SSoby Mathew	mov	w2, #0xD
719c94d3b3SSoby Mathew	str	w2, [x1, #R_UART_TX]
729c94d3b3SSoby Mathew2:
739c94d3b3SSoby Mathew	/* Check if the transmit FIFO is full */
749c94d3b3SSoby Mathew	ldr	w2, [x1, #R_UART_SR]
759c94d3b3SSoby Mathew	tbnz	w2, #UART_SR_INTR_TFUL_BIT, 2b
769c94d3b3SSoby Mathew	str	w0, [x1, #R_UART_TX]
779c94d3b3SSoby Mathew	ret
789c94d3b3SSoby Mathewputc_error:
799c94d3b3SSoby Mathew	mov	w0, #-1
809c94d3b3SSoby Mathew	ret
819c94d3b3SSoby Mathewendfunc console_core_putc
829c94d3b3SSoby Mathew
839c94d3b3SSoby Mathew	/* ---------------------------------------------
849c94d3b3SSoby Mathew	 * int console_core_getc(unsigned long base_addr)
859c94d3b3SSoby Mathew	 * Function to get a character from the console.
869c94d3b3SSoby Mathew	 * It returns the character grabbed on success
879c94d3b3SSoby Mathew	 * or -1 on error.
889c94d3b3SSoby Mathew	 * In : x0 - console base address
899c94d3b3SSoby Mathew	 * Clobber list : x0, x1
909c94d3b3SSoby Mathew	 * ---------------------------------------------
919c94d3b3SSoby Mathew	 */
929c94d3b3SSoby Mathewfunc console_core_getc
939c94d3b3SSoby Mathew	cbz	x0, getc_error
949c94d3b3SSoby Mathew1:
959c94d3b3SSoby Mathew	/* Check if the receive FIFO is empty */
969c94d3b3SSoby Mathew	ldr	w1, [x0, #R_UART_SR]
979c94d3b3SSoby Mathew	tbnz	w1, #UART_SR_INTR_REMPTY_BIT, 1b
989c94d3b3SSoby Mathew	ldr	w1, [x0, #R_UART_RX]
999c94d3b3SSoby Mathew	mov	w0, w1
1009c94d3b3SSoby Mathew	ret
1019c94d3b3SSoby Mathewgetc_error:
1029c94d3b3SSoby Mathew	mov	w0, #-1
1039c94d3b3SSoby Mathew	ret
1049c94d3b3SSoby Mathewendfunc console_core_getc
105ad4c2ec6SAntonio Nino Diaz
106ad4c2ec6SAntonio Nino Diaz	/* ---------------------------------------------
107ad4c2ec6SAntonio Nino Diaz	 * int console_core_flush(uintptr_t base_addr)
108ad4c2ec6SAntonio Nino Diaz	 * Function to force a write of all buffered
109ad4c2ec6SAntonio Nino Diaz	 * data that hasn't been output.
110ad4c2ec6SAntonio Nino Diaz	 * In : x0 - console base address
111ad4c2ec6SAntonio Nino Diaz	 * Out : return -1 on error else return 0.
112ad4c2ec6SAntonio Nino Diaz	 * Clobber list : x0, x1
113ad4c2ec6SAntonio Nino Diaz	 * ---------------------------------------------
114ad4c2ec6SAntonio Nino Diaz	 */
115ad4c2ec6SAntonio Nino Diazfunc console_core_flush
116ad4c2ec6SAntonio Nino Diaz	/* Placeholder */
117ad4c2ec6SAntonio Nino Diaz	mov	w0, #0
118ad4c2ec6SAntonio Nino Diaz	ret
119ad4c2ec6SAntonio Nino Diazendfunc console_core_flush
120