21#define FRACTION_PART_SIZE_IN_BITS 6
22#define FRACTION_PART_MASK ((1 << FRACTION_PART_SIZE_IN_BITS) - 1)
28 EFI_SERIAL_REQUEST_TO_SEND |
29 EFI_SERIAL_DATA_TERMINAL_READY |
30 EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE |
31 EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE |
32 EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;
38 EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE;
78 IN UINT32 UartClkInHz,
79 IN OUT UINT64 *BaudRate,
80 IN OUT UINT32 *ReceiveFifoDepth,
82 IN OUT UINT8 *DataBits,
90 UINT32 HardwareFifoDepth;
93 HardwareFifoDepth =
FixedPcdGet16 (PcdUartDefaultReceiveFifoDepth);
94 if (HardwareFifoDepth == 0) {
96 HardwareFifoDepth = (PL011_UARTPID2_VER (UartPid2) > PL011_VER_R1P4) ? 32 : 16;
102 if ((*ReceiveFifoDepth == 0) || (*ReceiveFifoDepth >= HardwareFifoDepth)) {
104 LineControl = PL011_UARTLCR_H_FEN;
105 *ReceiveFifoDepth = HardwareFifoDepth;
110 *ReceiveFifoDepth = 1;
123 LineControl |= (PL011_UARTLCR_H_PEN | PL011_UARTLCR_H_EPS);
126 LineControl |= PL011_UARTLCR_H_PEN;
129 LineControl |= (PL011_UARTLCR_H_PEN \
130 | PL011_UARTLCR_H_SPS \
131 | PL011_UARTLCR_H_EPS);
134 LineControl |= (PL011_UARTLCR_H_PEN | PL011_UARTLCR_H_SPS);
147 LineControl |= PL011_UARTLCR_H_WLEN_8;
150 LineControl |= PL011_UARTLCR_H_WLEN_7;
153 LineControl |= PL011_UARTLCR_H_WLEN_6;
156 LineControl |= PL011_UARTLCR_H_WLEN_5;
166 case DefaultStopBits:
167 *StopBits = OneStopBit;
172 LineControl |= PL011_UARTLCR_H_STP2;
174 case OneFiveStopBits:
195 if (*BaudRate == 0) {
197 if (*BaudRate == 0) {
202 if (0 == UartClkInHz) {
206 Divisor = (UINT32)((UartClkInHz * 4) / *BaudRate);
207 Integer = Divisor >> FRACTION_PART_SIZE_IN_BITS;
208 Fractional = Divisor & FRACTION_PART_MASK;
215 if (((
MmioRead32 (UartBase + UARTCR) & PL011_UARTCR_UARTEN) != 0) &&
216 (
MmioRead32 (UartBase + UARTLCR_H) == LineControl) &&
217 (
MmioRead32 (UartBase + UARTIBRD) == Integer) &&
218 (
MmioRead32 (UartBase + UARTFBRD) == Fractional))
225 while ((
MmioRead32 (UartBase + UARTFR) & PL011_UARTFR_TXFE) == 0) {
245 PL011_UARTCR_RXE | PL011_UARTCR_TXE | PL011_UARTCR_UARTEN
287 if ((Control & ~mAllowedControlBits) != 0) {
291 if ((Control & mPlatformInvalidControlBits) != 0) {
297 if ((Control & EFI_SERIAL_REQUEST_TO_SEND) != 0) {
298 Bits |= PL011_UARTCR_RTS;
300 Bits &= ~PL011_UARTCR_RTS;
303 if ((Control & EFI_SERIAL_DATA_TERMINAL_READY) != 0) {
304 Bits |= PL011_UARTCR_DTR;
306 Bits &= ~PL011_UARTCR_DTR;
309 if ((Control & EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE) != 0) {
310 Bits |= PL011_UARTCR_LBE;
312 Bits &= ~PL011_UARTCR_LBE;
315 if ((Control & EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE) != 0) {
316 Bits |= (PL011_UARTCR_CTSEN | PL011_UARTCR_RTSEN);
318 Bits &= ~(PL011_UARTCR_CTSEN | PL011_UARTCR_RTSEN);
367 UINT32 ControlRegister;
369 FlagRegister =
MmioRead32 (UartBase + UARTFR);
370 ControlRegister =
MmioRead32 (UartBase + UARTCR);
374 if ((FlagRegister & PL011_UARTFR_CTS) == PL011_UARTFR_CTS) {
375 *Control |= EFI_SERIAL_CLEAR_TO_SEND;
378 if ((FlagRegister & PL011_UARTFR_DSR) == PL011_UARTFR_DSR) {
379 *Control |= EFI_SERIAL_DATA_SET_READY;
382 if ((FlagRegister & PL011_UARTFR_RI) == PL011_UARTFR_RI) {
383 *Control |= EFI_SERIAL_RING_INDICATE;
386 if ((FlagRegister & PL011_UARTFR_DCD) == PL011_UARTFR_DCD) {
387 *Control |= EFI_SERIAL_CARRIER_DETECT;
390 if ((ControlRegister & PL011_UARTCR_RTS) == PL011_UARTCR_RTS) {
391 *Control |= EFI_SERIAL_REQUEST_TO_SEND;
394 if ((ControlRegister & PL011_UARTCR_DTR) == PL011_UARTCR_DTR) {
395 *Control |= EFI_SERIAL_DATA_TERMINAL_READY;
398 if ((FlagRegister & PL011_UARTFR_RXFE) == PL011_UARTFR_RXFE) {
399 *Control |= EFI_SERIAL_INPUT_BUFFER_EMPTY;
402 if ((FlagRegister & PL011_UARTFR_TXFE) == PL011_UARTFR_TXFE) {
403 *Control |= EFI_SERIAL_OUTPUT_BUFFER_EMPTY;
406 if ((ControlRegister & (PL011_UARTCR_CTSEN | PL011_UARTCR_RTSEN))
407 == (PL011_UARTCR_CTSEN | PL011_UARTCR_RTSEN))
409 *Control |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;
412 if ((ControlRegister & PL011_UARTCR_LBE) == PL011_UARTCR_LBE) {
413 *Control |= EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE;
437 UINT8 *
CONST Final = &Buffer[NumberOfBytes];
439 while (Buffer < Final) {
441 while ((
MmioRead32 (UartBase + UARTFR) & UART_TX_FULL_FLAG_MASK)) {
447 return NumberOfBytes;
470 for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {
471 while ((
MmioRead32 (UartBase + UARTFR) & UART_RX_EMPTY_FLAG_MASK) != 0) {
477 return NumberOfBytes;
493 return ((
MmioRead32 (UartBase + UARTFR) & UART_RX_EMPTY_FLAG_MASK) == 0);
UINT8 EFIAPI MmioRead8(IN UINTN Address)
UINT8 EFIAPI MmioWrite8(IN UINTN Address, IN UINT8 Value)
UINT32 EFIAPI MmioRead32(IN UINTN Address)
UINT32 EFIAPI MmioWrite32(IN UINTN Address, IN UINT32 Value)
#define RETURN_UNSUPPORTED
#define RETURN_INVALID_PARAMETER
RETURN_STATUS EFIAPI PL011UartInitializePort(IN UINTN UartBase, IN UINT32 UartClkInHz, IN OUT UINT64 *BaudRate, IN OUT UINT32 *ReceiveFifoDepth, IN OUT EFI_PARITY_TYPE *Parity, IN OUT UINT8 *DataBits, IN OUT EFI_STOP_BITS_TYPE *StopBits)
RETURN_STATUS EFIAPI PL011UartSetControl(IN UINTN UartBase, IN UINT32 Control)
UINTN EFIAPI PL011UartWrite(IN UINTN UartBase, IN UINT8 *Buffer, IN UINTN NumberOfBytes)
UINTN EFIAPI PL011UartRead(IN UINTN UartBase, OUT UINT8 *Buffer, IN UINTN NumberOfBytes)
BOOLEAN EFIAPI PL011UartPoll(IN UINTN UartBase)
RETURN_STATUS EFIAPI PL011UartGetControl(IN UINTN UartBase, OUT UINT32 *Control)
#define FixedPcdGet32(TokenName)
#define FixedPcdGet16(TokenName)