common: Drop init.h from common header
[oweals/u-boot.git] / arch / arm / mach-socfpga / spl_gen5.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  Copyright (C) 2012 Altera Corporation <www.altera.com>
4  */
5
6 #include <common.h>
7 #include <hang.h>
8 #include <init.h>
9 #include <asm/io.h>
10 #include <asm/u-boot.h>
11 #include <asm/utils.h>
12 #include <image.h>
13 #include <asm/arch/reset_manager.h>
14 #include <spl.h>
15 #include <asm/arch/system_manager.h>
16 #include <asm/arch/freeze_controller.h>
17 #include <asm/arch/clock_manager.h>
18 #include <asm/arch/misc.h>
19 #include <asm/arch/scan_manager.h>
20 #include <asm/arch/sdram.h>
21 #include <asm/sections.h>
22 #include <debug_uart.h>
23 #include <fdtdec.h>
24 #include <watchdog.h>
25 #include <dm/uclass.h>
26
27 DECLARE_GLOBAL_DATA_PTR;
28
29 u32 spl_boot_device(void)
30 {
31         const u32 bsel = readl(socfpga_get_sysmgr_addr() +
32                                SYSMGR_GEN5_BOOTINFO);
33
34         switch (SYSMGR_GET_BOOTINFO_BSEL(bsel)) {
35         case 0x1:       /* FPGA (HPS2FPGA Bridge) */
36                 return BOOT_DEVICE_RAM;
37         case 0x2:       /* NAND Flash (1.8V) */
38         case 0x3:       /* NAND Flash (3.0V) */
39                 return BOOT_DEVICE_NAND;
40         case 0x4:       /* SD/MMC External Transceiver (1.8V) */
41         case 0x5:       /* SD/MMC Internal Transceiver (3.0V) */
42                 return BOOT_DEVICE_MMC1;
43         case 0x6:       /* QSPI Flash (1.8V) */
44         case 0x7:       /* QSPI Flash (3.0V) */
45                 return BOOT_DEVICE_SPI;
46         default:
47                 printf("Invalid boot device (bsel=%08x)!\n", bsel);
48                 hang();
49         }
50 }
51
52 #ifdef CONFIG_SPL_MMC_SUPPORT
53 u32 spl_mmc_boot_mode(const u32 boot_device)
54 {
55 #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
56         return MMCSD_MODE_FS;
57 #else
58         return MMCSD_MODE_RAW;
59 #endif
60 }
61 #endif
62
63 void board_init_f(ulong dummy)
64 {
65         const struct cm_config *cm_default_cfg = cm_get_default_config();
66         unsigned long reg;
67         int ret;
68         struct udevice *dev;
69
70         ret = spl_early_init();
71         if (ret)
72                 hang();
73
74         socfpga_get_managers_addr();
75
76         /*
77          * Clear fake OCRAM ECC first as SBE
78          * and DBE might triggered during power on
79          */
80         reg = readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_ECCGRP_OCRAM);
81         if (reg & SYSMGR_ECC_OCRAM_SERR)
82                 writel(SYSMGR_ECC_OCRAM_SERR | SYSMGR_ECC_OCRAM_EN,
83                        socfpga_get_sysmgr_addr() + SYSMGR_GEN5_ECCGRP_OCRAM);
84         if (reg & SYSMGR_ECC_OCRAM_DERR)
85                 writel(SYSMGR_ECC_OCRAM_DERR  | SYSMGR_ECC_OCRAM_EN,
86                        socfpga_get_sysmgr_addr() + SYSMGR_GEN5_ECCGRP_OCRAM);
87
88         socfpga_sdram_remap_zero();
89         socfpga_pl310_clear();
90
91         debug("Freezing all I/O banks\n");
92         /* freeze all IO banks */
93         sys_mgr_frzctrl_freeze_req();
94
95         /* Put everything into reset but L4WD0. */
96         socfpga_per_reset_all();
97
98         if (!socfpga_is_booting_from_fpga()) {
99                 /* Put FPGA bridges into reset too. */
100                 socfpga_bridges_reset(1);
101         }
102
103         socfpga_per_reset(SOCFPGA_RESET(OSC1TIMER0), 0);
104         timer_init();
105
106         debug("Reconfigure Clock Manager\n");
107         /* reconfigure the PLLs */
108         if (cm_basic_init(cm_default_cfg))
109                 hang();
110
111         /* Enable bootrom to configure IOs. */
112         sysmgr_config_warmrstcfgio(1);
113
114         /* configure the IOCSR / IO buffer settings */
115         if (scan_mgr_configure_iocsr())
116                 hang();
117
118         sysmgr_config_warmrstcfgio(0);
119
120         /* configure the pin muxing through system manager */
121         sysmgr_config_warmrstcfgio(1);
122         sysmgr_pinmux_init();
123         sysmgr_config_warmrstcfgio(0);
124
125         /* Set bridges handoff value */
126         socfpga_bridges_set_handoff_regs(true, true, true);
127
128         debug("Unfreezing/Thaw all I/O banks\n");
129         /* unfreeze / thaw all IO banks */
130         sys_mgr_frzctrl_thaw_req();
131
132 #ifdef CONFIG_DEBUG_UART
133         socfpga_per_reset(SOCFPGA_RESET(UART0), 0);
134         debug_uart_init();
135 #endif
136
137         ret = uclass_get_device(UCLASS_RESET, 0, &dev);
138         if (ret)
139                 debug("Reset init failed: %d\n", ret);
140
141 #ifdef CONFIG_SPL_NAND_DENALI
142         clrbits_le32(SOCFPGA_RSTMGR_ADDRESS + RSTMGR_GEN5_PERMODRST, BIT(4));
143 #endif
144
145         /* enable console uart printing */
146         preloader_console_init();
147
148         ret = uclass_get_device(UCLASS_RAM, 0, &dev);
149         if (ret) {
150                 debug("DRAM init failed: %d\n", ret);
151                 hang();
152         }
153 }