blob: 380abecd7460198bf0e92bd60c37a022476774ba [file] [log] [blame]
Gaurav Jain2cddfcb2022-03-24 11:50:27 +05301// SPDX-License-Identifier: GPL-2.0-or-later
Peng Fand239d9d2019-09-16 03:09:55 +00002/*
Gaurav Jain2cddfcb2022-03-24 11:50:27 +05303 * Copyright 2018-2019, 2021 NXP
Peng Fand239d9d2019-09-16 03:09:55 +00004 *
Peng Fand239d9d2019-09-16 03:09:55 +00005 */
6
7#include <common.h>
Simon Glass09140112020-05-10 11:40:03 -06008#include <command.h>
Simon Glass9a3b4ce2019-12-28 10:45:01 -07009#include <cpu_func.h>
Simon Glassdb41d652019-12-28 10:45:07 -070010#include <hang.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060011#include <image.h>
Simon Glass691d7192020-05-10 11:40:02 -060012#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060013#include <log.h>
Peng Fand239d9d2019-09-16 03:09:55 +000014#include <spl.h>
Simon Glass401d1c42020-10-30 21:38:53 -060015#include <asm/global_data.h>
Peng Fand239d9d2019-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>
23
24#include <dm/uclass.h>
25#include <dm/device.h>
26#include <dm/uclass-internal.h>
27#include <dm/device-internal.h>
Peng Fan4e805c12021-03-19 15:57:08 +080028#include <power/pmic.h>
29#include <power/pca9450.h>
30#include <asm/mach-imx/gpio.h>
31#include <asm/mach-imx/mxc_i2c.h>
32#include <fsl_esdhc_imx.h>
33#include <mmc.h>
Peng Fand239d9d2019-09-16 03:09:55 +000034
35DECLARE_GLOBAL_DATA_PTR;
36
37int spl_board_boot_device(enum boot_device boot_dev_spl)
38{
39 return BOOT_DEVICE_BOOTROM;
40}
41
42void spl_dram_init(void)
43{
44 ddr_init(&dram_timing);
45}
46
47void spl_board_init(void)
48{
49 struct udevice *dev;
50 int ret;
51
Marek Vasut1f908b12022-09-19 21:41:15 +020052 arch_misc_init();
53
Peng Fand239d9d2019-09-16 03:09:55 +000054 puts("Normal Boot\n");
55
56 ret = uclass_get_device_by_name(UCLASS_CLK,
57 "clock-controller@30380000",
58 &dev);
59 if (ret < 0)
60 printf("Failed to find clock node. Check device tree\n");
61}
62
Peng Fan4e805c12021-03-19 15:57:08 +080063#if CONFIG_IS_ENABLED(DM_PMIC_PCA9450)
64int power_init_board(void)
65{
66 struct udevice *dev;
67 int ret;
68
Marcel Ziswiler4e5114d2022-07-21 15:43:37 +020069 ret = pmic_get("pmic@25", &dev);
Peng Fan4e805c12021-03-19 15:57:08 +080070 if (ret == -ENODEV) {
71 puts("No pca9450@25\n");
72 return 0;
73 }
74 if (ret != 0)
75 return ret;
76
77 /* BUCKxOUT_DVS0/1 control BUCK123 output */
78 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
79
Ye Li98bcdf12021-03-19 15:57:09 +080080#ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE
81 /* Set VDD_SOC/VDD_DRAM to 0.8v for low drive mode */
82 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x10);
83#else
Peng Fan4e805c12021-03-19 15:57:08 +080084 /* increase VDD_SOC/VDD_DRAM to typical value 0.95V before first DRAM access */
Ye Li98bcdf12021-03-19 15:57:09 +080085 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x1C);
86#endif
Peng Fan4e805c12021-03-19 15:57:08 +080087 /* Set DVS1 to 0.85v for suspend */
88 /* Enable DVS control through PMIC_STBY_REQ and set B1_ENMODE=1 (ON by PMIC_ON_REQ=H) */
Peng Fan4e805c12021-03-19 15:57:08 +080089 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x14);
90 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
91
92 /* set VDD_SNVS_0V8 from default 0.85V */
93 pmic_reg_write(dev, PCA9450_LDO2CTRL, 0xC0);
94
95 /* enable LDO4 to 1.2v */
96 pmic_reg_write(dev, PCA9450_LDO4CTRL, 0x44);
97
98 /* set WDOG_B_CFG to cold reset */
99 pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1);
100
101 return 0;
102}
103#endif
104
Peng Fand239d9d2019-09-16 03:09:55 +0000105#ifdef CONFIG_SPL_LOAD_FIT
106int board_fit_config_name_match(const char *name)
107{
108 /* Just empty function now - can't decide what to choose */
109 debug("%s: %s\n", __func__, name);
110
111 return 0;
112}
113#endif
114
Peng Fand239d9d2019-09-16 03:09:55 +0000115void board_init_f(ulong dummy)
116{
117 int ret;
118
119 arch_cpu_init();
120
121 init_uart_clk(1);
122
Peng Fand239d9d2019-09-16 03:09:55 +0000123 timer_init();
124
Peng Fand239d9d2019-09-16 03:09:55 +0000125 /* Clear the BSS. */
126 memset(__bss_start, 0, __bss_end - __bss_start);
127
128 ret = spl_init();
129 if (ret) {
130 debug("spl_init() failed: %d\n", ret);
131 hang();
132 }
133
Peng Fana4977402022-04-15 12:35:35 +0800134 preloader_console_init();
135
Peng Fand239d9d2019-09-16 03:09:55 +0000136 enable_tzc380();
137
138 /* DDR initialization */
139 spl_dram_init();
140
141 board_init_r(NULL, 0);
142}