blob: b5a2faf3a189c3a1d8012a4fe02568288fe23df3 [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) {
Fabio Estevame2b3a7b2022-09-19 21:20:13 -030036 case USB_BOOT:
37 return BOOT_DEVICE_BOARD;
Peng Fanf9220172019-08-27 06:26:08 +000038 case SD2_BOOT:
39 case MMC2_BOOT:
40 return BOOT_DEVICE_MMC1;
41 case SD3_BOOT:
42 case MMC3_BOOT:
43 return BOOT_DEVICE_MMC2;
Mamta Shukla34824292022-07-12 14:36:20 +000044 case QSPI_BOOT:
45 return BOOT_DEVICE_NOR;
Peng Fanf9220172019-08-27 06:26:08 +000046 default:
47 return BOOT_DEVICE_NONE;
48 }
49}
50
Alifer Moraesf0119b62020-01-14 15:55:00 -030051static void spl_dram_init(void)
Peng Fanf9220172019-08-27 06:26:08 +000052{
53 ddr_init(&dram_timing);
54}
55
56void spl_board_init(void)
57{
Marek Vasut085555f2022-09-19 21:41:15 +020058 arch_misc_init();
Peng Fanf9220172019-08-27 06:26:08 +000059}
60
61#ifdef CONFIG_SPL_LOAD_FIT
62int board_fit_config_name_match(const char *name)
63{
64 /* Just empty function now - can't decide what to choose */
65 debug("%s: %s\n", __func__, name);
66
67 return 0;
68}
69#endif
70
Alifer Moraesf0119b62020-01-14 15:55:00 -030071static int power_init_board(void)
Peng Fana9e04332019-10-16 10:24:42 +000072{
73 struct udevice *dev;
74 int ret;
75
Ye Li79e69702021-03-19 15:56:55 +080076 ret = pmic_get("pca9450@25", &dev);
Peng Fana9e04332019-10-16 10:24:42 +000077 if (ret == -ENODEV) {
78 puts("No pmic\n");
79 return 0;
80 }
81 if (ret != 0)
82 return ret;
83
Ye Li79e69702021-03-19 15:56:55 +080084 /* BUCKxOUT_DVS0/1 control BUCK123 output */
85 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
Peng Fana9e04332019-10-16 10:24:42 +000086
Ye Li79e69702021-03-19 15:56:55 +080087 /* Buck 1 DVS control through PMIC_STBY_REQ */
88 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
Peng Fana9e04332019-10-16 10:24:42 +000089
Ye Li79e69702021-03-19 15:56:55 +080090 /* Set DVS1 to 0.8v for suspend */
91 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x10);
Peng Fana9e04332019-10-16 10:24:42 +000092
Ye Li79e69702021-03-19 15:56:55 +080093 /* increase VDD_DRAM to 0.95v for 3Ghz DDR */
94 pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x1C);
Peng Fana9e04332019-10-16 10:24:42 +000095
Ye Li79e69702021-03-19 15:56:55 +080096 /* VDD_DRAM needs off in suspend, set B1_ENMODE=10 (ON by PMIC_ON_REQ = H && PMIC_STBY_REQ = L) */
97 pmic_reg_write(dev, PCA9450_BUCK3CTRL, 0x4a);
98
99 /* set VDD_SNVS_0V8 from default 0.85V */
100 pmic_reg_write(dev, PCA9450_LDO2CTRL, 0xC0);
Peng Fana9e04332019-10-16 10:24:42 +0000101
Ye Li79e69702021-03-19 15:56:55 +0800102 /* set WDOG_B_CFG to cold reset */
103 pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1);
Peng Fana9e04332019-10-16 10:24:42 +0000104
105 return 0;
106}
107
Peng Fanf9220172019-08-27 06:26:08 +0000108void board_init_f(ulong dummy)
109{
Peng Fanb9b76882019-10-16 10:24:39 +0000110 struct udevice *dev;
Peng Fanf9220172019-08-27 06:26:08 +0000111 int ret;
112
113 arch_cpu_init();
114
115 init_uart_clk(1);
116
Peng Fanf9220172019-08-27 06:26:08 +0000117 timer_init();
118
Peng Fanf9220172019-08-27 06:26:08 +0000119 /* Clear the BSS. */
120 memset(__bss_start, 0, __bss_end - __bss_start);
121
Peng Fanb9b76882019-10-16 10:24:39 +0000122 ret = spl_early_init();
Peng Fanf9220172019-08-27 06:26:08 +0000123 if (ret) {
Peng Fanb9b76882019-10-16 10:24:39 +0000124 debug("spl_early_init() failed: %d\n", ret);
125 hang();
126 }
127
128 ret = uclass_get_device_by_name(UCLASS_CLK,
129 "clock-controller@30380000",
130 &dev);
131 if (ret < 0) {
132 printf("Failed to find clock node. Check device tree\n");
Peng Fanf9220172019-08-27 06:26:08 +0000133 hang();
134 }
135
Peng Fan4ee5ade2022-04-15 12:35:34 +0800136 preloader_console_init();
137
Peng Fanf9220172019-08-27 06:26:08 +0000138 enable_tzc380();
139
Peng Fana9e04332019-10-16 10:24:42 +0000140 power_init_board();
141
Peng Fanf9220172019-08-27 06:26:08 +0000142 /* DDR initialization */
143 spl_dram_init();
144
145 board_init_r(NULL, 0);
146}