1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved. 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu */ 6*91f16700Schasinglulu 7*91f16700Schasinglulu #include <stddef.h> 8*91f16700Schasinglulu #include <stdint.h> 9*91f16700Schasinglulu 10*91f16700Schasinglulu #include <common/fdt_wrappers.h> 11*91f16700Schasinglulu #include <drivers/arm/pl011.h> 12*91f16700Schasinglulu #include <drivers/console.h> 13*91f16700Schasinglulu 14*91f16700Schasinglulu #include <platform_def.h> 15*91f16700Schasinglulu 16*91f16700Schasinglulu static console_t console; 17*91f16700Schasinglulu 18*91f16700Schasinglulu void fpga_console_init(void) 19*91f16700Schasinglulu { 20*91f16700Schasinglulu const void *fdt = (void *)(uintptr_t)FPGA_PRELOADED_DTB_BASE; 21*91f16700Schasinglulu uintptr_t base_addr = PLAT_FPGA_CRASH_UART_BASE; 22*91f16700Schasinglulu int node; 23*91f16700Schasinglulu 24*91f16700Schasinglulu /* 25*91f16700Schasinglulu * Try to read the UART base address from the DT, by chasing the 26*91f16700Schasinglulu * stdout-path property of the chosen node. 27*91f16700Schasinglulu * If this does not work, use the crash console address as a fallback. 28*91f16700Schasinglulu */ 29*91f16700Schasinglulu node = fdt_get_stdout_node_offset(fdt); 30*91f16700Schasinglulu if (node >= 0) { 31*91f16700Schasinglulu fdt_get_reg_props_by_index(fdt, node, 0, &base_addr, NULL); 32*91f16700Schasinglulu } 33*91f16700Schasinglulu 34*91f16700Schasinglulu (void)console_pl011_register(base_addr, 0, 0, &console); 35*91f16700Schasinglulu 36*91f16700Schasinglulu console_set_scope(&console, CONSOLE_FLAG_BOOT | 37*91f16700Schasinglulu CONSOLE_FLAG_RUNTIME); 38*91f16700Schasinglulu } 39