David Huang | 6109820 | 2022-01-25 20:56:31 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * J721E: SoC specific initialization |
| 4 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 5 | * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com/ |
David Huang | 6109820 | 2022-01-25 20:56:31 +0530 | [diff] [blame] | 6 | * David Huang <d-huang@ti.com> |
| 7 | */ |
| 8 | |
David Huang | 6109820 | 2022-01-25 20:56:31 +0530 | [diff] [blame] | 9 | #include <init.h> |
| 10 | #include <spl.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/armv7_mpu.h> |
| 13 | #include <asm/arch/hardware.h> |
Andrew Davis | f179985 | 2023-04-06 11:38:16 -0500 | [diff] [blame] | 14 | #include "sysfw-loader.h" |
David Huang | 6109820 | 2022-01-25 20:56:31 +0530 | [diff] [blame] | 15 | #include "common.h" |
David Huang | 6109820 | 2022-01-25 20:56:31 +0530 | [diff] [blame] | 16 | #include <linux/soc/ti/ti_sci_protocol.h> |
| 17 | #include <dm.h> |
| 18 | #include <dm/uclass-internal.h> |
| 19 | #include <dm/pinctrl.h> |
Andrew Davis | de20b95 | 2023-04-06 11:38:20 -0500 | [diff] [blame] | 20 | #include <dm/root.h> |
David Huang | 6109820 | 2022-01-25 20:56:31 +0530 | [diff] [blame] | 21 | #include <mmc.h> |
| 22 | #include <remoteproc.h> |
| 23 | |
Jayesh Choudhary | 7796c72 | 2023-03-28 18:32:01 +0530 | [diff] [blame] | 24 | struct fwl_data cbass_hc_cfg0_fwls[] = { |
| 25 | { "PCIE0_CFG", 2577, 7 }, |
| 26 | { "EMMC8SS0_CFG", 2579, 4 }, |
| 27 | { "USB3SS0_CORE", 2580, 4 }, |
| 28 | { "USB3SS1_CORE", 2581, 1 }, |
| 29 | }, cbass_hc2_fwls[] = { |
| 30 | { "PCIE0", 2547, 24 }, |
| 31 | { "HC2_WIZ16B8M4CT2", 2552, 1 }, |
| 32 | }, cbass_rc_cfg0_fwls[] = { |
| 33 | { "EMMCSD4SS0_CFG", 2400, 4 }, |
| 34 | }, infra_cbass0_fwls[] = { |
| 35 | { "PSC0", 5, 1 }, |
| 36 | { "PLL_CTRL0", 6, 1 }, |
| 37 | { "PLL_MMR0", 8, 26 }, |
| 38 | { "CTRL_MMR0", 9, 16 }, |
| 39 | { "GPIO0", 16, 1 }, |
| 40 | }, mcu_cbass0_fwls[] = { |
| 41 | { "MCU_R5FSS0_CORE0", 1024, 4 }, |
| 42 | { "MCU_R5FSS0_CORE0_CFG", 1025, 3 }, |
| 43 | { "MCU_R5FSS0_CORE1", 1028, 4 }, |
| 44 | { "MCU_R5FSS0_CORE1_CFG", 1029, 1 }, |
| 45 | { "MCU_FSS0_CFG", 1032, 12 }, |
| 46 | { "MCU_FSS0_S1", 1033, 8 }, |
| 47 | { "MCU_FSS0_S0", 1036, 8 }, |
| 48 | { "MCU_PSROM49152X32", 1048, 1 }, |
| 49 | { "MCU_MSRAM128KX64", 1050, 8 }, |
| 50 | { "MCU_MSRAM128KX64_CFG", 1051, 1 }, |
| 51 | { "MCU_TIMER0", 1056, 1 }, |
| 52 | { "MCU_TIMER9", 1065, 1 }, |
| 53 | { "MCU_USART0", 1120, 1 }, |
| 54 | { "MCU_I2C0", 1152, 1 }, |
| 55 | { "MCU_CTRL_MMR0", 1200, 8 }, |
| 56 | { "MCU_PLL_MMR0", 1201, 3 }, |
| 57 | { "MCU_CPSW0", 1220, 2 }, |
| 58 | }, wkup_cbass0_fwls[] = { |
| 59 | { "WKUP_PSC0", 129, 1 }, |
| 60 | { "WKUP_PLL_CTRL0", 130, 1 }, |
| 61 | { "WKUP_CTRL_MMR0", 131, 16 }, |
| 62 | { "WKUP_GPIO0", 132, 1 }, |
| 63 | { "WKUP_I2C0", 144, 1 }, |
| 64 | { "WKUP_USART0", 160, 1 }, |
| 65 | }, navss_cbass0_fwls[] = { |
| 66 | { "NACSS_VIRT0", 6253, 1 }, |
| 67 | }; |
| 68 | |
David Huang | 6109820 | 2022-01-25 20:56:31 +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); |
| 92 | mmr_unlock(CTRL_MMR0_BASE, 5); |
| 93 | mmr_unlock(CTRL_MMR0_BASE, 7); |
| 94 | } |
| 95 | |
| 96 | void k3_mmc_stop_clock(void) |
| 97 | { |
| 98 | if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) { |
| 99 | if (spl_boot_device() == BOOT_DEVICE_MMC1) { |
| 100 | struct mmc *mmc = find_mmc_device(0); |
| 101 | |
| 102 | if (!mmc) |
| 103 | return; |
| 104 | |
| 105 | mmc->saved_clock = mmc->clock; |
| 106 | mmc_set_clock(mmc, 0, true); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | void k3_mmc_restart_clock(void) |
| 112 | { |
| 113 | if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) { |
| 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 | } |
| 124 | |
| 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 | */ |
| 130 | u32 bootindex __attribute__((section(".data"))); |
| 131 | static struct rom_extended_boot_data bootdata __section(".data"); |
| 132 | |
| 133 | static void store_boot_info_from_rom(void) |
| 134 | { |
| 135 | bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX); |
Bryan Brattlof | 270537c | 2022-11-22 13:28:11 -0600 | [diff] [blame] | 136 | memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO, |
David Huang | 6109820 | 2022-01-25 20:56:31 +0530 | [diff] [blame] | 137 | sizeof(struct rom_extended_boot_data)); |
| 138 | } |
| 139 | |
Sinthu Raja | 863839a | 2023-01-10 21:17:53 +0530 | [diff] [blame] | 140 | void k3_spl_init(void) |
David Huang | 6109820 | 2022-01-25 20:56:31 +0530 | [diff] [blame] | 141 | { |
| 142 | struct udevice *dev; |
| 143 | int ret; |
| 144 | /* |
| 145 | * Cannot delay this further as there is a chance that |
| 146 | * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section. |
| 147 | */ |
| 148 | store_boot_info_from_rom(); |
| 149 | |
| 150 | /* Make all control module registers accessible */ |
| 151 | ctrl_mmr_unlock(); |
| 152 | |
| 153 | if (IS_ENABLED(CONFIG_CPU_V7R)) { |
| 154 | disable_linefill_optimization(); |
| 155 | setup_k3_mpu_regions(); |
| 156 | } |
| 157 | |
| 158 | /* Init DM early */ |
| 159 | spl_early_init(); |
| 160 | |
| 161 | /* Prepare console output */ |
| 162 | preloader_console_init(); |
| 163 | |
| 164 | if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) { |
| 165 | /* |
| 166 | * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue |
| 167 | * regardless of the result of pinctrl. Do this without probing the |
| 168 | * device, but instead by searching the device that would request the |
| 169 | * given sequence number if probed. The UART will be used by the system |
| 170 | * firmware (SYSFW) image for various purposes and SYSFW depends on us |
| 171 | * to initialize its pin settings. |
| 172 | */ |
| 173 | ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev); |
| 174 | if (!ret) |
| 175 | pinctrl_select_state(dev, "default"); |
| 176 | |
| 177 | /* |
| 178 | * Load, start up, and configure system controller firmware. Provide |
| 179 | * the U-Boot console init function to the SYSFW post-PM configuration |
| 180 | * callback hook, effectively switching on (or over) the console |
| 181 | * output. |
| 182 | */ |
| 183 | k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata), |
| 184 | k3_mmc_stop_clock, k3_mmc_restart_clock); |
| 185 | |
| 186 | if (IS_ENABLED(CONFIG_SPL_CLK_K3)) { |
| 187 | /* |
| 188 | * Force probe of clk_k3 driver here to ensure basic default clock |
| 189 | * configuration is always done for enabling PM services. |
| 190 | */ |
| 191 | ret = uclass_get_device_by_driver(UCLASS_CLK, |
| 192 | DM_DRIVER_GET(ti_clk), |
| 193 | &dev); |
| 194 | if (ret) |
| 195 | panic("Failed to initialize clk-k3!\n"); |
| 196 | } |
Jayesh Choudhary | 7796c72 | 2023-03-28 18:32:01 +0530 | [diff] [blame] | 197 | |
| 198 | remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls)); |
| 199 | remove_fwl_configs(cbass_hc2_fwls, ARRAY_SIZE(cbass_hc2_fwls)); |
| 200 | remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls)); |
| 201 | remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls)); |
| 202 | remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls)); |
| 203 | remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls)); |
| 204 | remove_fwl_configs(navss_cbass0_fwls, ARRAY_SIZE(navss_cbass0_fwls)); |
David Huang | 6109820 | 2022-01-25 20:56:31 +0530 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | /* Output System Firmware version info */ |
| 208 | k3_sysfw_print_ver(); |
Sinthu Raja | 863839a | 2023-01-10 21:17:53 +0530 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | bool check_rom_loaded_sysfw(void) |
| 212 | { |
| 213 | return is_rom_loaded_sysfw(&bootdata); |
| 214 | } |
| 215 | |
| 216 | void k3_mem_init(void) |
| 217 | { |
| 218 | struct udevice *dev; |
| 219 | int ret; |
David Huang | 6109820 | 2022-01-25 20:56:31 +0530 | [diff] [blame] | 220 | |
Dominik Haller | 6e95f87 | 2023-08-11 12:04:44 +0200 | [diff] [blame] | 221 | if (IS_ENABLED(CONFIG_K3_J721E_DDRSS)) { |
David Huang | 6109820 | 2022-01-25 20:56:31 +0530 | [diff] [blame] | 222 | ret = uclass_get_device_by_name(UCLASS_MISC, "msmc", &dev); |
| 223 | if (ret) |
| 224 | panic("Probe of msmc failed: %d\n", ret); |
| 225 | |
| 226 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 227 | if (ret) |
| 228 | panic("DRAM 0 init failed: %d\n", ret); |
| 229 | |
Michal Suchanek | 93ccce5 | 2022-10-12 21:58:00 +0200 | [diff] [blame] | 230 | ret = uclass_next_device_err(&dev); |
Neha Malcom Francis | 37d200e | 2024-01-30 15:53:56 +0530 | [diff] [blame] | 231 | if (ret && ret != -ENODEV) |
David Huang | 6109820 | 2022-01-25 20:56:31 +0530 | [diff] [blame] | 232 | panic("DRAM 1 init failed: %d\n", ret); |
| 233 | } |
Joao Paulo Goncalves | fc3557f | 2023-11-13 16:07:21 -0300 | [diff] [blame] | 234 | spl_enable_cache(); |
David Huang | 6109820 | 2022-01-25 20:56:31 +0530 | [diff] [blame] | 235 | } |
| 236 | |
Andrew Davis | de20b95 | 2023-04-06 11:38:20 -0500 | [diff] [blame] | 237 | /* Support for the various EVM / SK families */ |
| 238 | #if defined(CONFIG_SPL_OF_LIST) && defined(CONFIG_TI_I2C_BOARD_DETECT) |
| 239 | void do_dt_magic(void) |
| 240 | { |
| 241 | int ret, rescan, mmc_dev = -1; |
| 242 | static struct mmc *mmc; |
| 243 | |
| 244 | do_board_detect(); |
| 245 | |
| 246 | /* |
| 247 | * Board detection has been done. |
| 248 | * Let us see if another dtb wouldn't be a better match |
| 249 | * for our board |
| 250 | */ |
| 251 | if (IS_ENABLED(CONFIG_CPU_V7R)) { |
| 252 | ret = fdtdec_resetup(&rescan); |
| 253 | if (!ret && rescan) { |
| 254 | dm_uninit(); |
| 255 | dm_init_and_scan(true); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | /* |
| 260 | * Because of multi DTB configuration, the MMC device has |
| 261 | * to be re-initialized after reconfiguring FDT inorder to |
| 262 | * boot from MMC. Do this when boot mode is MMC and ROM has |
| 263 | * not loaded SYSFW. |
| 264 | */ |
| 265 | switch (spl_boot_device()) { |
| 266 | case BOOT_DEVICE_MMC1: |
| 267 | mmc_dev = 0; |
| 268 | break; |
| 269 | case BOOT_DEVICE_MMC2: |
| 270 | case BOOT_DEVICE_MMC2_2: |
| 271 | mmc_dev = 1; |
| 272 | break; |
| 273 | } |
| 274 | |
| 275 | if (mmc_dev > 0 && !check_rom_loaded_sysfw()) { |
| 276 | ret = mmc_init_device(mmc_dev); |
| 277 | if (!ret) { |
| 278 | mmc = find_mmc_device(mmc_dev); |
| 279 | if (mmc) { |
| 280 | ret = mmc_init(mmc); |
| 281 | if (ret) |
| 282 | printf("mmc init failed with error: %d\n", ret); |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | #endif |
| 288 | |
| 289 | #ifdef CONFIG_SPL_BUILD |
| 290 | void board_init_f(ulong dummy) |
| 291 | { |
| 292 | k3_spl_init(); |
| 293 | #if defined(CONFIG_SPL_OF_LIST) && defined(CONFIG_TI_I2C_BOARD_DETECT) |
| 294 | do_dt_magic(); |
| 295 | #endif |
| 296 | k3_mem_init(); |
| 297 | } |
| 298 | #endif |
| 299 | |
Andre Przywara | 3cb12ef | 2021-07-12 11:06:49 +0100 | [diff] [blame] | 300 | u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device) |
David Huang | 6109820 | 2022-01-25 20:56:31 +0530 | [diff] [blame] | 301 | { |
| 302 | switch (boot_device) { |
| 303 | case BOOT_DEVICE_MMC1: |
| 304 | return MMCSD_MODE_EMMCBOOT; |
| 305 | case BOOT_DEVICE_MMC2: |
| 306 | return MMCSD_MODE_FS; |
| 307 | default: |
| 308 | return MMCSD_MODE_RAW; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | static u32 __get_backup_bootmedia(u32 main_devstat) |
| 313 | { |
| 314 | u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >> |
| 315 | MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT; |
| 316 | |
| 317 | switch (bkup_boot) { |
| 318 | case BACKUP_BOOT_DEVICE_USB: |
| 319 | return BOOT_DEVICE_DFU; |
| 320 | case BACKUP_BOOT_DEVICE_UART: |
| 321 | return BOOT_DEVICE_UART; |
| 322 | case BACKUP_BOOT_DEVICE_ETHERNET: |
| 323 | return BOOT_DEVICE_ETHERNET; |
| 324 | case BACKUP_BOOT_DEVICE_MMC2: |
| 325 | { |
| 326 | u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >> |
| 327 | MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT; |
| 328 | if (port == 0x0) |
| 329 | return BOOT_DEVICE_MMC1; |
| 330 | return BOOT_DEVICE_MMC2; |
| 331 | } |
| 332 | case BACKUP_BOOT_DEVICE_SPI: |
| 333 | return BOOT_DEVICE_SPI; |
| 334 | case BACKUP_BOOT_DEVICE_I2C: |
| 335 | return BOOT_DEVICE_I2C; |
| 336 | } |
| 337 | |
| 338 | return BOOT_DEVICE_RAM; |
| 339 | } |
| 340 | |
| 341 | static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat) |
| 342 | { |
| 343 | u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >> |
| 344 | WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT; |
| 345 | |
| 346 | bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << |
| 347 | BOOT_MODE_B_SHIFT; |
| 348 | |
| 349 | if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI || |
| 350 | bootmode == BOOT_DEVICE_XSPI) |
| 351 | bootmode = BOOT_DEVICE_SPI; |
| 352 | |
| 353 | if (bootmode == BOOT_DEVICE_MMC2) { |
| 354 | u32 port = (main_devstat & |
| 355 | MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >> |
| 356 | MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT; |
| 357 | if (port == 0x0) |
| 358 | bootmode = BOOT_DEVICE_MMC1; |
| 359 | } |
| 360 | |
| 361 | return bootmode; |
| 362 | } |
| 363 | |
| 364 | u32 spl_boot_device(void) |
| 365 | { |
| 366 | u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT); |
| 367 | u32 main_devstat; |
| 368 | |
| 369 | if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) { |
| 370 | printf("ERROR: MCU only boot is not yet supported\n"); |
| 371 | return BOOT_DEVICE_RAM; |
| 372 | } |
| 373 | |
| 374 | /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */ |
| 375 | main_devstat = readl(CTRLMMR_MAIN_DEVSTAT); |
| 376 | |
| 377 | if (bootindex == K3_PRIMARY_BOOTMODE) |
| 378 | return __get_primary_bootmedia(main_devstat, wkup_devstat); |
| 379 | else |
| 380 | return __get_backup_bootmedia(main_devstat); |
| 381 | } |