blob: 8c1da62e23e3bd1b946b73b718dd5fccc75b2d67 [file] [log] [blame]
Oliver Swede8fed2fe2019-11-11 11:11:06 +00001/*
2 * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Andre Przywaradb968062020-04-09 10:25:43 +01007#include <stddef.h>
8#include <stdint.h>
9
10#include <common/fdt_wrappers.h>
Oliver Swede8fed2fe2019-11-11 11:11:06 +000011#include <drivers/arm/pl011.h>
Andre Przywaradb968062020-04-09 10:25:43 +010012#include <drivers/console.h>
Oliver Swede8fed2fe2019-11-11 11:11:06 +000013
14#include <platform_def.h>
15
16static console_t console;
17
18void fpga_console_init(void)
19{
Andre Przywaradb968062020-04-09 10:25:43 +010020 const void *fdt = (void *)(uintptr_t)FPGA_PRELOADED_DTB_BASE;
21 uintptr_t base_addr = PLAT_FPGA_CRASH_UART_BASE;
22 int node;
23
24 /*
25 * Try to read the UART base address from the DT, by chasing the
26 * stdout-path property of the chosen node.
27 * If this does not work, use the crash console address as a fallback.
28 */
29 node = fdt_get_stdout_node_offset(fdt);
30 if (node >= 0) {
31 fdt_get_reg_props_by_index(fdt, node, 0, &base_addr, NULL);
32 }
33
34 (void)console_pl011_register(base_addr, 0, 0, &console);
Oliver Swede8fed2fe2019-11-11 11:11:06 +000035
36 console_set_scope(&console, CONSOLE_FLAG_BOOT |
37 CONSOLE_FLAG_RUNTIME);
38}