blob: c49b5be4762052ca7754471779e4032632e6161b [file] [log] [blame]
Peng Fancbe5d382021-08-07 16:01:13 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2021 NXP
4 */
5
Tom Riniabb9a042024-05-18 20:20:43 -06006#include <common.h>
Peng Fancbe5d382021-08-07 16:01:13 +08007#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 Fand5c31832023-06-15 18:09:05 +080022#include <asm/mach-imx/ele_api.h>
Shiji Yangbb112342023-08-03 09:47:16 +080023#include <asm/sections.h>
Peng Fancbe5d382021-08-07 16:01:13 +080024
25DECLARE_GLOBAL_DATA_PTR;
26
27void spl_dram_init(void)
28{
Ye Li8c0c8d02022-04-06 14:30:13 +080029 /* 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 Fancbe5d382021-08-07 16:01:13 +080039}
40
41u32 spl_boot_device(void)
42{
43 return BOOT_DEVICE_BOOTROM;
44}
45
46int power_init_board(void)
47{
Peng Fan4cdb3a32022-04-06 14:30:12 +080048 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 Fancbe5d382021-08-07 16:01:13 +080059 return 0;
60}
61
Gaurav Jain580cc7b2022-05-11 14:07:55 +053062void display_ele_fw_version(void)
63{
64 u32 fw_version, sha1, res;
65 int ret;
66
Peng Fand5c31832023-06-15 18:09:05 +080067 ret = ele_get_fw_version(&fw_version, &sha1, &res);
Gaurav Jain580cc7b2022-05-11 14:07:55 +053068 if (ret) {
Peng Fand5c31832023-06-15 18:09:05 +080069 printf("ele get firmware version failed %d, 0x%x\n", ret, res);
Gaurav Jain580cc7b2022-05-11 14:07:55 +053070 } 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 Fancbe5d382021-08-07 16:01:13 +080079void spl_board_init(void)
80{
Clement Faure40bcdf92022-04-06 14:30:21 +080081 u32 res;
82 int ret;
Peng Fancbe5d382021-08-07 16:01:13 +080083
Ye Lid5ffe552023-01-31 16:42:13 +080084 ret = imx8ulp_dm_post_init();
85 if (ret)
86 return;
Peng Fancbe5d382021-08-07 16:01:13 +080087
88 board_early_init_f();
89
90 preloader_console_init();
91
92 puts("Normal Boot\n");
93
Gaurav Jain580cc7b2022-05-11 14:07:55 +053094 display_ele_fw_version();
95
Peng Fancbe5d382021-08-07 16:01:13 +080096 /* After AP set iomuxc0, the i2c can't work, Need M33 to set it now */
97
Ye Lifb82b772022-04-06 14:30:18 +080098 /* 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 Li133f8b82021-10-29 09:46:25 +0800100 load_lposc_fuse();
101
Peng Fancbe5d382021-08-07 16:01:13 +0800102 upower_init();
103
104 power_init_board();
105
Peng Fan4cdb3a32022-04-06 14:30:12 +0800106 clock_init_late();
107
Peng Fancbe5d382021-08-07 16:01:13 +0800108 /* 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 Li715cfa02021-10-29 09:46:23 +0800114
Ye Li7edb3622023-01-31 16:42:24 +0800115 xrdc_init_pdac_msc();
116
117 /* DDR initialization */
118 spl_dram_init();
119
Ye Li715cfa02021-10-29 09:46:23 +0800120 /* Call it after PS16 power up */
121 set_lpav_qos();
Clement Faure40bcdf92022-04-06 14:30:21 +0800122
123 /* Enable A35 access to the CAAM */
Peng Fand5c31832023-06-15 18:09:05 +0800124 ret = ele_release_caam(0x7, &res);
Clement Faure40bcdf92022-04-06 14:30:21 +0800125 if (ret)
Peng Fand5c31832023-06-15 18:09:05 +0800126 printf("ele release caam failed %d, 0x%x\n", ret, res);
Peng Fanaa70b852023-06-15 18:09:14 +0800127
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 Fancbe5d382021-08-07 16:01:13 +0800137}
138
139void 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}