blob: 45aea4ab6cc3b90e9f2fe0170001def4593b0b2c [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>
Simon Glass691d7192020-05-10 11:40:02 -06009#include <init.h>
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080010#include <asm/io.h>
11#include <asm/pl310.h>
12#include <asm/u-boot.h>
13#include <asm/utils.h>
14#include <image.h>
15#include <asm/arch/reset_manager.h>
16#include <spl.h>
17#include <asm/arch/system_manager.h>
18#include <asm/arch/freeze_controller.h>
19#include <asm/arch/clock_manager.h>
20#include <asm/arch/scan_manager.h>
21#include <asm/arch/sdram.h>
22#include <asm/arch/scu.h>
Marek Vasutaf746582018-07-30 13:58:54 +020023#include <asm/arch/misc.h>
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080024#include <asm/arch/nic301.h>
25#include <asm/sections.h>
26#include <fdtdec.h>
27#include <watchdog.h>
28#include <asm/arch/pinmux.h>
Tien Fong Chee1085bb32019-05-07 17:42:30 +080029#include <asm/arch/fpga_manager.h>
30#include <mmc.h>
31#include <memalign.h>
32
33#define FPGA_BUFSIZ 16 * 1024
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080034
35DECLARE_GLOBAL_DATA_PTR;
36
Ley Foon Tan3d884ff2020-03-06 16:55:20 +080037#define BOOTROM_SHARED_MEM_SIZE 0x800 /* 2KB */
38#define BOOTROM_SHARED_MEM_ADDR (CONFIG_SYS_INIT_RAM_ADDR + \
39 SOCFPGA_PHYS_OCRAM_SIZE - \
40 BOOTROM_SHARED_MEM_SIZE)
41#define RST_STATUS_SHARED_ADDR (BOOTROM_SHARED_MEM_ADDR + 0x438)
42static u32 rst_mgr_status __section(.data);
43
44/*
45 * Bootrom will clear the status register in reset manager and stores the
46 * reset status value in shared memory. Bootrom stores shared data at last
47 * 2KB of onchip RAM.
48 * This function save reset status provided by BootROM to rst_mgr_status.
49 * More information about reset status register value can be found in reset
50 * manager register description.
51 * When running in debugger without Bootrom, r0 to r3 are random values.
52 * So, skip save the value when r0 is not BootROM shared data address.
53 *
54 * r0 - Contains the pointer to the shared memory block. The shared
55 * memory block is located in the top 2 KB of on-chip RAM.
56 * r1 - contains the length of the shared memory.
57 * r2 - unused and set to 0x0.
58 * r3 - points to the version block.
59 */
60void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
61 unsigned long r3)
62{
63 if (r0 == BOOTROM_SHARED_MEM_ADDR)
64 rst_mgr_status = readl(RST_STATUS_SHARED_ADDR);
65
66 save_boot_params_ret();
67}
68
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080069u32 spl_boot_device(void)
70{
Ley Foon Tandb5741f2019-11-08 10:38:20 +080071 const u32 bsel = readl(socfpga_get_sysmgr_addr() + SYSMGR_A10_BOOTINFO);
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080072
73 switch (SYSMGR_GET_BOOTINFO_BSEL(bsel)) {
74 case 0x1: /* FPGA (HPS2FPGA Bridge) */
75 return BOOT_DEVICE_RAM;
76 case 0x2: /* NAND Flash (1.8V) */
77 case 0x3: /* NAND Flash (3.0V) */
78 socfpga_per_reset(SOCFPGA_RESET(NAND), 0);
79 return BOOT_DEVICE_NAND;
80 case 0x4: /* SD/MMC External Transceiver (1.8V) */
81 case 0x5: /* SD/MMC Internal Transceiver (3.0V) */
82 socfpga_per_reset(SOCFPGA_RESET(SDMMC), 0);
83 socfpga_per_reset(SOCFPGA_RESET(DMA), 0);
84 return BOOT_DEVICE_MMC1;
85 case 0x6: /* QSPI Flash (1.8V) */
86 case 0x7: /* QSPI Flash (3.0V) */
87 socfpga_per_reset(SOCFPGA_RESET(QSPI), 0);
88 return BOOT_DEVICE_SPI;
89 default:
90 printf("Invalid boot device (bsel=%08x)!\n", bsel);
91 hang();
92 }
93}
94
95#ifdef CONFIG_SPL_MMC_SUPPORT
Harald Seilere9759062020-04-15 11:33:30 +020096u32 spl_mmc_boot_mode(const u32 boot_device)
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080097{
Tien Fong Cheef4b40922019-01-23 14:20:05 +080098#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080099 return MMCSD_MODE_FS;
100#else
101 return MMCSD_MODE_RAW;
102#endif
103}
104#endif
105
106void spl_board_init(void)
107{
Tien Fong Chee1085bb32019-05-07 17:42:30 +0800108 ALLOC_CACHE_ALIGN_BUFFER(char, buf, FPGA_BUFSIZ);
109
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800110 /* enable console uart printing */
111 preloader_console_init();
Marek Vasutaf746582018-07-30 13:58:54 +0200112 WATCHDOG_RESET();
113
Marek Vasut0b8f6372018-08-18 19:11:52 +0200114 arch_early_init_r();
Tien Fong Chee1085bb32019-05-07 17:42:30 +0800115
116 /* If the full FPGA is already loaded, ie.from EPCQ, config fpga pins */
117 if (is_fpgamgr_user_mode()) {
118 int ret = config_pins(gd->fdt_blob, "shared");
119
120 if (ret)
121 return;
122
123 ret = config_pins(gd->fdt_blob, "fpga");
124 if (ret)
125 return;
126 } else if (!is_fpgamgr_early_user_mode()) {
127 /* Program IOSSM(early IO release) or full FPGA */
128 fpgamgr_program(buf, FPGA_BUFSIZ, 0);
129 }
130
131 /* If the IOSSM/full FPGA is already loaded, start DDR */
132 if (is_fpgamgr_early_user_mode() || is_fpgamgr_user_mode())
133 ddr_calibration_sequence();
134
135 if (!is_fpgamgr_user_mode())
136 fpgamgr_program(buf, FPGA_BUFSIZ, 0);
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800137}
138
139void board_init_f(ulong dummy)
140{
Ley Foon Tanbb25aca2019-11-08 10:38:19 +0800141 if (spl_early_init())
142 hang();
143
144 socfpga_get_managers_addr();
145
Marek Vasut7544ad02018-05-08 20:32:01 +0200146 dcache_disable();
147
Marek Vasut0b8f6372018-08-18 19:11:52 +0200148 socfpga_init_security_policies();
149 socfpga_sdram_remap_zero();
Marek Vasut476abb72019-03-09 22:25:57 +0100150 socfpga_pl310_clear();
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800151
Marek Vasut0b8f6372018-08-18 19:11:52 +0200152 /* Assert reset to all except L4WD0 and L4TIMER0 */
153 socfpga_per_reset_all();
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800154 socfpga_watchdog_disable();
155
Marek Vasut0b8f6372018-08-18 19:11:52 +0200156 /* Configure the clock based on handoff */
157 cm_basic_init(gd->fdt_blob);
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800158
159#ifdef CONFIG_HW_WATCHDOG
160 /* release osc1 watchdog timer 0 from reset */
161 socfpga_reset_deassert_osc1wd0();
162
163 /* reconfigure and enable the watchdog */
164 hw_watchdog_init();
165 WATCHDOG_RESET();
166#endif /* CONFIG_HW_WATCHDOG */
Marek Vasut0b8f6372018-08-18 19:11:52 +0200167
168 config_dedicated_pins(gd->fdt_blob);
169 WATCHDOG_RESET();
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800170}