refactor(rpi): split out console registration logic

Detection of the UART in use and GPIO code only apply to RPi 3 and 4.

RPi 5 has a dedicated PL011 debug port.

Change-Id: Iddf8aea01278e2b79b4e7c476740f1add8c419f0
Signed-off-by: Mario Bălănică <mariobalanica02@gmail.com>
This commit is contained in:
Mario Bălănică 2023-12-01 04:59:43 +02:00
parent 97ef53052b
commit b502978278
6 changed files with 66 additions and 23 deletions

View file

@ -7,14 +7,20 @@
#ifndef RPI_SHARED_H
#define RPI_SHARED_H
#include <stddef.h>
#include <stdint.h>
#include <drivers/console.h>
/*******************************************************************************
* Function and variable prototypes
******************************************************************************/
/* Utility functions */
/* Serial console functions */
void rpi3_console_init(void);
int rpi3_register_used_uart(console_t *console);
/* Utility functions */
void rpi3_setup_page_tables(uintptr_t total_base, size_t total_size,
uintptr_t code_start, uintptr_t code_limit,
uintptr_t rodata_start, uintptr_t rodata_limit

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@ -13,9 +13,6 @@
#include <common/debug.h>
#include <bl31/interrupt_mgmt.h>
#include <drivers/console.h>
#include <drivers/rpi3/gpio/rpi3_gpio.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>
@ -106,12 +103,6 @@ static const mmap_region_t plat_rpi3_mmap[] = {
******************************************************************************/
static console_t rpi3_console;
static bool rpi3_use_mini_uart(void)
{
return rpi3_gpio_get_select(14) == RPI3_GPIO_FUNC_ALT5;
}
void rpi3_console_init(void)
{
int console_scope = CONSOLE_FLAG_BOOT;
@ -120,18 +111,7 @@ void rpi3_console_init(void)
if (RPI3_RUNTIME_UART != -1)
console_scope |= CONSOLE_FLAG_RUNTIME;
rpi3_gpio_init();
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);
rc = rpi3_register_used_uart(&rpi3_console);
if (rc == 0) {
/*

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
* Copyright (c) 2024, Mario Bălănică <mariobalanica02@gmail.com>
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <drivers/arm/pl011.h>
#include <drivers/console.h>
#include <drivers/rpi3/gpio/rpi3_gpio.h>
#include <drivers/ti/uart/uart_16550.h>
#include <platform_def.h>
#include <rpi_shared.h>
static bool rpi3_use_mini_uart(void)
{
return rpi3_gpio_get_select(14) == RPI3_GPIO_FUNC_ALT5;
}
int rpi3_register_used_uart(console_t *console)
{
rpi3_gpio_init();
if (rpi3_use_mini_uart())
return console_16550_register(PLAT_RPI_MINI_UART_BASE,
0,
PLAT_RPI_UART_BAUDRATE,
console);
else
return console_pl011_register(PLAT_RPI_PL011_UART_BASE,
PLAT_RPI_PL011_UART_CLOCK,
PLAT_RPI_UART_BAUDRATE,
console);
}

View file

@ -0,0 +1,20 @@
/*
* Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
* Copyright (c) 2024, Mario Bălănică <mariobalanica02@gmail.com>
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <drivers/arm/pl011.h>
#include <drivers/console.h>
#include <platform_def.h>
#include <rpi_shared.h>
int rpi3_register_used_uart(console_t *console)
{
return console_pl011_register(PLAT_RPI_PL011_UART_BASE,
PLAT_RPI_PL011_UART_CLOCK,
PLAT_RPI_UART_BAUDRATE,
console);
}

View file

@ -17,6 +17,7 @@ PLAT_BL_COMMON_SOURCES := drivers/ti/uart/aarch64/16550_console.S \
drivers/rpi3/gpio/rpi3_gpio.c \
plat/rpi/common/aarch64/plat_helpers.S \
plat/rpi/common/rpi3_common.c \
plat/rpi/common/rpi3_console_dual.c \
${XLAT_TABLES_LIB_SRCS}
BL1_SOURCES += drivers/io/io_fip.c \

View file

@ -15,6 +15,7 @@ PLAT_INCLUDES := -Iplat/rpi/common/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 \
plat/rpi/common/rpi3_console_dual.c \
${XLAT_TABLES_LIB_SRCS}
BL31_SOURCES += lib/cpus/aarch64/cortex_a72.S \