blob: 35437811d9df7c8e343dbf9057412f04d6d78fe6 [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>
Shiji Yangbb112342023-08-03 09:47:16 +080022#include <asm/sections.h>
Peng Fanf9220172019-08-27 06:26:08 +000023
24#include <dm/uclass.h>
25#include <dm/device.h>
26#include <dm/uclass-internal.h>
27#include <dm/device-internal.h>
28
Peng Fana9e04332019-10-16 10:24:42 +000029#include <power/pmic.h>
Ye Li79e69702021-03-19 15:56:55 +080030#include <power/pca9450.h>
Peng Fana9e04332019-10-16 10:24:42 +000031
Peng Fanf9220172019-08-27 06:26:08 +000032DECLARE_GLOBAL_DATA_PTR;
33
34int spl_board_boot_device(enum boot_device boot_dev_spl)
35{
36 switch (boot_dev_spl) {
Fabio Estevame2b3a7b2022-09-19 21:20:13 -030037 case USB_BOOT:
38 return BOOT_DEVICE_BOARD;
Peng Fanf9220172019-08-27 06:26:08 +000039 case SD2_BOOT:
40 case MMC2_BOOT:
41 return BOOT_DEVICE_MMC1;
42 case SD3_BOOT:
43 case MMC3_BOOT:
44 return BOOT_DEVICE_MMC2;
Mamta Shukla34824292022-07-12 14:36:20 +000045 case QSPI_BOOT:
46 return BOOT_DEVICE_NOR;
Peng Fanf9220172019-08-27 06:26:08 +000047 default:
48 return BOOT_DEVICE_NONE;
49 }
50}
51
Alifer Moraesf0119b62020-01-14 15:55:00 -030052static void spl_dram_init(void)
Peng Fanf9220172019-08-27 06:26:08 +000053{
54 ddr_init(&dram_timing);
55}
56
57void spl_board_init(void)
58{
Marek Vasut085555f2022-09-19 21:41:15 +020059 arch_misc_init();
Peng Fanf9220172019-08-27 06:26:08 +000060}
61
62#ifdef CONFIG_SPL_LOAD_FIT
63int board_fit_config_name_match(const char *name)
64{
65 /* Just empty function now - can't decide what to choose */
66 debug("%s: %s\n", __func__, name);
67
68 return 0;
69}
70#endif
71
Alifer Moraesf0119b62020-01-14 15:55:00 -030072static int power_init_board(void)
Peng Fana9e04332019-10-16 10:24:42 +000073{
74 struct udevice *dev;
75 int ret;
76
Ye Li79e69702021-03-19 15:56:55 +080077 ret = pmic_get("pca9450@25", &dev);
Peng Fana9e04332019-10-16 10:24:42 +000078 if (ret == -ENODEV) {
79 puts("No pmic\n");
80 return 0;
81 }
82 if (ret != 0)
83 return ret;
84
Ye Li79e69702021-03-19 15:56:55 +080085 /* BUCKxOUT_DVS0/1 control BUCK123 output */
86 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
Peng Fana9e04332019-10-16 10:24:42 +000087
Ye Li79e69702021-03-19 15:56:55 +080088 /* Buck 1 DVS control through PMIC_STBY_REQ */
89 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
Peng Fana9e04332019-10-16 10:24:42 +000090
Ye Li79e69702021-03-19 15:56:55 +080091 /* Set DVS1 to 0.8v for suspend */
92 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x10);
Peng Fana9e04332019-10-16 10:24:42 +000093
Ye Li79e69702021-03-19 15:56:55 +080094 /* increase VDD_DRAM to 0.95v for 3Ghz DDR */
95 pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x1C);
Peng Fana9e04332019-10-16 10:24:42 +000096
Ye Li79e69702021-03-19 15:56:55 +080097 /* VDD_DRAM needs off in suspend, set B1_ENMODE=10 (ON by PMIC_ON_REQ = H && PMIC_STBY_REQ = L) */
98 pmic_reg_write(dev, PCA9450_BUCK3CTRL, 0x4a);
99
100 /* set VDD_SNVS_0V8 from default 0.85V */
101 pmic_reg_write(dev, PCA9450_LDO2CTRL, 0xC0);
Peng Fana9e04332019-10-16 10:24:42 +0000102
Peng Fana9e04332019-10-16 10:24:42 +0000103 return 0;
104}
105
Peng Fanf9220172019-08-27 06:26:08 +0000106void board_init_f(ulong dummy)
107{
Peng Fanb9b76882019-10-16 10:24:39 +0000108 struct udevice *dev;
Peng Fanf9220172019-08-27 06:26:08 +0000109 int ret;
110
111 arch_cpu_init();
112
113 init_uart_clk(1);
114
Peng Fanf9220172019-08-27 06:26:08 +0000115 timer_init();
116
Peng Fanf9220172019-08-27 06:26:08 +0000117 /* Clear the BSS. */
118 memset(__bss_start, 0, __bss_end - __bss_start);
119
Peng Fanb9b76882019-10-16 10:24:39 +0000120 ret = spl_early_init();
Peng Fanf9220172019-08-27 06:26:08 +0000121 if (ret) {
Peng Fanb9b76882019-10-16 10:24:39 +0000122 debug("spl_early_init() failed: %d\n", ret);
123 hang();
124 }
125
126 ret = uclass_get_device_by_name(UCLASS_CLK,
127 "clock-controller@30380000",
128 &dev);
129 if (ret < 0) {
130 printf("Failed to find clock node. Check device tree\n");
Peng Fanf9220172019-08-27 06:26:08 +0000131 hang();
132 }
133
Peng Fan4ee5ade2022-04-15 12:35:34 +0800134 preloader_console_init();
135
Peng Fanf9220172019-08-27 06:26:08 +0000136 enable_tzc380();
137
Peng Fana9e04332019-10-16 10:24:42 +0000138 power_init_board();
139
Peng Fanf9220172019-08-27 06:26:08 +0000140 /* DDR initialization */
141 spl_dram_init();
142
143 board_init_r(NULL, 0);
144}