1/* 2 * Copyright 2017, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the GNU General Public License version 2. Note that NO WARRANTY is provided. 8 * See "LICENSE_GPLv2.txt" for details. 9 * 10 * @TAG(DATA61_GPL) 11 */ 12 13#include <config.h> 14#include <stdint.h> 15#include <util.h> 16#include <machine/io.h> 17#include <plat/machine/devices.h> 18 19#define UART_REG(x) ((volatile uint32_t *)(UART_PPTR + (x))) 20 21/* When DLAB=1, MU_IO is a baud rate register. 22 * Otherwise, write to TX, read to RX */ 23#define MU_IO 0x40 24/* When DLAB=1, MU_IIR is a baud rate register. 25 * Otherwise IRQ enable */ 26#define MU_IIR 0x44 27#define MU_IER 0x48 28#define MU_LCR 0x4C 29#define MU_MCR 0x50 30#define MU_LSR 0x54 31#define MU_MSR 0x58 32#define MU_SCRATCH 0x5C 33#define MU_CNTL 0x60 34 35 36/* This bit is set if the transmit FIFO can accept at least one byte.*/ 37#define MU_LSR_TXEMPTY BIT(5) 38/* This bit is set if the transmit FIFO is empty and the 39 * transmitter is idle. (Finished shifting out the last bit). */ 40#define MU_LSR_TXIDLE BIT(6) 41#define MU_LSR_RXOVERRUN BIT(1) 42#define MU_LSR_DATAREADY BIT(0) 43 44#define MU_LCR_DLAB BIT(7) 45#define MU_LCR_BREAK BIT(6) 46#define MU_LCR_DATASIZE BIT(0) 47 48 49#if defined(CONFIG_DEBUG_BUILD) || defined(CONFIG_PRINTING) 50void putDebugChar(unsigned char c) 51{ 52 while ( !(*UART_REG(MU_LSR) & MU_LSR_TXIDLE) ); 53 *UART_REG(MU_IO) = (c & 0xff); 54} 55#endif 56 57#ifdef CONFIG_DEBUG_BUILD 58unsigned char getDebugChar(void) 59{ 60 while ( !(*UART_REG(MU_LSR) & MU_LSR_DATAREADY) ); 61 return *UART_REG(MU_IO); 62} 63#endif /* CONFIG_DEBUG_BUILD */ 64