1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012 Altera Corporation <www.altera.com>
11 #include <asm/u-boot.h>
12 #include <asm/utils.h>
14 #include <asm/arch/reset_manager.h>
16 #include <asm/arch/system_manager.h>
17 #include <asm/arch/freeze_controller.h>
18 #include <asm/arch/clock_manager.h>
19 #include <asm/arch/misc.h>
20 #include <asm/arch/scan_manager.h>
21 #include <asm/arch/sdram.h>
22 #include <asm/sections.h>
23 #include <debug_uart.h>
26 #include <dm/uclass.h>
28 DECLARE_GLOBAL_DATA_PTR;
30 u32 spl_boot_device(void)
32 const u32 bsel = readl(socfpga_get_sysmgr_addr() +
33 SYSMGR_GEN5_BOOTINFO);
35 switch (SYSMGR_GET_BOOTINFO_BSEL(bsel)) {
36 case 0x1: /* FPGA (HPS2FPGA Bridge) */
37 return BOOT_DEVICE_RAM;
38 case 0x2: /* NAND Flash (1.8V) */
39 case 0x3: /* NAND Flash (3.0V) */
40 return BOOT_DEVICE_NAND;
41 case 0x4: /* SD/MMC External Transceiver (1.8V) */
42 case 0x5: /* SD/MMC Internal Transceiver (3.0V) */
43 return BOOT_DEVICE_MMC1;
44 case 0x6: /* QSPI Flash (1.8V) */
45 case 0x7: /* QSPI Flash (3.0V) */
46 return BOOT_DEVICE_SPI;
48 printf("Invalid boot device (bsel=%08x)!\n", bsel);
53 #ifdef CONFIG_SPL_MMC_SUPPORT
54 u32 spl_mmc_boot_mode(const u32 boot_device)
56 #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
59 return MMCSD_MODE_RAW;
64 void board_init_f(ulong dummy)
66 const struct cm_config *cm_default_cfg = cm_get_default_config();
71 ret = spl_early_init();
75 socfpga_get_managers_addr();
78 * Clear fake OCRAM ECC first as SBE
79 * and DBE might triggered during power on
81 reg = readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_ECCGRP_OCRAM);
82 if (reg & SYSMGR_ECC_OCRAM_SERR)
83 writel(SYSMGR_ECC_OCRAM_SERR | SYSMGR_ECC_OCRAM_EN,
84 socfpga_get_sysmgr_addr() + SYSMGR_GEN5_ECCGRP_OCRAM);
85 if (reg & SYSMGR_ECC_OCRAM_DERR)
86 writel(SYSMGR_ECC_OCRAM_DERR | SYSMGR_ECC_OCRAM_EN,
87 socfpga_get_sysmgr_addr() + SYSMGR_GEN5_ECCGRP_OCRAM);
89 socfpga_sdram_remap_zero();
90 socfpga_pl310_clear();
92 debug("Freezing all I/O banks\n");
93 /* freeze all IO banks */
94 sys_mgr_frzctrl_freeze_req();
96 /* Put everything into reset but L4WD0. */
97 socfpga_per_reset_all();
99 if (!socfpga_is_booting_from_fpga()) {
100 /* Put FPGA bridges into reset too. */
101 socfpga_bridges_reset(1);
104 socfpga_per_reset(SOCFPGA_RESET(OSC1TIMER0), 0);
107 debug("Reconfigure Clock Manager\n");
108 /* reconfigure the PLLs */
109 if (cm_basic_init(cm_default_cfg))
112 /* Enable bootrom to configure IOs. */
113 sysmgr_config_warmrstcfgio(1);
115 /* configure the IOCSR / IO buffer settings */
116 if (scan_mgr_configure_iocsr())
119 sysmgr_config_warmrstcfgio(0);
121 /* configure the pin muxing through system manager */
122 sysmgr_config_warmrstcfgio(1);
123 sysmgr_pinmux_init();
124 sysmgr_config_warmrstcfgio(0);
126 /* Set bridges handoff value */
127 socfpga_bridges_set_handoff_regs(true, true, true);
129 debug("Unfreezing/Thaw all I/O banks\n");
130 /* unfreeze / thaw all IO banks */
131 sys_mgr_frzctrl_thaw_req();
133 #ifdef CONFIG_DEBUG_UART
134 socfpga_per_reset(SOCFPGA_RESET(UART0), 0);
138 ret = uclass_get_device(UCLASS_RESET, 0, &dev);
140 debug("Reset init failed: %d\n", ret);
142 #ifdef CONFIG_SPL_NAND_DENALI
143 clrbits_le32(SOCFPGA_RSTMGR_ADDRESS + RSTMGR_GEN5_PERMODRST, BIT(4));
146 /* enable console uart printing */
147 preloader_console_init();
149 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
151 debug("DRAM init failed: %d\n", ret);