blob: c2024f2500dcda1f1fc746a4719607ad1bd50d1e [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
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050026#ifdef CONFIG_K3_LOAD_SYSFW
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050027struct fwl_data cbass_hc_cfg0_fwls[] = {
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053028#if defined(CONFIG_TARGET_J721E_R5_EVM)
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050029 { "PCIE0_CFG", 2560, 8 },
30 { "PCIE1_CFG", 2561, 8 },
31 { "USB3SS0_CORE", 2568, 4 },
32 { "USB3SS1_CORE", 2570, 4 },
33 { "EMMC8SS0_CFG", 2576, 4 },
34 { "UFS_HCI0_CFG", 2580, 4 },
35 { "SERDES0", 2584, 1 },
36 { "SERDES1", 2585, 1 },
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053037#elif defined(CONFIG_TARGET_J7200_R5_EVM)
38 { "PCIE1_CFG", 2561, 7 },
39#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050040}, cbass_hc0_fwls[] = {
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053041#if defined(CONFIG_TARGET_J721E_R5_EVM)
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050042 { "PCIE0_HP", 2528, 24 },
43 { "PCIE0_LP", 2529, 24 },
44 { "PCIE1_HP", 2530, 24 },
45 { "PCIE1_LP", 2531, 24 },
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053046#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050047}, cbass_rc_cfg0_fwls[] = {
48 { "EMMCSD4SS0_CFG", 2380, 4 },
49}, cbass_rc0_fwls[] = {
50 { "GPMC0", 2310, 8 },
51}, infra_cbass0_fwls[] = {
52 { "PLL_MMR0", 8, 26 },
53 { "CTRL_MMR0", 9, 16 },
54}, mcu_cbass0_fwls[] = {
55 { "MCU_R5FSS0_CORE0", 1024, 4 },
56 { "MCU_R5FSS0_CORE0_CFG", 1025, 2 },
57 { "MCU_R5FSS0_CORE1", 1028, 4 },
58 { "MCU_FSS0_CFG", 1032, 12 },
59 { "MCU_FSS0_S1", 1033, 8 },
60 { "MCU_FSS0_S0", 1036, 8 },
61 { "MCU_PSROM49152X32", 1048, 1 },
62 { "MCU_MSRAM128KX64", 1050, 8 },
63 { "MCU_CTRL_MMR0", 1200, 8 },
64 { "MCU_PLL_MMR0", 1201, 3 },
65 { "MCU_CPSW0", 1220, 2 },
66}, wkup_cbass0_fwls[] = {
67 { "WKUP_CTRL_MMR0", 131, 16 },
68};
69#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050070
Andreas Dannenberg660aa462019-06-13 10:29:44 +053071static void ctrl_mmr_unlock(void)
72{
73 /* Unlock all WKUP_CTRL_MMR0 module registers */
74 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
75 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
76 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
77 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
78 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
79 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
80 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
81
82 /* Unlock all MCU_CTRL_MMR0 module registers */
83 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
84 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
85 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
86 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
87 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
88
89 /* Unlock all CTRL_MMR0 module registers */
90 mmr_unlock(CTRL_MMR0_BASE, 0);
91 mmr_unlock(CTRL_MMR0_BASE, 1);
92 mmr_unlock(CTRL_MMR0_BASE, 2);
93 mmr_unlock(CTRL_MMR0_BASE, 3);
Andreas Dannenberg660aa462019-06-13 10:29:44 +053094 mmr_unlock(CTRL_MMR0_BASE, 5);
Lokesh Vutlad5bc6862020-08-05 22:44:20 +053095 if (soc_is_j721e())
96 mmr_unlock(CTRL_MMR0_BASE, 6);
Andreas Dannenberg660aa462019-06-13 10:29:44 +053097 mmr_unlock(CTRL_MMR0_BASE, 7);
98}
99
Faiz Abbas68393212020-02-26 13:44:36 +0530100#if defined(CONFIG_K3_LOAD_SYSFW)
101void k3_mmc_stop_clock(void)
102{
103 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
104 struct mmc *mmc = find_mmc_device(0);
105
106 if (!mmc)
107 return;
108
109 mmc->saved_clock = mmc->clock;
110 mmc_set_clock(mmc, 0, true);
111 }
112}
113
114void k3_mmc_restart_clock(void)
115{
116 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
117 struct mmc *mmc = find_mmc_device(0);
118
119 if (!mmc)
120 return;
121
122 mmc_set_clock(mmc, mmc->saved_clock, false);
123 }
124}
125#endif
126
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530127/*
128 * This uninitialized global variable would normal end up in the .bss section,
129 * but the .bss is cleared between writing and reading this variable, so move
130 * it to the .data section.
131 */
Marek Behún4bebdd32021-05-20 13:23:52 +0200132u32 bootindex __section(".data");
133static struct rom_extended_boot_data bootdata __section(".data");
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530134
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530135static void store_boot_info_from_rom(void)
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530136{
137 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Bryan Brattlof270537c2022-11-22 13:28:11 -0600138 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530139 sizeof(struct rom_extended_boot_data));
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530140}
141
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530142#ifdef CONFIG_SPL_OF_LIST
143void do_dt_magic(void)
144{
145 int ret, rescan, mmc_dev = -1;
146 static struct mmc *mmc;
147
Andrew Davis2dde9a72023-04-06 11:38:17 -0500148 /* Perform board detection */
149 do_board_detect();
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530150
151 /*
152 * Board detection has been done.
153 * Let us see if another dtb wouldn't be a better match
154 * for our board
155 */
156 if (IS_ENABLED(CONFIG_CPU_V7R)) {
157 ret = fdtdec_resetup(&rescan);
158 if (!ret && rescan) {
159 dm_uninit();
160 dm_init_and_scan(true);
161 }
162 }
163
164 /*
165 * Because of multi DTB configuration, the MMC device has
166 * to be re-initialized after reconfiguring FDT inorder to
167 * boot from MMC. Do this when boot mode is MMC and ROM has
168 * not loaded SYSFW.
169 */
170 switch (spl_boot_device()) {
171 case BOOT_DEVICE_MMC1:
172 mmc_dev = 0;
173 break;
174 case BOOT_DEVICE_MMC2:
175 case BOOT_DEVICE_MMC2_2:
176 mmc_dev = 1;
177 break;
178 }
179
180 if (mmc_dev > 0 && !is_rom_loaded_sysfw(&bootdata)) {
181 ret = mmc_init_device(mmc_dev);
182 if (!ret) {
183 mmc = find_mmc_device(mmc_dev);
184 if (mmc) {
185 ret = mmc_init(mmc);
186 if (ret) {
187 printf("mmc init failed with error: %d\n", ret);
188 }
189 }
190 }
191 }
192}
193#endif
194
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530195void board_init_f(ulong dummy)
196{
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530197#if defined(CONFIG_K3_J721E_DDRSS) || defined(CONFIG_K3_LOAD_SYSFW)
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530198 struct udevice *dev;
199 int ret;
200#endif
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530201 /*
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530202 * Cannot delay this further as there is a chance that
203 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530204 */
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530205 store_boot_info_from_rom();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530206
Andreas Dannenberg660aa462019-06-13 10:29:44 +0530207 /* Make all control module registers accessible */
208 ctrl_mmr_unlock();
209
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530210#ifdef CONFIG_CPU_V7R
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +0530211 disable_linefill_optimization();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530212 setup_k3_mpu_regions();
213#endif
214
215 /* Init DM early */
216 spl_early_init();
217
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530218#ifdef CONFIG_K3_LOAD_SYSFW
219 /*
220 * Process pinctrl for the serial0 a.k.a. MCU_UART0 module and continue
221 * regardless of the result of pinctrl. Do this without probing the
222 * device, but instead by searching the device that would request the
223 * given sequence number if probed. The UART will be used by the system
224 * firmware (SYSFW) image for various purposes and SYSFW depends on us
225 * to initialize its pin settings.
226 */
Simon Glass07e13382020-12-16 21:20:29 -0700227 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530228 if (!ret)
229 pinctrl_select_state(dev, "default");
230
231 /*
Neha Malcom Francis0e15b1f2023-09-27 18:39:52 +0530232 * Force probe of clk_k3 driver here to ensure basic default clock
233 * configuration is always done.
234 */
235 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
236 ret = uclass_get_device_by_driver(UCLASS_CLK,
237 DM_DRIVER_GET(ti_clk),
238 &dev);
239 if (ret)
240 panic("Failed to initialize clk-k3!\n");
241 }
242
243 /*
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530244 * Load, start up, and configure system controller firmware. Provide
245 * the U-Boot console init function to the SYSFW post-PM configuration
246 * callback hook, effectively switching on (or over) the console
247 * output.
248 */
Lokesh Vutla8be6bbf2020-08-05 22:44:23 +0530249 k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata),
250 k3_mmc_stop_clock, k3_mmc_restart_clock);
Faiz Abbas68393212020-02-26 13:44:36 +0530251
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530252#ifdef CONFIG_SPL_OF_LIST
253 do_dt_magic();
254#endif
255
Faiz Abbas68393212020-02-26 13:44:36 +0530256 /* Prepare console output */
257 preloader_console_init();
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500258
259 /* Disable ROM configured firewalls right after loading sysfw */
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500260 remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls));
261 remove_fwl_configs(cbass_hc0_fwls, ARRAY_SIZE(cbass_hc0_fwls));
262 remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls));
263 remove_fwl_configs(cbass_rc0_fwls, ARRAY_SIZE(cbass_rc0_fwls));
264 remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls));
265 remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls));
266 remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls));
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530267#else
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530268 /* Prepare console output */
269 preloader_console_init();
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530270#endif
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530271
Lokesh Vutla5fafe442020-03-10 16:50:58 +0530272 /* Output System Firmware version info */
273 k3_sysfw_print_ver();
274
Andrew Davis2dde9a72023-04-06 11:38:17 -0500275 /* Perform board detection */
276 do_board_detect();
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530277
Keerthy0b01f662019-10-24 15:00:53 +0530278#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
Simon Glass65130cd2020-12-28 20:34:56 -0700279 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
Keerthy0b01f662019-10-24 15:00:53 +0530280 &dev);
281 if (ret)
282 printf("AVS init failed: %d\n", ret);
283#endif
284
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530285#if defined(CONFIG_K3_J721E_DDRSS)
286 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
287 if (ret)
288 panic("DRAM init failed: %d\n", ret);
289#endif
Joao Paulo Goncalvesfc3557f2023-11-13 16:07:21 -0300290 spl_enable_cache();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530291}
Lokesh Vutla6edde292019-06-13 10:29:43 +0530292
Andre Przywara3cb12ef2021-07-12 11:06:49 +0100293u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
Lokesh Vutla6edde292019-06-13 10:29:43 +0530294{
295 switch (boot_device) {
296 case BOOT_DEVICE_MMC1:
Nishanth Menon0f36a4a2023-11-04 02:21:47 -0500297 if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT)) {
298 if (spl_mmc_emmc_boot_partition(mmc))
299 return MMCSD_MODE_EMMCBOOT;
300 return MMCSD_MODE_FS;
301 }
302 if (IS_ENABLED(CONFIG_SPL_FS_FAT) || IS_ENABLED(CONFIG_SPL_FS_EXT4))
303 return MMCSD_MODE_FS;
304 return MMCSD_MODE_EMMCBOOT;
Lokesh Vutla6edde292019-06-13 10:29:43 +0530305 case BOOT_DEVICE_MMC2:
306 return MMCSD_MODE_FS;
307 default:
308 return MMCSD_MODE_RAW;
309 }
310}
311
Andreas Dannenbergee0f5e62020-05-16 21:05:01 +0530312static u32 __get_backup_bootmedia(u32 main_devstat)
313{
314 u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
315 MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
316
317 switch (bkup_boot) {
318 case BACKUP_BOOT_DEVICE_USB:
319 return BOOT_DEVICE_DFU;
320 case BACKUP_BOOT_DEVICE_UART:
321 return BOOT_DEVICE_UART;
322 case BACKUP_BOOT_DEVICE_ETHERNET:
323 return BOOT_DEVICE_ETHERNET;
324 case BACKUP_BOOT_DEVICE_MMC2:
325 {
326 u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
327 MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
328 if (port == 0x0)
329 return BOOT_DEVICE_MMC1;
330 return BOOT_DEVICE_MMC2;
331 }
332 case BACKUP_BOOT_DEVICE_SPI:
333 return BOOT_DEVICE_SPI;
334 case BACKUP_BOOT_DEVICE_I2C:
335 return BOOT_DEVICE_I2C;
336 }
337
338 return BOOT_DEVICE_RAM;
339}
340
Lokesh Vutla6edde292019-06-13 10:29:43 +0530341static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
342{
343
344 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
345 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
346
347 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
348 BOOT_MODE_B_SHIFT;
349
Jonathan Humphreys9d797682024-02-23 18:23:06 -0600350 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI ||
351 bootmode == BOOT_DEVICE_XSPI)
Lokesh Vutla6edde292019-06-13 10:29:43 +0530352 bootmode = BOOT_DEVICE_SPI;
353
354 if (bootmode == BOOT_DEVICE_MMC2) {
355 u32 port = (main_devstat &
356 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
357 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
358 if (port == 0x0)
359 bootmode = BOOT_DEVICE_MMC1;
360 }
361
362 return bootmode;
363}
364
Vaishnav Achath146b6c12022-06-03 11:32:16 +0530365u32 spl_spi_boot_bus(void)
366{
367 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
368 u32 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
369 u32 bootmode = ((wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
370 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT) |
371 ((main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << BOOT_MODE_B_SHIFT);
372
373 return (bootmode == BOOT_DEVICE_QSPI) ? 1 : 0;
374}
375
Lokesh Vutla6edde292019-06-13 10:29:43 +0530376u32 spl_boot_device(void)
377{
378 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
379 u32 main_devstat;
380
381 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
382 printf("ERROR: MCU only boot is not yet supported\n");
383 return BOOT_DEVICE_RAM;
384 }
385
386 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
387 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
388
Andreas Dannenbergee0f5e62020-05-16 21:05:01 +0530389 if (bootindex == K3_PRIMARY_BOOTMODE)
390 return __get_primary_bootmedia(main_devstat, wkup_devstat);
391 else
392 return __get_backup_bootmedia(main_devstat);
Lokesh Vutla6edde292019-06-13 10:29:43 +0530393}