blob: a93cc9387842455d77752327a07ab060fff1247f [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 -050062static int power_init_board(void)
63{
64 struct udevice *dev;
65 int ret;
66
67 ret = pmic_get("pmic@4b", &dev);
68 if (ret == -ENODEV) {
69 puts("No pmic\n");
70 return 0;
71 }
72 if (ret != 0)
73 return ret;
74
75 /* decrease RESET key long push time from the default 10s to 10ms */
76 pmic_reg_write(dev, BD718XX_PWRONCONFIG1, 0x0);
77
78 /* unlock the PMIC regs */
79 pmic_reg_write(dev, BD718XX_REGLOCK, 0x1);
80
81 /* increase VDD_SOC to typical value 0.85v before first DRAM access */
82 pmic_reg_write(dev, BD718XX_BUCK1_VOLT_RUN, 0x0f);
83
84 /* increase VDD_DRAM to 0.975v for 3Ghz DDR */
85 pmic_reg_write(dev, BD718XX_1ST_NODVS_BUCK_VOLT, 0x83);
86
87 /* lock the PMIC regs */
88 pmic_reg_write(dev, BD718XX_REGLOCK, 0x11);
89
90 return 0;
91}
92
93void board_init_f(ulong dummy)
94{
95 struct udevice *dev;
96 int ret;
97
98 arch_cpu_init();
99
100 init_uart_clk(1);
101
Adam Ford14879032020-05-03 08:11:33 -0500102 timer_init();
103
Adam Ford14879032020-05-03 08:11:33 -0500104 /* Clear the BSS. */
105 memset(__bss_start, 0, __bss_end - __bss_start);
106
107 ret = spl_early_init();
108 if (ret) {
109 debug("spl_early_init() failed: %d\n", ret);
110 hang();
111 }
112
Peng Fana9ed59c2022-06-11 20:20:55 +0800113 preloader_console_init();
114
Adam Ford14879032020-05-03 08:11:33 -0500115 ret = uclass_get_device_by_name(UCLASS_CLK,
116 "clock-controller@30380000",
117 &dev);
118 if (ret < 0) {
119 printf("Failed to find clock node. Check device tree\n");
120 hang();
121 }
122
123 enable_tzc380();
124
125 power_init_board();
126
127 /* DDR initialization */
128 spl_dram_init();
129
130 board_init_r(NULL, 0);
131}