]>
Commit | Line | Data |
---|---|---|
051e63bb | 1 | /** @file\r |
2 | *\r | |
ab716191 | 3 | * Copyright (c) 2011-2014, 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 | |
38 | // Data status bits\r | |
39 | #define UART_DATA_ERROR_MASK 0x0F00\r | |
40 | \r | |
41 | // Status reg bits\r | |
42 | #define UART_STATUS_ERROR_MASK 0x0F\r | |
43 | \r | |
44 | // Flag reg bits\r | |
45 | #define PL011_UARTFR_RI (1 << 8) // Ring indicator\r | |
46 | #define PL011_UARTFR_TXFE (1 << 7) // Transmit FIFO empty\r | |
47 | #define PL011_UARTFR_RXFF (1 << 6) // Receive FIFO full\r | |
48 | #define PL011_UARTFR_TXFF (1 << 5) // Transmit FIFO full\r | |
49 | #define PL011_UARTFR_RXFE (1 << 4) // Receive FIFO empty\r | |
50 | #define PL011_UARTFR_BUSY (1 << 3) // UART busy\r | |
51 | #define PL011_UARTFR_DCD (1 << 2) // Data carrier detect\r | |
52 | #define PL011_UARTFR_DSR (1 << 1) // Data set ready\r | |
53 | #define PL011_UARTFR_CTS (1 << 0) // Clear to send\r | |
54 | \r | |
55 | // Flag reg bits - alternative names\r | |
56 | #define UART_TX_EMPTY_FLAG_MASK PL011_UARTFR_TXFE\r | |
57 | #define UART_RX_FULL_FLAG_MASK PL011_UARTFR_RXFF\r | |
58 | #define UART_TX_FULL_FLAG_MASK PL011_UARTFR_TXFF\r | |
59 | #define UART_RX_EMPTY_FLAG_MASK PL011_UARTFR_RXFE\r | |
60 | #define UART_BUSY_FLAG_MASK PL011_UARTFR_BUSY\r | |
61 | \r | |
62 | // Control reg bits\r | |
63 | #define PL011_UARTCR_CTSEN (1 << 15) // CTS hardware flow control enable\r | |
64 | #define PL011_UARTCR_RTSEN (1 << 14) // RTS hardware flow control enable\r | |
65 | #define PL011_UARTCR_RTS (1 << 11) // Request to send\r | |
66 | #define PL011_UARTCR_DTR (1 << 10) // Data transmit ready.\r | |
67 | #define PL011_UARTCR_RXE (1 << 9) // Receive enable\r | |
68 | #define PL011_UARTCR_TXE (1 << 8) // Transmit enable\r | |
69 | #define PL011_UARTCR_LBE (1 << 7) // Loopback enable\r | |
70 | #define PL011_UARTCR_UARTEN (1 << 0) // UART Enable\r | |
71 | \r | |
72 | // Line Control Register Bits\r | |
73 | #define PL011_UARTLCR_H_SPS (1 << 7) // Stick parity select\r | |
74 | #define PL011_UARTLCR_H_WLEN_8 (3 << 5)\r | |
75 | #define PL011_UARTLCR_H_WLEN_7 (2 << 5)\r | |
76 | #define PL011_UARTLCR_H_WLEN_6 (1 << 5)\r | |
77 | #define PL011_UARTLCR_H_WLEN_5 (0 << 5)\r | |
78 | #define PL011_UARTLCR_H_FEN (1 << 4) // FIFOs Enable\r | |
79 | #define PL011_UARTLCR_H_STP2 (1 << 3) // Two stop bits select\r | |
80 | #define PL011_UARTLCR_H_EPS (1 << 2) // Even parity select\r | |
81 | #define PL011_UARTLCR_H_PEN (1 << 1) // Parity Enable\r | |
82 | #define PL011_UARTLCR_H_BRK (1 << 0) // Send break\r | |
83 | \r | |
84 | /*\r | |
85 | \r | |
86 | Programmed hardware of Serial port.\r | |
87 | \r | |
88 | @return Always return EFI_UNSUPPORTED.\r | |
89 | \r | |
90 | **/\r | |
91 | RETURN_STATUS\r | |
92 | EFIAPI\r | |
93 | PL011UartInitializePort (\r | |
15e277d5 | 94 | IN OUT UINTN UartBase,\r |
95 | IN OUT UINT64 *BaudRate,\r | |
96 | IN OUT UINT32 *ReceiveFifoDepth,\r | |
97 | IN OUT EFI_PARITY_TYPE *Parity,\r | |
98 | IN OUT UINT8 *DataBits,\r | |
99 | IN OUT EFI_STOP_BITS_TYPE *StopBits\r | |
051e63bb | 100 | );\r |
101 | \r | |
102 | /**\r | |
051e63bb | 103 | \r |
ab716191 RC |
104 | Assert or deassert the control signals on a serial port.\r |
105 | The following control signals are set according their bit settings :\r | |
106 | . Request to Send\r | |
107 | . Data Terminal Ready\r | |
108 | \r | |
109 | @param[in] UartBase UART registers base address\r | |
110 | @param[in] Control The following bits are taken into account :\r | |
111 | . EFI_SERIAL_REQUEST_TO_SEND : assert/deassert the\r | |
112 | "Request To Send" control signal if this bit is\r | |
113 | equal to one/zero.\r | |
114 | . EFI_SERIAL_DATA_TERMINAL_READY : assert/deassert\r | |
115 | the "Data Terminal Ready" control signal if this\r | |
116 | bit is equal to one/zero.\r | |
117 | . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : enable/disable\r | |
118 | the hardware loopback if this bit is equal to\r | |
119 | one/zero.\r | |
120 | . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : not supported.\r | |
121 | . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : enable/\r | |
122 | disable the hardware flow control based on CTS (Clear\r | |
123 | To Send) and RTS (Ready To Send) control signals.\r | |
124 | \r | |
125 | @retval RETURN_SUCCESS The new control bits were set on the serial device.\r | |
126 | @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r | |
051e63bb | 127 | \r |
128 | **/\r | |
129 | RETURN_STATUS\r | |
130 | EFIAPI\r | |
131 | PL011UartSetControl (\r | |
ab716191 RC |
132 | IN UINTN UartBase,\r |
133 | IN UINT32 Control\r | |
051e63bb | 134 | );\r |
135 | \r | |
136 | /**\r | |
051e63bb | 137 | \r |
d2e7e385 RC |
138 | Retrieve the status of the control bits on a serial device.\r |
139 | \r | |
140 | @param[in] UartBase UART registers base address\r | |
141 | @param[out] Control Status of the control bits on a serial device :\r | |
142 | \r | |
143 | . EFI_SERIAL_DATA_CLEAR_TO_SEND, EFI_SERIAL_DATA_SET_READY,\r | |
144 | EFI_SERIAL_RING_INDICATE, EFI_SERIAL_CARRIER_DETECT,\r | |
145 | EFI_SERIAL_REQUEST_TO_SEND, EFI_SERIAL_DATA_TERMINAL_READY\r | |
146 | are all related to the DTE (Data Terminal Equipment) and\r | |
147 | DCE (Data Communication Equipment) modes of operation of\r | |
148 | the serial device.\r | |
149 | . EFI_SERIAL_INPUT_BUFFER_EMPTY : equal to one if the receive\r | |
150 | buffer is empty, 0 otherwise.\r | |
151 | . EFI_SERIAL_OUTPUT_BUFFER_EMPTY : equal to one if the transmit\r | |
152 | buffer is empty, 0 otherwise.\r | |
153 | . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : equal to one if the\r | |
154 | hardware loopback is enabled (the ouput feeds the receive\r | |
155 | buffer), 0 otherwise.\r | |
156 | . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : equal to one if a\r | |
157 | loopback is accomplished by software, 0 otherwise.\r | |
158 | . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : equal to one if the\r | |
159 | hardware flow control based on CTS (Clear To Send) and RTS\r | |
160 | (Ready To Send) control signals is enabled, 0 otherwise.\r | |
161 | \r | |
162 | \r | |
163 | @retval RETURN_SUCCESS The control bits were read from the serial device.\r | |
051e63bb | 164 | \r |
165 | **/\r | |
166 | RETURN_STATUS\r | |
167 | EFIAPI\r | |
168 | PL011UartGetControl (\r | |
d2e7e385 RC |
169 | IN UINTN UartBase,\r |
170 | OUT UINT32 *Control\r | |
051e63bb | 171 | );\r |
172 | \r | |
173 | /**\r | |
174 | Write data to serial device.\r | |
175 | \r | |
176 | @param Buffer Point of data buffer which need to be written.\r | |
177 | @param NumberOfBytes Number of output bytes which are cached in Buffer.\r | |
178 | \r | |
179 | @retval 0 Write data failed.\r | |
180 | @retval !0 Actual number of bytes written to serial device.\r | |
181 | \r | |
182 | **/\r | |
183 | UINTN\r | |
184 | EFIAPI\r | |
185 | PL011UartWrite (\r | |
186 | IN UINTN UartBase,\r | |
187 | IN UINT8 *Buffer,\r | |
188 | IN UINTN NumberOfBytes\r | |
189 | );\r | |
190 | \r | |
191 | /**\r | |
192 | Read data from serial device and save the data in buffer.\r | |
193 | \r | |
194 | @param Buffer Point of data buffer which need to be written.\r | |
195 | @param NumberOfBytes Number of output bytes which are cached in Buffer.\r | |
196 | \r | |
197 | @retval 0 Read data failed.\r | |
198 | @retval !0 Actual number of bytes read from serial device.\r | |
199 | \r | |
200 | **/\r | |
201 | UINTN\r | |
202 | EFIAPI\r | |
203 | PL011UartRead (\r | |
204 | IN UINTN UartBase,\r | |
205 | OUT UINT8 *Buffer,\r | |
206 | IN UINTN NumberOfBytes\r | |
207 | );\r | |
208 | \r | |
209 | /**\r | |
210 | Check to see if any data is available to be read from the debug device.\r | |
211 | \r | |
212 | @retval EFI_SUCCESS At least one byte of data is available to be read\r | |
213 | @retval EFI_NOT_READY No data is available to be read\r | |
214 | @retval EFI_DEVICE_ERROR The serial device is not functioning properly\r | |
215 | \r | |
216 | **/\r | |
217 | BOOLEAN\r | |
218 | EFIAPI\r | |
219 | PL011UartPoll (\r | |
220 | IN UINTN UartBase\r | |
221 | );\r | |
222 | \r | |
223 | #endif\r |