Apurva Nandan | 67ebc30 | 2024-02-24 01:51:41 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * J784S4: SoC specific initialization |
| 4 | * |
| 5 | * Copyright (C) 2023-2024 Texas Instruments Incorporated - https://www.ti.com/ |
| 6 | * Hari Nagalla <hnagalla@ti.com> |
| 7 | */ |
| 8 | |
| 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> |
| 14 | #include "sysfw-loader.h" |
| 15 | #include "common.h" |
| 16 | #include <linux/soc/ti/ti_sci_protocol.h> |
| 17 | #include <dm.h> |
| 18 | #include <dm/uclass-internal.h> |
| 19 | #include <dm/pinctrl.h> |
| 20 | #include <mmc.h> |
| 21 | #include <remoteproc.h> |
| 22 | |
| 23 | #define J784S4_MAX_DDR_CONTROLLERS 4 |
| 24 | |
| 25 | struct fwl_data infra_cbass0_fwls[] = { |
| 26 | { "PSC0", 5, 1 }, |
| 27 | { "PLL_CTRL0", 6, 1 }, |
| 28 | { "PLL_MMR0", 8, 26 }, |
| 29 | { "CTRL_MMR0", 9, 16 }, |
| 30 | { "GPIO0", 16, 1 }, |
| 31 | }, wkup_cbass0_fwls[] = { |
| 32 | { "WKUP_PSC0", 129, 1 }, |
| 33 | { "WKUP_PLL_CTRL0", 130, 1 }, |
| 34 | { "WKUP_CTRL_MMR0", 131, 16 }, |
| 35 | { "WKUP_GPIO0", 132, 1 }, |
| 36 | { "WKUP_I2C0", 144, 1 }, |
| 37 | { "WKUP_USART0", 160, 1 }, |
| 38 | }, mcu_cbass0_fwls[] = { |
| 39 | { "MCU_R5FSS0_CORE0", 1024, 4 }, |
| 40 | { "MCU_R5FSS0_CORE0_CFG", 1025, 3 }, |
| 41 | { "MCU_R5FSS0_CORE1", 1028, 4 }, |
| 42 | { "MCU_R5FSS0_CORE1_CFG", 1029, 1 }, |
| 43 | { "MCU_FSS0_CFG", 1032, 12 }, |
| 44 | { "MCU_FSS0_S1", 1033, 8 }, |
| 45 | { "MCU_FSS0_S0", 1036, 8 }, |
| 46 | { "MCU_PSROM49152X32", 1048, 1 }, |
| 47 | { "MCU_MSRAM128KX64", 1050, 8 }, |
| 48 | { "MCU_MSRAM128KX64_CFG", 1051, 1 }, |
| 49 | { "MCU_TIMER0", 1056, 1 }, |
| 50 | { "MCU_TIMER9", 1065, 1 }, |
| 51 | { "MCU_USART0", 1120, 1 }, |
| 52 | { "MCU_I2C0", 1152, 1 }, |
| 53 | { "MCU_CTRL_MMR0", 1200, 8 }, |
| 54 | { "MCU_PLL_MMR0", 1201, 3 }, |
| 55 | { "MCU_CPSW0", 1220, 2 }, |
| 56 | }, cbass_rc_cfg0_fwls[] = { |
| 57 | { "EMMCSD4SS0_CFG", 2400, 4 }, |
| 58 | }, cbass_hc2_fwls[] = { |
| 59 | { "PCIE0", 2547, 24 }, |
| 60 | }, cbass_hc_cfg0_fwls[] = { |
| 61 | { "PCIE0_CFG", 2577, 7 }, |
| 62 | { "EMMC8SS0_CFG", 2579, 4 }, |
| 63 | { "USB3SS0_CORE", 2580, 4 }, |
| 64 | { "USB3SS1_CORE", 2581, 1 }, |
| 65 | }, navss_cbass0_fwls[] = { |
| 66 | { "NACSS_VIRT0", 6253, 1 }, |
| 67 | }; |
| 68 | |
| 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 | /* |
| 97 | * This uninitialized global variable would normal end up in the .bss section, |
| 98 | * but the .bss is cleared between writing and reading this variable, so move |
| 99 | * it to the .data section. |
| 100 | */ |
| 101 | u32 bootindex __section(".data"); |
| 102 | static struct rom_extended_boot_data bootdata __section(".data"); |
| 103 | |
| 104 | static void store_boot_info_from_rom(void) |
| 105 | { |
| 106 | bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX); |
| 107 | memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO, |
| 108 | sizeof(struct rom_extended_boot_data)); |
| 109 | } |
| 110 | |
| 111 | void k3_spl_init(void) |
| 112 | { |
| 113 | struct udevice *dev; |
| 114 | int ret; |
| 115 | |
| 116 | /* |
| 117 | * Cannot delay this further as there is a chance that |
| 118 | * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section. |
| 119 | */ |
| 120 | store_boot_info_from_rom(); |
| 121 | |
| 122 | /* Make all control module registers accessible */ |
| 123 | ctrl_mmr_unlock(); |
| 124 | |
| 125 | if (IS_ENABLED(CONFIG_CPU_V7R)) { |
| 126 | disable_linefill_optimization(); |
| 127 | setup_k3_mpu_regions(); |
| 128 | } |
| 129 | |
| 130 | /* Init DM early */ |
| 131 | ret = spl_early_init(); |
| 132 | |
| 133 | /* Prepare console output */ |
| 134 | preloader_console_init(); |
| 135 | |
| 136 | if (IS_ENABLED(CONFIG_CPU_V7R)) { |
| 137 | /* |
| 138 | * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue |
| 139 | * regardless of the result of pinctrl. Do this without probing the |
| 140 | * device, but instead by searching the device that would request the |
| 141 | * given sequence number if probed. The UART will be used by the system |
| 142 | * firmware (TIFS) image for various purposes and TIFS depends on us |
| 143 | * to initialize its pin settings. |
| 144 | */ |
| 145 | ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev); |
| 146 | if (!ret) |
| 147 | pinctrl_select_state(dev, "default"); |
| 148 | |
| 149 | /* |
| 150 | * Load, start up, and configure system controller firmware. Provide |
| 151 | * the U-Boot console init function to the TIFS post-PM configuration |
| 152 | * callback hook, effectively switching on (or over) the console |
| 153 | * output. |
| 154 | */ |
| 155 | k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata), NULL, NULL); |
| 156 | |
| 157 | if (IS_ENABLED(CONFIG_SPL_CLK_K3)) { |
| 158 | /* |
| 159 | * Force probe of clk_k3 driver here to ensure basic default clock |
| 160 | * configuration is always done for enabling PM services. |
| 161 | */ |
| 162 | ret = uclass_get_device_by_driver(UCLASS_CLK, |
| 163 | DM_DRIVER_GET(ti_clk), |
| 164 | &dev); |
| 165 | if (ret) |
| 166 | panic("Failed to initialize clk-k3!\n"); |
| 167 | } |
| 168 | |
| 169 | remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls)); |
| 170 | remove_fwl_configs(cbass_hc2_fwls, ARRAY_SIZE(cbass_hc2_fwls)); |
| 171 | remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls)); |
| 172 | remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls)); |
| 173 | remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls)); |
| 174 | remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls)); |
| 175 | remove_fwl_configs(navss_cbass0_fwls, ARRAY_SIZE(navss_cbass0_fwls)); |
| 176 | } |
| 177 | |
| 178 | /* Output System Firmware version info */ |
| 179 | k3_sysfw_print_ver(); |
| 180 | } |
| 181 | |
| 182 | void k3_mem_init(void) |
| 183 | { |
| 184 | struct udevice *dev; |
| 185 | int ret, ctrl = 0; |
| 186 | |
| 187 | if (IS_ENABLED(CONFIG_K3_J721E_DDRSS)) { |
| 188 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 189 | if (ret) |
| 190 | panic("DRAM 0 init failed: %d\n", ret); |
| 191 | ctrl++; |
| 192 | |
| 193 | while (ctrl < J784S4_MAX_DDR_CONTROLLERS) { |
| 194 | ret = uclass_next_device_err(&dev); |
| 195 | if (ret == -ENODEV) |
| 196 | break; |
| 197 | |
| 198 | if (ret) |
| 199 | panic("DRAM %d init failed: %d\n", ctrl, ret); |
| 200 | ctrl++; |
| 201 | } |
| 202 | printf("Initialized %d DRAM controllers\n", ctrl); |
| 203 | } |
| 204 | |
| 205 | spl_enable_cache(); |
| 206 | } |
| 207 | |
| 208 | void board_init_f(ulong dummy) |
| 209 | { |
| 210 | k3_spl_init(); |
| 211 | k3_mem_init(); |
| 212 | } |
| 213 | |
| 214 | u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device) |
| 215 | { |
| 216 | switch (boot_device) { |
| 217 | case BOOT_DEVICE_MMC1: |
| 218 | if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT)) |
| 219 | return MMCSD_MODE_EMMCBOOT; |
| 220 | if (IS_ENABLED(CONFIG_SPL_FS_FAT) || IS_ENABLED(CONFIG_SPL_FS_EXT4)) |
| 221 | return MMCSD_MODE_FS; |
| 222 | return MMCSD_MODE_EMMCBOOT; |
| 223 | case BOOT_DEVICE_MMC2: |
| 224 | return MMCSD_MODE_FS; |
| 225 | default: |
| 226 | return MMCSD_MODE_RAW; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | static u32 __get_backup_bootmedia(u32 main_devstat) |
| 231 | { |
| 232 | u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >> |
| 233 | MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT; |
| 234 | |
| 235 | switch (bkup_boot) { |
| 236 | case BACKUP_BOOT_DEVICE_USB: |
| 237 | return BOOT_DEVICE_DFU; |
| 238 | case BACKUP_BOOT_DEVICE_UART: |
| 239 | return BOOT_DEVICE_UART; |
| 240 | case BACKUP_BOOT_DEVICE_ETHERNET: |
| 241 | return BOOT_DEVICE_ETHERNET; |
| 242 | case BACKUP_BOOT_DEVICE_MMC2: |
| 243 | { |
| 244 | u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >> |
| 245 | MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT; |
| 246 | if (port == 0x0) |
| 247 | return BOOT_DEVICE_MMC1; |
| 248 | return BOOT_DEVICE_MMC2; |
| 249 | } |
| 250 | case BACKUP_BOOT_DEVICE_SPI: |
| 251 | return BOOT_DEVICE_SPI; |
| 252 | case BACKUP_BOOT_DEVICE_I2C: |
| 253 | return BOOT_DEVICE_I2C; |
| 254 | } |
| 255 | |
| 256 | return BOOT_DEVICE_RAM; |
| 257 | } |
| 258 | |
| 259 | static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat) |
| 260 | { |
| 261 | u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >> |
| 262 | WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT; |
| 263 | |
| 264 | bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << |
| 265 | BOOT_MODE_B_SHIFT; |
| 266 | |
| 267 | if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI || |
| 268 | bootmode == BOOT_DEVICE_XSPI) |
| 269 | bootmode = BOOT_DEVICE_SPI; |
| 270 | |
| 271 | if (bootmode == BOOT_DEVICE_MMC2) { |
| 272 | u32 port = (main_devstat & |
| 273 | MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >> |
| 274 | MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT; |
| 275 | if (port == 0x0) |
| 276 | bootmode = BOOT_DEVICE_MMC1; |
| 277 | } |
| 278 | |
| 279 | return bootmode; |
| 280 | } |
| 281 | |
| 282 | u32 spl_spi_boot_bus(void) |
| 283 | { |
| 284 | u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT); |
| 285 | u32 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT); |
| 286 | u32 bootmode = ((wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >> |
| 287 | WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT) | |
| 288 | ((main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << BOOT_MODE_B_SHIFT); |
| 289 | |
| 290 | return (bootmode == BOOT_DEVICE_QSPI) ? 1 : 0; |
| 291 | } |
| 292 | |
| 293 | u32 spl_boot_device(void) |
| 294 | { |
| 295 | u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT); |
| 296 | u32 main_devstat; |
| 297 | |
| 298 | if (wkup_devstat & WKUP_DEVSTAT_MCU_ONLY_MASK) { |
| 299 | printf("ERROR: MCU only boot is not yet supported\n"); |
| 300 | return BOOT_DEVICE_RAM; |
| 301 | } |
| 302 | |
| 303 | /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */ |
| 304 | main_devstat = readl(CTRLMMR_MAIN_DEVSTAT); |
| 305 | |
| 306 | if (bootindex == K3_PRIMARY_BOOTMODE) |
| 307 | return __get_primary_bootmedia(main_devstat, wkup_devstat); |
| 308 | else |
| 309 | return __get_backup_bootmedia(main_devstat); |
| 310 | } |