Tom Rini | cb896f5 | 2018-07-13 09:05:05 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 2 | /* |
Tien Fong Chee | b26072a | 2021-11-07 23:08:54 +0800 | [diff] [blame^] | 3 | * Copyright (C) 2012-2021 Altera Corporation <www.altera.com> |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 7 | #include <cpu_func.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 8 | #include <hang.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | #include <asm/pl310.h> |
| 13 | #include <asm/u-boot.h> |
| 14 | #include <asm/utils.h> |
| 15 | #include <image.h> |
| 16 | #include <asm/arch/reset_manager.h> |
| 17 | #include <spl.h> |
| 18 | #include <asm/arch/system_manager.h> |
| 19 | #include <asm/arch/freeze_controller.h> |
| 20 | #include <asm/arch/clock_manager.h> |
| 21 | #include <asm/arch/scan_manager.h> |
| 22 | #include <asm/arch/sdram.h> |
| 23 | #include <asm/arch/scu.h> |
Marek Vasut | 95db8ee | 2018-07-30 13:58:54 +0200 | [diff] [blame] | 24 | #include <asm/arch/misc.h> |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 25 | #include <asm/arch/nic301.h> |
| 26 | #include <asm/sections.h> |
| 27 | #include <fdtdec.h> |
| 28 | #include <watchdog.h> |
| 29 | #include <asm/arch/pinmux.h> |
Tien Fong Chee | fe03d80 | 2019-05-07 17:42:30 +0800 | [diff] [blame] | 30 | #include <asm/arch/fpga_manager.h> |
| 31 | #include <mmc.h> |
| 32 | #include <memalign.h> |
| 33 | |
| 34 | #define FPGA_BUFSIZ 16 * 1024 |
Tien Fong Chee | b26072a | 2021-11-07 23:08:54 +0800 | [diff] [blame^] | 35 | #define FSBL_IMAGE_IS_VALID 0x49535756 |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 36 | |
| 37 | DECLARE_GLOBAL_DATA_PTR; |
| 38 | |
Ley Foon Tan | f7fcc90 | 2020-03-06 16:55:20 +0800 | [diff] [blame] | 39 | #define BOOTROM_SHARED_MEM_SIZE 0x800 /* 2KB */ |
| 40 | #define BOOTROM_SHARED_MEM_ADDR (CONFIG_SYS_INIT_RAM_ADDR + \ |
| 41 | SOCFPGA_PHYS_OCRAM_SIZE - \ |
| 42 | BOOTROM_SHARED_MEM_SIZE) |
| 43 | #define RST_STATUS_SHARED_ADDR (BOOTROM_SHARED_MEM_ADDR + 0x438) |
Marek BehĂșn | 4bebdd3 | 2021-05-20 13:23:52 +0200 | [diff] [blame] | 44 | static u32 rst_mgr_status __section(".data"); |
Ley Foon Tan | f7fcc90 | 2020-03-06 16:55:20 +0800 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * Bootrom will clear the status register in reset manager and stores the |
| 48 | * reset status value in shared memory. Bootrom stores shared data at last |
| 49 | * 2KB of onchip RAM. |
| 50 | * This function save reset status provided by BootROM to rst_mgr_status. |
| 51 | * More information about reset status register value can be found in reset |
| 52 | * manager register description. |
| 53 | * When running in debugger without Bootrom, r0 to r3 are random values. |
| 54 | * So, skip save the value when r0 is not BootROM shared data address. |
| 55 | * |
| 56 | * r0 - Contains the pointer to the shared memory block. The shared |
| 57 | * memory block is located in the top 2 KB of on-chip RAM. |
| 58 | * r1 - contains the length of the shared memory. |
| 59 | * r2 - unused and set to 0x0. |
| 60 | * r3 - points to the version block. |
| 61 | */ |
| 62 | void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2, |
| 63 | unsigned long r3) |
| 64 | { |
| 65 | if (r0 == BOOTROM_SHARED_MEM_ADDR) |
| 66 | rst_mgr_status = readl(RST_STATUS_SHARED_ADDR); |
| 67 | |
| 68 | save_boot_params_ret(); |
| 69 | } |
| 70 | |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 71 | u32 spl_boot_device(void) |
| 72 | { |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 73 | const u32 bsel = readl(socfpga_get_sysmgr_addr() + SYSMGR_A10_BOOTINFO); |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 74 | |
| 75 | switch (SYSMGR_GET_BOOTINFO_BSEL(bsel)) { |
| 76 | case 0x1: /* FPGA (HPS2FPGA Bridge) */ |
| 77 | return BOOT_DEVICE_RAM; |
| 78 | case 0x2: /* NAND Flash (1.8V) */ |
| 79 | case 0x3: /* NAND Flash (3.0V) */ |
| 80 | socfpga_per_reset(SOCFPGA_RESET(NAND), 0); |
| 81 | return BOOT_DEVICE_NAND; |
| 82 | case 0x4: /* SD/MMC External Transceiver (1.8V) */ |
| 83 | case 0x5: /* SD/MMC Internal Transceiver (3.0V) */ |
| 84 | socfpga_per_reset(SOCFPGA_RESET(SDMMC), 0); |
| 85 | socfpga_per_reset(SOCFPGA_RESET(DMA), 0); |
| 86 | return BOOT_DEVICE_MMC1; |
| 87 | case 0x6: /* QSPI Flash (1.8V) */ |
| 88 | case 0x7: /* QSPI Flash (3.0V) */ |
| 89 | socfpga_per_reset(SOCFPGA_RESET(QSPI), 0); |
| 90 | return BOOT_DEVICE_SPI; |
| 91 | default: |
| 92 | printf("Invalid boot device (bsel=%08x)!\n", bsel); |
| 93 | hang(); |
| 94 | } |
| 95 | } |
| 96 | |
Simon Glass | b58bfe0 | 2021-08-08 12:20:09 -0600 | [diff] [blame] | 97 | #ifdef CONFIG_SPL_MMC |
Harald Seiler | 0bf7ab1 | 2020-04-15 11:33:30 +0200 | [diff] [blame] | 98 | u32 spl_mmc_boot_mode(const u32 boot_device) |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 99 | { |
Tien Fong Chee | 6091dd1 | 2019-01-23 14:20:05 +0800 | [diff] [blame] | 100 | #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4) |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 101 | return MMCSD_MODE_FS; |
| 102 | #else |
| 103 | return MMCSD_MODE_RAW; |
| 104 | #endif |
| 105 | } |
| 106 | #endif |
| 107 | |
| 108 | void spl_board_init(void) |
| 109 | { |
Tien Fong Chee | fe03d80 | 2019-05-07 17:42:30 +0800 | [diff] [blame] | 110 | ALLOC_CACHE_ALIGN_BUFFER(char, buf, FPGA_BUFSIZ); |
| 111 | |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 112 | /* enable console uart printing */ |
| 113 | preloader_console_init(); |
Marek Vasut | 95db8ee | 2018-07-30 13:58:54 +0200 | [diff] [blame] | 114 | WATCHDOG_RESET(); |
| 115 | |
Marek Vasut | 8fdb419 | 2018-08-18 19:11:52 +0200 | [diff] [blame] | 116 | arch_early_init_r(); |
Tien Fong Chee | fe03d80 | 2019-05-07 17:42:30 +0800 | [diff] [blame] | 117 | |
| 118 | /* If the full FPGA is already loaded, ie.from EPCQ, config fpga pins */ |
| 119 | if (is_fpgamgr_user_mode()) { |
| 120 | int ret = config_pins(gd->fdt_blob, "shared"); |
| 121 | |
| 122 | if (ret) |
| 123 | return; |
| 124 | |
| 125 | ret = config_pins(gd->fdt_blob, "fpga"); |
| 126 | if (ret) |
| 127 | return; |
| 128 | } else if (!is_fpgamgr_early_user_mode()) { |
| 129 | /* Program IOSSM(early IO release) or full FPGA */ |
| 130 | fpgamgr_program(buf, FPGA_BUFSIZ, 0); |
| 131 | } |
| 132 | |
| 133 | /* If the IOSSM/full FPGA is already loaded, start DDR */ |
| 134 | if (is_fpgamgr_early_user_mode() || is_fpgamgr_user_mode()) |
| 135 | ddr_calibration_sequence(); |
| 136 | |
| 137 | if (!is_fpgamgr_user_mode()) |
| 138 | fpgamgr_program(buf, FPGA_BUFSIZ, 0); |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | void board_init_f(ulong dummy) |
| 142 | { |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 143 | if (spl_early_init()) |
| 144 | hang(); |
| 145 | |
| 146 | socfpga_get_managers_addr(); |
| 147 | |
Marek Vasut | 339da98 | 2018-05-08 20:32:01 +0200 | [diff] [blame] | 148 | dcache_disable(); |
| 149 | |
Marek Vasut | 8fdb419 | 2018-08-18 19:11:52 +0200 | [diff] [blame] | 150 | socfpga_init_security_policies(); |
| 151 | socfpga_sdram_remap_zero(); |
Marek Vasut | a62817a | 2019-03-09 22:25:57 +0100 | [diff] [blame] | 152 | socfpga_pl310_clear(); |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 153 | |
Marek Vasut | 8fdb419 | 2018-08-18 19:11:52 +0200 | [diff] [blame] | 154 | /* Assert reset to all except L4WD0 and L4TIMER0 */ |
| 155 | socfpga_per_reset_all(); |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 156 | socfpga_watchdog_disable(); |
| 157 | |
Marek Vasut | 8fdb419 | 2018-08-18 19:11:52 +0200 | [diff] [blame] | 158 | /* Configure the clock based on handoff */ |
| 159 | cm_basic_init(gd->fdt_blob); |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 160 | |
| 161 | #ifdef CONFIG_HW_WATCHDOG |
| 162 | /* release osc1 watchdog timer 0 from reset */ |
| 163 | socfpga_reset_deassert_osc1wd0(); |
| 164 | |
| 165 | /* reconfigure and enable the watchdog */ |
| 166 | hw_watchdog_init(); |
| 167 | WATCHDOG_RESET(); |
| 168 | #endif /* CONFIG_HW_WATCHDOG */ |
Marek Vasut | 8fdb419 | 2018-08-18 19:11:52 +0200 | [diff] [blame] | 169 | |
| 170 | config_dedicated_pins(gd->fdt_blob); |
| 171 | WATCHDOG_RESET(); |
Ley Foon Tan | 3305ba7 | 2018-05-24 00:17:27 +0800 | [diff] [blame] | 172 | } |
Tien Fong Chee | b26072a | 2021-11-07 23:08:54 +0800 | [diff] [blame^] | 173 | |
| 174 | /* board specific function prior loading SSBL / U-Boot proper */ |
| 175 | void spl_board_prepare_for_boot(void) |
| 176 | { |
| 177 | writel(FSBL_IMAGE_IS_VALID, socfpga_get_sysmgr_addr() + |
| 178 | SYSMGR_A10_ROMCODE_INITSWSTATE); |
| 179 | } |