1 // SPDX-License-Identifier: GPL-2.0
3 * AM642: SoC specific initialization
5 * Copyright (C) 2020-2021 Texas Instruments Incorporated - https://www.ti.com/
11 #include <fdt_support.h>
14 #include <asm/arch/hardware.h>
15 #include <asm/arch/sysfw-loader.h>
16 #include <asm/arch/sys_proto.h>
18 #include <asm/arch/sys_proto.h>
19 #include <linux/soc/ti/ti_sci_protocol.h>
21 #include <dm/uclass-internal.h>
22 #include <dm/pinctrl.h>
26 #if defined(CONFIG_SPL_BUILD)
28 static void ctrl_mmr_unlock(void)
30 /* Unlock all PADCFG_MMR1 module registers */
31 mmr_unlock(PADCFG_MMR1_BASE, 1);
33 /* Unlock all CTRL_MMR0 module registers */
34 mmr_unlock(CTRL_MMR0_BASE, 0);
35 mmr_unlock(CTRL_MMR0_BASE, 1);
36 mmr_unlock(CTRL_MMR0_BASE, 2);
37 mmr_unlock(CTRL_MMR0_BASE, 3);
38 mmr_unlock(CTRL_MMR0_BASE, 5);
39 mmr_unlock(CTRL_MMR0_BASE, 6);
41 /* Unlock all MCU_PADCFG_MMR1 module registers */
42 mmr_unlock(MCU_PADCFG_MMR1_BASE, 1);
46 * This uninitialized global variable would normal end up in the .bss section,
47 * but the .bss is cleared between writing and reading this variable, so move
48 * it to the .data section.
50 u32 bootindex __section(".data");
51 static struct rom_extended_boot_data bootdata __section(".data");
53 static void store_boot_info_from_rom(void)
55 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
56 memcpy(&bootdata, (uintptr_t *)ROM_ENTENDED_BOOT_DATA_INFO,
57 sizeof(struct rom_extended_boot_data));
60 #if defined(CONFIG_K3_LOAD_SYSFW) && CONFIG_IS_ENABLED(DM_MMC)
61 void k3_mmc_stop_clock(void)
63 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
64 struct mmc *mmc = find_mmc_device(0);
69 mmc->saved_clock = mmc->clock;
70 mmc_set_clock(mmc, 0, true);
74 void k3_mmc_restart_clock(void)
76 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
77 struct mmc *mmc = find_mmc_device(0);
82 mmc_set_clock(mmc, mmc->saved_clock, false);
86 void k3_mmc_stop_clock(void) {}
87 void k3_mmc_restart_clock(void) {}
90 #ifdef CONFIG_SPL_OF_LIST
91 void do_dt_magic(void)
95 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT))
99 * Board detection has been done.
100 * Let us see if another dtb wouldn't be a better match
103 if (IS_ENABLED(CONFIG_CPU_V7R)) {
104 ret = fdtdec_resetup(&rescan);
105 if (!ret && rescan) {
107 dm_init_and_scan(true);
113 #if CONFIG_IS_ENABLED(USB_STORAGE)
114 static int fixup_usb_boot(const void *fdt_blob)
118 switch (spl_boot_device()) {
119 case BOOT_DEVICE_USB:
121 * If the boot mode is host, fixup the dr_mode to host
122 * before cdns3 bind takes place
124 ret = fdt_find_and_setprop((void *)fdt_blob,
125 "/bus@f4000/cdns-usb@f900000/usb@f400000",
126 "dr_mode", "host", 5, 0);
128 printf("%s: fdt_find_and_setprop() failed:%d\n",
138 int fdtdec_board_setup(const void *fdt_blob)
140 /* Can use the pointer from the function parameters */
141 return fixup_usb_boot(fdt_blob);
145 void board_init_f(ulong dummy)
147 #if defined(CONFIG_K3_LOAD_SYSFW) || defined(CONFIG_K3_AM64_DDRSS)
152 #if defined(CONFIG_CPU_V7R)
153 setup_k3_mpu_regions();
157 * Cannot delay this further as there is a chance that
158 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
160 store_boot_info_from_rom();
167 preloader_console_init();
171 #if defined(CONFIG_K3_LOAD_SYSFW)
173 * Process pinctrl for serial3 a.k.a. MAIN UART1 module and continue
174 * regardless of the result of pinctrl. Do this without probing the
175 * device, but instead by searching the device that would request the
176 * given sequence number if probed. The UART will be used by the system
177 * firmware (SYSFW) image for various purposes and SYSFW depends on us
178 * to initialize its pin settings.
180 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 3, &dev);
182 pinctrl_select_state(dev, "default");
185 * Load, start up, and configure system controller firmware.
186 * This will determine whether or not ROM has already loaded
187 * system firmware and if so, will only perform needed config
188 * and not attempt to load firmware again.
190 k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata), k3_mmc_stop_clock,
191 k3_mmc_restart_clock);
194 /* Output System Firmware version info */
195 k3_sysfw_print_ver();
197 #if defined(CONFIG_K3_AM64_DDRSS)
198 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
200 panic("DRAM init failed: %d\n", ret);
202 if (IS_ENABLED(CONFIG_SPL_ETH) && IS_ENABLED(CONFIG_TI_AM65_CPSW_NUSS) &&
203 spl_boot_device() == BOOT_DEVICE_ETHERNET) {
204 struct udevice *cpswdev;
206 if (uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(am65_cpsw_nuss), &cpswdev))
207 printf("Failed to probe am65_cpsw_nuss driver\n");
211 u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
213 switch (boot_device) {
214 case BOOT_DEVICE_MMC1:
215 return MMCSD_MODE_EMMCBOOT;
217 case BOOT_DEVICE_MMC2:
218 return MMCSD_MODE_FS;
221 return MMCSD_MODE_RAW;
225 static u32 __get_backup_bootmedia(u32 main_devstat)
228 (main_devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
229 MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT;
230 u32 bkup_bootmode_cfg =
231 (main_devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >>
232 MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT;
234 switch (bkup_bootmode) {
235 case BACKUP_BOOT_DEVICE_UART:
236 return BOOT_DEVICE_UART;
238 case BACKUP_BOOT_DEVICE_DFU:
239 if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE_MASK)
240 return BOOT_DEVICE_USB;
241 return BOOT_DEVICE_DFU;
244 case BACKUP_BOOT_DEVICE_ETHERNET:
245 return BOOT_DEVICE_ETHERNET;
247 case BACKUP_BOOT_DEVICE_MMC:
248 if (bkup_bootmode_cfg)
249 return BOOT_DEVICE_MMC2;
250 return BOOT_DEVICE_MMC1;
252 case BACKUP_BOOT_DEVICE_SPI:
253 return BOOT_DEVICE_SPI;
255 case BACKUP_BOOT_DEVICE_I2C:
256 return BOOT_DEVICE_I2C;
259 return BOOT_DEVICE_RAM;
262 static u32 __get_primary_bootmedia(u32 main_devstat)
264 u32 bootmode = (main_devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
265 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
267 (main_devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
268 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
271 case BOOT_DEVICE_OSPI:
273 case BOOT_DEVICE_QSPI:
275 case BOOT_DEVICE_XSPI:
277 case BOOT_DEVICE_SPI:
278 return BOOT_DEVICE_SPI;
280 case BOOT_DEVICE_ETHERNET_RGMII:
282 case BOOT_DEVICE_ETHERNET_RMII:
283 return BOOT_DEVICE_ETHERNET;
285 case BOOT_DEVICE_EMMC:
286 return BOOT_DEVICE_MMC1;
288 case BOOT_DEVICE_MMC:
289 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >>
290 MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT)
291 return BOOT_DEVICE_MMC2;
292 return BOOT_DEVICE_MMC1;
294 case BOOT_DEVICE_DFU:
295 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE_MASK) >>
296 MAIN_DEVSTAT_PRIMARY_USB_MODE_SHIFT)
297 return BOOT_DEVICE_USB;
298 return BOOT_DEVICE_DFU;
300 case BOOT_DEVICE_NOBOOT:
301 return BOOT_DEVICE_RAM;
307 u32 spl_boot_device(void)
309 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
311 if (bootindex == K3_PRIMARY_BOOTMODE)
312 return __get_primary_bootmedia(devstat);
314 return __get_backup_bootmedia(devstat);
318 #if defined(CONFIG_SYS_K3_SPL_ATF)
320 #define AM64X_DEV_RTI8 127
321 #define AM64X_DEV_RTI9 128
322 #define AM64X_DEV_R5FSS0_CORE0 121
323 #define AM64X_DEV_R5FSS0_CORE1 122
325 void release_resources_for_core_shutdown(void)
327 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
328 struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops;
329 struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
333 const u32 put_device_ids[] = {
338 /* Iterate through list of devices to put (shutdown) */
339 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
340 u32 id = put_device_ids[i];
342 ret = dev_ops->put_device(ti_sci, id);
344 panic("Failed to put device %u (%d)\n", id, ret);
347 const u32 put_core_ids[] = {
348 AM64X_DEV_R5FSS0_CORE1,
349 AM64X_DEV_R5FSS0_CORE0, /* Handle CPU0 after CPU1 */
352 /* Iterate through list of cores to put (shutdown) */
353 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
354 u32 id = put_core_ids[i];
357 * Queue up the core shutdown request. Note that this call
358 * needs to be followed up by an actual invocation of an WFE
359 * or WFI CPU instruction.
361 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
363 panic("Failed sending core %u shutdown message (%d)\n",