blob: e9ed8cb267c101c4498352541b68d8494ee5eb2f [file] [log] [blame]
Lokesh Vutlaa2285322019-06-13 10:29:42 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * J721E: SoC specific initialization
4 *
Nishanth Menoneaa39c62023-11-01 15:56:03 -05005 * Copyright (C) 2018-2019 Texas Instruments Incorporated - https://www.ti.com/
Lokesh Vutlaa2285322019-06-13 10:29:42 +05306 * Lokesh Vutla <lokeshvutla@ti.com>
7 */
8
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Lokesh Vutlaa2285322019-06-13 10:29:42 +053010#include <spl.h>
11#include <asm/io.h>
12#include <asm/armv7_mpu.h>
Lokesh Vutla6edde292019-06-13 10:29:43 +053013#include <asm/arch/hardware.h>
Lokesh Vutla96c11f42019-06-13 10:29:46 +053014#include <linux/soc/ti/ti_sci_protocol.h>
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +053015#include <dm.h>
16#include <dm/uclass-internal.h>
17#include <dm/pinctrl.h>
Sinthu Rajaa79cbe32022-02-09 15:06:53 +053018#include <dm/root.h>
19#include <fdtdec.h>
Faiz Abbas68393212020-02-26 13:44:36 +053020#include <mmc.h>
Keerthy7007adc2020-02-12 13:55:04 +053021#include <remoteproc.h>
Lokesh Vutlaa2285322019-06-13 10:29:42 +053022
Andrew Davis336b0792024-05-10 15:21:24 -050023#include "../sysfw-loader.h"
24#include "../common.h"
25
Jayesh Choudhary3aa50582024-06-14 18:14:37 +053026/* NAVSS North Bridge (NB) registers */
27#define NAVSS0_NBSS_NB0_CFG_MMRS 0x03802000
28#define NAVSS0_NBSS_NB1_CFG_MMRS 0x03803000
29#define NAVSS0_NBSS_NB0_CFG_NB_THREADMAP (NAVSS0_NBSS_NB0_CFG_MMRS + 0x10)
30#define NAVSS0_NBSS_NB1_CFG_NB_THREADMAP (NAVSS0_NBSS_NB1_CFG_MMRS + 0x10)
31/*
32 * Thread Map for North Bridge Configuration
33 * Each bit is for each VBUSM source.
34 * Bit[0] maps orderID 0-7 to VBUSM.C thread number
35 * Bit[1] maps orderID 8-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
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050042#ifdef CONFIG_K3_LOAD_SYSFW
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050043struct fwl_data cbass_hc_cfg0_fwls[] = {
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053044#if defined(CONFIG_TARGET_J721E_R5_EVM)
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050045 { "PCIE0_CFG", 2560, 8 },
46 { "PCIE1_CFG", 2561, 8 },
47 { "USB3SS0_CORE", 2568, 4 },
48 { "USB3SS1_CORE", 2570, 4 },
49 { "EMMC8SS0_CFG", 2576, 4 },
50 { "UFS_HCI0_CFG", 2580, 4 },
51 { "SERDES0", 2584, 1 },
52 { "SERDES1", 2585, 1 },
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053053#elif defined(CONFIG_TARGET_J7200_R5_EVM)
54 { "PCIE1_CFG", 2561, 7 },
55#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050056}, cbass_hc0_fwls[] = {
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053057#if defined(CONFIG_TARGET_J721E_R5_EVM)
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050058 { "PCIE0_HP", 2528, 24 },
59 { "PCIE0_LP", 2529, 24 },
60 { "PCIE1_HP", 2530, 24 },
61 { "PCIE1_LP", 2531, 24 },
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053062#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050063}, cbass_rc_cfg0_fwls[] = {
64 { "EMMCSD4SS0_CFG", 2380, 4 },
65}, cbass_rc0_fwls[] = {
66 { "GPMC0", 2310, 8 },
67}, infra_cbass0_fwls[] = {
68 { "PLL_MMR0", 8, 26 },
69 { "CTRL_MMR0", 9, 16 },
70}, mcu_cbass0_fwls[] = {
71 { "MCU_R5FSS0_CORE0", 1024, 4 },
72 { "MCU_R5FSS0_CORE0_CFG", 1025, 2 },
73 { "MCU_R5FSS0_CORE1", 1028, 4 },
74 { "MCU_FSS0_CFG", 1032, 12 },
75 { "MCU_FSS0_S1", 1033, 8 },
76 { "MCU_FSS0_S0", 1036, 8 },
77 { "MCU_PSROM49152X32", 1048, 1 },
78 { "MCU_MSRAM128KX64", 1050, 8 },
79 { "MCU_CTRL_MMR0", 1200, 8 },
80 { "MCU_PLL_MMR0", 1201, 3 },
81 { "MCU_CPSW0", 1220, 2 },
82}, wkup_cbass0_fwls[] = {
83 { "WKUP_CTRL_MMR0", 131, 16 },
84};
85#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050086
Andreas Dannenberg660aa462019-06-13 10:29:44 +053087static void ctrl_mmr_unlock(void)
88{
89 /* Unlock all WKUP_CTRL_MMR0 module registers */
90 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
91 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
92 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
93 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
94 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
95 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
96 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
97
98 /* Unlock all MCU_CTRL_MMR0 module registers */
99 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
100 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
101 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
102 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
103 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
104
105 /* Unlock all CTRL_MMR0 module registers */
106 mmr_unlock(CTRL_MMR0_BASE, 0);
107 mmr_unlock(CTRL_MMR0_BASE, 1);
108 mmr_unlock(CTRL_MMR0_BASE, 2);
109 mmr_unlock(CTRL_MMR0_BASE, 3);
Andreas Dannenberg660aa462019-06-13 10:29:44 +0530110 mmr_unlock(CTRL_MMR0_BASE, 5);
Lokesh Vutlad5bc6862020-08-05 22:44:20 +0530111 if (soc_is_j721e())
112 mmr_unlock(CTRL_MMR0_BASE, 6);
Andreas Dannenberg660aa462019-06-13 10:29:44 +0530113 mmr_unlock(CTRL_MMR0_BASE, 7);
114}
115
Faiz Abbas68393212020-02-26 13:44:36 +0530116#if defined(CONFIG_K3_LOAD_SYSFW)
117void k3_mmc_stop_clock(void)
118{
119 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
120 struct mmc *mmc = find_mmc_device(0);
121
122 if (!mmc)
123 return;
124
125 mmc->saved_clock = mmc->clock;
126 mmc_set_clock(mmc, 0, true);
127 }
128}
129
130void k3_mmc_restart_clock(void)
131{
132 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
133 struct mmc *mmc = find_mmc_device(0);
134
135 if (!mmc)
136 return;
137
138 mmc_set_clock(mmc, mmc->saved_clock, false);
139 }
140}
141#endif
142
Jayesh Choudhary3aa50582024-06-14 18:14:37 +0530143/* Setup North Bridge registers to map ORDERID 8-15 to RT traffic */
144static void setup_navss_nb(void)
145{
146 writel(NB_THREADMAP_BIT1, (uintptr_t)NAVSS0_NBSS_NB0_CFG_NB_THREADMAP);
147 writel(NB_THREADMAP_BIT1, (uintptr_t)NAVSS0_NBSS_NB1_CFG_NB_THREADMAP);
148}
149
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530150/*
151 * This uninitialized global variable would normal end up in the .bss section,
152 * but the .bss is cleared between writing and reading this variable, so move
153 * it to the .data section.
154 */
Marek Behún4bebdd32021-05-20 13:23:52 +0200155u32 bootindex __section(".data");
156static struct rom_extended_boot_data bootdata __section(".data");
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530157
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530158static void store_boot_info_from_rom(void)
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530159{
160 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Bryan Brattlof270537c2022-11-22 13:28:11 -0600161 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530162 sizeof(struct rom_extended_boot_data));
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530163}
164
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530165#ifdef CONFIG_SPL_OF_LIST
166void do_dt_magic(void)
167{
168 int ret, rescan, mmc_dev = -1;
169 static struct mmc *mmc;
170
Andrew Davis2dde9a72023-04-06 11:38:17 -0500171 /* Perform board detection */
172 do_board_detect();
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530173
174 /*
175 * Board detection has been done.
176 * Let us see if another dtb wouldn't be a better match
177 * for our board
178 */
179 if (IS_ENABLED(CONFIG_CPU_V7R)) {
180 ret = fdtdec_resetup(&rescan);
181 if (!ret && rescan) {
182 dm_uninit();
183 dm_init_and_scan(true);
184 }
185 }
186
187 /*
188 * Because of multi DTB configuration, the MMC device has
189 * to be re-initialized after reconfiguring FDT inorder to
190 * boot from MMC. Do this when boot mode is MMC and ROM has
191 * not loaded SYSFW.
192 */
193 switch (spl_boot_device()) {
194 case BOOT_DEVICE_MMC1:
195 mmc_dev = 0;
196 break;
197 case BOOT_DEVICE_MMC2:
198 case BOOT_DEVICE_MMC2_2:
199 mmc_dev = 1;
200 break;
201 }
202
203 if (mmc_dev > 0 && !is_rom_loaded_sysfw(&bootdata)) {
204 ret = mmc_init_device(mmc_dev);
205 if (!ret) {
206 mmc = find_mmc_device(mmc_dev);
207 if (mmc) {
208 ret = mmc_init(mmc);
209 if (ret) {
210 printf("mmc init failed with error: %d\n", ret);
211 }
212 }
213 }
214 }
215}
216#endif
217
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530218void board_init_f(ulong dummy)
219{
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530220#if defined(CONFIG_K3_J721E_DDRSS) || defined(CONFIG_K3_LOAD_SYSFW)
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530221 struct udevice *dev;
222 int ret;
223#endif
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530224 /*
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530225 * Cannot delay this further as there is a chance that
226 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530227 */
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530228 store_boot_info_from_rom();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530229
Andreas Dannenberg660aa462019-06-13 10:29:44 +0530230 /* Make all control module registers accessible */
231 ctrl_mmr_unlock();
232
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530233#ifdef CONFIG_CPU_V7R
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +0530234 disable_linefill_optimization();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530235 setup_k3_mpu_regions();
236#endif
237
238 /* Init DM early */
239 spl_early_init();
240
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530241#ifdef CONFIG_K3_LOAD_SYSFW
242 /*
243 * Process pinctrl for the serial0 a.k.a. MCU_UART0 module and continue
244 * regardless of the result of pinctrl. Do this without probing the
245 * device, but instead by searching the device that would request the
246 * given sequence number if probed. The UART will be used by the system
247 * firmware (SYSFW) image for various purposes and SYSFW depends on us
248 * to initialize its pin settings.
249 */
Simon Glass07e13382020-12-16 21:20:29 -0700250 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530251 if (!ret)
252 pinctrl_select_state(dev, "default");
253
254 /*
Neha Malcom Francis0e15b1f2023-09-27 18:39:52 +0530255 * Force probe of clk_k3 driver here to ensure basic default clock
256 * configuration is always done.
257 */
258 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
259 ret = uclass_get_device_by_driver(UCLASS_CLK,
260 DM_DRIVER_GET(ti_clk),
261 &dev);
262 if (ret)
263 panic("Failed to initialize clk-k3!\n");
264 }
265
266 /*
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530267 * Load, start up, and configure system controller firmware. Provide
268 * the U-Boot console init function to the SYSFW post-PM configuration
269 * callback hook, effectively switching on (or over) the console
270 * output.
271 */
Lokesh Vutla8be6bbf2020-08-05 22:44:23 +0530272 k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata),
273 k3_mmc_stop_clock, k3_mmc_restart_clock);
Faiz Abbas68393212020-02-26 13:44:36 +0530274
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530275#ifdef CONFIG_SPL_OF_LIST
276 do_dt_magic();
277#endif
278
Faiz Abbas68393212020-02-26 13:44:36 +0530279 /* Prepare console output */
280 preloader_console_init();
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500281
282 /* Disable ROM configured firewalls right after loading sysfw */
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500283 remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls));
284 remove_fwl_configs(cbass_hc0_fwls, ARRAY_SIZE(cbass_hc0_fwls));
285 remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls));
286 remove_fwl_configs(cbass_rc0_fwls, ARRAY_SIZE(cbass_rc0_fwls));
287 remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls));
288 remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls));
289 remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls));
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530290#else
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530291 /* Prepare console output */
292 preloader_console_init();
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530293#endif
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530294
Lokesh Vutla5fafe442020-03-10 16:50:58 +0530295 /* Output System Firmware version info */
296 k3_sysfw_print_ver();
297
Andrew Davis2dde9a72023-04-06 11:38:17 -0500298 /* Perform board detection */
299 do_board_detect();
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530300
Keerthy0b01f662019-10-24 15:00:53 +0530301#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
Simon Glass65130cd2020-12-28 20:34:56 -0700302 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
Keerthy0b01f662019-10-24 15:00:53 +0530303 &dev);
304 if (ret)
305 printf("AVS init failed: %d\n", ret);
306#endif
307
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530308#if defined(CONFIG_K3_J721E_DDRSS)
309 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
310 if (ret)
311 panic("DRAM init failed: %d\n", ret);
312#endif
Joao Paulo Goncalvesfc3557f2023-11-13 16:07:21 -0300313 spl_enable_cache();
Jayesh Choudhary3aa50582024-06-14 18:14:37 +0530314
315 if (IS_ENABLED(CONFIG_CPU_V7R))
316 setup_navss_nb();
317
318 setup_qos();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530319}
Lokesh Vutla6edde292019-06-13 10:29:43 +0530320
Andre Przywara3cb12ef2021-07-12 11:06:49 +0100321u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
Lokesh Vutla6edde292019-06-13 10:29:43 +0530322{
323 switch (boot_device) {
324 case BOOT_DEVICE_MMC1:
Nishanth Menon0f36a4a2023-11-04 02:21:47 -0500325 if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT)) {
326 if (spl_mmc_emmc_boot_partition(mmc))
327 return MMCSD_MODE_EMMCBOOT;
328 return MMCSD_MODE_FS;
329 }
330 if (IS_ENABLED(CONFIG_SPL_FS_FAT) || IS_ENABLED(CONFIG_SPL_FS_EXT4))
331 return MMCSD_MODE_FS;
332 return MMCSD_MODE_EMMCBOOT;
Lokesh Vutla6edde292019-06-13 10:29:43 +0530333 case BOOT_DEVICE_MMC2:
334 return MMCSD_MODE_FS;
335 default:
336 return MMCSD_MODE_RAW;
337 }
338}
339
Andreas Dannenbergee0f5e62020-05-16 21:05:01 +0530340static u32 __get_backup_bootmedia(u32 main_devstat)
341{
342 u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
343 MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
344
345 switch (bkup_boot) {
346 case BACKUP_BOOT_DEVICE_USB:
347 return BOOT_DEVICE_DFU;
348 case BACKUP_BOOT_DEVICE_UART:
349 return BOOT_DEVICE_UART;
350 case BACKUP_BOOT_DEVICE_ETHERNET:
351 return BOOT_DEVICE_ETHERNET;
352 case BACKUP_BOOT_DEVICE_MMC2:
353 {
354 u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
355 MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
356 if (port == 0x0)
357 return BOOT_DEVICE_MMC1;
358 return BOOT_DEVICE_MMC2;
359 }
360 case BACKUP_BOOT_DEVICE_SPI:
361 return BOOT_DEVICE_SPI;
362 case BACKUP_BOOT_DEVICE_I2C:
363 return BOOT_DEVICE_I2C;
364 }
365
366 return BOOT_DEVICE_RAM;
367}
368
Lokesh Vutla6edde292019-06-13 10:29:43 +0530369static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
370{
371
372 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
373 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
374
375 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
376 BOOT_MODE_B_SHIFT;
377
Jonathan Humphreys9d797682024-02-23 18:23:06 -0600378 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI ||
379 bootmode == BOOT_DEVICE_XSPI)
Lokesh Vutla6edde292019-06-13 10:29:43 +0530380 bootmode = BOOT_DEVICE_SPI;
381
382 if (bootmode == BOOT_DEVICE_MMC2) {
383 u32 port = (main_devstat &
384 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
385 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
386 if (port == 0x0)
387 bootmode = BOOT_DEVICE_MMC1;
388 }
389
390 return bootmode;
391}
392
Vaishnav Achath146b6c12022-06-03 11:32:16 +0530393u32 spl_spi_boot_bus(void)
394{
395 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
396 u32 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
397 u32 bootmode = ((wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
398 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT) |
399 ((main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << BOOT_MODE_B_SHIFT);
400
401 return (bootmode == BOOT_DEVICE_QSPI) ? 1 : 0;
402}
403
Lokesh Vutla6edde292019-06-13 10:29:43 +0530404u32 spl_boot_device(void)
405{
406 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
407 u32 main_devstat;
408
409 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
410 printf("ERROR: MCU only boot is not yet supported\n");
411 return BOOT_DEVICE_RAM;
412 }
413
414 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
415 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
416
Andreas Dannenbergee0f5e62020-05-16 21:05:01 +0530417 if (bootindex == K3_PRIMARY_BOOTMODE)
418 return __get_primary_bootmedia(main_devstat, wkup_devstat);
419 else
420 return __get_backup_bootmedia(main_devstat);
Lokesh Vutla6edde292019-06-13 10:29:43 +0530421}