1 /*
2 * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <stddef.h>
8 #include <stdint.h>
9
10 #include <common/fdt_wrappers.h>
11 #include <drivers/arm/pl011.h>
12 #include <drivers/console.h>
13
14 #include <platform_def.h>
15
16 static console_t console;
17
fpga_console_init(void)18 void fpga_console_init(void)
19 {
20 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);
35
36 console_set_scope(&console, CONSOLE_FLAG_BOOT |
37 CONSOLE_FLAG_RUNTIME);
38 }
39