Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2021 NXP |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <init.h> |
| 8 | #include <spl.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <errno.h> |
| 11 | #include <asm/arch/sys_proto.h> |
| 12 | #include <asm/arch/clock.h> |
| 13 | #include <asm/arch/imx8ulp-pins.h> |
| 14 | #include <dm/uclass.h> |
| 15 | #include <dm/device.h> |
| 16 | #include <dm/uclass-internal.h> |
| 17 | #include <dm/device-internal.h> |
| 18 | #include <dm/lists.h> |
| 19 | #include <asm/arch/ddr.h> |
| 20 | #include <asm/arch/rdc.h> |
| 21 | #include <asm/arch/upower.h> |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 22 | #include <asm/mach-imx/ele_api.h> |
Shiji Yang | bb11234 | 2023-08-03 09:47:16 +0800 | [diff] [blame] | 23 | #include <asm/sections.h> |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | void spl_dram_init(void) |
| 28 | { |
Ye Li | 8c0c8d0 | 2022-04-06 14:30:13 +0800 | [diff] [blame] | 29 | /* Reboot in dual boot setting no need to init ddr again */ |
| 30 | bool ddr_enable = pcc_clock_is_enable(5, LPDDR4_PCC5_SLOT); |
| 31 | |
| 32 | if (!ddr_enable) { |
| 33 | init_clk_ddr(); |
| 34 | ddr_init(&dram_timing); |
| 35 | } else { |
| 36 | /* reinit pfd/pfddiv and lpavnic except pll4*/ |
| 37 | cgc2_pll4_init(false); |
| 38 | } |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | u32 spl_boot_device(void) |
| 42 | { |
| 43 | return BOOT_DEVICE_BOOTROM; |
| 44 | } |
| 45 | |
| 46 | int power_init_board(void) |
| 47 | { |
Peng Fan | 4cdb3a3 | 2022-04-06 14:30:12 +0800 | [diff] [blame] | 48 | if (IS_ENABLED(CONFIG_IMX8ULP_LD_MODE)) { |
| 49 | /* Set buck3 to 0.9v LD */ |
| 50 | upower_pmic_i2c_write(0x22, 0x18); |
| 51 | } else if (IS_ENABLED(CONFIG_IMX8ULP_ND_MODE)) { |
| 52 | /* Set buck3 to 1.0v ND */ |
| 53 | upower_pmic_i2c_write(0x22, 0x20); |
| 54 | } else { |
| 55 | /* Set buck3 to 1.1v OD */ |
| 56 | upower_pmic_i2c_write(0x22, 0x28); |
| 57 | } |
| 58 | |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 59 | return 0; |
| 60 | } |
| 61 | |
Gaurav Jain | 580cc7b | 2022-05-11 14:07:55 +0530 | [diff] [blame] | 62 | void display_ele_fw_version(void) |
| 63 | { |
| 64 | u32 fw_version, sha1, res; |
| 65 | int ret; |
| 66 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 67 | ret = ele_get_fw_version(&fw_version, &sha1, &res); |
Gaurav Jain | 580cc7b | 2022-05-11 14:07:55 +0530 | [diff] [blame] | 68 | if (ret) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 69 | printf("ele get firmware version failed %d, 0x%x\n", ret, res); |
Gaurav Jain | 580cc7b | 2022-05-11 14:07:55 +0530 | [diff] [blame] | 70 | } else { |
| 71 | printf("ELE firmware version %u.%u.%u-%x", |
| 72 | (fw_version & (0x00ff0000)) >> 16, |
| 73 | (fw_version & (0x0000ff00)) >> 8, |
| 74 | (fw_version & (0x000000ff)), sha1); |
| 75 | ((fw_version & (0x80000000)) >> 31) == 1 ? puts("-dirty\n") : puts("\n"); |
| 76 | } |
| 77 | } |
| 78 | |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 79 | void spl_board_init(void) |
| 80 | { |
Clement Faure | 40bcdf9 | 2022-04-06 14:30:21 +0800 | [diff] [blame] | 81 | u32 res; |
| 82 | int ret; |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 83 | |
Ye Li | d5ffe55 | 2023-01-31 16:42:13 +0800 | [diff] [blame] | 84 | ret = imx8ulp_dm_post_init(); |
| 85 | if (ret) |
| 86 | return; |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 87 | |
| 88 | board_early_init_f(); |
| 89 | |
| 90 | preloader_console_init(); |
| 91 | |
| 92 | puts("Normal Boot\n"); |
| 93 | |
Gaurav Jain | 580cc7b | 2022-05-11 14:07:55 +0530 | [diff] [blame] | 94 | display_ele_fw_version(); |
| 95 | |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 96 | /* After AP set iomuxc0, the i2c can't work, Need M33 to set it now */ |
| 97 | |
Ye Li | fb82b77 | 2022-04-06 14:30:18 +0800 | [diff] [blame] | 98 | /* Load the lposc fuse to work around ROM issue. The fuse depends on S400 to read. */ |
| 99 | if (is_soc_rev(CHIP_REV_1_0)) |
Ye Li | 133f8b8 | 2021-10-29 09:46:25 +0800 | [diff] [blame] | 100 | load_lposc_fuse(); |
| 101 | |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 102 | upower_init(); |
| 103 | |
| 104 | power_init_board(); |
| 105 | |
Peng Fan | 4cdb3a3 | 2022-04-06 14:30:12 +0800 | [diff] [blame] | 106 | clock_init_late(); |
| 107 | |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 108 | /* This must place after upower init, so access to MDA and MRC are valid */ |
| 109 | /* Init XRDC MDA */ |
| 110 | xrdc_init_mda(); |
| 111 | |
| 112 | /* Init XRDC MRC for VIDEO, DSP domains */ |
| 113 | xrdc_init_mrc(); |
Ye Li | 715cfa0 | 2021-10-29 09:46:23 +0800 | [diff] [blame] | 114 | |
Ye Li | 7edb362 | 2023-01-31 16:42:24 +0800 | [diff] [blame] | 115 | xrdc_init_pdac_msc(); |
| 116 | |
| 117 | /* DDR initialization */ |
| 118 | spl_dram_init(); |
| 119 | |
Ye Li | 715cfa0 | 2021-10-29 09:46:23 +0800 | [diff] [blame] | 120 | /* Call it after PS16 power up */ |
| 121 | set_lpav_qos(); |
Clement Faure | 40bcdf9 | 2022-04-06 14:30:21 +0800 | [diff] [blame] | 122 | |
| 123 | /* Enable A35 access to the CAAM */ |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 124 | ret = ele_release_caam(0x7, &res); |
Clement Faure | 40bcdf9 | 2022-04-06 14:30:21 +0800 | [diff] [blame] | 125 | if (ret) |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 126 | printf("ele release caam failed %d, 0x%x\n", ret, res); |
Peng Fan | aa70b85 | 2023-06-15 18:09:14 +0800 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | * RNG start only available on the A1 soc revision. |
| 130 | * Check some JTAG register for the SoC revision. |
| 131 | */ |
| 132 | if (!is_soc_rev(CHIP_REV_1_0)) { |
| 133 | ret = ele_start_rng(); |
| 134 | if (ret) |
| 135 | printf("Fail to start RNG: %d\n", ret); |
| 136 | } |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | void board_init_f(ulong dummy) |
| 140 | { |
| 141 | /* Clear the BSS. */ |
| 142 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 143 | |
| 144 | timer_init(); |
| 145 | |
| 146 | arch_cpu_init(); |
| 147 | |
| 148 | board_init_r(NULL, 0); |
| 149 | } |