blob: 502e599b91aa9d3943cc764c949e8d292d4e21b9 [file] [log] [blame]
Mathieu Othacehe2415f1d2023-12-29 11:55:23 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2022 NXP
4 * Copyright 2023 Variscite Ltd.
5 */
6
7#include <command.h>
8#include <cpu_func.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>
16#include <asm/arch/clock.h>
17#include <asm/arch/sys_proto.h>
18#include <asm/mach-imx/boot_mode.h>
19#include <asm/mach-imx/mxc_i2c.h>
20#include <asm/arch-mx7ulp/gpio.h>
21#include <asm/sections.h>
22#include <asm/mach-imx/syscounter.h>
23#include <dm/uclass.h>
24#include <dm/device.h>
25#include <dm/uclass-internal.h>
26#include <dm/device-internal.h>
27#include <linux/delay.h>
28#include <asm/arch/clock.h>
29#include <asm/arch/ccm_regs.h>
30#include <asm/arch/ddr.h>
31#include <power/pmic.h>
32#include <power/pca9450.h>
33#include <asm/arch/trdc.h>
34
35#include "../common/imx9_eeprom.h"
36
37DECLARE_GLOBAL_DATA_PTR;
38
39static struct var_eeprom eeprom = {0};
40
41int spl_board_boot_device(enum boot_device boot_dev_spl)
42{
43 return BOOT_DEVICE_BOOTROM;
44}
45
46void spl_board_init(void)
47{
48 struct var_eeprom *ep = VAR_EEPROM_DATA;
49
50 puts("Normal Boot\n");
51
52 /* Copy EEPROM contents to DRAM */
53 memcpy(ep, &eeprom, sizeof(*ep));
54}
55
56void spl_dram_init(void)
57{
58 /* EEPROM initialization */
59 var_eeprom_read_header(&eeprom);
60
61 ddr_init(&dram_timing);
62}
63
64int power_init_board(void)
65{
66 struct udevice *dev;
67 int ret;
68
69 if (IS_ENABLED(CONFIG_SPL_DM_PMIC_PCA9450)) {
70 ret = pmic_get("pmic@25", &dev);
71 if (ret == -ENODEV) {
72 puts("No pca9450@25\n");
73 return 0;
74 }
75 if (ret != 0)
76 return ret;
77
78 /* BUCKxOUT_DVS0/1 control BUCK123 output */
79 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
80
81 /* enable DVS control through PMIC_STBY_REQ */
82 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
83
84 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x18);
85 pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x18);
86
87 /* set standby voltage to 0.65V */
88 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x4);
89
90 /* I2C_LT_EN*/
91 pmic_reg_write(dev, 0xa, 0x3);
92
93 /* set WDOG_B_CFG to cold reset */
94 pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1);
95 }
96
97 return 0;
98}
99
100void board_init_f(ulong dummy)
101{
102 int ret;
103
104 /* Clear the BSS. */
105 memset(__bss_start, 0, __bss_end - __bss_start);
106
107 timer_init();
108
109 arch_cpu_init();
110
111 board_early_init_f();
112
113 spl_early_init();
114
115 preloader_console_init();
116
117 ret = arch_cpu_init();
118 if (ret) {
119 printf("Fail to init Sentinel API\n");
120 } else {
121 printf("SOC: 0x%x\n", gd->arch.soc_rev);
122 printf("LC: 0x%x\n", gd->arch.lifecycle);
123 }
124 power_init_board();
125
126 set_arm_core_max_clk();
127
128 /* Init power of mix */
129 soc_power_init();
130
131 /* Setup TRDC for DDR access */
132 trdc_init();
133
134 /* DDR initialization */
135 spl_dram_init();
136
137 /* Put M33 into CPUWAIT for following kick */
138 ret = m33_prepare();
139 if (!ret)
140 printf("M33 prepare ok\n");
141
142 board_init_r(NULL, 0);
143}