Lokesh Vutla | c2562d7 | 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> |
| 10 | #include <spl.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/armv7_mpu.h> |
Lokesh Vutla | 0a70492 | 2019-06-13 10:29:43 +0530 | [diff] [blame] | 13 | #include <asm/arch/hardware.h> |
Andreas Dannenberg | 9d1303b | 2019-06-13 10:29:47 +0530 | [diff] [blame] | 14 | #include <asm/arch/sysfw-loader.h> |
Lokesh Vutla | c2562d7 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 15 | #include "common.h" |
Lokesh Vutla | 9c0ff86 | 2019-06-13 10:29:46 +0530 | [diff] [blame] | 16 | #include <asm/arch/sys_proto.h> |
| 17 | #include <linux/soc/ti/ti_sci_protocol.h> |
Andreas Dannenberg | 9d1303b | 2019-06-13 10:29:47 +0530 | [diff] [blame] | 18 | #include <dm.h> |
| 19 | #include <dm/uclass-internal.h> |
| 20 | #include <dm/pinctrl.h> |
Keerthy | 3ab34bc | 2020-02-12 13:55:04 +0530 | [diff] [blame] | 21 | #include <remoteproc.h> |
Lokesh Vutla | c2562d7 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 22 | |
| 23 | #ifdef CONFIG_SPL_BUILD |
Andrew F. Davis | ea70da1 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 24 | #ifdef CONFIG_K3_LOAD_SYSFW |
| 25 | #ifdef CONFIG_TI_SECURE_DEVICE |
| 26 | struct fwl_data cbass_hc_cfg0_fwls[] = { |
| 27 | { "PCIE0_CFG", 2560, 8 }, |
| 28 | { "PCIE1_CFG", 2561, 8 }, |
| 29 | { "USB3SS0_CORE", 2568, 4 }, |
| 30 | { "USB3SS1_CORE", 2570, 4 }, |
| 31 | { "EMMC8SS0_CFG", 2576, 4 }, |
| 32 | { "UFS_HCI0_CFG", 2580, 4 }, |
| 33 | { "SERDES0", 2584, 1 }, |
| 34 | { "SERDES1", 2585, 1 }, |
| 35 | }, cbass_hc0_fwls[] = { |
| 36 | { "PCIE0_HP", 2528, 24 }, |
| 37 | { "PCIE0_LP", 2529, 24 }, |
| 38 | { "PCIE1_HP", 2530, 24 }, |
| 39 | { "PCIE1_LP", 2531, 24 }, |
| 40 | }, cbass_rc_cfg0_fwls[] = { |
| 41 | { "EMMCSD4SS0_CFG", 2380, 4 }, |
| 42 | }, cbass_rc0_fwls[] = { |
| 43 | { "GPMC0", 2310, 8 }, |
| 44 | }, infra_cbass0_fwls[] = { |
| 45 | { "PLL_MMR0", 8, 26 }, |
| 46 | { "CTRL_MMR0", 9, 16 }, |
| 47 | }, mcu_cbass0_fwls[] = { |
| 48 | { "MCU_R5FSS0_CORE0", 1024, 4 }, |
| 49 | { "MCU_R5FSS0_CORE0_CFG", 1025, 2 }, |
| 50 | { "MCU_R5FSS0_CORE1", 1028, 4 }, |
| 51 | { "MCU_FSS0_CFG", 1032, 12 }, |
| 52 | { "MCU_FSS0_S1", 1033, 8 }, |
| 53 | { "MCU_FSS0_S0", 1036, 8 }, |
| 54 | { "MCU_PSROM49152X32", 1048, 1 }, |
| 55 | { "MCU_MSRAM128KX64", 1050, 8 }, |
| 56 | { "MCU_CTRL_MMR0", 1200, 8 }, |
| 57 | { "MCU_PLL_MMR0", 1201, 3 }, |
| 58 | { "MCU_CPSW0", 1220, 2 }, |
| 59 | }, wkup_cbass0_fwls[] = { |
| 60 | { "WKUP_CTRL_MMR0", 131, 16 }, |
| 61 | }; |
| 62 | #endif |
| 63 | #endif |
| 64 | |
Andreas Dannenberg | b73fcbc | 2019-06-13 10:29:44 +0530 | [diff] [blame] | 65 | static void mmr_unlock(u32 base, u32 partition) |
| 66 | { |
| 67 | /* Translate the base address */ |
| 68 | phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE; |
| 69 | |
| 70 | /* Unlock the requested partition if locked using two-step sequence */ |
| 71 | writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0); |
| 72 | writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1); |
| 73 | } |
| 74 | |
| 75 | static void ctrl_mmr_unlock(void) |
| 76 | { |
| 77 | /* Unlock all WKUP_CTRL_MMR0 module registers */ |
| 78 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 0); |
| 79 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 1); |
| 80 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 2); |
| 81 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 3); |
| 82 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 4); |
| 83 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 6); |
| 84 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 7); |
| 85 | |
| 86 | /* Unlock all MCU_CTRL_MMR0 module registers */ |
| 87 | mmr_unlock(MCU_CTRL_MMR0_BASE, 0); |
| 88 | mmr_unlock(MCU_CTRL_MMR0_BASE, 1); |
| 89 | mmr_unlock(MCU_CTRL_MMR0_BASE, 2); |
| 90 | mmr_unlock(MCU_CTRL_MMR0_BASE, 3); |
| 91 | mmr_unlock(MCU_CTRL_MMR0_BASE, 4); |
| 92 | |
| 93 | /* Unlock all CTRL_MMR0 module registers */ |
| 94 | mmr_unlock(CTRL_MMR0_BASE, 0); |
| 95 | mmr_unlock(CTRL_MMR0_BASE, 1); |
| 96 | mmr_unlock(CTRL_MMR0_BASE, 2); |
| 97 | mmr_unlock(CTRL_MMR0_BASE, 3); |
| 98 | mmr_unlock(CTRL_MMR0_BASE, 4); |
| 99 | mmr_unlock(CTRL_MMR0_BASE, 5); |
| 100 | mmr_unlock(CTRL_MMR0_BASE, 6); |
| 101 | mmr_unlock(CTRL_MMR0_BASE, 7); |
| 102 | } |
| 103 | |
Andreas Dannenberg | f94a07c | 2019-06-13 10:29:45 +0530 | [diff] [blame] | 104 | /* |
| 105 | * This uninitialized global variable would normal end up in the .bss section, |
| 106 | * but the .bss is cleared between writing and reading this variable, so move |
| 107 | * it to the .data section. |
| 108 | */ |
| 109 | u32 bootindex __attribute__((section(".data"))); |
| 110 | |
| 111 | static void store_boot_index_from_rom(void) |
| 112 | { |
| 113 | bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX); |
| 114 | } |
| 115 | |
Lokesh Vutla | c2562d7 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 116 | void board_init_f(ulong dummy) |
| 117 | { |
Lokesh Vutla | 22b5480 | 2019-10-07 19:26:38 +0530 | [diff] [blame] | 118 | #if defined(CONFIG_K3_J721E_DDRSS) || defined(CONFIG_K3_LOAD_SYSFW) |
Andreas Dannenberg | 9d1303b | 2019-06-13 10:29:47 +0530 | [diff] [blame] | 119 | struct udevice *dev; |
| 120 | int ret; |
| 121 | #endif |
Lokesh Vutla | c2562d7 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 122 | /* |
Andreas Dannenberg | f94a07c | 2019-06-13 10:29:45 +0530 | [diff] [blame] | 123 | * Cannot delay this further as there is a chance that |
| 124 | * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section. |
Lokesh Vutla | c2562d7 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 125 | */ |
Andreas Dannenberg | f94a07c | 2019-06-13 10:29:45 +0530 | [diff] [blame] | 126 | store_boot_index_from_rom(); |
Lokesh Vutla | c2562d7 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 127 | |
Andreas Dannenberg | b73fcbc | 2019-06-13 10:29:44 +0530 | [diff] [blame] | 128 | /* Make all control module registers accessible */ |
| 129 | ctrl_mmr_unlock(); |
| 130 | |
Lokesh Vutla | c2562d7 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 131 | #ifdef CONFIG_CPU_V7R |
Lokesh Vutla | 40109f4 | 2019-12-31 15:49:55 +0530 | [diff] [blame] | 132 | disable_linefill_optimization(); |
Lokesh Vutla | c2562d7 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 133 | setup_k3_mpu_regions(); |
| 134 | #endif |
| 135 | |
| 136 | /* Init DM early */ |
| 137 | spl_early_init(); |
| 138 | |
Andreas Dannenberg | 9d1303b | 2019-06-13 10:29:47 +0530 | [diff] [blame] | 139 | #ifdef CONFIG_K3_LOAD_SYSFW |
| 140 | /* |
| 141 | * Process pinctrl for the serial0 a.k.a. MCU_UART0 module and continue |
| 142 | * regardless of the result of pinctrl. Do this without probing the |
| 143 | * device, but instead by searching the device that would request the |
| 144 | * given sequence number if probed. The UART will be used by the system |
| 145 | * firmware (SYSFW) image for various purposes and SYSFW depends on us |
| 146 | * to initialize its pin settings. |
| 147 | */ |
| 148 | ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, &dev); |
| 149 | if (!ret) |
| 150 | pinctrl_select_state(dev, "default"); |
| 151 | |
| 152 | /* |
| 153 | * Load, start up, and configure system controller firmware. Provide |
| 154 | * the U-Boot console init function to the SYSFW post-PM configuration |
| 155 | * callback hook, effectively switching on (or over) the console |
| 156 | * output. |
| 157 | */ |
| 158 | k3_sysfw_loader(preloader_console_init); |
Andrew F. Davis | ea70da1 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 159 | |
| 160 | /* Disable ROM configured firewalls right after loading sysfw */ |
| 161 | #ifdef CONFIG_TI_SECURE_DEVICE |
| 162 | remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls)); |
| 163 | remove_fwl_configs(cbass_hc0_fwls, ARRAY_SIZE(cbass_hc0_fwls)); |
| 164 | remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls)); |
| 165 | remove_fwl_configs(cbass_rc0_fwls, ARRAY_SIZE(cbass_rc0_fwls)); |
| 166 | remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls)); |
| 167 | remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls)); |
| 168 | remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls)); |
| 169 | #endif |
Andreas Dannenberg | 9d1303b | 2019-06-13 10:29:47 +0530 | [diff] [blame] | 170 | #else |
Lokesh Vutla | c2562d7 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 171 | /* Prepare console output */ |
| 172 | preloader_console_init(); |
Andreas Dannenberg | 9d1303b | 2019-06-13 10:29:47 +0530 | [diff] [blame] | 173 | #endif |
Lokesh Vutla | 22b5480 | 2019-10-07 19:26:38 +0530 | [diff] [blame] | 174 | |
Andreas Dannenberg | 643eb6e | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 175 | /* Perform EEPROM-based board detection */ |
| 176 | do_board_detect(); |
| 177 | |
Keerthy | 7b13493 | 2019-10-24 15:00:53 +0530 | [diff] [blame] | 178 | #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0) |
| 179 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs), |
| 180 | &dev); |
| 181 | if (ret) |
| 182 | printf("AVS init failed: %d\n", ret); |
| 183 | #endif |
| 184 | |
Lokesh Vutla | 22b5480 | 2019-10-07 19:26:38 +0530 | [diff] [blame] | 185 | #if defined(CONFIG_K3_J721E_DDRSS) |
| 186 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 187 | if (ret) |
| 188 | panic("DRAM init failed: %d\n", ret); |
| 189 | #endif |
Lokesh Vutla | c2562d7 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 190 | } |
Lokesh Vutla | 0a70492 | 2019-06-13 10:29:43 +0530 | [diff] [blame] | 191 | |
| 192 | u32 spl_boot_mode(const u32 boot_device) |
| 193 | { |
| 194 | switch (boot_device) { |
| 195 | case BOOT_DEVICE_MMC1: |
| 196 | return MMCSD_MODE_EMMCBOOT; |
| 197 | case BOOT_DEVICE_MMC2: |
| 198 | return MMCSD_MODE_FS; |
| 199 | default: |
| 200 | return MMCSD_MODE_RAW; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat) |
| 205 | { |
| 206 | |
| 207 | u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >> |
| 208 | WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT; |
| 209 | |
| 210 | bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << |
| 211 | BOOT_MODE_B_SHIFT; |
| 212 | |
| 213 | if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI) |
| 214 | bootmode = BOOT_DEVICE_SPI; |
| 215 | |
| 216 | if (bootmode == BOOT_DEVICE_MMC2) { |
| 217 | u32 port = (main_devstat & |
| 218 | MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >> |
| 219 | MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT; |
| 220 | if (port == 0x0) |
| 221 | bootmode = BOOT_DEVICE_MMC1; |
| 222 | } |
| 223 | |
| 224 | return bootmode; |
| 225 | } |
| 226 | |
| 227 | u32 spl_boot_device(void) |
| 228 | { |
| 229 | u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT); |
| 230 | u32 main_devstat; |
| 231 | |
| 232 | if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) { |
| 233 | printf("ERROR: MCU only boot is not yet supported\n"); |
| 234 | return BOOT_DEVICE_RAM; |
| 235 | } |
| 236 | |
| 237 | /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */ |
| 238 | main_devstat = readl(CTRLMMR_MAIN_DEVSTAT); |
| 239 | |
| 240 | /* ToDo: Add support for backup boot media */ |
| 241 | return __get_primary_bootmedia(main_devstat, wkup_devstat); |
| 242 | } |
Lokesh Vutla | c2562d7 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 243 | #endif |
Lokesh Vutla | 9c0ff86 | 2019-06-13 10:29:46 +0530 | [diff] [blame] | 244 | |
| 245 | #ifdef CONFIG_SYS_K3_SPL_ATF |
| 246 | |
| 247 | #define J721E_DEV_MCU_RTI0 262 |
| 248 | #define J721E_DEV_MCU_RTI1 263 |
| 249 | #define J721E_DEV_MCU_ARMSS0_CPU0 250 |
| 250 | #define J721E_DEV_MCU_ARMSS0_CPU1 251 |
| 251 | |
| 252 | void release_resources_for_core_shutdown(void) |
| 253 | { |
| 254 | struct ti_sci_handle *ti_sci; |
| 255 | struct ti_sci_dev_ops *dev_ops; |
| 256 | struct ti_sci_proc_ops *proc_ops; |
| 257 | int ret; |
| 258 | u32 i; |
| 259 | |
| 260 | const u32 put_device_ids[] = { |
| 261 | J721E_DEV_MCU_RTI0, |
| 262 | J721E_DEV_MCU_RTI1, |
| 263 | }; |
| 264 | |
| 265 | ti_sci = get_ti_sci_handle(); |
| 266 | dev_ops = &ti_sci->ops.dev_ops; |
| 267 | proc_ops = &ti_sci->ops.proc_ops; |
| 268 | |
| 269 | /* Iterate through list of devices to put (shutdown) */ |
| 270 | for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) { |
| 271 | u32 id = put_device_ids[i]; |
| 272 | |
| 273 | ret = dev_ops->put_device(ti_sci, id); |
| 274 | if (ret) |
| 275 | panic("Failed to put device %u (%d)\n", id, ret); |
| 276 | } |
| 277 | |
| 278 | const u32 put_core_ids[] = { |
| 279 | J721E_DEV_MCU_ARMSS0_CPU1, |
| 280 | J721E_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */ |
| 281 | }; |
| 282 | |
| 283 | /* Iterate through list of cores to put (shutdown) */ |
| 284 | for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) { |
| 285 | u32 id = put_core_ids[i]; |
| 286 | |
| 287 | /* |
| 288 | * Queue up the core shutdown request. Note that this call |
| 289 | * needs to be followed up by an actual invocation of an WFE |
| 290 | * or WFI CPU instruction. |
| 291 | */ |
| 292 | ret = proc_ops->proc_shutdown_no_wait(ti_sci, id); |
| 293 | if (ret) |
| 294 | panic("Failed sending core %u shutdown message (%d)\n", |
| 295 | id, ret); |
| 296 | } |
| 297 | } |
| 298 | #endif |
Keerthy | 3ab34bc | 2020-02-12 13:55:04 +0530 | [diff] [blame] | 299 | |
| 300 | #ifdef CONFIG_SYS_K3_SPL_ATF |
| 301 | void start_non_linux_remote_cores(void) |
| 302 | { |
| 303 | int size = 0, ret; |
| 304 | u32 loadaddr = 0; |
| 305 | |
| 306 | size = load_firmware("name_mainr5f0_0fw", "addr_mainr5f0_0load", |
| 307 | &loadaddr); |
| 308 | if (size <= 0) |
| 309 | goto err_load; |
| 310 | |
| 311 | /* assuming remoteproc 2 is aliased for the needed remotecore */ |
| 312 | ret = rproc_load(2, loadaddr, size); |
| 313 | if (ret) { |
| 314 | printf("Firmware failed to start on rproc (%d)\n", ret); |
| 315 | goto err_load; |
| 316 | } |
| 317 | |
| 318 | ret = rproc_start(2); |
| 319 | if (ret) { |
| 320 | printf("Firmware init failed on rproc (%d)\n", ret); |
| 321 | goto err_load; |
| 322 | } |
| 323 | |
| 324 | printf("Remoteproc 2 started successfully\n"); |
| 325 | |
| 326 | return; |
| 327 | |
| 328 | err_load: |
| 329 | rproc_reset(2); |
| 330 | } |
| 331 | #endif |