Oliver Swede | 8fed2fe | 2019-11-11 11:11:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Andre Przywara | db96806 | 2020-04-09 10:25:43 +0100 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
| 9 | |
| 10 | #include <common/fdt_wrappers.h> |
Oliver Swede | 8fed2fe | 2019-11-11 11:11:06 +0000 | [diff] [blame] | 11 | #include <drivers/arm/pl011.h> |
Andre Przywara | db96806 | 2020-04-09 10:25:43 +0100 | [diff] [blame] | 12 | #include <drivers/console.h> |
Oliver Swede | 8fed2fe | 2019-11-11 11:11:06 +0000 | [diff] [blame] | 13 | |
| 14 | #include <platform_def.h> |
| 15 | |
| 16 | static console_t console; |
| 17 | |
| 18 | void fpga_console_init(void) |
| 19 | { |
Andre Przywara | db96806 | 2020-04-09 10:25:43 +0100 | [diff] [blame] | 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); |
Oliver Swede | 8fed2fe | 2019-11-11 11:11:06 +0000 | [diff] [blame] | 35 | |
| 36 | console_set_scope(&console, CONSOLE_FLAG_BOOT | |
| 37 | CONSOLE_FLAG_RUNTIME); |
| 38 | } |