1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved. 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu */ 6*91f16700Schasinglulu 7*91f16700Schasinglulu #ifndef PL011_H 8*91f16700Schasinglulu #define PL011_H 9*91f16700Schasinglulu 10*91f16700Schasinglulu #include <drivers/console.h> 11*91f16700Schasinglulu 12*91f16700Schasinglulu /* PL011 Registers */ 13*91f16700Schasinglulu #define UARTDR 0x000 14*91f16700Schasinglulu #define UARTRSR 0x004 15*91f16700Schasinglulu #define UARTECR 0x004 16*91f16700Schasinglulu #define UARTFR 0x018 17*91f16700Schasinglulu #define UARTIMSC 0x038 18*91f16700Schasinglulu #define UARTRIS 0x03C 19*91f16700Schasinglulu #define UARTICR 0x044 20*91f16700Schasinglulu 21*91f16700Schasinglulu /* PL011 registers (out of the SBSA specification) */ 22*91f16700Schasinglulu #if !PL011_GENERIC_UART 23*91f16700Schasinglulu #define UARTILPR 0x020 24*91f16700Schasinglulu #define UARTIBRD 0x024 25*91f16700Schasinglulu #define UARTFBRD 0x028 26*91f16700Schasinglulu #define UARTLCR_H 0x02C 27*91f16700Schasinglulu #define UARTCR 0x030 28*91f16700Schasinglulu #define UARTIFLS 0x034 29*91f16700Schasinglulu #define UARTMIS 0x040 30*91f16700Schasinglulu #define UARTDMACR 0x048 31*91f16700Schasinglulu #endif /* !PL011_GENERIC_UART */ 32*91f16700Schasinglulu 33*91f16700Schasinglulu /* Data status bits */ 34*91f16700Schasinglulu #define UART_DATA_ERROR_MASK 0x0F00 35*91f16700Schasinglulu 36*91f16700Schasinglulu /* Status reg bits */ 37*91f16700Schasinglulu #define UART_STATUS_ERROR_MASK 0x0F 38*91f16700Schasinglulu 39*91f16700Schasinglulu /* Flag reg bits */ 40*91f16700Schasinglulu #define PL011_UARTFR_RI (1 << 8) /* Ring indicator */ 41*91f16700Schasinglulu #define PL011_UARTFR_TXFE (1 << 7) /* Transmit FIFO empty */ 42*91f16700Schasinglulu #define PL011_UARTFR_RXFF (1 << 6) /* Receive FIFO full */ 43*91f16700Schasinglulu #define PL011_UARTFR_TXFF (1 << 5) /* Transmit FIFO full */ 44*91f16700Schasinglulu #define PL011_UARTFR_RXFE (1 << 4) /* Receive FIFO empty */ 45*91f16700Schasinglulu #define PL011_UARTFR_BUSY (1 << 3) /* UART busy */ 46*91f16700Schasinglulu #define PL011_UARTFR_DCD (1 << 2) /* Data carrier detect */ 47*91f16700Schasinglulu #define PL011_UARTFR_DSR (1 << 1) /* Data set ready */ 48*91f16700Schasinglulu #define PL011_UARTFR_CTS (1 << 0) /* Clear to send */ 49*91f16700Schasinglulu 50*91f16700Schasinglulu #define PL011_UARTFR_TXFF_BIT 5 /* Transmit FIFO full bit in UARTFR register */ 51*91f16700Schasinglulu #define PL011_UARTFR_RXFE_BIT 4 /* Receive FIFO empty bit in UARTFR register */ 52*91f16700Schasinglulu #define PL011_UARTFR_BUSY_BIT 3 /* UART busy bit in UARTFR register */ 53*91f16700Schasinglulu 54*91f16700Schasinglulu /* Control reg bits */ 55*91f16700Schasinglulu #if !PL011_GENERIC_UART 56*91f16700Schasinglulu #define PL011_UARTCR_CTSEN (1 << 15) /* CTS hardware flow control enable */ 57*91f16700Schasinglulu #define PL011_UARTCR_RTSEN (1 << 14) /* RTS hardware flow control enable */ 58*91f16700Schasinglulu #define PL011_UARTCR_RTS (1 << 11) /* Request to send */ 59*91f16700Schasinglulu #define PL011_UARTCR_DTR (1 << 10) /* Data transmit ready. */ 60*91f16700Schasinglulu #define PL011_UARTCR_RXE (1 << 9) /* Receive enable */ 61*91f16700Schasinglulu #define PL011_UARTCR_TXE (1 << 8) /* Transmit enable */ 62*91f16700Schasinglulu #define PL011_UARTCR_LBE (1 << 7) /* Loopback enable */ 63*91f16700Schasinglulu #define PL011_UARTCR_UARTEN (1 << 0) /* UART Enable */ 64*91f16700Schasinglulu 65*91f16700Schasinglulu #if !defined(PL011_LINE_CONTROL) 66*91f16700Schasinglulu /* FIFO Enabled / No Parity / 8 Data bit / One Stop Bit */ 67*91f16700Schasinglulu #define PL011_LINE_CONTROL (PL011_UARTLCR_H_FEN | PL011_UARTLCR_H_WLEN_8) 68*91f16700Schasinglulu #endif 69*91f16700Schasinglulu 70*91f16700Schasinglulu /* Line Control Register Bits */ 71*91f16700Schasinglulu #define PL011_UARTLCR_H_SPS (1 << 7) /* Stick parity select */ 72*91f16700Schasinglulu #define PL011_UARTLCR_H_WLEN_8 (3 << 5) 73*91f16700Schasinglulu #define PL011_UARTLCR_H_WLEN_7 (2 << 5) 74*91f16700Schasinglulu #define PL011_UARTLCR_H_WLEN_6 (1 << 5) 75*91f16700Schasinglulu #define PL011_UARTLCR_H_WLEN_5 (0 << 5) 76*91f16700Schasinglulu #define PL011_UARTLCR_H_FEN (1 << 4) /* FIFOs Enable */ 77*91f16700Schasinglulu #define PL011_UARTLCR_H_STP2 (1 << 3) /* Two stop bits select */ 78*91f16700Schasinglulu #define PL011_UARTLCR_H_EPS (1 << 2) /* Even parity select */ 79*91f16700Schasinglulu #define PL011_UARTLCR_H_PEN (1 << 1) /* Parity Enable */ 80*91f16700Schasinglulu #define PL011_UARTLCR_H_BRK (1 << 0) /* Send break */ 81*91f16700Schasinglulu 82*91f16700Schasinglulu #endif /* !PL011_GENERIC_UART */ 83*91f16700Schasinglulu 84*91f16700Schasinglulu #ifndef __ASSEMBLER__ 85*91f16700Schasinglulu 86*91f16700Schasinglulu #include <stdint.h> 87*91f16700Schasinglulu 88*91f16700Schasinglulu /* 89*91f16700Schasinglulu * Initialize a new PL011 console instance and register it with the console 90*91f16700Schasinglulu * framework. The |console| pointer must point to storage that will be valid 91*91f16700Schasinglulu * for the lifetime of the console, such as a global or static local variable. 92*91f16700Schasinglulu * Its contents will be reinitialized from scratch. 93*91f16700Schasinglulu */ 94*91f16700Schasinglulu int console_pl011_register(uintptr_t baseaddr, uint32_t clock, uint32_t baud, 95*91f16700Schasinglulu console_t *console); 96*91f16700Schasinglulu 97*91f16700Schasinglulu #endif /*__ASSEMBLER__*/ 98*91f16700Schasinglulu 99*91f16700Schasinglulu #endif /* PL011_H */ 100