blob: 78153c97a58aff99dba8a76d915802be37d58745 [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
Vignesh Raghavendraad998d22023-07-02 14:46:54 +053018struct fwl_data cbass_main_fwls[] = {
19 { "FSS_DAT_REG3", 7, 8 },
20};
21
Bryan Brattlofdaa39a62022-11-03 19:13:55 -050022/*
23 * This uninitialized global variable would normal end up in the .bss section,
24 * but the .bss is cleared between writing and reading this variable, so move
25 * it to the .data section.
26 */
27u32 bootindex __section(".data");
28static struct rom_extended_boot_data bootdata __section(".data");
29
30static void store_boot_info_from_rom(void)
31{
32 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Bryan Brattlofcdea1212022-12-23 19:15:23 -060033
34 if (IS_ENABLED(CONFIG_CPU_V7R)) {
Andrew Davis15ca72a2024-04-26 10:44:23 -050035 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
Bryan Brattlofcdea1212022-12-23 19:15:23 -060036 sizeof(struct rom_extended_boot_data));
37 }
Bryan Brattlofdaa39a62022-11-03 19:13:55 -050038}
39
40static void ctrl_mmr_unlock(void)
41{
42 /* Unlock all WKUP_CTRL_MMR0 module registers */
43 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
44 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
45 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
46 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
47 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
48 mmr_unlock(WKUP_CTRL_MMR0_BASE, 5);
49 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
50 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
51
52 /* Unlock all CTRL_MMR0 module registers */
53 mmr_unlock(CTRL_MMR0_BASE, 0);
54 mmr_unlock(CTRL_MMR0_BASE, 1);
55 mmr_unlock(CTRL_MMR0_BASE, 2);
56 mmr_unlock(CTRL_MMR0_BASE, 4);
57 mmr_unlock(CTRL_MMR0_BASE, 5);
58 mmr_unlock(CTRL_MMR0_BASE, 6);
59
60 /* Unlock all MCU_CTRL_MMR0 module registers */
61 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
62 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
63 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
64 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
65 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
66 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
67
68 /* Unlock PADCFG_CTRL_MMR padconf registers */
69 mmr_unlock(PADCFG_MMR0_BASE, 1);
70 mmr_unlock(PADCFG_MMR1_BASE, 1);
71}
72
73void board_init_f(ulong dummy)
74{
75 struct udevice *dev;
76 int ret;
77
78#if defined(CONFIG_CPU_V7R)
79 setup_k3_mpu_regions();
80#endif
81
82 /*
83 * Cannot delay this further as there is a chance that
84 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
85 */
86 store_boot_info_from_rom();
87
88 ctrl_mmr_unlock();
89
90 /* Init DM early */
91 spl_early_init();
92
93 /*
94 * Process pinctrl for the serial0 and serial3, aka WKUP_UART0 and
95 * MAIN_UART1 modules and continue regardless of the result of pinctrl.
96 * Do this without probing the device, but instead by searching the
97 * device that would request the given sequence number if probed. The
98 * UARTs will be used by the DM firmware and TIFS firmware images
99 * respectively and the firmware depend on SPL to initialize the pin
100 * settings.
101 */
102 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
103 if (!ret)
104 pinctrl_select_state(dev, "default");
105
106 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 3, &dev);
107 if (!ret)
108 pinctrl_select_state(dev, "default");
109
110#ifdef CONFIG_K3_EARLY_CONS
111 /*
112 * Allow establishing an early console as required for example when
113 * doing a UART-based boot. Note that this console may not "survive"
114 * through a SYSFW PM-init step and will need a re-init in some way
115 * due to changing module clock frequencies.
116 */
117 early_console_init();
118#endif
119
120#if defined(CONFIG_K3_LOAD_SYSFW)
121 /*
122 * Configure and start up system controller firmware. Provide
123 * the U-Boot console init function to the SYSFW post-PM configuration
124 * callback hook, effectively switching on (or over) the console
125 * output.
126 */
127 ret = is_rom_loaded_sysfw(&bootdata);
128 if (!ret)
129 panic("ROM has not loaded TIFS firmware\n");
130
131 k3_sysfw_loader(true, NULL, NULL);
Andrew Davis36a01bdf2024-02-01 18:24:46 -0600132
133 /* Disable ROM configured firewalls right after loading sysfw */
134 remove_fwl_configs(cbass_main_fwls, ARRAY_SIZE(cbass_main_fwls));
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500135#endif
136
Bryan Brattlofcdea1212022-12-23 19:15:23 -0600137#if defined(CONFIG_CPU_V7R)
138 /*
139 * Relocate boot information to OCRAM (after TIFS has opend this
140 * region for us) so the next bootloader stages can keep access to
141 * primary vs backup bootmodes.
142 */
143 writel(bootindex, K3_BOOT_PARAM_TABLE_INDEX_OCRAM);
144#endif
145
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500146 /*
147 * Force probe of clk_k3 driver here to ensure basic default clock
148 * configuration is always done.
149 */
150 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
151 ret = uclass_get_device_by_driver(UCLASS_CLK,
152 DM_DRIVER_GET(ti_clk),
153 &dev);
154 if (ret)
155 printf("Failed to initialize clk-k3!\n");
156 }
157
158 preloader_console_init();
159
160 /* Output System Firmware version info */
161 k3_sysfw_print_ver();
162
163#if defined(CONFIG_K3_AM62A_DDRSS)
164 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
165 if (ret)
166 panic("DRAM init failed: %d\n", ret);
167#endif
168
Aradhya Bhatia94024e92023-04-14 12:57:25 +0530169 setup_qos();
170
Bryan Brattlofd7404d72023-07-17 18:01:33 -0500171 debug("am62a_init: %s done\n", __func__);
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500172}
173
Vignesh Raghavendra8ee7c6e2024-12-20 14:36:58 -0600174u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
175{
176 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
177 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
178 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
179 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
180 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
181
182 switch (bootmode) {
183 case BOOT_DEVICE_EMMC:
184 return MMCSD_MODE_EMMCBOOT;
185 case BOOT_DEVICE_MMC:
186 if (bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_FS_RAW_MASK)
187 return MMCSD_MODE_RAW;
188 default:
189 return MMCSD_MODE_FS;
190 }
191}
192
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500193u32 spl_boot_device(void)
194{
Garrett Giordanof5c236d2024-10-31 09:21:03 -0700195 return get_boot_device();
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500196}