blob: d2f52f2f2cae136563d8b9272894ab6409ac0027 [file] [log] [blame]
Tom Rini914bb7e2018-07-13 09:05:05 -04001// SPDX-License-Identifier: GPL-2.0+
Ley Foon Tanc859f2a2018-05-24 00:17:27 +08002/*
Tien Fong Chee1085bb32019-05-07 17:42:30 +08003 * Copyright (C) 2012-2019 Altera Corporation <www.altera.com>
Ley Foon Tanc859f2a2018-05-24 00:17:27 +08004 */
5
6#include <common.h>
Simon Glass9edefc22019-11-14 12:57:37 -07007#include <cpu_func.h>
Simon Glassdb41d652019-12-28 10:45:07 -07008#include <hang.h>
Ley Foon Tanc859f2a2018-05-24 00:17:27 +08009#include <asm/io.h>
10#include <asm/pl310.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/scan_manager.h>
20#include <asm/arch/sdram.h>
21#include <asm/arch/scu.h>
Marek Vasutaf746582018-07-30 13:58:54 +020022#include <asm/arch/misc.h>
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080023#include <asm/arch/nic301.h>
24#include <asm/sections.h>
25#include <fdtdec.h>
26#include <watchdog.h>
27#include <asm/arch/pinmux.h>
Tien Fong Chee1085bb32019-05-07 17:42:30 +080028#include <asm/arch/fpga_manager.h>
29#include <mmc.h>
30#include <memalign.h>
31
32#define FPGA_BUFSIZ 16 * 1024
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080033
34DECLARE_GLOBAL_DATA_PTR;
35
Ley Foon Tan3d884ff2020-03-06 16:55:20 +080036#define BOOTROM_SHARED_MEM_SIZE 0x800 /* 2KB */
37#define BOOTROM_SHARED_MEM_ADDR (CONFIG_SYS_INIT_RAM_ADDR + \
38 SOCFPGA_PHYS_OCRAM_SIZE - \
39 BOOTROM_SHARED_MEM_SIZE)
40#define RST_STATUS_SHARED_ADDR (BOOTROM_SHARED_MEM_ADDR + 0x438)
41static u32 rst_mgr_status __section(.data);
42
43/*
44 * Bootrom will clear the status register in reset manager and stores the
45 * reset status value in shared memory. Bootrom stores shared data at last
46 * 2KB of onchip RAM.
47 * This function save reset status provided by BootROM to rst_mgr_status.
48 * More information about reset status register value can be found in reset
49 * manager register description.
50 * When running in debugger without Bootrom, r0 to r3 are random values.
51 * So, skip save the value when r0 is not BootROM shared data address.
52 *
53 * r0 - Contains the pointer to the shared memory block. The shared
54 * memory block is located in the top 2 KB of on-chip RAM.
55 * r1 - contains the length of the shared memory.
56 * r2 - unused and set to 0x0.
57 * r3 - points to the version block.
58 */
59void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
60 unsigned long r3)
61{
62 if (r0 == BOOTROM_SHARED_MEM_ADDR)
63 rst_mgr_status = readl(RST_STATUS_SHARED_ADDR);
64
65 save_boot_params_ret();
66}
67
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080068u32 spl_boot_device(void)
69{
Ley Foon Tandb5741f2019-11-08 10:38:20 +080070 const u32 bsel = readl(socfpga_get_sysmgr_addr() + SYSMGR_A10_BOOTINFO);
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080071
72 switch (SYSMGR_GET_BOOTINFO_BSEL(bsel)) {
73 case 0x1: /* FPGA (HPS2FPGA Bridge) */
74 return BOOT_DEVICE_RAM;
75 case 0x2: /* NAND Flash (1.8V) */
76 case 0x3: /* NAND Flash (3.0V) */
77 socfpga_per_reset(SOCFPGA_RESET(NAND), 0);
78 return BOOT_DEVICE_NAND;
79 case 0x4: /* SD/MMC External Transceiver (1.8V) */
80 case 0x5: /* SD/MMC Internal Transceiver (3.0V) */
81 socfpga_per_reset(SOCFPGA_RESET(SDMMC), 0);
82 socfpga_per_reset(SOCFPGA_RESET(DMA), 0);
83 return BOOT_DEVICE_MMC1;
84 case 0x6: /* QSPI Flash (1.8V) */
85 case 0x7: /* QSPI Flash (3.0V) */
86 socfpga_per_reset(SOCFPGA_RESET(QSPI), 0);
87 return BOOT_DEVICE_SPI;
88 default:
89 printf("Invalid boot device (bsel=%08x)!\n", bsel);
90 hang();
91 }
92}
93
94#ifdef CONFIG_SPL_MMC_SUPPORT
Harald Seilere9759062020-04-15 11:33:30 +020095u32 spl_mmc_boot_mode(const u32 boot_device)
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080096{
Tien Fong Cheef4b40922019-01-23 14:20:05 +080097#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080098 return MMCSD_MODE_FS;
99#else
100 return MMCSD_MODE_RAW;
101#endif
102}
103#endif
104
105void spl_board_init(void)
106{
Tien Fong Chee1085bb32019-05-07 17:42:30 +0800107 ALLOC_CACHE_ALIGN_BUFFER(char, buf, FPGA_BUFSIZ);
108
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800109 /* enable console uart printing */
110 preloader_console_init();
Marek Vasutaf746582018-07-30 13:58:54 +0200111 WATCHDOG_RESET();
112
Marek Vasut0b8f6372018-08-18 19:11:52 +0200113 arch_early_init_r();
Tien Fong Chee1085bb32019-05-07 17:42:30 +0800114
115 /* If the full FPGA is already loaded, ie.from EPCQ, config fpga pins */
116 if (is_fpgamgr_user_mode()) {
117 int ret = config_pins(gd->fdt_blob, "shared");
118
119 if (ret)
120 return;
121
122 ret = config_pins(gd->fdt_blob, "fpga");
123 if (ret)
124 return;
125 } else if (!is_fpgamgr_early_user_mode()) {
126 /* Program IOSSM(early IO release) or full FPGA */
127 fpgamgr_program(buf, FPGA_BUFSIZ, 0);
128 }
129
130 /* If the IOSSM/full FPGA is already loaded, start DDR */
131 if (is_fpgamgr_early_user_mode() || is_fpgamgr_user_mode())
132 ddr_calibration_sequence();
133
134 if (!is_fpgamgr_user_mode())
135 fpgamgr_program(buf, FPGA_BUFSIZ, 0);
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800136}
137
138void board_init_f(ulong dummy)
139{
Ley Foon Tanbb25aca2019-11-08 10:38:19 +0800140 if (spl_early_init())
141 hang();
142
143 socfpga_get_managers_addr();
144
Marek Vasut7544ad02018-05-08 20:32:01 +0200145 dcache_disable();
146
Marek Vasut0b8f6372018-08-18 19:11:52 +0200147 socfpga_init_security_policies();
148 socfpga_sdram_remap_zero();
Marek Vasut476abb72019-03-09 22:25:57 +0100149 socfpga_pl310_clear();
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800150
Marek Vasut0b8f6372018-08-18 19:11:52 +0200151 /* Assert reset to all except L4WD0 and L4TIMER0 */
152 socfpga_per_reset_all();
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800153 socfpga_watchdog_disable();
154
Marek Vasut0b8f6372018-08-18 19:11:52 +0200155 /* Configure the clock based on handoff */
156 cm_basic_init(gd->fdt_blob);
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800157
158#ifdef CONFIG_HW_WATCHDOG
159 /* release osc1 watchdog timer 0 from reset */
160 socfpga_reset_deassert_osc1wd0();
161
162 /* reconfigure and enable the watchdog */
163 hw_watchdog_init();
164 WATCHDOG_RESET();
165#endif /* CONFIG_HW_WATCHDOG */
Marek Vasut0b8f6372018-08-18 19:11:52 +0200166
167 config_dedicated_pins(gd->fdt_blob);
168 WATCHDOG_RESET();
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800169}