blob: 36e17219d63d23599c47baf57b842646b1c5d54a [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>
Mathieu Othacehea4dd3e52024-02-09 11:30:08 +010016#include <asm/arch/mu.h>
Mathieu Othacehe2415f1d2023-12-29 11:55:23 +010017#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>
22#include <asm/sections.h>
Mathieu Othacehe8bb6ede2024-02-26 18:37:18 +010023#include <asm/mach-imx/ele_api.h>
Mathieu Othacehe2415f1d2023-12-29 11:55:23 +010024#include <asm/mach-imx/syscounter.h>
25#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
37#include "../common/imx9_eeprom.h"
38
39DECLARE_GLOBAL_DATA_PTR;
40
41static struct var_eeprom eeprom = {0};
42
43int spl_board_boot_device(enum boot_device boot_dev_spl)
44{
45 return BOOT_DEVICE_BOOTROM;
46}
47
48void spl_board_init(void)
49{
50 struct var_eeprom *ep = VAR_EEPROM_DATA;
Mathieu Othacehe8bb6ede2024-02-26 18:37:18 +010051 int ret;
Mathieu Othacehe2415f1d2023-12-29 11:55:23 +010052
53 puts("Normal Boot\n");
54
Mathieu Othacehe8bb6ede2024-02-26 18:37:18 +010055 ret = ele_start_rng();
56 if (ret)
57 printf("Fail to start RNG: %d\n", ret);
58
Mathieu Othacehe2415f1d2023-12-29 11:55:23 +010059 /* Copy EEPROM contents to DRAM */
60 memcpy(ep, &eeprom, sizeof(*ep));
61}
62
63void spl_dram_init(void)
64{
65 /* EEPROM initialization */
66 var_eeprom_read_header(&eeprom);
67
68 ddr_init(&dram_timing);
69}
70
71int power_init_board(void)
72{
73 struct udevice *dev;
74 int ret;
75
76 if (IS_ENABLED(CONFIG_SPL_DM_PMIC_PCA9450)) {
77 ret = pmic_get("pmic@25", &dev);
78 if (ret == -ENODEV) {
79 puts("No pca9450@25\n");
80 return 0;
81 }
82 if (ret != 0)
83 return ret;
84
85 /* BUCKxOUT_DVS0/1 control BUCK123 output */
86 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
87
88 /* enable DVS control through PMIC_STBY_REQ */
89 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
90
91 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x18);
92 pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x18);
93
94 /* set standby voltage to 0.65V */
95 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x4);
96
97 /* I2C_LT_EN*/
98 pmic_reg_write(dev, 0xa, 0x3);
99
100 /* set WDOG_B_CFG to cold reset */
101 pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1);
102 }
103
104 return 0;
105}
106
107void board_init_f(ulong dummy)
108{
109 int ret;
110
111 /* Clear the BSS. */
112 memset(__bss_start, 0, __bss_end - __bss_start);
113
114 timer_init();
115
116 arch_cpu_init();
117
118 board_early_init_f();
119
120 spl_early_init();
121
122 preloader_console_init();
123
Mathieu Othacehea4dd3e52024-02-09 11:30:08 +0100124 ret = imx9_probe_mu(NULL, NULL);
Mathieu Othacehe2415f1d2023-12-29 11:55:23 +0100125 if (ret) {
Mathieu Othacehea4dd3e52024-02-09 11:30:08 +0100126 printf("Fail to init ELE API\n");
Mathieu Othacehe2415f1d2023-12-29 11:55:23 +0100127 } else {
128 printf("SOC: 0x%x\n", gd->arch.soc_rev);
129 printf("LC: 0x%x\n", gd->arch.lifecycle);
130 }
131 power_init_board();
132
133 set_arm_core_max_clk();
134
135 /* Init power of mix */
136 soc_power_init();
137
138 /* Setup TRDC for DDR access */
139 trdc_init();
140
141 /* DDR initialization */
142 spl_dram_init();
143
144 /* Put M33 into CPUWAIT for following kick */
145 ret = m33_prepare();
146 if (!ret)
147 printf("M33 prepare ok\n");
148
149 board_init_r(NULL, 0);
150}