blob: f92b4c3ed0abc8cd9b2df770ea7748e88a003848 [file] [log] [blame]
Adam Ford14879032020-05-03 08:11:33 -05001// SPDX-License-Identifier: GPL-2.0+
2
3#include <common.h>
4#include <cpu_func.h>
5#include <hang.h>
Simon Glass97589732020-05-10 11:40:02 -06006#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Adam Ford14879032020-05-03 08:11:33 -05008#include <spl.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06009#include <asm/global_data.h>
Adam Ford14879032020-05-03 08:11:33 -050010#include <asm/io.h>
11#include <asm/mach-imx/iomux-v3.h>
12#include <asm/arch/clock.h>
13#include <asm/arch/imx8mm_pins.h>
14#include <asm/arch/sys_proto.h>
15#include <asm/mach-imx/boot_mode.h>
16#include <asm/arch/ddr.h>
17
18#include <dm/uclass.h>
19#include <dm/device.h>
20#include <dm/uclass-internal.h>
21#include <dm/device-internal.h>
22
23#include <power/pmic.h>
24#include <power/bd71837.h>
25
26DECLARE_GLOBAL_DATA_PTR;
27
28int spl_board_boot_device(enum boot_device boot_dev_spl)
29{
30 switch (boot_dev_spl) {
31 case SD2_BOOT:
32 case MMC2_BOOT:
33 return BOOT_DEVICE_MMC1;
34 case SD3_BOOT:
35 case MMC3_BOOT:
36 return BOOT_DEVICE_MMC2;
37 default:
38 return BOOT_DEVICE_NONE;
39 }
40}
41
42static void spl_dram_init(void)
43{
44 ddr_init(&dram_timing);
45}
46
47void spl_board_init(void)
48{
49 debug("Normal Boot\n");
50}
51
52#ifdef CONFIG_SPL_LOAD_FIT
53int board_fit_config_name_match(const char *name)
54{
55 /* Just empty function now - can't decide what to choose */
56 debug("%s: %s\n", __func__, name);
57
58 return 0;
59}
60#endif
61
Adam Ford14879032020-05-03 08:11:33 -050062#define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
63
Adam Ford14879032020-05-03 08:11:33 -050064static iomux_v3_cfg_t const wdog_pads[] = {
65 IMX8MM_PAD_GPIO1_IO02_WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
66};
67
68int board_early_init_f(void)
69{
70 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
71
72 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
73
74 set_wdog_reset(wdog);
75
Adam Ford14879032020-05-03 08:11:33 -050076 return 0;
77}
78
79static int power_init_board(void)
80{
81 struct udevice *dev;
82 int ret;
83
84 ret = pmic_get("pmic@4b", &dev);
85 if (ret == -ENODEV) {
86 puts("No pmic\n");
87 return 0;
88 }
89 if (ret != 0)
90 return ret;
91
92 /* decrease RESET key long push time from the default 10s to 10ms */
93 pmic_reg_write(dev, BD718XX_PWRONCONFIG1, 0x0);
94
95 /* unlock the PMIC regs */
96 pmic_reg_write(dev, BD718XX_REGLOCK, 0x1);
97
98 /* increase VDD_SOC to typical value 0.85v before first DRAM access */
99 pmic_reg_write(dev, BD718XX_BUCK1_VOLT_RUN, 0x0f);
100
101 /* increase VDD_DRAM to 0.975v for 3Ghz DDR */
102 pmic_reg_write(dev, BD718XX_1ST_NODVS_BUCK_VOLT, 0x83);
103
104 /* lock the PMIC regs */
105 pmic_reg_write(dev, BD718XX_REGLOCK, 0x11);
106
107 return 0;
108}
109
110void board_init_f(ulong dummy)
111{
112 struct udevice *dev;
113 int ret;
114
115 arch_cpu_init();
116
117 init_uart_clk(1);
118
119 board_early_init_f();
120
121 timer_init();
122
Adam Ford14879032020-05-03 08:11:33 -0500123 /* Clear the BSS. */
124 memset(__bss_start, 0, __bss_end - __bss_start);
125
126 ret = spl_early_init();
127 if (ret) {
128 debug("spl_early_init() failed: %d\n", ret);
129 hang();
130 }
131
Peng Fana9ed59c2022-06-11 20:20:55 +0800132 preloader_console_init();
133
Adam Ford14879032020-05-03 08:11:33 -0500134 ret = uclass_get_device_by_name(UCLASS_CLK,
135 "clock-controller@30380000",
136 &dev);
137 if (ret < 0) {
138 printf("Failed to find clock node. Check device tree\n");
139 hang();
140 }
141
142 enable_tzc380();
143
144 power_init_board();
145
146 /* DDR initialization */
147 spl_dram_init();
148
149 board_init_r(NULL, 0);
150}