blob: f183704c9d2f3be74e6a76115a30677474fe2721 [file] [log] [blame]
Ying-Chun Liu (PaulLiu)53b516c2021-04-22 04:50:31 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 NXP
4 * Copyright 2020 Linaro
5 */
6
7#include <common.h>
8#include <command.h>
9#include <cpu_func.h>
10#include <hang.h>
11#include <image.h>
12#include <init.h>
13#include <log.h>
14#include <spl.h>
15#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/mach-imx/mxc_i2c.h>
22#include <asm/mach-imx/gpio.h>
23#include <asm/arch/ddr.h>
24
25#include <dm/uclass.h>
26#include <dm/device.h>
27#include <dm/uclass-internal.h>
28#include <dm/device-internal.h>
29
30#include <power/pmic.h>
31#include <power/bd71837.h>
32
33#include "ddr/ddr.h"
34
35DECLARE_GLOBAL_DATA_PTR;
36
37int spl_board_boot_device(enum boot_device boot_dev_spl)
38{
39 switch (boot_dev_spl) {
40 case SD2_BOOT:
41 case MMC2_BOOT:
42 return BOOT_DEVICE_MMC1;
43 case SD3_BOOT:
44 case MMC3_BOOT:
45 return BOOT_DEVICE_MMC2;
46 default:
47 return BOOT_DEVICE_NONE;
48 }
49}
50
51#define I2C_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PE)
52#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
53struct i2c_pads_info i2c_pad_info1 = {
54 .scl = {
55 .i2c_mode = IMX8MM_PAD_I2C2_SCL_I2C2_SCL | PC,
56 .gpio_mode = IMX8MM_PAD_I2C2_SCL_GPIO5_IO16 | PC,
57 .gp = IMX_GPIO_NR(5, 16),
58 },
59 .sda = {
60 .i2c_mode = IMX8MM_PAD_I2C2_SDA_I2C2_SDA | PC,
61 .gpio_mode = IMX8MM_PAD_I2C2_SDA_GPIO5_IO17 | PC,
62 .gp = IMX_GPIO_NR(5, 17),
63 },
64};
65
66static void spl_dram_init(void)
67{
68 spl_dram_init_compulab();
69}
70
71void spl_board_init(void)
72{
73 puts("Normal Boot\n");
74}
75
76#ifdef CONFIG_SPL_LOAD_FIT
77int board_fit_config_name_match(const char *name)
78{
79 /* Just empty function now - can't decide what to choose */
80 debug("%s: %s\n", __func__, name);
81
82 return 0;
83}
84#endif
85
Ying-Chun Liu (PaulLiu)53b516c2021-04-22 04:50:31 +080086#define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
87
Ying-Chun Liu (PaulLiu)53b516c2021-04-22 04:50:31 +080088static iomux_v3_cfg_t const wdog_pads[] = {
89 IMX8MM_PAD_GPIO1_IO02_WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
90};
91
92int board_early_init_f(void)
93{
94 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
95
96 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
97
98 set_wdog_reset(wdog);
99
Ying-Chun Liu (PaulLiu)53b516c2021-04-22 04:50:31 +0800100 return 0;
101}
102
103static int power_init_board(void)
104{
105 struct udevice *dev;
106 int ret;
107
108 ret = pmic_get("pmic@4b", &dev);
109 if (ret == -ENODEV) {
110 puts("No pmic\n");
111 return 0;
112 }
113 if (ret != 0)
114 return ret;
115
116 /* decrease RESET key long push time from the default 10s to 10ms */
117 pmic_reg_write(dev, BD718XX_PWRONCONFIG1, 0x0);
118
119 /* unlock the PMIC regs */
120 pmic_reg_write(dev, BD718XX_REGLOCK, 0x1);
121
122 /* increase VDD_SOC to typical value 0.85v before first DRAM access */
123 pmic_reg_write(dev, BD718XX_BUCK1_VOLT_RUN, 0x0f);
124
125 /* increase VDD_DRAM to 0.975v for 3Ghz DDR */
126 pmic_reg_write(dev, BD718XX_1ST_NODVS_BUCK_VOLT, 0x83);
127
128 /* increase NVCC_DRAM_1V2 to 1.2v for DDR4 */
129 pmic_reg_write(dev, BD718XX_4TH_NODVS_BUCK_VOLT, 0x28);
130
131 /* lock the PMIC regs */
132 pmic_reg_write(dev, BD718XX_REGLOCK, 0x11);
133
134 return 0;
135}
136
137void board_init_f(ulong dummy)
138{
139 struct udevice *dev;
140 int ret;
141
142 arch_cpu_init();
143
144 board_early_init_f();
145
146 init_uart_clk(2);
147
148 timer_init();
149
Ying-Chun Liu (PaulLiu)53b516c2021-04-22 04:50:31 +0800150 /* Clear the BSS. */
151 memset(__bss_start, 0, __bss_end - __bss_start);
152
153 ret = spl_early_init();
154 if (ret) {
155 debug("spl_early_init() failed: %d\n", ret);
156 hang();
157 }
158
Peng Fan37750502022-06-11 20:20:56 +0800159 preloader_console_init();
160
Ying-Chun Liu (PaulLiu)53b516c2021-04-22 04:50:31 +0800161 ret = uclass_get_device_by_name(UCLASS_CLK,
162 "clock-controller@30380000",
163 &dev);
164 if (ret < 0) {
165 printf("Failed to find clock node. Check device tree\n");
166 hang();
167 }
168
169 enable_tzc380();
170
Tom Rinia5752f82021-08-18 23:12:32 -0400171 setup_i2c(1, 100000, 0x7f, &i2c_pad_info1);
Ying-Chun Liu (PaulLiu)53b516c2021-04-22 04:50:31 +0800172
173 power_init_board();
174
175 /* DDR initialization */
176 spl_dram_init();
177
178 board_init_r(NULL, 0);
179}