blob: e2eb1426c83678a4f588ab87cc9b78957126e99a [file] [log] [blame]
Peng Fanf9220172019-08-27 06:26:08 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
Gaurav Jain81113a02022-03-24 11:50:27 +05303 * Copyright 2019, 2021 NXP
Peng Fanf9220172019-08-27 06:26:08 +00004 */
5
6#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -06007#include <command.h>
Simon Glassafb02152019-12-28 10:45:01 -07008#include <cpu_func.h>
Simon Glassf11478f2019-12-28 10:45:07 -07009#include <hang.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060010#include <image.h>
Simon Glass97589732020-05-10 11:40:02 -060011#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Peng Fanf9220172019-08-27 06:26:08 +000013#include <spl.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Peng Fanf9220172019-08-27 06:26:08 +000015#include <asm/io.h>
16#include <asm/mach-imx/iomux-v3.h>
17#include <asm/arch/clock.h>
18#include <asm/arch/imx8mm_pins.h>
19#include <asm/arch/sys_proto.h>
20#include <asm/mach-imx/boot_mode.h>
21#include <asm/arch/ddr.h>
22
23#include <dm/uclass.h>
24#include <dm/device.h>
25#include <dm/uclass-internal.h>
26#include <dm/device-internal.h>
27
Peng Fana9e04332019-10-16 10:24:42 +000028#include <power/pmic.h>
Ye Li79e69702021-03-19 15:56:55 +080029#include <power/pca9450.h>
Peng Fana9e04332019-10-16 10:24:42 +000030
Peng Fanf9220172019-08-27 06:26:08 +000031DECLARE_GLOBAL_DATA_PTR;
32
33int spl_board_boot_device(enum boot_device boot_dev_spl)
34{
35 switch (boot_dev_spl) {
36 case SD2_BOOT:
37 case MMC2_BOOT:
38 return BOOT_DEVICE_MMC1;
39 case SD3_BOOT:
40 case MMC3_BOOT:
41 return BOOT_DEVICE_MMC2;
Mamta Shukla34824292022-07-12 14:36:20 +000042 case QSPI_BOOT:
43 return BOOT_DEVICE_NOR;
Peng Fanf9220172019-08-27 06:26:08 +000044 default:
45 return BOOT_DEVICE_NONE;
46 }
47}
48
Alifer Moraesf0119b62020-01-14 15:55:00 -030049static void spl_dram_init(void)
Peng Fanf9220172019-08-27 06:26:08 +000050{
51 ddr_init(&dram_timing);
52}
53
54void spl_board_init(void)
55{
Gaurav Jain81113a02022-03-24 11:50:27 +053056 if (IS_ENABLED(CONFIG_FSL_CAAM)) {
57 struct udevice *dev;
58 int ret;
59
60 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev);
61 if (ret)
Ye Liec346892022-05-11 13:56:20 +053062 printf("Failed to initialize caam_jr: %d\n", ret);
Gaurav Jain81113a02022-03-24 11:50:27 +053063 }
Peng Fanf9220172019-08-27 06:26:08 +000064 puts("Normal Boot\n");
Peng Fanf9220172019-08-27 06:26:08 +000065}
66
67#ifdef CONFIG_SPL_LOAD_FIT
68int board_fit_config_name_match(const char *name)
69{
70 /* Just empty function now - can't decide what to choose */
71 debug("%s: %s\n", __func__, name);
72
73 return 0;
74}
75#endif
76
Alifer Moraesf0119b62020-01-14 15:55:00 -030077static int power_init_board(void)
Peng Fana9e04332019-10-16 10:24:42 +000078{
79 struct udevice *dev;
80 int ret;
81
Ye Li79e69702021-03-19 15:56:55 +080082 ret = pmic_get("pca9450@25", &dev);
Peng Fana9e04332019-10-16 10:24:42 +000083 if (ret == -ENODEV) {
84 puts("No pmic\n");
85 return 0;
86 }
87 if (ret != 0)
88 return ret;
89
Ye Li79e69702021-03-19 15:56:55 +080090 /* BUCKxOUT_DVS0/1 control BUCK123 output */
91 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
Peng Fana9e04332019-10-16 10:24:42 +000092
Ye Li79e69702021-03-19 15:56:55 +080093 /* Buck 1 DVS control through PMIC_STBY_REQ */
94 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
Peng Fana9e04332019-10-16 10:24:42 +000095
Ye Li79e69702021-03-19 15:56:55 +080096 /* Set DVS1 to 0.8v for suspend */
97 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x10);
Peng Fana9e04332019-10-16 10:24:42 +000098
Ye Li79e69702021-03-19 15:56:55 +080099 /* increase VDD_DRAM to 0.95v for 3Ghz DDR */
100 pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x1C);
Peng Fana9e04332019-10-16 10:24:42 +0000101
Ye Li79e69702021-03-19 15:56:55 +0800102 /* VDD_DRAM needs off in suspend, set B1_ENMODE=10 (ON by PMIC_ON_REQ = H && PMIC_STBY_REQ = L) */
103 pmic_reg_write(dev, PCA9450_BUCK3CTRL, 0x4a);
104
105 /* set VDD_SNVS_0V8 from default 0.85V */
106 pmic_reg_write(dev, PCA9450_LDO2CTRL, 0xC0);
Peng Fana9e04332019-10-16 10:24:42 +0000107
Ye Li79e69702021-03-19 15:56:55 +0800108 /* set WDOG_B_CFG to cold reset */
109 pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1);
Peng Fana9e04332019-10-16 10:24:42 +0000110
111 return 0;
112}
113
Peng Fanf9220172019-08-27 06:26:08 +0000114void board_init_f(ulong dummy)
115{
Peng Fanb9b76882019-10-16 10:24:39 +0000116 struct udevice *dev;
Peng Fanf9220172019-08-27 06:26:08 +0000117 int ret;
118
119 arch_cpu_init();
120
121 init_uart_clk(1);
122
Peng Fanf9220172019-08-27 06:26:08 +0000123 timer_init();
124
Peng Fanf9220172019-08-27 06:26:08 +0000125 /* Clear the BSS. */
126 memset(__bss_start, 0, __bss_end - __bss_start);
127
Peng Fanb9b76882019-10-16 10:24:39 +0000128 ret = spl_early_init();
Peng Fanf9220172019-08-27 06:26:08 +0000129 if (ret) {
Peng Fanb9b76882019-10-16 10:24:39 +0000130 debug("spl_early_init() failed: %d\n", ret);
131 hang();
132 }
133
134 ret = uclass_get_device_by_name(UCLASS_CLK,
135 "clock-controller@30380000",
136 &dev);
137 if (ret < 0) {
138 printf("Failed to find clock node. Check device tree\n");
Peng Fanf9220172019-08-27 06:26:08 +0000139 hang();
140 }
141
Peng Fan4ee5ade2022-04-15 12:35:34 +0800142 preloader_console_init();
143
Peng Fanf9220172019-08-27 06:26:08 +0000144 enable_tzc380();
145
Peng Fana9e04332019-10-16 10:24:42 +0000146 power_init_board();
147
Peng Fanf9220172019-08-27 06:26:08 +0000148 /* DDR initialization */
149 spl_dram_init();
150
151 board_init_r(NULL, 0);
152}