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