Tien Fong Chee | d938c81 | 2024-08-14 15:56:25 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2024 Intel Corporation <www.intel.com> |
| 4 | * Copyright (C) 2025 Altera Corporation <www.altera.com> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <init.h> |
| 9 | #include <asm/global_data.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <hang.h> |
| 12 | #include <spl.h> |
| 13 | #include <asm/arch/base_addr_soc64.h> |
| 14 | #include <asm/arch/clock_manager.h> |
| 15 | #include <asm/arch/mailbox_s10.h> |
| 16 | #include <asm/arch/misc.h> |
| 17 | #include <asm/arch/reset_manager.h> |
| 18 | #include <asm/arch/system_manager.h> |
| 19 | #include <wdt.h> |
| 20 | #include <dm/uclass.h> |
| 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Alif Zakuan Yuslaimi | 23fcaa9 | 2025-02-18 16:35:06 +0800 | [diff] [blame] | 24 | u32 reset_flag(void) |
| 25 | { |
| 26 | /* Check rstmgr.stat for warm reset status */ |
| 27 | u32 status = readl(SOCFPGA_RSTMGR_ADDRESS); |
| 28 | |
| 29 | /* Check whether any L4 watchdogs or SDM had triggered warm reset */ |
| 30 | u32 warm_reset_mask = RSTMGR_L4WD_MPU_WARMRESET_MASK; |
| 31 | |
| 32 | if (status & warm_reset_mask) |
| 33 | return 0; |
| 34 | |
| 35 | return 1; |
| 36 | } |
| 37 | |
Tien Fong Chee | d938c81 | 2024-08-14 15:56:25 +0800 | [diff] [blame] | 38 | void board_init_f(ulong dummy) |
| 39 | { |
| 40 | int ret; |
| 41 | struct udevice *dev; |
| 42 | |
Alif Zakuan Yuslaimi | 23fcaa9 | 2025-02-18 16:35:06 +0800 | [diff] [blame] | 43 | /* Enable Async */ |
| 44 | asm volatile("msr daifclr, #4"); |
| 45 | |
| 46 | #ifdef CONFIG_SPL_BUILD |
| 47 | spl_save_restore_data(); |
| 48 | #endif |
| 49 | |
Tien Fong Chee | d938c81 | 2024-08-14 15:56:25 +0800 | [diff] [blame] | 50 | ret = spl_early_init(); |
| 51 | if (ret) |
| 52 | hang(); |
| 53 | |
| 54 | socfpga_get_sys_mgr_addr("sysmgr@10d12000"); |
| 55 | socfpga_get_managers_addr(); |
| 56 | |
| 57 | sysmgr_pinmux_init(); |
| 58 | |
| 59 | /* Ensure watchdog is paused when debugging is happening */ |
| 60 | writel(SYSMGR_WDDBG_PAUSE_ALL_CPU, |
| 61 | socfpga_get_sysmgr_addr() + SYSMGR_SOC64_WDDBG); |
| 62 | |
| 63 | timer_init(); |
| 64 | |
| 65 | ret = uclass_get_device(UCLASS_CLK, 0, &dev); |
| 66 | if (ret) { |
| 67 | debug("Clock init failed: %d\n", ret); |
| 68 | hang(); |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * Enable watchdog as early as possible before initializing other |
| 73 | * component. Watchdog need to be enabled after clock driver because |
| 74 | * it will retrieve the clock frequency from clock driver. |
| 75 | */ |
| 76 | if (CONFIG_IS_ENABLED(WDT)) |
| 77 | initr_watchdog(); |
| 78 | |
| 79 | preloader_console_init(); |
| 80 | print_reset_info(); |
| 81 | cm_print_clock_quick_summary(); |
| 82 | |
| 83 | ret = uclass_get_device_by_name(UCLASS_NOP, "socfpga-ccu-config", &dev); |
| 84 | if (ret) { |
| 85 | printf("HPS CCU settings init failed: %d\n", ret); |
| 86 | hang(); |
| 87 | } |
| 88 | |
| 89 | ret = uclass_get_device_by_name(UCLASS_NOP, "socfpga-firewall-config", &dev); |
| 90 | if (ret) { |
| 91 | printf("HPS firewall settings init failed: %d\n", ret); |
| 92 | hang(); |
| 93 | } |
| 94 | |
| 95 | if (IS_ENABLED(CONFIG_SPL_ALTERA_SDRAM)) { |
| 96 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 97 | if (ret) { |
| 98 | debug("DRAM init failed: %d\n", ret); |
| 99 | hang(); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | mbox_init(); |
| 104 | |
| 105 | if (IS_ENABLED(CONFIG_CADENCE_QSPI)) |
| 106 | mbox_qspi_open(); |
| 107 | |
| 108 | /* Enable non secure access to ocram */ |
| 109 | clrbits_le32(SOCFPGA_OCRAM_FIREWALL_ADDRESS + 0x18, BIT(0)); |
| 110 | } |