blob: 6d5e110b27764665cbf80eb923a25086449862a3 [file] [log] [blame]
Peng Fanb72606c2022-07-26 16:41:10 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2022 NXP
4 */
5
6#include <common.h>
7#include <command.h>
8#include <cpu_func.h>
9#include <hang.h>
10#include <image.h>
11#include <init.h>
12#include <log.h>
13#include <spl.h>
14#include <asm/global_data.h>
15#include <asm/io.h>
16#include <asm/arch/imx93_pins.h>
Mathieu Othacehe72c6afe2024-02-09 11:30:07 +010017#include <asm/arch/mu.h>
Peng Fanb72606c2022-07-26 16:41:10 +080018#include <asm/arch/clock.h>
19#include <asm/arch/sys_proto.h>
20#include <asm/mach-imx/boot_mode.h>
21#include <asm/mach-imx/mxc_i2c.h>
22#include <asm/arch-mx7ulp/gpio.h>
Mathieu Othacehe8bb6ede2024-02-26 18:37:18 +010023#include <asm/mach-imx/ele_api.h>
Peng Fanb72606c2022-07-26 16:41:10 +080024#include <asm/mach-imx/syscounter.h>
Shiji Yangbb112342023-08-03 09:47:16 +080025#include <asm/sections.h>
Peng Fanb72606c2022-07-26 16:41:10 +080026#include <dm/uclass.h>
27#include <dm/device.h>
28#include <dm/uclass-internal.h>
29#include <dm/device-internal.h>
30#include <linux/delay.h>
31#include <asm/arch/clock.h>
32#include <asm/arch/ccm_regs.h>
33#include <asm/arch/ddr.h>
34#include <power/pmic.h>
35#include <power/pca9450.h>
36#include <asm/arch/trdc.h>
37
38DECLARE_GLOBAL_DATA_PTR;
39
40int spl_board_boot_device(enum boot_device boot_dev_spl)
41{
42 return BOOT_DEVICE_BOOTROM;
43}
44
45void spl_board_init(void)
46{
Mathieu Othacehe8bb6ede2024-02-26 18:37:18 +010047 int ret;
48
49 ret = ele_start_rng();
50 if (ret)
51 printf("Fail to start RNG: %d\n", ret);
52
Peng Fanb72606c2022-07-26 16:41:10 +080053 puts("Normal Boot\n");
54}
55
56void spl_dram_init(void)
57{
58 ddr_init(&dram_timing);
59}
60
61#if CONFIG_IS_ENABLED(DM_PMIC_PCA9450)
62int power_init_board(void)
63{
64 struct udevice *dev;
65 int ret;
66
67 ret = pmic_get("pmic@25", &dev);
68 if (ret == -ENODEV) {
69 puts("No pca9450@25\n");
70 return 0;
71 }
72 if (ret != 0)
73 return ret;
74
75 /* BUCKxOUT_DVS0/1 control BUCK123 output */
76 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
77
Peng Fan513d5082023-04-28 12:08:35 +080078 /* enable DVS control through PMIC_STBY_REQ */
79 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
80
81 if (IS_ENABLED(CONFIG_IMX9_LOW_DRIVE_MODE)) {
82 /* 0.75v for Low drive mode
83 */
84 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x0c);
85 pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x0c);
86 } else {
87 /* 0.9v for Over drive mode
88 */
89 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x18);
90 pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x18);
91 }
92
93 /* set standby voltage to 0.65v */
94 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x4);
Peng Fanb72606c2022-07-26 16:41:10 +080095
96 /* I2C_LT_EN*/
97 pmic_reg_write(dev, 0xa, 0x3);
Peng Fanb72606c2022-07-26 16:41:10 +080098 return 0;
99}
100#endif
101
Peng Fanb72606c2022-07-26 16:41:10 +0800102void board_init_f(ulong dummy)
103{
104 int ret;
105
106 /* Clear the BSS. */
107 memset(__bss_start, 0, __bss_end - __bss_start);
108
109 timer_init();
110
111 arch_cpu_init();
112
113 board_early_init_f();
114
115 spl_early_init();
116
117 preloader_console_init();
118
Ye Li81bfc1a2024-04-01 09:41:08 +0800119 ret = imx9_probe_mu();
Peng Fanb72606c2022-07-26 16:41:10 +0800120 if (ret) {
121 printf("Fail to init Sentinel API\n");
122 } else {
Fabio Estevam67480712024-04-15 18:57:17 -0300123 debug("SOC: 0x%x\n", gd->arch.soc_rev);
124 debug("LC: 0x%x\n", gd->arch.lifecycle);
Peng Fanb72606c2022-07-26 16:41:10 +0800125 }
Peng Fan513d5082023-04-28 12:08:35 +0800126
Peng Fanb72606c2022-07-26 16:41:10 +0800127 power_init_board();
128
Peng Fan513d5082023-04-28 12:08:35 +0800129 if (!IS_ENABLED(CONFIG_IMX9_LOW_DRIVE_MODE))
130 set_arm_clk(get_cpu_speed_grade_hz());
Peng Fan10fde4e2022-07-26 16:41:11 +0800131
Peng Fanb72606c2022-07-26 16:41:10 +0800132 /* Init power of mix */
133 soc_power_init();
134
135 /* Setup TRDC for DDR access */
136 trdc_init();
137
138 /* DDR initialization */
139 spl_dram_init();
140
141 /* Put M33 into CPUWAIT for following kick */
142 ret = m33_prepare();
143 if (!ret)
144 printf("M33 prepare ok\n");
145
146 board_init_r(NULL, 0);
147}