blob: 05453fcad41a628a71f17010dcc5c52307368e17 [file] [log] [blame]
David Huang61098202022-01-25 20:56:31 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * J721E: SoC specific initialization
4 *
Nishanth Menoneaa39c62023-11-01 15:56:03 -05005 * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com/
David Huang61098202022-01-25 20:56:31 +05306 * David Huang <d-huang@ti.com>
7 */
8
David Huang61098202022-01-25 20:56:31 +05309#include <init.h>
10#include <spl.h>
11#include <asm/io.h>
12#include <asm/armv7_mpu.h>
13#include <asm/arch/hardware.h>
David Huang61098202022-01-25 20:56:31 +053014#include <linux/soc/ti/ti_sci_protocol.h>
15#include <dm.h>
16#include <dm/uclass-internal.h>
17#include <dm/pinctrl.h>
Andrew Davisde20b952023-04-06 11:38:20 -050018#include <dm/root.h>
David Huang61098202022-01-25 20:56:31 +053019#include <mmc.h>
20#include <remoteproc.h>
21
Andrew Davis336b0792024-05-10 15:21:24 -050022#include "../sysfw-loader.h"
23#include "../common.h"
24
Jayesh Choudharye1f87a02024-06-14 18:14:38 +053025/* NAVSS North Bridge (NB) */
26#define NAVSS0_NBSS_NB0_CFG_MMRS 0x03702000
27#define NAVSS0_NBSS_NB1_CFG_MMRS 0x03703000
28#define NAVSS0_NBSS_NB0_CFG_NB_THREADMAP (NAVSS0_NBSS_NB0_CFG_MMRS + 0x10)
29#define NAVSS0_NBSS_NB1_CFG_NB_THREADMAP (NAVSS0_NBSS_NB1_CFG_MMRS + 0x10)
30/*
31 * Thread Map for North Bridge Configuration
32 * Each bit is for each VBUSM source.
33 * Bit[0] maps orderID 0-3 to VBUSM.C thread number
34 * Bit[1] maps orderID 4-9 to VBUSM.C thread number
35 * Bit[2] maps orderID 10-15 to VBUSM.C thread number
36 * When bit has value 0: VBUSM.C thread 0 (non-real time traffic)
37 * When bit has value 1: VBUSM.C thread 2 (real time traffic)
38 */
39#define NB_THREADMAP_BIT0 BIT(0)
40#define NB_THREADMAP_BIT1 BIT(1)
41#define NB_THREADMAP_BIT2 BIT(2)
42
Jayesh Choudhary7796c722023-03-28 18:32:01 +053043struct fwl_data cbass_hc_cfg0_fwls[] = {
44 { "PCIE0_CFG", 2577, 7 },
45 { "EMMC8SS0_CFG", 2579, 4 },
46 { "USB3SS0_CORE", 2580, 4 },
47 { "USB3SS1_CORE", 2581, 1 },
48}, cbass_hc2_fwls[] = {
49 { "PCIE0", 2547, 24 },
50 { "HC2_WIZ16B8M4CT2", 2552, 1 },
51}, cbass_rc_cfg0_fwls[] = {
52 { "EMMCSD4SS0_CFG", 2400, 4 },
53}, infra_cbass0_fwls[] = {
54 { "PSC0", 5, 1 },
55 { "PLL_CTRL0", 6, 1 },
56 { "PLL_MMR0", 8, 26 },
57 { "CTRL_MMR0", 9, 16 },
58 { "GPIO0", 16, 1 },
59}, mcu_cbass0_fwls[] = {
60 { "MCU_R5FSS0_CORE0", 1024, 4 },
61 { "MCU_R5FSS0_CORE0_CFG", 1025, 3 },
62 { "MCU_R5FSS0_CORE1", 1028, 4 },
63 { "MCU_R5FSS0_CORE1_CFG", 1029, 1 },
64 { "MCU_FSS0_CFG", 1032, 12 },
65 { "MCU_FSS0_S1", 1033, 8 },
66 { "MCU_FSS0_S0", 1036, 8 },
67 { "MCU_PSROM49152X32", 1048, 1 },
68 { "MCU_MSRAM128KX64", 1050, 8 },
69 { "MCU_MSRAM128KX64_CFG", 1051, 1 },
70 { "MCU_TIMER0", 1056, 1 },
71 { "MCU_TIMER9", 1065, 1 },
72 { "MCU_USART0", 1120, 1 },
73 { "MCU_I2C0", 1152, 1 },
74 { "MCU_CTRL_MMR0", 1200, 8 },
75 { "MCU_PLL_MMR0", 1201, 3 },
76 { "MCU_CPSW0", 1220, 2 },
77}, wkup_cbass0_fwls[] = {
78 { "WKUP_PSC0", 129, 1 },
79 { "WKUP_PLL_CTRL0", 130, 1 },
80 { "WKUP_CTRL_MMR0", 131, 16 },
81 { "WKUP_GPIO0", 132, 1 },
82 { "WKUP_I2C0", 144, 1 },
83 { "WKUP_USART0", 160, 1 },
84}, navss_cbass0_fwls[] = {
85 { "NACSS_VIRT0", 6253, 1 },
86};
87
David Huang61098202022-01-25 20:56:31 +053088static void ctrl_mmr_unlock(void)
89{
90 /* Unlock all WKUP_CTRL_MMR0 module registers */
91 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
92 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
93 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
94 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
95 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
96 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
97 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
98
99 /* Unlock all MCU_CTRL_MMR0 module registers */
100 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
101 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
102 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
103 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
104 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
105
106 /* Unlock all CTRL_MMR0 module registers */
107 mmr_unlock(CTRL_MMR0_BASE, 0);
108 mmr_unlock(CTRL_MMR0_BASE, 1);
109 mmr_unlock(CTRL_MMR0_BASE, 2);
110 mmr_unlock(CTRL_MMR0_BASE, 3);
111 mmr_unlock(CTRL_MMR0_BASE, 5);
112 mmr_unlock(CTRL_MMR0_BASE, 7);
113}
114
115void k3_mmc_stop_clock(void)
116{
117 if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) {
118 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
119 struct mmc *mmc = find_mmc_device(0);
120
121 if (!mmc)
122 return;
123
124 mmc->saved_clock = mmc->clock;
125 mmc_set_clock(mmc, 0, true);
126 }
127 }
128}
129
130void k3_mmc_restart_clock(void)
131{
132 if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) {
133 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
134 struct mmc *mmc = find_mmc_device(0);
135
136 if (!mmc)
137 return;
138
139 mmc_set_clock(mmc, mmc->saved_clock, false);
140 }
141 }
142}
143
Jayesh Choudharye1f87a02024-06-14 18:14:38 +0530144/* Setup North Bridge registers to map ORDERID 10-15 to RT traffic */
145static void setup_navss_nb(void)
146{
147 writel(NB_THREADMAP_BIT1, (uintptr_t)NAVSS0_NBSS_NB0_CFG_NB_THREADMAP);
148 writel(NB_THREADMAP_BIT2, (uintptr_t)NAVSS0_NBSS_NB1_CFG_NB_THREADMAP);
149}
150
David Huang61098202022-01-25 20:56:31 +0530151/*
152 * This uninitialized global variable would normal end up in the .bss section,
153 * but the .bss is cleared between writing and reading this variable, so move
154 * it to the .data section.
155 */
156u32 bootindex __attribute__((section(".data")));
157static struct rom_extended_boot_data bootdata __section(".data");
158
159static void store_boot_info_from_rom(void)
160{
161 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Bryan Brattlof270537c2022-11-22 13:28:11 -0600162 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
David Huang61098202022-01-25 20:56:31 +0530163 sizeof(struct rom_extended_boot_data));
164}
165
Sinthu Raja863839a2023-01-10 21:17:53 +0530166void k3_spl_init(void)
David Huang61098202022-01-25 20:56:31 +0530167{
168 struct udevice *dev;
169 int ret;
170 /*
171 * Cannot delay this further as there is a chance that
172 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
173 */
174 store_boot_info_from_rom();
175
176 /* Make all control module registers accessible */
177 ctrl_mmr_unlock();
178
179 if (IS_ENABLED(CONFIG_CPU_V7R)) {
180 disable_linefill_optimization();
181 setup_k3_mpu_regions();
182 }
183
184 /* Init DM early */
185 spl_early_init();
186
187 /* Prepare console output */
188 preloader_console_init();
189
190 if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) {
191 /*
192 * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue
193 * regardless of the result of pinctrl. Do this without probing the
194 * device, but instead by searching the device that would request the
195 * given sequence number if probed. The UART will be used by the system
196 * firmware (SYSFW) image for various purposes and SYSFW depends on us
197 * to initialize its pin settings.
198 */
199 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
200 if (!ret)
201 pinctrl_select_state(dev, "default");
202
203 /*
204 * Load, start up, and configure system controller firmware. Provide
205 * the U-Boot console init function to the SYSFW post-PM configuration
206 * callback hook, effectively switching on (or over) the console
207 * output.
208 */
209 k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata),
210 k3_mmc_stop_clock, k3_mmc_restart_clock);
211
212 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
213 /*
214 * Force probe of clk_k3 driver here to ensure basic default clock
215 * configuration is always done for enabling PM services.
216 */
217 ret = uclass_get_device_by_driver(UCLASS_CLK,
218 DM_DRIVER_GET(ti_clk),
219 &dev);
220 if (ret)
221 panic("Failed to initialize clk-k3!\n");
222 }
Jayesh Choudhary7796c722023-03-28 18:32:01 +0530223
224 remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls));
225 remove_fwl_configs(cbass_hc2_fwls, ARRAY_SIZE(cbass_hc2_fwls));
226 remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls));
227 remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls));
228 remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls));
229 remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls));
230 remove_fwl_configs(navss_cbass0_fwls, ARRAY_SIZE(navss_cbass0_fwls));
David Huang61098202022-01-25 20:56:31 +0530231 }
232
233 /* Output System Firmware version info */
234 k3_sysfw_print_ver();
Sinthu Raja863839a2023-01-10 21:17:53 +0530235}
236
237bool check_rom_loaded_sysfw(void)
238{
239 return is_rom_loaded_sysfw(&bootdata);
240}
241
242void k3_mem_init(void)
243{
244 struct udevice *dev;
245 int ret;
David Huang61098202022-01-25 20:56:31 +0530246
Dominik Haller6e95f872023-08-11 12:04:44 +0200247 if (IS_ENABLED(CONFIG_K3_J721E_DDRSS)) {
David Huang61098202022-01-25 20:56:31 +0530248 ret = uclass_get_device_by_name(UCLASS_MISC, "msmc", &dev);
249 if (ret)
250 panic("Probe of msmc failed: %d\n", ret);
251
252 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
253 if (ret)
254 panic("DRAM 0 init failed: %d\n", ret);
255
Michal Suchanek93ccce52022-10-12 21:58:00 +0200256 ret = uclass_next_device_err(&dev);
Neha Malcom Francis37d200e2024-01-30 15:53:56 +0530257 if (ret && ret != -ENODEV)
David Huang61098202022-01-25 20:56:31 +0530258 panic("DRAM 1 init failed: %d\n", ret);
259 }
Joao Paulo Goncalvesfc3557f2023-11-13 16:07:21 -0300260 spl_enable_cache();
David Huang61098202022-01-25 20:56:31 +0530261}
262
Andrew Davisde20b952023-04-06 11:38:20 -0500263/* Support for the various EVM / SK families */
264#if defined(CONFIG_SPL_OF_LIST) && defined(CONFIG_TI_I2C_BOARD_DETECT)
265void do_dt_magic(void)
266{
267 int ret, rescan, mmc_dev = -1;
268 static struct mmc *mmc;
269
270 do_board_detect();
271
272 /*
273 * Board detection has been done.
274 * Let us see if another dtb wouldn't be a better match
275 * for our board
276 */
277 if (IS_ENABLED(CONFIG_CPU_V7R)) {
278 ret = fdtdec_resetup(&rescan);
279 if (!ret && rescan) {
280 dm_uninit();
281 dm_init_and_scan(true);
282 }
283 }
284
285 /*
286 * Because of multi DTB configuration, the MMC device has
287 * to be re-initialized after reconfiguring FDT inorder to
288 * boot from MMC. Do this when boot mode is MMC and ROM has
289 * not loaded SYSFW.
290 */
291 switch (spl_boot_device()) {
292 case BOOT_DEVICE_MMC1:
293 mmc_dev = 0;
294 break;
295 case BOOT_DEVICE_MMC2:
296 case BOOT_DEVICE_MMC2_2:
297 mmc_dev = 1;
298 break;
299 }
300
301 if (mmc_dev > 0 && !check_rom_loaded_sysfw()) {
302 ret = mmc_init_device(mmc_dev);
303 if (!ret) {
304 mmc = find_mmc_device(mmc_dev);
305 if (mmc) {
306 ret = mmc_init(mmc);
307 if (ret)
308 printf("mmc init failed with error: %d\n", ret);
309 }
310 }
311 }
312}
313#endif
314
315#ifdef CONFIG_SPL_BUILD
316void board_init_f(ulong dummy)
317{
318 k3_spl_init();
319#if defined(CONFIG_SPL_OF_LIST) && defined(CONFIG_TI_I2C_BOARD_DETECT)
320 do_dt_magic();
321#endif
322 k3_mem_init();
Jayesh Choudharye1f87a02024-06-14 18:14:38 +0530323
324 if (IS_ENABLED(CONFIG_CPU_V7R))
325 setup_navss_nb();
326
327 setup_qos();
Andrew Davisde20b952023-04-06 11:38:20 -0500328}
329#endif
330
Andre Przywara3cb12ef2021-07-12 11:06:49 +0100331u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
David Huang61098202022-01-25 20:56:31 +0530332{
333 switch (boot_device) {
334 case BOOT_DEVICE_MMC1:
335 return MMCSD_MODE_EMMCBOOT;
336 case BOOT_DEVICE_MMC2:
337 return MMCSD_MODE_FS;
338 default:
339 return MMCSD_MODE_RAW;
340 }
341}
342
343static u32 __get_backup_bootmedia(u32 main_devstat)
344{
345 u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
346 MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
347
348 switch (bkup_boot) {
349 case BACKUP_BOOT_DEVICE_USB:
350 return BOOT_DEVICE_DFU;
351 case BACKUP_BOOT_DEVICE_UART:
352 return BOOT_DEVICE_UART;
353 case BACKUP_BOOT_DEVICE_ETHERNET:
354 return BOOT_DEVICE_ETHERNET;
355 case BACKUP_BOOT_DEVICE_MMC2:
356 {
357 u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
358 MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
359 if (port == 0x0)
360 return BOOT_DEVICE_MMC1;
361 return BOOT_DEVICE_MMC2;
362 }
363 case BACKUP_BOOT_DEVICE_SPI:
364 return BOOT_DEVICE_SPI;
365 case BACKUP_BOOT_DEVICE_I2C:
366 return BOOT_DEVICE_I2C;
367 }
368
369 return BOOT_DEVICE_RAM;
370}
371
372static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
373{
374 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
375 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
376
377 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
378 BOOT_MODE_B_SHIFT;
379
380 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI ||
381 bootmode == BOOT_DEVICE_XSPI)
382 bootmode = BOOT_DEVICE_SPI;
383
384 if (bootmode == BOOT_DEVICE_MMC2) {
385 u32 port = (main_devstat &
386 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
387 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
388 if (port == 0x0)
389 bootmode = BOOT_DEVICE_MMC1;
390 }
391
392 return bootmode;
393}
394
395u32 spl_boot_device(void)
396{
397 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
398 u32 main_devstat;
399
400 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
401 printf("ERROR: MCU only boot is not yet supported\n");
402 return BOOT_DEVICE_RAM;
403 }
404
405 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
406 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
407
408 if (bootindex == K3_PRIMARY_BOOTMODE)
409 return __get_primary_bootmedia(main_devstat, wkup_devstat);
410 else
411 return __get_backup_bootmedia(main_devstat);
412}