1 // SPDX-License-Identifier: GPL-2.0+
3 * J721E: SoC specific initialization
5 * Copyright (C) 2018-2019 Texas Instruments Incorporated - https://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
12 #include <asm/armv7_mpu.h>
13 #include <asm/arch/hardware.h>
14 #include "sysfw-loader.h"
16 #include <linux/soc/ti/ti_sci_protocol.h>
18 #include <dm/uclass-internal.h>
19 #include <dm/pinctrl.h>
23 #include <remoteproc.h>
25 #ifdef CONFIG_K3_LOAD_SYSFW
26 struct fwl_data cbass_hc_cfg0_fwls[] = {
27 #if defined(CONFIG_TARGET_J721E_R5_EVM)
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 #elif defined(CONFIG_TARGET_J7200_R5_EVM)
37 { "PCIE1_CFG", 2561, 7 },
39 }, cbass_hc0_fwls[] = {
40 #if defined(CONFIG_TARGET_J721E_R5_EVM)
41 { "PCIE0_HP", 2528, 24 },
42 { "PCIE0_LP", 2529, 24 },
43 { "PCIE1_HP", 2530, 24 },
44 { "PCIE1_LP", 2531, 24 },
46 }, cbass_rc_cfg0_fwls[] = {
47 { "EMMCSD4SS0_CFG", 2380, 4 },
48 }, cbass_rc0_fwls[] = {
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 },
70 static void ctrl_mmr_unlock(void)
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);
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);
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);
93 mmr_unlock(CTRL_MMR0_BASE, 5);
95 mmr_unlock(CTRL_MMR0_BASE, 6);
96 mmr_unlock(CTRL_MMR0_BASE, 7);
99 #if defined(CONFIG_K3_LOAD_SYSFW)
100 void k3_mmc_stop_clock(void)
102 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
103 struct mmc *mmc = find_mmc_device(0);
108 mmc->saved_clock = mmc->clock;
109 mmc_set_clock(mmc, 0, true);
113 void k3_mmc_restart_clock(void)
115 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
116 struct mmc *mmc = find_mmc_device(0);
121 mmc_set_clock(mmc, mmc->saved_clock, false);
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.
131 u32 bootindex __section(".data");
132 static struct rom_extended_boot_data bootdata __section(".data");
134 static void store_boot_info_from_rom(void)
136 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
137 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
138 sizeof(struct rom_extended_boot_data));
141 #ifdef CONFIG_SPL_OF_LIST
142 void do_dt_magic(void)
144 int ret, rescan, mmc_dev = -1;
145 static struct mmc *mmc;
147 /* Perform board detection */
151 * Board detection has been done.
152 * Let us see if another dtb wouldn't be a better match
155 if (IS_ENABLED(CONFIG_CPU_V7R)) {
156 ret = fdtdec_resetup(&rescan);
157 if (!ret && rescan) {
159 dm_init_and_scan(true);
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
169 switch (spl_boot_device()) {
170 case BOOT_DEVICE_MMC1:
173 case BOOT_DEVICE_MMC2:
174 case BOOT_DEVICE_MMC2_2:
179 if (mmc_dev > 0 && !is_rom_loaded_sysfw(&bootdata)) {
180 ret = mmc_init_device(mmc_dev);
182 mmc = find_mmc_device(mmc_dev);
186 printf("mmc init failed with error: %d\n", ret);
194 void board_init_f(ulong dummy)
196 #if defined(CONFIG_K3_J721E_DDRSS) || defined(CONFIG_K3_LOAD_SYSFW)
201 * Cannot delay this further as there is a chance that
202 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
204 store_boot_info_from_rom();
206 /* Make all control module registers accessible */
209 #ifdef CONFIG_CPU_V7R
210 disable_linefill_optimization();
211 setup_k3_mpu_regions();
217 #ifdef CONFIG_K3_LOAD_SYSFW
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.
226 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
228 pinctrl_select_state(dev, "default");
231 * Force probe of clk_k3 driver here to ensure basic default clock
232 * configuration is always done.
234 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
235 ret = uclass_get_device_by_driver(UCLASS_CLK,
236 DM_DRIVER_GET(ti_clk),
239 panic("Failed to initialize clk-k3!\n");
243 * 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
248 k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata),
249 k3_mmc_stop_clock, k3_mmc_restart_clock);
251 #ifdef CONFIG_SPL_OF_LIST
255 /* Prepare console output */
256 preloader_console_init();
258 /* Disable ROM configured firewalls right after loading sysfw */
259 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));
267 /* Prepare console output */
268 preloader_console_init();
271 /* Output System Firmware version info */
272 k3_sysfw_print_ver();
274 /* Perform board detection */
277 #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
278 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
281 printf("AVS init failed: %d\n", ret);
284 #if defined(CONFIG_K3_J721E_DDRSS)
285 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
287 panic("DRAM init failed: %d\n", ret);
292 u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
294 switch (boot_device) {
295 case BOOT_DEVICE_MMC1:
296 return (spl_mmc_emmc_boot_partition(mmc) ? MMCSD_MODE_EMMCBOOT : MMCSD_MODE_FS);
297 case BOOT_DEVICE_MMC2:
298 return MMCSD_MODE_FS;
300 return MMCSD_MODE_RAW;
304 static u32 __get_backup_bootmedia(u32 main_devstat)
306 u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
307 MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
310 case BACKUP_BOOT_DEVICE_USB:
311 return BOOT_DEVICE_DFU;
312 case BACKUP_BOOT_DEVICE_UART:
313 return BOOT_DEVICE_UART;
314 case BACKUP_BOOT_DEVICE_ETHERNET:
315 return BOOT_DEVICE_ETHERNET;
316 case BACKUP_BOOT_DEVICE_MMC2:
318 u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
319 MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
321 return BOOT_DEVICE_MMC1;
322 return BOOT_DEVICE_MMC2;
324 case BACKUP_BOOT_DEVICE_SPI:
325 return BOOT_DEVICE_SPI;
326 case BACKUP_BOOT_DEVICE_I2C:
327 return BOOT_DEVICE_I2C;
330 return BOOT_DEVICE_RAM;
333 static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
336 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
337 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
339 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
342 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
343 bootmode = BOOT_DEVICE_SPI;
345 if (bootmode == BOOT_DEVICE_MMC2) {
346 u32 port = (main_devstat &
347 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
348 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
350 bootmode = BOOT_DEVICE_MMC1;
356 u32 spl_spi_boot_bus(void)
358 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
359 u32 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
360 u32 bootmode = ((wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
361 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT) |
362 ((main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << BOOT_MODE_B_SHIFT);
364 return (bootmode == BOOT_DEVICE_QSPI) ? 1 : 0;
367 u32 spl_boot_device(void)
369 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
372 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
373 printf("ERROR: MCU only boot is not yet supported\n");
374 return BOOT_DEVICE_RAM;
377 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
378 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
380 if (bootindex == K3_PRIMARY_BOOTMODE)
381 return __get_primary_bootmedia(main_devstat, wkup_devstat);
383 return __get_backup_bootmedia(main_devstat);