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