]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Include/Drivers/PL011Uart.h
ArmPlatformPkg: Tidy PL011 UART driver
[mirror_edk2.git] / ArmPlatformPkg / Include / Drivers / PL011Uart.h
CommitLineData
051e63bb 1/** @file\r
2*\r
9f08a052 3* Copyright (c) 2011-2016, ARM Limited. All rights reserved.\r
051e63bb 4*\r
3402aac7
RC
5* This program and the accompanying materials\r
6* are licensed and made available under the terms and conditions of the BSD License\r
7* which accompanies this distribution. The full text of the license may be found at\r
8* http://opensource.org/licenses/bsd-license.php\r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
051e63bb 12*\r
13**/\r
14\r
15#ifndef __PL011_UART_H__\r
16#define __PL011_UART_H__\r
17\r
18#include <Uefi.h>\r
19#include <Protocol/SerialIo.h>\r
20\r
21// PL011 Registers\r
22#define UARTDR 0x000\r
23#define UARTRSR 0x004\r
24#define UARTECR 0x004\r
25#define UARTFR 0x018\r
26#define UARTILPR 0x020\r
27#define UARTIBRD 0x024\r
28#define UARTFBRD 0x028\r
29#define UARTLCR_H 0x02C\r
30#define UARTCR 0x030\r
31#define UARTIFLS 0x034\r
32#define UARTIMSC 0x038\r
33#define UARTRIS 0x03C\r
34#define UARTMIS 0x040\r
35#define UARTICR 0x044\r
36#define UARTDMACR 0x048\r
37\r
48edf6be
LL
38#define UARTPID0 0xFE0\r
39#define UARTPID1 0xFE4\r
40#define UARTPID2 0xFE8\r
41#define UARTPID3 0xFEC\r
42\r
051e63bb 43// Data status bits\r
44#define UART_DATA_ERROR_MASK 0x0F00\r
45\r
46// Status reg bits\r
47#define UART_STATUS_ERROR_MASK 0x0F\r
48\r
49// Flag reg bits\r
50#define PL011_UARTFR_RI (1 << 8) // Ring indicator\r
51#define PL011_UARTFR_TXFE (1 << 7) // Transmit FIFO empty\r
52#define PL011_UARTFR_RXFF (1 << 6) // Receive FIFO full\r
53#define PL011_UARTFR_TXFF (1 << 5) // Transmit FIFO full\r
54#define PL011_UARTFR_RXFE (1 << 4) // Receive FIFO empty\r
55#define PL011_UARTFR_BUSY (1 << 3) // UART busy\r
56#define PL011_UARTFR_DCD (1 << 2) // Data carrier detect\r
57#define PL011_UARTFR_DSR (1 << 1) // Data set ready\r
58#define PL011_UARTFR_CTS (1 << 0) // Clear to send\r
59\r
60// Flag reg bits - alternative names\r
61#define UART_TX_EMPTY_FLAG_MASK PL011_UARTFR_TXFE\r
62#define UART_RX_FULL_FLAG_MASK PL011_UARTFR_RXFF\r
63#define UART_TX_FULL_FLAG_MASK PL011_UARTFR_TXFF\r
64#define UART_RX_EMPTY_FLAG_MASK PL011_UARTFR_RXFE\r
65#define UART_BUSY_FLAG_MASK PL011_UARTFR_BUSY\r
66\r
67// Control reg bits\r
68#define PL011_UARTCR_CTSEN (1 << 15) // CTS hardware flow control enable\r
69#define PL011_UARTCR_RTSEN (1 << 14) // RTS hardware flow control enable\r
70#define PL011_UARTCR_RTS (1 << 11) // Request to send\r
71#define PL011_UARTCR_DTR (1 << 10) // Data transmit ready.\r
72#define PL011_UARTCR_RXE (1 << 9) // Receive enable\r
73#define PL011_UARTCR_TXE (1 << 8) // Transmit enable\r
74#define PL011_UARTCR_LBE (1 << 7) // Loopback enable\r
75#define PL011_UARTCR_UARTEN (1 << 0) // UART Enable\r
76\r
77// Line Control Register Bits\r
78#define PL011_UARTLCR_H_SPS (1 << 7) // Stick parity select\r
79#define PL011_UARTLCR_H_WLEN_8 (3 << 5)\r
80#define PL011_UARTLCR_H_WLEN_7 (2 << 5)\r
81#define PL011_UARTLCR_H_WLEN_6 (1 << 5)\r
82#define PL011_UARTLCR_H_WLEN_5 (0 << 5)\r
83#define PL011_UARTLCR_H_FEN (1 << 4) // FIFOs Enable\r
84#define PL011_UARTLCR_H_STP2 (1 << 3) // Two stop bits select\r
85#define PL011_UARTLCR_H_EPS (1 << 2) // Even parity select\r
86#define PL011_UARTLCR_H_PEN (1 << 1) // Parity Enable\r
87#define PL011_UARTLCR_H_BRK (1 << 0) // Send break\r
88\r
48edf6be
LL
89#define PL011_UARTPID2_VER(X) (((X) >> 4) & 0xF)\r
90#define PL011_VER_R1P4 0x2\r
91\r
051e63bb 92/*\r
93\r
9f08a052
EL
94 Initialise the serial port to the specified settings.\r
95 All unspecified settings will be set to the default values.\r
96\r
97 @param UartBase The base address of the serial device.\r
98 @param BaudRate The baud rate of the serial device. If the\r
99 baud rate is not supported, the speed will be\r
100 reduced to the nearest supported one and the\r
101 variable's value will be updated accordingly.\r
102 @param ReceiveFifoDepth The number of characters the device will\r
103 buffer on input. Value of 0 will use the\r
104 device's default FIFO depth.\r
105 @param Parity If applicable, this is the EFI_PARITY_TYPE\r
106 that is computed or checked as each character\r
107 is transmitted or received. If the device\r
108 does not support parity, the value is the\r
109 default parity value.\r
110 @param DataBits The number of data bits in each character.\r
111 @param StopBits If applicable, the EFI_STOP_BITS_TYPE number\r
112 of stop bits per character.\r
113 If the device does not support stop bits, the\r
114 value is the default stop bit value.\r
115\r
116 @retval RETURN_SUCCESS All attributes were set correctly on the\r
117 serial device.\r
118 @retval RETURN_INVALID_PARAMETER One or more of the attributes has an\r
119 unsupported value.\r
051e63bb 120\r
121**/\r
122RETURN_STATUS\r
123EFIAPI\r
124PL011UartInitializePort (\r
9f08a052 125 IN UINTN UartBase,\r
15e277d5 126 IN OUT UINT64 *BaudRate,\r
127 IN OUT UINT32 *ReceiveFifoDepth,\r
128 IN OUT EFI_PARITY_TYPE *Parity,\r
129 IN OUT UINT8 *DataBits,\r
130 IN OUT EFI_STOP_BITS_TYPE *StopBits\r
051e63bb 131 );\r
132\r
133/**\r
051e63bb 134\r
ab716191
RC
135 Assert or deassert the control signals on a serial port.\r
136 The following control signals are set according their bit settings :\r
137 . Request to Send\r
138 . Data Terminal Ready\r
139\r
140 @param[in] UartBase UART registers base address\r
141 @param[in] Control The following bits are taken into account :\r
142 . EFI_SERIAL_REQUEST_TO_SEND : assert/deassert the\r
143 "Request To Send" control signal if this bit is\r
144 equal to one/zero.\r
145 . EFI_SERIAL_DATA_TERMINAL_READY : assert/deassert\r
146 the "Data Terminal Ready" control signal if this\r
147 bit is equal to one/zero.\r
148 . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : enable/disable\r
149 the hardware loopback if this bit is equal to\r
150 one/zero.\r
151 . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : not supported.\r
152 . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : enable/\r
153 disable the hardware flow control based on CTS (Clear\r
154 To Send) and RTS (Ready To Send) control signals.\r
155\r
9f08a052
EL
156 @retval RETURN_SUCCESS The new control bits were set on the device.\r
157 @retval RETURN_UNSUPPORTED The device does not support this operation.\r
051e63bb 158\r
159**/\r
160RETURN_STATUS\r
161EFIAPI\r
162PL011UartSetControl (\r
ab716191
RC
163 IN UINTN UartBase,\r
164 IN UINT32 Control\r
051e63bb 165 );\r
166\r
167/**\r
051e63bb 168\r
d2e7e385
RC
169 Retrieve the status of the control bits on a serial device.\r
170\r
171 @param[in] UartBase UART registers base address\r
172 @param[out] Control Status of the control bits on a serial device :\r
173\r
9f08a052
EL
174 . EFI_SERIAL_DATA_CLEAR_TO_SEND,\r
175 EFI_SERIAL_DATA_SET_READY,\r
176 EFI_SERIAL_RING_INDICATE,\r
177 EFI_SERIAL_CARRIER_DETECT,\r
178 EFI_SERIAL_REQUEST_TO_SEND,\r
179 EFI_SERIAL_DATA_TERMINAL_READY\r
180 are all related to the DTE (Data Terminal Equipment)\r
181 and DCE (Data Communication Equipment) modes of\r
182 operation of the serial device.\r
183 . EFI_SERIAL_INPUT_BUFFER_EMPTY : equal to one if the\r
184 receive buffer is empty, 0 otherwise.\r
185 . EFI_SERIAL_OUTPUT_BUFFER_EMPTY : equal to one if the\r
186 transmit buffer is empty, 0 otherwise.\r
187 . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : equal to one if\r
188 the hardware loopback is enabled (the ouput feeds the\r
189 receive buffer), 0 otherwise.\r
190 . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : equal to one if\r
191 a loopback is accomplished by software, 0 otherwise.\r
192 . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : equal to\r
193 one if the hardware flow control based on CTS (Clear\r
194 To Send) and RTS (Ready To Send) control signals is\r
195 enabled, 0 otherwise.\r
d2e7e385
RC
196\r
197 @retval RETURN_SUCCESS The control bits were read from the serial device.\r
051e63bb 198\r
199**/\r
200RETURN_STATUS\r
201EFIAPI\r
202PL011UartGetControl (\r
d2e7e385
RC
203 IN UINTN UartBase,\r
204 OUT UINT32 *Control\r
051e63bb 205 );\r
206\r
207/**\r
208 Write data to serial device.\r
209\r
210 @param Buffer Point of data buffer which need to be written.\r
211 @param NumberOfBytes Number of output bytes which are cached in Buffer.\r
212\r
213 @retval 0 Write data failed.\r
214 @retval !0 Actual number of bytes written to serial device.\r
215\r
216**/\r
217UINTN\r
218EFIAPI\r
219PL011UartWrite (\r
220 IN UINTN UartBase,\r
221 IN UINT8 *Buffer,\r
222 IN UINTN NumberOfBytes\r
223 );\r
224\r
225/**\r
226 Read data from serial device and save the data in buffer.\r
227\r
228 @param Buffer Point of data buffer which need to be written.\r
229 @param NumberOfBytes Number of output bytes which are cached in Buffer.\r
230\r
231 @retval 0 Read data failed.\r
232 @retval !0 Actual number of bytes read from serial device.\r
233\r
234**/\r
235UINTN\r
236EFIAPI\r
237PL011UartRead (\r
238 IN UINTN UartBase,\r
239 OUT UINT8 *Buffer,\r
240 IN UINTN NumberOfBytes\r
241 );\r
242\r
243/**\r
244 Check to see if any data is available to be read from the debug device.\r
245\r
246 @retval EFI_SUCCESS At least one byte of data is available to be read\r
247 @retval EFI_NOT_READY No data is available to be read\r
248 @retval EFI_DEVICE_ERROR The serial device is not functioning properly\r
249\r
250**/\r
251BOOLEAN\r
252EFIAPI\r
253PL011UartPoll (\r
254 IN UINTN UartBase\r
255 );\r
256\r
257#endif\r