blob: 28aee34f30bf195bed1a269b2f448c81cf95302f [file] [log] [blame]
Bryan Brattlofdaa39a62022-11-03 19:13:55 -05001// SPDX-License-Identifier: GPL-2.0
2/*
3 * AM62A7: SoC specific initialization
4 *
5 * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
6 */
7
8#include <spl.h>
9#include <asm/io.h>
10#include <asm/arch/hardware.h>
Bryan Brattlofdaa39a62022-11-03 19:13:55 -050011#include <dm.h>
12#include <dm/uclass-internal.h>
13#include <dm/pinctrl.h>
14
Andrew Davis336b0792024-05-10 15:21:24 -050015#include "../sysfw-loader.h"
16#include "../common.h"
17
Santhosh Kumar K0dc33cd2025-01-29 17:44:02 -060018#define CTRLMMR_MCU_RST_CTRL 0x04518170
19#define RST_CTRL_ESM_ERROR_RST_EN_Z_MASK 0xFFFDFFFF
20
Vignesh Raghavendraad998d22023-07-02 14:46:54 +053021struct fwl_data cbass_main_fwls[] = {
22 { "FSS_DAT_REG3", 7, 8 },
23};
24
Bryan Brattlofdaa39a62022-11-03 19:13:55 -050025/*
26 * This uninitialized global variable would normal end up in the .bss section,
27 * but the .bss is cleared between writing and reading this variable, so move
28 * it to the .data section.
29 */
30u32 bootindex __section(".data");
31static struct rom_extended_boot_data bootdata __section(".data");
32
33static void store_boot_info_from_rom(void)
34{
35 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Bryan Brattlofcdea1212022-12-23 19:15:23 -060036
37 if (IS_ENABLED(CONFIG_CPU_V7R)) {
Andrew Davis15ca72a2024-04-26 10:44:23 -050038 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
Bryan Brattlofcdea1212022-12-23 19:15:23 -060039 sizeof(struct rom_extended_boot_data));
40 }
Bryan Brattlofdaa39a62022-11-03 19:13:55 -050041}
42
43static void ctrl_mmr_unlock(void)
44{
45 /* Unlock all WKUP_CTRL_MMR0 module registers */
46 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
47 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
48 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
49 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
50 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
51 mmr_unlock(WKUP_CTRL_MMR0_BASE, 5);
52 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
53 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
54
55 /* Unlock all CTRL_MMR0 module registers */
56 mmr_unlock(CTRL_MMR0_BASE, 0);
57 mmr_unlock(CTRL_MMR0_BASE, 1);
58 mmr_unlock(CTRL_MMR0_BASE, 2);
59 mmr_unlock(CTRL_MMR0_BASE, 4);
60 mmr_unlock(CTRL_MMR0_BASE, 5);
61 mmr_unlock(CTRL_MMR0_BASE, 6);
62
63 /* Unlock all MCU_CTRL_MMR0 module registers */
64 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
65 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
66 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
67 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
68 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
69 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
70
71 /* Unlock PADCFG_CTRL_MMR padconf registers */
72 mmr_unlock(PADCFG_MMR0_BASE, 1);
73 mmr_unlock(PADCFG_MMR1_BASE, 1);
74}
75
Santhosh Kumar K0dc33cd2025-01-29 17:44:02 -060076static __maybe_unused void enable_mcu_esm_reset(void)
77{
78 /* Set CTRLMMR_MCU_RST_CTRL:MCU_ESM_ERROR_RST_EN_Z to '0' (low active) */
79 u32 stat = readl(CTRLMMR_MCU_RST_CTRL);
80
81 stat &= RST_CTRL_ESM_ERROR_RST_EN_Z_MASK;
82 writel(stat, CTRLMMR_MCU_RST_CTRL);
83}
84
Bryan Brattlofdaa39a62022-11-03 19:13:55 -050085void board_init_f(ulong dummy)
86{
87 struct udevice *dev;
88 int ret;
89
90#if defined(CONFIG_CPU_V7R)
91 setup_k3_mpu_regions();
92#endif
93
94 /*
95 * Cannot delay this further as there is a chance that
96 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
97 */
98 store_boot_info_from_rom();
99
100 ctrl_mmr_unlock();
101
102 /* Init DM early */
103 spl_early_init();
104
105 /*
106 * Process pinctrl for the serial0 and serial3, aka WKUP_UART0 and
107 * MAIN_UART1 modules and continue regardless of the result of pinctrl.
108 * Do this without probing the device, but instead by searching the
109 * device that would request the given sequence number if probed. The
110 * UARTs will be used by the DM firmware and TIFS firmware images
111 * respectively and the firmware depend on SPL to initialize the pin
112 * settings.
113 */
114 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
115 if (!ret)
116 pinctrl_select_state(dev, "default");
117
118 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 3, &dev);
119 if (!ret)
120 pinctrl_select_state(dev, "default");
121
122#ifdef CONFIG_K3_EARLY_CONS
123 /*
124 * Allow establishing an early console as required for example when
125 * doing a UART-based boot. Note that this console may not "survive"
126 * through a SYSFW PM-init step and will need a re-init in some way
127 * due to changing module clock frequencies.
128 */
129 early_console_init();
130#endif
131
132#if defined(CONFIG_K3_LOAD_SYSFW)
133 /*
134 * Configure and start up system controller firmware. Provide
135 * the U-Boot console init function to the SYSFW post-PM configuration
136 * callback hook, effectively switching on (or over) the console
137 * output.
138 */
139 ret = is_rom_loaded_sysfw(&bootdata);
140 if (!ret)
141 panic("ROM has not loaded TIFS firmware\n");
142
143 k3_sysfw_loader(true, NULL, NULL);
Andrew Davis36a01bdf2024-02-01 18:24:46 -0600144
145 /* Disable ROM configured firewalls right after loading sysfw */
146 remove_fwl_configs(cbass_main_fwls, ARRAY_SIZE(cbass_main_fwls));
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500147#endif
148
Bryan Brattlofcdea1212022-12-23 19:15:23 -0600149#if defined(CONFIG_CPU_V7R)
150 /*
151 * Relocate boot information to OCRAM (after TIFS has opend this
152 * region for us) so the next bootloader stages can keep access to
153 * primary vs backup bootmodes.
154 */
155 writel(bootindex, K3_BOOT_PARAM_TABLE_INDEX_OCRAM);
156#endif
157
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500158 /*
159 * Force probe of clk_k3 driver here to ensure basic default clock
160 * configuration is always done.
161 */
162 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
163 ret = uclass_get_device_by_driver(UCLASS_CLK,
164 DM_DRIVER_GET(ti_clk),
165 &dev);
166 if (ret)
167 printf("Failed to initialize clk-k3!\n");
168 }
169
170 preloader_console_init();
171
172 /* Output System Firmware version info */
173 k3_sysfw_print_ver();
174
Santhosh Kumar K0dc33cd2025-01-29 17:44:02 -0600175 if (IS_ENABLED(CONFIG_ESM_K3)) {
176 /* Probe/configure ESM0 */
177 ret = uclass_get_device_by_name(UCLASS_MISC, "esm@420000", &dev);
178 if (ret)
179 printf("esm main init failed: %d\n", ret);
180
181 /* Probe/configure MCUESM */
182 ret = uclass_get_device_by_name(UCLASS_MISC, "esm@4100000", &dev);
183 if (ret)
184 printf("esm mcu init failed: %d\n", ret);
185
186 enable_mcu_esm_reset();
187 }
188
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500189#if defined(CONFIG_K3_AM62A_DDRSS)
190 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
191 if (ret)
192 panic("DRAM init failed: %d\n", ret);
193#endif
194
Aradhya Bhatia94024e92023-04-14 12:57:25 +0530195 setup_qos();
196
Nathan Morrisson49ad07d2025-03-25 04:58:21 +0100197 if (IS_ENABLED(CONFIG_SPL_ETH) && IS_ENABLED(CONFIG_TI_AM65_CPSW_NUSS) &&
198 spl_boot_device() == BOOT_DEVICE_ETHERNET) {
199 struct udevice *cpswdev;
200
201 if (uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(am65_cpsw_nuss),
202 &cpswdev))
203 printf("Failed to probe am65_cpsw_nuss driver\n");
204 }
205
Bryan Brattlofd7404d72023-07-17 18:01:33 -0500206 debug("am62a_init: %s done\n", __func__);
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500207}
208
Vignesh Raghavendra8ee7c6e2024-12-20 14:36:58 -0600209u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
210{
211 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
212 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
213 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
214 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
215 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
216
217 switch (bootmode) {
218 case BOOT_DEVICE_EMMC:
Anshul Dalald8b46d12025-04-15 15:22:24 +0530219 if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT))
220 return MMCSD_MODE_EMMCBOOT;
221 if (IS_ENABLED(CONFIG_SPL_FS_FAT) || IS_ENABLED(CONFIG_SPL_FS_EXT4))
222 return MMCSD_MODE_FS;
Vignesh Raghavendra8ee7c6e2024-12-20 14:36:58 -0600223 return MMCSD_MODE_EMMCBOOT;
224 case BOOT_DEVICE_MMC:
225 if (bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_FS_RAW_MASK)
226 return MMCSD_MODE_RAW;
227 default:
228 return MMCSD_MODE_FS;
229 }
230}
231
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500232u32 spl_boot_device(void)
233{
Garrett Giordanof5c236d2024-10-31 09:21:03 -0700234 return get_boot_device();
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500235}