blob: af211377e7c35321fd08f36a70b6b3ed2e884f62 [file] [log] [blame]
Jayesh Choudhary732d2ff2024-06-12 14:41:18 +05301// SPDX-License-Identifier: GPL-2.0
2/*
3 * J722S: SoC specific initialization
4 *
5 * Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/
6 */
7
8#include <spl.h>
9#include <asm/io.h>
10#include <asm/arch/hardware.h>
11#include <dm.h>
12#include <dm/uclass-internal.h>
13#include <dm/pinctrl.h>
14
15#include "../sysfw-loader.h"
16#include "../common.h"
17
18struct fwl_data cbass_main_fwls[] = {
19 { "FSS_DAT_REG3", 7, 8 },
20};
21
22/*
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
Keerthy788d01e2025-02-17 16:27:17 +053030#define CTRLMMR_MCU_RST_CTRL (MCU_CTRL_MMR0_BASE + 0x18170)
31#define RST_CTRL_ESM_ERROR_RST_EN_Z_MASK (~BIT(17))
32
Jayesh Choudhary732d2ff2024-06-12 14:41:18 +053033static void store_boot_info_from_rom(void)
34{
35 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
36 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
37 sizeof(struct rom_extended_boot_data));
38}
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
73static void k3_spl_init(void)
74{
75 struct udevice *dev;
76 int ret;
77
78 if (IS_ENABLED(CONFIG_CPU_V7R))
79 setup_k3_mpu_regions();
80
81 /*
82 * Cannot delay this further as there is a chance that
83 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
84 */
85 store_boot_info_from_rom();
86
87 ctrl_mmr_unlock();
88
89 /* Init DM early */
90 ret = spl_early_init();
91 if (ret)
92 panic("spl_early_init() failed: %d\n", ret);
93
94 /*
95 * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue
96 * regardless of the result of pinctrl. Do this without probing the
97 * device, but instead by searching the device that would request the
98 * given sequence number if probed. The UART will be used by the DM
99 * firmware image for various purposes and TIFS depends on us to
100 * initialize its pin settings.
101 */
102 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
103 if (!ret)
104 pinctrl_select_state(dev, "default");
105
106 if (IS_ENABLED(CONFIG_K3_EARLY_CONS)) {
107 /*
108 * Allow establishing an early console as required for example
109 * when doing a UART-based boot. Note that this console may not
110 * "survive" through a SYSFW PM-init step and will need a re-init
111 * in some way due to changing module clock frequencies.
112 */
113 ret = early_console_init();
114 if (ret)
115 panic("early_console_init() failed: %d\n", ret);
116 }
117
118 if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) {
119 /*
120 * Configure and start up system controller firmware. Provide
121 * the U-Boot console init function to the SYSFW post-PM
122 * configuration callback hook, effectively switching on (or
123 * over) the console output.
124 */
125 ret = is_rom_loaded_sysfw(&bootdata);
126 if (!ret)
127 panic("ROM has not loaded TIFS firmware\n");
128
129 k3_sysfw_loader(true, NULL, NULL);
130 }
131
132 /*
133 * Force probe of clk_k3 driver here to ensure basic default clock
134 * configuration is always done.
135 */
136 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
137 ret = uclass_get_device_by_driver(UCLASS_CLK,
138 DM_DRIVER_GET(ti_clk),
139 &dev);
140 if (ret)
141 printf("Failed to initialize clk-k3!\n");
142 }
143
144 preloader_console_init();
145
146 if (IS_ENABLED(CONFIG_CPU_V7R)) {
147 /* Disable ROM configured firewalls right after loading sysfw */
148 remove_fwl_configs(cbass_main_fwls, ARRAY_SIZE(cbass_main_fwls));
149 }
150
151 /* Output System Firmware version info */
152 k3_sysfw_print_ver();
153}
154
155static void k3_mem_init(void)
156{
157 struct udevice *dev;
158 int ret;
159
160 if (IS_ENABLED(CONFIG_K3_AM62A_DDRSS)) {
161 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
162 if (ret)
163 panic("DRAM init failed: %d\n", ret);
164 }
165}
166
Keerthy788d01e2025-02-17 16:27:17 +0530167static __maybe_unused void enable_mcu_esm_reset(void)
168{
169 /* Set CTRLMMR_MCU_RST_CTRL:MCU_ESM_ERROR_RST_EN_Z to '0' (low active) */
170 u32 stat = readl(CTRLMMR_MCU_RST_CTRL);
171
172 stat &= RST_CTRL_ESM_ERROR_RST_EN_Z_MASK;
173 writel(stat, CTRLMMR_MCU_RST_CTRL);
174}
175
Jayesh Choudhary732d2ff2024-06-12 14:41:18 +0530176void board_init_f(ulong dummy)
177{
Keerthy788d01e2025-02-17 16:27:17 +0530178 int ret;
179 struct udevice *dev;
180
Jayesh Choudhary732d2ff2024-06-12 14:41:18 +0530181 k3_spl_init();
182 k3_mem_init();
Jayesh Choudharyc35ba312024-11-26 12:36:11 +0530183 setup_qos();
Keerthy788d01e2025-02-17 16:27:17 +0530184
185 if (IS_ENABLED(CONFIG_ESM_K3)) {
186 /* Probe/configure ESM0 */
187 ret = uclass_get_device_by_name(UCLASS_MISC, "esm@420000", &dev);
188 if (ret) {
189 printf("esm main init failed: %d\n", ret);
190 return;
191 }
192
193 /* Probe/configure MCUESM */
194 ret = uclass_get_device_by_name(UCLASS_MISC, "esm@4100000", &dev);
195 if (ret) {
196 printf("esm mcu init failed: %d\n", ret);
197 return;
198 }
199 enable_mcu_esm_reset();
200 }
Jayesh Choudhary732d2ff2024-06-12 14:41:18 +0530201}
202
203static u32 __get_backup_bootmedia(u32 devstat)
204{
205 u32 bkup_bootmode = (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
206 MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT;
207 u32 bkup_bootmode_cfg =
208 (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >>
209 MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT;
210
211 switch (bkup_bootmode) {
212 case BACKUP_BOOT_DEVICE_UART:
213 return BOOT_DEVICE_UART;
214
215 case BACKUP_BOOT_DEVICE_USB:
216 return BOOT_DEVICE_USB;
217
218 case BACKUP_BOOT_DEVICE_ETHERNET:
219 return BOOT_DEVICE_ETHERNET;
220
221 case BACKUP_BOOT_DEVICE_MMC:
222 if (bkup_bootmode_cfg)
223 return BOOT_DEVICE_MMC2;
224 return BOOT_DEVICE_MMC1;
225
226 case BACKUP_BOOT_DEVICE_SPI:
227 return BOOT_DEVICE_SPI;
228
229 case BACKUP_BOOT_DEVICE_I2C:
230 return BOOT_DEVICE_I2C;
231
232 case BACKUP_BOOT_DEVICE_DFU:
233 if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE_MASK)
234 return BOOT_DEVICE_USB;
235 return BOOT_DEVICE_DFU;
236 };
237
238 return BOOT_DEVICE_RAM;
239}
240
241static u32 __get_primary_bootmedia(u32 devstat)
242{
243 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
244 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
245 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
246 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
247
248 switch (bootmode) {
249 case BOOT_DEVICE_OSPI:
250 fallthrough;
251 case BOOT_DEVICE_QSPI:
252 fallthrough;
253 case BOOT_DEVICE_XSPI:
254 fallthrough;
Vaishnav Achath177a4192024-12-18 18:43:40 +0530255 case BOOT_DEVICE_FAST_XSPI:
256 fallthrough;
Jayesh Choudhary732d2ff2024-06-12 14:41:18 +0530257 case BOOT_DEVICE_SPI:
258 return BOOT_DEVICE_SPI;
259
260 case BOOT_DEVICE_ETHERNET_RGMII:
261 fallthrough;
262 case BOOT_DEVICE_ETHERNET_RMII:
263 return BOOT_DEVICE_ETHERNET;
264
265 case BOOT_DEVICE_EMMC:
266 return BOOT_DEVICE_MMC1;
267
268 case BOOT_DEVICE_SPI_NAND:
269 return BOOT_DEVICE_SPINAND;
270
271 case BOOT_DEVICE_MMC:
272 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >>
273 MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT)
274 return BOOT_DEVICE_MMC2;
275 return BOOT_DEVICE_MMC1;
276
277 case BOOT_DEVICE_DFU:
278 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE_MASK) >>
279 MAIN_DEVSTAT_PRIMARY_USB_MODE_SHIFT)
280 return BOOT_DEVICE_USB;
281 return BOOT_DEVICE_DFU;
282
283 case BOOT_DEVICE_NOBOOT:
284 return BOOT_DEVICE_RAM;
285 }
286
287 return bootmode;
288}
289
290u32 spl_boot_device(void)
291{
292 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
293 u32 bootmedia;
294
295 if (bootindex == K3_PRIMARY_BOOTMODE)
296 bootmedia = __get_primary_bootmedia(devstat);
297 else
298 bootmedia = __get_backup_bootmedia(devstat);
299
300 debug("j722s_init: %s: devstat = 0x%x bootmedia = 0x%x bootindex = %d\n",
301 __func__, devstat, bootmedia, bootindex);
302 return bootmedia;
303}
304
305u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
306{
307 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
308 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
309 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
310 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
311 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
312
313 switch (bootmode) {
314 case BOOT_DEVICE_EMMC:
315 return MMCSD_MODE_EMMCBOOT;
316 case BOOT_DEVICE_MMC:
317 if (bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_FS_RAW_MASK)
318 return MMCSD_MODE_RAW;
319 default:
320 return MMCSD_MODE_FS;
321 }
322}