blob: 6e9513805cdd49a176ee7e673a3ab6d94e8a0e56 [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
Peng Fana9e04332019-10-16 10:24:42 +0000102 return 0;
103}
104
Peng Fanf9220172019-08-27 06:26:08 +0000105void board_init_f(ulong dummy)
106{
Peng Fanb9b76882019-10-16 10:24:39 +0000107 struct udevice *dev;
Peng Fanf9220172019-08-27 06:26:08 +0000108 int ret;
109
110 arch_cpu_init();
111
112 init_uart_clk(1);
113
Peng Fanf9220172019-08-27 06:26:08 +0000114 timer_init();
115
Peng Fanf9220172019-08-27 06:26:08 +0000116 /* Clear the BSS. */
117 memset(__bss_start, 0, __bss_end - __bss_start);
118
Peng Fanb9b76882019-10-16 10:24:39 +0000119 ret = spl_early_init();
Peng Fanf9220172019-08-27 06:26:08 +0000120 if (ret) {
Peng Fanb9b76882019-10-16 10:24:39 +0000121 debug("spl_early_init() failed: %d\n", ret);
122 hang();
123 }
124
125 ret = uclass_get_device_by_name(UCLASS_CLK,
126 "clock-controller@30380000",
127 &dev);
128 if (ret < 0) {
129 printf("Failed to find clock node. Check device tree\n");
Peng Fanf9220172019-08-27 06:26:08 +0000130 hang();
131 }
132
Peng Fan4ee5ade2022-04-15 12:35:34 +0800133 preloader_console_init();
134
Peng Fanf9220172019-08-27 06:26:08 +0000135 enable_tzc380();
136
Peng Fana9e04332019-10-16 10:24:42 +0000137 power_init_board();
138
Peng Fanf9220172019-08-27 06:26:08 +0000139 /* DDR initialization */
140 spl_dram_init();
141
142 board_init_r(NULL, 0);
143}