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