Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2022 NXP |
| 4 | * |
| 5 | * Peng Fan <peng.fan@nxp.com> |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <cpu_func.h> |
| 10 | #include <init.h> |
| 11 | #include <log.h> |
| 12 | #include <asm/arch/imx-regs.h> |
| 13 | #include <asm/global_data.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <asm/arch/clock.h> |
Peng Fan | 6d92996 | 2022-07-26 16:41:03 +0800 | [diff] [blame] | 16 | #include <asm/arch/ccm_regs.h> |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 17 | #include <asm/arch/sys_proto.h> |
Ye Li | 6218592 | 2022-07-26 16:40:54 +0800 | [diff] [blame] | 18 | #include <asm/arch/trdc.h> |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 19 | #include <asm/mach-imx/boot_mode.h> |
| 20 | #include <asm/mach-imx/syscounter.h> |
| 21 | #include <asm/armv8/mmu.h> |
| 22 | #include <dm/uclass.h> |
| 23 | #include <env.h> |
| 24 | #include <env_internal.h> |
| 25 | #include <errno.h> |
| 26 | #include <fdt_support.h> |
| 27 | #include <linux/bitops.h> |
| 28 | #include <asm/setup.h> |
| 29 | #include <asm/bootm.h> |
| 30 | #include <asm/arch-imx/cpu.h> |
Peng Fan | 3700c47 | 2022-07-26 16:40:56 +0800 | [diff] [blame] | 31 | #include <asm/mach-imx/s400_api.h> |
Peng Fan | 6556379 | 2022-07-26 16:41:02 +0800 | [diff] [blame] | 32 | #include <linux/delay.h> |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 33 | |
| 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
Peng Fan | 5de0fc0 | 2022-07-26 16:40:48 +0800 | [diff] [blame] | 36 | struct rom_api *g_rom_api = (struct rom_api *)0x1980; |
| 37 | |
| 38 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 39 | __weak int board_mmc_get_env_dev(int devno) |
| 40 | { |
| 41 | return devno; } |
| 42 | |
| 43 | int mmc_get_env_dev(void) |
| 44 | { |
| 45 | volatile gd_t *pgd = gd; |
| 46 | int ret; |
| 47 | u32 boot; |
| 48 | u16 boot_type; |
| 49 | u8 boot_instance; |
| 50 | |
| 51 | ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot, |
| 52 | ((uintptr_t)&boot) ^ QUERY_BT_DEV); |
| 53 | set_gd(pgd); |
| 54 | |
| 55 | if (ret != ROM_API_OKAY) { |
| 56 | puts("ROMAPI: failure at query_boot_info\n"); |
| 57 | return CONFIG_SYS_MMC_ENV_DEV; |
| 58 | } |
| 59 | |
| 60 | boot_type = boot >> 16; |
| 61 | boot_instance = (boot >> 8) & 0xff; |
| 62 | |
| 63 | debug("boot_type %d, instance %d\n", boot_type, boot_instance); |
| 64 | |
| 65 | /* If not boot from sd/mmc, use default value */ |
| 66 | if (boot_type != BOOT_TYPE_SD && boot_type != BOOT_TYPE_MMC) |
| 67 | return env_get_ulong("mmcdev", 10, CONFIG_SYS_MMC_ENV_DEV); |
| 68 | |
| 69 | return board_mmc_get_env_dev(boot_instance); |
| 70 | } |
| 71 | #endif |
| 72 | |
Peng Fan | 3700c47 | 2022-07-26 16:40:56 +0800 | [diff] [blame] | 73 | static void set_cpu_info(struct sentinel_get_info_data *info) |
| 74 | { |
| 75 | gd->arch.soc_rev = info->soc; |
| 76 | gd->arch.lifecycle = info->lc; |
| 77 | memcpy((void *)&gd->arch.uid, &info->uid, 4 * sizeof(u32)); |
| 78 | } |
| 79 | |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 80 | u32 get_cpu_rev(void) |
| 81 | { |
Peng Fan | 3700c47 | 2022-07-26 16:40:56 +0800 | [diff] [blame] | 82 | u32 rev = (gd->arch.soc_rev >> 24) - 0xa0; |
| 83 | |
| 84 | return (MXC_CPU_IMX93 << 12) | (CHIP_REV_1_0 + rev); |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 85 | } |
| 86 | |
Ye Li | 9e19ff9 | 2022-07-26 16:40:47 +0800 | [diff] [blame] | 87 | #define UNLOCK_WORD 0xD928C520 /* unlock word */ |
| 88 | #define REFRESH_WORD 0xB480A602 /* refresh word */ |
| 89 | |
| 90 | static void disable_wdog(void __iomem *wdog_base) |
| 91 | { |
| 92 | u32 val_cs = readl(wdog_base + 0x00); |
| 93 | |
| 94 | if (!(val_cs & 0x80)) |
| 95 | return; |
| 96 | |
| 97 | /* default is 32bits cmd */ |
| 98 | writel(REFRESH_WORD, (wdog_base + 0x04)); /* Refresh the CNT */ |
| 99 | |
| 100 | if (!(val_cs & 0x800)) { |
| 101 | writel(UNLOCK_WORD, (wdog_base + 0x04)); |
| 102 | while (!(readl(wdog_base + 0x00) & 0x800)) |
| 103 | ; |
| 104 | } |
| 105 | writel(0x0, (wdog_base + 0x0C)); /* Set WIN to 0 */ |
| 106 | writel(0x400, (wdog_base + 0x08)); /* Set timeout to default 0x400 */ |
| 107 | writel(0x2120, (wdog_base + 0x00)); /* Disable it and set update */ |
| 108 | |
| 109 | while (!(readl(wdog_base + 0x00) & 0x400)) |
| 110 | ; |
| 111 | } |
| 112 | |
| 113 | void init_wdog(void) |
| 114 | { |
| 115 | u32 src_val; |
| 116 | |
| 117 | disable_wdog((void __iomem *)WDG3_BASE_ADDR); |
| 118 | disable_wdog((void __iomem *)WDG4_BASE_ADDR); |
| 119 | disable_wdog((void __iomem *)WDG5_BASE_ADDR); |
| 120 | |
| 121 | src_val = readl(0x54460018); /* reset mask */ |
| 122 | src_val &= ~0x1c; |
| 123 | writel(src_val, 0x54460018); |
| 124 | } |
| 125 | |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 126 | static struct mm_region imx93_mem_map[] = { |
| 127 | { |
| 128 | /* ROM */ |
| 129 | .virt = 0x0UL, |
| 130 | .phys = 0x0UL, |
| 131 | .size = 0x100000UL, |
| 132 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 133 | PTE_BLOCK_OUTER_SHARE |
| 134 | }, { |
Peng Fan | 313af25 | 2022-07-26 16:41:04 +0800 | [diff] [blame] | 135 | /* TCM */ |
| 136 | .virt = 0x201c0000UL, |
| 137 | .phys = 0x201c0000UL, |
| 138 | .size = 0x80000UL, |
| 139 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 140 | PTE_BLOCK_NON_SHARE | |
| 141 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 142 | }, { |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 143 | /* OCRAM */ |
| 144 | .virt = 0x20480000UL, |
| 145 | .phys = 0x20480000UL, |
| 146 | .size = 0xA0000UL, |
| 147 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 148 | PTE_BLOCK_OUTER_SHARE |
| 149 | }, { |
| 150 | /* AIPS */ |
| 151 | .virt = 0x40000000UL, |
| 152 | .phys = 0x40000000UL, |
| 153 | .size = 0x40000000UL, |
| 154 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 155 | PTE_BLOCK_NON_SHARE | |
| 156 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 157 | }, { |
| 158 | /* Flexible Serial Peripheral Interface */ |
| 159 | .virt = 0x28000000UL, |
| 160 | .phys = 0x28000000UL, |
| 161 | .size = 0x30000000UL, |
| 162 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 163 | PTE_BLOCK_NON_SHARE | |
| 164 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 165 | }, { |
| 166 | /* DRAM1 */ |
| 167 | .virt = 0x80000000UL, |
| 168 | .phys = 0x80000000UL, |
| 169 | .size = PHYS_SDRAM_SIZE, |
| 170 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 171 | PTE_BLOCK_OUTER_SHARE |
| 172 | }, { |
| 173 | /* empty entrie to split table entry 5 if needed when TEEs are used */ |
| 174 | 0, |
| 175 | }, { |
| 176 | /* List terminator */ |
| 177 | 0, |
| 178 | } |
| 179 | }; |
| 180 | |
| 181 | struct mm_region *mem_map = imx93_mem_map; |
| 182 | |
Peng Fan | 1ed3c0a | 2023-04-28 12:08:20 +0800 | [diff] [blame^] | 183 | static unsigned int imx9_find_dram_entry_in_mem_map(void) |
| 184 | { |
| 185 | int i; |
| 186 | |
| 187 | for (i = 0; i < ARRAY_SIZE(imx93_mem_map); i++) |
| 188 | if (imx93_mem_map[i].phys == CFG_SYS_SDRAM_BASE) |
| 189 | return i; |
| 190 | |
| 191 | hang(); /* Entry not found, this must never happen. */ |
| 192 | } |
| 193 | |
| 194 | void enable_caches(void) |
| 195 | { |
| 196 | /* If OPTEE runs, remove OPTEE memory from MMU table to avoid speculative prefetch |
| 197 | * If OPTEE does not run, still update the MMU table according to dram banks structure |
| 198 | * to set correct dram size from board_phys_sdram_size |
| 199 | */ |
| 200 | int i = 0; |
| 201 | /* |
| 202 | * please make sure that entry initial value matches |
| 203 | * imx93_mem_map for DRAM1 |
| 204 | */ |
| 205 | int entry = imx9_find_dram_entry_in_mem_map(); |
| 206 | u64 attrs = imx93_mem_map[entry].attrs; |
| 207 | |
| 208 | while (i < CONFIG_NR_DRAM_BANKS && |
| 209 | entry < ARRAY_SIZE(imx93_mem_map)) { |
| 210 | if (gd->bd->bi_dram[i].start == 0) |
| 211 | break; |
| 212 | imx93_mem_map[entry].phys = gd->bd->bi_dram[i].start; |
| 213 | imx93_mem_map[entry].virt = gd->bd->bi_dram[i].start; |
| 214 | imx93_mem_map[entry].size = gd->bd->bi_dram[i].size; |
| 215 | imx93_mem_map[entry].attrs = attrs; |
| 216 | debug("Added memory mapping (%d): %llx %llx\n", entry, |
| 217 | imx93_mem_map[entry].phys, imx93_mem_map[entry].size); |
| 218 | i++; entry++; |
| 219 | } |
| 220 | |
| 221 | icache_enable(); |
| 222 | dcache_enable(); |
| 223 | } |
| 224 | |
| 225 | __weak int board_phys_sdram_size(phys_size_t *size) |
| 226 | { |
| 227 | if (!size) |
| 228 | return -EINVAL; |
| 229 | |
| 230 | *size = PHYS_SDRAM_SIZE; |
| 231 | |
| 232 | #ifdef PHYS_SDRAM_2_SIZE |
| 233 | *size += PHYS_SDRAM_2_SIZE; |
| 234 | #endif |
| 235 | return 0; |
| 236 | } |
| 237 | |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 238 | int dram_init(void) |
| 239 | { |
Peng Fan | 1ed3c0a | 2023-04-28 12:08:20 +0800 | [diff] [blame^] | 240 | phys_size_t sdram_size; |
| 241 | int ret; |
| 242 | |
| 243 | ret = board_phys_sdram_size(&sdram_size); |
| 244 | if (ret) |
| 245 | return ret; |
| 246 | |
| 247 | /* rom_pointer[1] contains the size of TEE occupies */ |
| 248 | if (rom_pointer[1]) |
| 249 | gd->ram_size = sdram_size - rom_pointer[1]; |
| 250 | else |
| 251 | gd->ram_size = sdram_size; |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | int dram_init_banksize(void) |
| 257 | { |
| 258 | int bank = 0; |
| 259 | int ret; |
| 260 | phys_size_t sdram_size; |
| 261 | phys_size_t sdram_b1_size, sdram_b2_size; |
| 262 | |
| 263 | ret = board_phys_sdram_size(&sdram_size); |
| 264 | if (ret) |
| 265 | return ret; |
| 266 | |
| 267 | /* Bank 1 can't cross over 4GB space */ |
| 268 | if (sdram_size > 0x80000000) { |
| 269 | sdram_b1_size = 0x80000000; |
| 270 | sdram_b2_size = sdram_size - 0x80000000; |
| 271 | } else { |
| 272 | sdram_b1_size = sdram_size; |
| 273 | sdram_b2_size = 0; |
| 274 | } |
| 275 | |
| 276 | gd->bd->bi_dram[bank].start = PHYS_SDRAM; |
| 277 | if (rom_pointer[1]) { |
| 278 | phys_addr_t optee_start = (phys_addr_t)rom_pointer[0]; |
| 279 | phys_size_t optee_size = (size_t)rom_pointer[1]; |
| 280 | |
| 281 | gd->bd->bi_dram[bank].size = optee_start - gd->bd->bi_dram[bank].start; |
| 282 | if ((optee_start + optee_size) < (PHYS_SDRAM + sdram_b1_size)) { |
| 283 | if (++bank >= CONFIG_NR_DRAM_BANKS) { |
| 284 | puts("CONFIG_NR_DRAM_BANKS is not enough\n"); |
| 285 | return -1; |
| 286 | } |
| 287 | |
| 288 | gd->bd->bi_dram[bank].start = optee_start + optee_size; |
| 289 | gd->bd->bi_dram[bank].size = PHYS_SDRAM + |
| 290 | sdram_b1_size - gd->bd->bi_dram[bank].start; |
| 291 | } |
| 292 | } else { |
| 293 | gd->bd->bi_dram[bank].size = sdram_b1_size; |
| 294 | } |
| 295 | |
| 296 | if (sdram_b2_size) { |
| 297 | if (++bank >= CONFIG_NR_DRAM_BANKS) { |
| 298 | puts("CONFIG_NR_DRAM_BANKS is not enough for SDRAM_2\n"); |
| 299 | return -1; |
| 300 | } |
| 301 | gd->bd->bi_dram[bank].start = 0x100000000UL; |
| 302 | gd->bd->bi_dram[bank].size = sdram_b2_size; |
| 303 | } |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 304 | |
| 305 | return 0; |
| 306 | } |
| 307 | |
Peng Fan | 1ed3c0a | 2023-04-28 12:08:20 +0800 | [diff] [blame^] | 308 | phys_size_t get_effective_memsize(void) |
| 309 | { |
| 310 | int ret; |
| 311 | phys_size_t sdram_size; |
| 312 | phys_size_t sdram_b1_size; |
| 313 | |
| 314 | ret = board_phys_sdram_size(&sdram_size); |
| 315 | if (!ret) { |
| 316 | /* Bank 1 can't cross over 4GB space */ |
| 317 | if (sdram_size > 0x80000000) |
| 318 | sdram_b1_size = 0x80000000; |
| 319 | else |
| 320 | sdram_b1_size = sdram_size; |
| 321 | |
| 322 | if (rom_pointer[1]) { |
| 323 | /* We will relocate u-boot to top of dram1. TEE position has two cases: |
| 324 | * 1. At the top of dram1, Then return the size removed optee size. |
| 325 | * 2. In the middle of dram1, return the size of dram1. |
| 326 | */ |
| 327 | if ((rom_pointer[0] + rom_pointer[1]) == (PHYS_SDRAM + sdram_b1_size)) |
| 328 | return ((phys_addr_t)rom_pointer[0] - PHYS_SDRAM); |
| 329 | } |
| 330 | |
| 331 | return sdram_b1_size; |
| 332 | } else { |
| 333 | return PHYS_SDRAM_SIZE; |
| 334 | } |
| 335 | } |
| 336 | |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 337 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) |
| 338 | { |
| 339 | mac[0] = 0x1; |
| 340 | mac[1] = 0x2; |
| 341 | mac[2] = 0x3; |
| 342 | mac[3] = 0x4; |
| 343 | mac[4] = 0x5; |
| 344 | mac[5] = 0x6; |
| 345 | } |
| 346 | |
| 347 | int print_cpuinfo(void) |
| 348 | { |
| 349 | u32 cpurev; |
| 350 | |
| 351 | cpurev = get_cpu_rev(); |
| 352 | |
| 353 | printf("CPU: i.MX93 rev%d.%d\n", (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0); |
| 354 | |
| 355 | return 0; |
| 356 | } |
| 357 | |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 358 | int ft_system_setup(void *blob, struct bd_info *bd) |
| 359 | { |
| 360 | return 0; |
| 361 | } |
Peng Fan | 3700c47 | 2022-07-26 16:40:56 +0800 | [diff] [blame] | 362 | |
| 363 | #if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG) |
| 364 | void get_board_serial(struct tag_serialnr *serialnr) |
| 365 | { |
| 366 | printf("UID: 0x%x 0x%x 0x%x 0x%x\n", |
| 367 | gd->arch.uid[0], gd->arch.uid[1], gd->arch.uid[2], gd->arch.uid[3]); |
| 368 | |
| 369 | serialnr->low = gd->arch.uid[0]; |
| 370 | serialnr->high = gd->arch.uid[3]; |
| 371 | } |
| 372 | #endif |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 373 | |
| 374 | int arch_cpu_init(void) |
| 375 | { |
Ye Li | 9e19ff9 | 2022-07-26 16:40:47 +0800 | [diff] [blame] | 376 | if (IS_ENABLED(CONFIG_SPL_BUILD)) { |
| 377 | /* Disable wdog */ |
| 378 | init_wdog(); |
| 379 | |
Peng Fan | 28b5cb5 | 2022-07-26 16:40:43 +0800 | [diff] [blame] | 380 | clock_init(); |
Ye Li | 6218592 | 2022-07-26 16:40:54 +0800 | [diff] [blame] | 381 | |
| 382 | trdc_early_init(); |
Ye Li | 9e19ff9 | 2022-07-26 16:40:47 +0800 | [diff] [blame] | 383 | } |
Peng Fan | 28b5cb5 | 2022-07-26 16:40:43 +0800 | [diff] [blame] | 384 | |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 385 | return 0; |
| 386 | } |
Peng Fan | 3700c47 | 2022-07-26 16:40:56 +0800 | [diff] [blame] | 387 | |
| 388 | int imx9_probe_mu(void *ctx, struct event *event) |
| 389 | { |
| 390 | struct udevice *devp; |
| 391 | int node, ret; |
| 392 | u32 res; |
| 393 | struct sentinel_get_info_data info; |
| 394 | |
| 395 | node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "fsl,imx93-mu-s4"); |
| 396 | |
| 397 | ret = uclass_get_device_by_of_offset(UCLASS_MISC, node, &devp); |
| 398 | if (ret) |
| 399 | return ret; |
| 400 | |
| 401 | if (gd->flags & GD_FLG_RELOC) |
| 402 | return 0; |
| 403 | |
| 404 | ret = ahab_get_info(&info, &res); |
| 405 | if (ret) |
| 406 | return ret; |
| 407 | |
| 408 | set_cpu_info(&info); |
| 409 | |
| 410 | return 0; |
| 411 | } |
Simon Glass | 9307401 | 2023-05-04 16:50:45 -0600 | [diff] [blame] | 412 | EVENT_SPY(EVT_DM_POST_INIT_F, imx9_probe_mu); |
Jian Li | acf41a3 | 2022-07-26 16:40:46 +0800 | [diff] [blame] | 413 | |
| 414 | int timer_init(void) |
| 415 | { |
| 416 | #ifdef CONFIG_SPL_BUILD |
| 417 | struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR; |
| 418 | unsigned long freq = readl(&sctr->cntfid0); |
| 419 | |
| 420 | /* Update with accurate clock frequency */ |
| 421 | asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory"); |
| 422 | |
| 423 | clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1, |
| 424 | SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG); |
| 425 | #endif |
| 426 | |
| 427 | gd->arch.tbl = 0; |
| 428 | gd->arch.tbu = 0; |
| 429 | |
| 430 | return 0; |
| 431 | } |
Peng Fan | 6556379 | 2022-07-26 16:41:02 +0800 | [diff] [blame] | 432 | |
Ye Li | 8e8687c | 2022-07-26 16:41:05 +0800 | [diff] [blame] | 433 | enum env_location env_get_location(enum env_operation op, int prio) |
| 434 | { |
| 435 | enum boot_device dev = get_boot_device(); |
| 436 | enum env_location env_loc = ENVL_UNKNOWN; |
| 437 | |
| 438 | if (prio) |
| 439 | return env_loc; |
| 440 | |
| 441 | switch (dev) { |
| 442 | #if defined(CONFIG_ENV_IS_IN_SPI_FLASH) |
| 443 | case QSPI_BOOT: |
| 444 | env_loc = ENVL_SPI_FLASH; |
| 445 | break; |
| 446 | #endif |
| 447 | #if defined(CONFIG_ENV_IS_IN_MMC) |
| 448 | case SD1_BOOT: |
| 449 | case SD2_BOOT: |
| 450 | case SD3_BOOT: |
| 451 | case MMC1_BOOT: |
| 452 | case MMC2_BOOT: |
| 453 | case MMC3_BOOT: |
| 454 | env_loc = ENVL_MMC; |
| 455 | break; |
| 456 | #endif |
| 457 | default: |
| 458 | #if defined(CONFIG_ENV_IS_NOWHERE) |
| 459 | env_loc = ENVL_NOWHERE; |
| 460 | #endif |
| 461 | break; |
| 462 | } |
| 463 | |
| 464 | return env_loc; |
| 465 | } |
| 466 | |
Peng Fan | 6556379 | 2022-07-26 16:41:02 +0800 | [diff] [blame] | 467 | static int mix_power_init(enum mix_power_domain pd) |
| 468 | { |
| 469 | enum src_mix_slice_id mix_id; |
| 470 | enum src_mem_slice_id mem_id; |
| 471 | struct src_mix_slice_regs *mix_regs; |
| 472 | struct src_mem_slice_regs *mem_regs; |
| 473 | struct src_general_regs *global_regs; |
| 474 | u32 scr, val; |
| 475 | |
| 476 | switch (pd) { |
| 477 | case MIX_PD_MEDIAMIX: |
| 478 | mix_id = SRC_MIX_MEDIA; |
| 479 | mem_id = SRC_MEM_MEDIA; |
| 480 | scr = BIT(5); |
| 481 | |
| 482 | /* Enable S400 handshake */ |
| 483 | struct blk_ctrl_s_aonmix_regs *s_regs = |
| 484 | (struct blk_ctrl_s_aonmix_regs *)BLK_CTRL_S_ANOMIX_BASE_ADDR; |
| 485 | |
| 486 | setbits_le32(&s_regs->lp_handshake[0], BIT(13)); |
| 487 | break; |
| 488 | case MIX_PD_MLMIX: |
| 489 | mix_id = SRC_MIX_ML; |
| 490 | mem_id = SRC_MEM_ML; |
| 491 | scr = BIT(4); |
| 492 | break; |
| 493 | case MIX_PD_DDRMIX: |
| 494 | mix_id = SRC_MIX_DDRMIX; |
| 495 | mem_id = SRC_MEM_DDRMIX; |
| 496 | scr = BIT(6); |
| 497 | break; |
| 498 | default: |
| 499 | return -EINVAL; |
| 500 | } |
| 501 | |
| 502 | mix_regs = (struct src_mix_slice_regs *)(ulong)(SRC_IPS_BASE_ADDR + 0x400 * (mix_id + 1)); |
| 503 | mem_regs = |
| 504 | (struct src_mem_slice_regs *)(ulong)(SRC_IPS_BASE_ADDR + 0x3800 + 0x400 * mem_id); |
| 505 | global_regs = (struct src_general_regs *)(ulong)SRC_GLOBAL_RBASE; |
| 506 | |
| 507 | /* Allow NS to set it */ |
| 508 | setbits_le32(&mix_regs->authen_ctrl, BIT(9)); |
| 509 | |
| 510 | clrsetbits_le32(&mix_regs->psw_ack_ctrl[0], BIT(28), BIT(29)); |
| 511 | |
| 512 | /* mix reset will be held until boot core write this bit to 1 */ |
| 513 | setbits_le32(&global_regs->scr, scr); |
| 514 | |
| 515 | /* Enable mem in Low power auto sequence */ |
| 516 | setbits_le32(&mem_regs->mem_ctrl, BIT(2)); |
| 517 | |
| 518 | /* Set the power down state */ |
| 519 | val = readl(&mix_regs->func_stat); |
| 520 | if (val & SRC_MIX_SLICE_FUNC_STAT_PSW_STAT) { |
| 521 | /* The mix is default power off, power down it to make PDN_SFT bit |
| 522 | * aligned with FUNC STAT |
| 523 | */ |
| 524 | setbits_le32(&mix_regs->slice_sw_ctrl, BIT(31)); |
| 525 | val = readl(&mix_regs->func_stat); |
| 526 | |
| 527 | /* Since PSW_STAT is 1, can't be used for power off status (SW_CTRL BIT31 set)) */ |
| 528 | /* Check the MEM STAT change to ensure SSAR is completed */ |
| 529 | while (!(val & SRC_MIX_SLICE_FUNC_STAT_MEM_STAT)) |
| 530 | val = readl(&mix_regs->func_stat); |
| 531 | |
| 532 | /* wait few ipg clock cycles to ensure FSM done and power off status is correct */ |
| 533 | /* About 5 cycles at 24Mhz, 1us is enough */ |
| 534 | udelay(1); |
| 535 | } else { |
| 536 | /* The mix is default power on, Do mix power cycle */ |
| 537 | setbits_le32(&mix_regs->slice_sw_ctrl, BIT(31)); |
| 538 | val = readl(&mix_regs->func_stat); |
| 539 | while (!(val & SRC_MIX_SLICE_FUNC_STAT_PSW_STAT)) |
| 540 | val = readl(&mix_regs->func_stat); |
| 541 | } |
| 542 | |
| 543 | /* power on */ |
| 544 | clrbits_le32(&mix_regs->slice_sw_ctrl, BIT(31)); |
| 545 | val = readl(&mix_regs->func_stat); |
| 546 | while (val & SRC_MIX_SLICE_FUNC_STAT_ISO_STAT) |
| 547 | val = readl(&mix_regs->func_stat); |
| 548 | |
| 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | void disable_isolation(void) |
| 553 | { |
| 554 | struct src_general_regs *global_regs = (struct src_general_regs *)(ulong)SRC_GLOBAL_RBASE; |
| 555 | /* clear isolation for usbphy, dsi, csi*/ |
| 556 | writel(0x0, &global_regs->sp_iso_ctrl); |
| 557 | } |
| 558 | |
| 559 | void soc_power_init(void) |
| 560 | { |
| 561 | mix_power_init(MIX_PD_MEDIAMIX); |
| 562 | mix_power_init(MIX_PD_MLMIX); |
| 563 | |
| 564 | disable_isolation(); |
| 565 | } |
Peng Fan | 6d92996 | 2022-07-26 16:41:03 +0800 | [diff] [blame] | 566 | |
Peng Fan | 313af25 | 2022-07-26 16:41:04 +0800 | [diff] [blame] | 567 | bool m33_is_rom_kicked(void) |
Peng Fan | 6d92996 | 2022-07-26 16:41:03 +0800 | [diff] [blame] | 568 | { |
| 569 | struct blk_ctrl_s_aonmix_regs *s_regs = |
| 570 | (struct blk_ctrl_s_aonmix_regs *)BLK_CTRL_S_ANOMIX_BASE_ADDR; |
| 571 | |
| 572 | if (!(readl(&s_regs->m33_cfg) & BIT(2))) |
| 573 | return true; |
| 574 | |
| 575 | return false; |
| 576 | } |
| 577 | |
| 578 | int m33_prepare(void) |
| 579 | { |
| 580 | struct src_mix_slice_regs *mix_regs = |
| 581 | (struct src_mix_slice_regs *)(ulong)(SRC_IPS_BASE_ADDR + 0x400 * (SRC_MIX_CM33 + 1)); |
| 582 | struct src_general_regs *global_regs = |
| 583 | (struct src_general_regs *)(ulong)SRC_GLOBAL_RBASE; |
| 584 | struct blk_ctrl_s_aonmix_regs *s_regs = |
| 585 | (struct blk_ctrl_s_aonmix_regs *)BLK_CTRL_S_ANOMIX_BASE_ADDR; |
| 586 | u32 val; |
| 587 | |
| 588 | if (m33_is_rom_kicked()) |
| 589 | return -EPERM; |
| 590 | |
| 591 | /* Release reset of M33 */ |
| 592 | setbits_le32(&global_regs->scr, BIT(0)); |
| 593 | |
| 594 | /* Check the reset released in M33 MIX func stat */ |
| 595 | val = readl(&mix_regs->func_stat); |
| 596 | while (!(val & SRC_MIX_SLICE_FUNC_STAT_RST_STAT)) |
| 597 | val = readl(&mix_regs->func_stat); |
| 598 | |
| 599 | /* Release Sentinel TROUT */ |
| 600 | ahab_release_m33_trout(); |
| 601 | |
| 602 | /* Mask WDOG1 IRQ from A55, we use it for M33 reset */ |
| 603 | setbits_le32(&s_regs->ca55_irq_mask[1], BIT(6)); |
| 604 | |
| 605 | /* Turn on WDOG1 clock */ |
| 606 | ccm_lpcg_on(CCGR_WDG1, 1); |
| 607 | |
| 608 | /* Set sentinel LP handshake for M33 reset */ |
| 609 | setbits_le32(&s_regs->lp_handshake[0], BIT(6)); |
| 610 | |
| 611 | /* Clear M33 TCM for ECC */ |
| 612 | memset((void *)(ulong)0x201e0000, 0, 0x40000); |
| 613 | |
| 614 | return 0; |
| 615 | } |