blob: dd54fa9b6085bb288c2782395f032c9ee754d48d [file] [log] [blame]
Gaurav Jain81113a02022-03-24 11:50:27 +05301// SPDX-License-Identifier: GPL-2.0-or-later
Peng Fana181afe2019-09-16 03:09:55 +00002/*
Gaurav Jain81113a02022-03-24 11:50:27 +05303 * Copyright 2018-2019, 2021 NXP
Peng Fana181afe2019-09-16 03:09:55 +00004 *
Peng Fana181afe2019-09-16 03:09:55 +00005 */
6
7#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -06008#include <command.h>
Simon Glassafb02152019-12-28 10:45:01 -07009#include <cpu_func.h>
Simon Glassf11478f2019-12-28 10:45:07 -070010#include <hang.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060011#include <image.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Peng Fana181afe2019-09-16 03:09:55 +000014#include <spl.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Peng Fana181afe2019-09-16 03:09:55 +000016#include <asm/io.h>
17#include <asm/mach-imx/iomux-v3.h>
18#include <asm/arch/clock.h>
19#include <asm/arch/imx8mn_pins.h>
20#include <asm/arch/sys_proto.h>
21#include <asm/mach-imx/boot_mode.h>
22#include <asm/arch/ddr.h>
Shiji Yangbb112342023-08-03 09:47:16 +080023#include <asm/sections.h>
Peng Fana181afe2019-09-16 03:09:55 +000024
25#include <dm/uclass.h>
26#include <dm/device.h>
27#include <dm/uclass-internal.h>
28#include <dm/device-internal.h>
Peng Fan80607bf2021-03-19 15:57:08 +080029#include <power/pmic.h>
30#include <power/pca9450.h>
31#include <asm/mach-imx/gpio.h>
32#include <asm/mach-imx/mxc_i2c.h>
33#include <fsl_esdhc_imx.h>
34#include <mmc.h>
Peng Fana181afe2019-09-16 03:09:55 +000035
36DECLARE_GLOBAL_DATA_PTR;
37
38int spl_board_boot_device(enum boot_device boot_dev_spl)
39{
40 return BOOT_DEVICE_BOOTROM;
41}
42
43void spl_dram_init(void)
44{
45 ddr_init(&dram_timing);
46}
47
48void spl_board_init(void)
49{
50 struct udevice *dev;
51 int ret;
52
Marek Vasut085555f2022-09-19 21:41:15 +020053 arch_misc_init();
54
Peng Fana181afe2019-09-16 03:09:55 +000055 puts("Normal Boot\n");
56
57 ret = uclass_get_device_by_name(UCLASS_CLK,
58 "clock-controller@30380000",
59 &dev);
60 if (ret < 0)
61 printf("Failed to find clock node. Check device tree\n");
62}
63
Peng Fan80607bf2021-03-19 15:57:08 +080064#if CONFIG_IS_ENABLED(DM_PMIC_PCA9450)
65int power_init_board(void)
66{
67 struct udevice *dev;
68 int ret;
69
Marcel Ziswilera1033b82022-07-21 15:43:37 +020070 ret = pmic_get("pmic@25", &dev);
Peng Fan80607bf2021-03-19 15:57:08 +080071 if (ret == -ENODEV) {
72 puts("No pca9450@25\n");
73 return 0;
74 }
75 if (ret != 0)
76 return ret;
77
78 /* BUCKxOUT_DVS0/1 control BUCK123 output */
79 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
80
Ye Liee337ce2021-03-19 15:57:09 +080081#ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE
82 /* Set VDD_SOC/VDD_DRAM to 0.8v for low drive mode */
83 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x10);
84#else
Peng Fan80607bf2021-03-19 15:57:08 +080085 /* increase VDD_SOC/VDD_DRAM to typical value 0.95V before first DRAM access */
Ye Liee337ce2021-03-19 15:57:09 +080086 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x1C);
87#endif
Peng Fan80607bf2021-03-19 15:57:08 +080088 /* Set DVS1 to 0.85v for suspend */
89 /* Enable DVS control through PMIC_STBY_REQ and set B1_ENMODE=1 (ON by PMIC_ON_REQ=H) */
Peng Fan80607bf2021-03-19 15:57:08 +080090 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x14);
91 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
92
93 /* set VDD_SNVS_0V8 from default 0.85V */
94 pmic_reg_write(dev, PCA9450_LDO2CTRL, 0xC0);
95
96 /* enable LDO4 to 1.2v */
97 pmic_reg_write(dev, PCA9450_LDO4CTRL, 0x44);
98
Peng Fan80607bf2021-03-19 15:57:08 +080099 return 0;
100}
101#endif
102
Peng Fana181afe2019-09-16 03:09:55 +0000103#ifdef CONFIG_SPL_LOAD_FIT
104int board_fit_config_name_match(const char *name)
105{
106 /* Just empty function now - can't decide what to choose */
107 debug("%s: %s\n", __func__, name);
108
109 return 0;
110}
111#endif
112
Peng Fana181afe2019-09-16 03:09:55 +0000113void board_init_f(ulong dummy)
114{
115 int ret;
116
117 arch_cpu_init();
118
119 init_uart_clk(1);
120
Peng Fana181afe2019-09-16 03:09:55 +0000121 timer_init();
122
Peng Fana181afe2019-09-16 03:09:55 +0000123 /* Clear the BSS. */
124 memset(__bss_start, 0, __bss_end - __bss_start);
125
126 ret = spl_init();
127 if (ret) {
128 debug("spl_init() failed: %d\n", ret);
129 hang();
130 }
131
Peng Fanbee25f12022-04-15 12:35:35 +0800132 preloader_console_init();
133
Peng Fana181afe2019-09-16 03:09:55 +0000134 enable_tzc380();
135
136 /* DDR initialization */
137 spl_dram_init();
138
139 board_init_r(NULL, 0);
140}