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