]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.c
ArmPlatformPkg: Add support to configure PL011 UART clock
[mirror_edk2.git] / ArmPlatformPkg / Drivers / PL011Uart / PL011Uart.c
index db15a8b322fe35aa3a21cd8f5cc123804c6d2fcd..3c283fdf33e1d64509de262638d4ca82af581161 100644 (file)
@@ -35,6 +35,8 @@ STATIC CONST UINT32 mInvalidControlBits = EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE;
   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
@@ -63,6 +65,7 @@ RETURN_STATUS
 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
@@ -72,6 +75,8 @@ PL011UartInitializePort (
 {\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
@@ -168,19 +173,27 @@ PL011UartInitializePort (
 \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