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 static void ctrl_mmr_unlock(void)
27 /* Unlock all WKUP_CTRL_MMR0 module registers */
28 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
29 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
30 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
31 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
32 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
33 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
34 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
36 /* Unlock all MCU_CTRL_MMR0 module registers */
37 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
38 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
39 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
40 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
41 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
43 /* Unlock all CTRL_MMR0 module registers */
44 mmr_unlock(CTRL_MMR0_BASE, 0);
45 mmr_unlock(CTRL_MMR0_BASE, 1);
46 mmr_unlock(CTRL_MMR0_BASE, 2);
47 mmr_unlock(CTRL_MMR0_BASE, 3);
48 mmr_unlock(CTRL_MMR0_BASE, 5);
49 mmr_unlock(CTRL_MMR0_BASE, 7);
52 void k3_mmc_stop_clock(void)
54 if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) {
55 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
56 struct mmc *mmc = find_mmc_device(0);
61 mmc->saved_clock = mmc->clock;
62 mmc_set_clock(mmc, 0, true);
67 void k3_mmc_restart_clock(void)
69 if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) {
70 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
71 struct mmc *mmc = find_mmc_device(0);
76 mmc_set_clock(mmc, mmc->saved_clock, false);
82 * This uninitialized global variable would normal end up in the .bss section,
83 * but the .bss is cleared between writing and reading this variable, so move
84 * it to the .data section.
86 u32 bootindex __attribute__((section(".data")));
87 static struct rom_extended_boot_data bootdata __section(".data");
89 static void store_boot_info_from_rom(void)
91 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
92 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
93 sizeof(struct rom_extended_boot_data));
96 void k3_spl_init(void)
101 * Cannot delay this further as there is a chance that
102 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
104 store_boot_info_from_rom();
106 /* Make all control module registers accessible */
109 if (IS_ENABLED(CONFIG_CPU_V7R)) {
110 disable_linefill_optimization();
111 setup_k3_mpu_regions();
117 /* Prepare console output */
118 preloader_console_init();
120 if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) {
122 * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue
123 * regardless of the result of pinctrl. Do this without probing the
124 * device, but instead by searching the device that would request the
125 * given sequence number if probed. The UART will be used by the system
126 * firmware (SYSFW) image for various purposes and SYSFW depends on us
127 * to initialize its pin settings.
129 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
131 pinctrl_select_state(dev, "default");
134 * Load, start up, and configure 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
139 k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata),
140 k3_mmc_stop_clock, k3_mmc_restart_clock);
142 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
144 * Force probe of clk_k3 driver here to ensure basic default clock
145 * configuration is always done for enabling PM services.
147 ret = uclass_get_device_by_driver(UCLASS_CLK,
148 DM_DRIVER_GET(ti_clk),
151 panic("Failed to initialize clk-k3!\n");
155 /* Output System Firmware version info */
156 k3_sysfw_print_ver();
159 bool check_rom_loaded_sysfw(void)
161 return is_rom_loaded_sysfw(&bootdata);
164 void k3_mem_init(void)
169 if (IS_ENABLED(CONFIG_TARGET_J721S2_R5_EVM)) {
170 ret = uclass_get_device_by_name(UCLASS_MISC, "msmc", &dev);
172 panic("Probe of msmc failed: %d\n", ret);
174 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
176 panic("DRAM 0 init failed: %d\n", ret);
178 ret = uclass_next_device_err(&dev);
180 panic("DRAM 1 init failed: %d\n", ret);
185 u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
187 switch (boot_device) {
188 case BOOT_DEVICE_MMC1:
189 return MMCSD_MODE_EMMCBOOT;
190 case BOOT_DEVICE_MMC2:
191 return MMCSD_MODE_FS;
193 return MMCSD_MODE_RAW;
197 static u32 __get_backup_bootmedia(u32 main_devstat)
199 u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
200 MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
203 case BACKUP_BOOT_DEVICE_USB:
204 return BOOT_DEVICE_DFU;
205 case BACKUP_BOOT_DEVICE_UART:
206 return BOOT_DEVICE_UART;
207 case BACKUP_BOOT_DEVICE_ETHERNET:
208 return BOOT_DEVICE_ETHERNET;
209 case BACKUP_BOOT_DEVICE_MMC2:
211 u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
212 MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
214 return BOOT_DEVICE_MMC1;
215 return BOOT_DEVICE_MMC2;
217 case BACKUP_BOOT_DEVICE_SPI:
218 return BOOT_DEVICE_SPI;
219 case BACKUP_BOOT_DEVICE_I2C:
220 return BOOT_DEVICE_I2C;
223 return BOOT_DEVICE_RAM;
226 static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
228 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
229 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
231 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
234 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI ||
235 bootmode == BOOT_DEVICE_XSPI)
236 bootmode = BOOT_DEVICE_SPI;
238 if (bootmode == BOOT_DEVICE_MMC2) {
239 u32 port = (main_devstat &
240 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
241 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
243 bootmode = BOOT_DEVICE_MMC1;
249 u32 spl_boot_device(void)
251 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
254 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
255 printf("ERROR: MCU only boot is not yet supported\n");
256 return BOOT_DEVICE_RAM;
259 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
260 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
262 if (bootindex == K3_PRIMARY_BOOTMODE)
263 return __get_primary_bootmedia(main_devstat, wkup_devstat);
265 return __get_backup_bootmedia(main_devstat);
268 #define J721S2_DEV_MCU_RTI0 295
269 #define J721S2_DEV_MCU_RTI1 296
270 #define J721S2_DEV_MCU_ARMSS0_CPU0 284
271 #define J721S2_DEV_MCU_ARMSS0_CPU1 285
273 void release_resources_for_core_shutdown(void)
275 if (IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)) {
276 struct ti_sci_handle *ti_sci;
277 struct ti_sci_dev_ops *dev_ops;
278 struct ti_sci_proc_ops *proc_ops;
282 const u32 put_device_ids[] = {
287 ti_sci = get_ti_sci_handle();
288 dev_ops = &ti_sci->ops.dev_ops;
289 proc_ops = &ti_sci->ops.proc_ops;
291 /* Iterate through list of devices to put (shutdown) */
292 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
293 u32 id = put_device_ids[i];
295 ret = dev_ops->put_device(ti_sci, id);
297 panic("Failed to put device %u (%d)\n", id, ret);
300 const u32 put_core_ids[] = {
301 J721S2_DEV_MCU_ARMSS0_CPU1,
302 J721S2_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
305 /* Iterate through list of cores to put (shutdown) */
306 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
307 u32 id = put_core_ids[i];
310 * Queue up the core shutdown request. Note that this call
311 * needs to be followed up by an actual invocation of an WFE
312 * or WFI CPU instruction.
314 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
316 panic("Failed sending core %u shutdown message (%d)\n",