All unspecified settings will be set to the default values.\r
\r
@param UartBase The base address of the serial device.\r
+ @param UartClkInHz The clock in Hz for the serial device.\r
+ Ignored if the PCD PL011UartInteger is not 0\r
@param BaudRate The baud rate of the serial device. If the\r
baud rate is not supported, the speed will be\r
reduced to the nearest supported one and the\r
EFIAPI\r
PL011UartInitializePort (\r
IN UINTN UartBase,\r
+ IN UINT32 UartClkInHz,\r
IN OUT UINT64 *BaudRate,\r
IN OUT UINT32 *ReceiveFifoDepth,\r
IN OUT EFI_PARITY_TYPE *Parity,\r
{\r
UINT32 LineControl;\r
UINT32 Divisor;\r
+ UINT32 Integer;\r
+ UINT32 Fractional;\r
\r
// The PL011 supports a buffer of 1, 16 or 32 chars. Therefore we can accept\r
// 1 char buffer as the minimum FIFO size. Because everything can be rounded\r
\r
// If PL011 Integer value has been defined then always ignore the BAUD rate\r
if (FixedPcdGet32 (PL011UartInteger) != 0) {\r
- MmioWrite32 (UartBase + UARTIBRD, FixedPcdGet32 (PL011UartInteger));\r
- MmioWrite32 (UartBase + UARTFBRD, FixedPcdGet32 (PL011UartFractional));\r
+ Integer = FixedPcdGet32 (PL011UartInteger);\r
+ Fractional = FixedPcdGet32 (PL011UartFractional);\r
} else {\r
// If BAUD rate is zero then replace it with the system default value\r
if (*BaudRate == 0) {\r
*BaudRate = FixedPcdGet32 (PcdSerialBaudRate);\r
- ASSERT (*BaudRate != 0);\r
+ if (*BaudRate == 0) {\r
+ return RETURN_INVALID_PARAMETER;\r
+ }\r
+ }\r
+ if (0 == UartClkInHz) {\r
+ return RETURN_INVALID_PARAMETER;\r
}\r
\r
- Divisor = (FixedPcdGet32 (PL011UartClkInHz) * 4) / *BaudRate;\r
- MmioWrite32 (UartBase + UARTIBRD, Divisor >> FRACTION_PART_SIZE_IN_BITS);\r
- MmioWrite32 (UartBase + UARTFBRD, Divisor & FRACTION_PART_MASK);\r
+ Divisor = (UartClkInHz * 4) / *BaudRate;\r
+ Integer = Divisor >> FRACTION_PART_SIZE_IN_BITS;\r
+ Fractional = Divisor & FRACTION_PART_MASK;\r
}\r
+ // Set Baud Rate Registers\r
+ MmioWrite32 (UartBase + UARTIBRD, Integer);\r
+ MmioWrite32 (UartBase + UARTFBRD, Fractional);\r
\r
// No parity, 1 stop, no fifo, 8 data bits\r
MmioWrite32 (UartBase + UARTLCR_H, LineControl);\r
[FixedPcd]\r
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate\r
\r
- gArmPlatformTokenSpaceGuid.PL011UartClkInHz\r
gArmPlatformTokenSpaceGuid.PL011UartInteger\r
gArmPlatformTokenSpaceGuid.PL011UartFractional\r
#define PL011_UARTPID2_VER(X) (((X) >> 4) & 0xF)\r
#define PL011_VER_R1P4 0x2\r
\r
-/*\r
+/**\r
\r
Initialise the serial port to the specified settings.\r
All unspecified settings will be set to the default values.\r
\r
- @param UartBase The base address of the serial device.\r
- @param BaudRate The baud rate of the serial device. If the\r
+ @param[in] UartBase The base address of the serial device.\r
+ @param[in] UartClkInHz The clock in Hz for the serial device.\r
+ Ignored if the PCD PL011UartInteger is not 0\r
+ @param[in out] BaudRate The baud rate of the serial device. If the\r
baud rate is not supported, the speed will be\r
reduced to the nearest supported one and the\r
variable's value will be updated accordingly.\r
- @param ReceiveFifoDepth The number of characters the device will\r
+ @param[in out] ReceiveFifoDepth The number of characters the device will\r
buffer on input. Value of 0 will use the\r
device's default FIFO depth.\r
- @param Parity If applicable, this is the EFI_PARITY_TYPE\r
+ @param[in out] Parity If applicable, this is the EFI_PARITY_TYPE\r
that is computed or checked as each character\r
is transmitted or received. If the device\r
does not support parity, the value is the\r
default parity value.\r
- @param DataBits The number of data bits in each character.\r
- @param StopBits If applicable, the EFI_STOP_BITS_TYPE number\r
+ @param[in out] DataBits The number of data bits in each character.\r
+ @param[in out] StopBits If applicable, the EFI_STOP_BITS_TYPE number\r
of stop bits per character.\r
If the device does not support stop bits, the\r
value is the default stop bit value.\r
EFIAPI\r
PL011UartInitializePort (\r
IN UINTN UartBase,\r
+ IN UINT32 UartClkInHz,\r
IN OUT UINT64 *BaudRate,\r
IN OUT UINT32 *ReceiveFifoDepth,\r
IN OUT EFI_PARITY_TYPE *Parity,\r
StopBits = (EFI_STOP_BITS_TYPE) FixedPcdGet8 (PcdUartDefaultStopBits);\r
\r
return PL011UartInitializePort (\r
- (UINTN)FixedPcdGet64 (PcdSerialRegisterBase),\r
- &BaudRate,\r
- &ReceiveFifoDepth,\r
- &Parity,\r
- &DataBits,\r
- &StopBits\r
- );\r
+ (UINTN)FixedPcdGet64 (PcdSerialRegisterBase),\r
+ FixedPcdGet32 (PL011UartClkInHz),\r
+ &BaudRate,\r
+ &ReceiveFifoDepth,\r
+ &Parity,\r
+ &DataBits,\r
+ &StopBits\r
+ );\r
}\r
\r
/**\r
)\r
{\r
return PL011UartInitializePort (\r
- (UINTN)FixedPcdGet64 (PcdSerialRegisterBase),\r
- BaudRate,\r
- ReceiveFifoDepth,\r
- Parity,\r
- DataBits,\r
- StopBits\r
- );\r
+ (UINTN)FixedPcdGet64 (PcdSerialRegisterBase),\r
+ FixedPcdGet32 (PL011UartClkInHz),\r
+ BaudRate,\r
+ ReceiveFifoDepth,\r
+ Parity,\r
+ DataBits,\r
+ StopBits\r
+ );\r
}\r
\r
/**\r
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits\r
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity\r
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits\r
+ gArmPlatformTokenSpaceGuid.PL011UartClkInHz\r