blob: a9aad5350d25fb6d6d65e89402901f43471bdb76 [file] [log] [blame]
Tien Fong Cheed938c812024-08-14 15:56:25 +08001// 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
22DECLARE_GLOBAL_DATA_PTR;
23
Alif Zakuan Yuslaimi23fcaa92025-02-18 16:35:06 +080024u32 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 Cheed938c812024-08-14 15:56:25 +080038void board_init_f(ulong dummy)
39{
40 int ret;
41 struct udevice *dev;
42
Alif Zakuan Yuslaimi23fcaa92025-02-18 16:35:06 +080043 /* Enable Async */
44 asm volatile("msr daifclr, #4");
45
46#ifdef CONFIG_SPL_BUILD
47 spl_save_restore_data();
48#endif
49
Tien Fong Cheed938c812024-08-14 15:56:25 +080050 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
Alif Zakuan Yuslaimif3ec9202025-03-10 23:38:52 -070065 mbox_init();
66
67 mbox_hps_stage_notify(HPS_EXECUTION_STATE_FSBL);
68
Tien Fong Cheed938c812024-08-14 15:56:25 +080069 ret = uclass_get_device(UCLASS_CLK, 0, &dev);
70 if (ret) {
71 debug("Clock init failed: %d\n", ret);
72 hang();
73 }
74
75 /*
76 * Enable watchdog as early as possible before initializing other
77 * component. Watchdog need to be enabled after clock driver because
78 * it will retrieve the clock frequency from clock driver.
79 */
80 if (CONFIG_IS_ENABLED(WDT))
81 initr_watchdog();
82
83 preloader_console_init();
84 print_reset_info();
85 cm_print_clock_quick_summary();
86
87 ret = uclass_get_device_by_name(UCLASS_NOP, "socfpga-ccu-config", &dev);
88 if (ret) {
89 printf("HPS CCU settings init failed: %d\n", ret);
90 hang();
91 }
92
93 ret = uclass_get_device_by_name(UCLASS_NOP, "socfpga-firewall-config", &dev);
94 if (ret) {
95 printf("HPS firewall settings init failed: %d\n", ret);
96 hang();
97 }
98
99 if (IS_ENABLED(CONFIG_SPL_ALTERA_SDRAM)) {
100 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
101 if (ret) {
102 debug("DRAM init failed: %d\n", ret);
103 hang();
104 }
105 }
106
Tien Fong Cheed938c812024-08-14 15:56:25 +0800107 if (IS_ENABLED(CONFIG_CADENCE_QSPI))
108 mbox_qspi_open();
109
110 /* Enable non secure access to ocram */
111 clrbits_le32(SOCFPGA_OCRAM_FIREWALL_ADDRESS + 0x18, BIT(0));
112}