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