Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Gaurav Jain | db4dd6a | 2022-03-24 11:50:33 +0530 | [diff] [blame] | 3 | * Copyright 2018, 2021 NXP |
Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <clk.h> |
Anatolij Gustschin | 9b39be9 | 2018-10-18 14:28:24 +0200 | [diff] [blame] | 8 | #include <cpu.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 10 | #include <dm.h> |
Simon Glass | fc55736 | 2022-03-04 08:43:05 -0700 | [diff] [blame] | 11 | #include <event.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 14 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 16 | #include <dm/device-internal.h> |
| 17 | #include <dm/lists.h> |
| 18 | #include <dm/uclass.h> |
| 19 | #include <errno.h> |
Peng Fan | 617fc29 | 2020-05-05 20:28:41 +0800 | [diff] [blame] | 20 | #include <spl.h> |
Peng Fan | 48f9c4e | 2019-04-26 01:44:27 +0000 | [diff] [blame] | 21 | #include <thermal.h> |
Peng Fan | 2e0644a | 2023-04-28 12:08:09 +0800 | [diff] [blame] | 22 | #include <firmware/imx/sci/sci.h> |
Peng Fan | 29c9dd3 | 2018-10-18 14:28:19 +0200 | [diff] [blame] | 23 | #include <asm/arch/sys_proto.h> |
Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 24 | #include <asm/arch-imx/cpu.h> |
| 25 | #include <asm/armv8/cpu.h> |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 26 | #include <asm/armv8/mmu.h> |
Peng Fan | d2aaf0c | 2020-05-05 20:28:39 +0800 | [diff] [blame] | 27 | #include <asm/setup.h> |
Peng Fan | 29c9dd3 | 2018-10-18 14:28:19 +0200 | [diff] [blame] | 28 | #include <asm/mach-imx/boot_mode.h> |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 29 | #include <power-domain.h> |
| 30 | #include <elf.h> |
Ye Li | c3169bd | 2020-05-05 20:28:42 +0800 | [diff] [blame] | 31 | #include <spl.h> |
Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 35 | #define BT_PASSOVER_TAG 0x504F |
| 36 | struct pass_over_info_t *get_pass_over_info(void) |
| 37 | { |
| 38 | struct pass_over_info_t *p = |
| 39 | (struct pass_over_info_t *)PASS_OVER_INFO_ADDR; |
| 40 | |
| 41 | if (p->barker != BT_PASSOVER_TAG || |
| 42 | p->len != sizeof(struct pass_over_info_t)) |
| 43 | return NULL; |
| 44 | |
| 45 | return p; |
| 46 | } |
| 47 | |
Igor Opaniuk | ab5ffef | 2024-01-31 13:49:26 +0100 | [diff] [blame] | 48 | static char *get_reset_cause(void) |
| 49 | { |
| 50 | sc_pm_reset_reason_t reason; |
| 51 | |
| 52 | if (sc_pm_reset_reason(-1, &reason) != SC_ERR_NONE) |
| 53 | return "Unknown reset"; |
| 54 | |
| 55 | switch (reason) { |
| 56 | case SC_PM_RESET_REASON_POR: |
| 57 | return "POR"; |
| 58 | case SC_PM_RESET_REASON_JTAG: |
| 59 | return "JTAG reset "; |
| 60 | case SC_PM_RESET_REASON_SW: |
| 61 | return "Software reset"; |
| 62 | case SC_PM_RESET_REASON_WDOG: |
| 63 | return "Watchdog reset"; |
| 64 | case SC_PM_RESET_REASON_LOCKUP: |
| 65 | return "SCU lockup reset"; |
| 66 | case SC_PM_RESET_REASON_SNVS: |
| 67 | return "SNVS reset"; |
| 68 | case SC_PM_RESET_REASON_TEMP: |
| 69 | return "Temp panic reset"; |
| 70 | case SC_PM_RESET_REASON_MSI: |
| 71 | return "MSI reset"; |
| 72 | case SC_PM_RESET_REASON_UECC: |
| 73 | return "ECC reset"; |
| 74 | case SC_PM_RESET_REASON_SCFW_WDOG: |
| 75 | return "SCFW watchdog reset"; |
| 76 | case SC_PM_RESET_REASON_ROM_WDOG: |
| 77 | return "SCU ROM watchdog reset"; |
| 78 | case SC_PM_RESET_REASON_SECO: |
| 79 | return "SECO reset"; |
| 80 | case SC_PM_RESET_REASON_SCFW_FAULT: |
| 81 | return "SCFW fault reset"; |
| 82 | default: |
| 83 | return "Unknown reset"; |
| 84 | } |
| 85 | } |
| 86 | |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 87 | int arch_cpu_init(void) |
| 88 | { |
Peng Fan | 617fc29 | 2020-05-05 20:28:41 +0800 | [diff] [blame] | 89 | #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_RECOVER_DATA_SECTION) |
| 90 | spl_save_restore_data(); |
| 91 | #endif |
| 92 | |
Peng Fan | 0bcec7f | 2019-01-18 08:58:38 +0000 | [diff] [blame] | 93 | #ifdef CONFIG_SPL_BUILD |
| 94 | struct pass_over_info_t *pass_over; |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 95 | |
Peng Fan | 0bcec7f | 2019-01-18 08:58:38 +0000 | [diff] [blame] | 96 | if (is_soc_rev(CHIP_REV_A)) { |
| 97 | pass_over = get_pass_over_info(); |
| 98 | if (pass_over && pass_over->g_ap_mu == 0) { |
| 99 | /* |
| 100 | * When ap_mu is 0, means the U-Boot booted |
| 101 | * from first container |
| 102 | */ |
| 103 | sc_misc_boot_status(-1, SC_MISC_BOOT_STATUS_SUCCESS); |
| 104 | } |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 105 | } |
Peng Fan | 0bcec7f | 2019-01-18 08:58:38 +0000 | [diff] [blame] | 106 | #endif |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
Simon Glass | b8357c1 | 2023-08-21 21:16:56 -0600 | [diff] [blame] | 111 | static int imx8_init_mu(void) |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 112 | { |
| 113 | struct udevice *devp; |
| 114 | int node, ret; |
| 115 | |
| 116 | node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "fsl,imx8-mu"); |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 117 | |
Ye Li | f2ea6f0 | 2019-08-26 08:11:42 +0000 | [diff] [blame] | 118 | ret = uclass_get_device_by_of_offset(UCLASS_MISC, node, &devp); |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 119 | if (ret) { |
Ye Li | f2ea6f0 | 2019-08-26 08:11:42 +0000 | [diff] [blame] | 120 | printf("could not get scu %d\n", ret); |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 121 | return ret; |
| 122 | } |
| 123 | |
Peng Fan | ee380c5 | 2019-08-26 08:11:49 +0000 | [diff] [blame] | 124 | if (is_imx8qm()) { |
| 125 | ret = sc_pm_set_resource_power_mode(-1, SC_R_SMMU, |
| 126 | SC_PM_PW_MODE_ON); |
| 127 | if (ret) |
| 128 | return ret; |
| 129 | } |
| 130 | |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 131 | return 0; |
| 132 | } |
Simon Glass | b8357c1 | 2023-08-21 21:16:56 -0600 | [diff] [blame] | 133 | EVENT_SPY_SIMPLE(EVT_DM_POST_INIT_F, imx8_init_mu); |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 134 | |
Gaurav Jain | db4dd6a | 2022-03-24 11:50:33 +0530 | [diff] [blame] | 135 | #if defined(CONFIG_ARCH_MISC_INIT) |
| 136 | int arch_misc_init(void) |
| 137 | { |
| 138 | if (IS_ENABLED(CONFIG_FSL_CAAM)) { |
| 139 | struct udevice *dev; |
| 140 | int ret; |
| 141 | |
| 142 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev); |
| 143 | if (ret) |
Ye Li | ec34689 | 2022-05-11 13:56:20 +0530 | [diff] [blame] | 144 | printf("Failed to initialize caam_jr: %d\n", ret); |
Gaurav Jain | db4dd6a | 2022-03-24 11:50:33 +0530 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | #endif |
| 150 | |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 151 | #ifdef CONFIG_IMX_BOOTAUX |
| 152 | |
| 153 | #ifdef CONFIG_IMX8QM |
| 154 | int arch_auxiliary_core_up(u32 core_id, ulong boot_private_data) |
| 155 | { |
| 156 | sc_rsrc_t core_rsrc, mu_rsrc; |
| 157 | sc_faddr_t tcml_addr; |
| 158 | u32 tcml_size = SZ_128K; |
| 159 | ulong addr; |
| 160 | |
| 161 | switch (core_id) { |
| 162 | case 0: |
| 163 | core_rsrc = SC_R_M4_0_PID0; |
| 164 | tcml_addr = 0x34FE0000; |
| 165 | mu_rsrc = SC_R_M4_0_MU_1A; |
| 166 | break; |
| 167 | case 1: |
| 168 | core_rsrc = SC_R_M4_1_PID0; |
| 169 | tcml_addr = 0x38FE0000; |
| 170 | mu_rsrc = SC_R_M4_1_MU_1A; |
| 171 | break; |
| 172 | default: |
| 173 | printf("Not support this core boot up, ID:%u\n", core_id); |
| 174 | return -EINVAL; |
| 175 | } |
| 176 | |
| 177 | addr = (sc_faddr_t)boot_private_data; |
| 178 | |
| 179 | if (addr >= tcml_addr && addr <= tcml_addr + tcml_size) { |
| 180 | printf("Wrong image address 0x%lx, should not in TCML\n", |
| 181 | addr); |
| 182 | return -EINVAL; |
| 183 | } |
| 184 | |
| 185 | printf("Power on M4 and MU\n"); |
| 186 | |
| 187 | if (sc_pm_set_resource_power_mode(-1, core_rsrc, SC_PM_PW_MODE_ON) != SC_ERR_NONE) |
| 188 | return -EIO; |
| 189 | |
| 190 | if (sc_pm_set_resource_power_mode(-1, mu_rsrc, SC_PM_PW_MODE_ON) != SC_ERR_NONE) |
| 191 | return -EIO; |
| 192 | |
| 193 | printf("Copy M4 image from 0x%lx to TCML 0x%lx\n", addr, (ulong)tcml_addr); |
| 194 | |
| 195 | if (addr != tcml_addr) |
| 196 | memcpy((void *)tcml_addr, (void *)addr, tcml_size); |
| 197 | |
| 198 | printf("Start M4 %u\n", core_id); |
| 199 | if (sc_pm_cpu_start(-1, core_rsrc, true, tcml_addr) != SC_ERR_NONE) |
| 200 | return -EIO; |
| 201 | |
| 202 | printf("bootaux complete\n"); |
| 203 | return 0; |
| 204 | } |
| 205 | #endif |
| 206 | |
| 207 | #ifdef CONFIG_IMX8QXP |
| 208 | int arch_auxiliary_core_up(u32 core_id, ulong boot_private_data) |
| 209 | { |
| 210 | sc_rsrc_t core_rsrc, mu_rsrc = SC_R_NONE; |
| 211 | sc_faddr_t aux_core_ram; |
| 212 | u32 size; |
| 213 | ulong addr; |
| 214 | |
| 215 | switch (core_id) { |
| 216 | case 0: |
| 217 | core_rsrc = SC_R_M4_0_PID0; |
| 218 | aux_core_ram = 0x34FE0000; |
| 219 | mu_rsrc = SC_R_M4_0_MU_1A; |
| 220 | size = SZ_128K; |
| 221 | break; |
| 222 | case 1: |
| 223 | core_rsrc = SC_R_DSP; |
| 224 | aux_core_ram = 0x596f8000; |
| 225 | size = SZ_2K; |
| 226 | break; |
| 227 | default: |
| 228 | printf("Not support this core boot up, ID:%u\n", core_id); |
| 229 | return -EINVAL; |
| 230 | } |
| 231 | |
| 232 | addr = (sc_faddr_t)boot_private_data; |
| 233 | |
| 234 | if (addr >= aux_core_ram && addr <= aux_core_ram + size) { |
| 235 | printf("Wrong image address 0x%lx, should not in aux core ram\n", |
| 236 | addr); |
| 237 | return -EINVAL; |
| 238 | } |
| 239 | |
| 240 | printf("Power on aux core %d\n", core_id); |
| 241 | |
| 242 | if (sc_pm_set_resource_power_mode(-1, core_rsrc, SC_PM_PW_MODE_ON) != SC_ERR_NONE) |
| 243 | return -EIO; |
| 244 | |
| 245 | if (mu_rsrc != SC_R_NONE) { |
| 246 | if (sc_pm_set_resource_power_mode(-1, mu_rsrc, SC_PM_PW_MODE_ON) != SC_ERR_NONE) |
| 247 | return -EIO; |
| 248 | } |
| 249 | |
| 250 | if (core_id == 1) { |
| 251 | struct power_domain pd; |
| 252 | |
| 253 | if (sc_pm_clock_enable(-1, core_rsrc, SC_PM_CLK_PER, true, false) != SC_ERR_NONE) { |
| 254 | printf("Error enable clock\n"); |
| 255 | return -EIO; |
| 256 | } |
| 257 | |
| 258 | if (!power_domain_lookup_name("audio_sai0", &pd)) { |
| 259 | if (power_domain_on(&pd)) { |
| 260 | printf("Error power on SAI0\n"); |
| 261 | return -EIO; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | if (!power_domain_lookup_name("audio_ocram", &pd)) { |
| 266 | if (power_domain_on(&pd)) { |
| 267 | printf("Error power on HIFI RAM\n"); |
| 268 | return -EIO; |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | printf("Copy image from 0x%lx to 0x%lx\n", addr, (ulong)aux_core_ram); |
| 274 | if (core_id == 0) { |
| 275 | /* M4 use bin file */ |
| 276 | memcpy((void *)aux_core_ram, (void *)addr, size); |
| 277 | } else { |
| 278 | /* HIFI use elf file */ |
| 279 | if (!valid_elf_image(addr)) |
| 280 | return -1; |
| 281 | addr = load_elf_image_shdr(addr); |
| 282 | } |
| 283 | |
| 284 | printf("Start %s\n", core_id == 0 ? "M4" : "HIFI"); |
| 285 | |
| 286 | if (sc_pm_cpu_start(-1, core_rsrc, true, aux_core_ram) != SC_ERR_NONE) |
| 287 | return -EIO; |
| 288 | |
| 289 | printf("bootaux complete\n"); |
| 290 | return 0; |
| 291 | } |
| 292 | #endif |
| 293 | |
| 294 | int arch_auxiliary_core_check_up(u32 core_id) |
| 295 | { |
| 296 | sc_rsrc_t core_rsrc; |
| 297 | sc_pm_power_mode_t power_mode; |
| 298 | |
| 299 | switch (core_id) { |
| 300 | case 0: |
| 301 | core_rsrc = SC_R_M4_0_PID0; |
| 302 | break; |
| 303 | #ifdef CONFIG_IMX8QM |
| 304 | case 1: |
| 305 | core_rsrc = SC_R_M4_1_PID0; |
| 306 | break; |
| 307 | #endif |
| 308 | default: |
| 309 | printf("Not support this core, ID:%u\n", core_id); |
| 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | if (sc_pm_get_resource_power_mode(-1, core_rsrc, &power_mode) != SC_ERR_NONE) |
| 314 | return 0; |
| 315 | |
| 316 | if (power_mode != SC_PM_PW_MODE_OFF) |
| 317 | return 1; |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | #endif |
| 322 | |
Peng Fan | 29c9dd3 | 2018-10-18 14:28:19 +0200 | [diff] [blame] | 323 | int print_bootinfo(void) |
| 324 | { |
| 325 | enum boot_device bt_dev = get_boot_device(); |
| 326 | |
| 327 | puts("Boot: "); |
| 328 | switch (bt_dev) { |
| 329 | case SD1_BOOT: |
| 330 | puts("SD0\n"); |
| 331 | break; |
| 332 | case SD2_BOOT: |
| 333 | puts("SD1\n"); |
| 334 | break; |
| 335 | case SD3_BOOT: |
| 336 | puts("SD2\n"); |
| 337 | break; |
| 338 | case MMC1_BOOT: |
| 339 | puts("MMC0\n"); |
| 340 | break; |
| 341 | case MMC2_BOOT: |
| 342 | puts("MMC1\n"); |
| 343 | break; |
| 344 | case MMC3_BOOT: |
| 345 | puts("MMC2\n"); |
| 346 | break; |
| 347 | case FLEXSPI_BOOT: |
| 348 | puts("FLEXSPI\n"); |
| 349 | break; |
| 350 | case SATA_BOOT: |
| 351 | puts("SATA\n"); |
| 352 | break; |
| 353 | case NAND_BOOT: |
| 354 | puts("NAND\n"); |
| 355 | break; |
| 356 | case USB_BOOT: |
| 357 | puts("USB\n"); |
| 358 | break; |
| 359 | default: |
| 360 | printf("Unknown device %u\n", bt_dev); |
| 361 | break; |
| 362 | } |
| 363 | |
Igor Opaniuk | ab5ffef | 2024-01-31 13:49:26 +0100 | [diff] [blame] | 364 | printf("Reset cause: %s\n", get_reset_cause()); |
| 365 | |
Peng Fan | 29c9dd3 | 2018-10-18 14:28:19 +0200 | [diff] [blame] | 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | enum boot_device get_boot_device(void) |
| 370 | { |
| 371 | enum boot_device boot_dev = SD1_BOOT; |
| 372 | |
| 373 | sc_rsrc_t dev_rsrc; |
| 374 | |
| 375 | sc_misc_get_boot_dev(-1, &dev_rsrc); |
| 376 | |
| 377 | switch (dev_rsrc) { |
| 378 | case SC_R_SDHC_0: |
| 379 | boot_dev = MMC1_BOOT; |
| 380 | break; |
| 381 | case SC_R_SDHC_1: |
| 382 | boot_dev = SD2_BOOT; |
| 383 | break; |
| 384 | case SC_R_SDHC_2: |
| 385 | boot_dev = SD3_BOOT; |
| 386 | break; |
| 387 | case SC_R_NAND: |
| 388 | boot_dev = NAND_BOOT; |
| 389 | break; |
| 390 | case SC_R_FSPI_0: |
| 391 | boot_dev = FLEXSPI_BOOT; |
| 392 | break; |
| 393 | case SC_R_SATA_0: |
| 394 | boot_dev = SATA_BOOT; |
| 395 | break; |
| 396 | case SC_R_USB_0: |
| 397 | case SC_R_USB_1: |
| 398 | case SC_R_USB_2: |
| 399 | boot_dev = USB_BOOT; |
| 400 | break; |
| 401 | default: |
| 402 | break; |
| 403 | } |
| 404 | |
| 405 | return boot_dev; |
| 406 | } |
Peng Fan | 93b6cfd | 2018-10-18 14:28:20 +0200 | [diff] [blame] | 407 | |
Tom Rini | ae21e7f | 2021-08-30 09:16:29 -0400 | [diff] [blame] | 408 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
Peng Fan | d2aaf0c | 2020-05-05 20:28:39 +0800 | [diff] [blame] | 409 | #define FUSE_UNIQUE_ID_WORD0 16 |
| 410 | #define FUSE_UNIQUE_ID_WORD1 17 |
| 411 | void get_board_serial(struct tag_serialnr *serialnr) |
| 412 | { |
Peng Fan | 25b7eb4 | 2023-06-15 18:08:58 +0800 | [diff] [blame] | 413 | int err; |
Peng Fan | d2aaf0c | 2020-05-05 20:28:39 +0800 | [diff] [blame] | 414 | u32 val1 = 0, val2 = 0; |
| 415 | u32 word1, word2; |
| 416 | |
| 417 | if (!serialnr) |
| 418 | return; |
| 419 | |
| 420 | word1 = FUSE_UNIQUE_ID_WORD0; |
| 421 | word2 = FUSE_UNIQUE_ID_WORD1; |
| 422 | |
| 423 | err = sc_misc_otp_fuse_read(-1, word1, &val1); |
Peng Fan | 25b7eb4 | 2023-06-15 18:08:58 +0800 | [diff] [blame] | 424 | if (err) { |
Peng Fan | d2aaf0c | 2020-05-05 20:28:39 +0800 | [diff] [blame] | 425 | printf("%s fuse %d read error: %d\n", __func__, word1, err); |
| 426 | return; |
| 427 | } |
| 428 | |
| 429 | err = sc_misc_otp_fuse_read(-1, word2, &val2); |
Peng Fan | 25b7eb4 | 2023-06-15 18:08:58 +0800 | [diff] [blame] | 430 | if (err) { |
Peng Fan | d2aaf0c | 2020-05-05 20:28:39 +0800 | [diff] [blame] | 431 | printf("%s fuse %d read error: %d\n", __func__, word2, err); |
| 432 | return; |
| 433 | } |
| 434 | serialnr->low = val1; |
| 435 | serialnr->high = val2; |
| 436 | } |
Tom Rini | ae21e7f | 2021-08-30 09:16:29 -0400 | [diff] [blame] | 437 | #endif /*CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG*/ |
Peng Fan | d2aaf0c | 2020-05-05 20:28:39 +0800 | [diff] [blame] | 438 | |
Peng Fan | 93b6cfd | 2018-10-18 14:28:20 +0200 | [diff] [blame] | 439 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 440 | __weak int board_mmc_get_env_dev(int devno) |
| 441 | { |
| 442 | return CONFIG_SYS_MMC_ENV_DEV; |
| 443 | } |
| 444 | |
| 445 | int mmc_get_env_dev(void) |
| 446 | { |
| 447 | sc_rsrc_t dev_rsrc; |
| 448 | int devno; |
| 449 | |
| 450 | sc_misc_get_boot_dev(-1, &dev_rsrc); |
| 451 | |
| 452 | switch (dev_rsrc) { |
| 453 | case SC_R_SDHC_0: |
| 454 | devno = 0; |
| 455 | break; |
| 456 | case SC_R_SDHC_1: |
| 457 | devno = 1; |
| 458 | break; |
| 459 | case SC_R_SDHC_2: |
| 460 | devno = 2; |
| 461 | break; |
| 462 | default: |
| 463 | /* If not boot from sd/mmc, use default value */ |
| 464 | return CONFIG_SYS_MMC_ENV_DEV; |
| 465 | } |
| 466 | |
| 467 | return board_mmc_get_env_dev(devno); |
| 468 | } |
| 469 | #endif |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 470 | |
| 471 | #define MEMSTART_ALIGNMENT SZ_2M /* Align the memory start with 2MB */ |
| 472 | |
| 473 | static int get_owned_memreg(sc_rm_mr_t mr, sc_faddr_t *addr_start, |
| 474 | sc_faddr_t *addr_end) |
| 475 | { |
| 476 | sc_faddr_t start, end; |
| 477 | int ret; |
| 478 | bool owned; |
| 479 | |
| 480 | owned = sc_rm_is_memreg_owned(-1, mr); |
| 481 | if (owned) { |
| 482 | ret = sc_rm_get_memreg_info(-1, mr, &start, &end); |
| 483 | if (ret) { |
| 484 | printf("Memreg get info failed, %d\n", ret); |
| 485 | return -EINVAL; |
| 486 | } |
| 487 | debug("0x%llx -- 0x%llx\n", start, end); |
| 488 | *addr_start = start; |
| 489 | *addr_end = end; |
| 490 | |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | return -EINVAL; |
| 495 | } |
| 496 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 497 | __weak void board_mem_get_layout(u64 *phys_sdram_1_start, |
| 498 | u64 *phys_sdram_1_size, |
| 499 | u64 *phys_sdram_2_start, |
| 500 | u64 *phys_sdram_2_size) |
| 501 | { |
| 502 | *phys_sdram_1_start = PHYS_SDRAM_1; |
| 503 | *phys_sdram_1_size = PHYS_SDRAM_1_SIZE; |
| 504 | *phys_sdram_2_start = PHYS_SDRAM_2; |
| 505 | *phys_sdram_2_size = PHYS_SDRAM_2_SIZE; |
| 506 | } |
| 507 | |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 508 | phys_size_t get_effective_memsize(void) |
| 509 | { |
| 510 | sc_rm_mr_t mr; |
Ye Li | 7545bd1 | 2020-05-05 20:28:38 +0800 | [diff] [blame] | 511 | sc_faddr_t start, end, end1, start_aligned; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 512 | u64 phys_sdram_1_start, phys_sdram_1_size; |
| 513 | u64 phys_sdram_2_start, phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 514 | int err; |
| 515 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 516 | board_mem_get_layout(&phys_sdram_1_start, &phys_sdram_1_size, |
| 517 | &phys_sdram_2_start, &phys_sdram_2_size); |
| 518 | |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 519 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 520 | end1 = (sc_faddr_t)phys_sdram_1_start + phys_sdram_1_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 521 | for (mr = 0; mr < 64; mr++) { |
| 522 | err = get_owned_memreg(mr, &start, &end); |
| 523 | if (!err) { |
Ye Li | 7545bd1 | 2020-05-05 20:28:38 +0800 | [diff] [blame] | 524 | start_aligned = roundup(start, MEMSTART_ALIGNMENT); |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 525 | /* Too small memory region, not use it */ |
Ye Li | 7545bd1 | 2020-05-05 20:28:38 +0800 | [diff] [blame] | 526 | if (start_aligned > end) |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 527 | continue; |
| 528 | |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 529 | /* Find the memory region runs the U-Boot */ |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 530 | if (start >= phys_sdram_1_start && start <= end1 && |
Simon Glass | 72cc538 | 2022-10-20 18:22:39 -0600 | [diff] [blame] | 531 | (start <= CONFIG_TEXT_BASE && |
| 532 | end >= CONFIG_TEXT_BASE)) { |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 533 | if ((end + 1) <= |
| 534 | ((sc_faddr_t)phys_sdram_1_start + |
| 535 | phys_sdram_1_size)) |
| 536 | return (end - phys_sdram_1_start + 1); |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 537 | else |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 538 | return phys_sdram_1_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | } |
| 542 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 543 | return phys_sdram_1_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | int dram_init(void) |
| 547 | { |
| 548 | sc_rm_mr_t mr; |
| 549 | sc_faddr_t start, end, end1, end2; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 550 | u64 phys_sdram_1_start, phys_sdram_1_size; |
| 551 | u64 phys_sdram_2_start, phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 552 | int err; |
| 553 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 554 | board_mem_get_layout(&phys_sdram_1_start, &phys_sdram_1_size, |
| 555 | &phys_sdram_2_start, &phys_sdram_2_size); |
| 556 | |
| 557 | end1 = (sc_faddr_t)phys_sdram_1_start + phys_sdram_1_size; |
| 558 | end2 = (sc_faddr_t)phys_sdram_2_start + phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 559 | for (mr = 0; mr < 64; mr++) { |
| 560 | err = get_owned_memreg(mr, &start, &end); |
| 561 | if (!err) { |
| 562 | start = roundup(start, MEMSTART_ALIGNMENT); |
| 563 | /* Too small memory region, not use it */ |
| 564 | if (start > end) |
| 565 | continue; |
| 566 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 567 | if (start >= phys_sdram_1_start && start <= end1) { |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 568 | if ((end + 1) <= end1) |
| 569 | gd->ram_size += end - start + 1; |
| 570 | else |
| 571 | gd->ram_size += end1 - start; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 572 | } else if (start >= phys_sdram_2_start && |
| 573 | start <= end2) { |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 574 | if ((end + 1) <= end2) |
| 575 | gd->ram_size += end - start + 1; |
| 576 | else |
| 577 | gd->ram_size += end2 - start; |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | /* If error, set to the default value */ |
| 583 | if (!gd->ram_size) { |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 584 | gd->ram_size = phys_sdram_1_size; |
| 585 | gd->ram_size += phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 586 | } |
| 587 | return 0; |
| 588 | } |
| 589 | |
| 590 | static void dram_bank_sort(int current_bank) |
| 591 | { |
| 592 | phys_addr_t start; |
| 593 | phys_size_t size; |
| 594 | |
| 595 | while (current_bank > 0) { |
| 596 | if (gd->bd->bi_dram[current_bank - 1].start > |
| 597 | gd->bd->bi_dram[current_bank].start) { |
| 598 | start = gd->bd->bi_dram[current_bank - 1].start; |
| 599 | size = gd->bd->bi_dram[current_bank - 1].size; |
| 600 | |
| 601 | gd->bd->bi_dram[current_bank - 1].start = |
| 602 | gd->bd->bi_dram[current_bank].start; |
| 603 | gd->bd->bi_dram[current_bank - 1].size = |
| 604 | gd->bd->bi_dram[current_bank].size; |
| 605 | |
| 606 | gd->bd->bi_dram[current_bank].start = start; |
| 607 | gd->bd->bi_dram[current_bank].size = size; |
| 608 | } |
| 609 | current_bank--; |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | int dram_init_banksize(void) |
| 614 | { |
| 615 | sc_rm_mr_t mr; |
| 616 | sc_faddr_t start, end, end1, end2; |
| 617 | int i = 0; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 618 | u64 phys_sdram_1_start, phys_sdram_1_size; |
| 619 | u64 phys_sdram_2_start, phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 620 | int err; |
| 621 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 622 | board_mem_get_layout(&phys_sdram_1_start, &phys_sdram_1_size, |
| 623 | &phys_sdram_2_start, &phys_sdram_2_size); |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 624 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 625 | end1 = (sc_faddr_t)phys_sdram_1_start + phys_sdram_1_size; |
| 626 | end2 = (sc_faddr_t)phys_sdram_2_start + phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 627 | for (mr = 0; mr < 64 && i < CONFIG_NR_DRAM_BANKS; mr++) { |
| 628 | err = get_owned_memreg(mr, &start, &end); |
| 629 | if (!err) { |
| 630 | start = roundup(start, MEMSTART_ALIGNMENT); |
| 631 | if (start > end) /* Small memory region, no use it */ |
| 632 | continue; |
| 633 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 634 | if (start >= phys_sdram_1_start && start <= end1) { |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 635 | gd->bd->bi_dram[i].start = start; |
| 636 | |
| 637 | if ((end + 1) <= end1) |
| 638 | gd->bd->bi_dram[i].size = |
| 639 | end - start + 1; |
| 640 | else |
| 641 | gd->bd->bi_dram[i].size = end1 - start; |
| 642 | |
| 643 | dram_bank_sort(i); |
| 644 | i++; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 645 | } else if (start >= phys_sdram_2_start && start <= end2) { |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 646 | gd->bd->bi_dram[i].start = start; |
| 647 | |
| 648 | if ((end + 1) <= end2) |
| 649 | gd->bd->bi_dram[i].size = |
| 650 | end - start + 1; |
| 651 | else |
| 652 | gd->bd->bi_dram[i].size = end2 - start; |
| 653 | |
| 654 | dram_bank_sort(i); |
| 655 | i++; |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | /* If error, set to the default value */ |
| 661 | if (!i) { |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 662 | gd->bd->bi_dram[0].start = phys_sdram_1_start; |
| 663 | gd->bd->bi_dram[0].size = phys_sdram_1_size; |
| 664 | gd->bd->bi_dram[1].start = phys_sdram_2_start; |
| 665 | gd->bd->bi_dram[1].size = phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | return 0; |
| 669 | } |
| 670 | |
| 671 | static u64 get_block_attrs(sc_faddr_t addr_start) |
| 672 | { |
| 673 | u64 attr = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE | |
| 674 | PTE_BLOCK_PXN | PTE_BLOCK_UXN; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 675 | u64 phys_sdram_1_start, phys_sdram_1_size; |
| 676 | u64 phys_sdram_2_start, phys_sdram_2_size; |
| 677 | |
| 678 | board_mem_get_layout(&phys_sdram_1_start, &phys_sdram_1_size, |
| 679 | &phys_sdram_2_start, &phys_sdram_2_size); |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 680 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 681 | if ((addr_start >= phys_sdram_1_start && |
| 682 | addr_start <= ((sc_faddr_t)phys_sdram_1_start + phys_sdram_1_size)) || |
| 683 | (addr_start >= phys_sdram_2_start && |
| 684 | addr_start <= ((sc_faddr_t)phys_sdram_2_start + phys_sdram_2_size))) |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 685 | return (PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_OUTER_SHARE); |
| 686 | |
| 687 | return attr; |
| 688 | } |
| 689 | |
| 690 | static u64 get_block_size(sc_faddr_t addr_start, sc_faddr_t addr_end) |
| 691 | { |
| 692 | sc_faddr_t end1, end2; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 693 | u64 phys_sdram_1_start, phys_sdram_1_size; |
| 694 | u64 phys_sdram_2_start, phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 695 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 696 | board_mem_get_layout(&phys_sdram_1_start, &phys_sdram_1_size, |
| 697 | &phys_sdram_2_start, &phys_sdram_2_size); |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 698 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 699 | |
| 700 | end1 = (sc_faddr_t)phys_sdram_1_start + phys_sdram_1_size; |
| 701 | end2 = (sc_faddr_t)phys_sdram_2_start + phys_sdram_2_size; |
| 702 | |
| 703 | if (addr_start >= phys_sdram_1_start && addr_start <= end1) { |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 704 | if ((addr_end + 1) > end1) |
| 705 | return end1 - addr_start; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 706 | } else if (addr_start >= phys_sdram_2_start && addr_start <= end2) { |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 707 | if ((addr_end + 1) > end2) |
| 708 | return end2 - addr_start; |
| 709 | } |
| 710 | |
| 711 | return (addr_end - addr_start + 1); |
| 712 | } |
| 713 | |
| 714 | #define MAX_PTE_ENTRIES 512 |
| 715 | #define MAX_MEM_MAP_REGIONS 16 |
| 716 | |
| 717 | static struct mm_region imx8_mem_map[MAX_MEM_MAP_REGIONS]; |
| 718 | struct mm_region *mem_map = imx8_mem_map; |
| 719 | |
| 720 | void enable_caches(void) |
| 721 | { |
| 722 | sc_rm_mr_t mr; |
| 723 | sc_faddr_t start, end; |
| 724 | int err, i; |
| 725 | |
| 726 | /* Create map for registers access from 0x1c000000 to 0x80000000*/ |
| 727 | imx8_mem_map[0].virt = 0x1c000000UL; |
| 728 | imx8_mem_map[0].phys = 0x1c000000UL; |
| 729 | imx8_mem_map[0].size = 0x64000000UL; |
| 730 | imx8_mem_map[0].attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 731 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN; |
| 732 | |
| 733 | i = 1; |
| 734 | for (mr = 0; mr < 64 && i < MAX_MEM_MAP_REGIONS; mr++) { |
| 735 | err = get_owned_memreg(mr, &start, &end); |
| 736 | if (!err) { |
| 737 | imx8_mem_map[i].virt = start; |
| 738 | imx8_mem_map[i].phys = start; |
| 739 | imx8_mem_map[i].size = get_block_size(start, end); |
| 740 | imx8_mem_map[i].attrs = get_block_attrs(start); |
| 741 | i++; |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | if (i < MAX_MEM_MAP_REGIONS) { |
| 746 | imx8_mem_map[i].size = 0; |
| 747 | imx8_mem_map[i].attrs = 0; |
| 748 | } else { |
| 749 | puts("Error, need more MEM MAP REGIONS reserved\n"); |
| 750 | icache_enable(); |
| 751 | return; |
| 752 | } |
| 753 | |
| 754 | for (i = 0; i < MAX_MEM_MAP_REGIONS; i++) { |
| 755 | debug("[%d] vir = 0x%llx phys = 0x%llx size = 0x%llx attrs = 0x%llx\n", |
| 756 | i, imx8_mem_map[i].virt, imx8_mem_map[i].phys, |
| 757 | imx8_mem_map[i].size, imx8_mem_map[i].attrs); |
| 758 | } |
| 759 | |
| 760 | icache_enable(); |
| 761 | dcache_enable(); |
| 762 | } |
| 763 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 764 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 765 | u64 get_page_table_size(void) |
| 766 | { |
| 767 | u64 one_pt = MAX_PTE_ENTRIES * sizeof(u64); |
| 768 | u64 size = 0; |
| 769 | |
| 770 | /* |
| 771 | * For each memory region, the max table size: |
| 772 | * 2 level 3 tables + 2 level 2 tables + 1 level 1 table |
| 773 | */ |
| 774 | size = (2 + 2 + 1) * one_pt * MAX_MEM_MAP_REGIONS + one_pt; |
| 775 | |
| 776 | /* |
| 777 | * We need to duplicate our page table once to have an emergency pt to |
| 778 | * resort to when splitting page tables later on |
| 779 | */ |
| 780 | size *= 2; |
| 781 | |
| 782 | /* |
| 783 | * We may need to split page tables later on if dcache settings change, |
| 784 | * so reserve up to 4 (random pick) page tables for that. |
| 785 | */ |
| 786 | size += one_pt * 4; |
| 787 | |
| 788 | return size; |
| 789 | } |
| 790 | #endif |
Anatolij Gustschin | 05b354b | 2018-10-18 14:28:23 +0200 | [diff] [blame] | 791 | |
Peng Fan | 303324d | 2019-08-26 08:12:23 +0000 | [diff] [blame] | 792 | #if defined(CONFIG_IMX8QM) |
| 793 | #define FUSE_MAC0_WORD0 452 |
| 794 | #define FUSE_MAC0_WORD1 453 |
| 795 | #define FUSE_MAC1_WORD0 454 |
| 796 | #define FUSE_MAC1_WORD1 455 |
| 797 | #elif defined(CONFIG_IMX8QXP) |
Anatolij Gustschin | 05b354b | 2018-10-18 14:28:23 +0200 | [diff] [blame] | 798 | #define FUSE_MAC0_WORD0 708 |
| 799 | #define FUSE_MAC0_WORD1 709 |
| 800 | #define FUSE_MAC1_WORD0 710 |
| 801 | #define FUSE_MAC1_WORD1 711 |
Peng Fan | 303324d | 2019-08-26 08:12:23 +0000 | [diff] [blame] | 802 | #endif |
Anatolij Gustschin | 05b354b | 2018-10-18 14:28:23 +0200 | [diff] [blame] | 803 | |
| 804 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) |
| 805 | { |
| 806 | u32 word[2], val[2] = {}; |
| 807 | int i, ret; |
| 808 | |
| 809 | if (dev_id == 0) { |
| 810 | word[0] = FUSE_MAC0_WORD0; |
| 811 | word[1] = FUSE_MAC0_WORD1; |
| 812 | } else { |
| 813 | word[0] = FUSE_MAC1_WORD0; |
| 814 | word[1] = FUSE_MAC1_WORD1; |
| 815 | } |
| 816 | |
| 817 | for (i = 0; i < 2; i++) { |
| 818 | ret = sc_misc_otp_fuse_read(-1, word[i], &val[i]); |
| 819 | if (ret < 0) |
| 820 | goto err; |
| 821 | } |
| 822 | |
| 823 | mac[0] = val[0]; |
| 824 | mac[1] = val[0] >> 8; |
| 825 | mac[2] = val[0] >> 16; |
| 826 | mac[3] = val[0] >> 24; |
| 827 | mac[4] = val[1]; |
| 828 | mac[5] = val[1] >> 8; |
| 829 | |
| 830 | debug("%s: MAC%d: %02x.%02x.%02x.%02x.%02x.%02x\n", |
| 831 | __func__, dev_id, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
| 832 | return; |
| 833 | err: |
| 834 | printf("%s: fuse %d, err: %d\n", __func__, word[i], ret); |
| 835 | } |
Anatolij Gustschin | 9b39be9 | 2018-10-18 14:28:24 +0200 | [diff] [blame] | 836 | |
Anatolij Gustschin | 9b39be9 | 2018-10-18 14:28:24 +0200 | [diff] [blame] | 837 | u32 get_cpu_rev(void) |
| 838 | { |
| 839 | u32 id = 0, rev = 0; |
| 840 | int ret; |
| 841 | |
| 842 | ret = sc_misc_get_control(-1, SC_R_SYSTEM, SC_C_ID, &id); |
| 843 | if (ret) |
| 844 | return 0; |
| 845 | |
| 846 | rev = (id >> 5) & 0xf; |
| 847 | id = (id & 0x1f) + MXC_SOC_IMX8; /* Dummy ID for chip */ |
| 848 | |
| 849 | return (id << 12) | rev; |
| 850 | } |
Ye Li | c3169bd | 2020-05-05 20:28:42 +0800 | [diff] [blame] | 851 | |
| 852 | void board_boot_order(u32 *spl_boot_list) |
| 853 | { |
| 854 | spl_boot_list[0] = spl_boot_device(); |
| 855 | |
| 856 | if (spl_boot_list[0] == BOOT_DEVICE_SPI) { |
| 857 | /* Check whether we own the flexspi0, if not, use NOR boot */ |
| 858 | if (!sc_rm_is_resource_owned(-1, SC_R_FSPI_0)) |
| 859 | spl_boot_list[0] = BOOT_DEVICE_NOR; |
| 860 | } |
| 861 | } |
Peng Fan | 2d65a16 | 2020-05-05 20:28:43 +0800 | [diff] [blame] | 862 | |
| 863 | bool m4_parts_booted(void) |
| 864 | { |
| 865 | sc_rm_pt_t m4_parts[2]; |
| 866 | int err; |
| 867 | |
| 868 | err = sc_rm_get_resource_owner(-1, SC_R_M4_0_PID0, &m4_parts[0]); |
| 869 | if (err) { |
| 870 | printf("%s get resource [%d] owner error: %d\n", __func__, |
| 871 | SC_R_M4_0_PID0, err); |
| 872 | return false; |
| 873 | } |
| 874 | |
| 875 | if (sc_pm_is_partition_started(-1, m4_parts[0])) |
| 876 | return true; |
| 877 | |
| 878 | if (is_imx8qm()) { |
| 879 | err = sc_rm_get_resource_owner(-1, SC_R_M4_1_PID0, &m4_parts[1]); |
| 880 | if (err) { |
| 881 | printf("%s get resource [%d] owner error: %d\n", |
| 882 | __func__, SC_R_M4_1_PID0, err); |
| 883 | return false; |
| 884 | } |
| 885 | |
| 886 | if (sc_pm_is_partition_started(-1, m4_parts[1])) |
| 887 | return true; |
| 888 | } |
| 889 | |
| 890 | return false; |
| 891 | } |