blob: 4d963246856f9b9e641eea1ad8489cca3d242a10 [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;
42 default:
43 return BOOT_DEVICE_NONE;
44 }
45}
46
Alifer Moraesf0119b62020-01-14 15:55:00 -030047static void spl_dram_init(void)
Peng Fanf9220172019-08-27 06:26:08 +000048{
49 ddr_init(&dram_timing);
50}
51
52void spl_board_init(void)
53{
Gaurav Jain81113a02022-03-24 11:50:27 +053054 if (IS_ENABLED(CONFIG_FSL_CAAM)) {
55 struct udevice *dev;
56 int ret;
57
58 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev);
59 if (ret)
Ye Liec346892022-05-11 13:56:20 +053060 printf("Failed to initialize caam_jr: %d\n", ret);
Gaurav Jain81113a02022-03-24 11:50:27 +053061 }
Peng Fanf9220172019-08-27 06:26:08 +000062 puts("Normal Boot\n");
Peng Fanf9220172019-08-27 06:26:08 +000063}
64
65#ifdef CONFIG_SPL_LOAD_FIT
66int board_fit_config_name_match(const char *name)
67{
68 /* Just empty function now - can't decide what to choose */
69 debug("%s: %s\n", __func__, name);
70
71 return 0;
72}
73#endif
74
Alifer Moraesf0119b62020-01-14 15:55:00 -030075static int power_init_board(void)
Peng Fana9e04332019-10-16 10:24:42 +000076{
77 struct udevice *dev;
78 int ret;
79
Ye Li79e69702021-03-19 15:56:55 +080080 ret = pmic_get("pca9450@25", &dev);
Peng Fana9e04332019-10-16 10:24:42 +000081 if (ret == -ENODEV) {
82 puts("No pmic\n");
83 return 0;
84 }
85 if (ret != 0)
86 return ret;
87
Ye Li79e69702021-03-19 15:56:55 +080088 /* BUCKxOUT_DVS0/1 control BUCK123 output */
89 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
Peng Fana9e04332019-10-16 10:24:42 +000090
Ye Li79e69702021-03-19 15:56:55 +080091 /* Buck 1 DVS control through PMIC_STBY_REQ */
92 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
Peng Fana9e04332019-10-16 10:24:42 +000093
Ye Li79e69702021-03-19 15:56:55 +080094 /* Set DVS1 to 0.8v for suspend */
95 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x10);
Peng Fana9e04332019-10-16 10:24:42 +000096
Ye Li79e69702021-03-19 15:56:55 +080097 /* increase VDD_DRAM to 0.95v for 3Ghz DDR */
98 pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x1C);
Peng Fana9e04332019-10-16 10:24:42 +000099
Ye Li79e69702021-03-19 15:56:55 +0800100 /* VDD_DRAM needs off in suspend, set B1_ENMODE=10 (ON by PMIC_ON_REQ = H && PMIC_STBY_REQ = L) */
101 pmic_reg_write(dev, PCA9450_BUCK3CTRL, 0x4a);
102
103 /* set VDD_SNVS_0V8 from default 0.85V */
104 pmic_reg_write(dev, PCA9450_LDO2CTRL, 0xC0);
Peng Fana9e04332019-10-16 10:24:42 +0000105
Ye Li79e69702021-03-19 15:56:55 +0800106 /* set WDOG_B_CFG to cold reset */
107 pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1);
Peng Fana9e04332019-10-16 10:24:42 +0000108
109 return 0;
110}
111
Peng Fanf9220172019-08-27 06:26:08 +0000112void board_init_f(ulong dummy)
113{
Peng Fanb9b76882019-10-16 10:24:39 +0000114 struct udevice *dev;
Peng Fanf9220172019-08-27 06:26:08 +0000115 int ret;
116
117 arch_cpu_init();
118
119 init_uart_clk(1);
120
Peng Fanf9220172019-08-27 06:26:08 +0000121 timer_init();
122
Peng Fanf9220172019-08-27 06:26:08 +0000123 /* Clear the BSS. */
124 memset(__bss_start, 0, __bss_end - __bss_start);
125
Peng Fanb9b76882019-10-16 10:24:39 +0000126 ret = spl_early_init();
Peng Fanf9220172019-08-27 06:26:08 +0000127 if (ret) {
Peng Fanb9b76882019-10-16 10:24:39 +0000128 debug("spl_early_init() failed: %d\n", ret);
129 hang();
130 }
131
132 ret = uclass_get_device_by_name(UCLASS_CLK,
133 "clock-controller@30380000",
134 &dev);
135 if (ret < 0) {
136 printf("Failed to find clock node. Check device tree\n");
Peng Fanf9220172019-08-27 06:26:08 +0000137 hang();
138 }
139
Peng Fan4ee5ade2022-04-15 12:35:34 +0800140 preloader_console_init();
141
Peng Fanf9220172019-08-27 06:26:08 +0000142 enable_tzc380();
143
Peng Fana9e04332019-10-16 10:24:42 +0000144 power_init_board();
145
Peng Fanf9220172019-08-27 06:26:08 +0000146 /* DDR initialization */
147 spl_dram_init();
148
149 board_init_r(NULL, 0);
150}