]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
rpi: Allow using PL011 UART for RPi3/RPi4
authorAndre Przywara <andre.przywara@arm.com>
Tue, 10 Mar 2020 12:34:56 +0000 (12:34 +0000)
committerAndre Przywara <andre.przywara@arm.com>
Tue, 17 Mar 2020 13:44:49 +0000 (13:44 +0000)
The Broadcom 283x SoCs feature multiple UARTs: the mostly used
"Mini-UART", which is an 8250 compatible IP, and at least one PL011.
While the 8250 is usually used for serial console purposes, it suffers
from a design flaw, where its clock depends on the VPU clock, which can
change at runtime. This will reliably mess up the baud rate.
To avoid this problem, people might choose to use the PL011 UART for
the serial console, which is pin-mux'ed to the very same GPIO pins.
This can be done by adding "miniuart-bt" to the "dtoverlay=" line in
config.txt.

To prepare for this situation, use the newly gained freedom of sharing
one console_t pointer across different UART drivers, to introduce the
option of choosing the PL011 for the console.

This is for now hard-coded to choose the Mini-UART by default.
A follow-up patch will introduce automatic detection.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Change-Id: I8cf2522151e09ff4ff94a6d396aec6fc4b091a05

plat/rpi/common/rpi3_common.c
plat/rpi/rpi3/include/platform_def.h
plat/rpi/rpi3/include/rpi_hw.h
plat/rpi/rpi3/platform.mk
plat/rpi/rpi4/include/platform_def.h
plat/rpi/rpi4/include/rpi_hw.h
plat/rpi/rpi4/platform.mk

index ba81ddb5ab953c7c49c871a5931e2d1ecce85412..8fc357a7888cfb92cc8bdd782aee3c3821135193 100644 (file)
@@ -14,6 +14,7 @@
 #include <bl31/interrupt_mgmt.h>
 #include <drivers/console.h>
 #include <drivers/ti/uart/uart_16550.h>
+#include <drivers/arm/pl011.h>
 #include <lib/xlat_tables/xlat_tables_v2.h>
 
 #include <rpi_hw.h>
