blob: b6164575b7bac5ceebae656d9c79e2fc160196f8 [file] [log] [blame]
Lokesh Vutlaa2285322019-06-13 10:29:42 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * J721E: SoC specific initialization
4 *
5 * Copyright (C) 2018-2019 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
7 */
8
9#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Lokesh Vutlaa2285322019-06-13 10:29:42 +053011#include <spl.h>
12#include <asm/io.h>
13#include <asm/armv7_mpu.h>
Lokesh Vutla6edde292019-06-13 10:29:43 +053014#include <asm/arch/hardware.h>
Andrew Davisf1799852023-04-06 11:38:16 -050015#include "sysfw-loader.h"
Lokesh Vutlaa2285322019-06-13 10:29:42 +053016#include "common.h"
Lokesh Vutla96c11f42019-06-13 10:29:46 +053017#include <linux/soc/ti/ti_sci_protocol.h>
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +053018#include <dm.h>
19#include <dm/uclass-internal.h>
20#include <dm/pinctrl.h>
Sinthu Rajaa79cbe32022-02-09 15:06:53 +053021#include <dm/root.h>
22#include <fdtdec.h>
Faiz Abbas68393212020-02-26 13:44:36 +053023#include <mmc.h>
Keerthy7007adc2020-02-12 13:55:04 +053024#include <remoteproc.h>
Lokesh Vutlaa2285322019-06-13 10:29:42 +053025
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 /*
232 * Load, start up, and configure system controller firmware. Provide
233 * the U-Boot console init function to the SYSFW post-PM configuration
234 * callback hook, effectively switching on (or over) the console
235 * output.
236 */
Lokesh Vutla8be6bbf2020-08-05 22:44:23 +0530237 k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata),
238 k3_mmc_stop_clock, k3_mmc_restart_clock);
Faiz Abbas68393212020-02-26 13:44:36 +0530239
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530240#ifdef CONFIG_SPL_OF_LIST
241 do_dt_magic();
242#endif
243
Dave Gerlach9cda54d2021-06-11 11:45:23 +0300244 /*
245 * Force probe of clk_k3 driver here to ensure basic default clock
246 * configuration is always done.
247 */
248 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
249 ret = uclass_get_device_by_driver(UCLASS_CLK,
250 DM_DRIVER_GET(ti_clk),
251 &dev);
252 if (ret)
253 panic("Failed to initialize clk-k3!\n");
254 }
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
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200290 spl_enable_dcache();
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:
Udit Kumar17d0b132023-05-11 14:47:50 +0530297 return (spl_mmc_emmc_boot_partition(mmc) ? MMCSD_MODE_EMMCBOOT : MMCSD_MODE_FS);
Lokesh Vutla6edde292019-06-13 10:29:43 +0530298 case BOOT_DEVICE_MMC2:
299 return MMCSD_MODE_FS;
300 default:
301 return MMCSD_MODE_RAW;
302 }
303}
304
Andreas Dannenbergee0f5e62020-05-16 21:05:01 +0530305static u32 __get_backup_bootmedia(u32 main_devstat)
306{
307 u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
308 MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
309
310 switch (bkup_boot) {
311 case BACKUP_BOOT_DEVICE_USB:
312 return BOOT_DEVICE_DFU;
313 case BACKUP_BOOT_DEVICE_UART:
314 return BOOT_DEVICE_UART;
315 case BACKUP_BOOT_DEVICE_ETHERNET:
316 return BOOT_DEVICE_ETHERNET;
317 case BACKUP_BOOT_DEVICE_MMC2:
318 {
319 u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
320 MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
321 if (port == 0x0)
322 return BOOT_DEVICE_MMC1;
323 return BOOT_DEVICE_MMC2;
324 }
325 case BACKUP_BOOT_DEVICE_SPI:
326 return BOOT_DEVICE_SPI;
327 case BACKUP_BOOT_DEVICE_I2C:
328 return BOOT_DEVICE_I2C;
329 }
330
331 return BOOT_DEVICE_RAM;
332}
333
Lokesh Vutla6edde292019-06-13 10:29:43 +0530334static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
335{
336
337 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
338 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
339
340 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
341 BOOT_MODE_B_SHIFT;
342
343 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
344 bootmode = BOOT_DEVICE_SPI;
345
346 if (bootmode == BOOT_DEVICE_MMC2) {
347 u32 port = (main_devstat &
348 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
349 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
350 if (port == 0x0)
351 bootmode = BOOT_DEVICE_MMC1;
352 }
353
354 return bootmode;
355}
356
Vaishnav Achath146b6c12022-06-03 11:32:16 +0530357u32 spl_spi_boot_bus(void)
358{
359 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
360 u32 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
361 u32 bootmode = ((wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
362 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT) |
363 ((main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << BOOT_MODE_B_SHIFT);
364
365 return (bootmode == BOOT_DEVICE_QSPI) ? 1 : 0;
366}
367
Lokesh Vutla6edde292019-06-13 10:29:43 +0530368u32 spl_boot_device(void)
369{
370 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
371 u32 main_devstat;
372
373 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
374 printf("ERROR: MCU only boot is not yet supported\n");
375 return BOOT_DEVICE_RAM;
376 }
377
378 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
379 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
380
Andreas Dannenbergee0f5e62020-05-16 21:05:01 +0530381 if (bootindex == K3_PRIMARY_BOOTMODE)
382 return __get_primary_bootmedia(main_devstat, wkup_devstat);
383 else
384 return __get_backup_bootmedia(main_devstat);
Lokesh Vutla6edde292019-06-13 10:29:43 +0530385}