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