Peng Fan | 5c2218a | 2021-08-07 16:00:31 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2021 NXP |
| 4 | */ |
| 5 | |
Peng Fan | 7253016 | 2021-08-07 16:00:33 +0800 | [diff] [blame] | 6 | #include <asm/io.h> |
| 7 | #include <asm/arch/clock.h> |
| 8 | #include <asm/arch/imx-regs.h> |
Peng Fan | 5c2218a | 2021-08-07 16:00:31 +0800 | [diff] [blame] | 9 | #include <asm/arch/sys_proto.h> |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 10 | #include <asm/armv8/mmu.h> |
Peng Fan | 7253016 | 2021-08-07 16:00:33 +0800 | [diff] [blame] | 11 | #include <asm/mach-imx/boot_mode.h> |
Ye Li | 88044c7 | 2021-08-07 16:01:01 +0800 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Ye Li | 6dd4302 | 2021-08-07 16:00:48 +0800 | [diff] [blame] | 13 | #include <efi_loader.h> |
| 14 | #include <spl.h> |
Peng Fan | 9c87e46 | 2021-08-07 16:00:59 +0800 | [diff] [blame] | 15 | #include <asm/arch/rdc.h> |
Ye Li | 853cc9d | 2021-08-07 16:00:55 +0800 | [diff] [blame] | 16 | #include <asm/arch/s400_api.h> |
| 17 | #include <asm/arch/mu_hal.h> |
| 18 | #include <cpu_func.h> |
| 19 | #include <asm/setup.h> |
Ye Li | 7bea5b0 | 2021-08-07 16:01:00 +0800 | [diff] [blame] | 20 | #include <dm.h> |
| 21 | #include <dm/device-internal.h> |
| 22 | #include <dm/lists.h> |
| 23 | #include <dm/uclass.h> |
| 24 | #include <dm/device.h> |
| 25 | #include <dm/uclass-internal.h> |
Ye Li | 7201262 | 2021-10-29 09:46:15 +0800 | [diff] [blame] | 26 | #include <fuse.h> |
Peng Fan | 5c2218a | 2021-08-07 16:00:31 +0800 | [diff] [blame] | 27 | |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 30 | struct rom_api *g_rom_api = (struct rom_api *)0x1980; |
| 31 | |
Ye Li | 88044c7 | 2021-08-07 16:01:01 +0800 | [diff] [blame] | 32 | enum boot_device get_boot_device(void) |
| 33 | { |
| 34 | volatile gd_t *pgd = gd; |
| 35 | int ret; |
| 36 | u32 boot; |
| 37 | u16 boot_type; |
| 38 | u8 boot_instance; |
| 39 | enum boot_device boot_dev = SD1_BOOT; |
| 40 | |
| 41 | ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot, |
| 42 | ((uintptr_t)&boot) ^ QUERY_BT_DEV); |
| 43 | set_gd(pgd); |
| 44 | |
| 45 | if (ret != ROM_API_OKAY) { |
| 46 | puts("ROMAPI: failure at query_boot_info\n"); |
| 47 | return -1; |
| 48 | } |
| 49 | |
| 50 | boot_type = boot >> 16; |
| 51 | boot_instance = (boot >> 8) & 0xff; |
| 52 | |
| 53 | switch (boot_type) { |
| 54 | case BT_DEV_TYPE_SD: |
| 55 | boot_dev = boot_instance + SD1_BOOT; |
| 56 | break; |
| 57 | case BT_DEV_TYPE_MMC: |
| 58 | boot_dev = boot_instance + MMC1_BOOT; |
| 59 | break; |
| 60 | case BT_DEV_TYPE_NAND: |
| 61 | boot_dev = NAND_BOOT; |
| 62 | break; |
| 63 | case BT_DEV_TYPE_FLEXSPINOR: |
| 64 | boot_dev = QSPI_BOOT; |
| 65 | break; |
| 66 | case BT_DEV_TYPE_USB: |
| 67 | boot_dev = USB_BOOT; |
| 68 | break; |
| 69 | default: |
| 70 | break; |
| 71 | } |
| 72 | |
| 73 | return boot_dev; |
| 74 | } |
| 75 | |
| 76 | bool is_usb_boot(void) |
| 77 | { |
| 78 | return get_boot_device() == USB_BOOT; |
| 79 | } |
| 80 | |
| 81 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 82 | __weak int board_mmc_get_env_dev(int devno) |
| 83 | { |
| 84 | return devno; |
| 85 | } |
| 86 | |
| 87 | int mmc_get_env_dev(void) |
| 88 | { |
| 89 | volatile gd_t *pgd = gd; |
| 90 | int ret; |
| 91 | u32 boot; |
| 92 | u16 boot_type; |
| 93 | u8 boot_instance; |
| 94 | |
| 95 | ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot, |
| 96 | ((uintptr_t)&boot) ^ QUERY_BT_DEV); |
| 97 | set_gd(pgd); |
| 98 | |
| 99 | if (ret != ROM_API_OKAY) { |
| 100 | puts("ROMAPI: failure at query_boot_info\n"); |
| 101 | return CONFIG_SYS_MMC_ENV_DEV; |
| 102 | } |
| 103 | |
| 104 | boot_type = boot >> 16; |
| 105 | boot_instance = (boot >> 8) & 0xff; |
| 106 | |
| 107 | /* If not boot from sd/mmc, use default value */ |
| 108 | if (boot_type != BOOT_TYPE_SD && boot_type != BOOT_TYPE_MMC) |
| 109 | return env_get_ulong("mmcdev", 10, CONFIG_SYS_MMC_ENV_DEV); |
| 110 | |
| 111 | return board_mmc_get_env_dev(boot_instance); |
| 112 | } |
| 113 | #endif |
| 114 | |
Peng Fan | 5c2218a | 2021-08-07 16:00:31 +0800 | [diff] [blame] | 115 | u32 get_cpu_rev(void) |
| 116 | { |
| 117 | return (MXC_CPU_IMX8ULP << 12) | CHIP_REV_1_0; |
| 118 | } |
Peng Fan | 7253016 | 2021-08-07 16:00:33 +0800 | [diff] [blame] | 119 | |
| 120 | enum bt_mode get_boot_mode(void) |
| 121 | { |
| 122 | u32 bt0_cfg = 0; |
| 123 | |
Ye Li | 0e35805 | 2021-08-07 16:01:07 +0800 | [diff] [blame] | 124 | bt0_cfg = readl(SIM_SEC_BASE_ADDR + 0x24); |
Peng Fan | 7253016 | 2021-08-07 16:00:33 +0800 | [diff] [blame] | 125 | bt0_cfg &= (BT0CFG_LPBOOT_MASK | BT0CFG_DUALBOOT_MASK); |
| 126 | |
| 127 | if (!(bt0_cfg & BT0CFG_LPBOOT_MASK)) { |
| 128 | /* No low power boot */ |
| 129 | if (bt0_cfg & BT0CFG_DUALBOOT_MASK) |
| 130 | return DUAL_BOOT; |
| 131 | else |
| 132 | return SINGLE_BOOT; |
| 133 | } |
| 134 | |
| 135 | return LOW_POWER_BOOT; |
| 136 | } |
| 137 | |
Peng Fan | af4f3b3 | 2021-08-07 16:00:34 +0800 | [diff] [blame] | 138 | #define CMC_SRS_TAMPER BIT(31) |
| 139 | #define CMC_SRS_SECURITY BIT(30) |
| 140 | #define CMC_SRS_TZWDG BIT(29) |
| 141 | #define CMC_SRS_JTAG_RST BIT(28) |
| 142 | #define CMC_SRS_CORE1 BIT(16) |
| 143 | #define CMC_SRS_LOCKUP BIT(15) |
| 144 | #define CMC_SRS_SW BIT(14) |
| 145 | #define CMC_SRS_WDG BIT(13) |
| 146 | #define CMC_SRS_PIN_RESET BIT(8) |
| 147 | #define CMC_SRS_WARM BIT(4) |
| 148 | #define CMC_SRS_HVD BIT(3) |
| 149 | #define CMC_SRS_LVD BIT(2) |
| 150 | #define CMC_SRS_POR BIT(1) |
| 151 | #define CMC_SRS_WUP BIT(0) |
| 152 | |
Peng Fan | af4f3b3 | 2021-08-07 16:00:34 +0800 | [diff] [blame] | 153 | static char *get_reset_cause(char *ret) |
| 154 | { |
| 155 | u32 cause1, cause = 0, srs = 0; |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 156 | void __iomem *reg_ssrs = (void __iomem *)(CMC1_BASE_ADDR + 0x88); |
| 157 | void __iomem *reg_srs = (void __iomem *)(CMC1_BASE_ADDR + 0x80); |
Peng Fan | af4f3b3 | 2021-08-07 16:00:34 +0800 | [diff] [blame] | 158 | |
| 159 | if (!ret) |
| 160 | return "null"; |
| 161 | |
| 162 | srs = readl(reg_srs); |
| 163 | cause1 = readl(reg_ssrs); |
| 164 | |
Peng Fan | 0d720e2 | 2021-08-07 16:01:06 +0800 | [diff] [blame] | 165 | cause = srs & (CMC_SRS_POR | CMC_SRS_WUP | CMC_SRS_WARM); |
Peng Fan | af4f3b3 | 2021-08-07 16:00:34 +0800 | [diff] [blame] | 166 | |
| 167 | switch (cause) { |
| 168 | case CMC_SRS_POR: |
| 169 | sprintf(ret, "%s", "POR"); |
| 170 | break; |
| 171 | case CMC_SRS_WUP: |
| 172 | sprintf(ret, "%s", "WUP"); |
| 173 | break; |
| 174 | case CMC_SRS_WARM: |
Peng Fan | 0d720e2 | 2021-08-07 16:01:06 +0800 | [diff] [blame] | 175 | cause = srs & (CMC_SRS_WDG | CMC_SRS_SW | |
Peng Fan | af4f3b3 | 2021-08-07 16:00:34 +0800 | [diff] [blame] | 176 | CMC_SRS_JTAG_RST); |
| 177 | switch (cause) { |
| 178 | case CMC_SRS_WDG: |
| 179 | sprintf(ret, "%s", "WARM-WDG"); |
| 180 | break; |
| 181 | case CMC_SRS_SW: |
| 182 | sprintf(ret, "%s", "WARM-SW"); |
| 183 | break; |
| 184 | case CMC_SRS_JTAG_RST: |
| 185 | sprintf(ret, "%s", "WARM-JTAG"); |
| 186 | break; |
| 187 | default: |
| 188 | sprintf(ret, "%s", "WARM-UNKN"); |
| 189 | break; |
| 190 | } |
| 191 | break; |
| 192 | default: |
Peng Fan | 0d720e2 | 2021-08-07 16:01:06 +0800 | [diff] [blame] | 193 | sprintf(ret, "%s-%X", "UNKN", srs); |
Peng Fan | af4f3b3 | 2021-08-07 16:00:34 +0800 | [diff] [blame] | 194 | break; |
| 195 | } |
| 196 | |
| 197 | debug("[%X] SRS[%X] %X - ", cause1, srs, srs ^ cause1); |
| 198 | return ret; |
| 199 | } |
| 200 | |
Peng Fan | 7253016 | 2021-08-07 16:00:33 +0800 | [diff] [blame] | 201 | #if defined(CONFIG_DISPLAY_CPUINFO) |
| 202 | const char *get_imx_type(u32 imxtype) |
| 203 | { |
| 204 | return "8ULP"; |
| 205 | } |
| 206 | |
| 207 | int print_cpuinfo(void) |
| 208 | { |
| 209 | u32 cpurev; |
| 210 | char cause[18]; |
| 211 | |
| 212 | cpurev = get_cpu_rev(); |
| 213 | |
Ye Li | f012ceb | 2021-10-29 09:46:24 +0800 | [diff] [blame^] | 214 | printf("CPU: i.MX%s rev%d.%d at %d MHz\n", |
Peng Fan | 7253016 | 2021-08-07 16:00:33 +0800 | [diff] [blame] | 215 | get_imx_type((cpurev & 0xFF000) >> 12), |
| 216 | (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0, |
| 217 | mxc_get_clock(MXC_ARM_CLK) / 1000000); |
| 218 | |
Peng Fan | af4f3b3 | 2021-08-07 16:00:34 +0800 | [diff] [blame] | 219 | printf("Reset cause: %s\n", get_reset_cause(cause)); |
| 220 | |
Peng Fan | 7253016 | 2021-08-07 16:00:33 +0800 | [diff] [blame] | 221 | printf("Boot mode: "); |
| 222 | switch (get_boot_mode()) { |
| 223 | case LOW_POWER_BOOT: |
| 224 | printf("Low power boot\n"); |
| 225 | break; |
| 226 | case DUAL_BOOT: |
| 227 | printf("Dual boot\n"); |
| 228 | break; |
| 229 | case SINGLE_BOOT: |
| 230 | default: |
| 231 | printf("Single boot\n"); |
| 232 | break; |
| 233 | } |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | #endif |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 238 | |
Peng Fan | c84bc10 | 2021-08-07 16:00:49 +0800 | [diff] [blame] | 239 | #define UNLOCK_WORD0 0xC520 /* 1st unlock word */ |
| 240 | #define UNLOCK_WORD1 0xD928 /* 2nd unlock word */ |
| 241 | #define REFRESH_WORD0 0xA602 /* 1st refresh word */ |
| 242 | #define REFRESH_WORD1 0xB480 /* 2nd refresh word */ |
| 243 | |
| 244 | static void disable_wdog(void __iomem *wdog_base) |
| 245 | { |
| 246 | u32 val_cs = readl(wdog_base + 0x00); |
| 247 | |
| 248 | if (!(val_cs & 0x80)) |
| 249 | return; |
| 250 | |
| 251 | dmb(); |
| 252 | __raw_writel(REFRESH_WORD0, (wdog_base + 0x04)); /* Refresh the CNT */ |
| 253 | __raw_writel(REFRESH_WORD1, (wdog_base + 0x04)); |
| 254 | dmb(); |
| 255 | |
| 256 | if (!(val_cs & 800)) { |
| 257 | dmb(); |
| 258 | __raw_writel(UNLOCK_WORD0, (wdog_base + 0x04)); |
| 259 | __raw_writel(UNLOCK_WORD1, (wdog_base + 0x04)); |
| 260 | dmb(); |
| 261 | |
| 262 | while (!(readl(wdog_base + 0x00) & 0x800)) |
| 263 | ; |
| 264 | } |
| 265 | writel(0x0, (wdog_base + 0x0C)); /* Set WIN to 0 */ |
| 266 | writel(0x400, (wdog_base + 0x08)); /* Set timeout to default 0x400 */ |
| 267 | writel(0x120, (wdog_base + 0x00)); /* Disable it and set update */ |
| 268 | |
| 269 | while (!(readl(wdog_base + 0x00) & 0x400)) |
| 270 | ; |
| 271 | } |
| 272 | |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 273 | void init_wdog(void) |
| 274 | { |
Peng Fan | c84bc10 | 2021-08-07 16:00:49 +0800 | [diff] [blame] | 275 | disable_wdog((void __iomem *)WDG3_RBASE); |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | static struct mm_region imx8ulp_arm64_mem_map[] = { |
| 279 | { |
| 280 | /* ROM */ |
| 281 | .virt = 0x0, |
| 282 | .phys = 0x0, |
| 283 | .size = 0x40000UL, |
| 284 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 285 | PTE_BLOCK_OUTER_SHARE |
| 286 | }, |
| 287 | { |
| 288 | /* FLEXSPI0 */ |
| 289 | .virt = 0x04000000, |
| 290 | .phys = 0x04000000, |
| 291 | .size = 0x08000000UL, |
| 292 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 293 | PTE_BLOCK_NON_SHARE | |
| 294 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 295 | }, |
| 296 | { |
| 297 | /* SSRAM (align with 2M) */ |
| 298 | .virt = 0x1FE00000UL, |
| 299 | .phys = 0x1FE00000UL, |
| 300 | .size = 0x400000UL, |
| 301 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 302 | PTE_BLOCK_OUTER_SHARE | |
| 303 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 304 | }, { |
| 305 | /* SRAM1 (align with 2M) */ |
| 306 | .virt = 0x21000000UL, |
| 307 | .phys = 0x21000000UL, |
| 308 | .size = 0x200000UL, |
| 309 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 310 | PTE_BLOCK_OUTER_SHARE | |
| 311 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 312 | }, { |
| 313 | /* SRAM0 (align with 2M) */ |
| 314 | .virt = 0x22000000UL, |
| 315 | .phys = 0x22000000UL, |
| 316 | .size = 0x200000UL, |
| 317 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 318 | PTE_BLOCK_OUTER_SHARE | |
| 319 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 320 | }, { |
| 321 | /* Peripherals */ |
| 322 | .virt = 0x27000000UL, |
| 323 | .phys = 0x27000000UL, |
| 324 | .size = 0x3000000UL, |
| 325 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 326 | PTE_BLOCK_NON_SHARE | |
| 327 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 328 | }, { |
| 329 | /* Peripherals */ |
| 330 | .virt = 0x2D000000UL, |
| 331 | .phys = 0x2D000000UL, |
| 332 | .size = 0x1600000UL, |
| 333 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 334 | PTE_BLOCK_NON_SHARE | |
| 335 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 336 | }, { |
| 337 | /* FLEXSPI1-2 */ |
| 338 | .virt = 0x40000000UL, |
| 339 | .phys = 0x40000000UL, |
| 340 | .size = 0x40000000UL, |
| 341 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 342 | PTE_BLOCK_NON_SHARE | |
| 343 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 344 | }, { |
| 345 | /* DRAM1 */ |
| 346 | .virt = 0x80000000UL, |
| 347 | .phys = 0x80000000UL, |
| 348 | .size = PHYS_SDRAM_SIZE, |
| 349 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 350 | PTE_BLOCK_OUTER_SHARE |
| 351 | }, { |
| 352 | /* |
| 353 | * empty entrie to split table entry 5 |
| 354 | * if needed when TEEs are used |
| 355 | */ |
| 356 | 0, |
| 357 | }, { |
| 358 | /* List terminator */ |
| 359 | 0, |
| 360 | } |
| 361 | }; |
| 362 | |
| 363 | struct mm_region *mem_map = imx8ulp_arm64_mem_map; |
| 364 | |
| 365 | /* simplify the page table size to enhance boot speed */ |
| 366 | #define MAX_PTE_ENTRIES 512 |
| 367 | #define MAX_MEM_MAP_REGIONS 16 |
| 368 | u64 get_page_table_size(void) |
| 369 | { |
| 370 | u64 one_pt = MAX_PTE_ENTRIES * sizeof(u64); |
| 371 | u64 size = 0; |
| 372 | |
| 373 | /* |
| 374 | * For each memory region, the max table size: |
| 375 | * 2 level 3 tables + 2 level 2 tables + 1 level 1 table |
| 376 | */ |
| 377 | size = (2 + 2 + 1) * one_pt * MAX_MEM_MAP_REGIONS + one_pt; |
| 378 | |
| 379 | /* |
| 380 | * We need to duplicate our page table once to have an emergency pt to |
| 381 | * resort to when splitting page tables later on |
| 382 | */ |
| 383 | size *= 2; |
| 384 | |
| 385 | /* |
| 386 | * We may need to split page tables later on if dcache settings change, |
| 387 | * so reserve up to 4 (random pick) page tables for that. |
| 388 | */ |
| 389 | size += one_pt * 4; |
| 390 | |
| 391 | return size; |
| 392 | } |
| 393 | |
| 394 | void enable_caches(void) |
| 395 | { |
| 396 | /* TODO: add TEE memmap region */ |
| 397 | |
| 398 | icache_enable(); |
| 399 | dcache_enable(); |
| 400 | } |
| 401 | |
| 402 | int dram_init(void) |
| 403 | { |
| 404 | gd->ram_size = PHYS_SDRAM_SIZE; |
| 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
Tom Rini | ae21e7f | 2021-08-30 09:16:29 -0400 | [diff] [blame] | 409 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 410 | void get_board_serial(struct tag_serialnr *serialnr) |
| 411 | { |
Ye Li | 7bea5b0 | 2021-08-07 16:01:00 +0800 | [diff] [blame] | 412 | u32 uid[4]; |
| 413 | u32 res; |
| 414 | int ret; |
| 415 | |
| 416 | ret = ahab_read_common_fuse(1, uid, 4, &res); |
| 417 | if (ret) |
| 418 | printf("ahab read fuse failed %d, 0x%x\n", ret, res); |
| 419 | else |
| 420 | printf("UID 0x%x,0x%x,0x%x,0x%x\n", uid[0], uid[1], uid[2], uid[3]); |
| 421 | |
| 422 | serialnr->low = uid[0]; |
| 423 | serialnr->high = uid[3]; |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 424 | } |
| 425 | #endif |
| 426 | |
Ye Li | 6ee435eb | 2021-08-07 16:00:50 +0800 | [diff] [blame] | 427 | static void set_core0_reset_vector(u32 entry) |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 428 | { |
Ye Li | 6dd4302 | 2021-08-07 16:00:48 +0800 | [diff] [blame] | 429 | /* Update SIM1 DGO8 for reset vector base */ |
Ye Li | 6ee435eb | 2021-08-07 16:00:50 +0800 | [diff] [blame] | 430 | writel(entry, SIM1_BASE_ADDR + 0x5c); |
Ye Li | 6dd4302 | 2021-08-07 16:00:48 +0800 | [diff] [blame] | 431 | |
| 432 | /* set update bit */ |
| 433 | setbits_le32(SIM1_BASE_ADDR + 0x8, 0x1 << 24); |
| 434 | |
| 435 | /* polling the ack */ |
| 436 | while ((readl(SIM1_BASE_ADDR + 0x8) & (0x1 << 26)) == 0) |
| 437 | ; |
| 438 | |
| 439 | /* clear the update */ |
| 440 | clrbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 24)); |
| 441 | |
| 442 | /* clear the ack by set 1 */ |
| 443 | setbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 26)); |
Ye Li | 6ee435eb | 2021-08-07 16:00:50 +0800 | [diff] [blame] | 444 | } |
| 445 | |
Peng Fan | 9c87e46 | 2021-08-07 16:00:59 +0800 | [diff] [blame] | 446 | static int trdc_set_access(void) |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 447 | { |
| 448 | /* |
Peng Fan | 9c87e46 | 2021-08-07 16:00:59 +0800 | [diff] [blame] | 449 | * TRDC mgr + 4 MBC + 2 MRC. |
| 450 | * S400 should already configure when release RDC |
| 451 | * A35 only map non-secure region for pbridge0 and 1, set sec_access to false |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 452 | */ |
Peng Fan | 9c87e46 | 2021-08-07 16:00:59 +0800 | [diff] [blame] | 453 | trdc_mbc_set_access(2, 7, 0, 49, false); |
| 454 | trdc_mbc_set_access(2, 7, 0, 50, false); |
| 455 | trdc_mbc_set_access(2, 7, 0, 51, false); |
| 456 | trdc_mbc_set_access(2, 7, 0, 52, false); |
| 457 | trdc_mbc_set_access(2, 7, 0, 53, false); |
| 458 | trdc_mbc_set_access(2, 7, 0, 54, false); |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 459 | |
Peng Fan | 9c87e46 | 2021-08-07 16:00:59 +0800 | [diff] [blame] | 460 | /* CGC0: PBridge0 slot 47 */ |
| 461 | trdc_mbc_set_access(2, 7, 0, 47, false); |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 462 | |
Peng Fan | 9c87e46 | 2021-08-07 16:00:59 +0800 | [diff] [blame] | 463 | /* Iomuxc0: : PBridge1 slot 33 */ |
| 464 | trdc_mbc_set_access(2, 7, 1, 33, false); |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 465 | |
Ye Li | d325d37 | 2021-10-29 09:46:20 +0800 | [diff] [blame] | 466 | /* flexspi0 */ |
| 467 | trdc_mrc_region_set_access(0, 7, 0x04000000, 0x0c000000, false); |
Ye Li | 27666ca | 2021-10-29 09:46:21 +0800 | [diff] [blame] | 468 | |
| 469 | /* tpm0: PBridge1 slot 21 */ |
| 470 | trdc_mbc_set_access(2, 7, 1, 21, false); |
| 471 | /* lpi2c0: PBridge1 slot 24 */ |
| 472 | trdc_mbc_set_access(2, 7, 1, 24, false); |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 473 | return 0; |
| 474 | } |
| 475 | |
Ye Li | 43819eb | 2021-10-29 09:46:16 +0800 | [diff] [blame] | 476 | void lpav_configure(void) |
| 477 | { |
| 478 | /* LPAV to APD */ |
| 479 | setbits_le32(SIM_SEC_BASE_ADDR + 0x44, BIT(7)); |
| 480 | |
Peng Fan | fa609b4 | 2021-10-29 09:46:17 +0800 | [diff] [blame] | 481 | /* PXP/GPU 2D/3D/DCNANO/MIPI_DSI/EPDC/HIFI4 to APD */ |
| 482 | setbits_le32(SIM_SEC_BASE_ADDR + 0x4c, 0x7F); |
Ye Li | 43819eb | 2021-10-29 09:46:16 +0800 | [diff] [blame] | 483 | |
| 484 | /* LPAV slave/dma2 ch allocation and request allocation to APD */ |
| 485 | writel(0x1f, SIM_SEC_BASE_ADDR + 0x50); |
| 486 | writel(0xffffffff, SIM_SEC_BASE_ADDR + 0x54); |
| 487 | writel(0x003fffff, SIM_SEC_BASE_ADDR + 0x58); |
Ye Li | 715cfa0 | 2021-10-29 09:46:23 +0800 | [diff] [blame] | 488 | } |
Ye Li | a031155 | 2021-10-29 09:46:22 +0800 | [diff] [blame] | 489 | |
Ye Li | 715cfa0 | 2021-10-29 09:46:23 +0800 | [diff] [blame] | 490 | void set_lpav_qos(void) |
| 491 | { |
Ye Li | a031155 | 2021-10-29 09:46:22 +0800 | [diff] [blame] | 492 | /* Set read QoS of dcnano on LPAV NIC */ |
| 493 | writel(0xf, 0x2e447100); |
Ye Li | 43819eb | 2021-10-29 09:46:16 +0800 | [diff] [blame] | 494 | } |
| 495 | |
Ye Li | 6ee435eb | 2021-08-07 16:00:50 +0800 | [diff] [blame] | 496 | int arch_cpu_init(void) |
| 497 | { |
| 498 | if (IS_ENABLED(CONFIG_SPL_BUILD)) { |
Ye Li | 7201262 | 2021-10-29 09:46:15 +0800 | [diff] [blame] | 499 | u32 val = 0; |
| 500 | int ret; |
| 501 | bool rdc_en = true; /* Default assume DBD_EN is set */ |
| 502 | |
Ye Li | 853cc9d | 2021-08-07 16:00:55 +0800 | [diff] [blame] | 503 | /* Disable wdog */ |
| 504 | init_wdog(); |
| 505 | |
Ye Li | 7201262 | 2021-10-29 09:46:15 +0800 | [diff] [blame] | 506 | /* Read DBD_EN fuse */ |
| 507 | ret = fuse_read(8, 1, &val); |
| 508 | if (!ret) |
| 509 | rdc_en = !!(val & 0x4000); |
| 510 | |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 511 | if (get_boot_mode() == SINGLE_BOOT) { |
Ye Li | 7201262 | 2021-10-29 09:46:15 +0800 | [diff] [blame] | 512 | if (rdc_en) |
| 513 | release_rdc(RDC_TRDC); |
| 514 | |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 515 | trdc_set_access(); |
Ye Li | 43819eb | 2021-10-29 09:46:16 +0800 | [diff] [blame] | 516 | |
| 517 | lpav_configure(); |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 518 | } |
Peng Fan | fa55b21 | 2021-08-07 16:00:57 +0800 | [diff] [blame] | 519 | |
Ye Li | 7201262 | 2021-10-29 09:46:15 +0800 | [diff] [blame] | 520 | /* Release xrdc, then allow A35 to write SRAM2 */ |
| 521 | if (rdc_en) |
| 522 | release_rdc(RDC_XRDC); |
| 523 | |
Ye Li | 853cc9d | 2021-08-07 16:00:55 +0800 | [diff] [blame] | 524 | xrdc_mrc_region_set_access(2, CONFIG_SPL_TEXT_BASE, 0xE00); |
| 525 | |
Ye Li | 6ee435eb | 2021-08-07 16:00:50 +0800 | [diff] [blame] | 526 | clock_init(); |
| 527 | } else { |
| 528 | /* reconfigure core0 reset vector to ROM */ |
| 529 | set_core0_reset_vector(0x1000); |
| 530 | } |
| 531 | |
| 532 | return 0; |
| 533 | } |
| 534 | |
Ye Li | 7bea5b0 | 2021-08-07 16:01:00 +0800 | [diff] [blame] | 535 | int arch_cpu_init_dm(void) |
| 536 | { |
| 537 | struct udevice *devp; |
| 538 | int node, ret; |
| 539 | |
| 540 | node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "fsl,imx8ulp-mu"); |
| 541 | |
| 542 | ret = uclass_get_device_by_of_offset(UCLASS_MISC, node, &devp); |
| 543 | if (ret) { |
| 544 | printf("could not get S400 mu %d\n", ret); |
| 545 | return ret; |
| 546 | } |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
Ye Li | 6ee435eb | 2021-08-07 16:00:50 +0800 | [diff] [blame] | 551 | #if defined(CONFIG_SPL_BUILD) |
| 552 | __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 553 | { |
| 554 | debug("image entry point: 0x%lx\n", spl_image->entry_point); |
| 555 | |
| 556 | set_core0_reset_vector((u32)spl_image->entry_point); |
Ye Li | 6dd4302 | 2021-08-07 16:00:48 +0800 | [diff] [blame] | 557 | |
| 558 | /* Enable the 512KB cache */ |
| 559 | setbits_le32(SIM1_BASE_ADDR + 0x30, (0x1 << 4)); |
| 560 | |
| 561 | /* reset core */ |
| 562 | setbits_le32(SIM1_BASE_ADDR + 0x30, (0x1 << 16)); |
| 563 | |
| 564 | while (1) |
| 565 | ; |
| 566 | } |
| 567 | #endif |
Peng Fan | fa6ae05 | 2021-08-07 16:01:03 +0800 | [diff] [blame] | 568 | |
| 569 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) |
| 570 | { |
| 571 | memset(mac, 0, 6); |
| 572 | } |
Ye Li | 479fd4a | 2021-08-07 16:01:08 +0800 | [diff] [blame] | 573 | |
| 574 | int (*card_emmc_is_boot_part_en)(void) = (void *)0x67cc; |
| 575 | u32 spl_arch_boot_image_offset(u32 image_offset, u32 rom_bt_dev) |
| 576 | { |
| 577 | /* Hard code for eMMC image_offset on 8ULP ROM, need fix by ROM, temp workaround */ |
| 578 | if (((rom_bt_dev >> 16) & 0xff) == BT_DEV_TYPE_MMC && card_emmc_is_boot_part_en()) |
| 579 | image_offset = 0; |
| 580 | |
| 581 | return image_offset; |
| 582 | } |