blob: c2976c4ea0dff92cb136ef8a9a460dc0e40dc785 [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>
Andrew Davisf1799852023-04-06 11:38:16 -050014#include "sysfw-loader.h"
Lokesh Vutlaa2285322019-06-13 10:29:42 +053015#include "common.h"
Lokesh Vutla96c11f42019-06-13 10:29:46 +053016#include <linux/soc/ti/ti_sci_protocol.h>
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +053017#include <dm.h>
18#include <dm/uclass-internal.h>
19#include <dm/pinctrl.h>
Sinthu Rajaa79cbe32022-02-09 15:06:53 +053020#include <dm/root.h>
21#include <fdtdec.h>
Faiz Abbas68393212020-02-26 13:44:36 +053022#include <mmc.h>
Keerthy7007adc2020-02-12 13:55:04 +053023#include <remoteproc.h>
Lokesh Vutlaa2285322019-06-13 10:29:42 +053024
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050025#ifdef CONFIG_K3_LOAD_SYSFW
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050026struct fwl_data cbass_hc_cfg0_fwls[] = {
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053027#if defined(CONFIG_TARGET_J721E_R5_EVM)
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050028 { "PCIE0_CFG", 2560, 8 },
29 { "PCIE1_CFG", 2561, 8 },
30 { "USB3SS0_CORE", 2568, 4 },
31 { "USB3SS1_CORE", 2570, 4 },
32 { "EMMC8SS0_CFG", 2576, 4 },
33 { "UFS_HCI0_CFG", 2580, 4 },
34 { "SERDES0", 2584, 1 },
35 { "SERDES1", 2585, 1 },
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053036#elif defined(CONFIG_TARGET_J7200_R5_EVM)
37 { "PCIE1_CFG", 2561, 7 },
38#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050039}, cbass_hc0_fwls[] = {
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053040#if defined(CONFIG_TARGET_J721E_R5_EVM)
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050041 { "PCIE0_HP", 2528, 24 },
42 { "PCIE0_LP", 2529, 24 },
43 { "PCIE1_HP", 2530, 24 },
44 { "PCIE1_LP", 2531, 24 },
Manorit Chawdhry43b818d2023-04-17 12:04:09 +053045#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050046}, cbass_rc_cfg0_fwls[] = {
47 { "EMMCSD4SS0_CFG", 2380, 4 },
48}, cbass_rc0_fwls[] = {
49 { "GPMC0", 2310, 8 },
50}, infra_cbass0_fwls[] = {
51 { "PLL_MMR0", 8, 26 },
52 { "CTRL_MMR0", 9, 16 },
53}, mcu_cbass0_fwls[] = {
54 { "MCU_R5FSS0_CORE0", 1024, 4 },
55 { "MCU_R5FSS0_CORE0_CFG", 1025, 2 },
56 { "MCU_R5FSS0_CORE1", 1028, 4 },
57 { "MCU_FSS0_CFG", 1032, 12 },
58 { "MCU_FSS0_S1", 1033, 8 },
59 { "MCU_FSS0_S0", 1036, 8 },
60 { "MCU_PSROM49152X32", 1048, 1 },
61 { "MCU_MSRAM128KX64", 1050, 8 },
62 { "MCU_CTRL_MMR0", 1200, 8 },
63 { "MCU_PLL_MMR0", 1201, 3 },
64 { "MCU_CPSW0", 1220, 2 },
65}, wkup_cbass0_fwls[] = {
66 { "WKUP_CTRL_MMR0", 131, 16 },
67};
68#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050069
Andreas Dannenberg660aa462019-06-13 10:29:44 +053070static void ctrl_mmr_unlock(void)
71{
72 /* Unlock all WKUP_CTRL_MMR0 module registers */
73 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
74 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
75 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
76 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
77 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
78 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
79 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
80
81 /* Unlock all MCU_CTRL_MMR0 module registers */
82 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
83 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
84 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
85 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
86 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
87
88 /* Unlock all CTRL_MMR0 module registers */
89 mmr_unlock(CTRL_MMR0_BASE, 0);
90 mmr_unlock(CTRL_MMR0_BASE, 1);
91 mmr_unlock(CTRL_MMR0_BASE, 2);
92 mmr_unlock(CTRL_MMR0_BASE, 3);
Andreas Dannenberg660aa462019-06-13 10:29:44 +053093 mmr_unlock(CTRL_MMR0_BASE, 5);
Lokesh Vutlad5bc6862020-08-05 22:44:20 +053094 if (soc_is_j721e())
95 mmr_unlock(CTRL_MMR0_BASE, 6);
Andreas Dannenberg660aa462019-06-13 10:29:44 +053096 mmr_unlock(CTRL_MMR0_BASE, 7);
97}
98
Faiz Abbas68393212020-02-26 13:44:36 +053099#if defined(CONFIG_K3_LOAD_SYSFW)
100void k3_mmc_stop_clock(void)
101{
102 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
103 struct mmc *mmc = find_mmc_device(0);
104
105 if (!mmc)
106 return;
107
108 mmc->saved_clock = mmc->clock;
109 mmc_set_clock(mmc, 0, true);
110 }
111}
112
113void k3_mmc_restart_clock(void)
114{
115 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
116 struct mmc *mmc = find_mmc_device(0);
117
118 if (!mmc)
119 return;
120
121 mmc_set_clock(mmc, mmc->saved_clock, false);
122 }
123}
124#endif
125
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530126/*
127 * This uninitialized global variable would normal end up in the .bss section,
128 * but the .bss is cleared between writing and reading this variable, so move
129 * it to the .data section.
130 */
Marek Behún4bebdd32021-05-20 13:23:52 +0200131u32 bootindex __section(".data");
132static struct rom_extended_boot_data bootdata __section(".data");
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530133
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530134static void store_boot_info_from_rom(void)
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530135{
136 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Bryan Brattlof270537c2022-11-22 13:28:11 -0600137 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530138 sizeof(struct rom_extended_boot_data));
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530139}
140
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530141#ifdef CONFIG_SPL_OF_LIST
142void do_dt_magic(void)
143{
144 int ret, rescan, mmc_dev = -1;
145 static struct mmc *mmc;
146
Andrew Davis2dde9a72023-04-06 11:38:17 -0500147 /* Perform board detection */
148 do_board_detect();
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530149
150 /*
151 * Board detection has been done.
152 * Let us see if another dtb wouldn't be a better match
153 * for our board
154 */
155 if (IS_ENABLED(CONFIG_CPU_V7R)) {
156 ret = fdtdec_resetup(&rescan);
157 if (!ret && rescan) {
158 dm_uninit();
159 dm_init_and_scan(true);
160 }
161 }
162
163 /*
164 * Because of multi DTB configuration, the MMC device has
165 * to be re-initialized after reconfiguring FDT inorder to
166 * boot from MMC. Do this when boot mode is MMC and ROM has
167 * not loaded SYSFW.
168 */
169 switch (spl_boot_device()) {
170 case BOOT_DEVICE_MMC1:
171 mmc_dev = 0;
172 break;
173 case BOOT_DEVICE_MMC2:
174 case BOOT_DEVICE_MMC2_2:
175 mmc_dev = 1;
176 break;
177 }
178
179 if (mmc_dev > 0 && !is_rom_loaded_sysfw(&bootdata)) {
180 ret = mmc_init_device(mmc_dev);
181 if (!ret) {
182 mmc = find_mmc_device(mmc_dev);
183 if (mmc) {
184 ret = mmc_init(mmc);
185 if (ret) {
186 printf("mmc init failed with error: %d\n", ret);
187 }
188 }
189 }
190 }
191}
192#endif
193
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530194void board_init_f(ulong dummy)
195{
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530196#if defined(CONFIG_K3_J721E_DDRSS) || defined(CONFIG_K3_LOAD_SYSFW)
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530197 struct udevice *dev;
198 int ret;
199#endif
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530200 /*
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530201 * Cannot delay this further as there is a chance that
202 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530203 */
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530204 store_boot_info_from_rom();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530205
Andreas Dannenberg660aa462019-06-13 10:29:44 +0530206 /* Make all control module registers accessible */
207 ctrl_mmr_unlock();
208
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530209#ifdef CONFIG_CPU_V7R
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +0530210 disable_linefill_optimization();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530211 setup_k3_mpu_regions();
212#endif
213
214 /* Init DM early */
215 spl_early_init();
216
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530217#ifdef CONFIG_K3_LOAD_SYSFW
218 /*
219 * Process pinctrl for the serial0 a.k.a. MCU_UART0 module and continue
220 * regardless of the result of pinctrl. Do this without probing the
221 * device, but instead by searching the device that would request the
222 * given sequence number if probed. The UART will be used by the system
223 * firmware (SYSFW) image for various purposes and SYSFW depends on us
224 * to initialize its pin settings.
225 */
Simon Glass07e13382020-12-16 21:20:29 -0700226 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530227 if (!ret)
228 pinctrl_select_state(dev, "default");
229
230 /*
Neha Malcom Francis0e15b1f2023-09-27 18:39:52 +0530231 * Force probe of clk_k3 driver here to ensure basic default clock
232 * configuration is always done.
233 */
234 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
235 ret = uclass_get_device_by_driver(UCLASS_CLK,
236 DM_DRIVER_GET(ti_clk),
237 &dev);
238 if (ret)
239 panic("Failed to initialize clk-k3!\n");
240 }
241
242 /*
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530243 * Load, start up, and configure system controller firmware. Provide
244 * the U-Boot console init function to the SYSFW post-PM configuration
245 * callback hook, effectively switching on (or over) the console
246 * output.
247 */
Lokesh Vutla8be6bbf2020-08-05 22:44:23 +0530248 k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata),
249 k3_mmc_stop_clock, k3_mmc_restart_clock);
Faiz Abbas68393212020-02-26 13:44:36 +0530250
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530251#ifdef CONFIG_SPL_OF_LIST
252 do_dt_magic();
253#endif
254
Faiz Abbas68393212020-02-26 13:44:36 +0530255 /* Prepare console output */
256 preloader_console_init();
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500257
258 /* Disable ROM configured firewalls right after loading sysfw */
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500259 remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls));
260 remove_fwl_configs(cbass_hc0_fwls, ARRAY_SIZE(cbass_hc0_fwls));
261 remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls));
262 remove_fwl_configs(cbass_rc0_fwls, ARRAY_SIZE(cbass_rc0_fwls));
263 remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls));
264 remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls));
265 remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls));
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530266#else
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530267 /* Prepare console output */
268 preloader_console_init();
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530269#endif
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530270
Lokesh Vutla5fafe442020-03-10 16:50:58 +0530271 /* Output System Firmware version info */
272 k3_sysfw_print_ver();
273
Andrew Davis2dde9a72023-04-06 11:38:17 -0500274 /* Perform board detection */
275 do_board_detect();
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530276
Keerthy0b01f662019-10-24 15:00:53 +0530277#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
Simon Glass65130cd2020-12-28 20:34:56 -0700278 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
Keerthy0b01f662019-10-24 15:00:53 +0530279 &dev);
280 if (ret)
281 printf("AVS init failed: %d\n", ret);
282#endif
283
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530284#if defined(CONFIG_K3_J721E_DDRSS)
285 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
286 if (ret)
287 panic("DRAM init failed: %d\n", ret);
288#endif
Joao Paulo Goncalvesfc3557f2023-11-13 16:07:21 -0300289 spl_enable_cache();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530290}
Lokesh Vutla6edde292019-06-13 10:29:43 +0530291
Andre Przywara3cb12ef2021-07-12 11:06:49 +0100292u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
Lokesh Vutla6edde292019-06-13 10:29:43 +0530293{
294 switch (boot_device) {
295 case BOOT_DEVICE_MMC1:
Nishanth Menon0f36a4a2023-11-04 02:21:47 -0500296 if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT)) {
297 if (spl_mmc_emmc_boot_partition(mmc))
298 return MMCSD_MODE_EMMCBOOT;
299 return MMCSD_MODE_FS;
300 }
301 if (IS_ENABLED(CONFIG_SPL_FS_FAT) || IS_ENABLED(CONFIG_SPL_FS_EXT4))
302 return MMCSD_MODE_FS;
303 return MMCSD_MODE_EMMCBOOT;
Lokesh Vutla6edde292019-06-13 10:29:43 +0530304 case BOOT_DEVICE_MMC2:
305 return MMCSD_MODE_FS;
306 default:
307 return MMCSD_MODE_RAW;
308 }
309}
310
Andreas Dannenbergee0f5e62020-05-16 21:05:01 +0530311static u32 __get_backup_bootmedia(u32 main_devstat)
312{
313 u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
314 MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
315
316 switch (bkup_boot) {
317 case BACKUP_BOOT_DEVICE_USB:
318 return BOOT_DEVICE_DFU;
319 case BACKUP_BOOT_DEVICE_UART:
320 return BOOT_DEVICE_UART;
321 case BACKUP_BOOT_DEVICE_ETHERNET:
322 return BOOT_DEVICE_ETHERNET;
323 case BACKUP_BOOT_DEVICE_MMC2:
324 {
325 u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
326 MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
327 if (port == 0x0)
328 return BOOT_DEVICE_MMC1;
329 return BOOT_DEVICE_MMC2;
330 }
331 case BACKUP_BOOT_DEVICE_SPI:
332 return BOOT_DEVICE_SPI;
333 case BACKUP_BOOT_DEVICE_I2C:
334 return BOOT_DEVICE_I2C;
335 }
336
337 return BOOT_DEVICE_RAM;
338}
339
Lokesh Vutla6edde292019-06-13 10:29:43 +0530340static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
341{
342
343 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
344 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
345
346 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
347 BOOT_MODE_B_SHIFT;
348
349 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
350 bootmode = BOOT_DEVICE_SPI;
351
352 if (bootmode == BOOT_DEVICE_MMC2) {
353 u32 port = (main_devstat &
354 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
355 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
356 if (port == 0x0)
357 bootmode = BOOT_DEVICE_MMC1;
358 }
359
360 return bootmode;
361}
362
Vaishnav Achath146b6c12022-06-03 11:32:16 +0530363u32 spl_spi_boot_bus(void)
364{
365 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
366 u32 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
367 u32 bootmode = ((wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
368 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT) |
369 ((main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << BOOT_MODE_B_SHIFT);
370
371 return (bootmode == BOOT_DEVICE_QSPI) ? 1 : 0;
372}
373
Lokesh Vutla6edde292019-06-13 10:29:43 +0530374u32 spl_boot_device(void)
375{
376 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
377 u32 main_devstat;
378
379 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
380 printf("ERROR: MCU only boot is not yet supported\n");
381 return BOOT_DEVICE_RAM;
382 }
383
384 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
385 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
386
Andreas Dannenbergee0f5e62020-05-16 21:05:01 +0530387 if (bootindex == K3_PRIMARY_BOOTMODE)
388 return __get_primary_bootmedia(main_devstat, wkup_devstat);
389 else
390 return __get_backup_bootmedia(main_devstat);
Lokesh Vutla6edde292019-06-13 10:29:43 +0530391}