blob: 19c1acd8a5254da7bcd8348da2e7cec62cca574f [file] [log] [blame]
Ying-Chun Liu (PaulLiu)a97107f2021-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>
Shiji Yangbb112342023-08-03 09:47:16 +080024#include <asm/sections.h>
Ying-Chun Liu (PaulLiu)a97107f2021-04-22 04:50:31 +080025
26#include <dm/uclass.h>
27#include <dm/device.h>
28#include <dm/uclass-internal.h>
29#include <dm/device-internal.h>
30
31#include <power/pmic.h>
32#include <power/bd71837.h>
33
34#include "ddr/ddr.h"
35
36DECLARE_GLOBAL_DATA_PTR;
37
38int spl_board_boot_device(enum boot_device boot_dev_spl)
39{
40 switch (boot_dev_spl) {
41 case SD2_BOOT:
42 case MMC2_BOOT:
43 return BOOT_DEVICE_MMC1;
44 case SD3_BOOT:
45 case MMC3_BOOT:
46 return BOOT_DEVICE_MMC2;
47 default:
48 return BOOT_DEVICE_NONE;
49 }
50}
51
52#define I2C_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PE)
53#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
54struct i2c_pads_info i2c_pad_info1 = {
55 .scl = {
56 .i2c_mode = IMX8MM_PAD_I2C2_SCL_I2C2_SCL | PC,
57 .gpio_mode = IMX8MM_PAD_I2C2_SCL_GPIO5_IO16 | PC,
58 .gp = IMX_GPIO_NR(5, 16),
59 },
60 .sda = {
61 .i2c_mode = IMX8MM_PAD_I2C2_SDA_I2C2_SDA | PC,
62 .gpio_mode = IMX8MM_PAD_I2C2_SDA_GPIO5_IO17 | PC,
63 .gp = IMX_GPIO_NR(5, 17),
64 },
65};
66
67static void spl_dram_init(void)
68{
69 spl_dram_init_compulab();
70}
71
72void spl_board_init(void)
73{
74 puts("Normal Boot\n");
75}
76
77#ifdef CONFIG_SPL_LOAD_FIT
78int board_fit_config_name_match(const char *name)
79{
80 /* Just empty function now - can't decide what to choose */
81 debug("%s: %s\n", __func__, name);
82
83 return 0;
84}
85#endif
86
Ying-Chun Liu (PaulLiu)a97107f2021-04-22 04:50:31 +080087static int power_init_board(void)
88{
89 struct udevice *dev;
90 int ret;
91
92 ret = pmic_get("pmic@4b", &dev);
93 if (ret == -ENODEV) {
94 puts("No pmic\n");
95 return 0;
96 }
97 if (ret != 0)
98 return ret;
99
100 /* decrease RESET key long push time from the default 10s to 10ms */
101 pmic_reg_write(dev, BD718XX_PWRONCONFIG1, 0x0);
102
103 /* unlock the PMIC regs */
104 pmic_reg_write(dev, BD718XX_REGLOCK, 0x1);
105
106 /* increase VDD_SOC to typical value 0.85v before first DRAM access */
107 pmic_reg_write(dev, BD718XX_BUCK1_VOLT_RUN, 0x0f);
108
109 /* increase VDD_DRAM to 0.975v for 3Ghz DDR */
110 pmic_reg_write(dev, BD718XX_1ST_NODVS_BUCK_VOLT, 0x83);
111
112 /* increase NVCC_DRAM_1V2 to 1.2v for DDR4 */
113 pmic_reg_write(dev, BD718XX_4TH_NODVS_BUCK_VOLT, 0x28);
114
115 /* lock the PMIC regs */
116 pmic_reg_write(dev, BD718XX_REGLOCK, 0x11);
117
118 return 0;
119}
120
121void board_init_f(ulong dummy)
122{
123 struct udevice *dev;
124 int ret;
125
126 arch_cpu_init();
127
Ying-Chun Liu (PaulLiu)a97107f2021-04-22 04:50:31 +0800128 init_uart_clk(2);
129
130 timer_init();
131
Ying-Chun Liu (PaulLiu)a97107f2021-04-22 04:50:31 +0800132 /* Clear the BSS. */
133 memset(__bss_start, 0, __bss_end - __bss_start);
134
135 ret = spl_early_init();
136 if (ret) {
137 debug("spl_early_init() failed: %d\n", ret);
138 hang();
139 }
140
Peng Fan12621ce2022-06-11 20:20:56 +0800141 preloader_console_init();
142
Ying-Chun Liu (PaulLiu)a97107f2021-04-22 04:50:31 +0800143 ret = uclass_get_device_by_name(UCLASS_CLK,
144 "clock-controller@30380000",
145 &dev);
146 if (ret < 0) {
147 printf("Failed to find clock node. Check device tree\n");
148 hang();
149 }
150
151 enable_tzc380();
152
Tom Rinia6e29232021-08-18 23:12:32 -0400153 setup_i2c(1, 100000, 0x7f, &i2c_pad_info1);
Ying-Chun Liu (PaulLiu)a97107f2021-04-22 04:50:31 +0800154
155 power_init_board();
156
157 /* DDR initialization */
158 spl_dram_init();
159
160 board_init_r(NULL, 0);
161}