blob: dfa81a0d652c86bfde55684244686d4f28c003f4 [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
Gaurav Jain2cddfcb2022-03-24 11:50:27 +053052 if (IS_ENABLED(CONFIG_FSL_CAAM)) {
53 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev);
54 if (ret)
55 printf("Failed to initialize %s: %d\n", dev->name, ret);
56 }
Peng Fand239d9d2019-09-16 03:09:55 +000057 puts("Normal Boot\n");
58
59 ret = uclass_get_device_by_name(UCLASS_CLK,
60 "clock-controller@30380000",
61 &dev);
62 if (ret < 0)
63 printf("Failed to find clock node. Check device tree\n");
64}
65
Peng Fan4e805c12021-03-19 15:57:08 +080066#if CONFIG_IS_ENABLED(DM_PMIC_PCA9450)
67int power_init_board(void)
68{
69 struct udevice *dev;
70 int ret;
71
72 ret = pmic_get("pca9450@25", &dev);
73 if (ret == -ENODEV) {
74 puts("No pca9450@25\n");
75 return 0;
76 }
77 if (ret != 0)
78 return ret;
79
80 /* BUCKxOUT_DVS0/1 control BUCK123 output */
81 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
82
Ye Li98bcdf12021-03-19 15:57:09 +080083#ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE
84 /* Set VDD_SOC/VDD_DRAM to 0.8v for low drive mode */
85 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x10);
86#else
Peng Fan4e805c12021-03-19 15:57:08 +080087 /* increase VDD_SOC/VDD_DRAM to typical value 0.95V before first DRAM access */
Ye Li98bcdf12021-03-19 15:57:09 +080088 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x1C);
89#endif
Peng Fan4e805c12021-03-19 15:57:08 +080090 /* Set DVS1 to 0.85v for suspend */
91 /* 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 +080092 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x14);
93 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
94
95 /* set VDD_SNVS_0V8 from default 0.85V */
96 pmic_reg_write(dev, PCA9450_LDO2CTRL, 0xC0);
97
98 /* enable LDO4 to 1.2v */
99 pmic_reg_write(dev, PCA9450_LDO4CTRL, 0x44);
100
101 /* set WDOG_B_CFG to cold reset */
102 pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1);
103
104 return 0;
105}
106#endif
107
Peng Fand239d9d2019-09-16 03:09:55 +0000108#ifdef CONFIG_SPL_LOAD_FIT
109int board_fit_config_name_match(const char *name)
110{
111 /* Just empty function now - can't decide what to choose */
112 debug("%s: %s\n", __func__, name);
113
114 return 0;
115}
116#endif
117
118#define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1)
119#define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
120
121static iomux_v3_cfg_t const uart_pads[] = {
122 IMX8MN_PAD_UART2_RXD__UART2_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
123 IMX8MN_PAD_UART2_TXD__UART2_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
124};
125
126static iomux_v3_cfg_t const wdog_pads[] = {
127 IMX8MN_PAD_GPIO1_IO02__WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
128};
129
130int board_early_init_f(void)
131{
132 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
133
134 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
135
136 set_wdog_reset(wdog);
137
138 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
139
Peng Fand239d9d2019-09-16 03:09:55 +0000140 return 0;
141}
142
143void board_init_f(ulong dummy)
144{
145 int ret;
146
147 arch_cpu_init();
148
149 init_uart_clk(1);
150
151 board_early_init_f();
152
153 timer_init();
154
155 preloader_console_init();
156
157 /* Clear the BSS. */
158 memset(__bss_start, 0, __bss_end - __bss_start);
159
160 ret = spl_init();
161 if (ret) {
162 debug("spl_init() failed: %d\n", ret);
163 hang();
164 }
165
166 enable_tzc380();
167
168 /* DDR initialization */
169 spl_dram_init();
170
171 board_init_r(NULL, 0);
172}