blob: 03f2a56e805efeb3e6829121ffaf3d014b8fbd67 [file] [log] [blame]
Peng Fana181afe2019-09-16 03:09:55 +00001/*
2 * Copyright 2018-2019 NXP
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
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>
23
24#include <dm/uclass.h>
25#include <dm/device.h>
26#include <dm/uclass-internal.h>
27#include <dm/device-internal.h>
Peng Fan80607bf2021-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 Fana181afe2019-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
52 puts("Normal Boot\n");
53
54 ret = uclass_get_device_by_name(UCLASS_CLK,
55 "clock-controller@30380000",
56 &dev);
57 if (ret < 0)
58 printf("Failed to find clock node. Check device tree\n");
59}
60
Peng Fan80607bf2021-03-19 15:57:08 +080061#if CONFIG_IS_ENABLED(DM_PMIC_PCA9450)
62int power_init_board(void)
63{
64 struct udevice *dev;
65 int ret;
66
67 ret = pmic_get("pca9450@25", &dev);
68 if (ret == -ENODEV) {
69 puts("No pca9450@25\n");
70 return 0;
71 }
72 if (ret != 0)
73 return ret;
74
75 /* BUCKxOUT_DVS0/1 control BUCK123 output */
76 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
77
Ye Liee337ce2021-03-19 15:57:09 +080078#ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE
79 /* Set VDD_SOC/VDD_DRAM to 0.8v for low drive mode */
80 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x10);
81#else
Peng Fan80607bf2021-03-19 15:57:08 +080082 /* increase VDD_SOC/VDD_DRAM to typical value 0.95V before first DRAM access */
Ye Liee337ce2021-03-19 15:57:09 +080083 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x1C);
84#endif
Peng Fan80607bf2021-03-19 15:57:08 +080085 /* Set DVS1 to 0.85v for suspend */
86 /* 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 +080087 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x14);
88 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
89
90 /* set VDD_SNVS_0V8 from default 0.85V */
91 pmic_reg_write(dev, PCA9450_LDO2CTRL, 0xC0);
92
93 /* enable LDO4 to 1.2v */
94 pmic_reg_write(dev, PCA9450_LDO4CTRL, 0x44);
95
96 /* set WDOG_B_CFG to cold reset */
97 pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1);
98
99 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
113#define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1)
114#define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
115
116static iomux_v3_cfg_t const uart_pads[] = {
117 IMX8MN_PAD_UART2_RXD__UART2_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
118 IMX8MN_PAD_UART2_TXD__UART2_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
119};
120
121static iomux_v3_cfg_t const wdog_pads[] = {
122 IMX8MN_PAD_GPIO1_IO02__WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
123};
124
125int board_early_init_f(void)
126{
127 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
128
129 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
130
131 set_wdog_reset(wdog);
132
133 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
134
Peng Fana181afe2019-09-16 03:09:55 +0000135 return 0;
136}
137
138void board_init_f(ulong dummy)
139{
140 int ret;
141
142 arch_cpu_init();
143
144 init_uart_clk(1);
145
146 board_early_init_f();
147
148 timer_init();
149
150 preloader_console_init();
151
152 /* Clear the BSS. */
153 memset(__bss_start, 0, __bss_end - __bss_start);
154
155 ret = spl_init();
156 if (ret) {
157 debug("spl_init() failed: %d\n", ret);
158 hang();
159 }
160
161 enable_tzc380();
162
163 /* DDR initialization */
164 spl_dram_init();
165
166 board_init_r(NULL, 0);
167}