]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPlatformPkg: Fix PL011 Glitches.
authorEvan Lloyd <evan.lloyd@arm.com>
Wed, 15 Jun 2016 12:52:43 +0000 (13:52 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 15 Jun 2016 14:17:10 +0000 (16:17 +0200)
This change corrects 3 problems in the PL011 driver.
1. The TRM states "The UARTLCR_H, UARTIBRD, and UARTFBRD registers must
   not be changed:...when the UART is enabled"
2. The TRM (3.3.8) describes logic requiring the UART to be disabled and
   flushed before adjusting UARTCR.
3. Several redundant calls get made to PL011UartInitializePort, where
   the characteristics do not change, but updating the registers can
   cause glitches in the output stream.

The parameters are compared to the current state and no action taken if
no change of state is required.
Where an update is required, the specified logic is followed, and the
register updates only made when the UART is disabled.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Evan Lloyd <evan.lloyd@arm.com>
Tested-by: Ryan Harkin <ryan.harkin@linaro.org>
Reviewed-by: Ryan Harkin <ryan.harkin@linaro.org>
ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.c

index 3c283fdf33e1d64509de262638d4ca82af581161..3748972acbfc80f1077b9b928756a72cc77b5c75 100644 (file)
@@ -32,6 +32,8 @@ STATIC CONST UINT32 mInvalidControlBits = EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE;
 /**\r
 \r
   Initialise the serial port to the specified settings.\r
+  The serial port is re-configured only if the specified settings\r
+  are different from the current settings.\r
   All unspecified settings will be set to the default values.\r
 \r
   @param  UartBase                The base address of the serial device.\r
@@ -191,6 +193,26 @@ PL011UartInitializePort (
     Integer = Divisor >> FRACTION_PART_SIZE_IN_BITS;\r
     Fractional = Divisor & FRACTION_PART_MASK;\r
   }\r
+\r
+  //\r
+  // If PL011 is already initialized, check the current settings\r
+  // and re-initialize only if the settings are different.\r
+  //\r
+  if (((MmioRead32 (UartBase + UARTCR) & PL011_UARTCR_UARTEN) != 0) &&\r
+       (MmioRead32 (UartBase + UARTLCR_H) == LineControl) &&\r
+       (MmioRead32 (UartBase + UARTIBRD) == Integer) &&\r
+       (MmioRead32 (UartBase + UARTFBRD) == Fractional)) {\r
+    // Nothing to do - already initialized with correct attributes\r
+    return RETURN_SUCCESS;\r
+  }\r
+\r
+  // Wait for the end of transmission\r
+  while ((MmioRead32 (UartBase + UARTFR) & PL011_UARTFR_TXFE) == 0);\r
+\r
+  // Disable UART: "The UARTLCR_H, UARTIBRD, and UARTFBRD registers must not be changed\r
+  // when the UART is enabled"\r
+  MmioWrite32 (UartBase + UARTCR, 0);\r
+\r
   // Set Baud Rate Registers\r
   MmioWrite32 (UartBase + UARTIBRD, Integer);\r
   MmioWrite32 (UartBase + UARTFBRD, Fractional);\r