Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Andrew F. Davis | 9b322db | 2020-01-10 14:35:20 -0500 | [diff] [blame] | 3 | * AM6: SoC specific initialization |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/ |
| 6 | * Lokesh Vutla <lokeshvutla@ti.com> |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Faiz Abbas | 403fc5c | 2020-08-03 11:35:09 +0530 | [diff] [blame] | 10 | #include <fdt_support.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 11 | #include <init.h> |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 12 | #include <asm/io.h> |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 13 | #include <spl.h> |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 14 | #include <asm/arch/hardware.h> |
Andreas Dannenberg | c222e3d | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 15 | #include <asm/arch/sysfw-loader.h> |
Andreas Dannenberg | 03facc7 | 2019-06-04 18:08:26 -0500 | [diff] [blame] | 16 | #include <asm/arch/sys_proto.h> |
Lokesh Vutla | 23f7b1a | 2018-11-02 19:51:03 +0530 | [diff] [blame] | 17 | #include "common.h" |
Lokesh Vutla | 59ebf4a | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 18 | #include <dm.h> |
Andreas Dannenberg | c222e3d | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 19 | #include <dm/uclass-internal.h> |
| 20 | #include <dm/pinctrl.h> |
Andreas Dannenberg | f9380a7 | 2019-06-07 19:24:42 +0530 | [diff] [blame] | 21 | #include <linux/soc/ti/ti_sci_protocol.h> |
Faiz Abbas | f9916b6 | 2020-08-03 11:35:06 +0530 | [diff] [blame] | 22 | #include <log.h> |
Faiz Abbas | d45ffb7 | 2020-02-26 13:44:36 +0530 | [diff] [blame] | 23 | #include <mmc.h> |
Faiz Abbas | f9916b6 | 2020-08-03 11:35:06 +0530 | [diff] [blame] | 24 | #include <stdlib.h> |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 25 | |
Faiz Abbas | 403fc5c | 2020-08-03 11:35:09 +0530 | [diff] [blame] | 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 28 | #ifdef CONFIG_SPL_BUILD |
Andrew F. Davis | ea70da1 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 29 | #ifdef CONFIG_K3_LOAD_SYSFW |
| 30 | #ifdef CONFIG_TI_SECURE_DEVICE |
| 31 | struct fwl_data main_cbass_fwls[] = { |
| 32 | { "MMCSD1_CFG", 2057, 1 }, |
| 33 | { "MMCSD0_CFG", 2058, 1 }, |
| 34 | { "USB3SS0_SLV0", 2176, 2 }, |
| 35 | { "PCIE0_SLV", 2336, 8 }, |
| 36 | { "PCIE1_SLV", 2337, 8 }, |
| 37 | { "PCIE0_CFG", 2688, 1 }, |
| 38 | { "PCIE1_CFG", 2689, 1 }, |
| 39 | }, mcu_cbass_fwls[] = { |
| 40 | { "MCU_ARMSS0_CORE0_SLV", 1024, 1 }, |
| 41 | { "MCU_ARMSS0_CORE1_SLV", 1028, 1 }, |
| 42 | { "MCU_FSS0_S1", 1033, 8 }, |
| 43 | { "MCU_FSS0_S0", 1036, 8 }, |
| 44 | { "MCU_CPSW0", 1220, 1 }, |
| 45 | }; |
| 46 | #endif |
| 47 | #endif |
| 48 | |
Andreas Dannenberg | c68721d | 2018-08-27 15:57:12 +0530 | [diff] [blame] | 49 | static void ctrl_mmr_unlock(void) |
| 50 | { |
| 51 | /* Unlock all WKUP_CTRL_MMR0 module registers */ |
| 52 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 0); |
| 53 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 1); |
| 54 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 2); |
| 55 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 3); |
| 56 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 6); |
| 57 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 7); |
| 58 | |
| 59 | /* Unlock all MCU_CTRL_MMR0 module registers */ |
| 60 | mmr_unlock(MCU_CTRL_MMR0_BASE, 0); |
| 61 | mmr_unlock(MCU_CTRL_MMR0_BASE, 1); |
| 62 | mmr_unlock(MCU_CTRL_MMR0_BASE, 2); |
| 63 | mmr_unlock(MCU_CTRL_MMR0_BASE, 6); |
| 64 | |
| 65 | /* Unlock all CTRL_MMR0 module registers */ |
| 66 | mmr_unlock(CTRL_MMR0_BASE, 0); |
| 67 | mmr_unlock(CTRL_MMR0_BASE, 1); |
| 68 | mmr_unlock(CTRL_MMR0_BASE, 2); |
| 69 | mmr_unlock(CTRL_MMR0_BASE, 3); |
| 70 | mmr_unlock(CTRL_MMR0_BASE, 6); |
| 71 | mmr_unlock(CTRL_MMR0_BASE, 7); |
| 72 | } |
| 73 | |
Andrew F. Davis | 407a219 | 2019-04-12 12:54:42 -0400 | [diff] [blame] | 74 | /* |
| 75 | * This uninitialized global variable would normal end up in the .bss section, |
| 76 | * but the .bss is cleared between writing and reading this variable, so move |
| 77 | * it to the .data section. |
| 78 | */ |
| 79 | u32 bootindex __attribute__((section(".data"))); |
| 80 | |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 81 | static void store_boot_index_from_rom(void) |
| 82 | { |
Andrew F. Davis | 407a219 | 2019-04-12 12:54:42 -0400 | [diff] [blame] | 83 | bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX); |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 84 | } |
| 85 | |
Faiz Abbas | febb47a | 2020-08-03 11:35:08 +0530 | [diff] [blame] | 86 | #if defined(CONFIG_K3_LOAD_SYSFW) && CONFIG_IS_ENABLED(DM_MMC) |
Faiz Abbas | d45ffb7 | 2020-02-26 13:44:36 +0530 | [diff] [blame] | 87 | void k3_mmc_stop_clock(void) |
| 88 | { |
| 89 | if (spl_boot_device() == BOOT_DEVICE_MMC1) { |
| 90 | struct mmc *mmc = find_mmc_device(0); |
| 91 | |
| 92 | if (!mmc) |
| 93 | return; |
| 94 | |
| 95 | mmc->saved_clock = mmc->clock; |
| 96 | mmc_set_clock(mmc, 0, true); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | void k3_mmc_restart_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_set_clock(mmc, mmc->saved_clock, false); |
| 109 | } |
| 110 | } |
Faiz Abbas | febb47a | 2020-08-03 11:35:08 +0530 | [diff] [blame] | 111 | #else |
| 112 | void k3_mmc_stop_clock(void) {} |
| 113 | void k3_mmc_restart_clock(void) {} |
Faiz Abbas | d45ffb7 | 2020-02-26 13:44:36 +0530 | [diff] [blame] | 114 | #endif |
Faiz Abbas | 403fc5c | 2020-08-03 11:35:09 +0530 | [diff] [blame] | 115 | #if CONFIG_IS_ENABLED(DFU) || CONFIG_IS_ENABLED(USB_STORAGE) |
| 116 | #define CTRLMMR_SERDES0_CTRL 0x00104080 |
| 117 | #define PCIE_LANE0 0x1 |
| 118 | static int fixup_usb_boot(void) |
| 119 | { |
| 120 | int ret; |
Faiz Abbas | d45ffb7 | 2020-02-26 13:44:36 +0530 | [diff] [blame] | 121 | |
Faiz Abbas | 403fc5c | 2020-08-03 11:35:09 +0530 | [diff] [blame] | 122 | switch (spl_boot_device()) { |
| 123 | case BOOT_DEVICE_USB: |
| 124 | /* |
| 125 | * If bootmode is Host bootmode, fixup the dr_mode to host |
| 126 | * before the dwc3 bind takes place |
| 127 | */ |
| 128 | ret = fdt_find_and_setprop((void *)gd->fdt_blob, |
| 129 | "/interconnect@100000/dwc3@4000000/usb@10000", |
| 130 | "dr_mode", "host", 11, 0); |
| 131 | if (ret) |
| 132 | printf("%s: fdt_find_and_setprop() failed:%d\n", __func__, |
| 133 | ret); |
| 134 | fallthrough; |
| 135 | case BOOT_DEVICE_DFU: |
| 136 | /* |
| 137 | * The serdes mux between PCIe and USB3 needs to be set to PCIe for |
| 138 | * accessing the interface at USB 2.0 |
| 139 | */ |
| 140 | writel(PCIE_LANE0, CTRLMMR_SERDES0_CTRL); |
| 141 | default: |
| 142 | break; |
| 143 | } |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | int fdtdec_board_setup(const void *fdt_blob) |
| 149 | { |
| 150 | return fixup_usb_boot(); |
| 151 | } |
| 152 | #endif |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 153 | void board_init_f(ulong dummy) |
| 154 | { |
Andreas Dannenberg | c222e3d | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 155 | #if defined(CONFIG_K3_LOAD_SYSFW) || defined(CONFIG_K3_AM654_DDRSS) |
Lokesh Vutla | 59ebf4a | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 156 | struct udevice *dev; |
Faiz Abbas | f9916b6 | 2020-08-03 11:35:06 +0530 | [diff] [blame] | 157 | size_t pool_size; |
| 158 | void *pool_addr; |
Lokesh Vutla | 59ebf4a | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 159 | int ret; |
| 160 | #endif |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 161 | /* |
| 162 | * Cannot delay this further as there is a chance that |
| 163 | * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section. |
| 164 | */ |
| 165 | store_boot_index_from_rom(); |
| 166 | |
Andreas Dannenberg | c68721d | 2018-08-27 15:57:12 +0530 | [diff] [blame] | 167 | /* Make all control module registers accessible */ |
| 168 | ctrl_mmr_unlock(); |
| 169 | |
Lokesh Vutla | 23f7b1a | 2018-11-02 19:51:03 +0530 | [diff] [blame] | 170 | #ifdef CONFIG_CPU_V7R |
Lokesh Vutla | 40109f4 | 2019-12-31 15:49:55 +0530 | [diff] [blame] | 171 | disable_linefill_optimization(); |
Lokesh Vutla | 23f7b1a | 2018-11-02 19:51:03 +0530 | [diff] [blame] | 172 | setup_k3_mpu_regions(); |
| 173 | #endif |
| 174 | |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 175 | /* Init DM early in-order to invoke system controller */ |
| 176 | spl_early_init(); |
| 177 | |
Andreas Dannenberg | 96dd223 | 2018-12-04 22:29:47 -0600 | [diff] [blame] | 178 | #ifdef CONFIG_K3_EARLY_CONS |
| 179 | /* |
| 180 | * Allow establishing an early console as required for example when |
| 181 | * doing a UART-based boot. Note that this console may not "survive" |
| 182 | * through a SYSFW PM-init step and will need a re-init in some way |
| 183 | * due to changing module clock frequencies. |
| 184 | */ |
| 185 | early_console_init(); |
| 186 | #endif |
| 187 | |
Andreas Dannenberg | c222e3d | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 188 | #ifdef CONFIG_K3_LOAD_SYSFW |
| 189 | /* |
Faiz Abbas | f9916b6 | 2020-08-03 11:35:06 +0530 | [diff] [blame] | 190 | * Initialize an early full malloc environment. Do so by allocating a |
| 191 | * new malloc area inside the currently active pre-relocation "first" |
| 192 | * malloc pool of which we use all that's left. |
| 193 | */ |
| 194 | pool_size = CONFIG_VAL(SYS_MALLOC_F_LEN) - gd->malloc_ptr; |
| 195 | pool_addr = malloc(pool_size); |
| 196 | if (!pool_addr) |
| 197 | panic("ERROR: Can't allocate full malloc pool!\n"); |
| 198 | |
| 199 | mem_malloc_init((ulong)pool_addr, (ulong)pool_size); |
| 200 | gd->flags |= GD_FLG_FULL_MALLOC_INIT; |
| 201 | debug("%s: initialized an early full malloc pool at 0x%08lx of 0x%lx bytes\n", |
| 202 | __func__, (unsigned long)pool_addr, (unsigned long)pool_size); |
| 203 | /* |
Andreas Dannenberg | c222e3d | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 204 | * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue |
| 205 | * regardless of the result of pinctrl. Do this without probing the |
| 206 | * device, but instead by searching the device that would request the |
| 207 | * given sequence number if probed. The UART will be used by the system |
| 208 | * firmware (SYSFW) image for various purposes and SYSFW depends on us |
| 209 | * to initialize its pin settings. |
| 210 | */ |
| 211 | ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, &dev); |
| 212 | if (!ret) |
| 213 | pinctrl_select_state(dev, "default"); |
| 214 | |
| 215 | /* |
Lokesh Vutla | 6e44aeb | 2020-03-10 16:50:58 +0530 | [diff] [blame] | 216 | * Load, start up, and configure system controller firmware while |
| 217 | * also populating the SYSFW post-PM configuration callback hook. |
Andreas Dannenberg | c222e3d | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 218 | */ |
Faiz Abbas | d45ffb7 | 2020-02-26 13:44:36 +0530 | [diff] [blame] | 219 | k3_sysfw_loader(k3_mmc_stop_clock, k3_mmc_restart_clock); |
| 220 | |
| 221 | /* Prepare console output */ |
| 222 | preloader_console_init(); |
Andrew F. Davis | ea70da1 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 223 | |
| 224 | /* Disable ROM configured firewalls right after loading sysfw */ |
| 225 | #ifdef CONFIG_TI_SECURE_DEVICE |
| 226 | remove_fwl_configs(main_cbass_fwls, ARRAY_SIZE(main_cbass_fwls)); |
| 227 | remove_fwl_configs(mcu_cbass_fwls, ARRAY_SIZE(mcu_cbass_fwls)); |
| 228 | #endif |
Andreas Dannenberg | c222e3d | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 229 | #else |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 230 | /* Prepare console output */ |
| 231 | preloader_console_init(); |
Andreas Dannenberg | c222e3d | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 232 | #endif |
Lokesh Vutla | 59ebf4a | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 233 | |
Lokesh Vutla | 6e44aeb | 2020-03-10 16:50:58 +0530 | [diff] [blame] | 234 | /* Output System Firmware version info */ |
| 235 | k3_sysfw_print_ver(); |
| 236 | |
Andreas Dannenberg | 03facc7 | 2019-06-04 18:08:26 -0500 | [diff] [blame] | 237 | /* Perform EEPROM-based board detection */ |
| 238 | do_board_detect(); |
| 239 | |
Keerthy | 27380cb | 2019-10-24 15:00:52 +0530 | [diff] [blame] | 240 | #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0) |
| 241 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs), |
| 242 | &dev); |
| 243 | if (ret) |
| 244 | printf("AVS init failed: %d\n", ret); |
| 245 | #endif |
| 246 | |
Lokesh Vutla | 59ebf4a | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 247 | #ifdef CONFIG_K3_AM654_DDRSS |
| 248 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
Andreas Dannenberg | 3e9b9c1 | 2019-03-11 15:15:43 -0500 | [diff] [blame] | 249 | if (ret) |
| 250 | panic("DRAM init failed: %d\n", ret); |
Lokesh Vutla | 59ebf4a | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 251 | #endif |
Jan Kiszka | c02712a | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 252 | spl_enable_dcache(); |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 253 | } |
| 254 | |
Harald Seiler | e975906 | 2020-04-15 11:33:30 +0200 | [diff] [blame] | 255 | u32 spl_mmc_boot_mode(const u32 boot_device) |
Andrew F. Davis | 81089a5 | 2018-10-03 10:03:23 -0500 | [diff] [blame] | 256 | { |
| 257 | #if defined(CONFIG_SUPPORT_EMMC_BOOT) |
| 258 | u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT); |
Andrew F. Davis | 81089a5 | 2018-10-03 10:03:23 -0500 | [diff] [blame] | 259 | |
| 260 | u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >> |
| 261 | CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT; |
| 262 | |
| 263 | /* eMMC boot0 mode is only supported for primary boot */ |
| 264 | if (bootindex == K3_PRIMARY_BOOTMODE && |
| 265 | bootmode == BOOT_DEVICE_MMC1) |
| 266 | return MMCSD_MODE_EMMCBOOT; |
| 267 | #endif |
| 268 | |
| 269 | /* Everything else use filesystem if available */ |
Tien Fong Chee | f4b4092 | 2019-01-23 14:20:05 +0800 | [diff] [blame] | 270 | #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4) |
Andrew F. Davis | 81089a5 | 2018-10-03 10:03:23 -0500 | [diff] [blame] | 271 | return MMCSD_MODE_FS; |
| 272 | #else |
| 273 | return MMCSD_MODE_RAW; |
| 274 | #endif |
| 275 | } |
| 276 | |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 277 | static u32 __get_backup_bootmedia(u32 devstat) |
| 278 | { |
| 279 | u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >> |
| 280 | CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT; |
| 281 | |
| 282 | switch (bkup_boot) { |
| 283 | case BACKUP_BOOT_DEVICE_USB: |
| 284 | return BOOT_DEVICE_USB; |
| 285 | case BACKUP_BOOT_DEVICE_UART: |
| 286 | return BOOT_DEVICE_UART; |
| 287 | case BACKUP_BOOT_DEVICE_ETHERNET: |
| 288 | return BOOT_DEVICE_ETHERNET; |
| 289 | case BACKUP_BOOT_DEVICE_MMC2: |
Andrew F. Davis | b5700ef | 2018-10-03 10:03:22 -0500 | [diff] [blame] | 290 | { |
| 291 | u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >> |
| 292 | CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT; |
| 293 | if (port == 0x0) |
| 294 | return BOOT_DEVICE_MMC1; |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 295 | return BOOT_DEVICE_MMC2; |
Andrew F. Davis | b5700ef | 2018-10-03 10:03:22 -0500 | [diff] [blame] | 296 | } |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 297 | case BACKUP_BOOT_DEVICE_SPI: |
| 298 | return BOOT_DEVICE_SPI; |
| 299 | case BACKUP_BOOT_DEVICE_HYPERFLASH: |
| 300 | return BOOT_DEVICE_HYPERFLASH; |
| 301 | case BACKUP_BOOT_DEVICE_I2C: |
| 302 | return BOOT_DEVICE_I2C; |
| 303 | }; |
| 304 | |
| 305 | return BOOT_DEVICE_RAM; |
| 306 | } |
| 307 | |
| 308 | static u32 __get_primary_bootmedia(u32 devstat) |
| 309 | { |
Andrew F. Davis | b5700ef | 2018-10-03 10:03:22 -0500 | [diff] [blame] | 310 | u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >> |
| 311 | CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT; |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 312 | |
| 313 | if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI) |
| 314 | bootmode = BOOT_DEVICE_SPI; |
| 315 | |
Andrew F. Davis | b5700ef | 2018-10-03 10:03:22 -0500 | [diff] [blame] | 316 | if (bootmode == BOOT_DEVICE_MMC2) { |
| 317 | u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >> |
| 318 | CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT; |
| 319 | if (port == 0x0) |
| 320 | bootmode = BOOT_DEVICE_MMC1; |
| 321 | } else if (bootmode == BOOT_DEVICE_MMC1) { |
| 322 | u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >> |
| 323 | CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT; |
| 324 | if (port == 0x1) |
| 325 | bootmode = BOOT_DEVICE_MMC2; |
Faiz Abbas | 897e83f | 2020-08-03 11:35:10 +0530 | [diff] [blame] | 326 | } else if (bootmode == BOOT_DEVICE_DFU) { |
| 327 | u32 mode = (devstat & CTRLMMR_MAIN_DEVSTAT_USB_MODE_MASK) >> |
| 328 | CTRLMMR_MAIN_DEVSTAT_USB_MODE_SHIFT; |
| 329 | if (mode == 0x2) |
| 330 | bootmode = BOOT_DEVICE_USB; |
Andrew F. Davis | b5700ef | 2018-10-03 10:03:22 -0500 | [diff] [blame] | 331 | } |
| 332 | |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 333 | return bootmode; |
| 334 | } |
| 335 | |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 336 | u32 spl_boot_device(void) |
| 337 | { |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 338 | u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT); |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 339 | |
| 340 | if (bootindex == K3_PRIMARY_BOOTMODE) |
| 341 | return __get_primary_bootmedia(devstat); |
| 342 | else |
| 343 | return __get_backup_bootmedia(devstat); |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 344 | } |
| 345 | #endif |
| 346 | |
Andreas Dannenberg | f9380a7 | 2019-06-07 19:24:42 +0530 | [diff] [blame] | 347 | #ifdef CONFIG_SYS_K3_SPL_ATF |
| 348 | |
| 349 | #define AM6_DEV_MCU_RTI0 134 |
| 350 | #define AM6_DEV_MCU_RTI1 135 |
| 351 | #define AM6_DEV_MCU_ARMSS0_CPU0 159 |
| 352 | #define AM6_DEV_MCU_ARMSS0_CPU1 245 |
| 353 | |
| 354 | void release_resources_for_core_shutdown(void) |
| 355 | { |
Lokesh Vutla | 78e5121 | 2019-09-09 12:47:38 +0530 | [diff] [blame] | 356 | struct ti_sci_handle *ti_sci = get_ti_sci_handle(); |
| 357 | struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops; |
| 358 | struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops; |
Andreas Dannenberg | f9380a7 | 2019-06-07 19:24:42 +0530 | [diff] [blame] | 359 | int ret; |
| 360 | u32 i; |
| 361 | |
| 362 | const u32 put_device_ids[] = { |
| 363 | AM6_DEV_MCU_RTI0, |
| 364 | AM6_DEV_MCU_RTI1, |
| 365 | }; |
| 366 | |
Andreas Dannenberg | f9380a7 | 2019-06-07 19:24:42 +0530 | [diff] [blame] | 367 | /* Iterate through list of devices to put (shutdown) */ |
| 368 | for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) { |
| 369 | u32 id = put_device_ids[i]; |
| 370 | |
| 371 | ret = dev_ops->put_device(ti_sci, id); |
| 372 | if (ret) |
| 373 | panic("Failed to put device %u (%d)\n", id, ret); |
| 374 | } |
| 375 | |
| 376 | const u32 put_core_ids[] = { |
| 377 | AM6_DEV_MCU_ARMSS0_CPU1, |
| 378 | AM6_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */ |
| 379 | }; |
| 380 | |
| 381 | /* Iterate through list of cores to put (shutdown) */ |
| 382 | for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) { |
| 383 | u32 id = put_core_ids[i]; |
| 384 | |
| 385 | /* |
| 386 | * Queue up the core shutdown request. Note that this call |
| 387 | * needs to be followed up by an actual invocation of an WFE |
| 388 | * or WFI CPU instruction. |
| 389 | */ |
| 390 | ret = proc_ops->proc_shutdown_no_wait(ti_sci, id); |
| 391 | if (ret) |
| 392 | panic("Failed sending core %u shutdown message (%d)\n", |
| 393 | id, ret); |
| 394 | } |
| 395 | } |
| 396 | #endif |