1 // SPDX-License-Identifier: GPL-2.0+
3 * J721E: SoC specific initialization
5 * Copyright (C) 2021 Texas Instruments Incorporated - http://www.ti.com/
6 * David Huang <d-huang@ti.com>
13 #include <asm/armv7_mpu.h>
14 #include <asm/arch/hardware.h>
15 #include <asm/arch/sysfw-loader.h>
17 #include <asm/arch/sys_proto.h>
18 #include <linux/soc/ti/ti_sci_protocol.h>
20 #include <dm/uclass-internal.h>
21 #include <dm/pinctrl.h>
23 #include <remoteproc.h>
25 #ifdef CONFIG_SPL_BUILD
27 static void ctrl_mmr_unlock(void)
29 /* Unlock all WKUP_CTRL_MMR0 module registers */
30 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
31 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
32 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
33 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
34 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
35 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
36 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
38 /* Unlock all MCU_CTRL_MMR0 module registers */
39 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
40 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
41 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
42 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
43 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
45 /* Unlock all CTRL_MMR0 module registers */
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, 3);
50 mmr_unlock(CTRL_MMR0_BASE, 5);
51 mmr_unlock(CTRL_MMR0_BASE, 7);
54 void k3_mmc_stop_clock(void)
56 if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) {
57 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
58 struct mmc *mmc = find_mmc_device(0);
63 mmc->saved_clock = mmc->clock;
64 mmc_set_clock(mmc, 0, true);
69 void k3_mmc_restart_clock(void)
71 if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) {
72 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
73 struct mmc *mmc = find_mmc_device(0);
78 mmc_set_clock(mmc, mmc->saved_clock, false);
84 * This uninitialized global variable would normal end up in the .bss section,
85 * but the .bss is cleared between writing and reading this variable, so move
86 * it to the .data section.
88 u32 bootindex __attribute__((section(".data")));
89 static struct rom_extended_boot_data bootdata __section(".data");
91 static void store_boot_info_from_rom(void)
93 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
94 memcpy(&bootdata, (uintptr_t *)ROM_ENTENDED_BOOT_DATA_INFO,
95 sizeof(struct rom_extended_boot_data));
98 void board_init_f(ulong dummy)
103 * Cannot delay this further as there is a chance that
104 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
106 store_boot_info_from_rom();
108 /* Make all control module registers accessible */
111 if (IS_ENABLED(CONFIG_CPU_V7R)) {
112 disable_linefill_optimization();
113 setup_k3_mpu_regions();
119 /* Prepare console output */
120 preloader_console_init();
122 if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) {
124 * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue
125 * regardless of the result of pinctrl. Do this without probing the
126 * device, but instead by searching the device that would request the
127 * given sequence number if probed. The UART will be used by the system
128 * firmware (SYSFW) image for various purposes and SYSFW depends on us
129 * to initialize its pin settings.
131 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
133 pinctrl_select_state(dev, "default");
136 * Load, start up, and configure system controller firmware. Provide
137 * the U-Boot console init function to the SYSFW post-PM configuration
138 * callback hook, effectively switching on (or over) the console
141 k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata),
142 k3_mmc_stop_clock, k3_mmc_restart_clock);
144 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
146 * Force probe of clk_k3 driver here to ensure basic default clock
147 * configuration is always done for enabling PM services.
149 ret = uclass_get_device_by_driver(UCLASS_CLK,
150 DM_DRIVER_GET(ti_clk),
153 panic("Failed to initialize clk-k3!\n");
157 /* Output System Firmware version info */
158 k3_sysfw_print_ver();
160 if (IS_ENABLED(CONFIG_TARGET_J721S2_R5_EVM)) {
161 ret = uclass_get_device_by_name(UCLASS_MISC, "msmc", &dev);
163 panic("Probe of msmc failed: %d\n", ret);
165 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
167 panic("DRAM 0 init failed: %d\n", ret);
169 ret = uclass_next_device(&dev);
171 panic("DRAM 1 init failed: %d\n", ret);
176 u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
178 switch (boot_device) {
179 case BOOT_DEVICE_MMC1:
180 return MMCSD_MODE_EMMCBOOT;
181 case BOOT_DEVICE_MMC2:
182 return MMCSD_MODE_FS;
184 return MMCSD_MODE_RAW;
188 static u32 __get_backup_bootmedia(u32 main_devstat)
190 u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
191 MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
194 case BACKUP_BOOT_DEVICE_USB:
195 return BOOT_DEVICE_DFU;
196 case BACKUP_BOOT_DEVICE_UART:
197 return BOOT_DEVICE_UART;
198 case BACKUP_BOOT_DEVICE_ETHERNET:
199 return BOOT_DEVICE_ETHERNET;
200 case BACKUP_BOOT_DEVICE_MMC2:
202 u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
203 MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
205 return BOOT_DEVICE_MMC1;
206 return BOOT_DEVICE_MMC2;
208 case BACKUP_BOOT_DEVICE_SPI:
209 return BOOT_DEVICE_SPI;
210 case BACKUP_BOOT_DEVICE_I2C:
211 return BOOT_DEVICE_I2C;
214 return BOOT_DEVICE_RAM;
217 static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
219 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
220 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
222 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
225 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI ||
226 bootmode == BOOT_DEVICE_XSPI)
227 bootmode = BOOT_DEVICE_SPI;
229 if (bootmode == BOOT_DEVICE_MMC2) {
230 u32 port = (main_devstat &
231 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
232 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
234 bootmode = BOOT_DEVICE_MMC1;
240 u32 spl_boot_device(void)
242 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
245 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
246 printf("ERROR: MCU only boot is not yet supported\n");
247 return BOOT_DEVICE_RAM;
250 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
251 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
253 if (bootindex == K3_PRIMARY_BOOTMODE)
254 return __get_primary_bootmedia(main_devstat, wkup_devstat);
256 return __get_backup_bootmedia(main_devstat);
260 #define J721S2_DEV_MCU_RTI0 295
261 #define J721S2_DEV_MCU_RTI1 296
262 #define J721S2_DEV_MCU_ARMSS0_CPU0 284
263 #define J721S2_DEV_MCU_ARMSS0_CPU1 285
265 void release_resources_for_core_shutdown(void)
267 if (IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)) {
268 struct ti_sci_handle *ti_sci;
269 struct ti_sci_dev_ops *dev_ops;
270 struct ti_sci_proc_ops *proc_ops;
274 const u32 put_device_ids[] = {
279 ti_sci = get_ti_sci_handle();
280 dev_ops = &ti_sci->ops.dev_ops;
281 proc_ops = &ti_sci->ops.proc_ops;
283 /* Iterate through list of devices to put (shutdown) */
284 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
285 u32 id = put_device_ids[i];
287 ret = dev_ops->put_device(ti_sci, id);
289 panic("Failed to put device %u (%d)\n", id, ret);
292 const u32 put_core_ids[] = {
293 J721S2_DEV_MCU_ARMSS0_CPU1,
294 J721S2_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
297 /* Iterate through list of cores to put (shutdown) */
298 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
299 u32 id = put_core_ids[i];
302 * Queue up the core shutdown request. Note that this call
303 * needs to be followed up by an actual invocation of an WFE
304 * or WFI CPU instruction.
306 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
308 panic("Failed sending core %u shutdown message (%d)\n",