blob: e672f6ee6cb19b387ba3f4e0d3bb0ff83df3d7bb [file] [log] [blame]
Peng Fancbe5d382021-08-07 16:01:13 +08001// 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>
Ye Lic408ed32022-07-26 16:40:49 +080022#include <asm/mach-imx/s400_api.h>
Peng Fancbe5d382021-08-07 16:01:13 +080023
24DECLARE_GLOBAL_DATA_PTR;
25
26void spl_dram_init(void)
27{
Ye Li8c0c8d02022-04-06 14:30:13 +080028 /* 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 Fancbe5d382021-08-07 16:01:13 +080038}
39
40u32 spl_boot_device(void)
41{
42 return BOOT_DEVICE_BOOTROM;
43}
44
45int power_init_board(void)
46{
Peng Fan4cdb3a32022-04-06 14:30:12 +080047 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 Fancbe5d382021-08-07 16:01:13 +080058 return 0;
59}
60
Gaurav Jain580cc7b2022-05-11 14:07:55 +053061void display_ele_fw_version(void)
62{
63 u32 fw_version, sha1, res;
64 int ret;
65
66 ret = ahab_get_fw_version(&fw_version, &sha1, &res);
67 if (ret) {
68 printf("ahab get firmware version failed %d, 0x%x\n", ret, res);
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 Fancbe5d382021-08-07 16:01:13 +080078void spl_board_init(void)
79{
80 struct udevice *dev;
Clement Faure40bcdf92022-04-06 14:30:21 +080081 u32 res;
82 int ret;
Peng Fancbe5d382021-08-07 16:01:13 +080083
84 uclass_find_first_device(UCLASS_MISC, &dev);
85
86 for (; dev; uclass_find_next_device(&dev)) {
87 if (device_probe(dev))
88 continue;
89 }
90
91 board_early_init_f();
92
93 preloader_console_init();
94
95 puts("Normal Boot\n");
96
Gaurav Jain580cc7b2022-05-11 14:07:55 +053097 display_ele_fw_version();
98
Peng Fancbe5d382021-08-07 16:01:13 +080099 /* After AP set iomuxc0, the i2c can't work, Need M33 to set it now */
100
Ye Lifb82b772022-04-06 14:30:18 +0800101 /* Load the lposc fuse to work around ROM issue. The fuse depends on S400 to read. */
102 if (is_soc_rev(CHIP_REV_1_0))
Ye Li133f8b82021-10-29 09:46:25 +0800103 load_lposc_fuse();
104
Peng Fancbe5d382021-08-07 16:01:13 +0800105 upower_init();
106
107 power_init_board();
108
Peng Fan4cdb3a32022-04-06 14:30:12 +0800109 clock_init_late();
110
Peng Fancbe5d382021-08-07 16:01:13 +0800111 /* DDR initialization */
112 spl_dram_init();
113
114 /* This must place after upower init, so access to MDA and MRC are valid */
115 /* Init XRDC MDA */
116 xrdc_init_mda();
117
118 /* Init XRDC MRC for VIDEO, DSP domains */
119 xrdc_init_mrc();
Ye Li715cfa02021-10-29 09:46:23 +0800120
121 /* Call it after PS16 power up */
122 set_lpav_qos();
Clement Faure40bcdf92022-04-06 14:30:21 +0800123
124 /* Enable A35 access to the CAAM */
125 ret = ahab_release_caam(0x7, &res);
126 if (ret)
127 printf("ahab release caam failed %d, 0x%x\n", ret, res);
Peng Fancbe5d382021-08-07 16:01:13 +0800128}
129
130void board_init_f(ulong dummy)
131{
132 /* Clear the BSS. */
133 memset(__bss_start, 0, __bss_end - __bss_start);
134
135 timer_init();
136
137 arch_cpu_init();
138
139 board_init_r(NULL, 0);
140}