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