Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * J721E: SoC specific initialization |
| 4 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 5 | * Copyright (C) 2018-2019 Texas Instruments Incorporated - https://www.ti.com/ |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 6 | * Lokesh Vutla <lokeshvutla@ti.com> |
| 7 | */ |
| 8 | |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 10 | #include <spl.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/armv7_mpu.h> |
Lokesh Vutla | 6edde29 | 2019-06-13 10:29:43 +0530 | [diff] [blame] | 13 | #include <asm/arch/hardware.h> |
Lokesh Vutla | 96c11f4 | 2019-06-13 10:29:46 +0530 | [diff] [blame] | 14 | #include <linux/soc/ti/ti_sci_protocol.h> |
Andreas Dannenberg | 5e1782c | 2019-06-13 10:29:47 +0530 | [diff] [blame] | 15 | #include <dm.h> |
| 16 | #include <dm/uclass-internal.h> |
| 17 | #include <dm/pinctrl.h> |
Sinthu Raja | a79cbe3 | 2022-02-09 15:06:53 +0530 | [diff] [blame] | 18 | #include <dm/root.h> |
| 19 | #include <fdtdec.h> |
Faiz Abbas | 6839321 | 2020-02-26 13:44:36 +0530 | [diff] [blame] | 20 | #include <mmc.h> |
Keerthy | 7007adc | 2020-02-12 13:55:04 +0530 | [diff] [blame] | 21 | #include <remoteproc.h> |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 22 | |
Andrew Davis | 336b079 | 2024-05-10 15:21:24 -0500 | [diff] [blame] | 23 | #include "../sysfw-loader.h" |
| 24 | #include "../common.h" |
| 25 | |
Jayesh Choudhary | 3aa5058 | 2024-06-14 18:14:37 +0530 | [diff] [blame] | 26 | /* NAVSS North Bridge (NB) registers */ |
| 27 | #define NAVSS0_NBSS_NB0_CFG_MMRS 0x03802000 |
| 28 | #define NAVSS0_NBSS_NB1_CFG_MMRS 0x03803000 |
| 29 | #define NAVSS0_NBSS_NB0_CFG_NB_THREADMAP (NAVSS0_NBSS_NB0_CFG_MMRS + 0x10) |
| 30 | #define NAVSS0_NBSS_NB1_CFG_NB_THREADMAP (NAVSS0_NBSS_NB1_CFG_MMRS + 0x10) |
| 31 | /* |
| 32 | * Thread Map for North Bridge Configuration |
| 33 | * Each bit is for each VBUSM source. |
| 34 | * Bit[0] maps orderID 0-7 to VBUSM.C thread number |
| 35 | * Bit[1] maps orderID 8-15 to VBUSM.C thread number |
| 36 | * When bit has value 0: VBUSM.C thread 0 (non-real time traffic) |
| 37 | * When bit has value 1: VBUSM.C thread 2 (real time traffic) |
| 38 | */ |
| 39 | #define NB_THREADMAP_BIT0 BIT(0) |
| 40 | #define NB_THREADMAP_BIT1 BIT(1) |
| 41 | |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 42 | #ifdef CONFIG_K3_LOAD_SYSFW |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 43 | struct fwl_data cbass_hc_cfg0_fwls[] = { |
Manorit Chawdhry | 43b818d | 2023-04-17 12:04:09 +0530 | [diff] [blame] | 44 | #if defined(CONFIG_TARGET_J721E_R5_EVM) |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 45 | { "PCIE0_CFG", 2560, 8 }, |
| 46 | { "PCIE1_CFG", 2561, 8 }, |
| 47 | { "USB3SS0_CORE", 2568, 4 }, |
| 48 | { "USB3SS1_CORE", 2570, 4 }, |
| 49 | { "EMMC8SS0_CFG", 2576, 4 }, |
| 50 | { "UFS_HCI0_CFG", 2580, 4 }, |
| 51 | { "SERDES0", 2584, 1 }, |
| 52 | { "SERDES1", 2585, 1 }, |
Manorit Chawdhry | 43b818d | 2023-04-17 12:04:09 +0530 | [diff] [blame] | 53 | #elif defined(CONFIG_TARGET_J7200_R5_EVM) |
| 54 | { "PCIE1_CFG", 2561, 7 }, |
| 55 | #endif |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 56 | }, cbass_hc0_fwls[] = { |
Manorit Chawdhry | 43b818d | 2023-04-17 12:04:09 +0530 | [diff] [blame] | 57 | #if defined(CONFIG_TARGET_J721E_R5_EVM) |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 58 | { "PCIE0_HP", 2528, 24 }, |
| 59 | { "PCIE0_LP", 2529, 24 }, |
| 60 | { "PCIE1_HP", 2530, 24 }, |
| 61 | { "PCIE1_LP", 2531, 24 }, |
Manorit Chawdhry | 43b818d | 2023-04-17 12:04:09 +0530 | [diff] [blame] | 62 | #endif |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 63 | }, cbass_rc_cfg0_fwls[] = { |
| 64 | { "EMMCSD4SS0_CFG", 2380, 4 }, |
| 65 | }, cbass_rc0_fwls[] = { |
| 66 | { "GPMC0", 2310, 8 }, |
| 67 | }, infra_cbass0_fwls[] = { |
| 68 | { "PLL_MMR0", 8, 26 }, |
| 69 | { "CTRL_MMR0", 9, 16 }, |
| 70 | }, mcu_cbass0_fwls[] = { |
| 71 | { "MCU_R5FSS0_CORE0", 1024, 4 }, |
| 72 | { "MCU_R5FSS0_CORE0_CFG", 1025, 2 }, |
| 73 | { "MCU_R5FSS0_CORE1", 1028, 4 }, |
| 74 | { "MCU_FSS0_CFG", 1032, 12 }, |
| 75 | { "MCU_FSS0_S1", 1033, 8 }, |
| 76 | { "MCU_FSS0_S0", 1036, 8 }, |
| 77 | { "MCU_PSROM49152X32", 1048, 1 }, |
| 78 | { "MCU_MSRAM128KX64", 1050, 8 }, |
| 79 | { "MCU_CTRL_MMR0", 1200, 8 }, |
| 80 | { "MCU_PLL_MMR0", 1201, 3 }, |
| 81 | { "MCU_CPSW0", 1220, 2 }, |
| 82 | }, wkup_cbass0_fwls[] = { |
| 83 | { "WKUP_CTRL_MMR0", 131, 16 }, |
| 84 | }; |
| 85 | #endif |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 86 | |
Andreas Dannenberg | 660aa46 | 2019-06-13 10:29:44 +0530 | [diff] [blame] | 87 | static void ctrl_mmr_unlock(void) |
| 88 | { |
| 89 | /* Unlock all WKUP_CTRL_MMR0 module registers */ |
| 90 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 0); |
| 91 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 1); |
| 92 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 2); |
| 93 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 3); |
| 94 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 4); |
| 95 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 6); |
| 96 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 7); |
| 97 | |
| 98 | /* Unlock all MCU_CTRL_MMR0 module registers */ |
| 99 | mmr_unlock(MCU_CTRL_MMR0_BASE, 0); |
| 100 | mmr_unlock(MCU_CTRL_MMR0_BASE, 1); |
| 101 | mmr_unlock(MCU_CTRL_MMR0_BASE, 2); |
| 102 | mmr_unlock(MCU_CTRL_MMR0_BASE, 3); |
| 103 | mmr_unlock(MCU_CTRL_MMR0_BASE, 4); |
| 104 | |
| 105 | /* Unlock all CTRL_MMR0 module registers */ |
| 106 | mmr_unlock(CTRL_MMR0_BASE, 0); |
| 107 | mmr_unlock(CTRL_MMR0_BASE, 1); |
| 108 | mmr_unlock(CTRL_MMR0_BASE, 2); |
| 109 | mmr_unlock(CTRL_MMR0_BASE, 3); |
Andreas Dannenberg | 660aa46 | 2019-06-13 10:29:44 +0530 | [diff] [blame] | 110 | mmr_unlock(CTRL_MMR0_BASE, 5); |
Lokesh Vutla | d5bc686 | 2020-08-05 22:44:20 +0530 | [diff] [blame] | 111 | if (soc_is_j721e()) |
| 112 | mmr_unlock(CTRL_MMR0_BASE, 6); |
Andreas Dannenberg | 660aa46 | 2019-06-13 10:29:44 +0530 | [diff] [blame] | 113 | mmr_unlock(CTRL_MMR0_BASE, 7); |
| 114 | } |
| 115 | |
Faiz Abbas | 6839321 | 2020-02-26 13:44:36 +0530 | [diff] [blame] | 116 | #if defined(CONFIG_K3_LOAD_SYSFW) |
| 117 | void k3_mmc_stop_clock(void) |
| 118 | { |
| 119 | if (spl_boot_device() == BOOT_DEVICE_MMC1) { |
| 120 | struct mmc *mmc = find_mmc_device(0); |
| 121 | |
| 122 | if (!mmc) |
| 123 | return; |
| 124 | |
| 125 | mmc->saved_clock = mmc->clock; |
| 126 | mmc_set_clock(mmc, 0, true); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | void k3_mmc_restart_clock(void) |
| 131 | { |
| 132 | if (spl_boot_device() == BOOT_DEVICE_MMC1) { |
| 133 | struct mmc *mmc = find_mmc_device(0); |
| 134 | |
| 135 | if (!mmc) |
| 136 | return; |
| 137 | |
| 138 | mmc_set_clock(mmc, mmc->saved_clock, false); |
| 139 | } |
| 140 | } |
| 141 | #endif |
| 142 | |
Jayesh Choudhary | 3aa5058 | 2024-06-14 18:14:37 +0530 | [diff] [blame] | 143 | /* Setup North Bridge registers to map ORDERID 8-15 to RT traffic */ |
| 144 | static void setup_navss_nb(void) |
| 145 | { |
| 146 | writel(NB_THREADMAP_BIT1, (uintptr_t)NAVSS0_NBSS_NB0_CFG_NB_THREADMAP); |
| 147 | writel(NB_THREADMAP_BIT1, (uintptr_t)NAVSS0_NBSS_NB1_CFG_NB_THREADMAP); |
| 148 | } |
| 149 | |
Andreas Dannenberg | b826741 | 2019-06-13 10:29:45 +0530 | [diff] [blame] | 150 | /* |
| 151 | * This uninitialized global variable would normal end up in the .bss section, |
| 152 | * but the .bss is cleared between writing and reading this variable, so move |
| 153 | * it to the .data section. |
| 154 | */ |
Marek Behún | 4bebdd3 | 2021-05-20 13:23:52 +0200 | [diff] [blame] | 155 | u32 bootindex __section(".data"); |
| 156 | static struct rom_extended_boot_data bootdata __section(".data"); |
Andreas Dannenberg | b826741 | 2019-06-13 10:29:45 +0530 | [diff] [blame] | 157 | |
Lokesh Vutla | 8e7bd01 | 2020-08-05 22:44:22 +0530 | [diff] [blame] | 158 | static void store_boot_info_from_rom(void) |
Andreas Dannenberg | b826741 | 2019-06-13 10:29:45 +0530 | [diff] [blame] | 159 | { |
| 160 | bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX); |
Bryan Brattlof | 270537c | 2022-11-22 13:28:11 -0600 | [diff] [blame] | 161 | memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO, |
Lokesh Vutla | 8e7bd01 | 2020-08-05 22:44:22 +0530 | [diff] [blame] | 162 | sizeof(struct rom_extended_boot_data)); |
Andreas Dannenberg | b826741 | 2019-06-13 10:29:45 +0530 | [diff] [blame] | 163 | } |
| 164 | |
Sinthu Raja | a79cbe3 | 2022-02-09 15:06:53 +0530 | [diff] [blame] | 165 | #ifdef CONFIG_SPL_OF_LIST |
| 166 | void do_dt_magic(void) |
| 167 | { |
| 168 | int ret, rescan, mmc_dev = -1; |
| 169 | static struct mmc *mmc; |
| 170 | |
Andrew Davis | 2dde9a7 | 2023-04-06 11:38:17 -0500 | [diff] [blame] | 171 | /* Perform board detection */ |
| 172 | do_board_detect(); |
Sinthu Raja | a79cbe3 | 2022-02-09 15:06:53 +0530 | [diff] [blame] | 173 | |
| 174 | /* |
| 175 | * Board detection has been done. |
| 176 | * Let us see if another dtb wouldn't be a better match |
| 177 | * for our board |
| 178 | */ |
| 179 | if (IS_ENABLED(CONFIG_CPU_V7R)) { |
| 180 | ret = fdtdec_resetup(&rescan); |
| 181 | if (!ret && rescan) { |
| 182 | dm_uninit(); |
| 183 | dm_init_and_scan(true); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * Because of multi DTB configuration, the MMC device has |
| 189 | * to be re-initialized after reconfiguring FDT inorder to |
| 190 | * boot from MMC. Do this when boot mode is MMC and ROM has |
| 191 | * not loaded SYSFW. |
| 192 | */ |
| 193 | switch (spl_boot_device()) { |
| 194 | case BOOT_DEVICE_MMC1: |
| 195 | mmc_dev = 0; |
| 196 | break; |
| 197 | case BOOT_DEVICE_MMC2: |
| 198 | case BOOT_DEVICE_MMC2_2: |
| 199 | mmc_dev = 1; |
| 200 | break; |
| 201 | } |
| 202 | |
| 203 | if (mmc_dev > 0 && !is_rom_loaded_sysfw(&bootdata)) { |
| 204 | ret = mmc_init_device(mmc_dev); |
| 205 | if (!ret) { |
| 206 | mmc = find_mmc_device(mmc_dev); |
| 207 | if (mmc) { |
| 208 | ret = mmc_init(mmc); |
| 209 | if (ret) { |
| 210 | printf("mmc init failed with error: %d\n", ret); |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | #endif |
| 217 | |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 218 | void board_init_f(ulong dummy) |
| 219 | { |
Lokesh Vutla | edfb5de | 2019-10-07 19:26:38 +0530 | [diff] [blame] | 220 | #if defined(CONFIG_K3_J721E_DDRSS) || defined(CONFIG_K3_LOAD_SYSFW) |
Andreas Dannenberg | 5e1782c | 2019-06-13 10:29:47 +0530 | [diff] [blame] | 221 | struct udevice *dev; |
| 222 | int ret; |
| 223 | #endif |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 224 | /* |
Andreas Dannenberg | b826741 | 2019-06-13 10:29:45 +0530 | [diff] [blame] | 225 | * Cannot delay this further as there is a chance that |
| 226 | * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section. |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 227 | */ |
Lokesh Vutla | 8e7bd01 | 2020-08-05 22:44:22 +0530 | [diff] [blame] | 228 | store_boot_info_from_rom(); |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 229 | |
Andreas Dannenberg | 660aa46 | 2019-06-13 10:29:44 +0530 | [diff] [blame] | 230 | /* Make all control module registers accessible */ |
| 231 | ctrl_mmr_unlock(); |
| 232 | |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 233 | #ifdef CONFIG_CPU_V7R |
Lokesh Vutla | 5fbd6fe | 2019-12-31 15:49:55 +0530 | [diff] [blame] | 234 | disable_linefill_optimization(); |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 235 | setup_k3_mpu_regions(); |
| 236 | #endif |
| 237 | |
| 238 | /* Init DM early */ |
| 239 | spl_early_init(); |
| 240 | |
Andreas Dannenberg | 5e1782c | 2019-06-13 10:29:47 +0530 | [diff] [blame] | 241 | #ifdef CONFIG_K3_LOAD_SYSFW |
| 242 | /* |
| 243 | * Process pinctrl for the serial0 a.k.a. MCU_UART0 module and continue |
| 244 | * regardless of the result of pinctrl. Do this without probing the |
| 245 | * device, but instead by searching the device that would request the |
| 246 | * given sequence number if probed. The UART will be used by the system |
| 247 | * firmware (SYSFW) image for various purposes and SYSFW depends on us |
| 248 | * to initialize its pin settings. |
| 249 | */ |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 250 | ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev); |
Andreas Dannenberg | 5e1782c | 2019-06-13 10:29:47 +0530 | [diff] [blame] | 251 | if (!ret) |
| 252 | pinctrl_select_state(dev, "default"); |
| 253 | |
| 254 | /* |
Neha Malcom Francis | 0e15b1f | 2023-09-27 18:39:52 +0530 | [diff] [blame] | 255 | * Force probe of clk_k3 driver here to ensure basic default clock |
| 256 | * configuration is always done. |
| 257 | */ |
| 258 | if (IS_ENABLED(CONFIG_SPL_CLK_K3)) { |
| 259 | ret = uclass_get_device_by_driver(UCLASS_CLK, |
| 260 | DM_DRIVER_GET(ti_clk), |
| 261 | &dev); |
| 262 | if (ret) |
| 263 | panic("Failed to initialize clk-k3!\n"); |
| 264 | } |
| 265 | |
| 266 | /* |
Andreas Dannenberg | 5e1782c | 2019-06-13 10:29:47 +0530 | [diff] [blame] | 267 | * Load, start up, and configure system controller firmware. Provide |
| 268 | * the U-Boot console init function to the SYSFW post-PM configuration |
| 269 | * callback hook, effectively switching on (or over) the console |
| 270 | * output. |
| 271 | */ |
Lokesh Vutla | 8be6bbf | 2020-08-05 22:44:23 +0530 | [diff] [blame] | 272 | k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata), |
| 273 | k3_mmc_stop_clock, k3_mmc_restart_clock); |
Faiz Abbas | 6839321 | 2020-02-26 13:44:36 +0530 | [diff] [blame] | 274 | |
Sinthu Raja | a79cbe3 | 2022-02-09 15:06:53 +0530 | [diff] [blame] | 275 | #ifdef CONFIG_SPL_OF_LIST |
| 276 | do_dt_magic(); |
| 277 | #endif |
| 278 | |
Faiz Abbas | 6839321 | 2020-02-26 13:44:36 +0530 | [diff] [blame] | 279 | /* Prepare console output */ |
| 280 | preloader_console_init(); |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 281 | |
| 282 | /* Disable ROM configured firewalls right after loading sysfw */ |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 283 | remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls)); |
| 284 | remove_fwl_configs(cbass_hc0_fwls, ARRAY_SIZE(cbass_hc0_fwls)); |
| 285 | remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls)); |
| 286 | remove_fwl_configs(cbass_rc0_fwls, ARRAY_SIZE(cbass_rc0_fwls)); |
| 287 | remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls)); |
| 288 | remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls)); |
| 289 | remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls)); |
Andreas Dannenberg | 5e1782c | 2019-06-13 10:29:47 +0530 | [diff] [blame] | 290 | #else |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 291 | /* Prepare console output */ |
| 292 | preloader_console_init(); |
Andreas Dannenberg | 5e1782c | 2019-06-13 10:29:47 +0530 | [diff] [blame] | 293 | #endif |
Lokesh Vutla | edfb5de | 2019-10-07 19:26:38 +0530 | [diff] [blame] | 294 | |
Lokesh Vutla | 5fafe44 | 2020-03-10 16:50:58 +0530 | [diff] [blame] | 295 | /* Output System Firmware version info */ |
| 296 | k3_sysfw_print_ver(); |
| 297 | |
Andrew Davis | 2dde9a7 | 2023-04-06 11:38:17 -0500 | [diff] [blame] | 298 | /* Perform board detection */ |
| 299 | do_board_detect(); |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 300 | |
Keerthy | 0b01f66 | 2019-10-24 15:00:53 +0530 | [diff] [blame] | 301 | #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0) |
Simon Glass | 65130cd | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 302 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs), |
Keerthy | 0b01f66 | 2019-10-24 15:00:53 +0530 | [diff] [blame] | 303 | &dev); |
| 304 | if (ret) |
| 305 | printf("AVS init failed: %d\n", ret); |
| 306 | #endif |
| 307 | |
Lokesh Vutla | edfb5de | 2019-10-07 19:26:38 +0530 | [diff] [blame] | 308 | #if defined(CONFIG_K3_J721E_DDRSS) |
| 309 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 310 | if (ret) |
| 311 | panic("DRAM init failed: %d\n", ret); |
| 312 | #endif |
Joao Paulo Goncalves | fc3557f | 2023-11-13 16:07:21 -0300 | [diff] [blame] | 313 | spl_enable_cache(); |
Jayesh Choudhary | 3aa5058 | 2024-06-14 18:14:37 +0530 | [diff] [blame] | 314 | |
| 315 | if (IS_ENABLED(CONFIG_CPU_V7R)) |
| 316 | setup_navss_nb(); |
| 317 | |
| 318 | setup_qos(); |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 319 | } |
Lokesh Vutla | 6edde29 | 2019-06-13 10:29:43 +0530 | [diff] [blame] | 320 | |
Andre Przywara | 3cb12ef | 2021-07-12 11:06:49 +0100 | [diff] [blame] | 321 | u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device) |
Lokesh Vutla | 6edde29 | 2019-06-13 10:29:43 +0530 | [diff] [blame] | 322 | { |
| 323 | switch (boot_device) { |
| 324 | case BOOT_DEVICE_MMC1: |
Nishanth Menon | 0f36a4a | 2023-11-04 02:21:47 -0500 | [diff] [blame] | 325 | if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT)) { |
| 326 | if (spl_mmc_emmc_boot_partition(mmc)) |
| 327 | return MMCSD_MODE_EMMCBOOT; |
| 328 | return MMCSD_MODE_FS; |
| 329 | } |
| 330 | if (IS_ENABLED(CONFIG_SPL_FS_FAT) || IS_ENABLED(CONFIG_SPL_FS_EXT4)) |
| 331 | return MMCSD_MODE_FS; |
| 332 | return MMCSD_MODE_EMMCBOOT; |
Lokesh Vutla | 6edde29 | 2019-06-13 10:29:43 +0530 | [diff] [blame] | 333 | case BOOT_DEVICE_MMC2: |
| 334 | return MMCSD_MODE_FS; |
| 335 | default: |
| 336 | return MMCSD_MODE_RAW; |
| 337 | } |
| 338 | } |
| 339 | |
Andreas Dannenberg | ee0f5e6 | 2020-05-16 21:05:01 +0530 | [diff] [blame] | 340 | static u32 __get_backup_bootmedia(u32 main_devstat) |
| 341 | { |
| 342 | u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >> |
| 343 | MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT; |
| 344 | |
| 345 | switch (bkup_boot) { |
| 346 | case BACKUP_BOOT_DEVICE_USB: |
| 347 | return BOOT_DEVICE_DFU; |
| 348 | case BACKUP_BOOT_DEVICE_UART: |
| 349 | return BOOT_DEVICE_UART; |
| 350 | case BACKUP_BOOT_DEVICE_ETHERNET: |
| 351 | return BOOT_DEVICE_ETHERNET; |
| 352 | case BACKUP_BOOT_DEVICE_MMC2: |
| 353 | { |
| 354 | u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >> |
| 355 | MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT; |
| 356 | if (port == 0x0) |
| 357 | return BOOT_DEVICE_MMC1; |
| 358 | return BOOT_DEVICE_MMC2; |
| 359 | } |
| 360 | case BACKUP_BOOT_DEVICE_SPI: |
| 361 | return BOOT_DEVICE_SPI; |
| 362 | case BACKUP_BOOT_DEVICE_I2C: |
| 363 | return BOOT_DEVICE_I2C; |
| 364 | } |
| 365 | |
| 366 | return BOOT_DEVICE_RAM; |
| 367 | } |
| 368 | |
Lokesh Vutla | 6edde29 | 2019-06-13 10:29:43 +0530 | [diff] [blame] | 369 | static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat) |
| 370 | { |
| 371 | |
| 372 | u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >> |
| 373 | WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT; |
| 374 | |
| 375 | bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << |
| 376 | BOOT_MODE_B_SHIFT; |
| 377 | |
Jonathan Humphreys | 9d79768 | 2024-02-23 18:23:06 -0600 | [diff] [blame] | 378 | if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI || |
| 379 | bootmode == BOOT_DEVICE_XSPI) |
Lokesh Vutla | 6edde29 | 2019-06-13 10:29:43 +0530 | [diff] [blame] | 380 | bootmode = BOOT_DEVICE_SPI; |
| 381 | |
| 382 | if (bootmode == BOOT_DEVICE_MMC2) { |
| 383 | u32 port = (main_devstat & |
| 384 | MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >> |
| 385 | MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT; |
| 386 | if (port == 0x0) |
| 387 | bootmode = BOOT_DEVICE_MMC1; |
| 388 | } |
| 389 | |
| 390 | return bootmode; |
| 391 | } |
| 392 | |
Vaishnav Achath | 146b6c1 | 2022-06-03 11:32:16 +0530 | [diff] [blame] | 393 | u32 spl_spi_boot_bus(void) |
| 394 | { |
| 395 | u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT); |
| 396 | u32 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT); |
| 397 | u32 bootmode = ((wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >> |
| 398 | WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT) | |
| 399 | ((main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << BOOT_MODE_B_SHIFT); |
| 400 | |
| 401 | return (bootmode == BOOT_DEVICE_QSPI) ? 1 : 0; |
| 402 | } |
| 403 | |
Lokesh Vutla | 6edde29 | 2019-06-13 10:29:43 +0530 | [diff] [blame] | 404 | u32 spl_boot_device(void) |
| 405 | { |
| 406 | u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT); |
| 407 | u32 main_devstat; |
| 408 | |
| 409 | if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) { |
| 410 | printf("ERROR: MCU only boot is not yet supported\n"); |
| 411 | return BOOT_DEVICE_RAM; |
| 412 | } |
| 413 | |
| 414 | /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */ |
| 415 | main_devstat = readl(CTRLMMR_MAIN_DEVSTAT); |
| 416 | |
Andreas Dannenberg | ee0f5e6 | 2020-05-16 21:05:01 +0530 | [diff] [blame] | 417 | if (bootindex == K3_PRIMARY_BOOTMODE) |
| 418 | return __get_primary_bootmedia(main_devstat, wkup_devstat); |
| 419 | else |
| 420 | return __get_backup_bootmedia(main_devstat); |
Lokesh Vutla | 6edde29 | 2019-06-13 10:29:43 +0530 | [diff] [blame] | 421 | } |