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