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