Serial I/O Port library functions with no library constructor/destructor\r
\r
Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
- Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>\r
+ Copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>\r
\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
RETURN_STATUS\r
EFIAPI\r
PL011UartInitializePort (\r
- IN UINTN UartBase,\r
- IN UINT64 BaudRate,\r
- IN UINT32 ReceiveFifoDepth,\r
- IN EFI_PARITY_TYPE Parity,\r
- IN UINT8 DataBits,\r
- IN EFI_STOP_BITS_TYPE StopBits\r
+ IN OUT UINTN UartBase,\r
+ IN OUT UINT64 *BaudRate,\r
+ IN OUT UINT32 *ReceiveFifoDepth,\r
+ IN OUT EFI_PARITY_TYPE *Parity,\r
+ IN OUT UINT8 *DataBits,\r
+ IN OUT EFI_STOP_BITS_TYPE *StopBits\r
)\r
{\r
UINT32 LineControl;\r
UINT32 Divisor;\r
\r
- // The BaudRate must be passed\r
- if (BaudRate == 0) {\r
- return RETURN_INVALID_PARAMETER;\r
- }\r
-\r
LineControl = 0;\r
\r
// The PL011 supports a buffer of either 1 or 32 chars. Therefore we can accept\r
// 1 char buffer as the minimum fifo size. Because everything can be rounded down,\r
// there is no maximum fifo size.\r
- if (ReceiveFifoDepth == 0) {\r
+ if ((*ReceiveFifoDepth == 0) || (*ReceiveFifoDepth >= 32)) {\r
LineControl |= PL011_UARTLCR_H_FEN;\r
- } else if (ReceiveFifoDepth < 32) {\r
+ *ReceiveFifoDepth = 32;\r
+ } else {\r
+ ASSERT (*ReceiveFifoDepth < 32);\r
// Nothing else to do. 1 byte fifo is default.\r
- } else if (ReceiveFifoDepth >= 32) {\r
- LineControl |= PL011_UARTLCR_H_FEN;\r
+ *ReceiveFifoDepth = 1;\r
}\r
\r
//\r
// Parity\r
//\r
- switch (Parity) {\r
+ switch (*Parity) {\r
case DefaultParity:\r
+ *Parity = NoParity;\r
case NoParity:\r
// Nothing to do. Parity is disabled by default.\r
break;\r
//\r
// Data Bits\r
//\r
- switch (DataBits) {\r
+ switch (*DataBits) {\r
case 0:\r
+ *DataBits = 8;\r
case 8:\r
LineControl |= PL011_UARTLCR_H_WLEN_8;\r
break;\r
//\r
// Stop Bits\r
//\r
- switch (StopBits) {\r
+ switch (*StopBits) {\r
case DefaultStopBits:\r
+ *StopBits = OneStopBit;\r
case OneStopBit:\r
// Nothing to do. One stop bit is enabled by default.\r
break;\r
//\r
// Baud Rate\r
//\r
- if (PcdGet32(PL011UartInteger) != 0) {\r
- // Integer and Factional part must be different of 0\r
- ASSERT(PcdGet32(PL011UartFractional) != 0);\r
\r
- MmioWrite32 (UartBase + UARTIBRD, PcdGet32(PL011UartInteger));\r
- MmioWrite32 (UartBase + UARTFBRD, PcdGet32(PL011UartFractional));\r
- } else {\r
- Divisor = (PcdGet32 (PL011UartClkInHz) * 4) / BaudRate;\r
+ // If BaudRate is zero then use default baud rate\r
+ if (BaudRate == 0) {\r
+ if (PcdGet32 (PL011UartInteger) != 0) {\r
+ MmioWrite32 (UartBase + UARTIBRD, PcdGet32 (PL011UartInteger));\r
+ MmioWrite32 (UartBase + UARTFBRD, PcdGet32 (PL011UartFractional));\r
+ } else {\r
+ *BaudRate = PcdGet32 (PcdSerialBaudRate);\r
+ ASSERT (*BaudRate != 0);\r
+ }\r
+ }\r
+\r
+ // If BaudRate != 0 then we must calculate the divisor from the value\r
+ if (*BaudRate != 0) {\r
+ Divisor = (PcdGet32 (PL011UartClkInHz) * 4) / *BaudRate;\r
MmioWrite32 (UartBase + UARTIBRD, Divisor >> 6);\r
MmioWrite32 (UartBase + UARTFBRD, Divisor & 0x3F);\r
}\r