1
2
3
4
5
6#include <common.h>
7#include <hang.h>
8#include <image.h>
9#include <init.h>
10#include <spl.h>
11#include <asm/io.h>
12#include <asm-generic/gpio.h>
13#include <asm/arch/clock.h>
14#include <asm/arch/imx8mp_pins.h>
15#include <asm/arch/sys_proto.h>
16#include <asm/mach-imx/boot_mode.h>
17#include <asm/arch/ddr.h>
18
19#include <dm/uclass.h>
20#include <dm/device.h>
21#include <dm/uclass-internal.h>
22#include <dm/device-internal.h>
23
24#include <power/pmic.h>
25#include <power/pca9450.h>
26
27#include "lpddr4_timing.h"
28
29DECLARE_GLOBAL_DATA_PTR;
30
31#define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1)
32#define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
33
34static const iomux_v3_cfg_t uart_pads[] = {
35 MX8MP_PAD_SAI2_RXFS__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
36 MX8MP_PAD_SAI2_RXC__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
37};
38
39static const iomux_v3_cfg_t wdog_pads[] = {
40 MX8MP_PAD_GPIO1_IO02__WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
41};
42
43static void dh_imx8mp_early_init_f(void)
44{
45 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
46
47 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
48
49 set_wdog_reset(wdog);
50
51 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
52}
53
54static int dh_imx8mp_board_power_init(void)
55{
56 struct udevice *dev;
57 int ret;
58
59 ret = pmic_get("pmic@25", &dev);
60 if (ret == -ENODEV) {
61 puts("Failed to get PMIC\n");
62 return 0;
63 }
64 if (ret != 0)
65 return ret;
66
67
68 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
69
70
71 if (IS_ENABLED(CONFIG_IMX8M_VDD_SOC_850MV))
72
73 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x14);
74 else
75 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x1c);
76
77
78 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x14);
79
80
81
82
83
84 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
85
86
87
88
89 pmic_reg_write(dev, PCA9450_BUCK2OUT_DVS0, 0x1c);
90
91
92 pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1);
93
94
95 pmic_reg_write(dev, PCA9450_LDO4CTRL, 0x59);
96 pmic_reg_write(dev, PCA9450_CONFIG2, 0x1);
97
98 return 0;
99}
100
101static struct dram_timing_info *dram_timing_info[8] = {
102 NULL,
103 NULL,
104 NULL,
105 NULL,
106 NULL,
107 &dh_imx8mp_dhcom_dram_timing_32g_x32,
108 NULL,
109 NULL,
110};
111
112static void spl_dram_init(void)
113{
114 const u16 size[] = { 512, 1024, 1536, 2048, 3072, 4096, 6144, 8192 };
115 u8 memcfg = dh_get_memcfg();
116 int i;
117
118 printf("DDR: %d MiB [0x%x]\n", size[memcfg], memcfg);
119
120 if (!dram_timing_info[memcfg]) {
121 printf("Unsupported DRAM strapping, trying lowest supported. MEMCFG=0x%x\n",
122 memcfg);
123 for (i = 0; i < ARRAY_SIZE(dram_timing_info); i++)
124 if (dram_timing_info[i])
125 break;
126 }
127
128 ddr_init(dram_timing_info[memcfg]);
129}
130
131void spl_board_init(void)
132{
133
134
135
136
137
138
139 clock_enable(CCGR_GIC, 0);
140 clock_set_target_val(GIC_CLK_ROOT, CLK_ROOT_ON | CLK_ROOT_SOURCE_SEL(5));
141 clock_enable(CCGR_GIC, 1);
142}
143
144int spl_board_boot_device(enum boot_device boot_dev_spl)
145{
146 return BOOT_DEVICE_BOOTROM;
147}
148
149void board_init_f(ulong dummy)
150{
151 struct udevice *dev;
152 int ret;
153
154 arch_cpu_init();
155
156 init_uart_clk(0);
157
158 dh_imx8mp_early_init_f();
159
160 preloader_console_init();
161
162
163 memset(__bss_start, 0, __bss_end - __bss_start);
164
165 ret = spl_early_init();
166 if (ret) {
167 debug("spl_early_init() failed: %d\n", ret);
168 hang();
169 }
170
171 ret = uclass_get_device_by_name(UCLASS_CLK,
172 "clock-controller@30380000",
173 &dev);
174 if (ret < 0) {
175 printf("Failed to find clock node. Check device tree\n");
176 hang();
177 }
178
179 enable_tzc380();
180
181 dh_imx8mp_board_power_init();
182
183
184 spl_dram_init();
185
186 board_init_r(NULL, 0);
187}
188