blob: 9bba5f795456e3befe34c468fce80885bdeaae1e [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[] = {
28 { "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 },
36}, cbass_hc0_fwls[] = {
37 { "PCIE0_HP", 2528, 24 },
38 { "PCIE0_LP", 2529, 24 },
39 { "PCIE1_HP", 2530, 24 },
40 { "PCIE1_LP", 2531, 24 },
41}, cbass_rc_cfg0_fwls[] = {
42 { "EMMCSD4SS0_CFG", 2380, 4 },
43}, cbass_rc0_fwls[] = {
44 { "GPMC0", 2310, 8 },
45}, infra_cbass0_fwls[] = {
46 { "PLL_MMR0", 8, 26 },
47 { "CTRL_MMR0", 9, 16 },
48}, mcu_cbass0_fwls[] = {
49 { "MCU_R5FSS0_CORE0", 1024, 4 },
50 { "MCU_R5FSS0_CORE0_CFG", 1025, 2 },
51 { "MCU_R5FSS0_CORE1", 1028, 4 },
52 { "MCU_FSS0_CFG", 1032, 12 },
53 { "MCU_FSS0_S1", 1033, 8 },
54 { "MCU_FSS0_S0", 1036, 8 },
55 { "MCU_PSROM49152X32", 1048, 1 },
56 { "MCU_MSRAM128KX64", 1050, 8 },
57 { "MCU_CTRL_MMR0", 1200, 8 },
58 { "MCU_PLL_MMR0", 1201, 3 },
59 { "MCU_CPSW0", 1220, 2 },
60}, wkup_cbass0_fwls[] = {
61 { "WKUP_CTRL_MMR0", 131, 16 },
62};
63#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050064
Andreas Dannenberg660aa462019-06-13 10:29:44 +053065static void ctrl_mmr_unlock(void)
66{
67 /* Unlock all WKUP_CTRL_MMR0 module registers */
68 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
69 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
70 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
71 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
72 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
73 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
74 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
75
76 /* Unlock all MCU_CTRL_MMR0 module registers */
77 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
78 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
79 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
80 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
81 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
82
83 /* Unlock all CTRL_MMR0 module registers */
84 mmr_unlock(CTRL_MMR0_BASE, 0);
85 mmr_unlock(CTRL_MMR0_BASE, 1);
86 mmr_unlock(CTRL_MMR0_BASE, 2);
87 mmr_unlock(CTRL_MMR0_BASE, 3);
Andreas Dannenberg660aa462019-06-13 10:29:44 +053088 mmr_unlock(CTRL_MMR0_BASE, 5);
Lokesh Vutlad5bc6862020-08-05 22:44:20 +053089 if (soc_is_j721e())
90 mmr_unlock(CTRL_MMR0_BASE, 6);
Andreas Dannenberg660aa462019-06-13 10:29:44 +053091 mmr_unlock(CTRL_MMR0_BASE, 7);
92}
93
Faiz Abbas68393212020-02-26 13:44:36 +053094#if defined(CONFIG_K3_LOAD_SYSFW)
95void k3_mmc_stop_clock(void)
96{
97 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
98 struct mmc *mmc = find_mmc_device(0);
99
100 if (!mmc)
101 return;
102
103 mmc->saved_clock = mmc->clock;
104 mmc_set_clock(mmc, 0, true);
105 }
106}
107
108void k3_mmc_restart_clock(void)
109{
110 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
111 struct mmc *mmc = find_mmc_device(0);
112
113 if (!mmc)
114 return;
115
116 mmc_set_clock(mmc, mmc->saved_clock, false);
117 }
118}
119#endif
120
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530121/*
122 * This uninitialized global variable would normal end up in the .bss section,
123 * but the .bss is cleared between writing and reading this variable, so move
124 * it to the .data section.
125 */
Marek BehĂșn4bebdd32021-05-20 13:23:52 +0200126u32 bootindex __section(".data");
127static struct rom_extended_boot_data bootdata __section(".data");
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530128
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530129static void store_boot_info_from_rom(void)
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530130{
131 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Bryan Brattlof270537c2022-11-22 13:28:11 -0600132 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530133 sizeof(struct rom_extended_boot_data));
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530134}
135
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530136#ifdef CONFIG_SPL_OF_LIST
137void do_dt_magic(void)
138{
139 int ret, rescan, mmc_dev = -1;
140 static struct mmc *mmc;
141
Andrew Davis2dde9a72023-04-06 11:38:17 -0500142 /* Perform board detection */
143 do_board_detect();
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530144
145 /*
146 * Board detection has been done.
147 * Let us see if another dtb wouldn't be a better match
148 * for our board
149 */
150 if (IS_ENABLED(CONFIG_CPU_V7R)) {
151 ret = fdtdec_resetup(&rescan);
152 if (!ret && rescan) {
153 dm_uninit();
154 dm_init_and_scan(true);
155 }
156 }
157
158 /*
159 * Because of multi DTB configuration, the MMC device has
160 * to be re-initialized after reconfiguring FDT inorder to
161 * boot from MMC. Do this when boot mode is MMC and ROM has
162 * not loaded SYSFW.
163 */
164 switch (spl_boot_device()) {
165 case BOOT_DEVICE_MMC1:
166 mmc_dev = 0;
167 break;
168 case BOOT_DEVICE_MMC2:
169 case BOOT_DEVICE_MMC2_2:
170 mmc_dev = 1;
171 break;
172 }
173
174 if (mmc_dev > 0 && !is_rom_loaded_sysfw(&bootdata)) {
175 ret = mmc_init_device(mmc_dev);
176 if (!ret) {
177 mmc = find_mmc_device(mmc_dev);
178 if (mmc) {
179 ret = mmc_init(mmc);
180 if (ret) {
181 printf("mmc init failed with error: %d\n", ret);
182 }
183 }
184 }
185 }
186}
187#endif
188
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530189void board_init_f(ulong dummy)
190{
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530191#if defined(CONFIG_K3_J721E_DDRSS) || defined(CONFIG_K3_LOAD_SYSFW)
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530192 struct udevice *dev;
193 int ret;
194#endif
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530195 /*
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530196 * Cannot delay this further as there is a chance that
197 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530198 */
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530199 store_boot_info_from_rom();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530200
Andreas Dannenberg660aa462019-06-13 10:29:44 +0530201 /* Make all control module registers accessible */
202 ctrl_mmr_unlock();
203
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530204#ifdef CONFIG_CPU_V7R
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +0530205 disable_linefill_optimization();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530206 setup_k3_mpu_regions();
207#endif
208
209 /* Init DM early */
210 spl_early_init();
211
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530212#ifdef CONFIG_K3_LOAD_SYSFW
213 /*
214 * Process pinctrl for the serial0 a.k.a. MCU_UART0 module and continue
215 * regardless of the result of pinctrl. Do this without probing the
216 * device, but instead by searching the device that would request the
217 * given sequence number if probed. The UART will be used by the system
218 * firmware (SYSFW) image for various purposes and SYSFW depends on us
219 * to initialize its pin settings.
220 */
Simon Glass07e13382020-12-16 21:20:29 -0700221 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530222 if (!ret)
223 pinctrl_select_state(dev, "default");
224
225 /*
226 * Load, start up, and configure system controller firmware. Provide
227 * the U-Boot console init function to the SYSFW post-PM configuration
228 * callback hook, effectively switching on (or over) the console
229 * output.
230 */
Lokesh Vutla8be6bbf2020-08-05 22:44:23 +0530231 k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata),
232 k3_mmc_stop_clock, k3_mmc_restart_clock);
Faiz Abbas68393212020-02-26 13:44:36 +0530233
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530234#ifdef CONFIG_SPL_OF_LIST
235 do_dt_magic();
236#endif
237
Dave Gerlach9cda54d2021-06-11 11:45:23 +0300238 /*
239 * Force probe of clk_k3 driver here to ensure basic default clock
240 * configuration is always done.
241 */
242 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
243 ret = uclass_get_device_by_driver(UCLASS_CLK,
244 DM_DRIVER_GET(ti_clk),
245 &dev);
246 if (ret)
247 panic("Failed to initialize clk-k3!\n");
248 }
249
Faiz Abbas68393212020-02-26 13:44:36 +0530250 /* Prepare console output */
251 preloader_console_init();
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500252
253 /* Disable ROM configured firewalls right after loading sysfw */
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500254 remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls));
255 remove_fwl_configs(cbass_hc0_fwls, ARRAY_SIZE(cbass_hc0_fwls));
256 remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls));
257 remove_fwl_configs(cbass_rc0_fwls, ARRAY_SIZE(cbass_rc0_fwls));
258 remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls));
259 remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls));
260 remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls));
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530261#else
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530262 /* Prepare console output */
263 preloader_console_init();
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530264#endif
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530265
Lokesh Vutla5fafe442020-03-10 16:50:58 +0530266 /* Output System Firmware version info */
267 k3_sysfw_print_ver();
268
Andrew Davis2dde9a72023-04-06 11:38:17 -0500269 /* Perform board detection */
270 do_board_detect();
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530271
Keerthy0b01f662019-10-24 15:00:53 +0530272#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
Simon Glass65130cd2020-12-28 20:34:56 -0700273 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
Keerthy0b01f662019-10-24 15:00:53 +0530274 &dev);
275 if (ret)
276 printf("AVS init failed: %d\n", ret);
277#endif
278
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530279#if defined(CONFIG_K3_J721E_DDRSS)
280 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
281 if (ret)
282 panic("DRAM init failed: %d\n", ret);
283#endif
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200284 spl_enable_dcache();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530285}
Lokesh Vutla6edde292019-06-13 10:29:43 +0530286
Andre Przywara3cb12ef2021-07-12 11:06:49 +0100287u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
Lokesh Vutla6edde292019-06-13 10:29:43 +0530288{
289 switch (boot_device) {
290 case BOOT_DEVICE_MMC1:
291 return MMCSD_MODE_EMMCBOOT;
292 case BOOT_DEVICE_MMC2:
293 return MMCSD_MODE_FS;
294 default:
295 return MMCSD_MODE_RAW;
296 }
297}
298
Andreas Dannenbergee0f5e62020-05-16 21:05:01 +0530299static u32 __get_backup_bootmedia(u32 main_devstat)
300{
301 u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
302 MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
303
304 switch (bkup_boot) {
305 case BACKUP_BOOT_DEVICE_USB:
306 return BOOT_DEVICE_DFU;
307 case BACKUP_BOOT_DEVICE_UART:
308 return BOOT_DEVICE_UART;
309 case BACKUP_BOOT_DEVICE_ETHERNET:
310 return BOOT_DEVICE_ETHERNET;
311 case BACKUP_BOOT_DEVICE_MMC2:
312 {
313 u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
314 MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
315 if (port == 0x0)
316 return BOOT_DEVICE_MMC1;
317 return BOOT_DEVICE_MMC2;
318 }
319 case BACKUP_BOOT_DEVICE_SPI:
320 return BOOT_DEVICE_SPI;
321 case BACKUP_BOOT_DEVICE_I2C:
322 return BOOT_DEVICE_I2C;
323 }
324
325 return BOOT_DEVICE_RAM;
326}
327
Lokesh Vutla6edde292019-06-13 10:29:43 +0530328static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
329{
330
331 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
332 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
333
334 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
335 BOOT_MODE_B_SHIFT;
336
337 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
338 bootmode = BOOT_DEVICE_SPI;
339
340 if (bootmode == BOOT_DEVICE_MMC2) {
341 u32 port = (main_devstat &
342 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
343 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
344 if (port == 0x0)
345 bootmode = BOOT_DEVICE_MMC1;
346 }
347
348 return bootmode;
349}
350
Vaishnav Achath146b6c12022-06-03 11:32:16 +0530351u32 spl_spi_boot_bus(void)
352{
353 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
354 u32 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
355 u32 bootmode = ((wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
356 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT) |
357 ((main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << BOOT_MODE_B_SHIFT);
358
359 return (bootmode == BOOT_DEVICE_QSPI) ? 1 : 0;
360}
361
Lokesh Vutla6edde292019-06-13 10:29:43 +0530362u32 spl_boot_device(void)
363{
364 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
365 u32 main_devstat;
366
367 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
368 printf("ERROR: MCU only boot is not yet supported\n");
369 return BOOT_DEVICE_RAM;
370 }
371
372 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
373 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
374
Andreas Dannenbergee0f5e62020-05-16 21:05:01 +0530375 if (bootindex == K3_PRIMARY_BOOTMODE)
376 return __get_primary_bootmedia(main_devstat, wkup_devstat);
377 else
378 return __get_backup_bootmedia(main_devstat);
Lokesh Vutla6edde292019-06-13 10:29:43 +0530379}