blob: 0f62f39075bae071741e17b403a4dd5895c9b274 [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
174static u32 __get_backup_bootmedia(u32 devstat)
175{
176 u32 bkup_bootmode = (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
177 MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT;
178 u32 bkup_bootmode_cfg =
179 (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >>
180 MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT;
181
182 switch (bkup_bootmode) {
183 case BACKUP_BOOT_DEVICE_UART:
184 return BOOT_DEVICE_UART;
185
186 case BACKUP_BOOT_DEVICE_USB:
187 return BOOT_DEVICE_USB;
188
189 case BACKUP_BOOT_DEVICE_ETHERNET:
190 return BOOT_DEVICE_ETHERNET;
191
192 case BACKUP_BOOT_DEVICE_MMC:
193 if (bkup_bootmode_cfg)
194 return BOOT_DEVICE_MMC2;
195 return BOOT_DEVICE_MMC1;
196
197 case BACKUP_BOOT_DEVICE_SPI:
198 return BOOT_DEVICE_SPI;
199
200 case BACKUP_BOOT_DEVICE_I2C:
201 return BOOT_DEVICE_I2C;
202
203 case BACKUP_BOOT_DEVICE_DFU:
204 if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE_MASK)
205 return BOOT_DEVICE_USB;
206 return BOOT_DEVICE_DFU;
207 };
208
209 return BOOT_DEVICE_RAM;
210}
211
212static u32 __get_primary_bootmedia(u32 devstat)
213{
214 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
215 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
216 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
217 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
218
219 switch (bootmode) {
220 case BOOT_DEVICE_OSPI:
221 fallthrough;
222 case BOOT_DEVICE_QSPI:
223 fallthrough;
224 case BOOT_DEVICE_XSPI:
225 fallthrough;
226 case BOOT_DEVICE_SPI:
227 return BOOT_DEVICE_SPI;
228
229 case BOOT_DEVICE_ETHERNET_RGMII:
230 fallthrough;
231 case BOOT_DEVICE_ETHERNET_RMII:
232 return BOOT_DEVICE_ETHERNET;
233
234 case BOOT_DEVICE_EMMC:
235 return BOOT_DEVICE_MMC1;
236
237 case BOOT_DEVICE_SPI_NAND:
238 return BOOT_DEVICE_SPINAND;
239
240 case BOOT_DEVICE_MMC:
241 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >>
242 MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT)
243 return BOOT_DEVICE_MMC2;
244 return BOOT_DEVICE_MMC1;
245
246 case BOOT_DEVICE_DFU:
247 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE_MASK) >>
248 MAIN_DEVSTAT_PRIMARY_USB_MODE_SHIFT)
249 return BOOT_DEVICE_USB;
250 return BOOT_DEVICE_DFU;
251
252 case BOOT_DEVICE_NOBOOT:
253 return BOOT_DEVICE_RAM;
254 }
255
256 return bootmode;
257}
258
259u32 spl_boot_device(void)
260{
261 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
262 u32 bootmedia;
263
264 if (bootindex == K3_PRIMARY_BOOTMODE)
265 bootmedia = __get_primary_bootmedia(devstat);
266 else
267 bootmedia = __get_backup_bootmedia(devstat);
268
Bryan Brattlofd7404d72023-07-17 18:01:33 -0500269 debug("am62a_init: %s: devstat = 0x%x bootmedia = 0x%x bootindex = %d\n",
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500270 __func__, devstat, bootmedia, bootindex);
271 return bootmedia;
272}