@@ -104,6 +105,11 @@ static const mmap_region_t plat_rpi3_mmap[] = {
  ******************************************************************************/
 static console_t rpi3_console;
 
+static bool rpi3_use_mini_uart(void)
+{
+       return true;
+}
+
 void rpi3_console_init(void)
 {
        int console_scope = CONSOLE_FLAG_BOOT;
@@ -112,10 +118,16 @@ void rpi3_console_init(void)
        if (RPI3_RUNTIME_UART != -1)
                console_scope |= CONSOLE_FLAG_RUNTIME;
 
-       rc = console_16550_register(PLAT_RPI_MINI_UART_BASE,
-                                   0,
-                                   PLAT_RPI_UART_BAUDRATE,
-                                   &rpi3_console);
+       if (rpi3_use_mini_uart())
+               rc = console_16550_register(PLAT_RPI_MINI_UART_BASE,
+                                           0,
+                                           PLAT_RPI_UART_BAUDRATE,
+                                           &rpi3_console);
+       else
+               rc = console_pl011_register(PLAT_RPI_PL011_UART_BASE,
+                                           PLAT_RPI_PL011_UART_CLOCK,
+                                           PLAT_RPI_UART_BAUDRATE,
+                                           &rpi3_console);
 
        if (rc == 0) {
                /*
index 854da8f2ea6a7c116aeccd39df89250bd3880f6f..9cacd991501e78f5c115215f6a37e4ddb81e8128 100644 (file)
  * Serial-related constants.
  */
 #define PLAT_RPI_MINI_UART_BASE                RPI3_MINI_UART_BASE
+#define PLAT_RPI_PL011_UART_BASE       RPI3_PL011_UART_BASE
+#define PLAT_RPI_PL011_UART_CLOCK      RPI3_PL011_UART_CLOCK
 #define PLAT_RPI_UART_BAUDRATE         ULL(115200)
 
 /*
index 60ecf0d7891a7d906dfc3b139d6e1acbdd9cdc20..2aecab3794e021194460ca1d92a60ff60a63ff11 100644 (file)
 #define RPI3_RNG_INT_MASK_DISABLE      U(0x1)
 
 /*
- * Serial port (called 'Mini UART' in the BCM docucmentation).
+ * Serial ports:
+ * 'Mini UART' in the BCM docucmentation is the 8250 compatible UART.
+ * There is also a PL011 UART, multiplexed to the same pins.
  */
 #define RPI3_IO_MINI_UART_OFFSET       ULL(0x00215040)
 #define RPI3_MINI_UART_BASE            (RPI_IO_BASE + RPI3_IO_MINI_UART_OFFSET)
+#define RPI3_IO_PL011_UART_OFFSET      ULL(0x00201000)
+#define RPI3_PL011_UART_BASE           (RPI_IO_BASE + RPI3_IO_PL011_UART_OFFSET)
+#define RPI3_PL011_UART_CLOCK          ULL(48000000)
 
 /*
  * GPIO controller
index a21a7709a3d042a865d881e587e533d4a5a1783a..e454ce37ef6c212e1d1eba8296b3a1c5ca10cd46 100644 (file)
@@ -11,6 +11,7 @@ PLAT_INCLUDES         :=      -Iplat/rpi/common/include               \
                                -Iplat/rpi/rpi3/include
 
 PLAT_BL_COMMON_SOURCES :=      drivers/ti/uart/aarch64/16550_console.S \
+                               drivers/arm/pl011/aarch64/pl011_console.S \
                                plat/rpi/common/rpi3_common.c           \
                                ${XLAT_TABLES_LIB_SRCS}
 
index e5d5aba6c42079909d49bcfd7be7e9e7bad216c9..6f6bbbe7aed3e4c894becd1c6496ff4a51260516 100644 (file)
  * Serial-related constants.
  */
 #define PLAT_RPI_MINI_UART_BASE                RPI4_MINI_UART_BASE
+#define PLAT_RPI_PL011_UART_BASE       RPI4_PL011_UART_BASE
+#define PLAT_RPI_PL011_UART_CLOCK       RPI4_PL011_UART_CLOCK
 #define PLAT_RPI_UART_BAUDRATE          ULL(115200)
 
 /*
index e46b0deb09e2d2d8ea878a3b070d2b67fe13e60b..7185106101c27ce617cfdaffec5ea1255e5be7fe 100644 (file)
 #define RPI3_RNG_INT_MASK_DISABLE      U(0x1)
 
 /*
- * Serial port (called 'Mini UART' in the Broadcom documentation).
+ * Serial ports:
+ * 'Mini UART' in the BCM docucmentation is the 8250 compatible UART.
+ * There is also a PL011 UART, multiplexed to the same pins.
  */
 #define RPI4_IO_MINI_UART_OFFSET       ULL(0x00215040)
 #define RPI4_MINI_UART_BASE            (RPI_IO_BASE + RPI4_IO_MINI_UART_OFFSET)
+#define RPI4_IO_PL011_UART_OFFSET      ULL(0x00201000)
+#define RPI4_PL011_UART_BASE           (RPI_IO_BASE + RPI4_IO_PL011_UART_OFFSET)
+#define RPI4_PL011_UART_CLOCK          ULL(48000000)
 
 /*
  * GPIO controller
index 2038021a01a6e5bd651e649e87f65e8f061fc811..28fcda8b0c9c57afd2f81026e1c40d117fdfb5bf 100644 (file)
@@ -11,6 +11,7 @@ PLAT_INCLUDES         :=      -Iplat/rpi/common/include               \
                                -Iplat/rpi/rpi4/include
 
 PLAT_BL_COMMON_SOURCES :=      drivers/ti/uart/aarch64/16550_console.S \
+                               drivers/arm/pl011/aarch64/pl011_console.S \
                                plat/rpi/common/rpi3_common.c           \
                                ${XLAT_TABLES_LIB_SRCS}