1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012 Altera Corporation <www.altera.com>
9 #include <asm/u-boot.h>
10 #include <asm/utils.h>
12 #include <asm/arch/reset_manager.h>
14 #include <asm/arch/system_manager.h>
15 #include <asm/arch/freeze_controller.h>
16 #include <asm/arch/clock_manager.h>
17 #include <asm/arch/misc.h>
18 #include <asm/arch/scan_manager.h>
19 #include <asm/arch/sdram.h>
20 #include <asm/sections.h>
21 #include <debug_uart.h>
24 #include <dm/uclass.h>
26 DECLARE_GLOBAL_DATA_PTR;
28 u32 spl_boot_device(void)
30 const u32 bsel = readl(socfpga_get_sysmgr_addr() +
31 SYSMGR_GEN5_BOOTINFO);
33 switch (SYSMGR_GET_BOOTINFO_BSEL(bsel)) {
34 case 0x1: /* FPGA (HPS2FPGA Bridge) */
35 return BOOT_DEVICE_RAM;
36 case 0x2: /* NAND Flash (1.8V) */
37 case 0x3: /* NAND Flash (3.0V) */
38 return BOOT_DEVICE_NAND;
39 case 0x4: /* SD/MMC External Transceiver (1.8V) */
40 case 0x5: /* SD/MMC Internal Transceiver (3.0V) */
41 return BOOT_DEVICE_MMC1;
42 case 0x6: /* QSPI Flash (1.8V) */
43 case 0x7: /* QSPI Flash (3.0V) */
44 return BOOT_DEVICE_SPI;
46 printf("Invalid boot device (bsel=%08x)!\n", bsel);
51 #ifdef CONFIG_SPL_MMC_SUPPORT
52 u32 spl_boot_mode(const u32 boot_device)
54 #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
57 return MMCSD_MODE_RAW;
62 void board_init_f(ulong dummy)
64 const struct cm_config *cm_default_cfg = cm_get_default_config();
69 ret = spl_early_init();
73 socfpga_get_managers_addr();
76 * Clear fake OCRAM ECC first as SBE
77 * and DBE might triggered during power on
79 reg = readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_ECCGRP_OCRAM);
80 if (reg & SYSMGR_ECC_OCRAM_SERR)
81 writel(SYSMGR_ECC_OCRAM_SERR | SYSMGR_ECC_OCRAM_EN,
82 socfpga_get_sysmgr_addr() + SYSMGR_GEN5_ECCGRP_OCRAM);
83 if (reg & SYSMGR_ECC_OCRAM_DERR)
84 writel(SYSMGR_ECC_OCRAM_DERR | SYSMGR_ECC_OCRAM_EN,
85 socfpga_get_sysmgr_addr() + SYSMGR_GEN5_ECCGRP_OCRAM);
87 socfpga_sdram_remap_zero();
88 socfpga_pl310_clear();
90 debug("Freezing all I/O banks\n");
91 /* freeze all IO banks */
92 sys_mgr_frzctrl_freeze_req();
94 /* Put everything into reset but L4WD0. */
95 socfpga_per_reset_all();
97 if (!socfpga_is_booting_from_fpga()) {
98 /* Put FPGA bridges into reset too. */
99 socfpga_bridges_reset(1);
102 socfpga_per_reset(SOCFPGA_RESET(OSC1TIMER0), 0);
105 debug("Reconfigure Clock Manager\n");
106 /* reconfigure the PLLs */
107 if (cm_basic_init(cm_default_cfg))
110 /* Enable bootrom to configure IOs. */
111 sysmgr_config_warmrstcfgio(1);
113 /* configure the IOCSR / IO buffer settings */
114 if (scan_mgr_configure_iocsr())
117 sysmgr_config_warmrstcfgio(0);
119 /* configure the pin muxing through system manager */
120 sysmgr_config_warmrstcfgio(1);
121 sysmgr_pinmux_init();
122 sysmgr_config_warmrstcfgio(0);
124 /* Set bridges handoff value */
125 socfpga_bridges_set_handoff_regs(true, true, true);
127 debug("Unfreezing/Thaw all I/O banks\n");
128 /* unfreeze / thaw all IO banks */
129 sys_mgr_frzctrl_thaw_req();
131 #ifdef CONFIG_DEBUG_UART
132 socfpga_per_reset(SOCFPGA_RESET(UART0), 0);
136 ret = uclass_get_device(UCLASS_RESET, 0, &dev);
138 debug("Reset init failed: %d\n", ret);
140 #ifdef CONFIG_SPL_NAND_DENALI
141 struct socfpga_reset_manager *reset_manager_base =
142 (struct socfpga_reset_manager *)SOCFPGA_RSTMGR_ADDRESS;
144 clrbits_le32(&reset_manager_base->per_mod_reset, BIT(4));
147 /* enable console uart printing */
148 preloader_console_init();
150 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
152 debug("DRAM init failed: %d\n", ret);