1
2
3
4
5
6
7
8
9#include <spl.h>
10#include <asm/io.h>
11#include <asm/arch/hardware.h>
12#include <asm/arch/sysfw-loader.h>
13#include "common.h"
14#include <dm.h>
15#include <dm/uclass-internal.h>
16#include <dm/pinctrl.h>
17
18
19
20
21
22
23u32 bootindex __section(".data");
24static struct rom_extended_boot_data bootdata __section(".data");
25
26static void store_boot_info_from_rom(void)
27{
28 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
29 memcpy(&bootdata, (uintptr_t *)ROM_ENTENDED_BOOT_DATA_INFO,
30 sizeof(struct rom_extended_boot_data));
31}
32
33static void ctrl_mmr_unlock(void)
34{
35
36 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
37 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
38 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
39 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
40 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
41 mmr_unlock(WKUP_CTRL_MMR0_BASE, 5);
42 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
43 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
44
45
46 mmr_unlock(CTRL_MMR0_BASE, 0);
47 mmr_unlock(CTRL_MMR0_BASE, 1);
48 mmr_unlock(CTRL_MMR0_BASE, 2);
49 mmr_unlock(CTRL_MMR0_BASE, 4);
50 mmr_unlock(CTRL_MMR0_BASE, 6);
51
52
53 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
54 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
55 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
56 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
57 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
58 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
59
60
61 mmr_unlock(PADCFG_MMR0_BASE, 1);
62 mmr_unlock(PADCFG_MMR1_BASE, 1);
63}
64
65static __maybe_unused void enable_mcu_esm_reset(void)
66{
67
68 u32 stat = readl(CTRLMMR_MCU_RST_CTRL);
69
70 stat &= RST_CTRL_ESM_ERROR_RST_EN_Z_MASK;
71 writel(stat, CTRLMMR_MCU_RST_CTRL);
72}
73
74void board_init_f(ulong dummy)
75{
76 struct udevice *dev;
77 int ret;
78
79#if defined(CONFIG_CPU_V7R)
80 setup_k3_mpu_regions();
81#endif
82
83
84
85
86
87 store_boot_info_from_rom();
88
89 ctrl_mmr_unlock();
90
91
92 spl_early_init();
93
94
95
96
97
98
99
100
101
102
103 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
104 if (!ret)
105 pinctrl_select_state(dev, "default");
106
107 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 3, &dev);
108 if (!ret)
109 pinctrl_select_state(dev, "default");
110
111 preloader_console_init();
112
113#ifdef CONFIG_K3_EARLY_CONS
114
115
116
117
118
119
120 early_console_init();
121#endif
122
123#if defined(CONFIG_K3_LOAD_SYSFW)
124
125
126
127
128
129
130 ret = is_rom_loaded_sysfw(&bootdata);
131 if (!ret)
132 panic("ROM has not loaded TIFS firmware\n");
133
134 k3_sysfw_loader(true, NULL, NULL);
135#endif
136
137
138
139
140
141 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
142 ret = uclass_get_device_by_driver(UCLASS_CLK,
143 DM_DRIVER_GET(ti_clk),
144 &dev);
145 if (ret)
146 printf("Failed to initialize clk-k3!\n");
147 }
148
149
150 k3_sysfw_print_ver();
151
152 if (IS_ENABLED(CONFIG_ESM_K3)) {
153
154 ret = uclass_get_device_by_name(UCLASS_MISC, "esm@420000", &dev);
155 if (ret)
156 printf("esm main init failed: %d\n", ret);
157
158
159 ret = uclass_get_device_by_name(UCLASS_MISC, "esm@4100000", &dev);
160 if (ret)
161 printf("esm mcu init failed: %d\n", ret);
162
163 enable_mcu_esm_reset();
164 }
165
166#if defined(CONFIG_K3_AM64_DDRSS)
167 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
168 if (ret)
169 panic("DRAM init failed: %d\n", ret);
170#endif
171}
172
173u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
174{
175 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
176 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
177 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
178
179 switch (boot_device) {
180 case BOOT_DEVICE_MMC1:
181 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_FS_RAW_MASK) >>
182 MAIN_DEVSTAT_PRIMARY_MMC_FS_RAW_SHIFT)
183 return MMCSD_MODE_EMMCBOOT;
184 return MMCSD_MODE_FS;
185
186 case BOOT_DEVICE_MMC2:
187 return MMCSD_MODE_FS;
188
189 default:
190 return MMCSD_MODE_RAW;
191 }
192}
193
194static u32 __get_backup_bootmedia(u32 devstat)
195{
196 u32 bkup_bootmode = (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
197 MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT;
198 u32 bkup_bootmode_cfg =
199 (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >>
200 MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT;
201
202 switch (bkup_bootmode) {
203 case BACKUP_BOOT_DEVICE_UART:
204 return BOOT_DEVICE_UART;
205
206 case BACKUP_BOOT_DEVICE_USB:
207 return BOOT_DEVICE_USB;
208
209 case BACKUP_BOOT_DEVICE_ETHERNET:
210 return BOOT_DEVICE_ETHERNET;
211
212 case BACKUP_BOOT_DEVICE_MMC:
213 if (bkup_bootmode_cfg)
214 return BOOT_DEVICE_MMC2;
215 return BOOT_DEVICE_MMC1;
216
217 case BACKUP_BOOT_DEVICE_SPI:
218 return BOOT_DEVICE_SPI;
219
220 case BACKUP_BOOT_DEVICE_I2C:
221 return BOOT_DEVICE_I2C;
222
223 case BACKUP_BOOT_DEVICE_DFU:
224 if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE_MASK)
225 return BOOT_DEVICE_USB;
226 return BOOT_DEVICE_DFU;
227 };
228
229 return BOOT_DEVICE_RAM;
230}
231
232static u32 __get_primary_bootmedia(u32 devstat)
233{
234 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
235 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
236 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
237 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
238
239 switch (bootmode) {
240 case BOOT_DEVICE_OSPI:
241 fallthrough;
242 case BOOT_DEVICE_QSPI:
243 fallthrough;
244 case BOOT_DEVICE_XSPI:
245 fallthrough;
246 case BOOT_DEVICE_SPI:
247 return BOOT_DEVICE_SPI;
248
249 case BOOT_DEVICE_ETHERNET_RGMII:
250 fallthrough;
251 case BOOT_DEVICE_ETHERNET_RMII:
252 return BOOT_DEVICE_ETHERNET;
253
254 case BOOT_DEVICE_EMMC:
255 return BOOT_DEVICE_MMC1;
256
257 case BOOT_DEVICE_MMC:
258 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >>
259 MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT)
260 return BOOT_DEVICE_MMC2;
261 return BOOT_DEVICE_MMC1;
262
263 case BOOT_DEVICE_DFU:
264 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE_MASK) >>
265 MAIN_DEVSTAT_PRIMARY_USB_MODE_SHIFT)
266 return BOOT_DEVICE_USB;
267 return BOOT_DEVICE_DFU;
268
269 case BOOT_DEVICE_NOBOOT:
270 return BOOT_DEVICE_RAM;
271 }
272
273 return bootmode;
274}
275
276u32 spl_boot_device(void)
277{
278 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
279 u32 bootmedia;
280
281 if (bootindex == K3_PRIMARY_BOOTMODE)
282 bootmedia = __get_primary_bootmedia(devstat);
283 else
284 bootmedia = __get_backup_bootmedia(devstat);
285
286 debug("am625_init: %s: devstat = 0x%x bootmedia = 0x%x bootindex = %d\n",
287 __func__, devstat, bootmedia, bootindex);
288
289 return bootmedia;
290}
291