blob: 8ac834cffdf9f1937752385f2228429a03248c8e [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>
Andrew Davisf1799852023-04-06 11:38:16 -050011#include "sysfw-loader.h"
Bryan Brattlofdaa39a62022-11-03 19:13:55 -050012#include "common.h"
13#include <dm.h>
14#include <dm/uclass-internal.h>
15#include <dm/pinctrl.h>
16
Vignesh Raghavendraad998d22023-07-02 14:46:54 +053017struct fwl_data cbass_main_fwls[] = {
18 { "FSS_DAT_REG3", 7, 8 },
19};
20
Bryan Brattlofdaa39a62022-11-03 19:13:55 -050021/*
22 * This uninitialized global variable would normal end up in the .bss section,
23 * but the .bss is cleared between writing and reading this variable, so move
24 * it to the .data section.
25 */
26u32 bootindex __section(".data");
27static struct rom_extended_boot_data bootdata __section(".data");
28
29static void store_boot_info_from_rom(void)
30{
31 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Bryan Brattlofcdea1212022-12-23 19:15:23 -060032
33 if (IS_ENABLED(CONFIG_CPU_V7R)) {
34 memcpy(&bootdata, (uintptr_t *)ROM_ENTENDED_BOOT_DATA_INFO,
35 sizeof(struct rom_extended_boot_data));
36 }
Bryan Brattlofdaa39a62022-11-03 19:13:55 -050037}
38
39static void ctrl_mmr_unlock(void)
40{
41 /* Unlock all WKUP_CTRL_MMR0 module registers */
42 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
43 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
44 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
45 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
46 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
47 mmr_unlock(WKUP_CTRL_MMR0_BASE, 5);
48 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
49 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
50
51 /* Unlock all CTRL_MMR0 module registers */
52 mmr_unlock(CTRL_MMR0_BASE, 0);
53 mmr_unlock(CTRL_MMR0_BASE, 1);
54 mmr_unlock(CTRL_MMR0_BASE, 2);
55 mmr_unlock(CTRL_MMR0_BASE, 4);
56 mmr_unlock(CTRL_MMR0_BASE, 5);
57 mmr_unlock(CTRL_MMR0_BASE, 6);
58
59 /* Unlock all MCU_CTRL_MMR0 module registers */
60 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
61 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
62 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
63 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
64 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
65 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
66
67 /* Unlock PADCFG_CTRL_MMR padconf registers */
68 mmr_unlock(PADCFG_MMR0_BASE, 1);
69 mmr_unlock(PADCFG_MMR1_BASE, 1);
70}
71
Aradhya Bhatia94024e92023-04-14 12:57:25 +053072#if (IS_ENABLED(CONFIG_CPU_V7R))
73static void setup_qos(void)
74{
75 u32 i;
76
77 for (i = 0; i < am62a_qos_count; i++)
78 writel(am62a_qos_data[i].val, (uintptr_t)am62a_qos_data[i].reg);
79}
80#else
81static void setup_qos(void)
82{
83}
84#endif
85
Bryan Brattlofdaa39a62022-11-03 19:13:55 -050086void board_init_f(ulong dummy)
87{
88 struct udevice *dev;
89 int ret;
90
91#if defined(CONFIG_CPU_V7R)
92 setup_k3_mpu_regions();
93#endif
94
95 /*
96 * Cannot delay this further as there is a chance that
97 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
98 */
99 store_boot_info_from_rom();
100
101 ctrl_mmr_unlock();
102
103 /* Init DM early */
104 spl_early_init();
105
106 /*
107 * Process pinctrl for the serial0 and serial3, aka WKUP_UART0 and
108 * MAIN_UART1 modules and continue regardless of the result of pinctrl.
109 * Do this without probing the device, but instead by searching the
110 * device that would request the given sequence number if probed. The
111 * UARTs will be used by the DM firmware and TIFS firmware images
112 * respectively and the firmware depend on SPL to initialize the pin
113 * settings.
114 */
115 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
116 if (!ret)
117 pinctrl_select_state(dev, "default");
118
119 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 3, &dev);
120 if (!ret)
121 pinctrl_select_state(dev, "default");
122
123#ifdef CONFIG_K3_EARLY_CONS
124 /*
125 * Allow establishing an early console as required for example when
126 * doing a UART-based boot. Note that this console may not "survive"
127 * through a SYSFW PM-init step and will need a re-init in some way
128 * due to changing module clock frequencies.
129 */
130 early_console_init();
131#endif
132
133#if defined(CONFIG_K3_LOAD_SYSFW)
134 /*
135 * Configure and start up system controller firmware. Provide
136 * the U-Boot console init function to the SYSFW post-PM configuration
137 * callback hook, effectively switching on (or over) the console
138 * output.
139 */
140 ret = is_rom_loaded_sysfw(&bootdata);
141 if (!ret)
142 panic("ROM has not loaded TIFS firmware\n");
143
144 k3_sysfw_loader(true, NULL, NULL);
145#endif
146
Bryan Brattlofcdea1212022-12-23 19:15:23 -0600147#if defined(CONFIG_CPU_V7R)
148 /*
149 * Relocate boot information to OCRAM (after TIFS has opend this
150 * region for us) so the next bootloader stages can keep access to
151 * primary vs backup bootmodes.
152 */
153 writel(bootindex, K3_BOOT_PARAM_TABLE_INDEX_OCRAM);
154#endif
155
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500156 /*
157 * Force probe of clk_k3 driver here to ensure basic default clock
158 * configuration is always done.
159 */
160 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
161 ret = uclass_get_device_by_driver(UCLASS_CLK,
162 DM_DRIVER_GET(ti_clk),
163 &dev);
164 if (ret)
165 printf("Failed to initialize clk-k3!\n");
166 }
167
168 preloader_console_init();
169
170 /* Output System Firmware version info */
171 k3_sysfw_print_ver();
172
Vignesh Raghavendraad998d22023-07-02 14:46:54 +0530173 /* Disable ROM configured firewalls right after loading sysfw */
174 remove_fwl_configs(cbass_main_fwls, ARRAY_SIZE(cbass_main_fwls));
175
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500176#if defined(CONFIG_K3_AM62A_DDRSS)
177 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
178 if (ret)
179 panic("DRAM init failed: %d\n", ret);
180#endif
181
Aradhya Bhatia94024e92023-04-14 12:57:25 +0530182 setup_qos();
183
Bryan Brattlofdaa39a62022-11-03 19:13:55 -0500184 printf("am62a_init: %s done\n", __func__);
185}
186
187static u32 __get_backup_bootmedia(u32 devstat)
188{
189 u32 bkup_bootmode = (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
190 MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT;
191 u32 bkup_bootmode_cfg =
192 (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >>
193 MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT;
194
195 switch (bkup_bootmode) {
196 case BACKUP_BOOT_DEVICE_UART:
197 return BOOT_DEVICE_UART;
198
199 case BACKUP_BOOT_DEVICE_USB:
200 return BOOT_DEVICE_USB;
201
202 case BACKUP_BOOT_DEVICE_ETHERNET:
203 return BOOT_DEVICE_ETHERNET;
204
205 case BACKUP_BOOT_DEVICE_MMC:
206 if (bkup_bootmode_cfg)
207 return BOOT_DEVICE_MMC2;
208 return BOOT_DEVICE_MMC1;
209
210 case BACKUP_BOOT_DEVICE_SPI:
211 return BOOT_DEVICE_SPI;
212
213 case BACKUP_BOOT_DEVICE_I2C:
214 return BOOT_DEVICE_I2C;
215
216 case BACKUP_BOOT_DEVICE_DFU:
217 if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE_MASK)
218 return BOOT_DEVICE_USB;
219 return BOOT_DEVICE_DFU;
220 };
221
222 return BOOT_DEVICE_RAM;
223}
224
225static u32 __get_primary_bootmedia(u32 devstat)
226{
227 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
228 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
229 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
230 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
231
232 switch (bootmode) {
233 case BOOT_DEVICE_OSPI:
234 fallthrough;
235 case BOOT_DEVICE_QSPI:
236 fallthrough;
237 case BOOT_DEVICE_XSPI:
238 fallthrough;
239 case BOOT_DEVICE_SPI:
240 return BOOT_DEVICE_SPI;
241
242 case BOOT_DEVICE_ETHERNET_RGMII:
243 fallthrough;
244 case BOOT_DEVICE_ETHERNET_RMII:
245 return BOOT_DEVICE_ETHERNET;
246
247 case BOOT_DEVICE_EMMC:
248 return BOOT_DEVICE_MMC1;
249
250 case BOOT_DEVICE_SPI_NAND:
251 return BOOT_DEVICE_SPINAND;
252
253 case BOOT_DEVICE_MMC:
254 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >>
255 MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT)
256 return BOOT_DEVICE_MMC2;
257 return BOOT_DEVICE_MMC1;
258
259 case BOOT_DEVICE_DFU:
260 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE_MASK) >>
261 MAIN_DEVSTAT_PRIMARY_USB_MODE_SHIFT)
262 return BOOT_DEVICE_USB;
263 return BOOT_DEVICE_DFU;
264
265 case BOOT_DEVICE_NOBOOT:
266 return BOOT_DEVICE_RAM;
267 }
268
269 return bootmode;
270}
271
272u32 spl_boot_device(void)
273{
274 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
275 u32 bootmedia;
276
277 if (bootindex == K3_PRIMARY_BOOTMODE)
278 bootmedia = __get_primary_bootmedia(devstat);
279 else
280 bootmedia = __get_backup_bootmedia(devstat);
281
282 printf("am62a_init: %s: devstat = 0x%x bootmedia = 0x%x bootindex = %d\n",
283 __func__, devstat, bootmedia, bootindex);
284 return bootmedia;
285}